[cfe-dev] Clang libtoolig

Eric Liu via cfe-dev cfe-dev at lists.llvm.org
Fri Jul 21 04:57:11 PDT 2017


Did you register the matcher (i.e. "typedefDeclMatch") beforehand? For
example,
https://github.com/llvm-mirror/clang-tools-extra/blob/master/include-fixer/find-all-symbols/FindAllSymbols.cpp#L117

You could also find many sample usages of libTooling in clang-tools-extra.

Hope this helps :)

Cheers,
Eric

On Fri, Jul 21, 2017 at 11:29 AM ogzu rasa via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> I'm novice with libtooling, I try to learn with easy c++ code. I try to
> parse/print typedef expression like below lines:
>
> namespace DEBUG {
>     typedef void(*function_pointer_t)(int&);
>     typedef int myInt;}
>
> clang++ -Xclang -ast-dump -fsyntax-only output:
>
> `-NamespaceDecl 0x3e4fe331a8 <test.h:3:1, line:7:1> line:3:11 TESTS
>   |-TypedefDecl 0x3e4fe333b8 <line:4:2, col:42> col:18 function_pointer_t 'double (*)(int &)'
>   | `-PointerType 0x3e4fe33350 'double (*)(int &)'
>   |   `-ParenType 0x3e4fe332f0 'double (int &)' sugar
>   |     `-FunctionProtoType 0x3e4fe332b0 'double (int &)' cdecl
>   |       |-BuiltinType 0x3e4fe32b60 'double'
>   |       `-LValueReferenceType 0x3e4fe33210 'int &'
>   |         `-BuiltinType 0x3e4fe32a40 'int'
>   `-TypedefDecl 0x3e4fe33420 <line:5:2, col:14> col:14 myInt 'int'
>     `-BuiltinType 0x3e4fe32a40 'int'
>
> For parse it I create a class that inherite from
> MatchFinder::MatchCallback and overload MatchFinder::MatchCallback::run:
>
>  class TypdefDeclFinder : public MatchFinder::MatchCallback {public:
>     virtual void run(const MatchFinder::MatchResult& result)
>     {
>
>         auto Item = result.Nodes.getNodeAs<clang::TypedefDecl>("typedefDeclMatch");
>         if (!Item) return;
>         if (!IsDeclFromInputFiles(Item, result.SourceManager)) return;
>         if (!Item->getIdentifier()) return;
>         if (IsInsideTemplateContext(Item)) return;
>         print(Item);
>     }};
>
> But the Item pointer is equal to null. I can parse/print function,
> variable, class, struct template, method templates, enum ... with
> MacthFinder::MatchCallback, but this way doesn't run on typedef. What's
> wrong with this code?
>
>
> Thanks in advance for helps.
> _______________________________________________
> 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/20170721/e64ea56d/attachment.html>


More information about the cfe-dev mailing list