Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] tracking macro expansion

Hi all,

for my bachelor thesis I'm planning on writing a refactoring plugin for the CDT platform. I'm therefore also interested in tracking macro expansion in order to report proper warnings to the user when trying to apply a refactoring. As by now my needs would probably be satisfied if I could be able to determine whether any node in the AST exists because of macro expansion (no matter from which macro).

As I want my plugin to comply with the official CDT release, changing internal API like Marco did is no option for me. I'd be glad if anyone has a suggestion on how to properly do this.

Thanks
Simon

On 05.03.2013 13:01, Marco Trudel wrote:
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
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev




Back to the top