public virtual object VisitCastExpression(CastExpression castExpression, object data) { Debug.Assert((castExpression != null)); Debug.Assert((castExpression.CastTo != null)); Debug.Assert((castExpression.Expression != null)); castExpression.CastTo.AcceptVisitor(this, data); return castExpression.Expression.AcceptVisitor(this, data); }
public override object VisitCastExpression(CastExpression castExpression, object data) { base.VisitCastExpression(castExpression, data); if (castExpression.CastType == CastType.Conversion || castExpression.CastType == CastType.PrimitiveConversion) { switch (castExpression.CastTo.Type) { case "System.Boolean": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToBoolean"); case "System.Byte": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToByte"); case "System.Char": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToChar"); case "System.DateTime": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToDateTime"); case "System.Decimal": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToDecimal"); case "System.Double": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToDouble"); case "System.Int16": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToInt16"); case "System.Int32": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToInt32"); case "System.Int64": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToInt64"); case "System.SByte": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToSByte"); case "System.Single": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToSingle"); case "System.String": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToString"); case "System.UInt16": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToUInt16"); case "System.UInt32": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToUInt32"); case "System.UInt64": return ReplacePrimitiveCastWithConvertMethodCall(castExpression, "ToUInt64"); } } return null; }
object ReplacePrimitiveCastWithConvertMethodCall(CastExpression castExpression, string methodName) { ReplaceCurrentNode(ExpressionBuilder.Identifier("Convert").Call(methodName, castExpression.Expression)); return null; }
public virtual object TrackedVisitCastExpression(CastExpression castExpression, object data) { return base.VisitCastExpression(castExpression, data); }
void RelationalExpr( #line 2239 "Frames/cs.ATG" ref Expression outExpr) { #line 2241 "Frames/cs.ATG" TypeReference type; Expression expr; BinaryOperatorType op = BinaryOperatorType.None; ShiftExpr( #line 2246 "Frames/cs.ATG" ref outExpr); while (StartOf(37)) { if (StartOf(38)) { if (la.kind == 23) { lexer.NextToken(); #line 2248 "Frames/cs.ATG" op = BinaryOperatorType.LessThan; } else if (la.kind == 22) { lexer.NextToken(); #line 2249 "Frames/cs.ATG" op = BinaryOperatorType.GreaterThan; } else if (la.kind == 36) { lexer.NextToken(); #line 2250 "Frames/cs.ATG" op = BinaryOperatorType.LessThanOrEqual; } else if (la.kind == 35) { lexer.NextToken(); #line 2251 "Frames/cs.ATG" op = BinaryOperatorType.GreaterThanOrEqual; } else SynErr(215); UnaryExpr( #line 2253 "Frames/cs.ATG" out expr); ShiftExpr( #line 2254 "Frames/cs.ATG" ref expr); #line 2255 "Frames/cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } else { if (la.kind == 85) { lexer.NextToken(); TypeWithRestriction( #line 2258 "Frames/cs.ATG" out type, false, false); if ( #line 2259 "Frames/cs.ATG" la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) { NullableQuestionMark( #line 2260 "Frames/cs.ATG" ref type); } #line 2261 "Frames/cs.ATG" outExpr = new TypeOfIsExpression(outExpr, type); } else if (la.kind == 50) { lexer.NextToken(); TypeWithRestriction( #line 2263 "Frames/cs.ATG" out type, false, false); if ( #line 2264 "Frames/cs.ATG" la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) { NullableQuestionMark( #line 2265 "Frames/cs.ATG" ref type); } #line 2266 "Frames/cs.ATG" outExpr = new CastExpression(type, outExpr, CastType.TryCast); } else SynErr(216); } } }
void SimpleNonInvocationExpression( #line 1645 "VBNET.ATG" out Expression pexpr) { #line 1647 "VBNET.ATG" Expression expr; TypeReference type = null; string name = String.Empty; pexpr = null; if (StartOf(32)) { switch (la.kind) { case 3: { lexer.NextToken(); #line 1655 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 4: { lexer.NextToken(); #line 1656 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 7: { lexer.NextToken(); #line 1657 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 6: { lexer.NextToken(); #line 1658 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 5: { lexer.NextToken(); #line 1659 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 9: { lexer.NextToken(); #line 1660 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 8: { lexer.NextToken(); #line 1661 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 202: { lexer.NextToken(); #line 1663 "VBNET.ATG" pexpr = new PrimitiveExpression(true, "true"); break; } case 109: { lexer.NextToken(); #line 1664 "VBNET.ATG" pexpr = new PrimitiveExpression(false, "false"); break; } case 151: { lexer.NextToken(); #line 1665 "VBNET.ATG" pexpr = new PrimitiveExpression(null, "null"); break; } case 25: { lexer.NextToken(); Expr( #line 1666 "VBNET.ATG" out expr); Expect(26); #line 1666 "VBNET.ATG" pexpr = new ParenthesizedExpression(expr); break; } case 2: case 45: case 49: case 51: case 52: case 53: case 54: case 57: case 74: case 85: case 91: case 94: case 103: case 108: case 113: case 120: case 126: case 130: case 133: case 156: case 162: case 169: case 188: case 197: case 198: case 208: case 209: case 215: { Identifier(); #line 1668 "VBNET.ATG" pexpr = new IdentifierExpression(t.val); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; if ( #line 1671 "VBNET.ATG" la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { lexer.NextToken(); Expect(155); TypeArgumentList( #line 1672 "VBNET.ATG" ((IdentifierExpression)pexpr).TypeArguments); Expect(26); } break; } case 55: case 58: case 69: case 86: case 87: case 96: case 128: case 137: case 154: case 181: case 186: case 187: case 193: case 206: case 207: case 210: { #line 1674 "VBNET.ATG" string val = String.Empty; if (StartOf(11)) { PrimitiveTypeName( #line 1675 "VBNET.ATG" out val); } else if (la.kind == 154) { lexer.NextToken(); #line 1675 "VBNET.ATG" val = "System.Object"; } else SynErr(257); #line 1676 "VBNET.ATG" pexpr = new TypeReferenceExpression(new TypeReference(val, true)); break; } case 139: { lexer.NextToken(); #line 1677 "VBNET.ATG" pexpr = new ThisReferenceExpression(); break; } case 144: case 145: { #line 1678 "VBNET.ATG" Expression retExpr = null; if (la.kind == 144) { lexer.NextToken(); #line 1679 "VBNET.ATG" retExpr = new BaseReferenceExpression(); } else if (la.kind == 145) { lexer.NextToken(); #line 1680 "VBNET.ATG" retExpr = new ClassReferenceExpression(); } else SynErr(258); Expect(16); IdentifierOrKeyword( #line 1682 "VBNET.ATG" out name); #line 1682 "VBNET.ATG" pexpr = new MemberReferenceExpression(retExpr, name); break; } case 117: { lexer.NextToken(); Expect(16); Identifier(); #line 1684 "VBNET.ATG" type = new TypeReference(t.val ?? ""); #line 1686 "VBNET.ATG" type.IsGlobal = true; #line 1687 "VBNET.ATG" pexpr = new TypeReferenceExpression(type); break; } case 148: { ObjectCreateExpression( #line 1688 "VBNET.ATG" out expr); #line 1688 "VBNET.ATG" pexpr = expr; break; } case 81: case 93: case 204: { #line 1690 "VBNET.ATG" CastType castType = CastType.Cast; if (la.kind == 93) { lexer.NextToken(); } else if (la.kind == 81) { lexer.NextToken(); #line 1692 "VBNET.ATG" castType = CastType.Conversion; } else if (la.kind == 204) { lexer.NextToken(); #line 1693 "VBNET.ATG" castType = CastType.TryCast; } else SynErr(259); Expect(25); Expr( #line 1695 "VBNET.ATG" out expr); Expect(12); TypeName( #line 1695 "VBNET.ATG" out type); Expect(26); #line 1696 "VBNET.ATG" pexpr = new CastExpression(type, expr, castType); break; } case 63: case 64: case 65: case 66: case 67: case 68: case 70: case 72: case 73: case 77: case 78: case 79: case 80: case 82: case 83: case 84: { CastTarget( #line 1697 "VBNET.ATG" out type); Expect(25); Expr( #line 1697 "VBNET.ATG" out expr); Expect(26); #line 1697 "VBNET.ATG" pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); break; } case 44: { lexer.NextToken(); Expr( #line 1698 "VBNET.ATG" out expr); #line 1698 "VBNET.ATG" pexpr = new AddressOfExpression(expr); break; } case 116: { lexer.NextToken(); Expect(25); GetTypeTypeName( #line 1699 "VBNET.ATG" out type); Expect(26); #line 1699 "VBNET.ATG" pexpr = new TypeOfExpression(type); break; } case 205: { lexer.NextToken(); SimpleExpr( #line 1700 "VBNET.ATG" out expr); Expect(131); TypeName( #line 1700 "VBNET.ATG" out type); #line 1700 "VBNET.ATG" pexpr = new TypeOfIsExpression(expr, type); break; } case 122: { ConditionalExpression( #line 1701 "VBNET.ATG" out pexpr); break; } } } else if (la.kind == 16) { lexer.NextToken(); IdentifierOrKeyword( #line 1705 "VBNET.ATG" out name); #line 1705 "VBNET.ATG" pexpr = new MemberReferenceExpression(null, name); } else SynErr(260); }
public sealed override object VisitCastExpression(CastExpression castExpression, object data) { this.BeginVisit(castExpression); object result = this.TrackedVisitCastExpression(castExpression, data); this.EndVisit(castExpression); return result; }
public override object VisitCastExpression (CastExpression castExpression, object data) { return CreateResult (castExpression.CastTo); }
public virtual object VisitCastExpression(CastExpression castExpression, object data) { Debug.Assert((castExpression != null)); Debug.Assert((castExpression.CastTo != null)); Debug.Assert((castExpression.Expression != null)); nodeStack.Push(castExpression.CastTo); castExpression.CastTo.AcceptVisitor(this, data); castExpression.CastTo = ((TypeReference)(nodeStack.Pop())); nodeStack.Push(castExpression.Expression); castExpression.Expression.AcceptVisitor(this, data); castExpression.Expression = ((Expression)(nodeStack.Pop())); return null; }
public virtual object VisitCastExpression(CastExpression castExpression, object data) { throw new global::System.NotImplementedException("CastExpression"); }
public override object VisitCastExpression(CastExpression castExpression, object data) { if (castExpression.CastType == CastType.Cast) { // Casts to value types are marked as conversions // this code only supports primitive types, user-defined value types are handled by // the DOM-aware CSharpToVBNetConvertVisitor string type; if (TypeReference.PrimitiveTypesCSharpReverse.TryGetValue(castExpression.CastTo.Type, out type)) { if (type != "object" && type != "string") { // type is value type castExpression.CastType = CastType.Conversion; } } } return base.VisitCastExpression(castExpression, data); }
public override object VisitCastExpression(CastExpression castExpression, object data) { CodeTypeReference typeRef = ConvType(castExpression.CastTo); return new CodeCastExpression(typeRef, (CodeExpression)castExpression.Expression.AcceptVisitor(this, data)); }