Add typepair.h
Introduces typ::Type which wraps a templated pair of AST and SEM type pointers. This is a temporary helper to ease migration of the thousands of tests that use the ProgramBuilder over from sem::Type to the new ast::Types. Bug: tint:724 Change-Id: I4e2643a819cde97947d789fce7a74c251f837a58 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48601 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
c0810e7e6e
commit
440636c15c
|
@ -496,6 +496,7 @@ libtint_source_set("libtint_core_all_src") {
|
||||||
"symbol_table.cc",
|
"symbol_table.cc",
|
||||||
"symbol_table.h",
|
"symbol_table.h",
|
||||||
"traits.h",
|
"traits.h",
|
||||||
|
"typepair.h",
|
||||||
"transform/binding_point.h",
|
"transform/binding_point.h",
|
||||||
"transform/binding_remapper.cc",
|
"transform/binding_remapper.cc",
|
||||||
"transform/binding_remapper.h",
|
"transform/binding_remapper.h",
|
||||||
|
|
|
@ -249,6 +249,7 @@ set(TINT_LIB_SRCS
|
||||||
symbol.cc
|
symbol.cc
|
||||||
symbol.h
|
symbol.h
|
||||||
traits.h
|
traits.h
|
||||||
|
typepair.h
|
||||||
transform/binding_point.h
|
transform/binding_point.h
|
||||||
transform/binding_remapper.cc
|
transform/binding_remapper.cc
|
||||||
transform/binding_remapper.h
|
transform/binding_remapper.h
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
// Copyright 2021 The Tint Authors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// This file contains temporary code to help implement the new `ast::Type`s.
|
||||||
|
// Once complete, this file should be completely removed.
|
||||||
|
// Bug: crbug.com/tint/724
|
||||||
|
|
||||||
|
#ifndef SRC_TYPEPAIR_H_
|
||||||
|
#define SRC_TYPEPAIR_H_
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
|
||||||
|
namespace ast {
|
||||||
|
class Bool;
|
||||||
|
class F32;
|
||||||
|
class I32;
|
||||||
|
class U32;
|
||||||
|
class Void;
|
||||||
|
} // namespace ast
|
||||||
|
|
||||||
|
namespace sem {
|
||||||
|
class Bool;
|
||||||
|
class F32;
|
||||||
|
class I32;
|
||||||
|
class U32;
|
||||||
|
class Void;
|
||||||
|
} // namespace sem
|
||||||
|
|
||||||
|
namespace typ { // type-pair
|
||||||
|
|
||||||
|
/// Type is a pair of ast::Type and sem::Type pointers used to simplify
|
||||||
|
/// migration to the new ast::Type nodes.
|
||||||
|
///
|
||||||
|
/// Type attempts to behave as either an ast::Type or sem::Type:
|
||||||
|
/// * Type has constructors that take either an ast::Type and sem::Type pointer
|
||||||
|
/// pair, and single-parameter implicit constructors for either a single
|
||||||
|
/// ast::Type or sem::Type pointer.
|
||||||
|
/// * Type also has user-defined conversion functions for returning either an
|
||||||
|
/// ast::Type or sem::Type pointer.
|
||||||
|
/// * operator->() returns the sem::Type pointer. Later in the migration this
|
||||||
|
/// will switch to returning the ast::Type pointer.
|
||||||
|
template <typename AST, typename SEM>
|
||||||
|
struct Type {
|
||||||
|
/// The ast::Type pointer
|
||||||
|
AST const* const ast = nullptr;
|
||||||
|
/// The sem::Type pointer
|
||||||
|
SEM const* const sem = nullptr;
|
||||||
|
|
||||||
|
/// Constructor
|
||||||
|
Type() = default;
|
||||||
|
/// Constructor
|
||||||
|
/// @param a the ast::Type pointer
|
||||||
|
Type(const AST* a) : ast(a) {} // NOLINT: explicit
|
||||||
|
/// Constructor
|
||||||
|
/// @param s the sem::Type pointer
|
||||||
|
Type(const SEM* s) : sem(s) {} // NOLINT: explicit
|
||||||
|
/// Constructor
|
||||||
|
/// @param a the ast::Type pointer
|
||||||
|
/// @param s the sem::Type pointer
|
||||||
|
Type(const AST* a, const SEM* s) : ast(a), sem(s) {}
|
||||||
|
|
||||||
|
/// @returns the ast::Type pointer
|
||||||
|
operator AST*() const { return const_cast<AST*>(ast); }
|
||||||
|
/// @returns the sem::Type pointer
|
||||||
|
operator SEM*() const { return const_cast<SEM*>(sem); }
|
||||||
|
/// @returns the sem::Type pointer
|
||||||
|
SEM* operator->() const { return const_cast<SEM*>(sem); }
|
||||||
|
};
|
||||||
|
|
||||||
|
using Bool = Type<ast::Bool, sem::Bool>;
|
||||||
|
using F32 = Type<ast::F32, sem::F32>;
|
||||||
|
using I32 = Type<ast::I32, sem::I32>;
|
||||||
|
using U32 = Type<ast::U32, sem::U32>;
|
||||||
|
using Void = Type<ast::Void, sem::Void>;
|
||||||
|
|
||||||
|
} // namespace typ
|
||||||
|
|
||||||
|
} // namespace tint
|
||||||
|
|
||||||
|
#endif // SRC_TYPEPAIR_H_
|
Loading…
Reference in New Issue