[cfe-dev] Handling expansions

Pedro Delgado Perez pedro.delgadoperez at mail.uca.es
Sat Feb 1 09:21:51 PST 2014


 
Hi again,

Please, I need some help with the preprocessor directives. I will describe my situation.
I have a directive in my file:

#define MY_DIRECTIVE( param )   {   ...   }

Then, I invoke the directive within a method:

void MyClass::Method() 
{ 
  ...
       MY_DIRECTIVE (param1);
  ...
}

My goal is to perform a change in the param passed, for instance, changing param1 by param2. I can make the modification with replaceText without any problem; however, it produces a "Stack dump" when I get the content with:

const RewriteBuffer *RewriteBuf = Rewrite.getRewriteBufferFor(file_id);

What is the problem? How can I handle this? I'm really lost with the expansions...


> Hi,
> 
> Yesterday I tested my tool with a progam containing preprocessor directives. It was the first time I had this possibility into account and I had an stack dump when triying to obtain the file:
> 
> FullSourceLoc FullLocation = Context->getFullLoc(sourceLoc);
> ... 
> file = Context->getSourceManager().getFileEntryForID(FullLocation.getFileID())->getName();
> 
> Then, I added:
> 
> if(Context->getSourceManager().getSLocEntry(FullLocation.getFileID()).isExpansion()){
>                FullLocation = FullLocation.getExpansionLoc();
>                file= Context->getSourceManager()
>                                           .getFileEntryForID(FullLocation.getFileID())->getName();
> }
> else{
> ...
> }
> 
> And the result seemed ok. But when I tried to obtain again the file with:
> 
> Context->getSourceManager().getFileEntryForID(FullLocation.getFileID());
> 
> I had another stack dump. How do you handle these directives? There are so many methods... that I'm not able to find a solution because I cannot understand very well whay is an expansion, an SEntryLoc...
> 
> My intention is to make a change in the directive. For instance, in this directive:
> #define delete( a )   {        
>           a.release();                
> }
> when the calling to the method release is found, my tool should include an argument in the method. 
> 
> A doubt: when I make that change, it affects to every inkovation to the directive, isn't it? But, is there a way that the change only affects to a single directive invokation?
> 
> Thanks in advance,
> 
> Pedro.
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140201/205563cc/attachment.html>


More information about the cfe-dev mailing list