mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Bug 401661 - CPPClassType.getScope() at split definition and declaration
Now CPPClassType.getScope() returns the scope of the surrounding class or namespace independent of the location of the definition.
This commit is contained in:
parent
6e5ac901f4
commit
d24992f0a6
2 changed files with 77 additions and 5 deletions
|
@ -10195,4 +10195,70 @@ public class AST2CPPTests extends AST2TestBase {
|
||||||
long BSize = SizeofCalculator.getSizeAndAlignment(B, nameB).size;
|
long BSize = SizeofCalculator.getSizeAndAlignment(B, nameB).size;
|
||||||
assertEquals(pointerSize, BSize);
|
assertEquals(pointerSize, BSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// namespace NS {
|
||||||
|
// class Enclosing {
|
||||||
|
// class Inner {};
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
public void testNestedClassScopeInlineDefinition_401661() throws Exception {
|
||||||
|
String code = getAboveComment();
|
||||||
|
parseAndCheckBindings(code);
|
||||||
|
|
||||||
|
BindingAssertionHelper bh = new BindingAssertionHelper(code, true);
|
||||||
|
|
||||||
|
ICPPClassType Enclosing = bh.assertNonProblem("Enclosing", 9);
|
||||||
|
ICPPClassType Inner = bh.assertNonProblem("Inner", 5);
|
||||||
|
|
||||||
|
assertEquals(Enclosing.getCompositeScope(), Inner.getScope());
|
||||||
|
}
|
||||||
|
|
||||||
|
// namespace NS {
|
||||||
|
// class Enclosing {
|
||||||
|
// class Inner;
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// class NS::Enclosing::Inner{};
|
||||||
|
public void testNestedClassScopeSeparateDefinition_401661() throws Exception {
|
||||||
|
String code = getAboveComment();
|
||||||
|
parseAndCheckBindings(code);
|
||||||
|
|
||||||
|
BindingAssertionHelper bh = new BindingAssertionHelper(code, true);
|
||||||
|
|
||||||
|
ICPPClassType Enclosing = bh.assertNonProblem("Enclosing", 9);
|
||||||
|
ICPPClassType Inner = bh.assertNonProblem("Inner;", 5);
|
||||||
|
|
||||||
|
assertEquals(Enclosing.getCompositeScope(), Inner.getScope());
|
||||||
|
}
|
||||||
|
|
||||||
|
// namespace NS {
|
||||||
|
// class Inner {};
|
||||||
|
// }
|
||||||
|
public void testClassScopeInlineDefinition_401661() throws Exception {
|
||||||
|
String code = getAboveComment();
|
||||||
|
parseAndCheckBindings(code);
|
||||||
|
|
||||||
|
BindingAssertionHelper bh = new BindingAssertionHelper(code, true);
|
||||||
|
|
||||||
|
ICPPNamespace NamespaceNS = bh.assertNonProblem("NS {", 2);
|
||||||
|
ICPPClassType Inner = bh.assertNonProblem("Inner", 5);
|
||||||
|
|
||||||
|
assertEquals(NamespaceNS.getNamespaceScope(), Inner.getScope());
|
||||||
|
}
|
||||||
|
|
||||||
|
// namespace NS {
|
||||||
|
// class Inner;
|
||||||
|
// }
|
||||||
|
// class NS::Inner{};
|
||||||
|
public void testClassScopeSeparateDefinition_401661() throws Exception {
|
||||||
|
String code = getAboveComment();
|
||||||
|
parseAndCheckBindings(code);
|
||||||
|
|
||||||
|
BindingAssertionHelper bh = new BindingAssertionHelper(code, true);
|
||||||
|
|
||||||
|
ICPPNamespace NamespaceNS = bh.assertNonProblem("NS {", 2);
|
||||||
|
ICPPClassType Inner = bh.assertNonProblem("Inner;", 5);
|
||||||
|
|
||||||
|
assertEquals(NamespaceNS.getNamespaceScope(), Inner.getScope());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,10 +117,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
|
||||||
private ICPPClassType typeInIndex;
|
private ICPPClassType typeInIndex;
|
||||||
|
|
||||||
public CPPClassType(IASTName name, IBinding indexBinding) {
|
public CPPClassType(IASTName name, IBinding indexBinding) {
|
||||||
if (name instanceof ICPPASTQualifiedName) {
|
name = stripQualifier(name);
|
||||||
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
|
||||||
name = ns[ns.length - 1];
|
|
||||||
}
|
|
||||||
IASTNode parent = name.getParent();
|
IASTNode parent = name.getParent();
|
||||||
while (parent instanceof IASTName)
|
while (parent instanceof IASTName)
|
||||||
parent = parent.getParent();
|
parent = parent.getParent();
|
||||||
|
@ -195,7 +192,8 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
|
||||||
@Override
|
@Override
|
||||||
public IScope getScope() {
|
public IScope getScope() {
|
||||||
IASTName name = definition != null ? definition : declarations[0];
|
IASTName name = definition != null ? definition : declarations[0];
|
||||||
|
name = stripQualifier(name);
|
||||||
|
|
||||||
IScope scope = CPPVisitor.getContainingScope(name);
|
IScope scope = CPPVisitor.getContainingScope(name);
|
||||||
if (definition == null && name.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME) {
|
if (definition == null && name.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME) {
|
||||||
IASTNode node = declarations[0].getParent().getParent();
|
IASTNode node = declarations[0].getParent().getParent();
|
||||||
|
@ -406,4 +404,12 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IASTName stripQualifier(IASTName name) {
|
||||||
|
if (name instanceof ICPPASTQualifiedName) {
|
||||||
|
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||||
|
name = ns[ ns.length - 1 ];
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue