[PATCH] [extra] pptrace - preprocessor tracing and testing tool
Kim Gräsman
kim.grasman at gmail.com
Tue Oct 29 15:37:31 PDT 2013
OK, I took some time to step through this. Enumerating the arguments of a MacroArgs seems like a difficult problem (tm).
- getNumArguments does not return the number of arguments, it returns the number of tokens in the argument list
- getUnexpArgument takes an index, but skips over eof tokens
Here's a way I've found to enumerate over the argument tokens:
// This can probably be translated into a for loop,
// but it's late here and my head is buzzing...
unsigned ArgTokenCount = Value->getNumArguments();
unsigned I = 0;
while (I < ArgTokenCount) {
const clang::Token* Current = Value->getUnexpArgument(I);
unsigned TokenCount = Value->getArgLength(Current) + 1; // include EOF
I++;
ArgTokenCount -= TokenCount;
}
One problem is arguments rarely consist of a single token, but we can look at things like:
#define X Y(1 + 6, 2)
#define Y(a,b)
X
You'd need to find a way to rejoin a sequence of tokens into a string. The tokens appear to live in contiguous memory, though, so once you have the first token and the length of every argument, the entire arg is covered by [Current, Current + TokenCount). Not sure how to go from there to something you can render, but it should be doable.
Hope that helps!
http://llvm-reviews.chandlerc.com/D2020
More information about the cfe-commits
mailing list