Пример #1
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			CsBinaryExpression li = (CsBinaryExpression)pStatement;

			Expression left = pCreator.Parse(li.lhs);
			Expression right = pCreator.Parse(li.rhs);

			return new Expression(left.Value + " " + JsHelpers.ConvertTokens(Helpers.GetTokenType(li.oper)) + " " + right.Value, pStatement.entity_typeref);
		}
Пример #2
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsBinaryExpression li = (CsBinaryExpression)pStatement;

            Expression left  = pCreator.Parse(li.lhs);
            Expression right = pCreator.Parse(li.rhs);

            return(new Expression(left.Value + " " + As3Helpers.ConvertTokens(Helpers.GetTokenType(li.oper)) + " " + right.Value, pStatement.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
			);
		}
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			CsConditionalExpression ex = (CsConditionalExpression)pStatement;

			return new Expression(
				pCreator.Parse(ex.condition).Value + " ? " +
				pCreator.Parse(ex.true_expression).Value + " : " +
				pCreator.Parse(ex.false_expression).Value,

				pStatement.entity_typeref
			);
		}
Пример #5
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsConditionalExpression ex = (CsConditionalExpression)pStatement;

            return(new Expression(
                       pCreator.Parse(ex.condition).Value + " ? " +
                       pCreator.Parse(ex.true_expression).Value + " : " +
                       pCreator.Parse(ex.false_expression).Value,

                       pStatement.entity_typeref
                       ));
        }
Пример #6
0
        private static List <AttributeItem> getAttributeValue(CsAttribute pAttribute, string pAttrName, FactoryExpressionCreator pCreator)
        {
            string        s;
            AttributeItem item = new AttributeItem();

            if (pAttribute.attribute_name != null)
            {
                CsNamespaceOrTypeName n = (CsNamespaceOrTypeName)pAttribute.attribute_name;
                s = n.identifier.original_text;
            }
            else
            {
                throw new Exception();
                //s = attribute.type.parent.name;
            }

            if (s.Equals(pAttrName, StringComparison.Ordinal) || (s + "Attribute").Equals(pAttrName, StringComparison.Ordinal))
            {
                item.IsEmpty = false;
                foreach (var argument in pAttribute.positional_argument_list.list)
                {
                    item.Parameters.Add(((CsLiteral)argument).literal);
                }

                foreach (var argument in pAttribute.named_argument_list)
                {
                    item.NamedArguments.Add(argument.identifier.identifier, pCreator.Parse(argument.expression));
                }
            }

            return(new List <AttributeItem> {
                item
            });
        }
Пример #7
0
        private static void parseForeachStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsForeachStatement fes = (CsForeachStatement)pStatement;

            Expression ex   = pCreator.Parse(fes.expression);
            string     type = JsHelpers.Convert(Helpers.GetType(fes.type));

            pSb.AppendLine();

            _enumCount++;
            string enumName = String.Format(@"__ie{0}", _enumCount);

            pSb.AppendFormat("var {0}:IEnumerator = {1}.GetEnumerator();",
                             enumName, ex.Value);
            pSb.AppendLine();
            pSb.AppendFormat("while ({0}.MoveNext()){{", enumName);
            pSb.AppendLine();

            pSb.AppendFormat("\tvar {1}:{2} = {0}.get_Current() as {2};",
                             enumName,
                             fes.identifier.identifier,
                             type
                             );

            pSb.AppendLine();


            ParseNode(fes.statement, pSb, pCreator);
            pSb.AppendLine("}");
            pSb.AppendLine();
        }
Пример #8
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            //"(" expression ")"
            CsParenthesizedExpression ex = (CsParenthesizedExpression)pStatement;

            return(new Expression("(" + pCreator.Parse(ex.expression).Value + ")", pStatement.entity_typeref));
        }
Пример #9
0
        private static void parseExpressionStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            Expression ex = pCreator.Parse(((CsExpressionStatement)pStatement).expression);

            pSb.Append(ex.Value + ";");
            pSb.AppendLine();
        }
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			CsPostIncrementDecrementExpression ex = (CsPostIncrementDecrementExpression)pStatement;

			Expression exp = pCreator.Parse(ex.expression);
			if (exp.InternalType) {
				if (ex.expression is CsElementAccess) {
					string setter = ElementAccessHelper.parseElementAccess(ex.expression, true, true, pCreator).Value;

					switch (ex.oper) {
						case CsTokenType.tkINC:
							return new Expression(string.Format(setter, exp.Value + "++"), exp.Type);

						case CsTokenType.tkDEC:
							return new Expression(string.Format(setter, exp.Value + "--"), exp.Type);

						default:
							throw new Exception();
					}

				}
			}

			switch (ex.oper) {
				case CsTokenType.tkINC:
					return new Expression(exp.Value + "++", exp.Type);

				case CsTokenType.tkDEC:
					return new Expression(exp.Value + "--", exp.Type);

				default:
					throw new NotImplementedException();
			}
		}
Пример #11
0
        public static void ParseNode(CsNode pNode, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsBlock block = pNode as CsBlock;

            if (block != null)
            {
                Parse(block, pSb, pCreator);
                return;
            }

            CsStatement statement = pNode as CsStatement;

            if (statement != null)
            {
                pSb.Indent();
                parseStatement(statement, pSb, pCreator);
                pSb.Unindent();
                return;
            }

            CsExpression expression = pNode as CsExpression;

            if (expression != null)
            {
                Expression ex = pCreator.Parse(pNode as CsExpression);
                pSb.Append(ex.Value + ";");
                pSb.AppendLine();
                return;
            }

            throw new Exception();
        }
