Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[find-all-symbols] Added hardcode header mapping from header postfix …
…to header name for STL symbols. Summary: [find-all-symbols] Added hardcode header mapping from header postfix to header name for STL symbols. Reviewers: klimek, bkramer Subscribers: cfe-commits, hokein Differential Revision: http://reviews.llvm.org/D20566 llvm-svn: 270566
- Loading branch information
Eric Liu
committed
May 24, 2016
1 parent
7175c2c
commit a7d1941
Showing
12 changed files
with
569 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbolsAction.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//===-- FindAllSymbolsAction.cpp - find all symbols action --------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "FindAllSymbolsAction.h" | ||
|
||
namespace clang { | ||
namespace find_all_symbols { | ||
|
||
FindAllSymbolsAction::FindAllSymbolsAction( | ||
SymbolReporter *Reporter, const HeaderMapCollector::HeaderMap *PostfixMap) | ||
: Reporter(Reporter), Collector(PostfixMap), Handler(&Collector), | ||
Matcher(Reporter, &Collector) { | ||
Matcher.registerMatchers(&MatchFinder); | ||
} | ||
|
||
std::unique_ptr<clang::ASTConsumer> | ||
FindAllSymbolsAction::CreateASTConsumer(clang::CompilerInstance &Compiler, | ||
StringRef InFile) { | ||
Compiler.getPreprocessor().addCommentHandler(&Handler); | ||
Compiler.getPreprocessor().addPPCallbacks(llvm::make_unique<FindAllMacros>( | ||
Reporter, &Compiler.getSourceManager(), &Collector)); | ||
return MatchFinder.newASTConsumer(); | ||
} | ||
|
||
} // namespace find_all_symbols | ||
} // namespace clang |
61 changes: 61 additions & 0 deletions
61
clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbolsAction.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//===-- FindAllSymbolsAction.h - find all symbols action --------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_FIND_ALL_SYMBOLS_ACTION_H | ||
#define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_FIND_ALL_SYMBOLS_ACTION_H | ||
|
||
#include "FindAllMacros.h" | ||
#include "FindAllSymbols.h" | ||
#include "HeaderMapCollector.h" | ||
#include "PragmaCommentHandler.h" | ||
#include "clang/Frontend/CompilerInstance.h" | ||
#include "clang/Frontend/FrontendActions.h" | ||
#include "clang/Tooling/Tooling.h" | ||
|
||
namespace clang { | ||
namespace find_all_symbols { | ||
|
||
class FindAllSymbolsAction : public clang::ASTFrontendAction { | ||
public: | ||
explicit FindAllSymbolsAction( | ||
SymbolReporter *Reporter, | ||
const HeaderMapCollector::HeaderMap *PostfixMap = nullptr); | ||
|
||
std::unique_ptr<clang::ASTConsumer> | ||
CreateASTConsumer(clang::CompilerInstance &Compiler, | ||
StringRef InFile) override; | ||
|
||
private: | ||
SymbolReporter *const Reporter; | ||
clang::ast_matchers::MatchFinder MatchFinder; | ||
HeaderMapCollector Collector; | ||
PragmaCommentHandler Handler; | ||
FindAllSymbols Matcher; | ||
}; | ||
|
||
class FindAllSymbolsActionFactory : public tooling::FrontendActionFactory { | ||
public: | ||
FindAllSymbolsActionFactory( | ||
SymbolReporter *Reporter, | ||
const HeaderMapCollector::HeaderMap *PostfixMap = nullptr) | ||
: Reporter(Reporter), PostfixMap(PostfixMap) {} | ||
|
||
virtual clang::FrontendAction *create() override { | ||
return new FindAllSymbolsAction(Reporter, PostfixMap); | ||
} | ||
|
||
private: | ||
SymbolReporter *const Reporter; | ||
const HeaderMapCollector::HeaderMap *const PostfixMap; | ||
}; | ||
|
||
} // namespace find_all_symbols | ||
} // namespace clang | ||
|
||
#endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_FIND_ALL_SYMBOLS_ACTION_H |
34 changes: 34 additions & 0 deletions
34
clang-tools-extra/include-fixer/find-all-symbols/HeaderMapCollector.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===-- HeaderMapCoolector.h - find all symbols------------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "HeaderMapCollector.h" | ||
|
||
namespace clang { | ||
namespace find_all_symbols { | ||
|
||
llvm::StringRef | ||
HeaderMapCollector::getMappedHeader(llvm::StringRef Header) const { | ||
auto Iter = HeaderMappingTable.find(Header); | ||
if (Iter != HeaderMappingTable.end()) | ||
return Iter->second; | ||
// If there is no complete header name mapping for this header, check the | ||
// postfix mapping. | ||
// FIXME: this is not very efficient. Change PostfixMappingTable to use | ||
// postfix tree if necessary. | ||
if (PostfixMappingTable) { | ||
for (const auto &Entry : *PostfixMappingTable) { | ||
if (Header.endswith(Entry.first())) | ||
return Entry.second; | ||
} | ||
} | ||
return Header; | ||
} | ||
|
||
} // namespace find_all_symbols | ||
} // namespace clang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
clang-tools-extra/include-fixer/find-all-symbols/tool/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.