2009-11-26 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / linq.cs
index 54876f6de62ca655a5d95efd60d809631128f884..3697ef0fe0010bc8775517f7bf386dbf2f63ac03 100644 (file)
@@ -33,12 +33,13 @@ namespace Mono.CSharp.Linq
                        return next.BuildQueryClause (ec, lSide);
                }
 
-               public override Expression DoResolve (ResolveContext ec)
+               protected override Expression DoResolve (ResolveContext ec)
                {
                        int counter = QueryBlock.TransparentParameter.Counter;
 
                        Expression e = BuildQueryClause (ec, null);
-                       e = e.Resolve (ec);
+                       if (e != null)
+                               e = e.Resolve (ec);
 
                        //
                        // Reset counter in probing mode to ensure that all transparent
@@ -110,15 +111,11 @@ namespace Mono.CSharp.Linq
                                        Argument a = arguments [0];
 
                                        if (TypeManager.IsGenericType (source_type) && TypeManager.ContainsGenericParameters (source_type)) {
-#if GMCS_SOURCE
                                                TypeInferenceContext tic = new TypeInferenceContext (TypeManager.GetTypeArguments (source_type));
                                                tic.OutputTypeInference (ec, a.Expr, source_type);
                                                if (tic.FixAllTypes (ec)) {
                                                        source_type = TypeManager.DropGenericTypeArguments (source_type).MakeGenericType (tic.InferredTypeArguments);
                                                }
-#else
-                                               throw new NotSupportedException ();
-#endif
                                        }
 
                                        if (!Convert.ImplicitConversionExists (ec, a.Expr, source_type)) {
@@ -169,9 +166,9 @@ namespace Mono.CSharp.Linq
                                t.next = (AQueryClause) next.Clone (clonectx);
                }
 
-               public override Expression DoResolve (ResolveContext ec)
+               protected override Expression DoResolve (ResolveContext ec)
                {
-                       return expr.DoResolve (ec);
+                       return expr.Resolve (ec);
                }
 
                public virtual Expression BuildQueryClause (ResolveContext ec, Expression lSide)
@@ -237,7 +234,7 @@ namespace Mono.CSharp.Linq
        {
                sealed class RangeAnonymousTypeParameter : AnonymousTypeParameter
                {
-                       public RangeAnonymousTypeParameter (Expression initializer, LocatedToken parameter)
+                       public RangeAnonymousTypeParameter (Expression initializer, SimpleMemberName parameter)
                                : base (initializer, parameter.Value, parameter.Location)
                        {
                        }
@@ -254,12 +251,12 @@ namespace Mono.CSharp.Linq
                {
                }
 
-               protected static Expression CreateRangeVariableType (ToplevelBlock block, IMemberContext context, LocatedToken name, Expression init)
+               protected static Expression CreateRangeVariableType (ToplevelBlock block, IMemberContext context, SimpleMemberName name, Expression init)
                {
                        ArrayList args = new ArrayList (2);
                        args.Add (new AnonymousTypeParameter (block.Parameters [0]));
                        args.Add (new RangeAnonymousTypeParameter (init, name));
-                       return new AnonymousTypeDeclaration (args, context.CurrentTypeDefinition, name.Location);
+                       return new NewAnonymousType (args, context.CurrentTypeDefinition, name.Location);
                }
        }
 
@@ -272,10 +269,21 @@ namespace Mono.CSharp.Linq
 
                public override Expression BuildQueryClause (ResolveContext ec, Expression lSide)
                {
+                       expr = expr.Resolve (ec);
+                       if (expr == null)
+                               return null;
+
+                       if (TypeManager.IsDynamicType (expr.Type) || 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;
+                       }
+
                        return next.BuildQueryClause (ec, expr);
                }
 
-               public override Expression DoResolve (ResolveContext ec)
+               protected override Expression DoResolve (ResolveContext ec)
                {
                        Expression e = BuildQueryClause (ec, null);
                        return e.Resolve (ec);
@@ -358,10 +366,10 @@ namespace Mono.CSharp.Linq
 
        class Join : ARangeVariableQueryClause
        {
-               readonly LocatedToken lt;
+               readonly SimpleMemberName lt;
                ToplevelBlock inner_selector, outer_selector;
 
-               public Join (ToplevelBlock block, LocatedToken lt, Expression inner, ToplevelBlock outerSelector, ToplevelBlock innerSelector, Location loc)
+               public Join (ToplevelBlock block, SimpleMemberName lt, Expression inner, ToplevelBlock outerSelector, ToplevelBlock innerSelector, Location loc)
                        : base (block, inner)
                {
                        this.lt = lt;
@@ -384,7 +392,7 @@ namespace Mono.CSharp.Linq
                        args.Add (new Argument (lambda));
 
                        Expression result_selector_expr;
-                       LocatedToken into_variable = GetIntoVariable ();
+                       SimpleMemberName into_variable = GetIntoVariable ();
                        //
                        // When select follows use is as result selector
                        //
@@ -403,7 +411,7 @@ namespace Mono.CSharp.Linq
                        args.Add (new Argument (result_selector));
                }
 
-               protected virtual LocatedToken GetIntoVariable ()
+               protected virtual SimpleMemberName GetIntoVariable ()
                {
                        return lt;
                }
@@ -423,16 +431,16 @@ namespace Mono.CSharp.Linq
 
        class GroupJoin : Join
        {
-               readonly LocatedToken into;
+               readonly SimpleMemberName into;
 
-               public GroupJoin (ToplevelBlock block, LocatedToken lt, Expression inner,
-                       ToplevelBlock outerSelector, ToplevelBlock innerSelector, LocatedToken into, Location loc)
+               public GroupJoin (ToplevelBlock block, SimpleMemberName lt, Expression inner,
+                       ToplevelBlock outerSelector, ToplevelBlock innerSelector, SimpleMemberName into, Location loc)
                        : base (block, lt, inner, outerSelector, innerSelector, loc)
                {
                        this.into = into;
                }
 
-               protected override LocatedToken GetIntoVariable ()
+               protected override SimpleMemberName GetIntoVariable ()
                {
                        return into;
                }
@@ -444,7 +452,7 @@ namespace Mono.CSharp.Linq
 
        class Let : ARangeVariableQueryClause
        {
-               public Let (ToplevelBlock block, TypeContainer container, LocatedToken identifier, Expression expr)
+               public Let (ToplevelBlock block, TypeContainer container, SimpleMemberName identifier, Expression expr)
                        : base (block, CreateRangeVariableType (block, container, identifier, expr))
                {
                }
@@ -482,9 +490,9 @@ namespace Mono.CSharp.Linq
 
        class SelectMany : ARangeVariableQueryClause
        {
-               LocatedToken lt;
+               SimpleMemberName lt;
 
-               public SelectMany (ToplevelBlock block, LocatedToken lt, Expression expr)
+               public SelectMany (ToplevelBlock block, SimpleMemberName lt, Expression expr)
                        : base (block, expr)
                {
                        this.lt = lt;
@@ -594,7 +602,7 @@ namespace Mono.CSharp.Linq
                        public readonly ParametersCompiled Parent;
                        public readonly string Identifier;
 
-                       public TransparentParameter (ParametersCompiled parent, LocatedToken identifier)
+                       public TransparentParameter (ParametersCompiled parent, SimpleMemberName identifier)
                                : base (ParameterNamePrefix + Counter++, identifier.Location)
                        {
                                Parent = parent;
@@ -615,15 +623,15 @@ namespace Mono.CSharp.Linq
                        }
                }
 
-               public QueryBlock (CompilerContext ctx, Block parent, LocatedToken lt, Location start)
-                       : base (ctx, parent, new ParametersCompiled (new ImplicitQueryParameter (lt.Value, lt.Location)), start)
+               public QueryBlock (CompilerContext ctx, Block parent, SimpleMemberName lt, Location start)
+                       : base (ctx, parent, new ParametersCompiled (ctx, new ImplicitQueryParameter (lt.Value, lt.Location)), start)
                {
                        if (parent != null)
                                base.CheckParentConflictName (parent.Toplevel, lt.Value, lt.Location);
                }
 
-               public QueryBlock (CompilerContext ctx, Block parent, ParametersCompiled parameters, LocatedToken lt, Location start)
-                       : base (ctx, parent, new ParametersCompiled (parameters [0].Clone (), new ImplicitQueryParameter (lt.Value, lt.Location)), start)
+               public QueryBlock (CompilerContext ctx, Block parent, ParametersCompiled parameters, SimpleMemberName lt, Location start)
+                       : base (ctx, parent, new ParametersCompiled (ctx, parameters [0].Clone (), new ImplicitQueryParameter (lt.Value, lt.Location)), start)
                {
                }
 
@@ -632,11 +640,11 @@ namespace Mono.CSharp.Linq
                {
                }
 
-               public void AddTransparentParameter (LocatedToken name)
+               public void AddTransparentParameter (CompilerContext ctx, SimpleMemberName name)
                {
                        base.CheckParentConflictName (this, name.Value, name.Location);
 
-                       parameters = new ParametersCompiled (new TransparentParameter (parameters, name));
+                       parameters = new ParametersCompiled (ctx, new TransparentParameter (parameters, name));
                }
 
                protected override bool CheckParentConflictName (ToplevelBlock block, string name, Location l)