コード例 #1
0
        private static void parseLocalVariable(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsDeclarationStatement declarationStatement = (CsDeclarationStatement)pStatement;

            CsLocalVariableDeclaration localVariableDeclaration = declarationStatement.declaration as CsLocalVariableDeclaration;

            if (localVariableDeclaration == null)
            {
                parseLocalConstantDeclaration(pStatement, pSb, pCreator);
                return;
            }

            foreach (var declarator in localVariableDeclaration.declarators)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat("var {0}:{1}",
                                declarator.identifier.identifier,
                                As3Helpers.Convert(Helpers.GetType(localVariableDeclaration.type))
                                );

                if (declarator.initializer == null)
                {
                    sb.Append(";");
                }
                else
                {
                    sb.AppendFormat(" = {0};", parseNode(declarator.initializer, pCreator));
                }

                pSb.Append(sb.ToString());
                pSb.AppendLine();
            }
        }
コード例 #2
0
        private static void parseUsingStatement(CsStatement pArg1, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsUsingStatement           statement   = (CsUsingStatement)pArg1;
            CsLocalVariableDeclaration declaration = statement.resource as CsLocalVariableDeclaration;

            string varname;

            if (declaration == null)
            {
                varname = "$$using$$";
                Expression e = pCreator.Parse(statement.resource);

                pSb.AppendFormat("var {0}:{1} = {2};",
                                 varname,
                                 As3Helpers.Convert(Helpers.GetType(e.Type)),
                                 e.Value
                                 );

                pSb.AppendLine();
            }
            else
            {
                CsLocalVariableDeclarator declarator = declaration.declarators.First.Value;
                StringBuilder             sb         = new StringBuilder();

                sb.AppendFormat("var {0}:{1}",
                                declarator.identifier.identifier,
                                As3Helpers.Convert(Helpers.GetType(declaration.type))
                                );

                varname = declarator.identifier.identifier;

                if (declarator.initializer == null)
                {
                    sb.Append(";");
                }
                else
                {
                    sb.AppendFormat(" = {0};", parseNode(declarator.initializer, pCreator));
                }

                pSb.Append(sb.ToString());
                pSb.AppendLine();
            }

            pSb.Append("try {");
            pSb.AppendLine();

            ParseNode(statement.statement, pSb, pCreator);

            pSb.Append("} finally {");
            pSb.AppendLine();
            pSb.AppendFormat("	if ({0} != null) {0}.Dispose();", varname);
            pSb.AppendLine();

            pSb.Append("}");
            pSb.AppendLine();
            pSb.AppendLine();
        }
