コード例 #1
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsLambdaExpression ex = (CsLambdaExpression)pStatement;

            LambdaMethodExpression lambda = new LambdaMethodExpression((CsLambdaExpression)pStatement, pCreator);

            CodeBuilder b = new CodeBuilder();

            b.AppendFormat("function ({0}):{1} {{",
                           As3Helpers.GetParameters(lambda.Arguments),
                           (lambda.ReturnType == null) ? "void" : As3Helpers.Convert(lambda.ReturnType)
                           );

            b.Indent();
            b.Indent();
            b.Indent();
            b.AppendLine();

            if (!(lambda.CodeBlock is CsBlock))
            {
                b.Append("return ");
            }

            BlockParser.ParseNode(lambda.CodeBlock, b, pCreator);

            b.AppendLine("}");
            b.AppendLine();
            b.Unindent();
            b.Unindent();
            b.Unindent();
            return(new Expression(b.ToString(), ex.entity_typeref));
        }
コード例 #2
0
ファイル: AsIsExpression.cs プロジェクト: kevinmiles/cstoas3
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsAsIsExpression ex = (CsAsIsExpression)pStatement;

            return(new Expression(
                       pCreator.Parse(ex.expression).Value
                       + " "
                       + As3Helpers.ConvertTokens(Helpers.GetTokenType(ex.oper)) + " " + As3Helpers.Convert(Helpers.GetType(ex.type)),
                       ex.entity_typeref
                       ));
        }
コード例 #3
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            //object-creation-expression:
            //"new" type "(" ( argument_list )? ")" object-or-collection-initializer?
            //"new" type object-or-collection-initializer

            //delegate-creation-expression:
            //"new" delegate-type "(" expression ")"
            CsNewObjectExpression node = (CsNewObjectExpression)pStatement;

            StringBuilder sb = new StringBuilder();

            string name     = As3Helpers.Convert(Helpers.GetType(node.type));
            bool   isVector = name.StartsWith("Vector.<", StringComparison.Ordinal) && node.initializer != null;
            bool   isArray  = name.Equals("Array", StringComparison.Ordinal) && node.initializer != null;

            if (!isArray)
            {
                sb.Append("(new ");
            }

            if (isVector || isArray)
            {
                if (isVector)
                {
                    int lb = name.IndexOf("<") + 1;
                    sb.AppendFormat("<{0}>", name.Substring(lb, name.IndexOf(">") - lb));
                }

                sb.Append("[");

                CsCollectionInitializer initializer = (CsCollectionInitializer)node.initializer;
                if (initializer.element_initializer_list != null)
                {
                    List <string> args = new List <string>();
                    foreach (var csNode in initializer.element_initializer_list)
                    {
                        args.Add(pCreator.Parse(csNode).Value);
                    }
                    sb.Append(String.Join(", ", args.ToArray()));
                }
            }
            else
            {
                sb.AppendFormat("{0}(", name);
                if (node.argument_list != null)
                {
                    List <string> args = new List <string>();
                    foreach (CsArgument argument in node.argument_list.list)
                    {
                        args.Add(pCreator.Parse(argument.expression).Value);
                    }

                    sb.Append(String.Join(", ", args.ToArray()));
                }
            }

            sb.Append(isVector || isArray ? "]" : ")");

            if (!isArray)
            {
                sb.Append(")");
            }

            return(new Expression(
                       sb.ToString(),
                       pStatement.entity_typeref
                       ));
        }