1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 08:45:44 +02:00

Cleaned up EXPRESSION_PARSE style expressions in the AST to be more space efficient.

This commit is contained in:
John Camelon 2004-05-05 20:10:46 +00:00
parent e86d9d4a94
commit 2c9b2f90fa
15 changed files with 472 additions and 94 deletions

View file

@ -18,6 +18,7 @@ import java.util.Map;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
import org.eclipse.cdt.core.parser.ast.IASTDesignator;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTScope;
@ -34,7 +35,8 @@ import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTypeId;
import org.eclipse.cdt.internal.core.parser.ast.complete.gcc.ASTGCCSimpleTypeSpecifier;
import org.eclipse.cdt.internal.core.parser.ast.expression.gcc.ASTGCCExpression;
import org.eclipse.cdt.internal.core.parser.ast.expression.ASTIdExpression;
import org.eclipse.cdt.internal.core.parser.ast.expression.ExpressionFactory;
import org.eclipse.cdt.internal.core.parser.ast.gcc.ASTGCCDesignator;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
@ -62,6 +64,34 @@ public class GCCASTExtension implements IASTFactoryExtension {
return true;
return false;
}
/**
* @param kind
* @param lhs
* @param rhs
* @param thirdExpression
* @param typeId
* @param string
* @param literal
* @param newDescriptor
* @return
*/
protected static IASTExpression createExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, String idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
if( !idExpression.equals( EMPTY_STRING ) && literal.equals( EMPTY_STRING ))
return new ASTIdExpression( kind, idExpression )
{
public int evaluateExpression() throws ASTExpressionEvaluationException {
if( getExpressionKind() == Kind.ID_EXPRESSION )
return 0;
return super.evaluateExpression();
}
};
return ExpressionFactory.createExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression, literal, newDescriptor );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#createExpression(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTTypeId, org.eclipse.cdt.core.parser.ITokenDuple, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor)
*/
@ -71,7 +101,7 @@ public class GCCASTExtension implements IASTFactoryExtension {
ITokenDuple idExpression, String literal,
IASTNewExpressionDescriptor newDescriptor)
{
return new ASTGCCExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor );//$NON-NLS-1$
return createExpression( kind, lhs, rhs, thirdExpression, typeId, (idExpression == null ) ? EMPTY_STRING : idExpression.toString(), literal, newDescriptor );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#canHandleExpressionKind(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind)

View file

