diff options
author | Rafael Stahl <r.stahl@tum.de> | 2019-01-10 17:44:04 +0000 |
---|---|---|
committer | Rafael Stahl <r.stahl@tum.de> | 2019-01-10 17:44:04 +0000 |
commit | 8c48705a19753ea10a99fd0223c5eee75de776cb (patch) | |
tree | cb4abdbbd7951093d5eadf7df880e5890ace1fb7 /clang/tools/clang-func-mapping/ClangFnMapGen.cpp | |
parent | b8819dc1e3cd59619b21276f0207e5377353db70 (diff) | |
download | bcm5719-llvm-8c48705a19753ea10a99fd0223c5eee75de776cb.tar.gz bcm5719-llvm-8c48705a19753ea10a99fd0223c5eee75de776cb.zip |
[analyzer][CrossTU][NFC] Generalize to external definitions instead of external functions
Summary: This is just changing naming and documentation to be general about external definitions that can be imported for cross translation unit analysis. There is at least a plan to add VarDecls: D46421
Reviewers: NoQ, xazax.hun, martong, a.sidorin, george.karpenkov, serge-sans-paille
Reviewed By: xazax.hun, martong
Subscribers: mgorny, whisperity, baloghadamsoftware, szepet, rnkovacs, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits
Differential Revision: https://reviews.llvm.org/D56441
llvm-svn: 350852
Diffstat (limited to 'clang/tools/clang-func-mapping/ClangFnMapGen.cpp')
-rw-r--r-- | clang/tools/clang-func-mapping/ClangFnMapGen.cpp | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/clang/tools/clang-func-mapping/ClangFnMapGen.cpp b/clang/tools/clang-func-mapping/ClangFnMapGen.cpp deleted file mode 100644 index 635bb0296c5..00000000000 --- a/clang/tools/clang-func-mapping/ClangFnMapGen.cpp +++ /dev/null @@ -1,118 +0,0 @@ -//===- ClangFnMapGen.cpp -----------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===--------------------------------------------------------------------===// -// -// Clang tool which creates a list of defined functions and the files in which -// they are defined. -// -//===--------------------------------------------------------------------===// - -#include "clang/AST/ASTConsumer.h" -#include "clang/AST/ASTContext.h" -#include "clang/Basic/SourceManager.h" -#include "clang/CrossTU/CrossTranslationUnit.h" -#include "clang/Frontend/CompilerInstance.h" -#include "clang/Frontend/FrontendActions.h" -#include "clang/Tooling/CommonOptionsParser.h" -#include "clang/Tooling/Tooling.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/Signals.h" -#include <sstream> -#include <string> - -using namespace llvm; -using namespace clang; -using namespace clang::cross_tu; -using namespace clang::tooling; - -static cl::OptionCategory ClangFnMapGenCategory("clang-fnmapgen options"); - -class MapFunctionNamesConsumer : public ASTConsumer { -public: - MapFunctionNamesConsumer(ASTContext &Context) - : SM(Context.getSourceManager()) {} - - ~MapFunctionNamesConsumer() { - // Flush results to standard output. - llvm::outs() << createCrossTUIndexString(Index); - } - - void HandleTranslationUnit(ASTContext &Ctx) override { - handleDecl(Ctx.getTranslationUnitDecl()); - } - -private: - void handleDecl(const Decl *D); - - SourceManager &SM; - llvm::StringMap<std::string> Index; - std::string CurrentFileName; -}; - -void MapFunctionNamesConsumer::handleDecl(const Decl *D) { - if (!D) - return; - - if (const auto *FD = dyn_cast<FunctionDecl>(D)) { - if (FD->isThisDeclarationADefinition()) { - if (const Stmt *Body = FD->getBody()) { - if (CurrentFileName.empty()) { - CurrentFileName = - SM.getFileEntryForID(SM.getMainFileID())->tryGetRealPathName(); - if (CurrentFileName.empty()) - CurrentFileName = "invalid_file"; - } - - switch (FD->getLinkageInternal()) { - case ExternalLinkage: - case VisibleNoLinkage: - case UniqueExternalLinkage: - if (SM.isInMainFile(Body->getBeginLoc())) { - std::string LookupName = - CrossTranslationUnitContext::getLookupName(FD); - Index[LookupName] = CurrentFileName; - } - break; - default: - break; - } - } - } - } - - if (const auto *DC = dyn_cast<DeclContext>(D)) - for (const Decl *D : DC->decls()) - handleDecl(D); -} - -class MapFunctionNamesAction : public ASTFrontendAction { -protected: - std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, - llvm::StringRef) { - return llvm::make_unique<MapFunctionNamesConsumer>(CI.getASTContext()); - } -}; - -static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); - -int main(int argc, const char **argv) { - // Print a stack trace if we signal out. - sys::PrintStackTraceOnErrorSignal(argv[0], false); - PrettyStackTraceProgram X(argc, argv); - - const char *Overview = "\nThis tool collects the USR name and location " - "of all functions definitions in the source files " - "(excluding headers).\n"; - CommonOptionsParser OptionsParser(argc, argv, ClangFnMapGenCategory, - cl::ZeroOrMore, Overview); - - ClangTool Tool(OptionsParser.getCompilations(), - OptionsParser.getSourcePathList()); - - return Tool.run(newFrontendActionFactory<MapFunctionNamesAction>().get()); -} |