mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +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.isRestrict());
|
||||||
assertFalse(mod.isVolatile());
|
assertFalse(mod.isVolatile());
|
||||||
}
|
}
|
||||||
|
//AJN: bug 77383 don't do external variables
|
||||||
public void testExternalVariable() throws Exception {
|
// public void testExternalVariable() throws Exception {
|
||||||
StringBuffer buffer = new StringBuffer();
|
// StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append("void f() { \n"); //$NON-NLS-1$
|
// buffer.append("void f() { \n"); //$NON-NLS-1$
|
||||||
buffer.append(" if( a == 0 ) \n"); //$NON-NLS-1$
|
// buffer.append(" if( a == 0 ) \n"); //$NON-NLS-1$
|
||||||
buffer.append(" a = a + 3; \n"); //$NON-NLS-1$
|
// buffer.append(" a = a + 3; \n"); //$NON-NLS-1$
|
||||||
buffer.append("} \n"); //$NON-NLS-1$
|
// buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
//
|
||||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
// IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||||
CNameCollector col = new CNameCollector();
|
// CNameCollector col = new CNameCollector();
|
||||||
tu.accept(col);
|
// tu.accept(col);
|
||||||
|
//
|
||||||
IVariable a = (IVariable) col.getName(1).resolveBinding();
|
// IVariable a = (IVariable) col.getName(1).resolveBinding();
|
||||||
assertNotNull(a);
|
// assertNotNull(a);
|
||||||
assertTrue(a instanceof ICExternalBinding);
|
// assertTrue(a instanceof ICExternalBinding);
|
||||||
assertInstances(col, a, 3);
|
// assertInstances(col, a, 3);
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void testExternalDefs() throws Exception {
|
public void testExternalDefs() throws Exception {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append("void f() { \n"); //$NON-NLS-1$
|
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(" if( a == 0 ) \n"); //$NON-NLS-1$
|
||||||
buffer.append(" g( a ); \n"); //$NON-NLS-1$
|
buffer.append(" g( a ); \n"); //$NON-NLS-1$
|
||||||
buffer.append(" if( a < 0 ) \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);
|
tu.accept(col);
|
||||||
|
|
||||||
IVariable a = (IVariable) col.getName(1).resolveBinding();
|
IVariable a = (IVariable) col.getName(1).resolveBinding();
|
||||||
IFunction g = (IFunction) col.getName(2).resolveBinding();
|
IFunction g = (IFunction) col.getName(3).resolveBinding();
|
||||||
assertNotNull(a);
|
assertNotNull(a);
|
||||||
assertNotNull(g);
|
assertNotNull(g);
|
||||||
assertTrue(a instanceof ICExternalBinding);
|
|
||||||
assertTrue(g instanceof ICExternalBinding);
|
assertTrue(g instanceof ICExternalBinding);
|
||||||
|
|
||||||
assertEquals(col.size(), 10);
|
assertEquals(col.size(), 11);
|
||||||
assertInstances(col, a, 6);
|
assertInstances(col, a, 7);
|
||||||
assertInstances(col, g, 3);
|
assertInstances(col, g, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -937,7 +937,7 @@ public class CVisitor {
|
||||||
IASTNode blockItem = getContainingBlockItem( node );
|
IASTNode blockItem = getContainingBlockItem( node );
|
||||||
try {
|
try {
|
||||||
IBinding binding = (IBinding) findBinding( blockItem, ((IASTIdExpression)node).getName(), bits );
|
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 new ProblemBinding( node, IProblemBinding.SEMANTIC_INVALID_TYPE, binding.getNameCharArray() );
|
||||||
}
|
}
|
||||||
return binding;
|
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
|
* otherwise returns IBinding
|
||||||
*/
|
*/
|
||||||
protected static Object findBinding( IASTNode blockItem, IASTName name, int bits ) throws DOMException{
|
protected static Object findBinding( IASTNode blockItem, IASTName name, int bits ) throws DOMException{
|
||||||
|
@ -1274,12 +1274,15 @@ public class CVisitor {
|
||||||
if( parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME ){
|
if( parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME ){
|
||||||
//external function
|
//external function
|
||||||
external = new CExternalFunction( tu, name );
|
external = new CExternalFunction( tu, name );
|
||||||
} else {
|
|
||||||
//external variable
|
|
||||||
external = new CExternalVariable( tu, name );
|
|
||||||
}
|
|
||||||
((CScope)tu.getScope()).addName( 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() );
|
||||||
|
}
|
||||||
|
}
|
||||||
return external;
|
return external;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue