[cfe-dev] Preprocessor/Parser interaction
Aditya Kumar
hiraditya at msn.com
Tue Feb 21 14:35:34 PST 2012
I want to use a PPCallback function (MacroExpands) to track all the locations where a macro has been invoked in the program. In the main function, there are a few things that I want to implement, details are given as comment inside the main function.
Till now what I have done is the following:
namespace clang {class MyASTAction : public FrontendAction{ public: ASTConsumer *CreateASTConsumer(CompilerInstance &CI, llvm::StringRef InFile) { return 0; } void ExecuteAction() { }
bool usesPreprocessorOnly() const { return false; }}; class TrackMacro : public PPCallbacks{ public: void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI, SourceRange Range) { std::cout<<"Macro expands to"<<MacroNameTok.getRawIdentifierData(); } ~TrackMacro(){}};}
using namespace clang;int main(int argc, const char** argv){ MyASTAction action; CompilerInstance Clang;
/*****************************************
How to create an instance of the preprocessor class, it seems like it takes too many(9) arguments which I was not able to figure out.Or is there a way to just create a default preprocessor and add my own call back function to it. And then pass the preprocessor object to the Parser and invoke the parser just by supplying a filename.
*****************************************/ TrackMacro track_macro; PP.addPPCallbacks(&track_macro);
Clang.setPreprocessor(PP);
MyASTAction* Act = new MyASTAction(); Clang.ExecuteAction(*Act);
return 0;}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120221/9c13e04d/attachment.html>
More information about the cfe-dev
mailing list