Beispiel #1
0
        public bool RemovePackage(string packName)
        {
            var superPack = ModuleNameHelper.ExtractPackageName(packName);
            var pack      = Root.GetOrCreateSubPackage(superPack);

            return(pack != null && pack.Packages.Remove(ModuleNameHelper.ExtractModuleName(packName)));
        }
Beispiel #2
0
        public static DModule GetModule(string file)
        {
            DModule ret;

            if (!fileLookup.TryGetValue(file, out ret))
            {
                foreach (var kv in ParsedDirectories)
                {
                    if (!file.StartsWith(kv.Key))
                    {
                        continue;
                    }

                    var modName = DModule.GetModuleName(kv.Key, file);
                    var pack    = kv.Value.GetOrCreateSubPackage(ModuleNameHelper.ExtractPackageName(modName));

                    if (pack != null)
                    {
                        ret = pack.GetModule(modName);
                    }
                    break;
                }
            }

            return(ret);
        }
Beispiel #3
0
        public bool Remove(string moduleName)
        {
            var packName = ModuleNameHelper.ExtractPackageName(moduleName);
            var pack     = Root.GetOrCreateSubPackage(packName, false);

            return(pack != null && pack.Modules.Remove(ModuleNameHelper.ExtractModuleName(moduleName)));
        }
Beispiel #4
0
        public static DModule GetModule(string basePath, string moduleName)
        {
            var pack = GetPackage(basePath, ModuleNameHelper.ExtractPackageName(moduleName));

            if (pack == null)
            {
                return(null);
            }

            return(pack.GetModule(ModuleNameHelper.ExtractModuleName(moduleName)));
        }
Beispiel #5
0
        public static ModulePackage GetPackage(DModule module, bool create = false)
        {
            if (module == null)
            {
                return(null);
            }

            var root = GetRootPackage(module.FileName);

            if (root == null)
            {
                return(null);
            }

            return(root.GetOrCreateSubPackage(ModuleNameHelper.ExtractPackageName(module.ModuleName), create));
        }
