Inheritance: ICSharpCode.NRefactory.Ast.Expression
Example #1
0
            public override object VisitCastExpression(CastExpression castExpression, object data)
            {
                //This was the hardest achievement to write ever :p
                UnlockWith(castExpression);

                return base.VisitCastExpression(castExpression, data);
            }
 public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
 {
     if (invocationExpression.TargetObject is FieldReferenceExpression)
     {
         FieldReferenceExpression targetObject = (FieldReferenceExpression) invocationExpression.TargetObject;
         string methodName = targetObject.FieldName;
         TypeDeclaration typeDeclaration = GetEnclosingTypeDeclaration(invocationExpression);
         TypeDeclaration thisTypeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(invocationExpression, typeof(TypeDeclaration));
         if (typeDeclaration != null && IsTestFixture(thisTypeDeclaration))
         {
             IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
             IList specialMethods = GetMethods(methods, methodName);
             if (ContainsInternalMethod(specialMethods))
             {
                 Expression replacedExpression;
                 MethodDeclaration method = (MethodDeclaration) specialMethods[0];
                 bool staticMethod = AstUtil.ContainsModifier(method, Modifiers.Static);
                 replacedExpression = CreateReflectionInvocation(invocationExpression, staticMethod);
                 if (invocationExpression.Parent is Expression || invocationExpression.Parent is VariableDeclaration)
                 {
                     TypeReference returnType = GetInternalMethodReturnType(specialMethods);
                     CastExpression castExpression = new CastExpression(returnType, replacedExpression, CastType.Cast);
                     replacedExpression = castExpression;
                 }
                 ReplaceCurrentNode(replacedExpression);
             }
         }
     }
     return base.TrackedVisitInvocationExpression(invocationExpression, data);
 }
Example #3
0
 public override object VisitCastExpression(CastExpression castExpression, object data)
 {
     if (GetPrecedence(castExpression.Expression) > GetPrecedence(castExpression)) {
         castExpression.Expression = Deparenthesize(castExpression.Expression);
     }
     return base.VisitCastExpression(castExpression, data);
 }
        private CastExpression GetCastExpression(BinaryOperatorExpression binaryOperatorExpression)
        {
            TypeReference leftType = GetExpressionType(binaryOperatorExpression.Left);

            CastExpression castedUnsignedShift = new CastExpression(new TypeReference("u" + leftType.Type), binaryOperatorExpression, CastType.Cast);
            ParenthesizedExpression parenthesizedCastedUnsignedShift = new ParenthesizedExpression(castedUnsignedShift);
            return new CastExpression(new TypeReference(leftType.Type), parenthesizedCastedUnsignedShift, CastType.Cast);
        }
		/// <summary>
		/// Creates an expression which, when evaluated, creates a List&lt;T&gt; in the debugee
		/// filled with contents of IEnumerable&lt;T&gt; from the debugee.
		/// </summary>
		/// <param name="iEnumerableVariable">Expression for IEnumerable variable in the debugee.</param>
		/// <param name="itemType">
		/// The generic argument of IEnumerable&lt;T&gt; that <paramref name="iEnumerableVariable"/> implements.</param>
		public static Expression CreateDebugListExpression(Expression iEnumerableVariable, DebugType itemType, out DebugType listType)
		{
			// is using itemType.AppDomain ok?
			listType = DebugType.CreateFromType(itemType.AppDomain, typeof(System.Collections.Generic.List<>), itemType);
			var iEnumerableType = DebugType.CreateFromType(itemType.AppDomain, typeof(IEnumerable<>), itemType);
			// explicitely cast the variable to IEnumerable<T>, where T is itemType
			Expression iEnumerableVariableExplicitCast = new CastExpression(iEnumerableType.GetTypeReference() , iEnumerableVariable, CastType.Cast);
			return new ObjectCreateExpression(listType.GetTypeReference(), iEnumerableVariableExplicitCast.ToList());
		}
Example #6
0
 public override object VisitCastExpression(CastExpression castExpression, object data)
 {
     if (castExpression.CastTo.Type == "int" &&
         castExpression.Expression is MemberReferenceExpression &&
         (castExpression.Expression as MemberReferenceExpression).MemberName == "Length") {
         ReplaceCurrentNode(castExpression.Expression);
         return null;
     }
     return base.VisitCastExpression(castExpression, data);
 }
