1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Added method to check that node belongs to macro expansion

This commit is contained in:
Alena Laskavaia 2010-05-19 02:41:12 +00:00
parent 5d3f18cb04
commit 85d6bff98e

View file

@ -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;
}
}