]> granicus.if.org Git - clang/commitdiff
ArrayRef-ize a pointer/length pair.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 23 Jul 2015 00:53:59 +0000 (00:53 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 23 Jul 2015 00:53:59 +0000 (00:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242977 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Serialization/Module.h
lib/Serialization/ASTReader.cpp

index 5ae9ec7d19a539d65312ad4a090beee76dc30b7c..1d9fb0bfe8d455a542ef23d875b34178ad39c4d5 100644 (file)
@@ -53,12 +53,11 @@ enum ModuleKind {
 /// \brief Information about the contents of a DeclContext.
 struct DeclContextInfo {
   DeclContextInfo()
-    : NameLookupTableData(), LexicalDecls(), NumLexicalDecls() {}
+    : NameLookupTableData(), LexicalDecls() {}
 
   llvm::OnDiskIterableChainedHashTable<reader::ASTDeclContextNameLookupTrait>
     *NameLookupTableData; // an ASTDeclContextNameLookupTable.
-  const KindDeclIDPair *LexicalDecls;
-  unsigned NumLexicalDecls;
+  ArrayRef<KindDeclIDPair> LexicalDecls;
 };
 
 /// \brief The input file that has been loaded from this AST file, along with
index c6fe363d7b56079b386557e41de48dce848756d9..73985fe2286d9de1c47d24e9dbbd3940dc430631 100644 (file)
@@ -973,8 +973,9 @@ bool ASTReader::ReadDeclContextStorage(ModuleFile &M,
       return true;
     }
 
-    Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob.data());
-    Info.NumLexicalDecls = Blob.size() / sizeof(KindDeclIDPair);
+    Info.LexicalDecls = llvm::makeArrayRef(
+        reinterpret_cast<const KindDeclIDPair *>(Blob.data()),
+        Blob.size() / sizeof(KindDeclIDPair));
   }
 
   // Now the lookup table.
@@ -2496,9 +2497,9 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
     case TU_UPDATE_LEXICAL: {
       DeclContext *TU = Context.getTranslationUnitDecl();
       DeclContextInfo &Info = F.DeclContextInfos[TU];
-      Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(Blob.data());
-      Info.NumLexicalDecls 
-        = static_cast<unsigned int>(Blob.size() / sizeof(KindDeclIDPair));
+      Info.LexicalDecls = llvm::makeArrayRef(
+          reinterpret_cast<const KindDeclIDPair *>(Blob.data()),
+          static_cast<unsigned int>(Blob.size() / sizeof(KindDeclIDPair)));
       TU->setHasExternalLexicalStorage(true);
       break;
     }
@@ -6202,26 +6203,24 @@ namespace {
 
       ModuleFile::DeclContextInfosMap::iterator Info
         = M.DeclContextInfos.find(This->DC);
-      if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls)
+      if (Info == M.DeclContextInfos.end() || Info->second.LexicalDecls.empty())
         return false;
 
       // Load all of the declaration IDs
-      for (const KindDeclIDPair *ID = Info->second.LexicalDecls,
-                               *IDE = ID + Info->second.NumLexicalDecls; 
-           ID != IDE; ++ID) {
-        if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first))
+      for (const KindDeclIDPair &P : Info->second.LexicalDecls) {
+        if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)P.first))
           continue;
 
         // Don't add predefined declarations to the lexical context more
         // than once.
-        if (ID->second < NUM_PREDEF_DECL_IDS) {
-          if (This->PredefsVisited[ID->second])
+        if (P.second < NUM_PREDEF_DECL_IDS) {
+          if (This->PredefsVisited[P.second])
             continue;
 
-          This->PredefsVisited[ID->second] = true;
+          This->PredefsVisited[P.second] = true;
         }
 
-        if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) {
+        if (Decl *D = This->Reader.GetLocalDecl(M, P.second)) {
           if (!This->DC->isDeclInLexicalTraversal(D))
             This->Decls.push_back(D);
         }