@ -0,0 +1,40 @@
/**********************************************************************
* 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.expression;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*
*/
public class ASTBinaryExpression extends ASTUnaryExpression
implements
IASTExpression {
private final IASTExpression rhs;
/**
* @param kind
* @param lhs
* @param rhs
*/
public ASTBinaryExpression(Kind kind, IASTExpression lhs, IASTExpression rhs) {
super( kind, lhs );
this.rhs = rhs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getRHSExpression()
*/
public IASTExpression getRHSExpression() {
return rhs;
}
}

View file

@ -0,0 +1,41 @@
/**********************************************************************
* 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.expression;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*
*/
public class ASTConditionalExpression extends ASTBinaryExpression
implements
IASTExpression {
private final IASTExpression thirdExpression;
/**
* @param kind
* @param lhs
* @param rhs
* @param thirdExpression
*/
public ASTConditionalExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression) {
super( kind, lhs, rhs );
this.thirdExpression = thirdExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getThirdExpression()
*/
public IASTExpression getThirdExpression() {
return thirdExpression;
}
}

View file

@ -0,0 +1,28 @@
/**********************************************************************
* 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.expression;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*
*/
public class ASTEmptyExpression extends ASTExpression implements IASTExpression {
/**
* @param kind
*/
public ASTEmptyExpression(Kind kind) {
super(kind);
// TODO Auto-generated constructor stub
}
}

View file

@ -21,28 +21,14 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeId;
public class ASTExpression implements IASTExpression {
private final Kind kind;
private final IASTExpression lhs, rhs, third;
private final IASTTypeId typeId;
private final String literal, idExpression;
private final IASTNewExpressionDescriptor newDescriptor;
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
/**
* @param kind
* @param lhs
* @param rhs
* @param id
* @param typeId
* @param literal
*/
public ASTExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression third, IASTTypeId typeId, String idExpression, String literal, IASTNewExpressionDescriptor newDescriptor ) {
public ASTExpression(Kind kind ) {
this.kind = kind;
this.lhs =lhs;
this.rhs = rhs;
this.third = third;
this.typeId = typeId;
this.literal = literal;
this.newDescriptor = newDescriptor;
this.idExpression = idExpression;
}
/* (non-Javadoc)
@ -56,42 +42,42 @@ public class ASTExpression implements IASTExpression {
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLHSExpression()
*/
public IASTExpression getLHSExpression() {
return lhs;
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getRHSExpression()
*/
public IASTExpression getRHSExpression() {
return rhs;
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString()
*/
public String getLiteralString() {
return literal;
return EMPTY_STRING;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/
public IASTTypeId getTypeId() {
return typeId;
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor()
*/
public IASTNewExpressionDescriptor getNewExpressionDescriptor() {
return newDescriptor;
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getThirdExpression()
*/
public IASTExpression getThirdExpression() {
return third;
return null;
}
/* (non-Javadoc)
@ -199,7 +185,7 @@ public class ASTExpression implements IASTExpression {
*/
public String getIdExpression()
{
return idExpression;
return null;
}
/* (non-Javadoc)

View file

@ -0,0 +1,40 @@
/**********************************************************************
* 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.expression;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*
*/
public class ASTIdExpression extends ASTExpression implements IASTExpression {
private final String idExpression;
/**
* @param kind
* @param idExpression
*/
public ASTIdExpression(Kind kind, String idExpression) {
super(kind);
this.idExpression = idExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getIdExpression()
*/
public String getIdExpression() {
return idExpression;
}
}

View file

@ -0,0 +1,36 @@
/**********************************************************************
* 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.expression;
/**
* @author jcamelon
*
*/
public class ASTLiteralExpression extends ASTExpression {
private final String literal;
/**
* @param kind
* @param literal
*/
public ASTLiteralExpression(Kind kind, String literal) {
super( kind );
this.literal =literal;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString()
*/
public String getLiteralString() {
return literal;
}
}

View file

@ -0,0 +1,47 @@
/**********************************************************************
* 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.expression;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
/**
* @author jcamelon
*
*/
public class ASTNewExpression extends ASTExpression implements IASTExpression {
private final IASTNewExpressionDescriptor newDescriptor;
private final IASTTypeId typeId;
/**
* @param kind
* @param newDescriptor
* @param typeId
*/
public ASTNewExpression(Kind kind, IASTNewExpressionDescriptor newDescriptor, IASTTypeId typeId) {
super(kind);
this.newDescriptor = newDescriptor;
this.typeId = typeId;
}
/* (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#getTypeId()
*/
public IASTTypeId getTypeId() {
return typeId;
}
}

View file

@ -0,0 +1,42 @@
/**********************************************************************
* 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.expression;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
/**
* @author jcamelon
*
*/
public class ASTTypeIdExpression extends ASTExpression
implements
IASTExpression {
private final IASTTypeId typeId;
/**
* @param kind
* @param typeId
*/
public ASTTypeIdExpression(Kind kind, IASTTypeId typeId) {
super( kind );
this.typeId = typeId;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/
public IASTTypeId getTypeId() {
return typeId;
}
}

View file

@ -0,0 +1,37 @@
/**********************************************************************
* 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.expression;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*
*/
public class ASTUnaryExpression extends ASTExpression implements IASTExpression {
private final IASTExpression lhs;
/**
* @param kind
* @param lhs
*/
public ASTUnaryExpression(Kind kind, IASTExpression lhs) {
super(kind);
this.lhs = lhs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLHSExpression()
*/
public IASTExpression getLHSExpression() {
return lhs;
}
}

View file

@ -0,0 +1,43 @@
/**********************************************************************
* 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.expression;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
/**
* @author jcamelon
*
*/
public class ASTUnaryTypeIdExpression extends ASTUnaryExpression
implements
IASTExpression {
private final IASTTypeId typeId;
/**
* @param kind
* @param lhs
* @param typeId
*/
public ASTUnaryTypeIdExpression(Kind kind, IASTExpression lhs, IASTTypeId typeId) {
super( kind, lhs );
this.typeId = typeId;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/
public IASTTypeId getTypeId() {
return typeId;
}
}

View file

@ -0,0 +1,71 @@
/**********************************************************************
* 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.expression;
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 {
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
/**
*
*/
public ExpressionFactory() {
super();
// TODO Auto-generated constructor stub
}
/**
* @param kind
* @param lhs
* @param rhs
* @param thirdExpression
* @param typeId
* @param string
* @param literal
* @param newDescriptor
* @return
*/
public static IASTExpression createExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, String idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
if( !literal.equals( EMPTY_STRING ) && idExpression.equals( EMPTY_STRING )) //$NON-NLS-1$
return new ASTLiteralExpression( kind, literal );
if( !idExpression.equals( EMPTY_STRING ) )
return new ASTIdExpression( kind, idExpression );
if( thirdExpression != null )
return new ASTConditionalExpression( kind, lhs, rhs, thirdExpression );
if( newDescriptor != null )
return new ASTNewExpression( kind, newDescriptor, typeId );
if( lhs != null && rhs != null )
return new ASTBinaryExpression( kind, lhs, rhs );
if( lhs != null && typeId != null )
return new ASTUnaryTypeIdExpression( kind, lhs, typeId );
if( lhs != null )
return new ASTUnaryExpression( kind, lhs );
if( typeId != null )
return new ASTTypeIdExpression( kind, typeId );
return new ASTEmptyExpression( kind );
}
}

View file

@ -381,15 +381,7 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
throws ASTSemanticException {
if( extension.overrideCreateExpressionMethod() )
return extension.createExpression(scope, kind, lhs, rhs, thirdExpression, typeId, idExpression, literal, newDescriptor );
return new ASTExpression(
kind,
lhs,
rhs,
thirdExpression,
typeId,
idExpression == null ? "" : idExpression.toString(), //$NON-NLS-1$
literal,
newDescriptor );
return ExpressionFactory.createExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor ); //$NON-NLS-1$
}

View file

@ -1,47 +0,0 @@
/**********************************************************************
* 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.expression.gcc;
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.internal.core.parser.ast.expression.ASTExpression;
/**
* @author jcamelon
*
*/
public class ASTGCCExpression extends ASTExpression {
/**
* @param kind
* @param lhs
* @param rhs
* @param third
* @param typeId
* @param idExpression
* @param literal
* @param newDescriptor
*/
public ASTGCCExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression third, IASTTypeId typeId, String idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
super(kind, lhs, rhs, third, typeId, idExpression, literal, newDescriptor);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression()
*/
public int evaluateExpression() throws ASTExpressionEvaluationException {
if( getExpressionKind() == Kind.ID_EXPRESSION )
return 0;
return super.evaluateExpression();
}
}

View file

@ -60,7 +60,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension;
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
import org.eclipse.cdt.internal.core.parser.ast.expression.ASTExpression;
import org.eclipse.cdt.internal.core.parser.ast.expression.ExpressionFactory;
/**
@ -69,8 +69,6 @@ import org.eclipse.cdt.internal.core.parser.ast.expression.ASTExpression;
*/
public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory {
private static final boolean CREATE_EXCESS_CONSTRUCTS = true;
public QuickParseASTFactory( IASTFactoryExtension extension )
{
super(extension);
@ -159,18 +157,14 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.ExpressionKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String)
*/
public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
if( CREATE_EXCESS_CONSTRUCTS )
return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor ); //$NON-NLS-1$
return null;
return ExpressionFactory.createExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor ); //$NON-NLS-1$
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor()
*/
public IASTNewExpressionDescriptor createNewDescriptor(List newPlacementEpressions, List newTypeIdExpressions, List newInitializerExpressions) {
if( CREATE_EXCESS_CONSTRUCTS )
return new ASTNewDescriptor();
return null;
return new ASTNewDescriptor();
}
/* (non-Javadoc)
@ -341,9 +335,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
public IASTInitializerClause createInitializerClause(IASTScope scope, IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators)
{
if( CREATE_EXCESS_CONSTRUCTS )
return new ASTInitializerClause( kind, assignmentExpression, initializerClauses, designators );
return null;
return new ASTInitializerClause( kind, assignmentExpression, initializerClauses, designators );
}
/* (non-Javadoc)