Skip to content

Commit

Permalink
2010-05-27 Marek Safar <marek.safar@gmail.com>
Browse files Browse the repository at this point in the history
	* *.cs: Sync with the latest gmcs.


svn path=/trunk/mcs/; revision=156166
  • Loading branch information
marek-safar committed Apr 27, 2010
1 parent d638968 commit 46b3c95
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public override DynamicMetaObject FallbackBinaryOperation (DynamicMetaObject tar
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public DynamicMetaObject Bind (Type callingType)

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) {
Expand Down Expand Up @@ -134,26 +134,26 @@ public static Compiler.Expression CreateCompilerExpression (CSharpArgumentInfo i
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;

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<CSharpArgumentInfo> info, DynamicMetaObject[] args)
Expand Down Expand Up @@ -208,27 +208,52 @@ public static BindingRestrictions CreateRestrictionsOnTarget (DynamicMetaObject[

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<Compiler.PredefinedTypeSpec> 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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public override DynamicMetaObject FallbackConvert (DynamicMetaObject target, Dyn
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override DynamicMetaObject FallbackGetIndex (DynamicMetaObject target, Dy
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override DynamicMetaObject FallbackGetMember (DynamicMetaObject target, D
{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public override DynamicMetaObject FallbackInvoke (DynamicMetaObject target, Dyna
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public CSharpInvokeConstructorBinder (Type callingContext, IEnumerable<CSharpArg
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override DynamicMetaObject FallbackInvokeMember (DynamicMetaObject target
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) {
Expand All @@ -76,9 +76,9 @@ public override DynamicMetaObject FallbackInvokeMember (DynamicMetaObject target
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public override DynamicMetaObject Bind (DynamicMetaObject target, DynamicMetaObj
{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override DynamicMetaObject FallbackSetIndex (DynamicMetaObject target, Dy

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override DynamicMetaObject FallbackSetMember (DynamicMetaObject target, D
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override DynamicMetaObject FallbackUnaryOperation (DynamicMetaObject targ
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2010-05-27 Marek Safar <marek.safar@gmail.com>

* *.cs: Sync with the latest gmcs.

2010-02-10 Marek Safar <marek.safar@gmail.com>

* *.cs: Track RC API changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,37 @@ 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;
}

#region IMemberContext Members

public Type CurrentType {
public Compiler.TypeSpec CurrentType {
get { return currentType; }
}

public Compiler.TypeParameter[] CurrentTypeParameters {
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
Expand All @@ -82,13 +88,13 @@ public string GetSignatureForError ()
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 ();
}
Expand Down

0 comments on commit 46b3c95

Please sign in to comment.