[cfe-dev] Emit fixit for root AST node

Dávid Bolvanský via cfe-dev cfe-dev at lists.llvm.org
Sat Oct 6 12:15:54 PDT 2018


Thanks. I found
https://github.com/llvm-mirror/clang/blob/f3b7928366f63b51ffc97e74f8afcff497c57e8d/lib/CodeGen/MacroPPCallbacks.cpp#L178
and I think this logic is what I need :)

so 6. 10. 2018 o 17:42 Artem Dergachev <noqnoqneo at gmail.com> napísal(a):

> The "root/top" AST node is TranslationUnitDecl that can be obtained via
> ASTContext.getTranslationUnitDecl().
>
> I guess you only need source locations in order to emit a fixit, so you
> can use SourceManager directly, eg.
> SourceManager.getLocForStartOfFile(SourceManager.getMainFileID()).
>
> The problem is probably harder though, because many files start with
> comments, which you'll most likely want to skip, so "top of the file"
> and "just before the first #include" will most likely be two different
> locations, and this difficulty will require more advanced hacking to
> overcome, which i'm not brave enough to reason about. You might find
> some inspiration in some of the existing clang-tidy checkers that deal
> with #includes, or maybe in the include-what-you-use tool (though it
> doesn't seem to be using fixits at all).
>
> On 10/6/18 1:53 AM, Dávid Bolvanský via cfe-dev wrote:
> > Hi,
> >
> > test.c:
> > #include <stdio.h>
> >
> > void foo() {
> >     bool x;
> > }
> >
> > When analyzing type "bool", I would like to emit fixit hint to top of
> > the file, just before "#include <stdio.h>".
> >
> > So my question is how to find the location of "root/top" AST node.
> >
> > Thanks
> >
> >
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181006/b470fda9/attachment.html>


More information about the cfe-dev mailing list