[cfe-commits] r67998 - in /cfe/trunk/include/clang: AST/DeclGroup.h Parse/Ownership.h
Chris Lattner
sabre at nondot.org
Sun Mar 29 07:24:09 PDT 2009
Author: lattner
Date: Sun Mar 29 09:23:52 2009
New Revision: 67998
URL: http://llvm.org/viewvc/llvm-project?rev=67998&view=rev
Log:
Implement PointerLikeTypeTraits for DeclGroupRef.
Make OpaquePtr work with things that are pointer-like but not
necessarily pointers.
Modified:
cfe/trunk/include/clang/AST/DeclGroup.h
cfe/trunk/include/clang/Parse/Ownership.h
Modified: cfe/trunk/include/clang/AST/DeclGroup.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclGroup.h?rev=67998&r1=67997&r2=67998&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclGroup.h (original)
+++ cfe/trunk/include/clang/AST/DeclGroup.h Sun Mar 29 09:23:52 2009
@@ -134,4 +134,21 @@
};
} // end clang namespace
+
+namespace llvm {
+ // DeclGroupRef is "like a pointer", implement PointerLikeTypeTraits.
+ template <typename T>
+ class PointerLikeTypeTraits;
+ template <>
+ class PointerLikeTypeTraits<clang::DeclGroupRef> {
+ public:
+ static inline void *getAsVoidPointer(clang::DeclGroupRef P) {
+ return P.getAsOpaquePtr();
+ }
+ static inline clang::DeclGroupRef getFromVoidPointer(void *P) {
+ return clang::DeclGroupRef::getFromOpaquePtr(P);
+ }
+ enum { NumLowBitsAvailable = 0 };
+ };
+}
#endif
Modified: cfe/trunk/include/clang/Parse/Ownership.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Ownership.h?rev=67998&r1=67997&r2=67998&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Ownership.h (original)
+++ cfe/trunk/include/clang/Parse/Ownership.h Sun Mar 29 09:23:52 2009
@@ -14,15 +14,12 @@
#ifndef LLVM_CLANG_PARSE_OWNERSHIP_H
#define LLVM_CLANG_PARSE_OWNERSHIP_H
+#include "llvm/Support/PointerLikeTypeTraits.h"
+
//===----------------------------------------------------------------------===//
// OpaquePtr
//===----------------------------------------------------------------------===//
-namespace llvm {
- template <typename T>
- class PointerLikeTypeTraits;
-}
-
namespace clang {
/// OpaquePtr - This is a very simple POD type that wraps a pointer that the
/// Parser doesn't know about but that Sema or another client does. The UID
@@ -35,12 +32,26 @@
OpaquePtr() : Ptr(0) {}
template <typename T>
- T* getAs() const { return static_cast<T*>(Ptr); }
+ T* getAs() const {
+ return llvm::PointerLikeTypeTraits<T*>::getFromVoidPointer(Ptr);
+ }
+
+ template <typename T>
+ T getAsVal() const {
+ return llvm::PointerLikeTypeTraits<T>::getFromVoidPointer(Ptr);
+ }
void *get() const { return Ptr; }
- static OpaquePtr make(void *P) { OpaquePtr R; R.Ptr = P; return R; }
- void set(void *P) { Ptr = P; }
+ template<typename T>
+ static OpaquePtr make(T P) {
+ OpaquePtr R; R.set(P); return R;
+ }
+
+ template<typename T>
+ void set(T P) {
+ Ptr = llvm::PointerLikeTypeTraits<T>::getAsVoidPointer(P);
+ }
operator bool() const { return Ptr != 0; }
};
More information about the cfe-commits
mailing list