// Copyright 2020 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. #include "src/type/type.h" #include "src/type/access_control_type.h" #include "src/type/alias_type.h" #include "src/type/bool_type.h" #include "src/type/f32_type.h" #include "src/type/i32_type.h" #include "src/type/matrix_type.h" #include "src/type/pointer_type.h" #include "src/type/sampler_type.h" #include "src/type/texture_type.h" #include "src/type/u32_type.h" #include "src/type/vector_type.h" TINT_INSTANTIATE_TYPEINFO(tint::type::Type); namespace tint { namespace type { Type::Type() = default; Type::Type(Type&&) = default; Type::~Type() = default; Type* Type::UnwrapPtrIfNeeded() { if (auto* ptr = As()) { return ptr->type(); } return this; } Type* Type::UnwrapAliasIfNeeded() { Type* unwrapped = this; while (auto* ptr = unwrapped->As()) { unwrapped = ptr->type(); } return unwrapped; } Type* Type::UnwrapIfNeeded() { auto* where = this; while (true) { if (auto* alias = where->As()) { where = alias->type(); } else if (auto* access = where->As()) { where = access->type(); } else { break; } } return where; } Type* Type::UnwrapAll() { return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded(); } bool Type::is_scalar() const { return IsAnyOf(); } bool Type::is_float_scalar() const { return Is(); } bool Type::is_float_matrix() const { return Is( [](const Matrix* m) { return m->type()->is_float_scalar(); }); } bool Type::is_float_vector() const { return Is( [](const Vector* v) { return v->type()->is_float_scalar(); }); } bool Type::is_float_scalar_or_vector() const { return is_float_scalar() || is_float_vector(); } bool Type::is_float_scalar_or_vector_or_matrix() const { return is_float_scalar() || is_float_vector() || is_float_matrix(); } bool Type::is_integer_scalar() const { return IsAnyOf(); } bool Type::is_unsigned_integer_vector() const { return Is([](const Vector* v) { return v->type()->Is(); }); } bool Type::is_signed_integer_vector() const { return Is([](const Vector* v) { return v->type()->Is(); }); } bool Type::is_unsigned_scalar_or_vector() const { return Is() || is_unsigned_integer_vector(); } bool Type::is_signed_scalar_or_vector() const { return Is() || is_signed_integer_vector(); } bool Type::is_integer_scalar_or_vector() const { return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector(); } bool Type::is_bool_vector() const { return Is([](const Vector* v) { return v->type()->Is(); }); } bool Type::is_bool_scalar_or_vector() const { return Is() || is_bool_vector(); } bool Type::is_handle() const { return IsAnyOf(); } } // namespace type } // namespace tint