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.

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

http://help.eclipse.org/juno/index.jsp?topic=/org.eclipse.cdt.doc.isv/reference/api/org/eclipse/cdt/core/dom/ast/IASTPreprocessorMacroExpansion.html&anchor=getNestedMacroReferences()
http://help.eclipse.org/juno/index.jsp?topic=/org.eclipse.cdt.doc.isv/reference/api/org/eclipse/cdt/core/dom/ast/IASTNode.html&anchor=getLeadingSyntax()
http://help.eclipse.org/juno/index.jsp?topic=/org.eclipse.cdt.doc.isv/reference/api/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.html



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.

Thanks,
Nate

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev


Back to the top