How to set LangOptions for AST Matcher (bool vs _Bool)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to set LangOptions for AST Matcher (bool vs _Bool)

suyash singh via cfe-dev
Is there any way how to setup LangOptions for AST matcher? We have following matcher:

static llvm::cl::OptionCategory OptionCategory("options");

class CMatcherCallback : public MatchFinder::MatchCallback
{
public:
     virtual void run(const MatchFinder::MatchResult& result) override
     {
         if (const CXXMethodDecl* method = result.Nodes.getNodeAs<CXXMethodDecl>("id"))
         {
             method->dumpColor();
         }
     }
};

int main(int argc, const char** argv)
{
     tooling::CommonOptionsParser optionsParser(argc, argv, OptionCategory);
     tooling::ClangTool tool(optionsParser.getCompilations(),
                             optionsParser.getSourcePathList());

     CMatcherCallback callback;
     MatchFinder finder;
     finder.addMatcher(
         cxxRecordDecl(
             isDefinition(),
             hasName("CTest"),
             isSameOrDerivedFrom(
                 cxxRecordDecl(
                     hasMethod(
                         cxxMethodDecl(
                             hasName("Method"),
                             hasParameter(0, parmVarDecl(hasType(asString("bool")))))
                             .bind("id"))))),
         &callback);
     int ret = tool.run(tooling::newFrontendActionFactory(&finder).get());

     return ret;
}

It doesn't match this method:

class CTest
{
   void Method(bool);
};

It does match when we change type from hasParameter(0, parmVarDecl(hasType(asString("bool")))))
to "_Bool". So it seems matcher is in C instead of C++ mode? Thank you for any suggestion...
 
Best regards
Jan Rysavy
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev