]> granicus.if.org Git - clang/commitdiff
[modules] Store a local offset to DeclContext lexical and visible contents. Saves...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 25 Mar 2016 01:17:43 +0000 (01:17 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 25 Mar 2016 01:17:43 +0000 (01:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264377 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp

index 573a13aee2de49ef6a0d761b0e90a5f770ba5e59..abfee00cf3aca39484061f4a92662fdebc694611 100644 (file)
@@ -53,6 +53,12 @@ namespace clang {
 
     uint64_t GetCurrentCursorOffset();
 
+    uint64_t ReadLocalOffset(const RecordData &R, unsigned &I) {
+      uint64_t LocalOffset = R[I++];
+      assert(LocalOffset < Offset && "offset point after current record");
+      return LocalOffset ? Offset - LocalOffset : 0;
+    }
+
     SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
       return Reader.ReadSourceLocation(F, R, I);
     }
@@ -2189,8 +2195,8 @@ void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) {
 
 std::pair<uint64_t, uint64_t>
 ASTDeclReader::VisitDeclContext(DeclContext *DC) {
-  uint64_t LexicalOffset = Record[Idx++];
-  uint64_t VisibleOffset = Record[Idx++];
+  uint64_t LexicalOffset = ReadLocalOffset(Record, Idx);
+  uint64_t VisibleOffset = ReadLocalOffset(Record, Idx);
   return std::make_pair(LexicalOffset, VisibleOffset);
 }
 
@@ -2225,10 +2231,7 @@ ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
     for (unsigned I = 0; I != N - 1; ++I)
       MergeWith = ReadDecl(Record, Idx/*, MergeWith*/);
 
-    RedeclOffset = Record[Idx++];
-    // RedeclOffset is a delta relative to the start of this record.
-    if (RedeclOffset)
-      RedeclOffset = Offset - RedeclOffset;
+    RedeclOffset = ReadLocalOffset(Record, Idx);
   } else {
     // This declaration was not the first local declaration. Read the first
     // local declaration now, to trigger the import of other redeclarations.
index e22a94df2f3d976c492dbf0168dc92ce21638622..752373646e608451bc1ca7e8963540bdadc83901 100644 (file)
@@ -136,6 +136,12 @@ namespace clang {
     void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
     void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
 
+    void AddLocalOffset(uint64_t LocalOffset) {
+      uint64_t Offset = Writer.Stream.GetCurrentBitNo();
+      assert(LocalOffset < Offset && "invalid offset");
+      Record.push_back(LocalOffset ? Offset - LocalOffset : 0);
+    }
+
     /// Add an Objective-C type parameter list to the given record.
     void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
       // Empty type parameter list.
@@ -1555,8 +1561,8 @@ void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
 /// contexts.
 void ASTDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
                                      uint64_t VisibleOffset) {
-  Record.push_back(LexicalOffset);
-  Record.push_back(VisibleOffset);
+  AddLocalOffset(LexicalOffset);
+  AddLocalOffset(VisibleOffset);
 }
 
 const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
@@ -1626,7 +1632,7 @@ void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
       else {
         auto Start = Writer.Stream.GetCurrentBitNo();
         Writer.Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedecls);
-        Record.push_back(Writer.Stream.GetCurrentBitNo() - Start);
+        AddLocalOffset(Start);
       }
     } else {
       Record.push_back(0);