Exemplo n.º 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);
		}
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			// "default" ( type )
			return new Expression(
				null,
				pStatement.entity_typeref
			);
		}
Exemplo n.º 3
0
		public static Expression ParseSimpleName(CsExpression pStatement, bool pForce, bool pGetSetter) {
			CsSimpleName ex = (CsSimpleName)pStatement;

			bool isInternal = false;
			string val;

			if (ex.ec == expression_classification.ec_property_access) {
				CsAssignmentExpression parent = pStatement.parent as CsAssignmentExpression;

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

				isInternal = true;
				CsEntityProperty property = (CsEntityProperty)ex.entity;
				val = pGetSetter ? string.Format("{0}({{0}})", property.setter.name) : string.Format("{0}()", property.getter.name);


			} else {
				//val = ex.identifier.identifier;
				Helpers.GetRealName(ex, ex.identifier.identifier, out val);
			}

			return new Expression(
				val,
				ex.entity_typeref,
				isInternal);
		}
		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();
			}
		}
Exemplo n.º 5
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);
		}
		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
			);
		}
Exemplo n.º 7
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) {
			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
			);
		}
Exemplo n.º 9
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
			);
		}
Exemplo n.º 10
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
			);
		}
Exemplo n.º 11
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
			);
		}
Exemplo n.º 12
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			CsTypeofExpression ex = (CsTypeofExpression)pStatement;
			//"typeof" "(" type ")"

			CsNamespaceOrTypeName isClass = ex.type.type_name as CsNamespaceOrTypeName;
			if (isClass != null) {
				return new Expression(isClass.identifier.identifier, ex.type.entity_typeref);
			}

			throw new NotImplementedException();
		}
Exemplo n.º 13
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);
		}
Exemplo n.º 14
0
        protected virtual void Add_GetBaseUnitValue()
        {
            var cs = Ext.Create <BasicUnitValuesGenerator>();

            cs.SingleLineIf("Unit.Equals(BaseUnit)", ReturnValue("Value"));
            cs.WriteLine("var factor = GlobalUnitRegistry.Factors.Get(Unit);");
            cs.SingleLineIf("!(factor is null)", ReturnValue("Value * factor.Value"));
            var exceptionMessage = new CsExpression("Unable to find multiplication for unit ".CsEncode())
                                   + new CsExpression("Unit");

            cs.Throw <Exception>(exceptionMessage.ToString());
            Target.AddMethod("GetBaseUnitValue", ValuePropertyType)
            .WithBody(cs);
        }
        protected override void Add_GetBaseUnitValue()
        {
            var cs = Ext.Create <BasicUnitValuesGenerator>();

            cs.WriteLine("var factor1 = GlobalUnitRegistry.Factors.Get(Unit.LeftUnit);");
            cs.WriteLine("var factor2 = GlobalUnitRegistry.Factors.Get(Unit.RightUnit);");
            cs.SingleLineIf("(factor1.HasValue && factor2.HasValue)", ReturnValue("Value * factor1.Value * factor2.Value"));
            var exceptionMessage = new CsExpression("Unable to find multiplication for unit ".CsEncode())
                                   + new CsExpression("Unit");

            cs.Throw <Exception>(exceptionMessage.ToString());
            Target.AddMethod("GetBaseUnitValue", ValuePropertyType)
            .WithBody(cs);
        }
Exemplo n.º 16
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));
        }
		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
			);
		}
		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);
		}
Exemplo n.º 19
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);
		}
Exemplo n.º 20
0
        public TheIndexer GetIndexer(CsExpression pIndexer)
        {
            CsBaseIndexerAccess csbia = pIndexer as CsBaseIndexerAccess;
            CsIndexer           i;
            CsEntityProperty    p;

            if (csbia != null)
            {
                p = (CsEntityProperty)csbia.entity;
                if (p == null)
                {
                    return(null);
                }

                i = (CsIndexer)p.decl;
                if (i == null)
                {
                    return(null);
                }

                return(_indexers.ContainsKey(i) ? _indexers[i] : null);
            }

            CsElementAccess csea = pIndexer as CsElementAccess;

            if (csea != null)
            {
                p = (CsEntityProperty)csea.entity;
                if (p == null)
                {
                    return(null);
                }

                i = (CsIndexer)p.decl;
                if (i == null)
                {
                    return(null);
                }

                return(_indexers.ContainsKey(i) ? _indexers[i] : null);
            }

            throw new NotImplementedException();
        }
