Example #1
0
 public MethodCall(int line, int col, Expression obj, string name, Expression[] args)
     : base(line, col)
 {
     this.name = name;
     this.args = args;
     this.obj = obj;
 }
Example #2
0
 public BinaryExpression(int line, int col, Expression lhs, TokenKind op, Expression rhs)
     : base(line, col)
 {
     this.lhs = lhs;
     this.rhs = rhs;
     this.op = op;
 }
Example #3
0
 public FieldAccess(int line, int col, Expression exp, string field)
     : base(line, col)
 {
     this.exp = exp;
     this.field = field;
 }
Example #4
0
 protected void ProcessExpression(Expression exp)
 {
     object value = EvalExpression(exp);
     WriteValue(value);
 }
Example #5
0
        protected object[] EvalArguments(Expression[] args)
        {
            object[] values = new object[args.Length];
            for (int i = 0; i < values.Length; i++)
                values[i] = EvalExpression(args[i]);

            return values;
        }
Example #6
0
        /// <summary>
        /// evaluates expression.
        /// This method is used by TemplateManager extensibility.
        /// </summary>
        public object EvalExpression(Expression exp)
        {
            currentExpression = exp;

            try
            {

                if (exp is StringLiteral)
                    return ((StringLiteral)exp).Content;
                else if (exp is Name)
                {
                    return GetValue(((Name)exp).Id);
                }
                else if (exp is FieldAccess)
                {
                    FieldAccess fa = (FieldAccess)exp;
                    object obj = EvalExpression(fa.Exp);
                    string propertyName = fa.Field;
                    return EvalProperty(obj, propertyName);
                }
                else if (exp is MethodCall)
                {
                    MethodCall ma = (MethodCall)exp;
                    object obj = EvalExpression(ma.CallObject);
                    string methodName = ma.Name;

                    return EvalMethodCall(obj, methodName, EvalArguments(ma.Args));
                }
                else if (exp is IntLiteral)
                    return ((IntLiteral)exp).Value;
                else if (exp is DoubleLiteral)
                    return ((DoubleLiteral)exp).Value;
                else if (exp is FCall)
                {
                    FCall fcall = (FCall)exp;
                    if (!functions.ContainsKey(fcall.Name))
                    {
                        string msg = string.Format("函数 '{0}' 未定义.", fcall.Name);
                        throw new TemplateRuntimeException(msg, exp.Line, exp.Col);
                    }

                    TemplateFunction func = functions[fcall.Name];
                    object[] values = EvalArguments(fcall.Args);

                    return func(values);
                }
                else if (exp is StringExpression)
                {
                    StringExpression stringExp = (StringExpression)exp;
                    StringBuilder sb = new StringBuilder();
                    foreach (Expression ex in stringExp.Expressions)
                        sb.Append(EvalExpression(ex));

                    return sb.ToString();
                }
                else if (exp is BinaryExpression)
                    return EvalBinaryExpression(exp as BinaryExpression);
                else if (exp is ArrayAccess)
                    return EvalArrayAccess(exp as ArrayAccess);
                else
                    throw new TemplateRuntimeException("Invalid expression type: " + exp.GetType().Name, exp.Line, exp.Col);

            }
            catch (TemplateRuntimeException ex)
            {
                DisplayError(ex);
                return null;
            }
            catch (Exception ex)
            {
                DisplayError(new TemplateRuntimeException(ex.Message, currentExpression.Line, currentExpression.Col));
                return null;
            }
        }
Example #7
0
 public void Add(Expression exp)
 {
     exps.Add(exp);
 }
Example #8
0
 public TagAttribute(string name, Expression expression)
 {
     this.name = name;
     this.expression = expression;
 }
Example #9
0
 public ArrayAccess(int line, int col, Expression exp, Expression index)
     : base(line, col)
 {
     this.exp = exp;
     this.index = index;
 }
Example #10
0
 public FCall(int line, int col, string name, Expression[] args)
     : base(line, col)
 {
     this.name = name;
     this.args = args;
 }