Merge pull request #1439 from BrzVlad/feature-managed-allocator
[mono.git] / mcs / mcs / linq.cs
index 5bd3f116df666b62673ea0be3541cd55b95c510a..7f19c2d89b35524f73e49b9b00c4029326fb4276 100644 (file)
@@ -64,7 +64,7 @@ namespace Mono.CSharp.Linq
                        {
                        }
 
-                       protected override void Error_TypeDoesNotContainDefinition (ResolveContext ec, TypeSpec type, string name)
+                       public override void Error_TypeDoesNotContainDefinition (ResolveContext ec, TypeSpec type, string name)
                        {
                                ec.Report.Error (1935, loc, "An implementation of `{0}' query expression pattern could not be found. " +
                                        "Are you missing `System.Linq' using directive or `System.Core.dll' assembly reference?",
@@ -85,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)
@@ -123,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;
                                        }
                                }
@@ -276,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)
@@ -395,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)
@@ -405,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);
 
@@ -455,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);
@@ -483,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
@@ -496,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);
@@ -529,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
@@ -550,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
@@ -568,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
@@ -593,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
@@ -644,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
@@ -656,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
@@ -668,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
@@ -680,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
@@ -692,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
@@ -704,6 +773,11 @@ namespace Mono.CSharp.Linq
                protected override string MethodName {
                        get { return "ThenByDescending"; }
                }
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        //
@@ -737,15 +811,14 @@ namespace Mono.CSharp.Linq
                }
 
                public QueryBlock (Block parent, Location start)
-                       : base (parent, ParametersCompiled.EmptyReadOnlyParameters, start)
+                       : base (parent, ParametersCompiled.EmptyReadOnlyParameters, start, Flags.CompilerGenerated)
                {
-                       flags |= Flags.CompilerGenerated;
                }
 
                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)