Handle C++ functions with clang API to insert code

前端 未结 3 1985
孤独总比滥情好
孤独总比滥情好 2021-02-02 02:35

I need to preprocess some C++ files to automatically insert code for testing and profiling, and I need to do it with the clang API.

Fo

3条回答
  •  时光取名叫无心
    2021-02-02 03:26

    Are there any settings to switch between C and C++ ?

    Finally I found out how to handle this:

    I extended from ASTConsumer and RecursiveASTVisitor to traverse the AST and implemented VisitCXXRecordDecl(CXXRecordDecl* D). Then I had to set the LangOptions parameter for the preprocessor, so it parses C++.

    langOpts.CPlusPlus = 1;
    

    My fault was to think that it would parse C++ right away, but that was not the case, it parses C as default and so doesn't recognize classes.

提交回复
热议问题