Exemplo n.º 1
0
        public TheMethod GetMethod(CsEntityMethod pMethod, FactoryExpressionCreator pCreator)
        {
            if (pMethod.decl != null)
            {
                return(GetMethod((CsMethod)pMethod.decl));
            }

            TheMethod c;

            if (_entityMethods.TryGetValue(pMethod, out c))
            {
                return(c);
            }

            c = new TheMethod(pMethod, this, pCreator);
            Dictionary <string, bool> methodNames = new Dictionary <string, bool>();

            foreach (KeyValuePair <CsEntityMethod, TheMethod> entityMethod in
                     _entityMethods.Where(pEntityMethod => methodNames.ContainsKey(pEntityMethod.Value.Name)))
            {
                entityMethod.Value._isUnique = false;
                c._isUnique = false;
            }

            _entityMethods.Add(pMethod, c);
            return(c);
        }
Exemplo n.º 2
0
		internal TheMethod(CsEntityMethod pCsMethod, TheClass pMyClass, FactoryExpressionCreator pCreator, bool pIsEvent = false, bool pIsAddEvent = false) {
			MyClass = pMyClass;
			//Modifiers.AddRange(Helpers.GetModifiers(pCsMethod.access));
			Arguments = getArguments(pCsMethod.parameters, pCreator);
			Signature = getSignature(Arguments);
			
			//_name = Helpers.GetRealName(pCsMethod, pIsEvent ? 
			//    pIsAddEvent ? "add" : "remove" : 
			//    pCsMethod.name);
			
			_name = pIsEvent ? pIsAddEvent ? "add" : "remove" : pCsMethod.name;
			_realName = pCsMethod.name;

			//FullRealName = MyClass.FullRealName + "." + RealName;

			ReturnType = Helpers.GetType(pCsMethod.specifier.return_type);
			IsExtensionMethod = pCsMethod.isExtensionMethod();
		}
Exemplo n.º 3
0
        internal TheMethod(CsEntityMethod pCsMethod, TheClass pMyClass, FactoryExpressionCreator pCreator, bool pIsEvent = false, bool pIsAddEvent = false)
        {
            MyClass = pMyClass;
            //Modifiers.AddRange(Helpers.GetModifiers(pCsMethod.access));
            Arguments = getArguments(pCsMethod.parameters, pCreator);
            Signature = getSignature(Arguments);

            //_name = Helpers.GetRealName(pCsMethod, pIsEvent ?
            //    pIsAddEvent ? "add" : "remove" :
            //    pCsMethod.name);

            _name     = pIsEvent ? pIsAddEvent ? "add" : "remove" : pCsMethod.name;
            _realName = pCsMethod.name;

            //FullRealName = MyClass.FullRealName + "." + RealName;

            ReturnType        = Helpers.GetType(pCsMethod.specifier.return_type);
            IsExtensionMethod = pCsMethod.isExtensionMethod();
        }
Exemplo n.º 4
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.º 5
0
        public static bool GetRealName(object pExpression, string pName, out string pRealName)
        {
            if (pExpression == null)
            {
                pRealName = pName;
                return(false);
            }

            CsEntityClass csEntityClass = pExpression as CsEntityClass;

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

            CsEntityEnum csEntityEnum = pExpression as CsEntityEnum;

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

            CsEntityStruct csEntityStruct = pExpression as CsEntityStruct;

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

            CsEntityInterface csEntityInterface = pExpression as CsEntityInterface;

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

            CsPrimaryExpressionMemberAccess csPrimaryExpressionMemberAccess = pExpression as CsPrimaryExpressionMemberAccess;

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

            CsEntityLocalVariable csEntityLocalVariable = pExpression as CsEntityLocalVariable;

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

            CsEntityVariable csEntityVariable = pExpression as CsEntityVariable;

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

            CsEntityConstant csEntityConstant = pExpression as CsEntityConstant;

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

            CsEntityMethod csEntityMethod = pExpression as CsEntityMethod;

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

            CsSimpleName csSimpleName = pExpression as CsSimpleName;

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

            CsPredefinedTypeMemberAccess csPredefinedTypeMemberAccess = pExpression as CsPredefinedTypeMemberAccess;

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

            CsEntityInstanceSpecifier csEntityInstanceSpecifier = pExpression as CsEntityInstanceSpecifier;

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


            pRealName = pName;
            return(false);

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

            //throw new NotImplementedException();
        }
