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);

                typeRef.GenericTypes.Add(result.ResolvedType.ConvertToTypeReference());

                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);
        }
        public override object VisitQueryExpression(QueryExpression queryExpression, object data)
        {
            QueryExpressionSelectClause selectClause = queryExpression.SelectOrGroupClause as QueryExpressionSelectClause;
            QueryExpressionGroupClause  groupClause  = queryExpression.SelectOrGroupClause as QueryExpressionGroupClause;

            if (selectClause != null)
            {
                // Fake a call to 'Select'
                var fakeInvocation = new InvocationExpression(new MemberReferenceExpression(
                                                                  queryExpression.FromClause.InExpression, "Select"));

                var selector = new LambdaExpression();
                selector.Parameters.Add(new ParameterDeclarationExpression(null, "__rangeVariable"));
                selector.ExpressionBody = selectClause.Projection;
                selector.Parent         = fakeInvocation;

                fakeInvocation.Arguments.Add(selector);

                return(CreateResolveResult(ResolveType(fakeInvocation)));
            }
            else if (groupClause != null)
            {
                // Fake a call to 'GroupBy'
                var fakeInvocation = new InvocationExpression(new MemberReferenceExpression(
                                                                  queryExpression.FromClause.InExpression, "GroupBy"));

                var keySelector = new LambdaExpression();
                keySelector.Parameters.Add(new ParameterDeclarationExpression(null, "__rangeVariable"));
                keySelector.ExpressionBody = groupClause.GroupBy;
                keySelector.Parent         = fakeInvocation;

                var elementSelector = new LambdaExpression();
                elementSelector.Parameters.Add(new ParameterDeclarationExpression(null, "__rangeVariable"));
                elementSelector.ExpressionBody = groupClause.Projection;
                elementSelector.Parent         = fakeInvocation;

                fakeInvocation.Arguments.Add(keySelector);
                fakeInvocation.Arguments.Add(elementSelector);

                return(CreateResolveResult(ResolveType(fakeInvocation)));
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
			public override object Visit (Mono.CSharp.Linq.GroupBy groupBy)
			{
				var result = new QueryExpressionGroupClause ();
				var location = LocationsBag.GetLocations (groupBy);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[0]), "group".Length), QueryExpressionGroupClause.GroupKeywordRole);
				result.AddChild ((INode)groupBy.ElementSelector.Accept (this), QueryExpressionGroupClause.GroupByExpressionRole);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[1]), "by".Length), QueryExpressionGroupClause.ByKeywordRole);
				result.AddChild ((INode)groupBy.Expr.Accept (this), QueryExpressionGroupClause.ProjectionExpressionRole);
				return result;
			}
