Example #1
0
 public PathExplorer(IASContext context, PathModel pathModel)
 {
     this.context = context;
     this.pathModel = pathModel;
     hashName = pathModel.Path;
     foundFiles = new List<string>();
     explored = new List<string>();
 }
Example #2
0
        static public void ParseCacheFile(PathModel inPath, string file, IASContext inContext)
		{
            lock (typeof(ASFileParser))
            {
                cachedPath = inPath;
                ParseFile(file, inContext);
                cachedPath = null;
            }
		}
 public PathExplorer(IASContext context, PathModel pathModel)
 {
     this.context = context;
     this.pathModel = pathModel;
     hashName = pathModel.Path;
     hiddenPackagePrefix = context.Features.hiddenPackagePrefix;
     foundFiles = new List<string>();
     explored = new List<string>();
 }
Example #4
0
 public PathExplorer(IASContext context, PathModel pathModel)
 {
     this.context = context;
     this.pathModel = pathModel;
     foundFiles = new List<string>();
     explored = new List<string>();
     if (context.Settings.LanguageId == "AS2")
     {
         explored.Add(Path.Combine(pathModel.Path, "aso"));
         explored.Add(Path.Combine(pathModel.Path, "FP7"));
         explored.Add(Path.Combine(pathModel.Path, "FP8"));
         explored.Add(Path.Combine(pathModel.Path, "FP9"));
     }
 }
Example #5
0
        /// <summary>
        /// Retrieve a PathModel from the cache or create a new one
        /// </summary>
        /// <param name="path"></param>
        /// <param name="context">Associated language context</param>
        /// <returns></returns>
        static public PathModel GetModel(string path, IASContext context)
        {
            if (context == null || context.Settings == null) 
                return null;

            string modelName = context.Settings.LanguageId + "|" + path.ToUpper();
            PathModel aPath;
            if (pathes.ContainsKey(modelName))
            {
                aPath = pathes[modelName] as PathModel;
                if (aPath.IsTemporaryPath || !aPath.IsValid || aPath.FilesCount == 0)
                {
                    pathes[modelName] = aPath = new PathModel(path, context);
                }
                else aPath.Touch();
            }
            else pathes[modelName] = aPath = new PathModel(path, context);
            return aPath;
        }
Example #6
0
 static public void Parse(PathModel path, Context context)
 {
     LibParser inst = new LibParser(path, context);
     inst.Run();
 }
Example #7
0
 private static PathModel ParseSWC(string swcFile)
 {
     PathModel path = new PathModel(System.IO.Path.GetFullPath(swcFile), context);
     if (!File.Exists(swcFile))
     {
         Console.WriteLine("Error: missing {0}, copy Flex SDK's lib directory", swcFile);
         return path;
     }
     SwfOp.ContentParser parser = new SwfOp.ContentParser(path.Path);
     parser.Run();
     AbcConverter.Convert(parser.Abcs, path, context);
     return path;
 }
Example #8
0
 private ClassModel LocateClassFile(PathModel aPath, string fileName)
 {
     if (!aPath.IsValid) return null;
     try
     {
         string path = Path.Combine(aPath.Path, fileName);
         // cached file
         if (aPath.HasFile(path))
         {
             FileModel nFile = aPath.GetFile(path);
             if (nFile.Context != this)
             {
                 // not associated with this context -> refresh
                 nFile.OutOfDate = true;
                 nFile.Context = this;
             }
             return nFile.GetPublicClass();
         }
         // non-cached existing file
         else if (File.Exists(path))
         {
             FileModel nFile = GetFileModel(path);
             if (nFile != null)
             {
                 aPath.AddFile(nFile);
                 return nFile.GetPublicClass();
             }
         }
     }
     catch (Exception ex)
     {
         aPath.IsValid = false;
         ErrorManager.ShowError(ex);
     }
     return null;
 }
