Example #1
0
		public ResolveResult Resolve (Expression expression)
		{
			ResolveResult result = expression.AcceptVisitor (this, null) as ResolveResult;
			if (result == null)
				result = CreateResult ("");
			return result;
		}
		public static void Assign(this BlockStatement block, Expression left, Expression right)
		{
			if (left == null)
				throw new ArgumentNullException("left");
			if (right == null)
				throw new ArgumentNullException("right");
			AddStatement(block, new AssignmentExpression(left, AssignmentOperatorType.Assign, right));
		}
		public LocalLookupVariable(string name, TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression, bool isQueryContinuation, Location inListPosition)
		{
			this.Name = name;
			this.TypeRef = typeRef;
			this.StartPos = startPos;
			this.EndPos = endPos;
			this.IsConst = isConst;
			this.IsLoopVariable = isLoopVariable;
			this.Initializer = initializer;
			this.ParentLambdaExpression = parentLambdaExpression;
			this.IsQueryContinuation = isQueryContinuation;
			this.InListPosition = inListPosition;
		}
Example #4
0
		/// <summary>
		/// Returns the existing expression plus the specified integer value.
		/// The old <paramref name="expr"/> object is not modified, but might be a subobject on the new expression
		/// (and thus its parent property is modified).
		/// </summary>
		public static Expression AddInteger(Expression expr, int value)
		{
			PrimitiveExpression pe = expr as PrimitiveExpression;
			if (pe != null && pe.Value is int) {
				int newVal = (int)pe.Value + value;
				return new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
			}
			BinaryOperatorExpression boe = expr as BinaryOperatorExpression;
			if (boe != null && boe.Op == BinaryOperatorType.Add) {
				// clone boe:
				boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right);
				
				boe.Right = AddInteger(boe.Right, value);
				if (boe.Right is PrimitiveExpression && ((PrimitiveExpression)boe.Right).Value is int) {
					int newVal = (int)((PrimitiveExpression)boe.Right).Value;
					if (newVal == 0) {
						return boe.Left;
					} else if (newVal < 0) {
						((PrimitiveExpression)boe.Right).Value = -newVal;
						boe.Op = BinaryOperatorType.Subtract;
					}
				}
				return boe;
			}
			if (boe != null && boe.Op == BinaryOperatorType.Subtract) {
				pe = boe.Right as PrimitiveExpression;
				if (pe != null && pe.Value is int) {
					int newVal = (int)pe.Value - value;
					if (newVal == 0)
						return boe.Left;
					
					// clone boe:
					boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right);
					
					if (newVal < 0) {
						newVal = -newVal;
						boe.Op = BinaryOperatorType.Add;
					}
					boe.Right = new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
					return boe;
				}
			}
			BinaryOperatorType opType = BinaryOperatorType.Add;
			if (value < 0) {
				value = -value;
				opType = BinaryOperatorType.Subtract;
			}
			return new BinaryOperatorExpression(expr, opType, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)));
		}
		public void AddVariable(TypeReference typeRef, string name,
		                        Location startPos, Location endPos, bool isConst,
		                        bool isLoopVariable, Expression initializer,
		                        LambdaExpression parentLambdaExpression,
		                        bool isQueryContinuation, Location inListPosition)
		{
			if (name == null || name.Length == 0) {
				return;
			}
			List<LocalLookupVariable> list;
			if (!variables.ContainsKey(name)) {
				variables[name] = list = new List<LocalLookupVariable>();
			} else {
				list = (List<LocalLookupVariable>)variables[name];
			}
			list.Add(new LocalLookupVariable (name, typeRef, startPos, endPos, isConst, isLoopVariable, initializer, parentLambdaExpression, isQueryContinuation, inListPosition));
		}
Example #6
0
		public IReturnType GetTypeSafe (Expression expression)
		{
			ResolveResult result = Resolve (expression);
			if (expression is LambdaExpression) {
				var lambda = (LambdaExpression)expression; 
				var bodyType = GetTypeSafe (lambda.ExpressionBody);
				DomReturnType constructedLambdaType = new DomReturnType (bodyType.FullName == DomReturnType.Void.FullName ? "System.Action" : "System.Func");
				foreach (var param in lambda.Parameters) {
					var typeParam = GetTypeSafe (param);
					// add void place holder for types that can't be resolved.
					if (typeParam == null || string.IsNullOrEmpty (typeParam.FullName))
						typeParam = DomReturnType.Void;
					constructedLambdaType.AddTypeParameter (typeParam);
				}
				if (bodyType.FullName != DomReturnType.Void.FullName)
					constructedLambdaType.AddTypeParameter (bodyType ?? result.ResolvedType);
				return constructedLambdaType;
			}
			return result.ResolvedType ?? DomReturnType.Void;
		}
Example #7
0
	void InclusiveOrExpr(
#line  2205 "Frames/cs.ATG" 
ref Expression outExpr) {

#line  2206 "Frames/cs.ATG" 
		Expression expr; 
		ExclusiveOrExpr(
#line  2208 "Frames/cs.ATG" 
ref outExpr);
		while (la.kind == 29) {
			lexer.NextToken();
			UnaryExpr(
#line  2208 "Frames/cs.ATG" 
out expr);
			ExclusiveOrExpr(
#line  2208 "Frames/cs.ATG" 
ref expr);

#line  2208 "Frames/cs.ATG" 
			outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr);  
		}
	}
