// Copyright 2021 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef SRC_TINT_LANG_WGSL_RESOLVER_RESOLVER_HELPER_TEST_H_ #define SRC_TINT_LANG_WGSL_RESOLVER_RESOLVER_HELPER_TEST_H_ #include <functional> #include <memory> #include <ostream> #include <string> #include <tuple> #include <utility> #include <variant> #include "gtest/gtest.h" #include "src/tint/lang/core/type/abstract_float.h" #include "src/tint/lang/core/type/abstract_int.h" #include "src/tint/lang/wgsl/program/program_builder.h" #include "src/tint/lang/wgsl/resolver/resolver.h" #include "src/tint/lang/wgsl/sem/array.h" #include "src/tint/lang/wgsl/sem/statement.h" #include "src/tint/lang/wgsl/sem/value_expression.h" #include "src/tint/lang/wgsl/sem/variable.h" #include "src/tint/utils/containers/vector.h" #include "src/tint/utils/traits/traits.h" namespace tint::resolver { /// Helper class for testing class TestHelper : public ProgramBuilder { … }; class ResolverTest : public TestHelper, public testing::Test { … }; ResolverDeathTest; template <typename T> class ResolverTestWithParam : public TestHelper, public testing::TestWithParam<T> { … }; namespace builder { template <typename TO, int ID = 0> struct alias { … }; alias1; alias2; alias3; /// Scalar represents a scalar value struct Scalar { … }; /// @param out the stream to write to /// @param s the Scalar /// @returns @p out so calls can be chained template <typename STREAM, typename = traits::EnableIfIsOStream<STREAM>> STREAM& operator<<(STREAM& out, const Scalar& s) { … } /// @return current variant value in @p s cast to type `T` template <typename T> T As(const Scalar& s) { … } ast_type_func_ptr; ast_expr_func_ptr; ast_expr_from_double_func_ptr; sem_type_func_ptr; type_name_func_ptr; struct UnspecializedElementType { … }; /// Base template for DataType, specialized below. template <typename T> struct DataType { … }; /// Helper that represents no-type. Returns nullptr for all static methods. template <> struct DataType<void> { … }; /// Helper for building bool types and expressions template <> struct DataType<bool> { … }; /// Helper for building i32 types and expressions template <> struct DataType<core::i32> { … }; /// Helper for building u32 types and expressions template <> struct DataType<core::u32> { … }; /// Helper for building f32 types and expressions template <> struct DataType<core::f32> { … }; /// Helper for building f16 types and expressions template <> struct DataType<core::f16> { … }; /// Helper for building abstract float types and expressions template <> struct DataType<core::AFloat> { … }; /// Helper for building abstract integer types and expressions template <> struct DataType<core::AInt> { … }; /// Helper for building vector types and expressions DataType<core::fluent_types::vec<N, T>>; /// Helper for building matrix types and expressions DataType<core::fluent_types::mat<N, M, T>>; /// Helper for building alias types and expressions DataType<alias<T, ID>>; /// Helper for building pointer types and expressions DataType<core::fluent_types::ptr<core::AddressSpace::kPrivate, T, core::Access::kUndefined>>; /// Helper for building array types and expressions DataType<core::fluent_types::array<T, N>>; /// Helper for building atomic types and expressions DataType<core::fluent_types::atomic<T>>; /// Struct of all creation pointer types struct CreatePtrs { … }; /// @param o the std::ostream to write to /// @param ptrs the CreatePtrs /// @return the std::ostream so calls can be chained inline std::ostream& operator<<(std::ostream& o, const CreatePtrs& ptrs) { … } /// Returns a CreatePtrs struct instance with all creation pointer types for /// type `T` template <typename T> constexpr CreatePtrs CreatePtrsFor() { … } /// True if DataType<T> is specialized for T, false otherwise. IsDataTypeSpecializedFor; /// Value is used to create Values with a Scalar vector initializer. struct Value { … }; /// Prints Value to ostream inline std::ostream& operator<<(std::ostream& o, const Value& value) { … } /// True if T is Value, false otherwise IsValue; /// Creates a Value of DataType<T> from a scalar `v` template <typename T> Value Val(T v) { … } /// Creates a Value of DataType<vec<N, T>> from N scalar `args` template <typename... Ts> Value Vec(Ts... args) { … } /// Creates a Value of DataType<array<N, T>> from N scalar `args` template <typename... Ts> Value Array(Ts... args) { … } /// Creates a Value of DataType<mat<C,R,T> from C*R scalar `args` template <size_t C, size_t R, typename T> Value Mat(const T (&m_in)[C][R]) { … } /// Creates a Value of DataType<mat<2,R,T> from column vectors `c0` and `c1` template <typename T, size_t R> Value Mat(const T (&c0)[R], const T (&c1)[R]) { … } /// Creates a Value of DataType<mat<3,R,T> from column vectors `c0`, `c1`, and `c2` template <typename T, size_t R> Value Mat(const T (&c0)[R], const T (&c1)[R], const T (&c2)[R]) { … } /// Creates a Value of DataType<mat<4,R,T> from column vectors `c0`, `c1`, `c2`, and `c3` template <typename T, size_t R> Value Mat(const T (&c0)[R], const T (&c1)[R], const T (&c2)[R], const T (&c3)[R]) { … } } // namespace builder } // namespace tint::resolver #endif // SRC_TINT_LANG_WGSL_RESOLVER_RESOLVER_HELPER_TEST_H_