[find-all-symbols] make HeaderMapCollector optional in FindAllSymbols and FindAllMacros.

llvm-svn: 270193
This commit is contained in:
Eric Liu 2016-05-20 09:12:01 +00:00
parent 0dfa6bc004
commit 83a4d7fbba
6 changed files with 22 additions and 19 deletions

View File

@ -27,11 +27,13 @@ void FindAllMacros::MacroDefined(const Token &MacroNameTok,
if (FilePath.empty())
return;
// Check pragma remapping header.
auto HeaderMappingTable = Collector->getHeaderMappingTable();
auto Iter = HeaderMappingTable.find(FilePath);
if (Iter != HeaderMappingTable.end())
FilePath = Iter->second;
// If Collector is not nullptr, check pragma remapping header.
if (Collector) {
auto HeaderMappingTable = Collector->getHeaderMappingTable();
auto Iter = HeaderMappingTable.find(FilePath);
if (Iter != HeaderMappingTable.end())
FilePath = Iter->second;
}
SymbolInfo Symbol(MacroNameTok.getIdentifierInfo()->getName(),
SymbolInfo::SymbolKind::Macro, FilePath.str(),

View File

@ -25,9 +25,9 @@ class HeaderMapCollector;
/// preprocessing period.
class FindAllMacros : public clang::PPCallbacks {
public:
explicit FindAllMacros(SymbolReporter *Reporter,
HeaderMapCollector *Collector, SourceManager *SM)
: Reporter(Reporter), Collector(Collector), SM(SM) {}
explicit FindAllMacros(SymbolReporter *Reporter, SourceManager *SM,
HeaderMapCollector *Collector = nullptr)
: Reporter(Reporter), SM(SM), Collector(Collector) {}
void MacroDefined(const Token &MacroNameTok,
const MacroDirective *MD) override;
@ -35,11 +35,10 @@ public:
private:
// Reporter for SymbolInfo.
SymbolReporter *const Reporter;
SourceManager *const SM;
// A remapping header file collector allowing clients to include a different
// header.
HeaderMapCollector *const Collector;
SourceManager *const SM;
};
} // namespace find_all_symbols

View File

@ -59,7 +59,7 @@ std::vector<SymbolInfo::Context> GetContexts(const NamedDecl *ND) {
llvm::Optional<SymbolInfo>
CreateSymbolInfo(const NamedDecl *ND, const SourceManager &SM,
const HeaderMapCollector::HeaderMap &HeaderMappingTable) {
const HeaderMapCollector *Collector) {
SymbolInfo::SymbolKind Type;
if (llvm::isa<VarDecl>(ND)) {
Type = SymbolInfo::SymbolKind::Variable;
@ -96,10 +96,12 @@ CreateSymbolInfo(const NamedDecl *ND, const SourceManager &SM,
if (FilePath.empty())
return llvm::None;
// Check pragma remapping header.
auto Iter = HeaderMappingTable.find(FilePath);
if (Iter != HeaderMappingTable.end())
FilePath = Iter->second;
// If Collector is not nullptr, check pragma remapping header.
if (Collector) {
auto Iter = Collector->getHeaderMappingTable().find(FilePath);
if (Iter != Collector->getHeaderMappingTable().end())
FilePath = Iter->second;
}
return SymbolInfo(ND->getNameAsString(), Type, FilePath.str(),
SM.getExpansionLineNumber(Loc), GetContexts(ND));
@ -215,7 +217,7 @@ void FindAllSymbols::run(const MatchFinder::MatchResult &Result) {
const SourceManager *SM = Result.SourceManager;
llvm::Optional<SymbolInfo> Symbol =
CreateSymbolInfo(ND, *SM, Collector->getHeaderMappingTable());
CreateSymbolInfo(ND, *SM, Collector);
if (Symbol)
Reporter->reportSymbol(
SM->getFileEntryForID(SM->getMainFileID())->getName(), *Symbol);

View File

@ -35,7 +35,7 @@ class HeaderMapCollector;
class FindAllSymbols : public clang::ast_matchers::MatchFinder::MatchCallback {
public:
explicit FindAllSymbols(SymbolReporter *Reporter,
HeaderMapCollector *Collector)
HeaderMapCollector *Collector = nullptr)
: Reporter(Reporter), Collector(Collector) {}
void registerMatchers(clang::ast_matchers::MatchFinder *MatchFinder);

View File

@ -25,7 +25,7 @@ public:
llvm::StringRef MappingHeaderPath) {
HeaderMappingTable[OrignalHeaderPath] = MappingHeaderPath;
};
const HeaderMap &getHeaderMappingTable() { return HeaderMappingTable; };
const HeaderMap &getHeaderMappingTable() const { return HeaderMappingTable; };
private:
/// A string-to-string map saving the mapping relationship.

View File

@ -67,7 +67,7 @@ public:
StringRef InFile) override {
Compiler.getPreprocessor().addCommentHandler(&Handler);
Compiler.getPreprocessor().addPPCallbacks(llvm::make_unique<FindAllMacros>(
Reporter, &Collector, &Compiler.getSourceManager()));
Reporter, &Compiler.getSourceManager(), &Collector));
return MatchFinder.newASTConsumer();
}