mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Bug 372004 - Locally declared extern variable
Change-Id: I33d634d6c63138910b2958b81f6d8df358e89e7d Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/23098 Tested-by: Hudson CI Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
c52eee2c40
commit
a2a05a515a
4 changed files with 49 additions and 35 deletions
|
@ -146,3 +146,8 @@ EMPTY int f();
|
||||||
|
|
||||||
//http://bugs.eclipse.org/340492
|
//http://bugs.eclipse.org/340492
|
||||||
template< template<class> class U > class myClass {};
|
template< template<class> class U > class myClass {};
|
||||||
|
|
||||||
|
//http://bugs.eclipse.org/372004
|
||||||
|
void g() {
|
||||||
|
extern int globalVariable; // declared as global near top
|
||||||
|
}
|
||||||
|
|
|
@ -273,6 +273,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
|
||||||
createPosition(102, 8, 13),
|
createPosition(102, 8, 13),
|
||||||
createPosition(137, 4, 1),
|
createPosition(137, 4, 1),
|
||||||
createPosition(144, 10, 1),
|
createPosition(144, 10, 1),
|
||||||
|
createPosition(150, 5, 1),
|
||||||
};
|
};
|
||||||
if (PRINT_POSITIONS) System.out.println(toString(actual));
|
if (PRINT_POSITIONS) System.out.println(toString(actual));
|
||||||
assertEqualPositions(expected, actual);
|
assertEqualPositions(expected, actual);
|
||||||
|
@ -291,6 +292,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
|
||||||
createPosition(131, 4, 11),
|
createPosition(131, 4, 11),
|
||||||
createPosition(137, 4, 1),
|
createPosition(137, 4, 1),
|
||||||
createPosition(144, 10, 1),
|
createPosition(144, 10, 1),
|
||||||
|
createPosition(150, 5, 1),
|
||||||
};
|
};
|
||||||
if (PRINT_POSITIONS) System.out.println(toString(actual));
|
if (PRINT_POSITIONS) System.out.println(toString(actual));
|
||||||
assertEqualPositions(expected, actual);
|
assertEqualPositions(expected, actual);
|
||||||
|
@ -306,6 +308,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
|
||||||
createPosition(33, 15, 20),
|
createPosition(33, 15, 20),
|
||||||
createPosition(101, 8, 12),
|
createPosition(101, 8, 12),
|
||||||
createPosition(104, 8, 12),
|
createPosition(104, 8, 12),
|
||||||
|
createPosition(151, 15, 14),
|
||||||
};
|
};
|
||||||
if (PRINT_POSITIONS) System.out.println(toString(actual));
|
if (PRINT_POSITIONS) System.out.println(toString(actual));
|
||||||
assertEqualPositions(expected, actual);
|
assertEqualPositions(expected, actual);
|
||||||
|
|
|
@ -1224,4 +1224,15 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
|
||||||
assertTrue(decl instanceof IASTName);
|
assertTrue(decl instanceof IASTName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// int waldo;
|
||||||
|
// void foo() {
|
||||||
|
// extern int waldo;
|
||||||
|
// }
|
||||||
|
public void testLocallyDeclaredExternVariable_372004() throws Exception {
|
||||||
|
String code = getAboveComment();
|
||||||
|
IFile file = importFile("testWaldo.cpp", code);
|
||||||
|
|
||||||
|
int offset = code.indexOf("extern int waldo") + 12;
|
||||||
|
assertTrue(testF3(file, offset) instanceof IASTName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -655,14 +655,9 @@ public class SemanticHighlightings {
|
||||||
&& !(binding instanceof IField)
|
&& !(binding instanceof IField)
|
||||||
&& !(binding instanceof IParameter)
|
&& !(binding instanceof IParameter)
|
||||||
&& !(binding instanceof IProblemBinding)) {
|
&& !(binding instanceof IProblemBinding)) {
|
||||||
try {
|
if (LocalVariableHighlighting.isLocalVariable((IVariable) binding)) {
|
||||||
IScope scope= binding.getScope();
|
|
||||||
if (LocalVariableHighlighting.isLocalScope(scope)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (DOMException exc) {
|
|
||||||
CUIPlugin.log(exc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -715,21 +710,23 @@ public class SemanticHighlightings {
|
||||||
&& !(binding instanceof IField)
|
&& !(binding instanceof IField)
|
||||||
&& !(binding instanceof IParameter)
|
&& !(binding instanceof IParameter)
|
||||||
&& !(binding instanceof IProblemBinding)) {
|
&& !(binding instanceof IProblemBinding)) {
|
||||||
try {
|
if (isLocalVariable((IVariable) binding)) {
|
||||||
IScope scope= binding.getScope();
|
|
||||||
if (isLocalScope(scope)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (DOMException exc) {
|
|
||||||
CUIPlugin.log(exc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLocalScope(IScope scope) {
|
public static boolean isLocalVariable(IVariable variable) {
|
||||||
|
// A variable marked 'extern' declares a global
|
||||||
|
// variable even if the declaration is local.
|
||||||
|
if (variable.isExtern()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
IScope scope= variable.getScope();
|
||||||
while (scope != null) {
|
while (scope != null) {
|
||||||
if (scope instanceof ICPPFunctionScope ||
|
if (scope instanceof ICPPFunctionScope ||
|
||||||
scope instanceof ICPPBlockScope ||
|
scope instanceof ICPPBlockScope ||
|
||||||
|
@ -742,6 +739,9 @@ public class SemanticHighlightings {
|
||||||
scope= null;
|
scope= null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (DOMException exc) {
|
||||||
|
CUIPlugin.log(exc);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -794,14 +794,9 @@ public class SemanticHighlightings {
|
||||||
&& !(binding instanceof IParameter)
|
&& !(binding instanceof IParameter)
|
||||||
&& !(binding instanceof ICPPTemplateNonTypeParameter)
|
&& !(binding instanceof ICPPTemplateNonTypeParameter)
|
||||||
&& !(binding instanceof IProblemBinding)) {
|
&& !(binding instanceof IProblemBinding)) {
|
||||||
try {
|
if (!LocalVariableHighlighting.isLocalVariable((IVariable) binding)) {
|
||||||
IScope scope= binding.getScope();
|
|
||||||
if (!LocalVariableHighlighting.isLocalScope(scope)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (DOMException exc) {
|
|
||||||
CUIPlugin.log(exc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue