Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rvkennedy opened this issue Apr 22, 2018 · 0 comments
Open

Comments

@rvkennedy
Copy link

rvkennedy commented Apr 22, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant