[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cdt-dev] tracking macro expansion
- From: Marco Trudel <marco@xxxxxxxxxxxx>
- Date: Tue, 5 Mar 2013 13:01:44 +0100
- Delivered-to: firstname.lastname@example.org
- User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130221 Thunderbird/17.0.3
I implemented some macro analysis using MacroExpander  and
MacroExpansionTracker . 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
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.