1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Hoda Amer:

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.
This commit is contained in:
Doug Schaefer 2003-08-20 18:05:30 +00:00
parent cc710063b4
commit a55df357e1
10 changed files with 132 additions and 18 deletions

View file

@ -19,6 +19,9 @@
are properly read and dealt with during project creation and persisting settings. are properly read and dealt with during project creation and persisting settings.
* build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java * 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 2003-08-14 John Camelon
Removed warnings from AutomatedIntegrationSuite.java (removing implicit accessor generation). Removed warnings from AutomatedIntegrationSuite.java (removing implicit accessor generation).

View file

@ -981,4 +981,23 @@ public class CompleteParseASTTest extends TestCase
IASTClassReference ref = (IASTClassReference)callback.getReferences().get(0); IASTClassReference ref = (IASTClassReference)callback.getReferences().get(0);
assertEquals( ref.getReferencedElement(), classA ); 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 );
}
} }

View file

@ -30,6 +30,11 @@
* build/org/eclipse/cdt/internal/core/build/managed/Option.java * build/org/eclipse/cdt/internal/core/build/managed/Option.java
* build/org/eclipse/cdt/internal/core/build/managed/OptionReference.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 2003-08-13 Sean Evoy
Changed text generated into makefile comments from the rather abstract Changed text generated into makefile comments from the rather abstract
term 'module' to the more meaningful 'subdirectory'. term 'module' to the more meaningful 'subdirectory'.

View file

@ -10,6 +10,8 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser.ast; package org.eclipse.cdt.core.parser.ast;
import java.util.List;
import org.eclipse.cdt.core.parser.Enum; import org.eclipse.cdt.core.parser.Enum;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
@ -122,7 +124,7 @@ public interface IASTExpression extends ISourceElementCallbackDelegate
public interface IASTNewExpressionDescriptor public interface IASTNewExpressionDescriptor
{ {
public List getExpressions();
} }

View file

@ -97,7 +97,7 @@ public interface IASTFactory
IToken id, IToken id,
ITokenDuple typeId, ITokenDuple typeId,
String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException; String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException;
public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(); public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List expressions);
public IASTInitializerClause createInitializerClause( public IASTInitializerClause createInitializerClause(
IASTInitializerClause.Kind kind, IASTInitializerClause.Kind kind,
IASTExpression assignmentExpression, IASTExpression assignmentExpression,

View file

@ -3531,6 +3531,9 @@ public class Parser implements IParser
boolean placementParseFailure = true; boolean placementParseFailure = true;
IToken beforeSecondParen = null; IToken beforeSecondParen = null;
IToken backtrackMarker = null; IToken backtrackMarker = null;
ITokenDuple typeId = null;
ArrayList expressions = new ArrayList();
if (LT(1) == IToken.tLPAREN) if (LT(1) == IToken.tLPAREN)
{ {
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
@ -3539,7 +3542,7 @@ public class Parser implements IParser
// Try to consume placement list // Try to consume placement list
// Note: since expressionList and expression are the same... // Note: since expressionList and expression are the same...
backtrackMarker = mark(); backtrackMarker = mark();
expression(scope); expressions.add(expression(scope));
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
placementParseFailure = false; placementParseFailure = false;
if (LT(1) == IToken.tLPAREN) if (LT(1) == IToken.tLPAREN)
@ -3558,7 +3561,7 @@ public class Parser implements IParser
// CASE: new (typeid-not-looking-as-placement) ... // CASE: new (typeid-not-looking-as-placement) ...
// the first expression in () is not a placement // the first expression in () is not a placement
// - then it has to be typeId // - then it has to be typeId
typeId(); typeId = typeId();
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
} }
else else
@ -3582,14 +3585,15 @@ public class Parser implements IParser
try try
{ {
backtrackMarker = mark(); backtrackMarker = mark();
typeId(); typeId = typeId();
} }
catch (Backtrack e) catch (Backtrack e)
{ {
// Hmmm, so it wasn't typeId after all... Then it is // Hmmm, so it wasn't typeId after all... Then it is
// CASE: new (typeid-looking-as-placement) // CASE: new (typeid-looking-as-placement)
backup(backtrackMarker); 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 // The problem is, the first expression might as well be a typeid
try try
{ {
typeId(); typeId = typeId();
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if (LT(1) == IToken.tLPAREN if (LT(1) == IToken.tLPAREN
|| LT(1) == IToken.tLBRACKET) || 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. // 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 // Luckily, we don't need to know what was that - we only know that
// new-expression ends here. // 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) catch (Backtrack e)
@ -3634,13 +3649,13 @@ public class Parser implements IParser
// CASE: new typeid ... // CASE: new typeid ...
// new parameters do not start with '(' // new parameters do not start with '('
// i.e it has to be a plain typeId // i.e it has to be a plain typeId
typeId(); typeId = typeId();
} }
while (LT(1) == IToken.tLBRACKET) while (LT(1) == IToken.tLBRACKET)
{ {
// array new // array new
consume(); consume();
assignmentExpression(scope); expressions.add(assignmentExpression(scope));
consume(IToken.tRBRACKET); consume(IToken.tRBRACKET);
} }
// newinitializer // newinitializer
@ -3648,10 +3663,21 @@ public class Parser implements IParser
{ {
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
if (LT(1) != IToken.tRPAREN) if (LT(1) != IToken.tRPAREN)
expression(scope); expressions.add(expression(scope));
consume(IToken.tRPAREN); 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, protected IASTExpression unaryOperatorCastExpression( IASTScope scope,
IASTExpression.Kind kind, IASTExpression.Kind kind,

View file

@ -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;
}
}

View file

@ -107,8 +107,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
result = startingScope.lookup( firstSymbol.getImage()); result = startingScope.lookup( firstSymbol.getImage());
if( result != null ) if( result != null )
references.add( createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() )); references.add( createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() ));
else //else
throw new ASTSemanticException(); // throw new ASTSemanticException();
} }
catch (ParserSymbolTableException e) catch (ParserSymbolTableException e)
{ {
@ -641,6 +641,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
getExpressionReferences(rhs, references); getExpressionReferences(rhs, references);
getExpressionReferences(thirdExpression,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 //look up id & add to references
IContainerSymbol startingScope = scopeToSymbol( scope ); IContainerSymbol startingScope = scopeToSymbol( scope );
@ -682,10 +690,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor() * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor()
*/ */
public IASTNewExpressionDescriptor createNewDescriptor() public IASTNewExpressionDescriptor createNewDescriptor(List expressions)
{ {
// TODO FIX THIS // TODO FIX THIS
return null; // return null;
return new ASTNewDescriptor(expressions);
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -10,6 +10,8 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.quick; package org.eclipse.cdt.internal.core.parser.ast.quick;
import java.util.List;
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; 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 { 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;
}
} }

View file

@ -155,7 +155,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor() * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor()
*/ */
public IASTNewExpressionDescriptor createNewDescriptor() { public IASTNewExpressionDescriptor createNewDescriptor(List expressions) {
return new ASTNewDescriptor(); return new ASTNewDescriptor();
} }