jessevdk / cldoc

clang based documentation generator for C and C++
GNU General Public License v2.0
552 stars 58 forks source link

Unable to match comments if a macro is expanded before the declaration. #135

Open rvkennedy opened 6 years ago

rvkennedy commented 6 years ago

If there's a macro expanded in front of a function definition, class Sorted fails to find the appropriate comment. For example:

#define ABC 
namespace ns
{
        /// Returns the  pointer.
        ABC void* GetPointer();
}

The comment will not be assigned to GetPointer(), because it will be associated with the position of ABC (libclang returns un-preprocessed macros from get_tokens, as though they were ordinary identifiers). We could force it to return the nearest comment with location equal or less than the declaration location if Sorted.find() becomes:

    def find(self, key):
        i = bisect.bisect_left(self.keys, key+1)
        if i<=0 or i>=len(self.keys):
            return None
        return self[i-1]

But this would multiply allocate a comment to any uncommented functions below it. The following works by removing the values as we find them:

    def find(self, key):
        i = bisect.bisect_right(self.keys, key)
        if i<=0 or i>len(self.keys):
            return None
        self.keys.pop(i-1)
        result=self.pop(i-1)
        return result

But this won't work because we don't process the nodes in order, so some comments will be mismatched.