Ejemplo n.º 1
0
            public static void Parse(AStructDecl str, AStructDecl clone, List <PType> types, SharedData data)
            {
                FixGenericLinks fixer = new FixGenericLinks(clone, types, data)
                {
                    original = str, clone = clone
                };

                str.Apply(fixer);
            }
Ejemplo n.º 2
0
 public static void Parse(AStructDecl str, AStructDecl clone, List<PType> types, SharedData data)
 {
     FixGenericLinks fixer = new FixGenericLinks(clone, types, data)
         {original = str, clone = clone};
     str.Apply(fixer);
 }
Ejemplo n.º 3
0
        public override void OutAAProgram(AAProgram node)
        {
            foreach (var pair in Refferences)
            {
                if (structsWithGenerics.Contains(pair.Key) && pair.Value.Count > 0)
                {
                    needAnotherPass = true;
                }
            }
            foreach (var pair in Refferences)
            {
                AStructDecl str = pair.Key;
                if (!copies.ContainsKey(str))
                {
                    copies[str] = new List <List <PType> >();
                }
                IList declList;
                Node  parent = str.Parent();
                if (parent is AASourceFile)
                {
                    declList = ((AASourceFile)parent).GetDecl();
                }
                else
                {
                    declList = ((ANamespaceDecl)parent).GetDecl();
                }
                //AASourceFile pFile = (AASourceFile) str.Parent();
                foreach (AGenericType refference in pair.Value)
                {
                    AStructDecl clone   = null;
                    bool        addList = true;
                    foreach (List <PType> list in copies[str])
                    {
                        bool listEqual = true;
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (!Util.TypesEqual(list[i], (PType)refference.GetGenericTypes()[i], data))
                            {
                                listEqual = false;
                                break;
                            }
                        }
                        if (listEqual)
                        {
                            addList = false;
                            clone   = clones[list];
                            break;
                        }
                    }
                    if (addList)
                    {
                        List <PType> list = new List <PType>();
                        foreach (PType type in refference.GetGenericTypes())
                        {
                            list.Add(type);
                        }
                        copies[str].Add(list);

                        clone = (AStructDecl)str.Clone();
                        declList.Insert(declList.IndexOf(str), clone);


                        clone.Apply(new EnviromentBuilding(errors, data));
                        clone.Apply(new EnviromentChecking(errors, data, false));
                        clone.Apply(new LinkNamedTypes(errors, data));

                        /*
                         * data.Structs.Add(new SharedData.DeclItem<AStructDecl>(pFile, clone));
                         * data.StructFields[clone] = new List<AALocalDecl>();
                         * data.StructMethods[clone] = new List<AMethodDecl>();
                         * data.StructProperties[clone] = new List<APropertyDecl>();
                         * data.StructConstructors[clone] = new List<AConstructorDecl>();
                         * foreach (PLocalDecl localDecl in clone.GetLocals())
                         * {
                         *  if (localDecl is AALocalDecl)
                         *  {
                         *      data.StructFields[clone].Add((AALocalDecl)localDecl);
                         *  }
                         *  else
                         *  {
                         *      PDecl decl = ((ADeclLocalDecl) localDecl).GetDecl();
                         *      if (decl is AMethodDecl)
                         *      {
                         *          data.StructMethods[clone].Add((AMethodDecl) decl);
                         *      }
                         *      else if (decl is APropertyDecl)
                         *      {
                         *          data.StructProperties[clone].Add((APropertyDecl)decl);
                         *      }
                         *      else
                         *      {
                         *          data.StructConstructors[clone].Add((AConstructorDecl) decl);
                         *      }
                         *  }
                         * }*/

                        clones[list] = clone;


                        clone.setGenericVars(new ArrayList());

                        FixGenericLinks.Parse(str, clone, list, data);
                        clone.GetName().Text = Util.TypeToIdentifierString(refference);
                    }
                    //Change refference to clone
                    ANamedType    baseRef = (ANamedType)refference.GetBase();
                    List <string> cloneNs = Util.GetFullNamespace(clone);
                    cloneNs.Add(clone.GetName().Text);
                    AAName aName = (AAName)baseRef.GetName();
                    aName.GetIdentifier().Clear();
                    foreach (var n in cloneNs)
                    {
                        aName.GetIdentifier().Add(new TIdentifier(n));
                    }
                    data.StructTypeLinks[baseRef] = clone;
                    refference.ReplaceBy(baseRef);
                }

                if (!needAnotherPass)
                {
                    parent.RemoveChild(str);
                }
            }
            if (needAnotherPass)
            {
                Refferences.Clear();
                structsWithGenerics.Clear();
                needAnotherPass = false;
                CaseAAProgram(node);
            }
        }