Example #9
0
        /// <summary>
        /// Create virtual FileModel objects from Abc bytecode
        /// </summary>
        /// <param name="abcs"></param>
        /// <param name="path"></param>
        /// <param name="context"></param>
        public static void Convert(ContentParser parser, PathModel path, IASContext context)
        {
            inSWF = Path.GetExtension(path.Path).ToLower() == ".swf";

            // extract documentation
            ParseDocumentation(parser);

            // extract models
            Dictionary<string, FileModel> models = new Dictionary<string, FileModel>();
            FileModel privateClasses = new FileModel(Path.Combine(path.Path, "__Private.as"));
            privateClasses.Version = 3;
            privateClasses.Package = "private";
            genericTypes = new Dictionary<string, FileModel>();
            imports = new Dictionary<string, string>();
            conflicts = new Dictionary<string, string>();

            foreach (Abc abc in parser.Abcs)
            {
                // types
                foreach (Traits trait in abc.classes)
                {
                    Traits instance = trait.itraits;
                    if (instance == null)
                        continue;
                    imports.Clear();
                    conflicts.Clear();

                    FileModel model = new FileModel("");
                    model.Context = context;
                    model.Package = reSafeChars.Replace(instance.name.uri, "_");
                    model.HasPackage = true;
                    string filename = reSafeChars.Replace(trait.name.ToString(), "_").TrimEnd('$');
                    filename = Path.Combine(model.Package.Replace('.', Path.DirectorySeparatorChar), filename);
                    model.FileName = Path.Combine(path.Path, filename);
                    model.Version = 3;

                    ClassModel type = new ClassModel();
                    model.Classes = new List<ClassModel>();
                    model.Classes.Add(type);

                    type.InFile = model;
                    type.Type = instance.name.ToTypeString();
                    type.Name = instance.name.localName;
                    type.Flags = FlagType.Class;
                    conflicts.Add(type.Name, type.QualifiedName);

                    if (instance.flags == TraitMember.Function)
                        type.Flags |= FlagType.Interface;

                    thisDocs = GetDocs(model.Package);
                    if (thisDocs != null)
                    {
                        docPath = (model.Package.Length > 0 ? model.Package + ":" : "globalClassifier:") + type.Name;
                        if (thisDocs.ContainsKey(docPath))
                        {
                            ASDocItem doc = thisDocs[docPath];
                            applyASDoc(doc, type);
                            if (doc.Meta != null) model.MetaDatas = doc.Meta;
                        }
                        if (model.Package.Length == 0) docPath = type.Name;
                    }

                    if (instance.baseName.uri == model.Package)
                        type.ExtendsType = ImportType(instance.baseName.localName);
                    else type.ExtendsType = ImportType(instance.baseName);

                    if (instance.interfaces != null && instance.interfaces.Length > 0)
                    {
                        type.Implements = new List<string>();
                        foreach (QName name in instance.interfaces)
                            type.Implements.Add(ImportType(name));
                    }

                    if (model.Package == "private")
                    {
                        model.Package = "";
                        type.Access = Visibility.Private;
                        type.Namespace = "private";
                    }
                    else if (model.Package == "__AS3__.vec")
                    {
                        model.Package = "";
                        type.Access = Visibility.Private;
                        type.Namespace = "private";
                        string genType = type.Name;
                        if (type.Name.IndexOf("$") > 0)
                        {
                            string[] itype = type.Name.Split('$');
                            genType = itype[0];
                            type.Name = itype[0] + "$" + itype[1];
                            type.IndexType = itype[1];
                        }
                        if (genericTypes.ContainsKey(genType))
                        {
                            model.Classes.Clear();
                            type.InFile = genericTypes[genType];
                            genericTypes[genType].Classes.Add(type);
                        }
                        else genericTypes[genType] = model;
                    }
                    else if (type.Name.StartsWith("_"))
                    {
                        type.Access = Visibility.Private;
                        type.Namespace = "private";
                    }
                    else
                    {
                        type.Access = Visibility.Public;
                        type.Namespace = "public";
                    }

                    type.Members = GetMembers(trait.members, FlagType.Static, instance.name);
                    type.Members.Add(GetMembers(instance.members, FlagType.Dynamic, instance.name));

                    if ((type.Flags & FlagType.Interface) > 0)
                    {
                        // TODO properly support interface multiple inheritance
                        type.ExtendsType = null;
                        if (type.Implements != null && type.Implements.Count > 0)
                        {
                            type.ExtendsType = type.Implements[0];
                            type.Implements.RemoveAt(0);
                            if (type.Implements.Count == 0) type.Implements = null;
                        }

                        foreach (MemberModel member in type.Members)
                        {
                            member.Access = Visibility.Public;
                            member.Namespace = "";
                        }
                    }

                    // constructor
                    if (instance.init != null && (type.Flags & FlagType.Interface) == 0)
                    {
                        List<MemberInfo> temp = new List<MemberInfo>(new MemberInfo[] { instance.init });
                        MemberList result = GetMembers(temp, 0, instance.name);
                        if (result.Count > 0)
                        {
                            MemberModel ctor = result[0];
                            ctor.Flags |= FlagType.Constructor;
                            ctor.Access = Visibility.Public;
                            ctor.Type = type.Type;
                            ctor.Namespace = "public";
                            type.Members.Merge(result);
                            type.Constructor = ctor.Name;
                        }
                        result = null;
                        temp = null;
                    }
                    else type.Constructor = type.Name;

                    if (type.Access == Visibility.Private)
                    {
                        model = privateClasses;
                        type.InFile = model;
                    }

                    if (model.Classes.Count > 0 || model.Members.Count > 0)
                    {
                        AddImports(model, imports);
                        models[model.FileName] = model;
                    }
                }

                // packages
                if (abc.scripts == null)
                    continue;
                foreach (Traits trait in abc.scripts)
                {
                    FileModel model = null;
                    foreach (MemberInfo info in trait.members)
                    {
                        if (info.kind == TraitMember.Class)
                            continue;

                        MemberModel member = GetMember(info, 0);
                        if (member == null) continue;

                        if (model == null || model.Package != info.name.uri)
                        {
                            AddImports(model, imports);

                            string package = info.name.uri ?? "";
                            string filename = package.Length > 0 ? "package.as" : "toplevel.as";
                            filename = Path.Combine(package.Replace('.', Path.DirectorySeparatorChar), filename);
                            filename = Path.Combine(path.Path, filename);
                            if (models.ContainsKey(filename))
                                model = models[filename];
                            else
                            {
                                model = new FileModel("");
                                model.Context = context;
                                model.Package = package;
                                model.HasPackage = true;
                                model.FileName = filename;
                                model.Version = 3;
                                models[filename] = model;
                            }
                        }

                        thisDocs = GetDocs(model.Package);
                        if (thisDocs != null)
                        {
                            docPath = "globalOperation:" + (model.Package.Length > 0 ? model.Package + ":" : "")
                                + member.Name;
                            if (member.Access == Visibility.Public && !String.IsNullOrEmpty(member.Namespace)
                                && member.Namespace != "public")
                                docPath += member.Namespace + ":";
                            if ((member.Flags & FlagType.Setter) > 0) docPath += ":set";
                            else if ((member.Flags & FlagType.Getter) > 0) docPath += ":get";

                            if (thisDocs.ContainsKey(docPath)) applyASDoc(thisDocs[docPath], member);
                        }

                        member.InFile = model;
                        member.IsPackageLevel = true;
                        model.Members.Add(member);
                    }

                    AddImports(model, imports);
                }
            }

            if (privateClasses.Classes.Count > 0) models[privateClasses.FileName] = privateClasses;

            // some SWCs need manual fixes
            CustomFixes(path.Path, models);

            // fake SWC (like 'playerglobal_rb.swc', only provides documentation)
            if (models.Keys.Count == 1)
            {
                foreach (FileModel model in models.Values)
                    if (model.GetPublicClass().QualifiedName == "Empty")
                    {
                        models.Clear();
                        break;
                    }
            }

            path.SetFiles(models);
        }