Пример #12
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();
        }
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			CsOperatorUnaryExpression ex = (CsOperatorUnaryExpression)pStatement;

			return new Expression(
				JsHelpers.ConvertTokens(Helpers.GetTokenType(ex.oper)) + pCreator.Parse(ex.unary_expression).Value,
				pStatement.entity_typeref
			);
		}
Пример #14
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            //expression "." identifier (type-argument-list?)
            CsPrimaryExpressionMemberAccess ex = (CsPrimaryExpressionMemberAccess)pStatement;
            string name;
            bool   renamed = Helpers.GetRealName(ex, ex.identifier.identifier, out name);

            if (renamed)
            {
                return(new Expression(name, pStatement.entity_typeref));
            }

            CsEntityProperty p          = ex.entity as CsEntityProperty;
            bool             isInternal = false;

            if (p != null && p.decl != null)
            {
                TheClass theClass = TheClassFactory.Get(p, pCreator);
                TheClass parent   = theClass;

                //Am I extending a standard flash class? Do not rename then...
                bool isStandardGetSet = false;
                while (parent.Base != null)
                {
                    isStandardGetSet |= parent.FullName.StartsWith("flash.");
                    parent            = parent.Base;
                }

                if (!isStandardGetSet)
                {
                    TheProperty theProperty = theClass.GetProperty((CsProperty)p.decl);
                    if (theProperty != null)
                    {
                        if (ex.parent is CsAssignmentExpression)
                        {
                            //setter
                            isInternal = true;
                            name       = "set_" + name + "({0})";
                        }
                        else
                        {
                            //getter, rename
                            name = "get_" + name + "()";
                        }
                    }
                }
            }
            else if (ex.ec == expression_classification.ec_event_access)                //remove eventhandler name
            {
                name = string.Empty;
            }

            return(new Expression(
                       pCreator.Parse(ex.expression).Value + "." + name,
                       pStatement.entity_typeref,
                       isInternal
                       ));
        }
Пример #15
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsOperatorUnaryExpression ex = (CsOperatorUnaryExpression)pStatement;

            return(new Expression(
                       As3Helpers.ConvertTokens(Helpers.GetTokenType(ex.oper)) + pCreator.Parse(ex.unary_expression).Value,
                       pStatement.entity_typeref
                       ));
        }
Пример #16
0
		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
			);
		}
Пример #17
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            //"new" non-array-type "[" expression-list "]" ( rank-specifiers )? ( array-initializer )?
            //"new" non-array-type? rank-specifiers array-initializer
            CsNewArrayExpression ex = (CsNewArrayExpression)pStatement;

            StringBuilder builder = new StringBuilder();

            if (ex.initializer != null)
            {
                builder.Append("[");
                //builder.AppendFormat("new <{0}>[", As3Helpers.Convert(Helpers.GetType(((CsEntityArraySpecifier)ex.entity_typeref.u).type)));


                if (ex.initializer.initializers != null)
                {
                    List <string> initializers = new List <string>();

                    foreach (CsNode node in ex.initializer.initializers)
                    {
                        Expression expression = pCreator.Parse(node as CsExpression);
                        initializers.Add(expression.Value);
                    }

                    if (initializers.Count != 0)
                    {
                        builder.Append(string.Join(", ", initializers.ToArray()));
                    }
                }

                builder.Append("]");
                //builder.Append("]");
            }
            else if (ex.expressions != null && ex.expressions.list != null && ex.expressions.list.Count == 1)
            {
                builder.Append("new Array(");
                Expression expression = pCreator.Parse(ex.expressions.list.First.Value);
                builder.Append(expression.Value);
                builder.Append(")");
            }

            return(new Expression(builder.ToString(), pStatement.entity_typeref));
        }
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			CsPreIncrementDecrementExpression ex = (CsPreIncrementDecrementExpression)pStatement;

			Expression exp = pCreator.Parse(ex.unary_expression);

			return new Expression(
				As3Helpers.ConvertTokens(Helpers.GetTokenType(ex.oper)) + exp.Value,
				pStatement.entity_typeref
			);
		}
Пример #19
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();
		}
Пример #20
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			CsCastUnaryExpression ex = (CsCastUnaryExpression)pStatement;
			
			//Do not cast anything. This is here just to support the automatic casting done by the flash player.
			return new Expression(
				//As3Helpers.Convert(Helpers.GetType(ex.type)) + "(" + 
				pCreator.Parse(ex.unary_expression).Value 
				//+ ")"
				, ex.type.entity_typeref
			);
		}
Пример #21
0
        private static void parseWhileStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsWhileStatement whileStatement = (CsWhileStatement)pStatement;

            pSb.AppendFormat("while ({0}){{", pCreator.Parse(whileStatement.condition));
            pSb.AppendLine();
            ParseNode(whileStatement.statement, pSb, pCreator);
            pSb.Append("}");
            pSb.AppendLine();
            pSb.AppendLine();
        }
Пример #22
0
        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
                       ));
        }
Пример #23
0
		internal static Expression parseElementAccess(CsExpression pStatement, bool pForce, bool pGetSetter, FactoryExpressionCreator pCreator) {
			//expression "[" expression-list "]"
			CsElementAccess stat = (CsElementAccess)pStatement;

			List<CsExpression> l = new List<CsExpression>();
			foreach (CsArgument csArgument in stat.argument_list.list) {
				l.Add(csArgument.expression);
			}

			return getIndexerExpression(stat, l, pCreator.Parse(stat.expression), pForce, pGetSetter, pCreator);
		}