Example #7
0
        /// <summary>
        /// Creates an expression which, when evaluated, creates a List&lt;T&gt; in the debugee
        /// filled with contents of IEnumerable&lt;T&gt; from the debugee.
        /// </summary>
        /// <param name="iEnumerableVariable">Expression for IEnumerable variable in the debugee.</param>
        /// <param name="itemType">
        /// The generic argument of IEnumerable&lt;T&gt; that <paramref name="iEnumerableVariable"/> implements.</param>
        public static Expression CreateDebugListExpression(Expression iEnumerableVariable, DebugType itemType, out DebugType listType)
        {
            // is using itemType.AppDomain ok?
            listType = DebugType.CreateFromType(itemType.AppDomain, typeof(System.Collections.Generic.List<>), itemType);
            var iEnumerableType = DebugType.CreateFromType(itemType.AppDomain, typeof(IEnumerable<>), itemType);
            // explicitely cast the variable to IEnumerable<T>, where T is itemType
            Expression iEnumerableVariableExplicitCast = new CastExpression { Expression = iEnumerableVariable.Clone() , Type = iEnumerableType.GetTypeReference() };

            var obj = new ObjectCreateExpression() { Type = listType.GetTypeReference() };
            obj.Arguments.Add(iEnumerableVariableExplicitCast);

            return obj;
        }
		public override object VisitLambdaExpression(ICSharpCode.NRefactory.Ast.LambdaExpression lambdaExpression, object data)
		{
			var invocationExpression = lambdaExpression.Parent as InvocationExpression;
			if (invocationExpression == null)
				return base.VisitLambdaExpression(lambdaExpression, data);

			var target = invocationExpression.TargetObject as MemberReferenceExpression;
			if(target == null)
				return base.VisitLambdaExpression(lambdaExpression, data);

			INode node = lambdaExpression;
			var parenthesizedlambdaExpression = new ParenthesizedExpression(lambdaExpression);
			switch (target.MemberName)
			{
				case "Sum":
				case "Average":
					node = ModifyLambdaForNumerics(lambdaExpression, parenthesizedlambdaExpression);
					break;
				case "Max":
				case "Min":
					node = ModifyLambdaForMinMax(lambdaExpression, parenthesizedlambdaExpression);
					break;
				case "OrderBy":
				case "OrderByDescending":
				case "GroupBy":
				case "Recurse":
				case "Select":
					node = ModifyLambdaForSelect(parenthesizedlambdaExpression, target);
					break;
				case "SelectMany":
					node = ModifyLambdaForSelectMany(lambdaExpression, parenthesizedlambdaExpression, invocationExpression);
					break;
				case "Any":
				case "all":
				case "First":
				case "FirstOrDefault":
				case "Last":
				case "LastOfDefault":
				case "Single":
				case "Where":
				case "Count":
				case "SingleOrDefault":
					node = new CastExpression(new TypeReference("Func<dynamic, bool>"), parenthesizedlambdaExpression, CastType.Cast);
				break;
			}
			ReplaceCurrentNode(node);

			return base.VisitLambdaExpression(lambdaExpression, data);
		}
 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)
 {
     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;
 }
		public sealed override object VisitCastExpression(CastExpression castExpression, object data) {
			this.BeginVisit(castExpression);
			object result = this.TrackedVisitCastExpression(castExpression, data);
			this.EndVisit(castExpression);
			return result;
		}
Example #12
0
		public virtual object VisitCastExpression(CastExpression castExpression, object data) {
			throw new global::System.NotImplementedException("CastExpression");
		}
Example #13
0
	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 override object VisitCastExpression (CastExpression expression, object data)
			{
				//				Console.WriteLine ("CastExpression");
				IntegrateTemporaryVariableVisitorOptions options = (IntegrateTemporaryVariableVisitorOptions)data;
				if (IsExpressionToReplace (expression.Expression, (IntegrateTemporaryVariableVisitorOptions)data)) {
					if (IsPrimary (options.Initializer))
						options.Changes.Add (ReplaceExpression (expression.Expression, options.Initializer, options));
					else
						options.Changes.Add (ReplaceExpression (expression.Expression, new ParenthesizedExpression (options.Initializer), options));
					return null;
				} else {
					return base.VisitCastExpression (expression, data);
				}
			}
Example #15
0
	void RelationalExpr(
#line  2251 "cs.ATG" 
ref Expression outExpr) {

#line  2253 "cs.ATG" 
		TypeReference type;
		Expression expr;
		BinaryOperatorType op = BinaryOperatorType.None;
		Location startLocation = la.Location;
		
		ShiftExpr(
#line  2259 "cs.ATG" 
ref outExpr);
		while (StartOf(37)) {
			if (StartOf(38)) {
				if (la.kind == 23) {
					lexer.NextToken();

#line  2261 "cs.ATG" 
					op = BinaryOperatorType.LessThan; 
				} else if (la.kind == 22) {
					lexer.NextToken();

#line  2262 "cs.ATG" 
					op = BinaryOperatorType.GreaterThan; 
				} else if (la.kind == 36) {
					lexer.NextToken();

#line  2263 "cs.ATG" 
					op = BinaryOperatorType.LessThanOrEqual; 
				} else if (la.kind == 35) {
					lexer.NextToken();

#line  2264 "cs.ATG" 
					op = BinaryOperatorType.GreaterThanOrEqual; 
				} else SynErr(215);
				UnaryExpr(
#line  2266 "cs.ATG" 
out expr);
				ShiftExpr(
#line  2267 "cs.ATG" 
ref expr);

#line  2268 "cs.ATG" 
				outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; 
			} else {
				if (la.kind == 85) {
					lexer.NextToken();
					TypeWithRestriction(
#line  2271 "cs.ATG" 
out type, false, false);
					if (
#line  2272 "cs.ATG" 
la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) {
						NullableQuestionMark(
#line  2273 "cs.ATG" 
ref type);
					}

#line  2274 "cs.ATG" 
					outExpr = new TypeOfIsExpression(outExpr, type)  { StartLocation = startLocation, EndLocation = t.EndLocation }; 
				} else if (la.kind == 50) {
					lexer.NextToken();
					TypeWithRestriction(
#line  2276 "cs.ATG" 
out type, false, false);
					if (
#line  2277 "cs.ATG" 
la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) {
						NullableQuestionMark(
#line  2278 "cs.ATG" 
ref type);
					}

#line  2279 "cs.ATG" 
					outExpr = new CastExpression(type, outExpr, CastType.TryCast) { StartLocation = startLocation, EndLocation = t.EndLocation }; 
				} else SynErr(216);
			}
		}
	}