Example #10
0
        protected override bool ExplorePath(PathModel path)
        {
            if (!path.WasExplored && !path.IsVirtual && !path.IsTemporaryPath)
            {
                string haxelib = Path.Combine(path.Path, "haxelib.xml");
                if (File.Exists(haxelib))
                {
                    path.ValidatePackage = true;

                    string src = File.ReadAllText(haxelib);
                    if (src.IndexOf("<project name=\"nme\"") >= 0)
                    {
                        ManualExploration(path, new string[] {
                            "js", "jeash", "neash", "native", "browser", "flash", "neko", "tools", "samples", "project" });
                    }
                }
            }
            return base.ExplorePath(path);
        }
Example #11
0
        private ClassModel LookupClass(string package, string cname, string inPackage, bool testSamePackage, bool testModule, PathModel aPath)
        {
            bool matchParentPackage = testSamePackage && features.hasFriendlyParentPackages;

            ClassModel found = null;
            int pLen = inPackage.Length;

            aPath.ForeachFile((aFile) =>
            {
                string pkg = aFile.Package;
                // qualified path
                if (pkg == package && aFile.Classes.Count > 0)
                {
                    foreach (ClassModel aClass in aFile.Classes)
                        if (aClass.Name == cname && (pkg == "" || aFile.Module == "" || aFile.Module == aClass.Name))
                        {
                            found = aClass;
                            return false;
                        }
                }
                else if (testModule && aFile.FullPackage == package && aFile.Classes.Count > 0)
                {
                    foreach (ClassModel aClass in aFile.Classes)
                        if (aClass.Name == cname)
                        {
                            found = aClass;
                            return false;
                        }
                }
                // in the same (or parent) package
                else if (testSamePackage)
                {
                    if (inPackage == pkg || (matchParentPackage && pkg.Length < pLen && inPackage.StartsWithOrdinal(pkg + ".")))
                        foreach (ClassModel aClass in aFile.Classes)
                            if (aClass.Name == cname /*&& (aFile.Module == "" || aFile.Module == aClass.Name)*/)
                            {
                                found = aClass;
                                return false;
                            }
                }
                return true;
            });
            return found;
        }
