Esempio n. 1
0
        public TypeInferenceContext(RelinqScriptExpression root, 
            TypeInferenceCache inferences, IntegrationContext integration)
        {
            Root = root;

            // ctx.Root might only be one of the following:
            // * Invoke expression (for both cases of compile-time and late-bound invocation)
            // * Indexer or Operator expression
            // * Root of an entire AST
            if (Root.Parent != null && !Root.IsCall())
            {
                throw new NotSupportedException(root.ToString());
            }

            Inferences = inferences;
            Integration = integration;
        }
Esempio n. 2
0
        private void AfterCall(Guid id, RelinqScriptExpression e, TypeInferenceCache cache)
        {
            var startedEntry = History.Single(entry2 => entry2.Id == id);
            var finishedEntry = new TypeInferenceHistoryEntry(startedEntry);

            finishedEntry.InferredType = cache.ContainsKey(e) ? cache[e] : null;

            if (e.IsCall())
            {
                RelinqScriptExpression invtarget = null;
                if (e is InvokeExpression)
                {
                    invtarget = e.Children.ElementAt(0);
                }
                else if (e is IndexerExpression || e is OperatorExpression)
                {
                    invtarget = e;
                }

                if (invtarget != null && cache.Invocations.ContainsKey(invtarget))
                {
                    finishedEntry.InferredInvocation = cache.Invocations[invtarget];
                }
            }

            History.Add(finishedEntry);
            if (History.Count % 20000 == 0) DumpHistory();
        }
        private LinqExpression Compile(RelinqScriptExpression e, CompilationContext ctx)
        {
            try
            {
                if (!ctx.Types.ContainsKey(e))
                {
                    throw new CSharpBuilderException(
                        JSToCSharpExceptionType.UnexpectedInferredAst, Ast, e, ctx);
                }

                if (!(ctx.Types[e] is ClrType || ctx.Types[e] is Null ||
                      ctx.Types[e] is UnknownConstant || ctx.Types[e] is Lambda))
                {
                    throw new CSharpBuilderException(
                        JSToCSharpExceptionType.UnexpectedInferredAst, Ast, e, ctx);
                }

                if (e.IsCall() && !ctx.Invocations.ContainsKey(e))
                {
                    throw new CSharpBuilderException(
                        JSToCSharpExceptionType.UnexpectedInferredAst, Ast, e, ctx);
                }

                if (e is LambdaExpression && !(ctx.Types[e] is Lambda))
                {
                    throw new CSharpBuilderException(
                        JSToCSharpExceptionType.UnexpectedInferredAst, Ast, e, ctx);
                }

                switch (e.NodeType)
                {
                    case ExpressionType.Keyword:
                        return CompileKeyword((KeywordExpression)e, ctx);

                    case ExpressionType.Variable:
                        return CompileVariable((VariableExpression)e, ctx);

                    case ExpressionType.Constant:
                        return CompileConstant((ConstantExpression)e, ctx);

                    case ExpressionType.New:
                        return CompileNew((NewExpression)e, ctx);

                    case ExpressionType.Lambda:
                        return CompileLambda((LambdaExpression)e, ctx);

                    case ExpressionType.MemberAccess:
                        return CompileMemberAccess((MemberAccessExpression)e, ctx);

                    case ExpressionType.Invoke:
                        return CompileInvoke((InvokeExpression)e, ctx);

                    case ExpressionType.Indexer:
                        return CompileIndexer((IndexerExpression)e, ctx);

                    case ExpressionType.Operator:
                        return CompileOperator((OperatorExpression)e, ctx);

                    case ExpressionType.Conditional:
                        return CompileConditional((ConditionalExpression)e, ctx);
                }
            }
            catch (CSharpBuilderException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new CSharpBuilderException(
                    JSToCSharpExceptionType.Unexpected, Ast, e, ctx, ex);
            }

            throw new NotSupportedException(e.ToString());
        }