]> granicus.if.org Git - clang/commitdiff
[libclang] When indexing an AST file, only deserialize the preprocessing record
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 2 Oct 2012 16:10:51 +0000 (16:10 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 2 Oct 2012 16:10:51 +0000 (16:10 +0000)
entities of the current primary module.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165023 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/ASTUnit.h
include/clang/Lex/PreprocessingRecord.h
include/clang/Serialization/ASTReader.h
lib/Frontend/ASTUnit.cpp
lib/Serialization/ASTReader.cpp
tools/libclang/Indexing.cpp

index 5e69abb9aeba520bfe134514ee2fba289f5387a8..22cc581531f473a9f4fc007f5c99328fc2fb3168 100644 (file)
@@ -607,6 +607,12 @@ public:
     return CachedCompletionResults.size(); 
   }
 
+  /// \brief Returns an iterator range for the local preprocessing entities
+  /// of the local Preprocessor, if this is a parsed source file, or the loaded
+  /// preprocessing entities of the primary module if this is an AST file.
+  std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
+    getLocalPreprocessingEntities() const;
+
   llvm::MemoryBuffer *getBufferForFile(StringRef Filename,
                                        std::string *ErrorStr = 0);
 
index 1a0734b5438698f344b7d3da7baaac90dce86225..a569575aa35257e44189ce61a64ef8b44f9234b6 100644 (file)
@@ -548,6 +548,17 @@ namespace clang {
       return iterator(this, PreprocessedEntities.size());
     }
 
+    /// \brief begin/end iterator pair for the given range of loaded
+    /// preprocessed entities.
+    std::pair<iterator, iterator>
+    getIteratorsForLoadedRange(unsigned start, unsigned count) {
+      unsigned end = start + count;
+      assert(end <= LoadedPreprocessedEntities.size());
+      return std::make_pair(
+                   iterator(this, int(start)-LoadedPreprocessedEntities.size()),
+                   iterator(this, int(end)-LoadedPreprocessedEntities.size()));
+    }
+
     /// \brief Returns a pair of [Begin, End) iterators of preprocessed entities
     /// that source range \p R encompasses.
     ///
index a3abce11684e257bf57124b256bce8ac3024abec..b5d1e62a20682480c4405c133279189ed288fcb1 100644 (file)
@@ -855,6 +855,11 @@ private:
   std::pair<ModuleFile *, unsigned>
     getModulePreprocessedEntity(unsigned GlobalIndex);
 
+  /// \brief Returns (begin, end) pair for the preprocessed entities of a
+  /// particular module.
+  std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
+    getModulePreprocessedEntities(ModuleFile &Mod) const;
+
   void PassInterestingDeclsToConsumer();
   void PassInterestingDeclToConsumer(Decl *D);
 
index 22476cae0aac4b6fbe20ceea64b91746acfa7304..2cf25ebd9ac41224ad4c9df4fde06418b927678d 100644 (file)
@@ -2777,6 +2777,21 @@ SourceLocation ASTUnit::getStartOfMainFileID() {
   return SourceMgr->getLocForStartOfFile(FID);
 }
 
+std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
+ASTUnit::getLocalPreprocessingEntities() const {
+  if (isMainFileAST()) {
+    serialization::ModuleFile &
+      Mod = Reader->getModuleManager().getPrimaryModule();
+    return Reader->getModulePreprocessedEntities(Mod);
+  }
+
+  if (PreprocessingRecord *PPRec = PP->getPreprocessingRecord())
+    return std::make_pair(PPRec->local_begin(), PPRec->local_end());
+
+  return std::make_pair(PreprocessingRecord::iterator(),
+                        PreprocessingRecord::iterator());
+}
+
 void ASTUnit::PreambleData::countLines() const {
   NumLines = 0;
   if (empty())
index b5e579566afa864ee65666d9fed4807717621863..6bf6f94fbbaf55a4309cabab29593c5297f39a07 100644 (file)
@@ -3381,6 +3381,16 @@ ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) {
   return std::make_pair(M, LocalIndex);
 }
 
+std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
+ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const {
+  if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord())
+    return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID,
+                                             Mod.NumPreprocessedEntities);
+
+  return std::make_pair(PreprocessingRecord::iterator(),
+                        PreprocessingRecord::iterator());
+}
+
 PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
   PreprocessedEntityID PPID = Index+1;
   std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
index f6314b90ec9174703a94d9f8d68d959aaceb9d7e..8c19aeba28553aed3d5473f8da350fcb8939e8bd 100644 (file)
@@ -455,21 +455,10 @@ static void indexPreprocessingRecord(ASTUnit &Unit, IndexingContext &IdxCtx) {
   if (!PP.getPreprocessingRecord())
     return;
 
-  PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
-
   // FIXME: Only deserialize inclusion directives.
-  // FIXME: Only deserialize stuff from the last chained PCH, not the PCH/Module
-  // that it depends on.
 
-  bool OnlyLocal = !Unit.isMainFileAST() && Unit.getOnlyLocalDecls();
   PreprocessingRecord::iterator I, E;
-  if (OnlyLocal) {
-    I = PPRec.local_begin();
-    E = PPRec.local_end();
-  } else {
-    I = PPRec.begin();
-    E = PPRec.end();
-  }
+  llvm::tie(I, E) = Unit.getLocalPreprocessingEntities();
 
   for (; I != E; ++I) {
     PreprocessedEntity *PPE = *I;