public CSharpBinder (DynamicMetaObjectBinder binder, Compiler.Expression expr, DynamicMetaObject errorSuggestion) { this.binder = binder; this.expr = expr; this.restrictions = BindingRestrictions.Empty; this.errorSuggestion = errorSuggestion; }
public override void Print (Compiler.AbstractMessage msg) { string text; if (msg.Code == 214) { text = "Pointers and fixed size buffers cannot be used in a dynamic context"; } else { text = msg.Text; } throw new RuntimeBinderException (text); }
public static DynamicMetaObject Bind (DynamicMetaObject target, Compiler.Expression expr, BindingRestrictions restrictions, DynamicMetaObject errorSuggestion) { var report = new Compiler.Report (ErrorPrinter.Instance) { WarningLevel = 0 }; var ctx = new Compiler.CompilerContext (report); Compiler.RootContext.ToplevelTypes = new Compiler.ModuleContainer (ctx, true); InitializeCompiler (ctx); Expression res; try { // TODO: ResolveOptions Compiler.ResolveContext rc = new Compiler.ResolveContext (new RuntimeBinderContext (ctx)); // Static typemanager and internal caches are not thread-safe lock (resolver) { expr = expr.Resolve (rc); } if (expr == null) throw new RuntimeBinderInternalCompilerException ("Expression resolved to null"); res = expr.MakeExpression (new Compiler.BuilderContext ()); } catch (RuntimeBinderException e) { if (errorSuggestion != null) return errorSuggestion; if (binder_exception_ctor == null) binder_exception_ctor = typeof (RuntimeBinderException).GetConstructor (new[] { typeof (string) }); // // Uses target type to keep expressions composition working // res = Expression.Throw (Expression.New (binder_exception_ctor, Expression.Constant (e.Message)), target.LimitType); } catch (Exception) { if (errorSuggestion != null) return errorSuggestion; throw; } return new DynamicMetaObject (res, restrictions); }
// // Creates an invoke call on invocable expression // public override System.Linq.Expressions.Expression MakeExpression (Compiler.BuilderContext ctx) { var invokeBinder = invoke.invokeBinder; var binder = Binder.Invoke (invokeBinder.flags, invokeBinder.callingContext, invokeBinder.argumentInfo); var args = invoke.Arguments; var args_expr = new SLE.Expression[invokeBinder.argumentInfo.Count]; var types = new Type [args_expr.Length + 2]; // Required by MakeDynamic types[0] = typeof (System.Runtime.CompilerServices.CallSite); types[1] = expr.Type.GetMetaInfo (); args_expr[0] = expr.MakeExpression (ctx); for (int i = 0; i < args.Count; ++i) { args_expr[i + 1] = args[i].Expr.MakeExpression (ctx); int type_index = i + 2; types[type_index] = args[i].Type.GetMetaInfo (); if (args[i].IsByRef) types[type_index] = types[type_index].MakeByRefType (); } // Return type goes last bool void_result = (invokeBinder.flags & CSharpBinderFlags.ResultDiscarded) != 0; types[types.Length - 1] = void_result ? typeof (void) : invokeBinder.ReturnType; // // Much easier to use Expression.Dynamic cannot be used because it ignores ByRef arguments // and it always generates either Func or Action and any value type argument is lost // Type delegateType = SLE.Expression.GetDelegateType (types); return SLE.Expression.MakeDynamic (delegateType, binder, args_expr); }
public Invocation (Compiler.Expression expr, Compiler.Arguments arguments, CSharpInvokeMemberBinder invokeBinder) : base (expr, arguments) { this.invokeBinder = invokeBinder; }
public RuntimeBinderContext (DynamicContext ctx, Compiler.TypeSpec callingType) { this.ctx = ctx; this.module = ctx.Module; this.callingTypeImported = callingType; }
public Compiler.ExtensionMethodCandidates LookupExtensionMethod (Compiler.TypeSpec extensionType, string name, int arity) { // No extension method lookup in this context return null; }
public RuntimeBinderContext (Compiler.CompilerContext ctx) { this.ctx = ctx; }
protected override Compiler.Expression DoResolve (Compiler.ResolveContext rc) { type = expr.Type; eclass = Compiler.ExprClass.Value; return this; }
public RuntimeBinderContext (DynamicContext ctx, Compiler.TypeSpec currentType) { this.ctx = ctx.CompilerContext; this.currentType = currentType; }
public static void InitializeCompiler (Compiler.CompilerContext ctx) { if (TypeImporter.Predefined == null) return; lock (compiler_initializer) { if (TypeImporter.Predefined == null) return; // I don't think dynamically loaded assemblies can be used as dynamic // expression without static type to be loaded first // AppDomain.CurrentDomain.AssemblyLoad += (sender, e) => { throw new NotImplementedException (); }; // Import all currently loaded assemblies 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, TypeImporter.Predefined); TypeImporter.Predefined = null; Compiler.TypeManager.InitOptionalCoreTypes (ctx); } }
private DynamicContext (Compiler.CompilerContext cc) { this.cc = cc; }
public Compiler.ExtensionMethodGroupExpr LookupExtensionMethod (Compiler.TypeSpec extensionType, string name, int arity, Mono.CSharp.Location loc) { // No extension method lookup in this context return null; }
static void InitializeCompiler (Compiler.CompilerContext ctx) { if (compiler_initialized) return; lock (compiler_initializer) { if (compiler_initialized) return; // TODO: This smells like pretty big issue // AppDomain.CurrentDomain.AssemblyLoad += (sender, e) => { throw new NotImplementedException (); }; // Add all currently loaded assemblies foreach (System.Reflection.Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) Compiler.GlobalRootNamespace.Instance.AddAssemblyReference (a); Compiler.TypeManager.InitCoreTypes (ctx); Compiler.TypeManager.InitOptionalCoreTypes (ctx); compiler_initialized = true; } }
protected override Compiler.Expression DoResolveDynamic (Compiler.ResolveContext ec, Compiler.Expression memberExpr) { return new RuntimeDynamicInvocation (this, memberExpr).Resolve (ec); }
public RuntimeDynamicInvocation (Invocation invoke, Compiler.Expression memberExpr) : base (memberExpr) { this.invoke = invoke; }
public IList<Compiler.MethodSpec> LookupExtensionMethod (Compiler.TypeSpec extensionType, string name, int arity, ref Compiler.NamespaceEntry scope) { // No extension method lookup in this context return null; }
private DynamicContext (Compiler.ModuleContainer module, Compiler.ReflectionImporter importer) { this.module = module; this.importer = importer; }
public override void Print (Compiler.AbstractMessage msg) { throw new RuntimeBinderException (msg.Text); }