Пример #24
0
        internal static Expression getIndexerExpression(CsExpression pStatement, IEnumerable <CsExpression> pList,
                                                        Expression pIndexer, bool pForce, bool pGetSetter, FactoryExpressionCreator pCreator)
        {
            TheClass k = TheClassFactory.Get(pStatement, pCreator);

            List <string>          indexes = new List <string>();
            List <CsEntityTypeRef> param   = new List <CsEntityTypeRef>();

            foreach (CsExpression ex in pList)
            {
                Expression te = pCreator.Parse(ex);
                indexes.Add(te.Value);
                param.Add(te.Type);
            }

            string     exp        = pIndexer == null ? "super" : pIndexer.Value;
            bool       isInternal = false;
            TheIndexer i          = null;

            if (k != null)
            {
                i = k.GetIndexer(pStatement);
            }

            //TODO: Check array access...
            if (i == null || pIndexer == null || (pIndexer.Type != null && pIndexer.Type.type == cs_entity_type.et_array))
            {
                //Array access or unknown accessor
                exp += "[" + indexes[0] + "]";
            }
            else
            {
                //TheIndexers i = k.GetIndexerBySignature(param);
                isInternal = true;

                CsAssignmentExpression parent = pStatement.parent as CsAssignmentExpression;

                if (!pForce)
                {
                    pGetSetter = parent != null && parent.lhs.Equals(pStatement);
                }

                if (pGetSetter)
                {
                    exp += "." + i.Setter.Name + "(" + string.Join(", ", indexes.ToArray()) + ", {0})";
                }
                else
                {
                    exp += "." + i.Getter.Name + "(" + string.Join(", ", indexes.ToArray()) + ")";
                }
            }

            return(new Expression(exp, pStatement.entity_typeref, isInternal));
        }
Пример #25
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsCastUnaryExpression ex = (CsCastUnaryExpression)pStatement;

            //Do not cast anything. This is here just to support the automatic casting done by the flash player.
            return(new Expression(
                       //JsHelpers.Convert(Helpers.GetType(ex.type)) + "(" +
                       pCreator.Parse(ex.unary_expression).Value
                       //+ ")"
                       , ex.type.entity_typeref
                       ));
        }
Пример #26
0
        private static void parseSwitchStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsSwitchStatement switchStatement = (CsSwitchStatement)pStatement;

            pSb.AppendFormat("switch ({0}){{", pCreator.Parse(switchStatement.expression).Value);
            pSb.AppendLine();
            pSb.Indent();

            foreach (CsSwitchSection caseNode in switchStatement.sections)
            {
                LinkedList <CsSwitchLabel> labels = caseNode.labels;
                foreach (CsSwitchLabel label in labels)
                {
                    if (label.default_label)
                    {
                        pSb.Append("default:");
                        pSb.AppendLine();
                    }
                    else
                    {
                        Expression txt = pCreator.Parse(label.expression);
                        pSb.AppendFormat("case {0}:", txt.Value);
                        pSb.AppendLine();
                    }
                }

                foreach (CsStatement statementNode in caseNode.statements)
                {
                    pSb.Indent();
                    parseStatement(statementNode, pSb, pCreator);
                    pSb.Unindent();
                }
            }

            pSb.Unindent();
            pSb.Append("}");
            pSb.AppendLine();
        }
Пример #27
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			//"new" non-array-type "[" expression-list "]" ( rank-specifiers )? ( array-initializer )?
			//"new" non-array-type? rank-specifiers array-initializer
			CsNewArrayExpression ex = (CsNewArrayExpression) pStatement;

			StringBuilder builder = new StringBuilder();

			if (ex.initializer != null) {
				builder.Append("[");
				//builder.AppendFormat("new <{0}>[", JsHelpers.Convert(Helpers.GetType(((CsEntityArraySpecifier)ex.entity_typeref.u).type)));


				if (ex.initializer.initializers != null) {
					List<string> initializers = new List<string>();

					foreach (CsNode node in ex.initializer.initializers) {
						Expression expression = pCreator.Parse(node as CsExpression);
						initializers.Add(expression.Value);
					}

					if (initializers.Count != 0) {
						builder.Append(string.Join(", ", initializers.ToArray()));
					}
				}

				builder.Append("]");
				//builder.Append("]");

			} else if (ex.expressions != null && ex.expressions.list != null && ex.expressions.list.Count == 1) {
				builder.Append("new Array(");
				Expression expression = pCreator.Parse(ex.expressions.list.First.Value);
				builder.Append(expression.Value);
				builder.Append(")");
			}

			return new Expression(builder.ToString(), pStatement.entity_typeref);
		}
Пример #28
0
        internal static Expression parseElementAccess(CsExpression pStatement, bool pForce, bool pGetSetter, FactoryExpressionCreator pCreator)
        {
            //expression "[" expression-list "]"
            CsElementAccess stat = (CsElementAccess)pStatement;

            List <CsExpression> l = new List <CsExpression>();

            foreach (CsArgument csArgument in stat.argument_list.list)
            {
                l.Add(csArgument.expression);
            }

            return(getIndexerExpression(stat, l,
                                        pCreator.Parse(stat.expression), pForce, pGetSetter, pCreator));
        }
Пример #29
0
		internal static List<TheMethodArgument> getArguments(IEnumerable<CsFormalParameter> pLinkedList, FactoryExpressionCreator pCreator) {
			List<TheMethodArgument> arguments = new List<TheMethodArgument>();

			if (pLinkedList != null) {
				arguments.AddRange(from param in pLinkedList
				                   let e = param.default_argument == null ? null : pCreator.Parse(param.default_argument.expression)
				                   select new TheMethodArgument {
				                   	Name = param.identifier.identifier,
									Type = param.type == null ? Helpers.GetType(param.entity.type) : Helpers.GetType(param.type), 
									DefaultValue = e
				                   });
			}

			return arguments;
		}