Exemplo n.º 21
0
        private void ProcessExpression(CsExpression expression)
        {
            switch (expression.e)
            {
            case cs_node.n_simple_name:

                ProcessResultExpression(expression);
                break;

            case cs_node.n_lambda_expression:

                ProcessLambdaExpression((CsLambdaExpression)expression);
                break;

            default:
                Debugger.Break();
                break;
            }
        }
Exemplo n.º 22
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)
        {
            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));
        }
Exemplo n.º 24
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();
            }
        }
        private Col1 GetPropertiesInfo(int nr)
        {
            IReadOnlyList <ConstructorParameterInfo> items = new[]
            {
                new ConstructorParameterInfo(PropName,
                                             "string",
                                             null,
                                             "name of unit",
                                             Flags1.NormalizedString | Flags1.AddNotNullAttributeToPropertyIfPossible)
            };

            if (nr == 0)
            {
                return(new Col1(items));
            }

            items = new[]
            {
                new ConstructorParameterInfo("BaseUnit",
                                             Cfg.Source.Unit.GetTypename(),
                                             null,
                                             "base unit",
                                             Flags1.NotNull | Flags1.PropertyCanBeNull),
                new ConstructorParameterInfo(PropName,
                                             "string",
                                             null,
                                             "name of unit",
                                             Flags1.TrimValue | Flags1.Optional | Flags1.DoNotAssignProperty | Flags1.DoNotCreateProperty)
            };

            var a                = new Col1(items);
            var forceValue       = new CsExpression("unitName");
            var takeFromBaseUnit = new CsExpression("1/".CsEncode()) + new CsExpression("baseUnit.UnitName");
            var c3               = new CsExpression("string.IsNullOrEmpty(unitName)").Conditional(takeFromBaseUnit, forceValue);

            a.Writer2.WriteAssign("UnitName", c3.Code);
            return(a);
        }
Exemplo n.º 26
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);
		}
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			//embedded-type "." identifier
			CsPredefinedTypeMemberAccess ex = pStatement as CsPredefinedTypeMemberAccess;
			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;
			if (p != null) {
				//getter, rename
				name = "get_" + name + "()";

			} else if (ex.ec == expression_classification.ec_event_access) {//remove eventhandler name
				name = string.Empty;
			}
			//FactoryExpressionCreator.Parse(ex.expression).Value
			return new Expression(
				 "nose" + "." + name,
				pStatement.entity_typeref
			);
		}
Exemplo n.º 28
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			CsBaseMemberAccess baseMemberAccess = (CsBaseMemberAccess)pStatement;
			// "base" "." identifier (type-argument-list)?
			return new Expression("super." + baseMemberAccess.identifier.identifier, pStatement.entity_typeref);
		}
Exemplo n.º 29
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     //"sizeof" "(" type ")"
     throw new NotImplementedException();
 }
Exemplo n.º 30
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     //"checked" "(" expression ")"
     throw new NotImplementedException();
 }
