mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
C++ bindings:
- namespace aliases - constructor chain references
This commit is contained in:
parent
0a1793e33f
commit
22d59f21f5
5 changed files with 83 additions and 4 deletions
|
@ -953,5 +953,23 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertTrue( qt.isConst() );
|
assertTrue( qt.isConst() );
|
||||||
assertSame( qt.getType(), A );
|
assertSame( qt.getType(), A );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNamespaceAlias() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "namespace A { int x; } \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append( "namespace B = A; \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append( "int f(){ B::x; } \n" ); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
CPPVisitor.visitTranslationUnit( tu, col );
|
||||||
|
|
||||||
|
assertEquals( col.size(), 8 );
|
||||||
|
ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding();
|
||||||
|
IVariable x = (IVariable) col.getName(1).resolveBinding();
|
||||||
|
|
||||||
|
assertInstances( col, A, 4 );
|
||||||
|
assertInstances( col, x, 3 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1314,10 +1314,20 @@ public class CompleteParser2Tests extends TestCase {
|
||||||
|
|
||||||
public void testBug44510() throws Exception
|
public void testBug44510() throws Exception
|
||||||
{
|
{
|
||||||
parse( "int initialize(); " + //$NON-NLS-1$
|
IASTTranslationUnit tu = parse( "int initialize(); " + //$NON-NLS-1$
|
||||||
"int initialize( char ){} " + //$NON-NLS-1$
|
"int initialize( char ){} " + //$NON-NLS-1$
|
||||||
"int initialize(){ return 1; } " + //$NON-NLS-1$
|
"int initialize(){ return 1; } " + //$NON-NLS-1$
|
||||||
"void main(){ int i = initialize(); }" ); //$NON-NLS-1$
|
"void main(){ int i = initialize(); }" ); //$NON-NLS-1$
|
||||||
|
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
CPPVisitor.visitTranslationUnit( tu, col );
|
||||||
|
|
||||||
|
assertEquals( col.size(), 7 );
|
||||||
|
IFunction init1 = (IFunction) col.getName(0).resolveBinding();
|
||||||
|
IFunction init2 = (IFunction) col.getName(1).resolveBinding();
|
||||||
|
|
||||||
|
assertInstances( col, init1, 3 );
|
||||||
|
assertInstances( col, init2, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug44925() throws Exception
|
public void testBug44925() throws Exception
|
||||||
|
@ -1327,7 +1337,23 @@ public class CompleteParser2Tests extends TestCase {
|
||||||
buffer.append( "class MyClass myObj1;"); //$NON-NLS-1$
|
buffer.append( "class MyClass myObj1;"); //$NON-NLS-1$
|
||||||
buffer.append( "enum MyEnum { Item1 };"); //$NON-NLS-1$
|
buffer.append( "enum MyEnum { Item1 };"); //$NON-NLS-1$
|
||||||
buffer.append( "enum MyEnum myObj2;"); //$NON-NLS-1$
|
buffer.append( "enum MyEnum myObj2;"); //$NON-NLS-1$
|
||||||
parse( buffer.toString() );
|
IASTTranslationUnit tu = parse( buffer.toString() );
|
||||||
|
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
CPPVisitor.visitTranslationUnit( tu, col );
|
||||||
|
|
||||||
|
assertEquals( col.size(), 7 );
|
||||||
|
ICPPClassType myClass = (ICPPClassType) col.getName(0).resolveBinding();
|
||||||
|
IVariable obj1 = (IVariable) col.getName(2).resolveBinding();
|
||||||
|
IEnumeration myEnum = (IEnumeration) col.getName(3).resolveBinding();
|
||||||
|
IEnumerator item = (IEnumerator) col.getName(4).resolveBinding();
|
||||||
|
IVariable obj2 = (IVariable)col.getName(6).resolveBinding();
|
||||||
|
|
||||||
|
assertInstances( col, myClass, 2 );
|
||||||
|
assertInstances( col, myEnum, 2 );
|
||||||
|
assertSame( obj1.getType(), myClass );
|
||||||
|
assertSame( obj2.getType(), myEnum );
|
||||||
|
assertSame( item.getType(), myEnum );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug44838() throws Exception
|
public void testBug44838() throws Exception
|
||||||
|
@ -1335,7 +1361,21 @@ public class CompleteParser2Tests extends TestCase {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append( "class A { int myX; A( int x ); };\n"); //$NON-NLS-1$
|
buffer.append( "class A { int myX; A( int x ); };\n"); //$NON-NLS-1$
|
||||||
buffer.append( "A::A( int x ) : myX( x ) { if( x == 5 ) myX++; }\n"); //$NON-NLS-1$
|
buffer.append( "A::A( int x ) : myX( x ) { if( x == 5 ) myX++; }\n"); //$NON-NLS-1$
|
||||||
parse( buffer.toString() );
|
IASTTranslationUnit tu = parse( buffer.toString() );
|
||||||
|
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
CPPVisitor.visitTranslationUnit( tu, col );
|
||||||
|
|
||||||
|
assertEquals( col.size(), 12 );
|
||||||
|
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||||
|
ICPPField myX = (ICPPField) col.getName(1).resolveBinding();
|
||||||
|
ICPPConstructor ctor = (ICPPConstructor) col.getName(2).resolveBinding();
|
||||||
|
IParameter x = (IParameter) col.getName(3).resolveBinding();
|
||||||
|
|
||||||
|
assertInstances( col, A, 2 );
|
||||||
|
assertInstances( col, myX, 3 );
|
||||||
|
assertInstances( col, ctor, 3 );
|
||||||
|
assertInstances( col, x, 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug46165() throws Exception
|
public void testBug46165() throws Exception
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class CPPImplicitMethod extends CPPMethod {
|
||||||
this.implicitName = name;
|
this.implicitName = name;
|
||||||
this.parameters = params;
|
this.parameters = params;
|
||||||
this.returnType = returnType;
|
this.returnType = returnType;
|
||||||
|
this.scope = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -54,10 +54,12 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||||
|
@ -372,7 +374,12 @@ public class CPPSemantics {
|
||||||
} else if( parent instanceof ICPPASTBaseSpecifier ) {
|
} else if( parent instanceof ICPPASTBaseSpecifier ) {
|
||||||
IASTNode n = CPPVisitor.getContainingBlockItem( parent );
|
IASTNode n = CPPVisitor.getContainingBlockItem( parent );
|
||||||
return (ICPPScope) CPPVisitor.getContainingScope( n );
|
return (ICPPScope) CPPVisitor.getContainingScope( n );
|
||||||
}
|
} else if( parent instanceof ICPPASTConstructorChainInitializer ){
|
||||||
|
ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) parent;
|
||||||
|
IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) initializer.getParent();
|
||||||
|
return (ICPPScope) dtor.getName().resolveBinding().getScope();
|
||||||
|
|
||||||
|
}
|
||||||
return (ICPPScope) CPPVisitor.getContainingScope( name );
|
return (ICPPScope) CPPVisitor.getContainingScope( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -800,6 +807,10 @@ public class CPPSemantics {
|
||||||
IASTName namespaceName = ((ICPPASTNamespaceDefinition) declaration).getName();
|
IASTName namespaceName = ((ICPPASTNamespaceDefinition) declaration).getName();
|
||||||
if( CharArrayUtils.equals( namespaceName.toCharArray(), data.name ) )
|
if( CharArrayUtils.equals( namespaceName.toCharArray(), data.name ) )
|
||||||
return namespaceName;
|
return namespaceName;
|
||||||
|
} else if( declaration instanceof ICPPASTNamespaceAlias ){
|
||||||
|
IASTName alias = ((ICPPASTNamespaceAlias) declaration).getAlias();
|
||||||
|
if( CharArrayUtils.equals( alias.toCharArray(), data.name ) )
|
||||||
|
return alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -259,6 +259,9 @@ public class CPPVisitor {
|
||||||
return binding;
|
return binding;
|
||||||
} else if( declaration instanceof ICPPASTUsingDirective ){
|
} else if( declaration instanceof ICPPASTUsingDirective ){
|
||||||
return CPPSemantics.resolveBinding( ((ICPPASTUsingDirective) declaration).getQualifiedName() );
|
return CPPSemantics.resolveBinding( ((ICPPASTUsingDirective) declaration).getQualifiedName() );
|
||||||
|
} else if( declaration instanceof ICPPASTNamespaceAlias ) {
|
||||||
|
ICPPASTNamespaceAlias alias = (ICPPASTNamespaceAlias) declaration;
|
||||||
|
return CPPSemantics.resolveBinding( alias.getQualifiedName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -387,6 +390,12 @@ public class CPPVisitor {
|
||||||
return ((IASTForStatement)parent).getScope();
|
return ((IASTForStatement)parent).getScope();
|
||||||
} else if( parent instanceof IASTCompoundStatement ){
|
} else if( parent instanceof IASTCompoundStatement ){
|
||||||
return ((IASTCompoundStatement)parent).getScope();
|
return ((IASTCompoundStatement)parent).getScope();
|
||||||
|
} else if( parent instanceof ICPPASTConstructorChainInitializer ){
|
||||||
|
IASTNode node = getContainingBlockItem( parent );
|
||||||
|
if( node instanceof IASTFunctionDefinition ){
|
||||||
|
IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition)node).getBody();
|
||||||
|
return body.getScope();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return getContainingScope( parent );
|
return getContainingScope( parent );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue