Index: clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp =================================================================== --- clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp +++ clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp @@ -59,9 +59,8 @@ class Action : public clang::ASTFrontendAction, public clang::ExternalSemaSource { public: - explicit Action(SymbolIndexManager &SymbolIndexMgr, StringRef StyleName, - bool MinimizeIncludePaths) - : SymbolIndexMgr(SymbolIndexMgr), FallbackStyle(StyleName), + explicit Action(SymbolIndexManager &SymbolIndexMgr, bool MinimizeIncludePaths) + : SymbolIndexMgr(SymbolIndexMgr), MinimizeIncludePaths(MinimizeIncludePaths) {} std::unique_ptr @@ -288,10 +287,6 @@ /// be used as the insertion point for new include directives. unsigned FirstIncludeOffset = -1U; - /// The fallback format style for formatting after insertion if there is no - /// clang-format config file found. - std::string FallbackStyle; - /// The symbol being queried. std::string QuerySymbol; @@ -347,7 +342,7 @@ SymbolIndexManager &SymbolIndexMgr, IncludeFixerContext &Context, StringRef StyleName, bool MinimizeIncludePaths) : SymbolIndexMgr(SymbolIndexMgr), Context(Context), - MinimizeIncludePaths(MinimizeIncludePaths), FallbackStyle(StyleName) {} + MinimizeIncludePaths(MinimizeIncludePaths) {} IncludeFixerActionFactory::~IncludeFixerActionFactory() = default; @@ -373,8 +368,8 @@ Compiler.getDiagnostics().setErrorLimit(0); // Run the parser, gather missing includes. - auto ScopedToolAction = llvm::make_unique( - SymbolIndexMgr, FallbackStyle, MinimizeIncludePaths); + auto ScopedToolAction = + llvm::make_unique(SymbolIndexMgr, MinimizeIncludePaths); Compiler.ExecuteAction(*ScopedToolAction); Context = ScopedToolAction->getIncludeFixerContext( Index: clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp =================================================================== --- clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp +++ clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp @@ -81,6 +81,59 @@ "headers if there is no clang-format config file found."), cl::init("llvm"), cl::cat(IncludeFixerCategory)); +std::unique_ptr +createSymbolIndexManager(StringRef FilePath) { + auto SymbolIndexMgr = llvm::make_unique(); + switch (DatabaseFormat) { + case fixed: { + // Parse input and fill the database with it. + // =
<, header...> + // Multiple symbols can be given, separated by semicolons. + std::map> SymbolsMap; + SmallVector SemicolonSplits; + StringRef(Input).split(SemicolonSplits, ";"); + std::vector Symbols; + for (StringRef Pair : SemicolonSplits) { + auto Split = Pair.split('='); + std::vector Headers; + SmallVector CommaSplits; + Split.second.split(CommaSplits, ","); + for (StringRef Header : CommaSplits) + Symbols.push_back(find_all_symbols::SymbolInfo( + Split.first.trim(), + find_all_symbols::SymbolInfo::SymbolKind::Unknown, Header.trim(), 1, + {})); + } + SymbolIndexMgr->addSymbolIndex( + llvm::make_unique(Symbols)); + break; + } + case yaml: { + llvm::ErrorOr> DB(nullptr); + if (!Input.empty()) { + DB = include_fixer::YamlSymbolIndex::createFromFile(Input); + } else { + // If we don't have any input file, look in the directory of the first + // file and its parents. + SmallString<128> AbsolutePath(tooling::getAbsolutePath(FilePath)); + StringRef Directory = llvm::sys::path::parent_path(AbsolutePath); + DB = include_fixer::YamlSymbolIndex::createFromDirectory( + Directory, "find_all_symbols_db.yaml"); + } + + if (!DB) { + llvm::errs() << "Couldn't find YAML db: " << DB.getError().message() + << '\n'; + return nullptr; + } + + SymbolIndexMgr->addSymbolIndex(std::move(*DB)); + break; + } + } + return SymbolIndexMgr; +} + int includeFixerMain(int argc, const char **argv) { tooling::CommonOptionsParser options(argc, argv, IncludeFixerCategory); tooling::ClangTool tool(options.getCompilations(), @@ -128,55 +181,10 @@ } // Set up data source. - auto SymbolIndexMgr = llvm::make_unique(); - switch (DatabaseFormat) { - case fixed: { - // Parse input and fill the database with it. - // =
<, header...> - // Multiple symbols can be given, separated by semicolons. - std::map> SymbolsMap; - SmallVector SemicolonSplits; - StringRef(Input).split(SemicolonSplits, ";"); - std::vector Symbols; - for (StringRef Pair : SemicolonSplits) { - auto Split = Pair.split('='); - std::vector Headers; - SmallVector CommaSplits; - Split.second.split(CommaSplits, ","); - for (StringRef Header : CommaSplits) - Symbols.push_back(find_all_symbols::SymbolInfo( - Split.first.trim(), - find_all_symbols::SymbolInfo::SymbolKind::Unknown, Header.trim(), 1, - {})); - } - SymbolIndexMgr->addSymbolIndex( - llvm::make_unique(Symbols)); - break; - } - case yaml: { - llvm::ErrorOr> DB(nullptr); - if (!Input.empty()) { - DB = include_fixer::YamlSymbolIndex::createFromFile(Input); - } else { - // If we don't have any input file, look in the directory of the first - // file and its parents. - SmallString<128> AbsolutePath( - tooling::getAbsolutePath(options.getSourcePathList().front())); - StringRef Directory = llvm::sys::path::parent_path(AbsolutePath); - DB = include_fixer::YamlSymbolIndex::createFromDirectory( - Directory, "find_all_symbols_db.yaml"); - } - - if (!DB) { - llvm::errs() << "Couldn't find YAML db: " << DB.getError().message() - << '\n'; - return 1; - } - - SymbolIndexMgr->addSymbolIndex(std::move(*DB)); - break; - } - } + std::unique_ptr SymbolIndexMgr = + createSymbolIndexManager(options.getSourcePathList().front()); + if (!SymbolIndexMgr) + return 1; // Now run our tool. include_fixer::IncludeFixerContext Context;