]> granicus.if.org Git - clang/commitdiff
serialization::TypeID is used with or without qualifiers, both as index and as index...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 20 Aug 2010 16:03:59 +0000 (16:03 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 20 Aug 2010 16:03:59 +0000 (16:03 +0000)
Disambiguate and provide some type safety by using a new class TypeIdx for the "TypeID as index" semantics.

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

include/clang/Serialization/ASTBitCodes.h
include/clang/Serialization/ASTDeserializationListener.h
include/clang/Serialization/ASTReader.h
include/clang/Serialization/ASTWriter.h
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp

index 55c11e29f0b470d38a1061eb9b74eeb7bf310d5a..3156a36040a0aa78fd42372e223c8d26dfdec5ab 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef LLVM_CLANG_FRONTEND_PCHBITCODES_H
 #define LLVM_CLANG_FRONTEND_PCHBITCODES_H
 
+#include "clang/AST/Type.h"
 #include "llvm/Bitcode/BitCodes.h"
 #include "llvm/System/DataTypes.h"
 
@@ -64,6 +65,22 @@ namespace clang {
     /// other types that have serialized representations.
     typedef uint32_t TypeID;
 
+    /// \brief A type index; the type ID with the qualifier bits removed.
+    class TypeIdx {
+      uint32_t Idx;
+    public:
+      TypeIdx() : Idx(0) { }
+      explicit TypeIdx(uint32_t index) : Idx(index) { }
+
+      uint32_t getIndex() const { return Idx; }
+      TypeID asTypeID(unsigned FastQuals) const {
+        return (Idx << Qualifiers::FastWidth) | FastQuals;
+      }
+      static TypeIdx fromTypeID(TypeID ID) {
+        return TypeIdx(ID >> Qualifiers::FastWidth);
+      }
+    };
+
     /// \brief An ID number that refers to an identifier in an AST
     /// file.
     typedef uint32_t IdentID;
index 543d29e6e2a62d00086f9716e1e450ffbdc1141e..f8114de5f15a87116822d5ca7a2dbc04a2e1d9b5 100644 (file)
@@ -37,7 +37,7 @@ public:
   /// \brief A type was deserialized from the AST file. The ID here has the
   ///        qualifier bits already removed, and T is guaranteed to be locally
   ///        unqualified.
-  virtual void TypeRead(serialization::TypeID ID, QualType T) = 0;
+  virtual void TypeRead(serialization::TypeIdx Idx, QualType T) = 0;
   /// \brief A decl was deserialized from the AST file.
   virtual void DeclRead(serialization::DeclID ID, const Decl *D) = 0;
   /// \brief A selector was read from the AST file.
index d4a0ea9f48cd5e73461f6e19507e2dc5d952ee5c..cbc3775cefe2aba28621311898fbf49f85b36e1c 100644 (file)
@@ -18,7 +18,6 @@
 #include "clang/Sema/ExternalSemaSource.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/DeclObjC.h"
-#include "clang/AST/Type.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/Lex/ExternalPreprocessorSource.h"
 #include "clang/Lex/PreprocessingRecord.h"
index 68a6eb0cb89bfd297d6ba57a043cfaaf709fb750..0776c69714dabe9104636e9707b09d2fd4392c90 100644 (file)
@@ -146,7 +146,7 @@ private:
   /// allow for the const/volatile qualifiers.
   ///
   /// Keys in the map never have const/volatile qualifiers.
-  llvm::DenseMap<QualType, serialization::TypeID, UnsafeQualTypeDenseMapInfo>
+  llvm::DenseMap<QualType, serialization::TypeIdx, UnsafeQualTypeDenseMapInfo>
       TypeIDs;
 
   /// \brief Offset of each type in the bitstream, indexed by
@@ -466,7 +466,7 @@ public:
   // ASTDeserializationListener implementation
   void SetReader(ASTReader *Reader);
   void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II);
-  void TypeRead(serialization::TypeID ID, QualType T);
+  void TypeRead(serialization::TypeIdx Idx, QualType T);
   void DeclRead(serialization::DeclID ID, const Decl *D);
   void SelectorRead(serialization::SelectorID iD, Selector Sel);
 };