Example #8
0
	void ConditionalAndExpr(
#line  2199 "Frames/cs.ATG" 
ref Expression outExpr) {

#line  2200 "Frames/cs.ATG" 
		Expression expr; 
		InclusiveOrExpr(
#line  2202 "Frames/cs.ATG" 
ref outExpr);
		while (la.kind == 25) {
			lexer.NextToken();
			UnaryExpr(
#line  2202 "Frames/cs.ATG" 
out expr);
			InclusiveOrExpr(
#line  2202 "Frames/cs.ATG" 
ref expr);

#line  2202 "Frames/cs.ATG" 
			outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr);  
		}
	}
Example #9
0
	void ObjectPropertyInitializerOrVariableInitializer(
#line  1461 "Frames/cs.ATG" 
out Expression expr) {

#line  1462 "Frames/cs.ATG" 
		expr = null; 
		if (
#line  1464 "Frames/cs.ATG" 
IdentAndAsgn()) {
			Identifier();

#line  1466 "Frames/cs.ATG" 
			NamedArgumentExpression nae = new NamedArgumentExpression(t.val, null);
			nae.StartLocation = t.Location;
			Expression r = null; 
			Expect(3);
			if (la.kind == 16) {
				CollectionOrObjectInitializer(
#line  1470 "Frames/cs.ATG" 
out r);
			} else if (StartOf(31)) {
				VariableInitializer(
#line  1471 "Frames/cs.ATG" 
out r);
			} else SynErr(195);

#line  1472 "Frames/cs.ATG" 
			nae.Expression = r; nae.EndLocation = t.EndLocation; expr = nae; 
		} else if (StartOf(31)) {
			VariableInitializer(
#line  1474 "Frames/cs.ATG" 
out expr);
		} else SynErr(196);
	}
Example #10
0
	void CollectionInitializer(
#line  1425 "Frames/cs.ATG" 
out Expression outExpr) {

#line  1427 "Frames/cs.ATG" 
		Expression expr = null;
		CollectionInitializerExpression initializer = new CollectionInitializerExpression();
		
		Expect(16);

#line  1431 "Frames/cs.ATG" 
		initializer.StartLocation = t.Location; 
		if (StartOf(31)) {
			VariableInitializer(
#line  1432 "Frames/cs.ATG" 
out expr);

#line  1433 "Frames/cs.ATG" 
			SafeAdd(initializer, initializer.CreateExpressions, expr); 
			while (
#line  1434 "Frames/cs.ATG" 
NotFinalComma()) {
				Expect(14);
				VariableInitializer(
#line  1435 "Frames/cs.ATG" 
out expr);

#line  1436 "Frames/cs.ATG" 
				SafeAdd(initializer, initializer.CreateExpressions, expr); 
			}
			if (la.kind == 14) {
				lexer.NextToken();
			}
		}
		Expect(17);

#line  1440 "Frames/cs.ATG" 
		initializer.EndLocation = t.Location; outExpr = initializer; 
	}
Example #11
0
	void MultiplicativeExpr(
#line  2304 "Frames/cs.ATG" 
ref Expression outExpr) {

#line  2306 "Frames/cs.ATG" 
		Expression expr;
		BinaryOperatorType op = BinaryOperatorType.None;
		
		while (la.kind == 6 || la.kind == 7 || la.kind == 8) {
			if (la.kind == 6) {
				lexer.NextToken();

#line  2312 "Frames/cs.ATG" 
				op = BinaryOperatorType.Multiply; 
			} else if (la.kind == 7) {
				lexer.NextToken();

#line  2313 "Frames/cs.ATG" 
				op = BinaryOperatorType.Divide; 
			} else {
				lexer.NextToken();

#line  2314 "Frames/cs.ATG" 
				op = BinaryOperatorType.Modulus; 
			}
			UnaryExpr(
#line  2316 "Frames/cs.ATG" 
out expr);

#line  2316 "Frames/cs.ATG" 
			outExpr = new BinaryOperatorExpression(outExpr, op, expr); 
		}
	}
Example #12
0
	void ShiftExpr(
#line  2271 "Frames/cs.ATG" 
ref Expression outExpr) {

#line  2273 "Frames/cs.ATG" 
		Expression expr;
		BinaryOperatorType op = BinaryOperatorType.None;
		
		AdditiveExpr(
#line  2277 "Frames/cs.ATG" 
ref outExpr);
		while (la.kind == 37 || 
#line  2280 "Frames/cs.ATG" 
IsShiftRight()) {
			if (la.kind == 37) {
				lexer.NextToken();

#line  2279 "Frames/cs.ATG" 
				op = BinaryOperatorType.ShiftLeft; 
			} else {
				Expect(22);
				Expect(22);

#line  2281 "Frames/cs.ATG" 
				op = BinaryOperatorType.ShiftRight; 
			}
			UnaryExpr(
#line  2284 "Frames/cs.ATG" 
out expr);
			AdditiveExpr(
#line  2284 "Frames/cs.ATG" 
ref expr);

#line  2284 "Frames/cs.ATG" 
			outExpr = new BinaryOperatorExpression(outExpr, op, expr);  
		}
	}
