[cfe-commits] r111630 - in /cfe/trunk: 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
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Aug 20 09:03:59 PDT 2010
Author: akirtzidis
Date: Fri Aug 20 11:03:59 2010
New Revision: 111630
URL: http://llvm.org/viewvc/llvm-project?rev=111630&view=rev
Log:
serialization::TypeID is used with or without qualifiers, both as index and as index + qualifiers.
Disambiguate and provide some type safety by using a new class TypeIdx for the "TypeID as index" semantics.
Modified:
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/include/clang/Serialization/ASTDeserializationListener.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=111630&r1=111629&r2=111630&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Fri Aug 20 11:03:59 2010
@@ -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 @@
/// 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;
Modified: cfe/trunk/include/clang/Serialization/ASTDeserializationListener.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTDeserializationListener.h?rev=111630&r1=111629&r2=111630&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTDeserializationListener.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTDeserializationListener.h Fri Aug 20 11:03:59 2010
@@ -37,7 +37,7 @@
/// \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.
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=111630&r1=111629&r2=111630&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Fri Aug 20 11:03:59 2010
@@ -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"
Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=111630&r1=111629&r2=111630&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Fri Aug 20 11:03:59 2010
@@ -146,7 +146,7 @@
/// 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 @@
// 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);
};
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=111630&r1=111629&r2=111630&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Aug 20 11:03:59 2010
@@ -2826,7 +2826,7 @@
TypesLoaded[Index] = ReadTypeRecord(Index);
TypesLoaded[Index]->setFromAST();
if (DeserializationListener)
- DeserializationListener->TypeRead(ID >> Qualifiers::FastWidth,
+ DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID),
TypesLoaded[Index]);
}
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=111630&r1=111629&r2=111630&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Aug 20 11:03:59 2010
@@ -1397,12 +1397,12 @@
/// \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 @@
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 @@
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 @@
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) {
More information about the cfe-commits
mailing list