using System;
using System.Reflection;
-using System.Collections;
+using System.Collections.Generic;
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
{
}
- protected override Expression Error_MemberLookupFailed (ResolveContext ec, Type container_type, Type qualifier_type,
- Type queried_type, string name, string class_name, MemberTypes mt, BindingFlags bf)
+ protected override Expression Error_MemberLookupFailed (ResolveContext ec, TypeSpec container_type, TypeSpec qualifier_type,
+ TypeSpec queried_type, string name, int arity, string class_name, MemberKind mt, BindingRestriction bf)
{
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?",
return rmg;
}
- public bool AmbiguousCall (ResolveContext ec, MethodBase ambiguous)
+ public bool AmbiguousCall (ResolveContext ec, MethodSpec ambiguous)
{
- ec.Report.SymbolRelatedToPreviousError ((MethodInfo) mg);
+ ec.Report.SymbolRelatedToPreviousError (mg.BestCandidate);
ec.Report.SymbolRelatedToPreviousError (ambiguous);
ec.Report.Error (1940, loc, "Ambiguous implementation of the query pattern `{0}' for source type `{1}'",
mg.Name, mg.InstanceExpression.GetSignatureForError ());
return true;
}
- public bool NoExactMatch (ResolveContext ec, MethodBase method)
+ public bool NoExactMatch (ResolveContext ec, MethodSpec method)
{
- AParametersCollection pd = TypeManager.GetParameterData (method);
- Type source_type = pd.ExtensionMethodType;
+ var pd = method.Parameters;
+ TypeSpec source_type = pd.ExtensionMethodType;
if (source_type != null) {
Argument a = arguments [0];
if (TypeManager.IsGenericType (source_type) && TypeManager.ContainsGenericParameters (source_type)) {
- TypeInferenceContext tic = new TypeInferenceContext (TypeManager.GetTypeArguments (source_type));
+ TypeInferenceContext tic = new TypeInferenceContext (source_type.TypeArguments);
tic.OutputTypeInference (ec, a.Expr, source_type);
if (tic.FixAllTypes (ec)) {
- source_type = TypeManager.DropGenericTypeArguments (source_type).MakeGenericType (tic.InferredTypeArguments);
+ source_type = source_type.GetDefinition ().MakeGenericType (tic.InferredTypeArguments);
}
}
}
}
- if (!TypeManager.IsGenericMethod (method))
+ if (!method.IsGeneric)
return false;
if (mg.Name == "SelectMany") {
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)
{
sealed class RangeAnonymousTypeParameter : AnonymousTypeParameter
{
- public RangeAnonymousTypeParameter (Expression initializer, LocatedToken parameter)
+ public RangeAnonymousTypeParameter (Expression initializer, SimpleMemberName parameter)
: base (initializer, parameter.Value, parameter.Location)
{
}
{
}
- protected static Expression CreateRangeVariableType (ToplevelBlock block, IMemberContext context, LocatedToken name, Expression init)
+ protected static Expression CreateRangeVariableType (ToplevelBlock block, TypeContainer container, SimpleMemberName name, Expression init)
{
- ArrayList args = new ArrayList (2);
+ var args = new List<AnonymousTypeParameter> (2);
args.Add (new AnonymousTypeParameter (block.Parameters [0]));
args.Add (new RangeAnonymousTypeParameter (init, name));
- return new NewAnonymousType (args, context.CurrentTypeDefinition, name.Location);
+ return new NewAnonymousType (args, container, name.Location);
}
}
public override Expression BuildQueryClause (ResolveContext ec, Expression lSide)
{
+ 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;
+ }
+
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);
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;
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
//
result_selector_expr = next.Expr;
next = next.next;
} else {
- result_selector_expr = CreateRangeVariableType (block, ec.MemberContext, into_variable,
+ result_selector_expr = CreateRangeVariableType (block, ec.MemberContext.CurrentMemberDefinition.Parent, into_variable,
new SimpleName (into_variable.Value, into_variable.Location));
}
args.Add (new Argument (result_selector));
}
- protected virtual LocatedToken GetIntoVariable ()
+ protected virtual SimpleMemberName GetIntoVariable ()
{
return lt;
}
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;
}
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))
{
}
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;
result_selector_expr = next.Expr;
next = next.next;
} else {
- result_selector_expr = CreateRangeVariableType (block, ec.MemberContext, lt, new SimpleName (lt.Value, lt.Location));
+ result_selector_expr = CreateRangeVariableType (block, ec.MemberContext.CurrentMemberDefinition.Parent, lt, new SimpleName (lt.Value, lt.Location));
}
LambdaExpression result_selector = new LambdaExpression (lt.Location);
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;
Identifier = identifier.Value;
}
- public static void Reset ()
+ public new static void Reset ()
{
Counter = 0;
}
}
}
- 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)
{
}
{
}
- 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)