Example #1
0
        public ResolutionContext(ParseCacheView parseCache, ConditionalCompilationFlags gFlags, IBlockNode bn, IStatement stmt = null)
        {
            this.CompilationEnvironment = gFlags;
            this.ParseCache             = parseCache;

            new ContextFrame(this, bn, stmt);
        }
Example #2
0
        public static ResolutionContext Create(IEditorData editor, ConditionalCompilationFlags globalConditions = null)
        {
            IStatement stmt;

            return(new ResolutionContext(editor.ParseCache, globalConditions ?? new ConditionalCompilationFlags(editor),
                                         DResolver.SearchBlockAt(editor.SyntaxTree, editor.CaretLocation, out stmt) ?? editor.SyntaxTree,
                                         stmt));
        }
Example #3
0
 public ResolutionContext(ParseCacheView parseCache, ConditionalCompilationFlags gFlags)
 {
     this.CompilationEnvironment = gFlags;
     this.ParseCache             = parseCache;
     //Cache = new ResolutionCache<AbstractType[]>(this);
     //ValueCache = new ResolutionCache<ISymbolValue>(this);
     MixinCache = new ResolutionCache <Tuple <string, VariableValue> >(this);
 }
Example #4
0
        public ResolutionContext(ParseCacheView parseCache, ConditionalCompilationFlags gFlags, IBlockNode bn, CodeLocation caret)
        {
            this.CompilationEnvironment = gFlags;
            this.ParseCache             = parseCache;
            //Cache = new ResolutionCache<AbstractType[]>(this);
            //ValueCache = new ResolutionCache<ISymbolValue>(this);
            MixinCache = new ResolutionCache <Tuple <string, VariableValue> >(this);

            new ContextFrame(this, bn, caret);
        }
        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;
        }
Example #7
0
        /// <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;
        }
Example #8
0
        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);
        }
Example #9
0
 public ConditionSet(ConditionalCompilationFlags gFLags, ConditionalCompilationFlags lFlags = null)
 {
     // Make a default global environment for test resolutions etc.
     GlobalFlags = gFLags ?? new ConditionalCompilationFlags(null, 0, false);
     LocalFlags  = lFlags;
 }
			public ConditionSet(ConditionalCompilationFlags gFLags, ConditionalCompilationFlags lFlags = null)
			{
				// Make a default global environment for test resolutions etc.
				GlobalFlags = gFLags ?? new ConditionalCompilationFlags(null,0,false);
				LocalFlags = lFlags;
			}
Example #11
0
        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);
        }
Example #12
0
 public static ResolutionContext Create(ParseCacheView pcl, ConditionalCompilationFlags globalConditions, IBlockNode scopedBlock, IStatement scopedStatement = null)
 {
     return(new ResolutionContext(pcl, globalConditions, scopedBlock, scopedStatement));
 }
Example #13
0
		public static void Main (string[] args)
		{
			var rt = new ResolutionTests ();
			rt.SetupEnvironment ();

			Trace.Listeners.Clear ();
			Trace.AutoFlush = false;
			Trace.UseGlobalLock = false;
			if(File.Exists(traceFile))
				File.Delete (traceFile);
			Trace.Listeners.Add (new TextWriterTraceListener (traceFile));

			/*
			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;*/
			//DParser.ParseString (@"");
			//(new ResolutionTests ()).BasicResolution0 ();
			//(new IndentationTests ()).TestIssue576 ();		
			//(new IndentationTests ()).SwitchIndentation ();

			//BotanProfil.Run ();
			rt.LooseResolution2();

			Trace.Flush ();
			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 skipFunctionBodies = false;


			var dirsLeft = dirs.Length;
			var ev=new System.Threading.AutoResetEvent(false);

			if (skipFunctionBodies)	Console.WriteLine ("Skipping method bodies!");
			GlobalParseCache.BeginAddOrUpdatePaths(dirs, skipFunctionBodies, (pc) =>
			{
				Console.WriteLine("{0}/{1}ms", pc.Duration, pc.ParseDuration);
				ev.Set();
			});

			ev.WaitOne();

			Console.WriteLine("done.");
			Console.WriteLine();
			var pcw = new LegacyParseCacheView(dirs);
			var ccf = new ConditionalCompilationFlags(new[]{ Environment.OSVersion.Platform == PlatformID.Unix ?"Posix":"Windows", "D2" }, 1, true, null, 0);

			Console.WriteLine ("Dump parse errors:");
			int modCount = 0;
			foreach (var dir in dirs)
				foreach (var mod in GlobalParseCache.EnumModulesRecursively(dir)) {
					modCount++;
					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("{0} modules parsed.", modCount);

			Console.WriteLine();
			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
Example #14
0
        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();
        }
Example #15
0
 private OldTypeReferenceFinder(ParseCacheView sharedCache, ConditionalCompilationFlags compilationEnvironment = null)
 {
     this.sharedParseCache = sharedCache;
     sharedCtxt = ResolutionContext.Create(sharedCache, gFlags_shared = compilationEnvironment, null);
 }
Example #16
0
 public ResolutionContext(ParseCacheView parseCache, ConditionalCompilationFlags gFlags, IBlockNode bn)
     : this(parseCache, gFlags, bn, CodeLocation.Empty)
 {
 }
Example #17
0
 public static ResolutionContext Create(ParseCacheView pcl, ConditionalCompilationFlags globalConditions, IBlockNode scopedBlock, CodeLocation caret)
 {
     return(new ResolutionContext(pcl, globalConditions, scopedBlock, caret));
 }
Example #18
0
 public static ResolutionContext Create(ParseCacheView pcl, ConditionalCompilationFlags globalConditions)
 {
     return(new ResolutionContext(pcl, globalConditions));
 }
Example #19
0
        public static ResolutionContext Create(IEditorData editor, bool pushFirstScope, ConditionalCompilationFlags globalConditions = null)
        {
            var ctxt = new ResolutionContext(editor.ParseCache, globalConditions ?? new ConditionalCompilationFlags(editor));

            if (pushFirstScope)
            {
                ctxt.Push(editor);
            }
            return(ctxt);
        }