aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Serialization/ASTBitCodes.h17
-rw-r--r--include/clang/Serialization/ASTDeserializationListener.h2
-rw-r--r--include/clang/Serialization/ASTReader.h1
-rw-r--r--include/clang/Serialization/ASTWriter.h4
-rw-r--r--lib/Serialization/ASTReader.cpp2
-rw-r--r--lib/Serialization/ASTWriter.cpp30
6 files changed, 36 insertions, 20 deletions
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h
index 55c11e29f0..3156a36040 100644
--- a/include/clang/Serialization/ASTBitCodes.h
+++ b/include/clang/Serialization/ASTBitCodes.h
@@ -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;
diff --git a/include/clang/Serialization/ASTDeserializationListener.h b/include/clang/Serialization/ASTDeserializationListener.h
index 543d29e6e2..f8114de5f1 100644
--- a/include/clang/Serialization/ASTDeserializationListener.h
+++ b/include/clang/Serialization/ASTDeserializationListener.h
@@ -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.
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h
index d4a0ea9f48..cbc3775cef 100644
--- a/include/clang/Serialization/ASTReader.h
+++ b/include/clang/Serialization/ASTReader.h
@@ -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"
diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h
index 68a6eb0cb8..0776c69714 100644
--- a/include/clang/Serialization/ASTWriter.h
+++ b/include/clang/Serialization/ASTWriter.h
@@ -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);
};
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 238ce3f5ed..040277074c 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -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]);
}
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index b305fffbc8..30a5d16e9e 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -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) {