Пример #30
0
        private static void parseReturnStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsReturnStatement returnStatement = (CsReturnStatement)pStatement;

            if (returnStatement.expression == null)
            {
                //pSb.AppendLine(InsideConstructor ? "return this" : InsideSetter ? "return value;" : "return;");
                pSb.AppendLine(InsideSetter ? "return value;" : "return;");
            }
            else
            {
                pSb.AppendFormat("return {0};", pCreator.Parse(returnStatement.expression).Value);
                pSb.AppendLine();
            }
        }
Пример #31
0
		public TheConstant(CsConstantDeclaration pCsConstantDeclaration, TheClass pTheClass, FactoryExpressionCreator pCreator) {
			Modifiers.AddRange(Helpers.GetModifiers(pCsConstantDeclaration.modifiers));

			foreach (CsConstantDeclarator declarator in pCsConstantDeclaration.declarators) {
				Constant v = new Constant {
					//RealName = declarator.identifier.identifier,
					//Name = Helpers.GetRealName(declarator, declarator.identifier.identifier),
					Name = declarator.identifier.identifier,
					Initializer = pCreator.Parse(declarator.expression),
					ReturnType = Helpers.GetType(declarator.entity.type)
				};

				v.Modifiers.AddRange(Modifiers);
				Constants.Add(v);
			}
		}
Пример #32
0
        public static List <Expression> GetCallingArguments(CsArgumentList pCsEntityFormalParameter, FactoryExpressionCreator pCreator)
        {
            List <Expression> arguments = new List <Expression>();

            if (pCsEntityFormalParameter == null || pCsEntityFormalParameter.list == null)
            {
                return(arguments);
            }

            arguments.AddRange(
                pCsEntityFormalParameter.list.Select(
                    pCsArgument =>
                    pCreator.Parse(pCsArgument.expression)));

            return(arguments);
        }
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			//expression "." identifier (type-argument-list?)
			CsPrimaryExpressionMemberAccess ex = (CsPrimaryExpressionMemberAccess)pStatement;
			string name;
			bool renamed = Helpers.GetRealName(ex, ex.identifier.identifier, out name);

			if (renamed) {
				return new Expression(name, pStatement.entity_typeref);
			}

			CsEntityProperty p = ex.entity as CsEntityProperty;
			bool isInternal = false;
			if (p != null && p.decl != null) {
				TheClass theClass = TheClassFactory.Get(p, pCreator);
				TheClass parent = theClass;

				//Am I extending a standard flash class? Do not rename then...
				bool isStandardGetSet = false;
				while (parent.Base != null) {
					isStandardGetSet |= parent.FullName.StartsWith("flash.");
					parent = parent.Base;
				}

				if (!isStandardGetSet) {
					TheProperty theProperty = theClass.GetProperty((CsProperty)p.decl);
					if (theProperty != null) {
						if (ex.parent is CsAssignmentExpression) {
							//setter
							isInternal = true;
							name = "set_" + name + "({0})";
						} else {
							//getter, rename
							name = "get_" + name + "()";
						}
					}
				}

			} else if (ex.ec == expression_classification.ec_event_access) {//remove eventhandler name
				name = string.Empty;
			}

			return new Expression(
				pCreator.Parse(ex.expression).Value + "." + name,
				pStatement.entity_typeref,
				isInternal
			);
		}
Пример #34
0
		internal static List<TheMethodArgument> getArguments(CsEntityFormalParameter[] pCsEntityFormalParameter, FactoryExpressionCreator pCreator) {
			List<TheMethodArgument> arguments = new List<TheMethodArgument>();

			if (pCsEntityFormalParameter != null) {
				foreach (CsEntityFormalParameter formalParameter in pCsEntityFormalParameter) {
					CsFormalParameter p = formalParameter.param;

					arguments.Add(new TheMethodArgument {
						Name = p == null ? formalParameter.name : p.identifier.identifier,
						Type = Helpers.GetType(formalParameter.type),
						DefaultValue = p == null ? null : p.default_argument == null ? null : pCreator.Parse(p.default_argument.expression)
					});
				}
			}

			return arguments;
		}
Пример #35
0
		internal TheVariable(CsVariableDeclaration pCsVariableDeclaration, TheClass pTheClass, FactoryExpressionCreator pCreator) {
			Modifiers.AddRange(Helpers.GetModifiers(pCsVariableDeclaration.modifiers));

			foreach (CsVariableDeclarator declarator in pCsVariableDeclaration.declarators) {
				Variable v = new Variable {
					//RealName = declarator.identifier.identifier,
					//Name = Helpers.GetRealName(declarator, declarator.identifier.identifier),
					Name = declarator.identifier.identifier,
					Initializer =
						declarator.initializer == null ? null : pCreator.Parse(declarator.initializer as CsExpression),
					ReturnType = Helpers.GetType(declarator.entity.type)
				};

				v.Modifiers.AddRange(Modifiers);
				Variables.Add(v);
			}
		}