Beispiel #6
0
        /// <summary>
        /// Returns null if no module was found.
        /// </summary>
        public IAbstractSyntaxTree GetModule(string moduleName)
        {
            var packName = ModuleNameHelper.ExtractPackageName(moduleName);

            var pack = Root.GetOrCreateSubPackage(packName, false);

            if (pack != null)
            {
                IAbstractSyntaxTree ret = null;
                if (pack.Modules.TryGetValue(ModuleNameHelper.ExtractModuleName(moduleName), out ret))
                {
                    return(ret);
                }
            }

            return(null);
        }
        void PrepareQueue(RootPackage root)
        {
            if (!Directory.Exists(baseDirectory))
            {
                return;
            }

            //ISSUE: wild card character ? seems to behave differently across platforms
            // msdn: -> Exactly zero or one character.
            // monodocs: -> Exactly one character.
            var dFiles  = Directory.GetFiles(baseDirectory, "*.d", SearchOption.AllDirectories);
            var diFiles = Directory.GetFiles(baseDirectory, "*.di", SearchOption.AllDirectories);
            var files   = new string[dFiles.Length + diFiles.Length];

            Array.Copy(dFiles, 0, files, 0, dFiles.Length);
            Array.Copy(diFiles, 0, files, dFiles.Length, diFiles.Length);

            var lastPack = (ModulePackage)root;
            var lastDir  = baseDirectory;

            bool isPhobosRoot = this.baseDirectory.EndsWith(Path.DirectorySeparatorChar + "phobos");

            foreach (var file in files)
            {
                var modulePath = DModule.GetModuleName(baseDirectory, file);

                if (lastDir != (lastDir = Path.GetDirectoryName(file)))
                {
                    isPhobosRoot = this.baseDirectory.EndsWith(Path.DirectorySeparatorChar + "phobos");

                    var packName = ModuleNameHelper.ExtractPackageName(modulePath);
                    lastPack = root.GetOrCreateSubPackage(packName, true);
                }

                // Skip index.d (D2) || phobos.d (D2|D1)
                if (isPhobosRoot && (file.EndsWith("index.d") || file.EndsWith("phobos.d")))
                {
                    continue;
                }

                queue.Push(new KeyValuePair <string, ModulePackage>(file, lastPack));
            }
        }
        void ParseThread()
        {
            var           file = "";
            ModulePackage pack = null;

            while (queue.Count != 0)
            {
                lock (queue)
                {
                    if (queue.Count == 0)
                    {
                        return;
                    }

                    var kv = queue.Pop();
                    file = kv.Key;
                    pack = kv.Value;
                }

                try
                {
                    // If no debugger attached, save time + memory by skipping function bodies
                    var ast = DParser.ParseFile(file, !Debugger.IsAttached);

                    if (!(pack is RootPackage))
                    {
                        ast.ModuleName = pack.Path + "." + Path.GetFileNameWithoutExtension(file);
                    }

                    ast.FileName = file;
                    pack.Modules[ModuleNameHelper.ExtractModuleName(ast.ModuleName)] = ast;
                }
                catch (Exception ex)
                {
                    LastException = ex;
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Use this method to add a syntax tree to the parse cache.
        /// Equally-named trees will be overwritten.
        /// </summary>
        public void AddOrUpdate(IAbstractSyntaxTree ast)
        {
            if (ast == null)
            {
                return;
            }

            var packName = ModuleNameHelper.ExtractPackageName(ast.ModuleName);

            if (string.IsNullOrEmpty(packName))
            {
                Root.Modules[ast.ModuleName] = ast;

                if (ast.ModuleName == "object")
                {
                    HandleObjectModule(ast);
                }
                return;
            }

            var pack = Root.GetOrCreateSubPackage(packName, true);

            pack.Modules[ModuleNameHelper.ExtractModuleName(ast.ModuleName)] = ast;
        }
Beispiel #10
0
        static void parseTh()
        {
            while (true)
            {
                if (queue.IsEmpty && !parseThreadStartEvent.WaitOne(ThreadWaitTimeout))
                {
                    return;
                }

                ParseIntermediate p;
                while (queue.TryPop(out p))
                {
                    if (stopParsing)
                    {
                        break;
                    }

                    var im = p.im;

                    if (p.file.EndsWith(phobosDFile) || p.file.EndsWith(indexDFile))
                    {
                        if (Interlocked.Decrement(ref im.remainingFiles) <= 0)
                        {
                            noticeFinish(p);
                        }
                        continue;
                    }

                    var sw = new System.Diagnostics.Stopwatch();

                    DModule ast;
                    try{
                        var code = File.ReadAllText(p.file);

                        sw.Start();

                        // If no debugger attached, save time + memory by skipping function bodies
                        ast = DParser.ParseString(code, im.skipFunctionBodies);
                    }
                    catch (Exception ex) {
                        ast = null;

                        Console.WriteLine("Exception occurred on \"" + p.file + "\":");
                        Console.WriteLine(ex.Message);
                        Console.WriteLine("-------------------------------");
                        Console.WriteLine("Stacktrace");
                        Console.WriteLine(ex.StackTrace);
                        Console.WriteLine("-------------------------------");
                    }

                    sw.Stop();

                    Interlocked.Add(ref im.totalMilliseconds, sw.ElapsedMilliseconds);

                    if (ast == null)
                    {
                        continue;
                    }

                    ast.FileName = p.file;

                    if (string.IsNullOrEmpty(ast.ModuleName))
                    {
                        ast.ModuleName = DModule.GetModuleName(im.basePath, p.file);
                    }

                    fileLookup.Remove(p.file);
                    fileLookup.Add(p.file, ast);

                    p.root.GetOrCreateSubPackage(ModuleNameHelper.ExtractPackageName(ast.ModuleName), true)
                    .AddModule(ast);

                    if (Interlocked.Decrement(ref im.remainingFiles) <= 0)
                    {
                        noticeFinish(p);
                    }
                }
            }
        }