Exemple #4
0
 public object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data)
 {
     AddError(queryExpressionGroupClause, "QueryExpressionGroupClause is not supported.");
     return(null);
 }
 public virtual object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data)
 {
     throw new global::System.NotImplementedException("QueryExpressionGroupClause");
 }
        public ResolveResult ResolveIdentifier(ResolveVisitor visitor, string identifier)
        {
            ResolveResult result = null;

            if (resultTable.TryGetValue(identifier, out result))
            {
                return(result);
            }
            resultTable[identifier] = result;
//			Console.WriteLine (lookupVariableLine);
            foreach (KeyValuePair <string, List <LocalLookupVariable> > pair in this.lookupTableVisitor.Variables)
            {
                if (identifier == pair.Key)
                {
                    LocalLookupVariable var = null;
//					Console.WriteLine ("--- RP:" + this.resolvePosition + "/" + pair.Value.Count);
                    foreach (LocalLookupVariable v2 in pair.Value)
                    {
                        DomLocation varStartPos = new DomLocation(lookupVariableLine + v2.StartPos.Line, v2.StartPos.Column - 1);
                        DomLocation varEndPos   = new DomLocation(lookupVariableLine + v2.EndPos.Line, v2.EndPos.Column - 1);
//						Console.WriteLine (v2.Name + ":" + varStartPos + " <> " + varEndPos + " resolve position:" + this.resolvePosition);
                        if (varStartPos > this.resolvePosition || (!v2.EndPos.IsEmpty && varEndPos < this.resolvePosition))
                        {
                            continue;
                        }
                        var = v2;
                    }
//					Console.WriteLine ("var:" + var);
                    if (var == null)
                    {
                        continue;
                    }
                    IReturnType varType           = null;
                    IReturnType varTypeUnresolved = null;
                    if (var.IsQueryContinuation)
                    {
                        QueryExpression query = var.Initializer as QueryExpression;

                        QueryExpressionGroupClause grouBy = query.SelectOrGroupClause as QueryExpressionGroupClause;
                        DomLocation old = resolvePosition;
                        try {
                            resolvePosition = new DomLocation(lookupVariableLine + grouBy.Projection.StartLocation.Line,
                                                              grouBy.Projection.StartLocation.Column);
                            ResolveResult initializerResolve = visitor.Resolve(grouBy.Projection);
                            ResolveResult groupByResolve     = visitor.Resolve(grouBy.GroupBy);
                            DomReturnType resolved           = new DomReturnType(dom.GetType("System.Linq.IGrouping", new IReturnType [] {
                                DomType.GetComponentType(dom, initializerResolve.ResolvedType), groupByResolve.ResolvedType
                            }));
                            varTypeUnresolved = varType = resolved;
                        } finally {
                            resolvePosition = old;
                        }
                    }
                    else if ((var.TypeRef == null || var.TypeRef.Type == "var" || var.TypeRef.IsNull))
                    {
                        if (var.ParentLambdaExpression != null)
                        {
                            ResolveResult lambdaResolve = ResolveLambda(visitor, var.ParentLambdaExpression);
                            if (lambdaResolve != null)
                            {
                                varType           = lambdaResolve.ResolvedType;
                                varTypeUnresolved = lambdaResolve.UnresolvedType;

                                IType type = Dom.GetType(varType);
                                if (type != null && type.ClassType == MonoDevelop.Projects.Dom.ClassType.Delegate)
                                {
                                    IMethod invocationMethod = type.Methods.First();
                                    if (invocationMethod.Parameters.Count > 0)
                                    {
                                        varType = varTypeUnresolved = invocationMethod.Parameters[0].ReturnType;
                                    }
                                }
                            }
                            else
                            {
                                varType = varTypeUnresolved = DomReturnType.Void;
                            }
                        }
                        if (var.Initializer != null)
                        {
                            ResolveResult initializerResolve = visitor.Resolve(var.Initializer);
//							Console.WriteLine ("initializer : "+ var.Initializer + " result:" + initializerResolve);
                            varType           = var.IsLoopVariable ? DomType.GetComponentType(dom, initializerResolve.ResolvedType) : initializerResolve.ResolvedType;
                            varTypeUnresolved = var.IsLoopVariable ? DomType.GetComponentType(dom, initializerResolve.UnresolvedType) : initializerResolve.UnresolvedType;
//							Console.WriteLine ("resolved type:" + initializerResolve.ResolvedType + " is loop : " + var.IsLoopVariable);
//							Console.WriteLine (varType);
//							Console.WriteLine ("----------");
                        }
                    }
                    else
                    {
                        varTypeUnresolved = varType = ConvertTypeReference(var.TypeRef);
                    }
                    varType = ResolveType(varType);
                    result  = new LocalVariableResolveResult(
                        new LocalVariable(CallingMember, identifier, varType,
                                          new DomRegion(lookupVariableLine + var.StartPos.Line, var.StartPos.Column,
                                                        lookupVariableLine + var.StartPos.Line, var.EndPos.Column)),
                        var.IsLoopVariable);

                    result.ResolvedType   = varType;
                    result.UnresolvedType = varTypeUnresolved;
                    goto end;
                }
            }
            if (this.callingMember != null)
            {
                // special handling of property or field return types, they can have the same name as the return type
                // ex.: MyType MyType { get; set; }  Type1 Type1;
                if ((callingMember is IProperty || callingMember is IField) && identifier == callingMember.Name)
                {
                    int pos = editor.GetPositionFromLineColumn(resolvePosition.Line, resolvePosition.Column);
                    while (pos < editor.TextLength && !Char.IsWhiteSpace(editor.GetCharAt(pos)))
                    {
                        pos++;
                    }
                    while (pos < editor.TextLength && Char.IsWhiteSpace(editor.GetCharAt(pos)))
                    {
                        pos++;
                    }
                    StringBuilder memberName = new StringBuilder();
                    while (pos < editor.TextLength && (Char.IsLetterOrDigit(editor.GetCharAt(pos)) || editor.GetCharAt(pos) == '_'))
                    {
                        memberName.Append(editor.GetCharAt(pos));
                        pos++;
                    }
                    //Console.WriteLine ("id: '" + identifier + "' : '" + memberName.ToString () +"'" + (memberName.ToString () == identifier));
                    if (memberName.ToString() == identifier)
                    {
                        result = visitor.CreateResult(callingMember.ReturnType);
                        goto end;
                    }
                }

                if (identifier == "value" && this.callingMember is IProperty)
                {
                    result = new MemberResolveResult(this.callingMember);
                    result.UnresolvedType = ((IProperty)this.callingMember).ReturnType;
                    result.ResolvedType   = ResolveType(((IProperty)this.callingMember).ReturnType);
                    goto end;
                }
                if (this.callingMember is IMethod || this.callingMember is IProperty)
                {
                    ReadOnlyCollection <IParameter> prms = this.callingMember is IMethod
                                                ? ((IMethod)this.callingMember).Parameters
                                                : ((IProperty)this.callingMember).Parameters;
                    if (prms != null)
                    {
                        foreach (IParameter para in prms)
                        {
                            if (para.Name == identifier)
                            {
                                result = new ParameterResolveResult(para);
                                result.UnresolvedType = para.ReturnType;
                                result.ResolvedType   = ResolveType(para.ReturnType);
                                goto end;
                            }
                        }
                    }
                }
            }
            IType searchedType = SearchType(identifier);

            if (this.callingType != null && dom != null)
            {
                List <IMember> members = new List <IMember> ();
                foreach (IType type in dom.GetInheritanceTree(callingType))
                {
                    members.AddRange(type.SearchMember(identifier, true));
                }
                bool includeProtected = true;
                // filter members
                if (this.CallingMember != null)
                {
                    for (int i = 0; i < members.Count; i++)
                    {
                        if (this.CallingMember.IsStatic && !members[i].IsStatic ||
                            !members[i].IsAccessibleFrom(dom, callingType, this.CallingMember, includeProtected))
                        {
                            members.RemoveAt(i);
                            i--;
                            continue;
                        }
                    }
                }

                if (members.Count > 0)
                {
                    if (members[0] is IMethod)
                    {
                        result = new MethodResolveResult(members);
                        if (CallingMember != null)
                        {
                            result.StaticResolve = CallingMember.IsStatic;
                        }
                    }
                    else if (members[0] is IType)
                    {
                        result = new MemberResolveResult(null, true);
                        result.UnresolvedType = result.ResolvedType = new DomReturnType((IType)members[0]);
                        goto end;
                    }
                    else
                    {
                        result = new MemberResolveResult(members[0]);
                    }
                    result.UnresolvedType = members[0].ReturnType;
                    result.ResolvedType   = ResolveType(members[0].ReturnType);

                    if (members[0] is IProperty && searchedType != null && result.ResolvedType.FullName == searchedType.FullName)
                    {
                        result = new AggregatedResolveResult(result, new MemberResolveResult(null, true)
                        {
                            UnresolvedType = new DomReturnType(searchedType),
                            ResolvedType   = new DomReturnType(searchedType)
                        });
                    }
                    goto end;
                }
            }

            if (searchedType != null)
            {
                result = new MemberResolveResult(null, true);
                result.UnresolvedType = result.ResolvedType = new DomReturnType(searchedType);
                goto end;
            }

            if (dom.NamespaceExists(identifier, true))
            {
                result = new NamespaceResolveResult(identifier);
                goto end;
            }

            if (unit != null && unit.Usings != null)
            {
                foreach (IUsing u in unit.Usings)
                {
                    if (u.IsFromNamespace && u.Region.Contains(resolvePosition))
                    {
                        foreach (string ns in u.Namespaces)
                        {
                            if (dom.NamespaceExists(ns + "." + identifier, true))
                            {
                                result = new NamespaceResolveResult(ns + "." + identifier);
                                goto end;
                            }
                        }
                    }
                    foreach (KeyValuePair <string, IReturnType> alias in u.Aliases)
                    {
                        if (alias.Key == identifier || alias.Key + ".?" == identifier)
                        {
                            result = new NamespaceResolveResult(alias.Value.FullName);
                            goto end;
                        }
                    }
                }
            }
end:
            if (result != null)
            {
                result.CallingType   = CallingType;
                result.CallingMember = CallingMember;
            }
            resultTable[identifier] = result;
            return(result);
        }
