[cfe-dev] Clang libtoolig

ogzu rasa via cfe-dev cfe-dev at lists.llvm.org
Fri Jul 21 02:29:45 PDT 2017


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170721/6fe3eba6/attachment.html>


More information about the cfe-dev mailing list