diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 57f7afc7570..ed44915c34f 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -19,6 +19,9 @@ are properly read and dealt with during project creation and persisting settings. * build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java +2003-08-20 Hoda Amer + Added testNewExpressions() to CompleteParseASTTest to test new expression's references. + 2003-08-14 John Camelon Removed warnings from AutomatedIntegrationSuite.java (removing implicit accessor generation). diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java index 4d32e0e79aa..3262a5cc067 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java @@ -980,5 +980,24 @@ public class CompleteParseASTTest extends TestCase assertEquals( callback.getReferences().size(), 1 ); IASTClassReference ref = (IASTClassReference)callback.getReferences().get(0); assertEquals( ref.getReferencedElement(), classA ); - } + } + + public void testNewExpressions() throws Exception + { + Iterator declarations = parse( "int A; int B; int C; int D; int P; int*p = new (P) (A)[B][C][D];" ).getDeclarations(); + IASTVariable variableA = (IASTVariable)declarations.next(); + IASTVariable variableB = (IASTVariable)declarations.next(); + IASTVariable variableC = (IASTVariable)declarations.next(); + IASTVariable variableD = (IASTVariable)declarations.next(); + IASTVariable variableP = (IASTVariable)declarations.next(); + IASTVariable variablep = (IASTVariable)declarations.next(); + assertEquals( callback.getReferences().size(), 5 ); + Iterator references = callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableP ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableB ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableC ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableD ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableA ); + } + } diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 42d588132f4..6fb12a57cbb 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -30,6 +30,11 @@ * build/org/eclipse/cdt/internal/core/build/managed/Option.java * build/org/eclipse/cdt/internal/core/build/managed/OptionReference.java +2003-08-20 Hoda Amer + Modified the parser's newExpression() to send all its sub expressions + to the newDescriptor and check on each expression to find references + in the CompleteParserASTFactory.createExpression(). + 2003-08-13 Sean Evoy Changed text generated into makefile comments from the rather abstract term 'module' to the more meaningful 'subdirectory'. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java index da88299dd6e..5516f7c5c92 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java @@ -10,6 +10,8 @@ ***********************************************************************/ package org.eclipse.cdt.core.parser.ast; +import java.util.List; + import org.eclipse.cdt.core.parser.Enum; import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; @@ -122,7 +124,7 @@ public interface IASTExpression extends ISourceElementCallbackDelegate public interface IASTNewExpressionDescriptor { - + public List getExpressions(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java index 5e0345b8770..af80f25cf34 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java @@ -97,7 +97,7 @@ public interface IASTFactory IToken id, ITokenDuple typeId, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException; - public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(); + public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List expressions); public IASTInitializerClause createInitializerClause( IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 543787d60e9..a9413c4f8b0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -3531,6 +3531,9 @@ public class Parser implements IParser boolean placementParseFailure = true; IToken beforeSecondParen = null; IToken backtrackMarker = null; + ITokenDuple typeId = null; + ArrayList expressions = new ArrayList(); + if (LT(1) == IToken.tLPAREN) { consume(IToken.tLPAREN); @@ -3539,7 +3542,7 @@ public class Parser implements IParser // Try to consume placement list // Note: since expressionList and expression are the same... backtrackMarker = mark(); - expression(scope); + expressions.add(expression(scope)); consume(IToken.tRPAREN); placementParseFailure = false; if (LT(1) == IToken.tLPAREN) @@ -3558,7 +3561,7 @@ public class Parser implements IParser // CASE: new (typeid-not-looking-as-placement) ... // the first expression in () is not a placement // - then it has to be typeId - typeId(); + typeId = typeId(); consume(IToken.tRPAREN); } else @@ -3582,14 +3585,15 @@ public class Parser implements IParser try { backtrackMarker = mark(); - typeId(); + typeId = typeId(); } catch (Backtrack e) { // Hmmm, so it wasn't typeId after all... Then it is // CASE: new (typeid-looking-as-placement) backup(backtrackMarker); - return null; // TODO fix this + // TODO fix this + return null; } } } @@ -3600,7 +3604,7 @@ public class Parser implements IParser // The problem is, the first expression might as well be a typeid try { - typeId(); + typeId = typeId(); consume(IToken.tRPAREN); if (LT(1) == IToken.tLPAREN || LT(1) == IToken.tLBRACKET) @@ -3617,7 +3621,18 @@ public class Parser implements IParser // Worst-case scenario - this cannot be resolved w/o more semantic information. // Luckily, we don't need to know what was that - we only know that // new-expression ends here. - return null; // TODO fix this + try + { + return astFactory.createExpression( + scope, IASTExpression.Kind.NEW_TYPEID, + null, null, null, null, typeId, "", + astFactory.createNewDescriptor(expressions)); + } + catch (ASTSemanticException e) + { + failParse(); + return null; + } } } catch (Backtrack e) @@ -3634,13 +3649,13 @@ public class Parser implements IParser // CASE: new typeid ... // new parameters do not start with '(' // i.e it has to be a plain typeId - typeId(); + typeId = typeId(); } while (LT(1) == IToken.tLBRACKET) { // array new consume(); - assignmentExpression(scope); + expressions.add(assignmentExpression(scope)); consume(IToken.tRBRACKET); } // newinitializer @@ -3648,10 +3663,21 @@ public class Parser implements IParser { consume(IToken.tLPAREN); if (LT(1) != IToken.tRPAREN) - expression(scope); + expressions.add(expression(scope)); consume(IToken.tRPAREN); } - return null; //TODO fix this + try + { + return astFactory.createExpression( + scope, IASTExpression.Kind.NEW_TYPEID, + null, null, null, null, typeId, "", + astFactory.createNewDescriptor(expressions)); + } + catch (ASTSemanticException e) + { + failParse(); + return null; + } } protected IASTExpression unaryOperatorCastExpression( IASTScope scope, IASTExpression.Kind kind, diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java new file mode 100644 index 00000000000..dadd1f52b30 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2001 Rational Software Corp. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * Rational Software - initial implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.core.parser.ast.complete; + +import java.util.List; + +import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; + +/** + * @author hamer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class ASTNewDescriptor implements IASTNewExpressionDescriptor { + + List expressions; + + public ASTNewDescriptor(List expressions) { + super(); + this.expressions = expressions; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor#getExpressions() + */ + public List getExpressions() { + return expressions; + } + +} 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 9d2f9156590..c217eab293e 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 @@ -107,8 +107,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto result = startingScope.lookup( firstSymbol.getImage()); if( result != null ) references.add( createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() )); - else - throw new ASTSemanticException(); + //else + // throw new ASTSemanticException(); } catch (ParserSymbolTableException e) { @@ -641,6 +641,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto getExpressionReferences(rhs, references); getExpressionReferences(thirdExpression,references); + // if there is a newDescriptor, check related expressions + if(newDescriptor != null){ + Iterator i = newDescriptor.getExpressions().iterator(); + while (i.hasNext()){ + getExpressionReferences((IASTExpression)i.next(), references); + } + } + //look up id & add to references IContainerSymbol startingScope = scopeToSymbol( scope ); @@ -682,10 +690,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor() */ - public IASTNewExpressionDescriptor createNewDescriptor() + public IASTNewExpressionDescriptor createNewDescriptor(List expressions) { // TODO FIX THIS - return null; + // return null; + return new ASTNewDescriptor(expressions); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java index adf39d7bffd..33a7eaafc90 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java @@ -10,6 +10,8 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.ast.quick; +import java.util.List; + import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; /** @@ -17,4 +19,12 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescripto */ public class ASTNewDescriptor implements IASTNewExpressionDescriptor { + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor#getExpressions() + */ + public List getExpressions() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java index af13571915c..8b48b6c0ce3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java @@ -155,7 +155,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor() */ - public IASTNewExpressionDescriptor createNewDescriptor() { + public IASTNewExpressionDescriptor createNewDescriptor(List expressions) { return new ASTNewDescriptor(); }