Example #12
0
        /// <summary>
        /// Parse a packaged library file
        /// </summary>
        /// <param name="path">Models owner</param>
        public override void ExploreVirtualPath(PathModel path)
        {
            if (path.WasExplored)
            {
                if (MxmlFilter.HasCatalog(path.Path)) MxmlFilter.AddCatalog(path.Path);

                if (path.FilesCount != 0) // already parsed
                    return;
            }

            try
            {
                if (File.Exists(path.Path) && !path.WasExplored)
                {
                    bool isRefresh = path.FilesCount > 0;
                    //TraceManager.AddAsync("parse " + path.Path);
                    lock (path)
                    {
                        path.WasExplored = true;
                        SwfOp.ContentParser parser = new SwfOp.ContentParser(path.Path);
                        parser.Run();
                        AbcConverter.Convert(parser, path, this);
                    }
                    // reset FCSH
                    if (isRefresh)
                    {
                        EventManager.DispatchEvent(this,
                            new DataEvent(EventType.Command, "ProjectManager.RestartFlexShell", path.Path));
                    }
                }
            }
            catch (Exception ex)
            {
                string message = TextHelper.GetString("Info.ExceptionWhileParsing");
                TraceManager.AddAsync(message + " " + path.Path);
                TraceManager.AddAsync(ex.Message);
                TraceManager.AddAsync(ex.StackTrace);
            }
        }
