Beispiel #1
0
        private static void ParseTopLevel(XmlNode node)
        {
            BlockModel block = new BlockModel();

            block.Name = "";
            //block.Decl = "package";
            foreach (XmlNode part in node.ChildNodes)
            {
                ParseTopLevelPart(part, block);
            }

            RegisterBlock(block);
        }
Beispiel #2
0
        private static void ParseProperties(XmlNode part, BlockModel block)
        {
            foreach (XmlNode node in part.ChildNodes)
            {
                PropertyModel model = new PropertyModel();
                model.Name = GetAttribute(node, "name");
                string text = GetAttribute(node, "text");
                if (GetAttribute(node, "constant") == "true")
                {
                    model.Kind = "const";
                }

                model.Comment = FixComment(GetAttribute(node, "tiptext"));
                block.Properties.Add(model);
            }
        }
Beispiel #3
0
        private static void ParsePart(XmlNode part, BlockModel block)
        {
            string id = GetAttribute(part, "id");

            if (id == "Methods")
            {
                ParseMethods(part, block);
            }
            else if (id == "Properties")
            {
                ParseProperties(part, block);
            }
            else if (id == "Events")
            {
                ParseEvents(part, block);
            }
            else
            {
                ParseClass(part, block);
            }
        }
Beispiel #4
0
        private static void ParseClass(XmlNode node, BlockModel parentBlock)
        {
            BlockModel block = new BlockModel();

            block.Name = GetAttribute(node, "name");
            string ext = GetAttribute(node, "asAncestors");

            if (ext.Length > 0 && ext != "Object")
            {
                ext = " extends " + ext.Split(',')[0].Replace(':', '.');
            }
            else
            {
                ext = "";
            }
            block.Comment = FixComment(GetAttribute(node, "tiptext"));

            foreach (XmlNode part in node.ChildNodes)
            {
                ParsePart(part, block);
            }

            parentBlock.Blocks.Add(block);
        }
Beispiel #5
0
        private static void ParseEvents(XmlNode part, BlockModel block)
        {
            foreach (XmlNode node in part.ChildNodes)
            {
                EventModel model = new EventModel();
                model.Name   = GetAttribute(node, "name");
                model.IsAIR  = GetAttribute(node, "playername").Trim() == "AIR" || GetAttribute(node, "version").Trim() == "1.0";
                model.IsFP10 = GetAttribute(node, "version").Trim() == "1.5";

                string temp = GetAttribute(node, "text");
                int    p    = temp.IndexOf("%type:String=");
                if (p > 0)
                {
                    temp            = temp.Substring(p + 13);
                    model.EventType = "flash.events." + temp.Substring(0, temp.IndexOf('{'));
                }
                else
                {
                    model.EventType = "???";
                }
                model.Comment = FixComment(GetAttribute(node, "tiptext"));
                block.Events.Add(model);
            }
        }
Beispiel #6
0
 private static void ParseMethods(XmlNode part, BlockModel block)
 {
     foreach (XmlNode node in part.ChildNodes)
     {
         MethodModel model = new MethodModel();
         model.Name = GetAttribute(node, "name");
         string text = GetAttribute(node, "text");
         int    p    = text.IndexOf("):");
         if (p > 0)
         {
             model.ReturnType = text.Substring(p + 2);
         }
         else if (model.Name != block.Name)
         {
             model.ReturnType = "void";
         }
         text          = text.Substring(text.IndexOf('%') + 1);
         text          = text.Substring(0, text.LastIndexOf('%'));
         model.Params  = text;
         model.Comment = FixComment(GetAttribute(node, "tiptext"));
         model.FixParams();
         block.Methods.Add(model);
     }
 }
Beispiel #7
0
 private static void ParsePart(XmlNode part, BlockModel block)
 {
     string id = GetAttribute(part, "id");
     if (id == "Methods") ParseMethods(part, block);
     else if (id == "Properties") ParseProperties(part, block);
     else if (id == "Events") ParseEvents(part, block);
     else ParseClass(part, block);
 }
Beispiel #8
0
        private static void ParsePackage(XmlNode node, string package)
        {
            if (package.StartsWith("fl.")) 
                return;
            foreach (XmlNode part in node.ChildNodes)
            {
                BlockModel block = new BlockModel();
                block.Name = package;
                //block.Decl = "package " + package;

                ParsePart(part, block);
                
                // MANUAL FIX FOR SPECIAL CASES
                if (package == "flash.utils" && block.Blocks.Count == 0)
                {
                    PropertyModel ns = new PropertyModel();
                    ns.Kind = "namespace";
                    ns.Name = "flash_proxy";
                    ns.Comment = "Proxy methods namespace";
                    block.Properties.Insert(0, ns);
                }

                RegisterBlock(block);
            }
        }
