Since clang branch 2.7 onwards the InitHeaderSearch and InitPreprocessor seem to have been removed from the include library ( to be replaced by HeaderSearchOptions) . It will be really helpful if someone can demonstrate via a small piece of code - how to initiate search paths of header files included in a file you want to parse ( which previously was done by InitHeaderSearch )
Also can someone give a small snippet of code to demonstrate forming a CFG class( branch 2.7 + ) given an already formed ASTContext class and maybe a RecursiveASTVisitor to traverse the AST .
Since clang branch 2.7 onwards the InitHeaderSearch and InitPreprocessor seem to have been removed from the include library ( to be replaced by HeaderSearchOptions) . It will be really helpful if someone can demonstrate via a small piece of code - how to initiate search paths of header files included in a file you want to parse ( which previously was done by InitHeaderSearch )
Also can someone give a small snippet of code to demonstrate forming a CFG class( branch 2.7 + ) given an already formed ASTContext class and maybe a RecursiveASTVisitor to traverse the AST .
Thanks and Regards ,
Parijat
Probably the best way to construct a CFG is to have an AnalysisContext object do it for you. You can construct an AnalysisContext object using a FunctionDecl, and then call the getCFG() method to have it lazily create a CFG. When the AnalysisContext object is destroyed, the CFG will be destroyed as well.
What is the TranslationUnit required as a parameter for AnalysisContext creation ?
Thanks and Regards
Parijat
It’s optional, and you can leave it NULL. It’s there to support cross-translation unit analysis (in the future).
Thanks a lot !
.By the way can someone guide me on how do I need to go about initializing header search paths because my parser collapses when it comes across included header files in the test code.
This is how I have initialized the preprocessor :
llvm::raw_ostream *os = NULL;
llvm::raw_ostream *ps = NULL;
const DiagnosticOptions diagop;
bool OwnsOutputStream=false;
TextDiagnosticPrinter diagClient(*os,diagop,OwnsOutputStream);
Diagnostic diags(&diagClient);
LangOptions opts;
TargetOptions to;
const std::string& triple = LLVM_HOSTTRIPLE;
to.ABI="";
to.CXXABI=“itanium”;
to.CPU="";
to.Features.clear();
to.Triple=triple;
TargetInfo* target = TargetInfo::CreateTargetInfo(diags,to);
SourceManager sm(diags);
FileManager fm;
HeaderSearch headers(fm);
Preprocessor pp(diags,opts,*target,sm,headers);
Any suggestions / modifications needed to make sure the included file search paths are taken care while parsing a test file ?
Thanks and Regards ,
Parijat