What I am trying to do is print only those macros which are defined in the current file.
So whenever the PPCallback function MacroDefined is called, I test if the presumed file name is same as
the file currently being processed. If it is then print macro identifier etc…
Relevant code is as follows…
void MacroDefined(const Token &MacroNameTok, const MacroInfo* MI)
std::cout<<“Macro “<<MacroNameTok.getIdentifierInfo()->getNameStart()<<” is defined here\n\t”;
//std::cout<<“Macro “<<tok::getTokenName(MacroNameTok.getKind())<<” is defined here\n\t”;
std::cout<<“The macro is function like\n”;
std::cout<<“The macro is object like\n”;
///if the macro is local to the current file being processed
bool MacroIsLocal(SourceLocation loc)
/// the source manager can decode the SourceLocation information
PresumedLoc presumed = sm->getPresumedLoc(loc);//sm is the SourceManager for the current file
if(file_name == presumed.getFilename())
When I do not call `bool MacroIsLocal(SourceLocation loc)’
It prints all the macros(including the predefined macros) without any errors.
What could be the problem… or is there any other way to
find out which macros are local to the file being processed.
Thanks for the help.