[cfe-commits] r136411 - in /cfe/trunk: include/clang/Serialization/ASTBitCodes.h include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp

Douglas Gregor dgregor at apple.com
Thu Jul 28 15:39:26 PDT 2011


Author: dgregor
Date: Thu Jul 28 17:39:26 2011
New Revision: 136411

URL: http://llvm.org/viewvc/llvm-project?rev=136411&view=rev
Log:
Introduce the local-global mapping for preprocessed entities, and use
it appropriately. Also, patch up a place where we were failing to map
local macro definition IDs into global macro definition IDs.

Modified:
    cfe/trunk/include/clang/Serialization/ASTBitCodes.h
    cfe/trunk/include/clang/Serialization/ASTReader.h
    cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=136411&r1=136410&r2=136411&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Thu Jul 28 17:39:26 2011
@@ -134,6 +134,10 @@
     /// AST file.
     typedef uint32_t CXXBaseSpecifiersID;
     
+    /// \brief An ID number that refers to an entity in the detailed
+    /// preprocessing record.
+    typedef uint32_t PreprocessedEntityID;
+    
     /// \brief Describes the various kinds of blocks that occur within
     /// an AST file.
     enum BlockIDs {

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=136411&r1=136410&r2=136411&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Jul 28 17:39:26 2011
@@ -1584,6 +1584,11 @@
   /// position.
   PreprocessedEntity *LoadPreprocessedEntity(Module &F);
       
+  /// \brief Determine the global preprocessed entity ID that corresponds to
+  /// the given local ID within the given module.
+  serialization::PreprocessedEntityID 
+  getGlobalPreprocessedEntityID(Module &M, unsigned LocalID);
+  
   /// \brief Note that the identifier is a macro whose record will be loaded
   /// from the given AST file at the given (file-local) offset.
   void SetIdentifierIsMacro(IdentifierInfo *II, Module &F,

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=136411&r1=136410&r2=136411&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Jul 28 17:39:26 2011
@@ -1570,7 +1570,8 @@
                                              Code, Record, BlobStart, BlobLen);
   switch (RecType) {
   case PPD_MACRO_EXPANSION: {
-    if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(Record[0]))
+    PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]);
+    if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID))
       return PE;
     
     MacroExpansion *ME =
@@ -1578,15 +1579,17 @@
                                  SourceRange(ReadSourceLocation(F, Record[1]),
                                              ReadSourceLocation(F, Record[2])),
                                  getLocalMacroDefinition(F, Record[4]));
-    PPRec.setLoadedPreallocatedEntity(Record[0], ME);
+    PPRec.setLoadedPreallocatedEntity(GlobalID, ME);
     return ME;
   }
       
   case PPD_MACRO_DEFINITION: {
-    if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(Record[0]))
+    PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]);
+    if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID))
       return PE;
-    
-    if (Record[1] > MacroDefinitionsLoaded.size()) {
+
+    unsigned MacroDefID = getGlobalMacroDefinitionID(F, Record[1]);
+    if (MacroDefID > MacroDefinitionsLoaded.size()) {
       Error("out-of-bounds macro definition record");
       return 0;
     }
@@ -1594,7 +1597,7 @@
     // Decode the identifier info and then check again; if the macro is
     // still defined and associated with the identifier,
     IdentifierInfo *II = getLocalIdentifier(F, Record[4]);
-    if (!MacroDefinitionsLoaded[Record[1] - 1]) {
+    if (!MacroDefinitionsLoaded[MacroDefID - 1]) {
       MacroDefinition *MD
         = new (PPRec) MacroDefinition(II,
                                       ReadSourceLocation(F, Record[5]),
@@ -1602,24 +1605,25 @@
                                             ReadSourceLocation(F, Record[2]),
                                             ReadSourceLocation(F, Record[3])));
       
-      PPRec.setLoadedPreallocatedEntity(Record[0], MD);
-      MacroDefinitionsLoaded[Record[1] - 1] = MD;
+      PPRec.setLoadedPreallocatedEntity(GlobalID, MD);
+      MacroDefinitionsLoaded[MacroDefID - 1] = MD;
       
       if (DeserializationListener)
-        DeserializationListener->MacroDefinitionRead(Record[1], MD);
+        DeserializationListener->MacroDefinitionRead(MacroDefID, MD);
     }
     
-    return MacroDefinitionsLoaded[Record[1] - 1];
+    return MacroDefinitionsLoaded[MacroDefID - 1];
   }
       
   case PPD_INCLUSION_DIRECTIVE: {
-    if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(Record[0]))
+    PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]);
+    if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID))
       return PE;
     
     const char *FullFileNameStart = BlobStart + Record[3];
     const FileEntry *File
       = PP->getFileManager().getFile(StringRef(FullFileNameStart,
-                                                     BlobLen - Record[3]));
+                                               BlobLen - Record[3]));
     
     // FIXME: Stable encoding
     InclusionDirective::InclusionKind Kind
@@ -1631,7 +1635,7 @@
                                        File,
                                  SourceRange(ReadSourceLocation(F, Record[1]),
                                              ReadSourceLocation(F, Record[2])));
-    PPRec.setLoadedPreallocatedEntity(Record[0], ID);
+    PPRec.setLoadedPreallocatedEntity(GlobalID, ID);
     return ID;
   }
   }
@@ -1640,6 +1644,12 @@
   return 0;
 }
 
+PreprocessedEntityID 
+ASTReader::getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) {
+  // FIXME: Local-to-global mapping
+  return LocalID;
+}
+
 namespace {
   /// \brief Trait class used to search the on-disk hash table containing all of
   /// the header search information.





More information about the cfe-commits mailing list