Example #13
0
	void EqualityExpr(
#line  2223 "Frames/cs.ATG" 
ref Expression outExpr) {

#line  2225 "Frames/cs.ATG" 
		Expression expr;
		BinaryOperatorType op = BinaryOperatorType.None;
		
		RelationalExpr(
#line  2229 "Frames/cs.ATG" 
ref outExpr);
		while (la.kind == 33 || la.kind == 34) {
			if (la.kind == 34) {
				lexer.NextToken();

#line  2232 "Frames/cs.ATG" 
				op = BinaryOperatorType.InEquality; 
			} else {
				lexer.NextToken();

#line  2233 "Frames/cs.ATG" 
				op = BinaryOperatorType.Equality; 
			}
			UnaryExpr(
#line  2235 "Frames/cs.ATG" 
out expr);
			RelationalExpr(
#line  2235 "Frames/cs.ATG" 
ref expr);

#line  2235 "Frames/cs.ATG" 
			outExpr = new BinaryOperatorExpression(outExpr, op, expr);  
		}
	}
Example #14
0
	void LambdaExpression(
#line  2093 "Frames/cs.ATG" 
out Expression outExpr) {

#line  2095 "Frames/cs.ATG" 
		LambdaExpression lambda = new LambdaExpression();
		lambda.StartLocation = la.Location;
		ParameterDeclarationExpression p;
		outExpr = lambda;
		
		Expect(20);
		if (StartOf(18)) {
			LambdaExpressionParameter(
#line  2103 "Frames/cs.ATG" 
out p);

#line  2103 "Frames/cs.ATG" 
			SafeAdd(lambda, lambda.Parameters, p); 
			while (la.kind == 14) {
				lexer.NextToken();
				LambdaExpressionParameter(
#line  2105 "Frames/cs.ATG" 
out p);

#line  2105 "Frames/cs.ATG" 
				SafeAdd(lambda, lambda.Parameters, p); 
			}
		}
		Expect(21);
		Expect(48);
		LambdaExpressionBody(
#line  2110 "Frames/cs.ATG" 
lambda);
	}
Example #15
0
	void ShortedLambdaExpression(
#line  2113 "Frames/cs.ATG" 
IdentifierExpression ident, out Expression pexpr) {

#line  2114 "Frames/cs.ATG" 
		LambdaExpression lambda = new LambdaExpression(); pexpr = lambda; 
		Expect(48);

#line  2119 "Frames/cs.ATG" 
		lambda.StartLocation = ident.StartLocation;
		SafeAdd(lambda, lambda.Parameters, new ParameterDeclarationExpression(null, ident.Identifier));
		lambda.Parameters[0].StartLocation = ident.StartLocation;
		lambda.Parameters[0].EndLocation = ident.EndLocation;
		
		LambdaExpressionBody(
#line  2124 "Frames/cs.ATG" 
lambda);
	}
Example #16
0
	void QueryExpression(
#line  2431 "Frames/cs.ATG" 
out Expression outExpr) {

#line  2432 "Frames/cs.ATG" 
		QueryExpression q = new QueryExpression(); outExpr = q; q.StartLocation = la.Location; 
		QueryExpressionFromClause fromClause;
		
		QueryExpressionFromClause(
#line  2436 "Frames/cs.ATG" 
out fromClause);

#line  2436 "Frames/cs.ATG" 
		q.FromClause = fromClause; 
		QueryExpressionBody(
#line  2437 "Frames/cs.ATG" 
ref q);

#line  2438 "Frames/cs.ATG" 
		q.EndLocation = t.EndLocation; 
		outExpr = q; /* set outExpr to q again if QueryExpressionBody changed it (can happen with 'into' clauses) */ 
		
	}