Пример #36
0
        internal static List <TheMethodArgument> getArguments(IEnumerable <CsFormalParameter> pLinkedList, FactoryExpressionCreator pCreator)
        {
            List <TheMethodArgument> arguments = new List <TheMethodArgument>();

            if (pLinkedList != null)
            {
                arguments.AddRange(from param in pLinkedList
                                   let e = param.default_argument == null ? null : pCreator.Parse(param.default_argument.expression)
                                           select new TheMethodArgument {
                    Name         = param.identifier.identifier,
                    Type         = param.type == null ? Helpers.GetType(param.entity.type) : Helpers.GetType(param.type),
                    DefaultValue = e
                });
            }

            return(arguments);
        }
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			CsAnonymousObjectCreationExpression ex = (CsAnonymousObjectCreationExpression)pStatement;
			StringBuilder builder = new StringBuilder("{");

			if (ex.member_declarator_list != null) {
				foreach (var declarator in ex.member_declarator_list) {
					builder.AppendFormat(@"""{0}"": {1}, ",
						declarator.identifier.identifier,
						pCreator.Parse(declarator.expression).Value
					);
				}

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

			builder.Append("}");
			return new Expression(builder.ToString(), ex.entity_typeref);
		}
Пример #38
0
        public TheConstant(CsConstantDeclaration pCsConstantDeclaration, TheClass pTheClass, FactoryExpressionCreator pCreator)
        {
            Modifiers.AddRange(Helpers.GetModifiers(pCsConstantDeclaration.modifiers));

            foreach (CsConstantDeclarator declarator in pCsConstantDeclaration.declarators)
            {
                Constant v = new Constant {
                    //RealName = declarator.identifier.identifier,
                    //Name = Helpers.GetRealName(declarator, declarator.identifier.identifier),
                    Name        = declarator.identifier.identifier,
                    Initializer = pCreator.Parse(declarator.expression),
                    ReturnType  = Helpers.GetType(declarator.entity.type)
                };

                v.Modifiers.AddRange(Modifiers);
                Constants.Add(v);
            }
        }
Пример #39
0
		internal static Expression getIndexerExpression(CsExpression pStatement, IEnumerable<CsExpression> pList,
														Expression pIndexer, bool pForce, bool pGetSetter, FactoryExpressionCreator pCreator) {

			TheClass k = TheClassFactory.Get(pStatement, pCreator);
			List<string> indexes = new List<string>();
			List<CsEntityTypeRef> param = new List<CsEntityTypeRef>();

			foreach (CsExpression ex in pList) {
				Expression te = pCreator.Parse(ex);
				indexes.Add(te.Value);
				param.Add(te.Type);
			}

			string exp = pIndexer == null ? "super" : pIndexer.Value;
			bool isInternal = false;
			TheIndexer i = null;
			if (k != null)
				i = k.GetIndexer(pStatement);

			//TODO: Check array access...
			if (i == null || pIndexer == null || (pIndexer.Type != null && pIndexer.Type.type == cs_entity_type.et_array)) {
				//Array access or unknown accessor
				exp += "[" + indexes[0] + "]";

			} else {
				//TheIndexers i = k.GetIndexerBySignature(param);
				isInternal = true;

				CsAssignmentExpression parent = pStatement.parent as CsAssignmentExpression;

				if (!pForce) {
					pGetSetter = parent != null && parent.lhs.Equals(pStatement);
				}

				if (pGetSetter) {
					exp += "." + i.Setter.Name + "(" + string.Join(", ", indexes.ToArray()) + ", {0})";

				} else {
					exp += "." + i.Getter.Name + "(" + string.Join(", ", indexes.ToArray()) + ")";
				}
			}

			return new Expression(exp, pStatement.entity_typeref, isInternal);
		}
Пример #40
0
        internal TheVariable(CsVariableDeclaration pCsVariableDeclaration, TheClass pTheClass, FactoryExpressionCreator pCreator)
        {
            Modifiers.AddRange(Helpers.GetModifiers(pCsVariableDeclaration.modifiers));

            foreach (CsVariableDeclarator declarator in pCsVariableDeclaration.declarators)
            {
                Variable v = new Variable {
                    //RealName = declarator.identifier.identifier,
                    //Name = Helpers.GetRealName(declarator, declarator.identifier.identifier),
                    Name        = declarator.identifier.identifier,
                    Initializer =
                        declarator.initializer == null ? null : pCreator.Parse(declarator.initializer as CsExpression),
                    ReturnType = Helpers.GetType(declarator.entity.type)
                };

                v.Modifiers.AddRange(Modifiers);
                Variables.Add(v);
            }
        }
Пример #41
0
        private static void parseLocalConstantDeclaration(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsDeclarationStatement declarationStatement = (CsDeclarationStatement)pStatement;

            CsLocalConstantDeclaration lcd = (CsLocalConstantDeclaration)declarationStatement.declaration;

            foreach (CsLocalConstantDeclarator declarator in lcd.declarators)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat(@"const {0}:{1} = {2};",
                                declarator.identifier.identifier,
                                As3Helpers.Convert(Helpers.GetType(lcd.type)),
                                pCreator.Parse(declarator.expression).Value
                                );

                pSb.Append(sb.ToString());
                pSb.AppendLine();
            }
        }
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsAnonymousObjectCreationExpression ex = (CsAnonymousObjectCreationExpression)pStatement;
            StringBuilder builder = new StringBuilder("{");

            if (ex.member_declarator_list != null)
            {
                foreach (var declarator in ex.member_declarator_list)
                {
                    builder.AppendFormat(@"""{0}"": {1}, ",
                                         declarator.identifier.identifier,
                                         pCreator.Parse(declarator.expression).Value
                                         );
                }

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

            builder.Append("}");
            return(new Expression(builder.ToString(), ex.entity_typeref));
        }
Пример #43
0
        private static void parseIfStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsIfStatement ifStatement = (CsIfStatement)pStatement;

            pSb.AppendFormat("if ({0}){{", pCreator.Parse(ifStatement.condition));
            pSb.AppendLine();

            ParseNode(ifStatement.if_statement, pSb, pCreator);

            if (ifStatement.else_statement != null)
            {
                pSb.AppendLine();
                pSb.Append("} else {");
                pSb.AppendLine();
                pSb.AppendLine();
                ParseNode(ifStatement.else_statement, pSb, pCreator);
            }

            pSb.Append("}");
            pSb.AppendLine();
            pSb.AppendLine();
        }
