//
using System;
-using System.Collections;
using System.Reflection.Emit;
+using SLE = System.Linq.Expressions;
#if NET_4_0
using System.Dynamic;
-using SLE = System.Linq.Expressions;
#endif
namespace Mono.CSharp
#if !NET_4_0
public class DynamicMetaObject
{
- public Type RuntimeType;
- public Type LimitType;
+ public TypeSpec RuntimeType;
+ public TypeSpec LimitType;
+ public SLE.Expression Expression;
}
#endif
readonly DynamicMetaObject obj;
- public RuntimeValueExpression (DynamicMetaObject obj, bool isCompileTimeType)
+ public RuntimeValueExpression (DynamicMetaObject obj, TypeSpec type)
{
this.obj = obj;
- this.type = isCompileTimeType ? obj.LimitType : obj.RuntimeType;
- this.type = obj.LimitType;
+ this.type = type;
this.eclass = ExprClass.Variable;
}
throw new NotImplementedException ();
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
return this;
}
#endregion
-#if NET_4_0
public SLE.Expression MakeAssignExpression (BuilderContext ctx)
{
return obj.Expression;
public override SLE.Expression MakeExpression (BuilderContext ctx)
{
- return SLE.Expression.Convert (obj.Expression, type);
+ return SLE.Expression.Convert (obj.Expression, type.GetMetaInfo ());
}
-#endif
public DynamicMetaObject MetaObject {
get { return obj; }
//
public class DynamicResultCast : ShimExpression
{
- public DynamicResultCast (Type type, Expression expr)
+ public DynamicResultCast (TypeSpec type, Expression expr)
: base (expr)
{
this.type = type;
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
- expr = expr.DoResolve (ec);
+ expr = expr.Resolve (ec);
eclass = ExprClass.Value;
return this;
}
#if NET_4_0
public override SLE.Expression MakeExpression (BuilderContext ctx)
{
- return SLE.Expression.Block (expr.MakeExpression (ctx), SLE.Expression.Default (type));
+ return SLE.Expression.Block (expr.MakeExpression (ctx), SLE.Expression.Default (type.GetMetaInfo ()));
}
#endif
}
new MemberName (CompilerGeneratedClass.MakeName (null, "c", "DynamicSites", 0)),
Modifiers.INTERNAL | Modifiers.STATIC)
{
- ModFlags &= ~Modifiers.SEALED;
}
}
CSharpBinderFlags flags;
public BinderFlags (CSharpBinderFlags flags, DynamicExpressionStatement statement)
- : base ()
+ : base (statement.loc)
{
this.flags = flags;
this.statement = statement;
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
- Child = new IntConstant ((int) (flags | statement.flags), statement.loc);
+ Child = new IntConstant ((int) (flags | statement.flags), statement.loc).Resolve (ec);
type = TypeManager.binder_flags;
eclass = Child.eclass;
if (global_site_container == null) {
global_site_container = new StaticDataClass ();
RootContext.ToplevelTypes.AddCompilerGeneratedClass (global_site_container);
+ global_site_container.CreateType ();
global_site_container.DefineType ();
global_site_container.Define ();
-// global_site_container.EmitType ();
-
- RootContext.RegisterCompilerGeneratedType (global_site_container.TypeBuilder);
}
return global_site_container;
return null;
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
- if (eclass != ExprClass.Invalid)
- return this;
-
if (DoResolveCore (ec))
binder_expr = binder.CreateCallSiteBinder (ec, arguments);
if (TypeManager.binder_type == null) {
var t = TypeManager.CoreLookupType (rc.Compiler,
- "Microsoft.CSharp.RuntimeBinder", "Binder", Kind.Class, true);
+ "Microsoft.CSharp.RuntimeBinder", "Binder", MemberKind.Class, true);
if (t != null)
TypeManager.binder_type = new TypeExpression (t, Location.Null);
}
if (TypeManager.call_site_type == null)
TypeManager.call_site_type = TypeManager.CoreLookupType (rc.Compiler,
- "System.Runtime.CompilerServices", "CallSite", Kind.Class, true);
+ "System.Runtime.CompilerServices", "CallSite", MemberKind.Class, true);
if (TypeManager.generic_call_site_type == null)
TypeManager.generic_call_site_type = TypeManager.CoreLookupType (rc.Compiler,
- "System.Runtime.CompilerServices", "CallSite`1", Kind.Class, true);
+ "System.Runtime.CompilerServices", "CallSite", 1, MemberKind.Class, true);
if (TypeManager.binder_flags == null) {
TypeManager.binder_flags = TypeManager.CoreLookupType (rc.Compiler,
- "Microsoft.CSharp.RuntimeBinder", "CSharpBinderFlags", Kind.Enum, true);
+ "Microsoft.CSharp.RuntimeBinder", "CSharpBinderFlags", MemberKind.Enum, true);
}
eclass = ExprClass.Value;
{
int dyn_args_count = arguments == null ? 0 : arguments.Count;
TypeExpr site_type = CreateSiteType (RootContext.ToplevelTypes.Compiler, arguments, dyn_args_count, isStatement);
- FieldExpr site_field_expr = new FieldExpr (CreateSiteField (site_type).FieldBuilder, loc);
+ FieldExpr site_field_expr = new FieldExpr (CreateSiteField (site_type), loc);
- SymbolWriter.OpenCompilerGeneratedBlock (ec.ig);
+ SymbolWriter.OpenCompilerGeneratedBlock (ec);
Arguments args = new Arguments (1);
args.Add (new Argument (binder));
BlockContext bc = new BlockContext (ec.MemberContext, null, TypeManager.void_type);
if (s.Resolve (bc)) {
- Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc)), s, loc);
+ Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc), loc), s, loc);
init.Emit (ec);
}
if (target != null)
target.Emit (ec);
- SymbolWriter.CloseCompilerGeneratedBlock (ec.ig);
+ SymbolWriter.CloseCompilerGeneratedBlock (ec);
}
public static MemberAccess GetBinderNamespace (Location loc)
FullNamedExpression[] targs = new FullNamedExpression[dyn_args_count + default_args];
targs [0] = new TypeExpression (TypeManager.call_site_type, loc);
for (int i = 0; i < dyn_args_count; ++i) {
- Type arg_type;
+ TypeSpec arg_type;
Argument a = arguments [i];
if (a.Type == TypeManager.null_type)
arg_type = TypeManager.object_type;
TypeExpr del_type = null;
if (!has_ref_out_argument) {
- string d_name = is_statement ? "Action`" : "Func`";
+ string d_name = is_statement ? "Action" : "Func";
- Type t = TypeManager.CoreLookupType (ctx, "System", d_name + (dyn_args_count + default_args), Kind.Delegate, false);
+ TypeSpec t = TypeManager.CoreLookupType (ctx, "System", d_name, dyn_args_count + default_args, MemberKind.Delegate, false);
if (t != null) {
if (!is_statement)
targs [targs.Length - 1] = new TypeExpression (type, loc);
// Create custom delegate when no appropriate predefined one is found
//
if (del_type == null) {
- Type rt = is_statement ? TypeManager.void_type : type;
+ TypeSpec rt = is_statement ? TypeManager.void_type : type;
Parameter[] p = new Parameter [dyn_args_count + 1];
p[0] = new Parameter (targs [0], "p0", Parameter.Modifier.NONE, null, loc);
Delegate d = new Delegate (parent.NamespaceEntry, parent, new TypeExpression (rt, loc),
Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED,
new MemberName ("Container" + container_counter++.ToString ("X")),
- new ParametersCompiled (p), null);
+ new ParametersCompiled (ctx, p), null);
+ d.CreateType ();
d.DefineType ();
d.Define ();
+ d.Emit ();
parent.AddDelegate (d);
- del_type = new TypeExpression (d.TypeBuilder, loc);
+ del_type = new TypeExpression (d.Definition, loc);
}
TypeExpr site_type = new GenericTypeExpr (TypeManager.generic_call_site_type, new TypeArguments (del_type), loc);
type = TypeManager.bool_type;
condition = new If (
- new Binary (Binary.Operator.Equality, this, new BoolLiteral (true, loc)),
+ new Binary (Binary.Operator.Equality, this, new BoolLiteral (true, loc), loc),
new StatementExpression (invoke), new StatementExpression (assignment),
loc);
}
class DynamicConversion : DynamicExpressionStatement, IDynamicBinder
{
- public DynamicConversion (Type targetType, CSharpBinderFlags flags, Arguments args, Location loc)
+ public DynamicConversion (TypeSpec targetType, CSharpBinderFlags flags, Arguments args, Location loc)
: base (null, args, loc)
{
type = targetType;
public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
{
- Arguments binder_args = new Arguments (2);
+ Arguments binder_args = new Arguments (3);
flags |= ec.HasSet (ResolveContext.Options.CheckedScope) ? CSharpBinderFlags.CheckedContext : 0;
binder_args.Add (new Argument (new BinderFlags (flags, this)));
+ binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
binder_args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
return new Invocation (GetBinder ("Convert", loc), binder_args);
}
class DynamicConstructorBinder : DynamicExpressionStatement, IDynamicBinder
{
- public DynamicConstructorBinder (Type type, Arguments args, Location loc)
+ public DynamicConstructorBinder (TypeSpec type, Arguments args, Location loc)
: base (null, args, loc)
{
this.type = type;
this.member = member;
}
- public DynamicInvocation (ATypeNameExpression member, Arguments args, Type type, Location loc)
+ public DynamicInvocation (ATypeNameExpression member, Arguments args, TypeSpec type, Location loc)
: this (member, args, loc)
{
// When a return type is known not to be dynamic
if (member != null && member.HasTypeArguments) {
TypeArguments ta = member.TypeArguments;
if (ta.Resolve (ec)) {
- ArrayList targs = new ArrayList (ta.Count);
- foreach (Type t in ta.Arguments)
+ var targs = new ArrayInitializer (ta.Count, loc);
+ foreach (TypeSpec t in ta.Arguments)
targs.Add (new TypeOf (new TypeExpression (t, loc), loc));
binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", targs, loc)));
Expression real_args;
if (args == null) {
// Cannot be null because .NET trips over
- real_args = new ArrayCreation (new MemberAccess (GetBinderNamespace (loc), "CSharpArgumentInfo", loc), "[]", new ArrayList (0), loc);
+ real_args = new ArrayCreation (
+ new MemberAccess (GetBinderNamespace (loc), "CSharpArgumentInfo", loc), "[]",
+ new ArrayInitializer (0, loc), loc);
} else {
real_args = new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc);
}
public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
{
- Arguments binder_args = new Arguments (3);
+ Arguments binder_args = new Arguments (4);
MemberAccess sle = new MemberAccess (new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Linq", loc), "Expressions", loc);
binder_args.Add (new Argument (new BinderFlags (flags, this)));
binder_args.Add (new Argument (new MemberAccess (new MemberAccess (sle, "ExpressionType", loc), name, loc)));
+ binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc)));
return new Invocation (GetBinder ("UnaryOperation", loc), binder_args);