Beispiel #9
0
 private static void ParseTopLevelPart(XmlNode part, BlockModel block)
 {
     string id = GetAttribute(part, "id");
     if (id == "Global Functions")
     {
         ParseMethods(part, block);
         List<MethodModel> methods = new List<MethodModel>();
         foreach (MethodModel method in block.Methods)
         {
             // ignore convertion methods
             if (method.Name != method.ReturnType && method.Name != "Vector")
             {
                 methods.Add(method);
             }
         }
         block.Methods = methods;
     }
     else if (id == "Global Constants")
     {
         ParseProperties(part, block);
         foreach (PropertyModel prop in block.Properties)
         {
             prop.Kind = "var";
         }
     }
 }
Beispiel #10
0
        private static void ParseTopLevel(XmlNode node)
        {
            BlockModel block = new BlockModel();
            block.Name = "";
            //block.Decl = "package";
            foreach (XmlNode part in node.ChildNodes)
                ParseTopLevelPart(part, block);

            RegisterBlock(block);
        }
Beispiel #11
0
        private static void RegisterBlock(BlockModel block)
        {
            if (block.Blocks.Count > 0)
            {
                BlockModel classBlock = block.Blocks[0];
                types.Add((block.Name.Length > 0 ? block.Name + "." : "") + classBlock.Name, block);

                // MANUAL FIX Vector.join
                if (classBlock.Name == "Vector")
                {
                    classBlock.Methods.ForEach(method => 
                    {
                        if (method.Name == "join")
                            method.Params = method.Params.Replace("= ,", "= \",\"");
                    });
                }
            }
            else if (block.Methods.Count != 0 || block.Properties.Count != 0)
            {
                // MANUAL FIX flah.net package
                if (block.Name == "flash.net")
                {
                    block.Imports = new List<string>();
                    block.Imports.Add("flash.net.URLRequest");
                    block.Methods.ForEach(method =>
                    {
                        method.Params = method.Params.Replace("flash.net.URLRequest", "URLRequest");
                    });
                }
                types[block.Name + ".*"] = block;
            }
        }
Beispiel #12
0
 private static void AddDocumentation(MemberList members, BlockModel docModel)
 {
     AddDocComments(members, docModel.Properties.ToArray());
     AddDocComments(members, docModel.Methods.ToArray());
 }
Beispiel #13
0
        private static void ParseEvents(XmlNode part, BlockModel block)
        {
            foreach (XmlNode node in part.ChildNodes)
            {
                EventModel model = new EventModel();
                model.Name = GetAttribute(node, "name");
                model.IsAIR = GetAttribute(node, "playername").Trim() == "AIR" || GetAttribute(node, "version").Trim() == "1.0";
                model.IsFP10 = GetAttribute(node, "version").Trim() == "1.5";

                string temp = GetAttribute(node, "text");
                int p = temp.IndexOf("%type:String=");
                if (p > 0)
                {
                    temp = temp.Substring(p + 13);
                    model.EventType = "flash.events." + temp.Substring(0, temp.IndexOf('{'));
                }
                else model.EventType = "???";
                model.Comment = FixComment(GetAttribute(node, "tiptext"));
                block.Events.Add(model);
            }
        }
Beispiel #14
0
 private static void ParseMethods(XmlNode part, BlockModel block)
 {
     foreach (XmlNode node in part.ChildNodes)
     {
         MethodModel model = new MethodModel();
         model.Name = GetAttribute(node, "name");
         string text = GetAttribute(node, "text");
         int p = text.IndexOf("):");
         if (p > 0) model.ReturnType = text.Substring(p + 2);
         else if (model.Name != block.Name) model.ReturnType = "void";
         text = text.Substring(text.IndexOf('%') + 1);
         text = text.Substring(0, text.LastIndexOf('%'));
         model.Params = text;
         model.Comment = FixComment(GetAttribute(node, "tiptext"));
         model.FixParams();
         block.Methods.Add(model);
     }
 }
Beispiel #15
0
        private static void AddEvents(FileModel aFile, BlockModel docModel, bool targetAIR, bool targetFP10)
        {
            aFile.MetaDatas = new List<ASMetaData>();
            foreach (EventModel ev in docModel.Events)
            {
                if (!targetAIR && ev.IsAIR) continue;
                if (!targetFP10 && ev.IsFP10) continue;

                int p = ev.EventType.LastIndexOf('.');
                string type = ev.EventType.Substring(0, p);
                string pname = ev.EventType.Substring(p + 1);
                ClassModel eClass = getClass(type);
                if (eClass.IsVoid()) continue;
                string value = '"' + ev.Name + '"';
                if (eClass.Members.Items.Any<MemberModel>(item => item.Name == pname))
                {
                    ASMetaData meta = new ASMetaData("Event");
                    if (ev.Comment != null)
                        meta.Comments = "\r\n\t * " + ev.Comment + "\r\n\t * @eventType " + ev.EventType;
                    meta.ParseParams(String.Format("name=\"{0}\", type=\"{1}\"", ev.Name, type));
                    aFile.MetaDatas.Add(meta);
                }
            }
        }
