public void UpdateModule(string filename, string srcText, bool verbose) { DModule ast; try { ast = DParser.ParseString(srcText, false); } catch (Exception ex) { ast = new DModule { ParseErrors = new System.Collections.ObjectModel.ReadOnlyCollection <ParserError>( new List <ParserError> { new ParserError(false, ex.Message + "\n\n" + ex.StackTrace, DTokens.Invariant, CodeLocation.Empty) }) }; //WTF } if (string.IsNullOrEmpty(ast.ModuleName)) { ast.ModuleName = Path.GetFileNameWithoutExtension(filename); } ast.FileName = filename; //GlobalParseCache.RemoveModule(filename); GlobalParseCache.AddOrUpdateModule(ast); ConditionalCompilationFlags cflags = new ConditionalCompilationFlags(_editorData); //GlobalParseCache.UfcsCache.CacheModuleMethods(ast, ResolutionContext.Create(_parseCacheList, cflags, null, null)); _modules[filename] = ast; _sources[filename] = srcText; //MessageBox.Show("UpdateModule(" + filename + ")"); //throw new NotImplementedException(); }
/// <summary> /// Returns false if cache is already updating. /// </summary> public bool BeginUpdate(ParseCacheView pcList, ConditionalCompilationFlags compilationEnvironment = null) { if (!processingEvent.WaitOne(0)) { if (Debugger.IsAttached) { Console.WriteLine("анализ ufcs уже проводится"); } return(false); } gFlags_shared = compilationEnvironment; methodCount = 0; queue.Clear(); // Prepare queue foreach (var module in Root) { PrepareQueue(module); } sw.Restart(); if (queue.Count != 0) { //completedEvent.Reset(); if (SingleThreaded) { parseThread(pcList); } else { var threads = new Thread[GlobalParseCache.NumThreads]; for (int i = 0; i < GlobalParseCache.NumThreads; i++) { var th = threads [i] = new Thread(parseThread) { IsBackground = true, Priority = ThreadPriority.Lowest, Name = "Поток анализа UFCS #" + i }; th.Start(pcList); } } } else { noticeFinish(); } return(true); }
public static void EnumAllAvailableMembers(ICompletionDataGenerator cdgen, IBlockNode ScopedBlock , IStatement ScopedStatement, CodeLocation Caret, ParseCacheView CodeCache, MemberFilter VisibleMembers, ConditionalCompilationFlags compilationEnvironment = null) { var ctxt = ResolutionContext.Create(CodeCache, compilationEnvironment, ScopedBlock, ScopedStatement); var en = new MemberCompletionEnumeration(ctxt, cdgen) { isVarInst = true }; en.IterateThroughScopeLayers(Caret, VisibleMembers); }
public static TypeReferencesResult Scan(DModule ast, ParseCacheView pcl, ConditionalCompilationFlags compilationEnvironment = null) { if (ast == null) { return(new TypeReferencesResult()); } var typeRefFinder = new OldTypeReferenceFinder(pcl, compilationEnvironment); typeRefFinder.ast = ast; // Enum all identifiers typeRefFinder.S(ast); // Crawl through all remaining expressions by evaluating their types and check if they're actual type references. typeRefFinder.queueCount = typeRefFinder.q.Count; typeRefFinder.ResolveAllIdentifiers(); return(typeRefFinder.result); }
private OldTypeReferenceFinder(ParseCacheView sharedCache, ConditionalCompilationFlags compilationEnvironment = null) { this.sharedParseCache = sharedCache; sharedCtxt = ResolutionContext.Create(sharedCache, gFlags_shared = compilationEnvironment, null); }
public static void Main(string[] args) { /* * var sw2 = new Stopwatch(); * var code = File.ReadAllText(@"B:\Programs\D\dmd2\src\phobos\std\datetime.d"); * sw2.Start(); * var ast = DParser.ParseString(code, true); * sw2.Stop(); * Console.WriteLine (sw2.ElapsedMilliseconds); * return;*/ (new ResolutionTests()).Unqual(); (new EvaluationTests()).IsExpressionAlias(); return; // Indent testing /*var code = @" * "; * var line = 4; * var ind = D_Parser.Formatting.Indent.IndentEngineWrapper.CalculateIndent(code, line, false, 4); * var o = DocumentHelper.LocationToOffset(code, line,1); * * var o2 = o; * while(o2 < code.Length && code[o2] == ' ' || code[o2] == '\t') * o2++; * * code = code.Substring(0,o) + ind + code.Substring(o2); * Console.Write(code+"|"); * * Console.ReadKey(true); * return;*/ // Phobos & Druntime parsing Console.WriteLine("Begin parsing..."); var dirs = Environment.OSVersion.Platform == PlatformID.Unix ? new[] { @"/usr/include/dlang" } : new[] { @"B:\Programs\D\dmd2\src\phobos", @"B:\Programs\D\dmd2\src\druntime\import" }; var dirsLeft = dirs.Length; var ev = new System.Threading.AutoResetEvent(false); GlobalParseCache.BeginAddOrUpdatePaths(dirs, false, (pc) => { Console.WriteLine("{1}ms", pc.Directory, pc.ParseDuration); ev.Set(); }); ev.WaitOne(); Console.WriteLine("done."); Console.WriteLine(); var pcw = new ParseCacheView(dirs); var ccf = new ConditionalCompilationFlags(new[] { Environment.OSVersion.Platform == PlatformID.Unix ?"Posix":"Windows", "D2" }, 1, true, null, 0); Console.WriteLine("Dump parse errors:"); foreach (var dir in dirs) { foreach (var mod in GlobalParseCache.EnumModulesRecursively(dir)) { if (mod.ParseErrors.Count > 0) { Console.WriteLine(" " + mod.FileName); Console.WriteLine(" (" + mod.ModuleName + ")"); foreach (var err in mod.ParseErrors) { Console.WriteLine("({0}):", err.Location.ToString()); Console.WriteLine("\t" + err.Message); } } } } Console.WriteLine(); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }