Beispiel #1
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 #2
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 #3
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 #4
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);
                    }
                }
            }
        }