]> granicus.if.org Git - clang/commitdiff
A bit of refactoring; Introduce ASTWriter::GetOrCreateTypeIdx and move the emission...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 20 Aug 2010 16:04:09 +0000 (16:04 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 20 Aug 2010 16:04:09 +0000 (16:04 +0000)
No functionality change.

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

include/clang/Serialization/ASTWriter.h
lib/Serialization/ASTWriter.cpp

index c03ad6c0f45fd327c292f0314b300033c2a45931..1634dfb26293e086cc5c825bdca58a64ab2f8bfb 100644 (file)
@@ -364,6 +364,12 @@ public:
   /// \brief Emit a reference to a type.
   void AddTypeRef(QualType T, RecordData &Record);
 
+  /// \brief Force a type to be emitted and get its index.
+  serialization::TypeIdx GetOrCreateTypeIdx(QualType T);
+
+  /// \brief Determine the type index of an already-emitted type.
+  serialization::TypeIdx getTypeIdx(QualType T);
+
   /// \brief Emits a reference to a declarator info.
   void AddTypeSourceInfo(TypeSourceInfo *TInfo, RecordData &Record);
 
index b421b857b414a0561e8d155419ac59b886927fc9..16c6f4b10105821a925ff0be5f88592482111edf 100644 (file)
@@ -2588,14 +2588,7 @@ void ASTWriter::AddTypeRef(QualType T, RecordData &Record) {
   T.removeFastQualifiers();
 
   if (T.hasLocalNonFastQualifiers()) {
-    TypeIdx &Idx = TypeIdxs[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.
-      Idx = TypeIdx(NextTypeID++);
-      DeclTypesToEmit.push(T);
-    }
+    TypeIdx Idx = GetOrCreateTypeIdx(T);
 
     // Encode the type qualifiers in the type reference.
     Record.push_back(Idx.asTypeID(FastQuals));
@@ -2644,6 +2637,17 @@ void ASTWriter::AddTypeRef(QualType T, RecordData &Record) {
     return;
   }
 
+  TypeIdx Idx = GetOrCreateTypeIdx(T);
+
+  // Encode the type qualifiers in the type reference.
+  Record.push_back(Idx.asTypeID(FastQuals));
+}
+
+TypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) {
+  if (T.isNull())
+    return TypeIdx();
+  assert(!T.getLocalFastQualifiers());
+
   TypeIdx &Idx = TypeIdxs[T];
   if (Idx.getIndex() == 0) {
     // We haven't seen this type before. Assign it a new ID and put it
@@ -2651,9 +2655,16 @@ void ASTWriter::AddTypeRef(QualType T, RecordData &Record) {
     Idx = TypeIdx(NextTypeID++);
     DeclTypesToEmit.push(T);
   }
+  return Idx;
+}
 
-  // Encode the type qualifiers in the type reference.
-  Record.push_back(Idx.asTypeID(FastQuals));
+TypeIdx ASTWriter::getTypeIdx(QualType T) {
+  if (T.isNull())
+    return TypeIdx();
+  assert(!T.getLocalFastQualifiers());
+
+  assert(TypeIdxs.find(T) != TypeIdxs.end() && "Type not emitted!");
+  return TypeIdxs[T];
 }
 
 void ASTWriter::AddDeclRef(const Decl *D, RecordData &Record) {