Skip to main content
summaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorAlena Laskavaia2010-05-18 22:41:12 -0400
committerAlena Laskavaia2010-05-18 22:41:12 -0400
commit85d6bff98e4c292ff6599beecd7d6dc163ae86ff (patch)
tree20cf129dfefb6df3c30cf72f241ee2279750c357 /codan
parent5d3f18cb0477cf333dd57896e5530a8758ac9dc6 (diff)
downloadorg.eclipse.cdt-85d6bff98e4c292ff6599beecd7d6dc163ae86ff.tar.gz
org.eclipse.cdt-85d6bff98e4c292ff6599beecd7d6dc163ae86ff.tar.xz
org.eclipse.cdt-85d6bff98e4c292ff6599beecd7d6dc163ae86ff.zip
Added method to check that node belongs to macro expansion
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java27
1 files changed, 23 insertions, 4 deletions
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 82c49b3d9f..e3a5c5163f 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;
+ }
}

Back to the top