forked from OSchip/llvm-project
[find-all-symbols] make HeaderMapCollector optional in FindAllSymbols and FindAllMacros.
llvm-svn: 270193
This commit is contained in:
parent
0dfa6bc004
commit
83a4d7fbba
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue