1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

Patch for Hoda Amer

Core: 
        - Changed the ASTExpression of the complete package to store the 
        whole ITokenDuple for the typeId instead of just the string. 
        - Changed the ASTExpression in both quick and complete packages and 
        deleted the "id" parameter. 
        - Added partial solution to bug #42453: Exception result types not computed. 
        Now they are computed for simple types only. 
Tests: 
        Call to ASTExpression getTypeId() changed to getTypeIdString(). 
UI: 
         Solution to bug#42414 :Extraneous semi-colons in generated class methods
This commit is contained in:
John Camelon 2003-09-04 14:39:20 +00:00
parent 5022fcb844
commit 1c6c93560a
12 changed files with 156 additions and 102 deletions

View file

@ -1,3 +1,6 @@
2003-09-04 Hoda Amer
Call to ASTExpression getTypeId() changed to getTypeIdString().
2003-09-03 Andrew Niefer
Modified ParserSymbolTableTest.testConstructors to test > 2 constructors

View file

@ -1429,7 +1429,7 @@ public class QuickParseASTTests extends BaseASTTest
assertFalse( enumerators.hasNext() );
assertEquals( enumerator.getName(), "isPointer");
assertEquals( enumerator.getInitialValue().getExpressionKind(), IASTExpression.Kind.ID_EXPRESSION );
assertEquals( enumerator.getInitialValue().getTypeId(), "PointerTraits<T>::result");
assertEquals( enumerator.getInitialValue().getTypeIdString(), "PointerTraits<T>::result");
}
public void testBug36690() throws Exception {

View file

@ -1,3 +1,11 @@
2003-09-04 Hoda Amer
- Changed the ASTExpression of the complete package to store the
whole ITOkenDuple for the typeId instead of just the string.
- Changed the ASTExpression in both quick and complete packages and
deleted the "id" parameter.
- Added partial solution to bug #42453: Exception result types not computed.
Now they are computed for simple types only.
2003-09-03 David Inglis
Added shared preference key for error parsers

View file

@ -119,7 +119,7 @@ public interface IASTExpression extends ISourceElementCallbackDelegate
{
super(enumValue);
}
}
public interface IASTNewExpressionDescriptor
@ -136,8 +136,7 @@ public interface IASTExpression extends ISourceElementCallbackDelegate
public IASTExpression getRHSExpression();
public IASTExpression getThirdExpression();
public String getLiteralString();
public String getTypeId();
public String getId();
public String getTypeIdString();
public IASTNewExpressionDescriptor getNewExpressionDescriptor();
public int evaluateExpression() throws ExpressionEvaluationException;

View file

@ -103,7 +103,6 @@ public interface IASTFactory
IASTExpression lhs,
IASTExpression rhs,
IASTExpression thirdExpression,
IToken id,
ITokenDuple typeId,
String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException;
public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions);

View file

@ -2743,7 +2743,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -2827,7 +2826,6 @@ public class Parser implements IParser
null,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -2861,7 +2859,6 @@ public class Parser implements IParser
null,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -2894,7 +2891,6 @@ public class Parser implements IParser
secondExpression,
thirdExpression,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -2929,7 +2925,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -2962,7 +2957,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -2996,7 +2990,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3030,7 +3023,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3063,7 +3055,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3104,7 +3095,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3181,7 +3171,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3225,7 +3214,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3268,7 +3256,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3322,7 +3309,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3364,7 +3350,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3413,7 +3398,6 @@ public class Parser implements IParser
castExpression,
null,
null,
null,
duple,
"", null);
}
@ -3527,7 +3511,6 @@ public class Parser implements IParser
null,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3660,7 +3643,7 @@ public class Parser implements IParser
{
return astFactory.createExpression(
scope, IASTExpression.Kind.NEW_TYPEID,
null, null, null, null, typeId, "",
null, null, null, typeId, "",
astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions));
}
catch (ASTSemanticException e)
@ -3705,7 +3688,7 @@ public class Parser implements IParser
{
return astFactory.createExpression(
scope, IASTExpression.Kind.NEW_TYPEID,
null, null, null, null, typeId, "",
null, null, null, typeId, "",
astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions));
}
catch (ASTSemanticException e)
@ -3729,7 +3712,6 @@ public class Parser implements IParser
null,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -3811,7 +3793,6 @@ public class Parser implements IParser
null,
null,
null,
null,
d,
"", null);
}
@ -3830,7 +3811,6 @@ public class Parser implements IParser
null,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e1)
@ -3970,7 +3950,6 @@ public class Parser implements IParser
lhs,
null,
null,
null,
typeId,
"", null);
}
@ -4002,7 +3981,6 @@ public class Parser implements IParser
firstExpression,
secondExpression,
null,
null,
null,
"", null);
}
@ -4027,7 +4005,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e3)
@ -4048,7 +4025,6 @@ public class Parser implements IParser
null,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e1)
@ -4069,7 +4045,6 @@ public class Parser implements IParser
null,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e4)
@ -4099,7 +4074,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e5)
@ -4129,7 +4103,6 @@ public class Parser implements IParser
secondExpression,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -4163,7 +4136,6 @@ public class Parser implements IParser
null,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -4189,7 +4161,6 @@ public class Parser implements IParser
null,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e)
@ -4220,7 +4191,6 @@ public class Parser implements IParser
null,
null,
null,
null,
t.getImage(), null);
}
catch (ASTSemanticException e1)
@ -4239,7 +4209,6 @@ public class Parser implements IParser
null,
null,
null,
null,
t.getImage(), null);
}
catch (ASTSemanticException e2)
@ -4252,7 +4221,7 @@ public class Parser implements IParser
t = consume();
try
{
return astFactory.createExpression( scope, IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, null, null, null, null, t.getImage(), null );
return astFactory.createExpression( scope, IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, null, null, null, t.getImage(), null );
}
catch (ASTSemanticException e5)
{
@ -4270,7 +4239,6 @@ public class Parser implements IParser
IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL,
null,
null,
null,
null,
null,
t.getImage(), null);
@ -4294,7 +4262,6 @@ public class Parser implements IParser
null,
null,
null,
null,
t.getImage(), null);
}
catch (ASTSemanticException e4)
@ -4314,7 +4281,6 @@ public class Parser implements IParser
null,
null,
null,
null,
"", null);
}
catch (ASTSemanticException e7)
@ -4334,7 +4300,6 @@ public class Parser implements IParser
lhs,
null,
null,
null,
null,
"", null);
}
@ -4353,7 +4318,6 @@ public class Parser implements IParser
IASTExpression.Kind.ID_EXPRESSION,
null,
null,
null,
null,
duple,
"", null);
@ -4371,7 +4335,6 @@ public class Parser implements IParser
IASTExpression.Kind.PRIMARY_EMPTY,
null,
null,
null,
null,
null,
"", null);

View file

@ -10,9 +10,11 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
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.ExpressionEvaluationException;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
@ -27,15 +29,15 @@ public class ASTExpression implements IASTExpression
private final IASTExpression rhs;
private final IASTExpression thirdExpression;
private final String literal;
private final String typeId;
private final String id;
private final ITokenDuple typeId;
private final IASTNewExpressionDescriptor newDescriptor;
private final List references;
private List resultType;
/**
*
*/
public ASTExpression( Kind kind, IASTExpression lhs, IASTExpression rhs,
IASTExpression thirdExpression, String literal, String typeId, String id, IASTNewExpressionDescriptor newDescriptor, List references )
IASTExpression thirdExpression, ITokenDuple typeId, String literal, IASTNewExpressionDescriptor newDescriptor, List references )
{
this.kind = kind;
this.lhs = lhs;
@ -43,9 +45,9 @@ public class ASTExpression implements IASTExpression
this.thirdExpression = thirdExpression;
this.literal = literal;
this.typeId = typeId;
this.id = id;
this.newDescriptor = newDescriptor;
this.references = references;
resultType = new ArrayList();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getExpressionKind()
@ -85,16 +87,16 @@ public class ASTExpression implements IASTExpression
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/
public String getTypeId()
public String getTypeIdString()
{
return typeId;
return typeId == null ? "" : typeId.toString();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getId()
/*
* returns the type id token
*/
public String getId()
public ITokenDuple getTypeId()
{
return id;
return typeId;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor()
@ -139,4 +141,18 @@ public class ASTExpression implements IASTExpression
{
}
/**
* @return
*/
public List getResultType() {
return resultType;
}
/**
* @param i
*/
public void setResultType(List i) {
resultType = i;
}
}

View file

@ -126,7 +126,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
}
protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, ITokenDuple name, List references, boolean throwOnError ) throws ASTSemanticException
protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, ITokenDuple name, List references, boolean throwOnError ) throws ASTSemanticException{
return lookupQualifiedName(startingScope, name, TypeInfo.t_any, null, references, throwOnError);
}
protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, ITokenDuple name, TypeInfo.eType type, List parameters, List references, boolean throwOnError ) throws ASTSemanticException
{
ISymbol result = null;
IToken firstSymbol = null;
@ -143,7 +147,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
firstSymbol = name.getFirstToken();
try
{
result = startingScope.lookup( firstSymbol.getImage());
if(type == TypeInfo.t_function)
result = startingScope.unqualifiedFunctionLookup( firstSymbol.getImage(), new LinkedList(parameters));
else
result = startingScope.lookup( firstSymbol.getImage());
if( result != null )
references.add( createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() ));
else
@ -160,7 +167,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
throw new ASTSemanticException();
try
{
result = pst.getCompilationUnit().lookup( name.getLastToken().getImage() );
if(type == TypeInfo.t_function)
result = pst.getCompilationUnit().unqualifiedFunctionLookup( name.getLastToken().getImage(), new LinkedList(parameters));
else
result = pst.getCompilationUnit().lookup( name.getLastToken().getImage() );
references.add( createReference( result, name.getLastToken().getImage(), name.getLastToken().getOffset() ));
}
catch( ParserSymbolTableException e)
@ -181,7 +191,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
try
{
if( t == name.getLastToken() )
result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() );
if(type == TypeInfo.t_function)
result = ((IContainerSymbol)result).qualifiedFunctionLookup( t.getImage(), new LinkedList(parameters) );
else
result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() );
else
result = ((IContainerSymbol)result).lookupNestedNameSpecifier( t.getImage() );
references.add( createReference( result, t.getImage(), t.getOffset() ));
@ -391,9 +404,6 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{
extension.addDefinition( astSymbol );
}
}
/* (non-Javadoc)
@ -670,7 +680,6 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
IASTExpression lhs,
IASTExpression rhs,
IASTExpression thirdExpression,
IToken id,
ITokenDuple typeId,
String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException
{
@ -699,33 +708,95 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
//look up id & add to references
IContainerSymbol startingScope = scopeToSymbol( scope );
if( id != null )
{
try
{
ISymbol s = startingScope.lookup( id.getImage() );
if( s != null )
references.add( createReference( s, id.getImage(), id.getOffset() ));
else
throw new ASTSemanticException();
}
catch (ParserSymbolTableException e)
{
throw new ASTSemanticException();
}
}
//look up typeId & add to references
if( typeId != null )
lookupQualifiedName( startingScope, typeId, references, false );
if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){
ITokenDuple functionId = ((ASTExpression)lhs).getTypeId();
List parameters = ((ASTExpression)rhs).getResultType();
lookupQualifiedName(startingScope, functionId, TypeInfo.t_function, parameters, references, false);
}
return new ASTExpression( kind, lhs, rhs, thirdExpression,
id == null ? "" : id.getImage(),
typeId == null ? "" : typeId.toString(),
literal, newDescriptor, references);
ASTExpression expression = new ASTExpression( kind, lhs, rhs, thirdExpression,
typeId, literal, newDescriptor, references);
expression.setResultType (getExpressionResultType(expression));
return expression;
}
protected List getExpressionResultType(IASTExpression expression){
List result = new ArrayList();
if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_EMPTY) {
TypeInfo info = new TypeInfo();
info.setType(TypeInfo.t_void);
result.add(info);
return result;
}
if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL) {
TypeInfo info = new TypeInfo();
info.setType(TypeInfo.t_int);
result.add(info);
return result;
}
if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_CHAR_LITERAL){
TypeInfo info = new TypeInfo();
info.setType(TypeInfo.t_char);
result.add(info);
return result;
}
if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_FLOAT_LITERAL){
TypeInfo info = new TypeInfo();
info.setType(TypeInfo.t_float);
result.add(info);
return result;
}
if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL){
TypeInfo info = new TypeInfo();
info.setType(TypeInfo.t_bool);
result.add(info);
return result;
}
if ((expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_PLUS)
|| (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_MINUS) ){
ASTExpression right = (ASTExpression)expression.getLHSExpression();
ASTExpression left = (ASTExpression)expression.getRHSExpression();
if((right != null) && (left != null)){
TypeInfo rightType =(TypeInfo)right.getResultType().iterator().next();
TypeInfo leftType =(TypeInfo)left.getResultType().iterator().next();
if ( rightType.equals(leftType) ){
result.add(rightType);
} else {
// TODO: two different types added or subtracted
}
}
}
if(expression.getExpressionKind() == IASTExpression.Kind.EXPRESSIONLIST){
if(expression.getLHSExpression() != null){
Iterator i = ((ASTExpression)expression.getLHSExpression()).getResultType().iterator();
while (i.hasNext()){
result.add(i.next());
}
}
if(expression.getRHSExpression() != null){
Iterator i = ((ASTExpression)expression.getRHSExpression()).getResultType().iterator();
while (i.hasNext()){
result.add(i.next());
}
}
return result;
}
if(expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){
TypeInfo type = new TypeInfo();
type.setType(TypeInfo.t_function);
result.add(type);
return result;
}
return result;
}
protected void getExpressionReferences(IASTExpression expression, List references)
{
@ -937,7 +1008,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
(IParameterizedSymbol) lookupQualifiedName(parentScope, functionName, TypeInfo.t_function, parameters, 0, functionReferences, false);
if(methodDeclaration != null){
ASTMethodReference reference = (ASTMethodReference) functionReferences.iterator().next();
visibility = ((IASTMethod)reference.getReferencedElement()).getVisiblity();
visibility = ((IASTMethod)reference.getReferencedElement()).getVisiblity();
}
return createMethod(scope, functionName, parameters, returnType,
exception, isInline, isFriend, isStatic, startOffset, offset,

View file

@ -22,7 +22,7 @@ public class ASTExpression implements IASTExpression {
private final Kind kind;
private final IASTExpression lhs, rhs, third;
private final String id, typeId, literal;
private final String typeId, literal;
private final IASTNewExpressionDescriptor newDescriptor;
/**
@ -33,13 +33,12 @@ public class ASTExpression implements IASTExpression {
* @param typeId
* @param literal
*/
public ASTExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression third, String id, String typeId, String literal, IASTNewExpressionDescriptor newDescriptor) {
public ASTExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression third, String typeId, String literal, IASTNewExpressionDescriptor newDescriptor) {
this.kind = kind;
this.lhs =lhs;
this.rhs = rhs;
this.third = third;
this.typeId = typeId;
this.id = id;
this.literal = literal;
this.newDescriptor = newDescriptor;
}
@ -75,17 +74,10 @@ public class ASTExpression implements IASTExpression {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/
public String getTypeId() {
public String getTypeIdString() {
return typeId;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getId()
*/
public String getId() {
return id;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor()
*/

View file

@ -149,8 +149,8 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc)
* @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, IToken id, ITokenDuple typeId, String literal, IASTNewExpressionDescriptor newDescriptor) {
return new ASTExpression( kind, lhs, rhs, thirdExpression, id == null ? "" : id.getImage(), typeId == null ? "" : typeId.toString(), literal, newDescriptor );
public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, ITokenDuple typeId, String literal, IASTNewExpressionDescriptor newDescriptor) {
return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId == null ? "" : typeId.toString(), literal, newDescriptor );
}
/* (non-Javadoc)

View file

@ -6,6 +6,9 @@
* src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java
* src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties
2003-09-04 Hoda Amer
- Solution to bug#42414 :Extraneous semi-colons in generated class methods
2003-09-03 David Inglis
Fixed parser block to save ids properly.
Use shared preference key for error parsers.

View file

@ -811,7 +811,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
text.append(getNewClassName());
text.append("()");
if(isInline()){
text.append(" {};");
text.append(" {}");
text.append(lineDelimiter);
}else {
text.append(";");
@ -827,7 +827,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
text.append(getNewClassName());
text.append("()");
if(isInline()){
text.append(" {};");
text.append(" {}");
text.append(lineDelimiter);
}else {
text.append(";");
@ -864,7 +864,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
text.append(getNewClassName());
text.append("()");
text.append(lineDelimiter);
text.append("{};");
text.append("{}");
text.append(lineDelimiter);
// destructor
@ -873,7 +873,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
text.append(getNewClassName());
text.append("()");
text.append(lineDelimiter);
text.append("{};");
text.append("{}");
text.append(lineDelimiter);
return text.toString();
}