summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/include-fixer/IncludeFixer.cpp
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2016-08-09 08:26:19 +0000
committerHaojian Wu <hokein@google.com>2016-08-09 08:26:19 +0000
commitc99f72868d1ce70695e2e4b7212d2fcd51e734b6 (patch)
tree7ce222ab0c03eecaa96b31497a09b574e9e2caf7 /clang-tools-extra/include-fixer/IncludeFixer.cpp
parent7e5445267f8adc66db66ca09c2804cf8f6ebb960 (diff)
downloadbcm5719-llvm-c99f72868d1ce70695e2e4b7212d2fcd51e734b6.tar.gz
bcm5719-llvm-c99f72868d1ce70695e2e4b7212d2fcd51e734b6.zip
[include-fixer] Support processing multiple files in one run.
Summary: Previously, if we pass multiple files or a file pattern (e.g. /path/to/*.cc) to include-fixer, include-fixer will apply all replacements to the first argument, which probably causes crashes. With this patch, include-fixer can process multiple files now. Vim and Emacs integration are tested manually. Reviewers: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D23266 llvm-svn: 278102
Diffstat (limited to 'clang-tools-extra/include-fixer/IncludeFixer.cpp')
-rw-r--r--clang-tools-extra/include-fixer/IncludeFixer.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/clang-tools-extra/include-fixer/IncludeFixer.cpp b/clang-tools-extra/include-fixer/IncludeFixer.cpp
index f6004c72abb..668b5928cae 100644
--- a/clang-tools-extra/include-fixer/IncludeFixer.cpp
+++ b/clang-tools-extra/include-fixer/IncludeFixer.cpp
@@ -37,6 +37,7 @@ public:
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &Compiler,
StringRef InFile) override {
+ FilePath = InFile;
return llvm::make_unique<clang::ASTConsumer>();
}
@@ -228,7 +229,7 @@ public:
Symbol.getContexts(),
Symbol.getNumOccurrences());
}
- return IncludeFixerContext(QuerySymbolInfos, SymbolCandidates);
+ return IncludeFixerContext(FilePath, QuerySymbolInfos, SymbolCandidates);
}
private:
@@ -297,6 +298,9 @@ private:
/// recovery.
std::vector<find_all_symbols::SymbolInfo> MatchedSymbols;
+ /// The file path to the file being processed.
+ std::string FilePath;
+
/// Whether we should use the smallest possible include path.
bool MinimizeIncludePaths = true;
};
@@ -304,9 +308,10 @@ private:
} // namespace
IncludeFixerActionFactory::IncludeFixerActionFactory(
- SymbolIndexManager &SymbolIndexMgr, IncludeFixerContext &Context,
- StringRef StyleName, bool MinimizeIncludePaths)
- : SymbolIndexMgr(SymbolIndexMgr), Context(Context),
+ SymbolIndexManager &SymbolIndexMgr,
+ std::vector<IncludeFixerContext> &Contexts, StringRef StyleName,
+ bool MinimizeIncludePaths)
+ : SymbolIndexMgr(SymbolIndexMgr), Contexts(Contexts),
MinimizeIncludePaths(MinimizeIncludePaths) {}
IncludeFixerActionFactory::~IncludeFixerActionFactory() = default;
@@ -337,9 +342,9 @@ bool IncludeFixerActionFactory::runInvocation(
llvm::make_unique<Action>(SymbolIndexMgr, MinimizeIncludePaths);
Compiler.ExecuteAction(*ScopedToolAction);
- Context = ScopedToolAction->getIncludeFixerContext(
+ Contexts.push_back(ScopedToolAction->getIncludeFixerContext(
Compiler.getSourceManager(),
- Compiler.getPreprocessor().getHeaderSearchInfo());
+ Compiler.getPreprocessor().getHeaderSearchInfo()));
// Technically this should only return true if we're sure that we have a
// parseable file. We don't know that though. Only inform users of fatal
@@ -348,10 +353,11 @@ bool IncludeFixerActionFactory::runInvocation(
}
llvm::Expected<tooling::Replacements> createIncludeFixerReplacements(
- StringRef Code, StringRef FilePath, const IncludeFixerContext &Context,
+ StringRef Code, const IncludeFixerContext &Context,
const clang::format::FormatStyle &Style, bool AddQualifiers) {
if (Context.getHeaderInfos().empty())
return tooling::Replacements();
+ StringRef FilePath = Context.getFilePath();
std::string IncludeName =
"#include " + Context.getHeaderInfos().front().Header + "\n";
// Create replacements for the new header.
OpenPOWER on IntegriCloud