From 4c1ee74b271a46588f8df790ff5e8d3dace60868 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Wed, 17 Jan 2018 21:48:09 -0800 Subject: [PATCH] Merge ParseFile and DoParseFile --- src/import_pipeline.cc | 46 +++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index 9dac1069..c497fee0 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -83,7 +83,8 @@ struct ActiveThread { enum class FileParseQuery { NeedsParse, DoesNotNeedParse, NoSuchFile }; -std::vector DoParseFile( + +std::vector ParseFile( Config* config, WorkingFiles* working_files, FileConsumerSharedState* file_consumer_shared, @@ -92,9 +93,21 @@ std::vector DoParseFile( ICacheManager* cache_manager, IIndexer* indexer, bool is_interactive, - const std::string& path, - const std::vector& args, - const FileContents& contents) { + const Project::Entry& entry, + const std::string& entry_contents) { + + FileContents contents(entry.filename, entry_contents); + + // If the file is inferred, we may not actually be able to parse that file + // directly (ie, a header file, which are not listed in the project). If this + // file is inferred, then try to use the file which originally imported it. + std::string path = entry.filename; + if (entry.is_inferred) { + IndexFile* entry_cache = cache_manager->TryLoad(entry.filename); + if (entry_cache) + path = entry_cache->import_file; + } + std::vector result; // Always run this block, even if we are interactive, so we can check @@ -236,7 +249,7 @@ std::vector DoParseFile( PerformanceImportFile perf; std::vector> indexes = indexer->Index( - config, file_consumer_shared, path, args, file_contents, &perf); + config, file_consumer_shared, path, entry.args, file_contents, &perf); for (std::unique_ptr& new_index : indexes) { Timer time; @@ -256,29 +269,6 @@ std::vector DoParseFile( return result; } -std::vector ParseFile( - Config* config, - WorkingFiles* working_files, - FileConsumerSharedState* file_consumer_shared, - TimestampManager* timestamp_manager, - ImportManager* import_manager, - ICacheManager* cache_manager, - IIndexer* indexer, - bool is_interactive, - const Project::Entry& entry, - const std::string& contents) { - FileContents file_contents(entry.filename, contents); - - // Try to determine the original import file by loading the file from cache. - // This lets the user request an index on a header file, which clang will - // complain about if indexed by itself. - IndexFile* entry_cache = cache_manager->TryLoad(entry.filename); - std::string tu_path = entry_cache ? entry_cache->import_file : entry.filename; - return DoParseFile(config, working_files, file_consumer_shared, - timestamp_manager, import_manager, cache_manager, indexer, - is_interactive, tu_path, entry.args, file_contents); -} - bool IndexMain_DoParse(Config* config, WorkingFiles* working_files, FileConsumerSharedState* file_consumer_shared,