public virtual DataType ProcessExpression(ExpressionAst expression)
        {
            Guard.Against.Null(expression, nameof(expression));

            if (expression is OperatorExpressionAst operatorExpression)
            {
                return(ProcessOperatorExpression(operatorExpression));
            }
            if (expression is AssignExpressionAst assignExpression)
            {
                return(ProcessAssignExpression(assignExpression));
            }
            if (expression is CallExpressionAst callExpression)
            {
                return(ProcessCallExpression(callExpression));
            }
            if (expression is LiteralExpressionAst literalExpression)
            {
                return(ProcessLiteralExpression(literalExpression));
            }
            if (expression is IdentExpressionAst identExpression)
            {
                return(ProcessIdentExpression(identExpression));
            }
            if (expression is GroupExpressionAst groupExpression)
            {
                return(ProcessGroupExpression(groupExpression));
            }

            throw new ArgumentException("Unknown expression type" + expression.GetType(), nameof(expression));
        }
Esempio n. 2
0
    public ExpressionAst _VisitExpression(ExpressionAst expressionAst)
    {
        //Console.WriteLine("Visiting expression type {0}", expressionAst.GetType().FullName);
        var @switch = new Dictionary <Type, Func <ExpressionAst, ExpressionAst> > {
            { typeof(ArrayExpressionAst), (e) => { return((ExpressionAst)VisitArrayExpression(e as ArrayExpressionAst)); } },
            { typeof(ArrayLiteralAst), (e) => { return((ExpressionAst)VisitArrayLiteral(e as ArrayLiteralAst)); } },
            { typeof(AttributedExpressionAst), (e) => { return((ExpressionAst)VisitAttributedExpression(e as AttributedExpressionAst)); } },
            //AttributedExpressionAst
            { typeof(ConvertExpressionAst), (e) => { return((ExpressionAst)VisitConvertExpression(e as ConvertExpressionAst)); } },
            { typeof(BinaryExpressionAst), (e) => { return((ExpressionAst)VisitBinaryExpression(e as BinaryExpressionAst)); } },
            { typeof(ConstantExpressionAst), (e) => { return((ExpressionAst)VisitConstantExpression(e as ConstantExpressionAst)); } },
            //ConstantExpressionAst
            { typeof(StringConstantExpressionAst), (e) => { return((ExpressionAst)VisitStringConstantExpression(e as StringConstantExpressionAst)); } },
            { typeof(ErrorExpressionAst), (e) => { return((ExpressionAst)VisitErrorExpression(e as ErrorExpressionAst)); } },
            { typeof(ExpandableStringExpressionAst), (e) => { return((ExpressionAst)VisitExpandableStringExpression(e as ExpandableStringExpressionAst)); } },
            { typeof(HashtableAst), (e) => { return((ExpressionAst)VisitHashtable(e as HashtableAst)); } },
            { typeof(IndexExpressionAst), (e) => { return((ExpressionAst)VisitIndexExpression(e as IndexExpressionAst)); } },
            { typeof(MemberExpressionAst), (e) => { return((ExpressionAst)VisitMemberExpression(e as MemberExpressionAst)); } },
            //MemberExpressionAst
            { typeof(InvokeMemberExpressionAst), (e) => { return((ExpressionAst)VisitInvokeMemberExpression(e as InvokeMemberExpressionAst)); } },
            { typeof(ParenExpressionAst), (e) => { return((ExpressionAst)VisitParenExpression(e as ParenExpressionAst)); } },
            { typeof(ScriptBlockExpressionAst), (e) => { return((ExpressionAst)VisitScriptBlockExpression(e as ScriptBlockExpressionAst)); } },
            { typeof(SubExpressionAst), (e) => { return((ExpressionAst)VisitSubExpression(e as SubExpressionAst)); } },
            { typeof(TypeExpressionAst), (e) => { return((ExpressionAst)VisitTypeExpression(e as TypeExpressionAst)); } },
            { typeof(UnaryExpressionAst), (e) => { return((ExpressionAst)VisitUnaryExpression(e as UnaryExpressionAst)); } },
            { typeof(UsingExpressionAst), (e) => { return((ExpressionAst)VisitUsingExpression(e as UsingExpressionAst)); } },
            { typeof(VariableExpressionAst), (e) => { return((ExpressionAst)VisitVariableExpression(e as VariableExpressionAst)); } }
        };

        if (expressionAst != null && @switch.ContainsKey(expressionAst.GetType()))
        {
            return(@switch[expressionAst.GetType()](expressionAst));
        }
        else
        {
            //Console.WriteLine("_VisitExpression may not know how to visit type {0}", expressionAst.GetType().FullName);
            return(null);
        }
    }
Esempio n. 3
0
        internal static SettableExpression Create(ExpressionAst valueExpression, ExecutionVisitor currentExecution)
        {
            if (valueExpression is VariableExpressionAst)
            {
                return(new SettableVariableExpression((VariableExpressionAst)valueExpression, currentExecution));
            }
            else if (valueExpression is MemberExpressionAst)
            {
                return(new SettableMemberExpression((MemberExpressionAst)valueExpression, currentExecution));
            }
            else if (valueExpression is IndexExpressionAst)
            {
                return(new SettableIndexExpression((IndexExpressionAst)valueExpression, currentExecution));
            }
            var msg = String.Format("The expression is not a modifiable value, but of type '{0}'. Please report this!",
                                    valueExpression.GetType().FullName);

            throw new InvalidOperationException(msg);
        }
Esempio n. 4
0
 private ExpressionAst CreateLoggingExpression(ExpressionAst source)
 {
     return(CreateLoggingExpressionImpl(CreateEvaluation(source), source.Extent, source.GetType()));
 }