From 2e7ff71a7eaea1a5a0aa36a8ea1fd5e875d0a10a Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Fri, 27 May 2005 20:11:05 +0000 Subject: [PATCH] turn off externally linked variables for C (77383) --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 42 +++++++++---------- .../internal/core/dom/parser/c/CVisitor.java | 13 +++--- 2 files changed, 29 insertions(+), 26 deletions(-) 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 504fbf612f3..0bb366e89c0 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 @@ -2468,27 +2468,28 @@ public class AST2Tests extends AST2BaseTest { assertFalse(mod.isRestrict()); assertFalse(mod.isVolatile()); } - - public void testExternalVariable() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("void f() { \n"); //$NON-NLS-1$ - buffer.append(" if( a == 0 ) \n"); //$NON-NLS-1$ - buffer.append(" a = a + 3; \n"); //$NON-NLS-1$ - buffer.append("} \n"); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); - CNameCollector col = new CNameCollector(); - tu.accept(col); - - IVariable a = (IVariable) col.getName(1).resolveBinding(); - assertNotNull(a); - assertTrue(a instanceof ICExternalBinding); - assertInstances(col, a, 3); - } +//AJN: bug 77383 don't do external variables +// public void testExternalVariable() throws Exception { +// StringBuffer buffer = new StringBuffer(); +// buffer.append("void f() { \n"); //$NON-NLS-1$ +// buffer.append(" if( a == 0 ) \n"); //$NON-NLS-1$ +// buffer.append(" a = a + 3; \n"); //$NON-NLS-1$ +// buffer.append("} \n"); //$NON-NLS-1$ +// +// IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); +// CNameCollector col = new CNameCollector(); +// tu.accept(col); +// +// IVariable a = (IVariable) col.getName(1).resolveBinding(); +// assertNotNull(a); +// assertTrue(a instanceof ICExternalBinding); +// assertInstances(col, a, 3); +// } public void testExternalDefs() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("void f() { \n"); //$NON-NLS-1$ + buffer.append(" int a = 1; \n"); //$NON-NLS-1$ buffer.append(" if( a == 0 ) \n"); //$NON-NLS-1$ buffer.append(" g( a ); \n"); //$NON-NLS-1$ buffer.append(" if( a < 0 ) \n"); //$NON-NLS-1$ @@ -2502,14 +2503,13 @@ public class AST2Tests extends AST2BaseTest { tu.accept(col); IVariable a = (IVariable) col.getName(1).resolveBinding(); - IFunction g = (IFunction) col.getName(2).resolveBinding(); + IFunction g = (IFunction) col.getName(3).resolveBinding(); assertNotNull(a); assertNotNull(g); - assertTrue(a instanceof ICExternalBinding); assertTrue(g instanceof ICExternalBinding); - assertEquals(col.size(), 10); - assertInstances(col, a, 6); + assertEquals(col.size(), 11); + assertInstances(col, a, 7); assertInstances(col, g, 3); } 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 681964bed89..34a2450ac11 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 @@ -937,7 +937,7 @@ public class CVisitor { IASTNode blockItem = getContainingBlockItem( node ); try { IBinding binding = (IBinding) findBinding( blockItem, ((IASTIdExpression)node).getName(), bits ); - if( binding instanceof IType ){ + if( binding instanceof IType && !(binding instanceof IProblemBinding) ){ return new ProblemBinding( node, IProblemBinding.SEMANTIC_INVALID_TYPE, binding.getNameCharArray() ); } return binding; @@ -1135,7 +1135,7 @@ public class CVisitor { } /** - * if (bits | PREFIX_LOOKUP) then returns IBinding [] + * if (bits & PREFIX_LOOKUP) then returns IBinding [] * otherwise returns IBinding */ protected static Object findBinding( IASTNode blockItem, IASTName name, int bits ) throws DOMException{ @@ -1274,11 +1274,14 @@ public class CVisitor { if( parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME ){ //external function external = new CExternalFunction( tu, name ); - } else { + ((CScope)tu.getScope()).addName( name ); + } + else { //external variable - external = new CExternalVariable( tu, name ); + //external = new CExternalVariable( tu, name ); + //((CScope)tu.getScope()).addName( name ); + external = new ProblemBinding( name, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, name.toCharArray() ); } - ((CScope)tu.getScope()).addName( name ); } return external; }