[cfe-commits] r67982 - in /cfe/trunk/include/clang/Parse: Action.h Ownership.h
Chris Lattner
sabre at nondot.org
Sat Mar 28 22:04:26 PDT 2009
Author: lattner
Date: Sun Mar 29 00:04:26 2009
New Revision: 67982
URL: http://llvm.org/viewvc/llvm-project?rev=67982&view=rev
Log:
genericize the ActionResult optimization for holding the "ininvalid" bit
in the low bit position a little bit (haha).
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/Ownership.h
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=67982&r1=67981&r2=67982&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Sun Mar 29 00:04:26 2009
@@ -47,6 +47,7 @@
template<> struct IsResultPtrLowBitFree<1> { static const bool value = true;};
template<> struct IsResultPtrLowBitFree<3> { static const bool value = true;};
template<> struct IsResultPtrLowBitFree<4> { static const bool value = true;};
+//template<> struct IsResultPtrLowBitFree<5> { static const bool value = true;};
/// Action - As the parser reads the input file and recognizes the productions
/// of the grammar, it invokes methods on this class to turn the parsed input
Modified: cfe/trunk/include/clang/Parse/Ownership.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Ownership.h?rev=67982&r1=67981&r2=67982&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Ownership.h (original)
+++ cfe/trunk/include/clang/Parse/Ownership.h Sun Mar 29 00:04:26 2009
@@ -211,35 +211,36 @@
}
};
- ///// FIXME: We just lost the ability to bitmangle into DeclPtrTy's and
- ///// friends!
-
// This ActionResult partial specialization places the "invalid"
// flag into the low bit of the pointer.
- template<unsigned UID>
- class ActionResult<UID, void*, true> {
+ template<unsigned UID, typename PtrTy>
+ class ActionResult<UID, PtrTy, true> {
// A pointer whose low bit is 1 if this result is invalid, 0
// otherwise.
uintptr_t PtrWithInvalid;
-
+ typedef llvm::PointerLikeTypeTraits<PtrTy> PtrTraits;
public:
ActionResult(bool Invalid = false)
: PtrWithInvalid(static_cast<uintptr_t>(Invalid)) { }
template<typename ActualExprTy>
- ActionResult(ActualExprTy *val)
- : PtrWithInvalid(reinterpret_cast<uintptr_t>(val)) {
+ ActionResult(ActualExprTy *val) {
+ PtrTy V(val);
+ void *VP = PtrTraits::getAsVoidPointer(V);
+ PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
}
ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) { }
- void *get() const {
- return reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
+ PtrTy get() const {
+ void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
+ return PtrTraits::getFromVoidPointer(VP);
}
- void set(void *V) {
- PtrWithInvalid = reinterpret_cast<uintptr_t>(V);
+ void set(PtrTy V) {
+ void *VP = PtrTraits::getAsVoidPointer(V);
+ PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
}
@@ -394,7 +395,7 @@
}
/// Move assignment from another owning result
- ASTOwningResult & operator =(moving::ASTResultMover<Destroyer> mover) {
+ ASTOwningResult &operator=(moving::ASTResultMover<Destroyer> mover) {
destroy();
ActionInv = mover->ActionInv;
Ptr = mover->Ptr;
@@ -403,7 +404,7 @@
}
/// Assignment from a raw pointer. Takes ownership - beware!
- ASTOwningResult & operator =(void *raw) {
+ ASTOwningResult &operator=(void *raw) {
destroy();
Ptr = raw;
ActionInv.setInt(false);
@@ -411,7 +412,7 @@
}
/// Assignment from an ActionResult. Takes ownership - beware!
- ASTOwningResult & operator =(const DumbResult &res) {
+ ASTOwningResult &operator=(const DumbResult &res) {
destroy();
Ptr = res.get();
ActionInv.setInt(res.isInvalid());
@@ -419,7 +420,7 @@
}
/// Access to the raw pointer.
- void * get() const { return Ptr; }
+ void *get() const { return Ptr; }
bool isInvalid() const { return ActionInv.getInt(); }
@@ -428,7 +429,7 @@
bool isUsable() const { return !isInvalid() && get(); }
/// Take outside ownership of the raw pointer.
- void * take() {
+ void *take() {
if (isInvalid())
return 0;
void *tmp = Ptr;
@@ -443,7 +444,7 @@
}
/// Alias for interface familiarity with unique_ptr.
- void * release() { return take(); }
+ void *release() { return take(); }
/// Pass ownership to a classical ActionResult.
DumbResult result() {
More information about the cfe-commits
mailing list