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;
|
||||
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;
|
||||
|
||||
public CPPClassType(IASTName name, IBinding indexBinding) {
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
||||
name = ns[ns.length - 1];
|
||||
}
|
||||
name = stripQualifier(name);
|
||||
IASTNode parent = name.getParent();
|
||||
while (parent instanceof IASTName)
|
||||
parent = parent.getParent();
|
||||
|
@ -195,6 +192,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
|
|||
@Override
|
||||
public IScope getScope() {
|
||||
IASTName name = definition != null ? definition : declarations[0];
|
||||
name = stripQualifier(name);
|
||||
|
||||
IScope scope = CPPVisitor.getContainingScope(name);
|
||||
if (definition == null && name.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME) {
|
||||
|
@ -406,4 +404,12 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
|
|||
}
|
||||
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