Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2005-03-23 15:26:11 +0000
committerAndrew Niefer2005-03-23 15:26:11 +0000
commite8ba635111ad80e43fd42b2d40a03e1fe0e2cc4e (patch)
tree9cf9bb657460df1981a8a5b06117c2034eac1e2a
parentfc915aee25396b2873d48765ad3d8835f6759230 (diff)
downloadorg.eclipse.cdt-e8ba635111ad80e43fd42b2d40a03e1fe0e2cc4e.tar.gz
org.eclipse.cdt-e8ba635111ad80e43fd42b2d40a03e1fe0e2cc4e.tar.xz
org.eclipse.cdt-e8ba635111ad80e43fd42b2d40a03e1fe0e2cc4e.zip
caching of IASTNames in C
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java70
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java71
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java50
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java55
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java17
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java62
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CLabel.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java91
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java113
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java745
-rw-r--r--core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java27
-rw-r--r--core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeObject.java141
14 files changed, 658 insertions, 802 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
index f0d73a7add4..c6b3f14216e 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
@@ -41,10 +41,10 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
-import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.dom.parser.c.CParameter;
+import org.eclipse.cdt.internal.core.dom.parser.c.CScope;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding;
@@ -83,11 +83,11 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals( decls[0], ((IASTStandardFunctionDeclarator)f1.getDeclarators()[0]).getParameters()[0].getDeclarator().getName() );
assertEquals( decls[1], ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName() );
- assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((ICScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
CVisitor.clearBindings(tu);
- assertNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNull( ((ICScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
}
@@ -118,11 +118,11 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals( decls.length, 1 );
assertEquals( decls[0], ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName() );
- assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((ICScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
CVisitor.clearBindings(tu);
- assertNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNull( ((ICScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
}
@@ -190,13 +190,13 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals( decls.length, 1 );
assertEquals( decls[0], x1.getName() );
- assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((ICScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((ICScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()) ); //$NON-NLS-1$
CVisitor.clearBindings(tu);
- assertNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
- assertNull( ((ICScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
- assertNull( ((ICScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()) ); //$NON-NLS-1$
}
@@ -213,7 +213,7 @@ public class AST2KnRTests extends AST2BaseTest {
IASTSimpleDeclaration isroot_decl = (IASTSimpleDeclaration)tu.getDeclarations()[1];
IASTFunctionDefinition isroot_def = (IASTFunctionDefinition)tu.getDeclarations()[2];
- IASTName x0 = ((IASTStandardFunctionDeclarator)isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
+ //IASTName x0 = ((IASTStandardFunctionDeclarator)isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
IASTName x1 = ((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterNames()[0];
IASTName x2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
IASTName x3 = ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
@@ -249,13 +249,13 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals( decls.length, 1 );
assertEquals( decls[0], x2 );
- assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((ICScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
CVisitor.clearBindings(tu);
- assertNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray()) ); //$NON-NLS-1$
- assertNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
- assertNull( ((ICScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
}
public void testKRCProblem1() throws Exception {
@@ -313,11 +313,11 @@ public class AST2KnRTests extends AST2BaseTest {
IASTName[] decls = tu.getDeclarations(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
assertEquals( decls.length, 0 );
- assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
CVisitor.clearBindings(tu);
- assertNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray()) ); //$NON-NLS-1$
- assertNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
}
public void testKRCProblem3() throws Exception {
@@ -453,7 +453,7 @@ public class AST2KnRTests extends AST2BaseTest {
IASTName A_struct_name1 = ((IASTCompositeTypeSpecifier)A_struct.getDeclSpecifier()).getName();
assertEquals( A_struct_name1.toString(), "A_struct" ); //$NON-NLS-1$
ICompositeType A_struct_type1 = (ICompositeType)A_struct_name1.resolveBinding();
- assertEquals( ((ICInternalBinding)A_struct_type1).getPhysicalNode(), A_struct.getDeclSpecifier() );
+ assertEquals( ((ICInternalBinding)A_struct_type1).getPhysicalNode(), ((IASTCompositeTypeSpecifier)A_struct.getDeclSpecifier()).getName() );
IField[] fields = A_struct_type1.getFields();
IField a1 = fields[0];
IField c1 = fields[1];
@@ -483,7 +483,7 @@ public class AST2KnRTests extends AST2BaseTest {
IFunction f_fun1 = (IFunction)f_name1.resolveBinding();
assertEquals( f_name1.toString(), "f" ); //$NON-NLS-1$
assertEquals( f_decltor1.getParameters().length, 1 );
- IASTName x0 = f_decltor1.getParameters()[0].getDeclarator().getName();
+ //IASTName x0 = f_decltor1.getParameters()[0].getDeclarator().getName();
IASTName A_name2 = ((ICASTTypedefNameSpecifier)f_decltor1.getParameters()[0].getDeclSpecifier()).getName();
assertEquals( A_name2.toString(), "A" ); //$NON-NLS-1$
ITypedef A_var2 = (ITypedef)A_name2.resolveBinding();
@@ -540,14 +540,14 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals( decls.length, 1 );
assertEquals( decls[0], x2 );
- assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("A").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((ICScope)((IASTCompoundStatement)f_def.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("A").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull( ((CScope)((IASTCompoundStatement)f_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
CVisitor.clearBindings(tu);
- assertNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray()) ); //$NON-NLS-1$
- assertNull( ((ICScope)tu.getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNull( ((ICScope)((IASTCompoundStatement)f_def.getBody()).getScope()).getBinding(ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
+ assertNull( ((CScope)((IASTCompoundStatement)f_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
index 32a0e1e6a6c..a3d05f56457 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
@@ -71,7 +71,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
-import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
@@ -200,24 +199,24 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(decls.length, 1);
assertEquals(decls[0], name_y);
- // test clearBindings
- assertNotNull(((ICScope) tu.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
- assertNotNull(((ICScope) tu.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
- assertNotNull(((ICScope) body_f.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("z").toCharArray())); //$NON-NLS-1$
- assertNotNull(((ICScope) body_f.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray())); //$NON-NLS-1$
- CVisitor.clearBindings(tu);
- assertNull(((ICScope) tu.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
- assertNull(((ICScope) tu.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
- assertNull(((ICScope) body_f.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("z").toCharArray())); //$NON-NLS-1$
- assertNull(((ICScope) body_f.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray())); //$NON-NLS-1$
+// // test clearBindings
+// assertNotNull(((ICScope) tu.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
+// assertNotNull(((ICScope) tu.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
+// assertNotNull(((ICScope) body_f.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("z").toCharArray())); //$NON-NLS-1$
+// assertNotNull(((ICScope) body_f.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray())); //$NON-NLS-1$
+// CVisitor.clearBindings(tu);
+// assertNull(((ICScope) tu.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
+// assertNull(((ICScope) tu.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
+// assertNull(((ICScope) body_f.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("z").toCharArray())); //$NON-NLS-1$
+// assertNull(((ICScope) body_f.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray())); //$NON-NLS-1$
}
public void testSimpleStruct() throws Exception {
@@ -769,23 +768,23 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(decls.length, 1);
assertEquals(decls[0], declaration2.getDeclarators()[0].getName());
- assertNotNull(((ICScope) tu.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_TAG, new String("x").toCharArray())); //$NON-NLS-1$
- assertNotNull(((ICScope) tu.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
- assertNotNull(((ICScope) compound.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
- assertNotNull(((ICScope) compound.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray())); //$NON-NLS-1$
- CVisitor.clearBindings(tu);
- assertNull(((ICScope) tu.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_TAG, new String("x").toCharArray())); //$NON-NLS-1$
- assertNull(((ICScope) tu.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
- assertNull(((ICScope) compound.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
- assertNull(((ICScope) compound.getScope()).getBinding(
- ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray())); //$NON-NLS-1$
+// assertNotNull(((ICScope) tu.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_TAG, new String("x").toCharArray())); //$NON-NLS-1$
+// assertNotNull(((ICScope) tu.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
+// assertNotNull(((ICScope) compound.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
+// assertNotNull(((ICScope) compound.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray())); //$NON-NLS-1$
+// CVisitor.clearBindings(tu);
+// assertNull(((ICScope) tu.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_TAG, new String("x").toCharArray())); //$NON-NLS-1$
+// assertNull(((ICScope) tu.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
+// assertNull(((ICScope) compound.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
+// assertNull(((ICScope) compound.getScope()).getBinding(
+// ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray())); //$NON-NLS-1$
}
public void testFunctionParameters() throws Exception {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java
index cee367a5c02..4194be648d8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java
@@ -15,6 +15,7 @@
package org.eclipse.cdt.core.dom.ast.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
@@ -23,42 +24,47 @@ import org.eclipse.cdt.core.dom.ast.IScope;
*/
public interface ICScope extends IScope {
/**
- * ISO C:99 6.2.3 there are seperate namespaces for various categories of
- * identifiers: - label names ( labels have ICFunctionScope ) - tags of
- * structures or unions : NAMESPACE_TYPE_TAG - members of structures or
- * unions ( members have ICCompositeTypeScope ) - all other identifiers :
- * NAMESPACE_TYPE_OTHER
- */
- public static final int NAMESPACE_TYPE_TAG = 0;
-
- public static final int NAMESPACE_TYPE_OTHER = 1;
-
- /**
- * add a binding to this scope
+ * remove the given binding from this scope
*
* @param binding
* @throws DOMException
*/
- void addBinding(IBinding binding) throws DOMException;
+ void removeBinding(IBinding binding) throws DOMException;
/**
- * remove the given binding from this scope
+ * Add an IASTName to be cached in this scope
*
- * @param binding
+ * @param name
* @throws DOMException
*/
- void removeBinding(IBinding binding) throws DOMException;
+ public void addName(IASTName name) throws DOMException;
/**
- * Get the binding that has previously been added to this scope that matches
- * the given name and is in the appropriate namespace
+ * Get the binding that the given name would resolve to in this scope. Could
+ * return null if there is no matching binding in this scope, or if resolve ==
+ * false and the appropriate binding has not yet been resolved.
*
- * @param namespaceType :
- * either NAMESPACE_TYPE_TAG or NAMESPACE_TYPE_OTHER
* @param name
- * @return
+ * @param resolve :
+ * whether or not to resolve the matching binding if it has not
+ * been so already.
+ * @return : the binding in this scope that matches the name, or null
* @throws DOMException
*/
- public IBinding getBinding(int namespaceType, char[] name)
+ public IBinding getBinding(IASTName name, boolean resolve)
throws DOMException;
+
+ /**
+ * Set whether or not all the names in this scope have been cached
+ *
+ * @param b
+ */
+ public void setFullyCached(boolean b) throws DOMException;
+
+ /**
+ * whether or not this scope's cache contains all the names
+ *
+ * @return
+ */
+ public boolean isFullyCached() throws DOMException;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java
index 9494926f39c..71dd1ad6ac4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java
@@ -87,7 +87,7 @@ public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implement
IBinding binding = name.resolveBinding();
if( binding instanceof ICInternalBinding ){
IASTNode node = ((ICInternalBinding)binding).getPhysicalNode();
- if( node == this )
+ if( node == name )
return r_declaration;
}
return r_reference;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java
index 615d57e54a8..9d8a27bfc1b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java
@@ -16,56 +16,24 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
-import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-import org.eclipse.cdt.internal.core.dom.parser.c.CScope.CollectNamesAction;
/**
* @author aniefer
*/
-public class CCompositeTypeScope implements ICCompositeTypeScope {
- private ICASTCompositeTypeSpecifier compositeTypeSpec = null;
-
- private CharArrayObjectMap bindings = CharArrayObjectMap.EMPTY_MAP;
-
+public class CCompositeTypeScope extends CScope implements ICCompositeTypeScope {
public CCompositeTypeScope( ICASTCompositeTypeSpecifier compTypeSpec ){
- compositeTypeSpec = compTypeSpec;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.c.ICScope#addBinding(org.eclipse.cdt.core.dom.ast.IBinding)
- */
- public void addBinding( IBinding binding ) {
- if( bindings == CharArrayObjectMap.EMPTY_MAP )
- bindings = new CharArrayObjectMap( 1 );
- bindings.put( binding.getNameCharArray(), binding );
+ super( compTypeSpec );
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.c.ICScope#getBinding(int, char[])
- */
- public IBinding getBinding( int namespaceType, char[] name ) {
- if( namespaceType == ICScope.NAMESPACE_TYPE_OTHER )
- return getBinding( name );
- return null;
- }
- /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope#getBinding(char[])
*/
public IBinding getBinding( char[] name ) {
- return (IBinding) bindings.get( name );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
- */
- public IScope getParent() {
- return CVisitor.getContainingScope( compositeTypeSpec );
+ return super.getBinding( NAMESPACE_TYPE_OTHER, name );
}
/* (non-Javadoc)
@@ -73,7 +41,7 @@ public class CCompositeTypeScope implements ICCompositeTypeScope {
*/
public IBinding[] find( String name ) {
CollectNamesAction action = new CollectNamesAction( name.toCharArray() );
- compositeTypeSpec.accept( action );
+ getPhysicalNode().accept( action );
IASTName [] names = action.getNames();
IBinding [] result = null;
@@ -89,19 +57,4 @@ public class CCompositeTypeScope implements ICCompositeTypeScope {
return (IBinding[]) ArrayUtil.trim( IBinding.class, result );
}
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.c.ICScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding)
- */
- public void removeBinding(IBinding binding) {
- if( bindings != CharArrayObjectMap.EMPTY_MAP ) {
- bindings.remove( binding.getNameCharArray(), 0, binding.getNameCharArray().length);
- }
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IScope#getPhysicalNode()
- */
- public IASTNode getPhysicalNode() {
- return compositeTypeSpec;
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java
index 048aad2295f..bb788a6f2b6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java
@@ -41,12 +41,14 @@ public class CEnumeration implements IEnumeration {
declarations = new IASTName[] { enumeration };
else
definition = enumeration;
+ ((CASTName)enumeration).setBinding( this );
}
public void addDeclaration( IASTName decl ){
if( decl.getPropertyInParent() != IASTElaboratedTypeSpecifier.TYPE_NAME )
return;
+ ((CASTName) decl).setBinding( this );
if( declarations == null ){
declarations = new IASTName[] { decl };
return;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java
index 10be3b84452..ab40e8a8a8b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java
@@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
@@ -38,36 +39,38 @@ public class CEnumerator implements IEnumerator {
}
}
- private final IASTEnumerator enumerator;
+ private final IASTName enumeratorName;
public CEnumerator( IASTEnumerator enumtor ){
- this.enumerator= enumtor;
+ this.enumeratorName = enumtor.getName();
+ ((CASTName)enumeratorName).setBinding( this );
}
public IASTNode getPhysicalNode(){
- return enumerator;
+ return enumeratorName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
public String getName() {
- return enumerator.getName().toString();
+ return enumeratorName.toString();
}
public char[] getNameCharArray(){
- return ((CASTName) enumerator.getName()).toCharArray();
+ return enumeratorName.toCharArray();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
public IScope getScope() {
- return CVisitor.getContainingScope( enumerator );
+ return CVisitor.getContainingScope( enumeratorName.getParent() );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IEnumerator#getType()
*/
public IType getType() {
- IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) enumerator.getParent();
+ IASTEnumerator etor = (IASTEnumerator) enumeratorName.getParent();
+ IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) etor.getParent();
IEnumeration enumeration = (IEnumeration) enumSpec.getName().resolveBinding();
return enumeration;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java
index ca89b4d4606..c28fc37c260 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java
@@ -21,72 +21,38 @@ import org.eclipse.cdt.core.dom.ast.ILabel;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
-import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
/**
* Created on Nov 8, 2004
* @author aniefer
*/
-public class CFunctionScope implements ICFunctionScope {
- private final IASTFunctionDefinition function;
- private CharArrayObjectMap bindings = CharArrayObjectMap.EMPTY_MAP;
-
+public class CFunctionScope extends CScope implements ICFunctionScope {
public CFunctionScope( IASTFunctionDefinition function ){
- this.function = function;
+ super( function );
}
- public void addBinding( IBinding binding ) {
- //only labels have function scope
- if( !(binding instanceof ILabel) )
- return;
- if( bindings == CharArrayObjectMap.EMPTY_MAP )
- bindings = new CharArrayObjectMap(1);
- bindings.put( binding.getNameCharArray(), binding );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.c.ICScope#getBinding(int, char[])
- */
- public IBinding getBinding( int namespaceType, char[] name ) {
- if( namespaceType == ICScope.NAMESPACE_TYPE_OTHER )
- return getBinding( name );
- return null;
- }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICFunctionScope#getBinding(char[])
*/
public IBinding getBinding( char[] name ) {
- return (IBinding) bindings.get( name );
+ return super.getBinding( NAMESPACE_TYPE_OTHER, name );
}
public IScope getBodyScope(){
- IASTStatement statement = function.getBody();
+ IASTNode node = getPhysicalNode();
+ IASTStatement statement = ((IASTFunctionDefinition)node).getBody();
if( statement instanceof IASTCompoundStatement ){
return ((IASTCompoundStatement)statement).getScope();
}
return null;
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
- */
- public IScope getParent() {
- return function.getScope();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
- */
- public IBinding[] find(String name) {
- return null;
- }
public ILabel[] getLabels(){
FindLabelsAction action = new FindLabelsAction();
- function.accept( action );
+ getPhysicalNode().accept( action );
ILabel [] result = null;
if( action.labels != null ){
@@ -114,20 +80,4 @@ public class CFunctionScope implements ICFunctionScope {
return PROCESS_CONTINUE;
}
}
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.c.ICScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding)
- */
- public void removeBinding(IBinding binding) {
- if( bindings != CharArrayObjectMap.EMPTY_MAP ) {
- bindings.remove( binding.getNameCharArray(), 0, binding.getNameCharArray().length);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IScope#getPhysicalNode()
- */
- public IASTNode getPhysicalNode() {
- return function;
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CLabel.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CLabel.java
index 3dab3c008e8..1ca780eb13f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CLabel.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CLabel.java
@@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
+import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.ILabel;
import org.eclipse.cdt.core.dom.ast.IScope;
@@ -36,10 +37,11 @@ public class CLabel implements ILabel {
}
}
- private final IASTLabelStatement labelStatement;
+ private final IASTName labelStatement;
- public CLabel( IASTLabelStatement statement ){
+ public CLabel( IASTName statement ){
labelStatement = statement;
+ ((CASTName)statement).setBinding( this );
}
public IASTNode getPhysicalNode(){
return labelStatement;
@@ -48,24 +50,24 @@ public class CLabel implements ILabel {
* @see org.eclipse.cdt.core.dom.ast.ILabel#getLabelStatement()
*/
public IASTLabelStatement getLabelStatement() {
- return labelStatement;
+ return (IASTLabelStatement) labelStatement.getParent();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
public String getName() {
- return labelStatement.getName().toString();
+ return labelStatement.toString();
}
public char[] getNameCharArray(){
- return ((CASTName) labelStatement.getName()).toCharArray();
+ return labelStatement.toCharArray();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
public IScope getScope() {
- return CVisitor.getContainingScope( labelStatement );
+ return CVisitor.getContainingScope( labelStatement.getParent() );
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java
index 4a3b6fa26f5..21c12d5a84a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java
@@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
@@ -37,7 +38,18 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
* @author aniefer
*/
public class CScope implements ICScope {
+ /**
+ * ISO C:99 6.2.3 there are seperate namespaces for various categories of
+ * identifiers: - label names ( labels have ICFunctionScope ) - tags of
+ * structures or unions : NAMESPACE_TYPE_TAG - members of structures or
+ * unions ( members have ICCompositeTypeScope ) - all other identifiers :
+ * NAMESPACE_TYPE_OTHER
+ */
+ public static final int NAMESPACE_TYPE_TAG = 0;
+ public static final int NAMESPACE_TYPE_OTHER = 1;
+
private IASTNode physicalNode = null;
+ private boolean isFullyCached = false;
private CharArrayObjectMap [] bindings = { CharArrayObjectMap.EMPTY_MAP, CharArrayObjectMap.EMPTY_MAP };
@@ -103,17 +115,18 @@ public class CScope implements ICScope {
return (IBinding[]) ArrayUtil.trim( IBinding.class, result );
}
- public void addBinding( IBinding binding ) {
- int type = ( binding instanceof ICompositeType || binding instanceof IEnumeration ) ?
- NAMESPACE_TYPE_TAG : NAMESPACE_TYPE_OTHER;
-
- if( bindings[type] == CharArrayObjectMap.EMPTY_MAP )
- bindings[type] = new CharArrayObjectMap(1);
- bindings[type].put( binding.getNameCharArray(), binding );
- }
+// public void addBinding( IBinding binding ) {
+// int type = ( binding instanceof ICompositeType || binding instanceof IEnumeration ) ?
+// NAMESPACE_TYPE_TAG : NAMESPACE_TYPE_OTHER;
+//
+// if( bindings[type] == CharArrayObjectMap.EMPTY_MAP )
+// bindings[type] = new CharArrayObjectMap(1);
+// bindings[type].put( binding.getNameCharArray(), binding );
+// }
public IBinding getBinding( int namespaceType, char [] name ){
- return (IBinding) bindings[namespaceType].get( name );
+ IASTName n = (IASTName) bindings[namespaceType].get( name );
+ return ( n != null ) ? n.resolveBinding() : null;
}
/* (non-Javadoc)
@@ -126,6 +139,7 @@ public class CScope implements ICScope {
if( bindings[type] != CharArrayObjectMap.EMPTY_MAP ) {
bindings[type].remove( binding.getNameCharArray(), 0, binding.getNameCharArray().length);
}
+ isFullyCached = false;
}
/* (non-Javadoc)
@@ -134,4 +148,63 @@ public class CScope implements ICScope {
public IASTNode getPhysicalNode() {
return physicalNode;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.dom.ast.c.ICScope#addName(org.eclipse.cdt.core.dom.ast.IASTName)
+ */
+ public void addName( IASTName name ) {
+ int type = getNamespaceType( name );
+ if( bindings[type] == CharArrayObjectMap.EMPTY_MAP )
+ bindings[type] = new CharArrayObjectMap(1);
+
+ char [] n = name.toCharArray();
+ IASTName current = (IASTName) bindings[type].get( n );
+ if( current == null || ((CASTName)current).getOffset() > ((CASTName) name).getOffset() ){
+ bindings[type].put( n, name );
+ }
+ }
+
+ private int getNamespaceType( IASTName name ){
+ ASTNodeProperty prop = name.getPropertyInParent();
+ if( prop == IASTCompositeTypeSpecifier.TYPE_NAME ||
+ prop == IASTElaboratedTypeSpecifier.TYPE_NAME ||
+ prop == IASTEnumerationSpecifier.ENUMERATION_NAME )
+ {
+ return NAMESPACE_TYPE_TAG;
+ }
+
+ return NAMESPACE_TYPE_OTHER;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.dom.ast.c.ICScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
+ */
+ public IBinding getBinding( IASTName name, boolean resolve ) {
+ int type = getNamespaceType( name );
+ Object o = bindings[type].get( name.toCharArray() );
+
+ if( o == null )
+ return null;
+
+ if( o instanceof IBinding )
+ return (IBinding) o;
+
+ if( (resolve || ((CASTName)o).hasBinding()) && ( o != name ) )
+ return ((IASTName)o).resolveBinding();
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.dom.ast.c.ICScope#setFullyCached(boolean)
+ */
+ public void setFullyCached( boolean b ){
+ isFullyCached = b;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.dom.ast.c.ICScope#isFullyCached()
+ */
+ public boolean isFullyCached(){
+ return isFullyCached;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java
index a01b5298b65..e29c69fb860 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java
@@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding;
@@ -34,15 +35,16 @@ import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
* @author aniefer
*/
public class CStructure implements ICompositeType, ICInternalBinding {
- private IASTElaboratedTypeSpecifier[] declarations = null;
- private ICASTCompositeTypeSpecifier definition;
+ private IASTName [] declarations = null;
+ private IASTName definition;
- public CStructure( IASTDeclSpecifier declSpec ){
- if( declSpec instanceof IASTCompositeTypeSpecifier )
- definition = (ICASTCompositeTypeSpecifier) declSpec;
+ public CStructure( IASTName name ){
+ if( name.getPropertyInParent() == IASTCompositeTypeSpecifier.TYPE_NAME )
+ definition = name;
else {
- declarations = new IASTElaboratedTypeSpecifier[] { (IASTElaboratedTypeSpecifier) declSpec };
+ declarations = new IASTName[] { name };
}
+ ((CASTName) name).setBinding( this );
}
public IASTNode getPhysicalNode(){
@@ -63,22 +65,22 @@ public class CStructure implements ICompositeType, ICInternalBinding {
*/
public String getName() {
if( definition != null )
- return definition.getName().toString();
+ return definition.toString();
- return declarations[0].getName().toString();
+ return declarations[0].toString();
}
public char[] getNameCharArray() {
if( definition != null )
- return ((CASTName)definition.getName()).toCharArray();
+ return definition.toCharArray();
- return ((CASTName)declarations[0].getName()).toCharArray();
+ return declarations[0].toCharArray();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
public IScope getScope() throws DOMException {
- IASTDeclSpecifier declSpec = (IASTDeclSpecifier) ( ( definition != null ) ? (IASTNode)definition : declarations[0] );
+ IASTDeclSpecifier declSpec = (IASTDeclSpecifier) ( ( definition != null ) ? (IASTNode)definition.getParent() : declarations[0].getParent() );
IScope scope = CVisitor.getContainingScope( declSpec );
while( scope instanceof ICCompositeTypeScope ){
scope = scope.getParent();
@@ -89,32 +91,38 @@ public class CStructure implements ICompositeType, ICInternalBinding {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields()
*/
- public IField[] getFields() {
+ public IField[] getFields() throws DOMException {
if( definition == null ){
- ICASTCompositeTypeSpecifier temp = checkForDefinition( declarations[0] );
+ ICASTCompositeTypeSpecifier temp = checkForDefinition( (IASTElaboratedTypeSpecifier) declarations[0].getParent() );
if( temp == null )
return new IField [] { new CField.CFieldProblem( IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() ) };
- definition = temp;
+ definition = temp.getName();
}
-
- IASTDeclaration[] members = definition.getMembers();
+ ICASTCompositeTypeSpecifier compSpec = (ICASTCompositeTypeSpecifier) definition.getParent();
+ IASTDeclaration[] members = compSpec.getMembers();
int size = members.length;
IField[] fields = new IField[ size ];
if( size > 0 ){
-
+ ICCompositeTypeScope scope = (ICCompositeTypeScope) getCompositeScope();
+ if( scope.isFullyCached() )
+ scope = null;
for( int i = 0; i < size; i++ ){
IASTNode node = members[i];
if( node instanceof IASTSimpleDeclaration ){
IASTDeclarator[] declarators = ((IASTSimpleDeclaration)node).getDeclarators();
for( int j = 0; j < declarators.length; j++ ){
IASTDeclarator declarator = declarators[j];
- IBinding binding = declarator.getName().resolveBinding();
+ IASTName name = declarator.getName();
+ IBinding binding = name.resolveBinding();
+ if( scope != null )
+ scope.addName( name );
if( binding != null )
fields[i] = (IField) binding;
}
}
}
-
+ if( scope != null )
+ scope.setFullyCached( true );
}
return fields;
}
@@ -122,32 +130,48 @@ public class CStructure implements ICompositeType, ICInternalBinding {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(org.eclipse.cdt.core.dom.ast.IASTName)
*/
- public IField findField(String name) {
+ public IField findField(String name) throws DOMException {
if( definition == null ){
- ICASTCompositeTypeSpecifier temp = checkForDefinition( declarations[0] );
+ ICASTCompositeTypeSpecifier temp = checkForDefinition( (IASTElaboratedTypeSpecifier) declarations[0].getParent() );
if( temp == null )
return new CField.CFieldProblem( IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() );
- definition = temp;
+ definition = temp.getName();
+ }
+
+ ICCompositeTypeScope scope = (ICCompositeTypeScope) getCompositeScope();
+ if( scope != null && scope.isFullyCached() ){
+ IBinding binding = scope.getBinding( name.toCharArray() );
+ if( binding instanceof IField )
+ return (IField) binding;
+ } else {
+ ICASTCompositeTypeSpecifier compSpec = (ICASTCompositeTypeSpecifier) definition.getParent();
+ IASTDeclaration[] members = compSpec.getMembers();
+ int size = members.length;
+ if( size > 0 ){
+ IField found = null;
+ for( int i = 0; i < size; i++ ){
+ IASTNode node = members[i];
+ if( node instanceof IASTSimpleDeclaration ){
+ IASTDeclarator[] declarators = ((IASTSimpleDeclaration)node).getDeclarators();
+ for( int j = 0; j < declarators.length; j++ ){
+ IASTDeclarator declarator = declarators[j];
+ IASTName dtorName = declarator.getName();
+ if( scope != null )
+ scope.addName( dtorName );
+ if( name.equals( dtorName.toString() ) ){
+ IBinding binding = dtorName.resolveBinding();
+ if( binding instanceof IField )
+ found = (IField) binding;
+ }
+ }
+ }
+ }
+ if( scope != null )
+ scope.setFullyCached( true );
+ if( found != null )
+ return found;
+ }
}
-
- IASTDeclaration[] members = definition.getMembers();
- int size = members.length;
- if( size > 0 ){
- for( int i = 0; i < size; i++ ){
- IASTNode node = members[i];
- if( node instanceof IASTSimpleDeclaration ){
- IASTDeclarator[] declarators = ((IASTSimpleDeclaration)node).getDeclarators();
- for( int j = 0; j < declarators.length; j++ ){
- IASTDeclarator declarator = declarators[j];
- if( name.equals( declarator.getName().toString() ) ){
- IBinding binding = declarator.getName().resolveBinding();
- if( binding instanceof IField )
- return (IField) binding;
- }
- }
- }
- }
- }
return null;
}
@@ -155,14 +179,15 @@ public class CStructure implements ICompositeType, ICInternalBinding {
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey()
*/
public int getKey() {
- return ( definition != null ) ? definition.getKey() : declarations[0].getKind();
+ return ( definition != null ) ? ((IASTCompositeTypeSpecifier)definition.getParent()).getKey()
+ : ((IASTElaboratedTypeSpecifier)declarations[0].getParent()).getKind();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope()
*/
public IScope getCompositeScope() {
- return (definition != null ) ? definition.getScope() : null;
+ return (definition != null ) ? ((IASTCompositeTypeSpecifier)definition.getParent()).getScope() : null;
}
public Object clone(){
@@ -179,7 +204,7 @@ public class CStructure implements ICompositeType, ICInternalBinding {
* @param compositeTypeSpec
*/
public void addDefinition(ICASTCompositeTypeSpecifier compositeTypeSpec) {
- definition = compositeTypeSpec;
+ definition = compositeTypeSpec.getName();
((CASTName)compositeTypeSpec.getName()).setBinding( this );
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
index 2a9075aabe7..743f3d3974d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
@@ -462,7 +462,7 @@ public class CVisitor {
ICScope scope = (ICScope) getContainingScope( enumeration );
IBinding binding;
try {
- binding = scope.getBinding( ICScope.NAMESPACE_TYPE_TAG, name.toCharArray() );
+ binding = scope.getBinding( name, false );
} catch ( DOMException e ) {
binding = null;
}
@@ -474,7 +474,7 @@ public class CVisitor {
} else {
binding = new CEnumeration( name );
try {
- scope.addBinding( binding );
+ scope.addName( name );
} catch ( DOMException e1 ) {
}
}
@@ -483,7 +483,7 @@ public class CVisitor {
private static IBinding createBinding( IASTEnumerator enumerator ){
IEnumerator binding = new CEnumerator( enumerator );
try {
- ((ICScope)binding.getScope()).addBinding( binding );
+ ((ICScope)binding.getScope()).addName( enumerator.getName() );
} catch ( DOMException e ) {
}
return binding;
@@ -505,9 +505,10 @@ public class CVisitor {
return new CLabel.CLabelProblem( IProblemBinding.SEMANTIC_LABEL_STATEMENT_NOT_FOUND, gotoName );
}
} else if( statement instanceof IASTLabelStatement ){
- IBinding binding = new CLabel( (IASTLabelStatement) statement );
+ IASTName name = ((IASTLabelStatement)statement).getName();
+ IBinding binding = new CLabel( name );
try {
- ((ICFunctionScope) binding.getScope()).addBinding( binding );
+ ((ICFunctionScope) binding.getScope()).addName( name );
} catch ( DOMException e ) {
}
return binding;
@@ -521,21 +522,21 @@ public class CVisitor {
if( parent instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)parent).getDeclarators().length == 0 ){
bits |= CURRENT_SCOPE;
}
-
+ IASTName name = elabTypeSpec.getName();
IBinding binding = resolveBinding( elabTypeSpec, bits );
if( binding != null ){
if( binding instanceof CEnumeration ){
- ((CEnumeration)binding).addDeclaration( elabTypeSpec.getName() );
+ ((CEnumeration)binding).addDeclaration( name );
}
} else {
if( elabTypeSpec.getKind() == IASTElaboratedTypeSpecifier.k_enum ){
- binding = new CEnumeration( elabTypeSpec.getName() );
+ binding = new CEnumeration( name );
} else {
- binding = new CStructure( elabTypeSpec );
+ binding = new CStructure( name );
}
try {
- ((ICScope) binding.getScope()).addBinding( binding );
+ ((ICScope) binding.getScope()).addName( name );
} catch ( DOMException e ) {
}
}
@@ -543,7 +544,11 @@ public class CVisitor {
return binding;
} else if( parent instanceof IASTTypeId || parent instanceof IASTParameterDeclaration ){
IASTNode blockItem = getContainingBlockItem( parent );
- return findBinding( blockItem, elabTypeSpec.getName(), COMPLETE | TAGS );
+ try {
+ return findBinding( blockItem, elabTypeSpec.getName(), COMPLETE | TAGS );
+ } catch ( DOMException e ) {
+ return null;
+ }
}
return null;
}
@@ -647,7 +652,7 @@ public class CVisitor {
ICScope scope = (ICScope) ((IASTCompoundStatement)((IASTFunctionDefinition)declarator.getParent()).getBody()).getScope();
if ( scope != null && binding != null )
try {
- scope.addBinding(binding);
+ scope.addName(name);
} catch ( DOMException e ) {
}
}
@@ -665,7 +670,7 @@ public class CVisitor {
ICScope scope = (ICScope) ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
if ( scope != null && binding != null )
try {
- scope.addBinding(binding);
+ scope.addName(name);
} catch ( DOMException e ) {
}
}
@@ -699,7 +704,7 @@ public class CVisitor {
IBinding binding = null;
try {
- binding = ( scope != null ) ? scope.getBinding( ICScope.NAMESPACE_TYPE_OTHER, declarator.getName().toCharArray() ) : null;
+ binding = ( scope != null ) ? scope.getBinding( declarator.getName(), false ) : null;
} catch ( DOMException e1 ) {
binding = null;
}
@@ -755,7 +760,7 @@ public class CVisitor {
if( scope != null && binding != null )
try {
- scope.addBinding( binding );
+ scope.addName( declarator.getName() );
} catch ( DOMException e ) {
}
return binding;
@@ -765,12 +770,13 @@ public class CVisitor {
private static IBinding createBinding( ICASTCompositeTypeSpecifier compositeTypeSpec ){
ICScope scope = null;
IBinding binding = null;
+ IASTName name = compositeTypeSpec.getName();
try {
scope = (ICScope) getContainingScope( compositeTypeSpec );
while( scope instanceof ICCompositeTypeScope )
scope = (ICScope) scope.getParent();
- binding = scope.getBinding( ICScope.NAMESPACE_TYPE_TAG, compositeTypeSpec.getName().toCharArray() );
+ binding = scope.getBinding( name, false );
if( binding != null ){
((CStructure)binding).addDefinition( compositeTypeSpec );
return binding;
@@ -778,11 +784,11 @@ public class CVisitor {
} catch (DOMException e2) {
}
- binding = new CStructure( compositeTypeSpec );
+ binding = new CStructure( name );
try {
scope = (ICScope) binding.getScope();
- scope.addBinding( binding );
+ scope.addName( name );
} catch ( DOMException e ) {
}
@@ -799,18 +805,18 @@ public class CVisitor {
if( simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){
binding = new CTypeDef( name );
try {
- ((ICScope) binding.getScope()).addBinding( binding );
+ ((ICScope) binding.getScope()).addName( name );
} catch ( DOMException e ) {
}
} else if( simpleDeclaration.getParent() instanceof ICASTCompositeTypeSpecifier ){
binding = new CField( name );
try {
- ((ICScope) binding.getScope()).addBinding( binding );
+ ((ICScope) binding.getScope()).addName( name );
} catch ( DOMException e ) {
}
} else {
CScope scope = (CScope) CVisitor.getContainingScope( simpleDeclaration );
- binding = scope.getBinding( ICScope.NAMESPACE_TYPE_OTHER, name.toCharArray() );
+ binding = scope.getBinding( name, false );
if( binding == null ){
// if the simpleDeclaration is part of a KRC function declarator, then the binding is to a KRC parameter
if ( simpleDeclaration.getParent() instanceof IASTFunctionDeclarator ) {
@@ -823,7 +829,7 @@ public class CVisitor {
binding = new CVariable( name );
}
- scope.addBinding( binding );
+ scope.addName( name );
}
}
@@ -839,19 +845,39 @@ public class CVisitor {
IASTFunctionDeclarator functionDeclartor = functionDef.getDeclarator();
IASTName name = functionDeclartor.getName();
IASTNode blockItem = getContainingBlockItem( node );
- return findBinding( blockItem, name, bits );
+ try {
+ return findBinding( blockItem, name, bits );
+ } catch ( DOMException e ) {
+ return null;
+ }
} else if( node instanceof IASTIdExpression ){
IASTNode blockItem = getContainingBlockItem( node );
- return findBinding( blockItem, ((IASTIdExpression)node).getName(), bits );
+ try {
+ return findBinding( blockItem, ((IASTIdExpression)node).getName(), bits );
+ } catch ( DOMException e ) {
+ return null;
+ }
} else if( node instanceof ICASTTypedefNameSpecifier ){
IASTNode blockItem = getContainingBlockItem( node );
- return findBinding( blockItem, ((ICASTTypedefNameSpecifier)node).getName(), bits );
+ try {
+ return findBinding( blockItem, ((ICASTTypedefNameSpecifier)node).getName(), bits );
+ } catch ( DOMException e ) {
+ return null;
+ }
} else if( node instanceof ICASTElaboratedTypeSpecifier ){
IASTNode blockItem = getContainingBlockItem( node );
- return findBinding( blockItem, ((ICASTElaboratedTypeSpecifier)node).getName(), bits );
+ try {
+ return findBinding( blockItem, ((ICASTElaboratedTypeSpecifier)node).getName(), bits );
+ } catch ( DOMException e ) {
+ return null;
+ }
} else if( node instanceof ICASTCompositeTypeSpecifier ){
IASTNode blockItem = getContainingBlockItem( node );
- return findBinding( blockItem, ((ICASTCompositeTypeSpecifier)node).getName(), bits );
+ try {
+ return findBinding( blockItem, ((ICASTCompositeTypeSpecifier)node).getName(), bits );
+ } catch ( DOMException e ) {
+ return null;
+ }
} else if( node instanceof IASTTypeId ){
IASTTypeId typeId = (IASTTypeId) node;
IASTDeclSpecifier declSpec = typeId.getDeclSpecifier();
@@ -887,7 +913,11 @@ public class CVisitor {
struct = ((IASTCompositeTypeSpecifier)simpleDecl.getDeclSpecifier()).getName().resolveBinding();
if ( struct instanceof CStructure ) {
- return ((CStructure)struct).findField(((ICASTFieldDesignator)node).getName().toString());
+ try {
+ return ((CStructure)struct).findField(((ICASTFieldDesignator)node).getName().toString());
+ } catch ( DOMException e ) {
+ return e.getProblem();
+ }
} else if ( struct instanceof ITypeContainer ) {
IType type;
try {
@@ -901,7 +931,11 @@ public class CVisitor {
if ( type instanceof CStructure )
- return ((CStructure)type).findField(((ICASTFieldDesignator)node).getName().toString());
+ try {
+ return ((CStructure)type).findField(((ICASTFieldDesignator)node).getName().toString());
+ } catch ( DOMException e1 ) {
+ return e1.getProblem();
+ }
}
}
}
@@ -1002,7 +1036,7 @@ public class CVisitor {
return getContainingBlockItem( parent );
}
- protected static IBinding findBinding( IASTNode blockItem, IASTName name, int bits ){
+ protected static IBinding findBinding( IASTNode blockItem, IASTName name, int bits ) throws DOMException{
IBinding binding = null;
while( blockItem != null ){
@@ -1011,8 +1045,18 @@ public class CVisitor {
ICScope scope = null;
if( parent instanceof IASTCompoundStatement ){
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
- nodes = compound.getStatements();
scope = (ICScope) compound.getScope();
+
+ if( parent.getParent() instanceof IASTFunctionDefinition ){
+ IASTFunctionDeclarator dtor = ((IASTFunctionDefinition)parent.getParent()).getDeclarator();
+ if( dtor instanceof IASTStandardFunctionDeclarator )
+ nodes = ((IASTStandardFunctionDeclarator)dtor).getParameters();
+ else if( dtor instanceof ICASTKnRFunctionDeclarator )
+ nodes = ((ICASTKnRFunctionDeclarator)dtor).getParameterDeclarations();
+ }
+ if( nodes == null || nodes.length == 0 ){
+ nodes = compound.getStatements();
+ }
} else if ( parent instanceof IASTTranslationUnit ){
IASTTranslationUnit translation = (IASTTranslationUnit) parent;
nodes = translation.getDeclarations();
@@ -1029,47 +1073,64 @@ public class CVisitor {
boolean typesOnly = (bits & TAGS) != 0;
boolean includeBlockItem = (bits & INCLUDE_BLOCK_ITEM) != 0;
- if( scope != null ){
- int namespaceType = typesOnly ? ICScope.NAMESPACE_TYPE_TAG : ICScope.NAMESPACE_TYPE_OTHER;
+ if( scope != null && scope.isFullyCached() ){
try {
- binding = scope.getBinding( namespaceType, name.toCharArray() );
+ binding = scope.getBinding( name, true );
} catch ( DOMException e ) {
binding = null;
}
if( binding != null )
return binding;
- }
+ } else {
- if( nodes != null ){
- for( int i = 0; i < nodes.length; i++ ){
- IASTNode node = nodes[i];
- if( node == null || ( !includeBlockItem && node == blockItem ) )
- break;
- if( node instanceof IASTDeclarationStatement ){
- IASTDeclarationStatement declStatement = (IASTDeclarationStatement) node;
- binding = checkForBinding( declStatement.getDeclaration(), name, typesOnly );
- } else if( node instanceof IASTDeclaration ){
- binding = checkForBinding( (IASTDeclaration) node, name, typesOnly );
- } else if( node instanceof IASTParameterDeclaration ){
- binding = checkForBinding( (IASTParameterDeclaration) node, name, typesOnly );
- }
- if( binding != null ){
- return binding;
+ IASTName result = null;
+ if( nodes != null ){
+ int idx = -1;
+ IASTNode node = ( nodes != null ? (nodes.length > 0 ? nodes[++idx] : null ) : parent );
+ while( node != null ) {
+ IASTName candidate = null;
+ try {
+ candidate = checkForBinding( scope, node, name, typesOnly );
+ } catch ( DOMException e ) {
+ continue;
+ }
+
+ if( result == null && ( includeBlockItem || (node != blockItem) ) )
+ result = candidate;
+
+ if( idx > -1 && ++idx < nodes.length ){
+ node = nodes[idx];
+ } else {
+ node = null;
+ if( parent instanceof IASTCompoundStatement &&
+ ( nodes[0].getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER ||
+ nodes[0].getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER ) )
+ {
+ //function body, we were looking at parameters, now check the body itself
+ IASTCompoundStatement compound = (IASTCompoundStatement) parent;
+ nodes = compound.getStatements();
+ if( nodes.length > 0 ){
+ idx = 0;
+ node = nodes[0];
+ }
+ }
+ }
}
- if( includeBlockItem && node == blockItem )
- break;
- }
- } else {
- //check the parent
- if( parent instanceof IASTDeclaration ){
- binding = checkForBinding( (IASTDeclaration) parent, name, typesOnly );
- } else if( parent instanceof IASTStatement ){
- binding = checkForBinding( (IASTStatement) parent, name, typesOnly );
+ } else {
+ try {
+ result = checkForBinding( scope, parent, name, typesOnly );
+ } catch ( DOMException e ) {
+ }
}
- if( binding != null ){
- return binding;
+ if( scope != null ) {
+ try {
+ scope.setFullyCached( true );
+ } catch ( DOMException e ) {
+ }
}
+ if( result != null )
+ return result.resolveBinding();
}
if( (bits & CURRENT_SCOPE) == 0 )
blockItem = parent;
@@ -1097,148 +1158,135 @@ public class CVisitor {
//external variable
external = new CExternalVariable( tu, name );
}
- ((CScope)tu.getScope()).addBinding( external );
+ ((CScope)tu.getScope()).addName( name );
}
return external;
}
- private static IBinding checkForBinding( IASTDeclSpecifier declSpec, IASTName name, boolean typesOnly ){
+ private static IASTName checkForBinding( ICScope scope, IASTDeclSpecifier declSpec, IASTName name, boolean typesOnly ) throws DOMException{
IASTName tempName = null;
- if( typesOnly ){
- if( declSpec instanceof ICASTElaboratedTypeSpecifier ){
- tempName = ((ICASTElaboratedTypeSpecifier)declSpec).getName();
- if( CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
- return tempName.resolveBinding();
- }
- } else if( declSpec instanceof ICASTCompositeTypeSpecifier ){
- tempName = ((ICASTCompositeTypeSpecifier)declSpec).getName();
- if( CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
- return tempName.resolveBinding();
- }
- //also have to check for any nested structs
- IASTDeclaration [] nested = ((ICASTCompositeTypeSpecifier)declSpec).getMembers();
- for( int i = 0; i < nested.length; i++ ){
- if( nested[i] instanceof IASTSimpleDeclaration ){
- IASTDeclSpecifier d = ((IASTSimpleDeclaration)nested[i]).getDeclSpecifier();
- if( d instanceof ICASTCompositeTypeSpecifier ) {
- IBinding temp = checkForBinding( d, name, typesOnly );
- if( temp != null )
- return temp;
- }
+
+ if( declSpec instanceof ICASTElaboratedTypeSpecifier ){
+ tempName = ((ICASTElaboratedTypeSpecifier)declSpec).getName();
+ if( scope != null )
+ scope.addName( tempName );
+ if( typesOnly && CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
+ return tempName;
+ }
+ } else if( declSpec instanceof ICASTCompositeTypeSpecifier ){
+ tempName = ((ICASTCompositeTypeSpecifier)declSpec).getName();
+ if( scope != null )
+ scope.addName( tempName );
+ if( typesOnly && CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
+ return tempName;
+ }
+ //also have to check for any nested structs
+ IASTDeclaration [] nested = ((ICASTCompositeTypeSpecifier)declSpec).getMembers();
+ for( int i = 0; i < nested.length; i++ ){
+ if( nested[i] instanceof IASTSimpleDeclaration ){
+ IASTDeclSpecifier d = ((IASTSimpleDeclaration)nested[i]).getDeclSpecifier();
+ if( d instanceof ICASTCompositeTypeSpecifier ) {
+ IASTName temp = checkForBinding( scope, d, name, typesOnly );
+ if( temp != null )
+ return temp;
}
}
- } else if( declSpec instanceof ICASTEnumerationSpecifier ){
- ICASTEnumerationSpecifier enumeration = (ICASTEnumerationSpecifier) declSpec;
- tempName = enumeration.getName();
- if( CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
- return tempName.resolveBinding();
- }
}
- } else {
- if( declSpec instanceof ICASTEnumerationSpecifier ) {
- //check enumerators
- IASTEnumerator [] list = ((ICASTEnumerationSpecifier) declSpec).getEnumerators();
- for( int i = 0; i < list.length; i++ ) {
- IASTEnumerator enumerator = list[i];
- if( enumerator == null ) break;
- tempName = enumerator.getName();
- if( CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
- return tempName.resolveBinding();
- }
- }
+ } else if( declSpec instanceof ICASTEnumerationSpecifier ){
+ ICASTEnumerationSpecifier enumeration = (ICASTEnumerationSpecifier) declSpec;
+ tempName = enumeration.getName();
+ if( scope != null )
+ scope.addName( tempName );
+ if( typesOnly && CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
+ return tempName;
}
+ //check enumerators
+ IASTEnumerator [] list = ((ICASTEnumerationSpecifier) declSpec).getEnumerators();
+ for( int i = 0; i < list.length; i++ ) {
+ IASTEnumerator enumerator = list[i];
+ if( enumerator == null ) break;
+ tempName = enumerator.getName();
+ if( scope != null )
+ scope.addName( tempName );
+ if( !typesOnly && CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
+ return tempName;
+ }
+ }
}
return null;
}
- private static IBinding checkForBinding( IASTParameterDeclaration paramDecl, IASTName name, boolean typesOnly ){
+
+ private static IASTName checkForBinding( ICScope scope, IASTParameterDeclaration paramDecl, IASTName name, boolean typesOnly ) throws DOMException{
if( paramDecl == null ) return null;
- if( typesOnly ){
- return checkForBinding( paramDecl.getDeclSpecifier(), name, typesOnly );
- }
-
- IASTDeclarator dtor = paramDecl.getDeclarator();
+ IASTDeclarator dtor = paramDecl.getDeclarator();
while( dtor.getNestedDeclarator() != null ){
dtor = dtor.getNestedDeclarator();
}
- IASTName declName = dtor.getName();
- if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
- return declName.resolveBinding();
+ IASTName tempName = dtor.getName();
+ if( scope != null )
+ scope.addName( tempName );
+ if( !typesOnly && CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
+ return tempName;
}
+
+ if( typesOnly ){
+ return checkForBinding( scope, paramDecl.getDeclSpecifier(), name, typesOnly );
+ }
return null;
}
- private static IBinding checkForBinding( IASTDeclaration declaration, IASTName name, boolean typesOnly ){
+ private static IASTName checkForBinding( ICScope scope, IASTNode node, IASTName name, boolean typesOnly ) throws DOMException{
+ if( node instanceof IASTDeclaration ){
+ return checkForBinding( scope, (IASTDeclaration) node, name, typesOnly );
+ } else if( node instanceof IASTParameterDeclaration ){
+ return checkForBinding( scope, (IASTParameterDeclaration) node, name, typesOnly );
+ } else if( node instanceof IASTDeclarationStatement ){
+ return checkForBinding( scope, ((IASTDeclarationStatement)node).getDeclaration(), name, typesOnly );
+ } else if( node instanceof IASTForStatement ){
+ IASTForStatement forStatement = (IASTForStatement) node;
+ if( forStatement.getInitDeclaration() != null ){
+ return checkForBinding( scope, forStatement.getInitDeclaration(), name, typesOnly );
+ }
+ }
+ return null;
+ }
+ private static IASTName checkForBinding( ICScope scope, IASTDeclaration declaration, IASTName name, boolean typesOnly ) throws DOMException{
IASTName tempName = null;
if( declaration instanceof IASTSimpleDeclaration ){
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration;
-
- if( !typesOnly ){
- IASTDeclarator [] declarators = simpleDeclaration.getDeclarators();
- for( int i = 0; i < declarators.length; i++ ){
- IASTDeclarator declarator = declarators[i];
- while( declarator.getNestedDeclarator() != null ){
- declarator = declarator.getNestedDeclarator();
- }
- tempName = declarator.getName();
- if( CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
- return tempName.resolveBinding();
- }
+ IASTDeclarator [] declarators = simpleDeclaration.getDeclarators();
+ for( int i = 0; i < declarators.length; i++ ){
+ IASTDeclarator declarator = declarators[i];
+ while( declarator.getNestedDeclarator() != null ){
+ declarator = declarator.getNestedDeclarator();
+ }
+ tempName = declarator.getName();
+ if( scope != null )
+ scope.addName( tempName );
+
+ if( !typesOnly && CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
+ return tempName;
}
}
- return checkForBinding( simpleDeclaration.getDeclSpecifier(), name, typesOnly );
+ tempName = checkForBinding( scope, simpleDeclaration.getDeclSpecifier(), name, typesOnly );
+ if( tempName != null ){
+ return tempName;
+ }
} else if( !typesOnly && declaration instanceof IASTFunctionDefinition ){
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
-
- if (functionDef.getDeclarator() instanceof IASTStandardFunctionDeclarator) {
- CASTFunctionDeclarator declarator = (CASTFunctionDeclarator) functionDef.getDeclarator();
-
- //check the function itself
- IASTName declName = declarator.getName();
- if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
- return declName.resolveBinding();
- }
- //check the parameters
- IASTParameterDeclaration [] parameters = declarator.getParameters();
- for( int i = 0; i < parameters.length; i++ ){
- IBinding binding = checkForBinding( parameters[i], name, typesOnly );
- if( binding != null ){
- return binding;
- }
- }
- } else if (functionDef.getDeclarator() instanceof ICASTKnRFunctionDeclarator) {
- CASTKnRFunctionDeclarator declarator = (CASTKnRFunctionDeclarator) functionDef.getDeclarator();
-
- //check the function itself
- IASTName declName = declarator.getName();
- if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
- return declName.resolveBinding();
- }
- //check the parameters
- IASTDeclaration [] parameters = declarator.getParameterDeclarations();
- for( int i = 0; i < parameters.length; i++ ){
- IASTDeclaration parameterDeclaration = parameters[i];
- if( parameterDeclaration == null || !(parameters[i] instanceof IASTSimpleDeclaration)) break;
- IASTDeclarator[] parmDecltors = ((IASTSimpleDeclaration)parameters[i]).getDeclarators();
- for (int j=0; j<parmDecltors.length; j++) {
- declName = parmDecltors[j].getName();
- if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
- return declName.resolveBinding();
- }
- }
- }
+
+ IASTDeclarator dtor = functionDef.getDeclarator();
+ tempName = dtor.getName();
+ if( scope != null )
+ scope.addName( tempName );
+ if( !typesOnly && CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
+ return tempName;
}
- }
- return null;
- }
-
- private static IBinding checkForBinding( IASTStatement statement, IASTName name, boolean typesOnly ){
- if( statement instanceof IASTDeclarationStatement ){
- return checkForBinding( ((IASTDeclarationStatement)statement).getDeclaration(), name, typesOnly );
- } else if( statement instanceof IASTForStatement ){
- IASTForStatement forStatement = (IASTForStatement) statement;
- if( forStatement.getInitDeclaration() != null ){
- return checkForBinding( forStatement.getInitDeclaration(), name, typesOnly );
+
+ tempName = checkForBinding( scope, functionDef.getDeclSpecifier(), name, typesOnly );
+ if( tempName != null ){
+ return tempName;
}
}
return null;
@@ -1319,352 +1367,6 @@ public class CVisitor {
tu.accept( new ClearBindingAction() );
}
-// public CVisitor( IASTTranslationUnit tu ) {
-// this.tu = tu;
-// }
-
-// public void visitTranslationUnit( ASTVisitor action ){
-// IASTDeclaration[] decls = tu.getDeclarations();
-// for( int i = 0; i < decls.length; i++ ){
-// if( !visitDeclaration( decls[i], action ) ) return;
-// }
-// }
-//
-// public boolean visitName( IASTName name, ASTVisitor action ){
-// if( action.processNames ) {
-// switch( action.processName( name ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-// return true;
-// }
-//
-// public boolean visitDeclaration( IASTDeclaration declaration, ASTVisitor action ){
-// if( action.processDeclarations ) {
-// switch( action.processDeclaration( declaration ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-//
-// if( declaration instanceof IASTSimpleDeclaration ){
-// IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declaration;
-// if( !visitDeclSpecifier( simpleDecl.getDeclSpecifier(), action ) ) return false;
-// IASTDeclarator [] list = simpleDecl.getDeclarators();
-// for( int i = 0; list != null && i < list.length; i++ ){
-// if( !visitDeclarator( list[i], action ) ) return false;
-// }
-// } else if( declaration instanceof IASTFunctionDefinition ){
-// IASTFunctionDefinition fnDef = (IASTFunctionDefinition) declaration;
-// if( !visitDeclSpecifier( fnDef.getDeclSpecifier(), action ) ) return false;
-// if( !visitDeclarator( fnDef.getDeclarator(), action ) ) return false;
-// if( !visitStatement( fnDef.getBody(), action ) ) return false;
-// }
-// return true;
-// }
-// public boolean visitDeclarator( IASTDeclarator declarator, ASTVisitor action ){
-// if( action.processDeclarators ){
-// switch( action.processDeclarator( declarator ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-//
-// //having a nested declarator implies that the name on this declarator is empty
-// if( declarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR &&
-// declarator.getNestedDeclarator() == null )
-// {
-// if( !visitName( declarator.getName(), action ) ) return false;
-// }
-//
-// if( declarator.getNestedDeclarator() != null )
-// if( !visitDeclarator( declarator.getNestedDeclarator(), action ) ) return false;
-//
-// if( declarator.getInitializer() != null )
-// if( !visitInitializer( declarator.getInitializer(), action ) ) return false;
-//
-// if( declarator instanceof IASTStandardFunctionDeclarator ){
-// IASTParameterDeclaration [] list = ((IASTStandardFunctionDeclarator)declarator).getParameters();
-// for( int i = 0; i < list.length; i++ ){
-// if( !visitParameterDeclaration( list[i], action ) ) return false;
-// }
-// } else if ( declarator instanceof ICASTKnRFunctionDeclarator ) {
-// ICASTKnRFunctionDeclarator knr = (ICASTKnRFunctionDeclarator) declarator;
-// IASTName [] names = knr.getParameterNames();
-// for( int i = 0; i < names.length; i++ ){
-// if( !visitName( names[i], action ) ) return false;
-// }
-//
-// IASTDeclaration[] parmDeclarations = knr.getParameterDeclarations();
-// for( int i = 0; i < parmDeclarations.length; i++ ){
-// if( !visitDeclaration( parmDeclarations[i], action ) ) return false;
-// }
-// }
-// else if( declarator instanceof IASTArrayDeclarator )
-// {
-// IASTArrayDeclarator arrayDecl = (IASTArrayDeclarator) declarator;
-// IASTArrayModifier [] mods = arrayDecl.getArrayModifiers();
-// for( int i = 0; i < mods.length; ++i )
-// if( mods[i].getConstantExpression() != null &&
-// !visitExpression( mods[i].getConstantExpression(), action ) ) return false;
-// }
-// else if( declarator instanceof IASTFieldDeclarator )
-// if( ! visitExpression( ((IASTFieldDeclarator) declarator).getBitFieldSize(), action ) ) return false;
-//
-// return true;
-// }
-//
-// public boolean visitInitializer( IASTInitializer initializer, ASTVisitor action ){
-// if( initializer == null )
-// return true;
-//
-// if( action.processInitializers ){
-// switch( action.processInitializer( initializer ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-//
-// if( initializer instanceof IASTInitializerExpression ){
-// if( !visitExpression( ((IASTInitializerExpression) initializer).getExpression(), action ) ) return false;
-// } else if( initializer instanceof IASTInitializerList ){
-// IASTInitializer [] list = ((IASTInitializerList) initializer).getInitializers();
-// for( int i = 0; i < list.length; i++ ){
-// if( !visitInitializer( list[i], action ) ) return false;
-// }
-// } else if( initializer instanceof ICASTDesignatedInitializer ){
-// ICASTDesignatedInitializer dinit = (ICASTDesignatedInitializer) initializer;
-// ICASTDesignator [] ds = dinit.getDesignators();
-// for( int i = 0; i < ds.length; i++ ){
-// if( !visitDesignator( ds[i], action ) ) return false;
-// }
-// if( !visitInitializer( dinit.getOperandInitializer(), action ) ) return false;
-// }
-// return true;
-// }
-// public boolean visitDesignator( ICASTDesignator designator, ASTVisitor action ){
-// if( action instanceof CASTVisitor && ((CASTVisitor)action).processDesignators ){
-// switch( ((CASTVisitor)action).processDesignator( designator ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-// if( designator instanceof ICASTFieldDesignator ){
-// if( !visitName( ((ICASTFieldDesignator)designator).getName(), action ) ) return false;
-// } else if( designator instanceof ICASTArrayDesignator ){
-// if( !visitExpression( ((ICASTArrayDesignator)designator).getSubscriptExpression(), action ) ) return false;
-// } else if( designator instanceof IGCCASTArrayRangeDesignator ){
-// if( !visitExpression( ((IGCCASTArrayRangeDesignator)designator).getRangeFloor(), action ) ) return false;
-// if( !visitExpression( ((IGCCASTArrayRangeDesignator)designator).getRangeCeiling(), action ) ) return false;
-// }
-// return true;
-// }
-// public boolean visitParameterDeclaration( IASTParameterDeclaration parameterDeclaration, ASTVisitor action ){
-// if( action.processParameterDeclarations ){
-// switch( action.processParameterDeclaration( parameterDeclaration ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-//
-// if( !visitDeclSpecifier( parameterDeclaration.getDeclSpecifier(), action ) ) return false;
-// if( !visitDeclarator( parameterDeclaration.getDeclarator(), action ) ) return false;
-// return true;
-// }
-//
-// public boolean visitDeclSpecifier( IASTDeclSpecifier declSpec, ASTVisitor action ){
-// if( action.processDeclSpecifiers ){
-// switch( action.processDeclSpecifier( declSpec ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-//
-// if( declSpec instanceof ICASTCompositeTypeSpecifier ){
-// ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) declSpec;
-// if( !visitName( compTypeSpec.getName(), action ) ) return false;
-//
-// IASTDeclaration [] list = compTypeSpec.getMembers();
-// for( int i = 0; i < list.length; i++ ){
-// if( !visitDeclaration( list[i], action ) ) return false;
-// }
-// } else if( declSpec instanceof ICASTElaboratedTypeSpecifier ){
-// if( !visitName( ((ICASTElaboratedTypeSpecifier) declSpec).getName(), action ) ) return false;
-// } else if( declSpec instanceof ICASTTypedefNameSpecifier ){
-// if( !visitName( ((ICASTTypedefNameSpecifier) declSpec).getName(), action ) ) return false;
-// } else if( declSpec instanceof ICASTEnumerationSpecifier ){
-// ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) declSpec;
-// if( !visitName( enumSpec.getName(), action ) ) return false;
-// IASTEnumerator [] list = enumSpec.getEnumerators();
-// for( int i = 0; i < list.length; i++ ){
-// if( !visitEnumerator( list[i], action ) ) return false;
-// }
-// }
-// return true;
-// }
-// public boolean visitEnumerator( IASTEnumerator enumerator, ASTVisitor action ){
-// if( action.processEnumerators ){
-// switch( action.processEnumerator( enumerator ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-//
-// if( !visitName( enumerator.getName(), action ) ) return false;
-// if( enumerator.getValue() != null )
-// if( !visitExpression( enumerator.getValue(), action ) ) return false;
-// return true;
-// }
-//
-// private boolean visitIfStatement( IASTIfStatement ifStatement, ASTVisitor action ){
-// while( ifStatement != null ){
-// if( action.processStatements ){
-// switch( action.processStatement( ifStatement ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-// if( !visitExpression( ifStatement.getCondition(), action ) ) return false;
-// if( !visitStatement( ifStatement.getThenClause(), action ) ) return false;
-// if( ifStatement.getElseClause() != null ){
-// IASTStatement statement = ifStatement.getElseClause();
-// if( statement instanceof IASTIfStatement ){
-// ifStatement = (IASTIfStatement) statement;
-// continue;
-// }
-// if( !visitStatement( statement, action ) ) return false;
-// }
-// ifStatement = null;
-// }
-// return true;
-// }
-// public boolean visitStatement( IASTStatement statement, ASTVisitor action ){
-// //handle if's in a non-recursive manner to avoid stack overflows in case of huge number of elses
-// if( statement instanceof IASTIfStatement )
-// return visitIfStatement( (IASTIfStatement) statement, action );
-//
-// if( action.processStatements ){
-// switch( action.processStatement( statement ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-//
-// if( statement instanceof IASTCompoundStatement ){
-// IASTStatement [] list = ((IASTCompoundStatement) statement).getStatements();
-// for( int i = 0; i < list.length; i++ ){
-// if( list[i] == null ) break;
-// if( !visitStatement( list[i], action ) ) return false;
-// }
-// } else if( statement instanceof IASTDeclarationStatement ){
-// if( !visitDeclaration( ((IASTDeclarationStatement)statement).getDeclaration(), action ) ) return false;
-// } else if( statement instanceof IASTExpressionStatement ){
-// if( ((IASTExpressionStatement)statement).getExpression() != null && !visitExpression( ((IASTExpressionStatement)statement).getExpression(), action ) ) return false;
-// } else if( statement instanceof IASTCaseStatement ){
-// if( !visitExpression( ((IASTCaseStatement)statement).getExpression(), action ) ) return false;
-// } else if( statement instanceof IASTDoStatement ){
-// if( !visitStatement( ((IASTDoStatement)statement).getBody(), action ) ) return false;
-// if( !visitExpression( ((IASTDoStatement)statement).getCondition(), action ) ) return false;
-// } else if( statement instanceof IASTGotoStatement ){
-// if( !visitName( ((IASTGotoStatement)statement).getName(), action ) ) return false;
-// } else if( statement instanceof IASTLabelStatement ){
-// if( !visitName( ((IASTLabelStatement)statement).getName(), action ) ) return false;
-// } else if( statement instanceof IASTReturnStatement ){
-// if( ((IASTReturnStatement) statement ).getReturnValue() != null )
-// if( !visitExpression( ((IASTReturnStatement) statement ).getReturnValue(), action ) ) return false;
-// } else if( statement instanceof IASTSwitchStatement ){
-// if( !visitExpression( ((IASTSwitchStatement) statement ).getController(), action ) ) return false;
-// if( !visitStatement( ((IASTSwitchStatement) statement ).getBody(), action ) ) return false;
-// } else if( statement instanceof IASTWhileStatement ){
-// if( !visitExpression( ((IASTWhileStatement) statement ).getCondition(), action ) ) return false;
-// if( !visitStatement( ((IASTWhileStatement) statement ).getBody(), action ) ) return false;
-// } else if( statement instanceof IASTForStatement ){
-// IASTForStatement s = (IASTForStatement) statement;
-// if( s.getInitDeclaration() != null )
-// if( !visitDeclaration( s.getInitDeclaration(), action ) ) return false;
-// if( s.getInitExpression() != null )
-// if( !visitExpression( s.getInitExpression(), action ) ) return false;
-// if( !visitExpression( s.getCondition(), action ) ) return false;
-// if( !visitExpression( s.getIterationExpression(), action ) ) return false;
-// if( !visitStatement( s.getBody(), action ) ) return false;
-// }
-// return true;
-// }
-// public boolean visitTypeId( IASTTypeId typeId, ASTVisitor action ){
-// if( action.processTypeIds ){
-// switch( action.processTypeId( typeId ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-//
-// if( !visitDeclarator( typeId.getAbstractDeclarator(), action ) ) return false;
-// if( !visitDeclSpecifier( typeId.getDeclSpecifier(), action ) ) return false;
-// return true;
-// }
-// public boolean visitExpression( IASTExpression expression, ASTVisitor action ){
-// if (expression == null) return true;
-//
-// if( action.processExpressions ){
-// switch( action.processExpression( expression ) ){
-// case ASTVisitor.PROCESS_ABORT : return false;
-// case ASTVisitor.PROCESS_SKIP : return true;
-// default : break;
-// }
-// }
-//
-// if( expression instanceof IASTArraySubscriptExpression ){
-// if( !visitExpression( ((IASTArraySubscriptExpression)expression).getArrayExpression(), action ) ) return false;
-// if( !visitExpression( ((IASTArraySubscriptExpression)expression).getSubscriptExpression(), action ) ) return false;
-// } else if( expression instanceof IASTBinaryExpression ){
-// if( !visitExpression( ((IASTBinaryExpression)expression).getOperand1(), action ) ) return false;
-// if( !visitExpression( ((IASTBinaryExpression)expression).getOperand2(), action ) ) return false;
-// } else if( expression instanceof IASTConditionalExpression){
-// if( !visitExpression( ((IASTConditionalExpression)expression).getLogicalConditionExpression(), action ) ) return false;
-// if( !visitExpression( ((IASTConditionalExpression)expression).getNegativeResultExpression(), action ) ) return false;
-// if( !visitExpression( ((IASTConditionalExpression)expression).getPositiveResultExpression(), action ) ) return false;
-// } else if( expression instanceof IASTExpressionList ){
-// IASTExpression[] list = ((IASTExpressionList)expression).getExpressions();
-// for( int i = 0; i < list.length; i++){
-// if( list[i] == null ) break;
-// if( !visitExpression( list[i], action ) ) return false;
-// }
-// } else if( expression instanceof IASTFieldReference ){
-// if( !visitExpression( ((IASTFieldReference)expression).getFieldOwner(), action ) ) return false;
-// if( !visitName( ((IASTFieldReference)expression).getFieldName(), action ) ) return false;
-// } else if( expression instanceof IASTFunctionCallExpression ){
-// if( !visitExpression( ((IASTFunctionCallExpression)expression).getFunctionNameExpression(), action ) ) return false;
-// if( ((IASTFunctionCallExpression)expression).getParameterExpression() != null && !visitExpression( ((IASTFunctionCallExpression)expression).getParameterExpression(), action ) ) return false;
-// } else if( expression instanceof IASTIdExpression ){
-// if( !visitName( ((IASTIdExpression)expression).getName(), action ) ) return false;
-// } else if( expression instanceof IASTTypeIdExpression ){
-// if( !visitTypeId( ((IASTTypeIdExpression)expression).getTypeId(), action ) ) return false;
-// } else if( expression instanceof IASTCastExpression ){
-// if( !visitTypeId( ((IASTCastExpression)expression).getTypeId(), action ) ) return false;
-// if( !visitExpression( ((IASTCastExpression)expression).getOperand(), action ) ) return false;
-// } else if( expression instanceof IASTUnaryExpression ){
-// if( !visitExpression( ((IASTUnaryExpression)expression).getOperand(), action ) ) return false;
-// } else if( expression instanceof ICASTTypeIdInitializerExpression ){
-// if( !visitTypeId( ((ICASTTypeIdInitializerExpression)expression).getTypeId(), action ) ) return false;
-// if( !visitInitializer( ((ICASTTypeIdInitializerExpression)expression).getInitializer(), action ) ) return false;
-// } else if( expression instanceof IGNUASTCompoundStatementExpression ){
-// if( !visitStatement( ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement(), action ) ) return false;
-// }
-// return true;
-// }
-
/**
* Create an IType for an IASTDeclarator.
*
@@ -1930,8 +1632,9 @@ public class CVisitor {
* @param startingPoint
* @param name
* @return
+ * @throws DOMException
*/
- public static IBinding findTypeBinding(IASTNode startingPoint, IASTName name) {
+ public static IBinding findTypeBinding(IASTNode startingPoint, IASTName name) throws DOMException {
if( startingPoint instanceof IASTTranslationUnit )
{
IASTDeclaration [] declarations = ((IASTTranslationUnit)startingPoint).getDeclarations();
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java
index 5c573833c6b..5bd0097bf95 100644
--- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java
@@ -110,6 +110,7 @@ import org.eclipse.ui.views.properties.PropertySheet;
*/
public class DOMAST extends ViewPart {
+ private static final String PROPERTIES_VIEW = "org.eclipse.ui.views.PropertySheet"; //$NON-NLS-1$
private static final String ASTUTIL_MENU_LABEL = "ASTUtil#"; //$NON-NLS-1$
private static final String DISPLAY_TYPE = "getNodeType(IASTNode)"; //$NON-NLS-1$
private static final String DISPLAY_SIGNATURE = "getNodeSignature(IASTNode)"; //$NON-NLS-1$
@@ -651,6 +652,20 @@ public class DOMAST extends ViewPart {
customFiltersActionGroup = new CustomFiltersActionGroup(DOMAST_FILTER_GROUP_ID, viewer);
contributeToActionBars();
+
+ viewer.addSelectionChangedListener(new UpdatePropertiesListener());
+ }
+
+ private class UpdatePropertiesListener implements ISelectionChangedListener {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ ISelection selection = viewer.getSelection();
+ IViewPart propertyPart = getSite().getPage().findView(PROPERTIES_VIEW);
+ if (propertyPart instanceof PropertySheet) {
+ ((PropertySheet)propertyPart).selectionChanged(getSite().getPart(), selection);
+ }
+ }
+
}
public void setContentProvider(ViewContentProvider vcp) {
@@ -931,7 +946,6 @@ public class DOMAST extends ViewPart {
}
private class ASTHighlighterAction extends Action {
- private static final String PROPERTIES_VIEW = "org.eclipse.ui.views.PropertySheet"; //$NON-NLS-1$
IEditorPart aPart = null;
public ASTHighlighterAction(IEditorPart part) {
@@ -990,11 +1004,6 @@ public class DOMAST extends ViewPart {
((TreeObject) obj).getLength());
aPart.getSite().getPage().activate(aPart.getSite().getPage().findView(OpenDOMViewAction.VIEW_ID));
-
- IViewPart part = getSite().getPage().findView(PROPERTIES_VIEW);
- if (part instanceof PropertySheet) {
- ((PropertySheet)part).selectionChanged(getSite().getPart(), selection);
- }
}
}
}
@@ -1093,6 +1102,12 @@ public class DOMAST extends ViewPart {
*/
public void setFocus() {
viewer.getControl().setFocus();
+
+ ISelection selection = viewer.getSelection();
+ IViewPart propertyPart = getSite().getPage().findView(PROPERTIES_VIEW);
+ if (propertyPart instanceof PropertySheet) {
+ ((PropertySheet)propertyPart).selectionChanged(getSite().getPart(), selection);
+ }
}
public void setPart(IEditorPart part) {
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeObject.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeObject.java
index 17667a467a5..d40d9c30029 100644
--- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeObject.java
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeObject.java
@@ -10,9 +10,12 @@
**********************************************************************/
package org.eclipse.cdt.ui.tests.DOMAST;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
+import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
@@ -34,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
@@ -67,7 +71,7 @@ public class TreeObject implements IAdaptable {
private static final String IAST_PREFIX = "IAST"; //$NON-NLS-1$
private static final String START_OF_LIST = ": "; //$NON-NLS-1$
private static final String LIST_SEPARATOR = ", "; //$NON-NLS-1$
- private static final String FILENAME_SEPARATOR = "."; //$NON-NLS-1$
+ private static final String PERIOD = "."; //$NON-NLS-1$
private IASTNode node = null;
private TreeParent parent;
@@ -109,10 +113,10 @@ public class TreeObject implements IAdaptable {
Class[] classes = node.getClass().getInterfaces();
for(int i=0; i<classes.length; i++) {
- String interfaceName = classes[i].getName().substring(classes[i].getName().lastIndexOf(FILENAME_SEPARATOR) + 1);
+ String interfaceName = classes[i].getName().substring(classes[i].getName().lastIndexOf(PERIOD) + 1);
if (hasProperPrefix(interfaceName)) {
buffer.append(interfaceName);
- if (i+1 < classes.length && hasProperPrefix(classes[i+1].getName().substring(classes[i+1].getName().lastIndexOf(FILENAME_SEPARATOR) + 1)))
+ if (i+1 < classes.length && hasProperPrefix(classes[i+1].getName().substring(classes[i+1].getName().lastIndexOf(PERIOD) + 1)))
buffer.append(LIST_SEPARATOR);
}
}
@@ -306,6 +310,15 @@ public class TreeObject implements IAdaptable {
private class ASTPropertySource implements IPropertySource {
+ private static final String L_BRACKET_STRING = "["; //$NON-NLS-1$
+ private static final String R_BRACKET_STRING = "]"; //$NON-NLS-1$
+ private static final String CLONE_METHOD_NAME = "clone"; //$NON-NLS-1$
+ private static final String NO_ELEMENT_STRING = "[0]"; //$NON-NLS-1$
+ private static final String SEMI = ";"; //$NON-NLS-1$
+ private static final String GETTYPE_METHOD_NAME = "getType"; //$NON-NLS-1$
+ private static final String EXCEPTION_ON = " on "; //$NON-NLS-1$
+ private static final String NULL_STRING = "null"; //$NON-NLS-1$
+ private static final String OBJECT_SEPARATOR = ", "; //$NON-NLS-1$
private static final String COLON_SEPARATOR = ": "; //$NON-NLS-1$
private static final String IBINDING_TAG = "IBinding: "; //$NON-NLS-1$
private static final String EMPTY_PARAMETER = "()"; //$NON-NLS-1$
@@ -352,7 +365,7 @@ public class TreeObject implements IAdaptable {
for(int i=0; i<interfaces.length; i++) {
Method[] methods = interfaces[i].getMethods();
for(int j=0; j<methods.length; j++) {
- if (methods[j].getParameterTypes().length > 0) continue; // only do getters
+ if (methods[j].getParameterTypes().length > 0 || (!shouldInvokeMethod(methods[j].getName()))) continue; // only do getters, that aren't in the bad list (like clone())
TextPropertyDescriptor text = null;
if (obj instanceof IBinding)
@@ -362,9 +375,9 @@ public class TreeObject implements IAdaptable {
if (text != null) {
if (obj instanceof IBinding)
- text.setCategory(IBINDING_TAG + ((IASTName)node).resolveBinding().getClass().getName().substring(((IASTName)node).resolveBinding().getClass().getName().lastIndexOf(FILENAME_SEPARATOR) + 1) + COLON_SEPARATOR + ((IASTName)node).resolveBinding().toString());
+ text.setCategory(IBINDING_TAG + ((IASTName)node).resolveBinding().getClass().getName().substring(((IASTName)node).resolveBinding().getClass().getName().lastIndexOf(PERIOD) + 1) + COLON_SEPARATOR + getValueString(((IASTName)node).resolveBinding()));
else
- text.setCategory(objClass.getName().substring(objClass.getName().lastIndexOf(FILENAME_SEPARATOR) + 1) + COLON_SEPARATOR + node.toString());
+ text.setCategory(objClass.getName().substring(objClass.getName().lastIndexOf(PERIOD) + 1) + COLON_SEPARATOR + getValueString(node));
desc = (IPropertyDescriptor[])ArrayUtil.append(IPropertyDescriptor.class, desc, text);
}
}
@@ -395,15 +408,127 @@ public class TreeObject implements IAdaptable {
result = method.invoke(node, null);
}
- if (result != null)
- value = result.toString();
+ if (result == null) {
+ value = NULL_STRING;
+ } else if (result.getClass().isArray()) { // if it's an array
+ if (result.getClass().getComponentType().equals(char.class)) // array of char
+ value = String.valueOf((char[])result);
+ else if (result.getClass().isPrimitive()) {
+ value = trimObjectToString(result.toString());
+ } else
+ value = getValueString((Object[])result);
+ } else {
+ value = getValueString(result);
+ }
} catch (Exception e) {
e.printStackTrace(); // display all exceptions to developers
+
+ if (e instanceof InvocationTargetException)
+ return trimObjectToString(((InvocationTargetException)e).getTargetException().toString()) + EXCEPTION_ON + ((InvocationTargetException)e).getTargetException().getStackTrace()[0].toString();
+
return e.toString();
}
return value;
}
+
+ private String trimObjectToString(String str) {
+ return str.substring(str.lastIndexOf(PERIOD) + 1);
+ }
+
+ private String getValueString(Object obj) {
+ StringBuffer buffer = new StringBuffer();
+
+ if (obj.getClass().isPrimitive()) {
+ buffer.append(trimObjectToString(obj.toString()));
+ } else if (obj instanceof ASTNodeProperty) {
+ buffer.append(((ASTNodeProperty)obj).getName());
+ } else if (obj instanceof IASTName) {
+ buffer.append( trimObjectToString(((IASTName)obj).toString()) );
+ buffer.append(COLON_SEPARATOR);
+ buffer.append( getType(((IASTName)obj).resolveBinding()) );
+ } else if (obj instanceof IType) {
+ buffer.append(getType(obj));
+ } else if (obj instanceof IBinding) {
+ buffer.append(((IBinding)obj).getName());
+ buffer.append(COLON_SEPARATOR);
+ buffer.append(getType(obj));
+ } else if (obj instanceof IASTExpression) {
+ buffer.append(ASTSignatureUtil.getExpressionString((IASTExpression)obj));
+ } else if (obj instanceof IASTNode) {
+ String utilString = ASTSignatureUtil.getNodeSignature((IASTNode)obj);
+ if (utilString != null && !utilString.equals(BLANK_STRING)) {
+ buffer.append(trimObjectToString(obj.toString()));
+ buffer.append(COLON_SEPARATOR);
+ buffer.append(utilString);
+ }
+ else
+ buffer.append(trimObjectToString(obj.toString()));
+ } else
+ buffer.append(trimObjectToString(obj.toString()));
+
+ return buffer.toString();
+ }
+
+ private String getType(Object obj) {
+ if (obj == null) return NULL_STRING;
+
+ if (obj instanceof IType)
+ return ASTTypeUtil.getType((IType)obj);
+
+ Method[] methods = obj.getClass().getMethods();
+ boolean hasGetType = false;
+
+ int i=0;
+ for(; i<methods.length; i++) {
+ if (methods[i].getName().equals(GETTYPE_METHOD_NAME)) {
+ hasGetType = true;
+ break;
+ }
+ }
+
+ if (hasGetType) {
+ try {
+ Object result = methods[i].invoke(obj, null);
+
+ if (result instanceof IType) {
+ return ASTTypeUtil.getType((IType)result);
+ }
+ } catch (Exception e) {
+ e.printStackTrace(); // display all exceptions to developers
+
+ if (e instanceof InvocationTargetException)
+ return trimObjectToString(((InvocationTargetException)e).getTargetException().toString()) + EXCEPTION_ON + ((InvocationTargetException)e).getTargetException().getStackTrace()[0].toString();
+
+ return e.toString();
+ }
+ }
+
+ return BLANK_STRING; // if there is no type
+ }
+
+ private String getValueString(Object[] objs) {
+ if (objs.length==0) return trimObjectToString(objs.getClass().getName()).replaceAll(SEMI, BLANK_STRING) + NO_ELEMENT_STRING;
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(L_BRACKET_STRING);
+ for(int i=0; i<objs.length; i++) {
+ buffer.append(getValueString(objs[i]));
+ if (i<objs.length-1) buffer.append(OBJECT_SEPARATOR);
+ }
+ buffer.append(R_BRACKET_STRING);
+
+ return buffer.toString();
+ }
+
+ // used to determine if a getter method should be invoked or not, there may be a list of them in the future...
+ private boolean shouldInvokeMethod(String method) {
+ if (method.equals(CLONE_METHOD_NAME))
+ return false;
+
+ return true;
+ }
+
public boolean isPropertySet(Object id) {
return false;
}

Back to the top