Example #16
0
	void SimpleNonInvocationExpression(
#line  1730 "VBNET.ATG" 
out Expression pexpr) {

#line  1732 "VBNET.ATG" 
		Expression expr;
		CollectionInitializerExpression cie;
		TypeReference type = null;
		string name = String.Empty;
		Location startLocation = la.Location;
		pexpr = null;
		
		if (StartOf(35)) {
			switch (la.kind) {
			case 3: {
				lexer.NextToken();

#line  1742 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 4: {
				lexer.NextToken();

#line  1743 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 7: {
				lexer.NextToken();

#line  1744 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 6: {
				lexer.NextToken();

#line  1745 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 5: {
				lexer.NextToken();

#line  1746 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 9: {
				lexer.NextToken();

#line  1747 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 8: {
				lexer.NextToken();

#line  1748 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 220: {
				lexer.NextToken();

#line  1750 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(true, "true");  
				break;
			}
			case 124: {
				lexer.NextToken();

#line  1751 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(false, "false"); 
				break;
			}
			case 168: {
				lexer.NextToken();

#line  1752 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(null, "null");  
				break;
			}
			case 37: {
				lexer.NextToken();
				Expr(
#line  1753 "VBNET.ATG" 
out expr);
				Expect(38);

#line  1753 "VBNET.ATG" 
				pexpr = new ParenthesizedExpression(expr); 
				break;
			}
			case 2: case 58: case 62: case 64: case 65: case 66: case 67: case 68: case 69: case 72: case 89: case 100: case 106: case 109: case 118: case 123: case 128: case 135: case 141: case 145: case 148: case 149: case 150: case 173: case 179: case 181: case 187: case 206: case 215: case 216: case 226: case 227: case 233: case 240: {
				Identifier();

#line  1755 "VBNET.ATG" 
				pexpr = new IdentifierExpression(t.val);
				pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation;
				
				if (
#line  1758 "VBNET.ATG" 
la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) {
					lexer.NextToken();
					Expect(172);
					TypeArgumentList(
#line  1759 "VBNET.ATG" 
((IdentifierExpression)pexpr).TypeArguments);
					Expect(38);
				}
				break;
			}
			case 70: case 73: case 84: case 101: case 102: case 111: case 143: case 154: case 171: case 199: case 204: case 205: case 211: case 224: case 225: case 228: {

#line  1761 "VBNET.ATG" 
				string val = String.Empty; 
				if (StartOf(12)) {
					PrimitiveTypeName(
#line  1762 "VBNET.ATG" 
out val);
				} else if (la.kind == 171) {
					lexer.NextToken();

#line  1762 "VBNET.ATG" 
					val = "System.Object"; 
				} else SynErr(284);

#line  1763 "VBNET.ATG" 
				pexpr = new TypeReferenceExpression(new TypeReference(val, true)); 
				break;
			}
			case 156: {
				lexer.NextToken();

#line  1764 "VBNET.ATG" 
				pexpr = new ThisReferenceExpression(); 
				break;
			}
			case 161: case 162: {

#line  1765 "VBNET.ATG" 
				Expression retExpr = null; 
				if (la.kind == 161) {
					lexer.NextToken();

#line  1766 "VBNET.ATG" 
					retExpr = new BaseReferenceExpression() { StartLocation = t.Location, EndLocation = t.EndLocation }; 
				} else if (la.kind == 162) {
					lexer.NextToken();

#line  1767 "VBNET.ATG" 
					retExpr = new ClassReferenceExpression() { StartLocation = t.Location, EndLocation = t.EndLocation }; 
				} else SynErr(285);
				Expect(26);
				IdentifierOrKeyword(
#line  1769 "VBNET.ATG" 
out name);

#line  1769 "VBNET.ATG" 
				pexpr = new MemberReferenceExpression(retExpr, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; 
				break;
			}
			case 132: {
				lexer.NextToken();
				Expect(26);
				Identifier();

#line  1771 "VBNET.ATG" 
				type = new TypeReference(t.val ?? ""); 

#line  1773 "VBNET.ATG" 
				type.IsGlobal = true; 

#line  1774 "VBNET.ATG" 
				pexpr = new TypeReferenceExpression(type); 
				break;
			}
			case 165: {
				ObjectCreateExpression(
#line  1775 "VBNET.ATG" 
out expr);

#line  1775 "VBNET.ATG" 
				pexpr = expr; 
				break;
			}
			case 35: {
				CollectionInitializer(
#line  1776 "VBNET.ATG" 
out cie);

#line  1776 "VBNET.ATG" 
				pexpr = cie; 
				break;
			}
			case 96: case 108: case 222: {

#line  1778 "VBNET.ATG" 
				CastType castType = CastType.Cast; 
				if (la.kind == 108) {
					lexer.NextToken();
				} else if (la.kind == 96) {
					lexer.NextToken();

#line  1780 "VBNET.ATG" 
					castType = CastType.Conversion; 
				} else if (la.kind == 222) {
					lexer.NextToken();

#line  1781 "VBNET.ATG" 
					castType = CastType.TryCast; 
				} else SynErr(286);
				Expect(37);
				Expr(
#line  1783 "VBNET.ATG" 
out expr);
				Expect(22);
				TypeName(
#line  1783 "VBNET.ATG" 
out type);
				Expect(38);

#line  1784 "VBNET.ATG" 
				pexpr = new CastExpression(type, expr, castType); 
				break;
			}
			case 78: case 79: case 80: case 81: case 82: case 83: case 85: case 87: case 88: case 92: case 93: case 94: case 95: case 97: case 98: case 99: {
				CastTarget(
#line  1785 "VBNET.ATG" 
out type);
				Expect(37);
				Expr(
#line  1785 "VBNET.ATG" 
out expr);
				Expect(38);

#line  1785 "VBNET.ATG" 
				pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); 
				break;
			}
			case 57: {
				lexer.NextToken();
				Expr(
#line  1786 "VBNET.ATG" 
out expr);

#line  1786 "VBNET.ATG" 
				pexpr = new AddressOfExpression(expr); 
				break;
			}
			case 131: {
				lexer.NextToken();
				Expect(37);
				GetTypeTypeName(
#line  1787 "VBNET.ATG" 
out type);
				Expect(38);

#line  1787 "VBNET.ATG" 
				pexpr = new TypeOfExpression(type); 
				break;
			}
			case 223: {
				lexer.NextToken();
				SimpleExpr(
#line  1788 "VBNET.ATG" 
out expr);
				Expect(146);
				TypeName(
#line  1788 "VBNET.ATG" 
out type);

#line  1788 "VBNET.ATG" 
				pexpr = new TypeOfIsExpression(expr, type); 
				break;
			}
			case 137: {
				ConditionalExpression(
#line  1789 "VBNET.ATG" 
out pexpr);
				break;
			}
			case 10: case 16: case 17: case 18: case 19: {
				XmlLiteralExpression(
#line  1790 "VBNET.ATG" 
out pexpr);
				break;
			}
			}
		} else if (StartOf(36)) {
			if (la.kind == 26) {
				lexer.NextToken();
				if (la.kind == 10) {
					lexer.NextToken();
					IdentifierOrKeyword(
#line  1796 "VBNET.ATG" 
out name);
					Expect(11);

#line  1797 "VBNET.ATG" 
					pexpr = new XmlMemberAccessExpression(null, XmlAxisType.Element, name, true) { StartLocation = startLocation, EndLocation = t.EndLocation }; 
				} else if (StartOf(34)) {
					IdentifierOrKeyword(
#line  1798 "VBNET.ATG" 
out name);

#line  1799 "VBNET.ATG" 
					pexpr = new MemberReferenceExpression(null, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; 
				} else SynErr(287);
			} else if (la.kind == 29) {
				lexer.NextToken();
				IdentifierOrKeyword(
#line  1801 "VBNET.ATG" 
out name);

#line  1801 "VBNET.ATG" 
				pexpr = new BinaryOperatorExpression(null, BinaryOperatorType.DictionaryAccess, new PrimitiveExpression(name, name) { StartLocation = t.Location, EndLocation = t.EndLocation }); 
			} else {

#line  1802 "VBNET.ATG" 
				XmlAxisType axisType = XmlAxisType.Element; bool isXmlIdentifier = false; 
				if (la.kind == 27) {
					lexer.NextToken();

#line  1803 "VBNET.ATG" 
					axisType = XmlAxisType.Descendents; 
				} else if (la.kind == 28) {
					lexer.NextToken();

#line  1803 "VBNET.ATG" 
					axisType = XmlAxisType.Attribute; 
				} else SynErr(288);
				if (la.kind == 10) {
					lexer.NextToken();

#line  1804 "VBNET.ATG" 
					isXmlIdentifier = true; 
				}
				IdentifierOrKeyword(
#line  1804 "VBNET.ATG" 
out name);
				if (la.kind == 11) {
					lexer.NextToken();
				}

#line  1805 "VBNET.ATG" 
				pexpr = new XmlMemberAccessExpression(null, axisType, name, isXmlIdentifier); 
			}
		} else SynErr(289);

#line  1810 "VBNET.ATG" 
		if (pexpr != null) {
		pexpr.StartLocation = startLocation;
		pexpr.EndLocation = t.EndLocation;
		}
		
	}
		private static INode ModifyLambdaForSelectMany(LambdaExpression lambdaExpression,
		                                               ParenthesizedExpression parenthesizedlambdaExpression,
		                                               InvocationExpression invocationExpression)
		{
			INode node = lambdaExpression;
			var argPos = invocationExpression.Arguments.IndexOf(lambdaExpression);
			switch (argPos)
			{
				case 0: // first one, select the collection
					// need to enter a cast for (IEnumerable<dynamic>) on the end of the lambda body
					var selectManyExpression = new LambdaExpression
					{
						ExpressionBody =
							new CastExpression(new TypeReference("IEnumerable<dynamic>"),
							                   new ParenthesizedExpression(lambdaExpression.ExpressionBody), CastType.Cast),
						Parameters = lambdaExpression.Parameters,
					};
					node = new CastExpression(new TypeReference("Func<dynamic, IEnumerable<dynamic>>"),
					                          new ParenthesizedExpression(selectManyExpression), CastType.Cast);
					break;
				case 1: // the transformation func
					node = new CastExpression(new TypeReference("Func<dynamic, dynamic, dynamic>"), parenthesizedlambdaExpression,
					                          CastType.Cast);
					break;
			}
			return node;
		}
Example #18
0
		public override object VisitCastExpression (CastExpression castExpression, object data) 
		{
			return CreateResult (castExpression.CastTo);
		}
Example #19
0
		public static IEnumerable<TreeNode> LazyGetItemsOfIList(Expression targetObject)
		{
			// This is needed for expanding IEnumerable<T>
			
			var type = new SimpleType() { Identifier = typeof(IList).FullName };
			type.AddAnnotation(typeof(IList));
			
			targetObject = new CastExpression() { Expression = targetObject.Clone(), Type = type };

			int count = 0;
			GetValueException error = null;
			try {
				count = GetIListCount(targetObject);
			} catch (GetValueException e) {
				// Cannot yield a value in the body of a catch clause (CS1631)
				error = e;
			}
			if (error != null) {
				yield return new TreeNode(null, "(error)", error.Message, null, null);
			} else if (count == 0) {
				yield return new TreeNode(null, "(empty)", null, null, null);
			} else {
				for(int i = 0; i < count; i++) {
					string imageName;
					var image = ExpressionNode.GetImageForArrayIndexer(out imageName);
					var expression = new ExpressionNode(image, "[" + i + "]", targetObject.AppendIndexer(i));
					expression.ImageName = imageName;
					yield return expression;
				}
			}
		}
 public override object TrackedVisitCastExpression(CastExpression castExpression, object data)
 {
     return castExpression.Expression.AcceptVisitor(this, data);
 }
 object ReplacePrimitiveCastWithConvertMethodCall(CastExpression castExpression, string methodName)
 {
     ReplaceCurrentNode(ExpressionBuilder.Identifier("Convert").Call(methodName, castExpression.Expression));
     return null;
 }
Example #22
0
 public override object VisitCastExpression(CastExpression castExpression, object data)
 {
     if (castExpression.CastType == CastType.TryCast)
         UnlockWith(castExpression);
     return base.VisitCastExpression(castExpression, data);
 }
		public virtual object TrackedVisitCastExpression(CastExpression castExpression, object data) {
			return base.VisitCastExpression(castExpression, data);
		}
Example #24
0
	void RelationalExpr(
//#line  2213 "cs.ATG" 
ref Expression outExpr) {

//#line  2215 "cs.ATG" 
		TypeReference type;
		Expression expr;
		BinaryOperatorType op = BinaryOperatorType.None;
		
		ShiftExpr(
//#line  2220 "cs.ATG" 
ref outExpr);
		while (StartOf(37)) {
			if (StartOf(38)) {
				if (la.kind == 23) {
					lexer.NextToken();

//#line  2222 "cs.ATG" 
					op = BinaryOperatorType.LessThan; 
				} else if (la.kind == 22) {
					lexer.NextToken();

//#line  2223 "cs.ATG" 
					op = BinaryOperatorType.GreaterThan; 
				} else if (la.kind == 36) {
					lexer.NextToken();

//#line  2224 "cs.ATG" 
					op = BinaryOperatorType.LessThanOrEqual; 
				} else if (la.kind == 35) {
					lexer.NextToken();

//#line  2225 "cs.ATG" 
					op = BinaryOperatorType.GreaterThanOrEqual; 
				} else SynErr(213);
				UnaryExpr(
//#line  2227 "cs.ATG" 
out expr);
				ShiftExpr(
//#line  2228 "cs.ATG" 
ref expr);

//#line  2229 "cs.ATG" 
				outExpr = new BinaryOperatorExpression(outExpr, op, expr); 
			} else {
				if (la.kind == 85) {
					lexer.NextToken();
					TypeWithRestriction(
//#line  2232 "cs.ATG" 
out type, false, false);
					if (
//#line  2233 "cs.ATG" 
la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) {
						NullableQuestionMark(
//#line  2234 "cs.ATG" 
ref type);
					}

//#line  2235 "cs.ATG" 
					outExpr = new TypeOfIsExpression(outExpr, type); 
				} else if (la.kind == 50) {
					lexer.NextToken();
					TypeWithRestriction(
//#line  2237 "cs.ATG" 
out type, false, false);
					if (
//#line  2238 "cs.ATG" 
la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) {
						NullableQuestionMark(
//#line  2239 "cs.ATG" 
ref type);
					}

//#line  2240 "cs.ATG" 
					outExpr = new CastExpression(type, outExpr, CastType.TryCast); 
				} else SynErr(214);
			}
		}
	}
		private static INode ModifyLambdaForMinMax(LambdaExpression lambdaExpression,
		                                           ParenthesizedExpression parenthesizedlambdaExpression)
		{
			var node = new CastExpression(new TypeReference("Func<dynamic, int>"), parenthesizedlambdaExpression, CastType.Cast);
			var castExpression = lambdaExpression.ExpressionBody as CastExpression;
			if (castExpression != null)
			{
				node = new CastExpression(new TypeReference("Func", new List<TypeReference>
				{
					new TypeReference("dynamic"),
					castExpression.CastTo
				}), parenthesizedlambdaExpression, CastType.Cast);
			}
			return node;
		}
Example #26
0
	void SimpleNonInvocationExpression(
#line  1593 "VBNET.ATG" 
out Expression pexpr) {

#line  1595 "VBNET.ATG" 
		Expression expr;
		TypeReference type = null;
		string name = String.Empty;
		pexpr = null;
		
		if (StartOf(29)) {
			switch (la.kind) {
			case 3: {
				lexer.NextToken();

#line  1603 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val);  
				break;
			}
			case 4: {
				lexer.NextToken();

#line  1604 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val);  
				break;
			}
			case 7: {
				lexer.NextToken();

#line  1605 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val);  
				break;
			}
			case 6: {
				lexer.NextToken();

#line  1606 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val);  
				break;
			}
			case 5: {
				lexer.NextToken();

#line  1607 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val);  
				break;
			}
			case 9: {
				lexer.NextToken();

#line  1608 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val);  
				break;
			}
			case 8: {
				lexer.NextToken();

#line  1609 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val);  
				break;
			}
			case 173: {
				lexer.NextToken();

#line  1611 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(true, "true");  
				break;
			}
			case 96: {
				lexer.NextToken();

#line  1612 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(false, "false"); 
				break;
			}
			case 130: {
				lexer.NextToken();

#line  1613 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(null, "null");  
				break;
			}
			case 24: {
				lexer.NextToken();
				Expr(
#line  1614 "VBNET.ATG" 
out expr);
				Expect(25);

#line  1614 "VBNET.ATG" 
				pexpr = new ParenthesizedExpression(expr); 
				break;
			}
			case 2: case 47: case 49: case 50: case 51: case 70: case 95: case 134: case 144: case 169: case 176: case 177: case 205: {
				Identifier();

#line  1616 "VBNET.ATG" 
				pexpr = new IdentifierExpression(t.val); 

#line  1617 "VBNET.ATG" 
				pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; 
				break;
			}
			case 52: case 54: case 65: case 76: case 77: case 84: case 111: case 117: case 133: case 159: case 160: case 165: case 191: case 192: case 193: case 194: {

#line  1618 "VBNET.ATG" 
				string val = String.Empty; 
				if (StartOf(10)) {
					PrimitiveTypeName(
#line  1619 "VBNET.ATG" 
out val);
				} else if (la.kind == 133) {
					lexer.NextToken();

#line  1619 "VBNET.ATG" 
					val = "Object"; 
				} else SynErr(240);
				Expect(10);

#line  1620 "VBNET.ATG" 
				t.val = ""; 
				Identifier();

#line  1620 "VBNET.ATG" 
				pexpr = new MemberReferenceExpression(new TypeReferenceExpression(val), t.val); 
				break;
			}
			case 119: {
				lexer.NextToken();

#line  1621 "VBNET.ATG" 
				pexpr = new ThisReferenceExpression(); 
				break;
			}
			case 124: case 125: {

#line  1622 "VBNET.ATG" 
				Expression retExpr = null; 
				if (la.kind == 124) {
					lexer.NextToken();

#line  1623 "VBNET.ATG" 
					retExpr = new BaseReferenceExpression(); 
				} else if (la.kind == 125) {
					lexer.NextToken();

#line  1624 "VBNET.ATG" 
					retExpr = new ClassReferenceExpression(); 
				} else SynErr(241);
				Expect(10);
				IdentifierOrKeyword(
#line  1626 "VBNET.ATG" 
out name);

#line  1626 "VBNET.ATG" 
				pexpr = new MemberReferenceExpression(retExpr, name); 
				break;
			}
			case 199: {
				lexer.NextToken();
				Expect(10);
				Identifier();

#line  1628 "VBNET.ATG" 
				type = new TypeReference(t.val ?? ""); 

#line  1630 "VBNET.ATG" 
				type.IsGlobal = true; 

#line  1631 "VBNET.ATG" 
				pexpr = new TypeReferenceExpression(type); 
				break;
			}
			case 127: {
				ObjectCreateExpression(
#line  1632 "VBNET.ATG" 
out expr);

#line  1632 "VBNET.ATG" 
				pexpr = expr; 
				break;
			}
			case 75: case 82: case 200: {

#line  1634 "VBNET.ATG" 
				CastType castType = CastType.Cast; 
				if (la.kind == 82) {
					lexer.NextToken();
				} else if (la.kind == 75) {
					lexer.NextToken();

#line  1636 "VBNET.ATG" 
					castType = CastType.Conversion; 
				} else if (la.kind == 200) {
					lexer.NextToken();

#line  1637 "VBNET.ATG" 
					castType = CastType.TryCast; 
				} else SynErr(242);
				Expect(24);
				Expr(
#line  1639 "VBNET.ATG" 
out expr);
				Expect(12);
				TypeName(
#line  1639 "VBNET.ATG" 
out type);
				Expect(25);

#line  1640 "VBNET.ATG" 
				pexpr = new CastExpression(type, expr, castType); 
				break;
			}
			case 59: case 60: case 61: case 62: case 63: case 64: case 66: case 68: case 69: case 72: case 73: case 74: case 195: case 196: case 197: case 198: {
				CastTarget(
#line  1641 "VBNET.ATG" 
out type);
				Expect(24);
				Expr(
#line  1641 "VBNET.ATG" 
out expr);
				Expect(25);

#line  1641 "VBNET.ATG" 
				pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); 
				break;
			}
			case 43: {
				lexer.NextToken();
				Expr(
#line  1642 "VBNET.ATG" 
out expr);

#line  1642 "VBNET.ATG" 
				pexpr = new AddressOfExpression(expr); 
				break;
			}
			case 102: {
				lexer.NextToken();
				Expect(24);
				GetTypeTypeName(
#line  1643 "VBNET.ATG" 
out type);
				Expect(25);

#line  1643 "VBNET.ATG" 
				pexpr = new TypeOfExpression(type); 
				break;
			}
			case 175: {
				lexer.NextToken();
				SimpleExpr(
#line  1644 "VBNET.ATG" 
out expr);
				Expect(113);
				TypeName(
#line  1644 "VBNET.ATG" 
out type);

#line  1644 "VBNET.ATG" 
				pexpr = new TypeOfIsExpression(expr, type); 
				break;
			}
			}
		} else if (la.kind == 10) {
			lexer.NextToken();
			IdentifierOrKeyword(
#line  1648 "VBNET.ATG" 
out name);

#line  1648 "VBNET.ATG" 
			pexpr = new MemberReferenceExpression(null, name);
		} else SynErr(243);
	}
        public override object VisitCastExpression(CastExpression castExpression, object data)
        {
            base.VisitCastExpression(castExpression, data);

            if (resolver.CompilationUnit == null)
                return null;

            IReturnType targetType = ResolveType(castExpression.CastTo);
            IClass targetClass = targetType != null ? targetType.GetUnderlyingClass() : null;
            if (castExpression.CastType != CastType.TryCast) {
                if (targetClass != null && (targetClass.ClassType == ClassType.Struct || targetClass.ClassType == ClassType.Enum)) {
                    // cast to value type is a conversion
                    castExpression.CastType = CastType.Conversion;
                    if (IsInteger(targetType)) {
                        ResolveResult sourceRR = resolver.ResolveInternal(castExpression.Expression, ExpressionContext.Default);
                        IReturnType sourceType = sourceRR != null ? sourceRR.ResolvedType : null;
                        if (IsFloatingPoint(sourceType)) {
                            // casts from float to int in C# truncate, but VB rounds
                            // we'll have to introduce a call to Math.Truncate
                            castExpression.Expression = ExpressionBuilder.Identifier("Math").Call("Truncate", castExpression.Expression);
                        } else if (sourceType != null && sourceType.FullyQualifiedName == "System.Char") {
                            // casts from char to int are valid in C#, but need to use AscW in VB
                            castExpression.Expression = ExpressionBuilder.Identifier("AscW").Call(castExpression.Expression);
                            if (targetType != null && targetType.FullyQualifiedName == "System.Int32") {
                                // AscW already returns int, so skip the cast
                                ReplaceCurrentNode(castExpression.Expression);
                                return null;
                            }
                        }
                    }
                }
                if (targetClass != null && targetClass.FullyQualifiedName == "System.Char") {
                    // C# cast to char is done using ChrW function
                    ResolveResult sourceRR = resolver.ResolveInternal(castExpression.Expression, ExpressionContext.Default);
                    IReturnType sourceType = sourceRR != null ? sourceRR.ResolvedType : null;
                    if (IsInteger(sourceType)) {
                        ReplaceCurrentNode(new IdentifierExpression("ChrW").Call(castExpression.Expression));
                    }
                }
            }
            return null;
        }
