Example #1
0
        static bool TryLoadParsedFileFromCache(DateTime sourceTimestamp, ASTLocalCacheData cacheData, Compiler compiler)
        {
            if (cacheData.Timestamp < sourceTimestamp || cacheData.Ast == null)
            {
                return(false);
            }

            compiler.AstProcessor.AddRange(cacheData.Ast);

            return(true);
        }
Example #2
0
        bool TryParse(SourcePackage package, AbsoluteFilePath path)
        {
            var compilerPath = path.NativePath;

            var sourceTimestamp = _editors.GetLastWriteTime(path);
            var cachedData      = _astCache.FirstOrDefault(x => x.Name == compilerPath);

            if (cachedData == null)
            {
                cachedData = new ASTLocalCacheData()
                {
                    Name = compilerPath, Timestamp = sourceTimestamp
                };
                _astCache.Add(cachedData);
            }
            else
            {
                if (TryLoadParsedFileFromCache(sourceTimestamp, cachedData, _compiler))
                {
                    return(true);
                }
            }

            try
            {
                var parser = new Parser(_log, package, compilerPath, _editors.ReadAllText(path));
                var ast    = new List <AstDocument>();

                parser.Parse(ast);
                _compiler.AstProcessor.AddRange(ast);
                cachedData.Ast = ast;
                return(false);
            }
            catch
            {
                return(false);
            }
        }