[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] New Expression References
|
Core:
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().
Core Tests:
Added
testNewExpressions() to CompleteParseASTTest to test new _expression_'s references.
Thanks,
Hoda Amer
Staff Software Engineer
Rational Software - IBM Software Group
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/ChangeLog,v
retrieving revision 1.125
diff -u -r1.125 ChangeLog
--- ChangeLog 18 Aug 2003 17:34:23 -0000 1.125
+++ ChangeLog 20 Aug 2003 15:18:46 -0000
@@ -1,3 +1,8 @@
+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'.
Index: parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java,v
retrieving revision 1.4
diff -u -r1.4 IASTExpression.java
--- parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java 13 Aug 2003 21:51:48 -0000 1.4
+++ parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java 20 Aug 2003 15:18:46 -0000
@@ -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 IASTNewExpressionDescriptor
{
-
+ public List getExpressions();
}
Index: parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java,v
retrieving revision 1.23
diff -u -r1.23 IASTFactory.java
--- parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java 14 Aug 2003 15:33:27 -0000 1.23
+++ parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java 20 Aug 2003 15:18:46 -0000
@@ -97,7 +97,7 @@
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,
Index: parser/org/eclipse/cdt/internal/core/parser/Parser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java,v
retrieving revision 1.92
diff -u -r1.92 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java 14 Aug 2003 15:33:27 -0000 1.92
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java 20 Aug 2003 15:18:47 -0000
@@ -3531,6 +3531,9 @@
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 @@
// 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 @@
// 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 @@
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 @@
// 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 @@
// 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 @@
// 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 @@
{
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,
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java
diff -N parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java 20 Aug 2003 15:18:47 -0000
@@ -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;
+ }
+
+}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java,v
retrieving revision 1.17
diff -u -r1.17 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 14 Aug 2003 19:49:44 -0000 1.17
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 20 Aug 2003 15:18:48 -0000
@@ -107,8 +107,8 @@
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 @@
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 @@
/* (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)
Index: parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java,v
retrieving revision 1.1
diff -u -r1.1 ASTNewDescriptor.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java 28 Jun 2003 22:39:33 -0000 1.1
+++ parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java 20 Aug 2003 15:18:48 -0000
@@ -10,11 +10,21 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.quick;
+import java.util.List;
+
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
/**
* @author jcamelon
*/
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;
+ }
}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java,v
retrieving revision 1.25
diff -u -r1.25 QuickParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java 14 Aug 2003 19:49:44 -0000 1.25
+++ parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java 20 Aug 2003 15:18:48 -0000
@@ -155,7 +155,7 @@
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor()
*/
- public IASTNewExpressionDescriptor createNewDescriptor() {
+ public IASTNewExpressionDescriptor createNewDescriptor(List expressions) {
return new ASTNewDescriptor();
}
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.62
diff -u -r1.62 ChangeLog
--- ChangeLog 14 Aug 2003 19:49:48 -0000 1.62
+++ ChangeLog 20 Aug 2003 15:19:13 -0000
@@ -1,3 +1,6 @@
+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).
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java,v
retrieving revision 1.14
diff -u -r1.14 CompleteParseASTTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java 14 Aug 2003 15:33:32 -0000 1.14
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java 20 Aug 2003 15:19:13 -0000
@@ -980,5 +980,24 @@
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 );
+ }
+
}