Пример #44
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsPostIncrementDecrementExpression ex = (CsPostIncrementDecrementExpression)pStatement;

            Expression exp = pCreator.Parse(ex.expression);

            if (exp.InternalType)
            {
                if (ex.expression is CsElementAccess)
                {
                    string setter = ElementAccessHelper.parseElementAccess(ex.expression, true, true, pCreator).Value;

                    switch (ex.oper)
                    {
                    case CsTokenType.tkINC:
                        return(new Expression(string.Format(setter, exp.Value + "++"), exp.Type));

                    case CsTokenType.tkDEC:
                        return(new Expression(string.Format(setter, exp.Value + "--"), exp.Type));

                    default:
                        throw new Exception();
                    }
                }
            }

            switch (ex.oper)
            {
            case CsTokenType.tkINC:
                return(new Expression(exp.Value + "++", exp.Type));

            case CsTokenType.tkDEC:
                return(new Expression(exp.Value + "--", exp.Type));

            default:
                throw new NotImplementedException();
            }
        }
Пример #45
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();

		}
Пример #46
0
        internal static List <TheMethodArgument> getArguments(CsEntityFormalParameter[] pCsEntityFormalParameter, FactoryExpressionCreator pCreator)
        {
            List <TheMethodArgument> arguments = new List <TheMethodArgument>();

            if (pCsEntityFormalParameter != null)
            {
                foreach (CsEntityFormalParameter formalParameter in pCsEntityFormalParameter)
                {
                    CsFormalParameter p = formalParameter.param;

                    arguments.Add(new TheMethodArgument {
                        Name         = p == null ? formalParameter.name : p.identifier.identifier,
                        Type         = Helpers.GetType(formalParameter.type),
                        DefaultValue = p == null ? null : p.default_argument == null ? null : pCreator.Parse(p.default_argument.expression)
                    });
                }
            }

            return(arguments);
        }
Пример #47
0
        private static void parseForeachStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator)
        {
            CsForeachStatement fes = (CsForeachStatement)pStatement;

            Expression ex   = pCreator.Parse(fes.expression);
            string     type = As3Helpers.Convert(Helpers.GetType(fes.type));

            pSb.AppendLine();

            TheClass theClass = TheClassFactory.Get(ex.Type, pCreator);

            if (ex.Type.type == cs_entity_type.et_array || ex.IsAs3Generic ||
                (theClass != null && @"System.Array".Equals(theClass.FullName)))                     //foreach
            {
                pSb.AppendFormat("for each(var {0}:{1} in {2}){{",
                                 fes.identifier.identifier,
                                 type,
                                 ex.Value);
                pSb.AppendLine();
            }
            else if (ex.Type.type == cs_entity_type.et_object ||
                     ex.Type.type == cs_entity_type.et_generic_param ||
                     (theClass != null && @"flash.utils.Dictionary".Equals(theClass.FullName)))
            {
                pSb.AppendFormat("for (var {0}:{1} in {2}){{",
                                 fes.identifier.identifier,
                                 type,
                                 ex.Value);

                pSb.AppendLine();
                if (ex.Type.type == cs_entity_type.et_object)
                {
                    pSb.AppendFormat("	if (!{1}.hasOwnProperty({0})) continue;",
                                     fes.identifier.identifier,
                                     ex.Value
                                     );
                }

                pSb.AppendLine();
            }
            else
            {
                _enumCount++;
                //TheClass theClass = TheClassFactory.Get(fes.expression.entity_typeref);

                string enumName = String.Format(@"__ie{0}", _enumCount);
                pSb.AppendFormat("var {0}:IEnumerator = {1}.GetEnumerator();", enumName, ex.Value);
                pSb.AppendLine();
                pSb.AppendFormat("while ({0}.MoveNext()){{", enumName);
                pSb.AppendLine();

                pSb.AppendFormat("\tvar {1}:{2} = {0}.get_Current() as {2};",
                                 enumName,
                                 fes.identifier.identifier,
                                 type
                                 );

                pSb.AppendLine();
            }

            ParseNode(fes.statement, pSb, pCreator);
            pSb.AppendLine("}");
            pSb.AppendLine();
        }
Пример #48
0
		private static void parseWhileStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator) {
			CsWhileStatement whileStatement = (CsWhileStatement)pStatement;

			pSb.AppendFormat("while ({0}){{", pCreator.Parse(whileStatement.condition));
			pSb.AppendLine();
			ParseNode(whileStatement.statement, pSb, pCreator);
			pSb.Append("}");
			pSb.AppendLine();
			pSb.AppendLine();
		}
Пример #49
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();
        }
Пример #50
0
		private static void parseExpressionStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator) {
			Expression ex = pCreator.Parse(((CsExpressionStatement)pStatement).expression);
			pSb.Append(ex.Value+";");
			pSb.AppendLine();
		}
Пример #51
0
		private static void parseReturnStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator) {
			CsReturnStatement returnStatement = (CsReturnStatement) pStatement;
			if (returnStatement.expression == null) {
				//pSb.AppendLine(InsideConstructor ? "return this" : InsideSetter ? "return value;" : "return;");
				pSb.AppendLine(InsideSetter ? "return value;" : "return;");

			} else {
				pSb.AppendFormat("return {0};", pCreator.Parse(returnStatement.expression).Value);
				pSb.AppendLine();
			}
		}
