mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 14:08:04 +00:00
Move tint::ast::type to tint::type
Despite `tint::ast::type::Type` being in the AST namespace, these classes are clearly not AST nodes: * They don't derive from ast::Node * They're deduplicated by the type manager * None of the types have an Source - they have no lexical declaration point * The fact we have `ast::Struct` and `ast::type::Struct` clearly demonstrates what is an AST node, and what is a type. * We have code scattered in the codebase (TypeDeterminer, writers, etc) that create new types after parsing - so clearly not part of the original syntax tree. Types in tint are closer to being semantic info, but due to the parse-time generation of types, and tight dependency of ast::Nodes to types, I'd be reluctant to class these as semantic info. Instead, put these into a separate root level `tint::type` namespace and `src/tint` directory. The fact that types exist in the ast::Module has already caused bugs (https://dawn-review.googlesource.com/c/tint/+/37261). This is a first step in separating out types from the ast::Module. Bug: tint:390 Change-Id: I8349bbbd1b19597b8e6d51d5cda0890de46ecaec Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38002 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
587f387fd9
commit
207b5e2de1
@@ -20,13 +20,13 @@
|
||||
#include "src/ast/scalar_constructor_expression.h"
|
||||
#include "src/ast/sint_literal.h"
|
||||
#include "src/ast/switch_statement.h"
|
||||
#include "src/ast/type/alias_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/u32_type.h"
|
||||
#include "src/ast/uint_literal.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/type/alias_type.h"
|
||||
#include "src/type/f32_type.h"
|
||||
#include "src/type/i32_type.h"
|
||||
#include "src/type/u32_type.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/validator/validator_impl.h"
|
||||
#include "src/validator/validator_test_helper.h"
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
#include "src/ast/scalar_constructor_expression.h"
|
||||
#include "src/ast/sint_literal.h"
|
||||
#include "src/ast/stage_decoration.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/void_type.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/type/f32_type.h"
|
||||
#include "src/type/i32_type.h"
|
||||
#include "src/type/void_type.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/validator/validator_impl.h"
|
||||
#include "src/validator/validator_test_helper.h"
|
||||
|
||||
@@ -27,16 +27,16 @@
|
||||
#include "src/ast/stage_decoration.h"
|
||||
#include "src/ast/struct.h"
|
||||
#include "src/ast/switch_statement.h"
|
||||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type/u32_type.h"
|
||||
#include "src/ast/type/vector_type.h"
|
||||
#include "src/ast/type/void_type.h"
|
||||
#include "src/ast/uint_literal.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/type/array_type.h"
|
||||
#include "src/type/i32_type.h"
|
||||
#include "src/type/matrix_type.h"
|
||||
#include "src/type/pointer_type.h"
|
||||
#include "src/type/struct_type.h"
|
||||
#include "src/type/u32_type.h"
|
||||
#include "src/type/vector_type.h"
|
||||
#include "src/type/void_type.h"
|
||||
|
||||
namespace tint {
|
||||
|
||||
@@ -83,11 +83,11 @@ bool ValidatorImpl::Validate() {
|
||||
}
|
||||
|
||||
bool ValidatorImpl::ValidateConstructedTypes(
|
||||
const std::vector<ast::type::Type*>& constructed_types) {
|
||||
const std::vector<type::Type*>& constructed_types) {
|
||||
for (auto* const ct : constructed_types) {
|
||||
if (auto* st = ct->As<ast::type::Struct>()) {
|
||||
if (auto* st = ct->As<type::Struct>()) {
|
||||
for (auto* member : st->impl()->members()) {
|
||||
if (auto* r = member->type()->UnwrapAll()->As<ast::type::Array>()) {
|
||||
if (auto* r = member->type()->UnwrapAll()->As<type::Array>()) {
|
||||
if (r->IsRuntimeArray()) {
|
||||
if (member != st->impl()->members().back()) {
|
||||
add_error(member->source(), "v-0015",
|
||||
@@ -167,7 +167,7 @@ bool ValidatorImpl::ValidateEntryPoint(const ast::FunctionList& funcs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!func->return_type()->Is<ast::type::Void>()) {
|
||||
if (!func->return_type()->Is<type::Void>()) {
|
||||
add_error(func->source(), "v-0024",
|
||||
"Entry point function must return void: '" +
|
||||
module_.SymbolToName(func->symbol()) + "'");
|
||||
@@ -209,7 +209,7 @@ bool ValidatorImpl::ValidateFunction(const ast::Function* func) {
|
||||
}
|
||||
variable_stack_.pop_scope();
|
||||
|
||||
if (!current_function_->return_type()->Is<ast::type::Void>()) {
|
||||
if (!current_function_->return_type()->Is<type::Void>()) {
|
||||
if (!func->get_last_statement() ||
|
||||
!func->get_last_statement()->Is<ast::ReturnStatement>()) {
|
||||
add_error(func->source(), "v-0002",
|
||||
@@ -221,7 +221,7 @@ bool ValidatorImpl::ValidateFunction(const ast::Function* func) {
|
||||
}
|
||||
|
||||
bool ValidatorImpl::ValidateParameter(const ast::Variable* param) {
|
||||
if (auto* r = param->type()->UnwrapAll()->As<ast::type::Array>()) {
|
||||
if (auto* r = param->type()->UnwrapAll()->As<type::Array>()) {
|
||||
if (r->IsRuntimeArray()) {
|
||||
add_error(
|
||||
param->source(), "v-0015",
|
||||
@@ -235,9 +235,9 @@ bool ValidatorImpl::ValidateParameter(const ast::Variable* param) {
|
||||
bool ValidatorImpl::ValidateReturnStatement(const ast::ReturnStatement* ret) {
|
||||
// TODO(sarahM0): update this when this issue resolves:
|
||||
// https://github.com/gpuweb/gpuweb/issues/996
|
||||
ast::type::Type* func_type = current_function_->return_type();
|
||||
type::Type* func_type = current_function_->return_type();
|
||||
|
||||
ast::type::Void void_type;
|
||||
type::Void void_type;
|
||||
auto* ret_type =
|
||||
ret->has_value() ? ret->value()->result_type()->UnwrapAll() : &void_type;
|
||||
|
||||
@@ -283,8 +283,7 @@ bool ValidatorImpl::ValidateDeclStatement(
|
||||
// storable.
|
||||
// - types match or the RHS can be dereferenced to equal the LHS type.
|
||||
variable_stack_.set(symbol, decl->variable());
|
||||
if (auto* arr =
|
||||
decl->variable()->type()->UnwrapAll()->As<ast::type::Array>()) {
|
||||
if (auto* arr = decl->variable()->type()->UnwrapAll()->As<type::Array>()) {
|
||||
if (arr->IsRuntimeArray()) {
|
||||
add_error(
|
||||
decl->source(), "v-0015",
|
||||
@@ -358,11 +357,11 @@ bool ValidatorImpl::ValidateSwitch(const ast::SwitchStatement* s) {
|
||||
}
|
||||
|
||||
auto v =
|
||||
static_cast<int32_t>(selector->type()->Is<ast::type::U32>()
|
||||
static_cast<int32_t>(selector->type()->Is<type::U32>()
|
||||
? selector->As<ast::UintLiteral>()->value()
|
||||
: selector->As<ast::SintLiteral>()->value());
|
||||
if (selector_set.count(v)) {
|
||||
auto v_str = selector->type()->Is<ast::type::U32>()
|
||||
auto v_str = selector->type()->Is<type::U32>()
|
||||
? selector->As<ast::UintLiteral>()->to_str()
|
||||
: selector->As<ast::SintLiteral>()->to_str();
|
||||
add_error(case_stmt->source(), "v-0027",
|
||||
@@ -485,7 +484,7 @@ bool ValidatorImpl::ValidateAssign(const ast::AssignmentStatement* assign) {
|
||||
return false;
|
||||
}
|
||||
auto* lhs_result_type = lhs->result_type()->UnwrapIfNeeded();
|
||||
if (auto* lhs_reference_type = As<ast::type::Pointer>(lhs_result_type)) {
|
||||
if (auto* lhs_reference_type = As<type::Pointer>(lhs_result_type)) {
|
||||
auto* lhs_store_type = lhs_reference_type->type()->UnwrapIfNeeded();
|
||||
if (lhs_store_type != rhs_result_type) {
|
||||
add_error(assign->source(), "v-000x",
|
||||
@@ -534,18 +533,18 @@ bool ValidatorImpl::ValidateIdentifier(const ast::IdentifierExpression* ident) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ValidatorImpl::IsStorable(ast::type::Type* type) {
|
||||
bool ValidatorImpl::IsStorable(type::Type* type) {
|
||||
if (type == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (type->is_scalar() || type->Is<ast::type::Vector>() ||
|
||||
type->Is<ast::type::Matrix>()) {
|
||||
if (type->is_scalar() || type->Is<type::Vector>() ||
|
||||
type->Is<type::Matrix>()) {
|
||||
return true;
|
||||
}
|
||||
if (ast::type::Array* array_type = type->As<ast::type::Array>()) {
|
||||
if (type::Array* array_type = type->As<type::Array>()) {
|
||||
return IsStorable(array_type->type());
|
||||
}
|
||||
if (ast::type::Struct* struct_type = type->As<ast::type::Struct>()) {
|
||||
if (type::Struct* struct_type = type->As<type::Struct>()) {
|
||||
for (const auto* member : struct_type->impl()->members()) {
|
||||
if (!IsStorable(member->type())) {
|
||||
return false;
|
||||
@@ -553,7 +552,7 @@ bool ValidatorImpl::IsStorable(ast::type::Type* type) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (ast::type::Alias* alias_type = type->As<ast::type::Alias>()) {
|
||||
if (type::Alias* alias_type = type->As<type::Alias>()) {
|
||||
return IsStorable(alias_type->type());
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -144,15 +144,16 @@ class ValidatorImpl {
|
||||
/// @param constructed_types the types to check
|
||||
/// @returns true if the valdiation was successful
|
||||
bool ValidateConstructedTypes(
|
||||
const std::vector<ast::type::Type*>& constructed_types);
|
||||
const std::vector<type::Type*>& constructed_types);
|
||||
|
||||
/// Returns true if the given type is storable. This uses and
|
||||
/// updates `storable_` and `not_storable_`.
|
||||
/// @param type the given type
|
||||
/// @returns true if the given type is storable.
|
||||
bool IsStorable(ast::type::Type* type);
|
||||
bool IsStorable(type::Type* type);
|
||||
|
||||
/// Testing method to inserting a given variable into the current scope.
|
||||
/// @param var the variable to register
|
||||
void RegisterVariableForTesting(ast::Variable* var) {
|
||||
variable_stack_.set(var->symbol(), var);
|
||||
}
|
||||
|
||||
@@ -38,19 +38,19 @@
|
||||
#include "src/ast/struct.h"
|
||||
#include "src/ast/struct_member.h"
|
||||
#include "src/ast/switch_statement.h"
|
||||
#include "src/ast/type/alias_type.h"
|
||||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type/vector_type.h"
|
||||
#include "src/ast/type/void_type.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/type/alias_type.h"
|
||||
#include "src/type/array_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/struct_type.h"
|
||||
#include "src/type/vector_type.h"
|
||||
#include "src/type/void_type.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/validator/validator_impl.h"
|
||||
#include "src/validator/validator_test_helper.h"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "src/ast/builder.h"
|
||||
#include "src/ast/type/void_type.h"
|
||||
#include "src/type/void_type.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/validator/validator_impl.h"
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
#include "src/ast/struct_block_decoration.h"
|
||||
#include "src/ast/struct_member.h"
|
||||
#include "src/ast/struct_member_decoration.h"
|
||||
#include "src/ast/type/alias_type.h"
|
||||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/type/alias_type.h"
|
||||
#include "src/type/array_type.h"
|
||||
#include "src/type/f32_type.h"
|
||||
#include "src/type/i32_type.h"
|
||||
#include "src/type/struct_type.h"
|
||||
#include "src/validator/validator_impl.h"
|
||||
#include "src/validator/validator_test_helper.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user