Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] getting preprocessed tokens for an AST node

Hi, I don't know if this is what you want... But, you can find the definition of a macro expansion using the IASTMacroExpansionLocation interface.

IASTNode node = ...
IASTNodeLocation[] location = node.getNodeLocations();
for (IASTNodeLocation loc : location) {
    if (loc instanceof IASTMacroExpansionLocation) {
        ((IASTMacroExpansionLocation)loc).getExpansion().getMacroDefinition() //<< returns the macro that generated "node"

2016-01-28 23:57 GMT-02:00 Nathan Ridge <zeratul976@xxxxxxxxxxx>:
When an AST node is created for something that occurs inside a macro expansion, the parser is operating on preprocessed tokens, that is, tokens that make up the macro expansion (as opposed to tokens that make up the macro invocation).

Is there a way to, given the AST node, recover the preprocessed tokens it was created from?

IASTNode has an 'IToken getSyntax()' method (and related methods getLeadingSyntax() and getTrailingSyntax()) which serve this purpose for AST nodes occurring in normal code (not inside a macro expansion), but these methods throw ExpansionOverlapsBoundaryException if the AST node occurs inside a macro expansion.


cdt-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top