예제 #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);
        }
예제 #2
0
        public override void ModifyTags(
            MonoDevelop.Projects.SolutionItem policyParent,
            MonoDevelop.Projects.Project project,
            string language,
            string identifier,
            string fileName,
            ref Dictionary <string, string> tags)
        {
            base.ModifyTags(policyParent, project, language, identifier, fileName, ref tags);

            if (tags != null)
            {
                tags["ModuleName"] = DModule.GetModuleName(project == null ? string.Empty : project.BaseDirectory.ToString(), fileName ?? identifier ?? string.Empty).Replace(' ', '_');
            }
        }
예제 #3
0
        public void Add(string rootDirectory, IAbstractSyntaxTree ast)
        {
            // Handle module packages
            var relativeDirectory = Path.GetDirectoryName(ast.FileName.Substring(rootDirectory.Length));
            var modulePackage     = relativeDirectory.Replace(Path.DirectorySeparatorChar, '.');

            if (!ModulePackageNames.ContainsKey(modulePackage))
            {
                ModulePackageNames.Add(modulePackage, Path.GetDirectoryName(ast.FileName));
            }

            // Overwrite its module name
            ast.ModuleName = DModule.GetModuleName(rootDirectory, ast);

            Add(ast, modulePackage);
        }
예제 #4
0
        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));
            }
        }
예제 #5
0
        public override void ModifyTags(
            MonoDevelop.Projects.SolutionItem policyParent,
            MonoDevelop.Projects.Project project,
            string language,
            string identifier,
            string fileName,
            ref Dictionary <string, string> tags)
        {
            base.ModifyTags(policyParent, project, language, identifier, fileName, ref tags);
            const string ModuleNameTag = "ModuleName";

            if (tags != null)
            {
                var dprj = project as AbstractDProject;
                if (dprj != null)
                {
                    if (fileName != null)
                    {
                        foreach (var basePath in dprj.GetSourcePaths())
                        {
                            var bp = System.IO.Path.GetFullPath(basePath);
                            if (fileName.StartsWith(bp))
                            {
                                tags [ModuleNameTag] = DModule.GetModuleName(bp, fileName);
                                break;
                            }
                        }
                    }
                }

                if (!tags.ContainsKey(ModuleNameTag))
                {
                    tags [ModuleNameTag] = DModule.GetModuleName(project == null ? string.Empty : project.BaseDirectory.ToString(), fileName ?? identifier ?? string.Empty).Replace(' ', '_');
                }
            }
        }
예제 #6
0
 public IAbstractSyntaxTree GetModuleByFileName(string file, string baseDirectory)
 {
     return(GetModule(DModule.GetModuleName(baseDirectory, file)));
 }
예제 #7
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);
                    }
                }
            }
        }