Exemple #1
0
 private AbstractSyntaxComponent simplifyStatement(CallData data)
 {
     if (!data.HaveParam())
     {
         //没有参数的调用退化为基本值数据
         if (data.IsHighOrder)
         {
             //这种情况应该不会出现
             return(data);
         }
         else
         {
             data.Name.CopyComments(data);
             return(data.Name);
         }
     }
     else if (data.GetId() == "-" && data.GetParamNum() == 1)
     {
         ISyntaxComponent val  = data.GetParam(0);
         ValueData        temp = val as ValueData;
         if (null != temp && temp.IsNumber())
         {
             ValueData ret = new ValueData("-" + temp.GetId(), ValueData.NUM_TOKEN);
             ret.CopyComments(temp);
             ret.CopyComments(data);
             return(ret);
         }
         else
         {
             simplifyCallData(data);
             return(data);
         }
     }
     else if (data.GetId() == "+" && data.GetParamNum() == 1)
     {
         ISyntaxComponent val  = data.GetParam(0);
         ValueData        temp = val as ValueData;
         if (null != temp && temp.IsNumber())
         {
             ValueData ret = new ValueData(temp.GetId(), ValueData.NUM_TOKEN);
             ret.CopyComments(temp);
             ret.CopyComments(data);
             return(ret);
         }
         else
         {
             simplifyCallData(data);
             return(data);
         }
     }
     else
     {
         //有参数不会退化,对各参数进行化简
         simplifyCallData(data);
         return(data);
     }
 }
Exemple #2
0
 private AbstractSyntaxComponent simplifyStatement(FunctionData data)
 {
     //注意,为了省内存ValueData上不附带注释了,相关接口无实际效果!!!
     if (!data.HaveParamOrStatement())
     {
         //没有参数的调用退化为基本值数据
         if (data.IsHighOrder)
         {
             //这种情况应该不会出现
             return(data);
         }
         else
         {
             return(data.Name);
         }
     }
     else if (data.GetId() == "-" && data.GetParamNum() == 1)
     {
         ISyntaxComponent val  = data.GetParam(0);
         ValueData        temp = val as ValueData;
         if (null != temp && temp.IsNumber())
         {
             ValueData ret = new ValueData("-" + temp.GetId(), ValueData.NUM_TOKEN);
             return(ret);
         }
         else
         {
             return(data);
         }
     }
     else if (data.GetId() == "+" && data.GetParamNum() == 1)
     {
         ISyntaxComponent val  = data.GetParam(0);
         ValueData        temp = val as ValueData;
         if (null != temp && temp.IsNumber())
         {
             ValueData ret = new ValueData(temp.GetId(), ValueData.NUM_TOKEN);
             return(ret);
         }
         else
         {
             return(data);
         }
     }
     else
     {
         return(data);
     }
 }
        protected override bool Load(ValueData valData)
        {
            string id     = valData.GetId();
            int    idType = valData.GetIdType();

            if (idType == Dsl.ValueData.NUM_TOKEN)
            {
                if (id.StartsWith("0x"))
                {
                    long v = long.Parse(id.Substring(2), System.Globalization.NumberStyles.HexNumber);
                    if (v >= int.MinValue && v <= int.MaxValue)
                    {
                        m_Val = (int)v;
                    }
                    else
                    {
                        m_Val = v;
                    }
                }
                else if (id.IndexOf('.') < 0)
                {
                    long v = long.Parse(id);
                    if (v >= int.MinValue && v <= int.MaxValue)
                    {
                        m_Val = (int)v;
                    }
                    else
                    {
                        m_Val = v;
                    }
                }
                else
                {
                    double v = double.Parse(id);
                    if (v >= float.MinValue && v <= float.MaxValue)
                    {
                        m_Val = (float)v;
                    }
                    else
                    {
                        m_Val = v;
                    }
                }
            }
            else
            {
                if (idType == Dsl.ValueData.ID_TOKEN)
                {
                    if (id == "true")
                    {
                        m_Val = true;
                    }
                    else if (id == "false")
                    {
                        m_Val = false;
                    }
                    else
                    {
                        m_Val = id;
                    }
                }
                else
                {
                    m_Val = id;
                }
            }
            return(true);
        }