//
using System;
-using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
+using System.Collections.Generic;
namespace Mono.CSharp
{
this.Expr = expr;
}
- public Type Type {
+ public TypeSpec Type {
get { return Expr.Type; }
}
mode |= AddressOp.Load;
IMemoryLocation ml = (IMemoryLocation) Expr;
- ParameterReference pr = ml as ParameterReference;
-
- //
- // ParameterReferences might already be references, so we want
- // to pass just the value
- //
- if (pr != null && pr.IsRef)
- pr.EmitLoad (ec);
- else
- ml.AddressOf (ec, mode);
+ ml.AddressOf (ec, mode);
}
public Argument Clone (CloneContext clonectx)
public class NamedArgument : Argument
{
- public readonly LocatedToken Name;
+ public readonly string Name;
+ readonly Location loc;
LocalTemporary variable;
- public NamedArgument (LocatedToken name, Expression expr)
- : base (expr)
+ public NamedArgument (string name, Location loc, Expression expr)
+ : this (name, loc, expr, AType.None)
{
- Name = name;
+ }
+
+ public NamedArgument (string name, Location loc, Expression expr, AType modifier)
+ : base (expr, modifier)
+ {
+ this.Name = name;
+ this.loc = loc;
}
public override Expression CreateExpressionTree (ResolveContext ec)
{
- ec.Report.Error (853, Name.Location, "An expression tree cannot contain named argument");
+ ec.Report.Error (853, loc, "An expression tree cannot contain named argument");
return base.CreateExpressionTree (ec);
}
public void EmitAssign (EmitContext ec)
{
- Expr.Emit (ec);
- variable = new LocalTemporary (Expr.Type);
+ var type = Expr.Type;
+ if (IsByRef) {
+ var ml = (IMemoryLocation) Expr;
+ ml.AddressOf (ec, AddressOp.Load);
+ type = ReferenceContainer.MakeType (type);
+ } else {
+ Expr.Emit (ec);
+ }
+
+ variable = new LocalTemporary (type);
variable.Store (ec);
Expr = variable;
}
- }
+ public Location Location {
+ get { return loc; }
+ }
+ }
+
public class Arguments
{
- ArrayList args; // TODO: This should really be linked list
- ArrayList reordered; // TODO: LinkedList
- bool has_dynamic;
+ List<Argument> args;
+ List<NamedArgument> reordered;
public Arguments (int capacity)
{
- args = new ArrayList (capacity);
+ args = new List<Argument> (capacity);
}
- public int Add (Argument arg)
+ public void Add (Argument arg)
{
- return args.Add (arg);
+ args.Add (arg);
}
public void AddRange (Arguments args)
this.args.AddRange (args.args);
}
- public ArrayList CreateDynamicBinderArguments (ResolveContext rc)
+ public ArrayInitializer CreateDynamicBinderArguments (ResolveContext rc)
{
- ArrayList all = new ArrayList (args.Count);
Location loc = Location.Null;
+ var all = new ArrayInitializer (args.Count, loc);
MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace (loc);
var constant = a.Expr as Constant;
if (constant != null && constant.IsLiteral) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
- new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "LiteralConstant", loc));
+ new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc), loc);
} else if (a.ArgType == Argument.AType.Ref) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
- new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc));
+ new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc), loc);
} else if (a.ArgType == Argument.AType.Out) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
- new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc));
+ new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc), loc);
} else if (a.ArgType == Argument.AType.DynamicTypeName) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
- new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc));
+ new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc), loc);
}
var arg_type = a.Expr.Type;
- if (!TypeManager.IsDynamicType (arg_type)) {
+ if (arg_type != InternalType.Dynamic) {
MethodGroupExpr mg = a.Expr as MethodGroupExpr;
if (mg != null) {
rc.Report.Error (1976, a.Expr.Location,
}
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
- new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
+ new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc), loc);
}
string named_value;
NamedArgument na = a as NamedArgument;
if (na != null) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
- new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc));
+ new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc), loc);
- named_value = na.Name.Value;
+ named_value = na.Name;
} else {
named_value = null;
}
foreach (Argument a in args) {
a.Emit (ec);
if (dup_args) {
- ec.ig.Emit (OpCodes.Dup);
+ ec.Emit (OpCodes.Dup);
(temps [i++] = new LocalTemporary (a.Type)).Store (ec);
}
}
}
}
- public bool GetAttributableValue (ResolveContext ec, out object[] values)
- {
- values = new object [args.Count];
- for (int j = 0; j < values.Length; ++j) {
- Argument a = this [j];
- if (!a.Expr.GetAttributableValue (ec, a.Type, out values[j]))
- return false;
- }
-
- return true;
- }
-
- public IEnumerator GetEnumerator ()
+ public IEnumerator<Argument> GetEnumerator ()
{
return args.GetEnumerator ();
}
//
public bool HasDynamic {
get {
- return has_dynamic;
+ foreach (Argument a in args) {
+ if (a.Type == InternalType.Dynamic)
+ return true;
+ }
+
+ return false;
}
}
args.Insert (index, arg);
}
-#if NET_4_0
public static System.Linq.Expressions.Expression[] MakeExpression (Arguments args, BuilderContext ctx)
{
if (args == null || args.Count == 0)
return exprs;
}
-#endif
public void MarkReorderedArgument (NamedArgument a)
{
return;
if (reordered == null)
- reordered = new ArrayList ();
+ reordered = new List<NamedArgument> ();
reordered.Add (a);
}
//
public void Resolve (ResolveContext ec, out bool dynamic)
{
+ dynamic = false;
foreach (Argument a in args) {
a.Resolve (ec);
- this.has_dynamic |= TypeManager.IsDynamicType (a.Type);
+ dynamic |= a.Type == InternalType.Dynamic;
}
-
- dynamic = has_dynamic;
- }
-
- public void MutateHoistedGenericType (AnonymousMethodStorey storey)
- {
- foreach (Argument a in args)
- a.Expr.MutateHoistedGenericType (storey);
}
public void RemoveAt (int index)