[cfe-dev] How to set LangOptions for AST Matcher (bool vs _Bool)

Jan Ryšavý via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 25 07:02:12 PST 2020


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


More information about the cfe-dev mailing list