xazax.hun created this revision.
xazax.hun added reviewers: NoQ, george.karpenkov, Szelethus, martong.
Herald added subscribers: dkrupp, donat.nagy, arphaman, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware, whisperity, mgorny.

Do not always return 0 to the OS. This will make it easier for orchestration 
tools like CodeChecker to detect errors.
Also small NFC cleanups along the way.


Repository:
  rC Clang

https://reviews.llvm.org/D53979

Files:
  tools/clang-func-mapping/CMakeLists.txt
  tools/clang-func-mapping/ClangFnMapGen.cpp

Index: tools/clang-func-mapping/ClangFnMapGen.cpp
===================================================================
--- tools/clang-func-mapping/ClangFnMapGen.cpp
+++ tools/clang-func-mapping/ClangFnMapGen.cpp
@@ -14,23 +14,17 @@
 
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/GlobalDecl.h"
-#include "clang/AST/Mangle.h"
-#include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/SourceManager.h"
-#include "clang/Basic/TargetInfo.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Index/USRGeneration.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Path.h"
 #include "llvm/Support/Signals.h"
 #include <sstream>
 #include <string>
-#include <vector>
 
 using namespace llvm;
 using namespace clang;
@@ -41,21 +35,22 @@
 
 class MapFunctionNamesConsumer : public ASTConsumer {
 public:
-  MapFunctionNamesConsumer(ASTContext &Context) : Ctx(Context) {}
+  MapFunctionNamesConsumer(ASTContext &Context)
+      : SM(Context.getSourceManager()) {}
 
   ~MapFunctionNamesConsumer() {
     // Flush results to standard output.
     llvm::outs() << createCrossTUIndexString(Index);
   }
 
-  virtual void HandleTranslationUnit(ASTContext &Ctx) {
+  void HandleTranslationUnit(ASTContext &Ctx) override {
     handleDecl(Ctx.getTranslationUnitDecl());
   }
 
 private:
   void handleDecl(const Decl *D);
 
-  ASTContext &Ctx;
+  SourceManager &SM;
   llvm::StringMap<std::string> Index;
   std::string CurrentFileName;
 };
@@ -67,8 +62,6 @@
   if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
     if (FD->isThisDeclarationADefinition()) {
       if (const Stmt *Body = FD->getBody()) {
-        std::string LookupName = CrossTranslationUnitContext::getLookupName(FD);
-        const SourceManager &SM = Ctx.getSourceManager();
         if (CurrentFileName.empty()) {
           CurrentFileName =
               SM.getFileEntryForID(SM.getMainFileID())->tryGetRealPathName();
@@ -80,8 +73,11 @@
         case ExternalLinkage:
         case VisibleNoLinkage:
         case UniqueExternalLinkage:
-          if (SM.isInMainFile(Body->getBeginLoc()))
+          if (SM.isInMainFile(Body->getBeginLoc())) {
+            std::string LookupName =
+                CrossTranslationUnitContext::getLookupName(FD);
             Index[LookupName] = CurrentFileName;
+          }
         default:
           break;
         }
@@ -98,9 +94,7 @@
 protected:
   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
                                                  llvm::StringRef) {
-    std::unique_ptr<ASTConsumer> PFC(
-        new MapFunctionNamesConsumer(CI.getASTContext()));
-    return PFC;
+    return llvm::make_unique<MapFunctionNamesConsumer>(CI.getASTContext());
   }
 };
 
@@ -119,6 +113,6 @@
 
   ClangTool Tool(OptionsParser.getCompilations(),
                  OptionsParser.getSourcePathList());
-  Tool.run(newFrontendActionFactory<MapFunctionNamesAction>().get());
-  return 0;
+  
+  return Tool.run(newFrontendActionFactory<MapFunctionNamesAction>().get());
 }
Index: tools/clang-func-mapping/CMakeLists.txt
===================================================================
--- tools/clang-func-mapping/CMakeLists.txt
+++ tools/clang-func-mapping/CMakeLists.txt
@@ -1,8 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
-  asmparser
   support
-  mc
   )
 
 add_clang_executable(clang-func-mapping
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to