Add typ::Ptr<T>
A simple raw pointer wrapper that will allow us to migrate typ aliases to ast::Types without immediately having to fix up all the `auto` declarations to `auto*`. Bug: tint:724 Change-Id: Icff7e009b768d9e54c8c73059c700af788962e77 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49346 Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
95c2e95100
commit
e41808b6b9
|
@ -73,6 +73,40 @@ class Void;
|
||||||
|
|
||||||
namespace typ { // type-pair
|
namespace typ { // type-pair
|
||||||
|
|
||||||
|
/// A simple wrapper around a raw pointer. Used to prevent a whole bunch of
|
||||||
|
/// warnings about `auto` needing to be declared as `auto*` while we're
|
||||||
|
/// migrating code.
|
||||||
|
template <typename T>
|
||||||
|
struct Ptr {
|
||||||
|
/// The raw pointer
|
||||||
|
T* const ptr;
|
||||||
|
|
||||||
|
/// Constructor
|
||||||
|
Ptr() = default;
|
||||||
|
|
||||||
|
/// Copy constructor
|
||||||
|
/// @param other the Ptr to copy
|
||||||
|
template <typename OTHER>
|
||||||
|
Ptr(const Ptr<OTHER>& other) : ptr(static_cast<T*>(other.ptr)) {}
|
||||||
|
|
||||||
|
/// Constructor
|
||||||
|
/// @param p the pointer to wrap in a Ptr
|
||||||
|
template <typename U>
|
||||||
|
Ptr(U* p) : ptr(p) {} // NOLINT: explicit
|
||||||
|
|
||||||
|
/// @returns the pointer
|
||||||
|
operator T*() { return ptr; }
|
||||||
|
|
||||||
|
/// @returns the pointer
|
||||||
|
operator const T*() const { return ptr; }
|
||||||
|
|
||||||
|
/// @returns the pointer
|
||||||
|
T* operator->() { return ptr; }
|
||||||
|
|
||||||
|
/// @returns the pointer
|
||||||
|
const T* operator->() const { return ptr; }
|
||||||
|
};
|
||||||
|
|
||||||
/// TypePair is a pair of ast::Type and sem::Type pointers used to simplify
|
/// TypePair is a pair of ast::Type and sem::Type pointers used to simplify
|
||||||
/// migration to the new ast::Type nodes.
|
/// migration to the new ast::Type nodes.
|
||||||
///
|
///
|
||||||
|
@ -110,6 +144,10 @@ struct TypePair {
|
||||||
/// @param s the sem::Type pointer
|
/// @param s the sem::Type pointer
|
||||||
TypePair(const AST* a, const SEM* s) : ast(a), sem(s) {}
|
TypePair(const AST* a, const SEM* s) : ast(a), sem(s) {}
|
||||||
/// Constructor
|
/// Constructor
|
||||||
|
/// @param ptr the Ptr<T>
|
||||||
|
template <typename T>
|
||||||
|
TypePair(Ptr<T> ptr) : TypePair(ptr.ptr) {} // NOLINT: explicit
|
||||||
|
/// Constructor
|
||||||
TypePair(std::nullptr_t) {} // NOLINT: explicit
|
TypePair(std::nullptr_t) {} // NOLINT: explicit
|
||||||
|
|
||||||
/// @returns the ast::Type pointer
|
/// @returns the ast::Type pointer
|
||||||
|
|
Loading…
Reference in New Issue