r320030 - [Index] Add setPreprocessor member to IndexDataConsumer.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 7 03:04:24 PST 2017


Author: ioeric
Date: Thu Dec  7 03:04:24 2017
New Revision: 320030

URL: http://llvm.org/viewvc/llvm-project?rev=320030&view=rev
Log:
[Index] Add setPreprocessor member to IndexDataConsumer.

Summary:
This enables us to use information in Preprocessor when handling symbol
occurrences.

Reviewers: arphaman, hokein

Reviewed By: hokein

Subscribers: malaperle, cfe-commits

Differential Revision: https://reviews.llvm.org/D40884

Modified:
    cfe/trunk/include/clang/Index/IndexDataConsumer.h
    cfe/trunk/lib/Index/IndexingAction.cpp
    cfe/trunk/tools/libclang/CXIndexDataConsumer.h

Modified: cfe/trunk/include/clang/Index/IndexDataConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexDataConsumer.h?rev=320030&r1=320029&r2=320030&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/IndexDataConsumer.h (original)
+++ cfe/trunk/include/clang/Index/IndexDataConsumer.h Thu Dec  7 03:04:24 2017
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_INDEX_INDEXDATACONSUMER_H
 
 #include "clang/Index/IndexSymbol.h"
+#include "clang/Lex/Preprocessor.h"
 
 namespace clang {
   class ASTContext;
@@ -36,6 +37,8 @@ public:
 
   virtual void initialize(ASTContext &Ctx) {}
 
+  virtual void setPreprocessor(std::shared_ptr<Preprocessor> PP) {}
+
   /// \returns true to continue indexing, or false to abort.
   virtual bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles,
                                    ArrayRef<SymbolRelation> Relations,

Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=320030&r1=320029&r2=320030&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Thu Dec  7 03:04:24 2017
@@ -8,10 +8,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Index/IndexingAction.h"
-#include "clang/Index/IndexDataConsumer.h"
 #include "IndexingContext.h"
+#include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/MultiplexConsumer.h"
+#include "clang/Index/IndexDataConsumer.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
 
@@ -42,16 +43,18 @@ bool IndexDataConsumer::handleModuleOccu
 namespace {
 
 class IndexASTConsumer : public ASTConsumer {
+  std::shared_ptr<Preprocessor> PP;
   IndexingContext &IndexCtx;
 
 public:
-  IndexASTConsumer(IndexingContext &IndexCtx)
-    : IndexCtx(IndexCtx) {}
+  IndexASTConsumer(std::shared_ptr<Preprocessor> PP, IndexingContext &IndexCtx)
+      : PP(std::move(PP)), IndexCtx(IndexCtx) {}
 
 protected:
   void Initialize(ASTContext &Context) override {
     IndexCtx.setASTContext(Context);
     IndexCtx.getDataConsumer().initialize(Context);
+    IndexCtx.getDataConsumer().setPreprocessor(PP);
   }
 
   bool HandleTopLevelDecl(DeclGroupRef DG) override {
@@ -80,8 +83,10 @@ protected:
     : DataConsumer(std::move(dataConsumer)),
       IndexCtx(Opts, *DataConsumer) {}
 
-  std::unique_ptr<IndexASTConsumer> createIndexASTConsumer() {
-    return llvm::make_unique<IndexASTConsumer>(IndexCtx);
+  std::unique_ptr<IndexASTConsumer>
+  createIndexASTConsumer(CompilerInstance &CI) {
+    return llvm::make_unique<IndexASTConsumer>(CI.getPreprocessorPtr(),
+                                               IndexCtx);
   }
 
   void finish() {
@@ -98,7 +103,7 @@ public:
 protected:
   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
                                                  StringRef InFile) override {
-    return createIndexASTConsumer();
+    return createIndexASTConsumer(CI);
   }
 
   void EndSourceFileAction() override {
@@ -142,7 +147,7 @@ WrappingIndexAction::CreateASTConsumer(C
 
   std::vector<std::unique_ptr<ASTConsumer>> Consumers;
   Consumers.push_back(std::move(OtherConsumer));
-  Consumers.push_back(createIndexASTConsumer());
+  Consumers.push_back(createIndexASTConsumer(CI));
   return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
 }
 
@@ -173,6 +178,7 @@ void index::indexASTUnit(ASTUnit &Unit,
   IndexingContext IndexCtx(Opts, *DataConsumer);
   IndexCtx.setASTContext(Unit.getASTContext());
   DataConsumer->initialize(Unit.getASTContext());
+  DataConsumer->setPreprocessor(Unit.getPreprocessorPtr());
   indexTranslationUnit(Unit, IndexCtx);
   DataConsumer->finish();
 }
@@ -198,7 +204,7 @@ void index::indexModuleFile(serializatio
   IndexCtx.setASTContext(Ctx);
   DataConsumer->initialize(Ctx);
 
-  for (const Decl *D :Reader.getModuleFileLevelDecls(Mod)) {
+  for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) {
     IndexCtx.indexTopLevelDecl(D);
   }
   DataConsumer->finish();

Modified: cfe/trunk/tools/libclang/CXIndexDataConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXIndexDataConsumer.h?rev=320030&r1=320029&r2=320030&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.h (original)
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.h Thu Dec  7 03:04:24 2017
@@ -342,7 +342,7 @@ public:
   CXTranslationUnit getCXTU() const { return CXTU; }
 
   void setASTContext(ASTContext &ctx);
-  void setPreprocessor(std::shared_ptr<Preprocessor> PP);
+  void setPreprocessor(std::shared_ptr<Preprocessor> PP) override;
 
   bool shouldSuppressRefs() const {
     return IndexOptions & CXIndexOpt_SuppressRedundantRefs;




More information about the cfe-commits mailing list