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 ParseCacheView CreateCache(params string[] moduleCodes) { var r = new MutableRootPackage (objMod); foreach (var code in moduleCodes) r.AddModule(DParser.ParseString(code)); UFCSCache.SingleThreaded = true; var pcl = new ParseCacheView (new [] { r }); r.UfcsCache.BeginUpdate (pcl); return pcl; }
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; }
/// <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 analysis already in progress"); 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 Analysis thread #" + i }; th.Start (pcList); } } } else noticeFinish (); return true; }
void parsedSources(ParsingFinishedEventArgs pfd) { InitialParsingDone = true; if(ParsingFinished != null) ParsingFinished(); var pcw = new ParseCacheView(tempImports); // Output parse time stats if (pfd != null) ErrorLogger.Log("Parsed " + pfd.FileAmount + " files in [" + string.Join(",",tempImports) + "] in " + Math.Round(pfd.ParseDuration/1000.0, 2).ToString() + "s (~" + Math.Round(pfd.FileParseDuration, 3).ToString() + "ms per file)", ErrorType.Information, ErrorOrigin.Parser); // For debugging purposes dump all parse results (errors etc.) to a log file. /*try { ParseLog.Write(ASTCache, IDEInterface.ConfigDirectory + "\\" + Version.ToString() + ".GlobalParseLog.log"); } catch (Exception ex) { ErrorLogger.Log(ex, ErrorType.Warning, ErrorOrigin.System); }*/ }
public static void Main(string[] args) { /* var sw2 = new Stopwatch(); var code = File.ReadAllText(@"D:\D\dmd2\src\phobos\std\datetime.d"); sw2.Start(); var ast = DParser.ParseString(code, true); sw2.Stop();*/ //(new ResolutionTests ()).EmptyTypeTuple (); //(new ParseTests()).TestPhobos(); //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 UFCSCache.SingleThreaded = true; Console.WriteLine ("Begin parsing..."); var dirs = Environment.OSVersion.Platform == PlatformID.Unix ? new[]{@"/usr/include/dlang"} : new[]{@"D:\D\dmd2\src\phobos", @"D:\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.Duration); 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.WriteLine("Begin building ufcs cache..."); var sw = new Stopwatch(); sw.Restart(); foreach (var dir in dirs) { var ufcs = GlobalParseCache.GetRootPackage(dir).UfcsCache; ufcs.AnalysisFinished += (root) => { if (System.Threading.Interlocked.Decrement(ref dirsLeft) <= 0) ev.Set(); }; ufcs.BeginUpdate(pcw, ccf); } ev.WaitOne(); sw.Stop(); Console.WriteLine("done. {0}ms needed.", sw.ElapsedMilliseconds); Console.WriteLine(); Console.Write("Press any key to continue . . . "); //Console.ReadKey(true); }
public static ResolutionContext CreateDefCtxt(ParseCacheView pcl, IBlockNode scope, IStatement stmt=null) { var r = ResolutionContext.Create(pcl, new ConditionalCompilationFlags(new[]{"Windows","all"},1,true,null,0), scope, stmt); CompletionOptions.Instance.DisableMixinAnalysis = false; return r; }
public void TestPrimitives() { TestPrimitive("1", DTokens.Int, 1M); TestPrimitive("1.0", DTokens.Double, 1.0M); TestPrimitive("1f",DTokens.Float, 1M); TestPrimitive("1e+3", DTokens.Int, 1000M); TestPrimitive("1.0e+2", DTokens.Double, 100M); TestPrimitive("'c'",DTokens.Char, (decimal)(int)'c'); TestString("\"asdf\"", "asdf", true); TestString("\"asdf\"c", "asdf", true); TestString("\"asdf\"w", "asdf", true); TestString("\"asdf\"d", "asdf", true); TestString("\"asdf\"", "asdf", false); TestString("\"asdf\"c", "asdf", false); TestString("\"asdf\"w", "asdf", false); TestString("\"asdf\"d", "asdf", false); var ex = DParser.ParseExpression("['a','s','d','f']"); var v = Evaluation.EvaluateValue(ex, (ResolutionContext)null); Assert.IsInstanceOfType(typeof(ArrayValue),v); var ar = (ArrayValue)v; Assert.AreEqual(ar.Elements.Length, 4); foreach (var ev in ar.Elements) Assert.IsInstanceOfType(typeof(PrimitiveValue),ev); ex = DParser.ParseExpression("[\"KeyA\":12, \"KeyB\":33, \"KeyC\":44]"); v = Evaluation.EvaluateValue(ex, (ResolutionContext)null); Assert.IsInstanceOfType(typeof(AssociativeArrayValue),v); var aa = (AssociativeArrayValue)v; Assert.AreEqual(aa.Elements.Count, 3); ex = DParser.ParseExpression("(a,b) => a+b"); var pcl = new ParseCacheView (new[]{new MutableRootPackage()}); v = Evaluation.EvaluateValue(ex, ResolutionContext.Create(pcl, null, null)); Assert.IsInstanceOfType(typeof(DelegateValue),v); }
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); }