diff options
author | John Camelon | 2003-09-15 13:20:30 +0000 |
---|---|---|
committer | John Camelon | 2003-09-15 13:20:30 +0000 |
commit | bc7648a24ee2ee4ddc4093185eae9a0fbb16a0ed (patch) | |
tree | 4fdca69e26a041d4115b2046f1b69a365d9d89f8 /core/org.eclipse.cdt.core/parser | |
parent | edd344b8af2bf6fd232273a76e2200de9c3953ae (diff) | |
download | org.eclipse.cdt-bc7648a24ee2ee4ddc4093185eae9a0fbb16a0ed.tar.gz org.eclipse.cdt-bc7648a24ee2ee4ddc4093185eae9a0fbb16a0ed.tar.xz org.eclipse.cdt-bc7648a24ee2ee4ddc4093185eae9a0fbb16a0ed.zip |
Patch for Hoda Amer.
Core:
In completeParseASTFactory.getExpressionResultType()
- Added the handling of some more expression types.
See CompleteParseASTExpressionTest for details.
Tests:
- Added lots of test cases to CompleteParseASTExpressionTest
Diffstat (limited to 'core/org.eclipse.cdt.core/parser')
4 files changed, 171 insertions, 24 deletions
diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 81ff90c66c1..e033d2dd20f 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,8 @@ +2003-09-12 Hoda Amer + In completeParseASTFactory.getExpressionResultType() + - Added the handling of some more expression types. + See CompleteParseASTExpressionTest for details. + 2003-09-12 John Camelon Fixed Bug 42985 : Search: Qualified function call is treated as a declaration Fixed Bug 40419 : parser fails on heavily templated expressions diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java index 5d52a7fbf68..59aa93c4e61 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java @@ -95,8 +95,7 @@ public interface IASTExpression extends ISourceElementCallbackDelegate public static final Kind INCLUSIVEOREXPRESSION = new Kind( 68 ); public static final Kind LOGICALANDEXPRESSION = new Kind( 69 ); public static final Kind LOGICALOREXPRESSION = new Kind( 70 ); - public static final Kind CONDITIONALEXPRESSION_SIMPLE = new Kind( 71 ); - public static final Kind CONDITIONALEXPRESSION_HARD = new Kind( 72 ); + public static final Kind CONDITIONALEXPRESSION = new Kind( 71 ); public static final Kind THROWEXPRESSION = new Kind( 72 ); public static final Kind ASSIGNMENTEXPRESSION_NORMAL = new Kind( 73 ); public static final Kind ASSIGNMENTEXPRESSION_PLUS = new Kind( 74 ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 42a352404f3..e3f3c45979d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -2893,7 +2893,7 @@ public class Parser implements IParser // if the condition not taken, try assignment operators if (conditionalExpression != null && conditionalExpression.getExpressionKind() - == IASTExpression.Kind.CONDITIONALEXPRESSION_HARD) + == IASTExpression.Kind.CONDITIONALEXPRESSION) return conditionalExpression; switch (LT(1)) { case IToken.tASSIGN : @@ -3031,7 +3031,7 @@ public class Parser implements IParser { return astFactory.createExpression( scope, - IASTExpression.Kind.CONDITIONALEXPRESSION_HARD, + IASTExpression.Kind.CONDITIONALEXPRESSION, firstExpression, secondExpression, thirdExpression, 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 7e824eb6caa..ffaacd02b8c 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 @@ -767,6 +767,15 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if( typeId != null ){ symbol = lookupQualifiedName( startingScope, typeId, references, false ); } + // "a.m" or "a->m : lookup m in the scope of the declaration of a + if ((kind == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION) + || (kind == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION)){ + TypeInfo lhsInfo = (TypeInfo) ((ASTExpression)lhs).getResultType().iterator().next(); + ISymbol containingScope = (ISymbol) lhsInfo.getTypeSymbol().getTypeSymbol(); + if(containingScope != null){ + symbol = lookupQualifiedName((IContainerSymbol)containingScope, ((ASTExpression)rhs).getTypeId() , references, false); + } + } if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){ ITokenDuple functionId = ((ASTExpression)lhs).getTypeId(); @@ -781,7 +790,72 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto return expression; } - + /* + * Apply the usual arithmetic conversions to find out the result of an expression + * that has a lhs and a rhs as indicated in the specs (section 5.Expressions, page 64) + */ + protected TypeInfo usualArithmeticConversions(TypeInfo lhs, TypeInfo rhs){ + TypeInfo info = new TypeInfo(); + if( + ( lhs.checkBit(TypeInfo.isLong) && lhs.getType() == TypeInfo.t_double) + || ( rhs.checkBit(TypeInfo.isLong) && rhs.getType() == TypeInfo.t_double) + ){ + info.setType(TypeInfo.t_double); + info.setBit(true, TypeInfo.isLong); + return info; + } + else if( + ( lhs.getType() == TypeInfo.t_double ) + || ( rhs.getType() == TypeInfo.t_double ) + ){ + info.setType(TypeInfo.t_double); + return info; + } + else if ( + ( lhs.getType() == TypeInfo.t_float ) + || ( rhs.getType() == TypeInfo.t_float ) + ){ + info.setType(TypeInfo.t_float); + return info; + } else { + // perform intergral promotions (Specs section 4.5) + info.setType(TypeInfo.t_int); + } + + if( + ( lhs.checkBit(TypeInfo.isUnsigned) && lhs.checkBit(TypeInfo.isLong)) + || ( rhs.checkBit(TypeInfo.isUnsigned) && rhs.checkBit(TypeInfo.isLong)) + ){ + info.setBit(true, TypeInfo.isUnsigned); + info.setBit(true, TypeInfo.isLong); + return info; + } + else if( + ( lhs.checkBit(TypeInfo.isUnsigned) && rhs.checkBit(TypeInfo.isLong) ) + || ( rhs.checkBit(TypeInfo.isUnsigned) && lhs.checkBit(TypeInfo.isLong) ) + ){ + info.setBit(true, TypeInfo.isUnsigned); + info.setBit(true, TypeInfo.isLong); + return info; + } + else if ( + ( lhs.checkBit(TypeInfo.isLong)) + || ( rhs.checkBit(TypeInfo.isLong)) + ){ + info.setBit(true, TypeInfo.isLong); + return info; + } + else if ( + ( lhs.checkBit(TypeInfo.isUnsigned) ) + || ( rhs.checkBit(TypeInfo.isUnsigned) ) + ){ + info.setBit(true, TypeInfo.isUnsigned); + return info; + } else { + // it should be both = int + return info; + } + } protected List getExpressionResultType(IASTExpression expression, ISymbol symbol){ List result = new ArrayList(); TypeInfo info = new TypeInfo(); @@ -794,25 +868,22 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto return result; } // types that resolve to int - // the relational kinds are 0 and !0 if ((expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL) || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT) - || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHAN) - || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO) - || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHAN) - || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO) - || (expression.getExpressionKind() == IASTExpression.Kind.EQUALITY_EQUALS) - || (expression.getExpressionKind() == IASTExpression.Kind.EQUALITY_NOTEQUALS) - || (expression.getExpressionKind() == IASTExpression.Kind.ANDEXPRESSION) - || (expression.getExpressionKind() == IASTExpression.Kind.EXCLUSIVEOREXPRESSION) - || (expression.getExpressionKind() == IASTExpression.Kind.INCLUSIVEOREXPRESSION) - || (expression.getExpressionKind() == IASTExpression.Kind.LOGICALANDEXPRESSION) - || (expression.getExpressionKind() == IASTExpression.Kind.LOGICALOREXPRESSION) ){ info.setType(TypeInfo.t_int); result.add(info); return result; } + // size of is always unsigned int + if ((expression.getExpressionKind() == IASTExpression.Kind.UNARY_SIZEOF_TYPEID) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION) + ){ + info.setType(TypeInfo.t_int); + info.setBit(true, TypeInfo.isUnsigned); + result.add(info); + return result; + } // types that resolve to char if( (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_CHAR_LITERAL) || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR)){ @@ -849,6 +920,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto // types that resolve to bool if( (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL) || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHAN) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHAN) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO) + || (expression.getExpressionKind() == IASTExpression.Kind.EQUALITY_EQUALS) + || (expression.getExpressionKind() == IASTExpression.Kind.EQUALITY_NOTEQUALS) + || (expression.getExpressionKind() == IASTExpression.Kind.LOGICALANDEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.LOGICALOREXPRESSION) ) { info.setType(TypeInfo.t_bool); @@ -885,7 +964,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } // types that resolve to t_type, symbol already looked up in type id - if (expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION){ + if( (expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPEID_TYPEID) + ){ info.setType(TypeInfo.t_type); if(symbol != null) info.setTypeSymbol(symbol); @@ -914,16 +995,64 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto result.add(info); return result; } - // types that resolve to LHS types - if ((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_INCREMENT) - || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DECREMENT) - || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_INCREMENT) - || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_DECREMENT) - || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY) + // the dot and the arrow resolves to the type of the member + if ((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION) + ){ + if(symbol != null){ + info = new TypeInfo(symbol.getTypeInfo()); + result.add(info); + return result; + } + } + // new +/* if((expression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID) + || (expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID) + ){ + if(symbol != null){ + info.setType(symbol.getType()); + info.setTypeSymbol(symbol); + result.add(info); + return result; + } + } +*/ // types that use the usual arithmetic conversions + if((expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY) || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_DIVIDE) || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MODULUS) || (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_PLUS) || (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_MINUS) + || (expression.getExpressionKind() == IASTExpression.Kind.ANDEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.EXCLUSIVEOREXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.INCLUSIVEOREXPRESSION) + ){ + ASTExpression left = (ASTExpression)expression.getLHSExpression(); + ASTExpression right = (ASTExpression)expression.getRHSExpression(); + if((left != null ) && (right != null)){ + TypeInfo leftType =(TypeInfo)left.getResultType().iterator().next(); + while( (leftType.getType() == TypeInfo.t_type) && (leftType.getTypeSymbol() != null)){ + leftType = leftType.getTypeSymbol().getTypeInfo(); + } + TypeInfo rightType =(TypeInfo)right.getResultType().iterator().next(); + while( (rightType.getType() == TypeInfo.t_type) && (rightType.getTypeSymbol() != null)){ + rightType = rightType.getTypeSymbol().getTypeInfo(); + } + info = usualArithmeticConversions(leftType, rightType); + result.add(info); + return result; + } + } + // types that resolve to LHS types + if ((expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_INCREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DECREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_INCREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_DECREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION) || (expression.getExpressionKind() == IASTExpression.Kind.SHIFT_LEFT) || (expression.getExpressionKind() == IASTExpression.Kind.SHIFT_RIGHT) || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL) @@ -945,6 +1074,20 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto return result; } } + // the cast changes the types to the type looked up in typeId = symbol + if((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DYNAMIC_CAST) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_REINTERPRET_CAST) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_STATIC_CAST) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_CONST_CAST) + ){ + if(symbol != null){ + info = new TypeInfo(symbol.getTypeInfo()); + info.setTypeSymbol(symbol); + result.add(info); + return result; + } + } + // a list collects all types of left and right hand sides if(expression.getExpressionKind() == IASTExpression.Kind.EXPRESSIONLIST){ if(expression.getLHSExpression() != null){ |