public override void LeaveCastExpression(CastExpression node) { Expression newExpression = Convert(node.ExpressionType, node.Target); if (null != newExpression) { node.Target = newExpression; } }
protected Expression cast_expression() //throws RecognitionException, TokenStreamException { Expression e; IToken t = null; e = null; TypeReference tr = null; Expression target = null; try { // for error handling t = LT(1); match(CAST); match(LPAREN); tr=type_reference(); match(COMMA); target=expression(); match(RPAREN); if (0==inputState.guessing) { e = new CastExpression(ToLexicalInfo(t), target, tr); } } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex, "cast_expression"); recover(ex,tokenSet_44_); } else { throw ex; } } return e; }
protected Expression exponentiation() //throws RecognitionException, TokenStreamException { Expression e; IToken t = null; IToken c = null; IToken token = null; e = null; Expression r = null; TypeReference tr = null; try { // for error handling e=unary_expression(); { if ((LA(1)==AS)) { t = LT(1); match(AS); tr=type_reference(); if (0==inputState.guessing) { e = new TryCastExpression(ToLexicalInfo(t)) { Target = e, Type = tr }; } } else if ((LA(1)==CAST) && (tokenSet_46_.member(LA(2)))) { c = LT(1); match(CAST); tr=type_reference(); if (0==inputState.guessing) { e = new CastExpression(ToLexicalInfo(c)) { Target = e, Type = tr }; } } else if ((tokenSet_123_.member(LA(1))) && (tokenSet_15_.member(LA(2)))) { } else { throw new NoViableAltException(LT(1), getFilename()); } } { // ( ... )* for (;;) { if ((LA(1)==EXPONENTIATION) && (tokenSet_116_.member(LA(2)))) { token = LT(1); match(EXPONENTIATION); r=exponentiation(); if (0==inputState.guessing) { e = new BinaryExpression(ToLexicalInfo(token)) { Operator = BinaryOperatorType.Exponentiation, Left = e, Right = r }; } } else { goto _loop541_breakloop; } } _loop541_breakloop: ; } // ( ... )* } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex, "exponentiation"); recover(ex,tokenSet_123_); } else { throw ex; } } return e; }
public override void OnCastExpression(CastExpression node) { IType type = GetType(node.Type); Visit(node.Target); EmitCastIfNeeded(type, PopType()); PushType(type); }
//throws RecognitionException, TokenStreamException protected Expression exponentiation() { Expression e; IToken t = null; IToken c = null; IToken token = null; e = null; Expression r = null; TypeReference tr = null; try { // for error handling e=unary_expression(); { switch ( LA(1) ) { case AS: { t = LT(1); match(AS); tr=type_reference(); if (0==inputState.guessing) { e = new TryCastExpression(ToLexicalInfo(t)) { Target = e, Type = tr }; } break; } case CAST: { c = LT(1); match(CAST); tr=type_reference(); if (0==inputState.guessing) { e = new CastExpression(ToLexicalInfo(c)) { Target = e, Type = tr }; } break; } case EOF: case ESEPARATOR: case AND: case DEF: case DO: case ELSE: case FOR: case IS: case ISA: case IF: case IN: case NOT: case OR: case UNLESS: case WHILE: case ID: case EOS: case NEWLINE: case RPAREN: case RBRACK: case ASSIGN: case SUBTRACT: case COMMA: case COLON: case MULTIPLY: case EXPONENTIATION: case BITWISE_OR: case RBRACE: case QQ_END: case INPLACE_BITWISE_OR: case INPLACE_EXCLUSIVE_OR: case INPLACE_BITWISE_AND: case INPLACE_SHIFT_LEFT: case INPLACE_SHIFT_RIGHT: case CMP_OPERATOR: case GREATER_THAN: case LESS_THAN: case ADD: case EXCLUSIVE_OR: case DIVISION: case MODULUS: case BITWISE_AND: case SHIFT_LEFT: case SHIFT_RIGHT: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { // ( ... )* for (;;) { if ((LA(1)==EXPONENTIATION) && (tokenSet_75_.member(LA(2)))) { token = LT(1); match(EXPONENTIATION); r=exponentiation(); if (0==inputState.guessing) { e = new BinaryExpression(ToLexicalInfo(token)) { Operator = BinaryOperatorType.Exponentiation, Left = e, Right = r }; } } else { goto _loop474_breakloop; } } _loop474_breakloop: ; } // ( ... )* } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex); recover(ex,tokenSet_112_); } else { throw ex; } } return e; }
public override void OnCastExpression(CastExpression node) { WriteKeyword("cast"); Write("("); Visit(node.Type); Write(", "); Visit(node.Target); Write(")"); }
public override void LeaveCastExpression(CastExpression node) { TryToReify(node.Target, GetExpressionType(node)); }
public override void OnCastExpression(CastExpression node) { MakeResult(ConvertType(node.Type)); }
override public object Clone() { CastExpression clone = new CastExpression(); clone._lexicalInfo = _lexicalInfo; clone._endSourceLocation = _endSourceLocation; clone._documentation = _documentation; clone._isSynthetic = _isSynthetic; clone._entity = _entity; if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone(); clone._expressionType = _expressionType; if (null != _target) { clone._target = _target.Clone() as Expression; clone._target.InitializeParent(clone); } if (null != _type) { clone._type = _type.Clone() as TypeReference; clone._type.InitializeParent(clone); } return clone; }
public override void OnCastExpression(CastExpression node) { base.OnCastExpression(node); ReplaceWithCallToExpressionConvert(node.Target, node.Type); }
override public void LeaveCastExpression(CastExpression node) { var newExpression = Convert(node.ExpressionType, node.Target); if (newExpression != null) node.Target = newExpression; }
public override void LeaveCastExpression(CastExpression node) { IType fromType = GetExpressionType(node.Target); IType toType = GetType(node.Type); if (!TypeSystemServices.AreTypesRelated(toType, fromType) && !(toType.IsInterface && !fromType.IsFinal) && !(TypeSystemServices.IsIntegerNumber(toType) && TypeSystemServices.CanBeExplicitlyCastToInteger(fromType)) && !(TypeSystemServices.IsIntegerNumber(fromType) && TypeSystemServices.CanBeExplicitlyCastToInteger(toType))) { IMethod explicitOperator = TypeSystemServices.FindExplicitConversionOperator(fromType, toType); if (null != explicitOperator) { node.ParentNode.Replace( node, CodeBuilder.CreateMethodInvocation( explicitOperator, node.Target)); return; } Error( CompilerErrorFactory.IncompatibleExpressionType( node, toType.ToString(), fromType.ToString())); } BindExpressionType(node, toType); }
public override void OnCastExpression(CastExpression node) { _expression = null; node.Target.Accept(this); if (_expression == null) return; if (_expression is CodeMethodReferenceExpression) { _expression = new CodeObjectCreateExpression(ConvTypeRef(node.Type), _expression); } else { _expression = new CodeCastExpression(ConvTypeRef(node.Type), _expression); } }
override public void LeaveForStatement(ForStatement node) { _iteratorNode = node.Iterator; CurrentEnumeratorType = GetExpressionType(node.Iterator); if (null == CurrentBestEnumeratorType) return; //error DeclarationCollection declarations = node.Declarations; Block body = new Block(node.LexicalInfo); InternalLocal iterator = CodeBuilder.DeclareLocal(_current, Context.GetUniqueName("iterator"), CurrentBestEnumeratorType); if (CurrentBestEnumeratorType == CurrentEnumeratorType) { //$iterator = <node.Iterator> body.Add( CodeBuilder.CreateAssignment( node.LexicalInfo, CodeBuilder.CreateReference(iterator), node.Iterator)); } else { //$iterator = <node.Iterator>.GetEnumerator() body.Add( CodeBuilder.CreateAssignment( node.LexicalInfo, CodeBuilder.CreateReference(iterator), CodeBuilder.CreateMethodInvocation(node.Iterator, CurrentBestGetEnumerator))); } // while __iterator.MoveNext(): if (null == CurrentBestMoveNext) return; //error WhileStatement ws = new WhileStatement(node.LexicalInfo); ws.Condition = CodeBuilder.CreateMethodInvocation( CodeBuilder.CreateReference(iterator), CurrentBestMoveNext); if (null == CurrentBestGetCurrent) return; //error Expression current = CodeBuilder.CreateMethodInvocation( CodeBuilder.CreateReference(iterator), CurrentBestGetCurrent); if (1 == declarations.Count) { // item = __iterator.Current ws.Block.Add( CodeBuilder.CreateAssignment( node.LexicalInfo, CodeBuilder.CreateReference((InternalLocal)declarations[0].Entity), current)); } else { UnpackExpression(ws.Block, CodeBuilder.CreateCast( CurrentEnumeratorItemType, current), node.Declarations); } ws.Block.Add(node.Block); ws.OrBlock = node.OrBlock; ws.ThenBlock = node.ThenBlock; // try: // while... // ensure: // d = iterator as IDisposable // d.Dispose() unless d is null if (IsAssignableFrom(TypeSystemServices.IDisposableType, CurrentBestEnumeratorType)) { TryStatement tryStatement = new TryStatement(); tryStatement.ProtectedBlock.Add(ws); tryStatement.EnsureBlock = new Block(); CastExpression castExpression = new CastExpression(); castExpression.Type = CodeBuilder.CreateTypeReference(TypeSystemServices.IDisposableType); castExpression.Target = CodeBuilder.CreateReference(iterator); castExpression.ExpressionType = TypeSystemServices.IDisposableType; tryStatement.EnsureBlock.Add( CodeBuilder.CreateMethodInvocation(castExpression, IDisposable_Dispose)); body.Add(tryStatement); } else { body.Add(ws); } ReplaceCurrentNode(body); }
public override void LeaveCastExpression(CastExpression node) { var fromType = GetExpressionType(node.Target); var toType = GetType(node.Type); BindExpressionType(node, toType); if (IsError(fromType) || IsError(toType)) return; if (IsAssignableFrom(toType, fromType)) return; if (TypeSystemServices.CanBeReachedByPromotion(toType, fromType)) return; var conversion = TypeSystemServices.FindExplicitConversionOperator(fromType, toType) ?? TypeSystemServices.FindImplicitConversionOperator(fromType, toType); if (null != conversion) { node.ParentNode.Replace(node, CodeBuilder.CreateMethodInvocation(conversion, node.Target)); return; } if (toType.IsValueType) { if (TypeSystemServices.IsSystemObject(fromType)) return; } else if (!fromType.IsFinal) return; Error(CompilerErrorFactory.IncompatibleExpressionType(node, toType, fromType)); }
override public void OnCastExpression(CastExpression node) { var type = GetType(node.Type); LoadExpressionWithType(type, node.Target); PushType(type); }
public Expression CreateCast(IType type, Expression target) { if (type == target.ExpressionType) return target; var expression = new CastExpression(target.LexicalInfo); expression.Type = CreateTypeReference(type); expression.Target = target; expression.ExpressionType = type; return expression; }
public Expression unary_expression() { Expression expression = null; IToken token = null; IToken token2 = null; try { TypeReference reference; int num = this.LA(1); switch (num) { case 0x4f: case 80: case 0x52: case 0x58: case 0x67: expression = this.prefix_unary_expression(); break; default: if (((((num != 12) && (num != 15)) && ((num != 0x13) && (num != 0x1b))) && (((num != 0x1d) && (num != 0x27)) && ((num != 40) && (num != 0x2a)))) && ((((num != 0x2c) && (num != 0x3b)) && ((num != 60) && (num != 0x3d))) && ((((num != 0x3f) && (num != 0x44)) && ((num != 0x69) && (num != 0x6a))) && (((num != 0x6b) && (num != 0x6c)) && (num != 0x6d))))) { throw new NoViableAltException(this.LT(1), this.getFilename()); } expression = this.postfix_unary_expression(); break; } if ((this.LA(1) == 4) && ((this.LA(2) == 0x13) || (this.LA(2) == 0x3b))) { token = this.LT(1); this.match(4); reference = this.type_reference(); if (base.inputState.guessing == 0) { TryCastExpression expression2; TryCastExpression expression1 = expression2 = new TryCastExpression(ToLexicalInfo(token)); expression2.set_Target(expression); expression2.set_Type(reference); expression = expression2; } return expression; } if ((this.LA(1) == 6) && ((this.LA(2) == 0x13) || (this.LA(2) == 0x3b))) { token2 = this.LT(1); this.match(6); reference = this.type_reference(); if (base.inputState.guessing == 0) { CastExpression expression3; CastExpression expression6 = expression3 = new CastExpression(ToLexicalInfo(token2)); expression3.set_Target(expression); expression3.set_Type(reference); expression = expression3; } return expression; } if (!tokenSet_20_.member(this.LA(1)) || !tokenSet_28_.member(this.LA(2))) { throw new NoViableAltException(this.LT(1), this.getFilename()); } return expression; } catch (RecognitionException exception) { if (base.inputState.guessing != 0) { throw; } this.reportError(exception); this.recover(exception, tokenSet_20_); return expression; } return expression; }