From e41808b6b9712064237b0b81098725a6d4c66a9d Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 28 Apr 2021 13:32:13 +0000 Subject: [PATCH] Add typ::Ptr 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 Reviewed-by: Antonio Maiorano --- src/typepair.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/typepair.h b/src/typepair.h index c3fa0f5e42..9bddaf716f 100644 --- a/src/typepair.h +++ b/src/typepair.h @@ -73,6 +73,40 @@ class Void; 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 +struct Ptr { + /// The raw pointer + T* const ptr; + + /// Constructor + Ptr() = default; + + /// Copy constructor + /// @param other the Ptr to copy + template + Ptr(const Ptr& other) : ptr(static_cast(other.ptr)) {} + + /// Constructor + /// @param p the pointer to wrap in a Ptr + template + 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 /// migration to the new ast::Type nodes. /// @@ -110,6 +144,10 @@ struct TypePair { /// @param s the sem::Type pointer TypePair(const AST* a, const SEM* s) : ast(a), sem(s) {} /// Constructor + /// @param ptr the Ptr + template + TypePair(Ptr ptr) : TypePair(ptr.ptr) {} // NOLINT: explicit + /// Constructor TypePair(std::nullptr_t) {} // NOLINT: explicit /// @returns the ast::Type pointer