(no subject)

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

(no subject)

Vassil Vassilev via cfe-dev
Hello!
When I write standalone tool based on ClangTool I ususally use CommonOptionsParser.
CommonOptionParser provides option --extra-arg-before=<string> that allow me to pass include directories to my clang-based tool.
For example: ./tool --extra-arg-before='/home/user/llvm_9/llvm_9-build/lib/clang/9.0.0/include -p /my/build/path /path/to/source.cpp. This invocation allow me to avoid preprocessor errors/
 
In general, my question is
how can I match AST nodes in A) source code in StringRef
B) source code in file
without run ClangTool instance?
The problem  is that I need include header files in source files for analysis.
 
For example code:
 
#define SOME_CODE R"(\
#include <stdio.h> \
...\
...\
);
 
auto M = compoundStmt(hasAncestor(functionDecl(hasName(fooName1)))).bind("bindStr")
std::unique_ptr<ASTUnit> Unit = buildASTFromCode(SOME_CODE , "pseudoFile.cpp")
auto MatchRes = match(M , Unit->getASTContext());
Node *Result = const_cast<Node *>(MatchRes[0].template getNodeAs<Node>("bindStr"));
 
So, when I write #include <stdio.h> in src file and run this non-ClangTool-based matcher this leads to errors:
/usr/include/stdio.h
 
In file included from pseudoFile.cpp:2:
/usr/include/stdio.h:33:10: fatal error: 'stddef.h' file not found
#include <stddef.h>
^~~~~~~~~~
 
How can we pass some extra args (same as CommonOptionsParser in ClangTool-based tool)?
Maybe the solution is to use buildASTFromCodeWithArgs or passing compile database entry for this source file then calling match method?
 
Thanks.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev