Handling expansions


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:

FullLocation = FullLocation.getExpansionLoc();
file= Context->getSourceManager()


And the result seemed ok. But when I tried to obtain again the file with:


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 ) {
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,