Example #17
0
	void PrimaryExpr(
#line  1888 "Frames/cs.ATG" 
out Expression pexpr) {

#line  1890 "Frames/cs.ATG" 
		TypeReference type = null;
		Expression expr;
		pexpr = null;
		

#line  1895 "Frames/cs.ATG" 
		Location startLocation = la.Location; 
		if (la.kind == 113) {
			lexer.NextToken();

#line  1897 "Frames/cs.ATG" 
			pexpr = new PrimitiveExpression(true, "true");  
		} else if (la.kind == 72) {
			lexer.NextToken();

#line  1898 "Frames/cs.ATG" 
			pexpr = new PrimitiveExpression(false, "false"); 
		} else if (la.kind == 90) {
			lexer.NextToken();

#line  1899 "Frames/cs.ATG" 
			pexpr = new PrimitiveExpression(null, "null");  
		} else if (la.kind == 2) {
			lexer.NextToken();

#line  1900 "Frames/cs.ATG" 
			pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
		} else if (
#line  1901 "Frames/cs.ATG" 
StartOfQueryExpression()) {
			QueryExpression(
#line  1902 "Frames/cs.ATG" 
out pexpr);
		} else if (
#line  1903 "Frames/cs.ATG" 
IdentAndDoubleColon()) {
			Identifier();

#line  1904 "Frames/cs.ATG" 
			type = new TypeReference(t.val); 
			Expect(10);

#line  1905 "Frames/cs.ATG" 
			pexpr = new TypeReferenceExpression(type); 
			Identifier();

#line  1906 "Frames/cs.ATG" 
			if (type.Type == "global") { type.IsGlobal = true; type.Type = t.val ?? "?"; } else type.Type += "." + (t.val ?? "?"); 
		} else if (StartOf(19)) {
			Identifier();

#line  1910 "Frames/cs.ATG" 
			pexpr = new IdentifierExpression(t.val); 
			if (la.kind == 48 || 
#line  1913 "Frames/cs.ATG" 
IsGenericInSimpleNameOrMemberAccess()) {
				if (la.kind == 48) {
					ShortedLambdaExpression(
#line  1912 "Frames/cs.ATG" 
(IdentifierExpression)pexpr, out pexpr);
				} else {

#line  1914 "Frames/cs.ATG" 
					List<TypeReference> typeList; 
					TypeArgumentList(
#line  1915 "Frames/cs.ATG" 
out typeList, false);

#line  1916 "Frames/cs.ATG" 
					((IdentifierExpression)pexpr).TypeArguments = typeList; 
				}
			}
		} else if (
#line  1918 "Frames/cs.ATG" 
IsLambdaExpression()) {
			LambdaExpression(
#line  1919 "Frames/cs.ATG" 
out pexpr);
		} else if (la.kind == 20) {
			lexer.NextToken();
			Expr(
#line  1922 "Frames/cs.ATG" 
out expr);
			Expect(21);

#line  1922 "Frames/cs.ATG" 
			pexpr = new ParenthesizedExpression(expr); 
		} else if (StartOf(35)) {

#line  1925 "Frames/cs.ATG" 
			string val = null; 
			switch (la.kind) {
			case 52: {
				lexer.NextToken();

#line  1926 "Frames/cs.ATG" 
				val = "System.Boolean"; 
				break;
			}
			case 54: {
				lexer.NextToken();

#line  1927 "Frames/cs.ATG" 
				val = "System.Byte"; 
				break;
			}
			case 57: {
				lexer.NextToken();

#line  1928 "Frames/cs.ATG" 
				val = "System.Char"; 
				break;
			}
			case 62: {
				lexer.NextToken();

#line  1929 "Frames/cs.ATG" 
				val = "System.Decimal"; 
				break;
			}
			case 66: {
				lexer.NextToken();

#line  1930 "Frames/cs.ATG" 
				val = "System.Double"; 
				break;
			}
			case 75: {
				lexer.NextToken();

#line  1931 "Frames/cs.ATG" 
				val = "System.Single"; 
				break;
			}
			case 82: {
				lexer.NextToken();

#line  1932 "Frames/cs.ATG" 
				val = "System.Int32"; 
				break;
			}
			case 87: {
				lexer.NextToken();

#line  1933 "Frames/cs.ATG" 
				val = "System.Int64"; 
				break;
			}
			case 91: {
				lexer.NextToken();

#line  1934 "Frames/cs.ATG" 
				val = "System.Object"; 
				break;
			}
			case 102: {
				lexer.NextToken();

#line  1935 "Frames/cs.ATG" 
				val = "System.SByte"; 
				break;
			}
			case 104: {
				lexer.NextToken();

#line  1936 "Frames/cs.ATG" 
				val = "System.Int16"; 
				break;
			}
			case 108: {
				lexer.NextToken();

#line  1937 "Frames/cs.ATG" 
				val = "System.String"; 
				break;
			}
			case 116: {
				lexer.NextToken();

#line  1938 "Frames/cs.ATG" 
				val = "System.UInt32"; 
				break;
			}
			case 117: {
				lexer.NextToken();

#line  1939 "Frames/cs.ATG" 
				val = "System.UInt64"; 
				break;
			}
			case 120: {
				lexer.NextToken();

#line  1940 "Frames/cs.ATG" 
				val = "System.UInt16"; 
				break;
			}
			case 123: {
				lexer.NextToken();

#line  1941 "Frames/cs.ATG" 
				val = "System.Void"; 
				break;
			}
			}

#line  1943 "Frames/cs.ATG" 
			pexpr = new TypeReferenceExpression(new TypeReference(val, true)) { StartLocation = t.Location, EndLocation = t.EndLocation }; 
		} else if (la.kind == 111) {
			lexer.NextToken();

#line  1946 "Frames/cs.ATG" 
			pexpr = new ThisReferenceExpression(); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; 
		} else if (la.kind == 51) {
			lexer.NextToken();

#line  1948 "Frames/cs.ATG" 
			pexpr = new BaseReferenceExpression(); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; 
		} else if (la.kind == 89) {
			NewExpression(
#line  1951 "Frames/cs.ATG" 
out pexpr);
		} else if (la.kind == 115) {
			lexer.NextToken();
			Expect(20);
			if (
#line  1955 "Frames/cs.ATG" 
NotVoidPointer()) {
				Expect(123);

#line  1955 "Frames/cs.ATG" 
				type = new TypeReference("System.Void", true); 
			} else if (StartOf(10)) {
				TypeWithRestriction(
#line  1956 "Frames/cs.ATG" 
out type, true, true);
			} else SynErr(207);
			Expect(21);

#line  1958 "Frames/cs.ATG" 
			pexpr = new TypeOfExpression(type); 
		} else if (la.kind == 63) {
			lexer.NextToken();
			Expect(20);
			Type(
#line  1960 "Frames/cs.ATG" 
out type);
			Expect(21);

#line  1960 "Frames/cs.ATG" 
			pexpr = new DefaultValueExpression(type); 
		} else if (la.kind == 105) {
			lexer.NextToken();
			Expect(20);
			Type(
#line  1961 "Frames/cs.ATG" 
out type);
			Expect(21);

#line  1961 "Frames/cs.ATG" 
			pexpr = new SizeOfExpression(type); 
		} else if (la.kind == 58) {
			lexer.NextToken();
			Expect(20);
			Expr(
#line  1962 "Frames/cs.ATG" 
out expr);
			Expect(21);

#line  1962 "Frames/cs.ATG" 
			pexpr = new CheckedExpression(expr); 
		} else if (la.kind == 118) {
			lexer.NextToken();
			Expect(20);
			Expr(
#line  1963 "Frames/cs.ATG" 
out expr);
			Expect(21);

#line  1963 "Frames/cs.ATG" 
			pexpr = new UncheckedExpression(expr); 
		} else if (la.kind == 64) {
			lexer.NextToken();
			AnonymousMethodExpr(
#line  1964 "Frames/cs.ATG" 
out expr);

#line  1964 "Frames/cs.ATG" 
			pexpr = expr; 
		} else SynErr(208);

#line  1966 "Frames/cs.ATG" 
		if (pexpr != null) {
		if (pexpr.StartLocation.IsEmpty)
			pexpr.StartLocation = startLocation;
		if (pexpr.EndLocation.IsEmpty)
			pexpr.EndLocation = t.EndLocation;
		}
		
		while (StartOf(36)) {
			if (la.kind == 31 || la.kind == 32) {

#line  1974 "Frames/cs.ATG" 
				startLocation = la.Location; 
				if (la.kind == 31) {
					lexer.NextToken();

#line  1976 "Frames/cs.ATG" 
					pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); 
				} else if (la.kind == 32) {
					lexer.NextToken();

#line  1977 "Frames/cs.ATG" 
					pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); 
				} else SynErr(209);
			} else if (la.kind == 47) {
				PointerMemberAccess(
#line  1980 "Frames/cs.ATG" 
out pexpr, pexpr);
			} else if (la.kind == 15) {
				MemberAccess(
#line  1981 "Frames/cs.ATG" 
out pexpr, pexpr);
			} else if (la.kind == 20) {
				lexer.NextToken();

#line  1985 "Frames/cs.ATG" 
				List<Expression> parameters = new List<Expression>(); 

#line  1986 "Frames/cs.ATG" 
				pexpr = new InvocationExpression(pexpr, parameters); pexpr.StartLocation = startLocation; 
				if (StartOf(26)) {
					Argument(
#line  1987 "Frames/cs.ATG" 
out expr);

#line  1987 "Frames/cs.ATG" 
					SafeAdd(pexpr, parameters, expr); 
					while (la.kind == 14) {
						lexer.NextToken();
						Argument(
#line  1988 "Frames/cs.ATG" 
out expr);

#line  1988 "Frames/cs.ATG" 
						SafeAdd(pexpr, parameters, expr); 
					}
				}
				Expect(21);
			} else {

#line  1994 "Frames/cs.ATG" 
				List<Expression> indices = new List<Expression>();
				pexpr = new IndexerExpression(pexpr, indices);
				
				lexer.NextToken();
				Expr(
#line  1997 "Frames/cs.ATG" 
out expr);

#line  1997 "Frames/cs.ATG" 
				SafeAdd(pexpr, indices, expr); 
				while (la.kind == 14) {
					lexer.NextToken();
					Expr(
#line  1998 "Frames/cs.ATG" 
out expr);

#line  1998 "Frames/cs.ATG" 
					SafeAdd(pexpr, indices, expr); 
				}
				Expect(19);

#line  2001 "Frames/cs.ATG" 
				if (pexpr != null) {
				pexpr.StartLocation = startLocation;
				pexpr.EndLocation = t.EndLocation;
				}
				
			}
		}
	}
