mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 02:15:31 +02:00
Owner of forward class declarations, bug 290693.
This commit is contained in:
parent
d1d38f73dc
commit
cb647d08f0
2 changed files with 38 additions and 4 deletions
|
@ -7411,4 +7411,26 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertEquals(declNames.length, i);
|
assertEquals(declNames.length, i);
|
||||||
assertEquals(defNames.length, j);
|
assertEquals(defNames.length, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// class X {
|
||||||
|
// struct S* m1;
|
||||||
|
// struct T;
|
||||||
|
// struct T* m2;
|
||||||
|
// };
|
||||||
|
public void testStructOwner_290693() throws Exception {
|
||||||
|
final String code = getAboveComment();
|
||||||
|
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||||
|
|
||||||
|
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||||
|
ICPPClassType S= bh.assertNonProblem("S*", 1);
|
||||||
|
assertNull(S.getOwner());
|
||||||
|
|
||||||
|
ICPPClassType X= bh.assertNonProblem("X {", 1);
|
||||||
|
ICPPClassType T= bh.assertNonProblem("T;", 1);
|
||||||
|
assertSame(X, T.getOwner());
|
||||||
|
|
||||||
|
T= bh.assertNonProblem("T* m2", 1);
|
||||||
|
assertSame(X, T.getOwner());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -2023,15 +2023,27 @@ public class CPPVisitor extends ASTQueries {
|
||||||
*/
|
*/
|
||||||
public static IBinding findDeclarationOwner(IASTNode node, boolean allowFunction) {
|
public static IBinding findDeclarationOwner(IASTNode node, boolean allowFunction) {
|
||||||
// Search for declaration
|
// Search for declaration
|
||||||
|
boolean isFriend= false;
|
||||||
|
boolean isNonSimpleElabDecl= false;
|
||||||
while (!(node instanceof IASTDeclaration)) {
|
while (!(node instanceof IASTDeclaration)) {
|
||||||
if (node == null)
|
if (node == null)
|
||||||
return null;
|
return null;
|
||||||
|
if (node instanceof IASTElaboratedTypeSpecifier) {
|
||||||
|
isNonSimpleElabDecl= true;
|
||||||
|
final IASTNode parent= node.getParent();
|
||||||
|
if (parent instanceof IASTSimpleDeclaration) {
|
||||||
|
final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) parent;
|
||||||
|
if (sdecl.getDeclarators().length==0) {
|
||||||
|
isNonSimpleElabDecl= false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
node= node.getParent();
|
node= node.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isFriend= false;
|
|
||||||
if (node instanceof IASTSimpleDeclaration) {
|
if (node instanceof IASTSimpleDeclaration) {
|
||||||
ICPPASTDeclSpecifier declSpec= (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) node).getDeclSpecifier();
|
final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) node;
|
||||||
|
ICPPASTDeclSpecifier declSpec= (ICPPASTDeclSpecifier) sdecl.getDeclSpecifier();
|
||||||
if (declSpec.isFriend()) {
|
if (declSpec.isFriend()) {
|
||||||
isFriend= true;
|
isFriend= true;
|
||||||
}
|
}
|
||||||
|
@ -2058,7 +2070,7 @@ public class CPPVisitor extends ASTQueries {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (node instanceof IASTCompositeTypeSpecifier) {
|
if (node instanceof IASTCompositeTypeSpecifier) {
|
||||||
if (isFriend)
|
if (isFriend || isNonSimpleElabDecl)
|
||||||
continue;
|
continue;
|
||||||
name= ((IASTCompositeTypeSpecifier) node).getName();
|
name= ((IASTCompositeTypeSpecifier) node).getName();
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue