diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java index 82c49b3d9f1..e3a5c5163f1 100644 --- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java +++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core.cxx; +import org.eclipse.cdt.core.dom.ast.IASTFileLocation; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; +import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; @@ -25,23 +29,38 @@ public final class CxxAstUtils { } public synchronized static CxxAstUtils getInstance() { - if (instance == null) instance = new CxxAstUtils(); + if (instance == null) + instance = new CxxAstUtils(); return instance; } public IType unwindTypedef(IType type) { - if (!(type instanceof IBinding)) return type; + if (!(type instanceof IBinding)) + return type; IBinding typeName = (IBinding) type; // unwind typedef chain try { while (typeName instanceof ITypedef) { IType t = ((ITypedef) typeName).getType(); - if (t instanceof IBinding) typeName = (IBinding) t; - else return t; + if (t instanceof IBinding) + typeName = (IBinding) t; + else + return t; } } catch (Exception e) { // in CDT 6.0 getType throws DOMException Activator.log(e); } return (IType) typeName; } + + public boolean isInMacro(IASTNode node) { + IASTNodeSelector nodeSelector = node.getTranslationUnit() + .getNodeSelector(node.getTranslationUnit().getFilePath()); + IASTFileLocation fileLocation = node.getFileLocation(); + + IASTPreprocessorMacroExpansion macro = nodeSelector + .findEnclosingMacroExpansion(fileLocation.getNodeOffset(), + fileLocation.getNodeLength()); + return macro != null; + } }