[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-dev] tracking macro expansion
|
Dear all
I implemented some macro analysis using MacroExpander [1] and
MacroExpansionTracker [2]. Are those classes intended to be used outside
of the CDT internals? To use them, I had to make some modifications to CDT:
- I made the class PreprocessorMacro public (the MacroExpander
constructor takes a CharArrayMap<PreprocessorMacro>).
- I made MacroExpansionTracker.finish() protected so I can redefine it
in my subclass (also start() and fail() probably should be protected).
- I made the class TokenList public (it's used as argument to
MacroExpansionTracker methods).
If MacroExpander is not intended to be used outside of the CDT
internals, is there a recommended way for Macro analysis?
Where possible in the AST, I want to identify nodes that were arguments
to function style macros. E.g. having an AST like:
1 + 2 * 3 * 4 + 5
coming from the C code:
1 + MUL(2 * 3, 4) + 5 // with the macro: #define MUL(A, B) A * B
I want to recognize that "2 * 3" comes from the macro argument A and
that "4" comes from the macro argument B. This indeed works now but
maybe there's a better way than what I did.
Thanks
Marco
[1] org.eclipse.cdt.internal.core.parser.scanner.MacroExpander
[2] org.eclipse.cdt.internal.core.parser.scanner.MacroExpansionTracker