Пример #52
0
		private static void parseForeachStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator) {
			CsForeachStatement fes = (CsForeachStatement)pStatement;

			Expression ex = pCreator.Parse(fes.expression);
			string type = As3Helpers.Convert(Helpers.GetType(fes.type));

			pSb.AppendLine();

			TheClass theClass = TheClassFactory.Get(ex.Type, pCreator);

			if (ex.Type.type == cs_entity_type.et_array || ex.IsAs3Generic
				|| (theClass != null && @"System.Array".Equals(theClass.FullName))) {//foreach
				pSb.AppendFormat("for each(var {0}:{1} in {2}){{",
					fes.identifier.identifier,
					type,
					ex.Value);
				pSb.AppendLine();

			} else if (ex.Type.type == cs_entity_type.et_object ||
						ex.Type.type == cs_entity_type.et_generic_param || 
					(theClass != null && @"flash.utils.Dictionary".Equals(theClass.FullName))) {

				pSb.AppendFormat("for (var {0}:{1} in {2}){{",
					fes.identifier.identifier,
					type,
					ex.Value);

				pSb.AppendLine();
				if (ex.Type.type == cs_entity_type.et_object) {
					pSb.AppendFormat("	if (!{1}.hasOwnProperty({0})) continue;",
						fes.identifier.identifier,
						ex.Value
					);
				}

				pSb.AppendLine();

			} else {
				_enumCount++;
				//TheClass theClass = TheClassFactory.Get(fes.expression.entity_typeref);

				string enumName = String.Format(@"__ie{0}", _enumCount);
				pSb.AppendFormat("var {0}:IEnumerator = {1}.GetEnumerator();", enumName, ex.Value);
				pSb.AppendLine();
				pSb.AppendFormat("while ({0}.MoveNext()){{", enumName);
				pSb.AppendLine();

				pSb.AppendFormat("\tvar {1}:{2} = {0}.get_Current() as {2};",
					enumName,
					fes.identifier.identifier,
					type
				);

				pSb.AppendLine();
			}

			ParseNode(fes.statement, pSb, pCreator);
			pSb.AppendLine("}");
			pSb.AppendLine();
		}
Пример #53
0
		private static void parseSwitchStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator) {
			CsSwitchStatement switchStatement = (CsSwitchStatement)pStatement;

			pSb.AppendFormat("switch ({0}){{", pCreator.Parse(switchStatement.expression).Value);
			pSb.AppendLine();
			pSb.Indent();

			foreach (CsSwitchSection caseNode in switchStatement.sections) {
				LinkedList<CsSwitchLabel> labels = caseNode.labels;
				foreach (CsSwitchLabel label in labels){
					if (label.default_label) {
						pSb.Append("default:");
						pSb.AppendLine();

					} else {
						Expression txt = pCreator.Parse(label.expression);
						pSb.AppendFormat("case {0}:", txt.Value);
						pSb.AppendLine();
					}
				}

				foreach (CsStatement statementNode in caseNode.statements) {
					pSb.Indent();
					parseStatement(statementNode, pSb, pCreator);
					pSb.Unindent();
				}
			}

			pSb.Unindent();
			pSb.Append("}");
			pSb.AppendLine();
		}
Пример #54
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			CsInvocationExpression ex = (CsInvocationExpression)pStatement;

			List<string> indexes = new List<string>();

			if (ex.argument_list != null) {
				foreach (CsArgument argument in ex.argument_list.list) {
					indexes.Add(pCreator.Parse(argument.expression).Value);
				}
			}

			TheClass c = TheClassFactory.Get(pStatement, pCreator);
			TheMethod m;

			CsEntityMethod method = ex.entity as CsEntityMethod;
			CsEntityDelegate entityDelegate = ex.entity as CsEntityDelegate;

			string name = pCreator.Parse(ex.expression).Value;

			//call es de tipo super. Necesito saber cuál es la clase heredada)
			if (name.EndsWith("super.", StringComparison.Ordinal)) {
				c = c.Base;
				m = c.GetMethod(method, pCreator);
				name = name + m.Name;

			} else if (method != null) {
				//si es una expresión de tipo xx.yy.method(), tengo que revisar la expresión
				//porque la invocación se da como expresión completa...
				c = TheClassFactory.Get(method.parent, pCreator);
				m = c.GetMethod(method, pCreator);

				if (m.IsExtensionMethod) {
					int fnIndex = name.IndexOf(m.Name);
					if (fnIndex > 0)
						fnIndex--;

					indexes.Insert(0, name.Substring(0, fnIndex));

					if (Helpers.HasAttribute(((CsEntityClass)method.parent).attributes, "JsExtensionAttribute")) {
						name = m.MyClass.FullName;
						name = name.Substring(0, name.LastIndexOf('.'));
						name = name + "."+m.Name;
						ImportStatementList.AddImport(name);
						name = m.Name;

					} else {
						name = m.FullName;
					}

				} else {
					name = name.Replace(m.Name, m.Name);
				}

			} else if (entityDelegate != null) {
				//es un evento?
				if (ex.expression.ec == expression_classification.ec_event_access) {
					TheEvent theEvent = c.GetEvent(name);
					name = theEvent.IsFlashEvent ?
								"dispatchEvent" :
								string.Format(@"if (_e{0}) _e{0}.fire", name);
				}
			}

			//patch
			if (name.Contains("{0}")) {
				string p = indexes[0];
				indexes.RemoveAt(0);
				name = string.Format(name, p, string.Join(", ", indexes.ToArray()));

			} else {
				name = name + "(" + string.Join(", ", indexes.ToArray()) + ")";
			}

			return new Expression(
				name,
				ex.entity_typeref
			);
		}
