[cfe-commits] r111632 - in /cfe/trunk: include/clang/Serialization/ASTWriter.h lib/Serialization/ASTWriter.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Aug 20 09:04:09 PDT 2010


Author: akirtzidis
Date: Fri Aug 20 11:04:09 2010
New Revision: 111632

URL: http://llvm.org/viewvc/llvm-project?rev=111632&view=rev
Log:
A bit of refactoring; Introduce ASTWriter::GetOrCreateTypeIdx and move the emission of types there.
No functionality change.

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

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=111632&r1=111631&r2=111632&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Fri Aug 20 11:04:09 2010
@@ -364,6 +364,12 @@
   /// \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);
 

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=111632&r1=111631&r2=111632&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Aug 20 11:04:09 2010
@@ -2588,14 +2588,7 @@
   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 @@
     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 @@
     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) {





More information about the cfe-commits mailing list