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;
		}
		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));
		}
		public virtual object VisitLambdaExpression (LambdaExpression lambdaExpression, object data)
		{
			Debug.Assert ((lambdaExpression != null));
			Debug.Assert ((lambdaExpression.Parameters != null));
			Debug.Assert ((lambdaExpression.StatementBody != null));
			Debug.Assert ((lambdaExpression.ExpressionBody != null));
			foreach (ParameterDeclarationExpression o in lambdaExpression.Parameters) {
				Debug.Assert (o != null);
				o.AcceptVisitor (this, data);
			}
			lambdaExpression.ExpressionBody.AcceptVisitor (this, data);
			lambdaExpression.StatementBody.AcceptVisitor(this, data);
			return lambdaExpression.ExpressionBody.AcceptVisitor(this, data);
		}
		public override object VisitLambdaExpression(LambdaExpression lambdaExpression, object data)
		{
			foreach (ParameterDeclarationExpression p in lambdaExpression.Parameters) {
				AddVariable(p.TypeReference, p.ParameterName,
				            lambdaExpression.StartLocation, lambdaExpression.ExtendedEndLocation,
				            false, false, null, lambdaExpression, false, lambdaExpression.StartLocation);
			}
			return base.VisitLambdaExpression(lambdaExpression, data);
		}
Example #5
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 #6
0
	void LambdaExpressionBody(
#line  2149 "Frames/cs.ATG" 
LambdaExpression lambda) {

#line  2150 "Frames/cs.ATG" 
		Expression expr; BlockStatement stmt; 
		if (la.kind == 16) {
			BlockInsideExpression(
#line  2153 "Frames/cs.ATG" 
out stmt);

#line  2153 "Frames/cs.ATG" 
			lambda.StatementBody = stmt; 
		} else if (StartOf(6)) {
			Expr(
#line  2154 "Frames/cs.ATG" 
out expr);

#line  2154 "Frames/cs.ATG" 
			lambda.ExpressionBody = expr; 
		} else SynErr(214);

#line  2156 "Frames/cs.ATG" 
		lambda.EndLocation = t.EndLocation; 

#line  2157 "Frames/cs.ATG" 
		lambda.ExtendedEndLocation = la.Location; 
	}
		public sealed override object VisitLambdaExpression(LambdaExpression lambdaExpression, object data) {
			this.BeginVisit(lambdaExpression);
			object result = this.TrackedVisitLambdaExpression(lambdaExpression, data);
			this.EndVisit(lambdaExpression);
			return result;
		}
Example #8
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);
	}
		public override object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data)
		{
			base.VisitAnonymousMethodExpression(anonymousMethodExpression, data);
			if (anonymousMethodExpression.Body.Children.Count == 1) {
				ReturnStatement rs = anonymousMethodExpression.Body.Children[0] as ReturnStatement;
				if (rs != null) {
					LambdaExpression lambda = new LambdaExpression();
					lambda.ExpressionBody = rs.Expression;
					lambda.Parameters = anonymousMethodExpression.Parameters;
					ReplaceCurrentNode(lambda);
				}
			}
			return null;
		}
		public virtual object TrackedVisitLambdaExpression(LambdaExpression lambdaExpression, object data) {
			return base.VisitLambdaExpression(lambdaExpression, data);
		}
Example #11
0
	void LambdaExpr(
#line  1995 "VBNET.ATG" 
out Expression expr) {

#line  1997 "VBNET.ATG" 
		Expression inner = null;
		LambdaExpression lambda = new LambdaExpression();
		lambda.StartLocation = la.Location;
		
		Expect(114);
		if (la.kind == 25) {
			lexer.NextToken();
			if (StartOf(4)) {
				FormalParameterList(
#line  2003 "VBNET.ATG" 
lambda.Parameters);
			}
			Expect(26);
		}
		Expr(
#line  2004 "VBNET.ATG" 
out inner);

#line  2006 "VBNET.ATG" 
		lambda.ExpressionBody = inner;
		lambda.EndLocation = t.EndLocation; // la.Location?
		
		expr = lambda;
		
	}