Example #28
0
	void RelationalExpr(
#line  2237 "Frames/cs.ATG" 
ref Expression outExpr) {

#line  2239 "Frames/cs.ATG" 
		TypeReference type;
		Expression expr;
		BinaryOperatorType op = BinaryOperatorType.None;
		
		ShiftExpr(
#line  2244 "Frames/cs.ATG" 
ref outExpr);
		while (StartOf(37)) {
			if (StartOf(38)) {
				if (la.kind == 23) {
					lexer.NextToken();

#line  2246 "Frames/cs.ATG" 
					op = BinaryOperatorType.LessThan; 
				} else if (la.kind == 22) {
					lexer.NextToken();

#line  2247 "Frames/cs.ATG" 
					op = BinaryOperatorType.GreaterThan; 
				} else if (la.kind == 36) {
					lexer.NextToken();

#line  2248 "Frames/cs.ATG" 
					op = BinaryOperatorType.LessThanOrEqual; 
				} else if (la.kind == 35) {
					lexer.NextToken();

#line  2249 "Frames/cs.ATG" 
					op = BinaryOperatorType.GreaterThanOrEqual; 
				} else SynErr(215);
				UnaryExpr(
#line  2251 "Frames/cs.ATG" 
out expr);
				ShiftExpr(
#line  2252 "Frames/cs.ATG" 
ref expr);

#line  2253 "Frames/cs.ATG" 
				outExpr = new BinaryOperatorExpression(outExpr, op, expr); 
			} else {
				if (la.kind == 85) {
					lexer.NextToken();
					TypeWithRestriction(
#line  2256 "Frames/cs.ATG" 
out type, false, false);
					if (
#line  2257 "Frames/cs.ATG" 
la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) {
						NullableQuestionMark(
#line  2258 "Frames/cs.ATG" 
ref type);
					}

#line  2259 "Frames/cs.ATG" 
					outExpr = new TypeOfIsExpression(outExpr, type); 
				} else if (la.kind == 50) {
					lexer.NextToken();
					TypeWithRestriction(
#line  2261 "Frames/cs.ATG" 
out type, false, false);
					if (
#line  2262 "Frames/cs.ATG" 
la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) {
						NullableQuestionMark(
#line  2263 "Frames/cs.ATG" 
ref type);
					}

#line  2264 "Frames/cs.ATG" 
					outExpr = new CastExpression(type, outExpr, CastType.TryCast); 
				} else SynErr(216);
			}
		}
	}