Example #18
0
	void ConditionalOrExpr(
#line  2193 "Frames/cs.ATG" 
ref Expression outExpr) {

#line  2194 "Frames/cs.ATG" 
		Expression expr;   
		ConditionalAndExpr(
#line  2196 "Frames/cs.ATG" 
ref outExpr);
		while (la.kind == 26) {
			lexer.NextToken();
			UnaryExpr(
#line  2196 "Frames/cs.ATG" 
out expr);
			ConditionalAndExpr(
#line  2196 "Frames/cs.ATG" 
ref expr);

#line  2196 "Frames/cs.ATG" 
			outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr);  
		}
	}
Example #19
0
	void UnaryExpr(
#line  1828 "Frames/cs.ATG" 
out Expression uExpr) {

#line  1830 "Frames/cs.ATG" 
		TypeReference type = null;
		Expression expr = null;
		ArrayList expressions = new ArrayList();
		uExpr = null;
		
		while (StartOf(33) || 
#line  1852 "Frames/cs.ATG" 
IsTypeCast()) {
			if (la.kind == 4) {
				lexer.NextToken();

#line  1839 "Frames/cs.ATG" 
				expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Plus)); 
			} else if (la.kind == 5) {
				lexer.NextToken();

#line  1840 "Frames/cs.ATG" 
				expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Minus)); 
			} else if (la.kind == 24) {
				lexer.NextToken();

#line  1841 "Frames/cs.ATG" 
				expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Not)); 
			} else if (la.kind == 27) {
				lexer.NextToken();

#line  1842 "Frames/cs.ATG" 
				expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitNot)); 
			} else if (la.kind == 6) {
				lexer.NextToken();

#line  1843 "Frames/cs.ATG" 
				expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Dereference)); 
			} else if (la.kind == 31) {
				lexer.NextToken();

#line  1844 "Frames/cs.ATG" 
				expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Increment)); 
			} else if (la.kind == 32) {
				lexer.NextToken();

#line  1845 "Frames/cs.ATG" 
				expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Decrement)); 
			} else if (la.kind == 28) {
				lexer.NextToken();

#line  1846 "Frames/cs.ATG" 
				expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.AddressOf)); 
			} else {
				Expect(20);
				Type(
#line  1852 "Frames/cs.ATG" 
out type);
				Expect(21);

#line  1852 "Frames/cs.ATG" 
				expressions.Add(new CastExpression(type)); 
			}
		}
		if (
#line  1857 "Frames/cs.ATG" 
LastExpressionIsUnaryMinus(expressions) && IsMostNegativeIntegerWithoutTypeSuffix()) {
			Expect(2);

#line  1860 "Frames/cs.ATG" 
			expressions.RemoveAt(expressions.Count - 1);
			if (t.literalValue is uint) {
				expr = new PrimitiveExpression(int.MinValue, int.MinValue.ToString());
			} else if (t.literalValue is ulong) {
				expr = new PrimitiveExpression(long.MinValue, long.MinValue.ToString());
			} else {
				throw new Exception("t.literalValue must be uint or ulong");
			}
			
		} else if (StartOf(34)) {
			PrimaryExpr(
#line  1869 "Frames/cs.ATG" 
out expr);
		} else SynErr(206);