Example #13
0
        private bool OpenVirtualFileModel(string virtualPath)
        {
            int p = virtualPath.IndexOf("::");
            if (p < 0) return false;

            string container = virtualPath.Substring(0, p);
            string ext = Path.GetExtension(container).ToLower();
            if (ext != ".loomlib") return false;
            if (!File.Exists(container)) return false;

            string fileName = Path.Combine(container, virtualPath.Substring(p + 2).Replace('.', Path.DirectorySeparatorChar));
            PathModel path = new PathModel(container, contextInstance);

            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return true;
            }
            return false;
        }
Example #14
0
 private static void CustomFixes(PathModel path)
 {
     string file = Path.GetFileName(path.Path);
     if (file == "playerglobal.swc" || file == "airglobal.swc")
     {
         string mathPath = Path.Combine(path.Path, "Math").ToUpper();
         if (path.HasFile(mathPath))
         {
             ClassModel mathModel = path.GetFile(mathPath).GetPublicClass();
             foreach (MemberModel member in mathModel.Members)
             {
                 if (member.Parameters != null && member.Parameters.Count > 0 && member.Parameters[0].Name == "x")
                 {
                     string n = member.Name;
                     if (member.Parameters.Count > 1)
                     {
                         if (n == "atan2") member.Parameters.Reverse();
                         else if (n == "min" || n == "max") { member.Parameters[0].Name = "val1"; member.Parameters[1].Name = "val2"; }
                         else if (n == "pow") { member.Parameters[0].Name = "base"; member.Parameters[1].Name = "pow"; }
                     }
                     else if (n == "sin" || n == "cos" || n == "tan") member.Parameters[0].Name = "angleRadians";
                     else member.Parameters[0].Name = "val";
                 }
             }
         }
         string objPath = Path.Combine(path.Path, "Object").ToUpper();
         if (path.HasFile(objPath))
         {
             ClassModel objModel = path.GetFile(objPath).GetPublicClass();
             if (objModel.Members.Search("prototype", 0, 0) == null)
             {
                 MemberModel proto = new MemberModel("prototype", "Object", FlagType.Dynamic | FlagType.Variable, Visibility.Public);
                 objModel.Members.Add(proto);
             }
         }
     }
 }
Example #15
0
 private static void ExploreNext()
 {
     if (index >= config.Classpath.Length)
     {
         ForceMXNamespace();
         AddBuiltInTags();
         ExpandInheritance();
         BuildGroups();
         //AddBuiltInEvents(); // FD intrinsics now contain required information
         GenerateDeclarations();
         output.Close();
         log.Close();
         Console.WriteLine("Finished. Press Enter to continue.");
     }
     else
     {
         string path = config.Classpath[index++];
         Log("> " + path);
         pathModel = new PathModel(path, context);
         explorer = new PathExplorer(context, pathModel);
         explorer.Run();
         explorer.OnExplorationDone += new PathExplorer.ExplorationDoneHandler(explorer_OnExplorationDone);
     }
 }
Example #16
0
 /// <summary>
 /// Confirms that the FileModel should be added to the PathModel
 /// - typically classes whose context do not patch the classpath should be ignored
 /// </summary>
 /// <param name="aFile"></param>
 /// <param name="pathModel"></param>
 /// <returns></returns>
 public virtual bool IsModelValid(FileModel aFile, PathModel pathModel)
 {
     return (aFile != null);
 }
Example #17
0
 protected override bool ExplorePath(PathModel path)
 {
     if (!path.WasExplored && !path.IsVirtual && !path.IsTemporaryPath)
     {
         // enable stricter validation for haxelibs which tend to include a lot of unrelated code (samples, templates)
         string haxelib = Path.Combine(path.Path, "haxelib.json");
         if (File.Exists(haxelib))
         {
             path.ValidatePackage = true;
         }
         else
         {
             haxelib = Path.Combine(path.Path, "haxelib.xml");
             if (File.Exists(haxelib))
             {
                 path.ValidatePackage = true;
                 // let's hide confusing packages of NME library
                 string src = File.ReadAllText(haxelib);
                 if (src.IndexOfOrdinal("<project name=\"nme\"") >= 0)
                 {
                     ManualExploration(path, new string[] {
                         "js", "jeash", "neash", "native", "browser", "flash", "neko", "tools", "samples", "project" });
                 }
             }
         }
     }
     return base.ExplorePath(path);
 }