index 238ce3f5ed883bc9b9889324a2d59f2828ac9575..040277074c221ef371c6f5f57cf88bbd43b4a775 100644 (file)
@@ -2826,7 +2826,7 @@ QualType ASTReader::GetType(TypeID ID) {
     TypesLoaded[Index] = ReadTypeRecord(Index);
     TypesLoaded[Index]->setFromAST();
     if (DeserializationListener)
-      DeserializationListener->TypeRead(ID >> Qualifiers::FastWidth,
+      DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID),
                                         TypesLoaded[Index]);
   }
 
index b305fffbc8b0437b9e24f0b9f7d3a060a58762c5..30a5d16e9eab3d76c0179b57afe4941416c00f63 100644 (file)
@@ -1397,12 +1397,12 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
 
 /// \brief Write the representation of a type to the AST stream.
 void ASTWriter::WriteType(QualType T) {
-  TypeID &ID = TypeIDs[T];
-  if (ID == 0) // we haven't seen this type before.
-    ID = NextTypeID++;
+  TypeIdx &Idx = TypeIDs[T];
+  if (Idx.getIndex() == 0) // we haven't seen this type before.
+    Idx = TypeIdx(NextTypeID++);
 
   // Record the offset for this type.
-  unsigned Index = ID - FirstTypeID;
+  unsigned Index = Idx.getIndex() - FirstTypeID;
   if (TypeOffsets.size() == Index)
     TypeOffsets.push_back(Stream.GetCurrentBitNo());
   else if (TypeOffsets.size() < Index) {
@@ -2588,17 +2588,17 @@ void ASTWriter::AddTypeRef(QualType T, RecordData &Record) {
   T.removeFastQualifiers();
 
   if (T.hasLocalNonFastQualifiers()) {
-    TypeID &ID = TypeIDs[T];
-    if (ID == 0) {
+    TypeIdx &Idx = TypeIDs[T];
+    if (Idx.getIndex() == 0) {
       // We haven't seen these qualifiers applied to this type before.
       // Assign it a new ID.  This is the only time we enqueue a
       // qualified type, and it has no CV qualifiers.
-      ID = NextTypeID++;
+      Idx = TypeIdx(NextTypeID++);
       DeclTypesToEmit.push(T);
     }
 
     // Encode the type qualifiers in the type reference.
-    Record.push_back((ID << Qualifiers::FastWidth) | FastQuals);
+    Record.push_back(Idx.asTypeID(FastQuals));
     return;
   }
 
@@ -2640,20 +2640,20 @@ void ASTWriter::AddTypeRef(QualType T, RecordData &Record) {
       break;
     }
 
-    Record.push_back((ID << Qualifiers::FastWidth) | FastQuals);
+    Record.push_back(TypeIdx(ID).asTypeID(FastQuals));
     return;
   }
 
-  TypeID &ID = TypeIDs[T];
-  if (ID == 0) {
+  TypeIdx &Idx = TypeIDs[T];
+  if (Idx.getIndex() == 0) {
     // We haven't seen this type before. Assign it a new ID and put it
     // into the queue of types to emit.
-    ID = NextTypeID++;
+    Idx = TypeIdx(NextTypeID++);
     DeclTypesToEmit.push(T);
   }
 
   // Encode the type qualifiers in the type reference.
-  Record.push_back((ID << Qualifiers::FastWidth) | FastQuals);
+  Record.push_back(Idx.asTypeID(FastQuals));
 }
 
 void ASTWriter::AddDeclRef(const Decl *D, RecordData &Record) {
@@ -2920,8 +2920,8 @@ void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) {
   IdentifierIDs[II] = ID;
 }
 
-void ASTWriter::TypeRead(TypeID ID, QualType T) {
-  TypeIDs[T] = ID;
+void ASTWriter::TypeRead(TypeIdx Idx, QualType T) {
+  TypeIDs[T] = Idx;
 }
 
 void ASTWriter::DeclRead(DeclID ID, const Decl *D) {