public CannotBeInvokedException(RelinqScriptExpression root, InvokeExpression ie, RelinqScriptType typeOfTarget) : base(JSToCSharpExceptionType.CannotBeInvoked, root, ie) { InferredTypeOfTarget = typeOfTarget; }
private void InferInvoke(InvokeExpression ie, TypeInferenceCache cache) { InferTypes(ie.Target, cache); var typeofTarget = cache[ie.Target]; if (typeofTarget is ClrType) { var preview = cache.Clone(); ie.Args.ForEach(arg => InferTypes(arg, preview)); var types = ie.Args.Select(arg => preview[arg]); if (types.Any(type => type is Variant)) { cache.Add(ie, new Variant()); cache.Upgrade(preview); } else { var clrType = ((ClrType)typeofTarget).Type; if (clrType.IsDelegate()) { var sig = clrType.GetFunctionSignature(); InferMethodGroup(new MethodGroup(sig.AsArray(), clrType.Name), ie, cache); } else { throw new CannotBeInvokedException(Root, ie, typeofTarget); } } } else if (typeofTarget is MethodGroup) { InferMethodGroup((MethodGroup)typeofTarget, ie, cache); } else if (typeofTarget is Variant) { cache.Add(ie, new Variant()); } else { throw new CannotBeInvokedException(Root, ie, typeofTarget); } }
private LinqExpression CompileInvoke(InvokeExpression ie, CompilationContext ctx) { var typeofTarget = ctx.Types[ie.Target]; if (typeofTarget is ClrType) { var clrType = ((ClrType)typeofTarget).Type; if (clrType.IsDelegate()) { // not checking for a void-returning signature return LinqExpression.Invoke( Compile(ie.Target, ctx), CompileCallArguments(ctx.Invocations[ie], ie.Args, ctx)); } else { throw new CSharpBuilderException( JSToCSharpExceptionType.UnexpectedInferredAst, Ast, ie, ctx); } } else if (typeofTarget is MethodGroup) { var target = ie.Target as MemberAccessExpression; if (target == null) { throw new CSharpBuilderException( JSToCSharpExceptionType.UnexpectedInferredAst, Ast, ie, ctx); } var invocation = ctx.Invocations[ie]; if (!invocation.Signature.IsExtension()) { // not checking for a void-returning signature return LinqExpression.Call( Compile(target.Target, ctx), invocation.Signature, CompileCallArguments(invocation, ie.Args, ctx)); } else { // not checking for a void-returning signature var callArguments = target.Target.AsArray().Concat(ie.Args); return LinqExpression.Call( invocation.Signature, CompileCallArguments(invocation, callArguments, ctx).ToArray()); } } else { throw new CSharpBuilderException( JSToCSharpExceptionType.UnexpectedInferredAst, Ast, ie, ctx); } }