Beispiel #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;
        }
        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());
        }