From 46b3c9551cf6ee5ebc6b9ea8efe667f4e96ff0b2 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Tue, 27 Apr 2010 08:20:18 +0000 Subject: [PATCH 1/1] 2010-05-27 Marek Safar * *.cs: Sync with the latest gmcs. svn path=/trunk/mcs/; revision=156166 --- .../CSharpBinaryOperationBinder.cs | 2 +- .../CSharpBinder.cs | 47 ++++++++++++++----- .../CSharpConvertBinder.cs | 4 +- .../CSharpGetIndexBinder.cs | 2 +- .../CSharpGetMemberBinder.cs | 2 +- .../CSharpInvokeBinder.cs | 4 +- .../CSharpInvokeConstructorBinder.cs | 2 +- .../CSharpInvokeMemberBinder.cs | 6 +-- .../CSharpIsEventBinder.cs | 3 +- .../CSharpSetIndexBinder.cs | 2 +- .../CSharpSetMemberBinder.cs | 2 +- .../CSharpUnaryOperationBinder.cs | 2 +- .../Microsoft.CSharp.RuntimeBinder/ChangeLog | 4 ++ .../RuntimeBinderContext.cs | 18 ++++--- 14 files changed, 68 insertions(+), 32 deletions(-) diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinaryOperationBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinaryOperationBinder.cs index 2aac9a5417f..72787fa3dc2 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinaryOperationBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinaryOperationBinder.cs @@ -144,7 +144,7 @@ namespace Microsoft.CSharp.RuntimeBinder expr = new Compiler.Binary (oper, left, right, Compiler.Location.Null); } - expr = new Compiler.Cast (new Compiler.TypeExpression (ReturnType, Compiler.Location.Null), expr); + expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr); if ((flags & CSharpBinderFlags.CheckedContext) != 0) expr = new Compiler.CheckedExpr (expr, Compiler.Location.Null); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinder.cs index 11cc31f2383..981252043cd 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinder.cs @@ -87,7 +87,7 @@ namespace Microsoft.CSharp.RuntimeBinder Expression res; try { - var rc = new Compiler.ResolveContext (new RuntimeBinderContext (ctx, callingType), ResolveOptions); + var rc = new Compiler.ResolveContext (new RuntimeBinderContext (ctx, TypeImporter.Import (callingType)), ResolveOptions); // Static typemanager and internal caches are not thread-safe lock (resolver) { @@ -134,7 +134,7 @@ namespace Microsoft.CSharp.RuntimeBinder return new Compiler.NullLiteral (Compiler.Location.Null); InitializeCompiler (null); - return Compiler.Constant.CreateConstantFromValue (value.LimitType, null, Compiler.Location.Null); + return Compiler.Constant.CreateConstantFromValue (TypeImporter.Import (value.LimitType), null, Compiler.Location.Null); } bool is_compile_time; @@ -142,18 +142,18 @@ namespace Microsoft.CSharp.RuntimeBinder if (info != null) { if ((info.Flags & CSharpArgumentInfoFlags.Constant) != 0) { InitializeCompiler (null); - return Compiler.Constant.CreateConstantFromValue (value.LimitType, value.Value, Compiler.Location.Null); + return Compiler.Constant.CreateConstantFromValue (TypeImporter.Import (value.LimitType), value.Value, Compiler.Location.Null); } if ((info.Flags & CSharpArgumentInfoFlags.IsStaticType) != 0) - return new Compiler.TypeExpression ((Type) value.Value, Compiler.Location.Null); + return new Compiler.TypeExpression (TypeImporter.Import ((Type) value.Value), Compiler.Location.Null); is_compile_time = (info.Flags & CSharpArgumentInfoFlags.UseCompileTimeType) != 0; } else { is_compile_time = false; } - return new Compiler.RuntimeValueExpression (value, is_compile_time); + return new Compiler.RuntimeValueExpression (value, TypeImporter.Import (is_compile_time ? value.LimitType : value.RuntimeType)); } public static Compiler.Arguments CreateCompilerArguments (IEnumerable info, DynamicMetaObject[] args) @@ -208,27 +208,52 @@ namespace Microsoft.CSharp.RuntimeBinder public static void InitializeCompiler (Compiler.CompilerContext ctx) { - if (Compiler.TypeManager.object_type != null) + if (TypeImporter.Predefined == null) return; lock (compiler_initializer) { - if (Compiler.TypeManager.object_type != null) + if (TypeImporter.Predefined == null) return; // I don't think dynamically loaded assemblies can be used as dynamic - // expression without static type be loaded first + // expression without static type to be loaded first // AppDomain.CurrentDomain.AssemblyLoad += (sender, e) => { throw new NotImplementedException (); }; // Import all currently loaded assemblies - foreach (System.Reflection.Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) - Compiler.GlobalRootNamespace.Instance.AddAssemblyReference (a); + var ns = Compiler.GlobalRootNamespace.Instance; + foreach (System.Reflection.Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) { + ns.AddAssemblyReference (a); + ns.ImportAssembly (a); + } if (ctx == null) ctx = CreateDefaultCompilerContext (); - Compiler.TypeManager.InitCoreTypes (ctx); + Compiler.TypeManager.InitCoreTypes (ctx, TypeImporter.Predefined); + TypeImporter.Predefined = null; + Compiler.TypeManager.InitOptionalCoreTypes (ctx); } } } + + static class TypeImporter + { + static object lock_object; + public static IList Predefined; + + static TypeImporter () + { + lock_object = new object (); + Predefined = Compiler.TypeManager.InitCoreTypes (); + Compiler.Import.Initialize (); + } + + public static Compiler.TypeSpec Import (Type type) + { + lock (lock_object) { + return Compiler.Import.ImportType (type); + } + } + } } diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpConvertBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpConvertBinder.cs index d125c4bbcc8..5af6409c0c1 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpConvertBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpConvertBinder.cs @@ -51,9 +51,9 @@ namespace Microsoft.CSharp.RuntimeBinder var expr = CSharpBinder.CreateCompilerExpression (null, target); if (Explicit) - expr = new Compiler.Cast (new Compiler.TypeExpression (Type, Compiler.Location.Null), expr); + expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (Type), Compiler.Location.Null), expr); else - expr = new Compiler.ImplicitCast (expr, Type, (flags & CSharpBinderFlags.ConvertArrayIndex) != 0); + expr = new Compiler.ImplicitCast (expr, TypeImporter.Import (Type), (flags & CSharpBinderFlags.ConvertArrayIndex) != 0); if ((flags & CSharpBinderFlags.CheckedContext) != 0) expr = new Compiler.CheckedExpr (expr, Compiler.Location.Null); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpGetIndexBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpGetIndexBinder.cs index 85e009ba229..a11bd9bae21 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpGetIndexBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpGetIndexBinder.cs @@ -58,7 +58,7 @@ namespace Microsoft.CSharp.RuntimeBinder var expr = CSharpBinder.CreateCompilerExpression (argumentInfo [0], target); var args = CSharpBinder.CreateCompilerArguments (argumentInfo.Skip (1), indexes); expr = new Compiler.ElementAccess (expr, args); - expr = new Compiler.Cast (new Compiler.TypeExpression (ReturnType, Compiler.Location.Null), expr); + expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr); var binder = new CSharpBinder (this, expr, errorSuggestion); binder.AddRestrictions (target); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpGetMemberBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpGetMemberBinder.cs index bf9bf3a208b..9f9fad0b931 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpGetMemberBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpGetMemberBinder.cs @@ -50,7 +50,7 @@ namespace Microsoft.CSharp.RuntimeBinder { var expr = CSharpBinder.CreateCompilerExpression (argumentInfo [0], target); expr = new Compiler.MemberAccess (expr, Name); - expr = new Compiler.Cast (new Compiler.TypeExpression (ReturnType, Compiler.Location.Null), expr); + expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr); var binder = new CSharpBinder (this, expr, errorSuggestion); binder.AddRestrictions (target); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeBinder.cs index 3748ba0e5e3..ded455c50b9 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeBinder.cs @@ -55,9 +55,9 @@ namespace Microsoft.CSharp.RuntimeBinder expr = new Compiler.Invocation (expr, c_args); if ((flags & CSharpBinderFlags.ResultDiscarded) == 0) - expr = new Compiler.Cast (new Compiler.TypeExpression (ReturnType, Compiler.Location.Null), expr); + expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr); else - expr = new Compiler.DynamicResultCast (ReturnType, expr); + expr = new Compiler.DynamicResultCast (TypeImporter.Import (ReturnType), expr); var binder = new CSharpBinder (this, expr, errorSuggestion); binder.AddRestrictions (target); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeConstructorBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeConstructorBinder.cs index 87ac5f7ffb8..b42cc43873d 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeConstructorBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeConstructorBinder.cs @@ -49,7 +49,7 @@ namespace Microsoft.CSharp.RuntimeBinder public override DynamicMetaObject Bind (DynamicMetaObject target, DynamicMetaObject[] args) { var type = CSharpBinder.CreateCompilerExpression (argumentInfo [0], target); - target_return_type = type.Type; + target_return_type = type.Type.GetMetaInfo (); var c_args = CSharpBinder.CreateCompilerArguments (argumentInfo.Skip (1), args); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeMemberBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeMemberBinder.cs index b578e499ea3..3417cfda5d7 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeMemberBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpInvokeMemberBinder.cs @@ -63,7 +63,7 @@ namespace Microsoft.CSharp.RuntimeBinder var c_args = CSharpBinder.CreateCompilerArguments (argumentInfo.Skip (1), args); var t_args = typeArguments == null ? null : - new Compiler.TypeArguments (typeArguments.Select (l => new Compiler.TypeExpression (l, Compiler.Location.Null)).ToArray ()); + new Compiler.TypeArguments (typeArguments.Select (l => new Compiler.TypeExpression (TypeImporter.Import (l), Compiler.Location.Null)).ToArray ()); Compiler.Expression expr; if ((flags & CSharpBinderFlags.InvokeSimpleName) != 0) { @@ -76,9 +76,9 @@ namespace Microsoft.CSharp.RuntimeBinder expr = new Compiler.Invocation (expr, c_args); if ((flags & CSharpBinderFlags.ResultDiscarded) == 0) - expr = new Compiler.Cast (new Compiler.TypeExpression (ReturnType, Compiler.Location.Null), expr); + expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr); else - expr = new Compiler.DynamicResultCast (ReturnType, expr); + expr = new Compiler.DynamicResultCast (TypeImporter.Import (ReturnType), expr); var binder = new CSharpBinder (this, expr, errorSuggestion); binder.AddRestrictions (target); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpIsEventBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpIsEventBinder.cs index 52996e40d1a..ee74d85cb59 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpIsEventBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpIsEventBinder.cs @@ -49,8 +49,9 @@ namespace Microsoft.CSharp.RuntimeBinder { var ctx = CSharpBinder.CreateDefaultCompilerContext (); CSharpBinder.InitializeCompiler (ctx); + var context = TypeImporter.Import (callingContext); - var expr = Compiler.Expression.MemberLookup (ctx, callingContext, callingContext, name, Compiler.Location.Null); + var expr = Compiler.Expression.MemberLookup (ctx, context, context, name, 0, Compiler.BindingRestriction.None, Compiler.Location.Null); var binder = new CSharpBinder ( this, new Compiler.BoolConstant (expr is Compiler.EventExpr, Compiler.Location.Null), null); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpSetIndexBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpSetIndexBinder.cs index 4a6a0ef37e4..e5da8410d70 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpSetIndexBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpSetIndexBinder.cs @@ -61,7 +61,7 @@ namespace Microsoft.CSharp.RuntimeBinder var source = CSharpBinder.CreateCompilerExpression (argumentInfo [indexes.Length + 1], value); expr = new Compiler.SimpleAssign (expr, source); - expr = new Compiler.Cast (new Compiler.TypeExpression (ReturnType, Compiler.Location.Null), expr); + expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr); var binder = new CSharpBinder (this, expr, errorSuggestion); binder.AddRestrictions (target); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpSetMemberBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpSetMemberBinder.cs index 2e323c8b1ac..b9e9d4a0fc6 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpSetMemberBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpSetMemberBinder.cs @@ -54,7 +54,7 @@ namespace Microsoft.CSharp.RuntimeBinder // Field assignment expr = new Compiler.MemberAccess (expr, Name); expr = new Compiler.SimpleAssign (expr, source); - expr = new Compiler.Cast (new Compiler.TypeExpression (ReturnType, Compiler.Location.Null), expr); + expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr); var binder = new CSharpBinder (this, expr, errorSuggestion); binder.AddRestrictions (target); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpUnaryOperationBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpUnaryOperationBinder.cs index 05a27c1ce1d..5e495c15abe 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpUnaryOperationBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpUnaryOperationBinder.cs @@ -83,7 +83,7 @@ namespace Microsoft.CSharp.RuntimeBinder else expr = new Compiler.Unary (GetOperator (), expr, Compiler.Location.Null); - expr = new Compiler.Cast (new Compiler.TypeExpression (ReturnType, Compiler.Location.Null), expr); + expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr); if ((flags & CSharpBinderFlags.CheckedContext) != 0) expr = new Compiler.CheckedExpr (expr, Compiler.Location.Null); diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/ChangeLog b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/ChangeLog index 356030f3d3a..797be5203df 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/ChangeLog +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/ChangeLog @@ -1,3 +1,7 @@ +2010-05-27 Marek Safar + + * *.cs: Sync with the latest gmcs. + 2010-02-10 Marek Safar * *.cs: Track RC API changes. diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/RuntimeBinderContext.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/RuntimeBinderContext.cs index 00fb0d4af2f..ee3f7a48d19 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/RuntimeBinderContext.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/RuntimeBinderContext.cs @@ -34,9 +34,9 @@ namespace Microsoft.CSharp.RuntimeBinder class RuntimeBinderContext : Compiler.IMemberContext { readonly Compiler.CompilerContext ctx; - readonly Type currentType; + readonly Compiler.TypeSpec currentType; - public RuntimeBinderContext (Compiler.CompilerContext ctx, Type currentType) + public RuntimeBinderContext (Compiler.CompilerContext ctx, Compiler.TypeSpec currentType) { this.ctx = ctx; this.currentType = currentType; @@ -44,7 +44,7 @@ namespace Microsoft.CSharp.RuntimeBinder #region IMemberContext Members - public Type CurrentType { + public Compiler.TypeSpec CurrentType { get { return currentType; } } @@ -52,13 +52,19 @@ namespace Microsoft.CSharp.RuntimeBinder get { throw new NotImplementedException (); } } - public Compiler.TypeContainer CurrentTypeDefinition { + public Compiler.MemberCore CurrentMemberDefinition { get { // For operators and methods return new Compiler.ModuleContainer (currentType.Assembly); } } + public bool HasUnresolvedConstraints { + get { + return false; + } + } + public bool IsObsolete { get { // Always true to ignore obsolete attribute checks @@ -82,13 +88,13 @@ namespace Microsoft.CSharp.RuntimeBinder throw new NotImplementedException (); } - public Compiler.ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Mono.CSharp.Location loc) + public Compiler.ExtensionMethodGroupExpr LookupExtensionMethod (Compiler.TypeSpec extensionType, string name, int arity, Mono.CSharp.Location loc) { // No extension method lookup in this context return null; } - public Compiler.FullNamedExpression LookupNamespaceOrType (string name, Mono.CSharp.Location loc, bool ignore_cs0104) + public Compiler.FullNamedExpression LookupNamespaceOrType (string name, int arity, Mono.CSharp.Location loc, bool ignore_cs0104) { throw new NotImplementedException (); } -- 2.25.1