#line  1871 "Frames/cs.ATG" 
		for (int i = 0; i < expressions.Count; ++i) {
		Expression nextExpression = i + 1 < expressions.Count ? (Expression)expressions[i + 1] : expr;
		if (expressions[i] is CastExpression) {
			((CastExpression)expressions[i]).Expression = nextExpression;
		} else {
			((UnaryOperatorExpression)expressions[i]).Expression = nextExpression;
		}
		}
		if (expressions.Count > 0) {
			uExpr = (Expression)expressions[0];
		} else {
			uExpr = expr;
		}
		
	}
Example #20
0
	void ExclusiveOrExpr(
#line  2211 "Frames/cs.ATG" 
ref Expression outExpr) {

#line  2212 "Frames/cs.ATG" 
		Expression expr; 
		AndExpr(
#line  2214 "Frames/cs.ATG" 
ref outExpr);
		while (la.kind == 30) {
			lexer.NextToken();
			UnaryExpr(
#line  2214 "Frames/cs.ATG" 
out expr);
			AndExpr(
#line  2214 "Frames/cs.ATG" 
ref expr);

#line  2214 "Frames/cs.ATG" 
			outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr);  
		}
	}
Example #21
0
	void AndExpr(
#line  2217 "Frames/cs.ATG" 
ref Expression outExpr) {

#line  2218 "Frames/cs.ATG" 
		Expression expr; 
		EqualityExpr(
#line  2220 "Frames/cs.ATG" 
ref outExpr);
		while (la.kind == 28) {
			lexer.NextToken();
			UnaryExpr(
#line  2220 "Frames/cs.ATG" 
out expr);
			EqualityExpr(
#line  2220 "Frames/cs.ATG" 
ref expr);

#line  2220 "Frames/cs.ATG" 
			outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr);  
		}
	}
