Esempio n. 1
0
        public string GenerateIntrinsic(bool caching)
        {
            StringBuilder sb         = new StringBuilder();
            string        nl         = (caching) ? "" : "\r\n";
            char          semi       = ';';
            string        tab0       = (!caching && InFile.Version == 3) ? "\t" : "";
            string        tab        = (caching) ? "" : ((InFile.Version == 3) ? "\t\t" : "\t");
            bool          preventVis = (bool)((this.Flags & FlagType.Interface) > 0);

            // SPECIAL DELEGATE

            /*if ((Flags & FlagType.Delegate) > 0)
             * {
             *  if (Members.Count > 0)
             *  {
             *      MemberModel ctor = Members[0].Clone() as MemberModel;
             *      ctor.Flags |= FlagType.Delegate;
             *      ctor.Access = Access;
             *      String comment = CommentDeclaration(ctor.Comments, tab0);
             *      sb.Append(comment);
             *      sb.Append(tab0).Append(MemberDeclaration(ctor, preventVis)).Append(semi).Append(nl);
             *      return sb.ToString();
             *  }
             * }*/

            // CLASS
            sb.Append(CommentDeclaration(Comments, tab0)).Append(tab0);
            if (!caching && InFile.Version != 3 && (this.Flags & (FlagType.Intrinsic | FlagType.Interface)) == 0)
            {
                sb.Append((InFile.haXe) ? "extern " : "intrinsic ");
            }
            sb.Append(ClassDeclaration(this, InFile.Version < 3));

            if (ExtendsType != null)
            {
                if ((this.Flags & FlagType.Abstract) > 0)
                {
                    sb.Append(" from ").Append(ExtendsType);
                }
                else
                {
                    sb.Append(" extends ").Append(ExtendsType);
                }
            }
            if (Implements != null)
            {
                sb.Append(" implements ");
                bool addSep = false;
                foreach (string iname in Implements)
                {
                    if (addSep)
                    {
                        sb.Append(", ");
                    }
                    else
                    {
                        addSep = true;
                    }
                    sb.Append(iname);
                }
            }
            sb.Append(nl).Append(tab0).Append('{');

            // MEMBERS
            int count = 0;

            foreach (MemberModel var in Members)
            {
                if ((var.Flags & FlagType.Variable) > 0)
                {
                    ASMetaData.GenerateIntrinsic(var.MetaDatas, sb, nl, tab);
                    String comment = CommentDeclaration(var.Comments, tab);
                    if (count == 0 || comment != "")
                    {
                        sb.Append(nl);
                    }
                    sb.Append(comment);
                    sb.Append(tab).Append(MemberDeclaration(var, preventVis)).Append(semi).Append(nl);
                    count++;
                }
            }

            // MEMBERS
            string      decl;
            MemberModel temp;
            string      prevProperty = null;

            foreach (MemberModel property in Members)
            {
                if ((property.Flags & (FlagType.Getter | FlagType.Setter)) > 0)
                {
                    if (prevProperty != property.Name)
                    {
                        sb.Append(nl);
                    }
                    prevProperty = property.Name;
                    ASMetaData.GenerateIntrinsic(property.MetaDatas, sb, nl, tab);
                    sb.Append(CommentDeclaration(property.Comments, tab));
                    FlagType flags = (property.Flags & ~(FlagType.Setter | FlagType.Getter)) | FlagType.Function;

                    if ((property.Flags & FlagType.Getter) > 0)
                    {
                        temp            = (MemberModel)property.Clone();
                        temp.Name       = "get " + temp.Name;
                        temp.Flags      = flags;
                        temp.Parameters = null;

                        string memberDecl = MemberDeclaration(temp, preventVis);

                        // Typed callback declaration (in get property)
                        if ((property.Flags & FlagType.Function) > 0)
                        {
                            string commentDecl = property.ToDeclarationString();
                            int    idxA        = Math.Max(memberDecl.LastIndexOf(":"), memberDecl.LastIndexOf(")") + 1);
                            int    idxB        = Math.Min(commentDecl.IndexOf(":"), commentDecl.IndexOf("/*"));

                            if (idxA > 0 && idxB > -1)
                            {
                                memberDecl = memberDecl.Substring(0, idxA) + commentDecl.Substring(idxB);
                            }
                        }

                        sb.Append(tab).Append(memberDecl).Append(semi).Append(nl);
                    }
                    if ((property.Flags & FlagType.Setter) > 0)
                    {
                        temp       = (MemberModel)property.Clone();
                        temp.Name  = "set " + temp.Name;
                        temp.Flags = flags;
                        temp.Type  = (InFile.Version == 3) ? "void" : "Void";
                        sb.Append(tab).Append(MemberDeclaration(temp, preventVis)).Append(semi).Append(nl);
                    }
                }
            }

            // MEMBERS
            foreach (MemberModel method in Members)
            {
                if ((method.Flags & FlagType.Function) > 0 && (method.Flags & FlagType.Variable) == 0 && (method.Flags & FlagType.Getter) == 0)
                {
                    decl = MemberDeclaration(method, preventVis);
                    if (InFile.haXe && (method.Flags & FlagType.Constructor) > 0)
                    {
                        decl = decl.Replace("function " + method.Name, "function new");
                    }
                    ASMetaData.GenerateIntrinsic(method.MetaDatas, sb, nl, tab);
                    sb.Append(nl).Append(CommentDeclaration(method.Comments, tab));
                    sb.Append(tab).Append(decl).Append(semi).Append(nl);
                }
            }

            // END CLASS
            sb.Append(tab0).Append('}');
            return(sb.ToString());
        }
Esempio n. 2
0
        public string GenerateIntrinsic(bool caching)
        {
            if (this == Ignore)
            {
                return("");
            }

            StringBuilder sb   = new StringBuilder();
            string        nl   = (caching) ? "" : "\r\n";
            char          semi = ';';
            string        tab  = (caching) ? "" : "\t";

            // header
            if (Version > 2)
            {
                sb.Append("package");
                if (Package.Length > 0)
                {
                    sb.Append(" ").Append(Package);
                }
                if (haXe)
                {
                    sb.Append(semi).Append(nl).Append(nl);
                }
                else
                {
                    sb.Append(nl).Append("{").Append(nl);
                }
            }

            // imports
            if (Imports.Count > 0)
            {
                foreach (MemberModel import in Imports)
                {
                    sb.Append(tab).Append("import ").Append(import.Type).Append(semi).Append(nl);
                }
                sb.Append(nl);
            }

            // event/style metadatas
            ASMetaData.GenerateIntrinsic(MetaDatas, sb, nl, tab);

            // members
            string decl;

            foreach (MemberModel member in Members)
            {
                ASMetaData.GenerateIntrinsic(member.MetaDatas, sb, nl, tab);
                if ((member.Flags & FlagType.Variable) > 0)
                {
                    sb.Append(ClassModel.CommentDeclaration(member.Comments, tab));
                    sb.Append(tab).Append(ClassModel.MemberDeclaration(member)).Append(semi).Append(nl);
                }
                else if ((member.Flags & FlagType.Function) > 0)
                {
                    decl = ClassModel.MemberDeclaration(member);
                    sb.Append(ClassModel.CommentDeclaration(member.Comments, tab));
                    sb.Append(tab).Append(decl).Append(semi).Append(nl);
                }
            }

            foreach (ClassModel aClass in Classes)
            {
                sb.Append(aClass.GenerateIntrinsic(caching));
                sb.Append(nl);
            }

            if (Version == 3)
            {
                sb.Append('}').Append(nl);
            }
            return(sb.ToString());
        }