Пример #55
0
		public static void ParseNode(CsNode pNode, CodeBuilder pSb, FactoryExpressionCreator pCreator) {
			CsBlock block = pNode as CsBlock;
			if (block != null) {
				Parse(block, pSb, pCreator);
				return;
			}

			CsStatement statement = pNode as CsStatement;
			if (statement != null) {
				pSb.Indent();
				parseStatement(statement, pSb, pCreator);
				pSb.Unindent();
				return;
			}

			CsExpression expression = pNode as CsExpression;
			if (expression != null) {
				Expression ex = pCreator.Parse(pNode as CsExpression);
				pSb.Append(ex.Value + ";");
				pSb.AppendLine();
				return;
			}

			throw new Exception();
		}
Пример #56
0
		private static void parseIfStatement(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator) {
			CsIfStatement ifStatement = (CsIfStatement)pStatement;

			pSb.AppendFormat("if ({0}){{", pCreator.Parse(ifStatement.condition));
			pSb.AppendLine();

			ParseNode(ifStatement.if_statement, pSb, pCreator);

			if (ifStatement.else_statement != null) {
				pSb.AppendLine();
				pSb.Append("} else {");
				pSb.AppendLine();
				pSb.AppendLine();
				ParseNode(ifStatement.else_statement, pSb, pCreator);
			}

			pSb.Append("}");
			pSb.AppendLine();
			pSb.AppendLine();
		}
Пример #57
0
		private static void parseLocalConstantDeclaration(CsStatement pStatement, CodeBuilder pSb, FactoryExpressionCreator pCreator) {
			CsDeclarationStatement declarationStatement = (CsDeclarationStatement)pStatement;

			CsLocalConstantDeclaration lcd = (CsLocalConstantDeclaration)declarationStatement.declaration;

			foreach (CsLocalConstantDeclarator declarator in lcd.declarators) {
				StringBuilder sb = new StringBuilder();

				sb.AppendFormat(@"const {0}:{1} = {2};",
					declarator.identifier.identifier,
					As3Helpers.Convert(Helpers.GetType(lcd.type)),
					pCreator.Parse(declarator.expression).Value
				);

				pSb.Append(sb.ToString());
				pSb.AppendLine();
			}
		}
Пример #58
0
		//public static void ParseBlockOrStatementOrExpression(CsNode pNode, CodeBuilder pSb, FactoryExpressionCreator pCreator) {
		//    CsBlock block = pNode as CsBlock;
		//    if (block != null) {
		//        Parse(block, pSb, pCreator);
		//        return;
		//    }

		//    CsStatement statement = pNode as CsStatement;
		//    if (statement != null) {
		//        pSb.Indent();
		//        parseStatement(statement, pSb, pCreator);
		//        pSb.Unindent();
		//        return;
		//    }

		//    Expression ex = pCreator.Parse(pNode as CsExpression);
		//    pSb.Append(ex.Value+";");
		//    pSb.AppendLine();
		//}

		private static string parseNode(CsNode pNode, FactoryExpressionCreator pCreator) {
			Expression ex = pCreator.Parse(pNode as CsExpression);
			return ex.Value;
		}
Пример #59
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsInvocationExpression ex = (CsInvocationExpression)pStatement;

            List <string> indexes = new List <string>();

            if (ex.argument_list != null)
            {
                foreach (CsArgument argument in ex.argument_list.list)
                {
                    indexes.Add(pCreator.Parse(argument.expression).Value);
                }
            }

            TheClass  c = TheClassFactory.Get(pStatement, pCreator);
            TheMethod m;

            CsEntityMethod   method         = ex.entity as CsEntityMethod;
            CsEntityDelegate entityDelegate = ex.entity as CsEntityDelegate;

            string name = pCreator.Parse(ex.expression).Value;

            //call es de tipo super. Necesito saber cuál es la clase heredada)
            if (name.EndsWith("super.", StringComparison.Ordinal))
            {
                c    = c.Base;
                m    = c.GetMethod(method, pCreator);
                name = name + m.Name;
            }
            else if (method != null)
            {
                //si es una expresión de tipo xx.yy.method(), tengo que revisar la expresión
                //porque la invocación se da como expresión completa...
                c = TheClassFactory.Get(method.parent, pCreator);
                m = c.GetMethod(method, pCreator);

                if (m.IsExtensionMethod)
                {
                    int fnIndex = name.IndexOf(m.Name);
                    if (fnIndex > 0)
                    {
                        fnIndex--;
                    }

                    indexes.Insert(0, name.Substring(0, fnIndex));

                    if (Helpers.HasAttribute(((CsEntityClass)method.parent).attributes, "As3ExtensionAttribute"))
                    {
                        name = m.MyClass.FullName;
                        name = name.Substring(0, name.LastIndexOf('.'));
                        name = name + "." + m.Name;
                        ImportStatementList.AddImport(name);
                        name = m.Name;
                    }
                    else
                    {
                        name = m.FullName;
                    }
                }
                else
                {
                    name = name.Replace(m.Name, m.Name);
                }
            }
            else if (entityDelegate != null)
            {
                //es un evento?
                if (ex.expression.ec == expression_classification.ec_event_access)
                {
                    TheEvent theEvent = c.GetEvent(name);
                    name = theEvent.IsFlashEvent ?
                           "dispatchEvent" :
                           string.Format(@"if (_e{0}) _e{0}.fire", name);
                }
            }

            //patch
            if (name.Contains("{0}"))
            {
                string p = indexes[0];
                indexes.RemoveAt(0);
                name = string.Format(name, p, string.Join(", ", indexes.ToArray()));
            }
            else
            {
                name = name + "(" + string.Join(", ", indexes.ToArray()) + ")";
            }

            return(new Expression(
                       name,
                       ex.entity_typeref
                       ));
        }
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			//"(" expression ")"
			CsParenthesizedExpression ex = (CsParenthesizedExpression)pStatement;
			return new Expression("(" + pCreator.Parse(ex.expression).Value + ")", pStatement.entity_typeref);
		}