mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
turn off externally linked variables for C (77383)
This commit is contained in:
parent
97ac9f71a0
commit
2e7ff71a7e
2 changed files with 29 additions and 26 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
//external variable
|
||||
external = new CExternalVariable( tu, name );
|
||||
((CScope)tu.getScope()).addName( name );
|
||||
}
|
||||
else {
|
||||
//external variable
|
||||
//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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue