Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAndrew Niefer2004-09-28 16:59:32 -0400
committerAndrew Niefer2004-09-28 16:59:32 -0400
commit28c842f6a3e740101d9e16cb4c71e51e1e153fa4 (patch)
treefd734f4620cdcceebb65c42af975872233f320cc /core
parent42ebad496ab5e3416c8984e3729c8145623f825e (diff)
downloadorg.eclipse.cdt-28c842f6a3e740101d9e16cb4c71e51e1e153fa4.tar.gz
org.eclipse.cdt-28c842f6a3e740101d9e16cb4c71e51e1e153fa4.tar.xz
org.eclipse.cdt-28c842f6a3e740101d9e16cb4c71e51e1e153fa4.zip
fix bug 72712: [Parser] Selection Search fails upon new expression
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java26
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java83
3 files changed, 99 insertions, 37 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java
index 46fd7efafe7..419220ca730 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java
@@ -452,5 +452,31 @@ public class SelectionParseTest extends SelectionParseBaseTest {
assertFalse( ((IASTMethod)node).previouslyDeclared() );
assertEquals( ((IASTMethod) node).getNameOffset(), code.indexOf( " initialize();" ) + 1 ); //$NON-NLS-1$
}
+
+ public void testBug72712() throws Exception{
+ Writer writer = new StringWriter();
+ writer.write( "class B{ public: B(); }; void f(){ B* b; b = new B(); }" ); //$NON-NLS-1$
+
+ String code = writer.toString();
+ int startIndex = code.indexOf( "new B" ) + 4; //$NON-NLS-1$
+
+ IASTNode node = parse( code, startIndex, startIndex + 1 );
+ assertTrue( node instanceof IASTMethod );
+ assertTrue( ((IASTMethod) node).isConstructor() );
+ }
+
+ public void testBug72712_2() throws Exception{
+ Writer writer = new StringWriter();
+ writer.write( "class A {}; \n"); //$NON-NLS-1$
+ writer.write( "class B{ public: B( A* ); }; \n"); //$NON-NLS-1$
+ writer.write( "void f(){ B* b; b = new B( (A*)0 ); } \n"); //$NON-NLS-1$
+
+ String code = writer.toString();
+ int startIndex = code.indexOf( "(A*)" ) + 1; //$NON-NLS-1$
+
+ IASTNode node = parse( code, startIndex, startIndex + 1 );
+ assertTrue( node instanceof IASTClassSpecifier );
+ assertEquals( ((IASTClassSpecifier)node).getName(), "A" ); //$NON-NLS-1$
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java
index bea396812d1..9cf647e20fd 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java
@@ -84,4 +84,31 @@ public class ASTNewExpression extends ASTExpression {
public String toString(){
return ASTUtil.getExpressionString( this );
}
+
+ public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) {
+ ASTTypeId typeId = (ASTTypeId) getTypeId();
+ ITokenDuple typeDuple = typeId.getTokenDuple();
+
+ if( typeDuple.equals( duple ) )
+ return this;
+ // check subduple
+ if( typeDuple.contains( duple ) )
+ return this;
+
+ //else, check the parameters
+ ASTExpression ownerExpression = null;
+ ASTNewDescriptor newDescriptor = (ASTNewDescriptor)getNewExpressionDescriptor();
+ List newInitializerExpressions = newDescriptor.getNewInitializerExpressionsList();
+ int size = newInitializerExpressions.size();
+ for( int i = 0; i < size; i++ )
+ {
+ ASTExpression expressionList = (ASTExpression) newInitializerExpressions.get(i);
+ ownerExpression = expressionList.findOwnerExpressionForIDExpression( duple );
+ if( ownerExpression != null ){
+ break;
+ }
+ }
+
+ return ownerExpression;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
index 2e9847adde8..b23f208e6b8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
@@ -3596,42 +3596,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
else if( expression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID ||
expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID )
{
- IContainerSymbol classSymbol = null;
- try {
- classSymbol = (IContainerSymbol) lookupQualifiedName(scopeToSymbol( scope ), duple, null, false );
- } catch (ASTSemanticException e) {
- }
- if( classSymbol != null && classSymbol.getTypeInfo().checkBit( ITypeInfo.isTypedef ) ){
- ITypeInfo info = classSymbol.getTypeInfo().getFinalType( pst.getTypeInfoProvider() );
- classSymbol = (IContainerSymbol) info.getTypeSymbol();
- pst.getTypeInfoProvider().returnTypeInfo( info );
- }
- if( classSymbol == null || ! (classSymbol instanceof IDerivableContainerSymbol ) ){
- return null;
- }
-
- List parameters = new ArrayList();
- ASTNewDescriptor newDescriptor = (ASTNewDescriptor) expression.getNewExpressionDescriptor();
- List newInitializerExpressions = newDescriptor.getNewInitializerExpressionsList();
- int size = newInitializerExpressions.size();
- for( int i = 0; i < size; i++ )
- {
- ASTExpression expressionList = (ASTExpression) newInitializerExpressions.get(i);
- while( expressionList != null ){
- parameters.add( expressionList.getResultType().getResult() );
- if( expressionList.getExpressionKind() == IASTExpression.Kind.EXPRESSIONLIST )
- expressionList = (ASTExpression) expressionList.getRHSExpression();
- else
- expressionList = null;
- }
- }
-
- try {
- s = ((IDerivableContainerSymbol)classSymbol).lookupConstructor( parameters );
- } catch (ParserSymbolTableException e1) {
- return null;
- }
-
+ s = lookupSymbolInNewExpression( scope, duple, expression );
}
else if( expression.getExpressionKind() == Kind.POSTFIX_FUNCTIONCALL &&
CharArrayUtils.equals( expression.getLHSExpression().getIdExpressionCharArray(), dupleAsCharArray ))
@@ -3658,11 +3623,16 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
return null;
}
}
+ else if( ownerExpression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID ||
+ ownerExpression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID )
+ {
+ s = lookupSymbolInNewExpression( scope, duple, ownerExpression );
+ }
else
{
try {
s = lookupQualifiedName( scopeToSymbol( scope ), duple, null, false );
- } catch (ASTSemanticException e1) {
+ } catch (ASTSemanticException e1) { //we'll return null
}
}
}
@@ -3672,6 +3642,45 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
return s.getASTExtension().getPrimaryDeclaration();
}
+ public ISymbol lookupSymbolInNewExpression( IASTScope scope, ITokenDuple duple, ASTExpression expression ){
+ IContainerSymbol classSymbol = null;
+ try {
+ classSymbol = (IContainerSymbol) lookupQualifiedName(scopeToSymbol( scope ), duple, null, false );
+ } catch (ASTSemanticException e) {
+ return null;
+ }
+ if( classSymbol != null && classSymbol.getTypeInfo().checkBit( ITypeInfo.isTypedef ) ){
+ ITypeInfo info = classSymbol.getTypeInfo().getFinalType( pst.getTypeInfoProvider() );
+ classSymbol = (IContainerSymbol) info.getTypeSymbol();
+ pst.getTypeInfoProvider().returnTypeInfo( info );
+ }
+ if( classSymbol == null || ! (classSymbol instanceof IDerivableContainerSymbol ) ){
+ return null;
+ }
+
+ List parameters = new ArrayList();
+ ASTNewDescriptor newDescriptor = (ASTNewDescriptor) expression.getNewExpressionDescriptor();
+ List newInitializerExpressions = newDescriptor.getNewInitializerExpressionsList();
+ int size = newInitializerExpressions.size();
+ for( int i = 0; i < size; i++ )
+ {
+ ASTExpression expressionList = (ASTExpression) newInitializerExpressions.get(i);
+ while( expressionList != null ){
+ parameters.add( expressionList.getResultType().getResult() );
+ if( expressionList.getExpressionKind() == IASTExpression.Kind.EXPRESSIONLIST )
+ expressionList = (ASTExpression) expressionList.getRHSExpression();
+ else
+ expressionList = null;
+ }
+ }
+
+ try {
+ return ((IDerivableContainerSymbol)classSymbol).lookupConstructor( parameters );
+ } catch (ParserSymbolTableException e1) {
+ //fall out and return null
+ }
+ return null;
+ }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#getNodeForThisExpression(org.eclipse.cdt.core.parser.ast.IASTExpression)
*/

Back to the top