Exemplo n.º 31
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 32
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsAssignmentExpression ex = (CsAssignmentExpression)pStatement;

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

            if (((ex.lhs is CsElementAccess) || (ex.lhs is CsPrimaryExpressionMemberAccess)) && left.InternalType)
            {
                switch (ex.oper)
                {
                case CsTokenType.tkASSIGN:
                    return(new Expression(string.Format(left.Value, right.Value), pStatement.entity_typeref));

                case CsTokenType.tkPLUS_EQ:
                case CsTokenType.tkMINUS_EQ:
                case CsTokenType.tkDIV_EQ:
                case CsTokenType.tkMUL_EQ:
                    string getter = ElementAccessHelper.parseElementAccess(ex.lhs, true, false, pCreator).Value;
                    return(new Expression(string.Format(left.Value, getter + As3Helpers.ConvertTokens(Helpers.GetTokenType(convertToken(ex.oper))) + right.Value), pStatement.entity_typeref));
                }
            }

            if ((ex.lhs is CsSimpleName) && left.InternalType)
            {
                switch (ex.oper)
                {
                case CsTokenType.tkASSIGN:
                    return(new Expression(string.Format(left.Value, right.Value), pStatement.entity_typeref));

                case CsTokenType.tkPLUS_EQ:
                case CsTokenType.tkMINUS_EQ:
                case CsTokenType.tkDIV_EQ:
                case CsTokenType.tkMUL_EQ:
                    string getter = SimpleNameHelper.ParseSimpleName(ex.lhs, true, false).Value;
                    return(new Expression(string.Format(left.Value, getter + As3Helpers.ConvertTokens(Helpers.GetTokenType(convertToken(ex.oper))) + right.Value), pStatement.entity_typeref));
                }
            }

            if (ex.lhs is CsPrimaryExpressionMemberAccess)
            {
                if (ex.lhs.ec == expression_classification.ec_event_access)
                {
                    CsEntityEvent ev = (CsEntityEvent)ex.lhs.entity;

                    TheClass theClass = TheClassFactory.Get(ev.parent, pCreator);
                    string   eventName;
                    //flash event on flash.xxxx
                    if (theClass == null)
                    {
                        eventName = Helpers.GetEventFromAttr(ev.attributes);

                        return(new Expression(
                                   left.Value +
                                   (ex.oper == CsTokenType.tkPLUS_EQ ?
                                    ("addEventListener(" + eventName + ", " + right.Value + ", false, 0, true)") :
                                    ("removeEventListener(" + eventName + ", " + right.Value + ")"))
                                   , pStatement.entity_typeref
                                   ));
                    }

                    TheEvent theEvent = theClass.GetEvent(ev.name);

                    if (theEvent != null && string.IsNullOrEmpty(theEvent.EventName))                      //custom event on the same class
                    {
                        return(new Expression(
                                   //event name == left => left IS the event name. Do not add twice
                                   left.Value + (ev.name.Equals(left.Value, StringComparison.Ordinal) ? string.Empty : ev.name) +
                                   (ex.oper == CsTokenType.tkPLUS_EQ ? ".add" : ".remove") +
                                   "(" + right.Value + ")"
                                   , pStatement.entity_typeref
                                   ));
                    }

                    eventName = theEvent == null?Helpers.GetEventFromAttr(ev.attributes) : theEvent.EventName;

                    //flash event on the same class.
                    return(new Expression(
                               //event name == left => left IS the event name. Do not add twice
                               (ev.name.Equals(left.Value, StringComparison.Ordinal) ? string.Empty : left.Value) +
                               (ex.oper == CsTokenType.tkPLUS_EQ
                                                        ? ("addEventListener(" + eventName + ", " + right.Value + ", false, 0, true)")
                                                        : ("removeEventListener(" + eventName + ", " + right.Value + ")"))
                               , pStatement.entity_typeref));
                }
                //else {
                //    left = FactoryExpressionCreator.Parse(ex.lhs);
                //    CsPrimaryExpressionMemberAccess primaryExpressionMemberAccess = (CsPrimaryExpressionMemberAccess)ex.lhs;
                //    TheClass theClass = TheClassFactory.Get((CsEntity)primaryExpressionMemberAccess.entity);
                //    //TheProperty theProp = theClass.GetProperty();
                //}
            }



            return(new Expression(string.Format("{0} {2} {1}", left.Value, right.Value, As3Helpers.ConvertTokens(Helpers.GetTokenType(ex.oper))), pStatement.entity_typeref));
        }
Exemplo n.º 33
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			throw new NotImplementedException();
		}