Example #18
0
 /// <summary>
 /// Parse a packaged library file
 /// </summary>
 /// <param name="path">Models owner</param>
 public override void ExploreVirtualPath(PathModel path)
 {
     try
     {
         if (File.Exists(path.Path))
         {
             SwfOp.ContentParser parser = new SwfOp.ContentParser(path.Path);
             parser.Run();
             AbcConverter.Convert(parser, path, this);
         }
     }
     catch (Exception ex)
     {
         string message = TextHelper.GetString("Info.ExceptionWhileParsing");
         TraceManager.AddAsync(message + " " + path.Path);
         TraceManager.AddAsync(ex.Message);
     }
 }
Example #19
0
        private bool OpenVirtualFileModel(string virtualPath)
        {
            int p = virtualPath.IndexOf("::");
            if (p < 0) return false;

            string container = virtualPath.Substring(0, p);
            string ext = Path.GetExtension(container).ToLower();
            if (ext != ".swc" && ext != ".swf")
                return false;
            if (!File.Exists(container))
                return false;

            string fileName = Path.Combine(container, 
                virtualPath.Substring(p + 2).Replace('.', Path.DirectorySeparatorChar));
            PathModel path = new PathModel(container, contextInstance);
            SwfOp.ContentParser parser = new SwfOp.ContentParser(path.Path);
            parser.Run();
            AbcConverter.Convert(parser, path, contextInstance);
            
            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
            }
            return false;
        }
Example #20
0
 /// <summary>
 /// Confirms that the FileModel should be added to the PathModel
 /// - typically classes whose context do not patch the classpath should be ignored
 /// </summary>
 /// <param name="aFile"></param>
 /// <param name="pathModel"></param>
 /// <returns></returns>
 public override bool IsModelValid(FileModel aFile, PathModel pathModel)
 {
     if (!pathModel.ValidatePackage) return true;
     string path = Path.GetDirectoryName(aFile.FileName);
     if (path.StartsWith(pathModel.Path, StringComparison.OrdinalIgnoreCase))
     {
         string package = path.Length <= pathModel.Path.Length ? "" : path.Substring(pathModel.Path.Length + 1).Replace('/', '.').Replace('\\', '.');
         return (aFile.Package == package);
     }
     else return false;
 }
Example #21
0
 private static ClassModel LookupClass(string package, string cname, string inPackage, bool testSamePackage, bool testModule, PathModel aPath)
 {
     ClassModel found = null;
     aPath.ForeachFile((aFile) =>
     {
         // qualified path
         if (aFile.Package == package && aFile.Classes.Count > 0)
         {
             foreach (ClassModel aClass in aFile.Classes)
                 if (aClass.Name == cname && (aFile.Module == "" || aFile.Module == aClass.Name))
                 {
                     found = aClass;
                     return false;
                 }
         }
         else if (testModule && aFile.FullPackage == package && aFile.Classes.Count > 0)
         {
             foreach (ClassModel aClass in aFile.Classes)
                 if (aClass.Name == cname)
                 {
                     found = aClass;
                     return false;
                 }
         }
         // in the same package
         else if (testSamePackage && aFile.Package == inPackage)
         {
             foreach (ClassModel aClass in aFile.Classes)
                 if (aClass.Name == cname && (aFile.Module == "" || aFile.Module == aClass.Name))
                 {
                     found = aClass;
                     return false;
                 }
         }
         return true;
     });
     return found;
 }
Example #22
0
 protected virtual PathModel AddPath(PathModel path)
 {
     // avoid duplicated pathes
     string upath = path.Path.ToUpper();
     foreach(PathModel apath in classPath)
     {
         if (!apath.IsTemporaryPath && apath.Path.ToUpper() == upath)
                 return apath;
     }
     // add new path
     classPath.Add(path);
     return path;
 }