Beispiel #16
0
        private static void ParseProperties(XmlNode part, BlockModel block)
        {
            foreach (XmlNode node in part.ChildNodes)
            {
                PropertyModel model = new PropertyModel();
                model.Name = GetAttribute(node, "name");
                string text = GetAttribute(node, "text");
                if (GetAttribute(node, "constant") == "true") model.Kind = "const";

                model.Comment = FixComment(GetAttribute(node, "tiptext"));
                block.Properties.Add(model);
            }
        }
Beispiel #17
0
 private static void AddDocumentation(MemberList members, BlockModel docModel)
 {
     AddDocComments(members, docModel.Properties.ToArray());
     AddDocComments(members, docModel.Methods.ToArray());
 }
Beispiel #18
0
        private static void ParseClass(XmlNode node, BlockModel parentBlock)
        {
            BlockModel block = new BlockModel();
            block.Name = GetAttribute(node, "name");
            string ext = GetAttribute(node, "asAncestors");
            if (ext.Length > 0 && ext != "Object") ext = " extends " + ext.Split(',')[0].Replace(':', '.');
            else ext = "";
            block.Comment = FixComment(GetAttribute(node, "tiptext"));

            foreach (XmlNode part in node.ChildNodes)
                ParsePart(part, block);

            parentBlock.Blocks.Add(block);
        }
