Merge pull request #587 from madewokherd/gdipdllmap
[mono.git] / mcs / mcs / linq.cs
index 205242d9faf971b0ff6800abed36644380f634aa..a1c5ab2f914f4bed7b7938ca2f1f93a4463c3d35 100644 (file)
@@ -6,6 +6,7 @@
 // Dual licensed under the terms of the MIT X11 or GNU GPL
 //
 // Copyright 2007-2008 Novell, Inc
+// Copyright 2011 Xamarin Inc
 //
 
 using System;
@@ -16,7 +17,7 @@ namespace Mono.CSharp.Linq
        public class QueryExpression : AQueryClause
        {
                public QueryExpression (AQueryClause start)
-                       : base (null, null, Location.Null)
+                       : base (null, null, start.Location)
                {
                        this.next = start;
                }
@@ -84,6 +85,13 @@ namespace Mono.CSharp.Linq
                                return rmg;
                        }
 
+                       protected override Expression DoResolveDynamic (ResolveContext ec, Expression memberExpr)
+                       {
+                               ec.Report.Error (1979, loc,
+                                       "Query expressions with a source or join sequence of type `dynamic' are not allowed");
+                               return null;
+                       }
+
                        #region IErrorHandler Members
 
                        bool OverloadResolver.IErrorHandler.AmbiguousCandidates (ResolveContext ec, MemberSpec best, MemberSpec ambiguous)
@@ -122,7 +130,7 @@ namespace Mono.CSharp.Linq
 
                                        if (!Convert.ImplicitConversionExists (rc, a.Expr, source_type)) {
                                                rc.Report.Error (1936, loc, "An implementation of `{0}' query expression pattern for source type `{1}' could not be found",
-                                                       best.Name, TypeManager.CSharpName (a.Type));
+                                                       best.Name, a.Type.GetSignatureForError ());
                                                return true;
                                        }
                                }
@@ -275,6 +283,12 @@ namespace Mono.CSharp.Linq
                        this.identifier = identifier;
                }
 
+               public RangeVariable Identifier {
+                       get {
+                               return identifier;
+                       }
+               }
+
                public FullNamedExpression IdentifierType { get; set; }
 
                protected Invocation CreateCastExpression (Expression lSide)
@@ -341,6 +355,12 @@ namespace Mono.CSharp.Linq
                        }
                }
 
+               public bool IsParameter {
+                       get {
+                               return false;
+                       }
+               }
+
                public Location Location { get; private set; }
 
                public string Name { get; private set; }
@@ -388,7 +408,7 @@ namespace Mono.CSharp.Linq
                }
        }
 
-       class QueryStartClause : ARangeVariableQueryClause
+       public class QueryStartClause : ARangeVariableQueryClause
        {
                public QueryStartClause (QueryBlock block, Expression expr, RangeVariable identifier, Location loc)
                        : base (block, identifier, expr, loc)
@@ -398,19 +418,6 @@ namespace Mono.CSharp.Linq
 
                public override Expression BuildQueryClause (ResolveContext ec, Expression lSide, Parameter parameter)
                {
-/*
-                       expr = expr.Resolve (ec);
-                       if (expr == null)
-                               return null;
-
-                       if (expr.Type == InternalType.Dynamic || expr.Type == TypeManager.void_type) {
-                               ec.Report.Error (1979, expr.Location,
-                                       "Query expression with a source or join sequence of type `{0}' is not allowed",
-                                       TypeManager.CSharpName (expr.Type));
-                               return null;
-                       }
-*/
-
                        if (IdentifierType != null)
                                expr = CreateCastExpression (expr);
 
@@ -448,6 +455,12 @@ namespace Mono.CSharp.Linq
                        }
                }
 
+               public Expression SelectorExpression {
+                       get {
+                               return element_selector;
+                       }
+               }
+
                protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args)
                {
                        base.CreateArguments (ec, parameter, ref args);
@@ -476,6 +489,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "GroupBy"; }
                }
+               
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        public class Join : SelectMany
@@ -489,6 +507,18 @@ namespace Mono.CSharp.Linq
                        this.inner_selector = innerSelector;
                }
 
+               public QueryBlock InnerSelector {
+                       get {
+                               return inner_selector;
+                       }
+               }
+               
+               public QueryBlock OuterSelector {
+                       get {
+                               return outer_selector;
+                       }
+               }
+
                protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args)
                {
                        args = new Arguments (4);
@@ -522,6 +552,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "Join"; }
                }
+               
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        public class GroupJoin : Join
@@ -543,6 +578,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "GroupJoin"; }
                }
+               
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        public class Let : ARangeVariableQueryClause
@@ -561,6 +601,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "Select"; }
                }
+               
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        public class Select : AQueryClause
@@ -586,6 +631,12 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "Select"; }
                }
+               
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
+
        }
 
        public class SelectMany : ARangeVariableQueryClause
@@ -637,6 +688,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "SelectMany"; }
                }
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        public class Where : AQueryClause
@@ -649,6 +705,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "Where"; }
                }
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        public class OrderByAscending : AQueryClause
@@ -661,6 +722,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "OrderBy"; }
                }
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        public class OrderByDescending : AQueryClause
@@ -673,6 +739,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "OrderByDescending"; }
                }
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        public class ThenByAscending : OrderByAscending
@@ -685,6 +756,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "ThenBy"; }
                }
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        public class ThenByDescending : OrderByDescending
@@ -697,6 +773,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "ThenByDescending"; }
                }
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        //
@@ -738,7 +819,7 @@ namespace Mono.CSharp.Linq
                public void AddRangeVariable (RangeVariable variable)
                {
                        variable.Block = this;
-                       AddLocalName (variable.Name, variable);
+                       TopBlock.AddLocalName (variable.Name, variable, true);
                }
 
                public override void Error_AlreadyDeclared (string name, INamedBlockVariable variable, string reason)