Example #29
0
	void SimpleNonInvocationExpression(
//#line  1723 "VBNET.ATG" 
out Expression pexpr) {

//#line  1725 "VBNET.ATG" 
		Expression expr;
		CollectionInitializerExpression cie;
		TypeReference type = null;
		string name = String.Empty;
		Location startLocation = la.Location;
		pexpr = null;
		
		if (StartOf(34)) {
			switch (la.kind) {
			case 3: {
				lexer.NextToken();

//#line  1735 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 4: {
				lexer.NextToken();

//#line  1736 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 7: {
				lexer.NextToken();

//#line  1737 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 6: {
				lexer.NextToken();

//#line  1738 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 5: {
				lexer.NextToken();

//#line  1739 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 9: {
				lexer.NextToken();

//#line  1740 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 8: {
				lexer.NextToken();

//#line  1741 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 217: {
				lexer.NextToken();

//#line  1743 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(true, "true");  
				break;
			}
			case 122: {
				lexer.NextToken();

//#line  1744 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(false, "false"); 
				break;
			}
			case 165: {
				lexer.NextToken();

//#line  1745 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(null, "null");  
				break;
			}
			case 37: {
				lexer.NextToken();
				Expr(
//#line  1746 "VBNET.ATG" 
out expr);
				Expect(38);

//#line  1746 "VBNET.ATG" 
				pexpr = new ParenthesizedExpression(expr); 
				break;
			}
			case 2: case 58: case 62: case 64: case 65: case 66: case 67: case 70: case 87: case 98: case 104: case 107: case 116: case 121: case 126: case 133: case 139: case 143: case 146: case 147: case 170: case 176: case 178: case 184: case 203: case 212: case 213: case 223: case 224: case 230: {
				Identifier();

//#line  1748 "VBNET.ATG" 
				pexpr = new IdentifierExpression(t.val);
				pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation;
				
				if (
//#line  1751 "VBNET.ATG" 
la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) {
					lexer.NextToken();
					Expect(169);
					TypeArgumentList(
//#line  1752 "VBNET.ATG" 
((IdentifierExpression)pexpr).TypeArguments);
					Expect(38);
				}
				break;
			}
			case 68: case 71: case 82: case 99: case 100: case 109: case 141: case 151: case 168: case 196: case 201: case 202: case 208: case 221: case 222: case 225: {

//#line  1754 "VBNET.ATG" 
				string val = String.Empty; 
				if (StartOf(12)) {
					PrimitiveTypeName(
//#line  1755 "VBNET.ATG" 
out val);
				} else if (la.kind == 168) {
					lexer.NextToken();

//#line  1755 "VBNET.ATG" 
					val = "System.Object"; 
				} else SynErr(280);

//#line  1756 "VBNET.ATG" 
				pexpr = new TypeReferenceExpression(new TypeReference(val, true)); 
				break;
			}
			case 153: {
				lexer.NextToken();

//#line  1757 "VBNET.ATG" 
				pexpr = new ThisReferenceExpression(); 
				break;
			}
			case 158: case 159: {

//#line  1758 "VBNET.ATG" 
				Expression retExpr = null; 
				if (la.kind == 158) {
					lexer.NextToken();

//#line  1759 "VBNET.ATG" 
					retExpr = new BaseReferenceExpression() { StartLocation = t.Location, EndLocation = t.EndLocation }; 
				} else if (la.kind == 159) {
					lexer.NextToken();

//#line  1760 "VBNET.ATG" 
					retExpr = new ClassReferenceExpression() { StartLocation = t.Location, EndLocation = t.EndLocation }; 
				} else SynErr(281);
				Expect(26);
				IdentifierOrKeyword(
//#line  1762 "VBNET.ATG" 
out name);

//#line  1762 "VBNET.ATG" 
				pexpr = new MemberReferenceExpression(retExpr, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; 
				break;
			}
			case 130: {
				lexer.NextToken();
				Expect(26);
				Identifier();

//#line  1764 "VBNET.ATG" 
				type = new TypeReference(t.val ?? ""); 

//#line  1766 "VBNET.ATG" 
				type.IsGlobal = true; 

//#line  1767 "VBNET.ATG" 
				pexpr = new TypeReferenceExpression(type); 
				break;
			}
			case 162: {
				ObjectCreateExpression(
//#line  1768 "VBNET.ATG" 
out expr);

//#line  1768 "VBNET.ATG" 
				pexpr = expr; 
				break;
			}
			case 35: {
				CollectionInitializer(
//#line  1769 "VBNET.ATG" 
out cie);

//#line  1769 "VBNET.ATG" 
				pexpr = cie; 
				break;
			}
			case 94: case 106: case 219: {

//#line  1771 "VBNET.ATG" 
				CastType castType = CastType.Cast; 
				if (la.kind == 106) {
					lexer.NextToken();
				} else if (la.kind == 94) {
					lexer.NextToken();

//#line  1773 "VBNET.ATG" 
					castType = CastType.Conversion; 
				} else if (la.kind == 219) {
					lexer.NextToken();

//#line  1774 "VBNET.ATG" 
					castType = CastType.TryCast; 
				} else SynErr(282);
				Expect(37);
				Expr(
//#line  1776 "VBNET.ATG" 
out expr);
				Expect(22);
				TypeName(
//#line  1776 "VBNET.ATG" 
out type);
				Expect(38);

//#line  1777 "VBNET.ATG" 
				pexpr = new CastExpression(type, expr, castType); 
				break;
			}
			case 76: case 77: case 78: case 79: case 80: case 81: case 83: case 85: case 86: case 90: case 91: case 92: case 93: case 95: case 96: case 97: {
				CastTarget(
//#line  1778 "VBNET.ATG" 
out type);
				Expect(37);
				Expr(
//#line  1778 "VBNET.ATG" 
out expr);
				Expect(38);

//#line  1778 "VBNET.ATG" 
				pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); 
				break;
			}
			case 57: {
				lexer.NextToken();
				Expr(
//#line  1779 "VBNET.ATG" 
out expr);

//#line  1779 "VBNET.ATG" 
				pexpr = new AddressOfExpression(expr); 
				break;
			}
			case 129: {
				lexer.NextToken();
				Expect(37);
				GetTypeTypeName(
//#line  1780 "VBNET.ATG" 
out type);
				Expect(38);

//#line  1780 "VBNET.ATG" 
				pexpr = new TypeOfExpression(type); 
				break;
			}
			case 220: {
				lexer.NextToken();
				SimpleExpr(
//#line  1781 "VBNET.ATG" 
out expr);
				Expect(144);
				TypeName(
//#line  1781 "VBNET.ATG" 
out type);

//#line  1781 "VBNET.ATG" 
				pexpr = new TypeOfIsExpression(expr, type); 
				break;
			}
			case 135: {
				ConditionalExpression(
//#line  1782 "VBNET.ATG" 
out pexpr);
				break;
			}
			case 10: case 16: case 17: case 18: case 19: {
				XmlLiteralExpression(
//#line  1783 "VBNET.ATG" 
out pexpr);
				break;
			}
			}
		} else if (StartOf(35)) {
			if (la.kind == 26) {
				lexer.NextToken();
				if (la.kind == 10) {
					lexer.NextToken();
					IdentifierOrKeyword(
//#line  1789 "VBNET.ATG" 
out name);
					Expect(11);

//#line  1790 "VBNET.ATG" 
					pexpr = new XmlMemberAccessExpression(null, XmlAxisType.Element, name, true) { StartLocation = startLocation, EndLocation = t.EndLocation }; 
				} else if (StartOf(33)) {
					IdentifierOrKeyword(
//#line  1791 "VBNET.ATG" 
out name);

//#line  1792 "VBNET.ATG" 
					pexpr = new MemberReferenceExpression(null, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; 
				} else SynErr(283);
			} else if (la.kind == 29) {
				lexer.NextToken();
				IdentifierOrKeyword(
//#line  1794 "VBNET.ATG" 
out name);

//#line  1794 "VBNET.ATG" 
				pexpr = new BinaryOperatorExpression(null, BinaryOperatorType.DictionaryAccess, new PrimitiveExpression(name, name) { StartLocation = t.Location, EndLocation = t.EndLocation }); 
			} else {

//#line  1795 "VBNET.ATG" 
				XmlAxisType axisType = XmlAxisType.Element; bool isXmlIdentifier = false; 
				if (la.kind == 27) {
					lexer.NextToken();

//#line  1796 "VBNET.ATG" 
					axisType = XmlAxisType.Descendents; 
				} else if (la.kind == 28) {
					lexer.NextToken();

//#line  1796 "VBNET.ATG" 
					axisType = XmlAxisType.Attribute; 
				} else SynErr(284);
				if (la.kind == 10) {
					lexer.NextToken();

//#line  1797 "VBNET.ATG" 
					isXmlIdentifier = true; 
				}
				IdentifierOrKeyword(
//#line  1797 "VBNET.ATG" 
out name);
				if (la.kind == 11) {
					lexer.NextToken();
				}

//#line  1798 "VBNET.ATG" 
				pexpr = new XmlMemberAccessExpression(null, axisType, name, isXmlIdentifier); 
			}
		} else SynErr(285);

//#line  1803 "VBNET.ATG" 
		if (pexpr != null) {
		pexpr.StartLocation = startLocation;
		pexpr.EndLocation = t.EndLocation;
		}
		
	}
Example #30
0
 public override object VisitCastExpression(CastExpression castExpression, object data)
 {
     CodeTypeReference typeRef = ConvType(castExpression.CastTo);
     return new CodeCastExpression(typeRef, (CodeExpression)castExpression.Expression.AcceptVisitor(this, data));
 }