Beispiel #19
0
        private static void GenerateIntrinsics(string dir, PathModel pathModel, bool targetAIR, bool targetFP10)
        {
            currentClassPath = pathModel;
            foreach (FileModel aFile in pathModel.Files.Values)
            {
                if (aFile.Package == "private")
                {
                    continue;
                }

                ClassModel aClass = aFile.GetPublicClass();
                string     type;
                string     fileName;
                string     src;

                // package-level declarations
                if (aClass.IsVoid())
                {
                    // MANUAL FIX toplevel
                    if (aFile.Package.Length == 0)
                    {
                        // clear inconsistent (although valid) default values
                        aFile.Members.Items
                        .FindAll(member => member.Parameters != null && member.Parameters.Count == 1)
                        .ForEach(member => member.Parameters[0].Value = null);

                        if (aFile.Members.Search("trace", 0, 0) == null)
                        {
                            MemberModel member = new MemberModel("trace", "String", FlagType.Function, Visibility.Public);
                            member.Parameters = new List <MemberModel>();
                            member.Parameters.Add(new MemberModel("...rest", null, 0, 0));
                            aFile.Members.Add(member);
                        }
                    }

                    type = aFile.Package + ".*";
                    aFile.Members.Sort();
                    if (types.Keys.Contains <string>(type))
                    {
                        BlockModel docModel = types[type];
                        AddDocumentation(aFile.Members, docModel);
                    }
                    fileName = (aFile.Package.Length == 0) ? "toplevel" : aFile.Package + ".package";
                    fileName = Path.Combine(Path.Combine("out", dir),
                                            fileName.Replace('.', Path.DirectorySeparatorChar)) + ".as";

                    src = CompactSrc(aFile.GenerateIntrinsic(false));
                    src = src.Replace(";\r\n", ";\r\n\r\n");
                    if (generated.ContainsKey(type) && generated[type] == src)
                    {
                        continue;
                    }
                    else
                    {
                        generated[type] = src;
                    }
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                    File.WriteAllText(fileName, src /*, Encoding.UTF8*/);
                    continue;
                }

                // class declaration
                aFile.Members.Sort();
                aClass.Members.Sort();

                type     = aClass.QualifiedName;
                fileName = Path.Combine(Path.Combine("out", dir),
                                        type.Replace('.', Path.DirectorySeparatorChar)) + ".as";

                // removing non-public members
                if ((aClass.Flags & FlagType.Interface) == 0)
                {
                    aClass.Members.Items
                    .RemoveAll(member => member.Access != Visibility.Public);
                }
                // removing AIR members
                if (dir != "AIR")
                {
                    aClass.Members.Items
                    .RemoveAll(member => member.Comments != null && member.Comments.StartsWith("[AIR]"));
                }

                // MANUAL FIX event consts' values
                if (aFile.Package == "flash.events" || aFile.Package == "mx.events")
                {
                    aClass.Members.Items
                    .FindAll(member => (member.Flags & FlagType.Constant) > 0 && member.Type == "String" &&
                             Char.IsUpper(member.Name[0]) && member.Name != "VERSION")
                    .ForEach(member => member.Value = '"' + BaseModel.Camelize(member.Name) + '"');
                }

                // MANUAL FIX MovieClip.addFrameScript
                if (aClass.QualifiedName == "flash.display.MovieClip")
                {
                    MemberModel member = aClass.Members.Search("addFrameScript", 0, 0);
                    if (member != null)
                    {
                        member.Comments   = "[Undocumented] Takes a collection of frame (zero-based) - method pairs that associates a method with a frame on the timeline.";
                        member.Parameters = new List <MemberModel>();
                        member.Parameters.Add(new MemberModel("frame", "int", 0, 0));
                        member.Parameters.Add(new MemberModel("method", "Function", 0, 0));
                    }
                }

                // MANUAL FIX Sprite.toString (needed for override)
                if (aClass.QualifiedName == "flash.display.Sprite")
                {
                    if (aClass.Members.Search("toString", 0, 0) == null)
                    {
                        aClass.Members.Add(new MemberModel("toString", "String", FlagType.Function, Visibility.Public));
                    }
                }

                // MANUAL FIX Math
                if (aClass.QualifiedName == "Math")
                {
                    MemberModel member = aClass.Members.Search("atan2", 0, 0);
                    if (member != null)
                    {
                        member.Parameters[0].Name = "y";
                        member.Parameters[1].Name = "x";
                    }
                }

                // MANUAL FIX Object
                if (aClass.QualifiedName == "Object")
                {
                    if (aClass.Members.Search("toString", 0, 0) == null)
                    {
                        aClass.Members.Add(new MemberModel("toString", "String", FlagType.Function, Visibility.Public));
                    }
                    if (aClass.Members.Search("valueOf", 0, 0) == null)
                    {
                        aClass.Members.Add(new MemberModel("valueOf", "Object", FlagType.Function, Visibility.Public));
                    }
                    if (aClass.Members.Search("setPropertyIsEnumerable", 0, 0) == null)
                    {
                        MemberModel member = new MemberModel("setPropertyIsEnumerable", "void", FlagType.Function, Visibility.Public);
                        member.Parameters = new List <MemberModel>();
                        member.Parameters.Add(new MemberModel("name", "String", 0, 0));
                        member.Parameters.Add(new MemberModel("isEnum", "Boolean", 0, 0));
                        member.Parameters[1].Value = "true";
                        aClass.Members.Add(member);
                    }
                }

                // MANUAL FIX Proxy
                // TODO  Need to check ABC parser for specific namespaces
                if (aClass.QualifiedName == "flash.utils.Proxy")
                {
                    aClass.Members.Items.ForEach(member => member.Namespace = "flash_proxy");
                }

                // MANUAL FIX Array
                if (aClass.QualifiedName == "Array")
                {
                    MemberModel member = aClass.Members.Search("slice", 0, 0);
                    if (member != null)
                    {
                        member.Parameters[0].Name = "startIndex";
                        member.Parameters[1].Name = "endIndex";
                    }
                    member = aClass.Members.Search("splice", 0, 0);
                    if (member != null)
                    {
                        member.Parameters = new List <MemberModel>();
                        member.Parameters.Add(new MemberModel("startIndex", "int", 0, 0));
                        member.Parameters.Add(new MemberModel("deleteCount", "uint", 0, 0));
                        member.Parameters.Add(new MemberModel("...values", "", 0, 0));
                        member.Type = "Array";
                    }
                    member = aClass.Members.Search("sort", 0, 0);
                    if (member != null)
                    {
                        member.Type = "Array";
                    }
                    member = aClass.Members.Search("sortOn", 0, 0);
                    if (member != null)
                    {
                        member.Type = "Array";
                    }
                    member = aClass.Members.Search("length", FlagType.Constant, 0); // static const length WTF
                    if (member != null)
                    {
                        aClass.Members.Remove(member);
                    }
                }

                // adding comments extracted from XML
                if (types.Keys.Contains <string>(type))
                {
                    BlockModel docModel = types[type];
                    aClass.Comments = docModel.Blocks[0].Comment;
                    AddDocumentation(aFile.Members, docModel);
                    AddDocumentation(aClass.Members, docModel.Blocks[0]);
                    AddEvents(aFile, docModel.Blocks[0], targetAIR, targetFP10);
                }

                src = CompactSrc(aFile.GenerateIntrinsic(false));
                if (generated.ContainsKey(type) && generated[type] == src)
                {
                    continue;
                }
                else
                {
                    generated[type] = src;
                }
                Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                File.WriteAllText(fileName, src /*, Encoding.UTF8*/);
            }
        }