Exemple #7
0
	void QueryExpressionGroupClause(
#line  2515 "cs.ATG" 
out QueryExpressionGroupClause gc) {

#line  2516 "cs.ATG" 
		Expression expr; gc = new QueryExpressionGroupClause(); gc.StartLocation = la.Location; 
		Expect(134);
		Expr(
#line  2519 "cs.ATG" 
out expr);

#line  2519 "cs.ATG" 
		gc.Projection = expr; 
		Expect(135);
		Expr(
#line  2521 "cs.ATG" 
out expr);

#line  2521 "cs.ATG" 
		gc.GroupBy = expr; 

#line  2522 "cs.ATG" 
		gc.EndLocation = t.EndLocation; 
	}
Exemple #8
0
 public override object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data)
 {
     return(base.VisitQueryExpressionGroupClause(queryExpressionGroupClause, data));
 }
 public object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data)
 {
     throw new NotImplementedException();
 }
		public virtual object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) {
			Debug.Assert((queryExpressionGroupClause != null));
			Debug.Assert((queryExpressionGroupClause.Projection != null));
			Debug.Assert((queryExpressionGroupClause.GroupBy != null));
			queryExpressionGroupClause.Projection.AcceptVisitor(this, data);
			return queryExpressionGroupClause.GroupBy.AcceptVisitor(this, data);
		}
 private bool IsMatch(QueryExpressionGroupClause left, QueryExpressionGroupClause data)
 {
     return(true);
 }
		public virtual object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) {
			throw new global::System.NotImplementedException("QueryExpressionGroupClause");
		}
		public virtual object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) {
			Debug.Assert((queryExpressionGroupClause != null));
			Debug.Assert((queryExpressionGroupClause.Projection != null));
			Debug.Assert((queryExpressionGroupClause.GroupBy != null));
			nodeStack.Push(queryExpressionGroupClause.Projection);
			queryExpressionGroupClause.Projection.AcceptVisitor(this, data);
			queryExpressionGroupClause.Projection = ((Expression)(nodeStack.Pop()));
			nodeStack.Push(queryExpressionGroupClause.GroupBy);
			queryExpressionGroupClause.GroupBy.AcceptVisitor(this, data);
			queryExpressionGroupClause.GroupBy = ((Expression)(nodeStack.Pop()));
			return null;
		}
		public sealed override object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) {
			BeginVisit(queryExpressionGroupClause);
			object result = TrackedVisitQueryExpressionGroupClause(queryExpressionGroupClause, data);
			EndVisit(queryExpressionGroupClause);
			return result;
		}
		public virtual object TrackedVisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) {
			return base.VisitQueryExpressionGroupClause(queryExpressionGroupClause, data);
		}