Exemplo n.º 34
0
        public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
        {
            CsLiteral li = (CsLiteral)pStatement;

            switch (li.type)
            {
            case CsTokenType.tkTRUE:
                return(new Expression("true", pStatement.entity_typeref));

            case CsTokenType.tkFALSE:
                return(new Expression("false", pStatement.entity_typeref));

            case CsTokenType.tkNULL:
                return(new Expression("null", pStatement.entity_typeref));

            default:
                switch (li.literal_type)
                {
                case CsLiteralType.literal_int:
                    return(new Expression(li.literal, pStatement.entity_typeref));

                case CsLiteralType.literal_uint_U:
                    return(new Expression(li.literal.Substring(0, li.literal.Length - 1), pStatement.entity_typeref));

                case CsLiteralType.literal_uint:
                    return(new Expression(li.literal, pStatement.entity_typeref));

                case CsLiteralType.literal_long:
                    return(new Expression(li.literal, pStatement.entity_typeref));

                case CsLiteralType.literal_long_L:
                    return(new Expression(li.literal.Substring(0, li.literal.Length - 1), pStatement.entity_typeref));

                case CsLiteralType.literal_decimal_M:
                    return(new Expression(li.literal, pStatement.entity_typeref));

                case CsLiteralType.literal_ulong:
                case CsLiteralType.literal_ulong_L:
                case CsLiteralType.literal_ulong_UL:
                    return(new Expression(li.literal, pStatement.entity_typeref));


                case CsLiteralType.literal_double_D:
                case CsLiteralType.literal_double:
                    return(new Expression(li.literal, pStatement.entity_typeref));

                case CsLiteralType.literal_number:
                    return(new Expression(li.literal, pStatement.entity_typeref));

                case CsLiteralType.literal_float_F:
                    return(new Expression(li.literal, pStatement.entity_typeref));

                case CsLiteralType.literal_char:
                    return(new Expression("'" + li.literal + "'", pStatement.entity_typeref));

                case CsLiteralType.literal_verbatim_string:
                    string l = li.literal.Substring(2, li.literal.Length - 3);
                    return(l.StartsWith(@"rx:", StringComparison.Ordinal) ?
                           new Expression(l.Substring(3, l.Length - 3), pStatement.entity_typeref) :
                           new Expression(Helpers.EscapeString(l), pStatement.entity_typeref));

                default:
                    return(new Expression(Helpers.EscapeString(li.literal), pStatement.entity_typeref));
                }
            }
        }
Exemplo n.º 35
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     //__arglist ( "(" expresion-list ")" )?
     throw new NotImplementedException();
 }
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			//"(" expression ")"
			CsParenthesizedExpression ex = (CsParenthesizedExpression)pStatement;
			return new Expression("(" + pCreator.Parse(ex.expression).Value + ")", pStatement.entity_typeref);
		}
Exemplo n.º 37
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
			);
		}
Exemplo n.º 38
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			//__arglist ( "(" expresion-list ")" )?
			throw new NotImplementedException();
		}
Exemplo n.º 39
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     //from-clause query-body
     throw new NotImplementedException();
 }
Exemplo n.º 40
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     //__refvalue "(" expresion "," type ")"
     throw new NotImplementedException();
 }
Exemplo n.º 41
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
                       ));
        }
Exemplo n.º 42
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			// expression "->" identifier (type-argument-list?)
			throw new NotImplementedException();
		}
Exemplo n.º 43
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     return(SimpleNameHelper.ParseSimpleName(pStatement, false, false));
 }
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			//"delegate" (explicit-anonymous-function-signature)? block
			throw new NotImplementedException();
		}
Exemplo n.º 45
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     return(ElementAccessHelper.parseElementAccess(pStatement, false, false, pCreator));
 }
Exemplo n.º 46
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			//from-clause query-body
			throw new NotImplementedException();
		}
Exemplo n.º 47
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     //CsThisAccess ex = (CsThisAccess)pExpression;
     return(new Expression("this", pStatement.entity_typeref));
 }
Exemplo n.º 48
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			//CsThisAccess ex = (CsThisAccess)pExpression;
			return new Expression("this", pStatement.entity_typeref);
		}
Exemplo n.º 49
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			// "base" "[" expression-list "]"
			CsBaseIndexerAccess indexerAccess = (CsBaseIndexerAccess) pStatement;

			return ElementAccessHelper.getIndexerExpression(indexerAccess, indexerAccess.expression_list.list, null, false, false, pCreator);
		}
Exemplo n.º 50
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			return SimpleNameHelper.ParseSimpleName(pStatement, false, false);
		}
Exemplo n.º 51
0
 public TheConstructor GetConstructor(CsExpression pMethod)
 {
     return(GetConstructor((CsConstructor)((CsEntityMethod)pMethod.entity).decl));
 }
Exemplo n.º 52
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
                       ));
        }
Exemplo n.º 53
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     //"delegate" (explicit-anonymous-function-signature)? block
     throw new NotImplementedException();
 }
Exemplo n.º 54
0
		public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) {
			//"checked" "(" expression ")"
			throw new NotImplementedException();
		}
Exemplo n.º 55
0
 public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator)
 {
     //identifier "::" identifier (type-argument-list)? "." identifier (type-argument-list)?
     throw new NotImplementedException();
 }