Пример #1
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
                       ));
        }
Пример #2
0
        public static string GetType(CsEntityTypeRef pDirective)
        {
            if (pDirective == null)
            {
                return(null);
            }

            if (_entityTypeRef.ContainsKey(pDirective.type))
            {
                return(_entityTypeRef[pDirective.type]);
            }

            switch (pDirective.type)
            {
            case cs_entity_type.et_valuetype:
                return(null);

            case cs_entity_type.et_array:
                return(GetType(((CsEntityArraySpecifier)pDirective.u).type) + "[]");

            case cs_entity_type.et_enum:
                return(((CsEntityEnum)pDirective.u).name);

            case cs_entity_type.et_generic_param:
                CsEntityGenericParam egp = pDirective.u as CsEntityGenericParam;
                //TODO: check generics parameters
                return("<" + egp.name + ">");

            case cs_entity_type.et_genericinst:
                CsEntityInstanceSpecifier eis = pDirective.u as CsEntityInstanceSpecifier;
                if (eis != null)
                {
                    string ret = GetType(eis.type);

                    if (eis.arguments != null)
                    {
                        List <string> val = new List <string> {
                            "<"
                        };

                        foreach (CsEntityTypeRef argument in eis.arguments)
                        {
                            val.Add(GetType(argument));
                            val.Add(", ");
                        }
                        val.RemoveAt(val.Count - 1);
                        val.Add(">");
                        ret += string.Join("", val.ToArray());
                    }

                    return(ret);
                }

                throw new Exception();

            case cs_entity_type.et_class:
                CsEntityInterface itf = pDirective.u as CsEntityInterface;
                if (itf != null)
                {
                    if (itf.interfaces != null && itf.interfaces.Count > 0)
                    {
                        List <string> val = new List <string>(itf.interfaces.Count);
                        foreach (CsEntityTypeRef typeRef in itf.interfaces)
                        {
                            val.Add(GetType(typeRef));
                        }

                        return(string.Join(", ", val.ToArray()));
                    }

                    if (!string.IsNullOrEmpty(itf.name))
                    {
                        return(itf.name);
                    }
                }

                CsEntityClass cls = pDirective.u as CsEntityClass;
                if (cls != null)
                {
                    //if (cls.indexers != null) {
                    //    foreach (CsEntityProperty indexer in cls.indexers) {
                    //        return GetType(indexer.type);
                    //    }
                    //}

                    return(cls.name);
                }

                CsEntityDelegate entityDelegate = pDirective.u as CsEntityDelegate;
                if (entityDelegate != null)
                {
                    return("function");
                }

                return("IHaveNOIdeaWhatShouldBeHere");
            }

            throw new Exception("Unknown EntityTypeRef: " + pDirective.type);
        }