Example #12
0
		public override object VisitQueryExpression(QueryExpression queryExpression, object data)
		{
			if (this.queryExpression != null) // prevent endloss loop: var n = from n select n; n.$ (doesn't make sense, but you can type this)
				return null;
			this.queryExpression = queryExpression;
			IReturnType type = null;
			QueryExpressionSelectClause selectClause = queryExpression.SelectOrGroupClause as QueryExpressionSelectClause;
			if (selectClause != null) {
				InvocationExpression selectInvocation = new InvocationExpression (new MemberReferenceExpression (queryExpression.FromClause.InExpression, "Select"));
				LambdaExpression selectLambdaExpr = new LambdaExpression ();
				selectLambdaExpr.Parent = selectInvocation;
				selectLambdaExpr.Parameters.Add (new ParameterDeclarationExpression (null, "par"));
				selectLambdaExpr.ExpressionBody = selectClause.Projection;
				TypeReference typeRef = new TypeReference ("System.Func");
				typeRef.GenericTypes.Add (TypeReference.Null);
				ResolveResult result = resolver.ResolveExpression (selectLambdaExpr, resolver.ResolvePosition, false);
				
				typeRef.GenericTypes.Add (NRefactoryResolver.ConvertToTypeReference (result.ResolvedType));
				
				ObjectCreateExpression createExpression = new ObjectCreateExpression (typeRef, new List<Expression> (new Expression [] {
					null,
					selectLambdaExpr
				}));
				
				selectInvocation.Arguments.Add (createExpression);
				return CreateResult (ResolveType (selectInvocation));
			}
			
			QueryExpressionGroupClause groupClause = queryExpression.SelectOrGroupClause as QueryExpressionGroupClause;
			if (groupClause != null) {
				InvocationExpression groupInvocation = new InvocationExpression (new MemberReferenceExpression (queryExpression.FromClause.InExpression, "GroupBy"));
				
				LambdaExpression keyLambdaExpr = new LambdaExpression ();
				keyLambdaExpr.Parent = groupInvocation;
				keyLambdaExpr.Parameters.Add (new ParameterDeclarationExpression (null, "par"));
				keyLambdaExpr.ExpressionBody = groupClause.GroupBy;
				groupInvocation.Arguments.Add (keyLambdaExpr);
				
				LambdaExpression elementLambdaExpr = new LambdaExpression ();
				elementLambdaExpr.Parent = groupInvocation;
				elementLambdaExpr.Parameters.Add (new ParameterDeclarationExpression (null, "par"));
				elementLambdaExpr.ExpressionBody = groupClause.Projection;
				groupInvocation.Arguments.Add (elementLambdaExpr);
				return CreateResult (ResolveType (groupInvocation));
			}
			
			if (type != null) 
				return CreateResult (new DomReturnType("System.Collections.Generic.IEnumerable", false, new List<IReturnType> (new IReturnType[] { type })));
			return null;
		}
Example #13
0
		public override object VisitLambdaExpression(LambdaExpression lambdaExpression, object data)
		{
			ResolveResult result;
			if (!lambdaDictionary.TryGetValue (lambdaExpression, out result)) {
				lambdaDictionary[lambdaExpression] = result;
				result = resolver.ResolveLambda (this, lambdaExpression);
			}
			return result;
		}
		public virtual object VisitLambdaExpression(LambdaExpression lambdaExpression, object data) {
			Debug.Assert((lambdaExpression != null));
			Debug.Assert((lambdaExpression.Parameters != null));
			Debug.Assert((lambdaExpression.StatementBody != null));
			Debug.Assert((lambdaExpression.ExpressionBody != null));
			for (int i = 0; i < lambdaExpression.Parameters.Count; i++) {
				ParameterDeclarationExpression o = lambdaExpression.Parameters[i];
				Debug.Assert(o != null);
				nodeStack.Push(o);
				o.AcceptVisitor(this, data);
				o = (ParameterDeclarationExpression)nodeStack.Pop();
				if (o == null)
					lambdaExpression.Parameters.RemoveAt(i--);
				else
					lambdaExpression.Parameters[i] = o;
			}
			nodeStack.Push(lambdaExpression.StatementBody);
			lambdaExpression.StatementBody.AcceptVisitor(this, data);
			lambdaExpression.StatementBody = ((BlockStatement)(nodeStack.Pop()));
			nodeStack.Push(lambdaExpression.ExpressionBody);
			lambdaExpression.ExpressionBody.AcceptVisitor(this, data);
			lambdaExpression.ExpressionBody = ((Expression)(nodeStack.Pop()));
			return null;
		}
		public virtual object VisitLambdaExpression(LambdaExpression lambdaExpression, object data) {
			throw new global::System.NotImplementedException("LambdaExpression");
		}