[cfe-commits] r60226 - in /cfe/trunk: include/clang/AST/Type.h lib/AST/TypeSerialization.cpp
Chris Lattner
sabre at nondot.org
Fri Nov 28 15:37:31 PST 2008
Author: lattner
Date: Fri Nov 28 17:37:31 2008
New Revision: 60226
URL: http://llvm.org/viewvc/llvm-project?rev=60226&view=rev
Log:
Switch QualType to use llvm::PointerIntPair internally to do the pointer
bitmangling.
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/TypeSerialization.cpp
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=60226&r1=60225&r2=60226&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Nov 28 17:37:31 2008
@@ -16,8 +16,9 @@
#include "clang/Basic/Diagnostic.h"
#include "llvm/Support/Casting.h"
-#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/PointerIntPair.h"
#include "llvm/Bitcode/SerializationFwd.h"
using llvm::isa;
using llvm::cast;
@@ -74,7 +75,7 @@
/// packing/unpacking, we make QualType be a simple wrapper class that acts like
/// a smart pointer.
class QualType {
- uintptr_t ThePtr;
+ llvm::PointerIntPair<Type*, 3> Value;
public:
enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
Const = 0x1,
@@ -83,39 +84,21 @@
CVRFlags = Const|Restrict|Volatile
};
- QualType() : ThePtr(0) {}
+ QualType() {}
- QualType(Type *Ptr, unsigned Quals) {
- assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!");
- ThePtr = reinterpret_cast<uintptr_t>(Ptr);
- assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?");
- ThePtr |= Quals;
- }
-
- QualType(const Type *Ptr, unsigned Quals) {
- assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!");
- ThePtr = reinterpret_cast<uintptr_t>(Ptr);
- assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?");
- ThePtr |= Quals;
- }
+ QualType(const Type *Ptr, unsigned Quals)
+ : Value(const_cast<Type*>(Ptr), Quals) {}
+ unsigned getCVRQualifiers() const { return Value.getInt(); }
+ Type *getTypePtr() const { return Value.getPointer(); }
+
+ void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
static QualType getFromOpaquePtr(void *Ptr) {
QualType T;
- T.ThePtr = reinterpret_cast<uintptr_t>(Ptr);
+ T.Value.setFromOpaqueValue(Ptr);
return T;
}
- unsigned getCVRQualifiers() const {
- return ThePtr & CVRFlags;
- }
- Type *getTypePtr() const {
- return reinterpret_cast<Type*>(ThePtr & ~CVRFlags);
- }
-
- void *getAsOpaquePtr() const {
- return reinterpret_cast<void*>(ThePtr);
- }
-
Type &operator*() const {
return *getTypePtr();
}
@@ -126,30 +109,30 @@
/// isNull - Return true if this QualType doesn't point to a type yet.
bool isNull() const {
- return ThePtr == 0;
+ return getTypePtr() == 0;
}
bool isConstQualified() const {
- return (ThePtr & Const) ? true : false;
+ return (getCVRQualifiers() & Const) ? true : false;
}
bool isVolatileQualified() const {
- return (ThePtr & Volatile) ? true : false;
+ return (getCVRQualifiers() & Volatile) ? true : false;
}
bool isRestrictQualified() const {
- return (ThePtr & Restrict) ? true : false;
+ return (getCVRQualifiers() & Restrict) ? true : false;
}
bool isConstant(ASTContext& Ctx) const;
/// addConst/addVolatile/addRestrict - add the specified type qual to this
/// QualType.
- void addConst() { ThePtr |= Const; }
- void addVolatile() { ThePtr |= Volatile; }
- void addRestrict() { ThePtr |= Restrict; }
-
- void removeConst() { ThePtr &= ~Const; }
- void removeVolatile() { ThePtr &= ~Volatile; }
- void removeRestrict() { ThePtr &= ~Restrict; }
+ void addConst() { Value.setInt(Value.getInt() | Const); }
+ void addVolatile() { Value.setInt(Value.getInt() | Volatile); }
+ void addRestrict() { Value.setInt(Value.getInt() | Restrict); }
+
+ void removeConst() { Value.setInt(Value.getInt() & ~Const); }
+ void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); }
+ void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); }
QualType getQualifiedType(unsigned TQs) const {
return QualType(getTypePtr(), TQs);
@@ -171,10 +154,10 @@
/// operator==/!= - Indicate whether the specified types and qualifiers are
/// identical.
bool operator==(const QualType &RHS) const {
- return ThePtr == RHS.ThePtr;
+ return Value == RHS.Value;
}
bool operator!=(const QualType &RHS) const {
- return ThePtr != RHS.ThePtr;
+ return Value != RHS.Value;
}
std::string getAsString() const {
std::string S;
Modified: cfe/trunk/lib/AST/TypeSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypeSerialization.cpp?rev=60226&r1=60225&r2=60226&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypeSerialization.cpp (original)
+++ cfe/trunk/lib/AST/TypeSerialization.cpp Fri Nov 28 17:37:31 2008
@@ -30,15 +30,17 @@
}
QualType QualType::ReadVal(Deserializer& D) {
- QualType Q;
- D.ReadUIntPtr(Q.ThePtr,false);
- Q.ThePtr |= D.ReadInt();
- return Q;
+ uintptr_t Val;
+ D.ReadUIntPtr(Val, false);
+ return QualType(reinterpret_cast<Type*>(Val), D.ReadInt());
}
void QualType::ReadBackpatch(Deserializer& D) {
- D.ReadUIntPtr(ThePtr,true);
- ThePtr |= D.ReadInt();
+ uintptr_t Val;
+ D.ReadUIntPtr(Val, false);
+
+ Value.setPointer(reinterpret_cast<Type*>(Val));
+ Value.setInt(D.ReadInt());
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list