<font face="arial, helvetica, sans-serif">Could you post the whole source?</font><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Where are you getting the SourceManager that you calling `<span style="font-size:12px;background-color:rgb(255,255,255)">sm->getPresumedLoc(loc)` on? It is important that you call that method on the same SourceManager that is in the CompilerInstance that clang is using.</span></font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Also, you probably want to use `sm->isFromMainFile(loc)` instead of getting the presumedloc, since the presumedloc can be modified by `#line` directives and other stuff.</font></div>
<div><a href="http://clang.llvm.org/doxygen/classclang_1_1SourceManager.html#ae243bd7789128f1bc5ad462f69f91579">http://clang.llvm.org/doxygen/classclang_1_1SourceManager.html#ae243bd7789128f1bc5ad462f69f91579</a><font face="arial, helvetica, sans-serif"><br>
</font><br>--Sean Silva<br><br><div class="gmail_quote">On Mon, Feb 27, 2012 at 2:29 PM, Aditya Kumar <span dir="ltr"><<a href="mailto:hiraditya@msn.com">hiraditya@msn.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div><div dir="ltr">
<font face="Verdana">What I am trying to do is print only those macros which are defined in the current file.</font><div><font face="Verdana">So whenever the PPCallback function MacroDefined is called, I test if the presumed file name is same as</font></div>
<div><font face="Verdana">the file currently being processed. If it is then print macro identifier etc...</font></div><div><font face="Verdana"><br></font></div><div><font face="Verdana">Relevant code is as follows...</font></div>
<div><font face="Verdana"><br></font></div><div><div><font face="Verdana">    void MacroDefined(const Token &MacroNameTok, const MacroInfo* MI)</font></div><div><font face="Verdana">    {</font></div><div><font face="Verdana">      if(MacroIsLocal(MI->getDefinitionLoc())) { </font></div>
<div><font face="Verdana">      //  if(MacroNameTok.getName()){ </font></div><div><font face="Verdana">        std::cout<<"Macro "<<MacroNameTok.getIdentifierInfo()->getNameStart()<<" is defined here\n\t"; </font></div>
<div><font face="Verdana">        //std::cout<<"Macro "<<tok::getTokenName(MacroNameTok.getKind())<<" is defined here\n\t"; </font></div><div><font face="Verdana">        if(MI->isFunctionLike()) </font></div>
<div><font face="Verdana">          std::cout<<"The macro is function like\n"; </font></div><div><font face="Verdana">        if(MI->isObjectLike()) </font></div><div><font face="Verdana">          std::cout<<"The macro is object like\n"; </font></div>
<div><font face="Verdana">      } </font></div><div><font face="Verdana">    } </font></div><div><span style="font-size:10pt"><font face="Verdana">    </font></span></div><div><font face="Verdana">    ///if the macro is local to the current file being processed </font></div>
<div><font face="Verdana">    bool MacroIsLocal(SourceLocation loc) </font></div><div><font face="Verdana">    { </font></div><div><font face="Verdana">      /// the source manager can decode the SourceLocation information </font></div>
<div><font face="Verdana">      PresumedLoc presumed = sm->getPresumedLoc(loc);//sm is the SourceManager for the current file </font></div><div><font face="Verdana">      if(file_name == presumed.getFilename()) </font></div>
<div><font face="Verdana">        return true; </font></div><div><font face="Verdana">      return false; </font></div><div><font face="Verdana">    } </font></div></div><div><font face="Verdana"><br></font></div><div><font face="Verdana">When I do not call <span style="font-size:10pt">    `bool MacroIsLocal(SourceLocation loc)' </span></font></div>
<div><span style="font-size:10pt"><font face="Verdana">It prints all the macros(including the predefined macros) without any errors. </font></span></div><div><span style="font-size:10pt"><font face="Verdana">What could be the problem... or is there any other way to </font></span></div>
<div><span style="font-size:10pt"><font face="Verdana">find out which macros are local to the file being processed. </font></span></div><div><span style="font-family:Verdana;font-size:10pt"> </span></div><div><span style="font-family:Verdana;font-size:10pt"><br>
</span></div><div><font face="Verdana">Thanks for the help.</font></div><span class="HOEnZb"><font color="#888888"><div><font face="Verdana">Aditya</font></div>                                          </font></span></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>