コード例 #1
0
        public virtual object Visit(ASTConstant node, object data)
        {
            object val = node.Value;

            this.FormatValue(val, this.sb);
            return(data);
        }
コード例 #2
0
        public object Visit(ASTConstant node, object data)
        {
            object item = node.Value;

            if (this._trapNaN && (((item is double) && double.IsNaN((double)item)) || ((item is float) && float.IsNaN((float)item))))
            {
                throw new EvaluationException("NaN constant value detected");
            }
            if (this._trapInfinity && (((item is double) && double.IsInfinity((double)item)) || ((item is float) && float.IsInfinity((float)item))))
            {
                throw new EvaluationException("Infinite constant value " + item.ToString() + "detected");
            }
            this.stack.Push(item);
            return(null);
        }
コード例 #3
0
        public override string ToString()
        {
            var ret = new StringBuilder();

            ret.AppendFormat("{0}{1}(", this.ILCode.ToOpCode().Name, this.Type == null ? "" : ":" + this.Type.Value);
            if (this.Operand != null)
            {
                if (this.Operand is string)
                {
                    ASTConstant.EscapeString(ret, (string)this.Operand, true);
                }
                else if (this.Operand is IBasicBlock)
                {
                    ret.AppendFormat("Block_{0:x2}", ((IBasicBlock)this.Operand).Id);
                }
                else if (this.Operand is IBasicBlock[])
                {
                    System.Collections.Generic.IEnumerable <string> targets = ((IBasicBlock[])this.Operand).Select(block => string.Format("Block_{0:x2}", block.Id));
                    ret.AppendFormat("[{0}]", string.Join(", ", targets));
                }
                else
                {
                    ret.Append(this.Operand);
                }
                if (this.Arguments.Length > 0)
                {
                    ret.Append(";");
                }
            }
            for (int i = 0; i < this.Arguments.Length; i++)
            {
                if (i != 0)
                {
                    ret.Append(",");
                }
                ret.Append(this.Arguments[i]);
            }
            ret.Append(")");
            return(ret.ToString());
        }
コード例 #4
0
        public override string ToString()
        {
            var ret = new StringBuilder();

            ret.AppendFormat("{0}{1}(", ILCode.ToOpCode().Name, Type == null ? "" : ":" + Type.Value);
            if (Operand != null)
            {
                if (Operand is string)
                {
                    ASTConstant.EscapeString(ret, (string)Operand, true);
                }
                else if (Operand is IBasicBlock)
                {
                    ret.AppendFormat("Block_{0:x2}", ((IBasicBlock)Operand).Id);
                }
                else if (Operand is IBasicBlock[])
                {
                    var targets = ((IBasicBlock[])Operand).Select(block => string.Format("Block_{0:x2}", block.Id));
                    ret.AppendFormat("[{0}]", string.Join(", ", targets));
                }
                else
                {
                    ret.Append(Operand);
                }
                if (Arguments.Length > 0)
                {
                    ret.Append(";");
                }
            }
            for (var i = 0; i < Arguments.Length; i++)
            {
                if (i != 0)
                {
                    ret.Append(",");
                }
                ret.Append(Arguments[i]);
            }
            ret.Append(")");
            return(ret.ToString());
        }
コード例 #5
0
 public ASTConstant BuildConstantNode(ASTConstant node)
 {
     return(this.BuildConstantNode(node.Value));
 }
コード例 #6
0
ファイル: RealEvaluator.cs プロジェクト: fabrimaciel/colosoft
 protected double VisitConstant(ASTConstant node)
 {
     return(FromObject(node.Value));
 }
コード例 #7
0
ファイル: VCIL.cs プロジェクト: SA-Root/VinewoodCC
 public static void InjectConstant(this QuadTuple qt, ASTConstant constant, int isRValue, ILIdentifier str = null)
 {
     if (constant is ASTStringConstant sc)
     {
         if (isRValue == 0)
         {
             qt.RValueA = str;
         }
         else if (isRValue == 1)
         {
             qt.RValueB = str;
         }
         else
         {
             qt.LValue = str;
         }
     }
     else if (constant is ASTIntegerConstant ic)
     {
         if (isRValue == 0)
         {
             qt.RValueA = new ILIdentifier(ic.Value.ToString(), ILNameType.Constant, "int");
         }
         else if (isRValue == 1)
         {
             qt.RValueB = new ILIdentifier(ic.Value.ToString(), ILNameType.Constant, "int");
         }
         else
         {
             qt.LValue = new ILIdentifier(ic.Value.ToString(), ILNameType.Constant, "int");
         }
     }
     else if (constant is ASTFloatConstant fp)
     {
         if (isRValue == 0)
         {
             qt.RValueA = new ILIdentifier(fp.Value.ToString(), ILNameType.Constant, "float");
         }
         else if (isRValue == 1)
         {
             qt.RValueB = new ILIdentifier(fp.Value.ToString(), ILNameType.Constant, "float");
         }
         else
         {
             qt.LValue = new ILIdentifier(fp.Value.ToString(), ILNameType.Constant, "float");
         }
     }
     else if (constant is ASTCharConstant cc)
     {
         if (isRValue == 0)
         {
             qt.RValueA = new ILIdentifier(cc.Value.ToString(), ILNameType.Constant, "char");
         }
         else if (isRValue == 1)
         {
             qt.RValueB = new ILIdentifier(cc.Value.ToString(), ILNameType.Constant, "char");
         }
         else
         {
             qt.LValue = new ILIdentifier(cc.Value.ToString(), ILNameType.Constant, "char");
         }
     }
 }