コード例 #3
0
        public static bool GetRealName(object pExpression, string pName, out string pRealName)
        {
            if (pExpression == null)
            {
                pRealName = pName;
                return(false);
            }

            CsEntityClass csEntityClass = pExpression as CsEntityClass;

            if (csEntityClass != null)
            {
                return(getRealName(csEntityClass.attributes, pName, out pRealName));
            }

            CsEntityEnum csEntityEnum = pExpression as CsEntityEnum;

            if (csEntityEnum != null)
            {
                return(getRealName(csEntityEnum.attributes, pName, out pRealName));
            }

            CsEntityStruct csEntityStruct = pExpression as CsEntityStruct;

            if (csEntityStruct != null)
            {
                return(getRealName(csEntityStruct.attributes, pName, out pRealName));
            }

            CsEntityInterface csEntityInterface = pExpression as CsEntityInterface;

            if (csEntityInterface != null)
            {
                return(getRealName(csEntityInterface.attributes, pName, out pRealName));
            }

            CsPrimaryExpressionMemberAccess csPrimaryExpressionMemberAccess = pExpression as CsPrimaryExpressionMemberAccess;

            if (csPrimaryExpressionMemberAccess != null)
            {
                return(GetRealName(csPrimaryExpressionMemberAccess.expression.entity, pName, out pRealName));
            }

            CsEntityLocalVariable csEntityLocalVariable = pExpression as CsEntityLocalVariable;

            if (csEntityLocalVariable != null)
            {
                CsLocalVariableDeclaration v = (csEntityLocalVariable.decl.parent) as CsLocalVariableDeclaration;
                if (v != null)
                {
                    GetRealName(v.type.entity_typeref.u, pName, out pRealName);
                    //get new name but do not replace expression, as this is a local accessor...
                    return(false);
                }
            }

            CsEntityVariable csEntityVariable = pExpression as CsEntityVariable;

            if (csEntityVariable != null)
            {
                return(GetRealName(csEntityVariable.type.u, pName, out pRealName));
            }

            CsEntityConstant csEntityConstant = pExpression as CsEntityConstant;

            if (csEntityConstant != null)
            {
                return(GetRealName(csEntityConstant.type.u, pName, out pRealName));
            }

            CsEntityMethod csEntityMethod = pExpression as CsEntityMethod;

            if (csEntityMethod != null)
            {
                return(GetRealName(csEntityMethod.parent, pName, out pRealName));
            }

            CsSimpleName csSimpleName = pExpression as CsSimpleName;

            if (csSimpleName != null)
            {
                return(GetRealName(csSimpleName.entity_typeref == null ? csSimpleName.entity : csSimpleName.entity_typeref.u,
                                   pName,
                                   out pRealName));
            }

            CsPredefinedTypeMemberAccess csPredefinedTypeMemberAccess = pExpression as CsPredefinedTypeMemberAccess;

            if (csPredefinedTypeMemberAccess != null)
            {
                return
                    (GetRealName(
                         csPredefinedTypeMemberAccess.entity_typeref == null
                                                        ? csPredefinedTypeMemberAccess.entity
                                                        : csPredefinedTypeMemberAccess.entity_typeref.u,
                         pName,
                         out pRealName));
            }

            CsEntityInstanceSpecifier csEntityInstanceSpecifier = pExpression as CsEntityInstanceSpecifier;

            if (csEntityInstanceSpecifier != null)
            {
                return(GetRealName(csEntityInstanceSpecifier.type.u, pName, out pRealName));
            }


            pRealName = pName;
            return(false);

            //CsEntityDelegate csEntityDelegate = pExpression as CsEntityDelegate;
            //if (csEntityDelegate != null) {
            //    pRealName = pName;
            //    return false;
            //}

            //throw new NotImplementedException();
        }
コード例 #4
0
        private static void parseForStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsForStatement forStatement = (CsForStatement)pStatement;

            StringBuilder sb = new StringBuilder("for (");

            CsLocalVariableDeclaration localVariableDeclaration = forStatement.initializer as CsLocalVariableDeclaration;
            CsStatementExpressionList  expressionList;

            if (localVariableDeclaration == null)
            {
                expressionList = forStatement.initializer as CsStatementExpressionList;
                foreach (CsExpression expression in expressionList.expressions)
                {
                    Expression ex = pCreator.Parse(expression);
                    sb.Append(ex.Value);
                    sb.Append(", ");
                }

                sb.Remove(sb.Length - 2, 2);
                sb.Append("; ");
            }
            else if (localVariableDeclaration.declarators.Count > 0)
            {
                sb.Append("var ");
                int count = localVariableDeclaration.declarators.Count;
                int now   = 0;

                foreach (CsLocalVariableDeclarator declarator in localVariableDeclaration.declarators)
                {
                    sb.AppendFormat("{0}:{1}",
                                    declarator.identifier.identifier,
                                    As3Helpers.Convert(Helpers.GetType(localVariableDeclaration.type))
                                    );

                    now++;

                    if (declarator.initializer != null)
                    {
                        sb.AppendFormat(" = {0}", parseNode(declarator.initializer, pCreator));
                    }

                    if (now < count)
                    {
                        sb.Append(", ");
                    }
                }

                sb.Append("; ");
            }

            sb.Append(pCreator.Parse(forStatement.condition).Value);
            sb.Append("; ");

            expressionList = (CsStatementExpressionList)forStatement.iterator;

            if (expressionList != null)
            {
                foreach (CsExpression expression in expressionList.expressions)
                {
                    Expression ex = pCreator.Parse(expression);
                    sb.Append(ex.Value);
                    sb.Append(", ");
                }

                sb.Remove(sb.Length - 2, 2);
            }

            sb.Append("){");
            pSb.AppendLine(sb.ToString());
            ParseNode(forStatement.statement, pSb, pCreator);
            pSb.AppendLine("}");
            pSb.AppendLine();
        }