Example #23
0
        /// <summary>
        /// Classpathes & classes cache initialisation
        /// </summary>
        public override void BuildClassPath()
        {
            ReleaseClasspath();
            started = true;
            if (as2settings == null) throw new Exception("BuildClassPath() must be overridden");
            if (contextSetup == null)
            {
                contextSetup = new ContextSetupInfos();
                contextSetup.Lang = settings.LanguageId;
                contextSetup.Platform = "Flash Player";
                contextSetup.Version = as2settings.DefaultFlashVersion + ".0";
            }

            // external version definition
            platform = contextSetup.Platform;
            majorVersion = as2settings.DefaultFlashVersion;
            minorVersion = 0;
            ParseVersion(contextSetup.Version, ref majorVersion, ref minorVersion);

            //
            // Class pathes
            //
            classPath = new List<PathModel>();

            // MTASC
            string mtascPath = PluginBase.CurrentProject != null
                    ? PluginBase.CurrentProject.CurrentSDK
                    : PathHelper.ResolvePath(as2settings.GetDefaultSDK().Path);
            if (Path.GetExtension(mtascPath) != "") mtascPath = Path.GetDirectoryName(mtascPath);

            string path;
            if ((as2settings.UseMtascIntrinsic || String.IsNullOrEmpty(as2settings.MMClassPath))
                && !String.IsNullOrEmpty(mtascPath) && System.IO.Directory.Exists(mtascPath))
            {
                try
                {
                    if (majorVersion == 9)
                    {
                        path = Path.Combine(mtascPath, "std9");
                        if (System.IO.Directory.Exists(path)) AddPath(path);
                        else majorVersion = 8;
                    }
                    if (majorVersion == 8)
                    {
                        path = Path.Combine(mtascPath, "std8");
                        if (System.IO.Directory.Exists(path)) AddPath(path);
                    }
                    path = Path.Combine(mtascPath, "std");
                    if (System.IO.Directory.Exists(path)) AddPath(path);
                }
                catch {}
            }
            // Macromedia/Adobe
            if (!String.IsNullOrEmpty(as2settings.MMClassPath) && System.IO.Directory.Exists(as2settings.MMClassPath))
            {
                if (classPath.Count == 0)
                {
                    // Flash CS3: the FP9 classpath overrides some classes of FP8
                    int tempVersion = majorVersion;
                    if (tempVersion > 8)
                    {
                        path = Path.Combine(as2settings.MMClassPath, "FP" + tempVersion);
                        if (System.IO.Directory.Exists(path))
                            AddPath(path);
                        // now add FP8
                        tempVersion = 8;
                    }
                    path = Path.Combine(as2settings.MMClassPath, "FP" + Math.Max(7, tempVersion));
                    if (System.IO.Directory.Exists(path))
                    {
                        PathModel aPath = new PathModel(path, this);
                        ManualExploration(aPath, new string[] { "aso", "FP7", "FP8", "FP9" });
                        AddPath(aPath);
                    }
                }
            }

            // add external pathes
            List<PathModel> initCP = classPath;
            classPath = new List<PathModel>();
            if (contextSetup.Classpath != null)
            {
                foreach (string cpath in contextSetup.Classpath)
                    AddPath(cpath.Trim());
            }

            // add library
            AddPath(Path.Combine(PathHelper.LibraryDir, "AS2/classes"));
            // add user pathes from settings
            if (settings.UserClasspath != null && settings.UserClasspath.Length > 0)
            {
                foreach(string cpath in settings.UserClasspath) AddPath(cpath.Trim());
            }
            // add initial pathes
            foreach(PathModel mpath in initCP) AddPath(mpath);

            // parse top-level elements
            InitTopLevelElements();
            if (cFile != null) UpdateTopLevelElements();

            // add current temporaty path
            if (temporaryPath != null)
            {
                string tempPath = temporaryPath;
                temporaryPath = null;
                SetTemporaryPath(tempPath);
            }
            FinalizeClasspath();
        }
