diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java new file mode 100644 index 00000000000..077d8ecda3a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java @@ -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 ); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java new file mode 100644 index 00000000000..9a9eb795090 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java @@ -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 ); + } + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java new file mode 100644 index 00000000000..9ddd22dc1fe --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java @@ -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 ); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java index e784c73eb69..73747b52782 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java @@ -28,36 +28,21 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo; * @author jcamelon * */ -public class ASTExpression extends ASTNode implements IASTExpression +public abstract class ASTExpression extends ASTNode implements IASTExpression { private final Kind kind; - private final IASTExpression lhs; - 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 final List references; private ExpressionResult resultType; - private String stringRepresentation; + /** * */ - public ASTExpression( Kind kind, IASTExpression lhs, IASTExpression rhs, - IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor, List references ) + public ASTExpression( Kind kind, List references ) { 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.idExpressionDuple = idExpression; - this.idExpression = idExpressionDuple == null ? "" : idExpressionDuple.toString(); //$NON-NLS-1$ } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getExpressionKind() */ @@ -65,56 +50,6 @@ public class ASTExpression extends ASTNode implements IASTExpression { 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) * @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression() */ @@ -143,20 +78,7 @@ public class ASTExpression extends ASTNode implements IASTExpression if( ! references.isEmpty() ) new ASTReferenceStore( references ).processReferences(requestor); - if( typeId != null ) - 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); + processCallbacks(requestor); 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) */ public void enterScope(ISourceElementRequestor requestor) @@ -194,36 +123,13 @@ public class ASTExpression extends ASTNode implements IASTExpression public void setResultType(ExpressionResult 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) * @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences() */ 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) { if( subExpression != null && subExpression.getReferences() != null ) @@ -237,22 +143,14 @@ public class ASTExpression extends ASTNode implements IASTExpression } } } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences() */ 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) { if( subExpression != null && subExpression.getReferences() != null ) @@ -262,56 +160,15 @@ public class ASTExpression extends ASTNode implements IASTExpression } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - if( stringRepresentation == null ) - { - 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; + protected String getStringPrefix() + { + StringBuffer buffer = new StringBuffer(); + buffer.append( "ASTExpression w/Kind=" ); //$NON-NLS-1$ + buffer.append( kind.getKindName() ); + return buffer.toString(); } + public IContainerSymbol getLookupQualificationSymbol() throws LookupError { ExpressionResult result = getResultType(); TypeInfo type = (result != null ) ? result.getResult() : null; @@ -326,7 +183,7 @@ public class ASTExpression extends ASTNode implements IASTExpression } return null; - } + } public boolean shouldFilterLookupResult( ISymbol symbol ){ ExpressionResult result = getResultType(); @@ -349,32 +206,28 @@ public class ASTExpression extends ASTNode implements IASTExpression * @return */ public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { - if( isIDExpressionForDuple( lhs, duple ) || isIDExpressionForDuple(rhs, duple) || isIDExpressionForDuple(thirdExpression, duple)) - 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; + return null; } /** * @param duple * @return */ - private ASTExpression recursiveFindExpressionForDuple(IASTExpression expression, ITokenDuple duple) { + protected ASTExpression recursiveFindExpressionForDuple(IASTExpression expression, ITokenDuple duple) { if( expression == null ) return null; 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.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION && - expression instanceof ASTExpression ) + expression instanceof ASTIdExpression ) { - ITokenDuple expressionDuple = ((ASTExpression)expression).getIdExpressionTokenDuple(); + ITokenDuple expressionDuple = ((ASTIdExpression)expression).getIdExpressionTokenDuple(); // check equality if( expressionDuple.equals( duple ) ) return true; @@ -384,4 +237,34 @@ public class ASTExpression extends ASTNode implements IASTExpression } 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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java new file mode 100644 index 00000000000..3ae2cfbc290 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java @@ -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; + } + + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java new file mode 100644 index 00000000000..1dd7aa2d6c8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java @@ -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; + } +} 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 new file mode 100644 index 00000000000..bee0dd52d97 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java @@ -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); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java new file mode 100644 index 00000000000..b8e9e88318b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java @@ -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); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java new file mode 100644 index 00000000000..4e1a93245a6 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java @@ -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 ); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java new file mode 100644 index 00000000000..96f6fa74b35 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java @@ -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 ); + } + +} 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 ebb21a09f45..23d63123d02 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 @@ -1080,9 +1080,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto // assert expressionResult != null : expressionResult; //throw new ASTSemanticException(); // create the ASTExpression - ASTExpression expression = new ASTExpression( kind, lhs, rhs, thirdExpression, - typeId, idExpression, literal, newDescriptor, references); - + ASTExpression expression = ExpressionFactory.createExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression, literal, newDescriptor, references ); // Assign the result to the created expression 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 "->" IContainerSymbol searchScope = getSearchScope(kind, lhs, 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 // 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 */ private ITokenDuple getFunctionId (IASTExpression expression){ - if(expression.getExpressionKind().isPostfixMemberReference() ) - return ((ASTExpression)expression.getRHSExpression()).getIdExpressionTokenDuple(); - else - return ((ASTExpression)expression).getIdExpressionTokenDuple(); + if(expression.getExpressionKind().isPostfixMemberReference() && expression.getRHSExpression() instanceof ASTIdExpression ) + return ((ASTIdExpression)expression.getRHSExpression()).getIdExpressionTokenDuple(); + else if( expression instanceof ASTIdExpression ) + return ((ASTIdExpression)expression).getIdExpressionTokenDuple(); + return null; } 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) { try { - return lookupSymbolInContext(scope, ((ASTExpression)expression).getIdExpressionTokenDuple(), null); + return lookupSymbolInContext(scope, ((ASTIdExpression)expression).getIdExpressionTokenDuple(), null); } catch (ASTNotImplementedException e) { // assert false : e; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java new file mode 100644 index 00000000000..3ad05e16856 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java @@ -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 ); + } +}