示例#1
0
 public bool ConvertMethodExp(IConverter Converter, Metadata.DB_Type type, Metadata.Expression.MethodExp me, out string exp_string)
 {
     if (type.name == "Object")
     {
         if (me.Name == "ToString")
         {
             exp_string = string.Format("Object::ToString({1})", Converter.ExpressionToString(me.Caller));
             return(true);
         }
     }
     exp_string = "";
     return(false);
 }
示例#2
0
        //static string ExpressionToString(Metadata.DB_InitializerExpressionSyntax es)
        //{
        //    StringBuilder ExpSB = new StringBuilder();
        //    if(es.Expressions.Count>0)
        //    {
        //        ExpSB.Append("(");
        //    }

        //    for(int i=0;i<es.Expressions.Count;i++)
        //    {
        //        ExpSB.Append(ExpressionToString(es.Expressions[i]));
        //        if (i < es.Expressions.Count - 2)
        //            ExpSB.Append(",");
        //    }

        //    if (es.Expressions.Count > 0)
        //    {
        //        ExpSB.Append(")");
        //    }

        //    return ExpSB.ToString();
        //}
        string ExpressionToString(Metadata.Expression.MethodExp es)
        {
            ITypeConverter tc = Converter.GetTypeConverter(Model.currentType);

            if (tc != null)
            {
                string content;
                if (tc.ConvertMethodExp(Converter, Model.currentType, es, out content))
                {
                    return(content);
                }
            }

            StringBuilder stringBuilder = new StringBuilder();

            //stringBuilder.Append(ExpressionToString(es.Caller));

            //Metadata.DB_Type caller_type = null;

            //if (es.Caller is Metadata.Expression.IndifierExp)
            //{
            //    Metadata.Expression.IndifierExp ie = es.Caller as Metadata.Expression.IndifierExp;
            //    Metadata.Model.IndifierInfo ii = Model.GetIndifierInfo(ie.Name);
            //    caller_type = ii.type;
            //    if (ii.is_namespace || ii.is_type)
            //    {
            //        stringBuilder.Append("::");
            //    }
            //    else if (caller_type.is_class)
            //    {
            //        stringBuilder.Append("->");
            //    }
            //    else
            //    {
            //        stringBuilder.Append(".");
            //    }
            //}
            //else if (es.Caller is Metadata.Expression.BaseExp)
            //{
            //    stringBuilder.Append("::");
            //    caller_type = Model.GetExpType(es.Caller);
            //}
            //else if(es.Caller is Metadata.Expression.ThisExp)
            //{
            //    stringBuilder.Append("->");
            //    caller_type = Model.GetExpType(es.Caller);
            //}
            //else
            //{
            //    caller_type = Model.GetExpType(es.Caller);
            //    if (caller_type.is_class)
            //    {
            //        stringBuilder.Append("->");
            //    }
            //    else
            //    {
            //        stringBuilder.Append(".");
            //    }
            //}

            //List<Metadata.DB_Type> args = new List<Metadata.DB_Type>();
            //for (int i = 0; i < es.Args.Count; i++)
            //{
            //    args.Add(Model.GetExpType(es.Args[i]));
            //}

            //Metadata.DB_Member method = caller_type.FindMethod(es.Name, args, Model);

            //stringBuilder.Append(es.Name);
            //stringBuilder.Append("(");
            //if (es.Args != null)
            //{
            //    for (int i = 0; i < es.Args.Count; i++)
            //    {
            //        Metadata.DB_Type arg_type = args[i];
            //        if (es.Args[i] is Metadata.Expression.ThisExp)
            //        {
            //            if(arg_type.is_value_type)
            //            {
            //                stringBuilder.Append("*");
            //            }
            //        }
            //        stringBuilder.Append(ExpressionToString(es.Args[i]));

            //        if (i < es.Args.Count - 2)
            //            stringBuilder.Append(",");
            //    }
            //}
            //stringBuilder.Append(")");

            return(stringBuilder.ToString());
        }