Example #24
0
 protected virtual void ManualExploration(PathModel path, IEnumerable<String> hideDirectories)
 {
     PathExplorer explorer = new PathExplorer(this, path);
     path.InUse = true;
     if (hideDirectories != null) explorer.HideDirectories(hideDirectories);
     explorer.OnExplorationDone += new PathExplorer.ExplorationDoneHandler(RefreshContextCache);
     explorer.OnExplorationProgress += new PathExplorer.ExplorationProgressHandler(ExplorationProgress);
     explorer.UseCache = !CommonSettings.DisableCache;
     explorer.Run();
 }
Example #25
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*/);
            }
        }
Example #26
0
 protected virtual bool ExplorePath(PathModel path)
 {
     // exploration
     if (path.IsTemporaryPath)
     {
         path.IsTemporaryPath = false;
         path.WasExplored = false;
     }
     if (Settings != null && path.IsValid && !path.WasExplored
         && (!Settings.LazyClasspathExploration || path.IsVirtual))
     {
         //TraceManager.Add("EXPLORE: " + path.Path);
         PathExplorer explorer = new PathExplorer(this, path);
         explorer.OnExplorationDone += new PathExplorer.ExplorationDoneHandler(RefreshContextCache);
         explorer.OnExplorationProgress += new PathExplorer.ExplorationProgressHandler(ExplorationProgress);
         explorer.UseCache = !CommonSettings.DisableCache;
         explorer.Run();
         return true;
     }
     else if (path.WasExplored && path.IsVirtual)
     {
         // restore metadatas
         ExploreVirtualPath(path);
     }
     return false;
 }
Example #27
0
        /// <summary>
        /// Parse a packaged library file
        /// </summary>
        /// <param name="path">Models owner</param>
        public override void ExploreVirtualPath(PathModel path)
        {
            if (path.WasExplored)
            {
                if (path.FilesCount != 0) // already parsed
                    return;
            }

            try
            {
                if (File.Exists(path.Path) && !path.WasExplored)
                {
                    //TraceManager.AddAsync("parse " + path.Path);
                    lock (path)
                    {
                        path.WasExplored = true;
                        // do not monitor
                        path.ReleaseWatcher(); 
                        // PARSE LOOMLIB
                        LibParser.Parse(path, this);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = TextHelper.GetString("AS3Context.Info.ExceptionWhileParsing");
                TraceManager.AddAsync(message + " " + path.Path);
                TraceManager.AddAsync(ex.Message);
                TraceManager.AddAsync(ex.StackTrace);
            }
        }
Example #28
0
 /// <summary>
 /// Parse a packaged library file
 /// </summary>
 /// <param name="path">Models owner</param>
 public virtual void ExploreVirtualPath(PathModel path)
 {
     // to be implemented
 }
Example #29
0
 public LibParser(PathModel path, Context context)
 {
     this.path = path;
     this.context = context;
 }
Example #30
0
        private bool OpenVirtualFileModel(string virtualPath)
        {
            int p = virtualPath.IndexOfOrdinal("::");
            if (p < 0) return false;

            string container = virtualPath.Substring(0, p);
            string ext = Path.GetExtension(container).ToLower();
            if (ext != ".swf" && ext != ".swc" && ext != ".ane") return false;
            if (!File.Exists(container)) return false;

            string fileName = Path.Combine(container, virtualPath.Substring(p + 2).Replace('.', Path.DirectorySeparatorChar));
            PathModel path = new PathModel(container, contextInstance);
            ContentParser parser = new ContentParser(path.Path);
            parser.Run();
            AbcConverter.Convert(parser, path, contextInstance);

            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return true;
            }
            int split = fileName.LastIndexOf(Path.DirectorySeparatorChar) + 1;
            fileName = fileName.Substring(0, split) + "package.as";
            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return true;
            }
            fileName = fileName.Substring(0, split) + "toplevel.as";
            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return true;
            }
            return false;
        }