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 void TryPreResolveCommonTypes()
        {
            var obj = GetModule("object");

            if (obj == null)
            {
                return;
            }

            ParseCacheView cache = null;

            foreach (var m in obj)
            {
                if (m.Name == "Object" && m is DClassLike)
                {
                    ObjectClassResult = new ClassType(ObjectClass = (DClassLike)m, new IdentifierDeclaration("Object"), null);
                    break;
                }
                else if (m.Name == "size_t")
                {
                    if (cache == null)
                    {
                        cache = new ParseCacheView(new[] { this });
                    }
                    //TODO: Do a version check, so that only on x64 dmd installations, size_t equals ulong.
                    SizeT = TypeDeclarationResolver.HandleNodeMatch(m,
                                                                    ResolutionContext.Create(cache, null, obj));
                }
            }
        }
Example #3
0
        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);
             * }*/
        }
Example #4
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 #5
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);
		}
Example #7
0
        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);
        }
Example #8
0
        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);
        }
		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 #10
0
        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 #11
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 #12
0
 private OldTypeReferenceFinder(ParseCacheView sharedCache, ConditionalCompilationFlags compilationEnvironment = null)
 {
     this.sharedParseCache = sharedCache;
     sharedCtxt            = ResolutionContext.Create(sharedCache, gFlags_shared = compilationEnvironment, null);
 }
		private OldTypeReferenceFinder(ParseCacheView sharedCache, ConditionalCompilationFlags compilationEnvironment = null)
		{
			this.sharedParseCache = sharedCache;
			sharedCtxt = ResolutionContext.Create(sharedCache, gFlags_shared = compilationEnvironment, null);
		}
Example #14
0
 public static ResolutionContext Create(ParseCacheView pcl, ConditionalCompilationFlags globalConditions, IBlockNode scopedBlock, IStatement scopedStatement = null)
 {
     return(new ResolutionContext(pcl, globalConditions, scopedBlock, scopedStatement));
 }
Example #15
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 #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));
 }