Example #22
0
	void NewExpression(
#line  2040 "Frames/cs.ATG" 
out Expression pexpr) {

#line  2041 "Frames/cs.ATG" 
		pexpr = null;
		List<Expression> parameters = new List<Expression>();
		TypeReference type = null;
		Expression expr;
		
		Expect(89);
		if (StartOf(10)) {
			NonArrayType(
#line  2048 "Frames/cs.ATG" 
out type);
		}
		if (la.kind == 16 || la.kind == 20) {
			if (la.kind == 20) {

#line  2054 "Frames/cs.ATG" 
				ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); 
				lexer.NextToken();

#line  2055 "Frames/cs.ATG" 
				if (type == null) Error("Cannot use an anonymous type with arguments for the constructor"); 
				if (StartOf(26)) {
					Argument(
#line  2056 "Frames/cs.ATG" 
out expr);

#line  2056 "Frames/cs.ATG" 
					SafeAdd(oce, parameters, expr); 
					while (la.kind == 14) {
						lexer.NextToken();
						Argument(
#line  2057 "Frames/cs.ATG" 
out expr);

#line  2057 "Frames/cs.ATG" 
						SafeAdd(oce, parameters, expr); 
					}
				}
				Expect(21);

#line  2059 "Frames/cs.ATG" 
				pexpr = oce; 
				if (la.kind == 16) {
					CollectionOrObjectInitializer(
#line  2060 "Frames/cs.ATG" 
out expr);

#line  2060 "Frames/cs.ATG" 
					oce.ObjectInitializer = (CollectionInitializerExpression)expr; 
				}
			} else {

#line  2061 "Frames/cs.ATG" 
				ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); 
				CollectionOrObjectInitializer(
#line  2062 "Frames/cs.ATG" 
out expr);

#line  2062 "Frames/cs.ATG" 
				oce.ObjectInitializer = (CollectionInitializerExpression)expr; 

#line  2063 "Frames/cs.ATG" 
				pexpr = oce; 
			}
		} else if (la.kind == 18) {
			lexer.NextToken();

#line  2068 "Frames/cs.ATG" 
			ArrayCreateExpression ace = new ArrayCreateExpression(type);
			/* we must not change RankSpecifier on the null type reference*/
			if (ace.CreateType.IsNull) { ace.CreateType = new TypeReference(""); }
			pexpr = ace;
			int dims = 0; List<int> ranks = new List<int>();
			
			if (la.kind == 14 || la.kind == 19) {
				while (la.kind == 14) {
					lexer.NextToken();

#line  2075 "Frames/cs.ATG" 
					dims += 1; 
				}
				Expect(19);

#line  2076 "Frames/cs.ATG" 
				ranks.Add(dims); dims = 0; 
				while (la.kind == 18) {
					lexer.NextToken();
					while (la.kind == 14) {
						lexer.NextToken();

#line  2077 "Frames/cs.ATG" 
						++dims; 
					}
					Expect(19);

#line  2077 "Frames/cs.ATG" 
					ranks.Add(dims); dims = 0; 
				}

#line  2078 "Frames/cs.ATG" 
				ace.CreateType.RankSpecifier = ranks.ToArray(); 
				CollectionInitializer(
#line  2079 "Frames/cs.ATG" 
out expr);

#line  2079 "Frames/cs.ATG" 
				ace.ArrayInitializer = (CollectionInitializerExpression)expr; 
			} else if (StartOf(6)) {
				Expr(
#line  2080 "Frames/cs.ATG" 
out expr);

#line  2080 "Frames/cs.ATG" 
				if (expr != null) parameters.Add(expr); 
				while (la.kind == 14) {
					lexer.NextToken();

#line  2081 "Frames/cs.ATG" 
					dims += 1; 
					Expr(
#line  2082 "Frames/cs.ATG" 
out expr);

#line  2082 "Frames/cs.ATG" 
					if (expr != null) parameters.Add(expr); 
				}
				Expect(19);

#line  2084 "Frames/cs.ATG" 
				ranks.Add(dims); ace.Arguments = parameters; dims = 0; 
				while (la.kind == 18) {
					lexer.NextToken();
					while (la.kind == 14) {
						lexer.NextToken();

#line  2085 "Frames/cs.ATG" 
						++dims; 
					}
					Expect(19);

#line  2085 "Frames/cs.ATG" 
					ranks.Add(dims); dims = 0; 
				}

#line  2086 "Frames/cs.ATG" 
				ace.CreateType.RankSpecifier = ranks.ToArray(); 
				if (la.kind == 16) {
					CollectionInitializer(
#line  2087 "Frames/cs.ATG" 
out expr);

#line  2087 "Frames/cs.ATG" 
					ace.ArrayInitializer = (CollectionInitializerExpression)expr; 
				}
			} else SynErr(211);
		} else SynErr(212);
	}
Example #23
0
	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);
			}
		}
	}
Example #24
0
	void Expr(
#line  1804 "Frames/cs.ATG" 
out Expression expr) {

#line  1805 "Frames/cs.ATG" 
		expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; 

#line  1807 "Frames/cs.ATG" 
		Location startLocation = la.Location; 
		UnaryExpr(
#line  1808 "Frames/cs.ATG" 
out expr);
		if (StartOf(7)) {
			AssignmentOperator(
#line  1811 "Frames/cs.ATG" 
out op);
			Expr(
#line  1811 "Frames/cs.ATG" 
out expr1);

#line  1811 "Frames/cs.ATG" 
			expr = new AssignmentExpression(expr, op, expr1); 
		} else if (
#line  1812 "Frames/cs.ATG" 
la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) {
			AssignmentOperator(
#line  1813 "Frames/cs.ATG" 
out op);
			Expr(
#line  1813 "Frames/cs.ATG" 
out expr1);

#line  1813 "Frames/cs.ATG" 
			expr = new AssignmentExpression(expr, op, expr1); 
		} else if (StartOf(8)) {
			ConditionalOrExpr(
#line  1815 "Frames/cs.ATG" 
ref expr);
			if (la.kind == 13) {
				lexer.NextToken();
				Expr(
#line  1816 "Frames/cs.ATG" 
out expr1);

#line  1816 "Frames/cs.ATG" 
				expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); 
			}
			if (la.kind == 12) {
				lexer.NextToken();
				Expr(
#line  1817 "Frames/cs.ATG" 
out expr1);
				Expect(9);
				Expr(
#line  1817 "Frames/cs.ATG" 
out expr2);

#line  1817 "Frames/cs.ATG" 
				expr = new ConditionalExpression(expr, expr1, expr2);  
			}
		} else SynErr(150);

#line  1820 "Frames/cs.ATG" 
		if (expr != null) {
		expr.StartLocation = startLocation;
		expr.EndLocation = t.EndLocation;
		}
		
	}
Example #25
0
	void AdditiveExpr(
#line  2288 "Frames/cs.ATG" 
ref Expression outExpr) {

#line  2290 "Frames/cs.ATG" 
		Expression expr;
		BinaryOperatorType op = BinaryOperatorType.None;
		
		MultiplicativeExpr(
#line  2294 "Frames/cs.ATG" 
ref outExpr);
		while (la.kind == 4 || la.kind == 5) {
			if (la.kind == 4) {
				lexer.NextToken();

#line  2297 "Frames/cs.ATG" 
				op = BinaryOperatorType.Add; 
			} else {
				lexer.NextToken();

#line  2298 "Frames/cs.ATG" 
				op = BinaryOperatorType.Subtract; 
			}
			UnaryExpr(
#line  2300 "Frames/cs.ATG" 
out expr);
			MultiplicativeExpr(
#line  2300 "Frames/cs.ATG" 
ref expr);

#line  2300 "Frames/cs.ATG" 
			outExpr = new BinaryOperatorExpression(outExpr, op, expr);  
		}
	}
Example #26
0
	void PointerMemberAccess(
#line  2028 "Frames/cs.ATG" 
out Expression expr, Expression target) {

#line  2029 "Frames/cs.ATG" 
		List<TypeReference> typeList; 
		Expect(47);
		Identifier();

#line  2033 "Frames/cs.ATG" 
		expr = new PointerReferenceExpression(target, t.val); expr.StartLocation = t.Location; expr.EndLocation = t.EndLocation; 
		if (
#line  2034 "Frames/cs.ATG" 
IsGenericInSimpleNameOrMemberAccess()) {
			TypeArgumentList(
#line  2035 "Frames/cs.ATG" 
out typeList, false);

#line  2036 "Frames/cs.ATG" 
			((MemberReferenceExpression)expr).TypeArguments = typeList; 
		}
	}
			public ReplaceWithAccessTransformer(Expression replaceWith)
			{
				this.replaceWith = replaceWith;
			}
Example #28
0
	void MemberAccess(
#line  2009 "Frames/cs.ATG" 
out Expression expr, Expression target) {

#line  2010 "Frames/cs.ATG" 
		List<TypeReference> typeList; 

#line  2012 "Frames/cs.ATG" 
		if (ShouldConvertTargetExpressionToTypeReference(target)) {
		TypeReference type = GetTypeReferenceFromExpression(target);
		if (type != null) {
			target = new TypeReferenceExpression(type) { StartLocation = t.Location, EndLocation = t.EndLocation };
		}
		}
		
		Expect(15);
		Identifier();

#line  2021 "Frames/cs.ATG" 
		expr = new MemberReferenceExpression(target, t.val); expr.StartLocation = t.Location; expr.EndLocation = t.EndLocation; 
		if (
#line  2022 "Frames/cs.ATG" 
IsGenericInSimpleNameOrMemberAccess()) {
			TypeArgumentList(
#line  2023 "Frames/cs.ATG" 
out typeList, false);

#line  2024 "Frames/cs.ATG" 
			((MemberReferenceExpression)expr).TypeArguments = typeList; 
		}
	}
Example #29
0
	void AnonymousMethodExpr(
#line  2160 "Frames/cs.ATG" 
out Expression outExpr) {

#line  2162 "Frames/cs.ATG" 
		AnonymousMethodExpression expr = new AnonymousMethodExpression();
		expr.StartLocation = t.Location;
		BlockStatement stmt;
		List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
		outExpr = expr;
		
		if (la.kind == 20) {
			lexer.NextToken();
			if (StartOf(11)) {
				FormalParameterList(
#line  2171 "Frames/cs.ATG" 
p);

#line  2171 "Frames/cs.ATG" 
				expr.Parameters = p; 
			}
			Expect(21);

#line  2173 "Frames/cs.ATG" 
			expr.HasParameterList = true; 
		}
		BlockInsideExpression(
#line  2175 "Frames/cs.ATG" 
out stmt);

#line  2175 "Frames/cs.ATG" 
		expr.Body  = stmt; 

#line  2176 "Frames/cs.ATG" 
		expr.EndLocation = t.Location; 
	}
Example #30
0
	void CollectionOrObjectInitializer(
#line  1443 "Frames/cs.ATG" 
out Expression outExpr) {

#line  1445 "Frames/cs.ATG" 
		Expression expr = null;
		CollectionInitializerExpression initializer = new CollectionInitializerExpression();
		
		Expect(16);

#line  1449 "Frames/cs.ATG" 
		initializer.StartLocation = t.Location; 
		if (StartOf(31)) {
			ObjectPropertyInitializerOrVariableInitializer(
#line  1450 "Frames/cs.ATG" 
out expr);

#line  1451 "Frames/cs.ATG" 
			SafeAdd(initializer, initializer.CreateExpressions, expr); 
			while (
#line  1452 "Frames/cs.ATG" 
NotFinalComma()) {
				Expect(14);
				ObjectPropertyInitializerOrVariableInitializer(
#line  1453 "Frames/cs.ATG" 
out expr);

#line  1454 "Frames/cs.ATG" 
				SafeAdd(initializer, initializer.CreateExpressions, expr); 
			}
			if (la.kind == 14) {
				lexer.NextToken();
			}
		}
		Expect(17);

#line  1458 "Frames/cs.ATG" 
		initializer.EndLocation = t.Location; outExpr = initializer; 
	}