Exemplo n.º 6
0
        public TheClass(CsEntity pCsEntity, FactoryExpressionCreator pCreator)
        {
            IsEntity = true;
            List <string> name   = new List <string>();
            CsEntity      parent = pCsEntity.parent;

            while (parent != null && parent is CsEntityNamespace)
            {
                if (!string.IsNullOrEmpty(parent.name))
                {
                    name.Add(parent.name);
                }
                parent = parent.parent;
            }

            name.Reverse();

            NameSpace = string.Join(".", name.ToArray());
            //RealName = pCsEntity.name;
            //Name = Helpers.GetRealName(pCsEntity, RealName);
            Name = pCsEntity.name;

            FullName = NameSpace + "." + Name;
            //FullRealName = NameSpace + "." + RealName;

            CsEntityClass klass = pCsEntity as CsEntityClass;

            if (klass != null)
            {
                _baseEntityTyperef = klass.base_type;

                if (klass.base_type.type != cs_entity_type.et_object)
                {
                    Extends.Add(Helpers.GetType(klass.base_type));
                }

                if (klass.interfaces != null)
                {
                    foreach (CsEntityTypeRef @interface in klass.interfaces)
                    {
                        Implements.Add(Helpers.GetType(@interface));
                    }
                }

                Dictionary <string, int> methodNames = new Dictionary <string, int>();
                //bool constructorsDone = false;
                bool methodsDone = false;
                if (klass.method_implementations == null)
                {
                    return;
                }

                foreach (CsEntityMethodImplementation methodImplementation in klass.method_implementations)
                {
                    CsEntityMethod m  = methodImplementation.implementation_method;
                    TheMethod      tm = new TheMethod(m, this, pCreator);
                    if (methodNames.ContainsKey(tm.Name))
                    {
                        methodNames[tm.Name]++;
                        int index = tm._index = methodNames[tm.Name];

                        if (!methodsDone)
                        {
                            methodsDone = true;
                            foreach (KeyValuePair <CsMethod, TheMethod> method in _methods)
                            {
                                method.Value._isUnique = false;
                                method.Value._index    = --index;
                            }
                        }

                        tm._isUnique = false;
                    }
                    else
                    {
                        methodNames[tm.Name] = tm._index = 1;
                    }

                    _entityMethods.Add(m, tm);
                }

                return;
            }

            CsEntityInterface entityInterface = pCsEntity as CsEntityInterface;

            if (entityInterface != null)
            {
                _baseEntityTyperef = entityInterface.base_type;

                if (entityInterface.base_type.type != cs_entity_type.et_object)
                {
                    Extends.Add(Helpers.GetType(entityInterface.base_type));
                }

                if (entityInterface.interfaces != null)
                {
                    foreach (CsEntityTypeRef @interface in entityInterface.interfaces)
                    {
                        Implements.Add(Helpers.GetType(@interface));
                    }
                }

                Dictionary <string, int> methodNames = new Dictionary <string, int>();
                bool methodsDone = false;
                if (entityInterface.method_implementations == null)
                {
                    return;
                }

                foreach (CsEntityMethodImplementation methodImplementation in entityInterface.method_implementations)
                {
                    CsEntityMethod m  = methodImplementation.implementation_method;
                    TheMethod      tm = new TheMethod(m, this, pCreator);
                    if (methodNames.ContainsKey(tm.Name))
                    {
                        methodNames[tm.Name]++;
                        int index = tm._index = methodNames[tm.Name];

                        if (!methodsDone)
                        {
                            methodsDone = true;
                            foreach (KeyValuePair <CsMethod, TheMethod> method in _methods)
                            {
                                method.Value._isUnique = false;
                                method.Value._index    = --index;
                            }
                        }

                        tm._isUnique = false;
                    }
                    else
                    {
                        methodNames[tm.Name] = tm._index = 1;
                    }

                    _entityMethods.Add(m, tm);
                }

                return;
            }

            CsEntityStruct entityStruct = pCsEntity as CsEntityStruct;

            if (entityStruct != null)
            {
                _baseEntityTyperef = entityStruct.base_type;

                if (entityStruct.base_type.type != cs_entity_type.et_object)
                {
                    Extends.Add(Helpers.GetType(entityStruct.base_type));
                }

                if (entityStruct.interfaces != null)
                {
                    foreach (CsEntityTypeRef @interface in entityStruct.interfaces)
                    {
                        Implements.Add(Helpers.GetType(@interface));
                    }
                }

                Dictionary <string, int> methodNames = new Dictionary <string, int>();
                bool methodsDone = false;
                if (entityStruct.method_implementations == null)
                {
                    return;
                }

                foreach (CsEntityMethodImplementation methodImplementation in entityStruct.method_implementations)
                {
                    CsEntityMethod m  = methodImplementation.implementation_method;
                    TheMethod      tm = new TheMethod(m, this, pCreator);
                    if (methodNames.ContainsKey(tm.Name))
                    {
                        methodNames[tm.Name]++;
                        int index = tm._index = methodNames[tm.Name];

                        if (!methodsDone)
                        {
                            methodsDone = true;
                            foreach (KeyValuePair <CsMethod, TheMethod> method in _methods)
                            {
                                method.Value._isUnique = false;
                                method.Value._index    = --index;
                            }
                        }

                        tm._isUnique = false;
                    }
                    else
                    {
                        methodNames[tm.Name] = tm._index = 1;
                    }

                    _entityMethods.Add(m, tm);
                }

                return;
            }

            throw new NotImplementedException();
        }
Exemplo n.º 7
0
		public TheMethod GetMethod(CsEntityMethod pMethod, FactoryExpressionCreator pCreator) {
			if (pMethod.decl != null)
				return GetMethod((CsMethod)pMethod.decl);

			TheMethod c;
			if (_entityMethods.TryGetValue(pMethod, out c))
				return c;

			c = new TheMethod(pMethod, this, pCreator);
			Dictionary<string, bool> methodNames = new Dictionary<string, bool>();

			foreach (KeyValuePair<CsEntityMethod, TheMethod> entityMethod in
				_entityMethods.Where(pEntityMethod => methodNames.ContainsKey(pEntityMethod.Value.Name))) {
				entityMethod.Value._isUnique = false;
				c._isUnique = false;
			}

			_entityMethods.Add(pMethod, c);
			return c;
		}