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

Made ASTExpression more polymorphic to improve our footprint in COMPLETE_PARSE mode.

This commit is contained in:
John Camelon 2004-05-03 18:26:27 +00:00
parent 580e67dcec
commit 025a94c662
12 changed files with 645 additions and 190 deletions

View file

@ -0,0 +1,83 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation 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:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*
*/
public class ASTBinaryExpression extends ASTUnaryExpression {
private final IASTExpression rhs;
/**
* @param kind
* @param references
* @param lhs
*/
public ASTBinaryExpression(Kind kind, List references, IASTExpression lhs, IASTExpression rhs) {
super(kind, references, lhs);
this.rhs = rhs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getRHSExpression()
*/
public IASTExpression getRHSExpression() {
return rhs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#findOwnerExpressionForIDExpression(org.eclipse.cdt.core.parser.ITokenDuple)
*/
public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) {
if( isIDExpressionForDuple( rhs, duple ) )
return this;
ASTExpression result = recursiveFindExpressionForDuple(rhs, duple);
if( result != null )
return result;
return super.findOwnerExpressionForIDExpression(duple);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences()
*/
public void purgeReferences() throws ASTNotImplementedException {
super.purgeReferences();
rhs.purgeReferences();
purgeSubExpression( (ASTExpression) rhs );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences()
*/
public void reconcileReferences() throws ASTNotImplementedException {
super.reconcileReferences();
rhs.reconcileReferences();
reconcileSubExpression((ASTExpression) rhs);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks()
*/
protected void processCallbacks( ISourceElementRequestor requestor ) {
super.processCallbacks(requestor);
rhs.acceptElement( requestor );
}
}

View file

@ -0,0 +1,87 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation 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:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*
*/
public class ASTConditionalExpression extends ASTBinaryExpression {
private final IASTExpression thirdExpression;
/**
* @param kind
* @param references
* @param lhs
* @param rhs
*/
public ASTConditionalExpression(Kind kind, List references,
IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression) {
super(kind, references, lhs, rhs);
this.thirdExpression = thirdExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getThirdExpression()
*/
public IASTExpression getThirdExpression() {
return thirdExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#findOwnerExpressionForIDExpression(org.eclipse.cdt.core.parser.ITokenDuple)
*/
public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) {
if( isIDExpressionForDuple( thirdExpression, duple ) )
return this;
ASTExpression result = recursiveFindExpressionForDuple(thirdExpression, duple);
if( result != null )
return result;
return super.findOwnerExpressionForIDExpression(duple);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences()
*/
public void purgeReferences() throws ASTNotImplementedException {
super.purgeReferences();
thirdExpression.purgeReferences();
purgeSubExpression( (ASTExpression) thirdExpression );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences()
*/
public void reconcileReferences() throws ASTNotImplementedException {
super.reconcileReferences();
thirdExpression.reconcileReferences();
reconcileSubExpression((ASTExpression) thirdExpression);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks()
*/
protected void processCallbacks( ISourceElementRequestor requestor ) {
super.processCallbacks(requestor);
thirdExpression.acceptElement( requestor );
}
}

View file

@ -0,0 +1,27 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation 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:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
/**
* @author jcamelon
*
*/
public class ASTEmptyExpression extends ASTExpression {
/**
* @param kind
* @param references
*/
public ASTEmptyExpression(Kind kind, List references) {
super( kind, references );
}
}

View file

@ -28,36 +28,21 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
* @author jcamelon * @author jcamelon
* *
*/ */
public class ASTExpression extends ASTNode implements IASTExpression public abstract class ASTExpression extends ASTNode implements IASTExpression
{ {
private final Kind kind; private final Kind kind;
private final IASTExpression lhs; private final List references;
private final IASTExpression rhs;
private final IASTExpression thirdExpression;
private final String literal, idExpression;
private ITokenDuple idExpressionDuple;
private final IASTTypeId typeId;
private final IASTNewExpressionDescriptor newDescriptor;
private final List references;
private ExpressionResult resultType; private ExpressionResult resultType;
private String stringRepresentation;
/** /**
* *
*/ */
public ASTExpression( Kind kind, IASTExpression lhs, IASTExpression rhs, public ASTExpression( Kind kind, List references )
IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor, List references )
{ {
this.kind = kind; this.kind = kind;
this.lhs = lhs;
this.rhs = rhs;
this.thirdExpression = thirdExpression;
this.literal = literal;
this.typeId = typeId;
this.newDescriptor = newDescriptor;
this.references = references; this.references = references;
this.idExpressionDuple = idExpression;
this.idExpression = idExpressionDuple == null ? "" : idExpressionDuple.toString(); //$NON-NLS-1$
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getExpressionKind() * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getExpressionKind()
*/ */
@ -65,56 +50,6 @@ public class ASTExpression extends ASTNode implements IASTExpression
{ {
return kind; return kind;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLHSExpression()
*/
public IASTExpression getLHSExpression()
{
return lhs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getRHSExpression()
*/
public IASTExpression getRHSExpression()
{
return rhs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getThirdExpression()
*/
public IASTExpression getThirdExpression()
{
return thirdExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString()
*/
public String getLiteralString()
{
return literal;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/
public IASTTypeId getTypeId()
{
return typeId;
}
/*
* returns the type id token
*/
public ITokenDuple getTypeIdTokenDuple()
{
if( typeId == null ) return null;
return ((ASTTypeId)typeId).getTokenDuple();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor()
*/
public IASTNewExpressionDescriptor getNewExpressionDescriptor()
{
return newDescriptor;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression() * @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression()
*/ */
@ -143,20 +78,7 @@ public class ASTExpression extends ASTNode implements IASTExpression
if( ! references.isEmpty() ) if( ! references.isEmpty() )
new ASTReferenceStore( references ).processReferences(requestor); new ASTReferenceStore( references ).processReferences(requestor);
if( typeId != null ) processCallbacks(requestor);
typeId.acceptElement(requestor);
if( lhs != null )
lhs.acceptElement(requestor);
if( rhs!= null )
rhs.acceptElement(requestor);
if( thirdExpression != null )
thirdExpression.acceptElement(requestor);
if( newDescriptor != null )
newDescriptor.acceptElement(requestor);
try try
{ {
@ -168,7 +90,14 @@ public class ASTExpression extends ASTNode implements IASTExpression
} }
} }
/* (non-Javadoc) /**
* @param requestor TODO
*
*/
protected void processCallbacks(ISourceElementRequestor requestor) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/ */
public void enterScope(ISourceElementRequestor requestor) public void enterScope(ISourceElementRequestor requestor)
@ -194,36 +123,13 @@ public class ASTExpression extends ASTNode implements IASTExpression
public void setResultType(ExpressionResult i) { public void setResultType(ExpressionResult i) {
resultType = i; resultType = i;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getIdExpression()
*/
public String getIdExpression()
{
return idExpression;
}
/**
* @return
*/
public ITokenDuple getIdExpressionTokenDuple()
{
return idExpressionDuple;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences() * @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences()
*/ */
public void reconcileReferences() throws ASTNotImplementedException public void reconcileReferences() throws ASTNotImplementedException
{ {
if( lhs != null )
lhs.reconcileReferences();
if( rhs != null )
rhs.reconcileReferences();
if( thirdExpression != null )
thirdExpression.reconcileReferences();
reconcileSubExpression((ASTExpression)lhs);
reconcileSubExpression((ASTExpression)rhs);
reconcileSubExpression((ASTExpression)thirdExpression);
} }
protected void reconcileSubExpression(ASTExpression subExpression) protected void reconcileSubExpression(ASTExpression subExpression)
{ {
if( subExpression != null && subExpression.getReferences() != null ) if( subExpression != null && subExpression.getReferences() != null )
@ -237,22 +143,14 @@ public class ASTExpression extends ASTNode implements IASTExpression
} }
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences() * @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences()
*/ */
public void purgeReferences() throws ASTNotImplementedException public void purgeReferences() throws ASTNotImplementedException
{ {
if( lhs != null )
lhs.purgeReferences();
if( rhs != null )
rhs.purgeReferences();
if( thirdExpression != null )
thirdExpression.purgeReferences();
purgeSubExpression((ASTExpression)lhs);
purgeSubExpression((ASTExpression)rhs);
purgeSubExpression((ASTExpression)thirdExpression);
} }
protected void purgeSubExpression(ASTExpression subExpression) protected void purgeSubExpression(ASTExpression subExpression)
{ {
if( subExpression != null && subExpression.getReferences() != null ) if( subExpression != null && subExpression.getReferences() != null )
@ -262,56 +160,15 @@ public class ASTExpression extends ASTNode implements IASTExpression
} }
protected String getStringPrefix()
/* (non-Javadoc) {
* @see java.lang.Object#toString() StringBuffer buffer = new StringBuffer();
*/ buffer.append( "ASTExpression w/Kind=" ); //$NON-NLS-1$
public String toString() { buffer.append( kind.getKindName() );
if( stringRepresentation == null ) return buffer.toString();
{
StringBuffer buffer = new StringBuffer();
buffer.append( "ASTExpression w/Kind=" ); //$NON-NLS-1$
buffer.append( kind.getKindName() );
if( !literal.equals( "" )) //$NON-NLS-1$
{
buffer.append( " LITERAL="); //$NON-NLS-1$
buffer.append( literal );
}
if( idExpressionDuple != null )
{
buffer.append( " IDEXPRESSION="); //$NON-NLS-1$
buffer.append( idExpressionDuple.toString() );
}
if( typeId != null )
{
buffer.append( " TYPEID="); //$NON-NLS-1$
buffer.append( typeId.getFullSignature() );
}
if( lhs != null )
{
buffer.append( "\n\tLHS=**"); //$NON-NLS-1$
buffer.append( lhs.toString() );
buffer.append( "**");//$NON-NLS-1$
}
if( rhs != null )
{
buffer.append( "\n\tRHS=="); //$NON-NLS-1$
buffer.append( rhs.toString() );
buffer.append( "==");//$NON-NLS-1$
}
if( thirdExpression != null )
{
buffer.append( "\n\t3rd Expression =::"); //$NON-NLS-1$
buffer.append( thirdExpression.toString() );
buffer.append( "::");//$NON-NLS-1$
}
stringRepresentation = buffer.toString();
}
return stringRepresentation;
} }
public IContainerSymbol getLookupQualificationSymbol() throws LookupError { public IContainerSymbol getLookupQualificationSymbol() throws LookupError {
ExpressionResult result = getResultType(); ExpressionResult result = getResultType();
TypeInfo type = (result != null ) ? result.getResult() : null; TypeInfo type = (result != null ) ? result.getResult() : null;
@ -326,7 +183,7 @@ public class ASTExpression extends ASTNode implements IASTExpression
} }
return null; return null;
} }
public boolean shouldFilterLookupResult( ISymbol symbol ){ public boolean shouldFilterLookupResult( ISymbol symbol ){
ExpressionResult result = getResultType(); ExpressionResult result = getResultType();
@ -349,32 +206,28 @@ public class ASTExpression extends ASTNode implements IASTExpression
* @return * @return
*/ */
public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) {
if( isIDExpressionForDuple( lhs, duple ) || isIDExpressionForDuple(rhs, duple) || isIDExpressionForDuple(thirdExpression, duple)) return null;
return this;
ASTExpression result = recursiveFindExpressionForDuple(lhs, duple);
if( result != null ) return result;
result = recursiveFindExpressionForDuple(rhs, duple);
if( result != null ) return result;
result = recursiveFindExpressionForDuple(thirdExpression, duple);
return result;
} }
/** /**
* @param duple * @param duple
* @return * @return
*/ */
private ASTExpression recursiveFindExpressionForDuple(IASTExpression expression, ITokenDuple duple) { protected ASTExpression recursiveFindExpressionForDuple(IASTExpression expression, ITokenDuple duple) {
if( expression == null ) return null; if( expression == null ) return null;
return ((ASTExpression)expression).findOwnerExpressionForIDExpression(duple); return ((ASTExpression)expression).findOwnerExpressionForIDExpression(duple);
} }
protected boolean isIDExpressionForDuple( IASTExpression expression, ITokenDuple duple ) /* (non-Javadoc)
{ * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#isIDExpressionForDuple(org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ITokenDuple)
*/
protected boolean isIDExpressionForDuple(IASTExpression expression,
ITokenDuple duple) {
if( expression == null ) return false; if( expression == null ) return false;
if( expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION && if( expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION &&
expression instanceof ASTExpression ) expression instanceof ASTIdExpression )
{ {
ITokenDuple expressionDuple = ((ASTExpression)expression).getIdExpressionTokenDuple(); ITokenDuple expressionDuple = ((ASTIdExpression)expression).getIdExpressionTokenDuple();
// check equality // check equality
if( expressionDuple.equals( duple ) ) if( expressionDuple.equals( duple ) )
return true; return true;
@ -384,4 +237,34 @@ public class ASTExpression extends ASTNode implements IASTExpression
} }
return false; return false;
} }
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
public IASTExpression getLHSExpression() {
return null;
}
public IASTExpression getRHSExpression() {
return null;
}
public IASTExpression getThirdExpression() {
return null;
}
public String getLiteralString() {
return EMPTY_STRING;
}
public String getIdExpression() {
return EMPTY_STRING;
}
public IASTTypeId getTypeId() {
return null;
}
public IASTNewExpressionDescriptor getNewExpressionDescriptor() {
return null;
}
} }

View file

@ -0,0 +1,49 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation 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:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ITokenDuple;
/**
* @author jcamelon
*
*/
public class ASTIdExpression extends ASTExpression {
private ITokenDuple idExpression;
private String idExpressionValue;
/**
* @param kind
* @param references
*/
public ASTIdExpression(Kind kind, List references, ITokenDuple idExpression) {
super(kind, references);
this.idExpression = idExpression;
idExpressionValue = idExpression.toString();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getIdExpression()
*/
public String getIdExpression() {
return idExpressionValue;
}
public ITokenDuple getIdExpressionTokenDuple()
{
return idExpression;
}
}

View file

@ -0,0 +1,38 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation 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:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
/**
* @author jcamelon
*
*/
public class ASTLiteralExpression extends ASTExpression {
private final String literal;
/**
* @param kind
* @param references
*/
public ASTLiteralExpression(Kind kind, List references, String literal) {
super(kind, references);
this.literal = literal;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString()
*/
public String getLiteralString() {
return literal;
}
}

View file

@ -0,0 +1,61 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation 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:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
/**
* @author jcamelon
*
*/
public class ASTNewExpression extends ASTExpression {
private final IASTTypeId typeId;
private final IASTNewExpressionDescriptor newDescriptor;
/**
* @param kind
* @param references
* @param newDescriptor
* @param typeId
*/
public ASTNewExpression(Kind kind, List references, IASTNewExpressionDescriptor newDescriptor, IASTTypeId typeId) {
super( kind, references );
this.newDescriptor = newDescriptor;
this.typeId = typeId;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/
public IASTTypeId getTypeId() {
return typeId;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor()
*/
public IASTNewExpressionDescriptor getNewExpressionDescriptor() {
return newDescriptor;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
protected void processCallbacks(ISourceElementRequestor requestor) {
super.processCallbacks(requestor);
typeId.acceptElement(requestor);
newDescriptor.acceptElement(requestor);
}
}

View file

@ -0,0 +1,44 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation 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:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
/**
* @author jcamelon
*
*/
public class ASTTypeIdExpression extends ASTExpression {
private final IASTTypeId typeId;
/**
* @param kind
* @param references
* @param typeId
*/
public ASTTypeIdExpression(Kind kind, List references, IASTTypeId typeId) {
super( kind, references );
this.typeId = typeId;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/
public IASTTypeId getTypeId() {
return typeId;
}
protected void processCallbacks(ISourceElementRequestor requestor) {
super.processCallbacks(requestor);
typeId.acceptElement(requestor);
}
}

View file

@ -0,0 +1,77 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation 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:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*
*/
public class ASTUnaryExpression extends ASTExpression {
private final IASTExpression lhs;
/**
* @param kind
* @param references
*/
public ASTUnaryExpression(Kind kind, List references, IASTExpression lhs ) {
super(kind, references);
this.lhs = lhs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLHSExpression()
*/
public IASTExpression getLHSExpression() {
return lhs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#findOwnerExpressionForIDExpression(org.eclipse.cdt.core.parser.ITokenDuple)
*/
public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) {
if( isIDExpressionForDuple( lhs, duple ) )
return this;
ASTExpression result = recursiveFindExpressionForDuple(lhs, duple);
return result;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences()
*/
public void reconcileReferences() throws ASTNotImplementedException {
lhs.reconcileReferences();
reconcileSubExpression((ASTExpression) lhs);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences()
*/
public void purgeReferences() throws ASTNotImplementedException {
lhs.purgeReferences();
purgeSubExpression( (ASTExpression) lhs );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks()
*/
protected void processCallbacks( ISourceElementRequestor requestor ) {
super.processCallbacks(requestor);
lhs.acceptElement( requestor );
}
}

View file

@ -0,0 +1,52 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation 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:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
/**
* @author jcamelon
*
*/
public class ASTUnaryTypeIdExpression extends ASTUnaryExpression {
private final IASTTypeId typeId;
/**
* @param kind
* @param references
* @param lhs
*/
public ASTUnaryTypeIdExpression(Kind kind, List references, IASTExpression lhs, IASTTypeId typeId) {
super(kind, references, lhs);
this.typeId = typeId;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/
public IASTTypeId getTypeId() {
return typeId;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks()
*/
protected void processCallbacks( ISourceElementRequestor requestor ) {
super.processCallbacks(requestor);
typeId.acceptElement( requestor );
}
}

View file

@ -1080,9 +1080,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
// assert expressionResult != null : expressionResult; //throw new ASTSemanticException(); // assert expressionResult != null : expressionResult; //throw new ASTSemanticException();
// create the ASTExpression // create the ASTExpression
ASTExpression expression = new ASTExpression( kind, lhs, rhs, thirdExpression, ASTExpression expression = ExpressionFactory.createExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression, literal, newDescriptor, references );
typeId, idExpression, literal, newDescriptor, references);
// Assign the result to the created expression // Assign the result to the created expression
expression.setResultType (expressionResult); expression.setResultType (expressionResult);
@ -1134,7 +1132,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
// If the expression is lookup symbol if it is in the scope of a type after a "." or an "->" // If the expression is lookup symbol if it is in the scope of a type after a "." or an "->"
IContainerSymbol searchScope = getSearchScope(kind, lhs, startingScope); IContainerSymbol searchScope = getSearchScope(kind, lhs, startingScope);
if ( searchScope != null && !searchScope.equals(startingScope)) if ( searchScope != null && !searchScope.equals(startingScope))
symbol = lookupQualifiedName(searchScope, ((ASTExpression)rhs).getIdExpressionTokenDuple(), references, false, LookupType.QUALIFIED ); symbol = lookupQualifiedName(searchScope, ((ASTIdExpression)rhs).getIdExpressionTokenDuple(), references, false, LookupType.QUALIFIED );
// get symbol if it is the "this" pointer // get symbol if it is the "this" pointer
// go up the scope until you hit a class // go up the scope until you hit a class
@ -1175,10 +1173,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
* Returns the function ID token * Returns the function ID token
*/ */
private ITokenDuple getFunctionId (IASTExpression expression){ private ITokenDuple getFunctionId (IASTExpression expression){
if(expression.getExpressionKind().isPostfixMemberReference() ) if(expression.getExpressionKind().isPostfixMemberReference() && expression.getRHSExpression() instanceof ASTIdExpression )
return ((ASTExpression)expression.getRHSExpression()).getIdExpressionTokenDuple(); return ((ASTIdExpression)expression.getRHSExpression()).getIdExpressionTokenDuple();
else else if( expression instanceof ASTIdExpression )
return ((ASTExpression)expression).getIdExpressionTokenDuple(); return ((ASTIdExpression)expression).getIdExpressionTokenDuple();
return null;
} }
private IContainerSymbol getSearchScope (Kind kind, IASTExpression lhs, IContainerSymbol startingScope) throws ASTSemanticException{ private IContainerSymbol getSearchScope (Kind kind, IASTExpression lhs, IContainerSymbol startingScope) throws ASTSemanticException{
@ -3379,7 +3378,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( expression instanceof ASTExpression) if( expression instanceof ASTExpression)
{ {
try { try {
return lookupSymbolInContext(scope, ((ASTExpression)expression).getIdExpressionTokenDuple(), null); return lookupSymbolInContext(scope, ((ASTIdExpression)expression).getIdExpressionTokenDuple(), null);
} catch (ASTNotImplementedException e) { } catch (ASTNotImplementedException e) {
// assert false : e; // assert false : e;
} }

View file

@ -0,0 +1,55 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation 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:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
/**
* @author jcamelon
*
*/
public class ExpressionFactory {
public static ASTExpression createExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor, List references )
{
if( !literal.equals( "") && idExpression == null ) //$NON-NLS-1$
return new ASTLiteralExpression( kind, references, literal );
if( idExpression != null )
return new ASTIdExpression( kind, references, idExpression );
if( thirdExpression != null )
return new ASTConditionalExpression( kind, references, lhs, rhs, thirdExpression );
if( newDescriptor != null )
return new ASTNewExpression( kind, references, newDescriptor, typeId );
if( lhs != null && rhs != null )
return new ASTBinaryExpression( kind, references, lhs, rhs );
if( lhs != null && typeId != null )
return new ASTUnaryTypeIdExpression( kind, references, lhs, typeId );
if( lhs != null )
return new ASTUnaryExpression( kind, references, lhs );
if( typeId != null )
return new ASTTypeIdExpression( kind, references, typeId );
return new ASTEmptyExpression( kind, references );
}
}