From 4f3ff57c28904c7d01b53b3a3a9ae0594fa601e8 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 15 Oct 2021 17:33:10 +0000 Subject: [PATCH] ast: Keep style consistent Methods and functions are `CamelCase()` Public fields are `snake_case` with no trailing `_` Private fields are `snake_case` with a trailing `_` Remove pointless getters on fully immutable fields. They provide no value, and just add `()` noise on use. Remove unused methods. Bug: tint:1231 Change-Id: If32efd039df48938efd5bc2186d51fe4853e9840 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66600 Reviewed-by: David Neto Commit-Queue: Ben Clayton Kokoro: Kokoro --- .../mutations/replace_identifier.cc | 4 +- .../mutations/replace_identifier_test.cc | 217 ++- fuzzers/tint_ast_fuzzer/util.h | 6 +- src/ast/alias.cc | 15 +- src/ast/alias.h | 19 +- src/ast/alias_test.cc | 4 +- src/ast/array.cc | 37 +- src/ast/array.h | 35 +- src/ast/array_accessor_expression.cc | 24 +- src/ast/array_accessor_expression.h | 23 +- src/ast/array_accessor_expression_test.cc | 6 +- src/ast/array_test.cc | 12 +- src/ast/assignment_statement.cc | 24 +- src/ast/assignment_statement.h | 14 +- src/ast/assignment_statement_test.cc | 6 +- src/ast/ast_type.cc | 3 +- src/ast/atomic.cc | 10 +- src/ast/atomic.h | 13 +- src/ast/atomic_test.cc | 2 +- src/ast/binary_expression.cc | 30 +- src/ast/binary_expression.h | 63 +- src/ast/binary_expression_test.cc | 8 +- src/ast/binding_decoration.cc | 12 +- src/ast/binding_decoration.h | 15 +- src/ast/binding_decoration_test.cc | 2 +- src/ast/bitcast_expression.cc | 22 +- src/ast/bitcast_expression.h | 13 +- src/ast/bitcast_expression_test.cc | 6 +- src/ast/block_statement.cc | 14 +- src/ast/block_statement.h | 40 +- src/ast/block_statement_test.cc | 6 +- src/ast/bool.cc | 5 +- src/ast/bool.h | 6 +- src/ast/bool_literal.cc | 12 +- src/ast/bool_literal.h | 17 +- src/ast/bool_literal_test.cc | 6 +- src/ast/break_statement.cc | 6 +- src/ast/break_statement.h | 6 +- src/ast/break_statement_test.cc | 2 +- src/ast/builtin_decoration.cc | 14 +- src/ast/builtin_decoration.h | 17 +- src/ast/builtin_decoration_test.cc | 2 +- src/ast/call_expression.cc | 22 +- src/ast/call_expression.h | 13 +- src/ast/call_expression_test.cc | 6 +- src/ast/call_statement.cc | 14 +- src/ast/call_statement.h | 16 +- src/ast/call_statement_test.cc | 2 +- src/ast/case_statement.cc | 20 +- src/ast/case_statement.h | 26 +- src/ast/case_statement_test.cc | 18 +- src/ast/constructor_expression.cc | 5 +- src/ast/constructor_expression.h | 6 +- src/ast/continue_statement.cc | 6 +- src/ast/continue_statement.h | 6 +- src/ast/continue_statement_test.cc | 2 +- src/ast/decoration.h | 9 +- src/ast/depth_multisampled_texture.cc | 14 +- src/ast/depth_multisampled_texture.h | 8 +- src/ast/depth_multisampled_texture_test.cc | 2 +- src/ast/depth_texture.cc | 12 +- src/ast/depth_texture.h | 8 +- src/ast/depth_texture_test.cc | 2 +- src/ast/disable_validation_decoration.cc | 11 +- src/ast/disable_validation_decoration.h | 7 +- src/ast/discard_statement.cc | 6 +- src/ast/discard_statement.h | 6 +- src/ast/discard_statement_test.cc | 16 +- src/ast/else_statement.cc | 22 +- src/ast/else_statement.h | 27 +- src/ast/else_statement_test.cc | 14 +- src/ast/expression.cc | 8 +- src/ast/expression.h | 11 +- src/ast/external_texture.cc | 4 +- src/ast/external_texture.h | 6 +- src/ast/external_texture_test.cc | 2 +- src/ast/f32.cc | 5 +- src/ast/f32.h | 6 +- src/ast/fallthrough_statement.cc | 7 +- src/ast/fallthrough_statement.h | 6 +- src/ast/fallthrough_statement_test.cc | 10 +- src/ast/float_literal.cc | 18 +- src/ast/float_literal.h | 16 +- src/ast/float_literal_test.cc | 7 +- src/ast/for_loop_statement.cc | 42 +- src/ast/for_loop_statement.h | 37 +- src/ast/for_loop_statement_test.cc | 12 +- src/ast/function.cc | 74 +- src/ast/function.h | 54 +- src/ast/function_test.cc | 26 +- src/ast/group_decoration.cc | 12 +- src/ast/group_decoration.h | 15 +- src/ast/group_decoration_test.cc | 2 +- src/ast/i32.cc | 5 +- src/ast/i32.h | 6 +- src/ast/identifier_expression.cc | 14 +- src/ast/identifier_expression.h | 14 +- src/ast/identifier_expression_test.cc | 6 +- src/ast/if_statement.cc | 34 +- src/ast/if_statement.h | 34 +- src/ast/if_statement_test.cc | 2 +- src/ast/int_literal.cc | 6 +- src/ast/int_literal.h | 18 +- src/ast/internal_decoration.cc | 5 +- src/ast/internal_decoration.h | 2 +- src/ast/interpolate_decoration.cc | 16 +- src/ast/interpolate_decoration.h | 24 +- src/ast/interpolate_decoration_test.cc | 4 +- src/ast/intrinsic_texture_helper_test.cc | 10 +- src/ast/intrinsic_texture_helper_test.h | 6 +- src/ast/invariant_decoration.cc | 9 +- src/ast/invariant_decoration.h | 8 +- src/ast/literal.cc | 3 +- src/ast/literal.h | 9 +- src/ast/location_decoration.cc | 12 +- src/ast/location_decoration.h | 17 +- src/ast/location_decoration_test.cc | 2 +- src/ast/loop_statement.cc | 22 +- src/ast/loop_statement.h | 23 +- src/ast/loop_statement_test.cc | 16 +- src/ast/matrix.cc | 23 +- src/ast/matrix.h | 27 +- src/ast/matrix_test.cc | 6 +- src/ast/member_accessor_expression.cc | 24 +- src/ast/member_accessor_expression.h | 14 +- src/ast/member_accessor_expression_test.cc | 6 +- src/ast/module.cc | 23 +- src/ast/module.h | 14 +- src/ast/module_test.cc | 6 +- src/ast/multisampled_texture.cc | 20 +- src/ast/multisampled_texture.h | 15 +- src/ast/multisampled_texture_test.cc | 4 +- src/ast/node.cc | 8 +- src/ast/node.h | 24 +- src/ast/override_decoration.cc | 19 +- src/ast/override_decoration.h | 28 +- src/ast/override_decoration_test.cc | 6 +- src/ast/pointer.cc | 29 +- src/ast/pointer.h | 29 +- src/ast/pointer_test.cc | 6 +- src/ast/return_statement.cc | 18 +- src/ast/return_statement.h | 24 +- src/ast/return_statement_test.cc | 12 +- src/ast/sampled_texture.cc | 20 +- src/ast/sampled_texture.h | 15 +- src/ast/sampled_texture_test.cc | 4 +- src/ast/sampler.cc | 10 +- src/ast/sampler.h | 15 +- src/ast/sampler_test.cc | 4 +- src/ast/scalar_constructor_expression.cc | 12 +- src/ast/scalar_constructor_expression.h | 16 +- src/ast/scalar_constructor_expression_test.cc | 4 +- src/ast/sint_literal.cc | 14 +- src/ast/sint_literal.h | 16 +- src/ast/sint_literal_test.cc | 7 +- src/ast/stage_decoration.cc | 14 +- src/ast/stage_decoration.h | 9 +- src/ast/stage_decoration_test.cc | 2 +- src/ast/statement.cc | 3 +- src/ast/statement.h | 6 +- src/ast/storage_class.cc | 4 +- src/ast/storage_class.h | 2 +- src/ast/storage_texture.cc | 25 +- src/ast/storage_texture.h | 36 +- src/ast/storage_texture_test.cc | 10 +- src/ast/stride_decoration.cc | 12 +- src/ast/stride_decoration.h | 15 +- src/ast/stride_decoration_test.cc | 11 +- src/ast/struct.cc | 37 +- src/ast/struct.h | 28 +- src/ast/struct_block_decoration.cc | 9 +- src/ast/struct_block_decoration.h | 8 +- src/ast/struct_member.cc | 39 +- src/ast/struct_member.h | 35 +- src/ast/struct_member_align_decoration.cc | 14 +- src/ast/struct_member_align_decoration.h | 17 +- .../struct_member_align_decoration_test.cc | 2 +- src/ast/struct_member_offset_decoration.cc | 14 +- src/ast/struct_member_offset_decoration.h | 17 +- .../struct_member_offset_decoration_test.cc | 2 +- src/ast/struct_member_size_decoration.cc | 14 +- src/ast/struct_member_size_decoration.h | 17 +- src/ast/struct_member_size_decoration_test.cc | 2 +- src/ast/struct_member_test.cc | 30 +- src/ast/struct_test.cc | 46 +- src/ast/switch_statement.cc | 22 +- src/ast/switch_statement.h | 24 +- src/ast/switch_statement_test.cc | 8 +- src/ast/texture.cc | 6 +- src/ast/texture.h | 13 +- src/ast/type.h | 6 +- src/ast/type_constructor_expression.cc | 20 +- src/ast/type_constructor_expression.h | 23 +- src/ast/type_constructor_expression_test.cc | 8 +- src/ast/type_decl.cc | 4 +- src/ast/type_decl.h | 12 +- src/ast/type_name.cc | 10 +- src/ast/type_name.h | 12 +- src/ast/u32.cc | 5 +- src/ast/u32.h | 6 +- src/ast/uint_literal.cc | 14 +- src/ast/uint_literal.h | 16 +- src/ast/uint_literal_test.cc | 2 +- src/ast/unary_op_expression.cc | 20 +- src/ast/unary_op_expression.h | 14 +- src/ast/unary_op_expression_test.cc | 6 +- src/ast/variable.cc | 57 +- src/ast/variable.h | 81 +- src/ast/variable_decl_statement.cc | 16 +- src/ast/variable_decl_statement.h | 8 +- src/ast/variable_decl_statement_test.cc | 4 +- src/ast/variable_test.cc | 78 +- src/ast/vector.cc | 20 +- src/ast/vector.h | 24 +- src/ast/vector_test.cc | 4 +- src/ast/void.cc | 5 +- src/ast/void.h | 6 +- src/ast/workgroup_decoration.cc | 24 +- src/ast/workgroup_decoration.h | 22 +- src/ast/workgroup_decoration_test.cc | 42 +- src/clone_context.h | 4 +- src/inspector/inspector.cc | 110 +- src/program_builder.cc | 6 +- src/program_builder.h | 4 +- src/program_builder_test.cc | 2 +- src/reader/spirv/function.cc | 4 +- src/reader/spirv/parser_impl.cc | 2 +- src/reader/spirv/parser_impl_barrier_test.cc | 16 +- ...ser_impl_convert_member_decoration_test.cc | 8 +- src/reader/spirv/parser_type.cc | 6 +- src/reader/wgsl/parser_impl.cc | 8 +- .../parser_impl_additive_expression_test.cc | 36 +- .../wgsl/parser_impl_and_expression_test.cc | 18 +- .../wgsl/parser_impl_assignment_stmt_test.cc | 90 +- src/reader/wgsl/parser_impl_body_stmt_test.cc | 8 +- src/reader/wgsl/parser_impl_call_stmt_test.cc | 36 +- src/reader/wgsl/parser_impl_case_body_test.cc | 12 +- .../wgsl/parser_impl_const_expr_test.cc | 36 +- .../wgsl/parser_impl_const_literal_test.cc | 30 +- .../wgsl/parser_impl_continuing_stmt_test.cc | 4 +- .../parser_impl_depth_texture_type_test.cc | 20 +- src/reader/wgsl/parser_impl_else_stmt_test.cc | 4 +- .../wgsl/parser_impl_elseif_stmt_test.cc | 18 +- .../parser_impl_equality_expression_test.cc | 36 +- ...arser_impl_exclusive_or_expression_test.cc | 18 +- .../parser_impl_external_texture_type_test.cc | 2 +- src/reader/wgsl/parser_impl_for_stmt_test.cc | 100 +- .../wgsl/parser_impl_function_decl_test.cc | 136 +- ...rser_impl_function_decoration_list_test.cc | 8 +- .../parser_impl_function_decoration_test.cc | 40 +- .../wgsl/parser_impl_function_header_test.cc | 16 +- .../parser_impl_global_constant_decl_test.cc | 92 +- .../wgsl/parser_impl_global_decl_test.cc | 38 +- .../parser_impl_global_variable_decl_test.cc | 76 +- src/reader/wgsl/parser_impl_if_stmt_test.cc | 26 +- ...arser_impl_inclusive_or_expression_test.cc | 18 +- ...parser_impl_logical_and_expression_test.cc | 18 +- .../parser_impl_logical_or_expression_test.cc | 18 +- src/reader/wgsl/parser_impl_loop_stmt_test.cc | 24 +- ...ser_impl_multiplicative_expression_test.cc | 54 +- .../wgsl/parser_impl_param_list_test.cc | 100 +- .../parser_impl_primary_expression_test.cc | 62 +- .../parser_impl_relational_expression_test.cc | 72 +- .../wgsl/parser_impl_sampler_type_test.cc | 4 +- .../wgsl/parser_impl_shift_expression_test.cc | 36 +- .../parser_impl_singular_expression_test.cc | 62 +- src/reader/wgsl/parser_impl_statement_test.cc | 11 +- .../wgsl/parser_impl_struct_body_decl_test.cc | 6 +- .../wgsl/parser_impl_struct_decl_test.cc | 36 +- ...rser_impl_struct_member_decoration_test.cc | 4 +- .../wgsl/parser_impl_struct_member_test.cc | 77 +- .../wgsl/parser_impl_switch_body_test.cc | 26 +- .../wgsl/parser_impl_switch_stmt_test.cc | 16 +- .../parser_impl_texture_sampler_types_test.cc | 50 +- .../wgsl/parser_impl_type_alias_test.cc | 10 +- src/reader/wgsl/parser_impl_type_decl_test.cc | 168 +-- .../wgsl/parser_impl_unary_expression_test.cc | 68 +- .../wgsl/parser_impl_variable_decl_test.cc | 2 +- ...rser_impl_variable_decoration_list_test.cc | 4 +- .../parser_impl_variable_decoration_test.cc | 24 +- .../parser_impl_variable_ident_decl_test.cc | 2 +- .../wgsl/parser_impl_variable_stmt_test.cc | 70 +- src/resolver/inferred_type_test.cc | 4 +- src/resolver/intrinsic_test.cc | 4 +- src/resolver/intrinsic_validation_test.cc | 20 +- src/resolver/resolver.cc | 1204 ++++++++--------- src/resolver/resolver_constants.cc | 12 +- src/resolver/resolver_test.cc | 52 +- src/resolver/validation_test.cc | 4 +- src/scope_stack_test.cc | 6 +- src/sem/block_statement.cc | 2 +- src/sem/function.cc | 14 +- src/sem/function.h | 4 +- src/sem/sem_struct_test.cc | 6 +- src/sem/struct.cc | 2 +- src/transform/array_length_from_uniform.cc | 10 +- src/transform/binding_remapper.cc | 24 +- src/transform/calculate_array_length.cc | 25 +- src/transform/canonicalize_entry_point_io.cc | 64 +- src/transform/decompose_memory_access.cc | 54 +- src/transform/decompose_strided_matrix.cc | 17 +- src/transform/external_texture_transform.cc | 34 +- src/transform/first_index_offset.cc | 8 +- src/transform/fold_constants.cc | 4 +- src/transform/fold_trivial_single_use_lets.cc | 12 +- src/transform/for_loop_to_loop.cc | 8 +- src/transform/inline_pointer_lets.cc | 24 +- src/transform/loop_to_for_loop.cc | 34 +- .../module_scope_var_to_entry_point_param.cc | 24 +- src/transform/num_workgroups_from_uniform.cc | 18 +- src/transform/pad_array_elements.cc | 8 +- .../promote_initializers_to_const_var.cc | 6 +- src/transform/renamer.cc | 12 +- src/transform/robustness.cc | 26 +- src/transform/simplify.cc | 14 +- src/transform/single_entry_point.cc | 6 +- src/transform/transform.cc | 4 +- src/transform/transform_test.cc | 51 +- src/transform/vertex_pulling.cc | 68 +- src/transform/wrap_arrays_in_structs.cc | 13 +- src/transform/zero_init_workgroup_memory.cc | 40 +- src/writer/append_vector.cc | 4 +- src/writer/append_vector_test.cc | 117 +- src/writer/glsl/generator.cc | 4 +- src/writer/glsl/generator_impl.cc | 280 ++-- src/writer/glsl/generator_impl_case_test.cc | 10 +- .../generator_impl_intrinsic_texture_test.cc | 4 +- src/writer/hlsl/generator.cc | 4 +- src/writer/hlsl/generator_impl.cc | 311 +++-- .../generator_impl_intrinsic_texture_test.cc | 4 +- src/writer/msl/generator_impl.cc | 284 ++-- src/writer/msl/generator_impl_case_test.cc | 10 +- .../generator_impl_intrinsic_texture_test.cc | 4 +- src/writer/spirv/builder.cc | 277 ++-- .../spirv/builder_intrinsic_texture_test.cc | 12 +- src/writer/wgsl/generator_impl.cc | 230 ++-- src/writer/wgsl/generator_impl_case_test.cc | 6 +- 337 files changed, 4287 insertions(+), 4803 deletions(-) diff --git a/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc b/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc index 2b2bb9d728..6823d21dfd 100644 --- a/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc +++ b/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc @@ -89,8 +89,8 @@ void MutationReplaceIdentifier::Apply(const NodeIdMap& node_id_map, tint::As(node_id_map.GetNode(message_.replacement_id())); auto* cloned_replacement = - clone_context->dst->Expr(clone_context->Clone(use_node->source()), - clone_context->Clone(replacement_var->symbol())); + clone_context->dst->Expr(clone_context->Clone(use_node->source), + clone_context->Clone(replacement_var->symbol)); clone_context->Replace(use_node, cloned_replacement); new_node_id_map->Add(cloned_replacement, message_.use_id()); } diff --git a/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc b/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc index bf12407f45..d3a125fb89 100644 --- a/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc +++ b/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc @@ -49,19 +49,18 @@ TEST(ReplaceIdentifierTest, NotApplicable_Simple) { NodeIdMap node_id_map(program); - const auto& main_fn_stmts = - program.AST().Functions()[0]->body()->statements(); + const auto& main_fn_stmts = program.AST().Functions()[0]->body->statements; const auto* a_var = - main_fn_stmts[0]->As()->variable(); + main_fn_stmts[0]->As()->variable; ASSERT_NE(a_var, nullptr); const auto* b_var = - main_fn_stmts[2]->As()->variable(); + main_fn_stmts[2]->As()->variable; ASSERT_NE(b_var, nullptr); const auto* e_var = - main_fn_stmts[4]->As()->variable(); + main_fn_stmts[4]->As()->variable; ASSERT_NE(e_var, nullptr); auto a_var_id = node_id_map.GetId(a_var); @@ -70,10 +69,10 @@ TEST(ReplaceIdentifierTest, NotApplicable_Simple) { auto b_var_id = node_id_map.GetId(b_var); ASSERT_NE(b_var_id, 0); - const auto* sum_expr = b_var->constructor()->As(); + const auto* sum_expr = b_var->constructor->As(); ASSERT_NE(sum_expr, nullptr); - auto a_ident_id = node_id_map.GetId(sum_expr->lhs()); + auto a_ident_id = node_id_map.GetId(sum_expr->lhs); ASSERT_NE(a_ident_id, 0); auto sum_expr_id = node_id_map.GetId(sum_expr); @@ -83,7 +82,7 @@ TEST(ReplaceIdentifierTest, NotApplicable_Simple) { ASSERT_NE(e_var_id, 0); auto vec_member_access_id = node_id_map.GetId( - e_var->constructor()->As()->member()); + e_var->constructor->As()->member); ASSERT_NE(vec_member_access_id, 0); // use_id is invalid. @@ -136,10 +135,9 @@ var b: i32; auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[0] + ->body->statements[0] ->As() - ->lhs()); + ->lhs); ASSERT_NE(use_id, 0); auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[1]); @@ -170,14 +168,11 @@ fn f() { auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[0] + ->body->statements[0] ->As() - ->lhs() - ->As() - ->expr() - ->As() - ->expr()); + ->lhs->As() + ->expr->As() + ->expr); ASSERT_NE(use_id, 0); ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id) @@ -202,22 +197,18 @@ fn f() { auto replacement_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[0] + ->body->statements[0] ->As() - ->variable()); + ->variable); ASSERT_NE(replacement_id, 0); auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[1] + ->body->statements[1] ->As() - ->lhs() - ->As() - ->expr() - ->As() - ->expr()); + ->lhs->As() + ->expr->As() + ->expr); ASSERT_NE(use_id, 0); ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id) @@ -242,22 +233,18 @@ fn f() { auto replacement_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[0] + ->body->statements[0] ->As() - ->variable()); + ->variable); ASSERT_NE(replacement_id, 0); auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[1] + ->body->statements[1] ->As() - ->lhs() - ->As() - ->expr() - ->As() - ->expr()); + ->lhs->As() + ->expr->As() + ->expr); ASSERT_NE(use_id, 0); ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id) @@ -280,19 +267,16 @@ fn f(b: i32) { NodeIdMap node_id_map(program); auto replacement_id = - node_id_map.GetId(program.AST().Functions()[0]->params()[0]); + node_id_map.GetId(program.AST().Functions()[0]->params[0]); ASSERT_NE(replacement_id, 0); auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[0] + ->body->statements[0] ->As() - ->lhs() - ->As() - ->expr() - ->As() - ->expr()); + ->lhs->As() + ->expr->As() + ->expr); ASSERT_NE(use_id, 0); ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id) @@ -325,14 +309,11 @@ fn f() { auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[0] + ->body->statements[0] ->As() - ->lhs() - ->As() - ->expr() - ->As() - ->expr()); + ->lhs->As() + ->expr->As() + ->expr); ASSERT_NE(use_id, 0); ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id) @@ -365,12 +346,10 @@ fn f() { auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[1] + ->body->statements[1] ->As() - ->rhs() - ->As() - ->expr()); + ->rhs->As() + ->expr); ASSERT_NE(use_id, 0); ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id) @@ -405,12 +384,10 @@ fn f() { auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[1] + ->body->statements[1] ->As() - ->rhs() - ->As() - ->expr()); + ->rhs->As() + ->expr); ASSERT_NE(use_id, 0); ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id) @@ -443,14 +420,11 @@ fn f() { auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[0] + ->body->statements[0] ->As() - ->rhs() - ->As() - ->expr() - ->As() - ->expr()); + ->rhs->As() + ->expr->As() + ->expr); ASSERT_NE(use_id, 0); ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id) @@ -483,14 +457,11 @@ fn f() { auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[0] + ->body->statements[0] ->As() - ->rhs() - ->As() - ->expr() - ->As() - ->expr()); + ->rhs->As() + ->expr->As() + ->expr); ASSERT_NE(use_id, 0); ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id) @@ -514,24 +485,19 @@ fn f() { auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[2] + ->body->statements[2] ->As() - ->lhs() - ->As() - ->array() - ->As() - ->expr() - ->As() - ->expr()); + ->lhs->As() + ->array->As() + ->expr->As() + ->expr); ASSERT_NE(use_id, 0); auto replacement_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[0] + ->body->statements[0] ->As() - ->variable()); + ->variable); ASSERT_NE(replacement_id, 0); ASSERT_TRUE(MaybeApplyMutation( @@ -569,18 +535,15 @@ fn f(b: ptr>) { auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[2] + ->body->statements[2] ->As() - ->lhs() - ->As() - ->array() - ->As() - ->expr()); + ->lhs->As() + ->array->As() + ->expr); ASSERT_NE(use_id, 0); auto replacement_id = - node_id_map.GetId(program.AST().Functions()[0]->params()[0]); + node_id_map.GetId(program.AST().Functions()[0]->params[0]); ASSERT_NE(replacement_id, 0); ASSERT_TRUE(MaybeApplyMutation( @@ -619,16 +582,12 @@ fn f() { auto use_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[1] + ->body->statements[1] ->As() - ->lhs() - ->As() - ->array() - ->As() - ->expr() - ->As() - ->expr()); + ->lhs->As() + ->array->As() + ->expr->As() + ->expr); ASSERT_NE(use_id, 0); auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]); @@ -654,19 +613,15 @@ fn f() { NodeIdMap node_id_map(program); - auto use_id = node_id_map.GetId(program.AST() - .Functions()[0] - ->body() - ->statements()[1] - ->As() - ->variable() - ->constructor() - ->As() - ->array() - ->As() - ->expr() - ->As() - ->expr()); + auto use_id = node_id_map.GetId( + program.AST() + .Functions()[0] + ->body->statements[1] + ->As() + ->variable->constructor->As() + ->array->As() + ->expr->As() + ->expr); ASSERT_NE(use_id, 0); auto replacement_id = node_id_map.GetId(program.AST().GlobalVariables()[0]); @@ -694,25 +649,21 @@ fn f() { NodeIdMap node_id_map(program); - auto use_id = node_id_map.GetId(program.AST() - .Functions()[0] - ->body() - ->statements()[3] - ->As() - ->variable() - ->constructor() - ->As() - ->array() - ->As() - ->expr()); + auto use_id = node_id_map.GetId( + program.AST() + .Functions()[0] + ->body->statements[3] + ->As() + ->variable->constructor->As() + ->array->As() + ->expr); ASSERT_NE(use_id, 0); auto replacement_id = node_id_map.GetId(program.AST() .Functions()[0] - ->body() - ->statements()[2] + ->body->statements[2] ->As() - ->variable()); + ->variable); ASSERT_NE(replacement_id, 0); ASSERT_FALSE(MutationReplaceIdentifier(use_id, replacement_id) .IsApplicable(program, node_id_map)); diff --git a/fuzzers/tint_ast_fuzzer/util.h b/fuzzers/tint_ast_fuzzer/util.h index d8515112bf..e82ebcc9c6 100644 --- a/fuzzers/tint_ast_fuzzer/util.h +++ b/fuzzers/tint_ast_fuzzer/util.h @@ -54,7 +54,7 @@ std::vector GetAllVarsInScope( // Walk up the hierarchy of blocks in which `curr_stmt` is contained. for (const auto* block = curr_stmt->Block(); block; block = tint::As(block->Parent())) { - for (const auto* stmt : *block->Declaration()) { + for (const auto* stmt : block->Declaration()->statements) { if (stmt == curr_stmt->Declaration()) { // `curr_stmt` was found. This is only possible if `block is the // enclosing block of `curr_stmt` since the AST nodes are not shared. @@ -65,7 +65,7 @@ std::vector GetAllVarsInScope( } if (const auto* var_node = tint::As(stmt)) { - const auto* sem_var = program.Sem().Get(var_node->variable()); + const auto* sem_var = program.Sem().Get(var_node->variable); if (pred(sem_var)) { result.push_back(sem_var); } @@ -74,7 +74,7 @@ std::vector GetAllVarsInScope( } // Process function parameters. - for (const auto* param : curr_stmt->Function()->params()) { + for (const auto* param : curr_stmt->Function()->params) { const auto* sem_var = program.Sem().Get(param); if (pred(sem_var)) { result.push_back(sem_var); diff --git a/src/ast/alias.cc b/src/ast/alias.cc index 8a8bba8398..a6983e1b40 100644 --- a/src/ast/alias.cc +++ b/src/ast/alias.cc @@ -21,12 +21,9 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Alias); namespace tint { namespace ast { -Alias::Alias(ProgramID program_id, - const Source& source, - const Symbol& name, - Type* subtype) - : Base(program_id, source, name), subtype_(subtype) { - TINT_ASSERT(AST, subtype_); +Alias::Alias(ProgramID pid, const Source& src, const Symbol& n, Type* subtype) + : Base(pid, src, n), type(subtype) { + TINT_ASSERT(AST, type); } Alias::Alias(Alias&&) = default; @@ -35,9 +32,9 @@ Alias::~Alias() = default; Alias* Alias::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto sym = ctx->Clone(name()); - auto* ty = ctx->Clone(type()); + auto src = ctx->Clone(source); + auto sym = ctx->Clone(name); + auto* ty = ctx->Clone(type); return ctx->dst->create(src, sym, ty); } diff --git a/src/ast/alias.h b/src/ast/alias.h index 9ca50b8c12..7f8acdb9aa 100644 --- a/src/ast/alias.h +++ b/src/ast/alias.h @@ -26,32 +26,23 @@ namespace ast { class Alias : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param name the symbol for the alias /// @param subtype the alias'd type - Alias(ProgramID program_id, - const Source& source, - const Symbol& name, - Type* subtype); + Alias(ProgramID pid, const Source& src, const Symbol& name, Type* subtype); /// Move constructor Alias(Alias&&); /// Destructor ~Alias() override; - /// [DEPRECATED] use name() - /// @returns the alias symbol - Symbol symbol() const { return name(); } - /// @returns the alias type - Type* type() const { return subtype_; } - /// Clones this type and all transitive types using the `CloneContext` `ctx`. /// @param ctx the clone context /// @return the newly cloned type Alias* Clone(CloneContext* ctx) const override; - private: - Type* const subtype_; + /// the alias type + Type* const type; }; } // namespace ast diff --git a/src/ast/alias_test.cc b/src/ast/alias_test.cc index 8a744cfc55..4e72967a29 100644 --- a/src/ast/alias_test.cc +++ b/src/ast/alias_test.cc @@ -36,8 +36,8 @@ using AstAliasTest = TestHelper; TEST_F(AstAliasTest, Create) { auto* u32 = create(); auto* a = Alias("a_type", u32); - EXPECT_EQ(a->symbol(), Symbol(1, ID())); - EXPECT_EQ(a->type(), u32); + EXPECT_EQ(a->name, Symbol(1, ID())); + EXPECT_EQ(a->type, u32); } } // namespace diff --git a/src/ast/array.cc b/src/ast/array.cc index b9993a58ba..c582805311 100644 --- a/src/ast/array.cc +++ b/src/ast/array.cc @@ -29,14 +29,14 @@ std::string SizeExprToString(const ast::Expression* size, const SymbolTable* symbols = nullptr) { if (auto* ident = size->As()) { if (symbols) { - return symbols->NameFor(ident->symbol()); + return symbols->NameFor(ident->symbol); } return ""; } if (auto* scalar = size->As()) { - auto* literal = scalar->literal()->As(); + auto* literal = scalar->literal->As(); if (literal) { - return std::to_string(literal->value_as_u32()); + return std::to_string(literal->ValueAsU32()); } } // This will never be exposed to the user as the Resolver will reject this @@ -45,15 +45,12 @@ std::string SizeExprToString(const ast::Expression* size, } } // namespace -Array::Array(ProgramID program_id, - const Source& source, +Array::Array(ProgramID pid, + const Source& src, Type* subtype, - ast::Expression* size, - ast::DecorationList decorations) - : Base(program_id, source), - subtype_(subtype), - size_(size), - decos_(decorations) {} + ast::Expression* cnt, + ast::DecorationList decos) + : Base(pid, src), type(subtype), count(cnt), decorations(decos) {} Array::Array(Array&&) = default; @@ -61,14 +58,14 @@ Array::~Array() = default; std::string Array::FriendlyName(const SymbolTable& symbols) const { std::ostringstream out; - for (auto* deco : decos_) { + for (auto* deco : decorations) { if (auto* stride = deco->As()) { - out << "[[stride(" << stride->stride() << ")]] "; + out << "[[stride(" << stride->stride << ")]] "; } } - out << "array<" << subtype_->FriendlyName(symbols); + out << "array<" << type->FriendlyName(symbols); if (!IsRuntimeArray()) { - out << ", " << SizeExprToString(size_, &symbols); + out << ", " << SizeExprToString(count, &symbols); } out << ">"; return out.str(); @@ -76,11 +73,11 @@ std::string Array::FriendlyName(const SymbolTable& symbols) const { Array* Array::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ty = ctx->Clone(type()); - auto* size = ctx->Clone(Size()); - auto decos = ctx->Clone(decorations()); - return ctx->dst->create(src, ty, size, decos); + auto src = ctx->Clone(source); + auto* ty = ctx->Clone(type); + auto* cnt = ctx->Clone(count); + auto decos = ctx->Clone(decorations); + return ctx->dst->create(src, ty, cnt, decos); } } // namespace ast diff --git a/src/ast/array.h b/src/ast/array.h index df0ba88871..28d8682ba4 100644 --- a/src/ast/array.h +++ b/src/ast/array.h @@ -30,16 +30,16 @@ class Expression; class Array : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param subtype the type of the array elements - /// @param size the number of elements in the array. nullptr represents a + /// @param count the number of elements in the array. nullptr represents a /// runtime-sized array. /// @param decorations the array decorations - Array(ProgramID program_id, - const Source& source, + Array(ProgramID pid, + const Source& src, Type* subtype, - ast::Expression* size, + ast::Expression* count, ast::DecorationList decorations); /// Move constructor Array(Array&&); @@ -47,16 +47,7 @@ class Array : public Castable { /// @returns true if this is a runtime array. /// i.e. the size is determined at runtime - bool IsRuntimeArray() const { return size_ == nullptr; } - - /// @returns the array decorations - const ast::DecorationList& decorations() const { return decos_; } - - /// @returns the array type - Type* type() const { return subtype_; } - - /// @returns the array size, or nullptr for a runtime array - ast::Expression* Size() const { return size_; } + bool IsRuntimeArray() const { return count == nullptr; } /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be @@ -68,10 +59,14 @@ class Array : public Castable { /// @return the newly cloned type Array* Clone(CloneContext* ctx) const override; - private: - Type* const subtype_; - ast::Expression* const size_; - ast::DecorationList const decos_; + /// the array element type + Type* const type; + + /// the array size in elements, or nullptr for a runtime array + ast::Expression* const count; + + /// the array decorations + ast::DecorationList const decorations; }; } // namespace ast diff --git a/src/ast/array_accessor_expression.cc b/src/ast/array_accessor_expression.cc index b7b9a41e8e..1f40234b8a 100644 --- a/src/ast/array_accessor_expression.cc +++ b/src/ast/array_accessor_expression.cc @@ -21,15 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ArrayAccessorExpression); namespace tint { namespace ast { -ArrayAccessorExpression::ArrayAccessorExpression(ProgramID program_id, - const Source& source, - Expression* array, - Expression* idx_expr) - : Base(program_id, source), array_(array), idx_expr_(idx_expr) { - TINT_ASSERT(AST, array_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, array_, program_id); - TINT_ASSERT(AST, idx_expr_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, idx_expr_, program_id); +ArrayAccessorExpression::ArrayAccessorExpression(ProgramID pid, + const Source& src, + Expression* arr, + Expression* idx) + : Base(pid, src), array(arr), index(idx) { + TINT_ASSERT(AST, array); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, array, program_id); + TINT_ASSERT(AST, idx); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, idx, program_id); } ArrayAccessorExpression::ArrayAccessorExpression(ArrayAccessorExpression&&) = @@ -40,9 +40,9 @@ ArrayAccessorExpression::~ArrayAccessorExpression() = default; ArrayAccessorExpression* ArrayAccessorExpression::Clone( CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* arr = ctx->Clone(array_); - auto* idx = ctx->Clone(idx_expr_); + auto src = ctx->Clone(source); + auto* arr = ctx->Clone(array); + auto* idx = ctx->Clone(index); return ctx->dst->create(src, arr, idx); } diff --git a/src/ast/array_accessor_expression.h b/src/ast/array_accessor_expression.h index 891884dade..fb5e5bc288 100644 --- a/src/ast/array_accessor_expression.h +++ b/src/ast/array_accessor_expression.h @@ -27,33 +27,30 @@ class ArrayAccessorExpression /// Constructor /// @param program_id the identifier of the program that owns this node /// @param source the array accessor source - /// @param array the array - /// @param idx_expr the index expression + /// @param arr the array + /// @param idx the index expression ArrayAccessorExpression(ProgramID program_id, const Source& source, - Expression* array, - Expression* idx_expr); + Expression* arr, + Expression* idx); /// Move constructor ArrayAccessorExpression(ArrayAccessorExpression&&); ~ArrayAccessorExpression() override; - /// @returns the array - Expression* array() const { return array_; } - - /// @returns the index expression - Expression* idx_expr() const { return idx_expr_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node ArrayAccessorExpression* Clone(CloneContext* ctx) const override; + /// the array + Expression* const array; + + /// the index expression + Expression* const index; + private: ArrayAccessorExpression(const ArrayAccessorExpression&) = delete; - - Expression* const array_; - Expression* const idx_expr_; }; } // namespace ast diff --git a/src/ast/array_accessor_expression_test.cc b/src/ast/array_accessor_expression_test.cc index 90f93ac097..93f374aea8 100644 --- a/src/ast/array_accessor_expression_test.cc +++ b/src/ast/array_accessor_expression_test.cc @@ -26,8 +26,8 @@ TEST_F(ArrayAccessorExpressionTest, Create) { auto* idx = Expr("idx"); auto* exp = create(ary, idx); - ASSERT_EQ(exp->array(), ary); - ASSERT_EQ(exp->idx_expr(), idx); + ASSERT_EQ(exp->array, ary); + ASSERT_EQ(exp->index, idx); } TEST_F(ArrayAccessorExpressionTest, CreateWithSource) { @@ -36,7 +36,7 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) { auto* exp = create(Source{Source::Location{20, 2}}, ary, idx); - auto src = exp->source(); + auto src = exp->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/array_test.cc b/src/ast/array_test.cc index 8bea47b8ce..3ada2c79a1 100644 --- a/src/ast/array_test.cc +++ b/src/ast/array_test.cc @@ -24,10 +24,10 @@ using AstArrayTest = TestHelper; TEST_F(AstArrayTest, CreateSizedArray) { auto* u32 = create(); - auto* size = Expr(3); - auto* arr = create(u32, size, DecorationList{}); - EXPECT_EQ(arr->type(), u32); - EXPECT_EQ(arr->Size(), size); + auto* count = Expr(3); + auto* arr = create(u32, count, DecorationList{}); + EXPECT_EQ(arr->type, u32); + EXPECT_EQ(arr->count, count); EXPECT_TRUE(arr->Is()); EXPECT_FALSE(arr->IsRuntimeArray()); } @@ -35,8 +35,8 @@ TEST_F(AstArrayTest, CreateSizedArray) { TEST_F(AstArrayTest, CreateRuntimeArray) { auto* u32 = create(); auto* arr = create(u32, nullptr, DecorationList{}); - EXPECT_EQ(arr->type(), u32); - EXPECT_EQ(arr->Size(), nullptr); + EXPECT_EQ(arr->type, u32); + EXPECT_EQ(arr->count, nullptr); EXPECT_TRUE(arr->Is()); EXPECT_TRUE(arr->IsRuntimeArray()); } diff --git a/src/ast/assignment_statement.cc b/src/ast/assignment_statement.cc index 5569a706f2..0031bf606d 100644 --- a/src/ast/assignment_statement.cc +++ b/src/ast/assignment_statement.cc @@ -21,15 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::AssignmentStatement); namespace tint { namespace ast { -AssignmentStatement::AssignmentStatement(ProgramID program_id, - const Source& source, - Expression* lhs, - Expression* rhs) - : Base(program_id, source), lhs_(lhs), rhs_(rhs) { - TINT_ASSERT(AST, lhs_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs_, program_id); - TINT_ASSERT(AST, rhs_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs_, program_id); +AssignmentStatement::AssignmentStatement(ProgramID pid, + const Source& src, + Expression* l, + Expression* r) + : Base(pid, src), lhs(l), rhs(r) { + TINT_ASSERT(AST, lhs); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id); + TINT_ASSERT(AST, rhs); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs, program_id); } AssignmentStatement::AssignmentStatement(AssignmentStatement&&) = default; @@ -38,9 +38,9 @@ AssignmentStatement::~AssignmentStatement() = default; AssignmentStatement* AssignmentStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* l = ctx->Clone(lhs_); - auto* r = ctx->Clone(rhs_); + auto src = ctx->Clone(source); + auto* l = ctx->Clone(lhs); + auto* r = ctx->Clone(rhs); return ctx->dst->create(src, l, r); } diff --git a/src/ast/assignment_statement.h b/src/ast/assignment_statement.h index 6857a0502c..bb8ea25f6e 100644 --- a/src/ast/assignment_statement.h +++ b/src/ast/assignment_statement.h @@ -37,22 +37,20 @@ class AssignmentStatement : public Castable { AssignmentStatement(AssignmentStatement&&); ~AssignmentStatement() override; - /// @returns the left side expression - Expression* lhs() const { return lhs_; } - /// @returns the right side expression - Expression* rhs() const { return rhs_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node AssignmentStatement* Clone(CloneContext* ctx) const override; + /// left side expression + Expression* const lhs; + + /// right side expression + Expression* const rhs; + private: AssignmentStatement(const AssignmentStatement&) = delete; - - Expression* const lhs_; - Expression* const rhs_; }; } // namespace ast diff --git a/src/ast/assignment_statement_test.cc b/src/ast/assignment_statement_test.cc index 677f0bca13..6c1a716d9a 100644 --- a/src/ast/assignment_statement_test.cc +++ b/src/ast/assignment_statement_test.cc @@ -28,8 +28,8 @@ TEST_F(AssignmentStatementTest, Creation) { auto* rhs = Expr("rhs"); auto* stmt = create(lhs, rhs); - EXPECT_EQ(stmt->lhs(), lhs); - EXPECT_EQ(stmt->rhs(), rhs); + EXPECT_EQ(stmt->lhs, lhs); + EXPECT_EQ(stmt->rhs, rhs); } TEST_F(AssignmentStatementTest, CreationWithSource) { @@ -38,7 +38,7 @@ TEST_F(AssignmentStatementTest, CreationWithSource) { auto* stmt = create(Source{Source::Location{20, 2}}, lhs, rhs); - auto src = stmt->source(); + auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/ast_type.cc b/src/ast/ast_type.cc index d48d66d290..cd6d4bb95d 100644 --- a/src/ast/ast_type.cc +++ b/src/ast/ast_type.cc @@ -31,8 +31,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Type); namespace tint { namespace ast { -Type::Type(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +Type::Type(ProgramID pid, const Source& src) : Base(pid, src) {} Type::Type(Type&&) = default; diff --git a/src/ast/atomic.cc b/src/ast/atomic.cc index 7ecd74d4e2..635e758d36 100644 --- a/src/ast/atomic.cc +++ b/src/ast/atomic.cc @@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Atomic); namespace tint { namespace ast { -Atomic::Atomic(ProgramID program_id, const Source& source, Type* const subtype) - : Base(program_id, source), subtype_(subtype) {} +Atomic::Atomic(ProgramID pid, const Source& src, Type* const subtype) + : Base(pid, src), type(subtype) {} std::string Atomic::FriendlyName(const SymbolTable& symbols) const { std::ostringstream out; - out << "atomic<" << subtype_->FriendlyName(symbols) << ">"; + out << "atomic<" << type->FriendlyName(symbols) << ">"; return out.str(); } @@ -36,8 +36,8 @@ Atomic::~Atomic() = default; Atomic* Atomic::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ty = ctx->Clone(type()); + auto src = ctx->Clone(source); + auto* ty = ctx->Clone(const_cast(type)); return ctx->dst->create(src, ty); } diff --git a/src/ast/atomic.h b/src/ast/atomic.h index 8488ee6f57..f00d128a1f 100644 --- a/src/ast/atomic.h +++ b/src/ast/atomic.h @@ -26,17 +26,14 @@ namespace ast { class Atomic : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param subtype the pointee type - Atomic(ProgramID program_id, const Source& source, Type* const subtype); + Atomic(ProgramID pid, const Source& src, Type* const subtype); /// Move constructor Atomic(Atomic&&); ~Atomic() override; - /// @returns the pointee type - Type* type() const { return const_cast(subtype_); } - /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be /// declared in WGSL. @@ -47,8 +44,8 @@ class Atomic : public Castable { /// @return the newly cloned type Atomic* Clone(CloneContext* ctx) const override; - private: - Type const* const subtype_; + /// the pointee type + Type const* const type; }; } // namespace ast diff --git a/src/ast/atomic_test.cc b/src/ast/atomic_test.cc index 33ffaaed65..961882710e 100644 --- a/src/ast/atomic_test.cc +++ b/src/ast/atomic_test.cc @@ -26,7 +26,7 @@ using AstAtomicTest = TestHelper; TEST_F(AstAtomicTest, Creation) { auto* i32 = create(); auto* p = create(i32); - EXPECT_EQ(p->type(), i32); + EXPECT_EQ(p->type, i32); } TEST_F(AstAtomicTest, FriendlyName) { diff --git a/src/ast/binary_expression.cc b/src/ast/binary_expression.cc index c5fb86003b..f757bfef25 100644 --- a/src/ast/binary_expression.cc +++ b/src/ast/binary_expression.cc @@ -21,17 +21,17 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BinaryExpression); namespace tint { namespace ast { -BinaryExpression::BinaryExpression(ProgramID program_id, - const Source& source, - BinaryOp op, - Expression* lhs, - Expression* rhs) - : Base(program_id, source), op_(op), lhs_(lhs), rhs_(rhs) { - TINT_ASSERT(AST, lhs_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs_, program_id); - TINT_ASSERT(AST, rhs_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs_, program_id); - TINT_ASSERT(AST, op_ != BinaryOp::kNone); +BinaryExpression::BinaryExpression(ProgramID pid, + const Source& src, + BinaryOp o, + Expression* l, + Expression* r) + : Base(pid, src), op(o), lhs(l), rhs(r) { + TINT_ASSERT(AST, lhs); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id); + TINT_ASSERT(AST, rhs); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs, program_id); + TINT_ASSERT(AST, op != BinaryOp::kNone); } BinaryExpression::BinaryExpression(BinaryExpression&&) = default; @@ -40,10 +40,10 @@ BinaryExpression::~BinaryExpression() = default; BinaryExpression* BinaryExpression::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* l = ctx->Clone(lhs_); - auto* r = ctx->Clone(rhs_); - return ctx->dst->create(src, op_, l, r); + auto src = ctx->Clone(source); + auto* l = ctx->Clone(lhs); + auto* r = ctx->Clone(rhs); + return ctx->dst->create(src, op, l, r); } } // namespace ast diff --git a/src/ast/binary_expression.h b/src/ast/binary_expression.h index fedcd06430..8c088f407a 100644 --- a/src/ast/binary_expression.h +++ b/src/ast/binary_expression.h @@ -61,45 +61,42 @@ class BinaryExpression : public Castable { BinaryExpression(BinaryExpression&&); ~BinaryExpression() override; - /// @returns the binary op type - BinaryOp op() const { return op_; } - /// @returns true if the op is and - bool IsAnd() const { return op_ == BinaryOp::kAnd; } + bool IsAnd() const { return op == BinaryOp::kAnd; } /// @returns true if the op is or - bool IsOr() const { return op_ == BinaryOp::kOr; } + bool IsOr() const { return op == BinaryOp::kOr; } /// @returns true if the op is xor - bool IsXor() const { return op_ == BinaryOp::kXor; } + bool IsXor() const { return op == BinaryOp::kXor; } /// @returns true if the op is logical and - bool IsLogicalAnd() const { return op_ == BinaryOp::kLogicalAnd; } + bool IsLogicalAnd() const { return op == BinaryOp::kLogicalAnd; } /// @returns true if the op is logical or - bool IsLogicalOr() const { return op_ == BinaryOp::kLogicalOr; } + bool IsLogicalOr() const { return op == BinaryOp::kLogicalOr; } /// @returns true if the op is equal - bool IsEqual() const { return op_ == BinaryOp::kEqual; } + bool IsEqual() const { return op == BinaryOp::kEqual; } /// @returns true if the op is not equal - bool IsNotEqual() const { return op_ == BinaryOp::kNotEqual; } + bool IsNotEqual() const { return op == BinaryOp::kNotEqual; } /// @returns true if the op is less than - bool IsLessThan() const { return op_ == BinaryOp::kLessThan; } + bool IsLessThan() const { return op == BinaryOp::kLessThan; } /// @returns true if the op is greater than - bool IsGreaterThan() const { return op_ == BinaryOp::kGreaterThan; } + bool IsGreaterThan() const { return op == BinaryOp::kGreaterThan; } /// @returns true if the op is less than equal - bool IsLessThanEqual() const { return op_ == BinaryOp::kLessThanEqual; } + bool IsLessThanEqual() const { return op == BinaryOp::kLessThanEqual; } /// @returns true if the op is greater than equal - bool IsGreaterThanEqual() const { return op_ == BinaryOp::kGreaterThanEqual; } + bool IsGreaterThanEqual() const { return op == BinaryOp::kGreaterThanEqual; } /// @returns true if the op is shift left - bool IsShiftLeft() const { return op_ == BinaryOp::kShiftLeft; } + bool IsShiftLeft() const { return op == BinaryOp::kShiftLeft; } /// @returns true if the op is shift right - bool IsShiftRight() const { return op_ == BinaryOp::kShiftRight; } + bool IsShiftRight() const { return op == BinaryOp::kShiftRight; } /// @returns true if the op is add - bool IsAdd() const { return op_ == BinaryOp::kAdd; } + bool IsAdd() const { return op == BinaryOp::kAdd; } /// @returns true if the op is subtract - bool IsSubtract() const { return op_ == BinaryOp::kSubtract; } + bool IsSubtract() const { return op == BinaryOp::kSubtract; } /// @returns true if the op is multiply - bool IsMultiply() const { return op_ == BinaryOp::kMultiply; } + bool IsMultiply() const { return op == BinaryOp::kMultiply; } /// @returns true if the op is divide - bool IsDivide() const { return op_ == BinaryOp::kDivide; } + bool IsDivide() const { return op == BinaryOp::kDivide; } /// @returns true if the op is modulo - bool IsModulo() const { return op_ == BinaryOp::kModulo; } + bool IsModulo() const { return op == BinaryOp::kModulo; } /// @returns true if the op is an arithmetic operation bool IsArithmetic() const; /// @returns true if the op is a comparison operation @@ -109,27 +106,25 @@ class BinaryExpression : public Castable { /// @returns true if the op is a bit shift operation bool IsBitshift() const; - /// @returns the left side expression - Expression* lhs() const { return lhs_; } - /// @returns the right side expression - Expression* rhs() const { return rhs_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node BinaryExpression* Clone(CloneContext* ctx) const override; + /// the binary op type + BinaryOp const op; + /// the left side expression + Expression* const lhs; + /// the right side expression + Expression* const rhs; + private: BinaryExpression(const BinaryExpression&) = delete; - - BinaryOp const op_; - Expression* const lhs_; - Expression* const rhs_; }; inline bool BinaryExpression::IsArithmetic() const { - switch (op_) { + switch (op) { case ast::BinaryOp::kAdd: case ast::BinaryOp::kSubtract: case ast::BinaryOp::kMultiply: @@ -142,7 +137,7 @@ inline bool BinaryExpression::IsArithmetic() const { } inline bool BinaryExpression::IsComparison() const { - switch (op_) { + switch (op) { case ast::BinaryOp::kEqual: case ast::BinaryOp::kNotEqual: case ast::BinaryOp::kLessThan: @@ -156,7 +151,7 @@ inline bool BinaryExpression::IsComparison() const { } inline bool BinaryExpression::IsBitwise() const { - switch (op_) { + switch (op) { case ast::BinaryOp::kAnd: case ast::BinaryOp::kOr: case ast::BinaryOp::kXor: @@ -167,7 +162,7 @@ inline bool BinaryExpression::IsBitwise() const { } inline bool BinaryExpression::IsBitshift() const { - switch (op_) { + switch (op) { case ast::BinaryOp::kShiftLeft: case ast::BinaryOp::kShiftRight: return true; diff --git a/src/ast/binary_expression_test.cc b/src/ast/binary_expression_test.cc index 343e0734d5..379385ec44 100644 --- a/src/ast/binary_expression_test.cc +++ b/src/ast/binary_expression_test.cc @@ -26,9 +26,9 @@ TEST_F(BinaryExpressionTest, Creation) { auto* rhs = Expr("rhs"); auto* r = create(BinaryOp::kEqual, lhs, rhs); - EXPECT_EQ(r->lhs(), lhs); - EXPECT_EQ(r->rhs(), rhs); - EXPECT_EQ(r->op(), BinaryOp::kEqual); + EXPECT_EQ(r->lhs, lhs); + EXPECT_EQ(r->rhs, rhs); + EXPECT_EQ(r->op, BinaryOp::kEqual); } TEST_F(BinaryExpressionTest, Creation_WithSource) { @@ -37,7 +37,7 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) { auto* r = create(Source{Source::Location{20, 2}}, BinaryOp::kEqual, lhs, rhs); - auto src = r->source(); + auto src = r->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/binding_decoration.cc b/src/ast/binding_decoration.cc index 3dbce49e01..1cdc219a8c 100644 --- a/src/ast/binding_decoration.cc +++ b/src/ast/binding_decoration.cc @@ -23,21 +23,21 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BindingDecoration); namespace tint { namespace ast { -BindingDecoration::BindingDecoration(ProgramID program_id, - const Source& source, +BindingDecoration::BindingDecoration(ProgramID pid, + const Source& src, uint32_t val) - : Base(program_id, source), value_(val) {} + : Base(pid, src), value(val) {} BindingDecoration::~BindingDecoration() = default; -std::string BindingDecoration::name() const { +std::string BindingDecoration::Name() const { return "binding"; } BindingDecoration* BindingDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, value_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/binding_decoration.h b/src/ast/binding_decoration.h index 0bb68a97b2..d9c2c14b28 100644 --- a/src/ast/binding_decoration.h +++ b/src/ast/binding_decoration.h @@ -26,17 +26,14 @@ namespace ast { class BindingDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param value the binding value - BindingDecoration(ProgramID program_id, const Source& source, uint32_t value); + BindingDecoration(ProgramID pid, const Source& src, uint32_t value); ~BindingDecoration() override; - /// @returns the binding value - uint32_t value() const { return value_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -44,8 +41,8 @@ class BindingDecoration : public Castable { /// @return the newly cloned node BindingDecoration* Clone(CloneContext* ctx) const override; - private: - uint32_t const value_; + /// the binding value + uint32_t const value; }; } // namespace ast diff --git a/src/ast/binding_decoration_test.cc b/src/ast/binding_decoration_test.cc index 7ebf1899d9..92feb3a3b0 100644 --- a/src/ast/binding_decoration_test.cc +++ b/src/ast/binding_decoration_test.cc @@ -23,7 +23,7 @@ using BindingDecorationTest = TestHelper; TEST_F(BindingDecorationTest, Creation) { auto* d = create(2); - EXPECT_EQ(2u, d->value()); + EXPECT_EQ(2u, d->value); } } // namespace diff --git a/src/ast/bitcast_expression.cc b/src/ast/bitcast_expression.cc index 268a51f177..e58b5e5061 100644 --- a/src/ast/bitcast_expression.cc +++ b/src/ast/bitcast_expression.cc @@ -21,13 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BitcastExpression); namespace tint { namespace ast { -BitcastExpression::BitcastExpression(ProgramID program_id, - const Source& source, - ast::Type* type, - Expression* expr) - : Base(program_id, source), type_(type), expr_(expr) { - TINT_ASSERT(AST, type_); - TINT_ASSERT(AST, expr_); +BitcastExpression::BitcastExpression(ProgramID pid, + const Source& src, + ast::Type* t, + Expression* e) + : Base(pid, src), type(t), expr(e) { + TINT_ASSERT(AST, type); + TINT_ASSERT(AST, expr); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id); } @@ -36,10 +36,10 @@ BitcastExpression::~BitcastExpression() = default; BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ty = ctx->Clone(type()); - auto* e = ctx->Clone(expr_); - return ctx->dst->create(src, ty, e); + auto src = ctx->Clone(source); + auto* t = ctx->Clone(type); + auto* e = ctx->Clone(expr); + return ctx->dst->create(src, t, e); } } // namespace ast diff --git a/src/ast/bitcast_expression.h b/src/ast/bitcast_expression.h index 413e64d5a9..6a0a60a24e 100644 --- a/src/ast/bitcast_expression.h +++ b/src/ast/bitcast_expression.h @@ -39,22 +39,19 @@ class BitcastExpression : public Castable { BitcastExpression(BitcastExpression&&); ~BitcastExpression() override; - /// @returns the left side expression - ast::Type* type() const { return type_; } - /// @returns the expression - Expression* expr() const { return expr_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node BitcastExpression* Clone(CloneContext* ctx) const override; + /// the target cast type + ast::Type* const type; + /// the expression + Expression* const expr; + private: BitcastExpression(const BitcastExpression&) = delete; - - ast::Type* const type_; - Expression* const expr_; }; } // namespace ast diff --git a/src/ast/bitcast_expression_test.cc b/src/ast/bitcast_expression_test.cc index 3af6a75c57..df0015f7e9 100644 --- a/src/ast/bitcast_expression_test.cc +++ b/src/ast/bitcast_expression_test.cc @@ -27,8 +27,8 @@ TEST_F(BitcastExpressionTest, Create) { auto* expr = Expr("expr"); auto* exp = create(ty.f32(), expr); - EXPECT_TRUE(exp->type()->Is()); - ASSERT_EQ(exp->expr(), expr); + EXPECT_TRUE(exp->type->Is()); + ASSERT_EQ(exp->expr, expr); } TEST_F(BitcastExpressionTest, CreateWithSource) { @@ -36,7 +36,7 @@ TEST_F(BitcastExpressionTest, CreateWithSource) { auto* exp = create(Source{Source::Location{20, 2}}, ty.f32(), expr); - auto src = exp->source(); + auto src = exp->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/block_statement.cc b/src/ast/block_statement.cc index 01190f4b0d..b0642f4f7b 100644 --- a/src/ast/block_statement.cc +++ b/src/ast/block_statement.cc @@ -21,11 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BlockStatement); namespace tint { namespace ast { -BlockStatement::BlockStatement(ProgramID program_id, - const Source& source, - const StatementList& statements) - : Base(program_id, source), statements_(std::move(statements)) { - for (auto* stmt : *this) { +BlockStatement::BlockStatement(ProgramID pid, + const Source& src, + const StatementList& stmts) + : Base(pid, src), statements(std::move(stmts)) { + for (auto* stmt : statements) { TINT_ASSERT(AST, stmt); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, stmt, program_id); } @@ -37,8 +37,8 @@ BlockStatement::~BlockStatement() = default; BlockStatement* BlockStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto stmts = ctx->Clone(statements_); + auto src = ctx->Clone(source); + auto stmts = ctx->Clone(statements); return ctx->dst->create(src, stmts); } diff --git a/src/ast/block_statement.h b/src/ast/block_statement.h index dad28587c8..f37db9eca5 100644 --- a/src/ast/block_statement.h +++ b/src/ast/block_statement.h @@ -36,40 +36,13 @@ class BlockStatement : public Castable { BlockStatement(BlockStatement&&); ~BlockStatement() override; - /// @returns the StatementList - const StatementList& list() const { return statements_; } - - /// @returns true if the block is empty - bool empty() const { return statements_.empty(); } - /// @returns the number of statements directly in the block - size_t size() const { return statements_.size(); } + /// @returns true if the block has no statements + bool Empty() const { return statements.empty(); } /// @returns the last statement in the block or nullptr if block empty - const Statement* last() const { - return statements_.empty() ? nullptr : statements_.back(); + Statement* Last() const { + return statements.empty() ? nullptr : statements.back(); } - /// @returns the last statement in the block or nullptr if block empty - Statement* last() { - return statements_.empty() ? nullptr : statements_.back(); - } - - /// Retrieves the statement at `idx` - /// @param idx the index. The index is not bounds checked. - /// @returns the statement at `idx` - Statement* get(size_t idx) const { return statements_[idx]; } - - /// Retrieves the statement at `idx` - /// @param idx the index. The index is not bounds checked. - /// @returns the statement at `idx` - Statement* operator[](size_t idx) const { return statements_[idx]; } - - /// @returns the beginning iterator - StatementList::const_iterator begin() const { return statements_.begin(); } - /// @returns the ending iterator - StatementList::const_iterator end() const { return statements_.end(); } - - /// @returns the statement list - const StatementList& statements() const { return statements_; } /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -77,10 +50,11 @@ class BlockStatement : public Castable { /// @return the newly cloned node BlockStatement* Clone(CloneContext* ctx) const override; + /// the statement list + StatementList const statements; + private: BlockStatement(const BlockStatement&) = delete; - - StatementList const statements_; }; } // namespace ast diff --git a/src/ast/block_statement_test.cc b/src/ast/block_statement_test.cc index 031523a913..70f44d5473 100644 --- a/src/ast/block_statement_test.cc +++ b/src/ast/block_statement_test.cc @@ -29,14 +29,14 @@ TEST_F(BlockStatementTest, Creation) { auto* b = create(StatementList{d}); - ASSERT_EQ(b->size(), 1u); - EXPECT_EQ((*b)[0], ptr); + ASSERT_EQ(b->statements.size(), 1u); + EXPECT_EQ(b->statements[0], ptr); } TEST_F(BlockStatementTest, Creation_WithSource) { auto* b = create(Source{Source::Location{20, 2}}, ast::StatementList{}); - auto src = b->source(); + auto src = b->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/bool.cc b/src/ast/bool.cc index 5ca1cdb9a3..f7caf9b67d 100644 --- a/src/ast/bool.cc +++ b/src/ast/bool.cc @@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Bool); namespace tint { namespace ast { -Bool::Bool(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +Bool::Bool(ProgramID pid, const Source& src) : Base(pid, src) {} Bool::Bool(Bool&&) = default; @@ -33,7 +32,7 @@ std::string Bool::FriendlyName(const SymbolTable&) const { } Bool* Bool::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/bool.h b/src/ast/bool.h index 803131970f..d3d87021cf 100644 --- a/src/ast/bool.h +++ b/src/ast/bool.h @@ -32,9 +32,9 @@ namespace ast { class Bool : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node - Bool(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + Bool(ProgramID pid, const Source& src); /// Move constructor Bool(Bool&&); ~Bool() override; diff --git a/src/ast/bool_literal.cc b/src/ast/bool_literal.cc index 5c7554a843..e6f256e18d 100644 --- a/src/ast/bool_literal.cc +++ b/src/ast/bool_literal.cc @@ -21,19 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BoolLiteral); namespace tint { namespace ast { -BoolLiteral::BoolLiteral(ProgramID program_id, const Source& source, bool value) - : Base(program_id, source), value_(value) {} +BoolLiteral::BoolLiteral(ProgramID pid, const Source& src, bool val) + : Base(pid, src), value(val) {} BoolLiteral::~BoolLiteral() = default; -std::string BoolLiteral::name() const { - return value_ ? "__bool_true" : "__bool_false"; -} - BoolLiteral* BoolLiteral::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, value_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/bool_literal.h b/src/ast/bool_literal.h index b728276b2e..da5f571c89 100644 --- a/src/ast/bool_literal.h +++ b/src/ast/bool_literal.h @@ -26,19 +26,12 @@ namespace ast { class BoolLiteral : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the input source + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param value the bool literals value - BoolLiteral(ProgramID program_id, const Source& source, bool value); + BoolLiteral(ProgramID pid, const Source& src, bool value); ~BoolLiteral() override; - /// @returns true if the bool literal is true - bool IsTrue() const { return value_; } - /// @returns true if the bool literal is false - bool IsFalse() const { return !value_; } - - /// @returns the name for this literal. This name is unique to this value. - std::string name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -46,8 +39,8 @@ class BoolLiteral : public Castable { /// @return the newly cloned node BoolLiteral* Clone(CloneContext* ctx) const override; - private: - bool const value_; + /// The boolean literal value + bool const value; }; } // namespace ast diff --git a/src/ast/bool_literal_test.cc b/src/ast/bool_literal_test.cc index d36671a26d..67d306ee35 100644 --- a/src/ast/bool_literal_test.cc +++ b/src/ast/bool_literal_test.cc @@ -23,15 +23,13 @@ using BoolLiteralTest = TestHelper; TEST_F(BoolLiteralTest, True) { auto* b = create(true); ASSERT_TRUE(b->Is()); - ASSERT_TRUE(b->IsTrue()); - ASSERT_FALSE(b->IsFalse()); + ASSERT_TRUE(b->value); } TEST_F(BoolLiteralTest, False) { auto* b = create(false); ASSERT_TRUE(b->Is()); - ASSERT_FALSE(b->IsTrue()); - ASSERT_TRUE(b->IsFalse()); + ASSERT_FALSE(b->value); } } // namespace diff --git a/src/ast/break_statement.cc b/src/ast/break_statement.cc index 154bc32a33..8bdde65279 100644 --- a/src/ast/break_statement.cc +++ b/src/ast/break_statement.cc @@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BreakStatement); namespace tint { namespace ast { -BreakStatement::BreakStatement(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +BreakStatement::BreakStatement(ProgramID pid, const Source& src) + : Base(pid, src) {} BreakStatement::BreakStatement(BreakStatement&&) = default; @@ -30,7 +30,7 @@ BreakStatement::~BreakStatement() = default; BreakStatement* BreakStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/break_statement.h b/src/ast/break_statement.h index 67a20d0544..2bc74f956c 100644 --- a/src/ast/break_statement.h +++ b/src/ast/break_statement.h @@ -24,9 +24,9 @@ namespace ast { class BreakStatement : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the break statement source - BreakStatement(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + BreakStatement(ProgramID pid, const Source& src); /// Move constructor BreakStatement(BreakStatement&&); ~BreakStatement() override; diff --git a/src/ast/break_statement_test.cc b/src/ast/break_statement_test.cc index 10d8e8e464..ed56b7b8aa 100644 --- a/src/ast/break_statement_test.cc +++ b/src/ast/break_statement_test.cc @@ -24,7 +24,7 @@ using BreakStatementTest = TestHelper; TEST_F(BreakStatementTest, Creation_WithSource) { auto* stmt = create(Source{Source::Location{20, 2}}); - auto src = stmt->source(); + auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/builtin_decoration.cc b/src/ast/builtin_decoration.cc index c891493c67..db3dfe4e81 100644 --- a/src/ast/builtin_decoration.cc +++ b/src/ast/builtin_decoration.cc @@ -23,21 +23,21 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BuiltinDecoration); namespace tint { namespace ast { -BuiltinDecoration::BuiltinDecoration(ProgramID program_id, - const Source& source, - Builtin builtin) - : Base(program_id, source), builtin_(builtin) {} +BuiltinDecoration::BuiltinDecoration(ProgramID pid, + const Source& src, + Builtin b) + : Base(pid, src), builtin(b) {} BuiltinDecoration::~BuiltinDecoration() = default; -std::string BuiltinDecoration::name() const { +std::string BuiltinDecoration::Name() const { return "builtin"; } BuiltinDecoration* BuiltinDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, builtin_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, builtin); } } // namespace ast diff --git a/src/ast/builtin_decoration.h b/src/ast/builtin_decoration.h index cfb201c37c..d31210337a 100644 --- a/src/ast/builtin_decoration.h +++ b/src/ast/builtin_decoration.h @@ -27,19 +27,14 @@ namespace ast { class BuiltinDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param builtin the builtin value - BuiltinDecoration(ProgramID program_id, - const Source& source, - Builtin builtin); + BuiltinDecoration(ProgramID pid, const Source& src, Builtin builtin); ~BuiltinDecoration() override; - /// @returns the builtin value - Builtin value() const { return builtin_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -47,8 +42,8 @@ class BuiltinDecoration : public Castable { /// @return the newly cloned node BuiltinDecoration* Clone(CloneContext* ctx) const override; - private: - Builtin const builtin_; + /// The builtin value + Builtin const builtin; }; } // namespace ast diff --git a/src/ast/builtin_decoration_test.cc b/src/ast/builtin_decoration_test.cc index e42999d87f..4efafaeb2e 100644 --- a/src/ast/builtin_decoration_test.cc +++ b/src/ast/builtin_decoration_test.cc @@ -23,7 +23,7 @@ using BuiltinDecorationTest = TestHelper; TEST_F(BuiltinDecorationTest, Creation) { auto* d = create(Builtin::kFragDepth); - EXPECT_EQ(Builtin::kFragDepth, d->value()); + EXPECT_EQ(Builtin::kFragDepth, d->builtin); } } // namespace diff --git a/src/ast/call_expression.cc b/src/ast/call_expression.cc index 7cd0f2a24a..43e7a44c60 100644 --- a/src/ast/call_expression.cc +++ b/src/ast/call_expression.cc @@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CallExpression); namespace tint { namespace ast { -CallExpression::CallExpression(ProgramID program_id, - const Source& source, - IdentifierExpression* func, - ExpressionList args) - : Base(program_id, source), func_(func), args_(args) { - TINT_ASSERT(AST, func_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func_, program_id); - for (auto* arg : args_) { +CallExpression::CallExpression(ProgramID pid, + const Source& src, + IdentifierExpression* fn, + ExpressionList a) + : Base(pid, src), func(fn), args(a) { + TINT_ASSERT(AST, func); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id); + for (auto* arg : args) { TINT_ASSERT(AST, arg); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, arg, program_id); } @@ -40,9 +40,9 @@ CallExpression::~CallExpression() = default; CallExpression* CallExpression::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* fn = ctx->Clone(func_); - auto p = ctx->Clone(args_); + auto src = ctx->Clone(source); + auto* fn = ctx->Clone(func); + auto p = ctx->Clone(args); return ctx->dst->create(src, fn, p); } diff --git a/src/ast/call_expression.h b/src/ast/call_expression.h index fef115ab9e..7cf625ef53 100644 --- a/src/ast/call_expression.h +++ b/src/ast/call_expression.h @@ -39,22 +39,19 @@ class CallExpression : public Castable { CallExpression(CallExpression&&); ~CallExpression() override; - /// @returns the func - IdentifierExpression* func() const { return func_; } - /// @returns the arguments - const ExpressionList& args() const { return args_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node CallExpression* Clone(CloneContext* ctx) const override; + /// The target function + IdentifierExpression* const func; + /// The arguments + ExpressionList const args; + private: CallExpression(const CallExpression&) = delete; - - IdentifierExpression* const func_; - ExpressionList const args_; }; } // namespace ast diff --git a/src/ast/call_expression_test.cc b/src/ast/call_expression_test.cc index b36c39a4c9..af250c0cf3 100644 --- a/src/ast/call_expression_test.cc +++ b/src/ast/call_expression_test.cc @@ -28,9 +28,9 @@ TEST_F(CallExpressionTest, Creation) { params.push_back(Expr("param2")); auto* stmt = create(func, params); - EXPECT_EQ(stmt->func(), func); + EXPECT_EQ(stmt->func, func); - const auto& vec = stmt->args(); + const auto& vec = stmt->args; ASSERT_EQ(vec.size(), 2u); EXPECT_EQ(vec[0], params[0]); EXPECT_EQ(vec[1], params[1]); @@ -40,7 +40,7 @@ TEST_F(CallExpressionTest, Creation_WithSource) { auto* func = Expr("func"); auto* stmt = create(Source{Source::Location{20, 2}}, func, ExpressionList{}); - auto src = stmt->source(); + auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/call_statement.cc b/src/ast/call_statement.cc index c0ac3add54..540f2addd1 100644 --- a/src/ast/call_statement.cc +++ b/src/ast/call_statement.cc @@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CallStatement); namespace tint { namespace ast { -CallStatement::CallStatement(ProgramID program_id, - const Source& source, +CallStatement::CallStatement(ProgramID pid, + const Source& src, CallExpression* call) - : Base(program_id, source), call_(call) { - TINT_ASSERT(AST, call_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, call_, program_id); + : Base(pid, src), expr(call) { + TINT_ASSERT(AST, expr); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id); } CallStatement::CallStatement(CallStatement&&) = default; @@ -35,8 +35,8 @@ CallStatement::~CallStatement() = default; CallStatement* CallStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* call = ctx->Clone(call_); + auto src = ctx->Clone(source); + auto* call = ctx->Clone(expr); return ctx->dst->create(src, call); } diff --git a/src/ast/call_statement.h b/src/ast/call_statement.h index e389503e57..2eb5aa33de 100644 --- a/src/ast/call_statement.h +++ b/src/ast/call_statement.h @@ -25,29 +25,25 @@ namespace ast { class CallStatement : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the input source for the statement + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node for the statement /// @param call the function - CallStatement(ProgramID program_id, - const Source& source, - CallExpression* call); + CallStatement(ProgramID pid, const Source& src, CallExpression* call); /// Move constructor CallStatement(CallStatement&&); ~CallStatement() override; - /// @returns the call expression - CallExpression* expr() const { return call_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node CallStatement* Clone(CloneContext* ctx) const override; + /// The call expression + CallExpression* const expr; + private: CallStatement(const CallStatement&) = delete; - - CallExpression* const call_; }; } // namespace ast diff --git a/src/ast/call_statement_test.cc b/src/ast/call_statement_test.cc index 3bff4cf84f..b5bd7e95b4 100644 --- a/src/ast/call_statement_test.cc +++ b/src/ast/call_statement_test.cc @@ -27,7 +27,7 @@ TEST_F(CallStatementTest, Creation) { auto* expr = create(Expr("func"), ExpressionList{}); auto* c = create(expr); - EXPECT_EQ(c->expr(), expr); + EXPECT_EQ(c->expr, expr); } TEST_F(CallStatementTest, IsCall) { diff --git a/src/ast/case_statement.cc b/src/ast/case_statement.cc index 82406dfa59..71fe7f98c6 100644 --- a/src/ast/case_statement.cc +++ b/src/ast/case_statement.cc @@ -21,13 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CaseStatement); namespace tint { namespace ast { -CaseStatement::CaseStatement(ProgramID program_id, - const Source& source, - CaseSelectorList selectors, - BlockStatement* body) - : Base(program_id, source), selectors_(selectors), body_(body) { - TINT_ASSERT(AST, body_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id); +CaseStatement::CaseStatement(ProgramID pid, + const Source& src, + CaseSelectorList s, + BlockStatement* b) + : Base(pid, src), selectors(s), body(b) { + TINT_ASSERT(AST, body); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); for (auto* selector : selectors) { TINT_ASSERT(AST, selector); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, selector, program_id); @@ -40,9 +40,9 @@ CaseStatement::~CaseStatement() = default; CaseStatement* CaseStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto sel = ctx->Clone(selectors_); - auto* b = ctx->Clone(body_); + auto src = ctx->Clone(source); + auto sel = ctx->Clone(selectors); + auto* b = ctx->Clone(body); return ctx->dst->create(src, sel, b); } diff --git a/src/ast/case_statement.h b/src/ast/case_statement.h index ebf3e9a6b7..eb74d59d07 100644 --- a/src/ast/case_statement.h +++ b/src/ast/case_statement.h @@ -30,27 +30,20 @@ using CaseSelectorList = std::vector; class CaseStatement : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source information + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param selectors the case selectors /// @param body the case body - CaseStatement(ProgramID program_id, - const Source& source, + CaseStatement(ProgramID pid, + const Source& src, CaseSelectorList selectors, BlockStatement* body); /// Move constructor CaseStatement(CaseStatement&&); ~CaseStatement() override; - /// @returns the case selectors, empty if none set - const CaseSelectorList& selectors() const { return selectors_; } /// @returns true if this is a default statement - bool IsDefault() const { return selectors_.empty(); } - - /// @returns the case body - const BlockStatement* body() const { return body_; } - /// @returns the case body - BlockStatement* body() { return body_; } + bool IsDefault() const { return selectors.empty(); } /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -58,11 +51,14 @@ class CaseStatement : public Castable { /// @return the newly cloned node CaseStatement* Clone(CloneContext* ctx) const override; + /// The case selectors, empty if none set + CaseSelectorList const selectors; + + /// The case body + BlockStatement* const body; + private: CaseStatement(const CaseStatement&) = delete; - - CaseSelectorList const selectors_; - BlockStatement* const body_; }; /// A list of case statements diff --git a/src/ast/case_statement_test.cc b/src/ast/case_statement_test.cc index aeb90972a3..7fc92ec187 100644 --- a/src/ast/case_statement_test.cc +++ b/src/ast/case_statement_test.cc @@ -34,10 +34,10 @@ TEST_F(CaseStatementTest, Creation_i32) { auto* body = create(StatementList{discard}); auto* c = create(b, body); - ASSERT_EQ(c->selectors().size(), 1u); - EXPECT_EQ(c->selectors()[0], selector); - ASSERT_EQ(c->body()->size(), 1u); - EXPECT_EQ(c->body()->get(0), discard); + ASSERT_EQ(c->selectors.size(), 1u); + EXPECT_EQ(c->selectors[0], selector); + ASSERT_EQ(c->body->statements.size(), 1u); + EXPECT_EQ(c->body->statements[0], discard); } TEST_F(CaseStatementTest, Creation_u32) { @@ -49,10 +49,10 @@ TEST_F(CaseStatementTest, Creation_u32) { auto* body = create(StatementList{discard}); auto* c = create(b, body); - ASSERT_EQ(c->selectors().size(), 1u); - EXPECT_EQ(c->selectors()[0], selector); - ASSERT_EQ(c->body()->size(), 1u); - EXPECT_EQ(c->body()->get(0), discard); + ASSERT_EQ(c->selectors.size(), 1u); + EXPECT_EQ(c->selectors[0], selector); + ASSERT_EQ(c->body->statements.size(), 1u); + EXPECT_EQ(c->body->statements[0], discard); } TEST_F(CaseStatementTest, Creation_WithSource) { @@ -63,7 +63,7 @@ TEST_F(CaseStatementTest, Creation_WithSource) { create(), }); auto* c = create(Source{Source::Location{20, 2}}, b, body); - auto src = c->source(); + auto src = c->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/constructor_expression.cc b/src/ast/constructor_expression.cc index c8d4ea269c..e1a8224b68 100644 --- a/src/ast/constructor_expression.cc +++ b/src/ast/constructor_expression.cc @@ -23,9 +23,8 @@ ConstructorExpression::~ConstructorExpression() = default; ConstructorExpression::ConstructorExpression(ConstructorExpression&&) = default; -ConstructorExpression::ConstructorExpression(ProgramID program_id, - const Source& source) - : Base(program_id, source) {} +ConstructorExpression::ConstructorExpression(ProgramID pid, const Source& src) + : Base(pid, src) {} } // namespace ast } // namespace tint diff --git a/src/ast/constructor_expression.h b/src/ast/constructor_expression.h index ce761bae60..93a19fd881 100644 --- a/src/ast/constructor_expression.h +++ b/src/ast/constructor_expression.h @@ -28,9 +28,9 @@ class ConstructorExpression protected: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the constructor source - ConstructorExpression(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + ConstructorExpression(ProgramID pid, const Source& src); /// Move constructor ConstructorExpression(ConstructorExpression&&); diff --git a/src/ast/continue_statement.cc b/src/ast/continue_statement.cc index a07572fe2f..222f7f5ff8 100644 --- a/src/ast/continue_statement.cc +++ b/src/ast/continue_statement.cc @@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ContinueStatement); namespace tint { namespace ast { -ContinueStatement::ContinueStatement(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +ContinueStatement::ContinueStatement(ProgramID pid, const Source& src) + : Base(pid, src) {} ContinueStatement::ContinueStatement(ContinueStatement&&) = default; @@ -30,7 +30,7 @@ ContinueStatement::~ContinueStatement() = default; ContinueStatement* ContinueStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/continue_statement.h b/src/ast/continue_statement.h index a618637e8a..eaf799d8d1 100644 --- a/src/ast/continue_statement.h +++ b/src/ast/continue_statement.h @@ -24,9 +24,9 @@ namespace ast { class ContinueStatement : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the continue statement source - ContinueStatement(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + ContinueStatement(ProgramID pid, const Source& src); /// Move constructor ContinueStatement(ContinueStatement&&); ~ContinueStatement() override; diff --git a/src/ast/continue_statement_test.cc b/src/ast/continue_statement_test.cc index addad15feb..1d3b490993 100644 --- a/src/ast/continue_statement_test.cc +++ b/src/ast/continue_statement_test.cc @@ -24,7 +24,7 @@ using ContinueStatementTest = TestHelper; TEST_F(ContinueStatementTest, Creation_WithSource) { auto* stmt = create(Source{Source::Location{20, 2}}); - auto src = stmt->source(); + auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/decoration.h b/src/ast/decoration.h index 0b2912e2ba..d915de3fad 100644 --- a/src/ast/decoration.h +++ b/src/ast/decoration.h @@ -29,14 +29,13 @@ class Decoration : public Castable { ~Decoration() override; /// @returns the WGSL name for the decoration - virtual std::string name() const = 0; + virtual std::string Name() const = 0; protected: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration - Decoration(ProgramID program_id, const Source& source) - : Base(program_id, source) {} + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + Decoration(ProgramID pid, const Source& src) : Base(pid, src) {} }; /// A list of decorations diff --git a/src/ast/depth_multisampled_texture.cc b/src/ast/depth_multisampled_texture.cc index b822195447..5985fee1ba 100644 --- a/src/ast/depth_multisampled_texture.cc +++ b/src/ast/depth_multisampled_texture.cc @@ -28,10 +28,10 @@ bool IsValidDepthDimension(TextureDimension dim) { } // namespace -DepthMultisampledTexture::DepthMultisampledTexture(ProgramID program_id, - const Source& source, - TextureDimension dim) - : Base(program_id, source, dim) { +DepthMultisampledTexture::DepthMultisampledTexture(ProgramID pid, + const Source& src, + TextureDimension d) + : Base(pid, src, d) { TINT_ASSERT(AST, IsValidDepthDimension(dim)); } @@ -42,14 +42,14 @@ DepthMultisampledTexture::~DepthMultisampledTexture() = default; std::string DepthMultisampledTexture::FriendlyName(const SymbolTable&) const { std::ostringstream out; - out << "texture_depth_multisampled_" << dim(); + out << "texture_depth_multisampled_" << dim; return out.str(); } DepthMultisampledTexture* DepthMultisampledTexture::Clone( CloneContext* ctx) const { - auto src = ctx->Clone(source()); - return ctx->dst->create(src, dim()); + auto src = ctx->Clone(source); + return ctx->dst->create(src, dim); } } // namespace ast diff --git a/src/ast/depth_multisampled_texture.h b/src/ast/depth_multisampled_texture.h index 4f23933219..c274d937ac 100644 --- a/src/ast/depth_multisampled_texture.h +++ b/src/ast/depth_multisampled_texture.h @@ -27,11 +27,11 @@ class DepthMultisampledTexture : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param dim the dimensionality of the texture - DepthMultisampledTexture(ProgramID program_id, - const Source& source, + DepthMultisampledTexture(ProgramID pid, + const Source& src, TextureDimension dim); /// Move constructor DepthMultisampledTexture(DepthMultisampledTexture&&); diff --git a/src/ast/depth_multisampled_texture_test.cc b/src/ast/depth_multisampled_texture_test.cc index 7c1ce0fcf0..b75d2a6eb5 100644 --- a/src/ast/depth_multisampled_texture_test.cc +++ b/src/ast/depth_multisampled_texture_test.cc @@ -24,7 +24,7 @@ using AstDepthMultisampledTextureTest = TestHelper; TEST_F(AstDepthMultisampledTextureTest, Dim) { auto* d = create(TextureDimension::k2d); - EXPECT_EQ(d->dim(), TextureDimension::k2d); + EXPECT_EQ(d->dim, TextureDimension::k2d); } TEST_F(AstDepthMultisampledTextureTest, FriendlyName) { diff --git a/src/ast/depth_texture.cc b/src/ast/depth_texture.cc index 8cad4ba843..39f576c6c5 100644 --- a/src/ast/depth_texture.cc +++ b/src/ast/depth_texture.cc @@ -29,10 +29,8 @@ bool IsValidDepthDimension(TextureDimension dim) { } // namespace -DepthTexture::DepthTexture(ProgramID program_id, - const Source& source, - TextureDimension dim) - : Base(program_id, source, dim) { +DepthTexture::DepthTexture(ProgramID pid, const Source& src, TextureDimension d) + : Base(pid, src, d) { TINT_ASSERT(AST, IsValidDepthDimension(dim)); } @@ -42,13 +40,13 @@ DepthTexture::~DepthTexture() = default; std::string DepthTexture::FriendlyName(const SymbolTable&) const { std::ostringstream out; - out << "texture_depth_" << dim(); + out << "texture_depth_" << dim; return out.str(); } DepthTexture* DepthTexture::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source()); - return ctx->dst->create(src, dim()); + auto src = ctx->Clone(source); + return ctx->dst->create(src, dim); } } // namespace ast diff --git a/src/ast/depth_texture.h b/src/ast/depth_texture.h index e0ff248c1f..f2e1e10271 100644 --- a/src/ast/depth_texture.h +++ b/src/ast/depth_texture.h @@ -26,12 +26,10 @@ namespace ast { class DepthTexture : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param dim the dimensionality of the texture - DepthTexture(ProgramID program_id, - const Source& source, - TextureDimension dim); + DepthTexture(ProgramID pid, const Source& src, TextureDimension dim); /// Move constructor DepthTexture(DepthTexture&&); ~DepthTexture() override; diff --git a/src/ast/depth_texture_test.cc b/src/ast/depth_texture_test.cc index 9e760d9e6a..2a0ec2b7fd 100644 --- a/src/ast/depth_texture_test.cc +++ b/src/ast/depth_texture_test.cc @@ -31,7 +31,7 @@ TEST_F(AstDepthTextureTest, IsTexture) { TEST_F(AstDepthTextureTest, Dim) { auto* d = create(TextureDimension::kCube); - EXPECT_EQ(d->dim(), TextureDimension::kCube); + EXPECT_EQ(d->dim, TextureDimension::kCube); } TEST_F(AstDepthTextureTest, FriendlyName) { diff --git a/src/ast/disable_validation_decoration.cc b/src/ast/disable_validation_decoration.cc index 8708cec73f..69c4605d39 100644 --- a/src/ast/disable_validation_decoration.cc +++ b/src/ast/disable_validation_decoration.cc @@ -21,15 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::DisableValidationDecoration); namespace tint { namespace ast { -DisableValidationDecoration::DisableValidationDecoration( - ProgramID program_id, - DisabledValidation validation) - : Base(program_id), validation_(validation) {} +DisableValidationDecoration::DisableValidationDecoration(ProgramID pid, + DisabledValidation val) + : Base(pid), validation(val) {} DisableValidationDecoration::~DisableValidationDecoration() = default; std::string DisableValidationDecoration::InternalName() const { - switch (validation_) { + switch (validation) { case DisabledValidation::kFunctionHasNoBody: return "disable_validation__function_has_no_body"; case DisabledValidation::kBindingPointCollision: @@ -51,7 +50,7 @@ std::string DisableValidationDecoration::InternalName() const { DisableValidationDecoration* DisableValidationDecoration::Clone( CloneContext* ctx) const { return ctx->dst->ASTNodes().Create( - ctx->dst->ID(), validation_); + ctx->dst->ID(), validation); } } // namespace ast diff --git a/src/ast/disable_validation_decoration.h b/src/ast/disable_validation_decoration.h index 5e8213fcbc..2d0fd8927e 100644 --- a/src/ast/disable_validation_decoration.h +++ b/src/ast/disable_validation_decoration.h @@ -64,9 +64,6 @@ class DisableValidationDecoration /// Destructor ~DisableValidationDecoration() override; - /// @return the validation that this decoration disables - DisabledValidation Validation() const { return validation_; } - /// @return a short description of the internal decoration which will be /// displayed in WGSL as `[[internal()]]` (but is not parsable). std::string InternalName() const override; @@ -76,8 +73,8 @@ class DisableValidationDecoration /// @return the newly cloned object DisableValidationDecoration* Clone(CloneContext* ctx) const override; - private: - DisabledValidation const validation_; + /// The validation that this decoration disables + DisabledValidation const validation; }; } // namespace ast diff --git a/src/ast/discard_statement.cc b/src/ast/discard_statement.cc index 129cc56e3f..fbc5d28960 100644 --- a/src/ast/discard_statement.cc +++ b/src/ast/discard_statement.cc @@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::DiscardStatement); namespace tint { namespace ast { -DiscardStatement::DiscardStatement(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +DiscardStatement::DiscardStatement(ProgramID pid, const Source& src) + : Base(pid, src) {} DiscardStatement::DiscardStatement(DiscardStatement&&) = default; @@ -30,7 +30,7 @@ DiscardStatement::~DiscardStatement() = default; DiscardStatement* DiscardStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/discard_statement.h b/src/ast/discard_statement.h index 0a363c8dfa..2159323461 100644 --- a/src/ast/discard_statement.h +++ b/src/ast/discard_statement.h @@ -24,9 +24,9 @@ namespace ast { class DiscardStatement : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the discard statement source - DiscardStatement(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + DiscardStatement(ProgramID pid, const Source& src); /// Move constructor DiscardStatement(DiscardStatement&&); ~DiscardStatement() override; diff --git a/src/ast/discard_statement_test.cc b/src/ast/discard_statement_test.cc index 97b459e0e7..b83e69b269 100644 --- a/src/ast/discard_statement_test.cc +++ b/src/ast/discard_statement_test.cc @@ -24,19 +24,19 @@ using DiscardStatementTest = TestHelper; TEST_F(DiscardStatementTest, Creation) { auto* stmt = create(); - EXPECT_EQ(stmt->source().range.begin.line, 0u); - EXPECT_EQ(stmt->source().range.begin.column, 0u); - EXPECT_EQ(stmt->source().range.end.line, 0u); - EXPECT_EQ(stmt->source().range.end.column, 0u); + EXPECT_EQ(stmt->source.range.begin.line, 0u); + EXPECT_EQ(stmt->source.range.begin.column, 0u); + EXPECT_EQ(stmt->source.range.end.line, 0u); + EXPECT_EQ(stmt->source.range.end.column, 0u); } TEST_F(DiscardStatementTest, Creation_WithSource) { auto* stmt = create( Source{Source::Range{Source::Location{20, 2}, Source::Location{20, 5}}}); - EXPECT_EQ(stmt->source().range.begin.line, 20u); - EXPECT_EQ(stmt->source().range.begin.column, 2u); - EXPECT_EQ(stmt->source().range.end.line, 20u); - EXPECT_EQ(stmt->source().range.end.column, 5u); + EXPECT_EQ(stmt->source.range.begin.line, 20u); + EXPECT_EQ(stmt->source.range.begin.column, 2u); + EXPECT_EQ(stmt->source.range.end.line, 20u); + EXPECT_EQ(stmt->source.range.end.column, 5u); } TEST_F(DiscardStatementTest, IsDiscard) { diff --git a/src/ast/else_statement.cc b/src/ast/else_statement.cc index ed88bbd745..8c3bd59ac7 100644 --- a/src/ast/else_statement.cc +++ b/src/ast/else_statement.cc @@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ElseStatement); namespace tint { namespace ast { -ElseStatement::ElseStatement(ProgramID program_id, - const Source& source, - Expression* condition, - BlockStatement* body) - : Base(program_id, source), condition_(condition), body_(body) { - TINT_ASSERT(AST, body_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition_, program_id); +ElseStatement::ElseStatement(ProgramID pid, + const Source& src, + Expression* cond, + BlockStatement* b) + : Base(pid, src), condition(cond), body(b) { + TINT_ASSERT(AST, body); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id); } ElseStatement::ElseStatement(ElseStatement&&) = default; @@ -37,9 +37,9 @@ ElseStatement::~ElseStatement() = default; ElseStatement* ElseStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* cond = ctx->Clone(condition_); - auto* b = ctx->Clone(body_); + auto src = ctx->Clone(source); + auto* cond = ctx->Clone(condition); + auto* b = ctx->Clone(body); return ctx->dst->create(src, cond, b); } diff --git a/src/ast/else_statement.h b/src/ast/else_statement.h index 26a03c5cba..5cdc344855 100644 --- a/src/ast/else_statement.h +++ b/src/ast/else_statement.h @@ -27,39 +27,32 @@ namespace ast { class ElseStatement : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source information + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param condition the else condition /// @param body the else body - ElseStatement(ProgramID program_id, - const Source& source, + ElseStatement(ProgramID pid, + const Source& src, Expression* condition, BlockStatement* body); /// Move constructor ElseStatement(ElseStatement&&); ~ElseStatement() override; - /// @returns the else condition or nullptr if none set - Expression* condition() const { return condition_; } - /// @returns true if the else has a condition - bool HasCondition() const { return condition_ != nullptr; } - - /// @returns the else body - const BlockStatement* body() const { return body_; } - /// @returns the else body - BlockStatement* body() { return body_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node ElseStatement* Clone(CloneContext* ctx) const override; + /// The else condition or nullptr if none set + Expression* const condition; + + /// The else body + BlockStatement* const body; + private: ElseStatement(const ElseStatement&) = delete; - - Expression* const condition_; - BlockStatement* const body_; }; /// A list of else statements diff --git a/src/ast/else_statement_test.cc b/src/ast/else_statement_test.cc index 5f3e69788c..11c4828ca0 100644 --- a/src/ast/else_statement_test.cc +++ b/src/ast/else_statement_test.cc @@ -28,18 +28,18 @@ TEST_F(ElseStatementTest, Creation) { auto* body = create(StatementList{ create(), }); - auto* discard = body->get(0); + auto* discard = body->statements[0]; auto* e = create(cond, body); - EXPECT_EQ(e->condition(), cond); - ASSERT_EQ(e->body()->size(), 1u); - EXPECT_EQ(e->body()->get(0), discard); + EXPECT_EQ(e->condition, cond); + ASSERT_EQ(e->body->statements.size(), 1u); + EXPECT_EQ(e->body->statements[0], discard); } TEST_F(ElseStatementTest, Creation_WithSource) { auto* e = create(Source{Source::Location{20, 2}}, Expr(true), Block()); - auto src = e->source(); + auto src = e->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } @@ -52,12 +52,12 @@ TEST_F(ElseStatementTest, IsElse) { TEST_F(ElseStatementTest, HasCondition) { auto* cond = Expr(true); auto* e = create(cond, Block()); - EXPECT_TRUE(e->HasCondition()); + EXPECT_TRUE(e->condition); } TEST_F(ElseStatementTest, HasContition_NullCondition) { auto* e = create(nullptr, Block()); - EXPECT_FALSE(e->HasCondition()); + EXPECT_FALSE(e->condition); } TEST_F(ElseStatementTest, Assert_Null_Body) { diff --git a/src/ast/expression.cc b/src/ast/expression.cc index 710e79dd59..304bc48197 100644 --- a/src/ast/expression.cc +++ b/src/ast/expression.cc @@ -22,17 +22,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Expression); namespace tint { namespace ast { -Expression::Expression(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +Expression::Expression(ProgramID pid, const Source& src) : Base(pid, src) {} Expression::Expression(Expression&&) = default; Expression::~Expression() = default; -std::string Expression::result_type_str(const sem::Info& sem) const { - auto* sem_expr = sem.Get(this); - return sem_expr ? sem_expr->Type()->type_name() : "not set"; -} - } // namespace ast } // namespace tint diff --git a/src/ast/expression.h b/src/ast/expression.h index 0db419fc26..a319f1623b 100644 --- a/src/ast/expression.h +++ b/src/ast/expression.h @@ -31,17 +31,12 @@ class Expression : public Castable { protected: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of the expression - Expression(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + Expression(ProgramID pid, const Source& src); /// Move constructor Expression(Expression&&); - /// @param sem the semantic info for the program - /// @returns a string representation of the result type or 'not set' if no - /// result type present - std::string result_type_str(const sem::Info& sem) const; - private: Expression(const Expression&) = delete; }; diff --git a/src/ast/external_texture.cc b/src/ast/external_texture.cc index 16376b6b29..cdd120c0cd 100644 --- a/src/ast/external_texture.cc +++ b/src/ast/external_texture.cc @@ -22,8 +22,8 @@ namespace tint { namespace ast { // ExternalTexture::ExternalTexture() : Base(ast::TextureDimension::k2d) {} -ExternalTexture::ExternalTexture(ProgramID program_id, const Source& source) - : Base(program_id, source, ast::TextureDimension::k2d) {} +ExternalTexture::ExternalTexture(ProgramID pid, const Source& src) + : Base(pid, src, ast::TextureDimension::k2d) {} ExternalTexture::ExternalTexture(ExternalTexture&&) = default; diff --git a/src/ast/external_texture.h b/src/ast/external_texture.h index 38d1791e49..250f466d4d 100644 --- a/src/ast/external_texture.h +++ b/src/ast/external_texture.h @@ -26,9 +26,9 @@ namespace ast { class ExternalTexture : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node - ExternalTexture(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + ExternalTexture(ProgramID pid, const Source& src); /// Move constructor ExternalTexture(ExternalTexture&&); diff --git a/src/ast/external_texture_test.cc b/src/ast/external_texture_test.cc index 7cd722095a..a9a80fbc26 100644 --- a/src/ast/external_texture_test.cc +++ b/src/ast/external_texture_test.cc @@ -33,7 +33,7 @@ TEST_F(AstExternalTextureTest, IsTexture) { TEST_F(AstExternalTextureTest, Dim) { auto* ty = create(); - EXPECT_EQ(ty->dim(), ast::TextureDimension::k2d); + EXPECT_EQ(ty->dim, ast::TextureDimension::k2d); } TEST_F(AstExternalTextureTest, FriendlyName) { diff --git a/src/ast/f32.cc b/src/ast/f32.cc index 039cf7fbd1..cc5f0d1663 100644 --- a/src/ast/f32.cc +++ b/src/ast/f32.cc @@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::F32); namespace tint { namespace ast { -F32::F32(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +F32::F32(ProgramID pid, const Source& src) : Base(pid, src) {} F32::F32(F32&&) = default; @@ -33,7 +32,7 @@ std::string F32::FriendlyName(const SymbolTable&) const { } F32* F32::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/f32.h b/src/ast/f32.h index 1e0d4c60c8..804ea55001 100644 --- a/src/ast/f32.h +++ b/src/ast/f32.h @@ -26,9 +26,9 @@ namespace ast { class F32 : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node - F32(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + F32(ProgramID pid, const Source& src); /// Move constructor F32(F32&&); ~F32() override; diff --git a/src/ast/fallthrough_statement.cc b/src/ast/fallthrough_statement.cc index 4fcc2f7c37..cac4d86080 100644 --- a/src/ast/fallthrough_statement.cc +++ b/src/ast/fallthrough_statement.cc @@ -21,9 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::FallthroughStatement); namespace tint { namespace ast { -FallthroughStatement::FallthroughStatement(ProgramID program_id, - const Source& source) - : Base(program_id, source) {} +FallthroughStatement::FallthroughStatement(ProgramID pid, const Source& src) + : Base(pid, src) {} FallthroughStatement::FallthroughStatement(FallthroughStatement&&) = default; @@ -31,7 +30,7 @@ FallthroughStatement::~FallthroughStatement() = default; FallthroughStatement* FallthroughStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/fallthrough_statement.h b/src/ast/fallthrough_statement.h index 7976b2bcdb..026a907c18 100644 --- a/src/ast/fallthrough_statement.h +++ b/src/ast/fallthrough_statement.h @@ -24,9 +24,9 @@ namespace ast { class FallthroughStatement : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source information - FallthroughStatement(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + FallthroughStatement(ProgramID pid, const Source& src); /// Move constructor FallthroughStatement(FallthroughStatement&&); ~FallthroughStatement() override; diff --git a/src/ast/fallthrough_statement_test.cc b/src/ast/fallthrough_statement_test.cc index 9081a8d2b4..95f136e16c 100644 --- a/src/ast/fallthrough_statement_test.cc +++ b/src/ast/fallthrough_statement_test.cc @@ -24,15 +24,15 @@ using FallthroughStatementTest = TestHelper; TEST_F(FallthroughStatementTest, Creation) { auto* stmt = create(); - EXPECT_EQ(stmt->source().range.begin.line, 0u); - EXPECT_EQ(stmt->source().range.begin.column, 0u); - EXPECT_EQ(stmt->source().range.end.line, 0u); - EXPECT_EQ(stmt->source().range.end.column, 0u); + EXPECT_EQ(stmt->source.range.begin.line, 0u); + EXPECT_EQ(stmt->source.range.begin.column, 0u); + EXPECT_EQ(stmt->source.range.end.line, 0u); + EXPECT_EQ(stmt->source.range.end.column, 0u); } TEST_F(FallthroughStatementTest, Creation_WithSource) { auto* stmt = create(Source{Source::Location{20, 2}}); - auto src = stmt->source(); + auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/float_literal.cc b/src/ast/float_literal.cc index 57cd430314..94bc68ecbd 100644 --- a/src/ast/float_literal.cc +++ b/src/ast/float_literal.cc @@ -23,25 +23,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::FloatLiteral); namespace tint { namespace ast { -FloatLiteral::FloatLiteral(ProgramID program_id, - const Source& source, - float value) - : Base(program_id, source), value_(value) {} +FloatLiteral::FloatLiteral(ProgramID pid, const Source& src, float val) + : Base(pid, src), value(val) {} FloatLiteral::~FloatLiteral() = default; -std::string FloatLiteral::name() const { - std::ostringstream out; - out.flags(out.flags() | std::ios_base::showpoint); - out.precision(std::numeric_limits::max_digits10); - out << "__float" << value_; - return out.str(); -} - FloatLiteral* FloatLiteral::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, value_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/float_literal.h b/src/ast/float_literal.h index 5453430c4a..990b7e4246 100644 --- a/src/ast/float_literal.h +++ b/src/ast/float_literal.h @@ -26,26 +26,20 @@ namespace ast { class FloatLiteral : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the input source + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param value the float literals value - FloatLiteral(ProgramID program_id, const Source& source, float value); + FloatLiteral(ProgramID pid, const Source& src, float value); ~FloatLiteral() override; - /// @returns the float literal value - float value() const { return value_; } - - /// @returns the name for this literal. This name is unique to this value. - std::string name() const override; - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node FloatLiteral* Clone(CloneContext* ctx) const override; - private: - float const value_; + /// The float literal value + float const value; }; } // namespace ast diff --git a/src/ast/float_literal_test.cc b/src/ast/float_literal_test.cc index a6483a73d9..a89f2ee119 100644 --- a/src/ast/float_literal_test.cc +++ b/src/ast/float_literal_test.cc @@ -23,12 +23,7 @@ using FloatLiteralTest = TestHelper; TEST_F(FloatLiteralTest, Value) { auto* f = create(47.2f); ASSERT_TRUE(f->Is()); - EXPECT_EQ(f->value(), 47.2f); -} - -TEST_F(FloatLiteralTest, ToName) { - auto* f = create(42.1f); - EXPECT_EQ(f->name(), "__float42.0999985"); + EXPECT_EQ(f->value, 47.2f); } } // namespace diff --git a/src/ast/for_loop_statement.cc b/src/ast/for_loop_statement.cc index 50d81842c2..a1eab181d5 100644 --- a/src/ast/for_loop_statement.cc +++ b/src/ast/for_loop_statement.cc @@ -21,23 +21,23 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ForLoopStatement); namespace tint { namespace ast { -ForLoopStatement::ForLoopStatement(ProgramID program_id, - const Source& source, - Statement* initializer, - Expression* condition, - Statement* continuing, - BlockStatement* body) - : Base(program_id, source), - initializer_(initializer), - condition_(condition), - continuing_(continuing), - body_(body) { - TINT_ASSERT(AST, body_); +ForLoopStatement::ForLoopStatement(ProgramID pid, + const Source& src, + Statement* init, + Expression* cond, + Statement* cont, + BlockStatement* b) + : Base(pid, src), + initializer(init), + condition(cond), + continuing(cont), + body(b) { + TINT_ASSERT(AST, body); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, initializer_, program_id); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition_, program_id); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, continuing_, program_id); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, initializer, program_id); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, continuing, program_id); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); } ForLoopStatement::ForLoopStatement(ForLoopStatement&&) = default; @@ -46,12 +46,12 @@ ForLoopStatement::~ForLoopStatement() = default; ForLoopStatement* ForLoopStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); - auto* init = ctx->Clone(initializer_); - auto* cond = ctx->Clone(condition_); - auto* cont = ctx->Clone(continuing_); - auto* b = ctx->Clone(body_); + auto* init = ctx->Clone(initializer); + auto* cond = ctx->Clone(condition); + auto* cont = ctx->Clone(continuing); + auto* b = ctx->Clone(body); return ctx->dst->create(src, init, cond, cont, b); } diff --git a/src/ast/for_loop_statement.h b/src/ast/for_loop_statement.h index e5dbcc730b..2dcd1675f3 100644 --- a/src/ast/for_loop_statement.h +++ b/src/ast/for_loop_statement.h @@ -42,39 +42,26 @@ class ForLoopStatement : public Castable { ForLoopStatement(ForLoopStatement&&); ~ForLoopStatement() override; - /// @returns the initializer statement - const Statement* initializer() const { return initializer_; } - /// @returns the initializer statement - Statement* initializer() { return initializer_; } - - /// @returns the condition expression - const Expression* condition() const { return condition_; } - /// @returns the condition expression - Expression* condition() { return condition_; } - - /// @returns the continuing statement - const Statement* continuing() const { return continuing_; } - /// @returns the continuing statement - Statement* continuing() { return continuing_; } - - /// @returns the loop body block - const BlockStatement* body() const { return body_; } - /// @returns the loop body block - BlockStatement* body() { return body_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node ForLoopStatement* Clone(CloneContext* ctx) const override; + /// The initializer statement + Statement* const initializer; + + /// The condition expression + Expression* const condition; + + /// The continuing statement + Statement* const continuing; + + /// The loop body block + BlockStatement* const body; + private: ForLoopStatement(const ForLoopStatement&) = delete; - - Statement* const initializer_; - Expression* const condition_; - Statement* const continuing_; - BlockStatement* const body_; }; } // namespace ast diff --git a/src/ast/for_loop_statement_test.cc b/src/ast/for_loop_statement_test.cc index 8217e3f5da..73f70fae4e 100644 --- a/src/ast/for_loop_statement_test.cc +++ b/src/ast/for_loop_statement_test.cc @@ -30,16 +30,16 @@ TEST_F(ForLoopStatementTest, Creation) { auto* body = Block(Return()); auto* l = For(init, cond, cont, body); - EXPECT_EQ(l->initializer(), init); - EXPECT_EQ(l->condition(), cond); - EXPECT_EQ(l->continuing(), cont); - EXPECT_EQ(l->body(), body); + EXPECT_EQ(l->initializer, init); + EXPECT_EQ(l->condition, cond); + EXPECT_EQ(l->continuing, cont); + EXPECT_EQ(l->body, body); } TEST_F(ForLoopStatementTest, Creation_WithSource) { auto* body = Block(Return()); auto* l = For(Source{{20u, 2u}}, nullptr, nullptr, nullptr, body); - auto src = l->source(); + auto src = l->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } @@ -47,7 +47,7 @@ TEST_F(ForLoopStatementTest, Creation_WithSource) { TEST_F(ForLoopStatementTest, Creation_Null_InitCondCont) { auto* body = Block(Return()); auto* l = For(nullptr, nullptr, nullptr, body); - EXPECT_EQ(l->body(), body); + EXPECT_EQ(l->body, body); } TEST_F(ForLoopStatementTest, Assert_Null_Body) { diff --git a/src/ast/function.cc b/src/ast/function.cc index d6dfc9e803..fa44f3ea4a 100644 --- a/src/ast/function.cc +++ b/src/ast/function.cc @@ -23,33 +23,33 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Function); namespace tint { namespace ast { -Function::Function(ProgramID program_id, - const Source& source, - Symbol symbol, - VariableList params, - ast::Type* return_type, - BlockStatement* body, - DecorationList decorations, - DecorationList return_type_decorations) - : Base(program_id, source), - symbol_(symbol), - params_(std::move(params)), - return_type_(return_type), - body_(body), - decorations_(std::move(decorations)), - return_type_decorations_(std::move(return_type_decorations)) { - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol_, program_id); +Function::Function(ProgramID pid, + const Source& src, + Symbol sym, + VariableList parameters, + ast::Type* return_ty, + BlockStatement* b, + DecorationList decos, + DecorationList return_type_decos) + : Base(pid, src), + symbol(sym), + params(std::move(parameters)), + return_type(return_ty), + body(b), + decorations(std::move(decos)), + return_type_decorations(std::move(return_type_decos)) { + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); - for (auto* param : params_) { - TINT_ASSERT(AST, param && param->is_const()); + for (auto* param : params) { + TINT_ASSERT(AST, param && param->is_const); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, param, program_id); } - TINT_ASSERT(AST, symbol_.IsValid()); - TINT_ASSERT(AST, return_type_); - for (auto* deco : decorations_) { + TINT_ASSERT(AST, symbol.IsValid()); + TINT_ASSERT(AST, return_type); + for (auto* deco : decorations) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, deco, program_id); } - for (auto* deco : return_type_decorations_) { + for (auto* deco : return_type_decorations) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, deco, program_id); } } @@ -58,32 +58,28 @@ Function::Function(Function&&) = default; Function::~Function() = default; -PipelineStage Function::pipeline_stage() const { - if (auto* stage = GetDecoration(decorations_)) { - return stage->value(); +PipelineStage Function::PipelineStage() const { + if (auto* stage = GetDecoration(decorations)) { + return stage->stage; } return PipelineStage::kNone; } -const Statement* Function::get_last_statement() const { - return body_->last(); -} - Function* Function::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto sym = ctx->Clone(symbol()); - auto p = ctx->Clone(params_); - auto* ret = ctx->Clone(return_type_); - auto* b = ctx->Clone(body_); - auto decos = ctx->Clone(decorations_); - auto ret_decos = ctx->Clone(return_type_decorations_); + auto src = ctx->Clone(source); + auto sym = ctx->Clone(symbol); + auto p = ctx->Clone(params); + auto* ret = ctx->Clone(return_type); + auto* b = ctx->Clone(body); + auto decos = ctx->Clone(decorations); + auto ret_decos = ctx->Clone(return_type_decorations); return ctx->dst->create(src, sym, p, ret, b, decos, ret_decos); } Function* FunctionList::Find(Symbol sym) const { for (auto* func : *this) { - if (func->symbol() == sym) { + if (func->symbol == sym) { return func; } } @@ -92,7 +88,7 @@ Function* FunctionList::Find(Symbol sym) const { Function* FunctionList::Find(Symbol sym, PipelineStage stage) const { for (auto* func : *this) { - if (func->symbol() == sym && func->pipeline_stage() == stage) { + if (func->symbol == sym && func->PipelineStage() == stage) { return func; } } @@ -101,7 +97,7 @@ Function* FunctionList::Find(Symbol sym, PipelineStage stage) const { bool FunctionList::HasStage(ast::PipelineStage stage) const { for (auto* func : *this) { - if (func->pipeline_stage() == stage) { + if (func->PipelineStage() == stage) { return true; } } diff --git a/src/ast/function.h b/src/ast/function.h index 2cc83e998d..2e60d55646 100644 --- a/src/ast/function.h +++ b/src/ast/function.h @@ -57,36 +57,11 @@ class Function : public Castable { ~Function() override; - /// @returns the function symbol - Symbol symbol() const { return symbol_; } - /// @returns the function params - const VariableList& params() const { return params_; } - - /// @returns the decorations attached to this function - const DecorationList& decorations() const { return decorations_; } - /// @returns the functions pipeline stage or None if not set - PipelineStage pipeline_stage() const; + ast::PipelineStage PipelineStage() const; /// @returns true if this function is an entry point - bool IsEntryPoint() const { return pipeline_stage() != PipelineStage::kNone; } - - /// @returns the function return type. - ast::Type* return_type() const { return return_type_; } - - /// @returns the decorations attached to the function return type. - const DecorationList& return_type_decorations() const { - return return_type_decorations_; - } - - /// @returns a pointer to the last statement of the function or nullptr if - // function is empty - const Statement* get_last_statement() const; - - /// @returns the function body - const BlockStatement* body() const { return body_; } - /// @returns the function body - BlockStatement* body() { return body_; } + bool IsEntryPoint() const { return PipelineStage() != PipelineStage::kNone; } /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -94,15 +69,26 @@ class Function : public Castable { /// @return the newly cloned node Function* Clone(CloneContext* ctx) const override; + /// The function symbol + Symbol const symbol; + + /// The function params + VariableList const params; + + /// The function return type + ast::Type* const return_type; + + /// The function body + BlockStatement* const body; + + /// The decorations attached to this function + DecorationList const decorations; + + /// The decorations attached to the function return type. + DecorationList const return_type_decorations; + private: Function(const Function&) = delete; - - Symbol const symbol_; - VariableList const params_; - ast::Type* const return_type_; - BlockStatement* const body_; - DecorationList const decorations_; - DecorationList const return_type_decorations_; }; /// A list of functions diff --git a/src/ast/function_test.cc b/src/ast/function_test.cc index 839e9b29a4..85e77d2891 100644 --- a/src/ast/function_test.cc +++ b/src/ast/function_test.cc @@ -30,10 +30,10 @@ TEST_F(FunctionTest, Creation) { auto* var = params[0]; auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{}); - EXPECT_EQ(f->symbol(), Symbols().Get("func")); - ASSERT_EQ(f->params().size(), 1u); - EXPECT_TRUE(f->return_type()->Is()); - EXPECT_EQ(f->params()[0], var); + EXPECT_EQ(f->symbol, Symbols().Get("func")); + ASSERT_EQ(f->params.size(), 1u); + EXPECT_TRUE(f->return_type->Is()); + EXPECT_EQ(f->params[0], var); } TEST_F(FunctionTest, Creation_WithSource) { @@ -42,7 +42,7 @@ TEST_F(FunctionTest, Creation_WithSource) { auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(), StatementList{}, DecorationList{}); - auto src = f->source(); + auto src = f->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } @@ -139,22 +139,6 @@ TEST_F(FunctionTest, Assert_NonConstParam) { "internal compiler error"); } -TEST_F(FunctionTest, GetLastStatement) { - VariableList params; - auto* stmt = create(); - auto* f = - Func("func", params, ty.void_(), StatementList{stmt}, DecorationList{}); - - EXPECT_EQ(f->get_last_statement(), stmt); -} - -TEST_F(FunctionTest, GetLastStatement_nullptr) { - VariableList params; - auto* f = Func("func", params, ty.void_(), StatementList{}, DecorationList{}); - - EXPECT_EQ(f->get_last_statement(), nullptr); -} - using FunctionListTest = TestHelper; TEST_F(FunctionListTest, FindSymbol) { diff --git a/src/ast/group_decoration.cc b/src/ast/group_decoration.cc index c72f444f4c..571794e8ec 100644 --- a/src/ast/group_decoration.cc +++ b/src/ast/group_decoration.cc @@ -23,21 +23,19 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::GroupDecoration); namespace tint { namespace ast { -GroupDecoration::GroupDecoration(ProgramID program_id, - const Source& source, - uint32_t val) - : Base(program_id, source), value_(val) {} +GroupDecoration::GroupDecoration(ProgramID pid, const Source& src, uint32_t val) + : Base(pid, src), value(val) {} GroupDecoration::~GroupDecoration() = default; -std::string GroupDecoration::name() const { +std::string GroupDecoration::Name() const { return "group"; } GroupDecoration* GroupDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, value_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/group_decoration.h b/src/ast/group_decoration.h index 1d8612862d..de14126b81 100644 --- a/src/ast/group_decoration.h +++ b/src/ast/group_decoration.h @@ -26,17 +26,14 @@ namespace ast { class GroupDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param value the group value - /// @param source the source of this decoration - GroupDecoration(ProgramID program_id, const Source& source, uint32_t value); + GroupDecoration(ProgramID pid, const Source& src, uint32_t value); ~GroupDecoration() override; - /// @returns the group value - uint32_t value() const { return value_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -44,8 +41,8 @@ class GroupDecoration : public Castable { /// @return the newly cloned node GroupDecoration* Clone(CloneContext* ctx) const override; - private: - uint32_t const value_; + /// The group value + uint32_t const value; }; } // namespace ast diff --git a/src/ast/group_decoration_test.cc b/src/ast/group_decoration_test.cc index 7398b753f8..662d88c852 100644 --- a/src/ast/group_decoration_test.cc +++ b/src/ast/group_decoration_test.cc @@ -23,7 +23,7 @@ using GroupDecorationTest = TestHelper; TEST_F(GroupDecorationTest, Creation) { auto* d = create(2); - EXPECT_EQ(2u, d->value()); + EXPECT_EQ(2u, d->value); } } // namespace diff --git a/src/ast/i32.cc b/src/ast/i32.cc index e59ab25de4..b9145d3a7e 100644 --- a/src/ast/i32.cc +++ b/src/ast/i32.cc @@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::I32); namespace tint { namespace ast { -I32::I32(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +I32::I32(ProgramID pid, const Source& src) : Base(pid, src) {} I32::I32(I32&&) = default; @@ -33,7 +32,7 @@ std::string I32::FriendlyName(const SymbolTable&) const { } I32* I32::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/i32.h b/src/ast/i32.h index 5134b8b975..63e66e452e 100644 --- a/src/ast/i32.h +++ b/src/ast/i32.h @@ -26,9 +26,9 @@ namespace ast { class I32 : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node - I32(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + I32(ProgramID pid, const Source& src); /// Move constructor I32(I32&&); ~I32() override; diff --git a/src/ast/identifier_expression.cc b/src/ast/identifier_expression.cc index c3160622b1..da80ff03db 100644 --- a/src/ast/identifier_expression.cc +++ b/src/ast/identifier_expression.cc @@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IdentifierExpression); namespace tint { namespace ast { -IdentifierExpression::IdentifierExpression(ProgramID program_id, - const Source& source, +IdentifierExpression::IdentifierExpression(ProgramID pid, + const Source& src, Symbol sym) - : Base(program_id, source), sym_(sym) { - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, sym_, program_id); - TINT_ASSERT(AST, sym_.IsValid()); + : Base(pid, src), symbol(sym) { + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id); + TINT_ASSERT(AST, symbol.IsValid()); } IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default; @@ -35,8 +35,8 @@ IdentifierExpression::~IdentifierExpression() = default; IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto sym = ctx->Clone(symbol()); + auto src = ctx->Clone(source); + auto sym = ctx->Clone(symbol); return ctx->dst->create(src, sym); } diff --git a/src/ast/identifier_expression.h b/src/ast/identifier_expression.h index b47a1502d6..b60a5ad25f 100644 --- a/src/ast/identifier_expression.h +++ b/src/ast/identifier_expression.h @@ -24,27 +24,25 @@ namespace ast { class IdentifierExpression : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param sym the symbol for the identifier - IdentifierExpression(ProgramID program_id, const Source& source, Symbol sym); + IdentifierExpression(ProgramID pid, const Source& src, Symbol sym); /// Move constructor IdentifierExpression(IdentifierExpression&&); ~IdentifierExpression() override; - /// @returns the symbol for the identifier - Symbol symbol() const { return sym_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node IdentifierExpression* Clone(CloneContext* ctx) const override; + /// The symbol for the identifier + Symbol const symbol; + private: IdentifierExpression(const IdentifierExpression&) = delete; - - Symbol const sym_; }; } // namespace ast diff --git a/src/ast/identifier_expression_test.cc b/src/ast/identifier_expression_test.cc index 6d2296970b..ad6dff57de 100644 --- a/src/ast/identifier_expression_test.cc +++ b/src/ast/identifier_expression_test.cc @@ -23,14 +23,14 @@ using IdentifierExpressionTest = TestHelper; TEST_F(IdentifierExpressionTest, Creation) { auto* i = Expr("ident"); - EXPECT_EQ(i->symbol(), Symbol(1, ID())); + EXPECT_EQ(i->symbol, Symbol(1, ID())); } TEST_F(IdentifierExpressionTest, Creation_WithSource) { auto* i = Expr(Source{Source::Location{20, 2}}, "ident"); - EXPECT_EQ(i->symbol(), Symbol(1, ID())); + EXPECT_EQ(i->symbol, Symbol(1, ID())); - auto src = i->source(); + auto src = i->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/if_statement.cc b/src/ast/if_statement.cc index 0d4db227ee..f4120d7227 100644 --- a/src/ast/if_statement.cc +++ b/src/ast/if_statement.cc @@ -21,20 +21,20 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IfStatement); namespace tint { namespace ast { -IfStatement::IfStatement(ProgramID program_id, - const Source& source, - Expression* condition, - BlockStatement* body, +IfStatement::IfStatement(ProgramID pid, + const Source& src, + Expression* cond, + BlockStatement* b, ElseStatementList else_stmts) - : Base(program_id, source), - condition_(condition), - body_(body), - else_statements_(std::move(else_stmts)) { - TINT_ASSERT(AST, condition_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition_, program_id); - TINT_ASSERT(AST, body_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id); - for (auto* el : else_statements_) { + : Base(pid, src), + condition(cond), + body(b), + else_statements(std::move(else_stmts)) { + TINT_ASSERT(AST, condition); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id); + TINT_ASSERT(AST, body); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); + for (auto* el : else_statements) { TINT_ASSERT(AST, el); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, el, program_id); } @@ -46,10 +46,10 @@ IfStatement::~IfStatement() = default; IfStatement* IfStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* cond = ctx->Clone(condition_); - auto* b = ctx->Clone(body_); - auto el = ctx->Clone(else_statements_); + auto src = ctx->Clone(source); + auto* cond = ctx->Clone(condition); + auto* b = ctx->Clone(body); + auto el = ctx->Clone(else_statements); return ctx->dst->create(src, cond, b, el); } diff --git a/src/ast/if_statement.h b/src/ast/if_statement.h index ed12df4b24..f955107283 100644 --- a/src/ast/if_statement.h +++ b/src/ast/if_statement.h @@ -26,13 +26,13 @@ namespace ast { class IfStatement : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source information + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param condition the if condition /// @param body the if body /// @param else_stmts the else statements - IfStatement(ProgramID program_id, - const Source& source, + IfStatement(ProgramID pid, + const Source& src, Expression* condition, BlockStatement* body, ElseStatementList else_stmts); @@ -40,31 +40,23 @@ class IfStatement : public Castable { IfStatement(IfStatement&&); ~IfStatement() override; - /// @returns the if condition or nullptr if none set - Expression* condition() const { return condition_; } - /// @returns the if body - const BlockStatement* body() const { return body_; } - /// @returns the if body - BlockStatement* body() { return body_; } - - /// @returns the else statements - const ElseStatementList& else_statements() const { return else_statements_; } - - /// @returns true if there are else statements - bool has_else_statements() const { return !else_statements_.empty(); } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node IfStatement* Clone(CloneContext* ctx) const override; + /// The if condition or nullptr if none set + Expression* const condition; + + /// The if body + BlockStatement* const body; + + /// The else statements + ElseStatementList const else_statements; + private: IfStatement(const IfStatement&) = delete; - - Expression* const condition_; - BlockStatement* const body_; - ElseStatementList const else_statements_; }; } // namespace ast diff --git a/src/ast/if_statement_test.cc b/src/ast/if_statement_test.cc index c5740ce729..99903aea27 100644 --- a/src/ast/if_statement_test.cc +++ b/src/ast/if_statement_test.cc @@ -29,7 +29,7 @@ TEST_F(IfStatementTest, Creation) { auto* stmt = create(Source{Source::Location{20, 2}}, cond, Block(create()), ElseStatementList{}); - auto src = stmt->source(); + auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/int_literal.cc b/src/ast/int_literal.cc index 75dd5cdba4..f9659d503a 100644 --- a/src/ast/int_literal.cc +++ b/src/ast/int_literal.cc @@ -19,10 +19,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IntLiteral); namespace tint { namespace ast { -IntLiteral::IntLiteral(ProgramID program_id, - const Source& source, - uint32_t value) - : Base(program_id, source), value_(value) {} +IntLiteral::IntLiteral(ProgramID pid, const Source& src) + : Base(pid, src) {} IntLiteral::~IntLiteral() = default; diff --git a/src/ast/int_literal.h b/src/ast/int_literal.h index 4a12ef6ef3..96d55a9456 100644 --- a/src/ast/int_literal.h +++ b/src/ast/int_literal.h @@ -25,21 +25,17 @@ class IntLiteral : public Castable { public: ~IntLiteral() override; - /// @returns the literal value as an i32 - int32_t value_as_i32() const { return static_cast(value_); } - /// @returns the literal value as a u32 - uint32_t value_as_u32() const { return value_; } + virtual uint32_t ValueAsU32() const = 0; + + /// @returns the literal value as an i32 + int32_t ValueAsI32() const { return static_cast(ValueAsU32()); } protected: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the input source - /// @param value value of the literal - IntLiteral(ProgramID program_id, const Source& source, uint32_t value); - - private: - uint32_t const value_; + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + IntLiteral(ProgramID pid, const Source& src); }; // namespace ast } // namespace ast diff --git a/src/ast/internal_decoration.cc b/src/ast/internal_decoration.cc index 01489f5eff..d3354c56ee 100644 --- a/src/ast/internal_decoration.cc +++ b/src/ast/internal_decoration.cc @@ -19,12 +19,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::InternalDecoration); namespace tint { namespace ast { -InternalDecoration::InternalDecoration(ProgramID program_id) - : Base(program_id, Source{}) {} +InternalDecoration::InternalDecoration(ProgramID pid) : Base(pid, Source{}) {} InternalDecoration::~InternalDecoration() = default; -std::string InternalDecoration::name() const { +std::string InternalDecoration::Name() const { return "internal"; } diff --git a/src/ast/internal_decoration.h b/src/ast/internal_decoration.h index 71960561fe..eb0b814423 100644 --- a/src/ast/internal_decoration.h +++ b/src/ast/internal_decoration.h @@ -39,7 +39,7 @@ class InternalDecoration : public Castable { virtual std::string InternalName() const = 0; /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; }; } // namespace ast diff --git a/src/ast/interpolate_decoration.cc b/src/ast/interpolate_decoration.cc index 35a12f5104..e3f7fae8f6 100644 --- a/src/ast/interpolate_decoration.cc +++ b/src/ast/interpolate_decoration.cc @@ -23,22 +23,22 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::InterpolateDecoration); namespace tint { namespace ast { -InterpolateDecoration::InterpolateDecoration(ProgramID program_id, - const Source& source, - InterpolationType type, - InterpolationSampling sampling) - : Base(program_id, source), type_(type), sampling_(sampling) {} +InterpolateDecoration::InterpolateDecoration(ProgramID pid, + const Source& src, + InterpolationType ty, + InterpolationSampling smpl) + : Base(pid, src), type(ty), sampling(smpl) {} InterpolateDecoration::~InterpolateDecoration() = default; -std::string InterpolateDecoration::name() const { +std::string InterpolateDecoration::Name() const { return "interpolate"; } InterpolateDecoration* InterpolateDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, type_, sampling_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, type, sampling); } std::ostream& operator<<(std::ostream& out, InterpolationType type) { diff --git a/src/ast/interpolate_decoration.h b/src/ast/interpolate_decoration.h index a2194993db..54883fab34 100644 --- a/src/ast/interpolate_decoration.h +++ b/src/ast/interpolate_decoration.h @@ -34,24 +34,18 @@ class InterpolateDecoration : public Castable { public: /// Create an interpolate decoration. - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param type the interpolation type /// @param sampling the interpolation sampling - InterpolateDecoration(ProgramID program_id, - const Source& source, + InterpolateDecoration(ProgramID pid, + const Source& src, InterpolationType type, InterpolationSampling sampling); ~InterpolateDecoration() override; - /// @returns the interpolation type - InterpolationType type() const { return type_; } - - /// @returns the interpolation sampling - InterpolationSampling sampling() const { return sampling_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -59,9 +53,11 @@ class InterpolateDecoration /// @return the newly cloned node InterpolateDecoration* Clone(CloneContext* ctx) const override; - private: - InterpolationType const type_; - InterpolationSampling const sampling_; + /// The interpolation type + InterpolationType const type; + + /// The interpolation sampling + InterpolationSampling const sampling; }; /// @param out the std::ostream to write to diff --git a/src/ast/interpolate_decoration_test.cc b/src/ast/interpolate_decoration_test.cc index d6ce1c6064..cb93b0c500 100644 --- a/src/ast/interpolate_decoration_test.cc +++ b/src/ast/interpolate_decoration_test.cc @@ -25,8 +25,8 @@ using InterpolateDecorationTest = TestHelper; TEST_F(InterpolateDecorationTest, Creation) { auto* d = create(InterpolationType::kLinear, InterpolationSampling::kCenter); - EXPECT_EQ(InterpolationType::kLinear, d->type()); - EXPECT_EQ(InterpolationSampling::kCenter, d->sampling()); + EXPECT_EQ(InterpolationType::kLinear, d->type); + EXPECT_EQ(InterpolationSampling::kCenter, d->sampling); } } // namespace diff --git a/src/ast/intrinsic_texture_helper_test.cc b/src/ast/intrinsic_texture_helper_test.cc index 471a802d41..c926f2d2db 100644 --- a/src/ast/intrinsic_texture_helper_test.cc +++ b/src/ast/intrinsic_texture_helper_test.cc @@ -134,7 +134,7 @@ std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data) { return out; } -ast::Type* TextureOverloadCase::buildResultVectorComponentType( +ast::Type* TextureOverloadCase::BuildResultVectorComponentType( ProgramBuilder* b) const { switch (texture_data_type) { case ast::intrinsic::test::TextureDataType::kF32: @@ -149,7 +149,7 @@ ast::Type* TextureOverloadCase::buildResultVectorComponentType( return {}; } -ast::Variable* TextureOverloadCase::buildTextureVariable( +ast::Variable* TextureOverloadCase::BuildTextureVariable( ProgramBuilder* b) const { DecorationList decos = { b->create(0), @@ -159,7 +159,7 @@ ast::Variable* TextureOverloadCase::buildTextureVariable( case ast::intrinsic::test::TextureKind::kRegular: return b->Global("texture", b->ty.sampled_texture(texture_dimension, - buildResultVectorComponentType(b)), + BuildResultVectorComponentType(b)), decos); case ast::intrinsic::test::TextureKind::kDepth: @@ -175,7 +175,7 @@ ast::Variable* TextureOverloadCase::buildTextureVariable( return b->Global( "texture", b->ty.multisampled_texture(texture_dimension, - buildResultVectorComponentType(b)), + BuildResultVectorComponentType(b)), decos); case ast::intrinsic::test::TextureKind::kStorage: { @@ -188,7 +188,7 @@ ast::Variable* TextureOverloadCase::buildTextureVariable( return nullptr; } -ast::Variable* TextureOverloadCase::buildSamplerVariable( +ast::Variable* TextureOverloadCase::BuildSamplerVariable( ProgramBuilder* b) const { DecorationList decos = { b->create(0), diff --git a/src/ast/intrinsic_texture_helper_test.h b/src/ast/intrinsic_texture_helper_test.h index 0c47fa42c0..5f842f1225 100644 --- a/src/ast/intrinsic_texture_helper_test.h +++ b/src/ast/intrinsic_texture_helper_test.h @@ -205,15 +205,15 @@ struct TextureOverloadCase { /// @param builder the AST builder used for the test /// @returns the vector component type of the texture function return value - ast::Type* buildResultVectorComponentType(ProgramBuilder* builder) const; + ast::Type* BuildResultVectorComponentType(ProgramBuilder* builder) const; /// @param builder the AST builder used for the test /// @returns a variable holding the test texture, automatically registered as /// a global variable. - ast::Variable* buildTextureVariable(ProgramBuilder* builder) const; + ast::Variable* BuildTextureVariable(ProgramBuilder* builder) const; /// @param builder the AST builder used for the test /// @returns a Variable holding the test sampler, automatically registered as /// a global variable. - ast::Variable* buildSamplerVariable(ProgramBuilder* builder) const; + ast::Variable* BuildSamplerVariable(ProgramBuilder* builder) const; /// The enumerator for this overload ValidTextureOverload const overload; diff --git a/src/ast/invariant_decoration.cc b/src/ast/invariant_decoration.cc index 6425d14274..cf00a5b4af 100644 --- a/src/ast/invariant_decoration.cc +++ b/src/ast/invariant_decoration.cc @@ -21,19 +21,18 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::InvariantDecoration); namespace tint { namespace ast { -InvariantDecoration::InvariantDecoration(ProgramID program_id, - const Source& source) - : Base(program_id, source) {} +InvariantDecoration::InvariantDecoration(ProgramID pid, const Source& src) + : Base(pid, src) {} InvariantDecoration::~InvariantDecoration() = default; -std::string InvariantDecoration::name() const { +std::string InvariantDecoration::Name() const { return "invariant"; } InvariantDecoration* InvariantDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/invariant_decoration.h b/src/ast/invariant_decoration.h index 290741c1eb..5f3216de53 100644 --- a/src/ast/invariant_decoration.h +++ b/src/ast/invariant_decoration.h @@ -26,13 +26,13 @@ namespace ast { class InvariantDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration - InvariantDecoration(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + InvariantDecoration(ProgramID pid, const Source& src); ~InvariantDecoration() override; /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. diff --git a/src/ast/literal.cc b/src/ast/literal.cc index 0c6e26f57f..6232a96e2e 100644 --- a/src/ast/literal.cc +++ b/src/ast/literal.cc @@ -19,8 +19,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Literal); namespace tint { namespace ast { -Literal::Literal(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +Literal::Literal(ProgramID pid, const Source& src) : Base(pid, src) {} Literal::~Literal() = default; diff --git a/src/ast/literal.h b/src/ast/literal.h index 0b86d6208d..df8db02c9d 100644 --- a/src/ast/literal.h +++ b/src/ast/literal.h @@ -27,14 +27,11 @@ class Literal : public Castable { public: ~Literal() override; - /// @returns the name for this literal. This name is unique to this value. - virtual std::string name() const = 0; - protected: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the input source - Literal(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the input source + Literal(ProgramID pid, const Source& src); }; } // namespace ast diff --git a/src/ast/location_decoration.cc b/src/ast/location_decoration.cc index ff5b9c9907..5db7e36644 100644 --- a/src/ast/location_decoration.cc +++ b/src/ast/location_decoration.cc @@ -23,21 +23,21 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::LocationDecoration); namespace tint { namespace ast { -LocationDecoration::LocationDecoration(ProgramID program_id, - const Source& source, +LocationDecoration::LocationDecoration(ProgramID pid, + const Source& src, uint32_t val) - : Base(program_id, source), value_(val) {} + : Base(pid, src), value(val) {} LocationDecoration::~LocationDecoration() = default; -std::string LocationDecoration::name() const { +std::string LocationDecoration::Name() const { return "location"; } LocationDecoration* LocationDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, value_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/location_decoration.h b/src/ast/location_decoration.h index 7e8eef8931..d5478745b3 100644 --- a/src/ast/location_decoration.h +++ b/src/ast/location_decoration.h @@ -26,19 +26,14 @@ namespace ast { class LocationDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param value the location value - LocationDecoration(ProgramID program_id, - const Source& source, - uint32_t value); + LocationDecoration(ProgramID pid, const Source& src, uint32_t value); ~LocationDecoration() override; - /// @returns the location value - uint32_t value() const { return value_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -46,8 +41,8 @@ class LocationDecoration : public Castable { /// @return the newly cloned node LocationDecoration* Clone(CloneContext* ctx) const override; - private: - uint32_t const value_; + /// The location value + uint32_t const value; }; } // namespace ast diff --git a/src/ast/location_decoration_test.cc b/src/ast/location_decoration_test.cc index 66a57e1e5c..386846396a 100644 --- a/src/ast/location_decoration_test.cc +++ b/src/ast/location_decoration_test.cc @@ -23,7 +23,7 @@ using LocationDecorationTest = TestHelper; TEST_F(LocationDecorationTest, Creation) { auto* d = create(2); - EXPECT_EQ(2u, d->value()); + EXPECT_EQ(2u, d->value); } } // namespace diff --git a/src/ast/loop_statement.cc b/src/ast/loop_statement.cc index cbbca68be4..e01392ed1a 100644 --- a/src/ast/loop_statement.cc +++ b/src/ast/loop_statement.cc @@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::LoopStatement); namespace tint { namespace ast { -LoopStatement::LoopStatement(ProgramID program_id, - const Source& source, - BlockStatement* body, - BlockStatement* continuing) - : Base(program_id, source), body_(body), continuing_(continuing) { - TINT_ASSERT(AST, body_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body_, program_id); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, continuing_, program_id); +LoopStatement::LoopStatement(ProgramID pid, + const Source& src, + BlockStatement* b, + BlockStatement* cont) + : Base(pid, src), body(b), continuing(cont) { + TINT_ASSERT(AST, body); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, continuing, program_id); } LoopStatement::LoopStatement(LoopStatement&&) = default; @@ -37,9 +37,9 @@ LoopStatement::~LoopStatement() = default; LoopStatement* LoopStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* b = ctx->Clone(body_); - auto* cont = ctx->Clone(continuing_); + auto src = ctx->Clone(source); + auto* b = ctx->Clone(body); + auto* cont = ctx->Clone(continuing); return ctx->dst->create(src, b, cont); } diff --git a/src/ast/loop_statement.h b/src/ast/loop_statement.h index 9ddafe29c4..062ad39d5c 100644 --- a/src/ast/loop_statement.h +++ b/src/ast/loop_statement.h @@ -36,31 +36,20 @@ class LoopStatement : public Castable { LoopStatement(LoopStatement&&); ~LoopStatement() override; - /// @returns the body statements - const BlockStatement* body() const { return body_; } - /// @returns the body statements - BlockStatement* body() { return body_; } - - /// @returns the continuing statements - const BlockStatement* continuing() const { return continuing_; } - /// @returns the continuing statements - BlockStatement* continuing() { return continuing_; } - /// @returns true if there are continuing statements in the loop - bool has_continuing() const { - return continuing_ != nullptr && !continuing_->empty(); - } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node LoopStatement* Clone(CloneContext* ctx) const override; + /// The loop body + BlockStatement* const body; + + /// The continuing statements + BlockStatement* const continuing; + private: LoopStatement(const LoopStatement&) = delete; - - BlockStatement* const body_; - BlockStatement* const continuing_; }; } // namespace ast diff --git a/src/ast/loop_statement_test.cc b/src/ast/loop_statement_test.cc index cc06c76bb4..6d8521aac0 100644 --- a/src/ast/loop_statement_test.cc +++ b/src/ast/loop_statement_test.cc @@ -27,15 +27,15 @@ using LoopStatementTest = TestHelper; TEST_F(LoopStatementTest, Creation) { auto* body = Block(create()); - auto* b = body->last(); + auto* b = body->Last(); auto* continuing = Block(create()); auto* l = create(body, continuing); - ASSERT_EQ(l->body()->size(), 1u); - EXPECT_EQ(l->body()->get(0), b); - ASSERT_EQ(l->continuing()->size(), 1u); - EXPECT_EQ(l->continuing()->get(0), continuing->last()); + ASSERT_EQ(l->body->statements.size(), 1u); + EXPECT_EQ(l->body->statements[0], b); + ASSERT_EQ(l->continuing->statements.size(), 1u); + EXPECT_EQ(l->continuing->statements[0], continuing->Last()); } TEST_F(LoopStatementTest, Creation_WithSource) { @@ -45,7 +45,7 @@ TEST_F(LoopStatementTest, Creation_WithSource) { auto* l = create(Source{Source::Location{20, 2}}, body, continuing); - auto src = l->source(); + auto src = l->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } @@ -59,7 +59,7 @@ TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) { auto* body = Block(create()); auto* l = create(body, nullptr); - EXPECT_FALSE(l->has_continuing()); + EXPECT_FALSE(l->continuing); } TEST_F(LoopStatementTest, HasContinuing_WithContinuing) { @@ -68,7 +68,7 @@ TEST_F(LoopStatementTest, HasContinuing_WithContinuing) { auto* continuing = Block(create()); auto* l = create(body, continuing); - EXPECT_TRUE(l->has_continuing()); + EXPECT_TRUE(l->continuing); } TEST_F(LoopStatementTest, Assert_Null_Body) { diff --git a/src/ast/matrix.cc b/src/ast/matrix.cc index 357fe52990..2a5801a99f 100644 --- a/src/ast/matrix.cc +++ b/src/ast/matrix.cc @@ -21,15 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Matrix); namespace tint { namespace ast { -Matrix::Matrix(ProgramID program_id, - const Source& source, +Matrix::Matrix(ProgramID pid, + const Source& src, Type* subtype, - uint32_t rows, - uint32_t columns) - : Base(program_id, source), - subtype_(subtype), - rows_(rows), - columns_(columns) { + uint32_t r, + uint32_t c) + : Base(pid, src), type(subtype), rows(r), columns(c) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, subtype, program_id); TINT_ASSERT(AST, rows > 1); TINT_ASSERT(AST, rows < 5); @@ -43,16 +40,16 @@ Matrix::~Matrix() = default; std::string Matrix::FriendlyName(const SymbolTable& symbols) const { std::ostringstream out; - out << "mat" << columns_ << "x" << rows_ << "<" - << subtype_->FriendlyName(symbols) << ">"; + out << "mat" << columns << "x" << rows << "<" << type->FriendlyName(symbols) + << ">"; return out.str(); } Matrix* Matrix::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ty = ctx->Clone(type()); - return ctx->dst->create(src, ty, rows_, columns_); + auto src = ctx->Clone(source); + auto* ty = ctx->Clone(type); + return ctx->dst->create(src, ty, rows, columns); } } // namespace ast diff --git a/src/ast/matrix.h b/src/ast/matrix.h index 27417c2766..434ee3f098 100644 --- a/src/ast/matrix.h +++ b/src/ast/matrix.h @@ -26,13 +26,13 @@ namespace ast { class Matrix : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param subtype type matrix type /// @param rows the number of rows in the matrix /// @param columns the number of columns in the matrix - Matrix(ProgramID program_id, - const Source& source, + Matrix(ProgramID pid, + const Source& src, Type* subtype, uint32_t rows, uint32_t columns); @@ -40,13 +40,6 @@ class Matrix : public Castable { Matrix(Matrix&&); ~Matrix() override; - /// @returns the type of the matrix - Type* type() const { return subtype_; } - /// @returns the number of rows in the matrix - uint32_t rows() const { return rows_; } - /// @returns the number of columns in the matrix - uint32_t columns() const { return columns_; } - /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be /// declared in WGSL. @@ -57,10 +50,14 @@ class Matrix : public Castable { /// @return the newly cloned type Matrix* Clone(CloneContext* ctx) const override; - private: - Type* const subtype_; - uint32_t const rows_; - uint32_t const columns_; + /// The type of the matrix + Type* const type; + + /// The number of rows in the matrix + uint32_t const rows; + + /// The number of columns in the matrix + uint32_t const columns; }; } // namespace ast diff --git a/src/ast/matrix_test.cc b/src/ast/matrix_test.cc index 4e1ed2c825..f85ac60c84 100644 --- a/src/ast/matrix_test.cc +++ b/src/ast/matrix_test.cc @@ -36,9 +36,9 @@ using AstMatrixTest = TestHelper; TEST_F(AstMatrixTest, Creation) { auto* i32 = create(); auto* m = create(i32, 2, 4); - EXPECT_EQ(m->type(), i32); - EXPECT_EQ(m->rows(), 2u); - EXPECT_EQ(m->columns(), 4u); + EXPECT_EQ(m->type, i32); + EXPECT_EQ(m->rows, 2u); + EXPECT_EQ(m->columns, 4u); } TEST_F(AstMatrixTest, FriendlyName) { diff --git a/src/ast/member_accessor_expression.cc b/src/ast/member_accessor_expression.cc index 7e75488dd6..4dc3bf896f 100644 --- a/src/ast/member_accessor_expression.cc +++ b/src/ast/member_accessor_expression.cc @@ -21,15 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::MemberAccessorExpression); namespace tint { namespace ast { -MemberAccessorExpression::MemberAccessorExpression(ProgramID program_id, - const Source& source, - Expression* structure, - IdentifierExpression* member) - : Base(program_id, source), struct_(structure), member_(member) { - TINT_ASSERT(AST, struct_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, struct_, program_id); - TINT_ASSERT(AST, member_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, member_, program_id); +MemberAccessorExpression::MemberAccessorExpression(ProgramID pid, + const Source& src, + Expression* str, + IdentifierExpression* mem) + : Base(pid, src), structure(str), member(mem) { + TINT_ASSERT(AST, structure); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, structure, program_id); + TINT_ASSERT(AST, member); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, member, program_id); } MemberAccessorExpression::MemberAccessorExpression(MemberAccessorExpression&&) = @@ -40,9 +40,9 @@ MemberAccessorExpression::~MemberAccessorExpression() = default; MemberAccessorExpression* MemberAccessorExpression::Clone( CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* str = ctx->Clone(structure()); - auto* mem = ctx->Clone(member()); + auto src = ctx->Clone(source); + auto* str = ctx->Clone(structure); + auto* mem = ctx->Clone(member); return ctx->dst->create(src, str, mem); } diff --git a/src/ast/member_accessor_expression.h b/src/ast/member_accessor_expression.h index 46ddd5da3a..a5c0bed3c1 100644 --- a/src/ast/member_accessor_expression.h +++ b/src/ast/member_accessor_expression.h @@ -37,22 +37,20 @@ class MemberAccessorExpression MemberAccessorExpression(MemberAccessorExpression&&); ~MemberAccessorExpression() override; - /// @returns the structure - Expression* structure() const { return struct_; } - /// @returns the member expression - IdentifierExpression* member() const { return member_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node MemberAccessorExpression* Clone(CloneContext* ctx) const override; + /// The structure + Expression* const structure; + + /// The member expression + IdentifierExpression* const member; + private: MemberAccessorExpression(const MemberAccessorExpression&) = delete; - - Expression* const struct_; - IdentifierExpression* const member_; }; } // namespace ast diff --git a/src/ast/member_accessor_expression_test.cc b/src/ast/member_accessor_expression_test.cc index 66179ceb37..8b3362452e 100644 --- a/src/ast/member_accessor_expression_test.cc +++ b/src/ast/member_accessor_expression_test.cc @@ -26,14 +26,14 @@ TEST_F(MemberAccessorExpressionTest, Creation) { auto* mem = Expr("member"); auto* stmt = create(str, mem); - EXPECT_EQ(stmt->structure(), str); - EXPECT_EQ(stmt->member(), mem); + EXPECT_EQ(stmt->structure, str); + EXPECT_EQ(stmt->member, mem); } TEST_F(MemberAccessorExpressionTest, Creation_WithSource) { auto* stmt = create( Source{Source::Location{20, 2}}, Expr("structure"), Expr("member")); - auto src = stmt->source(); + auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/module.cc b/src/ast/module.cc index 029af15b5b..33ccd055ae 100644 --- a/src/ast/module.cc +++ b/src/ast/module.cc @@ -24,13 +24,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Module); namespace tint { namespace ast { -Module::Module(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +Module::Module(ProgramID pid, const Source& src) : Base(pid, src) {} -Module::Module(ProgramID program_id, - const Source& source, +Module::Module(ProgramID pid, + const Source& src, std::vector global_decls) - : Base(program_id, source), global_declarations_(std::move(global_decls)) { + : Base(pid, src), global_declarations_(std::move(global_decls)) { for (auto* decl : global_declarations_) { if (decl == nullptr) { continue; @@ -53,7 +52,7 @@ Module::~Module() = default; const ast::TypeDecl* Module::LookupType(Symbol name) const { for (auto* ty : TypeDecls()) { - if (ty->name() == name) { + if (ty->name == name) { return ty; } } @@ -62,21 +61,21 @@ const ast::TypeDecl* Module::LookupType(Symbol name) const { void Module::AddGlobalVariable(ast::Variable* var) { TINT_ASSERT(AST, var); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id()); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id); global_variables_.push_back(var); global_declarations_.push_back(var); } void Module::AddTypeDecl(ast::TypeDecl* type) { TINT_ASSERT(AST, type); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id()); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id); type_decls_.push_back(type); global_declarations_.push_back(type); } void Module::AddFunction(ast::Function* func) { TINT_ASSERT(AST, func); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id()); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id); functions_.push_back(func); global_declarations_.push_back(func); } @@ -103,13 +102,13 @@ void Module::Copy(CloneContext* ctx, const Module* src) { continue; } if (auto* type = decl->As()) { - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id()); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id); type_decls_.push_back(type); } else if (auto* func = decl->As()) { - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id()); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id); functions_.push_back(func); } else if (auto* var = decl->As()) { - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id()); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id); global_variables_.push_back(var); } else { TINT_ICE(AST, ctx->dst->Diagnostics()) diff --git a/src/ast/module.h b/src/ast/module.h index ab52095798..a4e392c9e2 100644 --- a/src/ast/module.h +++ b/src/ast/module.h @@ -31,17 +31,17 @@ class TypeDecl; class Module : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of the module - Module(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + Module(ProgramID pid, const Source& src); /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of the module + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param global_decls the list of global types, functions, and variables, in /// the order they were declared in the source program - Module(ProgramID program_id, - const Source& source, + Module(ProgramID pid, + const Source& src, std::vector global_decls); /// Destructor diff --git a/src/ast/module_test.cc b/src/ast/module_test.cc index 861c4d07f0..e36a2b8ab8 100644 --- a/src/ast/module_test.cc +++ b/src/ast/module_test.cc @@ -130,11 +130,11 @@ TEST_F(ModuleTest, CloneOrder) { ASSERT_TRUE(decls[2]->Is()); ASSERT_TRUE(decls[4]->Is()); - ASSERT_EQ(cloned.Symbols().NameFor(decls[0]->As()->name()), + ASSERT_EQ(cloned.Symbols().NameFor(decls[0]->As()->name), "inserted_before_F"); - ASSERT_EQ(cloned.Symbols().NameFor(decls[2]->As()->name()), + ASSERT_EQ(cloned.Symbols().NameFor(decls[2]->As()->name), "inserted_before_A"); - ASSERT_EQ(cloned.Symbols().NameFor(decls[4]->As()->name()), + ASSERT_EQ(cloned.Symbols().NameFor(decls[4]->As()->name), "inserted_before_V"); } diff --git a/src/ast/multisampled_texture.cc b/src/ast/multisampled_texture.cc index a5328f9df5..bd8127e970 100644 --- a/src/ast/multisampled_texture.cc +++ b/src/ast/multisampled_texture.cc @@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::MultisampledTexture); namespace tint { namespace ast { -MultisampledTexture::MultisampledTexture(ProgramID program_id, - const Source& source, - TextureDimension dim, - Type* type) - : Base(program_id, source, dim), type_(type) { - TINT_ASSERT(AST, type_); +MultisampledTexture::MultisampledTexture(ProgramID pid, + const Source& src, + TextureDimension d, + Type* ty) + : Base(pid, src, d), type(ty) { + TINT_ASSERT(AST, type); } MultisampledTexture::MultisampledTexture(MultisampledTexture&&) = default; @@ -36,16 +36,16 @@ MultisampledTexture::~MultisampledTexture() = default; std::string MultisampledTexture::FriendlyName( const SymbolTable& symbols) const { std::ostringstream out; - out << "texture_multisampled_" << dim() << "<" << type_->FriendlyName(symbols) + out << "texture_multisampled_" << dim << "<" << type->FriendlyName(symbols) << ">"; return out.str(); } MultisampledTexture* MultisampledTexture::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ty = ctx->Clone(type()); - return ctx->dst->create(src, dim(), ty); + auto src = ctx->Clone(source); + auto* ty = ctx->Clone(type); + return ctx->dst->create(src, dim, ty); } } // namespace ast diff --git a/src/ast/multisampled_texture.h b/src/ast/multisampled_texture.h index 0c44a910ff..c1cef57a16 100644 --- a/src/ast/multisampled_texture.h +++ b/src/ast/multisampled_texture.h @@ -26,21 +26,18 @@ namespace ast { class MultisampledTexture : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param dim the dimensionality of the texture /// @param type the data type of the multisampled texture - MultisampledTexture(ProgramID program_id, - const Source& source, + MultisampledTexture(ProgramID pid, + const Source& src, TextureDimension dim, Type* type); /// Move constructor MultisampledTexture(MultisampledTexture&&); ~MultisampledTexture() override; - /// @returns the subtype of the sampled texture - Type* type() const { return type_; } - /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be /// declared in WGSL. @@ -51,8 +48,8 @@ class MultisampledTexture : public Castable { /// @return the newly cloned type MultisampledTexture* Clone(CloneContext* ctx) const override; - private: - Type* const type_; + /// The subtype of the multisampled texture + Type* const type; }; } // namespace ast diff --git a/src/ast/multisampled_texture_test.cc b/src/ast/multisampled_texture_test.cc index 406774971e..699d76be59 100644 --- a/src/ast/multisampled_texture_test.cc +++ b/src/ast/multisampled_texture_test.cc @@ -50,13 +50,13 @@ TEST_F(AstMultisampledTextureTest, IsTexture) { TEST_F(AstMultisampledTextureTest, Dim) { auto* f32 = create(); auto* s = create(TextureDimension::k3d, f32); - EXPECT_EQ(s->dim(), TextureDimension::k3d); + EXPECT_EQ(s->dim, TextureDimension::k3d); } TEST_F(AstMultisampledTextureTest, Type) { auto* f32 = create(); auto* s = create(TextureDimension::k3d, f32); - EXPECT_EQ(s->type(), f32); + EXPECT_EQ(s->type, f32); } TEST_F(AstMultisampledTextureTest, FriendlyName) { diff --git a/src/ast/node.cc b/src/ast/node.cc index c4c75914f3..92ac290e10 100644 --- a/src/ast/node.cc +++ b/src/ast/node.cc @@ -19,17 +19,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Node); namespace tint { namespace ast { -Node::Node(ProgramID program_id, const Source& source) - : program_id_(program_id), source_(source) {} +Node::Node(ProgramID pid, const Source& src) : program_id(pid), source(src) {} Node::Node(Node&&) = default; Node::~Node() = default; -void Node::make_indent(std::ostream& out, size_t indent) const { - for (size_t i = 0; i < indent; ++i) - out << " "; -} - } // namespace ast } // namespace tint diff --git a/src/ast/node.h b/src/ast/node.h index 10546b0f71..242f7a38df 100644 --- a/src/ast/node.h +++ b/src/ast/node.h @@ -37,30 +37,22 @@ class Node : public Castable { public: ~Node() override; - /// @returns the identifier of the program that owns this node - ProgramID program_id() const { return program_id_; } + /// The identifier of the program that owns this node + ProgramID const program_id; - /// @returns the node source data - const Source& source() const { return source_; } + /// The node source data + Source const source; protected: /// Create a new node - /// @param program_id the identifier of the program that owns this node - /// @param source the input source for the node - Node(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the input source for the node + Node(ProgramID pid, const Source& src); /// Move constructor Node(Node&&); - /// Writes indent into stream - /// @param out the stream to write to - /// @param indent the number of spaces to write - void make_indent(std::ostream& out, size_t indent) const; - private: Node(const Node&) = delete; - - ProgramID const program_id_; - Source const source_; }; } // namespace ast @@ -68,7 +60,7 @@ class Node : public Castable { /// @param node a pointer to an AST node /// @returns the ProgramID of the given AST node. inline ProgramID ProgramIDOf(const ast::Node* node) { - return node ? node->program_id() : ProgramID(); + return node ? node->program_id : ProgramID(); } } // namespace tint diff --git a/src/ast/override_decoration.cc b/src/ast/override_decoration.cc index 312c7fd7b7..6227d9ce7f 100644 --- a/src/ast/override_decoration.cc +++ b/src/ast/override_decoration.cc @@ -23,26 +23,25 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::OverrideDecoration); namespace tint { namespace ast { -OverrideDecoration::OverrideDecoration(ProgramID program_id, - const Source& source) - : Base(program_id, source), has_value_(false), value_(0) {} +OverrideDecoration::OverrideDecoration(ProgramID pid, const Source& src) + : Base(pid, src), has_value(false), value(0) {} -OverrideDecoration::OverrideDecoration(ProgramID program_id, - const Source& source, +OverrideDecoration::OverrideDecoration(ProgramID pid, + const Source& src, uint32_t val) - : Base(program_id, source), has_value_(true), value_(val) {} + : Base(pid, src), has_value(true), value(val) {} OverrideDecoration::~OverrideDecoration() = default; -std::string OverrideDecoration::name() const { +std::string OverrideDecoration::Name() const { return "override"; } OverrideDecoration* OverrideDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - if (has_value_) { - return ctx->dst->create(src, value_); + auto src = ctx->Clone(source); + if (has_value) { + return ctx->dst->create(src, value); } else { return ctx->dst->create(src); } diff --git a/src/ast/override_decoration.h b/src/ast/override_decoration.h index 09e251f444..714498aa3b 100644 --- a/src/ast/override_decoration.h +++ b/src/ast/override_decoration.h @@ -26,24 +26,18 @@ namespace ast { class OverrideDecoration : public Castable { public: /// Create an override decoration with no specified id. - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration - OverrideDecoration(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + OverrideDecoration(ProgramID pid, const Source& src); /// Create an override decoration with a specific id value. - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param val the override value - OverrideDecoration(ProgramID program_id, const Source& source, uint32_t val); + OverrideDecoration(ProgramID pid, const Source& src, uint32_t val); ~OverrideDecoration() override; - /// @returns true if an override id was specified - uint32_t HasValue() const { return has_value_; } - - /// @returns the override id value - uint32_t value() const { return value_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -51,9 +45,11 @@ class OverrideDecoration : public Castable { /// @return the newly cloned node OverrideDecoration* Clone(CloneContext* ctx) const override; - private: - bool has_value_; - uint32_t const value_; + /// True if an override id was specified + bool const has_value; + + /// The override id value + uint32_t const value; }; } // namespace ast diff --git a/src/ast/override_decoration_test.cc b/src/ast/override_decoration_test.cc index fc655b2c76..34a25edb87 100644 --- a/src/ast/override_decoration_test.cc +++ b/src/ast/override_decoration_test.cc @@ -24,13 +24,13 @@ using OverrideDecorationTest = TestHelper; TEST_F(OverrideDecorationTest, Creation_WithValue) { auto* d = create(12); - EXPECT_TRUE(d->HasValue()); - EXPECT_EQ(12u, d->value()); + EXPECT_TRUE(d->has_value); + EXPECT_EQ(12u, d->value); } TEST_F(OverrideDecorationTest, Creation_WithoutValue) { auto* d = create(); - EXPECT_FALSE(d->HasValue()); + EXPECT_FALSE(d->has_value); } } // namespace diff --git a/src/ast/pointer.cc b/src/ast/pointer.cc index 2c97ae471e..4ae782dde1 100644 --- a/src/ast/pointer.cc +++ b/src/ast/pointer.cc @@ -21,25 +21,22 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Pointer); namespace tint { namespace ast { -Pointer::Pointer(ProgramID program_id, - const Source& source, +Pointer::Pointer(ProgramID pid, + const Source& src, Type* const subtype, - ast::StorageClass storage_class, - ast::Access access) - : Base(program_id, source), - subtype_(subtype), - storage_class_(storage_class), - access_(access) {} + ast::StorageClass sc, + ast::Access ac) + : Base(pid, src), type(subtype), storage_class(sc), access(ac) {} std::string Pointer::FriendlyName(const SymbolTable& symbols) const { std::ostringstream out; out << "ptr<"; - if (storage_class_ != ast::StorageClass::kNone) { - out << storage_class_ << ", "; + if (storage_class != ast::StorageClass::kNone) { + out << storage_class << ", "; } - out << subtype_->FriendlyName(symbols); - if (access_ != ast::Access::kUndefined) { - out << ", " << access_; + out << type->FriendlyName(symbols); + if (access != ast::Access::kUndefined) { + out << ", " << access; } out << ">"; return out.str(); @@ -51,9 +48,9 @@ Pointer::~Pointer() = default; Pointer* Pointer::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ty = ctx->Clone(type()); - return ctx->dst->create(src, ty, storage_class_, access_); + auto src = ctx->Clone(source); + auto* ty = ctx->Clone(type); + return ctx->dst->create(src, ty, storage_class, access); } } // namespace ast diff --git a/src/ast/pointer.h b/src/ast/pointer.h index 2469d65d10..b621c954f4 100644 --- a/src/ast/pointer.h +++ b/src/ast/pointer.h @@ -28,13 +28,13 @@ namespace ast { class Pointer : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param subtype the pointee type /// @param storage_class the storage class of the pointer /// @param access the access control of the pointer - Pointer(ProgramID program_id, - const Source& source, + Pointer(ProgramID pid, + const Source& src, Type* const subtype, ast::StorageClass storage_class, ast::Access access); @@ -42,15 +42,6 @@ class Pointer : public Castable { Pointer(Pointer&&); ~Pointer() override; - /// @returns the pointee type - Type* type() const { return const_cast(subtype_); } - - /// @returns the storage class of the pointer - ast::StorageClass storage_class() const { return storage_class_; } - - /// @returns the access control of the pointer - ast::Access access() const { return access_; } - /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be /// declared in WGSL. @@ -61,10 +52,14 @@ class Pointer : public Castable { /// @return the newly cloned type Pointer* Clone(CloneContext* ctx) const override; - private: - Type const* const subtype_; - ast::StorageClass const storage_class_; - ast::Access const access_; + /// The pointee type + Type* const type; + + /// The storage class of the pointer + ast::StorageClass const storage_class; + + /// The access control of the pointer + ast::Access const access; }; } // namespace ast diff --git a/src/ast/pointer_test.cc b/src/ast/pointer_test.cc index 9e187829eb..a8dff94b62 100644 --- a/src/ast/pointer_test.cc +++ b/src/ast/pointer_test.cc @@ -26,9 +26,9 @@ using AstPointerTest = TestHelper; TEST_F(AstPointerTest, Creation) { auto* i32 = create(); auto* p = create(i32, ast::StorageClass::kStorage, Access::kRead); - EXPECT_EQ(p->type(), i32); - EXPECT_EQ(p->storage_class(), ast::StorageClass::kStorage); - EXPECT_EQ(p->access(), Access::kRead); + EXPECT_EQ(p->type, i32); + EXPECT_EQ(p->storage_class, ast::StorageClass::kStorage); + EXPECT_EQ(p->access, Access::kRead); } TEST_F(AstPointerTest, FriendlyName) { diff --git a/src/ast/return_statement.cc b/src/ast/return_statement.cc index 58884703d4..e48be37362 100644 --- a/src/ast/return_statement.cc +++ b/src/ast/return_statement.cc @@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ReturnStatement); namespace tint { namespace ast { -ReturnStatement::ReturnStatement(ProgramID program_id, const Source& source) - : Base(program_id, source), value_(nullptr) {} +ReturnStatement::ReturnStatement(ProgramID pid, const Source& src) + : Base(pid, src), value(nullptr) {} -ReturnStatement::ReturnStatement(ProgramID program_id, - const Source& source, - Expression* value) - : Base(program_id, source), value_(value) { - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, value_, program_id); +ReturnStatement::ReturnStatement(ProgramID pid, + const Source& src, + Expression* val) + : Base(pid, src), value(val) { + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, value, program_id); } ReturnStatement::ReturnStatement(ReturnStatement&&) = default; @@ -37,8 +37,8 @@ ReturnStatement::~ReturnStatement() = default; ReturnStatement* ReturnStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ret = ctx->Clone(value()); + auto src = ctx->Clone(source); + auto* ret = ctx->Clone(value); return ctx->dst->create(src, ret); } diff --git a/src/ast/return_statement.h b/src/ast/return_statement.h index c8420f837c..c6dd4a64c7 100644 --- a/src/ast/return_statement.h +++ b/src/ast/return_statement.h @@ -25,36 +25,30 @@ namespace ast { class ReturnStatement : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source information - ReturnStatement(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + ReturnStatement(ProgramID pid, const Source& src); /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the return statement source + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param value the return value - ReturnStatement(ProgramID program_id, - const Source& source, - Expression* value); + ReturnStatement(ProgramID pid, const Source& src, Expression* value); /// Move constructor ReturnStatement(ReturnStatement&&); ~ReturnStatement() override; - /// @returns the value - Expression* value() const { return value_; } - /// @returns true if the return has a value - bool has_value() const { return value_ != nullptr; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node ReturnStatement* Clone(CloneContext* ctx) const override; + /// The value returned. May be null. + Expression* const value; + private: ReturnStatement(const ReturnStatement&) = delete; - - Expression* const value_; }; } // namespace ast diff --git a/src/ast/return_statement_test.cc b/src/ast/return_statement_test.cc index dbc5c11056..3d2403a1ed 100644 --- a/src/ast/return_statement_test.cc +++ b/src/ast/return_statement_test.cc @@ -27,12 +27,12 @@ TEST_F(ReturnStatementTest, Creation) { auto* expr = Expr("expr"); auto* r = create(expr); - EXPECT_EQ(r->value(), expr); + EXPECT_EQ(r->value, expr); } TEST_F(ReturnStatementTest, Creation_WithSource) { auto* r = create(Source{Source::Location{20, 2}}); - auto src = r->source(); + auto src = r->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } @@ -42,15 +42,15 @@ TEST_F(ReturnStatementTest, IsReturn) { EXPECT_TRUE(r->Is()); } -TEST_F(ReturnStatementTest, HasValue_WithoutValue) { +TEST_F(ReturnStatementTest, WithoutValue) { auto* r = create(); - EXPECT_FALSE(r->has_value()); + EXPECT_EQ(r->value, nullptr); } -TEST_F(ReturnStatementTest, HasValue_WithValue) { +TEST_F(ReturnStatementTest, WithValue) { auto* expr = Expr("expr"); auto* r = create(expr); - EXPECT_TRUE(r->has_value()); + EXPECT_NE(r->value, nullptr); } TEST_F(ReturnStatementTest, Assert_DifferentProgramID_Expr) { diff --git a/src/ast/sampled_texture.cc b/src/ast/sampled_texture.cc index cc1109f6f4..11e0d17d56 100644 --- a/src/ast/sampled_texture.cc +++ b/src/ast/sampled_texture.cc @@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::SampledTexture); namespace tint { namespace ast { -SampledTexture::SampledTexture(ProgramID program_id, - const Source& source, - TextureDimension dim, - Type const* type) - : Base(program_id, source, dim), type_(type) { - TINT_ASSERT(AST, type_); +SampledTexture::SampledTexture(ProgramID pid, + const Source& src, + TextureDimension d, + Type const* ty) + : Base(pid, src, d), type(const_cast(ty)) { + TINT_ASSERT(AST, type); } SampledTexture::SampledTexture(SampledTexture&&) = default; @@ -35,15 +35,15 @@ SampledTexture::~SampledTexture() = default; std::string SampledTexture::FriendlyName(const SymbolTable& symbols) const { std::ostringstream out; - out << "texture_" << dim() << "<" << type_->FriendlyName(symbols) << ">"; + out << "texture_" << dim << "<" << type->FriendlyName(symbols) << ">"; return out.str(); } SampledTexture* SampledTexture::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ty = ctx->Clone(type()); - return ctx->dst->create(src, dim(), ty); + auto src = ctx->Clone(source); + auto* ty = ctx->Clone(type); + return ctx->dst->create(src, dim, ty); } } // namespace ast diff --git a/src/ast/sampled_texture.h b/src/ast/sampled_texture.h index 9bfc52aa0e..05307673f7 100644 --- a/src/ast/sampled_texture.h +++ b/src/ast/sampled_texture.h @@ -26,21 +26,18 @@ namespace ast { class SampledTexture : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param dim the dimensionality of the texture /// @param type the data type of the sampled texture - SampledTexture(ProgramID program_id, - const Source& source, + SampledTexture(ProgramID pid, + const Source& src, TextureDimension dim, Type const* type); /// Move constructor SampledTexture(SampledTexture&&); ~SampledTexture() override; - /// @returns the subtype of the sampled texture - Type* type() const { return const_cast(type_); } - /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be /// declared in WGSL. @@ -51,8 +48,8 @@ class SampledTexture : public Castable { /// @return the newly cloned type SampledTexture* Clone(CloneContext* ctx) const override; - private: - Type const* const type_; + /// The subtype of the sampled texture + Type* const type; }; } // namespace ast diff --git a/src/ast/sampled_texture_test.cc b/src/ast/sampled_texture_test.cc index 12f1b8f0c8..74ade1efb5 100644 --- a/src/ast/sampled_texture_test.cc +++ b/src/ast/sampled_texture_test.cc @@ -34,13 +34,13 @@ TEST_F(AstSampledTextureTest, IsTexture) { TEST_F(AstSampledTextureTest, Dim) { auto* f32 = create(); auto* s = create(TextureDimension::k3d, f32); - EXPECT_EQ(s->dim(), TextureDimension::k3d); + EXPECT_EQ(s->dim, TextureDimension::k3d); } TEST_F(AstSampledTextureTest, Type) { auto* f32 = create(); auto* s = create(TextureDimension::k3d, f32); - EXPECT_EQ(s->type(), f32); + EXPECT_EQ(s->type, f32); } TEST_F(AstSampledTextureTest, FriendlyName) { diff --git a/src/ast/sampler.cc b/src/ast/sampler.cc index 5a6ca23d83..e2387bbab9 100644 --- a/src/ast/sampler.cc +++ b/src/ast/sampler.cc @@ -33,20 +33,20 @@ std::ostream& operator<<(std::ostream& out, SamplerKind kind) { return out; } -Sampler::Sampler(ProgramID program_id, const Source& source, SamplerKind kind) - : Base(program_id, source), kind_(kind) {} +Sampler::Sampler(ProgramID pid, const Source& src, SamplerKind k) + : Base(pid, src), kind(k) {} Sampler::Sampler(Sampler&&) = default; Sampler::~Sampler() = default; std::string Sampler::FriendlyName(const SymbolTable&) const { - return kind_ == SamplerKind::kSampler ? "sampler" : "sampler_comparison"; + return kind == SamplerKind::kSampler ? "sampler" : "sampler_comparison"; } Sampler* Sampler::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source()); - return ctx->dst->create(src, kind_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, kind); } } // namespace ast diff --git a/src/ast/sampler.h b/src/ast/sampler.h index 797a4f2faa..64bf4ea2f2 100644 --- a/src/ast/sampler.h +++ b/src/ast/sampler.h @@ -39,19 +39,16 @@ std::ostream& operator<<(std::ostream& out, SamplerKind kind); class Sampler : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param kind the kind of sampler - Sampler(ProgramID program_id, const Source& source, SamplerKind kind); + Sampler(ProgramID pid, const Source& src, SamplerKind kind); /// Move constructor Sampler(Sampler&&); ~Sampler() override; - /// @returns the sampler type - SamplerKind kind() const { return kind_; } - /// @returns true if this is a comparison sampler - bool IsComparison() const { return kind_ == SamplerKind::kComparisonSampler; } + bool IsComparison() const { return kind == SamplerKind::kComparisonSampler; } /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be @@ -63,8 +60,8 @@ class Sampler : public Castable { /// @return the newly cloned type Sampler* Clone(CloneContext* ctx) const override; - private: - SamplerKind const kind_; + /// The sampler type + SamplerKind const kind; }; } // namespace ast diff --git a/src/ast/sampler_test.cc b/src/ast/sampler_test.cc index 2f9c2023c4..12de46e96e 100644 --- a/src/ast/sampler_test.cc +++ b/src/ast/sampler_test.cc @@ -24,12 +24,12 @@ using AstSamplerTest = TestHelper; TEST_F(AstSamplerTest, Creation) { auto* s = create(SamplerKind::kSampler); - EXPECT_EQ(s->kind(), SamplerKind::kSampler); + EXPECT_EQ(s->kind, SamplerKind::kSampler); } TEST_F(AstSamplerTest, Creation_ComparisonSampler) { auto* s = create(SamplerKind::kComparisonSampler); - EXPECT_EQ(s->kind(), SamplerKind::kComparisonSampler); + EXPECT_EQ(s->kind, SamplerKind::kComparisonSampler); EXPECT_TRUE(s->IsComparison()); } diff --git a/src/ast/scalar_constructor_expression.cc b/src/ast/scalar_constructor_expression.cc index 83b9da318f..74e6e78c07 100644 --- a/src/ast/scalar_constructor_expression.cc +++ b/src/ast/scalar_constructor_expression.cc @@ -21,10 +21,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ScalarConstructorExpression); namespace tint { namespace ast { -ScalarConstructorExpression::ScalarConstructorExpression(ProgramID program_id, - const Source& source, - Literal* literal) - : Base(program_id, source), literal_(literal) { +ScalarConstructorExpression::ScalarConstructorExpression(ProgramID pid, + const Source& src, + Literal* lit) + : Base(pid, src), literal(lit) { TINT_ASSERT(AST, literal); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, literal, program_id); } @@ -37,8 +37,8 @@ ScalarConstructorExpression::~ScalarConstructorExpression() = default; ScalarConstructorExpression* ScalarConstructorExpression::Clone( CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* lit = ctx->Clone(literal()); + auto src = ctx->Clone(source); + auto* lit = ctx->Clone(literal); return ctx->dst->create(src, lit); } diff --git a/src/ast/scalar_constructor_expression.h b/src/ast/scalar_constructor_expression.h index 0a7925dd1a..ad1d1caa87 100644 --- a/src/ast/scalar_constructor_expression.h +++ b/src/ast/scalar_constructor_expression.h @@ -26,29 +26,27 @@ class ScalarConstructorExpression : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the constructor source + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param literal the const literal - ScalarConstructorExpression(ProgramID program_id, - const Source& source, + ScalarConstructorExpression(ProgramID pid, + const Source& src, Literal* literal); /// Move constructor ScalarConstructorExpression(ScalarConstructorExpression&&); ~ScalarConstructorExpression() override; - /// @returns the literal value - Literal* literal() const { return literal_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node ScalarConstructorExpression* Clone(CloneContext* ctx) const override; + /// The literal value + Literal* const literal; + private: ScalarConstructorExpression(const ScalarConstructorExpression&) = delete; - - Literal* const literal_; }; } // namespace ast diff --git a/src/ast/scalar_constructor_expression_test.cc b/src/ast/scalar_constructor_expression_test.cc index 8548d0df1d..1c184d5f56 100644 --- a/src/ast/scalar_constructor_expression_test.cc +++ b/src/ast/scalar_constructor_expression_test.cc @@ -24,12 +24,12 @@ using ScalarConstructorExpressionTest = TestHelper; TEST_F(ScalarConstructorExpressionTest, Creation) { auto* b = create(true); auto* c = create(b); - EXPECT_EQ(c->literal(), b); + EXPECT_EQ(c->literal, b); } TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) { SetSource(Source{Source::Location{20, 2}}); - auto src = Expr(true)->source(); + auto src = Expr(true)->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/sint_literal.cc b/src/ast/sint_literal.cc index 710ecab31b..2e6f23220f 100644 --- a/src/ast/sint_literal.cc +++ b/src/ast/sint_literal.cc @@ -21,21 +21,19 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::SintLiteral); namespace tint { namespace ast { -SintLiteral::SintLiteral(ProgramID program_id, - const Source& source, - int32_t value) - : Base(program_id, source, static_cast(value)) {} +SintLiteral::SintLiteral(ProgramID pid, const Source& src, int32_t val) + : Base(pid, src), value(val) {} SintLiteral::~SintLiteral() = default; -std::string SintLiteral::name() const { - return "__sint_" + std::to_string(value()); +uint32_t SintLiteral::ValueAsU32() const { + return static_cast(value); } SintLiteral* SintLiteral::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, value()); + auto src = ctx->Clone(source); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/sint_literal.h b/src/ast/sint_literal.h index b0a2baaa84..75f9aa365f 100644 --- a/src/ast/sint_literal.h +++ b/src/ast/sint_literal.h @@ -26,23 +26,23 @@ namespace ast { class SintLiteral : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the input source + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param value the signed int literals value - SintLiteral(ProgramID program_id, const Source& source, int32_t value); + SintLiteral(ProgramID pid, const Source& src, int32_t value); ~SintLiteral() override; - /// @returns the int literal value - int32_t value() const { return static_cast(value_as_u32()); } - - /// @returns the name for this literal. This name is unique to this value. - std::string name() const override; + /// @returns the literal value as a u32 + uint32_t ValueAsU32() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node SintLiteral* Clone(CloneContext* ctx) const override; + + /// The int literal value + int32_t const value; }; } // namespace ast diff --git a/src/ast/sint_literal_test.cc b/src/ast/sint_literal_test.cc index d9805f3ca2..7503e623d8 100644 --- a/src/ast/sint_literal_test.cc +++ b/src/ast/sint_literal_test.cc @@ -23,12 +23,7 @@ using SintLiteralTest = TestHelper; TEST_F(SintLiteralTest, Value) { auto* i = create(47); ASSERT_TRUE(i->Is()); - EXPECT_EQ(i->value(), 47); -} - -TEST_F(SintLiteralTest, Name_I32) { - auto* i = create(2); - EXPECT_EQ("__sint_2", i->name()); + EXPECT_EQ(i->value, 47); } } // namespace diff --git a/src/ast/stage_decoration.cc b/src/ast/stage_decoration.cc index af12ba2065..3fd66ee646 100644 --- a/src/ast/stage_decoration.cc +++ b/src/ast/stage_decoration.cc @@ -23,21 +23,21 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StageDecoration); namespace tint { namespace ast { -StageDecoration::StageDecoration(ProgramID program_id, - const Source& source, - PipelineStage stage) - : Base(program_id, source), stage_(stage) {} +StageDecoration::StageDecoration(ProgramID pid, + const Source& src, + PipelineStage s) + : Base(pid, src), stage(s) {} StageDecoration::~StageDecoration() = default; -std::string StageDecoration::name() const { +std::string StageDecoration::Name() const { return "stage"; } StageDecoration* StageDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, stage_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, stage); } } // namespace ast diff --git a/src/ast/stage_decoration.h b/src/ast/stage_decoration.h index d411d7aca9..acd035923f 100644 --- a/src/ast/stage_decoration.h +++ b/src/ast/stage_decoration.h @@ -35,11 +35,8 @@ class StageDecoration : public Castable { PipelineStage stage); ~StageDecoration() override; - /// @returns the stage - PipelineStage value() const { return stage_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -47,8 +44,8 @@ class StageDecoration : public Castable { /// @return the newly cloned node StageDecoration* Clone(CloneContext* ctx) const override; - private: - PipelineStage const stage_; + /// The pipeline stage + PipelineStage const stage; }; } // namespace ast diff --git a/src/ast/stage_decoration_test.cc b/src/ast/stage_decoration_test.cc index e6fc5be9c3..6febb85177 100644 --- a/src/ast/stage_decoration_test.cc +++ b/src/ast/stage_decoration_test.cc @@ -25,7 +25,7 @@ using StageDecorationTest = TestHelper; TEST_F(StageDecorationTest, Creation_1param) { auto* d = create(PipelineStage::kFragment); - EXPECT_EQ(d->value(), PipelineStage::kFragment); + EXPECT_EQ(d->stage, PipelineStage::kFragment); } } // namespace diff --git a/src/ast/statement.cc b/src/ast/statement.cc index f4618a09a1..0121d545b3 100644 --- a/src/ast/statement.cc +++ b/src/ast/statement.cc @@ -31,8 +31,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Statement); namespace tint { namespace ast { -Statement::Statement(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +Statement::Statement(ProgramID pid, const Source& src) : Base(pid, src) {} Statement::Statement(Statement&&) = default; diff --git a/src/ast/statement.h b/src/ast/statement.h index b371a1eaf2..24e3cd2925 100644 --- a/src/ast/statement.h +++ b/src/ast/statement.h @@ -32,9 +32,9 @@ class Statement : public Castable { protected: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of the expression - Statement(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of the expression + Statement(ProgramID pid, const Source& src); /// Move constructor Statement(Statement&&); diff --git a/src/ast/storage_class.cc b/src/ast/storage_class.cc index 2ec1ca2a49..ca15be5097 100644 --- a/src/ast/storage_class.cc +++ b/src/ast/storage_class.cc @@ -17,7 +17,7 @@ namespace tint { namespace ast { -const char* str(StorageClass sc) { +const char* ToString(StorageClass sc) { switch (sc) { case StorageClass::kInvalid: return "invalid"; @@ -45,7 +45,7 @@ const char* str(StorageClass sc) { return ""; } std::ostream& operator<<(std::ostream& out, StorageClass sc) { - out << str(sc); + out << ToString(sc); return out; } diff --git a/src/ast/storage_class.h b/src/ast/storage_class.h index 4f263afe18..ccfeda2502 100644 --- a/src/ast/storage_class.h +++ b/src/ast/storage_class.h @@ -44,7 +44,7 @@ inline bool IsHostShareable(StorageClass sc) { /// @param sc the StorageClass /// @return the name of the given storage class -const char* str(StorageClass sc); +const char* ToString(StorageClass sc); /// @param out the std::ostream to write to /// @param sc the StorageClass diff --git a/src/ast/storage_texture.cc b/src/ast/storage_texture.cc index 39f5a1e000..6c8783f040 100644 --- a/src/ast/storage_texture.cc +++ b/src/ast/storage_texture.cc @@ -140,16 +140,13 @@ std::ostream& operator<<(std::ostream& out, ImageFormat format) { return out; } -StorageTexture::StorageTexture(ProgramID program_id, - const Source& source, - TextureDimension dim, - ImageFormat format, +StorageTexture::StorageTexture(ProgramID pid, + const Source& src, + TextureDimension d, + ImageFormat fmt, Type* subtype, - Access access) - : Base(program_id, source, dim), - image_format_(format), - subtype_(subtype), - access_(access) {} + Access ac) + : Base(pid, src, d), format(fmt), type(subtype), access(ac) {} StorageTexture::StorageTexture(StorageTexture&&) = default; @@ -157,17 +154,15 @@ StorageTexture::~StorageTexture() = default; std::string StorageTexture::FriendlyName(const SymbolTable&) const { std::ostringstream out; - out << "texture_storage_" << dim() << "<" << image_format_ << ", " << access_ - << ">"; + out << "texture_storage_" << dim << "<" << format << ", " << access << ">"; return out.str(); } StorageTexture* StorageTexture::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ty = ctx->Clone(type()); - return ctx->dst->create(src, dim(), image_format(), ty, - access()); + auto src = ctx->Clone(source); + auto* ty = ctx->Clone(type); + return ctx->dst->create(src, dim, format, ty, access); } Type* StorageTexture::SubtypeFor(ImageFormat format, ProgramBuilder& builder) { diff --git a/src/ast/storage_texture.h b/src/ast/storage_texture.h index c89a2307ad..d09bb1a7a6 100644 --- a/src/ast/storage_texture.h +++ b/src/ast/storage_texture.h @@ -74,14 +74,14 @@ std::ostream& operator<<(std::ostream& out, ImageFormat format); class StorageTexture : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param dim the dimensionality of the texture /// @param format the image format of the texture /// @param subtype the storage subtype. Use SubtypeFor() to calculate this. /// @param access_control the access control for the texture. - StorageTexture(ProgramID program_id, - const Source& source, + StorageTexture(ProgramID pid, + const Source& src, TextureDimension dim, ImageFormat format, Type* subtype, @@ -91,22 +91,6 @@ class StorageTexture : public Castable { StorageTexture(StorageTexture&&); ~StorageTexture() override; - /// @returns the image format - ImageFormat image_format() const { return image_format_; } - - /// @returns the storage subtype - Type* type() const { return subtype_; } - - /// @returns the access control - Access access() const { return access_; } - - /// @returns true if the access control is read only - bool is_read_only() const { return access_ == Access::kRead; } - /// @returns true if the access control is write only - bool is_write_only() const { return access_ == Access::kWrite; } - /// @returns true if the access control is read/write - bool is_read_write() const { return access_ == Access::kReadWrite; } - /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be /// declared in WGSL. @@ -122,10 +106,14 @@ class StorageTexture : public Castable { /// @returns the storage texture subtype for the given ImageFormat static Type* SubtypeFor(ImageFormat format, ProgramBuilder& builder); - private: - ImageFormat const image_format_; - Type* const subtype_; - Access const access_; + /// The image format + ImageFormat const format; + + /// The storage subtype + Type* const type; + + /// The access control + Access const access; }; } // namespace ast diff --git a/src/ast/storage_texture_test.cc b/src/ast/storage_texture_test.cc index 7642282d99..ecd2c1342a 100644 --- a/src/ast/storage_texture_test.cc +++ b/src/ast/storage_texture_test.cc @@ -37,7 +37,7 @@ TEST_F(AstStorageTextureTest, Dim) { auto* s = create(TextureDimension::k2dArray, ImageFormat::kRgba32Float, subtype, Access::kRead); - EXPECT_EQ(s->dim(), TextureDimension::k2dArray); + EXPECT_EQ(s->dim, TextureDimension::k2dArray); } TEST_F(AstStorageTextureTest, Format) { @@ -45,7 +45,7 @@ TEST_F(AstStorageTextureTest, Format) { auto* s = create(TextureDimension::k2dArray, ImageFormat::kRgba32Float, subtype, Access::kRead); - EXPECT_EQ(s->image_format(), ImageFormat::kRgba32Float); + EXPECT_EQ(s->format, ImageFormat::kRgba32Float); } TEST_F(AstStorageTextureTest, FriendlyName) { @@ -65,7 +65,7 @@ TEST_F(AstStorageTextureTest, F32) { ASSERT_TRUE(s->Is()); ASSERT_TRUE(s->Is()); - EXPECT_TRUE(s->As()->type()->Is()); + EXPECT_TRUE(s->As()->type->Is()); } TEST_F(AstStorageTextureTest, U32) { @@ -76,7 +76,7 @@ TEST_F(AstStorageTextureTest, U32) { ASSERT_TRUE(s->Is()); ASSERT_TRUE(s->Is()); - EXPECT_TRUE(s->As()->type()->Is()); + EXPECT_TRUE(s->As()->type->Is()); } TEST_F(AstStorageTextureTest, I32) { @@ -87,7 +87,7 @@ TEST_F(AstStorageTextureTest, I32) { ASSERT_TRUE(s->Is()); ASSERT_TRUE(s->Is()); - EXPECT_TRUE(s->As()->type()->Is()); + EXPECT_TRUE(s->As()->type->Is()); } } // namespace diff --git a/src/ast/stride_decoration.cc b/src/ast/stride_decoration.cc index 1a4c47bf5b..08d7ee9d39 100644 --- a/src/ast/stride_decoration.cc +++ b/src/ast/stride_decoration.cc @@ -23,21 +23,19 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StrideDecoration); namespace tint { namespace ast { -StrideDecoration::StrideDecoration(ProgramID program_id, - const Source& source, - uint32_t stride) - : Base(program_id, source), stride_(stride) {} +StrideDecoration::StrideDecoration(ProgramID pid, const Source& src, uint32_t s) + : Base(pid, src), stride(s) {} StrideDecoration::~StrideDecoration() = default; -std::string StrideDecoration::name() const { +std::string StrideDecoration::Name() const { return "stride"; } StrideDecoration* StrideDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, stride_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, stride); } } // namespace ast diff --git a/src/ast/stride_decoration.h b/src/ast/stride_decoration.h index 6d0a92c1e9..c9cf3e35e7 100644 --- a/src/ast/stride_decoration.h +++ b/src/ast/stride_decoration.h @@ -26,17 +26,14 @@ namespace ast { class StrideDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param stride the stride value - /// @param source the source of this decoration - StrideDecoration(ProgramID program_id, const Source& source, uint32_t stride); + StrideDecoration(ProgramID pid, const Source& src, uint32_t stride); ~StrideDecoration() override; - /// @returns the stride value - uint32_t stride() const { return stride_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -44,8 +41,8 @@ class StrideDecoration : public Castable { /// @return the newly cloned node StrideDecoration* Clone(CloneContext* ctx) const override; - private: - uint32_t const stride_; + /// The stride value + uint32_t const stride; }; } // namespace ast diff --git a/src/ast/stride_decoration_test.cc b/src/ast/stride_decoration_test.cc index 1e25ad3654..066b46a980 100644 --- a/src/ast/stride_decoration_test.cc +++ b/src/ast/stride_decoration_test.cc @@ -22,17 +22,16 @@ using StrideDecorationTest = TestHelper; TEST_F(StrideDecorationTest, Creation) { auto* d = create(2); - EXPECT_EQ(2u, d->stride()); + EXPECT_EQ(2u, d->stride); } - TEST_F(StrideDecorationTest, Source) { auto* d = create( Source{Source::Range{Source::Location{1, 2}, Source::Location{3, 4}}}, 2); - EXPECT_EQ(d->source().range.begin.line, 1u); - EXPECT_EQ(d->source().range.begin.column, 2u); - EXPECT_EQ(d->source().range.end.line, 3u); - EXPECT_EQ(d->source().range.end.column, 4u); + EXPECT_EQ(d->source.range.begin.line, 1u); + EXPECT_EQ(d->source.range.begin.column, 2u); + EXPECT_EQ(d->source.range.end.line, 3u); + EXPECT_EQ(d->source.range.end.column, 4u); } } // namespace diff --git a/src/ast/struct.cc b/src/ast/struct.cc index b49dd28f2f..cb9106785f 100644 --- a/src/ast/struct.cc +++ b/src/ast/struct.cc @@ -24,19 +24,17 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Struct); namespace tint { namespace ast { -Struct::Struct(ProgramID program_id, - const Source& source, - Symbol name, - StructMemberList members, - DecorationList decorations) - : Base(program_id, source, name), - members_(std::move(members)), - decorations_(std::move(decorations)) { - for (auto* mem : members_) { +Struct::Struct(ProgramID pid, + const Source& src, + Symbol n, + StructMemberList m, + DecorationList decos) + : Base(pid, src, n), members(std::move(m)), decorations(std::move(decos)) { + for (auto* mem : members) { TINT_ASSERT(AST, mem); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, mem, program_id); } - for (auto* deco : decorations_) { + for (auto* deco : decorations) { TINT_ASSERT(AST, deco); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, deco, program_id); } @@ -46,25 +44,16 @@ Struct::Struct(Struct&&) = default; Struct::~Struct() = default; -StructMember* Struct::get_member(const Symbol& symbol) const { - for (auto* mem : members_) { - if (mem->symbol() == symbol) { - return mem; - } - } - return nullptr; -} - bool Struct::IsBlockDecorated() const { - return HasDecoration(decorations_); + return HasDecoration(decorations); } Struct* Struct::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto n = ctx->Clone(name()); - auto mem = ctx->Clone(members()); - auto decos = ctx->Clone(decorations()); + auto src = ctx->Clone(source); + auto n = ctx->Clone(name); + auto mem = ctx->Clone(members); + auto decos = ctx->Clone(decorations); return ctx->dst->create(src, n, mem, decos); } diff --git a/src/ast/struct.h b/src/ast/struct.h index dcc5b5954d..beecd27c75 100644 --- a/src/ast/struct.h +++ b/src/ast/struct.h @@ -29,13 +29,13 @@ namespace ast { class Struct : public Castable { public: /// Create a new struct statement - /// @param program_id the identifier of the program that owns this node - /// @param source The input source for the import statement + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node for the import statement /// @param name The name of the structure /// @param members The struct members /// @param decorations The struct decorations - Struct(ProgramID program_id, - const Source& source, + Struct(ProgramID pid, + const Source& src, Symbol name, StructMemberList members, DecorationList decorations); @@ -44,17 +44,6 @@ class Struct : public Castable { ~Struct() override; - /// @returns the struct decorations - const DecorationList& decorations() const { return decorations_; } - - /// @returns the members - const StructMemberList& members() const { return members_; } - - /// Returns the struct member with the given symbol or nullptr if non exists. - /// @param symbol the symbol of the member - /// @returns the struct member or nullptr if not found - StructMember* get_member(const Symbol& symbol) const; - /// @returns true if the struct is block decorated bool IsBlockDecorated() const; @@ -64,11 +53,14 @@ class Struct : public Castable { /// @return the newly cloned node Struct* Clone(CloneContext* ctx) const override; + /// The members + StructMemberList const members; + + /// The struct decorations + DecorationList const decorations; + private: Struct(const Struct&) = delete; - - StructMemberList const members_; - DecorationList const decorations_; }; } // namespace ast diff --git a/src/ast/struct_block_decoration.cc b/src/ast/struct_block_decoration.cc index a83d828b9c..e41b34e42a 100644 --- a/src/ast/struct_block_decoration.cc +++ b/src/ast/struct_block_decoration.cc @@ -23,19 +23,18 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StructBlockDecoration); namespace tint { namespace ast { -StructBlockDecoration::StructBlockDecoration(ProgramID program_id, - const Source& source) - : Base(program_id, source) {} +StructBlockDecoration::StructBlockDecoration(ProgramID pid, const Source& src) + : Base(pid, src) {} StructBlockDecoration::~StructBlockDecoration() = default; -std::string StructBlockDecoration::name() const { +std::string StructBlockDecoration::Name() const { return "block"; } StructBlockDecoration* StructBlockDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/struct_block_decoration.h b/src/ast/struct_block_decoration.h index 8a304a7f43..8a3cbffe40 100644 --- a/src/ast/struct_block_decoration.h +++ b/src/ast/struct_block_decoration.h @@ -28,13 +28,13 @@ class StructBlockDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration - StructBlockDecoration(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + StructBlockDecoration(ProgramID pid, const Source& src); ~StructBlockDecoration() override; /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. diff --git a/src/ast/struct_member.cc b/src/ast/struct_member.cc index 995aedccf1..73a34600ff 100644 --- a/src/ast/struct_member.cc +++ b/src/ast/struct_member.cc @@ -21,19 +21,16 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StructMember); namespace tint { namespace ast { -StructMember::StructMember(ProgramID program_id, - const Source& source, +StructMember::StructMember(ProgramID pid, + const Source& src, const Symbol& sym, - ast::Type* type, - DecorationList decorations) - : Base(program_id, source), - symbol_(sym), - type_(type), - decorations_(std::move(decorations)) { + ast::Type* ty, + DecorationList decos) + : Base(pid, src), symbol(sym), type(ty), decorations(std::move(decos)) { TINT_ASSERT(AST, type); - TINT_ASSERT(AST, symbol_.IsValid()); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol_, program_id); - for (auto* deco : decorations_) { + TINT_ASSERT(AST, symbol.IsValid()); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id); + for (auto* deco : decorations) { TINT_ASSERT(AST, deco); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, deco, program_id); } @@ -43,24 +40,12 @@ StructMember::StructMember(StructMember&&) = default; StructMember::~StructMember() = default; -bool StructMember::has_offset_decoration() const { - return HasDecoration(decorations_); -} - -uint32_t StructMember::offset() const { - if (auto* offset = - GetDecoration(decorations_)) { - return offset->offset(); - } - return 0; -} - StructMember* StructMember::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto sym = ctx->Clone(symbol_); - auto* ty = ctx->Clone(type_); - auto decos = ctx->Clone(decorations_); + auto src = ctx->Clone(source); + auto sym = ctx->Clone(symbol); + auto* ty = ctx->Clone(type); + auto decos = ctx->Clone(decorations); return ctx->dst->create(src, sym, ty, decos); } diff --git a/src/ast/struct_member.h b/src/ast/struct_member.h index 6635153baf..c3865b5461 100644 --- a/src/ast/struct_member.h +++ b/src/ast/struct_member.h @@ -30,13 +30,13 @@ class Type; class StructMember : public Castable { public: /// Create a new struct member statement - /// @param program_id the identifier of the program that owns this node - /// @param source The input source for the struct member statement + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node for the struct member statement /// @param sym The struct member symbol /// @param type The struct member type /// @param decorations The struct member decorations - StructMember(ProgramID program_id, - const Source& source, + StructMember(ProgramID pid, + const Source& src, const Symbol& sym, ast::Type* type, DecorationList decorations); @@ -45,32 +45,23 @@ class StructMember : public Castable { ~StructMember() override; - /// @returns the symbol - const Symbol& symbol() const { return symbol_; } - - /// @returns the type - ast::Type* type() const { return type_; } - - /// @returns the decorations - const DecorationList& decorations() const { return decorations_; } - - /// @returns true if the struct member has an offset decoration - bool has_offset_decoration() const; - /// @returns the offset decoration value. - uint32_t offset() const; - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node StructMember* Clone(CloneContext* ctx) const override; + /// The symbol + Symbol const symbol; + + /// The type + ast::Type* const type; + + /// The decorations + DecorationList const decorations; + private: StructMember(const StructMember&) = delete; - - Symbol const symbol_; - ast::Type* const type_; - DecorationList const decorations_; }; /// A list of struct members diff --git a/src/ast/struct_member_align_decoration.cc b/src/ast/struct_member_align_decoration.cc index 770e888112..e2fb028b30 100644 --- a/src/ast/struct_member_align_decoration.cc +++ b/src/ast/struct_member_align_decoration.cc @@ -24,22 +24,22 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StructMemberAlignDecoration); namespace tint { namespace ast { -StructMemberAlignDecoration::StructMemberAlignDecoration(ProgramID program_id, - const Source& source, - uint32_t align) - : Base(program_id, source), align_(align) {} +StructMemberAlignDecoration::StructMemberAlignDecoration(ProgramID pid, + const Source& src, + uint32_t a) + : Base(pid, src), align(a) {} StructMemberAlignDecoration::~StructMemberAlignDecoration() = default; -std::string StructMemberAlignDecoration::name() const { +std::string StructMemberAlignDecoration::Name() const { return "align"; } StructMemberAlignDecoration* StructMemberAlignDecoration::Clone( CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, align_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, align); } } // namespace ast diff --git a/src/ast/struct_member_align_decoration.h b/src/ast/struct_member_align_decoration.h index d25dfaef5e..64c4dfa634 100644 --- a/src/ast/struct_member_align_decoration.h +++ b/src/ast/struct_member_align_decoration.h @@ -28,19 +28,14 @@ class StructMemberAlignDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param align the align value - StructMemberAlignDecoration(ProgramID program_id, - const Source& source, - uint32_t align); + StructMemberAlignDecoration(ProgramID pid, const Source& src, uint32_t align); ~StructMemberAlignDecoration() override; - /// @returns the align value - uint32_t align() const { return align_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -48,8 +43,8 @@ class StructMemberAlignDecoration /// @return the newly cloned node StructMemberAlignDecoration* Clone(CloneContext* ctx) const override; - private: - uint32_t const align_; + /// The align value + uint32_t const align; }; } // namespace ast diff --git a/src/ast/struct_member_align_decoration_test.cc b/src/ast/struct_member_align_decoration_test.cc index 8dc71a62e3..beb545ea5f 100644 --- a/src/ast/struct_member_align_decoration_test.cc +++ b/src/ast/struct_member_align_decoration_test.cc @@ -24,7 +24,7 @@ using StructMemberAlignDecorationTest = TestHelper; TEST_F(StructMemberAlignDecorationTest, Creation) { auto* d = create(2); - EXPECT_EQ(2u, d->align()); + EXPECT_EQ(2u, d->align); } } // namespace diff --git a/src/ast/struct_member_offset_decoration.cc b/src/ast/struct_member_offset_decoration.cc index 7939b19595..a482fbd39e 100644 --- a/src/ast/struct_member_offset_decoration.cc +++ b/src/ast/struct_member_offset_decoration.cc @@ -23,22 +23,22 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StructMemberOffsetDecoration); namespace tint { namespace ast { -StructMemberOffsetDecoration::StructMemberOffsetDecoration(ProgramID program_id, - const Source& source, - uint32_t offset) - : Base(program_id, source), offset_(offset) {} +StructMemberOffsetDecoration::StructMemberOffsetDecoration(ProgramID pid, + const Source& src, + uint32_t o) + : Base(pid, src), offset(o) {} StructMemberOffsetDecoration::~StructMemberOffsetDecoration() = default; -std::string StructMemberOffsetDecoration::name() const { +std::string StructMemberOffsetDecoration::Name() const { return "offset"; } StructMemberOffsetDecoration* StructMemberOffsetDecoration::Clone( CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, offset_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, offset); } } // namespace ast diff --git a/src/ast/struct_member_offset_decoration.h b/src/ast/struct_member_offset_decoration.h index 8cd9db18c8..753c647b13 100644 --- a/src/ast/struct_member_offset_decoration.h +++ b/src/ast/struct_member_offset_decoration.h @@ -36,19 +36,16 @@ class StructMemberOffsetDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param offset the offset value - StructMemberOffsetDecoration(ProgramID program_id, - const Source& source, + StructMemberOffsetDecoration(ProgramID pid, + const Source& src, uint32_t offset); ~StructMemberOffsetDecoration() override; - /// @returns the offset value - uint32_t offset() const { return offset_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -56,8 +53,8 @@ class StructMemberOffsetDecoration /// @return the newly cloned node StructMemberOffsetDecoration* Clone(CloneContext* ctx) const override; - private: - uint32_t const offset_; + /// The offset value + uint32_t const offset; }; } // namespace ast diff --git a/src/ast/struct_member_offset_decoration_test.cc b/src/ast/struct_member_offset_decoration_test.cc index 94f3e873ad..d04e1a07d9 100644 --- a/src/ast/struct_member_offset_decoration_test.cc +++ b/src/ast/struct_member_offset_decoration_test.cc @@ -22,7 +22,7 @@ using StructMemberOffsetDecorationTest = TestHelper; TEST_F(StructMemberOffsetDecorationTest, Creation) { auto* d = create(2); - EXPECT_EQ(2u, d->offset()); + EXPECT_EQ(2u, d->offset); } } // namespace diff --git a/src/ast/struct_member_size_decoration.cc b/src/ast/struct_member_size_decoration.cc index 1b679c688f..0155c41f0f 100644 --- a/src/ast/struct_member_size_decoration.cc +++ b/src/ast/struct_member_size_decoration.cc @@ -24,22 +24,22 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StructMemberSizeDecoration); namespace tint { namespace ast { -StructMemberSizeDecoration::StructMemberSizeDecoration(ProgramID program_id, - const Source& source, - uint32_t size) - : Base(program_id, source), size_(size) {} +StructMemberSizeDecoration::StructMemberSizeDecoration(ProgramID pid, + const Source& src, + uint32_t sz) + : Base(pid, src), size(sz) {} StructMemberSizeDecoration::~StructMemberSizeDecoration() = default; -std::string StructMemberSizeDecoration::name() const { +std::string StructMemberSizeDecoration::Name() const { return "size"; } StructMemberSizeDecoration* StructMemberSizeDecoration::Clone( CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, size_); + auto src = ctx->Clone(source); + return ctx->dst->create(src, size); } } // namespace ast diff --git a/src/ast/struct_member_size_decoration.h b/src/ast/struct_member_size_decoration.h index 25cfb2a72e..50bbed0fcc 100644 --- a/src/ast/struct_member_size_decoration.h +++ b/src/ast/struct_member_size_decoration.h @@ -28,19 +28,14 @@ class StructMemberSizeDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param size the size value - StructMemberSizeDecoration(ProgramID program_id, - const Source& source, - uint32_t size); + StructMemberSizeDecoration(ProgramID pid, const Source& src, uint32_t size); ~StructMemberSizeDecoration() override; - /// @returns the size value - uint32_t size() const { return size_; } - /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -48,8 +43,8 @@ class StructMemberSizeDecoration /// @return the newly cloned node StructMemberSizeDecoration* Clone(CloneContext* ctx) const override; - private: - uint32_t const size_; + /// The size value + uint32_t const size; }; } // namespace ast diff --git a/src/ast/struct_member_size_decoration_test.cc b/src/ast/struct_member_size_decoration_test.cc index fea6fd2a4c..1e6df5fd00 100644 --- a/src/ast/struct_member_size_decoration_test.cc +++ b/src/ast/struct_member_size_decoration_test.cc @@ -24,7 +24,7 @@ using StructMemberOffsetDecorationTest = TestHelper; TEST_F(StructMemberOffsetDecorationTest, Creation) { auto* d = create(2); - EXPECT_EQ(2u, d->size()); + EXPECT_EQ(2u, d->size); } } // namespace diff --git a/src/ast/struct_member_test.cc b/src/ast/struct_member_test.cc index 6bf3edd2f1..c5a1630351 100644 --- a/src/ast/struct_member_test.cc +++ b/src/ast/struct_member_test.cc @@ -23,27 +23,27 @@ using StructMemberTest = TestHelper; TEST_F(StructMemberTest, Creation) { auto* st = Member("a", ty.i32(), {MemberSize(4)}); - EXPECT_EQ(st->symbol(), Symbol(1, ID())); - EXPECT_TRUE(st->type()->Is()); - EXPECT_EQ(st->decorations().size(), 1u); - EXPECT_TRUE(st->decorations()[0]->Is()); - EXPECT_EQ(st->source().range.begin.line, 0u); - EXPECT_EQ(st->source().range.begin.column, 0u); - EXPECT_EQ(st->source().range.end.line, 0u); - EXPECT_EQ(st->source().range.end.column, 0u); + EXPECT_EQ(st->symbol, Symbol(1, ID())); + EXPECT_TRUE(st->type->Is()); + EXPECT_EQ(st->decorations.size(), 1u); + EXPECT_TRUE(st->decorations[0]->Is()); + EXPECT_EQ(st->source.range.begin.line, 0u); + EXPECT_EQ(st->source.range.begin.column, 0u); + EXPECT_EQ(st->source.range.end.line, 0u); + EXPECT_EQ(st->source.range.end.column, 0u); } TEST_F(StructMemberTest, CreationWithSource) { auto* st = Member( Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, "a", ty.i32()); - EXPECT_EQ(st->symbol(), Symbol(1, ID())); - EXPECT_TRUE(st->type()->Is()); - EXPECT_EQ(st->decorations().size(), 0u); - EXPECT_EQ(st->source().range.begin.line, 27u); - EXPECT_EQ(st->source().range.begin.column, 4u); - EXPECT_EQ(st->source().range.end.line, 27u); - EXPECT_EQ(st->source().range.end.column, 8u); + EXPECT_EQ(st->symbol, Symbol(1, ID())); + EXPECT_TRUE(st->type->Is()); + EXPECT_EQ(st->decorations.size(), 0u); + EXPECT_EQ(st->source.range.begin.line, 27u); + EXPECT_EQ(st->source.range.begin.column, 4u); + EXPECT_EQ(st->source.range.end.line, 27u); + EXPECT_EQ(st->source.range.end.column, 8u); } TEST_F(StructMemberTest, Assert_Empty_Symbol) { diff --git a/src/ast/struct_test.cc b/src/ast/struct_test.cc index 7fe50e48be..5d1701dfb7 100644 --- a/src/ast/struct_test.cc +++ b/src/ast/struct_test.cc @@ -38,13 +38,13 @@ TEST_F(AstStructTest, Creation) { auto name = Sym("s"); auto* s = create(name, StructMemberList{Member("a", ty.i32())}, DecorationList{}); - EXPECT_EQ(s->name(), name); - EXPECT_EQ(s->members().size(), 1u); - EXPECT_TRUE(s->decorations().empty()); - EXPECT_EQ(s->source().range.begin.line, 0u); - EXPECT_EQ(s->source().range.begin.column, 0u); - EXPECT_EQ(s->source().range.end.line, 0u); - EXPECT_EQ(s->source().range.end.column, 0u); + EXPECT_EQ(s->name, name); + EXPECT_EQ(s->members.size(), 1u); + EXPECT_TRUE(s->decorations.empty()); + EXPECT_EQ(s->source.range.begin.line, 0u); + EXPECT_EQ(s->source.range.begin.column, 0u); + EXPECT_EQ(s->source.range.end.line, 0u); + EXPECT_EQ(s->source.range.end.column, 0u); } TEST_F(AstStructTest, Creation_WithDecorations) { @@ -54,14 +54,14 @@ TEST_F(AstStructTest, Creation_WithDecorations) { auto* s = create(name, StructMemberList{Member("a", ty.i32())}, decos); - EXPECT_EQ(s->name(), name); - EXPECT_EQ(s->members().size(), 1u); - ASSERT_EQ(s->decorations().size(), 1u); - EXPECT_TRUE(s->decorations()[0]->Is()); - EXPECT_EQ(s->source().range.begin.line, 0u); - EXPECT_EQ(s->source().range.begin.column, 0u); - EXPECT_EQ(s->source().range.end.line, 0u); - EXPECT_EQ(s->source().range.end.column, 0u); + EXPECT_EQ(s->name, name); + EXPECT_EQ(s->members.size(), 1u); + ASSERT_EQ(s->decorations.size(), 1u); + EXPECT_TRUE(s->decorations[0]->Is()); + EXPECT_EQ(s->source.range.begin.line, 0u); + EXPECT_EQ(s->source.range.begin.column, 0u); + EXPECT_EQ(s->source.range.end.line, 0u); + EXPECT_EQ(s->source.range.end.column, 0u); } TEST_F(AstStructTest, CreationWithSourceAndDecorations) { @@ -70,14 +70,14 @@ TEST_F(AstStructTest, CreationWithSourceAndDecorations) { Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, name, StructMemberList{Member("a", ty.i32())}, DecorationList{create()}); - EXPECT_EQ(s->name(), name); - EXPECT_EQ(s->members().size(), 1u); - ASSERT_EQ(s->decorations().size(), 1u); - EXPECT_TRUE(s->decorations()[0]->Is()); - EXPECT_EQ(s->source().range.begin.line, 27u); - EXPECT_EQ(s->source().range.begin.column, 4u); - EXPECT_EQ(s->source().range.end.line, 27u); - EXPECT_EQ(s->source().range.end.column, 8u); + EXPECT_EQ(s->name, name); + EXPECT_EQ(s->members.size(), 1u); + ASSERT_EQ(s->decorations.size(), 1u); + EXPECT_TRUE(s->decorations[0]->Is()); + EXPECT_EQ(s->source.range.begin.line, 27u); + EXPECT_EQ(s->source.range.begin.column, 4u); + EXPECT_EQ(s->source.range.end.line, 27u); + EXPECT_EQ(s->source.range.end.column, 8u); } TEST_F(AstStructTest, Assert_Null_StructMember) { diff --git a/src/ast/switch_statement.cc b/src/ast/switch_statement.cc index 7091b3e794..2013fccdc8 100644 --- a/src/ast/switch_statement.cc +++ b/src/ast/switch_statement.cc @@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::SwitchStatement); namespace tint { namespace ast { -SwitchStatement::SwitchStatement(ProgramID program_id, - const Source& source, - Expression* condition, - CaseStatementList body) - : Base(program_id, source), condition_(condition), body_(body) { - TINT_ASSERT(AST, condition_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition_, program_id); - for (auto* stmt : body_) { +SwitchStatement::SwitchStatement(ProgramID pid, + const Source& src, + Expression* cond, + CaseStatementList b) + : Base(pid, src), condition(cond), body(b) { + TINT_ASSERT(AST, condition); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id); + for (auto* stmt : body) { TINT_ASSERT(AST, stmt); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, stmt, program_id); } @@ -40,9 +40,9 @@ SwitchStatement::~SwitchStatement() = default; SwitchStatement* SwitchStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* cond = ctx->Clone(condition()); - auto b = ctx->Clone(body()); + auto src = ctx->Clone(source); + auto* cond = ctx->Clone(condition); + auto b = ctx->Clone(body); return ctx->dst->create(src, cond, b); } diff --git a/src/ast/switch_statement.h b/src/ast/switch_statement.h index fae33f5336..beec41955e 100644 --- a/src/ast/switch_statement.h +++ b/src/ast/switch_statement.h @@ -25,25 +25,20 @@ namespace ast { class SwitchStatement : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source information + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param condition the switch condition /// @param body the switch body - SwitchStatement(ProgramID program_id, - const Source& source, + SwitchStatement(ProgramID pid, + const Source& src, Expression* condition, CaseStatementList body); /// Move constructor SwitchStatement(SwitchStatement&&); ~SwitchStatement() override; - /// @returns the switch condition or nullptr if none set - Expression* condition() const { return condition_; } /// @returns true if this is a default statement - bool IsDefault() const { return condition_ == nullptr; } - - /// @returns the Switch body - const CaseStatementList& body() const { return body_; } + bool IsDefault() const { return condition == nullptr; } /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -51,11 +46,14 @@ class SwitchStatement : public Castable { /// @return the newly cloned node SwitchStatement* Clone(CloneContext* ctx) const override; + /// The switch condition or nullptr if none set + Expression* const condition; + + /// The Switch body + CaseStatementList const body; + private: SwitchStatement(const SwitchStatement&) = delete; - - Expression* const condition_; - CaseStatementList const body_; }; } // namespace ast diff --git a/src/ast/switch_statement_test.cc b/src/ast/switch_statement_test.cc index 66c29e4b1c..355f70f2f6 100644 --- a/src/ast/switch_statement_test.cc +++ b/src/ast/switch_statement_test.cc @@ -33,9 +33,9 @@ TEST_F(SwitchStatementTest, Creation) { body.push_back(case_stmt); auto* stmt = create(ident, body); - EXPECT_EQ(stmt->condition(), ident); - ASSERT_EQ(stmt->body().size(), 1u); - EXPECT_EQ(stmt->body()[0], case_stmt); + EXPECT_EQ(stmt->condition, ident); + ASSERT_EQ(stmt->body.size(), 1u); + EXPECT_EQ(stmt->body[0], case_stmt); } TEST_F(SwitchStatementTest, Creation_WithSource) { @@ -43,7 +43,7 @@ TEST_F(SwitchStatementTest, Creation_WithSource) { auto* stmt = create(Source{Source::Location{20, 2}}, ident, CaseStatementList()); - auto src = stmt->source(); + auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/texture.cc b/src/ast/texture.cc index 28de192de0..6c54e24155 100644 --- a/src/ast/texture.cc +++ b/src/ast/texture.cc @@ -78,10 +78,8 @@ int NumCoordinateAxes(TextureDimension dim) { return 0; } -Texture::Texture(ProgramID program_id, - const Source& source, - TextureDimension dim) - : Base(program_id, source), dim_(dim) {} +Texture::Texture(ProgramID pid, const Source& src, TextureDimension d) + : Base(pid, src), dim(d) {} Texture::Texture(Texture&&) = default; diff --git a/src/ast/texture.h b/src/ast/texture.h index 4c2270e010..769d1ebea9 100644 --- a/src/ast/texture.h +++ b/src/ast/texture.h @@ -65,19 +65,16 @@ int NumCoordinateAxes(TextureDimension dim); class Texture : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param dim the dimensionality of the texture - Texture(ProgramID program_id, const Source& source, TextureDimension dim); + Texture(ProgramID pid, const Source& src, TextureDimension dim); /// Move constructor Texture(Texture&&); ~Texture() override; - /// @returns the texture dimension - TextureDimension dim() const { return dim_; } - - private: - TextureDimension const dim_; + /// The texture dimension + TextureDimension const dim; }; } // namespace ast diff --git a/src/ast/type.h b/src/ast/type.h index c03a2b5732..3f60261bee 100644 --- a/src/ast/type.h +++ b/src/ast/type.h @@ -42,9 +42,9 @@ class Type : public Castable { protected: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node - Type(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + Type(ProgramID pid, const Source& src); }; } // namespace ast diff --git a/src/ast/type_constructor_expression.cc b/src/ast/type_constructor_expression.cc index e382b1249e..bfae88bcf7 100644 --- a/src/ast/type_constructor_expression.cc +++ b/src/ast/type_constructor_expression.cc @@ -21,13 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::TypeConstructorExpression); namespace tint { namespace ast { -TypeConstructorExpression::TypeConstructorExpression(ProgramID program_id, - const Source& source, - ast::Type* type, - ExpressionList values) - : Base(program_id, source), type_(type), values_(std::move(values)) { - TINT_ASSERT(AST, type_); - for (auto* val : values_) { +TypeConstructorExpression::TypeConstructorExpression(ProgramID pid, + const Source& src, + ast::Type* ty, + ExpressionList vals) + : Base(pid, src), type(ty), values(std::move(vals)) { + TINT_ASSERT(AST, type); + for (auto* val : values) { TINT_ASSERT(AST, val); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, val, program_id); } @@ -41,9 +41,9 @@ TypeConstructorExpression::~TypeConstructorExpression() = default; TypeConstructorExpression* TypeConstructorExpression::Clone( CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ty = ctx->Clone(type()); - auto vals = ctx->Clone(values()); + auto src = ctx->Clone(source); + auto* ty = ctx->Clone(type); + auto vals = ctx->Clone(values); return ctx->dst->create(src, ty, vals); } diff --git a/src/ast/type_constructor_expression.h b/src/ast/type_constructor_expression.h index b23aeeb998..f8590d4946 100644 --- a/src/ast/type_constructor_expression.h +++ b/src/ast/type_constructor_expression.h @@ -30,35 +30,32 @@ class TypeConstructorExpression : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the constructor source + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param type the type /// @param values the constructor values - TypeConstructorExpression(ProgramID program_id, - const Source& source, + TypeConstructorExpression(ProgramID pid, + const Source& src, ast::Type* type, ExpressionList values); /// Move constructor TypeConstructorExpression(TypeConstructorExpression&&); ~TypeConstructorExpression() override; - /// @returns the type - ast::Type* type() const { return type_; } - - /// @returns the values - const ExpressionList& values() const { return values_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node TypeConstructorExpression* Clone(CloneContext* ctx) const override; + /// The type + ast::Type* const type; + + /// The values + ExpressionList const values; + private: TypeConstructorExpression(const TypeConstructorExpression&) = delete; - - ast::Type* const type_; - ExpressionList const values_; }; } // namespace ast diff --git a/src/ast/type_constructor_expression_test.cc b/src/ast/type_constructor_expression_test.cc index 7ef5eb8e50..fa87cc522c 100644 --- a/src/ast/type_constructor_expression_test.cc +++ b/src/ast/type_constructor_expression_test.cc @@ -26,9 +26,9 @@ TEST_F(TypeConstructorExpressionTest, Creation) { expr.push_back(Expr("expr")); auto* t = create(ty.f32(), expr); - EXPECT_TRUE(t->type()->Is()); - ASSERT_EQ(t->values().size(), 1u); - EXPECT_EQ(t->values()[0], expr[0]); + EXPECT_TRUE(t->type->Is()); + ASSERT_EQ(t->values.size(), 1u); + EXPECT_EQ(t->values[0], expr[0]); } TEST_F(TypeConstructorExpressionTest, Creation_WithSource) { @@ -37,7 +37,7 @@ TEST_F(TypeConstructorExpressionTest, Creation_WithSource) { auto* t = create(Source{Source::Location{20, 2}}, ty.f32(), expr); - auto src = t->source(); + auto src = t->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/type_decl.cc b/src/ast/type_decl.cc index 41491ee772..94c94afdb0 100644 --- a/src/ast/type_decl.cc +++ b/src/ast/type_decl.cc @@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::TypeDecl); namespace tint { namespace ast { -TypeDecl::TypeDecl(ProgramID program_id, const Source& source, Symbol name) - : Base(program_id, source), name_(name) { +TypeDecl::TypeDecl(ProgramID pid, const Source& src, Symbol n) + : Base(pid, src), name(n) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, name, program_id); } diff --git a/src/ast/type_decl.h b/src/ast/type_decl.h index 0f5c7a80c2..df6b94d113 100644 --- a/src/ast/type_decl.h +++ b/src/ast/type_decl.h @@ -26,23 +26,21 @@ namespace ast { class TypeDecl : public Castable { public: /// Create a new struct statement - /// @param program_id the identifier of the program that owns this node - /// @param source The input source for the import statement + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node for the import statement /// @param name The name of the structure - TypeDecl(ProgramID program_id, const Source& source, Symbol name); + TypeDecl(ProgramID pid, const Source& src, Symbol name); /// Move constructor TypeDecl(TypeDecl&&); ~TypeDecl() override; - /// @returns the name of the type declaration - Symbol name() const { return name_; } + /// The name of the type declaration + Symbol const name; private: TypeDecl(const TypeDecl&) = delete; TypeDecl& operator=(const TypeDecl&) = delete; - - Symbol const name_; }; } // namespace ast diff --git a/src/ast/type_name.cc b/src/ast/type_name.cc index 943e66f3ce..3ad3236dbb 100644 --- a/src/ast/type_name.cc +++ b/src/ast/type_name.cc @@ -21,20 +21,20 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::TypeName); namespace tint { namespace ast { -TypeName::TypeName(ProgramID program_id, const Source& source, Symbol name) - : Base(program_id, source), name_(name) {} +TypeName::TypeName(ProgramID pid, const Source& src, Symbol n) + : Base(pid, src), name(n) {} TypeName::~TypeName() = default; TypeName::TypeName(TypeName&&) = default; std::string TypeName::FriendlyName(const SymbolTable& symbols) const { - return symbols.NameFor(name_); + return symbols.NameFor(name); } TypeName* TypeName::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source()); - auto n = ctx->Clone(name()); + auto src = ctx->Clone(source); + auto n = ctx->Clone(name); return ctx->dst->create(src, n); } diff --git a/src/ast/type_name.h b/src/ast/type_name.h index fb4cc8c384..867bc96815 100644 --- a/src/ast/type_name.h +++ b/src/ast/type_name.h @@ -26,17 +26,15 @@ namespace ast { class TypeName : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param name the type name - TypeName(ProgramID program_id, const Source& source, Symbol name); + TypeName(ProgramID pid, const Source& src, Symbol name); /// Move constructor TypeName(TypeName&&); /// Destructor ~TypeName() override; - /// @return the type name - const Symbol& name() const { return name_; } /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be @@ -48,8 +46,8 @@ class TypeName : public Castable { /// @return the newly cloned type TypeName* Clone(CloneContext* ctx) const override; - private: - Symbol name_; + /// The type name + Symbol name; }; } // namespace ast diff --git a/src/ast/u32.cc b/src/ast/u32.cc index 21bcc16841..9337861d86 100644 --- a/src/ast/u32.cc +++ b/src/ast/u32.cc @@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::U32); namespace tint { namespace ast { -U32::U32(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +U32::U32(ProgramID pid, const Source& src) : Base(pid, src) {} U32::~U32() = default; @@ -33,7 +32,7 @@ std::string U32::FriendlyName(const SymbolTable&) const { } U32* U32::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/u32.h b/src/ast/u32.h index 2acf667f51..66714298af 100644 --- a/src/ast/u32.h +++ b/src/ast/u32.h @@ -26,9 +26,9 @@ namespace ast { class U32 : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node - U32(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + U32(ProgramID pid, const Source& src); /// Move constructor U32(U32&&); ~U32() override; diff --git a/src/ast/uint_literal.cc b/src/ast/uint_literal.cc index c00846e8d9..b25db81960 100644 --- a/src/ast/uint_literal.cc +++ b/src/ast/uint_literal.cc @@ -21,21 +21,19 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::UintLiteral); namespace tint { namespace ast { -UintLiteral::UintLiteral(ProgramID program_id, - const Source& source, - uint32_t value) - : Base(program_id, source, value) {} +UintLiteral::UintLiteral(ProgramID pid, const Source& src, uint32_t val) + : Base(pid, src), value(val) {} UintLiteral::~UintLiteral() = default; -std::string UintLiteral::name() const { - return "__uint" + std::to_string(value()); +uint32_t UintLiteral::ValueAsU32() const { + return value; } UintLiteral* UintLiteral::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - return ctx->dst->create(src, value()); + auto src = ctx->Clone(source); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/uint_literal.h b/src/ast/uint_literal.h index f6b084ea7f..3a2df6299c 100644 --- a/src/ast/uint_literal.h +++ b/src/ast/uint_literal.h @@ -26,23 +26,23 @@ namespace ast { class UintLiteral : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the input source + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param value the uint literals value - UintLiteral(ProgramID program_id, const Source& source, uint32_t value); + UintLiteral(ProgramID pid, const Source& src, uint32_t value); ~UintLiteral() override; - /// @returns the uint literal value - uint32_t value() const { return value_as_u32(); } - - /// @returns the name for this literal. This name is unique to this value. - std::string name() const override; + /// @returns the literal value as a u32 + uint32_t ValueAsU32() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node UintLiteral* Clone(CloneContext* ctx) const override; + + /// The int literal value + uint32_t const value; }; } // namespace ast diff --git a/src/ast/uint_literal_test.cc b/src/ast/uint_literal_test.cc index 1da417df0b..a65750a292 100644 --- a/src/ast/uint_literal_test.cc +++ b/src/ast/uint_literal_test.cc @@ -23,7 +23,7 @@ using UintLiteralTest = TestHelper; TEST_F(UintLiteralTest, Value) { auto* u = create(47); ASSERT_TRUE(u->Is()); - EXPECT_EQ(u->value(), 47u); + EXPECT_EQ(u->value, 47u); } } // namespace diff --git a/src/ast/unary_op_expression.cc b/src/ast/unary_op_expression.cc index 52eb6873b9..21ebfec0a9 100644 --- a/src/ast/unary_op_expression.cc +++ b/src/ast/unary_op_expression.cc @@ -21,13 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::UnaryOpExpression); namespace tint { namespace ast { -UnaryOpExpression::UnaryOpExpression(ProgramID program_id, - const Source& source, - UnaryOp op, - Expression* expr) - : Base(program_id, source), op_(op), expr_(expr) { - TINT_ASSERT(AST, expr_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr_, program_id); +UnaryOpExpression::UnaryOpExpression(ProgramID pid, + const Source& src, + UnaryOp o, + Expression* e) + : Base(pid, src), op(o), expr(e) { + TINT_ASSERT(AST, expr); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id); } UnaryOpExpression::UnaryOpExpression(UnaryOpExpression&&) = default; @@ -36,9 +36,9 @@ UnaryOpExpression::~UnaryOpExpression() = default; UnaryOpExpression* UnaryOpExpression::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* e = ctx->Clone(expr()); - return ctx->dst->create(src, op_, e); + auto src = ctx->Clone(source); + auto* e = ctx->Clone(expr); + return ctx->dst->create(src, op, e); } } // namespace ast diff --git a/src/ast/unary_op_expression.h b/src/ast/unary_op_expression.h index 94f3137cf8..03345f5023 100644 --- a/src/ast/unary_op_expression.h +++ b/src/ast/unary_op_expression.h @@ -37,22 +37,20 @@ class UnaryOpExpression : public Castable { UnaryOpExpression(UnaryOpExpression&&); ~UnaryOpExpression() override; - /// @returns the op - UnaryOp op() const { return op_; } - /// @returns the expression - Expression* expr() const { return expr_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node UnaryOpExpression* Clone(CloneContext* ctx) const override; + /// The op + UnaryOp const op; + + /// The expression + Expression* const expr; + private: UnaryOpExpression(const UnaryOpExpression&) = delete; - - UnaryOp const op_; - Expression* const expr_; }; } // namespace ast diff --git a/src/ast/unary_op_expression_test.cc b/src/ast/unary_op_expression_test.cc index db11efff44..47f870ab47 100644 --- a/src/ast/unary_op_expression_test.cc +++ b/src/ast/unary_op_expression_test.cc @@ -27,15 +27,15 @@ TEST_F(UnaryOpExpressionTest, Creation) { auto* ident = Expr("ident"); auto* u = create(UnaryOp::kNot, ident); - EXPECT_EQ(u->op(), UnaryOp::kNot); - EXPECT_EQ(u->expr(), ident); + EXPECT_EQ(u->op, UnaryOp::kNot); + EXPECT_EQ(u->expr, ident); } TEST_F(UnaryOpExpressionTest, Creation_WithSource) { auto* ident = Expr("ident"); auto* u = create(Source{Source::Location{20, 2}}, UnaryOp::kNot, ident); - auto src = u->source(); + auto src = u->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/variable.cc b/src/ast/variable.cc index c355054618..f5da167d78 100644 --- a/src/ast/variable.cc +++ b/src/ast/variable.cc @@ -23,25 +23,25 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Variable); namespace tint { namespace ast { -Variable::Variable(ProgramID program_id, - const Source& source, +Variable::Variable(ProgramID pid, + const Source& src, const Symbol& sym, - StorageClass declared_storage_class, - Access declared_access, - const ast::Type* type, - bool is_const, - Expression* constructor, - DecorationList decorations) - : Base(program_id, source), - symbol_(sym), - type_(type), - is_const_(is_const), - constructor_(constructor), - decorations_(std::move(decorations)), - declared_storage_class_(declared_storage_class), - declared_access_(declared_access) { - TINT_ASSERT(AST, symbol_.IsValid()); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol_, program_id); + StorageClass dsc, + Access da, + const ast::Type* ty, + bool constant, + Expression* ctor, + DecorationList decos) + : Base(pid, src), + symbol(sym), + type(const_cast(ty)), + is_const(constant), + constructor(ctor), + decorations(std::move(decos)), + declared_storage_class(dsc), + declared_access(da) { + TINT_ASSERT(AST, symbol.IsValid()); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, constructor, program_id); } @@ -49,28 +49,27 @@ Variable::Variable(Variable&&) = default; Variable::~Variable() = default; -Variable::BindingPoint Variable::binding_point() const { +VariableBindingPoint Variable::BindingPoint() const { GroupDecoration* group = nullptr; BindingDecoration* binding = nullptr; - for (auto* deco : decorations()) { + for (auto* deco : decorations) { if (auto* g = deco->As()) { group = g; } else if (auto* b = deco->As()) { binding = b; } } - return BindingPoint{group, binding}; + return VariableBindingPoint{group, binding}; } Variable* Variable::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source()); - auto sym = ctx->Clone(symbol()); - auto* ty = ctx->Clone(type()); - auto* ctor = ctx->Clone(constructor()); - auto decos = ctx->Clone(decorations()); - return ctx->dst->create(src, sym, declared_storage_class(), - declared_access(), ty, is_const_, ctor, - decos); + auto src = ctx->Clone(source); + auto sym = ctx->Clone(symbol); + auto* ty = ctx->Clone(type); + auto* ctor = ctx->Clone(constructor); + auto decos = ctx->Clone(decorations); + return ctx->dst->create(src, sym, declared_storage_class, + declared_access, ty, is_const, ctor, decos); } } // namespace ast diff --git a/src/ast/variable.h b/src/ast/variable.h index 2cbeaf250b..b02db6e700 100644 --- a/src/ast/variable.h +++ b/src/ast/variable.h @@ -32,6 +32,18 @@ class GroupDecoration; class LocationDecoration; class Type; +/// VariableBindingPoint holds a group and binding decoration. +struct VariableBindingPoint { + /// The `[[group]]` part of the binding point + GroupDecoration* group = nullptr; + /// The `[[binding]]` part of the binding point + BindingDecoration* binding = nullptr; + + /// @returns true if the BindingPoint has a valid group and binding + /// decoration. + inline operator bool() const { return group && binding; } +}; + /// A Variable statement. /// /// An instance of this class represents one of three constructs in WGSL: "var" @@ -87,18 +99,6 @@ class Type; /// - formal parameter is always StorageClass::kNone. class Variable : public Castable { public: - /// BindingPoint holds a group and binding decoration. - struct BindingPoint { - /// The `[[group]]` part of the binding point - GroupDecoration* group = nullptr; - /// The `[[binding]]` part of the binding point - BindingDecoration* binding = nullptr; - - /// @returns true if the BindingPoint has a valid group and binding - /// decoration. - inline operator bool() const { return group && binding; } - }; - /// Create a variable /// @param program_id the identifier of the program that owns this node /// @param source the variable source @@ -123,33 +123,8 @@ class Variable : public Castable { ~Variable() override; - /// @returns the variable symbol - const Symbol& symbol() const { return symbol_; } - - /// @returns the variable type - ast::Type* type() const { return const_cast(type_); } - - /// @returns the declared storage class - StorageClass declared_storage_class() const { - return declared_storage_class_; - } - - /// @returns the declared access control - Access declared_access() const { return declared_access_; } - - /// @returns the constructor expression or nullptr if none set - Expression* constructor() const { return constructor_; } - /// @returns true if the variable has an constructor - bool has_constructor() const { return constructor_ != nullptr; } - - /// @returns true if this is a constant, false otherwise - bool is_const() const { return is_const_; } - - /// @returns the decorations attached to this variable - const DecorationList& decorations() const { return decorations_; } - /// @returns the binding point information for the variable - BindingPoint binding_point() const; + VariableBindingPoint BindingPoint() const; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -157,17 +132,29 @@ class Variable : public Castable { /// @return the newly cloned node Variable* Clone(CloneContext* ctx) const override; + /// The variable symbol + Symbol const symbol; + + /// The variable type + ast::Type* const type; + + /// True if this is a constant, false otherwise + bool const is_const; + + /// The constructor expression or nullptr if none set + Expression* const constructor; + + /// The decorations attached to this variable + DecorationList const decorations; + + /// The declared storage class + StorageClass const declared_storage_class; + + /// The declared access control + Access const declared_access; + private: Variable(const Variable&) = delete; - - Symbol const symbol_; - // The value type if a const or formal paramter, and the store type if a var - ast::Type const* const type_; - bool const is_const_; - Expression* const constructor_; - DecorationList const decorations_; - StorageClass const declared_storage_class_; - Access const declared_access_; }; /// A list of variables diff --git a/src/ast/variable_decl_statement.cc b/src/ast/variable_decl_statement.cc index b686a8383d..d4ffaca9d9 100644 --- a/src/ast/variable_decl_statement.cc +++ b/src/ast/variable_decl_statement.cc @@ -21,12 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::VariableDeclStatement); namespace tint { namespace ast { -VariableDeclStatement::VariableDeclStatement(ProgramID program_id, - const Source& source, - Variable* variable) - : Base(program_id, source), variable_(variable) { - TINT_ASSERT(AST, variable_); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, variable_, program_id); +VariableDeclStatement::VariableDeclStatement(ProgramID pid, + const Source& src, + Variable* var) + : Base(pid, src), variable(var) { + TINT_ASSERT(AST, variable); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, variable, program_id); } VariableDeclStatement::VariableDeclStatement(VariableDeclStatement&&) = default; @@ -35,8 +35,8 @@ VariableDeclStatement::~VariableDeclStatement() = default; VariableDeclStatement* VariableDeclStatement::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* var = ctx->Clone(variable()); + auto src = ctx->Clone(source); + auto* var = ctx->Clone(variable); return ctx->dst->create(src, var); } diff --git a/src/ast/variable_decl_statement.h b/src/ast/variable_decl_statement.h index f1b3083260..ef67ded978 100644 --- a/src/ast/variable_decl_statement.h +++ b/src/ast/variable_decl_statement.h @@ -36,19 +36,17 @@ class VariableDeclStatement VariableDeclStatement(VariableDeclStatement&&); ~VariableDeclStatement() override; - /// @returns the variable - Variable* variable() const { return variable_; } - /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node VariableDeclStatement* Clone(CloneContext* ctx) const override; + /// The variable + Variable* const variable; + private: VariableDeclStatement(const VariableDeclStatement&) = delete; - - Variable* const variable_; }; } // namespace ast diff --git a/src/ast/variable_decl_statement_test.cc b/src/ast/variable_decl_statement_test.cc index cb619672c6..bcf92adb5d 100644 --- a/src/ast/variable_decl_statement_test.cc +++ b/src/ast/variable_decl_statement_test.cc @@ -27,7 +27,7 @@ TEST_F(VariableDeclStatementTest, Creation) { auto* var = Var("a", ty.f32(), StorageClass::kNone); auto* stmt = create(var); - EXPECT_EQ(stmt->variable(), var); + EXPECT_EQ(stmt->variable, var); } TEST_F(VariableDeclStatementTest, Creation_WithSource) { @@ -35,7 +35,7 @@ TEST_F(VariableDeclStatementTest, Creation_WithSource) { auto* stmt = create(Source{Source::Location{20, 2}}, var); - auto src = stmt->source(); + auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } diff --git a/src/ast/variable_test.cc b/src/ast/variable_test.cc index 9f29307494..a78775bdaa 100644 --- a/src/ast/variable_test.cc +++ b/src/ast/variable_test.cc @@ -25,13 +25,13 @@ using VariableTest = TestHelper; TEST_F(VariableTest, Creation) { auto* v = Var("my_var", ty.i32(), StorageClass::kFunction); - EXPECT_EQ(v->symbol(), Symbol(1, ID())); - EXPECT_EQ(v->declared_storage_class(), StorageClass::kFunction); - EXPECT_TRUE(v->type()->Is()); - EXPECT_EQ(v->source().range.begin.line, 0u); - EXPECT_EQ(v->source().range.begin.column, 0u); - EXPECT_EQ(v->source().range.end.line, 0u); - EXPECT_EQ(v->source().range.end.column, 0u); + EXPECT_EQ(v->symbol, Symbol(1, ID())); + EXPECT_EQ(v->declared_storage_class, StorageClass::kFunction); + EXPECT_TRUE(v->type->Is()); + EXPECT_EQ(v->source.range.begin.line, 0u); + EXPECT_EQ(v->source.range.begin.column, 0u); + EXPECT_EQ(v->source.range.end.line, 0u); + EXPECT_EQ(v->source.range.end.column, 0u); } TEST_F(VariableTest, CreationWithSource) { @@ -39,13 +39,13 @@ TEST_F(VariableTest, CreationWithSource) { Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i", ty.f32(), StorageClass::kPrivate, nullptr, DecorationList{}); - EXPECT_EQ(v->symbol(), Symbol(1, ID())); - EXPECT_EQ(v->declared_storage_class(), StorageClass::kPrivate); - EXPECT_TRUE(v->type()->Is()); - EXPECT_EQ(v->source().range.begin.line, 27u); - EXPECT_EQ(v->source().range.begin.column, 4u); - EXPECT_EQ(v->source().range.end.line, 27u); - EXPECT_EQ(v->source().range.end.column, 5u); + EXPECT_EQ(v->symbol, Symbol(1, ID())); + EXPECT_EQ(v->declared_storage_class, StorageClass::kPrivate); + EXPECT_TRUE(v->type->Is()); + EXPECT_EQ(v->source.range.begin.line, 27u); + EXPECT_EQ(v->source.range.begin.column, 4u); + EXPECT_EQ(v->source.range.end.line, 27u); + EXPECT_EQ(v->source.range.end.column, 5u); } TEST_F(VariableTest, CreationEmpty) { @@ -53,13 +53,13 @@ TEST_F(VariableTest, CreationEmpty) { Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var", ty.i32(), StorageClass::kWorkgroup, nullptr, DecorationList{}); - EXPECT_EQ(v->symbol(), Symbol(1, ID())); - EXPECT_EQ(v->declared_storage_class(), StorageClass::kWorkgroup); - EXPECT_TRUE(v->type()->Is()); - EXPECT_EQ(v->source().range.begin.line, 27u); - EXPECT_EQ(v->source().range.begin.column, 4u); - EXPECT_EQ(v->source().range.end.line, 27u); - EXPECT_EQ(v->source().range.end.column, 7u); + EXPECT_EQ(v->symbol, Symbol(1, ID())); + EXPECT_EQ(v->declared_storage_class, StorageClass::kWorkgroup); + EXPECT_TRUE(v->type->Is()); + EXPECT_EQ(v->source.range.begin.line, 27u); + EXPECT_EQ(v->source.range.begin.column, 4u); + EXPECT_EQ(v->source.range.end.line, 27u); + EXPECT_EQ(v->source.range.end.column, 7u); } TEST_F(VariableTest, Assert_MissingSymbol) { @@ -99,14 +99,14 @@ TEST_F(VariableTest, WithDecorations) { create(1200), }); - auto& decorations = var->decorations(); + auto& decorations = var->decorations; EXPECT_TRUE(ast::HasDecoration(decorations)); EXPECT_TRUE(ast::HasDecoration(decorations)); EXPECT_TRUE(ast::HasDecoration(decorations)); auto* location = ast::GetDecoration(decorations); ASSERT_NE(nullptr, location); - EXPECT_EQ(1u, location->value()); + EXPECT_EQ(1u, location->value); } TEST_F(VariableTest, BindingPoint) { @@ -115,19 +115,19 @@ TEST_F(VariableTest, BindingPoint) { create(2), create(1), }); - EXPECT_TRUE(var->binding_point()); - ASSERT_NE(var->binding_point().binding, nullptr); - ASSERT_NE(var->binding_point().group, nullptr); - EXPECT_EQ(var->binding_point().binding->value(), 2u); - EXPECT_EQ(var->binding_point().group->value(), 1u); + EXPECT_TRUE(var->BindingPoint()); + ASSERT_NE(var->BindingPoint().binding, nullptr); + ASSERT_NE(var->BindingPoint().group, nullptr); + EXPECT_EQ(var->BindingPoint().binding->value, 2u); + EXPECT_EQ(var->BindingPoint().group->value, 1u); } TEST_F(VariableTest, BindingPointoDecorations) { auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr, DecorationList{}); - EXPECT_FALSE(var->binding_point()); - EXPECT_EQ(var->binding_point().group, nullptr); - EXPECT_EQ(var->binding_point().binding, nullptr); + EXPECT_FALSE(var->BindingPoint()); + EXPECT_EQ(var->BindingPoint().group, nullptr); + EXPECT_EQ(var->BindingPoint().binding, nullptr); } TEST_F(VariableTest, BindingPointMissingGroupDecoration) { @@ -135,19 +135,19 @@ TEST_F(VariableTest, BindingPointMissingGroupDecoration) { DecorationList{ create(2), }); - EXPECT_FALSE(var->binding_point()); - ASSERT_NE(var->binding_point().binding, nullptr); - EXPECT_EQ(var->binding_point().binding->value(), 2u); - EXPECT_EQ(var->binding_point().group, nullptr); + EXPECT_FALSE(var->BindingPoint()); + ASSERT_NE(var->BindingPoint().binding, nullptr); + EXPECT_EQ(var->BindingPoint().binding->value, 2u); + EXPECT_EQ(var->BindingPoint().group, nullptr); } TEST_F(VariableTest, BindingPointMissingBindingDecoration) { auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr, DecorationList{create(1)}); - EXPECT_FALSE(var->binding_point()); - ASSERT_NE(var->binding_point().group, nullptr); - EXPECT_EQ(var->binding_point().group->value(), 1u); - EXPECT_EQ(var->binding_point().binding, nullptr); + EXPECT_FALSE(var->BindingPoint()); + ASSERT_NE(var->BindingPoint().group, nullptr); + EXPECT_EQ(var->BindingPoint().group->value, 1u); + EXPECT_EQ(var->BindingPoint().binding, nullptr); } } // namespace diff --git a/src/ast/vector.cc b/src/ast/vector.cc index b3d6d89f45..4fdd60eb4b 100644 --- a/src/ast/vector.cc +++ b/src/ast/vector.cc @@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Vector); namespace tint { namespace ast { -Vector::Vector(ProgramID program_id, - const Source& source, +Vector::Vector(ProgramID pid, + const Source& src, Type const* subtype, - uint32_t size) - : Base(program_id, source), subtype_(subtype), size_(size) { + uint32_t w) + : Base(pid, src), type(const_cast(subtype)), width(w) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, subtype, program_id); - TINT_ASSERT(AST, size_ > 1); - TINT_ASSERT(AST, size_ < 5); + TINT_ASSERT(AST, width > 1); + TINT_ASSERT(AST, width < 5); } Vector::Vector(Vector&&) = default; @@ -37,15 +37,15 @@ Vector::~Vector() = default; std::string Vector::FriendlyName(const SymbolTable& symbols) const { std::ostringstream out; - out << "vec" << size_ << "<" << subtype_->FriendlyName(symbols) << ">"; + out << "vec" << width << "<" << type->FriendlyName(symbols) << ">"; return out.str(); } Vector* Vector::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* ty = ctx->Clone(type()); - return ctx->dst->create(src, ty, size_); + auto src = ctx->Clone(source); + auto* ty = ctx->Clone(type); + return ctx->dst->create(src, ty, width); } } // namespace ast diff --git a/src/ast/vector.h b/src/ast/vector.h index 9a6f402592..91a53c5fbd 100644 --- a/src/ast/vector.h +++ b/src/ast/vector.h @@ -26,23 +26,15 @@ namespace ast { class Vector : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param subtype the vector element type - /// @param size the number of elements in the vector - Vector(ProgramID program_id, - const Source& source, - Type const* subtype, - uint32_t size); + /// @param width the number of elements in the vector + Vector(ProgramID pid, const Source& src, Type const* subtype, uint32_t width); /// Move constructor Vector(Vector&&); ~Vector() override; - /// @returns the type of the vector elements - Type* type() const { return const_cast(subtype_); } - /// @returns the size of the vector - uint32_t size() const { return size_; } - /// @param symbols the program's symbol table /// @returns the name for this type that closely resembles how it would be /// declared in WGSL. @@ -53,9 +45,11 @@ class Vector : public Castable { /// @return the newly cloned type Vector* Clone(CloneContext* ctx) const override; - private: - Type const* const subtype_; - uint32_t const size_; + /// The type of the vector elements + Type* const type; + + /// The number of elements in the vector + uint32_t const width; }; } // namespace ast diff --git a/src/ast/vector_test.cc b/src/ast/vector_test.cc index 4cbbc71ceb..87cff03109 100644 --- a/src/ast/vector_test.cc +++ b/src/ast/vector_test.cc @@ -26,8 +26,8 @@ using AstVectorTest = TestHelper; TEST_F(AstVectorTest, Creation) { auto* i32 = create(); auto* v = create(i32, 2); - EXPECT_EQ(v->type(), i32); - EXPECT_EQ(v->size(), 2u); + EXPECT_EQ(v->type, i32); + EXPECT_EQ(v->width, 2u); } TEST_F(AstVectorTest, FriendlyName) { diff --git a/src/ast/void.cc b/src/ast/void.cc index a96d5f02fc..427d82755a 100644 --- a/src/ast/void.cc +++ b/src/ast/void.cc @@ -21,8 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Void); namespace tint { namespace ast { -Void::Void(ProgramID program_id, const Source& source) - : Base(program_id, source) {} +Void::Void(ProgramID pid, const Source& src) : Base(pid, src) {} Void::Void(Void&&) = default; @@ -33,7 +32,7 @@ std::string Void::FriendlyName(const SymbolTable&) const { } Void* Void::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source()); + auto src = ctx->Clone(source); return ctx->dst->create(src); } diff --git a/src/ast/void.h b/src/ast/void.h index 94e0fda0aa..46cb3a23d5 100644 --- a/src/ast/void.h +++ b/src/ast/void.h @@ -26,9 +26,9 @@ namespace ast { class Void : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this node - Void(ProgramID program_id, const Source& source); + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node + Void(ProgramID pid, const Source& src); /// Move constructor Void(Void&&); ~Void() override; diff --git a/src/ast/workgroup_decoration.cc b/src/ast/workgroup_decoration.cc index 9b346aa8c9..271bb85506 100644 --- a/src/ast/workgroup_decoration.cc +++ b/src/ast/workgroup_decoration.cc @@ -23,26 +23,26 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::WorkgroupDecoration); namespace tint { namespace ast { -WorkgroupDecoration::WorkgroupDecoration(ProgramID program_id, - const Source& source, - ast::Expression* x, - ast::Expression* y, - ast::Expression* z) - : Base(program_id, source), x_(x), y_(y), z_(z) {} +WorkgroupDecoration::WorkgroupDecoration(ProgramID pid, + const Source& src, + ast::Expression* x_, + ast::Expression* y_, + ast::Expression* z_) + : Base(pid, src), x(x_), y(y_), z(z_) {} WorkgroupDecoration::~WorkgroupDecoration() = default; -std::string WorkgroupDecoration::name() const { +std::string WorkgroupDecoration::Name() const { return "workgroup_size"; } WorkgroupDecoration* WorkgroupDecoration::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source()); - auto* x = ctx->Clone(x_); - auto* y = ctx->Clone(y_); - auto* z = ctx->Clone(z_); - return ctx->dst->create(src, x, y, z); + auto src = ctx->Clone(source); + auto* x_ = ctx->Clone(x); + auto* y_ = ctx->Clone(y); + auto* z_ = ctx->Clone(z); + return ctx->dst->create(src, x_, y_, z_); } } // namespace ast diff --git a/src/ast/workgroup_decoration.h b/src/ast/workgroup_decoration.h index f9d8e56f39..daae3f0ece 100644 --- a/src/ast/workgroup_decoration.h +++ b/src/ast/workgroup_decoration.h @@ -30,13 +30,13 @@ class Expression; class WorkgroupDecoration : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node - /// @param source the source of this decoration + /// @param pid the identifier of the program that owns this node + /// @param src the source of this node /// @param x the workgroup x dimension expression /// @param y the optional workgroup y dimension expression /// @param z the optional workgroup z dimension expression - WorkgroupDecoration(ProgramID program_id, - const Source& source, + WorkgroupDecoration(ProgramID pid, + const Source& src, ast::Expression* x, ast::Expression* y = nullptr, ast::Expression* z = nullptr); @@ -44,10 +44,10 @@ class WorkgroupDecoration : public Castable { ~WorkgroupDecoration() override; /// @returns the workgroup dimensions - std::array values() const { return {x_, y_, z_}; } + std::array Values() const { return {x, y, z}; } /// @returns the WGSL name for the decoration - std::string name() const override; + std::string Name() const override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -55,10 +55,12 @@ class WorkgroupDecoration : public Castable { /// @return the newly cloned node WorkgroupDecoration* Clone(CloneContext* ctx) const override; - private: - ast::Expression* const x_ = nullptr; - ast::Expression* const y_ = nullptr; - ast::Expression* const z_ = nullptr; + /// The workgroup x dimension. + ast::Expression* const x; + /// The optional workgroup y dimension. May be null. + ast::Expression* const y = nullptr; + /// The optional workgroup z dimension. May be null. + ast::Expression* const z = nullptr; }; } // namespace ast diff --git a/src/ast/workgroup_decoration_test.cc b/src/ast/workgroup_decoration_test.cc index f437c63fad..cbf7ee8aef 100644 --- a/src/ast/workgroup_decoration_test.cc +++ b/src/ast/workgroup_decoration_test.cc @@ -25,75 +25,75 @@ using WorkgroupDecorationTest = TestHelper; TEST_F(WorkgroupDecorationTest, Creation_1param) { auto* d = WorkgroupSize(2); - auto values = d->values(); + auto values = d->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_TRUE(x_scalar); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 2u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 2u); EXPECT_EQ(values[1], nullptr); EXPECT_EQ(values[2], nullptr); } TEST_F(WorkgroupDecorationTest, Creation_2param) { auto* d = WorkgroupSize(2, 4); - auto values = d->values(); + auto values = d->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_TRUE(x_scalar); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 2u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 2u); ASSERT_NE(values[1], nullptr); auto* y_scalar = values[1]->As(); ASSERT_TRUE(y_scalar); - ASSERT_TRUE(y_scalar->literal()->Is()); - EXPECT_EQ(y_scalar->literal()->As()->value_as_u32(), 4u); + ASSERT_TRUE(y_scalar->literal->Is()); + EXPECT_EQ(y_scalar->literal->As()->ValueAsU32(), 4u); EXPECT_EQ(values[2], nullptr); } TEST_F(WorkgroupDecorationTest, Creation_3param) { auto* d = WorkgroupSize(2, 4, 6); - auto values = d->values(); + auto values = d->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_TRUE(x_scalar); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 2u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 2u); ASSERT_NE(values[1], nullptr); auto* y_scalar = values[1]->As(); ASSERT_TRUE(y_scalar); - ASSERT_TRUE(y_scalar->literal()->Is()); - EXPECT_EQ(y_scalar->literal()->As()->value_as_u32(), 4u); + ASSERT_TRUE(y_scalar->literal->Is()); + EXPECT_EQ(y_scalar->literal->As()->ValueAsU32(), 4u); ASSERT_NE(values[2], nullptr); auto* z_scalar = values[2]->As(); ASSERT_TRUE(z_scalar); - ASSERT_TRUE(z_scalar->literal()->Is()); - EXPECT_EQ(z_scalar->literal()->As()->value_as_u32(), 6u); + ASSERT_TRUE(z_scalar->literal->Is()); + EXPECT_EQ(z_scalar->literal->As()->ValueAsU32(), 6u); } TEST_F(WorkgroupDecorationTest, Creation_WithIdentifier) { auto* d = WorkgroupSize(2, 4, "depth"); - auto values = d->values(); + auto values = d->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_TRUE(x_scalar); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 2u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 2u); ASSERT_NE(values[1], nullptr); auto* y_scalar = values[1]->As(); ASSERT_TRUE(y_scalar); - ASSERT_TRUE(y_scalar->literal()->Is()); - EXPECT_EQ(y_scalar->literal()->As()->value_as_u32(), 4u); + ASSERT_TRUE(y_scalar->literal->Is()); + EXPECT_EQ(y_scalar->literal->As()->ValueAsU32(), 4u); ASSERT_NE(values[2], nullptr); auto* z_ident = values[2]->As(); ASSERT_TRUE(z_ident); - EXPECT_EQ(Symbols().NameFor(z_ident->symbol()), "depth"); + EXPECT_EQ(Symbols().NameFor(z_ident->symbol), "depth"); } } // namespace diff --git a/src/clone_context.h b/src/clone_context.h index 4f72d2f420..04f5dac0e4 100644 --- a/src/clone_context.h +++ b/src/clone_context.h @@ -255,8 +255,8 @@ class CloneContext { /// CloneCtx ctx(&out, in); /// ctx.ReplaceAll([&] (ast::UintLiteral* l) { /// return ctx->dst->create( - /// ctx->Clone(l->source()), - /// ctx->Clone(l->type()), + /// ctx->Clone(l->source), + /// ctx->Clone(l->type), /// 42); /// }); /// ctx.Clone(); diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index d4fa7443ac..fe64df1876 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -114,8 +114,8 @@ std::tuple CalculateInterpolationData( return {InterpolationType::kPerspective, InterpolationSampling::kCenter}; } - auto interpolation_type = interpolation_decoration->type(); - auto sampling = interpolation_decoration->sampling(); + auto interpolation_type = interpolation_decoration->type; + auto sampling = interpolation_decoration->sampling; if (interpolation_type != ast::InterpolationType::kFlat && sampling == ast::InterpolationSampling::kNone) { sampling = ast::InterpolationSampling::kCenter; @@ -141,9 +141,9 @@ std::vector Inspector::GetEntryPoints() { auto* sem = program_->Sem().Get(func); EntryPoint entry_point; - entry_point.name = program_->Symbols().NameFor(func->symbol()); - entry_point.remapped_name = program_->Symbols().NameFor(func->symbol()); - entry_point.stage = func->pipeline_stage(); + entry_point.name = program_->Symbols().NameFor(func->symbol); + entry_point.remapped_name = program_->Symbols().NameFor(func->symbol); + entry_point.stage = func->PipelineStage(); auto wgsize = sem->workgroup_size(); entry_point.workgroup_size_x = wgsize[0].value; @@ -157,41 +157,41 @@ std::vector Inspector::GetEntryPoints() { for (auto* param : sem->Parameters()) { AddEntryPointInOutVariables( - program_->Symbols().NameFor(param->Declaration()->symbol()), - param->Type(), param->Declaration()->decorations(), + program_->Symbols().NameFor(param->Declaration()->symbol), + param->Type(), param->Declaration()->decorations, entry_point.input_variables); entry_point.input_position_used |= ContainsBuiltin(ast::Builtin::kPosition, param->Type(), - param->Declaration()->decorations()); + param->Declaration()->decorations); entry_point.front_facing_used |= ContainsBuiltin(ast::Builtin::kFrontFacing, param->Type(), - param->Declaration()->decorations()); + param->Declaration()->decorations); entry_point.sample_index_used |= ContainsBuiltin(ast::Builtin::kSampleIndex, param->Type(), - param->Declaration()->decorations()); + param->Declaration()->decorations); entry_point.input_sample_mask_used |= ContainsBuiltin(ast::Builtin::kSampleMask, param->Type(), - param->Declaration()->decorations()); + param->Declaration()->decorations); entry_point.num_workgroups_used |= ContainsBuiltin(ast::Builtin::kNumWorkgroups, param->Type(), - param->Declaration()->decorations()); + param->Declaration()->decorations); } if (!sem->ReturnType()->Is()) { AddEntryPointInOutVariables("", sem->ReturnType(), - func->return_type_decorations(), + func->return_type_decorations, entry_point.output_variables); entry_point.output_sample_mask_used = ContainsBuiltin(ast::Builtin::kSampleMask, sem->ReturnType(), - func->return_type_decorations()); + func->return_type_decorations); } for (auto* var : sem->ReferencedModuleVariables()) { auto* decl = var->Declaration(); - auto name = program_->Symbols().NameFor(decl->symbol()); + auto name = program_->Symbols().NameFor(decl->symbol); auto* global = var->As(); if (global && global->IsPipelineConstant()) { @@ -212,7 +212,7 @@ std::vector Inspector::GetEntryPoints() { } overridable_constant.is_initialized = - global->Declaration()->has_constructor(); + global->Declaration()->constructor; entry_point.overridable_constants.push_back(overridable_constant); } @@ -254,12 +254,12 @@ std::map Inspector::GetConstantIDs() { continue; } - if (!var->has_constructor()) { + if (!var->constructor) { result[constant_id] = Scalar(); continue; } - auto* expression = var->constructor(); + auto* expression = var->constructor; auto* constructor = expression->As(); if (constructor == nullptr) { // This is invalid WGSL, but handling gracefully. @@ -275,7 +275,7 @@ std::map Inspector::GetConstantIDs() { continue; } - auto* literal = scalar_constructor->literal(); + auto* literal = scalar_constructor->literal; if (!literal) { // This is invalid WGSL, but handling gracefully. result[constant_id] = Scalar(); @@ -283,22 +283,22 @@ std::map Inspector::GetConstantIDs() { } if (auto* l = literal->As()) { - result[constant_id] = Scalar(l->IsTrue()); + result[constant_id] = Scalar(l->value); continue; } if (auto* l = literal->As()) { - result[constant_id] = Scalar(l->value()); + result[constant_id] = Scalar(l->value); continue; } if (auto* l = literal->As()) { - result[constant_id] = Scalar(l->value()); + result[constant_id] = Scalar(l->value); continue; } if (auto* l = literal->As()) { - result[constant_id] = Scalar(l->value()); + result[constant_id] = Scalar(l->value); continue; } @@ -313,7 +313,7 @@ std::map Inspector::GetConstantNameToIdMap() { for (auto* var : program_->AST().GlobalVariables()) { auto* global = program_->Sem().Get(var); if (global && global->IsPipelineConstant()) { - auto name = program_->Symbols().NameFor(var->symbol()); + auto name = program_->Symbols().NameFor(var->symbol); result[name] = global->ConstantId(); } } @@ -400,8 +400,8 @@ std::vector Inspector::GetUniformBufferResourceBindings( ResourceBinding entry; entry.resource_type = ResourceBinding::ResourceType::kUniformBuffer; - entry.bind_group = binding_info.group->value(); - entry.binding = binding_info.binding->value(); + entry.bind_group = binding_info.group->value; + entry.binding = binding_info.binding->value; entry.size = str->Size(); entry.size_no_padding = str->SizeNoPadding(); @@ -437,8 +437,8 @@ std::vector Inspector::GetSamplerResourceBindings( ResourceBinding entry; entry.resource_type = ResourceBinding::ResourceType::kSampler; - entry.bind_group = binding_info.group->value(); - entry.binding = binding_info.binding->value(); + entry.bind_group = binding_info.group->value; + entry.binding = binding_info.binding->value; result.push_back(entry); } @@ -461,8 +461,8 @@ std::vector Inspector::GetComparisonSamplerResourceBindings( ResourceBinding entry; entry.resource_type = ResourceBinding::ResourceType::kComparisonSampler; - entry.bind_group = binding_info.group->value(); - entry.binding = binding_info.binding->value(); + entry.bind_group = binding_info.group->value; + entry.binding = binding_info.binding->value; result.push_back(entry); } @@ -503,8 +503,8 @@ std::vector Inspector::GetTextureResourceBindings( ResourceBinding entry; entry.resource_type = resource_type; - entry.bind_group = binding_info.group->value(); - entry.binding = binding_info.binding->value(); + entry.bind_group = binding_info.group->value; + entry.binding = binding_info.binding->value; auto* tex = var->Type()->UnwrapRef()->As(); entry.dim = @@ -612,8 +612,8 @@ void Inspector::AddEntryPointInOutVariables( for (auto* member : struct_ty->Members()) { AddEntryPointInOutVariables( name + "." + - program_->Symbols().NameFor(member->Declaration()->symbol()), - member->Type(), member->Declaration()->decorations(), variables); + program_->Symbols().NameFor(member->Declaration()->symbol), + member->Type(), member->Declaration()->decorations, variables); } return; } @@ -628,7 +628,7 @@ void Inspector::AddEntryPointInOutVariables( auto* location = ast::GetDecoration(decorations); TINT_ASSERT(Inspector, location != nullptr); stage_variable.has_location_decoration = true; - stage_variable.location_decoration = location->value(); + stage_variable.location_decoration = location->value; std::tie(stage_variable.interpolation_type, stage_variable.interpolation_sampling) = @@ -646,7 +646,7 @@ bool Inspector::ContainsBuiltin(ast::Builtin builtin, // Recurse into members. for (auto* member : struct_ty->Members()) { if (ContainsBuiltin(builtin, member->Type(), - member->Declaration()->decorations())) { + member->Declaration()->decorations)) { return true; } } @@ -656,7 +656,7 @@ bool Inspector::ContainsBuiltin(ast::Builtin builtin, // Base case: check for builtin auto* builtin_declaration = ast::GetDecoration(decorations); - if (!builtin_declaration || builtin_declaration->value() != builtin) { + if (!builtin_declaration || builtin_declaration->builtin != builtin) { return false; } @@ -690,8 +690,8 @@ std::vector Inspector::GetStorageBufferResourceBindingsImpl( entry.resource_type = read_only ? ResourceBinding::ResourceType::kReadOnlyStorageBuffer : ResourceBinding::ResourceType::kStorageBuffer; - entry.bind_group = binding_info.group->value(); - entry.binding = binding_info.binding->value(); + entry.bind_group = binding_info.group->value; + entry.binding = binding_info.binding->value; entry.size = str->Size(); entry.size_no_padding = str->SizeNoPadding(); @@ -722,8 +722,8 @@ std::vector Inspector::GetSampledTextureResourceBindingsImpl( entry.resource_type = multisampled_only ? ResourceBinding::ResourceType::kMultisampledTexture : ResourceBinding::ResourceType::kSampledTexture; - entry.bind_group = binding_info.group->value(); - entry.binding = binding_info.binding->value(); + entry.bind_group = binding_info.group->value; + entry.binding = binding_info.binding->value; auto* texture_type = var->Type()->UnwrapRef()->As(); entry.dim = TypeTextureDimensionToResourceBindingTextureDimension( @@ -761,8 +761,8 @@ std::vector Inspector::GetStorageTextureResourceBindingsImpl( ResourceBinding entry; entry.resource_type = ResourceBinding::ResourceType::kWriteOnlyStorageTexture; - entry.bind_group = binding_info.group->value(); - entry.binding = binding_info.binding->value(); + entry.bind_group = binding_info.group->value; + entry.binding = binding_info.binding->value; entry.dim = TypeTextureDimensionToResourceBindingTextureDimension( texture_type->dim()); @@ -820,7 +820,7 @@ void Inspector::GenerateSamplerTargets() { auto* call_func = call->Stmt()->Function(); std::vector entry_points; if (call_func->IsEntryPoint()) { - entry_points = {call_func->symbol()}; + entry_points = {call_func->symbol}; } else { entry_points = sem.Get(call_func)->AncestorEntryPoints(); } @@ -829,21 +829,21 @@ void Inspector::GenerateSamplerTargets() { continue; } - auto* t = c->args()[texture_index]; - auto* s = c->args()[sampler_index]; + auto* t = c->args[texture_index]; + auto* s = c->args[sampler_index]; GetOriginatingResources( std::array{t, s}, [&](std::array globals) { auto* texture = globals[0]; sem::BindingPoint texture_binding_point = { - texture->Declaration()->binding_point().group->value(), - texture->Declaration()->binding_point().binding->value()}; + texture->Declaration()->BindingPoint().group->value, + texture->Declaration()->BindingPoint().binding->value}; auto* sampler = globals[1]; sem::BindingPoint sampler_binding_point = { - sampler->Declaration()->binding_point().group->value(), - sampler->Declaration()->binding_point().binding->value()}; + sampler->Declaration()->BindingPoint().group->value, + sampler->Declaration()->BindingPoint().binding->value}; for (auto entry_point : entry_points) { const auto& ep_name = program_->Symbols().NameFor(entry_point); @@ -885,7 +885,7 @@ void Inspector::GetOriginatingResources( if (auto* local = tint::As(var)) { // Chase the variable - expr = local->Declaration()->constructor(); + expr = local->Declaration()->constructor; if (!expr) { TINT_ICE(Inspector, diagnostics_) << "resource variable had no initializer"; @@ -916,17 +916,17 @@ void Inspector::GetOriginatingResources( } if (auto* unary = tint::As(expr)) { - switch (unary->op()) { + switch (unary->op) { case ast::UnaryOp::kAddressOf: case ast::UnaryOp::kIndirection: // `*` and `&` are the only valid unary ops for a resource type, // and must be balanced in order for the program to have passed // validation. Just skip past these. - expr = unary->expr(); + expr = unary->expr; continue; default: { TINT_ICE(Inspector, diagnostics_) - << "unexpected unary op on resource: " << unary->op(); + << "unexpected unary op on resource: " << unary->op; return; } } @@ -946,7 +946,7 @@ void Inspector::GetOriginatingResources( // Patch all the parameter expressions with their argument for (size_t i = 0; i < N; i++) { if (auto* param = parameters[i]) { - call_exprs[i] = call_expr->args()[param->Index()]; + call_exprs[i] = call_expr->args[param->Index()]; } } // Now call GetOriginatingResources() with from the callsite diff --git a/src/program_builder.cc b/src/program_builder.cc index 287175c70f..f9b6bc6baa 100644 --- a/src/program_builder.cc +++ b/src/program_builder.cc @@ -65,7 +65,7 @@ ProgramBuilder ProgramBuilder::Wrap(const Program* program) { builder.id_ = program->ID(); builder.types_ = sem::Manager::Wrap(program->Types()); builder.ast_ = builder.create( - program->AST().source(), program->AST().GlobalDeclarations()); + program->AST().source, program->AST().GlobalDeclarations()); builder.sem_ = sem::Info::Wrap(program->Sem()); builder.symbols_ = program->Symbols(); builder.diagnostics_ = program->Diagnostics(); @@ -108,12 +108,12 @@ const sem::Type* ProgramBuilder::TypeOf(const ast::TypeDecl* type_decl) const { } ast::TypeName* ProgramBuilder::TypesBuilder::Of(ast::TypeDecl* decl) const { - return type_name(decl->name()); + return type_name(decl->name); } const ast::TypeName* ProgramBuilder::TypesBuilder::Of( const ast::TypeDecl* decl) const { - return type_name(decl->name()); + return type_name(decl->name); } ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {} diff --git a/src/program_builder.h b/src/program_builder.h index bc529e86b5..39a1fa3501 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -965,13 +965,13 @@ class ProgramBuilder { /// @return an ast::IdentifierExpression with the variable's symbol ast::IdentifierExpression* Expr(const Source& source, ast::Variable* variable) { - return create(source, variable->symbol()); + return create(source, variable->symbol); } /// @param variable the AST variable /// @return an ast::IdentifierExpression with the variable's symbol ast::IdentifierExpression* Expr(ast::Variable* variable) { - return create(variable->symbol()); + return create(variable->symbol); } /// @param source the source information diff --git a/src/program_builder_test.cc b/src/program_builder_test.cc index bfa9159f26..5367cdd615 100644 --- a/src/program_builder_test.cc +++ b/src/program_builder_test.cc @@ -60,7 +60,7 @@ TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) { ASSERT_EQ(inner.AST().Functions().size(), 1u); ASSERT_EQ(outer.AST().Functions().size(), 2u); EXPECT_EQ(inner.AST().Functions()[0], outer.AST().Functions()[0]); - EXPECT_EQ(outer.AST().Functions()[1]->symbol(), outer.Symbols().Get("b")); + EXPECT_EQ(outer.AST().Functions()[1]->symbol, outer.Symbols().Get("b")); EXPECT_EQ(inner.Symbols().Get("a"), outer.Symbols().Get("a")); EXPECT_TRUE(inner.Symbols().Get("a").IsValid()); EXPECT_TRUE(outer.Symbols().Get("a").IsValid()); diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 07d904f455..b9ef0c93c8 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -703,7 +703,7 @@ struct LoopStatementBuilder /// @returns true if the decorations include a SampleMask builtin bool HasBuiltinSampleMask(const ast::DecorationList& decos) { if (auto* builtin = ast::GetDecoration(decos)) { - return builtin->value() == ast::Builtin::kSampleMask; + return builtin->builtin == ast::Builtin::kSampleMask; } return false; } @@ -1061,7 +1061,7 @@ void FunctionEmitter::IncrementLocation(ast::DecorationList* decos) { // Replace this location decoration with a new one with one higher index. // The old one doesn't leak because it's kept in the builder's AST node // list. - deco = builder_.Location(loc_deco->source(), loc_deco->value() + 1); + deco = builder_.Location(loc_deco->source, loc_deco->value + 1); } } } diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index ae37f47963..89617566dd 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -1200,7 +1200,7 @@ const Type* ParserImpl::ConvertType( auto* ast_struct = create(Source{}, sym, std::move(ast_members), std::move(ast_struct_decorations)); if (num_non_writable_members == members.size()) { - read_only_struct_types_.insert(ast_struct->name()); + read_only_struct_types_.insert(ast_struct->name); } AddTypeDecl(sym, ast_struct); const auto* result = ty_.Struct(sym, std::move(ast_member_types)); diff --git a/src/reader/spirv/parser_impl_barrier_test.cc b/src/reader/spirv/parser_impl_barrier_test.cc index 1e643060a7..da4df49a41 100644 --- a/src/reader/spirv/parser_impl_barrier_test.cc +++ b/src/reader/spirv/parser_impl_barrier_test.cc @@ -68,11 +68,11 @@ TEST_F(SpvParserTest, WorkgroupBarrier) { auto* helper = program.AST().Functions().Find(program.Symbols().Get("helper")); ASSERT_NE(helper, nullptr); - ASSERT_GT(helper->body()->size(), 0u); - auto* call = helper->body()->get(0)->As(); + ASSERT_GT(helper->body->statements.size(), 0u); + auto* call = helper->body->statements[0]->As(); ASSERT_NE(call, nullptr); - EXPECT_EQ(call->expr()->args().size(), 0u); - auto* sem_call = program.Sem().Get(call->expr()); + EXPECT_EQ(call->expr->args.size(), 0u); + auto* sem_call = program.Sem().Get(call->expr); ASSERT_NE(sem_call, nullptr); auto* intrinsic = sem_call->Target()->As(); ASSERT_NE(intrinsic, nullptr); @@ -102,11 +102,11 @@ TEST_F(SpvParserTest, StorageBarrier) { auto* helper = program.AST().Functions().Find(program.Symbols().Get("helper")); ASSERT_NE(helper, nullptr); - ASSERT_GT(helper->body()->size(), 0u); - auto* call = helper->body()->get(0)->As(); + ASSERT_GT(helper->body->statements.size(), 0u); + auto* call = helper->body->statements[0]->As(); ASSERT_NE(call, nullptr); - EXPECT_EQ(call->expr()->args().size(), 0u); - auto* sem_call = program.Sem().Get(call->expr()); + EXPECT_EQ(call->expr->args.size(), 0u); + auto* sem_call = program.Sem().Get(call->expr); ASSERT_NE(sem_call, nullptr); auto* intrinsic = sem_call->Target()->As(); ASSERT_NE(intrinsic, nullptr); diff --git a/src/reader/spirv/parser_impl_convert_member_decoration_test.cc b/src/reader/spirv/parser_impl_convert_member_decoration_test.cc index d431fb5e51..ae5ebe34f0 100644 --- a/src/reader/spirv/parser_impl_convert_member_decoration_test.cc +++ b/src/reader/spirv/parser_impl_convert_member_decoration_test.cc @@ -59,7 +59,7 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Offset) { EXPECT_TRUE(result[0]->Is()); auto* offset_deco = result[0]->As(); ASSERT_NE(offset_deco, nullptr); - EXPECT_EQ(offset_deco->offset(), 8u); + EXPECT_EQ(offset_deco->offset, 8u); EXPECT_TRUE(p->error().empty()); } @@ -85,7 +85,7 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Matrix2x2_Stride_Custom) { EXPECT_TRUE(result[0]->Is()); auto* stride_deco = result[0]->As(); ASSERT_NE(stride_deco, nullptr); - EXPECT_EQ(stride_deco->stride(), 16u); + EXPECT_EQ(stride_deco->stride, 16u); EXPECT_TRUE(p->error().empty()); } @@ -111,7 +111,7 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Matrix2x4_Stride_Custom) { EXPECT_TRUE(result[0]->Is()); auto* stride_deco = result[0]->As(); ASSERT_NE(stride_deco, nullptr); - EXPECT_EQ(stride_deco->stride(), 64u); + EXPECT_EQ(stride_deco->stride, 64u); EXPECT_TRUE(p->error().empty()); } @@ -126,7 +126,7 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Matrix2x3_Stride_Custom) { EXPECT_TRUE(result[0]->Is()); auto* stride_deco = result[0]->As(); ASSERT_NE(stride_deco, nullptr); - EXPECT_EQ(stride_deco->stride(), 32u); + EXPECT_EQ(stride_deco->stride, 32u); EXPECT_TRUE(p->error().empty()); } diff --git a/src/reader/spirv/parser_type.cc b/src/reader/spirv/parser_type.cc index 7556659292..a8e03c6683 100644 --- a/src/reader/spirv/parser_type.cc +++ b/src/reader/spirv/parser_type.cc @@ -565,15 +565,15 @@ std::string I32::String() const { std::string Pointer::String() const { std::stringstream ss; - ss << "ptr<" << std::string(ast::str(storage_class)) << ", " + ss << "ptr<" << std::string(ast::ToString(storage_class)) << ", " << type->String() + ">"; return ss.str(); } std::string Reference::String() const { std::stringstream ss; - ss << "ref<" + std::string(ast::str(storage_class)) << ", " << type->String() - << ">"; + ss << "ref<" + std::string(ast::ToString(storage_class)) << ", " + << type->String() << ">"; return ss.str(); } diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index c86277a1ec..57c20ac7cd 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -419,7 +419,7 @@ Expect ParserImpl::expect_global_decl() { if (!expect("struct declaration", Token::Type::kSemicolon)) return Failure::kErrored; - register_type(builder_.Symbols().NameFor(str.value->name()), str.value); + register_type(builder_.Symbols().NameFor(str.value->name), str.value); builder_.AST().AddTypeDecl(str.value); return true; } @@ -1791,7 +1791,7 @@ Maybe ParserImpl::variable_stmt() { constructor, // constructor ast::DecorationList{}); // decorations - return create(var->source(), var); + return create(var->source, var); } // if_stmt @@ -1946,7 +1946,7 @@ Expect ParserImpl::expect_case_selectors() { } else if (!cond.matched) { break; } else if (!cond->Is()) { - return add_error(cond.value->source(), + return add_error(cond.value->source, "invalid case selector must be an integer value"); } @@ -3191,7 +3191,7 @@ bool ParserImpl::expect_decorations_consumed(const ast::DecorationList& in) { if (in.empty()) { return true; } - add_error(in[0]->source(), "unexpected decorations"); + add_error(in[0]->source, "unexpected decorations"); return false; } diff --git a/src/reader/wgsl/parser_impl_additive_expression_test.cc b/src/reader/wgsl/parser_impl_additive_expression_test.cc index 0a650fd97a..f6643d4dec 100644 --- a/src/reader/wgsl/parser_impl_additive_expression_test.cc +++ b/src/reader/wgsl/parser_impl_additive_expression_test.cc @@ -29,17 +29,17 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kAdd, rel->op()); + EXPECT_EQ(ast::BinaryOp::kAdd, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) { @@ -52,17 +52,17 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kSubtract, rel->op()); + EXPECT_EQ(ast::BinaryOp::kSubtract, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, AdditiveExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_and_expression_test.cc b/src/reader/wgsl/parser_impl_and_expression_test.cc index baebcdaea5..64f715ca03 100644 --- a/src/reader/wgsl/parser_impl_and_expression_test.cc +++ b/src/reader/wgsl/parser_impl_and_expression_test.cc @@ -29,17 +29,17 @@ TEST_F(ParserImplTest, AndExpression_Parses) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kAnd, rel->op()); + EXPECT_EQ(ast::BinaryOp::kAnd, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Register("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, AndExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_assignment_stmt_test.cc b/src/reader/wgsl/parser_impl_assignment_stmt_test.cc index 07c59e948e..ef4ec979c5 100644 --- a/src/reader/wgsl/parser_impl_assignment_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_assignment_stmt_test.cc @@ -28,20 +28,20 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_NE(e->lhs(), nullptr); - ASSERT_NE(e->rhs(), nullptr); + ASSERT_NE(e->lhs, nullptr); + ASSERT_NE(e->rhs, nullptr); - ASSERT_TRUE(e->lhs()->Is()); - auto* ident = e->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(e->lhs->Is()); + auto* ident = e->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(e->rhs()->Is()); - ASSERT_TRUE(e->rhs()->Is()); + ASSERT_TRUE(e->rhs->Is()); + ASSERT_TRUE(e->rhs->Is()); - auto* init = e->rhs()->As(); - ASSERT_NE(init->literal(), nullptr); - ASSERT_TRUE(init->literal()->Is()); - EXPECT_EQ(init->literal()->As()->value(), 123); + auto* init = e->rhs->As(); + ASSERT_NE(init->literal, nullptr); + ASSERT_TRUE(init->literal->Is()); + EXPECT_EQ(init->literal->As()->value, 123); } TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) { @@ -53,49 +53,49 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_NE(e->lhs(), nullptr); - ASSERT_NE(e->rhs(), nullptr); + ASSERT_NE(e->lhs, nullptr); + ASSERT_NE(e->rhs, nullptr); - ASSERT_TRUE(e->rhs()->Is()); - ASSERT_TRUE(e->rhs()->Is()); - auto* init = e->rhs()->As(); - ASSERT_NE(init->literal(), nullptr); - ASSERT_TRUE(init->literal()->Is()); - EXPECT_EQ(init->literal()->As()->value(), 123); + ASSERT_TRUE(e->rhs->Is()); + ASSERT_TRUE(e->rhs->Is()); + auto* init = e->rhs->As(); + ASSERT_NE(init->literal, nullptr); + ASSERT_TRUE(init->literal->Is()); + EXPECT_EQ(init->literal->As()->value, 123); - ASSERT_TRUE(e->lhs()->Is()); - auto* mem = e->lhs()->As(); + ASSERT_TRUE(e->lhs->Is()); + auto* mem = e->lhs->As(); - ASSERT_TRUE(mem->member()->Is()); - auto* ident = mem->member()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("d")); + ASSERT_TRUE(mem->member->Is()); + auto* ident = mem->member->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("d")); - ASSERT_TRUE(mem->structure()->Is()); - auto* ary = mem->structure()->As(); + ASSERT_TRUE(mem->structure->Is()); + auto* ary = mem->structure->As(); - ASSERT_TRUE(ary->idx_expr()->Is()); - ASSERT_TRUE(ary->idx_expr()->Is()); - init = ary->idx_expr()->As(); - ASSERT_NE(init->literal(), nullptr); - ASSERT_TRUE(init->literal()->Is()); - EXPECT_EQ(init->literal()->As()->value(), 2); + ASSERT_TRUE(ary->index->Is()); + ASSERT_TRUE(ary->index->Is()); + init = ary->index->As(); + ASSERT_NE(init->literal, nullptr); + ASSERT_TRUE(init->literal->Is()); + EXPECT_EQ(init->literal->As()->value, 2); - ASSERT_TRUE(ary->array()->Is()); - mem = ary->array()->As(); - ASSERT_TRUE(mem->member()->Is()); - ident = mem->member()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("c")); + ASSERT_TRUE(ary->array->Is()); + mem = ary->array->As(); + ASSERT_TRUE(mem->member->Is()); + ident = mem->member->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("c")); - ASSERT_TRUE(mem->structure()->Is()); - mem = mem->structure()->As(); + ASSERT_TRUE(mem->structure->Is()); + mem = mem->structure->As(); - ASSERT_TRUE(mem->structure()->Is()); - ident = mem->structure()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(mem->structure->Is()); + ident = mem->structure->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(mem->member()->Is()); - ident = mem->member()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("b")); + ASSERT_TRUE(mem->member->Is()); + ident = mem->member->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("b")); } TEST_F(ParserImplTest, AssignmentStmt_MissingEqual) { diff --git a/src/reader/wgsl/parser_impl_body_stmt_test.cc b/src/reader/wgsl/parser_impl_body_stmt_test.cc index 73468e95b4..ee3df0af7f 100644 --- a/src/reader/wgsl/parser_impl_body_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_body_stmt_test.cc @@ -28,9 +28,9 @@ TEST_F(ParserImplTest, BodyStmt) { auto e = p->expect_body_stmt(); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(e.errored); - ASSERT_EQ(e->size(), 2u); - EXPECT_TRUE(e->get(0)->Is()); - EXPECT_TRUE(e->get(1)->Is()); + ASSERT_EQ(e->statements.size(), 2u); + EXPECT_TRUE(e->statements[0]->Is()); + EXPECT_TRUE(e->statements[1]->Is()); } TEST_F(ParserImplTest, BodyStmt_Empty) { @@ -38,7 +38,7 @@ TEST_F(ParserImplTest, BodyStmt_Empty) { auto e = p->expect_body_stmt(); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(e.errored); - EXPECT_EQ(e->size(), 0u); + EXPECT_EQ(e->statements.size(), 0u); } TEST_F(ParserImplTest, BodyStmt_InvalidStmt) { diff --git a/src/reader/wgsl/parser_impl_call_stmt_test.cc b/src/reader/wgsl/parser_impl_call_stmt_test.cc index 4e9b1055ac..e38774f869 100644 --- a/src/reader/wgsl/parser_impl_call_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_call_stmt_test.cc @@ -28,17 +28,17 @@ TEST_F(ParserImplTest, Statement_Call) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - EXPECT_EQ(e->source().range.begin.line, 1u); - EXPECT_EQ(e->source().range.begin.column, 1u); - EXPECT_EQ(e->source().range.end.line, 1u); - EXPECT_EQ(e->source().range.end.column, 2u); + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 1u); + EXPECT_EQ(e->source.range.end.line, 1u); + EXPECT_EQ(e->source.range.end.column, 2u); ASSERT_TRUE(e->Is()); - auto* c = e->As()->expr(); + auto* c = e->As()->expr; - EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("a")); - EXPECT_EQ(c->args().size(), 0u); + EXPECT_EQ(c->args.size(), 0u); } TEST_F(ParserImplTest, Statement_Call_WithParams) { @@ -50,14 +50,14 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) { EXPECT_FALSE(e.errored); ASSERT_TRUE(e->Is()); - auto* c = e->As()->expr(); + auto* c = e->As()->expr; - EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("a")); - EXPECT_EQ(c->args().size(), 3u); - EXPECT_TRUE(c->args()[0]->Is()); - EXPECT_TRUE(c->args()[1]->Is()); - EXPECT_TRUE(c->args()[2]->Is()); + EXPECT_EQ(c->args.size(), 3u); + EXPECT_TRUE(c->args[0]->Is()); + EXPECT_TRUE(c->args[1]->Is()); + EXPECT_TRUE(c->args[2]->Is()); } TEST_F(ParserImplTest, Statement_Call_WithParams_TrailingComma) { @@ -69,13 +69,13 @@ TEST_F(ParserImplTest, Statement_Call_WithParams_TrailingComma) { EXPECT_FALSE(e.errored); ASSERT_TRUE(e->Is()); - auto* c = e->As()->expr(); + auto* c = e->As()->expr; - EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("a")); - EXPECT_EQ(c->args().size(), 2u); - EXPECT_TRUE(c->args()[0]->Is()); - EXPECT_TRUE(c->args()[1]->Is()); + EXPECT_EQ(c->args.size(), 2u); + EXPECT_TRUE(c->args[0]->Is()); + EXPECT_TRUE(c->args[1]->Is()); } TEST_F(ParserImplTest, Statement_Call_Missing_RightParen) { diff --git a/src/reader/wgsl/parser_impl_case_body_test.cc b/src/reader/wgsl/parser_impl_case_body_test.cc index 6edf7c5092..0237cdbedc 100644 --- a/src/reader/wgsl/parser_impl_case_body_test.cc +++ b/src/reader/wgsl/parser_impl_case_body_test.cc @@ -26,7 +26,7 @@ TEST_F(ParserImplTest, CaseBody_Empty) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(e.errored); EXPECT_TRUE(e.matched); - EXPECT_EQ(e->size(), 0u); + EXPECT_EQ(e->statements.size(), 0u); } TEST_F(ParserImplTest, CaseBody_Statements) { @@ -38,9 +38,9 @@ TEST_F(ParserImplTest, CaseBody_Statements) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(e.errored); EXPECT_TRUE(e.matched); - ASSERT_EQ(e->size(), 2u); - EXPECT_TRUE(e->get(0)->Is()); - EXPECT_TRUE(e->get(1)->Is()); + ASSERT_EQ(e->statements.size(), 2u); + EXPECT_TRUE(e->statements[0]->Is()); + EXPECT_TRUE(e->statements[1]->Is()); } TEST_F(ParserImplTest, CaseBody_InvalidStatement) { @@ -58,8 +58,8 @@ TEST_F(ParserImplTest, CaseBody_Fallthrough) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(e.errored); EXPECT_TRUE(e.matched); - ASSERT_EQ(e->size(), 1u); - EXPECT_TRUE(e->get(0)->Is()); + ASSERT_EQ(e->statements.size(), 1u); + EXPECT_TRUE(e->statements[0]->Is()); } TEST_F(ParserImplTest, CaseBody_Fallthrough_MissingSemicolon) { diff --git a/src/reader/wgsl/parser_impl_const_expr_test.cc b/src/reader/wgsl/parser_impl_const_expr_test.cc index 3f313abe10..a37f6e0b2e 100644 --- a/src/reader/wgsl/parser_impl_const_expr_test.cc +++ b/src/reader/wgsl/parser_impl_const_expr_test.cc @@ -28,23 +28,23 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) { ASSERT_TRUE(e->Is()); auto* t = e->As(); - ASSERT_TRUE(t->type()->Is()); - EXPECT_EQ(t->type()->As()->size(), 2u); + ASSERT_TRUE(t->type->Is()); + EXPECT_EQ(t->type->As()->width, 2u); - ASSERT_EQ(t->values().size(), 2u); - auto& v = t->values(); + ASSERT_EQ(t->values.size(), 2u); + auto& v = t->values; ASSERT_TRUE(v[0]->Is()); ASSERT_TRUE(v[0]->Is()); auto* c = v[0]->As(); - ASSERT_TRUE(c->literal()->Is()); - EXPECT_FLOAT_EQ(c->literal()->As()->value(), 1.); + ASSERT_TRUE(c->literal->Is()); + EXPECT_FLOAT_EQ(c->literal->As()->value, 1.); ASSERT_TRUE(v[1]->Is()); ASSERT_TRUE(v[1]->Is()); c = v[1]->As(); - ASSERT_TRUE(c->literal()->Is()); - EXPECT_FLOAT_EQ(c->literal()->As()->value(), 2.); + ASSERT_TRUE(c->literal->Is()); + EXPECT_FLOAT_EQ(c->literal->As()->value, 2.); } TEST_F(ParserImplTest, ConstExpr_TypeDecl_Empty) { @@ -56,10 +56,10 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl_Empty) { ASSERT_TRUE(e->Is()); auto* t = e->As(); - ASSERT_TRUE(t->type()->Is()); - EXPECT_EQ(t->type()->As()->size(), 2u); + ASSERT_TRUE(t->type->Is()); + EXPECT_EQ(t->type->As()->width, 2u); - ASSERT_EQ(t->values().size(), 0u); + ASSERT_EQ(t->values.size(), 0u); } TEST_F(ParserImplTest, ConstExpr_TypeDecl_TrailingComma) { @@ -71,12 +71,12 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl_TrailingComma) { ASSERT_TRUE(e->Is()); auto* t = e->As(); - ASSERT_TRUE(t->type()->Is()); - EXPECT_EQ(t->type()->As()->size(), 2u); + ASSERT_TRUE(t->type->Is()); + EXPECT_EQ(t->type->As()->width, 2u); - ASSERT_EQ(t->values().size(), 2u); - ASSERT_TRUE(t->values()[0]->Is()); - ASSERT_TRUE(t->values()[1]->Is()); + ASSERT_EQ(t->values.size(), 2u); + ASSERT_TRUE(t->values[0]->Is()); + ASSERT_TRUE(t->values[1]->Is()); } TEST_F(ParserImplTest, ConstExpr_TypeDecl_MissingRightParen) { @@ -124,8 +124,8 @@ TEST_F(ParserImplTest, ConstExpr_ConstLiteral) { ASSERT_TRUE(e->Is()); ASSERT_TRUE(e->Is()); auto* c = e->As(); - ASSERT_TRUE(c->literal()->Is()); - EXPECT_TRUE(c->literal()->As()->IsTrue()); + ASSERT_TRUE(c->literal->Is()); + EXPECT_TRUE(c->literal->As()->value); } TEST_F(ParserImplTest, ConstExpr_ConstLiteral_Invalid) { diff --git a/src/reader/wgsl/parser_impl_const_literal_test.cc b/src/reader/wgsl/parser_impl_const_literal_test.cc index 16e3472782..33d972c6ee 100644 --- a/src/reader/wgsl/parser_impl_const_literal_test.cc +++ b/src/reader/wgsl/parser_impl_const_literal_test.cc @@ -49,8 +49,8 @@ TEST_F(ParserImplTest, ConstLiteral_Int) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); - EXPECT_EQ(c->As()->value(), -234); - EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 5u}})); + EXPECT_EQ(c->As()->value, -234); + EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } TEST_F(ParserImplTest, ConstLiteral_Uint) { @@ -61,8 +61,8 @@ TEST_F(ParserImplTest, ConstLiteral_Uint) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); - EXPECT_EQ(c->As()->value(), 234u); - EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 5u}})); + EXPECT_EQ(c->As()->value, 234u); + EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } TEST_F(ParserImplTest, ConstLiteral_Float) { @@ -73,8 +73,8 @@ TEST_F(ParserImplTest, ConstLiteral_Float) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); - EXPECT_FLOAT_EQ(c->As()->value(), 234e12f); - EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 8u}})); + EXPECT_FLOAT_EQ(c->As()->value, 234e12f); + EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); } TEST_F(ParserImplTest, ConstLiteral_InvalidFloat) { @@ -108,7 +108,7 @@ TEST_P(ParserImplFloatLiteralTest, Parse) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); - EXPECT_FLOAT_EQ(c->As()->value(), params.expected); + EXPECT_FLOAT_EQ(c->As()->value, params.expected); } FloatLiteralTestCase float_literal_test_cases[] = { @@ -366,9 +366,9 @@ TEST_F(ParserImplTest, ConstLiteral_FloatHighest) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); - EXPECT_FLOAT_EQ(c->As()->value(), + EXPECT_FLOAT_EQ(c->As()->value, std::numeric_limits::max()); - EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 42u}})); + EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 42u}})); } TEST_F(ParserImplTest, ConstLiteral_FloatLowest) { @@ -389,9 +389,9 @@ TEST_F(ParserImplTest, ConstLiteral_FloatLowest) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); - EXPECT_FLOAT_EQ(c->As()->value(), + EXPECT_FLOAT_EQ(c->As()->value, std::numeric_limits::lowest()); - EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 43u}})); + EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 43u}})); } TEST_F(ParserImplTest, ConstLiteral_True) { @@ -402,8 +402,8 @@ TEST_F(ParserImplTest, ConstLiteral_True) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); - EXPECT_TRUE(c->As()->IsTrue()); - EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 5u}})); + EXPECT_TRUE(c->As()->value); + EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } TEST_F(ParserImplTest, ConstLiteral_False) { @@ -414,8 +414,8 @@ TEST_F(ParserImplTest, ConstLiteral_False) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); ASSERT_TRUE(c->Is()); - EXPECT_TRUE(c->As()->IsFalse()); - EXPECT_EQ(c->source().range, (Source::Range{{1u, 1u}, {1u, 6u}})); + EXPECT_FALSE(c->As()->value); + EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 6u}})); } TEST_F(ParserImplTest, ConstLiteral_NoMatch) { diff --git a/src/reader/wgsl/parser_impl_continuing_stmt_test.cc b/src/reader/wgsl/parser_impl_continuing_stmt_test.cc index 22706e93ba..27714fff2a 100644 --- a/src/reader/wgsl/parser_impl_continuing_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_continuing_stmt_test.cc @@ -26,8 +26,8 @@ TEST_F(ParserImplTest, ContinuingStmt) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); - ASSERT_EQ(e->size(), 1u); - ASSERT_TRUE(e->get(0)->Is()); + ASSERT_EQ(e->statements.size(), 1u); + ASSERT_TRUE(e->statements[0]->Is()); } TEST_F(ParserImplTest, ContinuingStmt_InvalidBody) { diff --git a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc index 01022964ba..da5e0800df 100644 --- a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc +++ b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc @@ -36,9 +36,9 @@ TEST_F(ParserImplTest, DepthTextureType_2d) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::k2d); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 17u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } TEST_F(ParserImplTest, DepthTextureType_2dArray) { @@ -49,9 +49,9 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::k2dArray); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 23u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 23u}})); } TEST_F(ParserImplTest, DepthTextureType_Cube) { @@ -62,9 +62,9 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::kCube); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::kCube); EXPECT_FALSE(p->has_error()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 19u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } TEST_F(ParserImplTest, DepthTextureType_CubeArray) { @@ -75,9 +75,9 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::kCubeArray); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::kCubeArray); EXPECT_FALSE(p->has_error()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 25u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}})); } TEST_F(ParserImplTest, DepthTextureType_Multisampled2d) { @@ -88,9 +88,9 @@ TEST_F(ParserImplTest, DepthTextureType_Multisampled2d) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::k2d); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 30u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 30u}})); } } // namespace diff --git a/src/reader/wgsl/parser_impl_else_stmt_test.cc b/src/reader/wgsl/parser_impl_else_stmt_test.cc index 4d2f87ba40..822602bc26 100644 --- a/src/reader/wgsl/parser_impl_else_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_else_stmt_test.cc @@ -27,8 +27,8 @@ TEST_F(ParserImplTest, ElseStmt) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_EQ(e->condition(), nullptr); - EXPECT_EQ(e->body()->size(), 2u); + ASSERT_EQ(e->condition, nullptr); + EXPECT_EQ(e->body->statements.size(), 2u); } TEST_F(ParserImplTest, ElseStmt_InvalidBody) { diff --git a/src/reader/wgsl/parser_impl_elseif_stmt_test.cc b/src/reader/wgsl/parser_impl_elseif_stmt_test.cc index 7051f47025..ade3c999ec 100644 --- a/src/reader/wgsl/parser_impl_elseif_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_elseif_stmt_test.cc @@ -28,9 +28,9 @@ TEST_F(ParserImplTest, ElseIfStmt) { ASSERT_EQ(e.value.size(), 1u); ASSERT_TRUE(e.value[0]->Is()); - ASSERT_NE(e.value[0]->condition(), nullptr); - ASSERT_TRUE(e.value[0]->condition()->Is()); - EXPECT_EQ(e.value[0]->body()->size(), 2u); + ASSERT_NE(e.value[0]->condition, nullptr); + ASSERT_TRUE(e.value[0]->condition->Is()); + EXPECT_EQ(e.value[0]->body->statements.size(), 2u); } TEST_F(ParserImplTest, ElseIfStmt_Multiple) { @@ -42,14 +42,14 @@ TEST_F(ParserImplTest, ElseIfStmt_Multiple) { ASSERT_EQ(e.value.size(), 2u); ASSERT_TRUE(e.value[0]->Is()); - ASSERT_NE(e.value[0]->condition(), nullptr); - ASSERT_TRUE(e.value[0]->condition()->Is()); - EXPECT_EQ(e.value[0]->body()->size(), 2u); + ASSERT_NE(e.value[0]->condition, nullptr); + ASSERT_TRUE(e.value[0]->condition->Is()); + EXPECT_EQ(e.value[0]->body->statements.size(), 2u); ASSERT_TRUE(e.value[1]->Is()); - ASSERT_NE(e.value[1]->condition(), nullptr); - ASSERT_TRUE(e.value[1]->condition()->Is()); - EXPECT_EQ(e.value[1]->body()->size(), 1u); + ASSERT_NE(e.value[1]->condition, nullptr); + ASSERT_TRUE(e.value[1]->condition->Is()); + EXPECT_EQ(e.value[1]->body->statements.size(), 1u); } TEST_F(ParserImplTest, ElseIfStmt_InvalidBody) { diff --git a/src/reader/wgsl/parser_impl_equality_expression_test.cc b/src/reader/wgsl/parser_impl_equality_expression_test.cc index d23f6b6807..8350e96f96 100644 --- a/src/reader/wgsl/parser_impl_equality_expression_test.cc +++ b/src/reader/wgsl/parser_impl_equality_expression_test.cc @@ -29,17 +29,17 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kEqual, rel->op()); + EXPECT_EQ(ast::BinaryOp::kEqual, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) { @@ -52,17 +52,17 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kNotEqual, rel->op()); + EXPECT_EQ(ast::BinaryOp::kNotEqual, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, EqualityExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc b/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc index 08608c87e2..bfcbf9467e 100644 --- a/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc @@ -29,17 +29,17 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kXor, rel->op()); + EXPECT_EQ(ast::BinaryOp::kXor, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, ExclusiveOrExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_external_texture_type_test.cc b/src/reader/wgsl/parser_impl_external_texture_type_test.cc index 35f4c40c82..f09e083617 100644 --- a/src/reader/wgsl/parser_impl_external_texture_type_test.cc +++ b/src/reader/wgsl/parser_impl_external_texture_type_test.cc @@ -32,7 +32,7 @@ TEST_F(ParserImplTest, ExternalTextureType) { auto t = p->external_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 17u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } } // namespace diff --git a/src/reader/wgsl/parser_impl_for_stmt_test.cc b/src/reader/wgsl/parser_impl_for_stmt_test.cc index 1aac60e994..ba36f9ddde 100644 --- a/src/reader/wgsl/parser_impl_for_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_for_stmt_test.cc @@ -30,10 +30,10 @@ TEST_F(ForStmtTest, Empty) { EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(fl.errored); ASSERT_TRUE(fl.matched); - EXPECT_EQ(fl->initializer(), nullptr); - EXPECT_EQ(fl->condition(), nullptr); - EXPECT_EQ(fl->continuing(), nullptr); - EXPECT_TRUE(fl->body()->empty()); + EXPECT_EQ(fl->initializer, nullptr); + EXPECT_EQ(fl->condition, nullptr); + EXPECT_EQ(fl->continuing, nullptr); + EXPECT_TRUE(fl->body->Empty()); } // Test a for loop with non-empty body. @@ -43,11 +43,11 @@ TEST_F(ForStmtTest, Body) { EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(fl.errored); ASSERT_TRUE(fl.matched); - EXPECT_EQ(fl->initializer(), nullptr); - EXPECT_EQ(fl->condition(), nullptr); - EXPECT_EQ(fl->continuing(), nullptr); - ASSERT_EQ(fl->body()->size(), 1u); - EXPECT_TRUE(fl->body()->statements()[0]->Is()); + EXPECT_EQ(fl->initializer, nullptr); + EXPECT_EQ(fl->condition, nullptr); + EXPECT_EQ(fl->continuing, nullptr); + ASSERT_EQ(fl->body->statements.size(), 1u); + EXPECT_TRUE(fl->body->statements[0]->Is()); } // Test a for loop declaring a variable in the initializer statement. @@ -57,13 +57,13 @@ TEST_F(ForStmtTest, InitializerStatementDecl) { EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(fl.errored); ASSERT_TRUE(fl.matched); - ASSERT_TRUE(Is(fl->initializer())); - auto* var = fl->initializer()->As()->variable(); - EXPECT_FALSE(var->is_const()); - EXPECT_EQ(var->constructor(), nullptr); - EXPECT_EQ(fl->condition(), nullptr); - EXPECT_EQ(fl->continuing(), nullptr); - EXPECT_TRUE(fl->body()->empty()); + ASSERT_TRUE(Is(fl->initializer)); + auto* var = fl->initializer->As()->variable; + EXPECT_FALSE(var->is_const); + EXPECT_EQ(var->constructor, nullptr); + EXPECT_EQ(fl->condition, nullptr); + EXPECT_EQ(fl->continuing, nullptr); + EXPECT_TRUE(fl->body->Empty()); } // Test a for loop declaring and initializing a variable in the initializer @@ -74,13 +74,13 @@ TEST_F(ForStmtTest, InitializerStatementDeclEqual) { EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(fl.errored); ASSERT_TRUE(fl.matched); - ASSERT_TRUE(Is(fl->initializer())); - auto* var = fl->initializer()->As()->variable(); - EXPECT_FALSE(var->is_const()); - EXPECT_NE(var->constructor(), nullptr); - EXPECT_EQ(fl->condition(), nullptr); - EXPECT_EQ(fl->continuing(), nullptr); - EXPECT_TRUE(fl->body()->empty()); + ASSERT_TRUE(Is(fl->initializer)); + auto* var = fl->initializer->As()->variable; + EXPECT_FALSE(var->is_const); + EXPECT_NE(var->constructor, nullptr); + EXPECT_EQ(fl->condition, nullptr); + EXPECT_EQ(fl->continuing, nullptr); + EXPECT_TRUE(fl->body->Empty()); } // Test a for loop declaring a const variable in the initializer statement. @@ -90,13 +90,13 @@ TEST_F(ForStmtTest, InitializerStatementConstDecl) { EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(fl.errored); ASSERT_TRUE(fl.matched); - ASSERT_TRUE(Is(fl->initializer())); - auto* var = fl->initializer()->As()->variable(); - EXPECT_TRUE(var->is_const()); - EXPECT_NE(var->constructor(), nullptr); - EXPECT_EQ(fl->condition(), nullptr); - EXPECT_EQ(fl->continuing(), nullptr); - EXPECT_TRUE(fl->body()->empty()); + ASSERT_TRUE(Is(fl->initializer)); + auto* var = fl->initializer->As()->variable; + EXPECT_TRUE(var->is_const); + EXPECT_NE(var->constructor, nullptr); + EXPECT_EQ(fl->condition, nullptr); + EXPECT_EQ(fl->continuing, nullptr); + EXPECT_TRUE(fl->body->Empty()); } // Test a for loop assigning a variable in the initializer statement. @@ -106,10 +106,10 @@ TEST_F(ForStmtTest, InitializerStatementAssignment) { EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(fl.errored); ASSERT_TRUE(fl.matched); - EXPECT_TRUE(Is(fl->initializer())); - EXPECT_EQ(fl->condition(), nullptr); - EXPECT_EQ(fl->continuing(), nullptr); - EXPECT_TRUE(fl->body()->empty()); + EXPECT_TRUE(Is(fl->initializer)); + EXPECT_EQ(fl->condition, nullptr); + EXPECT_EQ(fl->continuing, nullptr); + EXPECT_TRUE(fl->body->Empty()); } // Test a for loop calling a function in the initializer statement. @@ -119,10 +119,10 @@ TEST_F(ForStmtTest, InitializerStatementFuncCall) { EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(fl.errored); ASSERT_TRUE(fl.matched); - EXPECT_TRUE(Is(fl->initializer())); - EXPECT_EQ(fl->condition(), nullptr); - EXPECT_EQ(fl->continuing(), nullptr); - EXPECT_TRUE(fl->body()->empty()); + EXPECT_TRUE(Is(fl->initializer)); + EXPECT_EQ(fl->condition, nullptr); + EXPECT_EQ(fl->continuing, nullptr); + EXPECT_TRUE(fl->body->Empty()); } // Test a for loop with a break condition @@ -132,10 +132,10 @@ TEST_F(ForStmtTest, BreakCondition) { EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(fl.errored); ASSERT_TRUE(fl.matched); - EXPECT_EQ(fl->initializer(), nullptr); - EXPECT_TRUE(Is(fl->condition())); - EXPECT_EQ(fl->continuing(), nullptr); - EXPECT_TRUE(fl->body()->empty()); + EXPECT_EQ(fl->initializer, nullptr); + EXPECT_TRUE(Is(fl->condition)); + EXPECT_EQ(fl->continuing, nullptr); + EXPECT_TRUE(fl->body->Empty()); } // Test a for loop assigning a variable in the continuing statement. @@ -145,10 +145,10 @@ TEST_F(ForStmtTest, ContinuingAssignment) { EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(fl.errored); ASSERT_TRUE(fl.matched); - EXPECT_EQ(fl->initializer(), nullptr); - EXPECT_EQ(fl->condition(), nullptr); - EXPECT_TRUE(Is(fl->continuing())); - EXPECT_TRUE(fl->body()->empty()); + EXPECT_EQ(fl->initializer, nullptr); + EXPECT_EQ(fl->condition, nullptr); + EXPECT_TRUE(Is(fl->continuing)); + EXPECT_TRUE(fl->body->Empty()); } // Test a for loop calling a function in the continuing statement. @@ -158,10 +158,10 @@ TEST_F(ForStmtTest, ContinuingFuncCall) { EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(fl.errored); ASSERT_TRUE(fl.matched); - EXPECT_EQ(fl->initializer(), nullptr); - EXPECT_EQ(fl->condition(), nullptr); - EXPECT_TRUE(Is(fl->continuing())); - EXPECT_TRUE(fl->body()->empty()); + EXPECT_EQ(fl->initializer, nullptr); + EXPECT_EQ(fl->condition, nullptr); + EXPECT_TRUE(Is(fl->continuing)); + EXPECT_TRUE(fl->body->Empty()); } class ForStmtErrorTest : public ParserImplTest { diff --git a/src/reader/wgsl/parser_impl_function_decl_test.cc b/src/reader/wgsl/parser_impl_function_decl_test.cc index f08db28e65..2ec9a8d7ad 100644 --- a/src/reader/wgsl/parser_impl_function_decl_test.cc +++ b/src/reader/wgsl/parser_impl_function_decl_test.cc @@ -32,20 +32,20 @@ TEST_F(ParserImplTest, FunctionDecl) { EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f->symbol(), p->builder().Symbols().Get("main")); - ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); + EXPECT_EQ(f->symbol, p->builder().Symbols().Get("main")); + ASSERT_NE(f->return_type, nullptr); + EXPECT_TRUE(f->return_type->Is()); - ASSERT_EQ(f->params().size(), 2u); - EXPECT_EQ(f->params()[0]->symbol(), p->builder().Symbols().Get("a")); - EXPECT_EQ(f->params()[1]->symbol(), p->builder().Symbols().Get("b")); + ASSERT_EQ(f->params.size(), 2u); + EXPECT_EQ(f->params[0]->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(f->params[1]->symbol, p->builder().Symbols().Get("b")); - ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); + ASSERT_NE(f->return_type, nullptr); + EXPECT_TRUE(f->return_type->Is()); - auto* body = f->body(); - ASSERT_EQ(body->size(), 1u); - EXPECT_TRUE(body->get(0)->Is()); + auto* body = f->body; + ASSERT_EQ(body->statements.size(), 1u); + EXPECT_TRUE(body->statements[0]->Is()); } TEST_F(ParserImplTest, FunctionDecl_DecorationList) { @@ -60,38 +60,38 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) { EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f->symbol(), p->builder().Symbols().Get("main")); - ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); - ASSERT_EQ(f->params().size(), 0u); + EXPECT_EQ(f->symbol, p->builder().Symbols().Get("main")); + ASSERT_NE(f->return_type, nullptr); + EXPECT_TRUE(f->return_type->Is()); + ASSERT_EQ(f->params.size(), 0u); - auto& decorations = f->decorations(); + auto& decorations = f->decorations; ASSERT_EQ(decorations.size(), 1u); ASSERT_TRUE(decorations[0]->Is()); - auto values = decorations[0]->As()->values(); + auto values = decorations[0]->As()->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_NE(x_scalar, nullptr); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 2u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 2u); ASSERT_NE(values[1], nullptr); auto* y_scalar = values[1]->As(); ASSERT_NE(y_scalar, nullptr); - ASSERT_TRUE(y_scalar->literal()->Is()); - EXPECT_EQ(y_scalar->literal()->As()->value_as_u32(), 3u); + ASSERT_TRUE(y_scalar->literal->Is()); + EXPECT_EQ(y_scalar->literal->As()->ValueAsU32(), 3u); ASSERT_NE(values[2], nullptr); auto* z_scalar = values[2]->As(); ASSERT_NE(z_scalar, nullptr); - ASSERT_TRUE(z_scalar->literal()->Is()); - EXPECT_EQ(z_scalar->literal()->As()->value_as_u32(), 4u); + ASSERT_TRUE(z_scalar->literal->Is()); + EXPECT_EQ(z_scalar->literal->As()->ValueAsU32(), 4u); - auto* body = f->body(); - ASSERT_EQ(body->size(), 1u); - EXPECT_TRUE(body->get(0)->Is()); + auto* body = f->body; + ASSERT_EQ(body->statements.size(), 1u); + EXPECT_TRUE(body->statements[0]->Is()); } TEST_F(ParserImplTest, FunctionDecl_DecorationList_MultipleEntries) { @@ -108,42 +108,42 @@ fn main() { return; })"); EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f->symbol(), p->builder().Symbols().Get("main")); - ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); - ASSERT_EQ(f->params().size(), 0u); + EXPECT_EQ(f->symbol, p->builder().Symbols().Get("main")); + ASSERT_NE(f->return_type, nullptr); + EXPECT_TRUE(f->return_type->Is()); + ASSERT_EQ(f->params.size(), 0u); - auto& decorations = f->decorations(); + auto& decorations = f->decorations; ASSERT_EQ(decorations.size(), 2u); ASSERT_TRUE(decorations[0]->Is()); - auto values = decorations[0]->As()->values(); + auto values = decorations[0]->As()->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_NE(x_scalar, nullptr); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 2u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 2u); ASSERT_NE(values[1], nullptr); auto* y_scalar = values[1]->As(); ASSERT_NE(y_scalar, nullptr); - ASSERT_TRUE(y_scalar->literal()->Is()); - EXPECT_EQ(y_scalar->literal()->As()->value_as_u32(), 3u); + ASSERT_TRUE(y_scalar->literal->Is()); + EXPECT_EQ(y_scalar->literal->As()->ValueAsU32(), 3u); ASSERT_NE(values[2], nullptr); auto* z_scalar = values[2]->As(); ASSERT_NE(z_scalar, nullptr); - ASSERT_TRUE(z_scalar->literal()->Is()); - EXPECT_EQ(z_scalar->literal()->As()->value_as_u32(), 4u); + ASSERT_TRUE(z_scalar->literal->Is()); + EXPECT_EQ(z_scalar->literal->As()->ValueAsU32(), 4u); ASSERT_TRUE(decorations[1]->Is()); - EXPECT_EQ(decorations[1]->As()->value(), + EXPECT_EQ(decorations[1]->As()->stage, ast::PipelineStage::kCompute); - auto* body = f->body(); - ASSERT_EQ(body->size(), 1u); - EXPECT_TRUE(body->get(0)->Is()); + auto* body = f->body; + ASSERT_EQ(body->statements.size(), 1u); + EXPECT_TRUE(body->statements[0]->Is()); } TEST_F(ParserImplTest, FunctionDecl_DecorationList_MultipleLists) { @@ -161,42 +161,42 @@ fn main() { return; })"); EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f->symbol(), p->builder().Symbols().Get("main")); - ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); - ASSERT_EQ(f->params().size(), 0u); + EXPECT_EQ(f->symbol, p->builder().Symbols().Get("main")); + ASSERT_NE(f->return_type, nullptr); + EXPECT_TRUE(f->return_type->Is()); + ASSERT_EQ(f->params.size(), 0u); - auto& decos = f->decorations(); + auto& decos = f->decorations; ASSERT_EQ(decos.size(), 2u); ASSERT_TRUE(decos[0]->Is()); - auto values = decos[0]->As()->values(); + auto values = decos[0]->As()->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_NE(x_scalar, nullptr); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 2u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 2u); ASSERT_NE(values[1], nullptr); auto* y_scalar = values[1]->As(); ASSERT_NE(y_scalar, nullptr); - ASSERT_TRUE(y_scalar->literal()->Is()); - EXPECT_EQ(y_scalar->literal()->As()->value_as_u32(), 3u); + ASSERT_TRUE(y_scalar->literal->Is()); + EXPECT_EQ(y_scalar->literal->As()->ValueAsU32(), 3u); ASSERT_NE(values[2], nullptr); auto* z_scalar = values[2]->As(); ASSERT_NE(z_scalar, nullptr); - ASSERT_TRUE(z_scalar->literal()->Is()); - EXPECT_EQ(z_scalar->literal()->As()->value_as_u32(), 4u); + ASSERT_TRUE(z_scalar->literal->Is()); + EXPECT_EQ(z_scalar->literal->As()->ValueAsU32(), 4u); ASSERT_TRUE(decos[1]->Is()); - EXPECT_EQ(decos[1]->As()->value(), + EXPECT_EQ(decos[1]->As()->stage, ast::PipelineStage::kCompute); - auto* body = f->body(); - ASSERT_EQ(body->size(), 1u); - EXPECT_TRUE(body->get(0)->Is()); + auto* body = f->body; + ASSERT_EQ(body->statements.size(), 1u); + EXPECT_TRUE(body->statements[0]->Is()); } TEST_F(ParserImplTest, FunctionDecl_ReturnTypeDecorationList) { @@ -211,23 +211,23 @@ TEST_F(ParserImplTest, FunctionDecl_ReturnTypeDecorationList) { EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f->symbol(), p->builder().Symbols().Get("main")); - ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); - ASSERT_EQ(f->params().size(), 0u); + EXPECT_EQ(f->symbol, p->builder().Symbols().Get("main")); + ASSERT_NE(f->return_type, nullptr); + EXPECT_TRUE(f->return_type->Is()); + ASSERT_EQ(f->params.size(), 0u); - auto& decorations = f->decorations(); + auto& decorations = f->decorations; EXPECT_EQ(decorations.size(), 0u); - auto& ret_type_decorations = f->return_type_decorations(); + auto& ret_type_decorations = f->return_type_decorations; ASSERT_EQ(ret_type_decorations.size(), 1u); auto* loc = ret_type_decorations[0]->As(); ASSERT_TRUE(loc != nullptr); - EXPECT_EQ(loc->value(), 1u); + EXPECT_EQ(loc->value, 1u); - auto* body = f->body(); - ASSERT_EQ(body->size(), 1u); - EXPECT_TRUE(body->get(0)->Is()); + auto* body = f->body; + ASSERT_EQ(body->statements.size(), 1u); + EXPECT_TRUE(body->statements[0]->Is()); } TEST_F(ParserImplTest, FunctionDecl_InvalidHeader) { diff --git a/src/reader/wgsl/parser_impl_function_decoration_list_test.cc b/src/reader/wgsl/parser_impl_function_decoration_list_test.cc index 0b76ef2ab2..dae3f9aaf8 100644 --- a/src/reader/wgsl/parser_impl_function_decoration_list_test.cc +++ b/src/reader/wgsl/parser_impl_function_decoration_list_test.cc @@ -34,15 +34,15 @@ TEST_F(ParserImplTest, DecorationList_Parses) { ASSERT_NE(deco_1, nullptr); ASSERT_TRUE(deco_0->Is()); - ast::Expression* x = deco_0->As()->values()[0]; + ast::Expression* x = deco_0->As()->x; ASSERT_NE(x, nullptr); auto* x_scalar = x->As(); ASSERT_NE(x_scalar, nullptr); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 2u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 2u); ASSERT_TRUE(deco_1->Is()); - EXPECT_EQ(deco_1->As()->value(), + EXPECT_EQ(deco_1->As()->stage, ast::PipelineStage::kCompute); } diff --git a/src/reader/wgsl/parser_impl_function_decoration_test.cc b/src/reader/wgsl/parser_impl_function_decoration_test.cc index 432f99e7fd..2fe6994122 100644 --- a/src/reader/wgsl/parser_impl_function_decoration_test.cc +++ b/src/reader/wgsl/parser_impl_function_decoration_test.cc @@ -32,13 +32,13 @@ TEST_F(ParserImplTest, Decoration_Workgroup) { ASSERT_NE(func_deco, nullptr); ASSERT_TRUE(func_deco->Is()); - auto values = func_deco->As()->values(); + auto values = func_deco->As()->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_NE(x_scalar, nullptr); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 4u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 4u); EXPECT_EQ(values[1], nullptr); EXPECT_EQ(values[2], nullptr); @@ -55,19 +55,19 @@ TEST_F(ParserImplTest, Decoration_Workgroup_2Param) { ASSERT_NE(func_deco, nullptr) << p->error(); ASSERT_TRUE(func_deco->Is()); - auto values = func_deco->As()->values(); + auto values = func_deco->As()->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_NE(x_scalar, nullptr); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 4u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 4u); ASSERT_NE(values[1], nullptr); auto* y_scalar = values[1]->As(); ASSERT_NE(y_scalar, nullptr); - ASSERT_TRUE(y_scalar->literal()->Is()); - EXPECT_EQ(y_scalar->literal()->As()->value_as_u32(), 5u); + ASSERT_TRUE(y_scalar->literal->Is()); + EXPECT_EQ(y_scalar->literal->As()->ValueAsU32(), 5u); EXPECT_EQ(values[2], nullptr); } @@ -83,25 +83,25 @@ TEST_F(ParserImplTest, Decoration_Workgroup_3Param) { ASSERT_NE(func_deco, nullptr); ASSERT_TRUE(func_deco->Is()); - auto values = func_deco->As()->values(); + auto values = func_deco->As()->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_NE(x_scalar, nullptr); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 4u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 4u); ASSERT_NE(values[1], nullptr); auto* y_scalar = values[1]->As(); ASSERT_NE(y_scalar, nullptr); - ASSERT_TRUE(y_scalar->literal()->Is()); - EXPECT_EQ(y_scalar->literal()->As()->value_as_u32(), 5u); + ASSERT_TRUE(y_scalar->literal->Is()); + EXPECT_EQ(y_scalar->literal->As()->ValueAsU32(), 5u); ASSERT_NE(values[2], nullptr); auto* z_scalar = values[2]->As(); ASSERT_NE(z_scalar, nullptr); - ASSERT_TRUE(z_scalar->literal()->Is()); - EXPECT_EQ(z_scalar->literal()->As()->value_as_u32(), 6u); + ASSERT_TRUE(z_scalar->literal->Is()); + EXPECT_EQ(z_scalar->literal->As()->ValueAsU32(), 6u); } TEST_F(ParserImplTest, Decoration_Workgroup_WithIdent) { @@ -115,18 +115,18 @@ TEST_F(ParserImplTest, Decoration_Workgroup_WithIdent) { ASSERT_NE(func_deco, nullptr); ASSERT_TRUE(func_deco->Is()); - auto values = func_deco->As()->values(); + auto values = func_deco->As()->Values(); ASSERT_NE(values[0], nullptr); auto* x_scalar = values[0]->As(); ASSERT_NE(x_scalar, nullptr); - ASSERT_TRUE(x_scalar->literal()->Is()); - EXPECT_EQ(x_scalar->literal()->As()->value_as_u32(), 4u); + ASSERT_TRUE(x_scalar->literal->Is()); + EXPECT_EQ(x_scalar->literal->As()->ValueAsU32(), 4u); ASSERT_NE(values[1], nullptr); auto* y_ident = values[1]->As(); ASSERT_NE(y_ident, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(y_ident->symbol()), "height"); + EXPECT_EQ(p->builder().Symbols().NameFor(y_ident->symbol), "height"); ASSERT_EQ(values[2], nullptr); } @@ -231,7 +231,7 @@ TEST_F(ParserImplTest, Decoration_Stage) { auto* func_deco = deco.value->As(); ASSERT_NE(func_deco, nullptr); ASSERT_TRUE(func_deco->Is()); - EXPECT_EQ(func_deco->As()->value(), + EXPECT_EQ(func_deco->As()->stage, ast::PipelineStage::kCompute); } diff --git a/src/reader/wgsl/parser_impl_function_header_test.cc b/src/reader/wgsl/parser_impl_function_header_test.cc index b3f38c8054..b17581e24b 100644 --- a/src/reader/wgsl/parser_impl_function_header_test.cc +++ b/src/reader/wgsl/parser_impl_function_header_test.cc @@ -28,8 +28,8 @@ TEST_F(ParserImplTest, FunctionHeader) { EXPECT_EQ(f->name, "main"); ASSERT_EQ(f->params.size(), 2u); - EXPECT_EQ(f->params[0]->symbol(), p->builder().Symbols().Get("a")); - EXPECT_EQ(f->params[1]->symbol(), p->builder().Symbols().Get("b")); + EXPECT_EQ(f->params[0]->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(f->params[1]->symbol, p->builder().Symbols().Get("b")); EXPECT_TRUE(f->return_type->Is()); } @@ -41,7 +41,7 @@ TEST_F(ParserImplTest, FunctionHeader_TrailingComma) { EXPECT_EQ(f->name, "main"); ASSERT_EQ(f->params.size(), 1u); - EXPECT_EQ(f->params[0]->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(f->params[0]->symbol, p->builder().Symbols().Get("a")); EXPECT_TRUE(f->return_type->Is()); } @@ -58,7 +58,7 @@ TEST_F(ParserImplTest, FunctionHeader_DecoratedReturnType) { ASSERT_EQ(f->return_type_decorations.size(), 1u); auto* loc = f->return_type_decorations[0]->As(); ASSERT_TRUE(loc != nullptr); - EXPECT_EQ(loc->value(), 1u); + EXPECT_EQ(loc->value, 1u); } TEST_F(ParserImplTest, FunctionHeader_InvariantReturnType) { @@ -87,13 +87,13 @@ TEST_F(ParserImplTest, FunctionHeader_DecoratedReturnType_WithArrayStride) { ASSERT_EQ(f->return_type_decorations.size(), 1u); auto* loc = f->return_type_decorations[0]->As(); ASSERT_TRUE(loc != nullptr); - EXPECT_EQ(loc->value(), 1u); + EXPECT_EQ(loc->value, 1u); auto* array_type = f->return_type->As(); - ASSERT_EQ(array_type->decorations().size(), 1u); - auto* stride = array_type->decorations()[0]->As(); + ASSERT_EQ(array_type->decorations.size(), 1u); + auto* stride = array_type->decorations[0]->As(); ASSERT_TRUE(stride != nullptr); - EXPECT_EQ(stride->stride(), 16u); + EXPECT_EQ(stride->stride, 16u); } TEST_F(ParserImplTest, FunctionHeader_MissingIdent) { diff --git a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc index df4bf98891..308bd70b6b 100644 --- a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc @@ -31,21 +31,21 @@ TEST_F(ParserImplTest, GlobalConstantDecl) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_TRUE(e->is_const()); - EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a")); - ASSERT_NE(e->type(), nullptr); - EXPECT_TRUE(e->type()->Is()); + EXPECT_TRUE(e->is_const); + EXPECT_EQ(e->symbol, p->builder().Symbols().Get("a")); + ASSERT_NE(e->type, nullptr); + EXPECT_TRUE(e->type->Is()); - EXPECT_EQ(e->source().range.begin.line, 1u); - EXPECT_EQ(e->source().range.begin.column, 5u); - EXPECT_EQ(e->source().range.end.line, 1u); - EXPECT_EQ(e->source().range.end.column, 6u); + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 5u); + EXPECT_EQ(e->source.range.end.line, 1u); + EXPECT_EQ(e->source.range.end.column, 6u); - ASSERT_NE(e->constructor(), nullptr); - EXPECT_TRUE(e->constructor()->Is()); + ASSERT_NE(e->constructor, nullptr); + EXPECT_TRUE(e->constructor->Is()); EXPECT_FALSE( - ast::HasDecoration(e.value->decorations())); + ast::HasDecoration(e.value->decorations)); } TEST_F(ParserImplTest, GlobalConstantDecl_Inferred) { @@ -59,20 +59,20 @@ TEST_F(ParserImplTest, GlobalConstantDecl_Inferred) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_TRUE(e->is_const()); - EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a")); - EXPECT_EQ(e->type(), nullptr); + EXPECT_TRUE(e->is_const); + EXPECT_EQ(e->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(e->type, nullptr); - EXPECT_EQ(e->source().range.begin.line, 1u); - EXPECT_EQ(e->source().range.begin.column, 5u); - EXPECT_EQ(e->source().range.end.line, 1u); - EXPECT_EQ(e->source().range.end.column, 6u); + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 5u); + EXPECT_EQ(e->source.range.end.line, 1u); + EXPECT_EQ(e->source.range.end.column, 6u); - ASSERT_NE(e->constructor(), nullptr); - EXPECT_TRUE(e->constructor()->Is()); + ASSERT_NE(e->constructor, nullptr); + EXPECT_TRUE(e->constructor->Is()); EXPECT_FALSE( - ast::HasDecoration(e.value->decorations())); + ast::HasDecoration(e.value->decorations)); } TEST_F(ParserImplTest, GlobalConstantDecl_InvalidVariable) { @@ -126,24 +126,24 @@ TEST_F(ParserImplTest, GlobalConstantDec_Override_WithId) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_TRUE(e->is_const()); - EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a")); - ASSERT_NE(e->type(), nullptr); - EXPECT_TRUE(e->type()->Is()); + EXPECT_TRUE(e->is_const); + EXPECT_EQ(e->symbol, p->builder().Symbols().Get("a")); + ASSERT_NE(e->type, nullptr); + EXPECT_TRUE(e->type->Is()); - EXPECT_EQ(e->source().range.begin.line, 1u); - EXPECT_EQ(e->source().range.begin.column, 21u); - EXPECT_EQ(e->source().range.end.line, 1u); - EXPECT_EQ(e->source().range.end.column, 22u); + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 21u); + EXPECT_EQ(e->source.range.end.line, 1u); + EXPECT_EQ(e->source.range.end.column, 22u); - ASSERT_NE(e->constructor(), nullptr); - EXPECT_TRUE(e->constructor()->Is()); + ASSERT_NE(e->constructor, nullptr); + EXPECT_TRUE(e->constructor->Is()); auto* override_deco = - ast::GetDecoration(e.value->decorations()); + ast::GetDecoration(e.value->decorations); ASSERT_NE(override_deco, nullptr); - EXPECT_TRUE(override_deco->HasValue()); - EXPECT_EQ(override_deco->value(), 7u); + EXPECT_TRUE(override_deco->has_value); + EXPECT_EQ(override_deco->value, 7u); } TEST_F(ParserImplTest, GlobalConstantDec_Override_WithoutId) { @@ -158,23 +158,23 @@ TEST_F(ParserImplTest, GlobalConstantDec_Override_WithoutId) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_TRUE(e->is_const()); - EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a")); - ASSERT_NE(e->type(), nullptr); - EXPECT_TRUE(e->type()->Is()); + EXPECT_TRUE(e->is_const); + EXPECT_EQ(e->symbol, p->builder().Symbols().Get("a")); + ASSERT_NE(e->type, nullptr); + EXPECT_TRUE(e->type->Is()); - EXPECT_EQ(e->source().range.begin.line, 1u); - EXPECT_EQ(e->source().range.begin.column, 18u); - EXPECT_EQ(e->source().range.end.line, 1u); - EXPECT_EQ(e->source().range.end.column, 19u); + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 18u); + EXPECT_EQ(e->source.range.end.line, 1u); + EXPECT_EQ(e->source.range.end.column, 19u); - ASSERT_NE(e->constructor(), nullptr); - EXPECT_TRUE(e->constructor()->Is()); + ASSERT_NE(e->constructor, nullptr); + EXPECT_TRUE(e->constructor->Is()); auto* override_deco = - ast::GetDecoration(e.value->decorations()); + ast::GetDecoration(e.value->decorations); ASSERT_NE(override_deco, nullptr); - EXPECT_FALSE(override_deco->HasValue()); + EXPECT_FALSE(override_deco->has_value); } TEST_F(ParserImplTest, GlobalConstantDec_Override_MissingId) { diff --git a/src/reader/wgsl/parser_impl_global_decl_test.cc b/src/reader/wgsl/parser_impl_global_decl_test.cc index ef7caff36a..8489fe6046 100644 --- a/src/reader/wgsl/parser_impl_global_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_decl_test.cc @@ -34,7 +34,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable) { ASSERT_EQ(program.AST().GlobalVariables().size(), 1u); auto* v = program.AST().GlobalVariables()[0]; - EXPECT_EQ(v->symbol(), program.Symbols().Get("a")); + EXPECT_EQ(v->symbol, program.Symbols().Get("a")); } TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Inferred_Invalid) { @@ -67,7 +67,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalConstant) { ASSERT_EQ(program.AST().GlobalVariables().size(), 1u); auto* v = program.AST().GlobalVariables()[0]; - EXPECT_EQ(v->symbol(), program.Symbols().Get("a")); + EXPECT_EQ(v->symbol, program.Symbols().Get("a")); } TEST_F(ParserImplTest, GlobalDecl_GlobalConstant_Invalid) { @@ -93,7 +93,7 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) { ASSERT_EQ(program.AST().TypeDecls().size(), 1u); ASSERT_TRUE(program.AST().TypeDecls()[0]->Is()); EXPECT_EQ(program.Symbols().NameFor( - program.AST().TypeDecls()[0]->As()->symbol()), + program.AST().TypeDecls()[0]->As()->name), "A"); } @@ -110,14 +110,14 @@ type B = A;)"); ASSERT_EQ(program.AST().TypeDecls().size(), 2u); ASSERT_TRUE(program.AST().TypeDecls()[0]->Is()); auto* str = program.AST().TypeDecls()[0]->As(); - EXPECT_EQ(str->name(), program.Symbols().Get("A")); + EXPECT_EQ(str->name, program.Symbols().Get("A")); ASSERT_TRUE(program.AST().TypeDecls()[1]->Is()); auto* alias = program.AST().TypeDecls()[1]->As(); - EXPECT_EQ(alias->symbol(), program.Symbols().Get("B")); - auto* tn = alias->type()->As(); + EXPECT_EQ(alias->name, program.Symbols().Get("B")); + auto* tn = alias->type->As(); EXPECT_NE(tn, nullptr); - EXPECT_EQ(tn->name(), str->name()); + EXPECT_EQ(tn->name, str->name); } TEST_F(ParserImplTest, GlobalDecl_TypeAlias_Invalid) { @@ -141,7 +141,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function) { auto program = p->program(); ASSERT_EQ(program.AST().Functions().size(), 1u); - EXPECT_EQ(program.Symbols().NameFor(program.AST().Functions()[0]->symbol()), + EXPECT_EQ(program.Symbols().NameFor(program.AST().Functions()[0]->symbol), "main"); } @@ -152,7 +152,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) { auto program = p->program(); ASSERT_EQ(program.AST().Functions().size(), 1u); - EXPECT_EQ(program.Symbols().NameFor(program.AST().Functions()[0]->symbol()), + EXPECT_EQ(program.Symbols().NameFor(program.AST().Functions()[0]->symbol), "main"); } @@ -176,8 +176,8 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) { ASSERT_TRUE(t->Is()); auto* str = t->As(); - EXPECT_EQ(str->name(), program.Symbols().Get("A")); - EXPECT_EQ(str->members().size(), 2u); + EXPECT_EQ(str->name, program.Symbols().Get("A")); + EXPECT_EQ(str->members.size(), 2u); } TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) { @@ -194,18 +194,18 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) { ASSERT_TRUE(t->Is()); auto* str = t->As(); - EXPECT_EQ(str->name(), program.Symbols().Get("A")); - EXPECT_EQ(str->members().size(), 1u); + EXPECT_EQ(str->name, program.Symbols().Get("A")); + EXPECT_EQ(str->members.size(), 1u); EXPECT_FALSE(str->IsBlockDecorated()); - const auto* ty = str->members()[0]->type(); + const auto* ty = str->members[0]->type; ASSERT_TRUE(ty->Is()); const auto* arr = ty->As(); - ASSERT_EQ(arr->decorations().size(), 1u); - auto* stride = arr->decorations()[0]; + ASSERT_EQ(arr->decorations.size(), 1u); + auto* stride = arr->decorations[0]; ASSERT_TRUE(stride->Is()); - ASSERT_EQ(stride->As()->stride(), 4u); + ASSERT_EQ(stride->As()->stride, 4u); } TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) { @@ -221,8 +221,8 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) { ASSERT_TRUE(t->Is()); auto* str = t->As(); - EXPECT_EQ(str->name(), program.Symbols().Get("A")); - EXPECT_EQ(str->members().size(), 1u); + EXPECT_EQ(str->name, program.Symbols().Get("A")); + EXPECT_EQ(str->members.size(), 1u); EXPECT_TRUE(str->IsBlockDecorated()); } diff --git a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc index ba6b1157b9..c7c563066d 100644 --- a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc @@ -30,16 +30,16 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a")); - EXPECT_TRUE(e->type()->Is()); - EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kPrivate); + EXPECT_EQ(e->symbol, p->builder().Symbols().Get("a")); + EXPECT_TRUE(e->type->Is()); + EXPECT_EQ(e->declared_storage_class, ast::StorageClass::kPrivate); - EXPECT_EQ(e->source().range.begin.line, 1u); - EXPECT_EQ(e->source().range.begin.column, 14u); - EXPECT_EQ(e->source().range.end.line, 1u); - EXPECT_EQ(e->source().range.end.column, 15u); + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 14u); + EXPECT_EQ(e->source.range.end.line, 1u); + EXPECT_EQ(e->source.range.end.column, 15u); - ASSERT_EQ(e->constructor(), nullptr); + ASSERT_EQ(e->constructor, nullptr); } TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) { @@ -53,18 +53,18 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a")); - EXPECT_TRUE(e->type()->Is()); - EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kPrivate); + EXPECT_EQ(e->symbol, p->builder().Symbols().Get("a")); + EXPECT_TRUE(e->type->Is()); + EXPECT_EQ(e->declared_storage_class, ast::StorageClass::kPrivate); - EXPECT_EQ(e->source().range.begin.line, 1u); - EXPECT_EQ(e->source().range.begin.column, 14u); - EXPECT_EQ(e->source().range.end.line, 1u); - EXPECT_EQ(e->source().range.end.column, 15u); + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 14u); + EXPECT_EQ(e->source.range.end.line, 1u); + EXPECT_EQ(e->source.range.end.column, 15u); - ASSERT_NE(e->constructor(), nullptr); - ASSERT_TRUE(e->constructor()->Is()); - ASSERT_TRUE(e->constructor()->Is()); + ASSERT_NE(e->constructor, nullptr); + ASSERT_TRUE(e->constructor->Is()); + ASSERT_TRUE(e->constructor->Is()); } TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) { @@ -78,19 +78,19 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a")); - ASSERT_NE(e->type(), nullptr); - EXPECT_TRUE(e->type()->Is()); - EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kUniform); + EXPECT_EQ(e->symbol, p->builder().Symbols().Get("a")); + ASSERT_NE(e->type, nullptr); + EXPECT_TRUE(e->type->Is()); + EXPECT_EQ(e->declared_storage_class, ast::StorageClass::kUniform); - EXPECT_EQ(e->source().range.begin.line, 1u); - EXPECT_EQ(e->source().range.begin.column, 39u); - EXPECT_EQ(e->source().range.end.line, 1u); - EXPECT_EQ(e->source().range.end.column, 40u); + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 39u); + EXPECT_EQ(e->source.range.end.line, 1u); + EXPECT_EQ(e->source.range.end.column, 40u); - ASSERT_EQ(e->constructor(), nullptr); + ASSERT_EQ(e->constructor, nullptr); - auto& decorations = e->decorations(); + auto& decorations = e->decorations; ASSERT_EQ(decorations.size(), 2u); ASSERT_TRUE(decorations[0]->Is()); ASSERT_TRUE(decorations[1]->Is()); @@ -108,19 +108,19 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration_MulitpleGroups) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a")); - ASSERT_NE(e->type(), nullptr); - EXPECT_TRUE(e->type()->Is()); - EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kUniform); + EXPECT_EQ(e->symbol, p->builder().Symbols().Get("a")); + ASSERT_NE(e->type, nullptr); + EXPECT_TRUE(e->type->Is()); + EXPECT_EQ(e->declared_storage_class, ast::StorageClass::kUniform); - EXPECT_EQ(e->source().range.begin.line, 1u); - EXPECT_EQ(e->source().range.begin.column, 42u); - EXPECT_EQ(e->source().range.end.line, 1u); - EXPECT_EQ(e->source().range.end.column, 43u); + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 42u); + EXPECT_EQ(e->source.range.end.line, 1u); + EXPECT_EQ(e->source.range.end.column, 43u); - ASSERT_EQ(e->constructor(), nullptr); + ASSERT_EQ(e->constructor, nullptr); - auto& decorations = e->decorations(); + auto& decorations = e->decorations; ASSERT_EQ(decorations.size(), 2u); ASSERT_TRUE(decorations[0]->Is()); ASSERT_TRUE(decorations[1]->Is()); diff --git a/src/reader/wgsl/parser_impl_if_stmt_test.cc b/src/reader/wgsl/parser_impl_if_stmt_test.cc index fdee7c8201..1c93c1976a 100644 --- a/src/reader/wgsl/parser_impl_if_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_if_stmt_test.cc @@ -28,10 +28,10 @@ TEST_F(ParserImplTest, IfStmt) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_NE(e->condition(), nullptr); - ASSERT_TRUE(e->condition()->Is()); - EXPECT_EQ(e->body()->size(), 2u); - EXPECT_EQ(e->else_statements().size(), 0u); + ASSERT_NE(e->condition, nullptr); + ASSERT_TRUE(e->condition->Is()); + EXPECT_EQ(e->body->statements.size(), 2u); + EXPECT_EQ(e->else_statements.size(), 0u); } TEST_F(ParserImplTest, IfStmt_WithElse) { @@ -43,18 +43,18 @@ TEST_F(ParserImplTest, IfStmt_WithElse) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_NE(e->condition(), nullptr); - ASSERT_TRUE(e->condition()->Is()); - EXPECT_EQ(e->body()->size(), 2u); + ASSERT_NE(e->condition, nullptr); + ASSERT_TRUE(e->condition->Is()); + EXPECT_EQ(e->body->statements.size(), 2u); - ASSERT_EQ(e->else_statements().size(), 2u); - ASSERT_NE(e->else_statements()[0]->condition(), nullptr); + ASSERT_EQ(e->else_statements.size(), 2u); + ASSERT_NE(e->else_statements[0]->condition, nullptr); ASSERT_TRUE( - e->else_statements()[0]->condition()->Is()); - EXPECT_EQ(e->else_statements()[0]->body()->size(), 1u); + e->else_statements[0]->condition->Is()); + EXPECT_EQ(e->else_statements[0]->body->statements.size(), 1u); - ASSERT_EQ(e->else_statements()[1]->condition(), nullptr); - EXPECT_EQ(e->else_statements()[1]->body()->size(), 0u); + ASSERT_EQ(e->else_statements[1]->condition, nullptr); + EXPECT_EQ(e->else_statements[1]->body->statements.size(), 0u); } TEST_F(ParserImplTest, IfStmt_InvalidCondition) { diff --git a/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc b/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc index 8fee841ea8..15b04aaffd 100644 --- a/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc @@ -29,17 +29,17 @@ TEST_F(ParserImplTest, InclusiveOrExpression_Parses) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kOr, rel->op()); + EXPECT_EQ(ast::BinaryOp::kOr, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, InclusiveOrExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_logical_and_expression_test.cc b/src/reader/wgsl/parser_impl_logical_and_expression_test.cc index f987321a81..c2bbb2bfc2 100644 --- a/src/reader/wgsl/parser_impl_logical_and_expression_test.cc +++ b/src/reader/wgsl/parser_impl_logical_and_expression_test.cc @@ -29,17 +29,17 @@ TEST_F(ParserImplTest, LogicalAndExpression_Parses) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kLogicalAnd, rel->op()); + EXPECT_EQ(ast::BinaryOp::kLogicalAnd, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, LogicalAndExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_logical_or_expression_test.cc b/src/reader/wgsl/parser_impl_logical_or_expression_test.cc index aa1e0948f0..320bad6c17 100644 --- a/src/reader/wgsl/parser_impl_logical_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_logical_or_expression_test.cc @@ -29,17 +29,17 @@ TEST_F(ParserImplTest, LogicalOrExpression_Parses) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kLogicalOr, rel->op()); + EXPECT_EQ(ast::BinaryOp::kLogicalOr, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, LogicalOrExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_loop_stmt_test.cc b/src/reader/wgsl/parser_impl_loop_stmt_test.cc index b55aa91a09..4da4962d21 100644 --- a/src/reader/wgsl/parser_impl_loop_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_loop_stmt_test.cc @@ -28,10 +28,10 @@ TEST_F(ParserImplTest, LoopStmt_BodyNoContinuing) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_EQ(e->body()->size(), 1u); - EXPECT_TRUE(e->body()->get(0)->Is()); + ASSERT_EQ(e->body->statements.size(), 1u); + EXPECT_TRUE(e->body->statements[0]->Is()); - EXPECT_EQ(e->continuing()->size(), 0u); + EXPECT_EQ(e->continuing->statements.size(), 0u); } TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) { @@ -42,11 +42,11 @@ TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_EQ(e->body()->size(), 1u); - EXPECT_TRUE(e->body()->get(0)->Is()); + ASSERT_EQ(e->body->statements.size(), 1u); + EXPECT_TRUE(e->body->statements[0]->Is()); - EXPECT_EQ(e->continuing()->size(), 1u); - EXPECT_TRUE(e->continuing()->get(0)->Is()); + EXPECT_EQ(e->continuing->statements.size(), 1u); + EXPECT_TRUE(e->continuing->statements[0]->Is()); } TEST_F(ParserImplTest, LoopStmt_NoBodyNoContinuing) { @@ -56,8 +56,8 @@ TEST_F(ParserImplTest, LoopStmt_NoBodyNoContinuing) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_EQ(e->body()->size(), 0u); - ASSERT_EQ(e->continuing()->size(), 0u); + ASSERT_EQ(e->body->statements.size(), 0u); + ASSERT_EQ(e->continuing->statements.size(), 0u); } TEST_F(ParserImplTest, LoopStmt_NoBodyWithContinuing) { @@ -67,9 +67,9 @@ TEST_F(ParserImplTest, LoopStmt_NoBodyWithContinuing) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_EQ(e->body()->size(), 0u); - ASSERT_EQ(e->continuing()->size(), 1u); - EXPECT_TRUE(e->continuing()->get(0)->Is()); + ASSERT_EQ(e->body->statements.size(), 0u); + ASSERT_EQ(e->continuing->statements.size(), 1u); + EXPECT_TRUE(e->continuing->statements[0]->Is()); } TEST_F(ParserImplTest, LoopStmt_MissingBracketLeft) { diff --git a/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc b/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc index 05a3b760b1..ad860475d0 100644 --- a/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc +++ b/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc @@ -29,17 +29,17 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kMultiply, rel->op()); + EXPECT_EQ(ast::BinaryOp::kMultiply, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) { @@ -52,17 +52,17 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kDivide, rel->op()); + EXPECT_EQ(ast::BinaryOp::kDivide, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) { @@ -75,17 +75,17 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kModulo, rel->op()); + EXPECT_EQ(ast::BinaryOp::kModulo, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, MultiplicativeExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_param_list_test.cc b/src/reader/wgsl/parser_impl_param_list_test.cc index 4713462f85..e29725fcb2 100644 --- a/src/reader/wgsl/parser_impl_param_list_test.cc +++ b/src/reader/wgsl/parser_impl_param_list_test.cc @@ -27,14 +27,14 @@ TEST_F(ParserImplTest, ParamList_Single) { ASSERT_FALSE(e.errored); EXPECT_EQ(e.value.size(), 1u); - EXPECT_EQ(e.value[0]->symbol(), p->builder().Symbols().Get("a")); - EXPECT_TRUE(e.value[0]->type()->Is()); - EXPECT_TRUE(e.value[0]->is_const()); + EXPECT_EQ(e.value[0]->symbol, p->builder().Symbols().Get("a")); + EXPECT_TRUE(e.value[0]->type->Is()); + EXPECT_TRUE(e.value[0]->is_const); - ASSERT_EQ(e.value[0]->source().range.begin.line, 1u); - ASSERT_EQ(e.value[0]->source().range.begin.column, 1u); - ASSERT_EQ(e.value[0]->source().range.end.line, 1u); - ASSERT_EQ(e.value[0]->source().range.end.column, 2u); + ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); + ASSERT_EQ(e.value[0]->source.range.begin.column, 1u); + ASSERT_EQ(e.value[0]->source.range.end.line, 1u); + ASSERT_EQ(e.value[0]->source.range.end.column, 2u); } TEST_F(ParserImplTest, ParamList_Multiple) { @@ -45,34 +45,34 @@ TEST_F(ParserImplTest, ParamList_Multiple) { ASSERT_FALSE(e.errored); EXPECT_EQ(e.value.size(), 3u); - EXPECT_EQ(e.value[0]->symbol(), p->builder().Symbols().Get("a")); - EXPECT_TRUE(e.value[0]->type()->Is()); - EXPECT_TRUE(e.value[0]->is_const()); + EXPECT_EQ(e.value[0]->symbol, p->builder().Symbols().Get("a")); + EXPECT_TRUE(e.value[0]->type->Is()); + EXPECT_TRUE(e.value[0]->is_const); - ASSERT_EQ(e.value[0]->source().range.begin.line, 1u); - ASSERT_EQ(e.value[0]->source().range.begin.column, 1u); - ASSERT_EQ(e.value[0]->source().range.end.line, 1u); - ASSERT_EQ(e.value[0]->source().range.end.column, 2u); + ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); + ASSERT_EQ(e.value[0]->source.range.begin.column, 1u); + ASSERT_EQ(e.value[0]->source.range.end.line, 1u); + ASSERT_EQ(e.value[0]->source.range.end.column, 2u); - EXPECT_EQ(e.value[1]->symbol(), p->builder().Symbols().Get("b")); - EXPECT_TRUE(e.value[1]->type()->Is()); - EXPECT_TRUE(e.value[1]->is_const()); + EXPECT_EQ(e.value[1]->symbol, p->builder().Symbols().Get("b")); + EXPECT_TRUE(e.value[1]->type->Is()); + EXPECT_TRUE(e.value[1]->is_const); - ASSERT_EQ(e.value[1]->source().range.begin.line, 1u); - ASSERT_EQ(e.value[1]->source().range.begin.column, 10u); - ASSERT_EQ(e.value[1]->source().range.end.line, 1u); - ASSERT_EQ(e.value[1]->source().range.end.column, 11u); + ASSERT_EQ(e.value[1]->source.range.begin.line, 1u); + ASSERT_EQ(e.value[1]->source.range.begin.column, 10u); + ASSERT_EQ(e.value[1]->source.range.end.line, 1u); + ASSERT_EQ(e.value[1]->source.range.end.column, 11u); - EXPECT_EQ(e.value[2]->symbol(), p->builder().Symbols().Get("c")); - ASSERT_TRUE(e.value[2]->type()->Is()); - ASSERT_TRUE(e.value[2]->type()->As()->type()->Is()); - EXPECT_EQ(e.value[2]->type()->As()->size(), 2u); - EXPECT_TRUE(e.value[2]->is_const()); + EXPECT_EQ(e.value[2]->symbol, p->builder().Symbols().Get("c")); + ASSERT_TRUE(e.value[2]->type->Is()); + ASSERT_TRUE(e.value[2]->type->As()->type->Is()); + EXPECT_EQ(e.value[2]->type->As()->width, 2u); + EXPECT_TRUE(e.value[2]->is_const); - ASSERT_EQ(e.value[2]->source().range.begin.line, 1u); - ASSERT_EQ(e.value[2]->source().range.begin.column, 18u); - ASSERT_EQ(e.value[2]->source().range.end.line, 1u); - ASSERT_EQ(e.value[2]->source().range.end.column, 19u); + ASSERT_EQ(e.value[2]->source.range.begin.line, 1u); + ASSERT_EQ(e.value[2]->source.range.begin.column, 18u); + ASSERT_EQ(e.value[2]->source.range.end.line, 1u); + ASSERT_EQ(e.value[2]->source.range.end.column, 19u); } TEST_F(ParserImplTest, ParamList_Empty) { @@ -101,34 +101,34 @@ TEST_F(ParserImplTest, ParamList_Decorations) { ASSERT_FALSE(e.errored); ASSERT_EQ(e.value.size(), 2u); - EXPECT_EQ(e.value[0]->symbol(), p->builder().Symbols().Get("coord")); - ASSERT_TRUE(e.value[0]->type()->Is()); - EXPECT_TRUE(e.value[0]->type()->As()->type()->Is()); - EXPECT_EQ(e.value[0]->type()->As()->size(), 4u); - EXPECT_TRUE(e.value[0]->is_const()); - auto decos0 = e.value[0]->decorations(); + EXPECT_EQ(e.value[0]->symbol, p->builder().Symbols().Get("coord")); + ASSERT_TRUE(e.value[0]->type->Is()); + EXPECT_TRUE(e.value[0]->type->As()->type->Is()); + EXPECT_EQ(e.value[0]->type->As()->width, 4u); + EXPECT_TRUE(e.value[0]->is_const); + auto decos0 = e.value[0]->decorations; ASSERT_EQ(decos0.size(), 1u); EXPECT_TRUE(decos0[0]->Is()); - EXPECT_EQ(decos0[0]->As()->value(), + EXPECT_EQ(decos0[0]->As()->builtin, ast::Builtin::kPosition); - ASSERT_EQ(e.value[0]->source().range.begin.line, 1u); - ASSERT_EQ(e.value[0]->source().range.begin.column, 23u); - ASSERT_EQ(e.value[0]->source().range.end.line, 1u); - ASSERT_EQ(e.value[0]->source().range.end.column, 28u); + ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); + ASSERT_EQ(e.value[0]->source.range.begin.column, 23u); + ASSERT_EQ(e.value[0]->source.range.end.line, 1u); + ASSERT_EQ(e.value[0]->source.range.end.column, 28u); - EXPECT_EQ(e.value[1]->symbol(), p->builder().Symbols().Get("loc1")); - EXPECT_TRUE(e.value[1]->type()->Is()); - EXPECT_TRUE(e.value[1]->is_const()); - auto decos1 = e.value[1]->decorations(); + EXPECT_EQ(e.value[1]->symbol, p->builder().Symbols().Get("loc1")); + EXPECT_TRUE(e.value[1]->type->Is()); + EXPECT_TRUE(e.value[1]->is_const); + auto decos1 = e.value[1]->decorations; ASSERT_EQ(decos1.size(), 1u); EXPECT_TRUE(decos1[0]->Is()); - EXPECT_EQ(decos1[0]->As()->value(), 1u); + EXPECT_EQ(decos1[0]->As()->value, 1u); - ASSERT_EQ(e.value[1]->source().range.begin.line, 1u); - ASSERT_EQ(e.value[1]->source().range.begin.column, 58u); - ASSERT_EQ(e.value[1]->source().range.end.line, 1u); - ASSERT_EQ(e.value[1]->source().range.end.column, 62u); + ASSERT_EQ(e.value[1]->source.range.begin.line, 1u); + ASSERT_EQ(e.value[1]->source.range.begin.column, 58u); + ASSERT_EQ(e.value[1]->source.range.end.line, 1u); + ASSERT_EQ(e.value[1]->source.range.end.column, 62u); } } // namespace diff --git a/src/reader/wgsl/parser_impl_primary_expression_test.cc b/src/reader/wgsl/parser_impl_primary_expression_test.cc index 28241a623a..4a23abc78d 100644 --- a/src/reader/wgsl/parser_impl_primary_expression_test.cc +++ b/src/reader/wgsl/parser_impl_primary_expression_test.cc @@ -29,7 +29,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Ident) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); auto* ident = e->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); } TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) { @@ -43,31 +43,31 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) { ASSERT_TRUE(e->Is()); auto* ty = e->As(); - ASSERT_EQ(ty->values().size(), 4u); - const auto& val = ty->values(); + ASSERT_EQ(ty->values.size(), 4u); + const auto& val = ty->values; ASSERT_TRUE(val[0]->Is()); ASSERT_TRUE(val[0]->Is()); auto* ident = val[0]->As(); - ASSERT_TRUE(ident->literal()->Is()); - EXPECT_EQ(ident->literal()->As()->value(), 1); + ASSERT_TRUE(ident->literal->Is()); + EXPECT_EQ(ident->literal->As()->value, 1); ASSERT_TRUE(val[1]->Is()); ASSERT_TRUE(val[1]->Is()); ident = val[1]->As(); - ASSERT_TRUE(ident->literal()->Is()); - EXPECT_EQ(ident->literal()->As()->value(), 2); + ASSERT_TRUE(ident->literal->Is()); + EXPECT_EQ(ident->literal->As()->value, 2); ASSERT_TRUE(val[2]->Is()); ASSERT_TRUE(val[2]->Is()); ident = val[2]->As(); - ASSERT_TRUE(ident->literal()->Is()); - EXPECT_EQ(ident->literal()->As()->value(), 3); + ASSERT_TRUE(ident->literal->Is()); + EXPECT_EQ(ident->literal->As()->value, 3); ASSERT_TRUE(val[3]->Is()); ASSERT_TRUE(val[3]->Is()); ident = val[3]->As(); - ASSERT_TRUE(ident->literal()->Is()); - EXPECT_EQ(ident->literal()->As()->value(), 4); + ASSERT_TRUE(ident->literal->Is()); + EXPECT_EQ(ident->literal->As()->value, 4); } TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_ZeroConstructor) { @@ -81,7 +81,7 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_ZeroConstructor) { ASSERT_TRUE(e->Is()); auto* ty = e->As(); - ASSERT_EQ(ty->values().size(), 0u); + ASSERT_EQ(ty->values.size(), 0u); } TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_InvalidTypeDecl) { @@ -141,11 +141,11 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructConstructor_Empty) { ASSERT_TRUE(e->Is()); auto* constructor = e->As(); - ASSERT_TRUE(constructor->type()->Is()); - EXPECT_EQ(constructor->type()->As()->name(), + ASSERT_TRUE(constructor->type->Is()); + EXPECT_EQ(constructor->type->As()->name, p->builder().Symbols().Get("S")); - auto values = constructor->values(); + auto values = constructor->values; ASSERT_EQ(values.size(), 0u); } @@ -166,22 +166,22 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructConstructor_NotEmpty) { ASSERT_TRUE(e->Is()); auto* constructor = e->As(); - ASSERT_TRUE(constructor->type()->Is()); - EXPECT_EQ(constructor->type()->As()->name(), + ASSERT_TRUE(constructor->type->Is()); + EXPECT_EQ(constructor->type->As()->name, p->builder().Symbols().Get("S")); - auto values = constructor->values(); + auto values = constructor->values; ASSERT_EQ(values.size(), 2u); ASSERT_TRUE(values[0]->Is()); auto* val0 = values[0]->As(); - ASSERT_TRUE(val0->literal()->Is()); - EXPECT_EQ(val0->literal()->As()->value(), 1u); + ASSERT_TRUE(val0->literal->Is()); + EXPECT_EQ(val0->literal->As()->value, 1u); ASSERT_TRUE(values[1]->Is()); auto* val1 = values[1]->As(); - ASSERT_TRUE(val1->literal()->Is()); - EXPECT_EQ(val1->literal()->As()->value(), 2.f); + ASSERT_TRUE(val1->literal->Is()); + EXPECT_EQ(val1->literal->As()->value, 2.f); } TEST_F(ParserImplTest, PrimaryExpression_ConstLiteral_True) { @@ -194,8 +194,8 @@ TEST_F(ParserImplTest, PrimaryExpression_ConstLiteral_True) { ASSERT_TRUE(e->Is()); ASSERT_TRUE(e->Is()); auto* init = e->As(); - ASSERT_TRUE(init->literal()->Is()); - EXPECT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(init->literal->Is()); + EXPECT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, PrimaryExpression_ParenExpr) { @@ -250,11 +250,11 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) { ASSERT_TRUE(e->Is()); auto* c = e->As(); - ASSERT_TRUE(c->type()->Is()); - ASSERT_EQ(c->values().size(), 1u); + ASSERT_TRUE(c->type->Is()); + ASSERT_EQ(c->values.size(), 1u); - ASSERT_TRUE(c->values()[0]->Is()); - ASSERT_TRUE(c->values()[0]->Is()); + ASSERT_TRUE(c->values[0]->Is()); + ASSERT_TRUE(c->values[0]->Is()); } TEST_F(ParserImplTest, PrimaryExpression_Bitcast) { @@ -268,9 +268,9 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) { ASSERT_TRUE(e->Is()); auto* c = e->As(); - ASSERT_TRUE(c->type()->Is()); - ASSERT_TRUE(c->expr()->Is()); - ASSERT_TRUE(c->expr()->Is()); + ASSERT_TRUE(c->type->Is()); + ASSERT_TRUE(c->expr->Is()); + ASSERT_TRUE(c->expr->Is()); } TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingGreaterThan) { diff --git a/src/reader/wgsl/parser_impl_relational_expression_test.cc b/src/reader/wgsl/parser_impl_relational_expression_test.cc index 80584875b3..2bbfcbfe2b 100644 --- a/src/reader/wgsl/parser_impl_relational_expression_test.cc +++ b/src/reader/wgsl/parser_impl_relational_expression_test.cc @@ -29,17 +29,17 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThan) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kLessThan, rel->op()); + EXPECT_EQ(ast::BinaryOp::kLessThan, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Register("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) { @@ -52,17 +52,17 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kGreaterThan, rel->op()); + EXPECT_EQ(ast::BinaryOp::kGreaterThan, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Register("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) { @@ -75,17 +75,17 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kLessThanEqual, rel->op()); + EXPECT_EQ(ast::BinaryOp::kLessThanEqual, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Register("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) { @@ -98,17 +98,17 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kGreaterThanEqual, rel->op()); + EXPECT_EQ(ast::BinaryOp::kGreaterThanEqual, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Register("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, RelationalExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_sampler_type_test.cc b/src/reader/wgsl/parser_impl_sampler_type_test.cc index a7891e25f7..32de50d91b 100644 --- a/src/reader/wgsl/parser_impl_sampler_type_test.cc +++ b/src/reader/wgsl/parser_impl_sampler_type_test.cc @@ -37,7 +37,7 @@ TEST_F(ParserImplTest, SamplerType_Sampler) { ASSERT_TRUE(t->Is()); EXPECT_FALSE(t->As()->IsComparison()); EXPECT_FALSE(p->has_error()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 8u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); } TEST_F(ParserImplTest, SamplerType_ComparisonSampler) { @@ -49,7 +49,7 @@ TEST_F(ParserImplTest, SamplerType_ComparisonSampler) { ASSERT_TRUE(t->Is()); EXPECT_TRUE(t->As()->IsComparison()); EXPECT_FALSE(p->has_error()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 19u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } } // namespace diff --git a/src/reader/wgsl/parser_impl_shift_expression_test.cc b/src/reader/wgsl/parser_impl_shift_expression_test.cc index e4d93e9ef4..58675d6b0c 100644 --- a/src/reader/wgsl/parser_impl_shift_expression_test.cc +++ b/src/reader/wgsl/parser_impl_shift_expression_test.cc @@ -29,17 +29,17 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftLeft) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kShiftLeft, rel->op()); + EXPECT_EQ(ast::BinaryOp::kShiftLeft, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) { @@ -52,17 +52,17 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) { ASSERT_TRUE(e->Is()); auto* rel = e->As(); - EXPECT_EQ(ast::BinaryOp::kShiftRight, rel->op()); + EXPECT_EQ(ast::BinaryOp::kShiftRight, rel->op); - ASSERT_TRUE(rel->lhs()->Is()); - auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs()->Is()); - ASSERT_TRUE(rel->rhs()->Is()); - auto* init = rel->rhs()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_TRUE(init->literal()->As()->IsTrue()); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->Is()); + auto* init = rel->rhs->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_TRUE(init->literal->As()->value); } TEST_F(ParserImplTest, ShiftExpression_InvalidSpaceLeft) { diff --git a/src/reader/wgsl/parser_impl_singular_expression_test.cc b/src/reader/wgsl/parser_impl_singular_expression_test.cc index 36b803dbb3..50afbb07c8 100644 --- a/src/reader/wgsl/parser_impl_singular_expression_test.cc +++ b/src/reader/wgsl/parser_impl_singular_expression_test.cc @@ -30,15 +30,15 @@ TEST_F(ParserImplTest, SingularExpression_Array_ConstantIndex) { ASSERT_TRUE(e->Is()); auto* ary = e->As(); - ASSERT_TRUE(ary->array()->Is()); - auto* ident = ary->array()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(ary->array->Is()); + auto* ident = ary->array->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(ary->idx_expr()->Is()); - ASSERT_TRUE(ary->idx_expr()->Is()); - auto* c = ary->idx_expr()->As(); - ASSERT_TRUE(c->literal()->Is()); - EXPECT_EQ(c->literal()->As()->value(), 1); + ASSERT_TRUE(ary->index->Is()); + ASSERT_TRUE(ary->index->Is()); + auto* c = ary->index->As(); + ASSERT_TRUE(c->literal->Is()); + EXPECT_EQ(c->literal->As()->value, 1); } TEST_F(ParserImplTest, SingularExpression_Array_ExpressionIndex) { @@ -52,11 +52,11 @@ TEST_F(ParserImplTest, SingularExpression_Array_ExpressionIndex) { ASSERT_TRUE(e->Is()); auto* ary = e->As(); - ASSERT_TRUE(ary->array()->Is()); - auto* ident = ary->array()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(ary->array->Is()); + auto* ident = ary->array->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(ary->idx_expr()->Is()); + ASSERT_TRUE(ary->index->Is()); } TEST_F(ParserImplTest, SingularExpression_Array_MissingIndex) { @@ -100,9 +100,9 @@ TEST_F(ParserImplTest, SingularExpression_Call_Empty) { ASSERT_TRUE(e->Is()); auto* c = e->As(); - EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("a")); - EXPECT_EQ(c->args().size(), 0u); + EXPECT_EQ(c->args.size(), 0u); } TEST_F(ParserImplTest, SingularExpression_Call_WithArgs) { @@ -116,12 +116,12 @@ TEST_F(ParserImplTest, SingularExpression_Call_WithArgs) { ASSERT_TRUE(e->Is()); auto* c = e->As(); - EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("test")); + EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("test")); - EXPECT_EQ(c->args().size(), 3u); - EXPECT_TRUE(c->args()[0]->Is()); - EXPECT_TRUE(c->args()[1]->Is()); - EXPECT_TRUE(c->args()[2]->Is()); + EXPECT_EQ(c->args.size(), 3u); + EXPECT_TRUE(c->args[0]->Is()); + EXPECT_TRUE(c->args[1]->Is()); + EXPECT_TRUE(c->args[2]->Is()); } TEST_F(ParserImplTest, SingularExpression_Call_TrailingComma) { @@ -133,7 +133,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_TrailingComma) { ASSERT_TRUE(e->Is()); auto* c = e->As(); - EXPECT_EQ(c->args().size(), 1u); + EXPECT_EQ(c->args.size(), 1u); } TEST_F(ParserImplTest, SingularExpression_Call_InvalidArg) { @@ -166,12 +166,12 @@ TEST_F(ParserImplTest, SingularExpression_MemberAccessor) { ASSERT_TRUE(e->Is()); auto* m = e->As(); - ASSERT_TRUE(m->structure()->Is()); - EXPECT_EQ(m->structure()->As()->symbol(), + ASSERT_TRUE(m->structure->Is()); + EXPECT_EQ(m->structure->As()->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(m->member()->Is()); - EXPECT_EQ(m->member()->As()->symbol(), + ASSERT_TRUE(m->member->Is()); + EXPECT_EQ(m->member->As()->symbol, p->builder().Symbols().Get("b")); } @@ -217,23 +217,23 @@ TEST_F(ParserImplTest, SingularExpression_Array_NestedArrayAccessor) { ASSERT_TRUE(outer_accessor); const auto* outer_array = - outer_accessor->array()->As(); + outer_accessor->array->As(); ASSERT_TRUE(outer_array); - EXPECT_EQ(outer_array->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(outer_array->symbol, p->builder().Symbols().Get("a")); const auto* inner_accessor = - outer_accessor->idx_expr()->As(); + outer_accessor->index->As(); ASSERT_TRUE(inner_accessor); const auto* inner_array = - inner_accessor->array()->As(); + inner_accessor->array->As(); ASSERT_TRUE(inner_array); - EXPECT_EQ(inner_array->symbol(), p->builder().Symbols().Get("b")); + EXPECT_EQ(inner_array->symbol, p->builder().Symbols().Get("b")); const auto* index_expr = - inner_accessor->idx_expr()->As(); + inner_accessor->index->As(); ASSERT_TRUE(index_expr); - EXPECT_EQ(index_expr->symbol(), p->builder().Symbols().Get("c")); + EXPECT_EQ(index_expr->symbol, p->builder().Symbols().Get("c")); } TEST_F(ParserImplTest, SingularExpression_PostfixPlusPlus) { diff --git a/src/reader/wgsl/parser_impl_statement_test.cc b/src/reader/wgsl/parser_impl_statement_test.cc index 153ebd3a19..5a63a034e8 100644 --- a/src/reader/wgsl/parser_impl_statement_test.cc +++ b/src/reader/wgsl/parser_impl_statement_test.cc @@ -45,7 +45,7 @@ TEST_F(ParserImplTest, Statement_Return_NoValue) { EXPECT_FALSE(e.errored); ASSERT_TRUE(e->Is()); auto* ret = e->As(); - ASSERT_EQ(ret->value(), nullptr); + ASSERT_EQ(ret->value, nullptr); } TEST_F(ParserImplTest, Statement_Return_Value) { @@ -57,8 +57,8 @@ TEST_F(ParserImplTest, Statement_Return_Value) { EXPECT_FALSE(e.errored); ASSERT_TRUE(e->Is()); auto* ret = e->As(); - ASSERT_NE(ret->value(), nullptr); - EXPECT_TRUE(ret->value()->Is()); + ASSERT_NE(ret->value, nullptr); + EXPECT_TRUE(ret->value->Is()); } TEST_F(ParserImplTest, Statement_Return_MissingSemi) { @@ -261,8 +261,9 @@ TEST_F(ParserImplTest, Statement_Body) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); ASSERT_TRUE(e->Is()); - EXPECT_TRUE( - e->As()->get(0)->Is()); + EXPECT_TRUE(e->As() + ->statements[0] + ->Is()); } TEST_F(ParserImplTest, Statement_Body_Invalid) { diff --git a/src/reader/wgsl/parser_impl_struct_body_decl_test.cc b/src/reader/wgsl/parser_impl_struct_body_decl_test.cc index cd0b526623..729fac475e 100644 --- a/src/reader/wgsl/parser_impl_struct_body_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_body_decl_test.cc @@ -30,9 +30,9 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) { ASSERT_EQ(m.value.size(), 1u); const auto* mem = m.value[0]; - EXPECT_EQ(mem->symbol(), builder.Symbols().Get("a")); - EXPECT_TRUE(mem->type()->Is()); - EXPECT_EQ(mem->decorations().size(), 0u); + EXPECT_EQ(mem->symbol, builder.Symbols().Get("a")); + EXPECT_TRUE(mem->type->Is()); + EXPECT_EQ(mem->decorations.size(), 0u); } TEST_F(ParserImplTest, StructBodyDecl_ParsesEmpty) { diff --git a/src/reader/wgsl/parser_impl_struct_decl_test.cc b/src/reader/wgsl/parser_impl_struct_decl_test.cc index 1d5b78351b..e7c4e9f745 100644 --- a/src/reader/wgsl/parser_impl_struct_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_decl_test.cc @@ -36,10 +36,10 @@ struct S { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s->name(), p->builder().Symbols().Register("S")); - ASSERT_EQ(s->members().size(), 2u); - EXPECT_EQ(s->members()[0]->symbol(), p->builder().Symbols().Register("a")); - EXPECT_EQ(s->members()[1]->symbol(), p->builder().Symbols().Register("b")); + ASSERT_EQ(s->name, p->builder().Symbols().Register("S")); + ASSERT_EQ(s->members.size(), 2u); + EXPECT_EQ(s->members[0]->symbol, p->builder().Symbols().Register("a")); + EXPECT_EQ(s->members[1]->symbol, p->builder().Symbols().Register("b")); } TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) { @@ -58,12 +58,12 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s->name(), p->builder().Symbols().Register("B")); - ASSERT_EQ(s->members().size(), 2u); - EXPECT_EQ(s->members()[0]->symbol(), p->builder().Symbols().Register("a")); - EXPECT_EQ(s->members()[1]->symbol(), p->builder().Symbols().Register("b")); - ASSERT_EQ(s->decorations().size(), 1u); - EXPECT_TRUE(s->decorations()[0]->Is()); + ASSERT_EQ(s->name, p->builder().Symbols().Register("B")); + ASSERT_EQ(s->members.size(), 2u); + EXPECT_EQ(s->members[0]->symbol, p->builder().Symbols().Register("a")); + EXPECT_EQ(s->members[1]->symbol, p->builder().Symbols().Register("b")); + ASSERT_EQ(s->decorations.size(), 1u); + EXPECT_TRUE(s->decorations[0]->Is()); } TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) { @@ -83,13 +83,13 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s->name(), p->builder().Symbols().Register("S")); - ASSERT_EQ(s->members().size(), 2u); - EXPECT_EQ(s->members()[0]->symbol(), p->builder().Symbols().Register("a")); - EXPECT_EQ(s->members()[1]->symbol(), p->builder().Symbols().Register("b")); - ASSERT_EQ(s->decorations().size(), 2u); - EXPECT_TRUE(s->decorations()[0]->Is()); - EXPECT_TRUE(s->decorations()[1]->Is()); + ASSERT_EQ(s->name, p->builder().Symbols().Register("S")); + ASSERT_EQ(s->members.size(), 2u); + EXPECT_EQ(s->members[0]->symbol, p->builder().Symbols().Register("a")); + EXPECT_EQ(s->members[1]->symbol, p->builder().Symbols().Register("b")); + ASSERT_EQ(s->decorations.size(), 2u); + EXPECT_TRUE(s->decorations[0]->Is()); + EXPECT_TRUE(s->decorations[1]->Is()); } TEST_F(ParserImplTest, StructDecl_EmptyMembers) { @@ -104,7 +104,7 @@ TEST_F(ParserImplTest, StructDecl_EmptyMembers) { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s->members().size(), 0u); + ASSERT_EQ(s->members.size(), 0u); } TEST_F(ParserImplTest, StructDecl_MissingIdent) { diff --git a/src/reader/wgsl/parser_impl_struct_member_decoration_test.cc b/src/reader/wgsl/parser_impl_struct_member_decoration_test.cc index 6add8ee355..eee2718332 100644 --- a/src/reader/wgsl/parser_impl_struct_member_decoration_test.cc +++ b/src/reader/wgsl/parser_impl_struct_member_decoration_test.cc @@ -32,7 +32,7 @@ TEST_F(ParserImplTest, Decoration_Size) { ASSERT_TRUE(member_deco->Is()); auto* o = member_deco->As(); - EXPECT_EQ(o->size(), 4u); + EXPECT_EQ(o->size, 4u); } TEST_F(ParserImplTest, Decoration_Size_MissingLeftParen) { @@ -90,7 +90,7 @@ TEST_F(ParserImplTest, Decoration_Align) { ASSERT_TRUE(member_deco->Is()); auto* o = member_deco->As(); - EXPECT_EQ(o->align(), 4u); + EXPECT_EQ(o->align, 4u); } TEST_F(ParserImplTest, Decoration_Align_MissingLeftParen) { diff --git a/src/reader/wgsl/parser_impl_struct_member_test.cc b/src/reader/wgsl/parser_impl_struct_member_test.cc index 2ba2260591..8a514acbbe 100644 --- a/src/reader/wgsl/parser_impl_struct_member_test.cc +++ b/src/reader/wgsl/parser_impl_struct_member_test.cc @@ -34,12 +34,12 @@ TEST_F(ParserImplTest, StructMember_Parses) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->symbol(), builder.Symbols().Get("a")); - EXPECT_TRUE(m->type()->Is()); - EXPECT_EQ(m->decorations().size(), 0u); + EXPECT_EQ(m->symbol, builder.Symbols().Get("a")); + EXPECT_TRUE(m->type->Is()); + EXPECT_EQ(m->decorations.size(), 0u); - EXPECT_EQ(m->source().range, (Source::Range{{1u, 1u}, {1u, 2u}})); - EXPECT_EQ(m->type()->source().range, (Source::Range{{1u, 5u}, {1u, 8u}})); + EXPECT_EQ(m->source.range, (Source::Range{{1u, 1u}, {1u, 2u}})); + EXPECT_EQ(m->type->source.range, (Source::Range{{1u, 5u}, {1u, 8u}})); } TEST_F(ParserImplTest, StructMember_ParsesWithAlignDecoration) { @@ -57,15 +57,15 @@ TEST_F(ParserImplTest, StructMember_ParsesWithAlignDecoration) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->symbol(), builder.Symbols().Get("a")); - EXPECT_TRUE(m->type()->Is()); - EXPECT_EQ(m->decorations().size(), 1u); - EXPECT_TRUE(m->decorations()[0]->Is()); - EXPECT_EQ( - m->decorations()[0]->As()->align(), 2u); + EXPECT_EQ(m->symbol, builder.Symbols().Get("a")); + EXPECT_TRUE(m->type->Is()); + EXPECT_EQ(m->decorations.size(), 1u); + EXPECT_TRUE(m->decorations[0]->Is()); + EXPECT_EQ(m->decorations[0]->As()->align, + 2u); - EXPECT_EQ(m->source().range, (Source::Range{{1u, 14u}, {1u, 15u}})); - EXPECT_EQ(m->type()->source().range, (Source::Range{{1u, 18u}, {1u, 21u}})); + EXPECT_EQ(m->source.range, (Source::Range{{1u, 14u}, {1u, 15u}})); + EXPECT_EQ(m->type->source.range, (Source::Range{{1u, 18u}, {1u, 21u}})); } TEST_F(ParserImplTest, StructMember_ParsesWithSizeDecoration) { @@ -83,15 +83,14 @@ TEST_F(ParserImplTest, StructMember_ParsesWithSizeDecoration) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->symbol(), builder.Symbols().Get("a")); - EXPECT_TRUE(m->type()->Is()); - EXPECT_EQ(m->decorations().size(), 1u); - EXPECT_TRUE(m->decorations()[0]->Is()); - EXPECT_EQ(m->decorations()[0]->As()->size(), - 2u); + EXPECT_EQ(m->symbol, builder.Symbols().Get("a")); + EXPECT_TRUE(m->type->Is()); + EXPECT_EQ(m->decorations.size(), 1u); + EXPECT_TRUE(m->decorations[0]->Is()); + EXPECT_EQ(m->decorations[0]->As()->size, 2u); - EXPECT_EQ(m->source().range, (Source::Range{{1u, 13u}, {1u, 14u}})); - EXPECT_EQ(m->type()->source().range, (Source::Range{{1u, 17u}, {1u, 20u}})); + EXPECT_EQ(m->source.range, (Source::Range{{1u, 13u}, {1u, 14u}})); + EXPECT_EQ(m->type->source.range, (Source::Range{{1u, 17u}, {1u, 20u}})); } TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) { @@ -109,15 +108,14 @@ TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->symbol(), builder.Symbols().Get("a")); - EXPECT_TRUE(m->type()->Is()); - EXPECT_EQ(m->decorations().size(), 1u); - EXPECT_TRUE(m->decorations()[0]->Is()); - EXPECT_EQ(m->decorations()[0]->As()->size(), - 2u); + EXPECT_EQ(m->symbol, builder.Symbols().Get("a")); + EXPECT_TRUE(m->type->Is()); + EXPECT_EQ(m->decorations.size(), 1u); + EXPECT_TRUE(m->decorations[0]->Is()); + EXPECT_EQ(m->decorations[0]->As()->size, 2u); - EXPECT_EQ(m->source().range, (Source::Range{{1u, 13u}, {1u, 14u}})); - EXPECT_EQ(m->type()->source().range, (Source::Range{{1u, 17u}, {1u, 20u}})); + EXPECT_EQ(m->source.range, (Source::Range{{1u, 13u}, {1u, 14u}})); + EXPECT_EQ(m->type->source.range, (Source::Range{{1u, 17u}, {1u, 20u}})); } TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) { @@ -136,18 +134,17 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->symbol(), builder.Symbols().Get("a")); - EXPECT_TRUE(m->type()->Is()); - EXPECT_EQ(m->decorations().size(), 2u); - EXPECT_TRUE(m->decorations()[0]->Is()); - EXPECT_EQ(m->decorations()[0]->As()->size(), - 2u); - EXPECT_TRUE(m->decorations()[1]->Is()); - EXPECT_EQ( - m->decorations()[1]->As()->align(), 4u); + EXPECT_EQ(m->symbol, builder.Symbols().Get("a")); + EXPECT_TRUE(m->type->Is()); + EXPECT_EQ(m->decorations.size(), 2u); + EXPECT_TRUE(m->decorations[0]->Is()); + EXPECT_EQ(m->decorations[0]->As()->size, 2u); + EXPECT_TRUE(m->decorations[1]->Is()); + EXPECT_EQ(m->decorations[1]->As()->align, + 4u); - EXPECT_EQ(m->source().range, (Source::Range{{2u, 14u}, {2u, 15u}})); - EXPECT_EQ(m->type()->source().range, (Source::Range{{2u, 18u}, {2u, 21u}})); + EXPECT_EQ(m->source.range, (Source::Range{{2u, 14u}, {2u, 15u}})); + EXPECT_EQ(m->type->source.range, (Source::Range{{2u, 18u}, {2u, 21u}})); } TEST_F(ParserImplTest, StructMember_InvalidDecoration) { diff --git a/src/reader/wgsl/parser_impl_switch_body_test.cc b/src/reader/wgsl/parser_impl_switch_body_test.cc index e9b7809cef..f6fa138717 100644 --- a/src/reader/wgsl/parser_impl_switch_body_test.cc +++ b/src/reader/wgsl/parser_impl_switch_body_test.cc @@ -29,10 +29,10 @@ TEST_F(ParserImplTest, SwitchBody_Case) { ASSERT_TRUE(e->Is()); EXPECT_FALSE(e->IsDefault()); auto* stmt = e->As(); - ASSERT_EQ(stmt->selectors().size(), 1u); - EXPECT_EQ(stmt->selectors()[0]->value_as_u32(), 1u); - ASSERT_EQ(e->body()->size(), 1u); - EXPECT_TRUE(e->body()->get(0)->Is()); + ASSERT_EQ(stmt->selectors.size(), 1u); + EXPECT_EQ(stmt->selectors[0]->ValueAsU32(), 1u); + ASSERT_EQ(e->body->statements.size(), 1u); + EXPECT_TRUE(e->body->statements[0]->Is()); } TEST_F(ParserImplTest, SwitchBody_Case_TrailingComma) { @@ -45,9 +45,9 @@ TEST_F(ParserImplTest, SwitchBody_Case_TrailingComma) { ASSERT_TRUE(e->Is()); EXPECT_FALSE(e->IsDefault()); auto* stmt = e->As(); - ASSERT_EQ(stmt->selectors().size(), 2u); - EXPECT_EQ(stmt->selectors()[0]->value_as_u32(), 1u); - EXPECT_EQ(stmt->selectors()[1]->value_as_u32(), 2u); + ASSERT_EQ(stmt->selectors.size(), 2u); + EXPECT_EQ(stmt->selectors[0]->ValueAsU32(), 1u); + EXPECT_EQ(stmt->selectors[1]->ValueAsU32(), 2u); } TEST_F(ParserImplTest, SwitchBody_Case_InvalidConstLiteral) { @@ -129,10 +129,10 @@ TEST_F(ParserImplTest, SwitchBody_Case_MultipleSelectors) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); EXPECT_FALSE(e->IsDefault()); - ASSERT_EQ(e->body()->size(), 0u); - ASSERT_EQ(e->selectors().size(), 2u); - ASSERT_EQ(e->selectors()[0]->value_as_i32(), 1); - ASSERT_EQ(e->selectors()[1]->value_as_i32(), 2); + ASSERT_EQ(e->body->statements.size(), 0u); + ASSERT_EQ(e->selectors.size(), 2u); + ASSERT_EQ(e->selectors[0]->ValueAsI32(), 1); + ASSERT_EQ(e->selectors[1]->ValueAsI32(), 2); } TEST_F(ParserImplTest, SwitchBody_Case_MultipleSelectorsMissingColon) { @@ -174,8 +174,8 @@ TEST_F(ParserImplTest, SwitchBody_Default) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); EXPECT_TRUE(e->IsDefault()); - ASSERT_EQ(e->body()->size(), 1u); - EXPECT_TRUE(e->body()->get(0)->Is()); + ASSERT_EQ(e->body->statements.size(), 1u); + EXPECT_TRUE(e->body->statements[0]->Is()); } TEST_F(ParserImplTest, SwitchBody_Default_MissingColon) { diff --git a/src/reader/wgsl/parser_impl_switch_stmt_test.cc b/src/reader/wgsl/parser_impl_switch_stmt_test.cc index 5d73e04eab..496335654b 100644 --- a/src/reader/wgsl/parser_impl_switch_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_switch_stmt_test.cc @@ -30,9 +30,9 @@ TEST_F(ParserImplTest, SwitchStmt_WithoutDefault) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_EQ(e->body().size(), 2u); - EXPECT_FALSE(e->body()[0]->IsDefault()); - EXPECT_FALSE(e->body()[1]->IsDefault()); + ASSERT_EQ(e->body.size(), 2u); + EXPECT_FALSE(e->body[0]->IsDefault()); + EXPECT_FALSE(e->body[1]->IsDefault()); } TEST_F(ParserImplTest, SwitchStmt_Empty) { @@ -43,7 +43,7 @@ TEST_F(ParserImplTest, SwitchStmt_Empty) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_EQ(e->body().size(), 0u); + ASSERT_EQ(e->body.size(), 0u); } TEST_F(ParserImplTest, SwitchStmt_DefaultInMiddle) { @@ -59,10 +59,10 @@ TEST_F(ParserImplTest, SwitchStmt_DefaultInMiddle) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_EQ(e->body().size(), 3u); - ASSERT_FALSE(e->body()[0]->IsDefault()); - ASSERT_TRUE(e->body()[1]->IsDefault()); - ASSERT_FALSE(e->body()[2]->IsDefault()); + ASSERT_EQ(e->body.size(), 3u); + ASSERT_FALSE(e->body[0]->IsDefault()); + ASSERT_TRUE(e->body[1]->IsDefault()); + ASSERT_FALSE(e->body[2]->IsDefault()); } TEST_F(ParserImplTest, SwitchStmt_InvalidExpression) { diff --git a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc index c006882aa7..970e4303fd 100644 --- a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc +++ b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc @@ -40,7 +40,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_Sampler) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_FALSE(t->As()->IsComparison()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 8u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_SamplerComparison) { @@ -52,7 +52,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SamplerComparison) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->As()->IsComparison()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 19u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { @@ -64,8 +64,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::k2d); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 17u}})); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) { @@ -77,9 +77,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::k1d); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 16u}})); + ASSERT_TRUE(t->As()->type->Is()); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::k1d); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { @@ -91,9 +91,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::k2d); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 16u}})); + ASSERT_TRUE(t->As()->type->Is()); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { @@ -105,9 +105,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::k3d); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 16u}})); + ASSERT_TRUE(t->As()->type->Is()); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::k3d); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid) { @@ -159,9 +159,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::k2d); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 29u}})); + ASSERT_TRUE(t->As()->type->Is()); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 29u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_Invalid) { @@ -214,11 +214,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) { ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->image_format(), - ast::ImageFormat::kR8Unorm); - EXPECT_EQ(t->As()->access(), ast::Access::kRead); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::k1d); - EXPECT_EQ(t->source().range, (Source::Range{{1u, 1u}, {1u, 34u}})); + EXPECT_EQ(t->As()->format, ast::ImageFormat::kR8Unorm); + EXPECT_EQ(t->As()->access, ast::Access::kRead); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::k1d); + EXPECT_EQ(t->source.range, (Source::Range{{1u, 1u}, {1u, 34u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { @@ -231,11 +230,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->image_format(), - ast::ImageFormat::kR16Float); - EXPECT_EQ(t->As()->access(), ast::Access::kWrite); - EXPECT_EQ(t->As()->dim(), ast::TextureDimension::k2d); - EXPECT_EQ(t->source().range, (Source::Range{{1u, 1u}, {1u, 36u}})); + EXPECT_EQ(t->As()->format, ast::ImageFormat::kR16Float); + EXPECT_EQ(t->As()->access, ast::Access::kWrite); + EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); + EXPECT_EQ(t->source.range, (Source::Range{{1u, 1u}, {1u, 36u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType) { diff --git a/src/reader/wgsl/parser_impl_type_alias_test.cc b/src/reader/wgsl/parser_impl_type_alias_test.cc index 274d8a9ca8..5f1e03d9ef 100644 --- a/src/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/reader/wgsl/parser_impl_type_alias_test.cc @@ -29,9 +29,9 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); auto* alias = t->As(); - ASSERT_TRUE(alias->type()->Is()); + ASSERT_TRUE(alias->type->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 13u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 13u}})); } TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { @@ -47,9 +47,9 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t.value->Is()); auto* alias = t.value->As(); - EXPECT_EQ(p->builder().Symbols().NameFor(alias->symbol()), "a"); - EXPECT_TRUE(alias->type()->Is()); - EXPECT_EQ(alias->source().range, (Source::Range{{1u, 1u}, {1u, 11u}})); + EXPECT_EQ(p->builder().Symbols().NameFor(alias->name), "a"); + EXPECT_TRUE(alias->type->Is()); + EXPECT_EQ(alias->source.range, (Source::Range{{1u, 1u}, {1u, 11u}})); } TEST_F(ParserImplTest, TypeDecl_MissingIdent) { diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index 4c3c266597..2035359233 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -46,8 +46,8 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) { ASSERT_NE(t.value, nullptr) << p->error(); auto* type_name = t.value->As(); ASSERT_NE(type_name, nullptr); - EXPECT_EQ(p->builder().Symbols().Get("A"), type_name->name()); - EXPECT_EQ(type_name->source().range, (Source::Range{{1u, 1u}, {1u, 2u}})); + EXPECT_EQ(p->builder().Symbols().Get("A"), type_name->name); + EXPECT_EQ(type_name->source.range, (Source::Range{{1u, 1u}, {1u, 2u}})); } TEST_F(ParserImplTest, TypeDecl_Identifier_NotFound) { @@ -69,7 +69,7 @@ TEST_F(ParserImplTest, TypeDecl_Bool) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 5u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } TEST_F(ParserImplTest, TypeDecl_F32) { @@ -80,7 +80,7 @@ TEST_F(ParserImplTest, TypeDecl_F32) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 4u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } TEST_F(ParserImplTest, TypeDecl_I32) { @@ -91,7 +91,7 @@ TEST_F(ParserImplTest, TypeDecl_I32) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 4u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } TEST_F(ParserImplTest, TypeDecl_U32) { @@ -102,7 +102,7 @@ TEST_F(ParserImplTest, TypeDecl_U32) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 4u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } struct VecData { @@ -126,8 +126,8 @@ TEST_P(VecTest, Parse) { ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); EXPECT_TRUE(t.value->Is()); - EXPECT_EQ(t.value->As()->size(), params.count); - EXPECT_EQ(t.value->source().range, params.range); + EXPECT_EQ(t.value->As()->width, params.count); + EXPECT_EQ(t.value->source.range, params.range); } INSTANTIATE_TEST_SUITE_P( ParserImplTest, @@ -218,9 +218,9 @@ TEST_F(ParserImplTest, TypeDecl_Ptr) { ASSERT_TRUE(t.value->Is()); auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type()->Is()); - ASSERT_EQ(ptr->storage_class(), ast::StorageClass::kFunction); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 19u}})); + ASSERT_TRUE(ptr->type->Is()); + ASSERT_EQ(ptr->storage_class, ast::StorageClass::kFunction); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } TEST_F(ParserImplTest, TypeDecl_Ptr_WithAccess) { @@ -233,10 +233,10 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_WithAccess) { ASSERT_TRUE(t.value->Is()); auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type()->Is()); - ASSERT_EQ(ptr->storage_class(), ast::StorageClass::kFunction); - ASSERT_EQ(ptr->access(), ast::Access::kRead); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 25u}})); + ASSERT_TRUE(ptr->type->Is()); + ASSERT_EQ(ptr->storage_class, ast::StorageClass::kFunction); + ASSERT_EQ(ptr->access, ast::Access::kRead); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}})); } TEST_F(ParserImplTest, TypeDecl_Ptr_ToVec) { @@ -249,13 +249,13 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_ToVec) { ASSERT_TRUE(t.value->Is()); auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type()->Is()); - ASSERT_EQ(ptr->storage_class(), ast::StorageClass::kFunction); + ASSERT_TRUE(ptr->type->Is()); + ASSERT_EQ(ptr->storage_class, ast::StorageClass::kFunction); - auto* vec = ptr->type()->As(); - ASSERT_EQ(vec->size(), 2u); - ASSERT_TRUE(vec->type()->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 25}})); + auto* vec = ptr->type->As(); + ASSERT_EQ(vec->width, 2u); + ASSERT_TRUE(vec->type->Is()); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25}})); } TEST_F(ParserImplTest, TypeDecl_Ptr_MissingLessThan) { @@ -388,8 +388,8 @@ TEST_F(ParserImplTest, TypeDecl_Atomic) { ASSERT_TRUE(t.value->Is()); auto* atomic = t.value->As(); - ASSERT_TRUE(atomic->type()->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 12u}})); + ASSERT_TRUE(atomic->type->Is()); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 12u}})); } TEST_F(ParserImplTest, TypeDecl_Atomic_ToVec) { @@ -402,12 +402,12 @@ TEST_F(ParserImplTest, TypeDecl_Atomic_ToVec) { ASSERT_TRUE(t.value->Is()); auto* atomic = t.value->As(); - ASSERT_TRUE(atomic->type()->Is()); + ASSERT_TRUE(atomic->type->Is()); - auto* vec = atomic->type()->As(); - ASSERT_EQ(vec->size(), 2u); - ASSERT_TRUE(vec->type()->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 18u}})); + auto* vec = atomic->type->As(); + ASSERT_EQ(vec->width, 2u); + ASSERT_TRUE(vec->type->Is()); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}})); } TEST_F(ParserImplTest, TypeDecl_Atomic_MissingLessThan) { @@ -451,15 +451,15 @@ TEST_F(ParserImplTest, TypeDecl_Array_SintLiteralSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); - EXPECT_EQ(a->decorations().size(), 0u); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 14u}})); + ASSERT_TRUE(a->type->Is()); + EXPECT_EQ(a->decorations.size(), 0u); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 14u}})); - auto* size_expr = a->Size()->As(); - ASSERT_NE(size_expr, nullptr); - auto* size = size_expr->literal()->As(); + auto* count_expr = a->count->As(); + ASSERT_NE(count_expr, nullptr); + auto* size = count_expr->literal->As(); ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value_as_i32(), 5); + EXPECT_EQ(size->ValueAsI32(), 5); } TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) { @@ -473,15 +473,15 @@ TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); - EXPECT_EQ(a->decorations().size(), 0u); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 15u}})); + ASSERT_TRUE(a->type->Is()); + EXPECT_EQ(a->decorations.size(), 0u); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}})); - auto* size_expr = a->Size()->As(); - ASSERT_NE(size_expr, nullptr); - auto* size = size_expr->literal()->As(); + auto* count_expr = a->count->As(); + ASSERT_NE(count_expr, nullptr); + auto* size = count_expr->literal->As(); ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value_as_u32(), 5u); + EXPECT_EQ(size->ValueAsU32(), 5u); } TEST_F(ParserImplTest, TypeDecl_Array_ConstantSize) { @@ -495,13 +495,13 @@ TEST_F(ParserImplTest, TypeDecl_Array_ConstantSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); - EXPECT_EQ(a->decorations().size(), 0u); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 17u}})); + ASSERT_TRUE(a->type->Is()); + EXPECT_EQ(a->decorations.size(), 0u); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); - auto* size_expr = a->Size()->As(); - ASSERT_NE(size_expr, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(size_expr->symbol()), "size"); + auto* count_expr = a->count->As(); + ASSERT_NE(count_expr, nullptr); + EXPECT_EQ(p->builder().Symbols().NameFor(count_expr->symbol), "size"); } TEST_F(ParserImplTest, TypeDecl_Array_Stride) { @@ -515,19 +515,19 @@ TEST_F(ParserImplTest, TypeDecl_Array_Stride) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); + ASSERT_TRUE(a->type->Is()); - auto* size_expr = a->Size()->As(); - ASSERT_NE(size_expr, nullptr); - auto* size = size_expr->literal()->As(); + auto* count_expr = a->count->As(); + ASSERT_NE(count_expr, nullptr); + auto* size = count_expr->literal->As(); ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value_as_i32(), 5); + EXPECT_EQ(size->ValueAsI32(), 5); - ASSERT_EQ(a->decorations().size(), 1u); - auto* stride = a->decorations()[0]; + ASSERT_EQ(a->decorations.size(), 1u); + auto* stride = a->decorations[0]; ASSERT_TRUE(stride->Is()); - ASSERT_EQ(stride->As()->stride(), 16u); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 16u}, {1u, 29u}})); + ASSERT_EQ(stride->As()->stride, 16u); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 16u}, {1u, 29u}})); } TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Stride) { @@ -541,13 +541,13 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Stride) { auto* a = t.value->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); + ASSERT_TRUE(a->type->Is()); - ASSERT_EQ(a->decorations().size(), 1u); - auto* stride = a->decorations()[0]; + ASSERT_EQ(a->decorations.size(), 1u); + auto* stride = a->decorations[0]; ASSERT_TRUE(stride->Is()); - ASSERT_EQ(stride->As()->stride(), 16u); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 16u}, {1u, 26u}})); + ASSERT_EQ(stride->As()->stride, 16u); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 16u}, {1u, 26u}})); } TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_OneBlock) { @@ -561,15 +561,15 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_OneBlock) { auto* a = t.value->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); + ASSERT_TRUE(a->type->Is()); - auto& decos = a->decorations(); + auto& decos = a->decorations; ASSERT_EQ(decos.size(), 2u); EXPECT_TRUE(decos[0]->Is()); - EXPECT_EQ(decos[0]->As()->stride(), 16u); + EXPECT_EQ(decos[0]->As()->stride, 16u); EXPECT_TRUE(decos[1]->Is()); - EXPECT_EQ(decos[1]->As()->stride(), 32u); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 28u}, {1u, 38u}})); + EXPECT_EQ(decos[1]->As()->stride, 32u); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 28u}, {1u, 38u}})); } TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_MultipleBlocks) { @@ -583,15 +583,15 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_MultipleBlocks) { auto* a = t.value->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); + ASSERT_TRUE(a->type->Is()); - auto& decos = a->decorations(); + auto& decos = a->decorations; ASSERT_EQ(decos.size(), 2u); EXPECT_TRUE(decos[0]->Is()); - EXPECT_EQ(decos[0]->As()->stride(), 16u); + EXPECT_EQ(decos[0]->As()->stride, 16u); EXPECT_TRUE(decos[1]->Is()); - EXPECT_EQ(decos[1]->As()->stride(), 32u); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 31u}, {1u, 41u}})); + EXPECT_EQ(decos[1]->As()->stride, 32u); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 31u}, {1u, 41u}})); } TEST_F(ParserImplTest, TypeDecl_Array_Decoration_MissingArray) { @@ -687,8 +687,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) { auto* a = t.value->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 11u}})); + ASSERT_TRUE(a->type->Is()); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 11u}})); } TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Vec) { @@ -702,10 +702,10 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Vec) { auto* a = t.value->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); - EXPECT_EQ(a->type()->As()->size(), 4u); - EXPECT_TRUE(a->type()->As()->type()->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 17u}})); + ASSERT_TRUE(a->type->Is()); + EXPECT_EQ(a->type->As()->width, 4u); + EXPECT_TRUE(a->type->As()->type->Is()); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } TEST_F(ParserImplTest, TypeDecl_Array_BadType) { @@ -791,9 +791,9 @@ TEST_P(MatrixTest, Parse) { ASSERT_FALSE(p->has_error()); EXPECT_TRUE(t.value->Is()); auto* mat = t.value->As(); - EXPECT_EQ(mat->rows(), params.rows); - EXPECT_EQ(mat->columns(), params.columns); - EXPECT_EQ(t.value->source().range, params.range); + EXPECT_EQ(mat->rows, params.rows); + EXPECT_EQ(mat->columns, params.columns); + EXPECT_EQ(t.value->source.range, params.range); } INSTANTIATE_TEST_SUITE_P( ParserImplTest, @@ -915,7 +915,7 @@ TEST_F(ParserImplTest, TypeDecl_Sampler) { ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_TRUE(t.value->Is()); ASSERT_FALSE(t.value->As()->IsComparison()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 8u}})); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); } TEST_F(ParserImplTest, TypeDecl_Texture) { @@ -927,8 +927,8 @@ TEST_F(ParserImplTest, TypeDecl_Texture) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t.value->Is()); ASSERT_TRUE(t.value->Is()); - ASSERT_TRUE(t.value->As()->type()->Is()); - EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 18u}})); + ASSERT_TRUE(t.value->As()->type->Is()); + EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}})); } } // namespace diff --git a/src/reader/wgsl/parser_impl_unary_expression_test.cc b/src/reader/wgsl/parser_impl_unary_expression_test.cc index 0724c55f27..46273661e0 100644 --- a/src/reader/wgsl/parser_impl_unary_expression_test.cc +++ b/src/reader/wgsl/parser_impl_unary_expression_test.cc @@ -30,15 +30,15 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) { ASSERT_TRUE(e->Is()); auto* ary = e->As(); - ASSERT_TRUE(ary->array()->Is()); - auto* ident = ary->array()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + ASSERT_TRUE(ary->array->Is()); + auto* ident = ary->array->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(ary->idx_expr()->Is()); - ASSERT_TRUE(ary->idx_expr()->Is()); - auto* init = ary->idx_expr()->As(); - ASSERT_TRUE(init->literal()->Is()); - ASSERT_EQ(init->literal()->As()->value(), 2); + ASSERT_TRUE(ary->index->Is()); + ASSERT_TRUE(ary->index->Is()); + auto* init = ary->index->As(); + ASSERT_TRUE(init->literal->Is()); + ASSERT_EQ(init->literal->As()->value, 2); } TEST_F(ParserImplTest, UnaryExpression_Minus) { @@ -51,14 +51,14 @@ TEST_F(ParserImplTest, UnaryExpression_Minus) { ASSERT_TRUE(e->Is()); auto* u = e->As(); - ASSERT_EQ(u->op(), ast::UnaryOp::kNegation); + ASSERT_EQ(u->op, ast::UnaryOp::kNegation); - ASSERT_TRUE(u->expr()->Is()); - ASSERT_TRUE(u->expr()->Is()); + ASSERT_TRUE(u->expr->Is()); + ASSERT_TRUE(u->expr->Is()); - auto* init = u->expr()->As(); - ASSERT_TRUE(init->literal()->Is()); - EXPECT_EQ(init->literal()->As()->value(), 1); + auto* init = u->expr->As(); + ASSERT_TRUE(init->literal->Is()); + EXPECT_EQ(init->literal->As()->value, 1); } TEST_F(ParserImplTest, UnaryExpression_AddressOf) { @@ -71,8 +71,8 @@ TEST_F(ParserImplTest, UnaryExpression_AddressOf) { ASSERT_TRUE(e->Is()); auto* u = e->As(); - EXPECT_EQ(u->op(), ast::UnaryOp::kAddressOf); - EXPECT_TRUE(u->expr()->Is()); + EXPECT_EQ(u->op, ast::UnaryOp::kAddressOf); + EXPECT_TRUE(u->expr->Is()); } TEST_F(ParserImplTest, UnaryExpression_Dereference) { @@ -85,8 +85,8 @@ TEST_F(ParserImplTest, UnaryExpression_Dereference) { ASSERT_TRUE(e->Is()); auto* u = e->As(); - EXPECT_EQ(u->op(), ast::UnaryOp::kIndirection); - EXPECT_TRUE(u->expr()->Is()); + EXPECT_EQ(u->op, ast::UnaryOp::kIndirection); + EXPECT_TRUE(u->expr->Is()); } TEST_F(ParserImplTest, UnaryExpression_AddressOf_Precedence) { @@ -99,8 +99,8 @@ TEST_F(ParserImplTest, UnaryExpression_AddressOf_Precedence) { ASSERT_TRUE(e->Is()); auto* u = e->As(); - EXPECT_EQ(u->op(), ast::UnaryOp::kAddressOf); - EXPECT_TRUE(u->expr()->Is()); + EXPECT_EQ(u->op, ast::UnaryOp::kAddressOf); + EXPECT_TRUE(u->expr->Is()); } TEST_F(ParserImplTest, UnaryExpression_Dereference_Precedence) { @@ -113,8 +113,8 @@ TEST_F(ParserImplTest, UnaryExpression_Dereference_Precedence) { ASSERT_TRUE(e->Is()); auto* u = e->As(); - EXPECT_EQ(u->op(), ast::UnaryOp::kIndirection); - EXPECT_TRUE(u->expr()->Is()); + EXPECT_EQ(u->op, ast::UnaryOp::kIndirection); + EXPECT_TRUE(u->expr->Is()); } TEST_F(ParserImplTest, UnaryExpression_Minus_InvalidRHS) { @@ -137,14 +137,14 @@ TEST_F(ParserImplTest, UnaryExpression_Bang) { ASSERT_TRUE(e->Is()); auto* u = e->As(); - ASSERT_EQ(u->op(), ast::UnaryOp::kNot); + ASSERT_EQ(u->op, ast::UnaryOp::kNot); - ASSERT_TRUE(u->expr()->Is()); - ASSERT_TRUE(u->expr()->Is()); + ASSERT_TRUE(u->expr->Is()); + ASSERT_TRUE(u->expr->Is()); - auto* init = u->expr()->As(); - ASSERT_TRUE(init->literal()->Is()); - EXPECT_EQ(init->literal()->As()->value(), 1); + auto* init = u->expr->As(); + ASSERT_TRUE(init->literal->Is()); + EXPECT_EQ(init->literal->As()->value, 1); } TEST_F(ParserImplTest, UnaryExpression_Bang_InvalidRHS) { @@ -167,14 +167,14 @@ TEST_F(ParserImplTest, UnaryExpression_Tilde) { ASSERT_TRUE(e->Is()); auto* u = e->As(); - ASSERT_EQ(u->op(), ast::UnaryOp::kComplement); + ASSERT_EQ(u->op, ast::UnaryOp::kComplement); - ASSERT_TRUE(u->expr()->Is()); - ASSERT_TRUE(u->expr()->Is()); + ASSERT_TRUE(u->expr->Is()); + ASSERT_TRUE(u->expr->Is()); - auto* init = u->expr()->As(); - ASSERT_TRUE(init->literal()->Is()); - EXPECT_EQ(init->literal()->As()->value(), 1); + auto* init = u->expr->As(); + ASSERT_TRUE(init->literal->Is()); + EXPECT_EQ(init->literal->As()->value, 1); } TEST_F(ParserImplTest, UnaryExpression_PrefixPlusPlus) { diff --git a/src/reader/wgsl/parser_impl_variable_decl_test.cc b/src/reader/wgsl/parser_impl_variable_decl_test.cc index efb91d8d5a..97bffb1cb4 100644 --- a/src/reader/wgsl/parser_impl_variable_decl_test.cc +++ b/src/reader/wgsl/parser_impl_variable_decl_test.cc @@ -30,7 +30,7 @@ TEST_F(ParserImplTest, VariableDecl_Parses) { EXPECT_TRUE(v->type->Is()); EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 11u}})); - EXPECT_EQ(v->type->source().range, (Source::Range{{1u, 14u}, {1u, 17u}})); + EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 14u}, {1u, 17u}})); } TEST_F(ParserImplTest, VariableDecl_Inferred_Parses) { diff --git a/src/reader/wgsl/parser_impl_variable_decoration_list_test.cc b/src/reader/wgsl/parser_impl_variable_decoration_list_test.cc index c265efbdf0..54933452da 100644 --- a/src/reader/wgsl/parser_impl_variable_decoration_list_test.cc +++ b/src/reader/wgsl/parser_impl_variable_decoration_list_test.cc @@ -33,9 +33,9 @@ TEST_F(ParserImplTest, DecorationList_Parses) { ASSERT_NE(deco_1, nullptr); ASSERT_TRUE(deco_0->Is()); - EXPECT_EQ(deco_0->As()->value(), 4u); + EXPECT_EQ(deco_0->As()->value, 4u); ASSERT_TRUE(deco_1->Is()); - EXPECT_EQ(deco_1->As()->value(), + EXPECT_EQ(deco_1->As()->builtin, ast::Builtin::kPosition); } diff --git a/src/reader/wgsl/parser_impl_variable_decoration_test.cc b/src/reader/wgsl/parser_impl_variable_decoration_test.cc index a805f6be22..e04103b284 100644 --- a/src/reader/wgsl/parser_impl_variable_decoration_test.cc +++ b/src/reader/wgsl/parser_impl_variable_decoration_test.cc @@ -31,7 +31,7 @@ TEST_F(ParserImplTest, Decoration_Location) { ASSERT_TRUE(var_deco->Is()); auto* loc = var_deco->As(); - EXPECT_EQ(loc->value(), 4u); + EXPECT_EQ(loc->value, 4u); } TEST_F(ParserImplTest, Decoration_Location_MissingLeftParen) { @@ -101,7 +101,7 @@ TEST_P(BuiltinTest, Decoration_Builtin) { ASSERT_TRUE(var_deco->Is()); auto* builtin = var_deco->As(); - EXPECT_EQ(builtin->value(), params.result); + EXPECT_EQ(builtin->builtin, params.result); } INSTANTIATE_TEST_SUITE_P( ParserImplTest, @@ -185,8 +185,8 @@ TEST_F(ParserImplTest, Decoration_Interpolate_Flat) { ASSERT_TRUE(var_deco->Is()); auto* interp = var_deco->As(); - EXPECT_EQ(interp->type(), ast::InterpolationType::kFlat); - EXPECT_EQ(interp->sampling(), ast::InterpolationSampling::kNone); + EXPECT_EQ(interp->type, ast::InterpolationType::kFlat); + EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kNone); } TEST_F(ParserImplTest, Decoration_Interpolate_Perspective_Center) { @@ -201,8 +201,8 @@ TEST_F(ParserImplTest, Decoration_Interpolate_Perspective_Center) { ASSERT_TRUE(var_deco->Is()); auto* interp = var_deco->As(); - EXPECT_EQ(interp->type(), ast::InterpolationType::kPerspective); - EXPECT_EQ(interp->sampling(), ast::InterpolationSampling::kCenter); + EXPECT_EQ(interp->type, ast::InterpolationType::kPerspective); + EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kCenter); } TEST_F(ParserImplTest, Decoration_Interpolate_Perspective_Centroid) { @@ -217,8 +217,8 @@ TEST_F(ParserImplTest, Decoration_Interpolate_Perspective_Centroid) { ASSERT_TRUE(var_deco->Is()); auto* interp = var_deco->As(); - EXPECT_EQ(interp->type(), ast::InterpolationType::kPerspective); - EXPECT_EQ(interp->sampling(), ast::InterpolationSampling::kCentroid); + EXPECT_EQ(interp->type, ast::InterpolationType::kPerspective); + EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kCentroid); } TEST_F(ParserImplTest, Decoration_Interpolate_Linear_Sample) { @@ -233,8 +233,8 @@ TEST_F(ParserImplTest, Decoration_Interpolate_Linear_Sample) { ASSERT_TRUE(var_deco->Is()); auto* interp = var_deco->As(); - EXPECT_EQ(interp->type(), ast::InterpolationType::kLinear); - EXPECT_EQ(interp->sampling(), ast::InterpolationSampling::kSample); + EXPECT_EQ(interp->type, ast::InterpolationType::kLinear); + EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kSample); } TEST_F(ParserImplTest, Decoration_Interpolate_MissingLeftParen) { @@ -309,7 +309,7 @@ TEST_F(ParserImplTest, Decoration_Binding) { ASSERT_TRUE(var_deco->Is()); auto* binding = var_deco->As(); - EXPECT_EQ(binding->value(), 4u); + EXPECT_EQ(binding->value, 4u); } TEST_F(ParserImplTest, Decoration_Binding_MissingLeftParen) { @@ -366,7 +366,7 @@ TEST_F(ParserImplTest, Decoration_group) { ASSERT_TRUE(var_deco->Is()); auto* group = var_deco->As(); - EXPECT_EQ(group->value(), 4u); + EXPECT_EQ(group->value, 4u); } TEST_F(ParserImplTest, Decoration_Group_MissingLeftParen) { diff --git a/src/reader/wgsl/parser_impl_variable_ident_decl_test.cc b/src/reader/wgsl/parser_impl_variable_ident_decl_test.cc index a063a61219..0cf6a31dd9 100644 --- a/src/reader/wgsl/parser_impl_variable_ident_decl_test.cc +++ b/src/reader/wgsl/parser_impl_variable_ident_decl_test.cc @@ -30,7 +30,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_Parses) { ASSERT_TRUE(decl->type->Is()); EXPECT_EQ(decl->source.range, (Source::Range{{1u, 1u}, {1u, 7u}})); - EXPECT_EQ(decl->type->source().range, (Source::Range{{1u, 10u}, {1u, 13u}})); + EXPECT_EQ(decl->type->source.range, (Source::Range{{1u, 10u}, {1u, 13u}})); } TEST_F(ParserImplTest, VariableIdentDecl_Inferred_Parses) { diff --git a/src/reader/wgsl/parser_impl_variable_stmt_test.cc b/src/reader/wgsl/parser_impl_variable_stmt_test.cc index ee6536c3ab..d9ec4ad823 100644 --- a/src/reader/wgsl/parser_impl_variable_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_variable_stmt_test.cc @@ -27,15 +27,15 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_NE(e->variable(), nullptr); - EXPECT_EQ(e->variable()->symbol(), p->builder().Symbols().Get("a")); + ASSERT_NE(e->variable, nullptr); + EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); - ASSERT_EQ(e->source().range.begin.line, 1u); - ASSERT_EQ(e->source().range.begin.column, 5u); - ASSERT_EQ(e->source().range.end.line, 1u); - ASSERT_EQ(e->source().range.end.column, 6u); + ASSERT_EQ(e->source.range.begin.line, 1u); + ASSERT_EQ(e->source.range.begin.column, 5u); + ASSERT_EQ(e->source.range.end.line, 1u); + ASSERT_EQ(e->source.range.end.column, 6u); - EXPECT_EQ(e->variable()->constructor(), nullptr); + EXPECT_EQ(e->variable->constructor, nullptr); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) { @@ -46,16 +46,16 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_NE(e->variable(), nullptr); - EXPECT_EQ(e->variable()->symbol(), p->builder().Symbols().Get("a")); + ASSERT_NE(e->variable, nullptr); + EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); - ASSERT_EQ(e->source().range.begin.line, 1u); - ASSERT_EQ(e->source().range.begin.column, 5u); - ASSERT_EQ(e->source().range.end.line, 1u); - ASSERT_EQ(e->source().range.end.column, 6u); + ASSERT_EQ(e->source.range.begin.line, 1u); + ASSERT_EQ(e->source.range.begin.column, 5u); + ASSERT_EQ(e->source.range.end.line, 1u); + ASSERT_EQ(e->source.range.end.column, 6u); - ASSERT_NE(e->variable()->constructor(), nullptr); - EXPECT_TRUE(e->variable()->constructor()->Is()); + ASSERT_NE(e->variable->constructor, nullptr); + EXPECT_TRUE(e->variable->constructor->Is()); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_Invalid) { @@ -86,11 +86,11 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_NE(e->variable(), nullptr); - EXPECT_EQ(e->variable()->symbol(), p->builder().Symbols().Get("a")); + ASSERT_NE(e->variable, nullptr); + EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); - ASSERT_NE(e->variable()->constructor(), nullptr); - EXPECT_TRUE(e->variable()->constructor()->Is()); + ASSERT_NE(e->variable->constructor, nullptr); + EXPECT_TRUE(e->variable->constructor->Is()); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) { @@ -101,11 +101,11 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_NE(e->variable(), nullptr); - EXPECT_EQ(e->variable()->symbol(), p->builder().Symbols().Get("a")); + ASSERT_NE(e->variable, nullptr); + EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); - ASSERT_NE(e->variable()->constructor(), nullptr); - EXPECT_TRUE(e->variable()->constructor()->Is()); + ASSERT_NE(e->variable->constructor, nullptr); + EXPECT_TRUE(e->variable->constructor->Is()); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) { @@ -116,11 +116,11 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_NE(e->variable(), nullptr); - EXPECT_EQ(e->variable()->symbol(), p->builder().Symbols().Get("a")); + ASSERT_NE(e->variable, nullptr); + EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); - ASSERT_NE(e->variable()->constructor(), nullptr); - EXPECT_TRUE(e->variable()->constructor()->Is()); + ASSERT_NE(e->variable->constructor, nullptr); + EXPECT_TRUE(e->variable->constructor->Is()); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) { @@ -131,11 +131,11 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_NE(e->variable(), nullptr); - EXPECT_EQ(e->variable()->symbol(), p->builder().Symbols().Get("a")); + ASSERT_NE(e->variable, nullptr); + EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); - ASSERT_NE(e->variable()->constructor(), nullptr); - EXPECT_TRUE(e->variable()->constructor()->Is()); + ASSERT_NE(e->variable->constructor, nullptr); + EXPECT_TRUE(e->variable->constructor->Is()); } TEST_F(ParserImplTest, VariableStmt_Let) { @@ -147,10 +147,10 @@ TEST_F(ParserImplTest, VariableStmt_Let) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - ASSERT_EQ(e->source().range.begin.line, 1u); - ASSERT_EQ(e->source().range.begin.column, 5u); - ASSERT_EQ(e->source().range.end.line, 1u); - ASSERT_EQ(e->source().range.end.column, 6u); + ASSERT_EQ(e->source.range.begin.line, 1u); + ASSERT_EQ(e->source.range.begin.column, 5u); + ASSERT_EQ(e->source.range.end.line, 1u); + ASSERT_EQ(e->source.range.end.column, 6u); } TEST_F(ParserImplTest, VariableStmt_Let_InvalidVarIdent) { diff --git a/src/resolver/inferred_type_test.cc b/src/resolver/inferred_type_test.cc index c625b64bc1..b194e14cce 100644 --- a/src/resolver/inferred_type_test.cc +++ b/src/resolver/inferred_type_test.cc @@ -157,9 +157,9 @@ TEST_F(ResolverInferredTypeTest, InferStruct_Pass) { auto* str = Structure("S", {member}, {create()}); auto* expected_type = create( - str, str->name(), + str, str->name, sem::StructMemberList{create( - member, member->symbol(), create(), 0, 0, 0, 4)}, + member, member->symbol, create(), 0, 0, 0, 4)}, 0, 4, 4); auto* ctor_expr = Construct(ty.Of(str)); diff --git a/src/resolver/intrinsic_test.cc b/src/resolver/intrinsic_test.cc index 5e6526a57f..677b64a36a 100644 --- a/src/resolver/intrinsic_test.cc +++ b/src/resolver/intrinsic_test.cc @@ -1925,8 +1925,8 @@ const char* expected_texture_overload( TEST_P(ResolverIntrinsicTest_Texture, Call) { auto param = GetParam(); - param.buildTextureVariable(this); - param.buildSamplerVariable(this); + param.BuildTextureVariable(this); + param.BuildSamplerVariable(this); auto* call = Call(param.function, param.args(this)); auto* stmt = ast::intrinsic::test::ReturnsVoid(param.overload) diff --git a/src/resolver/intrinsic_validation_test.cc b/src/resolver/intrinsic_validation_test.cc index 77b7e94f2b..b41c1ce250 100644 --- a/src/resolver/intrinsic_validation_test.cc +++ b/src/resolver/intrinsic_validation_test.cc @@ -125,8 +125,8 @@ TEST_P(IntrinsicTextureSamplerValidationTest, ConstExpr) { auto& p = GetParam(); auto param = std::get<0>(p); auto offset = std::get<1>(p); - param.buildTextureVariable(this); - param.buildSamplerVariable(this); + param.BuildTextureVariable(this); + param.BuildSamplerVariable(this); auto args = param.args(this); // Make Resolver visit the Node about to be removed @@ -160,8 +160,8 @@ TEST_P(IntrinsicTextureSamplerValidationTest, ConstExprOfConstExpr) { auto& p = GetParam(); auto param = std::get<0>(p); auto offset = std::get<1>(p); - param.buildTextureVariable(this); - param.buildSamplerVariable(this); + param.BuildTextureVariable(this); + param.BuildSamplerVariable(this); auto args = param.args(this); // Make Resolver visit the Node about to be removed @@ -192,8 +192,8 @@ TEST_P(IntrinsicTextureSamplerValidationTest, ConstExprOfConstExpr) { TEST_P(IntrinsicTextureSamplerValidationTest, EmptyVectorConstructor) { auto& p = GetParam(); auto param = std::get<0>(p); - param.buildTextureVariable(this); - param.buildSamplerVariable(this); + param.BuildTextureVariable(this); + param.BuildSamplerVariable(this); auto args = param.args(this); // Make Resolver visit the Node about to be removed @@ -215,8 +215,8 @@ TEST_P(IntrinsicTextureSamplerValidationTest, GlobalConst) { auto& p = GetParam(); auto param = std::get<0>(p); auto offset = std::get<1>(p); - param.buildTextureVariable(this); - param.buildSamplerVariable(this); + param.BuildTextureVariable(this); + param.BuildSamplerVariable(this); auto args = param.args(this); // Make Resolver visit the Node about to be removed @@ -245,8 +245,8 @@ TEST_P(IntrinsicTextureSamplerValidationTest, ScalarConst) { auto& p = GetParam(); auto param = std::get<0>(p); auto offset = std::get<1>(p); - param.buildTextureVariable(this); - param.buildSamplerVariable(this); + param.BuildTextureVariable(this); + param.BuildSamplerVariable(this); auto* x = Const("x", ty.i32(), Construct(ty.i32(), offset.x)); auto args = param.args(this); diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index 75b4a82833..19f461ae7f 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -125,7 +125,7 @@ bool IsValidationDisabled(const ast::DecorationList& decorations, ast::DisabledValidation validation) { for (auto* decoration : decorations) { if (auto* dv = decoration->As()) { - if (dv->Validation() == validation) { + if (dv->validation == validation) { return true; } } @@ -145,9 +145,9 @@ bool IsValidationEnabled(const ast::DecorationList& decorations, std::string deco_to_str(const ast::Decoration* deco) { std::stringstream str; if (auto* builtin = deco->As()) { - str << "builtin(" << builtin->value() << ")"; + str << "builtin(" << builtin->builtin << ")"; } else if (auto* location = deco->As()) { - str << "location(" << location->value() << ")"; + str << "location(" << location->value << ")"; } return str.str(); } @@ -275,7 +275,7 @@ bool Resolver::ResolveInternal() { if (marked_.count(node) == 0) { TINT_ICE(Resolver, diagnostics_) << "AST node '" << node->TypeInfo().name << "' was not reached by the resolver\n" - << "At: " << node->source() << "\n" + << "At: " << node->source << "\n" << "Pointer: " << node; result = false; } @@ -303,10 +303,10 @@ sem::Type* Resolver::Type(const ast::Type* ty) { return builder_->create(); } if (auto* t = ty->As()) { - if (auto* el = Type(t->type())) { + if (auto* el = Type(t->type)) { if (auto* vector = builder_->create( - const_cast(el), t->size())) { - if (ValidateVector(vector, t->source())) { + const_cast(el), t->width)) { + if (ValidateVector(vector, t->source)) { return vector; } } @@ -314,12 +314,12 @@ sem::Type* Resolver::Type(const ast::Type* ty) { return nullptr; } if (auto* t = ty->As()) { - if (auto* el = Type(t->type())) { + if (auto* el = Type(t->type)) { if (auto* column_type = builder_->create( - const_cast(el), t->rows())) { + const_cast(el), t->rows)) { if (auto* matrix = - builder_->create(column_type, t->columns())) { - if (ValidateMatrix(matrix, t->source())) { + builder_->create(column_type, t->columns)) { + if (ValidateMatrix(matrix, t->source)) { return matrix; } } @@ -331,7 +331,7 @@ sem::Type* Resolver::Type(const ast::Type* ty) { return Array(t); } if (auto* t = ty->As()) { - if (auto* el = Type(t->type())) { + if (auto* el = Type(t->type)) { auto* a = builder_->create(const_cast(el)); if (!ValidateAtomic(t, a)) { return nullptr; @@ -341,47 +341,46 @@ sem::Type* Resolver::Type(const ast::Type* ty) { return nullptr; } if (auto* t = ty->As()) { - if (auto* el = Type(t->type())) { - auto access = t->access(); + if (auto* el = Type(t->type)) { + auto access = t->access; if (access == ast::kUndefined) { - access = DefaultAccessForStorageClass(t->storage_class()); + access = DefaultAccessForStorageClass(t->storage_class); } return builder_->create(const_cast(el), - t->storage_class(), access); + t->storage_class, access); } return nullptr; } if (auto* t = ty->As()) { - return builder_->create(t->kind()); + return builder_->create(t->kind); } if (auto* t = ty->As()) { - if (auto* el = Type(t->type())) { + if (auto* el = Type(t->type)) { return builder_->create( - t->dim(), const_cast(el)); + t->dim, const_cast(el)); } return nullptr; } if (auto* t = ty->As()) { - if (auto* el = Type(t->type())) { + if (auto* el = Type(t->type)) { return builder_->create( - t->dim(), const_cast(el)); + t->dim, const_cast(el)); } return nullptr; } if (auto* t = ty->As()) { - return builder_->create(t->dim()); + return builder_->create(t->dim); } if (auto* t = ty->As()) { - return builder_->create(t->dim()); + return builder_->create(t->dim); } if (auto* t = ty->As()) { - if (auto* el = Type(t->type())) { + if (auto* el = Type(t->type)) { if (!ValidateStorageTexture(t)) { return nullptr; } return builder_->create( - t->dim(), t->image_format(), t->access(), - const_cast(el)); + t->dim, t->format, t->access, const_cast(el)); } return nullptr; } @@ -389,11 +388,10 @@ sem::Type* Resolver::Type(const ast::Type* ty) { return builder_->create(); } if (auto* t = ty->As()) { - auto it = named_type_info_.find(t->name()); + auto it = named_type_info_.find(t->name); if (it == named_type_info_.end()) { - AddError( - "unknown type '" + builder_->Symbols().NameFor(t->name()) + "'", - t->source()); + AddError("unknown type '" + builder_->Symbols().NameFor(t->name) + "'", + t->source); return nullptr; } return it->second.sem; @@ -414,36 +412,36 @@ bool Resolver::ValidateAtomic(const ast::Atomic* a, const sem::Atomic* s) { // T must be either u32 or i32. if (!s->Type()->IsAnyOf()) { AddError("atomic only supports i32 or u32 types", - a->type() ? a->type()->source() : a->source()); + a->type ? a->type->source : a->source); return false; } return true; } bool Resolver::ValidateStorageTexture(const ast::StorageTexture* t) { - switch (t->access()) { + switch (t->access) { case ast::Access::kWrite: break; case ast::Access::kUndefined: - AddError("storage texture missing access control", t->source()); + AddError("storage texture missing access control", t->source); return false; default: AddError("storage textures currently only support 'write' access control", - t->source()); + t->source); return false; } - if (!IsValidStorageTextureDimension(t->dim())) { + if (!IsValidStorageTextureDimension(t->dim)) { AddError("cube dimensions for storage textures are not supported", - t->source()); + t->source); return false; } - if (!IsValidStorageTextureImageFormat(t->image_format())) { + if (!IsValidStorageTextureImageFormat(t->format)) { AddError( "image format must be one of the texel formats specified for storage " "textues in https://gpuweb.github.io/gpuweb/wgsl/#texel-formats", - t->source()); + t->source); return false; } return true; @@ -454,7 +452,7 @@ Resolver::VariableInfo* Resolver::Variable(ast::Variable* var, uint32_t index /* = 0 */) { if (variable_to_info_.count(var)) { TINT_ICE(Resolver, diagnostics_) - << "Variable " << builder_->Symbols().NameFor(var->symbol()) + << "Variable " << builder_->Symbols().NameFor(var->symbol) << " already resolved"; return nullptr; } @@ -463,7 +461,7 @@ Resolver::VariableInfo* Resolver::Variable(ast::Variable* var, const sem::Type* storage_type = nullptr; // If the variable has a declared type, resolve it. - if (auto* ty = var->type()) { + if (auto* ty = var->type) { type_name = ty->FriendlyName(builder_->Symbols()); storage_type = Type(ty); if (!storage_type) { @@ -475,9 +473,9 @@ Resolver::VariableInfo* Resolver::Variable(ast::Variable* var, const sem::Type* rhs_type = nullptr; // Does the variable have a constructor? - if (auto* ctor = var->constructor()) { - Mark(var->constructor()); - if (!Expression(var->constructor())) { + if (auto* ctor = var->constructor) { + Mark(var->constructor); + if (!Expression(var->constructor)) { return nullptr; } @@ -490,37 +488,37 @@ Resolver::VariableInfo* Resolver::Variable(ast::Variable* var, // If the variable has no declared type, infer it from the RHS if (!storage_type) { - if (!var->is_const() && kind == VariableKind::kGlobal) { - AddError("global var declaration must specify a type", var->source()); + if (!var->is_const && kind == VariableKind::kGlobal) { + AddError("global var declaration must specify a type", var->source); return nullptr; } type_name = rhs_type_name; storage_type = rhs_type->UnwrapRef(); // Implicit load of RHS } - } else if (var->is_const() && kind != VariableKind::kParameter && - !ast::HasDecoration(var->decorations())) { - AddError("let declaration must have an initializer", var->source()); + } else if (var->is_const && kind != VariableKind::kParameter && + !ast::HasDecoration(var->decorations)) { + AddError("let declaration must have an initializer", var->source); return nullptr; - } else if (!var->type()) { + } else if (!var->type) { AddError( (kind == VariableKind::kGlobal) ? "module scope var declaration requires a type and initializer" : "function scope var declaration requires a type or initializer", - var->source()); + var->source); return nullptr; } if (!storage_type) { TINT_ICE(Resolver, diagnostics_) << "failed to determine storage type for variable '" + - builder_->Symbols().NameFor(var->symbol()) + "'\n" - << "Source: " << var->source(); + builder_->Symbols().NameFor(var->symbol) + "'\n" + << "Source: " << var->source; return nullptr; } - auto storage_class = var->declared_storage_class(); - if (storage_class == ast::StorageClass::kNone && !var->is_const()) { + auto storage_class = var->declared_storage_class; + if (storage_class == ast::StorageClass::kNone && !var->is_const) { // No declared storage class. Infer from usage / type. if (kind == VariableKind::kLocal) { storage_class = ast::StorageClass::kFunction; @@ -533,13 +531,13 @@ Resolver::VariableInfo* Resolver::Variable(ast::Variable* var, } } - auto access = var->declared_access(); + auto access = var->declared_access; if (access == ast::Access::kUndefined) { access = DefaultAccessForStorageClass(storage_class); } auto* type = storage_type; - if (!var->is_const()) { + if (!var->is_const) { // Variable declaration. Unlike `let`, `var` has storage. // Variables are always of a reference type to the declared storage type. type = @@ -588,14 +586,14 @@ void Resolver::AllocateOverridableConstantIds() { continue; } auto* override_deco = - ast::GetDecoration(var->decorations()); + ast::GetDecoration(var->decorations); if (!override_deco) { continue; } uint16_t constant_id; - if (override_deco->HasValue()) { - constant_id = static_cast(override_deco->value()); + if (override_deco->has_value) { + constant_id = static_cast(override_deco->value); } else { // No ID was specified, so allocate the next available ID. constant_id = next_constant_id; @@ -624,14 +622,14 @@ bool Resolver::ValidateVariableConstructor(const ast::Variable* var, // Value type has to match storage type if (storage_type != value_type) { - std::string decl = var->is_const() ? "let" : "var"; + std::string decl = var->is_const ? "let" : "var"; AddError("cannot initialize " + decl + " of type '" + type_name + "' with value of type '" + rhs_type_name + "'", - var->source()); + var->source); return false; } - if (!var->is_const()) { + if (!var->is_const) { switch (storage_class) { case ast::StorageClass::kPrivate: case ast::StorageClass::kFunction: @@ -641,11 +639,11 @@ bool Resolver::ValidateVariableConstructor(const ast::Variable* var, // Optionally has an initializer expression, if the variable is in the // private or function storage classes. AddError("var of storage class '" + - std::string(ast::str(storage_class)) + + std::string(ast::ToString(storage_class)) + "' cannot have an initializer. var initializers are only " "supported for the storage classes " "'private' and 'function'", - var->source()); + var->source); return false; } } @@ -654,7 +652,7 @@ bool Resolver::ValidateVariableConstructor(const ast::Variable* var, } bool Resolver::GlobalVariable(ast::Variable* var) { - if (!ValidateNoDuplicateDefinition(var->symbol(), var->source(), + if (!ValidateNoDuplicateDefinition(var->symbol, var->source, /* check_global_scope_only */ true)) { return false; } @@ -663,34 +661,34 @@ bool Resolver::GlobalVariable(ast::Variable* var) { if (!info) { return false; } - variable_stack_.set_global(var->symbol(), info); + variable_stack_.set_global(var->symbol, info); - if (!var->is_const() && info->storage_class == ast::StorageClass::kNone) { - AddError("global variables must have a storage class", var->source()); + if (!var->is_const && info->storage_class == ast::StorageClass::kNone) { + AddError("global variables must have a storage class", var->source); return false; } - if (var->is_const() && !(info->storage_class == ast::StorageClass::kNone)) { - AddError("global constants shouldn't have a storage class", var->source()); + if (var->is_const && !(info->storage_class == ast::StorageClass::kNone)) { + AddError("global constants shouldn't have a storage class", var->source); return false; } - for (auto* deco : var->decorations()) { + for (auto* deco : var->decorations) { Mark(deco); if (auto* override_deco = deco->As()) { // Track the constant IDs that are specified in the shader. - if (override_deco->HasValue()) { - constant_ids_.emplace(override_deco->value(), info); + if (override_deco->has_value) { + constant_ids_.emplace(override_deco->value, info); } } } - if (!ValidateNoDuplicateDecorations(var->decorations())) { + if (!ValidateNoDuplicateDecorations(var->decorations)) { return false; } - if (auto bp = var->binding_point()) { - info->binding_point = {bp.group->value(), bp.binding->value()}; + if (auto bp = var->BindingPoint()) { + info->binding_point = {bp.group->value, bp.binding->value}; } if (!ValidateGlobalVariable(info)) { @@ -699,10 +697,10 @@ bool Resolver::GlobalVariable(ast::Variable* var) { if (!ApplyStorageClassUsageToType( info->storage_class, const_cast(info->type->UnwrapRef()), - var->source())) { + var->source)) { AddNote("while instantiating variable " + - builder_->Symbols().NameFor(var->symbol()), - var->source()); + builder_->Symbols().NameFor(var->symbol), + var->source); return false; } @@ -738,11 +736,11 @@ bool Resolver::ValidateStorageClassLayout(const sem::Struct* str, }; auto member_name_of = [this](const sem::StructMember* sm) { - return builder_->Symbols().NameFor(sm->Declaration()->symbol()); + return builder_->Symbols().NameFor(sm->Declaration()->symbol); }; auto type_name_of = [this](const sem::StructMember* sm) { - return sm->Declaration()->type()->FriendlyName(builder_->Symbols()); + return sm->Declaration()->type->FriendlyName(builder_->Symbols()); }; // TODO(amaiorano): Output struct and member decorations so that this output @@ -833,21 +831,21 @@ bool Resolver::ValidateStorageClassLayout(const sem::Struct* str, // Validate that member is at a valid byte offset if (m->Offset() % required_align != 0) { AddError("the offset of a struct member of type '" + type_name_of(m) + - "' in storage class '" + ast::str(sc) + + "' in storage class '" + ast::ToString(sc) + "' must be a multiple of " + std::to_string(required_align) + " bytes, but '" + member_name_of(m) + "' is currently at offset " + std::to_string(m->Offset()) + ". Consider setting [[align(" + std::to_string(required_align) + ")]] on this member", - m->Declaration()->source()); + m->Declaration()->source); AddNote("see layout of struct:\n" + get_struct_layout_string(str), - str->Declaration()->source()); + str->Declaration()->source); if (auto* member_str = m->Type()->As()) { AddNote("and layout of struct member:\n" + get_struct_layout_string(member_str), - member_str->Declaration()->source()); + member_str->Declaration()->source); } return false; @@ -866,15 +864,15 @@ bool Resolver::ValidateStorageClassLayout(const sem::Struct* str, std::to_string(prev_to_curr_offset) + " bytes between '" + member_name_of(prev_member) + "' and '" + member_name_of(m) + "'. Consider setting [[align(16)]] on this member", - m->Declaration()->source()); + m->Declaration()->source); AddNote("see layout of struct:\n" + get_struct_layout_string(str), - str->Declaration()->source()); + str->Declaration()->source); auto* prev_member_str = prev_member->Type()->As(); AddNote("and layout of previous member struct:\n" + get_struct_layout_string(prev_member_str), - prev_member_str->Declaration()->source()); + prev_member_str->Declaration()->source); return false; } } @@ -896,9 +894,9 @@ bool Resolver::ValidateStorageClassLayout(const sem::Struct* str, std::to_string( utils::RoundUp(required_align, arr->Stride())) + ")]] on the array type", - m->Declaration()->type()->source()); + m->Declaration()->type->source); AddNote("see layout of struct:\n" + get_struct_layout_string(str), - str->Declaration()->source()); + str->Declaration()->source); return false; } } @@ -921,7 +919,7 @@ bool Resolver::ValidateStorageClassLayout(const sem::Struct* str, bool Resolver::ValidateStorageClassLayout(const VariableInfo* info) { if (auto* str = info->type->UnwrapRef()->As()) { if (!ValidateStorageClassLayout(str, info->storage_class)) { - AddNote("see declaration of variable", info->declaration->source()); + AddNote("see declaration of variable", info->declaration->source); return false; } } @@ -930,34 +928,34 @@ bool Resolver::ValidateStorageClassLayout(const VariableInfo* info) { } bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { - if (!ValidateNoDuplicateDecorations(info->declaration->decorations())) { + if (!ValidateNoDuplicateDecorations(info->declaration->decorations)) { return false; } - for (auto* deco : info->declaration->decorations()) { - if (info->declaration->is_const()) { + for (auto* deco : info->declaration->decorations) { + if (info->declaration->is_const) { if (auto* override_deco = deco->As()) { - if (override_deco->HasValue()) { - uint32_t id = override_deco->value(); + if (override_deco->has_value) { + uint32_t id = override_deco->value; auto itr = constant_ids_.find(id); if (itr != constant_ids_.end() && itr->second != info) { - AddError("pipeline constant IDs must be unique", deco->source()); + AddError("pipeline constant IDs must be unique", deco->source); AddNote("a pipeline constant with an ID of " + std::to_string(id) + " was previously declared " "here:", ast::GetDecoration( - itr->second->declaration->decorations()) - ->source()); + itr->second->declaration->decorations) + ->source); return false; } if (id > 65535) { AddError("pipeline constant IDs must be between 0 and 65535", - deco->source()); + deco->source); return false; } } } else { - AddError("decoration is not valid for constants", deco->source()); + AddError("decoration is not valid for constants", deco->source); return false; } } else { @@ -970,13 +968,13 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { if (!(deco->IsAnyOf()) && (!is_shader_io_decoration || !has_io_storage_class)) { - AddError("decoration is not valid for variables", deco->source()); + AddError("decoration is not valid for variables", deco->source); return false; } } } - auto binding_point = info->declaration->binding_point(); + auto binding_point = info->declaration->BindingPoint(); switch (info->storage_class) { case ast::StorageClass::kUniform: case ast::StorageClass::kStorage: @@ -988,7 +986,7 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { AddError( "resource variables require [[group]] and [[binding]] " "decorations", - info->declaration->source()); + info->declaration->source); return false; } break; @@ -1000,7 +998,7 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { AddError( "non-resource variables must not have [[group]] or [[binding]] " "decorations", - info->declaration->source()); + info->declaration->source); return false; } } @@ -1009,10 +1007,10 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { // The access mode always has a default, and except for variables in the // storage storage class, must not be written. if (info->storage_class != ast::StorageClass::kStorage && - info->declaration->declared_access() != ast::Access::kUndefined) { + info->declaration->declared_access != ast::Access::kUndefined) { AddError( "only variables in storage class may declare an access mode", - info->declaration->source()); + info->declaration->source); return false; } @@ -1029,7 +1027,7 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { AddError( "variables declared in the storage class must be of a " "structure type", - info->declaration->source()); + info->declaration->source); return false; } @@ -1037,10 +1035,10 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { AddError( "structure used as a storage buffer must be declared with the " "[[block]] decoration", - str->Declaration()->source()); - if (info->declaration->source().range.begin.line) { + str->Declaration()->source); + if (info->declaration->source.range.begin.line) { AddNote("structure used as storage buffer here", - info->declaration->source()); + info->declaration->source); } return false; } @@ -1056,7 +1054,7 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { AddError( "variables declared in the storage class must be of a " "structure type", - info->declaration->source()); + info->declaration->source); return false; } @@ -1064,10 +1062,10 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { AddError( "structure used as a uniform buffer must be declared with the " "[[block]] decoration", - str->Declaration()->source()); - if (info->declaration->source().range.begin.line) { + str->Declaration()->source); + if (info->declaration->source.range.begin.line) { AddNote("structure used as uniform buffer here", - info->declaration->source()); + info->declaration->source); } return false; } @@ -1078,8 +1076,8 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { AddError( "structure containing a runtime sized array " "cannot be used as a uniform buffer", - info->declaration->source()); - AddNote("structure is declared here", str->Declaration()->source()); + info->declaration->source); + AddNote("structure is declared here", str->Declaration()->source); return false; } } @@ -1091,7 +1089,7 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) { break; } - if (!info->declaration->is_const()) { + if (!info->declaration->is_const) { if (!ValidateAtomicVariable(info)) { return false; } @@ -1107,8 +1105,8 @@ bool Resolver::ValidateAtomicVariable(const VariableInfo* info) { auto sc = info->storage_class; auto access = info->access; auto* type = info->type->UnwrapRef(); - auto source = info->declaration->type() ? info->declaration->type()->source() - : info->declaration->source(); + auto source = info->declaration->type ? info->declaration->type->source + : info->declaration->source; if (type->Is()) { if (sc != ast::StorageClass::kWorkgroup) { @@ -1152,59 +1150,59 @@ bool Resolver::ValidateVariable(const VariableInfo* info) { auto* var = info->declaration; auto* storage_type = info->type->UnwrapRef(); - if (!var->is_const() && !IsStorable(storage_type)) { + if (!var->is_const && !IsStorable(storage_type)) { AddError(storage_type->FriendlyName(builder_->Symbols()) + " cannot be used as the type of a var", - var->source()); + var->source); return false; } - if (var->is_const() && info->kind != VariableKind::kParameter && + if (var->is_const && info->kind != VariableKind::kParameter && !(storage_type->IsConstructible() || storage_type->Is())) { AddError(storage_type->FriendlyName(builder_->Symbols()) + " cannot be used as the type of a let", - var->source()); + var->source); return false; } if (auto* r = storage_type->As()) { if (r->IsRuntimeSized()) { AddError("runtime arrays may only appear as the last member of a struct", - var->source()); + var->source); return false; } } if (auto* r = storage_type->As()) { if (r->dim() != ast::TextureDimension::k2d) { - AddError("only 2d multisampled textures are supported", var->source()); + AddError("only 2d multisampled textures are supported", var->source); return false; } if (!r->type()->UnwrapRef()->is_numeric_scalar()) { AddError("texture_multisampled_2d: type must be f32, i32 or u32", - var->source()); + var->source); return false; } } if (storage_type->is_handle() && - var->declared_storage_class() != ast::StorageClass::kNone) { + var->declared_storage_class != ast::StorageClass::kNone) { // https://gpuweb.github.io/gpuweb/wgsl/#module-scope-variables // If the store type is a texture type or a sampler type, then the // variable declaration must not have a storage class decoration. The // storage class will always be handle. AddError("variables of type '" + info->type_name + "' must not have a storage class", - var->source()); + var->source); return false; } - if (IsValidationEnabled(var->decorations(), + if (IsValidationEnabled(var->decorations, ast::DisabledValidation::kIgnoreStorageClass) && - (var->declared_storage_class() == ast::StorageClass::kInput || - var->declared_storage_class() == ast::StorageClass::kOutput)) { - AddError("invalid use of input/output storage class", var->source()); + (var->declared_storage_class == ast::StorageClass::kInput || + var->declared_storage_class == ast::StorageClass::kOutput)) { + AddError("invalid use of input/output storage class", var->source); return false; } return true; @@ -1216,25 +1214,24 @@ bool Resolver::ValidateFunctionParameter(const ast::Function* func, return false; } - for (auto* deco : info->declaration->decorations()) { + for (auto* deco : info->declaration->decorations) { if (!func->IsEntryPoint() && !deco->Is()) { AddError( "decoration is not valid for non-entry point function parameters", - deco->source()); + deco->source); return false; } else if (!deco->IsAnyOf() && (IsValidationEnabled( - info->declaration->decorations(), + info->declaration->decorations, ast::DisabledValidation::kEntryPointParameter) && IsValidationEnabled( - info->declaration->decorations(), + info->declaration->decorations, ast::DisabledValidation:: kIgnoreConstructibleFunctionParameter))) { - AddError("decoration is not valid for function parameters", - deco->source()); + AddError("decoration is not valid for function parameters", deco->source); return false; } } @@ -1247,7 +1244,7 @@ bool Resolver::ValidateFunctionParameter(const ast::Function* func, std::stringstream ss; ss << "function parameter of pointer type cannot be in '" << sc << "' storage class"; - AddError(ss.str(), info->declaration->source()); + AddError(ss.str(), info->declaration->source); return false; } } @@ -1255,16 +1252,16 @@ bool Resolver::ValidateFunctionParameter(const ast::Function* func, if (IsPlain(info->type)) { if (!info->type->IsConstructible() && IsValidationEnabled( - info->declaration->decorations(), + info->declaration->decorations, ast::DisabledValidation::kIgnoreConstructibleFunctionParameter)) { AddError("store type of function parameter must be a constructible type", - info->declaration->source()); + info->declaration->source); return false; } } else if (!info->type->IsAnyOf()) { AddError("store type of function parameter cannot be " + info->type->FriendlyName(builder_->Symbols()), - info->declaration->source()); + info->declaration->source); return false; } @@ -1276,13 +1273,13 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, const bool is_input) { auto* type = storage_type->UnwrapRef(); const auto stage = current_function_ - ? current_function_->declaration->pipeline_stage() + ? current_function_->declaration->PipelineStage() : ast::PipelineStage::kNone; std::stringstream stage_name; stage_name << stage; bool is_stage_mismatch = false; bool is_output = !is_input; - switch (deco->value()) { + switch (deco->builtin) { case ast::Builtin::kPosition: if (stage != ast::PipelineStage::kNone && !((is_input && stage == ast::PipelineStage::kFragment) || @@ -1291,7 +1288,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, } if (!(type->is_float_vector() && type->As()->Width() == 4)) { AddError("store type of " + deco_to_str(deco) + " must be 'vec4'", - deco->source()); + deco->source); return false; } break; @@ -1306,7 +1303,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, if (!(type->is_unsigned_integer_vector() && type->As()->Width() == 3)) { AddError("store type of " + deco_to_str(deco) + " must be 'vec3'", - deco->source()); + deco->source); return false; } break; @@ -1317,7 +1314,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, } if (!type->Is()) { AddError("store type of " + deco_to_str(deco) + " must be 'f32'", - deco->source()); + deco->source); return false; } break; @@ -1328,7 +1325,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, } if (!type->Is()) { AddError("store type of " + deco_to_str(deco) + " must be 'bool'", - deco->source()); + deco->source); return false; } break; @@ -1339,7 +1336,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, } if (!type->Is()) { AddError("store type of " + deco_to_str(deco) + " must be 'u32'", - deco->source()); + deco->source); return false; } break; @@ -1351,7 +1348,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, } if (!type->Is()) { AddError("store type of " + deco_to_str(deco) + " must be 'u32'", - deco->source()); + deco->source); return false; } break; @@ -1362,7 +1359,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, } if (!type->Is()) { AddError("store type of " + deco_to_str(deco) + " must be 'u32'", - deco->source()); + deco->source); return false; } break; @@ -1373,7 +1370,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, } if (!type->Is()) { AddError("store type of " + deco_to_str(deco) + " must be 'u32'", - deco->source()); + deco->source); return false; } break; @@ -1385,7 +1382,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, AddError(deco_to_str(deco) + " cannot be used in " + (is_input ? "input of " : "output of ") + stage_name.str() + " pipeline stage", - deco->source()); + deco->source); return false; } @@ -1401,14 +1398,14 @@ bool Resolver::ValidateInterpolateDecoration( AddError( "store type of interpolate attribute must be floating point scalar or " "vector", - deco->source()); + deco->source); return false; } - if (deco->type() == ast::InterpolationType::kFlat && - deco->sampling() != ast::InterpolationSampling::kNone) { + if (deco->type == ast::InterpolationType::kFlat && + deco->sampling != ast::InterpolationSampling::kNone) { AddError("flat interpolation attribute must not have a sampling parameter", - deco->source()); + deco->source); return false; } @@ -1417,34 +1414,34 @@ bool Resolver::ValidateInterpolateDecoration( bool Resolver::ValidateFunction(const ast::Function* func, const FunctionInfo* info) { - if (!ValidateNoDuplicateDefinition(func->symbol(), func->source(), + if (!ValidateNoDuplicateDefinition(func->symbol, func->source, /* check_global_scope_only */ true)) { return false; } auto workgroup_deco_count = 0; - for (auto* deco : func->decorations()) { + for (auto* deco : func->decorations) { if (deco->Is()) { workgroup_deco_count++; - if (func->pipeline_stage() != ast::PipelineStage::kCompute) { + if (func->PipelineStage() != ast::PipelineStage::kCompute) { AddError( "the workgroup_size attribute is only valid for compute stages", - deco->source()); + deco->source); return false; } } else if (!deco->IsAnyOf()) { - AddError("decoration is not valid for functions", deco->source()); + AddError("decoration is not valid for functions", deco->source); return false; } } - if (func->params().size() > 255) { - AddError("functions may declare at most 255 parameters", func->source()); + if (func->params.size() > 255) { + AddError("functions may declare at most 255 parameters", func->source); return false; } - for (auto* param : func->params()) { + for (auto* param : func->params) { if (!ValidateFunctionParameter(func, variable_to_info_.at(param))) { return false; } @@ -1453,42 +1450,42 @@ bool Resolver::ValidateFunction(const ast::Function* func, if (!info->return_type->Is()) { if (!info->return_type->IsConstructible()) { AddError("function return type must be a constructible type", - func->return_type()->source()); + func->return_type->source); return false; } - if (func->body()) { - if (!func->get_last_statement() || - !func->get_last_statement()->Is()) { + if (func->body) { + if (!func->body->Last() || + !func->body->Last()->Is()) { AddError("non-void function must end with a return statement", - func->source()); + func->source); return false; } } else if (IsValidationEnabled( - func->decorations(), + func->decorations, ast::DisabledValidation::kFunctionHasNoBody)) { TINT_ICE(Resolver, diagnostics_) - << "Function " << builder_->Symbols().NameFor(func->symbol()) + << "Function " << builder_->Symbols().NameFor(func->symbol) << " has no body"; } - for (auto* deco : func->return_type_decorations()) { + for (auto* deco : func->return_type_decorations) { if (!func->IsEntryPoint()) { AddError( "decoration is not valid for non-entry point function return types", - deco->source()); + deco->source); return false; } if (!deco->IsAnyOf() && - (IsValidationEnabled(info->declaration->decorations(), + (IsValidationEnabled(info->declaration->decorations, ast::DisabledValidation::kEntryPointParameter) && - IsValidationEnabled(info->declaration->decorations(), + IsValidationEnabled(info->declaration->decorations, ast::DisabledValidation:: kIgnoreConstructibleFunctionParameter))) { AddError("decoration is not valid for entry point return types", - deco->source()); + deco->source); return false; } } @@ -1529,21 +1526,21 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func, auto is_invalid_compute_shader_decoration = false; if (auto* builtin = deco->As()) { if (pipeline_io_attribute) { - AddError("multiple entry point IO attributes", deco->source()); + AddError("multiple entry point IO attributes", deco->source); AddNote( "previously consumed " + deco_to_str(pipeline_io_attribute), - pipeline_io_attribute->source()); + pipeline_io_attribute->source); return false; } pipeline_io_attribute = deco; - if (builtins.count(builtin->value())) { + if (builtins.count(builtin->builtin)) { AddError( deco_to_str(builtin) + " attribute appears multiple times as pipeline " + (param_or_ret == ParamOrRetType::kParameter ? "input" : "output"), - func->source()); + func->source); return false; } @@ -1552,13 +1549,13 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func, ParamOrRetType::kParameter)) { return false; } - builtins.emplace(builtin->value()); + builtins.emplace(builtin->builtin); } else if (auto* location = deco->As()) { if (pipeline_io_attribute) { - AddError("multiple entry point IO attributes", deco->source()); + AddError("multiple entry point IO attributes", deco->source); AddNote( "previously consumed " + deco_to_str(pipeline_io_attribute), - pipeline_io_attribute->source()); + pipeline_io_attribute->source); return false; } pipeline_io_attribute = deco; @@ -1570,13 +1567,13 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func, } } else if (auto* interpolate = deco->As()) { - if (func->pipeline_stage() == ast::PipelineStage::kCompute) { + if (func->PipelineStage() == ast::PipelineStage::kCompute) { is_invalid_compute_shader_decoration = true; } else if (!ValidateInterpolateDecoration(interpolate, ty)) { return false; } } else if (auto* invariant = deco->As()) { - if (func->pipeline_stage() == ast::PipelineStage::kCompute) { + if (func->PipelineStage() == ast::PipelineStage::kCompute) { is_invalid_compute_shader_decoration = true; } invariant_attribute = invariant; @@ -1587,7 +1584,7 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func, : "output"; AddError( "decoration is not valid for compute shader " + input_or_output, - deco->source()); + deco->source); return false; } } @@ -1616,14 +1613,14 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func, if (pipeline_io_attribute) { if (auto* builtin = pipeline_io_attribute->As()) { - has_position = (builtin->value() == ast::Builtin::kPosition); + has_position = (builtin->builtin == ast::Builtin::kPosition); } } if (!has_position) { AddError( "invariant attribute must only be applied to a position " "builtin", - invariant_attribute->source()); + invariant_attribute->source); return false; } } @@ -1643,12 +1640,12 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func, if (auto* str = ty->As()) { for (auto* member : str->Members()) { if (!validate_entry_point_decorations_inner( - member->Declaration()->decorations(), member->Type(), - member->Declaration()->source(), param_or_ret, + member->Declaration()->decorations, member->Type(), + member->Declaration()->source, param_or_ret, /*is_struct_member*/ true)) { AddNote("while analysing entry point '" + - builder_->Symbols().NameFor(func->symbol()) + "'", - func->source()); + builder_->Symbols().NameFor(func->symbol) + "'", + func->source); return false; } } @@ -1659,8 +1656,8 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func, for (auto* param : info->parameters) { if (!validate_entry_point_decorations( - param->declaration->decorations(), param->type, - param->declaration->source(), ParamOrRetType::kParameter)) { + param->declaration->decorations, param->type, + param->declaration->source, ParamOrRetType::kParameter)) { return false; } } @@ -1672,21 +1669,21 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func, locations.clear(); if (!info->return_type->Is()) { - if (!validate_entry_point_decorations(func->return_type_decorations(), - info->return_type, func->source(), + if (!validate_entry_point_decorations(func->return_type_decorations, + info->return_type, func->source, ParamOrRetType::kReturnType)) { return false; } } - if (func->pipeline_stage() == ast::PipelineStage::kVertex && + if (func->PipelineStage() == ast::PipelineStage::kVertex && builtins.count(ast::Builtin::kPosition) == 0) { // Check module-scope variables, as the SPIR-V sanitizer generates these. bool found = false; for (auto* var : info->referenced_module_vars) { if (auto* builtin = ast::GetDecoration( - var->declaration->decorations())) { - if (builtin->value() == ast::Builtin::kPosition) { + var->declaration->decorations)) { + if (builtin->builtin == ast::Builtin::kPosition) { found = true; break; } @@ -1696,17 +1693,17 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func, AddError( "a vertex shader must include the 'position' builtin in its return " "type", - func->source()); + func->source); return false; } } - if (func->pipeline_stage() == ast::PipelineStage::kCompute) { - if (!ast::HasDecoration(func->decorations())) { + if (func->PipelineStage() == ast::PipelineStage::kCompute) { + if (!ast::HasDecoration(func->decorations)) { AddError( "a compute shader must include 'workgroup_size' in its " "attributes", - func->source()); + func->source); return false; } } @@ -1714,30 +1711,30 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func, // Validate there are no resource variable binding collisions std::unordered_map binding_points; for (auto* var_info : info->referenced_module_vars) { - if (!var_info->declaration->binding_point()) { + if (!var_info->declaration->BindingPoint()) { continue; } auto bp = var_info->binding_point; auto res = binding_points.emplace(bp, var_info->declaration); if (!res.second && - IsValidationEnabled(var_info->declaration->decorations(), + IsValidationEnabled(var_info->declaration->decorations, ast::DisabledValidation::kBindingPointCollision) && - IsValidationEnabled(res.first->second->decorations(), + IsValidationEnabled(res.first->second->decorations, ast::DisabledValidation::kBindingPointCollision)) { // https://gpuweb.github.io/gpuweb/wgsl/#resource-interface // Bindings must not alias within a shader stage: two different // variables in the resource interface of a given shader must not have // the same group and binding values, when considered as a pair of // values. - auto func_name = builder_->Symbols().NameFor(info->declaration->symbol()); + auto func_name = builder_->Symbols().NameFor(info->declaration->symbol); AddError("entry point '" + func_name + "' references multiple variables that use the " "same resource binding [[group(" + std::to_string(bp.group) + "), binding(" + std::to_string(bp.binding) + ")]]", - var_info->declaration->source()); + var_info->declaration->source); AddNote("first resource binding usage declared here", - res.first->second->source()); + res.first->second->source); return false; } } @@ -1757,14 +1754,14 @@ bool Resolver::Function(ast::Function* func) { variable_stack_.push_scope(); uint32_t parameter_index = 0; std::unordered_map parameter_names; - for (auto* param : func->params()) { + for (auto* param : func->params) { Mark(param); { // Check the parameter name is unique for the function - auto emplaced = parameter_names.emplace(param->symbol(), param->source()); + auto emplaced = parameter_names.emplace(param->symbol, param->source); if (!emplaced.second) { - auto name = builder_->Symbols().NameFor(param->symbol()); - AddError("redefinition of parameter '" + name + "'", param->source()); + auto name = builder_->Symbols().NameFor(param->symbol); + AddError("redefinition of parameter '" + name + "'", param->source); AddNote("previous definition is here", emplaced.first->second); return false; } @@ -1776,26 +1773,26 @@ bool Resolver::Function(ast::Function* func) { return false; } - for (auto* deco : param->decorations()) { + for (auto* deco : param->decorations) { Mark(deco); } - if (!ValidateNoDuplicateDecorations(param->decorations())) { + if (!ValidateNoDuplicateDecorations(param->decorations)) { return false; } - variable_stack_.set(param->symbol(), param_info); + variable_stack_.set(param->symbol, param_info); info->parameters.emplace_back(param_info); - if (!ApplyStorageClassUsageToType(param->declared_storage_class(), - param_info->type, param->source())) { + if (!ApplyStorageClassUsageToType(param->declared_storage_class, + param_info->type, param->source)) { AddNote("while instantiating parameter " + - builder_->Symbols().NameFor(param->symbol()), - param->source()); + builder_->Symbols().NameFor(param->symbol), + param->source); return false; } if (auto* str = param_info->type->As()) { - switch (func->pipeline_stage()) { + switch (func->PipelineStage()) { case ast::PipelineStage::kVertex: str->AddUsage(sem::PipelineStageUsage::kVertexInput); break; @@ -1811,7 +1808,7 @@ bool Resolver::Function(ast::Function* func) { } } - if (auto* ty = func->return_type()) { + if (auto* ty = func->return_type) { info->return_type = Type(ty); info->return_type_name = ty->FriendlyName(builder_->Symbols()); if (!info->return_type) { @@ -1825,14 +1822,14 @@ bool Resolver::Function(ast::Function* func) { if (auto* str = info->return_type->As()) { if (!ApplyStorageClassUsageToType(ast::StorageClass::kNone, str, - func->source())) { + func->source)) { AddNote("while instantiating return type for " + - builder_->Symbols().NameFor(func->symbol()), - func->source()); + builder_->Symbols().NameFor(func->symbol), + func->source); return false; } - switch (func->pipeline_stage()) { + switch (func->PipelineStage()) { case ast::PipelineStage::kVertex: str->AddUsage(sem::PipelineStageUsage::kVertexOutput); break; @@ -1847,32 +1844,32 @@ bool Resolver::Function(ast::Function* func) { } } - if (func->body()) { - Mark(func->body()); + if (func->body) { + Mark(func->body); if (current_compound_statement_) { TINT_ICE(Resolver, diagnostics_) << "Resolver::Function() called with a current compound statement"; return false; } auto* sem_block = builder_->create(func); - builder_->Sem().Add(func->body(), sem_block); - if (!Scope(sem_block, [&] { return Statements(func->body()->list()); })) { + builder_->Sem().Add(func->body, sem_block); + if (!Scope(sem_block, [&] { return Statements(func->body->statements); })) { return false; } } variable_stack_.pop_scope(); - for (auto* deco : func->decorations()) { + for (auto* deco : func->decorations) { Mark(deco); } - if (!ValidateNoDuplicateDecorations(func->decorations())) { + if (!ValidateNoDuplicateDecorations(func->decorations)) { return false; } - for (auto* deco : func->return_type_decorations()) { + for (auto* deco : func->return_type_decorations) { Mark(deco); } - if (!ValidateNoDuplicateDecorations(func->return_type_decorations())) { + if (!ValidateNoDuplicateDecorations(func->return_type_decorations)) { return false; } @@ -1883,8 +1880,8 @@ bool Resolver::Function(ast::Function* func) { } if (auto* workgroup = - ast::GetDecoration(func->decorations())) { - auto values = workgroup->values(); + ast::GetDecoration(func->decorations)) { + auto values = workgroup->Values(); auto any_i32 = false; auto any_u32 = false; for (int i = 0; i < 3; i++) { @@ -1913,33 +1910,33 @@ bool Resolver::Function(ast::Function* func) { bool is_i32 = ty->UnwrapRef()->Is(); bool is_u32 = ty->UnwrapRef()->Is(); if (!is_i32 && !is_u32) { - AddError(kErrBadType, expr->source()); + AddError(kErrBadType, expr->source); return false; } any_i32 = any_i32 || is_i32; any_u32 = any_u32 || is_u32; if (any_i32 && any_u32) { - AddError(kErrInconsistentType, expr->source()); + AddError(kErrInconsistentType, expr->source); return false; } if (auto* ident = expr->As()) { // We have an identifier of a module-scope constant. VariableInfo* var = nullptr; - if (!variable_stack_.get(ident->symbol(), &var) || - !(var->declaration->is_const())) { - AddError(kErrBadType, expr->source()); + if (!variable_stack_.get(ident->symbol, &var) || + !(var->declaration->is_const)) { + AddError(kErrBadType, expr->source); return false; } // Capture the constant if an [[override]] attribute is present. if (ast::HasDecoration( - var->declaration->decorations())) { + var->declaration->decorations)) { info->workgroup_size[i].overridable_const = var->declaration; } - expr = var->declaration->constructor(); + expr = var->declaration->constructor; if (!expr) { // No constructor means this value must be overriden by the user. info->workgroup_size[i].value = 0; @@ -1949,7 +1946,7 @@ bool Resolver::Function(ast::Function* func) { AddError( "workgroup_size argument must be either a literal or a " "module-scope constant", - values[i]->source()); + values[i]->source); return false; } @@ -1962,7 +1959,7 @@ bool Resolver::Function(ast::Function* func) { // Validate and set the default value for this dimension. if (is_i32 ? val.Elements()[0].i32 < 1 : val.Elements()[0].u32 < 1) { AddError("workgroup_size argument must be at least 1", - values[i]->source()); + values[i]->source); return false; } @@ -1979,7 +1976,7 @@ bool Resolver::Function(ast::Function* func) { // Register the function information _after_ processing the statements. This // allows us to catch a function calling itself when determining the call // information as this function doesn't exist until it's finished. - symbol_to_function_[func->symbol()] = info; + symbol_to_function_[func->symbol] = info; function_to_info_.emplace(func, info); return true; @@ -2003,16 +2000,16 @@ bool Resolver::ValidateStatements(const ast::StatementList& stmts) { bool unreachable = false; for (auto* stmt : stmts) { if (unreachable) { - AddError("code is unreachable", stmt->source()); + AddError("code is unreachable", stmt->source); return false; } auto* nested_stmt = stmt; while (auto* block = nested_stmt->As()) { - if (block->empty()) { + if (block->Empty()) { break; } - nested_stmt = block->statements().back(); + nested_stmt = block->statements.back(); } if (nested_stmt->IsAnyOf()) { @@ -2025,7 +2022,7 @@ bool Resolver::ValidateStatements(const ast::StatementList& stmts) { bool Resolver::Statement(ast::Statement* stmt) { if (stmt->Is()) { AddError("case statement can only be used inside a switch statement", - stmt->source()); + stmt->source); return false; } if (stmt->Is()) { @@ -2066,14 +2063,14 @@ bool Resolver::Statement(ast::Statement* stmt) { if (!sem_statement->FindFirstParent() && !sem_statement->FindFirstParent()) { AddError("break statement must be in a loop or switch case", - stmt->source()); + stmt->source); return false; } return true; } if (auto* c = stmt->As()) { - Mark(c->expr()); - if (!Expression(c->expr())) { + Mark(c->expr); + if (!Expression(c->expr)) { return false; } if (!ValidateCallStatement(c)) { @@ -2093,11 +2090,11 @@ bool Resolver::Statement(ast::Statement* stmt) { } } else { AddError("continuing blocks must not contain a continue statement", - stmt->source()); + stmt->source); return false; } } else { - AddError("continue statement must be in a loop", stmt->source()); + AddError("continue statement must be in a loop", stmt->source); return false; } @@ -2108,10 +2105,9 @@ bool Resolver::Statement(ast::Statement* stmt) { sem_statement ->FindFirstParent()) { AddError("continuing blocks must not contain a discard statement", - stmt->source()); + stmt->source); if (continuing != sem_statement->Parent()) { - AddNote("see continuing block here", - continuing->Declaration()->source()); + AddNote("see continuing block here", continuing->Declaration()->source); } return false; } @@ -2129,20 +2125,20 @@ bool Resolver::Statement(ast::Statement* stmt) { AddError("unknown statement type for type determination: " + std::string(stmt->TypeInfo().name), - stmt->source()); + stmt->source); return false; } bool Resolver::CaseStatement(ast::CaseStatement* stmt) { auto* sem = builder_->create( - stmt->body(), current_compound_statement_); + stmt->body, current_compound_statement_); builder_->Sem().Add(stmt, sem); - builder_->Sem().Add(stmt->body(), sem); - Mark(stmt->body()); - for (auto* sel : stmt->selectors()) { + builder_->Sem().Add(stmt->body, sem); + Mark(stmt->body); + for (auto* sel : stmt->selectors) { Mark(sel); } - return Scope(sem, [&] { return Statements(stmt->body()->list()); }); + return Scope(sem, [&] { return Statements(stmt->body->statements); }); } bool Resolver::IfStatement(ast::IfStatement* stmt) { @@ -2150,28 +2146,28 @@ bool Resolver::IfStatement(ast::IfStatement* stmt) { builder_->create(stmt, current_compound_statement_); builder_->Sem().Add(stmt, sem); return Scope(sem, [&] { - Mark(stmt->condition()); - if (!Expression(stmt->condition())) { + Mark(stmt->condition); + if (!Expression(stmt->condition)) { return false; } - auto* cond_type = TypeOf(stmt->condition())->UnwrapRef(); + auto* cond_type = TypeOf(stmt->condition)->UnwrapRef(); if (!cond_type->Is()) { AddError("if statement condition must be bool, got " + cond_type->FriendlyName(builder_->Symbols()), - stmt->condition()->source()); + stmt->condition->source); return false; } - Mark(stmt->body()); + Mark(stmt->body); auto* body = builder_->create( - stmt->body(), current_compound_statement_); - builder_->Sem().Add(stmt->body(), body); - if (!Scope(body, [&] { return Statements(stmt->body()->list()); })) { + stmt->body, current_compound_statement_); + builder_->Sem().Add(stmt->body, body); + if (!Scope(body, [&] { return Statements(stmt->body->statements); })) { return false; } - for (auto* else_stmt : stmt->else_statements()) { + for (auto* else_stmt : stmt->else_statements) { Mark(else_stmt); if (!ElseStatement(else_stmt)) { return false; @@ -2186,7 +2182,7 @@ bool Resolver::ElseStatement(ast::ElseStatement* stmt) { builder_->create(stmt, current_compound_statement_); builder_->Sem().Add(stmt, sem); return Scope(sem, [&] { - if (auto* cond = stmt->condition()) { + if (auto* cond = stmt->condition) { Mark(cond); if (!Expression(cond)) { return false; @@ -2196,16 +2192,16 @@ bool Resolver::ElseStatement(ast::ElseStatement* stmt) { if (!else_cond_type->Is()) { AddError("else statement condition must be bool, got " + else_cond_type->FriendlyName(builder_->Symbols()), - cond->source()); + cond->source); return false; } } - Mark(stmt->body()); + Mark(stmt->body); auto* body = builder_->create( - stmt->body(), current_compound_statement_); - builder_->Sem().Add(stmt->body(), body); - return Scope(body, [&] { return Statements(stmt->body()->list()); }); + stmt->body, current_compound_statement_); + builder_->Sem().Add(stmt->body, body); + return Scope(body, [&] { return Statements(stmt->body->statements); }); }); } @@ -2213,7 +2209,7 @@ bool Resolver::BlockStatement(ast::BlockStatement* stmt) { auto* sem = builder_->create( stmt->As(), current_compound_statement_); builder_->Sem().Add(stmt, sem); - return Scope(sem, [&] { return Statements(stmt->list()); }); + return Scope(sem, [&] { return Statements(stmt->statements); }); } bool Resolver::LoopStatement(ast::LoopStatement* stmt) { @@ -2221,25 +2217,27 @@ bool Resolver::LoopStatement(ast::LoopStatement* stmt) { builder_->create(stmt, current_compound_statement_); builder_->Sem().Add(stmt, sem); return Scope(sem, [&] { - Mark(stmt->body()); + Mark(stmt->body); auto* body = builder_->create( - stmt->body(), current_compound_statement_); - builder_->Sem().Add(stmt->body(), body); + stmt->body, current_compound_statement_); + builder_->Sem().Add(stmt->body, body); return Scope(body, [&] { - if (!Statements(stmt->body()->list())) { + if (!Statements(stmt->body->statements)) { return false; } - if (stmt->continuing()) { // has_continuing() also checks for empty() - Mark(stmt->continuing()); - } - if (stmt->has_continuing()) { - auto* continuing = builder_->create( - stmt->continuing(), current_compound_statement_); - builder_->Sem().Add(stmt->continuing(), continuing); - if (!Scope(continuing, - [&] { return Statements(stmt->continuing()->list()); })) { - return false; + if (stmt->continuing) { + Mark(stmt->continuing); + if (!stmt->continuing->Empty()) { + auto* continuing = + builder_->create( + stmt->continuing, current_compound_statement_); + builder_->Sem().Add(stmt->continuing, continuing); + if (!Scope(continuing, [&] { + return Statements(stmt->continuing->statements); + })) { + return false; + } } } return true; @@ -2252,14 +2250,14 @@ bool Resolver::ForLoopStatement(ast::ForLoopStatement* stmt) { stmt, current_compound_statement_); builder_->Sem().Add(stmt, sem); return Scope(sem, [&] { - if (auto* initializer = stmt->initializer()) { + if (auto* initializer = stmt->initializer) { Mark(initializer); if (!Statement(initializer)) { return false; } } - if (auto* condition = stmt->condition()) { + if (auto* condition = stmt->condition) { Mark(condition); if (!Expression(condition)) { return false; @@ -2268,24 +2266,24 @@ bool Resolver::ForLoopStatement(ast::ForLoopStatement* stmt) { if (!TypeOf(condition)->UnwrapRef()->Is()) { AddError( "for-loop condition must be bool, got " + TypeNameOf(condition), - condition->source()); + condition->source); return false; } } - if (auto* continuing = stmt->continuing()) { + if (auto* continuing = stmt->continuing) { Mark(continuing); if (!Statement(continuing)) { return false; } } - Mark(stmt->body()); + Mark(stmt->body); auto* body = builder_->create( - stmt->body(), current_compound_statement_); - builder_->Sem().Add(stmt->body(), body); - return Scope(body, [&] { return Statements(stmt->body()->statements()); }); + stmt->body, current_compound_statement_); + builder_->Sem().Add(stmt->body, body); + return Scope(body, [&] { return Statements(stmt->body->statements); }); }); } @@ -2306,25 +2304,25 @@ bool Resolver::TraverseExpressions(ast::Expression* root, out.emplace_back(expr); if (auto* array = expr->As()) { - add(array->array()); - add(array->idx_expr()); + add(array->array); + add(array->index); } else if (auto* bin_op = expr->As()) { - add(bin_op->lhs()); - add(bin_op->rhs()); + add(bin_op->lhs); + add(bin_op->rhs); } else if (auto* bitcast = expr->As()) { - add(bitcast->expr()); + add(bitcast->expr); } else if (auto* call = expr->As()) { - for (auto* arg : call->args()) { + for (auto* arg : call->args) { add(arg); } } else if (auto* type_ctor = expr->As()) { - for (auto* value : type_ctor->values()) { + for (auto* value : type_ctor->values) { add(value); } } else if (auto* member = expr->As()) { - add(member->structure()); + add(member->structure); } else if (auto* unary = expr->As()) { - add(unary->expr()); + add(unary->expr); } else if (expr->IsAnyOf()) { // Leaf expression @@ -2376,8 +2374,8 @@ bool Resolver::Expression(ast::Expression* root) { } bool Resolver::ArrayAccessor(ast::ArrayAccessorExpression* expr) { - auto* idx = expr->idx_expr(); - auto* res = TypeOf(expr->array()); + auto* idx = expr->index; + auto* res = TypeOf(expr->array); auto* parent_type = res->UnwrapRef(); const sem::Type* ret = nullptr; if (auto* arr = parent_type->As()) { @@ -2387,15 +2385,15 @@ bool Resolver::ArrayAccessor(ast::ArrayAccessorExpression* expr) { } else if (auto* mat = parent_type->As()) { ret = builder_->create(mat->type(), mat->rows()); } else { - AddError("cannot index type '" + TypeNameOf(expr->array()) + "'", - expr->source()); + AddError("cannot index type '" + TypeNameOf(expr->array) + "'", + expr->source); return false; } if (!TypeOf(idx)->UnwrapRef()->IsAnyOf()) { AddError("index must be of type 'i32' or 'u32', found: '" + TypeNameOf(idx) + "'", - idx->source()); + idx->source); return false; } @@ -2404,9 +2402,9 @@ bool Resolver::ArrayAccessor(ast::ArrayAccessorExpression* expr) { // TODO(bclayton): expand this to allow any const_expr expression // https://github.com/gpuweb/gpuweb/issues/1272 auto* scalar = idx->As(); - if (!scalar || !scalar->literal()->As()) { + if (!scalar || !scalar->literal->As()) { AddError("index must be signed or unsigned integer literal", - idx->source()); + idx->source); return false; } } @@ -2423,22 +2421,22 @@ bool Resolver::ArrayAccessor(ast::ArrayAccessorExpression* expr) { } bool Resolver::Bitcast(ast::BitcastExpression* expr) { - auto* ty = Type(expr->type()); + auto* ty = Type(expr->type); if (!ty) { return false; } if (ty->Is()) { - AddError("cannot cast to a pointer", expr->source()); + AddError("cannot cast to a pointer", expr->source); return false; } - SetExprInfo(expr, ty, expr->type()->FriendlyName(builder_->Symbols())); + SetExprInfo(expr, ty, expr->type->FriendlyName(builder_->Symbols())); return true; } bool Resolver::Call(ast::CallExpression* call) { - Mark(call->func()); - auto* ident = call->func(); - auto name = builder_->Symbols().NameFor(ident->symbol()); + Mark(call->func); + auto* ident = call->func; + auto name = builder_->Symbols().NameFor(ident->symbol); auto intrinsic_type = sem::ParseIntrinsicType(name); if (intrinsic_type != IntrinsicType::kNone) { @@ -2460,7 +2458,7 @@ bool Resolver::ValidateCall(ast::CallExpression* call) { if (current_statement_) { if (auto* call_stmt = As(current_statement_->Declaration())) { - if (call_stmt->expr() == call) { + if (call_stmt->expr == call) { is_call_statement = true; } } @@ -2469,15 +2467,15 @@ bool Resolver::ValidateCall(ast::CallExpression* call) { // https://gpuweb.github.io/gpuweb/wgsl/#function-call-expr // If the called function does not return a value, a function call // statement should be used instead. - auto* ident = call->func(); - auto name = builder_->Symbols().NameFor(ident->symbol()); + auto* ident = call->func; + auto name = builder_->Symbols().NameFor(ident->symbol); // A function call is made to either a user declared function or an // intrinsic. function_calls_ only maps CallExpression to user declared // functions bool is_function = function_calls_.count(call) != 0; AddError((is_function ? "function" : "intrinsic") + std::string(" '") + name + "' does not return a value", - call->source()); + call->source); return false; } } @@ -2486,7 +2484,7 @@ bool Resolver::ValidateCall(ast::CallExpression* call) { } bool Resolver::ValidateCallStatement(ast::CallStatement* stmt) { - const sem::Type* return_type = TypeOf(stmt->expr()); + const sem::Type* return_type = TypeOf(stmt->expr); if (!return_type->Is()) { // https://gpuweb.github.io/gpuweb/wgsl/#function-call-statement // A function call statement executes a function call where the called @@ -2497,7 +2495,7 @@ bool Resolver::ValidateCallStatement(ast::CallStatement* stmt) { AddError( "result of called function was not used. If this was intentional wrap " "the function call in ignore()", - stmt->source()); + stmt->source); return false; } return true; @@ -2506,19 +2504,19 @@ bool Resolver::ValidateCallStatement(ast::CallStatement* stmt) { bool Resolver::IntrinsicCall(ast::CallExpression* call, sem::IntrinsicType intrinsic_type) { std::vector arg_tys; - arg_tys.reserve(call->args().size()); - for (auto* expr : call->args()) { + arg_tys.reserve(call->args.size()); + for (auto* expr : call->args) { arg_tys.emplace_back(TypeOf(expr)); } auto* result = - intrinsic_table_->Lookup(intrinsic_type, arg_tys, call->source()); + intrinsic_table_->Lookup(intrinsic_type, arg_tys, call->source); if (!result) { return false; } if (result->IsDeprecated()) { - AddWarning("use of deprecated intrinsic", call->source()); + AddWarning("use of deprecated intrinsic", call->source); } auto* out = builder_->create(call, result, current_statement_); @@ -2547,13 +2545,13 @@ bool Resolver::ValidateTextureIntrinsicFunction( auto& signature = intrinsic->Signature(); auto index = signature.IndexOf(sem::ParameterUsage::kOffset); if (index > -1) { - auto* param = ast_call->args()[index]; + auto* param = ast_call->args[index]; if (param->Is()) { auto values = ConstantValueOf(param); if (!values.IsValid()) { AddError( "'" + func_name + "' offset parameter must be a const_expression", - param->source()); + param->source); return false; } if (!values.Type()->Is() || @@ -2569,14 +2567,14 @@ bool Resolver::ValidateTextureIntrinsicFunction( "' must be at least -8 and at most 7. " "found: '" + std::to_string(offset_value) + "'", - param->source()); + param->source); return false; } } } else { AddError( "'" + func_name + "' offset parameter must be a const_expression", - param->source()); + param->source); return false; } } @@ -2584,18 +2582,18 @@ bool Resolver::ValidateTextureIntrinsicFunction( } bool Resolver::FunctionCall(const ast::CallExpression* call) { - auto* ident = call->func(); - auto name = builder_->Symbols().NameFor(ident->symbol()); + auto* ident = call->func; + auto name = builder_->Symbols().NameFor(ident->symbol); - auto callee_func_it = symbol_to_function_.find(ident->symbol()); + auto callee_func_it = symbol_to_function_.find(ident->symbol); if (callee_func_it == symbol_to_function_.end()) { if (current_function_ && - current_function_->declaration->symbol() == ident->symbol()) { + current_function_->declaration->symbol == ident->symbol) { AddError("recursion is not permitted. '" + name + "' attempted to call itself.", - call->source()); + call->source); } else { - AddError("unable to find called function: " + name, call->source()); + AddError("unable to find called function: " + name, call->source); } return false; } @@ -2630,30 +2628,30 @@ bool Resolver::FunctionCall(const ast::CallExpression* call) { bool Resolver::ValidateFunctionCall(const ast::CallExpression* call, const FunctionInfo* target) { - auto* ident = call->func(); - auto name = builder_->Symbols().NameFor(ident->symbol()); + auto* ident = call->func; + auto name = builder_->Symbols().NameFor(ident->symbol); if (target->declaration->IsEntryPoint()) { // https://www.w3.org/TR/WGSL/#function-restriction // An entry point must never be the target of a function call. AddError("entry point functions cannot be the target of a function call", - call->source()); + call->source); return false; } - if (call->args().size() != target->parameters.size()) { - bool more = call->args().size() > target->parameters.size(); + if (call->args.size() != target->parameters.size()) { + bool more = call->args.size() > target->parameters.size(); AddError("too " + (more ? std::string("many") : std::string("few")) + " arguments in call to '" + name + "', expected " + std::to_string(target->parameters.size()) + ", got " + - std::to_string(call->args().size()), - call->source()); + std::to_string(call->args.size()), + call->source); return false; } - for (size_t i = 0; i < call->args().size(); ++i) { + for (size_t i = 0; i < call->args.size(); ++i) { const VariableInfo* param = target->parameters[i]; - const ast::Expression* arg_expr = call->args()[i]; + const ast::Expression* arg_expr = call->args[i]; auto* arg_type = TypeOf(arg_expr)->UnwrapRef(); if (param->type != arg_type) { @@ -2661,15 +2659,15 @@ bool Resolver::ValidateFunctionCall(const ast::CallExpression* call, " in call to '" + name + "', expected '" + param->type->FriendlyName(builder_->Symbols()) + "', got '" + arg_type->FriendlyName(builder_->Symbols()) + "'", - arg_expr->source()); + arg_expr->source); return false; } - if (param->declaration->type()->Is()) { + if (param->declaration->type->Is()) { auto is_valid = false; if (auto* ident_expr = arg_expr->As()) { VariableInfo* var; - if (!variable_stack_.get(ident_expr->symbol(), &var)) { + if (!variable_stack_.get(ident_expr->symbol, &var)) { TINT_ICE(Resolver, diagnostics_) << "failed to resolve identifier"; return false; } @@ -2677,16 +2675,16 @@ bool Resolver::ValidateFunctionCall(const ast::CallExpression* call, is_valid = true; } } else if (auto* unary = arg_expr->As()) { - if (unary->op() == ast::UnaryOp::kAddressOf) { + if (unary->op == ast::UnaryOp::kAddressOf) { if (auto* ident_unary = - unary->expr()->As()) { + unary->expr->As()) { VariableInfo* var; - if (!variable_stack_.get(ident_unary->symbol(), &var)) { + if (!variable_stack_.get(ident_unary->symbol, &var)) { TINT_ICE(Resolver, diagnostics_) << "failed to resolve identifier"; return false; } - if (var->declaration->is_const()) { + if (var->declaration->is_const) { TINT_ICE(Resolver, diagnostics_) << "Resolver::FunctionCall() encountered an address-of " "expression of a constant identifier expression"; @@ -2699,12 +2697,12 @@ bool Resolver::ValidateFunctionCall(const ast::CallExpression* call, if (!is_valid && IsValidationEnabled( - param->declaration->decorations(), + param->declaration->decorations, ast::DisabledValidation::kIgnoreInvalidPointerArgument)) { AddError( "expected an address-of expression of a variable identifier " "expression or a function parameter", - arg_expr->source()); + arg_expr->source); return false; } } @@ -2714,12 +2712,12 @@ bool Resolver::ValidateFunctionCall(const ast::CallExpression* call, bool Resolver::Constructor(ast::ConstructorExpression* expr) { if (auto* type_ctor = expr->As()) { - auto* type = Type(type_ctor->type()); + auto* type = Type(type_ctor->type); if (!type) { return false; } - auto type_name = type_ctor->type()->FriendlyName(builder_->Symbols()); + auto type_name = type_ctor->type->FriendlyName(builder_->Symbols()); // Now that the argument types have been determined, make sure that they // obey the constructor type rules laid out in @@ -2736,7 +2734,7 @@ bool Resolver::Constructor(ast::ConstructorExpression* expr) { } else if (auto* struct_type = type->As()) { ok = ValidateStructureConstructor(type_ctor, struct_type); } else { - AddError("type is not constructible", type_ctor->source()); + AddError("type is not constructible", type_ctor->source); return false; } if (!ok) { @@ -2747,8 +2745,8 @@ bool Resolver::Constructor(ast::ConstructorExpression* expr) { } if (auto* scalar_ctor = expr->As()) { - Mark(scalar_ctor->literal()); - auto* type = TypeOf(scalar_ctor->literal()); + Mark(scalar_ctor->literal); + auto* type = TypeOf(scalar_ctor->literal); if (!type) { return false; } @@ -2764,30 +2762,29 @@ bool Resolver::ValidateStructureConstructor( const ast::TypeConstructorExpression* ctor, const sem::Struct* struct_type) { if (!struct_type->IsConstructible()) { - AddError("struct constructor has non-constructible type", ctor->source()); + AddError("struct constructor has non-constructible type", ctor->source); return false; } - if (ctor->values().size() > 0) { - if (ctor->values().size() != struct_type->Members().size()) { - std::string fm = ctor->values().size() < struct_type->Members().size() - ? "few" - : "many"; + if (ctor->values.size() > 0) { + if (ctor->values.size() != struct_type->Members().size()) { + std::string fm = + ctor->values.size() < struct_type->Members().size() ? "few" : "many"; AddError("struct constructor has too " + fm + " inputs: expected " + std::to_string(struct_type->Members().size()) + ", found " + - std::to_string(ctor->values().size()), - ctor->source()); + std::to_string(ctor->values.size()), + ctor->source); return false; } for (auto* member : struct_type->Members()) { - auto* value = ctor->values()[member->Index()]; + auto* value = ctor->values[member->Index()]; if (member->Type() != TypeOf(value)->UnwrapRef()) { AddError( "type in struct constructor does not match struct member type: " "expected '" + member->Type()->FriendlyName(builder_->Symbols()) + "', found '" + TypeNameOf(value) + "'", - value->source()); + value->source); return false; } } @@ -2798,7 +2795,7 @@ bool Resolver::ValidateStructureConstructor( bool Resolver::ValidateArrayConstructor( const ast::TypeConstructorExpression* ctor, const sem::Array* array_type) { - auto& values = ctor->values(); + auto& values = ctor->values; auto* elem_type = array_type->ElemType(); for (auto* value : values) { auto* value_type = TypeOf(value)->UnwrapRef(); @@ -2808,30 +2805,30 @@ bool Resolver::ValidateArrayConstructor( "expected '" + elem_type->FriendlyName(builder_->Symbols()) + "', found '" + TypeNameOf(value) + "'", - value->source()); + value->source); return false; } } if (array_type->IsRuntimeSized()) { - AddError("cannot init a runtime-sized array", ctor->source()); + AddError("cannot init a runtime-sized array", ctor->source); return false; } else if (!elem_type->IsConstructible()) { AddError("array constructor has non-constructible element type", - ctor->type()->As()->type()->source()); + ctor->type->As()->type->source); return false; } else if (!values.empty() && (values.size() != array_type->Count())) { std::string fm = values.size() < array_type->Count() ? "few" : "many"; AddError("array constructor has too " + fm + " elements: expected " + std::to_string(array_type->Count()) + ", found " + std::to_string(values.size()), - ctor->source()); + ctor->source); return false; } else if (values.size() > array_type->Count()) { AddError("array constructor has too many elements: expected " + std::to_string(array_type->Count()) + ", found " + std::to_string(values.size()), - ctor->source()); + ctor->source); return false; } return true; @@ -2841,7 +2838,7 @@ bool Resolver::ValidateVectorConstructor( const ast::TypeConstructorExpression* ctor, const sem::Vector* vec_type, const std::string& type_name) { - auto& values = ctor->values(); + auto& values = ctor->values; auto* elem_type = vec_type->type(); size_t value_cardinality_sum = 0; for (auto* value : values) { @@ -2853,7 +2850,7 @@ bool Resolver::ValidateVectorConstructor( "expected '" + elem_type->FriendlyName(builder_->Symbols()) + "', found '" + TypeNameOf(value) + "'", - value->source()); + value->source); return false; } @@ -2869,7 +2866,7 @@ bool Resolver::ValidateVectorConstructor( "expected '" + elem_type->FriendlyName(builder_->Symbols()) + "', found '" + value_elem_type->FriendlyName(builder_->Symbols()) + "'", - value->source()); + value->source); return false; } @@ -2878,7 +2875,7 @@ bool Resolver::ValidateVectorConstructor( // A vector constructor can only accept vectors and scalars. AddError("expected vector or scalar type in vector constructor; found: " + value_type->FriendlyName(builder_->Symbols()), - value->source()); + value->source); return false; } } @@ -2891,8 +2888,8 @@ bool Resolver::ValidateVectorConstructor( TINT_ICE(Resolver, diagnostics_) << "constructor arguments expected to be non-empty!"; } - const Source& values_start = values[0]->source(); - const Source& values_end = values[values.size() - 1]->source(); + const Source& values_start = values[0]->source; + const Source& values_end = values[values.size() - 1]->source; AddError("attempted to construct '" + type_name + "' with " + std::to_string(value_cardinality_sum) + " component(s)", Source::Combine(values_start, values_end)); @@ -2922,20 +2919,20 @@ bool Resolver::ValidateMatrixConstructor( const ast::TypeConstructorExpression* ctor, const sem::Matrix* matrix_type, const std::string& type_name) { - auto& values = ctor->values(); + auto& values = ctor->values; // Zero Value expression if (values.empty()) { return true; } - if (!ValidateMatrix(matrix_type, ctor->source())) { + if (!ValidateMatrix(matrix_type, ctor->source)) { return false; } auto* elem_type = matrix_type->type(); if (matrix_type->columns() != values.size()) { - const Source& values_start = values[0]->source(); - const Source& values_end = values[values.size() - 1]->source(); + const Source& values_start = values[0]->source; + const Source& values_end = values[values.size() - 1]->source; AddError("expected " + std::to_string(matrix_type->columns()) + " '" + VectorPretty(matrix_type->rows(), elem_type) + "' arguments in '" + type_name + "' constructor, found " + @@ -2954,7 +2951,7 @@ bool Resolver::ValidateMatrixConstructor( VectorPretty(matrix_type->rows(), elem_type) + "' in '" + type_name + "' constructor, found '" + TypeNameOf(value) + "'", - value->source()); + value->source); return false; } } @@ -2966,18 +2963,18 @@ bool Resolver::ValidateScalarConstructor( const ast::TypeConstructorExpression* ctor, const sem::Type* type, const std::string& type_name) { - if (ctor->values().size() == 0) { + if (ctor->values.size() == 0) { return true; } - if (ctor->values().size() > 1) { + if (ctor->values.size() > 1) { AddError("expected zero or one value in constructor, got " + - std::to_string(ctor->values().size()), - ctor->source()); + std::to_string(ctor->values.size()), + ctor->source); return false; } // Validate constructor - auto* value = ctor->values()[0]; + auto* value = ctor->values[0]; auto* value_type = TypeOf(value)->UnwrapRef(); using Bool = sem::Bool; @@ -2992,7 +2989,7 @@ bool Resolver::ValidateScalarConstructor( if (!is_valid) { AddError("cannot construct '" + type_name + "' with a value of type '" + TypeNameOf(value) + "'", - ctor->source()); + ctor->source); return false; } @@ -3001,7 +2998,7 @@ bool Resolver::ValidateScalarConstructor( } bool Resolver::Identifier(ast::IdentifierExpression* expr) { - auto symbol = expr->symbol(); + auto symbol = expr->symbol; VariableInfo* var; if (variable_stack_.get(symbol, &var)) { SetExprInfo(expr, var->type, var->type_name); @@ -3022,22 +3019,22 @@ bool Resolver::Identifier(ast::IdentifierExpression* expr) { auto& decls = loop_block->Decls(); // If our identifier is in loop_block->decls, make sure its index is // less than first_continue - auto iter = std::find_if( - decls.begin(), decls.end(), - [&symbol](auto* v) { return v->symbol() == symbol; }); + auto iter = + std::find_if(decls.begin(), decls.end(), + [&symbol](auto* v) { return v->symbol == symbol; }); if (iter != decls.end()) { auto var_decl_index = static_cast(std::distance(decls.begin(), iter)); if (var_decl_index >= loop_block->NumDeclsAtFirstContinue()) { AddError("continue statement bypasses declaration of '" + builder_->Symbols().NameFor(symbol) + "'", - loop_block->FirstContinue()->source()); + loop_block->FirstContinue()->source); AddNote("identifier '" + builder_->Symbols().NameFor(symbol) + "' declared here", - (*iter)->source()); + (*iter)->source); AddNote("identifier '" + builder_->Symbols().NameFor(symbol) + "' referenced in continuing block here", - expr->source()); + expr->source); return false; } } @@ -3050,30 +3047,30 @@ bool Resolver::Identifier(ast::IdentifierExpression* expr) { auto iter = symbol_to_function_.find(symbol); if (iter != symbol_to_function_.end()) { - AddError("missing '(' for function call", expr->source().End()); + AddError("missing '(' for function call", expr->source.End()); return false; } std::string name = builder_->Symbols().NameFor(symbol); if (sem::ParseIntrinsicType(name) != IntrinsicType::kNone) { - AddError("missing '(' for intrinsic call", expr->source().End()); + AddError("missing '(' for intrinsic call", expr->source.End()); return false; } - AddError("identifier must be declared before use: " + name, expr->source()); + AddError("identifier must be declared before use: " + name, expr->source); return false; } bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) { - auto* structure = TypeOf(expr->structure()); + auto* structure = TypeOf(expr->structure); auto* storage_type = structure->UnwrapRef(); sem::Type* ret = nullptr; std::vector swizzle; if (auto* str = storage_type->As()) { - Mark(expr->member()); - auto symbol = expr->member()->symbol(); + Mark(expr->member); + auto symbol = expr->member->symbol; const sem::StructMember* member = nullptr; for (auto* m : str->Members()) { @@ -3087,7 +3084,7 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) { if (ret == nullptr) { AddError( "struct member " + builder_->Symbols().NameFor(symbol) + " not found", - expr->source()); + expr->source); return false; } @@ -3100,8 +3097,8 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) { builder_->Sem().Add(expr, builder_->create( expr, ret, current_statement_, member)); } else if (auto* vec = storage_type->As()) { - Mark(expr->member()); - std::string s = builder_->Symbols().NameFor(expr->member()->symbol()); + Mark(expr->member); + std::string s = builder_->Symbols().NameFor(expr->member->symbol); auto size = s.size(); swizzle.reserve(s.size()); @@ -3125,18 +3122,18 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) { break; default: AddError("invalid vector swizzle character", - expr->member()->source().Begin() + swizzle.size()); + expr->member->source.Begin() + swizzle.size()); return false; } if (swizzle.back() >= vec->Width()) { - AddError("invalid vector swizzle member", expr->member()->source()); + AddError("invalid vector swizzle member", expr->member->source); return false; } } if (size < 1 || size > 4) { - AddError("invalid vector swizzle size", expr->member()->source()); + AddError("invalid vector swizzle size", expr->member->source); return false; } @@ -3150,7 +3147,7 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) { if (!std::all_of(s.begin(), s.end(), is_rgba) && !std::all_of(s.begin(), s.end(), is_xyzw)) { AddError("invalid mixing of vector swizzle characters rgba with xyzw", - expr->member()->source()); + expr->member->source); return false; } @@ -3174,8 +3171,8 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) { } else { AddError( "invalid member accessor expression. Expected vector or struct, got '" + - TypeNameOf(expr->structure()) + "'", - expr->structure()->source()); + TypeNameOf(expr->structure) + "'", + expr->structure->source); return false; } @@ -3192,8 +3189,8 @@ bool Resolver::Binary(ast::BinaryExpression* expr) { using Matrix = sem::Matrix; using Vector = sem::Vector; - auto* lhs_type = const_cast(TypeOf(expr->lhs())->UnwrapRef()); - auto* rhs_type = const_cast(TypeOf(expr->rhs())->UnwrapRef()); + auto* lhs_type = const_cast(TypeOf(expr->lhs)->UnwrapRef()); + auto* rhs_type = const_cast(TypeOf(expr->rhs)->UnwrapRef()); auto* lhs_vec = lhs_type->As(); auto* lhs_vec_elem_type = lhs_vec ? lhs_vec->type() : nullptr; @@ -3383,14 +3380,14 @@ bool Resolver::Binary(ast::BinaryExpression* expr) { AddError("Binary expression operand types are invalid for this operation: " + lhs_type->FriendlyName(builder_->Symbols()) + " " + - FriendlyName(expr->op()) + " " + + FriendlyName(expr->op) + " " + rhs_type->FriendlyName(builder_->Symbols()), - expr->source()); + expr->source); return false; } bool Resolver::UnaryOp(ast::UnaryOpExpression* unary) { - auto* expr_type = TypeOf(unary->expr()); + auto* expr_type = TypeOf(unary->expr); if (!expr_type) { return false; } @@ -3398,40 +3395,39 @@ bool Resolver::UnaryOp(ast::UnaryOpExpression* unary) { std::string type_name; const sem::Type* type = nullptr; - switch (unary->op()) { + switch (unary->op) { case ast::UnaryOp::kNot: // Result type matches the deref'd inner type. - type_name = TypeNameOf(unary->expr()); + type_name = TypeNameOf(unary->expr); type = expr_type->UnwrapRef(); if (!type->Is() && !type->is_bool_vector()) { AddError("cannot logical negate expression of type '" + - TypeNameOf(unary->expr()), - unary->expr()->source()); + TypeNameOf(unary->expr), + unary->expr->source); return false; } break; case ast::UnaryOp::kComplement: // Result type matches the deref'd inner type. - type_name = TypeNameOf(unary->expr()); + type_name = TypeNameOf(unary->expr); type = expr_type->UnwrapRef(); if (!type->is_integer_scalar_or_vector()) { AddError("cannot bitwise complement expression of type '" + - TypeNameOf(unary->expr()), - unary->expr()->source()); + TypeNameOf(unary->expr), + unary->expr->source); return false; } break; case ast::UnaryOp::kNegation: // Result type matches the deref'd inner type. - type_name = TypeNameOf(unary->expr()); + type_name = TypeNameOf(unary->expr); type = expr_type->UnwrapRef(); if (!(type->IsAnyOf() || type->is_signed_integer_vector() || type->is_float_vector())) { - AddError( - "cannot negate expression of type '" + TypeNameOf(unary->expr()), - unary->expr()->source()); + AddError("cannot negate expression of type '" + TypeNameOf(unary->expr), + unary->expr->source); return false; } break; @@ -3441,14 +3437,13 @@ bool Resolver::UnaryOp(ast::UnaryOpExpression* unary) { if (ref->StoreType()->UnwrapRef()->is_handle()) { AddError( "cannot take the address of expression in handle storage class", - unary->expr()->source()); + unary->expr->source); return false; } type = builder_->create( ref->StoreType(), ref->StorageClass(), ref->Access()); } else { - AddError("cannot take the address of expression", - unary->expr()->source()); + AddError("cannot take the address of expression", unary->expr->source); return false; } break; @@ -3459,8 +3454,8 @@ bool Resolver::UnaryOp(ast::UnaryOpExpression* unary) { ptr->StoreType(), ptr->StorageClass(), ptr->Access()); } else { AddError("cannot dereference expression of type '" + - TypeNameOf(unary->expr()) + "'", - unary->expr()->source()); + TypeNameOf(unary->expr) + "'", + unary->expr->source); return false; } break; @@ -3471,10 +3466,10 @@ bool Resolver::UnaryOp(ast::UnaryOpExpression* unary) { } bool Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) { - ast::Variable* var = stmt->variable(); + ast::Variable* var = stmt->variable; Mark(var); - if (!ValidateNoDuplicateDefinition(var->symbol(), var->source())) { + if (!ValidateNoDuplicateDefinition(var->symbol, var->source)) { return false; } @@ -3483,15 +3478,15 @@ bool Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) { return false; } - for (auto* deco : var->decorations()) { + for (auto* deco : var->decorations) { Mark(deco); if (!deco->Is()) { - AddError("decorations are not valid on local variables", deco->source()); + AddError("decorations are not valid on local variables", deco->source); return false; } } - variable_stack_.set(var->symbol(), info); + variable_stack_.set(var->symbol, info); if (current_block_) { // Not all statements are inside a block current_block_->AddDecl(var); } @@ -3500,18 +3495,18 @@ bool Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) { return false; } - if (!var->is_const() && - IsValidationEnabled(var->decorations(), + if (!var->is_const && + IsValidationEnabled(var->decorations, ast::DisabledValidation::kIgnoreStorageClass)) { if (!info->type->UnwrapRef()->IsConstructible()) { AddError("function variable must have a constructible type", - var->type() ? var->type()->source() : var->source()); + var->type ? var->type->source : var->source); return false; } if (info->storage_class != ast::StorageClass::kFunction) { if (info->storage_class != ast::StorageClass::kNone) { AddError("function variable has a non-function storage class", - stmt->source()); + stmt->source); return false; } info->storage_class = ast::StorageClass::kFunction; @@ -3519,10 +3514,10 @@ bool Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) { } if (!ApplyStorageClassUsageToType(info->storage_class, info->type, - var->source())) { + var->source)) { AddNote("while instantiating variable " + - builder_->Symbols().NameFor(var->symbol()), - var->source()); + builder_->Symbols().NameFor(var->symbol), + var->source); return false; } @@ -3532,7 +3527,7 @@ bool Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) { sem::Type* Resolver::TypeDecl(const ast::TypeDecl* named_type) { sem::Type* result = nullptr; if (auto* alias = named_type->As()) { - result = Type(alias->type()); + result = Type(alias->type); } else if (auto* str = named_type->As()) { result = Structure(str); } else { @@ -3543,8 +3538,7 @@ sem::Type* Resolver::TypeDecl(const ast::TypeDecl* named_type) { return nullptr; } - named_type_info_.emplace(named_type->name(), - TypeDeclInfo{named_type, result}); + named_type_info_.emplace(named_type->name, TypeDeclInfo{named_type, result}); if (!ValidateTypeDecl(named_type)) { return nullptr; @@ -3555,17 +3549,17 @@ sem::Type* Resolver::TypeDecl(const ast::TypeDecl* named_type) { } bool Resolver::ValidateTypeDecl(const ast::TypeDecl* named_type) const { - auto iter = named_type_info_.find(named_type->name()); + auto iter = named_type_info_.find(named_type->name); if (iter == named_type_info_.end()) { TINT_ICE(Resolver, diagnostics_) << "ValidateTypeDecl called() before TypeDecl()"; } if (iter->second.ast != named_type) { AddError("type with the name '" + - builder_->Symbols().NameFor(named_type->name()) + + builder_->Symbols().NameFor(named_type->name) + "' was already declared", - named_type->source()); - AddNote("first declared here", iter->second.ast->source()); + named_type->source); + AddNote("first declared here", iter->second.ast->source); return false; } return true; @@ -3624,7 +3618,7 @@ void Resolver::SetExprInfo(const ast::Expression* expr, bool Resolver::ValidatePipelineStages() { auto check_workgroup_storage = [&](FunctionInfo* func, FunctionInfo* entry_point) { - auto stage = entry_point->declaration->pipeline_stage(); + auto stage = entry_point->declaration->PipelineStage(); if (stage != ast::PipelineStage::kCompute) { for (auto* var : func->local_referenced_module_vars) { if (var->storage_class == ast::StorageClass::kWorkgroup) { @@ -3633,29 +3627,28 @@ bool Resolver::ValidatePipelineStages() { for (auto* user : var->users) { auto it = expr_info_.find(user->As()); if (it != expr_info_.end()) { - if (func->declaration->symbol() == - it->second.statement->Function()->symbol()) { + if (func->declaration->symbol == + it->second.statement->Function()->symbol) { AddError("workgroup memory cannot be used by " + stage_name.str() + " pipeline stage", - user->source()); + user->source); break; } } } - AddNote("variable is declared here", var->declaration->source()); + AddNote("variable is declared here", var->declaration->source); if (func != entry_point) { TraverseCallChain(entry_point, func, [&](FunctionInfo* f) { - AddNote( - "called by function '" + - builder_->Symbols().NameFor(f->declaration->symbol()) + - "'", - f->declaration->source()); + AddNote("called by function '" + + builder_->Symbols().NameFor(f->declaration->symbol) + + "'", + f->declaration->source); }); AddNote("called by entry point '" + builder_->Symbols().NameFor( - entry_point->declaration->symbol()) + + entry_point->declaration->symbol) + "'", - entry_point->declaration->source()); + entry_point->declaration->source); } return false; } @@ -3677,24 +3670,24 @@ bool Resolver::ValidatePipelineStages() { auto check_intrinsic_calls = [&](FunctionInfo* func, FunctionInfo* entry_point) { - auto stage = entry_point->declaration->pipeline_stage(); + auto stage = entry_point->declaration->PipelineStage(); for (auto& call : func->intrinsic_calls) { if (!call.intrinsic->SupportedStages().Contains(stage)) { std::stringstream err; err << "built-in cannot be used by " << stage << " pipeline stage"; - AddError(err.str(), call.call->source()); + AddError(err.str(), call.call->source); if (func != entry_point) { TraverseCallChain(entry_point, func, [&](FunctionInfo* f) { AddNote("called by function '" + - builder_->Symbols().NameFor(f->declaration->symbol()) + + builder_->Symbols().NameFor(f->declaration->symbol) + "'", - f->declaration->source()); + f->declaration->source); }); AddNote("called by entry point '" + builder_->Symbols().NameFor( - entry_point->declaration->symbol()) + + entry_point->declaration->symbol) + "'", - entry_point->declaration->source()); + entry_point->declaration->source); } return false; } @@ -3742,8 +3735,8 @@ void Resolver::CreateSemanticNodes() const { std::unordered_map> ancestor_entry_points; for (auto* entry_point : entry_points_) { for (auto* call : entry_point->transitive_calls) { - auto& vec = ancestor_entry_points[call->declaration->symbol()]; - vec.emplace_back(entry_point->declaration->symbol()); + auto& vec = ancestor_entry_points[call->declaration->symbol]; + vec.emplace_back(entry_point->declaration->symbol); } } @@ -3755,7 +3748,7 @@ void Resolver::CreateSemanticNodes() const { sem::Variable* sem_var = nullptr; - if (ast::HasDecoration(var->decorations())) { + if (ast::HasDecoration(var->decorations)) { // Create a pipeline overridable constant. sem_var = builder_->create(var, info->type, info->constant_id); @@ -3829,7 +3822,7 @@ void Resolver::CreateSemanticNodes() const { info->declaration, const_cast(info->return_type), parameters, remap_vars(info->referenced_module_vars), remap_vars(info->local_referenced_module_vars), info->return_statements, - info->callsites, ancestor_entry_points[func->symbol()], + info->callsites, ancestor_entry_points[func->symbol], info->workgroup_size); func_info_to_sem_func.emplace(info, sem_func); sem.Add(func, sem_func); @@ -3858,9 +3851,9 @@ void Resolver::CreateSemanticNodes() const { } sem::Array* Resolver::Array(const ast::Array* arr) { - auto source = arr->source(); + auto source = arr->source; - auto* elem_type = Type(arr->type()); + auto* elem_type = Type(arr->type); if (!elem_type) { return nullptr; } @@ -3875,23 +3868,23 @@ sem::Array* Resolver::Array(const ast::Array* arr) { uint32_t el_align = elem_type->Align(); uint32_t el_size = elem_type->Size(); - if (!ValidateNoDuplicateDecorations(arr->decorations())) { + if (!ValidateNoDuplicateDecorations(arr->decorations)) { return nullptr; } // Look for explicit stride via [[stride(n)]] decoration uint32_t explicit_stride = 0; - for (auto* deco : arr->decorations()) { + for (auto* deco : arr->decorations) { Mark(deco); if (auto* sd = deco->As()) { - explicit_stride = sd->stride(); + explicit_stride = sd->stride; if (!ValidateArrayStrideDecoration(sd, el_size, el_align, source)) { return nullptr; } continue; } - AddError("decoration is not valid for array types", deco->source()); + AddError("decoration is not valid for array types", deco->source); return nullptr; } @@ -3903,13 +3896,13 @@ sem::Array* Resolver::Array(const ast::Array* arr) { // Evaluate the constant array size expression. // sem::Array uses a size of 0 for a runtime-sized array. uint32_t count = 0; - if (auto* count_expr = arr->Size()) { + if (auto* count_expr = arr->count) { Mark(count_expr); if (!Expression(count_expr)) { return nullptr; } - auto size_source = count_expr->source(); + auto size_source = count_expr->source; auto* ty = TypeOf(count_expr)->UnwrapRef(); if (!ty->is_integer_scalar()) { @@ -3921,20 +3914,20 @@ sem::Array* Resolver::Array(const ast::Array* arr) { // Make sure the identifier is a non-overridable module-scope constant. VariableInfo* var = nullptr; bool is_global = false; - if (!variable_stack_.get(ident->symbol(), &var, &is_global) || - !is_global || !var->declaration->is_const()) { + if (!variable_stack_.get(ident->symbol, &var, &is_global) || !is_global || + !var->declaration->is_const) { AddError("array size identifier must be a module-scope constant", size_source); return nullptr; } if (ast::HasDecoration( - var->declaration->decorations())) { + var->declaration->decorations)) { AddError("array size expression must not be pipeline-overridable", size_source); return nullptr; } - count_expr = var->declaration->constructor(); + count_expr = var->declaration->constructor; } else if (!count_expr->Is()) { AddError( "array size expression must be either a literal or a module-scope " @@ -3965,7 +3958,7 @@ sem::Array* Resolver::Array(const ast::Array* arr) { msg << "array size in bytes must not exceed 0x" << std::hex << std::numeric_limits::max() << ", but is 0x" << std::hex << size; - AddError(msg.str(), arr->source()); + AddError(msg.str(), arr->source); return nullptr; } if (stride > std::numeric_limits::max() || @@ -3983,7 +3976,7 @@ sem::Array* Resolver::Array(const ast::Array* arr) { } if (elem_type->Is()) { - atomic_composite_info_.emplace(out, arr->type()->source()); + atomic_composite_info_.emplace(out, arr->type->source); } else { auto found = atomic_composite_info_.find(elem_type); if (found != atomic_composite_info_.end()) { @@ -4017,7 +4010,7 @@ bool Resolver::ValidateArrayStrideDecoration(const ast::StrideDecoration* deco, uint32_t el_size, uint32_t el_align, const Source& source) { - auto stride = deco->stride(); + auto stride = deco->stride; bool is_valid_stride = (stride >= el_size) && (stride >= el_align) && (stride % el_align == 0); if (!is_valid_stride) { @@ -4038,7 +4031,7 @@ bool Resolver::ValidateArrayStrideDecoration(const ast::StrideDecoration* deco, bool Resolver::ValidateStructure(const sem::Struct* str) { if (str->Members().empty()) { AddError("structures must have at least one member", - str->Declaration()->source()); + str->Declaration()->source); return false; } @@ -4049,15 +4042,15 @@ bool Resolver::ValidateStructure(const sem::Struct* str) { if (member != str->Members().back()) { AddError( "runtime arrays may only appear as the last member of a struct", - member->Declaration()->source()); + member->Declaration()->source); return false; } if (!str->IsBlockDecorated()) { AddError( "a struct containing a runtime-sized array " "requires the [[block]] attribute: '" + - builder_->Symbols().NameFor(str->Declaration()->name()) + "'", - member->Declaration()->source()); + builder_->Symbols().NameFor(str->Declaration()->name) + "'", + member->Declaration()->source); return false; } } @@ -4065,7 +4058,7 @@ bool Resolver::ValidateStructure(const sem::Struct* str) { auto has_position = false; ast::InvariantDecoration* invariant_attribute = nullptr; - for (auto* deco : member->Declaration()->decorations()) { + for (auto* deco : member->Declaration()->decorations) { if (!deco->IsAnyOf()) { if (deco->Is() && IsValidationDisabled( - member->Declaration()->decorations(), + member->Declaration()->decorations, ast::DisabledValidation::kIgnoreStrideDecoration)) { continue; } - AddError("decoration is not valid for structure members", - deco->source()); + AddError("decoration is not valid for structure members", deco->source); return false; } @@ -4089,7 +4081,7 @@ bool Resolver::ValidateStructure(const sem::Struct* str) { invariant_attribute = invariant; } else if (auto* location = deco->As()) { if (!ValidateLocationDecoration(location, member->Type(), locations, - member->Declaration()->source())) { + member->Declaration()->source)) { return false; } } else if (auto* builtin = deco->As()) { @@ -4097,7 +4089,7 @@ bool Resolver::ValidateStructure(const sem::Struct* str) { /* is_input */ false)) { return false; } - if (builtin->value() == ast::Builtin::kPosition) { + if (builtin->builtin == ast::Builtin::kPosition) { has_position = true; } } else if (auto* interpolate = deco->As()) { @@ -4109,27 +4101,26 @@ bool Resolver::ValidateStructure(const sem::Struct* str) { if (invariant_attribute && !has_position) { AddError("invariant attribute must only be applied to a position builtin", - invariant_attribute->source()); + invariant_attribute->source); return false; } if (auto* member_struct_type = member->Type()->As()) { if (auto* member_struct_type_block_decoration = ast::GetDecoration( - member_struct_type->Declaration()->decorations())) { + member_struct_type->Declaration()->decorations)) { AddError("structs must not contain [[block]] decorated struct members", - member->Declaration()->source()); + member->Declaration()->source); AddNote("see member's struct decoration here", - member_struct_type_block_decoration->source()); + member_struct_type_block_decoration->source); return false; } } } - for (auto* deco : str->Declaration()->decorations()) { + for (auto* deco : str->Declaration()->decorations) { if (!(deco->Is())) { - AddError("decoration is not valid for struct declarations", - deco->source()); + AddError("decoration is not valid for struct declarations", deco->source); return false; } } @@ -4144,10 +4135,10 @@ bool Resolver::ValidateLocationDecoration( const Source& source, const bool is_input) { std::string inputs_or_output = is_input ? "inputs" : "output"; - if (current_function_ && current_function_->declaration->pipeline_stage() == + if (current_function_ && current_function_->declaration->PipelineStage() == ast::PipelineStage::kCompute) { AddError("decoration is not valid for compute shader " + inputs_or_output, - location->source()); + location->source); return false; } @@ -4159,30 +4150,30 @@ bool Resolver::ValidateLocationDecoration( AddNote( "'location' attribute must only be applied to declarations of " "numeric scalar or numeric vector type", - location->source()); + location->source); return false; } - if (locations.count(location->value())) { + if (locations.count(location->value)) { AddError(deco_to_str(location) + " attribute appears multiple times", - location->source()); + location->source); return false; } - locations.emplace(location->value()); + locations.emplace(location->value); return true; } sem::Struct* Resolver::Structure(const ast::Struct* str) { - if (!ValidateNoDuplicateDecorations(str->decorations())) { + if (!ValidateNoDuplicateDecorations(str->decorations)) { return nullptr; } - for (auto* deco : str->decorations()) { + for (auto* deco : str->decorations) { Mark(deco); } sem::StructMemberList sem_members; - sem_members.reserve(str->members().size()); + sem_members.reserve(str->members.size()); // Calculate the effective size and alignment of each field, and the overall // size of the structure. @@ -4198,19 +4189,19 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) { uint64_t struct_align = 1; std::unordered_map member_map; - for (auto* member : str->members()) { + for (auto* member : str->members) { Mark(member); - auto result = member_map.emplace(member->symbol(), member); + auto result = member_map.emplace(member->symbol, member); if (!result.second) { AddError("redefinition of '" + - builder_->Symbols().NameFor(member->symbol()) + "'", - member->source()); - AddNote("previous definition is here", result.first->second->source()); + builder_->Symbols().NameFor(member->symbol) + "'", + member->source); + AddNote("previous definition is here", result.first->second->source); return nullptr; } // Resolve member type - auto* type = Type(member->type()); + auto* type = Type(member->type); if (!type) { return nullptr; } @@ -4219,7 +4210,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) { if (!IsPlain(type)) { AddError(type->FriendlyName(builder_->Symbols()) + " cannot be used as the type of a structure member", - member->source()); + member->source); return nullptr; } @@ -4227,41 +4218,41 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) { uint64_t align = type->Align(); uint64_t size = type->Size(); - if (!ValidateNoDuplicateDecorations(member->decorations())) { + if (!ValidateNoDuplicateDecorations(member->decorations)) { return nullptr; } bool has_offset_deco = false; bool has_align_deco = false; bool has_size_deco = false; - for (auto* deco : member->decorations()) { + for (auto* deco : member->decorations) { Mark(deco); if (auto* o = deco->As()) { // Offset decorations are not part of the WGSL spec, but are emitted // by the SPIR-V reader. - if (o->offset() < struct_size) { - AddError("offsets must be in ascending order", o->source()); + if (o->offset < struct_size) { + AddError("offsets must be in ascending order", o->source); return nullptr; } - offset = o->offset(); + offset = o->offset; align = 1; has_offset_deco = true; } else if (auto* a = deco->As()) { - if (a->align() <= 0 || !utils::IsPowerOfTwo(a->align())) { + if (a->align <= 0 || !utils::IsPowerOfTwo(a->align)) { AddError("align value must be a positive, power-of-two integer", - a->source()); + a->source); return nullptr; } - align = a->align(); + align = a->align; has_align_deco = true; } else if (auto* s = deco->As()) { - if (s->size() < size) { + if (s->size < size) { AddError("size must be at least as big as the type's size (" + std::to_string(size) + ")", - s->source()); + s->source); return nullptr; } - size = s->size(); + size = s->size; has_size_deco = true; } } @@ -4269,7 +4260,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) { if (has_offset_deco && (has_align_deco || has_size_deco)) { AddError( "offset decorations cannot be used with align or size decorations", - member->source()); + member->source); return nullptr; } @@ -4279,12 +4270,12 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) { msg << "struct member has byte offset 0x" << std::hex << offset << ", but must not exceed 0x" << std::hex << std::numeric_limits::max(); - AddError(msg.str(), member->source()); + AddError(msg.str(), member->source); return nullptr; } auto* sem_member = builder_->create( - member, member->symbol(), const_cast(type), + member, member->symbol, const_cast(type), static_cast(sem_members.size()), static_cast(offset), static_cast(align), static_cast(size)); @@ -4303,7 +4294,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) { msg << "struct size in bytes must not exceed 0x" << std::hex << std::numeric_limits::max() << ", but is 0x" << std::hex << struct_size; - AddError(msg.str(), str->source()); + AddError(msg.str(), str->source); return nullptr; } if (struct_align > std::numeric_limits::max()) { @@ -4313,7 +4304,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) { } auto* out = builder_->create( - str, str->name(), sem_members, static_cast(struct_align), + str, str->name, sem_members, static_cast(struct_align), static_cast(struct_size), static_cast(size_no_padding)); @@ -4321,7 +4312,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) { auto* mem_type = sem_members[i]->Type(); if (mem_type->Is()) { atomic_composite_info_.emplace(out, - sem_members[i]->Declaration()->source()); + sem_members[i]->Declaration()->source); break; } else { auto found = atomic_composite_info_.find(mem_type); @@ -4342,8 +4333,8 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) { bool Resolver::ValidateReturn(const ast::ReturnStatement* ret) { auto* func_type = current_function_->return_type; - auto* ret_type = ret->has_value() ? TypeOf(ret->value())->UnwrapRef() - : builder_->create(); + auto* ret_type = ret->value ? TypeOf(ret->value)->UnwrapRef() + : builder_->create(); if (func_type->UnwrapRef() != ret_type) { AddError( @@ -4351,7 +4342,7 @@ bool Resolver::ValidateReturn(const ast::ReturnStatement* ret) { "return type, returned '" + ret_type->FriendlyName(builder_->Symbols()) + "', expected '" + current_function_->return_type_name + "'", - ret->source()); + ret->source); return false; } @@ -4359,9 +4350,9 @@ bool Resolver::ValidateReturn(const ast::ReturnStatement* ret) { if (auto* continuing = sem->FindFirstParent()) { AddError("continuing blocks must not contain a return statement", - ret->source()); + ret->source); if (continuing != sem->Parent()) { - AddNote("see continuing block here", continuing->Declaration()->source()); + AddNote("see continuing block here", continuing->Declaration()->source); } return false; } @@ -4372,7 +4363,7 @@ bool Resolver::ValidateReturn(const ast::ReturnStatement* ret) { bool Resolver::Return(ast::ReturnStatement* ret) { current_function_->return_statements.push_back(ret); - if (auto* value = ret->value()) { + if (auto* value = ret->value) { Mark(value); if (!Expression(value)) { return false; @@ -4385,66 +4376,66 @@ bool Resolver::Return(ast::ReturnStatement* ret) { } bool Resolver::ValidateSwitch(const ast::SwitchStatement* s) { - auto* cond_type = TypeOf(s->condition())->UnwrapRef(); + auto* cond_type = TypeOf(s->condition)->UnwrapRef(); if (!cond_type->is_integer_scalar()) { AddError( "switch statement selector expression must be of a " "scalar integer type", - s->condition()->source()); + s->condition->source); return false; } bool has_default = false; std::unordered_map selectors; - for (auto* case_stmt : s->body()) { + for (auto* case_stmt : s->body) { if (case_stmt->IsDefault()) { if (has_default) { // More than one default clause AddError("switch statement must have exactly one default clause", - case_stmt->source()); + case_stmt->source); return false; } has_default = true; } - for (auto* selector : case_stmt->selectors()) { + for (auto* selector : case_stmt->selectors) { if (cond_type != TypeOf(selector)) { AddError( "the case selector values must have the same " "type as the selector expression.", - case_stmt->source()); + case_stmt->source); return false; } - auto v = selector->value_as_u32(); + auto v = selector->ValueAsU32(); auto it = selectors.find(v); if (it != selectors.end()) { auto val = selector->Is() - ? std::to_string(selector->value_as_i32()) - : std::to_string(selector->value_as_u32()); - AddError("duplicate switch case '" + val + "'", selector->source()); + ? std::to_string(selector->ValueAsI32()) + : std::to_string(selector->ValueAsU32()); + AddError("duplicate switch case '" + val + "'", selector->source); AddNote("previous case declared here", it->second); return false; } - selectors.emplace(v, selector->source()); + selectors.emplace(v, selector->source); } } if (!has_default) { // No default clause - AddError("switch statement must have a default clause", s->source()); + AddError("switch statement must have a default clause", s->source); return false; } - if (!s->body().empty()) { - auto* last_clause = s->body().back()->As(); - auto* last_stmt = last_clause->body()->last(); + if (!s->body.empty()) { + auto* last_clause = s->body.back()->As(); + auto* last_stmt = last_clause->body->Last(); if (last_stmt && last_stmt->Is()) { AddError( "a fallthrough statement must not appear as " "the last statement in last clause of a switch", - last_stmt->source()); + last_stmt->source); return false; } } @@ -4457,11 +4448,11 @@ bool Resolver::SwitchStatement(ast::SwitchStatement* stmt) { builder_->create(stmt, current_compound_statement_); builder_->Sem().Add(stmt, sem); return Scope(sem, [&] { - Mark(stmt->condition()); - if (!Expression(stmt->condition())) { + Mark(stmt->condition); + if (!Expression(stmt->condition)) { return false; } - for (auto* case_stmt : stmt->body()) { + for (auto* case_stmt : stmt->body) { Mark(case_stmt); if (!CaseStatement(case_stmt)) { return false; @@ -4475,10 +4466,10 @@ bool Resolver::SwitchStatement(ast::SwitchStatement* stmt) { } bool Resolver::Assignment(ast::AssignmentStatement* a) { - Mark(a->lhs()); - Mark(a->rhs()); + Mark(a->lhs); + Mark(a->rhs); - if (!Expression(a->lhs()) || !Expression(a->rhs())) { + if (!Expression(a->lhs) || !Expression(a->rhs)) { return false; } return ValidateAssignment(a); @@ -4486,24 +4477,24 @@ bool Resolver::Assignment(ast::AssignmentStatement* a) { bool Resolver::ValidateAssignment(const ast::AssignmentStatement* a) { // https://gpuweb.github.io/gpuweb/wgsl/#assignment-statement - auto const* lhs_type = TypeOf(a->lhs()); - auto const* rhs_type = TypeOf(a->rhs()); + auto const* lhs_type = TypeOf(a->lhs); + auto const* rhs_type = TypeOf(a->rhs); - if (auto* ident = a->lhs()->As()) { + if (auto* ident = a->lhs->As()) { VariableInfo* var; - if (variable_stack_.get(ident->symbol(), &var)) { + if (variable_stack_.get(ident->symbol, &var)) { if (var->kind == VariableKind::kParameter) { - AddError("cannot assign to function parameter", a->lhs()->source()); - AddNote("'" + builder_->Symbols().NameFor(ident->symbol()) + + AddError("cannot assign to function parameter", a->lhs->source); + AddNote("'" + builder_->Symbols().NameFor(ident->symbol) + "' is declared here:", - var->declaration->source()); + var->declaration->source); return false; } - if (var->declaration->is_const()) { - AddError("cannot assign to const", a->lhs()->source()); - AddNote("'" + builder_->Symbols().NameFor(ident->symbol()) + + if (var->declaration->is_const) { + AddError("cannot assign to const", a->lhs->source); + AddNote("'" + builder_->Symbols().NameFor(ident->symbol) + "' is declared here:", - var->declaration->source()); + var->declaration->source); return false; } } @@ -4512,8 +4503,8 @@ bool Resolver::ValidateAssignment(const ast::AssignmentStatement* a) { auto* lhs_ref = lhs_type->As(); if (!lhs_ref) { // LHS is not a reference, so it has no storage. - AddError("cannot assign to value of type '" + TypeNameOf(a->lhs()) + "'", - a->lhs()->source()); + AddError("cannot assign to value of type '" + TypeNameOf(a->lhs) + "'", + a->lhs->source); return false; } @@ -4522,19 +4513,18 @@ bool Resolver::ValidateAssignment(const ast::AssignmentStatement* a) { // Value type has to match storage type if (storage_type != value_type) { - AddError("cannot assign '" + TypeNameOf(a->rhs()) + "' to '" + - TypeNameOf(a->lhs()) + "'", - a->source()); + AddError("cannot assign '" + TypeNameOf(a->rhs) + "' to '" + + TypeNameOf(a->lhs) + "'", + a->source); return false; } if (!storage_type->IsConstructible()) { - AddError("storage type of assignment must be constructible", a->source()); + AddError("storage type of assignment must be constructible", a->source); return false; } if (lhs_ref->Access() == ast::Access::kRead) { - AddError( - "cannot store into a read-only type '" + TypeNameOf(a->lhs()) + "'", - a->source()); + AddError("cannot store into a read-only type '" + TypeNameOf(a->lhs) + "'", + a->source); return false; } return true; @@ -4550,7 +4540,7 @@ bool Resolver::ValidateNoDuplicateDefinition(Symbol sym, if (is_global) { AddError("redefinition of '" + builder_->Symbols().NameFor(sym) + "'", source); - AddNote("previous definition is here", var->declaration->source()); + AddNote("previous definition is here", var->declaration->source); return false; } } @@ -4558,7 +4548,7 @@ bool Resolver::ValidateNoDuplicateDefinition(Symbol sym, if (it != symbol_to_function_.end()) { AddError("redefinition of '" + builder_->Symbols().NameFor(sym) + "'", source); - AddNote("previous definition is here", it->second->declaration->source()); + AddNote("previous definition is here", it->second->declaration->source); return false; } } else { @@ -4566,7 +4556,7 @@ bool Resolver::ValidateNoDuplicateDefinition(Symbol sym, if (variable_stack_.get(sym, &var)) { AddError("redefinition of '" + builder_->Symbols().NameFor(sym) + "'", source); - AddNote("previous definition is here", var->declaration->source()); + AddNote("previous definition is here", var->declaration->source); return false; } } @@ -4577,9 +4567,9 @@ bool Resolver::ValidateNoDuplicateDecorations( const ast::DecorationList& decorations) { std::unordered_map seen; for (auto* d : decorations) { - auto res = seen.emplace(&d->TypeInfo(), d->source()); + auto res = seen.emplace(&d->TypeInfo(), d->source); if (!res.second && !d->Is()) { - AddError("duplicate " + d->name() + " decoration", d->source()); + AddError("duplicate " + d->Name() + " decoration", d->source); AddNote("first decoration declared here", res.first->second); return false; } @@ -4604,8 +4594,8 @@ bool Resolver::ApplyStorageClassUsageToType(ast::StorageClass sc, std::stringstream err; err << "while analysing structure member " << str->FriendlyName(builder_->Symbols()) << "." - << builder_->Symbols().NameFor(member->Declaration()->symbol()); - AddNote(err.str(), member->Declaration()->source()); + << builder_->Symbols().NameFor(member->Declaration()->symbol); + AddNote(err.str(), member->Declaration()->source); return false; } } @@ -4665,7 +4655,7 @@ void Resolver::Mark(const ast::Node* node) { TINT_ICE(Resolver, diagnostics_) << "AST node '" << node->TypeInfo().name << "' was encountered twice in the same AST of a Program\n" - << "At: " << node->source() << "\n" + << "At: " << node->source << "\n" << "Pointer: " << node; } diff --git a/src/resolver/resolver_constants.cc b/src/resolver/resolver_constants.cc index dc453cc1b5..e28ed038d9 100644 --- a/src/resolver/resolver_constants.cc +++ b/src/resolver/resolver_constants.cc @@ -80,18 +80,18 @@ sem::Constant Resolver::EvaluateConstantValue(const ast::Expression* expr, sem::Constant Resolver::EvaluateConstantValue( const ast::ScalarConstructorExpression* scalar_ctor, const sem::Type* type) { - auto* literal = scalar_ctor->literal(); + auto* literal = scalar_ctor->literal; if (auto* lit = literal->As()) { - return {type, {lit->value_as_i32()}}; + return {type, {lit->ValueAsI32()}}; } if (auto* lit = literal->As()) { - return {type, {lit->value_as_u32()}}; + return {type, {lit->ValueAsU32()}}; } if (auto* lit = literal->As()) { - return {type, {lit->value()}}; + return {type, {lit->value}}; } if (auto* lit = literal->As()) { - return {type, {lit->IsTrue()}}; + return {type, {lit->value}}; } TINT_UNREACHABLE(Resolver, builder_->Diagnostics()); return {}; @@ -100,7 +100,7 @@ sem::Constant Resolver::EvaluateConstantValue( sem::Constant Resolver::EvaluateConstantValue( const ast::TypeConstructorExpression* type_ctor, const sem::Type* type) { - auto& ctor_values = type_ctor->values(); + auto& ctor_values = type_ctor->values; auto* vec = type->As(); // For now, only fold scalars and vectors diff --git a/src/resolver/resolver_test.cc b/src/resolver/resolver_test.cc index 024d07dba6..776cf4c15a 100644 --- a/src/resolver/resolver_test.cc +++ b/src/resolver/resolver_test.cc @@ -175,12 +175,12 @@ TEST_F(ResolverTest, Stmt_If) { EXPECT_TRUE(r()->Resolve()) << r()->error(); - ASSERT_NE(TypeOf(stmt->condition()), nullptr); + ASSERT_NE(TypeOf(stmt->condition), nullptr); ASSERT_NE(TypeOf(else_lhs), nullptr); ASSERT_NE(TypeOf(else_rhs), nullptr); ASSERT_NE(TypeOf(lhs), nullptr); ASSERT_NE(TypeOf(rhs), nullptr); - EXPECT_TRUE(TypeOf(stmt->condition())->Is()); + EXPECT_TRUE(TypeOf(stmt->condition)->Is()); EXPECT_TRUE(TypeOf(else_lhs)->UnwrapRef()->Is()); EXPECT_TRUE(TypeOf(else_rhs)->Is()); EXPECT_TRUE(TypeOf(lhs)->UnwrapRef()->Is()); @@ -253,11 +253,11 @@ TEST_F(ResolverTest, Stmt_Switch) { EXPECT_TRUE(r()->Resolve()) << r()->error(); - ASSERT_NE(TypeOf(stmt->condition()), nullptr); + ASSERT_NE(TypeOf(stmt->condition), nullptr); ASSERT_NE(TypeOf(lhs), nullptr); ASSERT_NE(TypeOf(rhs), nullptr); - EXPECT_TRUE(TypeOf(stmt->condition())->Is()); + EXPECT_TRUE(TypeOf(stmt->condition)->Is()); EXPECT_TRUE(TypeOf(lhs)->UnwrapRef()->Is()); EXPECT_TRUE(TypeOf(rhs)->Is()); EXPECT_EQ(BlockOf(lhs), case_block); @@ -282,7 +282,7 @@ TEST_F(ResolverTest, Stmt_Call) { TEST_F(ResolverTest, Stmt_VariableDecl) { auto* var = Var("my_var", ty.i32(), ast::StorageClass::kNone, Expr(2)); - auto* init = var->constructor(); + auto* init = var->constructor; auto* decl = Decl(var); WrapInFunction(decl); @@ -296,7 +296,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl) { TEST_F(ResolverTest, Stmt_VariableDecl_Alias) { auto* my_int = Alias("MyInt", ty.i32()); auto* var = Var("my_var", ty.Of(my_int), ast::StorageClass::kNone, Expr(2)); - auto* init = var->constructor(); + auto* init = var->constructor; auto* decl = Decl(var); WrapInFunction(decl); @@ -343,24 +343,24 @@ TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) { // Declare i32 "foo" inside a block auto* foo_i32 = Var("foo", ty.i32(), ast::StorageClass::kNone, Expr(2)); - auto* foo_i32_init = foo_i32->constructor(); + auto* foo_i32_init = foo_i32->constructor; auto* foo_i32_decl = Decl(foo_i32); // Reference "foo" inside the block auto* bar_i32 = Var("bar", ty.i32(), ast::StorageClass::kNone, Expr("foo")); - auto* bar_i32_init = bar_i32->constructor(); + auto* bar_i32_init = bar_i32->constructor; auto* bar_i32_decl = Decl(bar_i32); auto* inner = Block(foo_i32_decl, bar_i32_decl); // Declare f32 "foo" at function scope auto* foo_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f)); - auto* foo_f32_init = foo_f32->constructor(); + auto* foo_f32_init = foo_f32->constructor; auto* foo_f32_decl = Decl(foo_f32); // Reference "foo" at function scope auto* bar_f32 = Var("bar", ty.f32(), ast::StorageClass::kNone, Expr("foo")); - auto* bar_f32_init = bar_f32->constructor(); + auto* bar_f32_init = bar_f32->constructor; auto* bar_f32_decl = Decl(bar_f32); Func("func", params, ty.void_(), {inner, foo_f32_decl, bar_f32_decl}, @@ -379,12 +379,12 @@ TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) { EXPECT_EQ(StmtOf(bar_i32_init), bar_i32_decl); EXPECT_EQ(StmtOf(foo_f32_init), foo_f32_decl); EXPECT_EQ(StmtOf(bar_f32_init), bar_f32_decl); - EXPECT_TRUE(CheckVarUsers(foo_i32, {bar_i32->constructor()})); - EXPECT_TRUE(CheckVarUsers(foo_f32, {bar_f32->constructor()})); - ASSERT_NE(VarOf(bar_i32->constructor()), nullptr); - EXPECT_EQ(VarOf(bar_i32->constructor())->Declaration(), foo_i32); - ASSERT_NE(VarOf(bar_f32->constructor()), nullptr); - EXPECT_EQ(VarOf(bar_f32->constructor())->Declaration(), foo_f32); + EXPECT_TRUE(CheckVarUsers(foo_i32, {bar_i32->constructor})); + EXPECT_TRUE(CheckVarUsers(foo_f32, {bar_f32->constructor})); + ASSERT_NE(VarOf(bar_i32->constructor), nullptr); + EXPECT_EQ(VarOf(bar_i32->constructor)->Declaration(), foo_i32); + ASSERT_NE(VarOf(bar_f32->constructor), nullptr); + EXPECT_EQ(VarOf(bar_f32->constructor)->Declaration(), foo_f32); } TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) { @@ -400,18 +400,18 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) { // Declare i32 "foo" inside a function auto* fn_i32 = Var("foo", ty.i32(), ast::StorageClass::kNone, Expr(2)); - auto* fn_i32_init = fn_i32->constructor(); + auto* fn_i32_init = fn_i32->constructor; auto* fn_i32_decl = Decl(fn_i32); Func("func_i32", params, ty.void_(), {fn_i32_decl}, ast::DecorationList{}); // Declare f32 "foo" at module scope auto* mod_f32 = Var("foo", ty.f32(), ast::StorageClass::kPrivate, Expr(2.f)); - auto* mod_init = mod_f32->constructor(); + auto* mod_init = mod_f32->constructor; AST().AddGlobalVariable(mod_f32); // Reference "foo" in another function auto* fn_f32 = Var("bar", ty.f32(), ast::StorageClass::kNone, Expr("foo")); - auto* fn_f32_init = fn_f32->constructor(); + auto* fn_f32_init = fn_f32->constructor; auto* fn_f32_decl = Decl(fn_f32); Func("func_f32", params, ty.void_(), {fn_f32_decl}, ast::DecorationList{}); @@ -426,9 +426,9 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) { EXPECT_EQ(StmtOf(mod_init), nullptr); EXPECT_EQ(StmtOf(fn_f32_init), fn_f32_decl); EXPECT_TRUE(CheckVarUsers(fn_i32, {})); - EXPECT_TRUE(CheckVarUsers(mod_f32, {fn_f32->constructor()})); - ASSERT_NE(VarOf(fn_f32->constructor()), nullptr); - EXPECT_EQ(VarOf(fn_f32->constructor())->Declaration(), mod_f32); + EXPECT_TRUE(CheckVarUsers(mod_f32, {fn_f32->constructor})); + ASSERT_NE(VarOf(fn_f32->constructor), nullptr); + EXPECT_EQ(VarOf(fn_f32->constructor)->Declaration(), mod_f32); } TEST_F(ResolverTest, ArraySize_UnsignedLiteral) { @@ -1115,7 +1115,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct) { ASSERT_NE(sma, nullptr); EXPECT_TRUE(sma->Member()->Type()->Is()); EXPECT_EQ(sma->Member()->Index(), 1u); - EXPECT_EQ(sma->Member()->Declaration()->symbol(), + EXPECT_EQ(sma->Member()->Declaration()->symbol, Symbols().Get("second_member")); } @@ -1623,7 +1623,7 @@ TEST_P(Expr_Binary_Test_Invalid, All) { ASSERT_EQ(r()->error(), "12:34 error: Binary expression operand types are invalid for " "this operation: " + - FriendlyName(lhs_type) + " " + ast::FriendlyName(expr->op()) + + FriendlyName(lhs_type) + " " + ast::FriendlyName(expr->op) + " " + FriendlyName(rhs_type)); } INSTANTIATE_TEST_SUITE_P( @@ -1672,7 +1672,7 @@ TEST_P(Expr_Binary_Test_Invalid_VectorMatrixMultiply, All) { ASSERT_EQ(r()->error(), "12:34 error: Binary expression operand types are invalid for " "this operation: " + - FriendlyName(lhs_type) + " " + ast::FriendlyName(expr->op()) + + FriendlyName(lhs_type) + " " + ast::FriendlyName(expr->op) + " " + FriendlyName(rhs_type)); } } @@ -1714,7 +1714,7 @@ TEST_P(Expr_Binary_Test_Invalid_MatrixMatrixMultiply, All) { ASSERT_EQ(r()->error(), "12:34 error: Binary expression operand types are invalid for " "this operation: " + - FriendlyName(lhs_type) + " " + ast::FriendlyName(expr->op()) + + FriendlyName(lhs_type) + " " + ast::FriendlyName(expr->op) + " " + FriendlyName(rhs_type)); } } diff --git a/src/resolver/validation_test.cc b/src/resolver/validation_test.cc index 8a1511f5cc..3871e59614 100644 --- a/src/resolver/validation_test.cc +++ b/src/resolver/validation_test.cc @@ -49,13 +49,13 @@ using ResolverValidationTest = ResolverTest; class FakeStmt : public Castable { public: - FakeStmt(ProgramID program_id, Source source) : Base(program_id, source) {} + FakeStmt(ProgramID pid, Source src) : Base(pid, src) {} FakeStmt* Clone(CloneContext*) const override { return nullptr; } }; class FakeExpr : public Castable { public: - FakeExpr(ProgramID program_id, Source source) : Base(program_id, source) {} + FakeExpr(ProgramID pid, Source src) : Base(pid, src) {} FakeExpr* Clone(CloneContext*) const override { return nullptr; } }; diff --git a/src/scope_stack_test.cc b/src/scope_stack_test.cc index 85bd86ba6d..9c6c0a54c4 100644 --- a/src/scope_stack_test.cc +++ b/src/scope_stack_test.cc @@ -34,11 +34,11 @@ TEST_F(ScopeStackTest, Global) { TEST_F(ScopeStackTest, Global_SetWithPointer) { auto* v = Var("my_var", ty.f32(), ast::StorageClass::kNone); ScopeStack s; - s.set_global(v->symbol(), v); + s.set_global(v->symbol, v); ast::Variable* v2 = nullptr; - EXPECT_TRUE(s.get(v->symbol(), &v2)); - EXPECT_EQ(v2->symbol(), v->symbol()); + EXPECT_TRUE(s.get(v->symbol, &v2)); + EXPECT_EQ(v2->symbol, v->symbol); } TEST_F(ScopeStackTest, Global_CanNotPop) { diff --git a/src/sem/block_statement.cc b/src/sem/block_statement.cc index 70cdd0b79f..8022cff2f1 100644 --- a/src/sem/block_statement.cc +++ b/src/sem/block_statement.cc @@ -40,7 +40,7 @@ void BlockStatement::AddDecl(ast::Variable* var) { } FunctionBlockStatement::FunctionBlockStatement(const ast::Function* function) - : Base(function->body(), nullptr), function_(function) {} + : Base(function->body, nullptr), function_(function) {} FunctionBlockStatement::~FunctionBlockStatement() = default; diff --git a/src/sem/function.cc b/src/sem/function.cc index 4912a69fbc..0743cb4ea7 100644 --- a/src/sem/function.cc +++ b/src/sem/function.cc @@ -57,7 +57,7 @@ Function::ReferencedLocationVariables() const { std::vector> ret; for (auto* var : ReferencedModuleVariables()) { - for (auto* deco : var->Declaration()->decorations()) { + for (auto* deco : var->Declaration()->decorations) { if (auto* location = deco->As()) { ret.push_back({var, location}); break; @@ -75,7 +75,7 @@ Function::VariableBindings Function::ReferencedUniformVariables() const { continue; } - if (auto binding_point = var->Declaration()->binding_point()) { + if (auto binding_point = var->Declaration()->BindingPoint()) { ret.push_back({var, binding_point}); } } @@ -90,7 +90,7 @@ Function::VariableBindings Function::ReferencedStorageBufferVariables() const { continue; } - if (auto binding_point = var->Declaration()->binding_point()) { + if (auto binding_point = var->Declaration()->BindingPoint()) { ret.push_back({var, binding_point}); } } @@ -102,7 +102,7 @@ Function::ReferencedBuiltinVariables() const { std::vector> ret; for (auto* var : ReferencedModuleVariables()) { - for (auto* deco : var->Declaration()->decorations()) { + for (auto* deco : var->Declaration()->decorations) { if (auto* builtin = deco->As()) { ret.push_back({var, builtin}); break; @@ -136,7 +136,7 @@ Function::VariableBindings Function::ReferencedVariablesOfType( for (auto* var : ReferencedModuleVariables()) { auto* unwrapped_type = var->Type()->UnwrapRef(); if (unwrapped_type->TypeInfo().Is(type_info)) { - if (auto binding_point = var->Declaration()->binding_point()) { + if (auto binding_point = var->Declaration()->BindingPoint()) { ret.push_back({var, binding_point}); } } @@ -164,7 +164,7 @@ Function::VariableBindings Function::ReferencedSamplerVariablesImpl( continue; } - if (auto binding_point = var->Declaration()->binding_point()) { + if (auto binding_point = var->Declaration()->BindingPoint()) { ret.push_back({var, binding_point}); } } @@ -189,7 +189,7 @@ Function::VariableBindings Function::ReferencedSampledTextureVariablesImpl( continue; } - if (auto binding_point = var->Declaration()->binding_point()) { + if (auto binding_point = var->Declaration()->BindingPoint()) { ret.push_back({var, binding_point}); } } diff --git a/src/sem/function.h b/src/sem/function.h index 08ea5bf7e1..cd0c014f51 100644 --- a/src/sem/function.h +++ b/src/sem/function.h @@ -52,9 +52,9 @@ struct WorkgroupDimension { /// Function holds the semantic information for function nodes. class Function : public Castable { public: - /// A vector of [Variable*, ast::Variable::BindingPoint] pairs + /// A vector of [Variable*, ast::VariableBindingPoint] pairs using VariableBindings = - std::vector>; + std::vector>; /// Constructor /// @param declaration the ast::Function diff --git a/src/sem/sem_struct_test.cc b/src/sem/sem_struct_test.cc index ed0eba3163..104df11d3a 100644 --- a/src/sem/sem_struct_test.cc +++ b/src/sem/sem_struct_test.cc @@ -28,7 +28,7 @@ TEST_F(StructTest, Creation) { create(name, ast::StructMemberList{}, ast::DecorationList{}); auto* ptr = impl; auto* s = - create(impl, impl->name(), StructMemberList{}, 4 /* align */, + create(impl, impl->name, StructMemberList{}, 4 /* align */, 8 /* size */, 16 /* size_no_padding */); EXPECT_EQ(s->Declaration(), ptr); EXPECT_EQ(s->Align(), 4u); @@ -41,7 +41,7 @@ TEST_F(StructTest, TypeName) { auto* impl = create(name, ast::StructMemberList{}, ast::DecorationList{}); auto* s = - create(impl, impl->name(), StructMemberList{}, 4 /* align */, + create(impl, impl->name, StructMemberList{}, 4 /* align */, 4 /* size */, 4 /* size_no_padding */); EXPECT_EQ(s->type_name(), "__struct_$1"); } @@ -51,7 +51,7 @@ TEST_F(StructTest, FriendlyName) { auto* impl = create(name, ast::StructMemberList{}, ast::DecorationList{}); auto* s = - create(impl, impl->name(), StructMemberList{}, 4 /* align */, + create(impl, impl->name, StructMemberList{}, 4 /* align */, 4 /* size */, 4 /* size_no_padding */); EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct"); } diff --git a/src/sem/struct.cc b/src/sem/struct.cc index dea2fd112d..9238ec9eaa 100644 --- a/src/sem/struct.cc +++ b/src/sem/struct.cc @@ -51,7 +51,7 @@ Struct::~Struct() = default; const StructMember* Struct::FindMember(Symbol name) const { for (auto* member : members_) { - if (member->Declaration()->symbol() == name) { + if (member->Declaration()->symbol == name) { return member; } } diff --git a/src/transform/array_length_from_uniform.cc b/src/transform/array_length_from_uniform.cc index 0a2f3ecf8b..70ba5fc31f 100644 --- a/src/transform/array_length_from_uniform.cc +++ b/src/transform/array_length_from_uniform.cc @@ -106,21 +106,21 @@ void ArrayLengthFromUniform::Run(CloneContext& ctx, // We assume that the argument to `arrayLength` has the form // `&resource.array`, which requires that `InlinePointerLets` and // `Simplify` have been run before this transform. - auto* param = call_expr->args()[0]->As(); - if (!param || param->op() != ast::UnaryOp::kAddressOf) { + auto* param = call_expr->args[0]->As(); + if (!param || param->op != ast::UnaryOp::kAddressOf) { TINT_ICE(Transform, ctx.dst->Diagnostics()) << "expected form of arrayLength argument to be " "&resource.array"; break; } - auto* accessor = param->expr()->As(); + auto* accessor = param->expr->As(); if (!accessor) { TINT_ICE(Transform, ctx.dst->Diagnostics()) << "expected form of arrayLength argument to be " "&resource.array"; break; } - auto* storage_buffer_expr = accessor->structure(); + auto* storage_buffer_expr = accessor->structure; auto* storage_buffer_sem = sem.Get(storage_buffer_expr)->As(); if (!storage_buffer_sem) { @@ -151,7 +151,7 @@ void ArrayLengthFromUniform::Run(CloneContext& ctx, // Load the total storage buffer size from the UBO. uint32_t array_index = idx_itr->second / 4; auto* vec_expr = ctx.dst->IndexAccessor( - ctx.dst->MemberAccessor(get_ubo()->symbol(), kBufferSizeMemberName), + ctx.dst->MemberAccessor(get_ubo()->symbol, kBufferSizeMemberName), array_index); uint32_t vec_index = idx_itr->second % 4; auto* total_storage_buffer_size = diff --git a/src/transform/binding_remapper.cc b/src/transform/binding_remapper.cc index adecc8464c..3fe4e6ef0c 100644 --- a/src/transform/binding_remapper.cc +++ b/src/transform/binding_remapper.cc @@ -65,9 +65,9 @@ void BindingRemapper::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) { auto* func = ctx.src->Sem().Get(func_ast); std::unordered_map binding_point_counts; for (auto* var : func->ReferencedModuleVariables()) { - if (auto binding_point = var->Declaration()->binding_point()) { - BindingPoint from{binding_point.group->value(), - binding_point.binding->value()}; + if (auto binding_point = var->Declaration()->BindingPoint()) { + BindingPoint from{binding_point.group->value, + binding_point.binding->value}; auto bp_it = remappings->binding_points.find(from); if (bp_it != remappings->binding_points.end()) { // Remapped @@ -87,17 +87,17 @@ void BindingRemapper::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) { } for (auto* var : ctx.src->AST().GlobalVariables()) { - if (auto binding_point = var->binding_point()) { + if (auto binding_point = var->BindingPoint()) { // The original binding point - BindingPoint from{binding_point.group->value(), - binding_point.binding->value()}; + BindingPoint from{binding_point.group->value, + binding_point.binding->value}; // The binding point after remapping BindingPoint bp = from; // Replace any group or binding decorations. // Note: This has to be performed *before* remapping access controls, as - // `ctx.Clone(var->decorations())` depend on these replacements. + // `ctx.Clone(var->decorations)` depend on these replacements. auto bp_it = remappings->binding_points.find(from); if (bp_it != remappings->binding_points.end()) { BindingPoint to = bp_it->second; @@ -125,15 +125,15 @@ void BindingRemapper::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) { ctx.dst->Diagnostics().add_error( diag::System::Transform, "cannot apply access control to variable with storage class " + - std::string(ast::str(sem->StorageClass()))); + std::string(ast::ToString(sem->StorageClass()))); return; } auto* ty = sem->Type()->UnwrapRef(); ast::Type* inner_ty = CreateASTTypeFor(ctx, ty); auto* new_var = ctx.dst->create( - ctx.Clone(var->source()), ctx.Clone(var->symbol()), - var->declared_storage_class(), ac, inner_ty, var->is_const(), - ctx.Clone(var->constructor()), ctx.Clone(var->decorations())); + ctx.Clone(var->source), ctx.Clone(var->symbol), + var->declared_storage_class, ac, inner_ty, var->is_const, + ctx.Clone(var->constructor), ctx.Clone(var->decorations)); ctx.Replace(var, new_var); } @@ -142,7 +142,7 @@ void BindingRemapper::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) { auto* decoration = ctx.dst->ASTNodes().Create( ctx.dst->ID(), ast::DisabledValidation::kBindingPointCollision); - ctx.InsertBefore(var->decorations(), *var->decorations().begin(), + ctx.InsertBefore(var->decorations, *var->decorations.begin(), decoration); } } diff --git a/src/transform/calculate_array_length.cc b/src/transform/calculate_array_length.cc index b4d1e12181..37394a0ac5 100644 --- a/src/transform/calculate_array_length.cc +++ b/src/transform/calculate_array_length.cc @@ -54,9 +54,8 @@ struct ArrayUsage { } // namespace -CalculateArrayLength::BufferSizeIntrinsic::BufferSizeIntrinsic( - ProgramID program_id) - : Base(program_id) {} +CalculateArrayLength::BufferSizeIntrinsic::BufferSizeIntrinsic(ProgramID pid) + : Base(pid) {} CalculateArrayLength::BufferSizeIntrinsic::~BufferSizeIntrinsic() = default; std::string CalculateArrayLength::BufferSizeIntrinsic::InternalName() const { return "intrinsic_buffer_size"; @@ -82,7 +81,7 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) { return utils::GetOrCreate(buffer_size_intrinsics, buffer_type, [&] { auto name = ctx.dst->Sym(); auto* buffer_typename = - ctx.dst->ty.type_name(ctx.Clone(buffer_type->Declaration()->name())); + ctx.dst->ty.type_name(ctx.Clone(buffer_type->Declaration()->name)); auto* disable_validation = ctx.dst->ASTNodes().Create( ctx.dst->ID(), @@ -134,14 +133,14 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) { // We can assume that the arrayLength() call has a single argument of // the form: arrayLength(&X.Y) where X is an expression that resolves // to the storage buffer structure, and Y is the runtime sized array. - auto* arg = call_expr->args()[0]; + auto* arg = call_expr->args[0]; auto* address_of = arg->As(); - if (!address_of || address_of->op() != ast::UnaryOp::kAddressOf) { + if (!address_of || address_of->op != ast::UnaryOp::kAddressOf) { TINT_ICE(Transform, ctx.dst->Diagnostics()) << "arrayLength() expected pointer to member access, got " << address_of->TypeInfo().name; } - auto* array_expr = address_of->expr(); + auto* array_expr = address_of->expr; auto* accessor = array_expr->As(); if (!accessor) { @@ -151,7 +150,7 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) { << array_expr->TypeInfo().name; break; } - auto* storage_buffer_expr = accessor->structure(); + auto* storage_buffer_expr = accessor->structure; auto* storage_buffer_sem = sem.Get(storage_buffer_expr); auto* storage_buffer_type = storage_buffer_sem->Type()->UnwrapRef()->As(); @@ -201,7 +200,7 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) { // X.GetDimensions(ARGS..) by the writer buffer_size, ctx.Clone(storage_buffer_expr), ctx.dst->AddressOf(ctx.dst->Expr( - buffer_size_result->variable()->symbol())))); + buffer_size_result->variable->symbol)))); // Calculate actual array length // total_storage_buffer_size - array_offset @@ -213,16 +212,16 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) { auto* array_length_var = ctx.dst->Decl(ctx.dst->Const( name, ctx.dst->ty.u32(), ctx.dst->Div( - ctx.dst->Sub(buffer_size_result->variable()->symbol(), + ctx.dst->Sub(buffer_size_result->variable->symbol, array_offset), array_stride))); // Insert the array length calculations at the top of the block - ctx.InsertBefore(block->statements(), *block->begin(), + ctx.InsertBefore(block->statements, block->statements[0], buffer_size_result); - ctx.InsertBefore(block->statements(), *block->begin(), + ctx.InsertBefore(block->statements, block->statements[0], call_get_dims); - ctx.InsertBefore(block->statements(), *block->begin(), + ctx.InsertBefore(block->statements, block->statements[0], array_length_var); return name; }); diff --git a/src/transform/canonicalize_entry_point_io.cc b/src/transform/canonicalize_entry_point_io.cc index 46f24ae733..28378b1856 100644 --- a/src/transform/canonicalize_entry_point_io.cc +++ b/src/transform/canonicalize_entry_point_io.cc @@ -40,24 +40,24 @@ namespace { // those with builtin attributes. bool StructMemberComparator(const ast::StructMember* a, const ast::StructMember* b) { - auto* a_loc = ast::GetDecoration(a->decorations()); - auto* b_loc = ast::GetDecoration(b->decorations()); - auto* a_blt = ast::GetDecoration(a->decorations()); - auto* b_blt = ast::GetDecoration(b->decorations()); + auto* a_loc = ast::GetDecoration(a->decorations); + auto* b_loc = ast::GetDecoration(b->decorations); + auto* a_blt = ast::GetDecoration(a->decorations); + auto* b_blt = ast::GetDecoration(b->decorations); if (a_loc) { if (!b_loc) { // `a` has location attribute and `b` does not: `a` goes first. return true; } // Both have location attributes: smallest goes first. - return a_loc->value() < b_loc->value(); + return a_loc->value < b_loc->value; } else { if (b_loc) { // `b` has location attribute and `a` does not: `b` goes first. return false; } // Both are builtins: order doesn't matter, just use enum value. - return a_blt->value() < b_blt->value(); + return a_blt->builtin < b_blt->builtin; } } @@ -70,7 +70,7 @@ bool IsShaderIODecoration(const ast::Decoration* deco) { // Returns true if `decos` contains a `sample_mask` builtin. bool HasSampleMask(const ast::DecorationList& decos) { auto* builtin = ast::GetDecoration(decos); - return builtin && builtin->value() == ast::Builtin::kSampleMask; + return builtin && builtin->builtin == ast::Builtin::kSampleMask; } } // namespace @@ -163,7 +163,7 @@ struct CanonicalizeEntryPointIO::State { // always decorated with `Flat`. if (type->is_integer_scalar_or_vector() && ast::HasDecoration(attributes) && - func_ast->pipeline_stage() == ast::PipelineStage::kFragment) { + func_ast->PipelineStage() == ast::PipelineStage::kFragment) { attributes.push_back(ctx.dst->Interpolate( ast::InterpolationType::kFlat, ast::InterpolationSampling::kNone)); } @@ -220,7 +220,7 @@ struct CanonicalizeEntryPointIO::State { if (cfg.shader_style == ShaderStyle::kSpirv && type->is_integer_scalar_or_vector() && ast::HasDecoration(attributes) && - func_ast->pipeline_stage() == ast::PipelineStage::kVertex) { + func_ast->PipelineStage() == ast::PipelineStage::kVertex) { attributes.push_back(ctx.dst->Interpolate( ast::InterpolationType::kFlat, ast::InterpolationSampling::kNone)); } @@ -242,14 +242,14 @@ struct CanonicalizeEntryPointIO::State { // Remove the shader IO attributes from the inner function parameter, and // attach them to the new object instead. ast::DecorationList attributes; - for (auto* deco : param->Declaration()->decorations()) { + for (auto* deco : param->Declaration()->decorations) { if (IsShaderIODecoration(deco)) { - ctx.Remove(param->Declaration()->decorations(), deco); + ctx.Remove(param->Declaration()->decorations, deco); attributes.push_back(ctx.Clone(deco)); } } - auto name = ctx.src->Symbols().NameFor(param->Declaration()->symbol()); + auto name = ctx.src->Symbols().NameFor(param->Declaration()->symbol); auto* input_expr = AddInput(name, param->Type(), std::move(attributes)); inner_call_parameters.push_back(input_expr); } @@ -272,15 +272,15 @@ struct CanonicalizeEntryPointIO::State { } auto* member_ast = member->Declaration(); - auto name = ctx.src->Symbols().NameFor(member_ast->symbol()); - auto attributes = CloneShaderIOAttributes(member_ast->decorations()); + auto name = ctx.src->Symbols().NameFor(member_ast->symbol); + auto attributes = CloneShaderIOAttributes(member_ast->decorations); auto* input_expr = AddInput(name, member->Type(), std::move(attributes)); inner_struct_values.push_back(input_expr); } // Construct the original structure using the new shader input objects. inner_call_parameters.push_back(ctx.dst->Construct( - ctx.Clone(param->Declaration()->type()), inner_struct_values)); + ctx.Clone(param->Declaration()->type), inner_struct_values)); } /// Process the entry point return type. @@ -298,8 +298,8 @@ struct CanonicalizeEntryPointIO::State { } auto* member_ast = member->Declaration(); - auto name = ctx.src->Symbols().NameFor(member_ast->symbol()); - auto attributes = CloneShaderIOAttributes(member_ast->decorations()); + auto name = ctx.src->Symbols().NameFor(member_ast->symbol); + auto attributes = CloneShaderIOAttributes(member_ast->decorations); // Extract the original structure member. AddOutput(name, member->Type(), std::move(attributes), @@ -307,7 +307,7 @@ struct CanonicalizeEntryPointIO::State { } } else if (!inner_ret_type->Is()) { auto attributes = - CloneShaderIOAttributes(func_ast->return_type_decorations()); + CloneShaderIOAttributes(func_ast->return_type_decorations); // Propagate the non-struct return value as is. AddOutput("value", func_sem->ReturnType(), std::move(attributes), @@ -396,7 +396,7 @@ struct CanonicalizeEntryPointIO::State { // Create the output struct object, assign its members, and return it. auto* result_object = - ctx.dst->Var(wrapper_result, ctx.dst->ty.type_name(out_struct->name())); + ctx.dst->Var(wrapper_result, ctx.dst->ty.type_name(out_struct->name)); wrapper_body.push_back(ctx.dst->Decl(result_object)); wrapper_body.insert(wrapper_body.end(), assignments.begin(), assignments.end()); @@ -435,31 +435,31 @@ struct CanonicalizeEntryPointIO::State { ast::CallExpression* CallInnerFunction() { // Add a suffix to the function name, as the wrapper function will take the // original entry point name. - auto ep_name = ctx.src->Symbols().NameFor(func_ast->symbol()); + auto ep_name = ctx.src->Symbols().NameFor(func_ast->symbol); auto inner_name = ctx.dst->Symbols().New(ep_name + "_inner"); // Clone everything, dropping the function and return type attributes. // The parameter attributes will have already been stripped during // processing. auto* inner_function = ctx.dst->create( - inner_name, ctx.Clone(func_ast->params()), - ctx.Clone(func_ast->return_type()), ctx.Clone(func_ast->body()), + inner_name, ctx.Clone(func_ast->params), + ctx.Clone(func_ast->return_type), ctx.Clone(func_ast->body), ast::DecorationList{}, ast::DecorationList{}); ctx.Replace(func_ast, inner_function); // Call the function. - return ctx.dst->Call(inner_function->symbol(), inner_call_parameters); + return ctx.dst->Call(inner_function->symbol, inner_call_parameters); } /// Process the entry point function. void Process() { bool needs_fixed_sample_mask = false; bool needs_vertex_point_size = false; - if (func_ast->pipeline_stage() == ast::PipelineStage::kFragment && + if (func_ast->PipelineStage() == ast::PipelineStage::kFragment && cfg.fixed_sample_mask != 0xFFFFFFFF) { needs_fixed_sample_mask = true; } - if (func_ast->pipeline_stage() == ast::PipelineStage::kVertex && + if (func_ast->PipelineStage() == ast::PipelineStage::kVertex && cfg.emit_vertex_point_size) { needs_vertex_point_size = true; } @@ -506,7 +506,7 @@ struct CanonicalizeEntryPointIO::State { // Process the original return type to determine the outputs that the // outer function needs to produce. - ProcessReturnType(func_sem->ReturnType(), inner_result->symbol()); + ProcessReturnType(func_sem->ReturnType(), inner_result->symbol); } // Add a fixed sample mask, if necessary. @@ -526,17 +526,17 @@ struct CanonicalizeEntryPointIO::State { } else { auto* output_struct = CreateOutputStruct(); wrapper_ret_type = [&, output_struct] { - return ctx.dst->ty.type_name(output_struct->name()); + return ctx.dst->ty.type_name(output_struct->name); }; } } // Create the wrapper entry point function. // Take the name of the original entry point function. - auto name = ctx.Clone(func_ast->symbol()); + auto name = ctx.Clone(func_ast->symbol); auto* wrapper_func = ctx.dst->create( name, wrapper_ep_parameters, wrapper_ret_type(), - ctx.dst->Block(wrapper_body), ctx.Clone(func_ast->decorations()), + ctx.dst->Block(wrapper_body), ctx.Clone(func_ast->decorations), ast::DecorationList{}); ctx.InsertAfter(ctx.src->AST().GlobalDeclarations(), func_ast, wrapper_func); @@ -558,10 +558,10 @@ void CanonicalizeEntryPointIO::Run(CloneContext& ctx, // New structures will be created for each entry point, as necessary. for (auto* ty : ctx.src->AST().TypeDecls()) { if (auto* struct_ty = ty->As()) { - for (auto* member : struct_ty->members()) { - for (auto* deco : member->decorations()) { + for (auto* member : struct_ty->members) { + for (auto* deco : member->decorations) { if (IsShaderIODecoration(deco)) { - ctx.Remove(member->decorations(), deco); + ctx.Remove(member->decorations, deco); } } } diff --git a/src/transform/decompose_memory_access.cc b/src/transform/decompose_memory_access.cc index 561c29fbda..d6b5a40ab0 100644 --- a/src/transform/decompose_memory_access.cc +++ b/src/transform/decompose_memory_access.cc @@ -332,11 +332,11 @@ struct DecomposeMemoryAccess::State { /// @returns an Offset for the given ast::Expression const Offset* ToOffset(ast::Expression* expr) { if (auto* scalar = expr->As()) { - if (auto* u32 = scalar->literal()->As()) { - return offsets_.Create(u32->value()); - } else if (auto* i32 = scalar->literal()->As()) { - if (i32->value() > 0) { - return offsets_.Create(i32->value()); + if (auto* u32 = scalar->literal->As()) { + return offsets_.Create(u32->value); + } else if (auto* i32 = scalar->literal->As()) { + if (i32->value > 0) { + return offsets_.Create(i32->value); } } } @@ -625,7 +625,7 @@ struct DecomposeMemoryAccess::State { for (auto* member : str->Members()) { auto* offset = b.Add("offset", member->Offset()); auto* access = b.MemberAccessor( - "value", ctx.Clone(member->Declaration()->symbol())); + "value", ctx.Clone(member->Declaration()->symbol)); Symbol store = StoreFunc(buf_ty, member->Type()->UnwrapRef(), var_user); auto* call = b.Call(store, "buffer", offset, access); @@ -697,16 +697,16 @@ struct DecomposeMemoryAccess::State { ast::DecorationList{}); b.AST().AddFunction(func); - return func->symbol(); + return func->symbol; }); } }; -DecomposeMemoryAccess::Intrinsic::Intrinsic(ProgramID program_id, +DecomposeMemoryAccess::Intrinsic::Intrinsic(ProgramID pid, Op o, ast::StorageClass sc, DataType ty) - : Base(program_id), op(o), storage_class(sc), type(ty) {} + : Base(pid), op(o), storage_class(sc), type(ty) {} DecomposeMemoryAccess::Intrinsic::~Intrinsic() = default; std::string DecomposeMemoryAccess::Intrinsic::InternalName() const { std::stringstream ss; @@ -837,7 +837,7 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { auto* accessor_sem = sem.Get(accessor); if (auto* swizzle = accessor_sem->As()) { if (swizzle->Indices().size() == 1) { - if (auto access = state.TakeAccess(accessor->structure())) { + if (auto access = state.TakeAccess(accessor->structure)) { auto* vec_ty = access.type->As(); auto* offset = state.Mul(vec_ty->type()->Size(), swizzle->Indices()[0]); @@ -849,9 +849,9 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { } } } else { - if (auto access = state.TakeAccess(accessor->structure())) { + if (auto access = state.TakeAccess(accessor->structure)) { auto* str_ty = access.type->As(); - auto* member = str_ty->FindMember(accessor->member()->symbol()); + auto* member = str_ty->FindMember(accessor->member->symbol); auto offset = member->Offset(); state.AddAccess(accessor, { access.var, @@ -864,10 +864,10 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { } if (auto* accessor = node->As()) { - if (auto access = state.TakeAccess(accessor->array())) { + if (auto access = state.TakeAccess(accessor->array)) { // X[Y] if (auto* arr = access.type->As()) { - auto* offset = state.Mul(arr->Stride(), accessor->idx_expr()); + auto* offset = state.Mul(arr->Stride(), accessor->index); state.AddAccess(accessor, { access.var, state.Add(access.offset, offset), @@ -876,8 +876,7 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { continue; } if (auto* vec_ty = access.type->As()) { - auto* offset = - state.Mul(vec_ty->type()->Size(), accessor->idx_expr()); + auto* offset = state.Mul(vec_ty->type()->Size(), accessor->index); state.AddAccess(accessor, { access.var, state.Add(access.offset, offset), @@ -886,8 +885,7 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { continue; } if (auto* mat_ty = access.type->As()) { - auto* offset = - state.Mul(mat_ty->ColumnStride(), accessor->idx_expr()); + auto* offset = state.Mul(mat_ty->ColumnStride(), accessor->index); state.AddAccess(accessor, { access.var, state.Add(access.offset, offset), @@ -899,9 +897,9 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { } if (auto* op = node->As()) { - if (op->op() == ast::UnaryOp::kAddressOf) { + if (op->op == ast::UnaryOp::kAddressOf) { // &X - if (auto access = state.TakeAccess(op->expr())) { + if (auto access = state.TakeAccess(op->expr)) { // HLSL does not support pointers, so just take the access from the // reference and place it on the pointer. state.AddAccess(op, access); @@ -913,7 +911,7 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { if (auto* assign = node->As()) { // X = Y // Move the LHS access to a store. - if (auto lhs = state.TakeAccess(assign->lhs())) { + if (auto lhs = state.TakeAccess(assign->lhs)) { state.stores.emplace_back(Store{assign, lhs}); } } @@ -927,8 +925,8 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { // may refer to a structure holding a runtime array, which cannot be // loaded. Instead replace X with the underlying storage / uniform // buffer variable. - if (auto access = state.TakeAccess(call_expr->args()[0])) { - ctx.Replace(call_expr->args()[0], [=, &ctx] { + if (auto access = state.TakeAccess(call_expr->args[0])) { + ctx.Replace(call_expr->args[0], [=, &ctx] { return ctx.CloneWithoutTransform(access.var->Declaration()); }); } @@ -938,11 +936,11 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { // arrayLength(X) // Don't convert X into a load, this intrinsic actually requires the // real pointer. - state.TakeAccess(call_expr->args()[0]); + state.TakeAccess(call_expr->args[0]); continue; } if (intrinsic->IsAtomic()) { - if (auto access = state.TakeAccess(call_expr->args()[0])) { + if (auto access = state.TakeAccess(call_expr->args[0])) { // atomic___(X) ctx.Replace(call_expr, [=, &ctx, &state] { auto* buf = access.var->Declaration(); @@ -954,8 +952,8 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { access.var->As()); ast::ExpressionList args{ctx.Clone(buf), offset}; - for (size_t i = 1; i < call_expr->args().size(); i++) { - auto* arg = call_expr->args()[i]; + for (size_t i = 1; i < call_expr->args.size(); i++) { + auto* arg = call_expr->args[i]; args.emplace_back(ctx.Clone(arg)); } return ctx.dst->Call(func, args); @@ -992,7 +990,7 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) { auto* offset = store.target.offset->Build(ctx); auto* buf_ty = store.target.var->Type()->UnwrapRef(); auto* el_ty = store.target.type->UnwrapRef(); - auto* value = store.assignment->rhs(); + auto* value = store.assignment->rhs; Symbol func = state.StoreFunc(buf_ty, el_ty, store.target.var->As()); auto* call = ctx.dst->Call(func, ctx.CloneWithoutTransform(buf), offset, diff --git a/src/transform/decompose_strided_matrix.cc b/src/transform/decompose_strided_matrix.cc index 786f509b2c..497a89151f 100644 --- a/src/transform/decompose_strided_matrix.cc +++ b/src/transform/decompose_strided_matrix.cc @@ -86,11 +86,11 @@ void GatherCustomStrideMatrixMembers(const Program* program, F&& callback) { continue; } auto* deco = ast::GetDecoration( - member->Declaration()->decorations()); + member->Declaration()->decorations); if (!deco) { continue; } - uint32_t stride = deco->stride(); + uint32_t stride = deco->stride; if (matrix->ColumnStride() == stride) { continue; } @@ -147,11 +147,11 @@ void DecomposeStridedMatrix::Run(CloneContext& ctx, const DataMap&, DataMap&) { ctx.ReplaceAll( [&](ast::ArrayAccessorExpression* expr) -> ast::ArrayAccessorExpression* { if (auto* access = - ctx.src->Sem().Get(expr->array())) { + ctx.src->Sem().Get(expr->array)) { auto it = decomposed.find(access->Member()->Declaration()); if (it != decomposed.end()) { - auto* obj = ctx.CloneWithoutTransform(expr->array()); - auto* idx = ctx.Clone(expr->idx_expr()); + auto* obj = ctx.CloneWithoutTransform(expr->array); + auto* idx = ctx.Clone(expr->index); return ctx.dst->IndexAccessor(obj, idx); } } @@ -165,8 +165,7 @@ void DecomposeStridedMatrix::Run(CloneContext& ctx, const DataMap&, DataMap&) { // ssbo.mat = mat_to_arr(m) std::unordered_map mat_to_arr; ctx.ReplaceAll([&](ast::AssignmentStatement* stmt) -> ast::Statement* { - if (auto* access = - ctx.src->Sem().Get(stmt->lhs())) { + if (auto* access = ctx.src->Sem().Get(stmt->lhs)) { auto it = decomposed.find(access->Member()->Declaration()); if (it == decomposed.end()) { return nullptr; @@ -196,8 +195,8 @@ void DecomposeStridedMatrix::Run(CloneContext& ctx, const DataMap&, DataMap&) { }); return name; }); - auto* lhs = ctx.CloneWithoutTransform(stmt->lhs()); - auto* rhs = ctx.dst->Call(fn, ctx.Clone(stmt->rhs())); + auto* lhs = ctx.CloneWithoutTransform(stmt->lhs); + auto* rhs = ctx.dst->Call(fn, ctx.Clone(stmt->rhs)); return ctx.dst->Assign(lhs, rhs); } return nullptr; diff --git a/src/transform/external_texture_transform.cc b/src/transform/external_texture_transform.cc index da2539a144..3b540ad036 100644 --- a/src/transform/external_texture_transform.cc +++ b/src/transform/external_texture_transform.cc @@ -53,43 +53,43 @@ void ExternalTextureTransform::Run(CloneContext& ctx, // When a textureLoad or textureSampleLevel has been identified, check // if the first parameter is an external texture. if (auto* var = - sem.Get(call_expr->args()[0])->As()) { + sem.Get(call_expr->args[0])->As()) { if (var->Variable() ->Type() ->UnwrapRef() ->Is()) { if (intrinsic->Type() == sem::IntrinsicType::kTextureLoad && - call_expr->args().size() != 2) { + call_expr->args.size() != 2) { TINT_ICE(Transform, ctx.dst->Diagnostics()) << "expected textureLoad call with a texture_external to " "have 2 parameters, found " - << call_expr->args().size() << " parameters"; + << call_expr->args.size() << " parameters"; } if (intrinsic->Type() == sem::IntrinsicType::kTextureSampleLevel && - call_expr->args().size() != 3) { + call_expr->args.size() != 3) { TINT_ICE(Transform, ctx.dst->Diagnostics()) << "expected textureSampleLevel call with a " "texture_external to have 3 parameters, found " - << call_expr->args().size() << " parameters"; + << call_expr->args.size() << " parameters"; } // Replace the call with another that has the same parameters in // addition to a level parameter (always zero for external // textures). - auto* exp = ctx.Clone(call_expr->func()); - auto* externalTextureParam = ctx.Clone(call_expr->args()[0]); + auto* exp = ctx.Clone(call_expr->func); + auto* externalTextureParam = ctx.Clone(call_expr->args[0]); ast::ExpressionList params; if (intrinsic->Type() == sem::IntrinsicType::kTextureLoad) { - auto* coordsParam = ctx.Clone(call_expr->args()[1]); + auto* coordsParam = ctx.Clone(call_expr->args[1]); auto* levelParam = ctx.dst->Expr(0); params = {externalTextureParam, coordsParam, levelParam}; } else if (intrinsic->Type() == sem::IntrinsicType::kTextureSampleLevel) { - auto* samplerParam = ctx.Clone(call_expr->args()[1]); - auto* coordsParam = ctx.Clone(call_expr->args()[2]); + auto* samplerParam = ctx.Clone(call_expr->args[1]); + auto* coordsParam = ctx.Clone(call_expr->args[2]); auto* levelParam = ctx.dst->Expr(0.0f); params = {externalTextureParam, samplerParam, coordsParam, levelParam}; @@ -107,18 +107,18 @@ void ExternalTextureTransform::Run(CloneContext& ctx, // Scan the AST nodes for external texture declarations. for (auto* node : ctx.src->ASTNodes().Objects()) { if (auto* var = node->As()) { - if (::tint::Is(var->type())) { + if (::tint::Is(var->type)) { // Replace a single-plane external texture with a 2D, f32 sampled // texture. auto* newType = ctx.dst->ty.sampled_texture(ast::TextureDimension::k2d, ctx.dst->ty.f32()); - auto clonedSrc = ctx.Clone(var->source()); - auto clonedSym = ctx.Clone(var->symbol()); - auto* clonedConstructor = ctx.Clone(var->constructor()); - auto clonedDecorations = ctx.Clone(var->decorations()); + auto clonedSrc = ctx.Clone(var->source); + auto clonedSym = ctx.Clone(var->symbol); + auto* clonedConstructor = ctx.Clone(var->constructor); + auto clonedDecorations = ctx.Clone(var->decorations); auto* newVar = ctx.dst->create( - clonedSrc, clonedSym, var->declared_storage_class(), - var->declared_access(), newType, var->is_const(), clonedConstructor, + clonedSrc, clonedSym, var->declared_storage_class, + var->declared_access, newType, var->is_const, clonedConstructor, clonedDecorations); ctx.Replace(var, newVar); diff --git a/src/transform/first_index_offset.cc b/src/transform/first_index_offset.cc index 8a28364ae6..0ae7ffa49f 100644 --- a/src/transform/first_index_offset.cc +++ b/src/transform/first_index_offset.cc @@ -80,9 +80,9 @@ void FirstIndexOffset::Run(CloneContext& ctx, // parameters) or structure member accesses. for (auto* node : ctx.src->ASTNodes().Objects()) { if (auto* var = node->As()) { - for (ast::Decoration* dec : var->decorations()) { + for (ast::Decoration* dec : var->decorations) { if (auto* builtin_dec = dec->As()) { - ast::Builtin builtin = builtin_dec->value(); + ast::Builtin builtin = builtin_dec->builtin; if (builtin == ast::Builtin::kVertexIndex) { auto* sem_var = ctx.src->Sem().Get(var); builtin_vars.emplace(sem_var, kFirstVertexName); @@ -97,9 +97,9 @@ void FirstIndexOffset::Run(CloneContext& ctx, } } if (auto* member = node->As()) { - for (ast::Decoration* dec : member->decorations()) { + for (ast::Decoration* dec : member->decorations) { if (auto* builtin_dec = dec->As()) { - ast::Builtin builtin = builtin_dec->value(); + ast::Builtin builtin = builtin_dec->builtin; if (builtin == ast::Builtin::kVertexIndex) { auto* sem_mem = ctx.src->Sem().Get(member); builtin_members.emplace(sem_mem, kFirstVertexName); diff --git a/src/transform/fold_constants.cc b/src/transform/fold_constants.cc index 4868b3c51f..54f7f15f0d 100644 --- a/src/transform/fold_constants.cc +++ b/src/transform/fold_constants.cc @@ -51,7 +51,7 @@ void FoldConstants::Run(CloneContext& ctx, const DataMap&, DataMap&) { // If original ctor expression had no init values, don't replace the // expression - if (ctor->values().size() == 0) { + if (ctor->values.size() == 0) { return nullptr; } @@ -68,7 +68,7 @@ void FoldConstants::Run(CloneContext& ctx, const DataMap&, DataMap&) { // create it with 3. So what we do is construct with vec_size args, // except if the original vector was single-value initialized, in // which case, we only construct with one arg again. - uint32_t ctor_size = (ctor->values().size() == 1) ? 1 : vec_size; + uint32_t ctor_size = (ctor->values.size() == 1) ? 1 : vec_size; ast::ExpressionList ctors; for (uint32_t i = 0; i < ctor_size; ++i) { diff --git a/src/transform/fold_trivial_single_use_lets.cc b/src/transform/fold_trivial_single_use_lets.cc index d1deb8f8c0..78d77e3eae 100644 --- a/src/transform/fold_trivial_single_use_lets.cc +++ b/src/transform/fold_trivial_single_use_lets.cc @@ -32,11 +32,11 @@ ast::VariableDeclStatement* AsTrivialLetDecl(ast::Statement* stmt) { if (!var_decl) { return nullptr; } - auto* var = var_decl->variable(); - if (!var->is_const()) { + auto* var = var_decl->variable; + if (!var->is_const) { return nullptr; } - auto* ctor = var->constructor(); + auto* ctor = var->constructor; if (!IsAnyOf( ctor)) { return nullptr; @@ -55,11 +55,11 @@ void FoldTrivialSingleUseLets::Run(CloneContext& ctx, DataMap&) { for (auto* node : ctx.src->ASTNodes().Objects()) { if (auto* block = node->As()) { - auto& stmts = block->statements(); + auto& stmts = block->statements; for (size_t stmt_idx = 0; stmt_idx < stmts.size(); stmt_idx++) { auto* stmt = stmts[stmt_idx]; if (auto* let_decl = AsTrivialLetDecl(stmt)) { - auto* let = let_decl->variable(); + auto* let = let_decl->variable; auto* sem_let = ctx.src->Sem().Get(let); auto& users = sem_let->Users(); if (users.size() != 1) { @@ -73,7 +73,7 @@ void FoldTrivialSingleUseLets::Run(CloneContext& ctx, if (user_stmt == stmts[i]) { auto* user_expr = user->Declaration(); ctx.Remove(stmts, let_decl); - ctx.Replace(user_expr, ctx.Clone(let->constructor())); + ctx.Replace(user_expr, ctx.Clone(let->constructor)); } if (!AsTrivialLetDecl(stmts[i])) { // Stop if we hit a statement that isn't the single use of the diff --git a/src/transform/for_loop_to_loop.cc b/src/transform/for_loop_to_loop.cc index 5f553a8a2f..6b43064cad 100644 --- a/src/transform/for_loop_to_loop.cc +++ b/src/transform/for_loop_to_loop.cc @@ -28,7 +28,7 @@ ForLoopToLoop::~ForLoopToLoop() = default; void ForLoopToLoop::Run(CloneContext& ctx, const DataMap&, DataMap&) { ctx.ReplaceAll([&](ast::ForLoopStatement* for_loop) -> ast::Statement* { ast::StatementList stmts; - if (auto* cond = for_loop->condition()) { + if (auto* cond = for_loop->condition) { // !condition auto* not_cond = ctx.dst->create( ast::UnaryOp::kNot, ctx.Clone(cond)); @@ -39,19 +39,19 @@ void ForLoopToLoop::Run(CloneContext& ctx, const DataMap&, DataMap&) { // if (!condition) { break; } stmts.emplace_back(ctx.dst->If(not_cond, break_body)); } - for (auto* stmt : for_loop->body()->statements()) { + for (auto* stmt : for_loop->body->statements) { stmts.emplace_back(ctx.Clone(stmt)); } ast::BlockStatement* continuing = nullptr; - if (auto* cont = for_loop->continuing()) { + if (auto* cont = for_loop->continuing) { continuing = ctx.dst->Block(ctx.Clone(cont)); } auto* body = ctx.dst->Block(stmts); auto* loop = ctx.dst->create(body, continuing); - if (auto* init = for_loop->initializer()) { + if (auto* init = for_loop->initializer) { return ctx.dst->Block(ctx.Clone(init), loop); } diff --git a/src/transform/inline_pointer_lets.cc b/src/transform/inline_pointer_lets.cc index 38d905c916..85287a2c50 100644 --- a/src/transform/inline_pointer_lets.cc +++ b/src/transform/inline_pointer_lets.cc @@ -44,21 +44,21 @@ void CollectSavedArrayIndices(const Program* program, ast::Expression* expr, F&& cb) { if (auto* a = expr->As()) { - CollectSavedArrayIndices(program, a->array(), cb); + CollectSavedArrayIndices(program, a->array, cb); - if (!a->idx_expr()->Is()) { - cb(a->idx_expr()); + if (!a->index->Is()) { + cb(a->index); } return; } if (auto* m = expr->As()) { - CollectSavedArrayIndices(program, m->structure(), cb); + CollectSavedArrayIndices(program, m->structure, cb); return; } if (auto* u = expr->As()) { - CollectSavedArrayIndices(program, u->expr(), cb); + CollectSavedArrayIndices(program, u->expr, cb); return; } @@ -119,7 +119,7 @@ void InlinePointerLets::Run(CloneContext& ctx, const DataMap&, DataMap&) { // TINT_SCOPED_ASSIGNMENT provides a stack of PtrLet*, this is // required to handle the 'chaining' of inlined `let`s. TINT_SCOPED_ASSIGNMENT(current_ptr_let, ptr_let); - return ctx.Clone(var->constructor()); + return ctx.Clone(var->constructor); } } } @@ -131,11 +131,11 @@ void InlinePointerLets::Run(CloneContext& ctx, const DataMap&, DataMap&) { // permitted. for (auto* node : ctx.src->ASTNodes().Objects()) { if (auto* let = node->As()) { - if (!let->variable()->is_const()) { + if (!let->variable->is_const) { continue; // Not a `let` declaration. Ignore. } - auto* var = ctx.src->Sem().Get(let->variable()); + auto* var = ctx.src->Sem().Get(let->variable); if (!var->Type()->Is()) { continue; // Not a pointer type. Ignore. } @@ -149,12 +149,12 @@ void InlinePointerLets::Run(CloneContext& ctx, const DataMap&, DataMap&) { // Scan the initializer expression for array index expressions that need // to be hoist to temporary "saved" variables. CollectSavedArrayIndices( - ctx.src, var->Declaration()->constructor(), + ctx.src, var->Declaration()->constructor, [&](ast::Expression* idx_expr) { // We have a sub-expression that needs to be saved. // Create a new variable auto saved_name = ctx.dst->Symbols().New( - ctx.src->Symbols().NameFor(var->Declaration()->symbol()) + + ctx.src->Symbols().NameFor(var->Declaration()->symbol) + "_save"); auto* saved = ctx.dst->Decl( ctx.dst->Const(saved_name, nullptr, ctx.Clone(idx_expr))); @@ -165,7 +165,7 @@ void InlinePointerLets::Run(CloneContext& ctx, const DataMap&, DataMap&) { // Note that repeated calls to InsertAfter() with the same `after` // argument will result in nodes to inserted in the order the calls // are made (last call is inserted last). - ctx.InsertAfter(block->statements(), let, saved); + ctx.InsertAfter(block->statements, let, saved); // Record the substitution of `idx_expr` to the saved variable with // the symbol `saved_name`. This will be used by the ReplaceAll() // handler above. @@ -174,7 +174,7 @@ void InlinePointerLets::Run(CloneContext& ctx, const DataMap&, DataMap&) { // Record the pointer-typed `let` declaration. // This will be used by the ReplaceAll() handler above. - ptr_lets.emplace(let->variable(), std::move(ptr_let)); + ptr_lets.emplace(let->variable, std::move(ptr_let)); // As the original `let` declaration will be fully inlined, there's no // need for the original declaration to exist. Remove it. RemoveStatement(ctx, let); diff --git a/src/transform/loop_to_for_loop.cc b/src/transform/loop_to_for_loop.cc index 85f7a84dd7..34d452477c 100644 --- a/src/transform/loop_to_for_loop.cc +++ b/src/transform/loop_to_for_loop.cc @@ -30,10 +30,10 @@ namespace transform { namespace { bool IsBlockWithSingleBreak(ast::BlockStatement* block) { - if (block->size() != 1) { + if (block->statements.size() != 1) { return false; } - return block->statements()[0]->Is(); + return block->statements[0]->Is(); } bool IsVarUsedByStmt(const sem::Info& sem, @@ -67,7 +67,7 @@ void LoopToForLoop::Run(CloneContext& ctx, const DataMap&, DataMap&) { // Examples: // loop { if (condition) { break; } ... } // loop { if (condition) {} else { break; } ... } - auto& stmts = loop->body()->statements(); + auto& stmts = loop->body->statements; if (stmts.empty()) { return nullptr; } @@ -77,13 +77,12 @@ void LoopToForLoop::Run(CloneContext& ctx, const DataMap&, DataMap&) { } bool negate_condition = false; - if (IsBlockWithSingleBreak(if_stmt->body()) && - if_stmt->else_statements().empty()) { + if (IsBlockWithSingleBreak(if_stmt->body) && + if_stmt->else_statements.empty()) { negate_condition = true; - } else if (if_stmt->body()->empty() && - if_stmt->else_statements().size() == 1 && - if_stmt->else_statements()[0]->condition() == nullptr && - IsBlockWithSingleBreak(if_stmt->else_statements()[0]->body())) { + } else if (if_stmt->body->Empty() && if_stmt->else_statements.size() == 1 && + if_stmt->else_statements[0]->condition == nullptr && + IsBlockWithSingleBreak(if_stmt->else_statements[0]->body)) { negate_condition = false; } else { return nullptr; @@ -92,12 +91,12 @@ void LoopToForLoop::Run(CloneContext& ctx, const DataMap&, DataMap&) { // The continuing block must be empty or contain a single, assignment or // function call statement. ast::Statement* continuing = nullptr; - if (auto* loop_cont = loop->continuing()) { - if (loop_cont->statements().size() != 1) { + if (auto* loop_cont = loop->continuing) { + if (loop_cont->statements.size() != 1) { return nullptr; } - continuing = loop_cont->statements()[0]; + continuing = loop_cont->statements[0]; if (!continuing ->IsAnyOf()) { return nullptr; @@ -105,10 +104,9 @@ void LoopToForLoop::Run(CloneContext& ctx, const DataMap&, DataMap&) { // And the continuing statement must not use any of the variables declared // in the loop body. - for (auto* stmt : loop->body()->statements()) { + for (auto* stmt : loop->body->statements) { if (auto* var_decl = stmt->As()) { - if (IsVarUsedByStmt(ctx.src->Sem(), var_decl->variable(), - continuing)) { + if (IsVarUsedByStmt(ctx.src->Sem(), var_decl->variable, continuing)) { return nullptr; } } @@ -117,7 +115,7 @@ void LoopToForLoop::Run(CloneContext& ctx, const DataMap&, DataMap&) { continuing = ctx.Clone(continuing); } - auto* condition = ctx.Clone(if_stmt->condition()); + auto* condition = ctx.Clone(if_stmt->condition); if (negate_condition) { condition = ctx.dst->create(ast::UnaryOp::kNot, condition); @@ -125,8 +123,8 @@ void LoopToForLoop::Run(CloneContext& ctx, const DataMap&, DataMap&) { ast::Statement* initializer = nullptr; - ctx.Remove(loop->body()->statements(), if_stmt); - auto* body = ctx.Clone(loop->body()); + ctx.Remove(loop->body->statements, if_stmt); + auto* body = ctx.Clone(loop->body); return ctx.dst->create(initializer, condition, continuing, body); }); diff --git a/src/transform/module_scope_var_to_entry_point_param.cc b/src/transform/module_scope_var_to_entry_point_param.cc index f0a3ee7fa0..f71a0105dc 100644 --- a/src/transform/module_scope_var_to_entry_point_param.cc +++ b/src/transform/module_scope_var_to_entry_point_param.cc @@ -127,10 +127,10 @@ struct ModuleScopeVarToEntryPointParam::State { ident_to_address_of; for (auto* node : ctx.src->ASTNodes().Objects()) { auto* address_of = node->As(); - if (!address_of || address_of->op() != ast::UnaryOp::kAddressOf) { + if (!address_of || address_of->op != ast::UnaryOp::kAddressOf) { continue; } - if (auto* ident = address_of->expr()->As()) { + if (auto* ident = address_of->expr->As()) { ident_to_address_of[ident] = address_of; } } @@ -180,10 +180,10 @@ struct ModuleScopeVarToEntryPointParam::State { ctx.dst->ASTNodes().Create( ctx.dst->ID(), ast::DisabledValidation::kEntryPointParameter); - auto decos = ctx.Clone(var->Declaration()->decorations()); + auto decos = ctx.Clone(var->Declaration()->decorations); decos.push_back(disable_validation); auto* param = ctx.dst->Param(new_var_symbol, store_type(), decos); - ctx.InsertFront(func_ast->params(), param); + ctx.InsertFront(func_ast->params, param); } else if (var->StorageClass() == ast::StorageClass::kWorkgroup && ContainsMatrix(var->Type())) { // Due to a bug in the MSL compiler, we use a threadgroup memory @@ -192,7 +192,7 @@ struct ModuleScopeVarToEntryPointParam::State { // TODO(jrprice): Do this for all other workgroup variables too. // Create a member in the workgroup parameter struct. - auto member = ctx.Clone(var->Declaration()->symbol()); + auto member = ctx.Clone(var->Declaration()->symbol); workgroup_parameter_members.push_back( ctx.dst->Member(member, store_type())); CloneStructTypes(var->Type()->UnwrapRef()); @@ -205,7 +205,7 @@ struct ModuleScopeVarToEntryPointParam::State { ctx.dst->ty.pointer( store_type(), ast::StorageClass::kWorkgroup), member_ptr); - ctx.InsertFront(func_ast->body()->statements(), + ctx.InsertFront(func_ast->body->statements, ctx.dst->Decl(local_var)); is_pointer = true; } else { @@ -216,11 +216,11 @@ struct ModuleScopeVarToEntryPointParam::State { ctx.dst->ASTNodes().Create( ctx.dst->ID(), ast::DisabledValidation::kIgnoreStorageClass); - auto* constructor = ctx.Clone(var->Declaration()->constructor()); + auto* constructor = ctx.Clone(var->Declaration()->constructor); auto* local_var = ctx.dst->Var( new_var_symbol, store_type(), var->StorageClass(), constructor, ast::DecorationList{disable_validation}); - ctx.InsertFront(func_ast->body()->statements(), + ctx.InsertFront(func_ast->body->statements, ctx.dst->Decl(local_var)); } } else { @@ -240,7 +240,7 @@ struct ModuleScopeVarToEntryPointParam::State { ast::DisabledValidation::kIgnoreInvalidPointerArgument)); } ctx.InsertBack( - func_ast->params(), + func_ast->params, ctx.dst->Param(new_var_symbol, param_type, attributes)); } @@ -282,12 +282,12 @@ struct ModuleScopeVarToEntryPointParam::State { ctx.dst->ID(), ast::DisabledValidation::kEntryPointParameter); auto* param = ctx.dst->Param(workgroup_param(), param_type, {disable_validation}); - ctx.InsertFront(func_ast->params(), param); + ctx.InsertFront(func_ast->params, param); } // Pass the variables as pointers to any functions that need them. for (auto* call : calls_to_replace[func_ast]) { - auto* target = ctx.src->AST().Functions().Find(call->func()->symbol()); + auto* target = ctx.src->AST().Functions().Find(call->func->symbol); auto* target_sem = ctx.src->Sem().Get(target); // Add new arguments for any variables that are needed by the callee. @@ -305,7 +305,7 @@ struct ModuleScopeVarToEntryPointParam::State { if (is_entry_point && !is_handle && !is_workgroup_matrix) { arg = ctx.dst->AddressOf(arg); } - ctx.InsertBack(call->args(), arg); + ctx.InsertBack(call->args, arg); } } } diff --git a/src/transform/num_workgroups_from_uniform.cc b/src/transform/num_workgroups_from_uniform.cc index ae0148ea0c..4b2815c59f 100644 --- a/src/transform/num_workgroups_from_uniform.cc +++ b/src/transform/num_workgroups_from_uniform.cc @@ -73,7 +73,7 @@ void NumWorkgroupsFromUniform::Run(CloneContext& ctx, std::unordered_set to_replace; for (auto* func : ctx.src->AST().Functions()) { // num_workgroups is only valid for compute stages. - if (func->pipeline_stage() != ast::PipelineStage::kCompute) { + if (func->PipelineStage() != ast::PipelineStage::kCompute) { continue; } @@ -87,8 +87,8 @@ void NumWorkgroupsFromUniform::Run(CloneContext& ctx, for (auto* member : str->Members()) { auto* builtin = ast::GetDecoration( - member->Declaration()->decorations()); - if (!builtin || builtin->value() != ast::Builtin::kNumWorkgroups) { + member->Declaration()->decorations); + if (!builtin || builtin->builtin != ast::Builtin::kNumWorkgroups) { continue; } @@ -96,18 +96,18 @@ void NumWorkgroupsFromUniform::Run(CloneContext& ctx, // we will replace later. We currently have no way to get from the // parameter directly to the member accessor expressions that use it. to_replace.insert( - {param->Declaration()->symbol(), member->Declaration()->symbol()}); + {param->Declaration()->symbol, member->Declaration()->symbol}); // Remove the struct member. // The CanonicalizeEntryPointIO transform will have generated this // struct uniquely for this particular entry point, so we know that // there will be no other uses of this struct in the module and that we // can safely modify it here. - ctx.Remove(str->Declaration()->members(), member->Declaration()); + ctx.Remove(str->Declaration()->members, member->Declaration()); // If this is the only member, remove the struct and parameter too. if (str->Members().size() == 1) { - ctx.Remove(func->params(), param->Declaration()); + ctx.Remove(func->params, param->Declaration()); ctx.Remove(ctx.src->AST().GlobalDeclarations(), str->Declaration()); } } @@ -140,13 +140,13 @@ void NumWorkgroupsFromUniform::Run(CloneContext& ctx, if (!accessor) { continue; } - auto* ident = accessor->structure()->As(); + auto* ident = accessor->structure->As(); if (!ident) { continue; } - if (to_replace.count({ident->symbol(), accessor->member()->symbol()})) { - ctx.Replace(accessor, ctx.dst->MemberAccessor(get_ubo()->symbol(), + if (to_replace.count({ident->symbol, accessor->member->symbol})) { + ctx.Replace(accessor, ctx.dst->MemberAccessor(get_ubo()->symbol, kNumWorkgroupsMemberName)); } } diff --git a/src/transform/pad_array_elements.cc b/src/transform/pad_array_elements.cc index 04358bddb7..ff3f8df2f8 100644 --- a/src/transform/pad_array_elements.cc +++ b/src/transform/pad_array_elements.cc @@ -118,7 +118,7 @@ void PadArrayElements::Run(CloneContext& ctx, const DataMap&, DataMap&) { ctx.ReplaceAll( [&](ast::ArrayAccessorExpression* accessor) -> ast::Expression* { if (auto* array = tint::As( - sem.Get(accessor->array())->Type()->UnwrapRef())) { + sem.Get(accessor->array)->Type()->UnwrapRef())) { if (pad(array)) { // Array element is wrapped in a structure. Emit a member accessor // to get to the actual array element. @@ -136,11 +136,11 @@ void PadArrayElements::Run(CloneContext& ctx, const DataMap&, DataMap&) { tint::As(sem.Get(ctor)->Type()->UnwrapRef())) { if (auto p = pad(array)) { auto* arr_ty = p(); - auto el_typename = arr_ty->type()->As()->name(); + auto el_typename = arr_ty->type->As()->name; ast::ExpressionList args; - args.reserve(ctor->values().size()); - for (auto* arg : ctor->values()) { + args.reserve(ctor->values.size()); + for (auto* arg : ctor->values) { args.emplace_back(ctx.dst->Construct( ctx.dst->create(el_typename), ctx.Clone(arg))); } diff --git a/src/transform/promote_initializers_to_const_var.cc b/src/transform/promote_initializers_to_const_var.cc index 87e7976075..4128d6ff12 100644 --- a/src/transform/promote_initializers_to_const_var.cc +++ b/src/transform/promote_initializers_to_const_var.cc @@ -68,7 +68,7 @@ void PromoteInitializersToConstVar::Run(CloneContext& ctx, auto* src_stmt = src_sem_stmt->Declaration(); if (auto* src_var_decl = src_stmt->As()) { - if (src_var_decl->variable()->constructor() == src_init) { + if (src_var_decl->variable->constructor == src_init) { // This statement is just a variable declaration with the initializer // as the constructor value. This is what we're attempting to // transform to, and so ignore. @@ -81,7 +81,7 @@ void PromoteInitializersToConstVar::Run(CloneContext& ctx, // Create a new symbol for the constant auto dst_symbol = ctx.dst->Sym(); // Clone the type - auto* dst_ty = ctx.Clone(src_init->type()); + auto* dst_ty = ctx.Clone(src_init->type); // Clone the initializer auto* dst_init = ctx.Clone(src_init); // Construct the constant that holds the hoisted initializer @@ -92,7 +92,7 @@ void PromoteInitializersToConstVar::Run(CloneContext& ctx, auto* dst_ident = ctx.dst->Expr(dst_symbol); // Insert the constant before the usage - ctx.InsertBefore(src_sem_stmt->Block()->Declaration()->statements(), + ctx.InsertBefore(src_sem_stmt->Block()->Declaration()->statements, src_stmt, dst_var_decl); // Replace the inlined initializer with a reference to the constant ctx.Replace(src_init, dst_ident); diff --git a/src/transform/renamer.cc b/src/transform/renamer.cc index 9a89cf8902..e9e2f6afbf 100644 --- a/src/transform/renamer.cc +++ b/src/transform/renamer.cc @@ -1115,11 +1115,11 @@ Output Renamer::Run(const Program* in, const DataMap& inputs) { continue; } if (sem->Is()) { - preserve.emplace(member->member()); - } else if (auto* str_expr = in->Sem().Get(member->structure())) { + preserve.emplace(member->member); + } else if (auto* str_expr = in->Sem().Get(member->structure)) { if (auto* ty = str_expr->Type()->UnwrapRef()->As()) { if (ty->Declaration() == nullptr) { // Builtin structure - preserve.emplace(member->member()); + preserve.emplace(member->member); } } } @@ -1131,7 +1131,7 @@ Output Renamer::Run(const Program* in, const DataMap& inputs) { continue; } if (sem->Target()->Is()) { - preserve.emplace(call->func()); + preserve.emplace(call->func); } } } @@ -1190,11 +1190,11 @@ Output Renamer::Run(const Program* in, const DataMap& inputs) { ctx.ReplaceAll( [&](ast::IdentifierExpression* ident) -> ast::IdentifierExpression* { if (preserve.count(ident)) { - auto sym_in = ident->symbol(); + auto sym_in = ident->symbol; auto str = in->Symbols().NameFor(sym_in); auto sym_out = out.Symbols().Register(str); return ctx.dst->create( - ctx.Clone(ident->source()), sym_out); + ctx.Clone(ident->source), sym_out); } return nullptr; // Clone ident. Uses the symbol remapping above. }); diff --git a/src/transform/robustness.cc b/src/transform/robustness.cc index a5f1eacaf1..9aa5a3e76c 100644 --- a/src/transform/robustness.cc +++ b/src/transform/robustness.cc @@ -46,7 +46,7 @@ struct Robustness::State { /// @return the clamped replacement expression, or nullptr if `expr` should be /// cloned without changes. ast::ArrayAccessorExpression* Transform(ast::ArrayAccessorExpression* expr) { - auto* ret_type = ctx.src->Sem().Get(expr->array())->Type()->UnwrapRef(); + auto* ret_type = ctx.src->Sem().Get(expr->array)->Type()->UnwrapRef(); ProgramBuilder& b = *ctx.dst; using u32 = ProgramBuilder::u32; @@ -78,11 +78,11 @@ struct Robustness::State { if (size.u32 == 0) { if (!ret_type->Is()) { b.Diagnostics().add_error(diag::System::Transform, - "invalid 0 sized non-array", expr->source()); + "invalid 0 sized non-array", expr->source); return nullptr; } // Runtime sized array - auto* arr = ctx.Clone(expr->array()); + auto* arr = ctx.Clone(expr->array); size.expr = b.Call("arrayLength", b.AddressOf(arr)); } @@ -101,7 +101,7 @@ struct Robustness::State { Value idx; // index value - auto* idx_sem = ctx.src->Sem().Get(expr->idx_expr()); + auto* idx_sem = ctx.src->Sem().Get(expr->index); auto* idx_ty = idx_sem->Type()->UnwrapRef(); if (!idx_ty->IsAnyOf()) { TINT_ICE(Transform, b.Diagnostics()) @@ -121,12 +121,12 @@ struct Robustness::State { b.Diagnostics().add_error(diag::System::Transform, "unsupported constant value for accessor: " + idx_constant.Type()->type_name(), - expr->source()); + expr->source); return nullptr; } } else { // Dynamic value index - idx.expr = ctx.Clone(expr->idx_expr()); + idx.expr = ctx.Clone(expr->index); idx.is_signed = idx_ty->Is(); } @@ -178,8 +178,8 @@ struct Robustness::State { } // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx.Clone(expr->source()); - auto* arr = ctx.Clone(expr->array()); + auto src = ctx.Clone(expr->source); + auto* arr = ctx.Clone(expr->array); return b.IndexAccessor(src, arr, idx.expr); } @@ -214,8 +214,8 @@ struct Robustness::State { auto array_idx = signature.IndexOf(sem::ParameterUsage::kArrayIndex); auto level_idx = signature.IndexOf(sem::ParameterUsage::kLevel); - auto* texture_arg = expr->args()[texture_idx]; - auto* coords_arg = expr->args()[coords_idx]; + auto* texture_arg = expr->args[texture_idx]; + auto* coords_arg = expr->args[coords_idx]; auto* coords_ty = intrinsic->Parameters()[coords_idx]->Type(); // If the level is provided, then we need to clamp this. As the level is @@ -226,7 +226,7 @@ struct Robustness::State { std::function level_arg; if (level_idx >= 0) { level_arg = [&] { - auto* arg = expr->args()[level_idx]; + auto* arg = expr->args[level_idx]; auto* num_levels = b.Call("textureNumLevels", ctx.Clone(texture_arg)); auto* zero = b.Expr(0); auto* max = ctx.dst->Sub(num_levels, 1); @@ -250,7 +250,7 @@ struct Robustness::State { // Clamp the array_index argument, if provided if (array_idx >= 0) { - auto* arg = expr->args()[array_idx]; + auto* arg = expr->args[array_idx]; auto* num_layers = b.Call("textureNumLayers", ctx.Clone(texture_arg)); auto* zero = b.Expr(0); auto* max = ctx.dst->Sub(num_layers, 1); @@ -260,7 +260,7 @@ struct Robustness::State { // Clamp the level argument, if provided if (level_idx >= 0) { - auto* arg = expr->args()[level_idx]; + auto* arg = expr->args[level_idx]; ctx.Replace(arg, level_arg ? level_arg() : ctx.dst->Expr(0)); } diff --git a/src/transform/simplify.cc b/src/transform/simplify.cc index c007d35fc4..2d414d762d 100644 --- a/src/transform/simplify.cc +++ b/src/transform/simplify.cc @@ -37,16 +37,16 @@ Simplify::~Simplify() = default; void Simplify::Run(CloneContext& ctx, const DataMap&, DataMap&) { ctx.ReplaceAll([&](ast::Expression* expr) -> ast::Expression* { if (auto* outer = expr->As()) { - if (auto* inner = outer->expr()->As()) { - if (outer->op() == ast::UnaryOp::kAddressOf && - inner->op() == ast::UnaryOp::kIndirection) { + if (auto* inner = outer->expr->As()) { + if (outer->op == ast::UnaryOp::kAddressOf && + inner->op == ast::UnaryOp::kIndirection) { // &(*(expr)) => expr - return ctx.Clone(inner->expr()); + return ctx.Clone(inner->expr); } - if (outer->op() == ast::UnaryOp::kIndirection && - inner->op() == ast::UnaryOp::kAddressOf) { + if (outer->op == ast::UnaryOp::kIndirection && + inner->op == ast::UnaryOp::kAddressOf) { // *(&(expr)) => expr - return ctx.Clone(inner->expr()); + return ctx.Clone(inner->expr); } } } diff --git a/src/transform/single_entry_point.cc b/src/transform/single_entry_point.cc index 264d5fa299..9a3135a044 100644 --- a/src/transform/single_entry_point.cc +++ b/src/transform/single_entry_point.cc @@ -47,7 +47,7 @@ void SingleEntryPoint::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) { if (!f->IsEntryPoint()) { continue; } - if (ctx.src->Symbols().NameFor(f->symbol()) == cfg->entry_point_name) { + if (ctx.src->Symbols().NameFor(f->symbol) == cfg->entry_point_name) { entry_point = f; break; } @@ -74,11 +74,11 @@ void SingleEntryPoint::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) { // TODO(jrprice): Strip unused types. ctx.dst->AST().AddTypeDecl(ctx.Clone(ty)); } else if (auto* var = decl->As()) { - if (var->is_const() || referenced_vars.count(var)) { + if (var->is_const || referenced_vars.count(var)) { ctx.dst->AST().AddGlobalVariable(ctx.Clone(var)); } } else if (auto* func = decl->As()) { - if (sem.Get(func)->HasAncestorEntryPoint(entry_point->symbol())) { + if (sem.Get(func)->HasAncestorEntryPoint(entry_point->symbol)) { ctx.dst->AST().AddFunction(ctx.Clone(func)); } } else { diff --git a/src/transform/transform.cc b/src/transform/transform.cc index 8b199a5574..32ca39d39b 100644 --- a/src/transform/transform.cc +++ b/src/transform/transform.cc @@ -78,7 +78,7 @@ bool Transform::Requires(CloneContext& ctx, void Transform::RemoveStatement(CloneContext& ctx, ast::Statement* stmt) { auto* sem = ctx.src->Sem().Get(stmt); if (auto* block = tint::As(sem->Parent())) { - ctx.Remove(block->Declaration()->statements(), stmt); + ctx.Remove(block->Declaration()->statements, stmt); return; } if (tint::Is(sem->Parent())) { @@ -127,7 +127,7 @@ ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const sem::Type* ty) { } } if (auto* s = ty->As()) { - return ctx.dst->create(ctx.Clone(s->Declaration()->name())); + return ctx.dst->create(ctx.Clone(s->Declaration()->name)); } if (auto* s = ty->As()) { return CreateASTTypeFor(ctx, s->StoreType()); diff --git a/src/transform/transform_test.cc b/src/transform/transform_test.cc index 7cd0cdc513..6b9d352a08 100644 --- a/src/transform/transform_test.cc +++ b/src/transform/transform_test.cc @@ -62,9 +62,9 @@ TEST_F(CreateASTTypeForTest, Matrix) { return b.create(column_type, 3u); }); ASSERT_TRUE(mat->Is()); - ASSERT_TRUE(mat->As()->type()->Is()); - ASSERT_EQ(mat->As()->columns(), 3u); - ASSERT_EQ(mat->As()->rows(), 2u); + ASSERT_TRUE(mat->As()->type->Is()); + ASSERT_EQ(mat->As()->columns, 3u); + ASSERT_EQ(mat->As()->rows, 2u); } TEST_F(CreateASTTypeForTest, Vector) { @@ -72,8 +72,8 @@ TEST_F(CreateASTTypeForTest, Vector) { return b.create(b.create(), 2); }); ASSERT_TRUE(vec->Is()); - ASSERT_TRUE(vec->As()->type()->Is()); - ASSERT_EQ(vec->As()->size(), 2u); + ASSERT_TRUE(vec->As()->type->Is()); + ASSERT_EQ(vec->As()->width, 2u); } TEST_F(CreateASTTypeForTest, ArrayImplicitStride) { @@ -81,15 +81,15 @@ TEST_F(CreateASTTypeForTest, ArrayImplicitStride) { return b.create(b.create(), 2, 4, 4, 32u, 32u); }); ASSERT_TRUE(arr->Is()); - ASSERT_TRUE(arr->As()->type()->Is()); - ASSERT_EQ(arr->As()->decorations().size(), 0u); + ASSERT_TRUE(arr->As()->type->Is()); + ASSERT_EQ(arr->As()->decorations.size(), 0u); - auto* size_expr = - arr->As()->Size()->As(); - ASSERT_NE(size_expr, nullptr); - auto* size = size_expr->literal()->As(); + auto* count_expr = + arr->As()->count->As(); + ASSERT_NE(count_expr, nullptr); + auto* size = count_expr->literal->As(); ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value_as_i32(), 2); + EXPECT_EQ(size->ValueAsI32(), 2); } TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) { @@ -97,35 +97,34 @@ TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) { return b.create(b.create(), 2, 4, 4, 64u, 32u); }); ASSERT_TRUE(arr->Is()); - ASSERT_TRUE(arr->As()->type()->Is()); - ASSERT_EQ(arr->As()->decorations().size(), 1u); + ASSERT_TRUE(arr->As()->type->Is()); + ASSERT_EQ(arr->As()->decorations.size(), 1u); ASSERT_TRUE( - arr->As()->decorations()[0]->Is()); + arr->As()->decorations[0]->Is()); ASSERT_EQ(arr->As() - ->decorations()[0] + ->decorations[0] ->As() - ->stride(), + ->stride, 64u); - auto* size_expr = - arr->As()->Size()->As(); - ASSERT_NE(size_expr, nullptr); - auto* size = size_expr->literal()->As(); + auto* count_expr = + arr->As()->count->As(); + ASSERT_NE(count_expr, nullptr); + auto* size = count_expr->literal->As(); ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value_as_i32(), 2); + EXPECT_EQ(size->ValueAsI32(), 2); } TEST_F(CreateASTTypeForTest, Struct) { auto* str = create([](ProgramBuilder& b) { auto* decl = b.Structure("S", {}, {}); - return b.create(decl, decl->name(), sem::StructMemberList{}, + return b.create(decl, decl->name, sem::StructMemberList{}, 4 /* align */, 4 /* size */, 4 /* size_no_padding */); }); ASSERT_TRUE(str->Is()); - EXPECT_EQ( - ast_type_builder.Symbols().NameFor(str->As()->name()), - "S"); + EXPECT_EQ(ast_type_builder.Symbols().NameFor(str->As()->name), + "S"); } } // namespace diff --git a/src/transform/vertex_pulling.cc b/src/transform/vertex_pulling.cc index a44ba63d50..ae89e3dd21 100644 --- a/src/transform/vertex_pulling.cc +++ b/src/transform/vertex_pulling.cc @@ -726,27 +726,27 @@ struct State { /// @param param the parameter to process void ProcessNonStructParameter(ast::Function* func, ast::Variable* param) { if (auto* location = - ast::GetDecoration(param->decorations())) { + ast::GetDecoration(param->decorations)) { // Create a function-scope variable to replace the parameter. - auto func_var_sym = ctx.Clone(param->symbol()); - auto* func_var_type = ctx.Clone(param->type()); + auto func_var_sym = ctx.Clone(param->symbol); + auto* func_var_type = ctx.Clone(param->type); auto* func_var = ctx.dst->Var(func_var_sym, func_var_type); - ctx.InsertFront(func->body()->statements(), ctx.dst->Decl(func_var)); + ctx.InsertFront(func->body->statements, ctx.dst->Decl(func_var)); // Capture mapping from location to the new variable. LocationInfo info; info.expr = [this, func_var]() { return ctx.dst->Expr(func_var); }; info.type = ctx.src->Sem().Get(param)->Type(); - location_info[location->value()] = info; + location_info[location->value] = info; } else if (auto* builtin = ast::GetDecoration( - param->decorations())) { + param->decorations)) { // Check for existing vertex_index and instance_index builtins. - if (builtin->value() == ast::Builtin::kVertexIndex) { + if (builtin->builtin == ast::Builtin::kVertexIndex) { vertex_index_expr = [this, param]() { - return ctx.dst->Expr(ctx.Clone(param->symbol())); + return ctx.dst->Expr(ctx.Clone(param->symbol)); }; - } else if (builtin->value() == ast::Builtin::kInstanceIndex) { + } else if (builtin->builtin == ast::Builtin::kInstanceIndex) { instance_index_expr = [this, param]() { - return ctx.dst->Expr(ctx.Clone(param->symbol())); + return ctx.dst->Expr(ctx.Clone(param->symbol)); }; } new_function_parameters.push_back(ctx.Clone(param)); @@ -767,32 +767,32 @@ struct State { void ProcessStructParameter(ast::Function* func, ast::Variable* param, const ast::Struct* struct_ty) { - auto param_sym = ctx.Clone(param->symbol()); + auto param_sym = ctx.Clone(param->symbol); // Process the struct members. bool has_locations = false; ast::StructMemberList members_to_clone; - for (auto* member : struct_ty->members()) { - auto member_sym = ctx.Clone(member->symbol()); + for (auto* member : struct_ty->members) { + auto member_sym = ctx.Clone(member->symbol); std::function member_expr = [this, param_sym, member_sym]() { return ctx.dst->MemberAccessor(param_sym, member_sym); }; if (auto* location = ast::GetDecoration( - member->decorations())) { + member->decorations)) { // Capture mapping from location to struct member. LocationInfo info; info.expr = member_expr; info.type = ctx.src->Sem().Get(member)->Type(); - location_info[location->value()] = info; + location_info[location->value] = info; has_locations = true; } else if (auto* builtin = ast::GetDecoration( - member->decorations())) { + member->decorations)) { // Check for existing vertex_index and instance_index builtins. - if (builtin->value() == ast::Builtin::kVertexIndex) { + if (builtin->builtin == ast::Builtin::kVertexIndex) { vertex_index_expr = member_expr; - } else if (builtin->value() == ast::Builtin::kInstanceIndex) { + } else if (builtin->builtin == ast::Builtin::kInstanceIndex) { instance_index_expr = member_expr; } members_to_clone.push_back(member); @@ -809,16 +809,16 @@ struct State { } // Create a function-scope variable to replace the parameter. - auto* func_var = ctx.dst->Var(param_sym, ctx.Clone(param->type())); - ctx.InsertFront(func->body()->statements(), ctx.dst->Decl(func_var)); + auto* func_var = ctx.dst->Var(param_sym, ctx.Clone(param->type)); + ctx.InsertFront(func->body->statements, ctx.dst->Decl(func_var)); if (!members_to_clone.empty()) { // Create a new struct without the location attributes. ast::StructMemberList new_members; for (auto* member : members_to_clone) { - auto member_sym = ctx.Clone(member->symbol()); - auto* member_type = ctx.Clone(member->type()); - auto member_decos = ctx.Clone(member->decorations()); + auto member_sym = ctx.Clone(member->symbol); + auto* member_type = ctx.Clone(member->type); + auto member_decos = ctx.Clone(member->decorations); new_members.push_back( ctx.dst->Member(member_sym, member_type, std::move(member_decos))); } @@ -831,9 +831,9 @@ struct State { // Copy values from the new parameter to the function-scope variable. for (auto* member : members_to_clone) { - auto member_name = ctx.Clone(member->symbol()); + auto member_name = ctx.Clone(member->symbol); ctx.InsertFront( - func->body()->statements(), + func->body->statements, ctx.dst->Assign(ctx.dst->MemberAccessor(func_var, member_name), ctx.dst->MemberAccessor(new_param, member_name))); } @@ -843,12 +843,12 @@ struct State { /// Process an entry point function. /// @param func the entry point function void Process(ast::Function* func) { - if (func->body()->empty()) { + if (func->body->Empty()) { return; } // Process entry point parameters. - for (auto* param : func->params()) { + for (auto* param : func->params) { auto* sem = ctx.src->Sem().Get(param); if (auto* str = sem->Type()->As()) { ProcessStructParameter(func, param, str->Declaration()); @@ -885,17 +885,17 @@ struct State { // Generate vertex pulling preamble. if (auto* block = CreateVertexPullingPreamble()) { - ctx.InsertFront(func->body()->statements(), block); + ctx.InsertFront(func->body->statements, block); } // Rewrite the function header with the new parameters. - auto func_sym = ctx.Clone(func->symbol()); - auto* ret_type = ctx.Clone(func->return_type()); - auto* body = ctx.Clone(func->body()); - auto decos = ctx.Clone(func->decorations()); - auto ret_decos = ctx.Clone(func->return_type_decorations()); + auto func_sym = ctx.Clone(func->symbol); + auto* ret_type = ctx.Clone(func->return_type); + auto* body = ctx.Clone(func->body); + auto decos = ctx.Clone(func->decorations); + auto ret_decos = ctx.Clone(func->return_type_decorations); auto* new_func = ctx.dst->create( - func->source(), func_sym, new_function_parameters, ret_type, body, + func->source, func_sym, new_function_parameters, ret_type, body, std::move(decos), std::move(ret_decos)); ctx.Replace(func, new_func); } diff --git a/src/transform/wrap_arrays_in_structs.cc b/src/transform/wrap_arrays_in_structs.cc index b3c315559d..6d6f90cb0c 100644 --- a/src/transform/wrap_arrays_in_structs.cc +++ b/src/transform/wrap_arrays_in_structs.cc @@ -60,14 +60,14 @@ void WrapArraysInStructs::Run(CloneContext& ctx, const DataMap&, DataMap&) { ctx.ReplaceAll([&](ast::ArrayAccessorExpression* accessor) -> ast::ArrayAccessorExpression* { if (auto* array = ::tint::As( - sem.Get(accessor->array())->Type()->UnwrapRef())) { + sem.Get(accessor->array)->Type()->UnwrapRef())) { if (wrapper(array)) { // Array is wrapped in a structure. Emit a member accessor to get // to the actual array. - auto* arr = ctx.Clone(accessor->array()); - auto* idx = ctx.Clone(accessor->idx_expr()); + auto* arr = ctx.Clone(accessor->array); + auto* idx = ctx.Clone(accessor->index); auto* unwrapped = ctx.dst->MemberAccessor(arr, "arr"); - return ctx.dst->IndexAccessor(accessor->source(), unwrapped, idx); + return ctx.dst->IndexAccessor(accessor->source, unwrapped, idx); } } return nullptr; @@ -80,10 +80,9 @@ void WrapArraysInStructs::Run(CloneContext& ctx, const DataMap&, DataMap&) { if (auto w = wrapper(array)) { // Wrap the array type constructor with another constructor for // the wrapper - auto* wrapped_array_ty = ctx.Clone(ctor->type()); + auto* wrapped_array_ty = ctx.Clone(ctor->type); auto* array_ty = w.array_type(ctx); - auto* arr_ctor = - ctx.dst->Construct(array_ty, ctx.Clone(ctor->values())); + auto* arr_ctor = ctx.dst->Construct(array_ty, ctx.Clone(ctor->values)); return ctx.dst->Construct(wrapped_array_ty, arr_ctor); } } diff --git a/src/transform/zero_init_workgroup_memory.cc b/src/transform/zero_init_workgroup_memory.cc index cd3cb553ae..edd51c33a6 100644 --- a/src/transform/zero_init_workgroup_memory.cc +++ b/src/transform/zero_init_workgroup_memory.cc @@ -116,7 +116,7 @@ struct ZeroInitWorkgroupMemory::State { auto& sem = ctx.src->Sem(); CalculateWorkgroupSize( - ast::GetDecoration(fn->decorations())); + ast::GetDecoration(fn->decorations)); // Generate a list of statements to zero initialize each of the // workgroup storage variables used by `fn`. This will populate #statements. @@ -125,7 +125,7 @@ struct ZeroInitWorkgroupMemory::State { if (var->StorageClass() == ast::StorageClass::kWorkgroup) { BuildZeroingStatements( var->Type()->UnwrapRef(), [&](uint32_t num_values) { - auto var_name = ctx.Clone(var->Declaration()->symbol()); + auto var_name = ctx.Clone(var->Declaration()->symbol); return Expression{b.Expr(var_name), num_values, ArrayIndices{}}; }); } @@ -138,11 +138,11 @@ struct ZeroInitWorkgroupMemory::State { // Scan the entry point for an existing local_invocation_index builtin // parameter std::function local_index; - for (auto* param : fn->params()) { - if (auto* builtin = ast::GetDecoration( - param->decorations())) { - if (builtin->value() == ast::Builtin::kLocalInvocationIndex) { - local_index = [=] { return b.Expr(ctx.Clone(param->symbol())); }; + for (auto* param : fn->params) { + if (auto* builtin = + ast::GetDecoration(param->decorations)) { + if (builtin->builtin == ast::Builtin::kLocalInvocationIndex) { + local_index = [=] { return b.Expr(ctx.Clone(param->symbol)); }; break; } } @@ -150,11 +150,11 @@ struct ZeroInitWorkgroupMemory::State { if (auto* str = sem.Get(param)->Type()->As()) { for (auto* member : str->Members()) { if (auto* builtin = ast::GetDecoration( - member->Declaration()->decorations())) { - if (builtin->value() == ast::Builtin::kLocalInvocationIndex) { + member->Declaration()->decorations)) { + if (builtin->builtin == ast::Builtin::kLocalInvocationIndex) { local_index = [=] { - auto* param_expr = b.Expr(ctx.Clone(param->symbol())); - auto member_name = ctx.Clone(member->Declaration()->symbol()); + auto* param_expr = b.Expr(ctx.Clone(param->symbol)); + auto member_name = ctx.Clone(member->Declaration()->symbol); return b.MemberAccessor(param_expr, member_name); }; break; @@ -168,8 +168,8 @@ struct ZeroInitWorkgroupMemory::State { auto* param = b.Param(b.Symbols().New("local_invocation_index"), b.ty.u32(), {b.Builtin(ast::Builtin::kLocalInvocationIndex)}); - ctx.InsertBack(fn->params(), param); - local_index = [=] { return b.Expr(param->symbol()); }; + ctx.InsertBack(fn->params, param); + local_index = [=] { return b.Expr(param->symbol); }; } // Take the zeroing statements and bin them by the number of iterations @@ -225,7 +225,7 @@ struct ZeroInitWorkgroupMemory::State { block.emplace_back(s.stmt); } auto* for_loop = b.For(init, cond, cont, b.Block(block)); - ctx.InsertFront(fn->body()->statements(), for_loop); + ctx.InsertFront(fn->body->statements, for_loop); } else if (num_iterations < workgroup_size_const) { // Workgroup size is a known constant, but is greater than // num_iterations. Emit an if statement: @@ -241,7 +241,7 @@ struct ZeroInitWorkgroupMemory::State { block.emplace_back(s.stmt); } auto* if_stmt = b.If(cond, b.Block(block)); - ctx.InsertFront(fn->body()->statements(), if_stmt); + ctx.InsertFront(fn->body->statements, if_stmt); } else { // Workgroup size exactly equals num_iterations. // No need for any conditionals. Just emit a basic block: @@ -254,12 +254,12 @@ struct ZeroInitWorkgroupMemory::State { for (auto& s : stmts) { block.emplace_back(s.stmt); } - ctx.InsertFront(fn->body()->statements(), b.Block(block)); + ctx.InsertFront(fn->body->statements, b.Block(block)); } } // Append a single workgroup barrier after the zero initialization. - ctx.InsertFront(fn->body()->statements(), + ctx.InsertFront(fn->body->statements, b.create(b.Call("workgroupBarrier"))); } @@ -294,7 +294,7 @@ struct ZeroInitWorkgroupMemory::State { if (auto* str = ty->As()) { for (auto* member : str->Members()) { - auto name = ctx.Clone(member->Declaration()->symbol()); + auto name = ctx.Clone(member->Declaration()->symbol); BuildZeroingStatements(member->Type(), [&](uint32_t num_values) { auto s = get_expr(num_values); return Expression{b.MemberAccessor(s.expr, name), s.num_iterations, @@ -365,7 +365,7 @@ struct ZeroInitWorkgroupMemory::State { bool is_signed = false; workgroup_size_const = 1u; workgroup_size_expr = nullptr; - for (auto* expr : deco->values()) { + for (auto* expr : deco->Values()) { if (!expr) { continue; } @@ -436,7 +436,7 @@ ZeroInitWorkgroupMemory::~ZeroInitWorkgroupMemory() = default; void ZeroInitWorkgroupMemory::Run(CloneContext& ctx, const DataMap&, DataMap&) { for (auto* fn : ctx.src->AST().Functions()) { - if (fn->pipeline_stage() == ast::PipelineStage::kCompute) { + if (fn->PipelineStage() == ast::PipelineStage::kCompute) { State{ctx}.Run(fn); } } diff --git a/src/writer/append_vector.cc b/src/writer/append_vector.cc index ea3da7c553..0da52c0497 100644 --- a/src/writer/append_vector.cc +++ b/src/writer/append_vector.cc @@ -80,7 +80,7 @@ ast::TypeConstructorExpression* AppendVector(ProgramBuilder* b, // In that case, preserve the original argument, or you'll get a type error. ast::ExpressionList packed; if (auto* vc = AsVectorConstructor(b, vector)) { - const auto num_supplied = vc->values().size(); + const auto num_supplied = vc->values.size(); if (num_supplied == 0) { // Zero-value vector constructor. Populate with zeros auto buildZero = [&]() -> ast::ScalarConstructorExpression* { @@ -109,7 +109,7 @@ ast::TypeConstructorExpression* AppendVector(ProgramBuilder* b, } } else if (num_supplied + 1 == packed_size) { // All vector components were supplied as scalars. Pass them through. - packed = vc->values(); + packed = vc->values; } } if (packed.empty()) { diff --git a/src/writer/append_vector_test.cc b/src/writer/append_vector_test.cc index e720c48ac3..39d837cecc 100644 --- a/src/writer/append_vector_test.cc +++ b/src/writer/append_vector_test.cc @@ -37,10 +37,10 @@ TEST_F(AppendVectorTest, Vec2i32_i32) { auto* vec_123 = AppendVector(this, vec_12, scalar_3) ->As(); ASSERT_NE(vec_123, nullptr); - ASSERT_EQ(vec_123->values().size(), 3u); - EXPECT_EQ(vec_123->values()[0], scalar_1); - EXPECT_EQ(vec_123->values()[1], scalar_2); - EXPECT_EQ(vec_123->values()[2], scalar_3); + ASSERT_EQ(vec_123->values.size(), 3u); + EXPECT_EQ(vec_123->values[0], scalar_1); + EXPECT_EQ(vec_123->values[1], scalar_2); + EXPECT_EQ(vec_123->values[2], scalar_3); } TEST_F(AppendVectorTest, Vec2i32_u32) { @@ -56,14 +56,14 @@ TEST_F(AppendVectorTest, Vec2i32_u32) { auto* vec_123 = AppendVector(this, vec_12, scalar_3) ->As(); ASSERT_NE(vec_123, nullptr); - ASSERT_EQ(vec_123->values().size(), 3u); - EXPECT_EQ(vec_123->values()[0], scalar_1); - EXPECT_EQ(vec_123->values()[1], scalar_2); - auto* u32_to_i32 = vec_123->values()[2]->As(); + ASSERT_EQ(vec_123->values.size(), 3u); + EXPECT_EQ(vec_123->values[0], scalar_1); + EXPECT_EQ(vec_123->values[1], scalar_2); + auto* u32_to_i32 = vec_123->values[2]->As(); ASSERT_NE(u32_to_i32, nullptr); - EXPECT_TRUE(u32_to_i32->type()->Is()); - ASSERT_EQ(u32_to_i32->values().size(), 1u); - EXPECT_EQ(u32_to_i32->values()[0], scalar_3); + EXPECT_TRUE(u32_to_i32->type->Is()); + ASSERT_EQ(u32_to_i32->values.size(), 1u); + EXPECT_EQ(u32_to_i32->values[0], scalar_3); } TEST_F(AppendVectorTest, Vec2i32FromVec2u32_u32) { @@ -80,22 +80,21 @@ TEST_F(AppendVectorTest, Vec2i32FromVec2u32_u32) { auto* vec_123 = AppendVector(this, vec_12, scalar_3) ->As(); ASSERT_NE(vec_123, nullptr); - ASSERT_EQ(vec_123->values().size(), 2u); + ASSERT_EQ(vec_123->values.size(), 2u); auto* v2u32_to_v2i32 = - vec_123->values()[0]->As(); + vec_123->values[0]->As(); ASSERT_NE(v2u32_to_v2i32, nullptr); - ASSERT_TRUE(v2u32_to_v2i32->type()->Is()); - EXPECT_EQ(v2u32_to_v2i32->type()->As()->size(), 2u); - EXPECT_TRUE( - v2u32_to_v2i32->type()->As()->type()->Is()); - EXPECT_EQ(v2u32_to_v2i32->values().size(), 1u); - EXPECT_EQ(v2u32_to_v2i32->values()[0], uvec_12); + ASSERT_TRUE(v2u32_to_v2i32->type->Is()); + EXPECT_EQ(v2u32_to_v2i32->type->As()->width, 2u); + EXPECT_TRUE(v2u32_to_v2i32->type->As()->type->Is()); + EXPECT_EQ(v2u32_to_v2i32->values.size(), 1u); + EXPECT_EQ(v2u32_to_v2i32->values[0], uvec_12); - auto* u32_to_i32 = vec_123->values()[1]->As(); + auto* u32_to_i32 = vec_123->values[1]->As(); ASSERT_NE(u32_to_i32, nullptr); - EXPECT_TRUE(u32_to_i32->type()->Is()); - ASSERT_EQ(u32_to_i32->values().size(), 1u); - EXPECT_EQ(u32_to_i32->values()[0], scalar_3); + EXPECT_TRUE(u32_to_i32->type->Is()); + ASSERT_EQ(u32_to_i32->values.size(), 1u); + EXPECT_EQ(u32_to_i32->values[0], scalar_3); } TEST_F(AppendVectorTest, Vec2i32_f32) { @@ -111,14 +110,14 @@ TEST_F(AppendVectorTest, Vec2i32_f32) { auto* vec_123 = AppendVector(this, vec_12, scalar_3) ->As(); ASSERT_NE(vec_123, nullptr); - ASSERT_EQ(vec_123->values().size(), 3u); - EXPECT_EQ(vec_123->values()[0], scalar_1); - EXPECT_EQ(vec_123->values()[1], scalar_2); - auto* f32_to_i32 = vec_123->values()[2]->As(); + ASSERT_EQ(vec_123->values.size(), 3u); + EXPECT_EQ(vec_123->values[0], scalar_1); + EXPECT_EQ(vec_123->values[1], scalar_2); + auto* f32_to_i32 = vec_123->values[2]->As(); ASSERT_NE(f32_to_i32, nullptr); - EXPECT_TRUE(f32_to_i32->type()->Is()); - ASSERT_EQ(f32_to_i32->values().size(), 1u); - EXPECT_EQ(f32_to_i32->values()[0], scalar_3); + EXPECT_TRUE(f32_to_i32->type->Is()); + ASSERT_EQ(f32_to_i32->values.size(), 1u); + EXPECT_EQ(f32_to_i32->values[0], scalar_3); } TEST_F(AppendVectorTest, Vec3i32_i32) { @@ -135,11 +134,11 @@ TEST_F(AppendVectorTest, Vec3i32_i32) { auto* vec_1234 = AppendVector(this, vec_123, scalar_4) ->As(); ASSERT_NE(vec_1234, nullptr); - ASSERT_EQ(vec_1234->values().size(), 4u); - EXPECT_EQ(vec_1234->values()[0], scalar_1); - EXPECT_EQ(vec_1234->values()[1], scalar_2); - EXPECT_EQ(vec_1234->values()[2], scalar_3); - EXPECT_EQ(vec_1234->values()[3], scalar_4); + ASSERT_EQ(vec_1234->values.size(), 4u); + EXPECT_EQ(vec_1234->values[0], scalar_1); + EXPECT_EQ(vec_1234->values[1], scalar_2); + EXPECT_EQ(vec_1234->values[2], scalar_3); + EXPECT_EQ(vec_1234->values[3], scalar_4); } TEST_F(AppendVectorTest, Vec2i32Var_i32) { @@ -154,9 +153,9 @@ TEST_F(AppendVectorTest, Vec2i32Var_i32) { auto* vec_123 = AppendVector(this, vec_12, scalar_3) ->As(); ASSERT_NE(vec_123, nullptr); - ASSERT_EQ(vec_123->values().size(), 2u); - EXPECT_EQ(vec_123->values()[0], vec_12); - EXPECT_EQ(vec_123->values()[1], scalar_3); + ASSERT_EQ(vec_123->values.size(), 2u); + EXPECT_EQ(vec_123->values[0], vec_12); + EXPECT_EQ(vec_123->values[1], scalar_3); } TEST_F(AppendVectorTest, Vec2i32_i32Var) { @@ -173,10 +172,10 @@ TEST_F(AppendVectorTest, Vec2i32_i32Var) { auto* vec_123 = AppendVector(this, vec_12, scalar_3) ->As(); ASSERT_NE(vec_123, nullptr); - ASSERT_EQ(vec_123->values().size(), 3u); - EXPECT_EQ(vec_123->values()[0], scalar_1); - EXPECT_EQ(vec_123->values()[1], scalar_2); - EXPECT_EQ(vec_123->values()[2], scalar_3); + ASSERT_EQ(vec_123->values.size(), 3u); + EXPECT_EQ(vec_123->values[0], scalar_1); + EXPECT_EQ(vec_123->values[1], scalar_2); + EXPECT_EQ(vec_123->values[2], scalar_3); } TEST_F(AppendVectorTest, Vec2i32Var_i32Var) { @@ -192,9 +191,9 @@ TEST_F(AppendVectorTest, Vec2i32Var_i32Var) { auto* vec_123 = AppendVector(this, vec_12, scalar_3) ->As(); ASSERT_NE(vec_123, nullptr); - ASSERT_EQ(vec_123->values().size(), 2u); - EXPECT_EQ(vec_123->values()[0], vec_12); - EXPECT_EQ(vec_123->values()[1], scalar_3); + ASSERT_EQ(vec_123->values.size(), 2u); + EXPECT_EQ(vec_123->values[0], vec_12); + EXPECT_EQ(vec_123->values[1], scalar_3); } TEST_F(AppendVectorTest, Vec2i32Var_f32Var) { @@ -210,13 +209,13 @@ TEST_F(AppendVectorTest, Vec2i32Var_f32Var) { auto* vec_123 = AppendVector(this, vec_12, scalar_3) ->As(); ASSERT_NE(vec_123, nullptr); - ASSERT_EQ(vec_123->values().size(), 2u); - EXPECT_EQ(vec_123->values()[0], vec_12); - auto* f32_to_i32 = vec_123->values()[1]->As(); + ASSERT_EQ(vec_123->values.size(), 2u); + EXPECT_EQ(vec_123->values[0], vec_12); + auto* f32_to_i32 = vec_123->values[1]->As(); ASSERT_NE(f32_to_i32, nullptr); - EXPECT_TRUE(f32_to_i32->type()->Is()); - ASSERT_EQ(f32_to_i32->values().size(), 1u); - EXPECT_EQ(f32_to_i32->values()[0], scalar_3); + EXPECT_TRUE(f32_to_i32->type->Is()); + ASSERT_EQ(f32_to_i32->values.size(), 1u); + EXPECT_EQ(f32_to_i32->values[0], scalar_3); } TEST_F(AppendVectorTest, Vec2boolVar_boolVar) { @@ -232,9 +231,9 @@ TEST_F(AppendVectorTest, Vec2boolVar_boolVar) { auto* vec_123 = AppendVector(this, vec_12, scalar_3) ->As(); ASSERT_NE(vec_123, nullptr); - ASSERT_EQ(vec_123->values().size(), 2u); - EXPECT_EQ(vec_123->values()[0], vec_12); - EXPECT_EQ(vec_123->values()[1], scalar_3); + ASSERT_EQ(vec_123->values.size(), 2u); + EXPECT_EQ(vec_123->values[0], vec_12); + EXPECT_EQ(vec_123->values[1], scalar_3); } TEST_F(AppendVectorTest, ZeroVec3i32_i32) { @@ -248,15 +247,15 @@ TEST_F(AppendVectorTest, ZeroVec3i32_i32) { auto* vec_0004 = AppendVector(this, vec000, scalar)->As(); ASSERT_NE(vec_0004, nullptr); - ASSERT_EQ(vec_0004->values().size(), 4u); + ASSERT_EQ(vec_0004->values.size(), 4u); for (size_t i = 0; i < 3; i++) { - auto* ctor = vec_0004->values()[i]->As(); + auto* ctor = vec_0004->values[i]->As(); ASSERT_NE(ctor, nullptr); - auto* literal = As(ctor->literal()); + auto* literal = As(ctor->literal); ASSERT_NE(literal, nullptr); - EXPECT_EQ(literal->value(), 0); + EXPECT_EQ(literal->value, 0); } - EXPECT_EQ(vec_0004->values()[3], scalar); + EXPECT_EQ(vec_0004->values[3], scalar); } } // namespace diff --git a/src/writer/glsl/generator.cc b/src/writer/glsl/generator.cc index a03e7ca0ae..101b7baa30 100644 --- a/src/writer/glsl/generator.cc +++ b/src/writer/glsl/generator.cc @@ -50,8 +50,8 @@ Result Generate(const Program* program, // Collect the list of entry points in the sanitized program. for (auto* func : output.program.AST().Functions()) { if (func->IsEntryPoint()) { - auto name = output.program.Symbols().NameFor(func->symbol()); - result.entry_points.push_back({name, func->pipeline_stage()}); + auto name = output.program.Symbols().NameFor(func->symbol); + result.entry_points.push_back({name, func->PipelineStage()}); } } diff --git a/src/writer/glsl/generator_impl.cc b/src/writer/glsl/generator_impl.cc index 54aa31e203..c5a8aa0f08 100644 --- a/src/writer/glsl/generator_impl.cc +++ b/src/writer/glsl/generator_impl.cc @@ -59,12 +59,7 @@ const char kTempNamePrefix[] = "tint_tmp"; const char kSpecConstantPrefix[] = "WGSL_SPEC_CONSTANT_"; bool last_is_break_or_fallthrough(const ast::BlockStatement* stmts) { - if (stmts->empty()) { - return false; - } - - return stmts->last()->Is() || - stmts->last()->Is(); + return IsAnyOf(stmts->Last()); } const char* image_format_to_rwtexture_type(ast::ImageFormat image_format) { @@ -164,12 +159,12 @@ bool GeneratorImpl::Generate() { bool GeneratorImpl::EmitArrayAccessor(std::ostream& out, ast::ArrayAccessorExpression* expr) { - if (!EmitExpression(out, expr->array())) { + if (!EmitExpression(out, expr->array)) { return false; } out << "["; - if (!EmitExpression(out, expr->idx_expr())) { + if (!EmitExpression(out, expr->index)) { return false; } out << "]"; @@ -196,7 +191,7 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, return false; } out << "("; - if (!EmitExpression(out, expr->expr())) { + if (!EmitExpression(out, expr->expr)) { return false; } out << ")"; @@ -205,11 +200,11 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, bool GeneratorImpl::EmitAssign(ast::AssignmentStatement* stmt) { auto out = line(); - if (!EmitExpression(out, stmt->lhs())) { + if (!EmitExpression(out, stmt->lhs)) { return false; } out << " = "; - if (!EmitExpression(out, stmt->rhs())) { + if (!EmitExpression(out, stmt->rhs)) { return false; } out << ";"; @@ -217,20 +212,20 @@ bool GeneratorImpl::EmitAssign(ast::AssignmentStatement* stmt) { } bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { - if (expr->op() == ast::BinaryOp::kLogicalAnd || - expr->op() == ast::BinaryOp::kLogicalOr) { + if (expr->op == ast::BinaryOp::kLogicalAnd || + expr->op == ast::BinaryOp::kLogicalOr) { auto name = UniqueIdentifier(kTempNamePrefix); { auto pre = line(); pre << "bool " << name << " = "; - if (!EmitExpression(pre, expr->lhs())) { + if (!EmitExpression(pre, expr->lhs)) { return false; } pre << ";"; } - if (expr->op() == ast::BinaryOp::kLogicalOr) { + if (expr->op == ast::BinaryOp::kLogicalOr) { line() << "if (!" << name << ") {"; } else { line() << "if (" << name << ") {"; @@ -240,7 +235,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { ScopedIndent si(this); auto pre = line(); pre << name << " = "; - if (!EmitExpression(pre, expr->rhs())) { + if (!EmitExpression(pre, expr->rhs)) { return false; } pre << ";"; @@ -253,12 +248,12 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { } out << "("; - if (!EmitExpression(out, expr->lhs())) { + if (!EmitExpression(out, expr->lhs)) { return false; } out << " "; - switch (expr->op()) { + switch (expr->op) { case ast::BinaryOp::kAnd: out << "&"; break; @@ -325,7 +320,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { } out << " "; - if (!EmitExpression(out, expr->rhs())) { + if (!EmitExpression(out, expr->rhs)) { return false; } @@ -349,7 +344,7 @@ bool GeneratorImpl::EmitStatementsWithIndent(const ast::StatementList& stmts) { bool GeneratorImpl::EmitBlock(const ast::BlockStatement* stmt) { line() << "{"; - if (!EmitStatementsWithIndent(stmt->statements())) { + if (!EmitStatementsWithIndent(stmt->statements)) { return false; } line() << "}"; @@ -362,15 +357,15 @@ bool GeneratorImpl::EmitBreak(ast::BreakStatement*) { } bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { - const auto& args = expr->args(); - auto* ident = expr->func(); + const auto& args = expr->args; + auto* ident = expr->func; auto* call = builder_.Sem().Get(expr); auto* target = call->Target(); if (auto* func = target->As()) { if (ast::HasDecoration< transform::CalculateArrayLength::BufferSizeIntrinsic>( - func->Declaration()->decorations())) { + func->Declaration()->decorations)) { // Special function generated by the CalculateArrayLength transform for // calling X.GetDimensions(Y) if (!EmitExpression(out, args[0])) { @@ -397,7 +392,7 @@ bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { } else if (intrinsic->Type() == sem::IntrinsicType::kIsNormal) { return EmitIsNormalCall(out, expr, intrinsic); } else if (intrinsic->Type() == sem::IntrinsicType::kIgnore) { - return EmitExpression(out, expr->args()[0]); + return EmitExpression(out, expr->args[0]); } else if (intrinsic->IsDataPacking()) { return EmitDataPackingCall(out, expr, intrinsic); } else if (intrinsic->IsDataUnpacking()) { @@ -430,14 +425,14 @@ bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { return true; } - auto name = builder_.Symbols().NameFor(ident->symbol()); - auto caller_sym = ident->symbol(); + auto name = builder_.Symbols().NameFor(ident->symbol); + auto caller_sym = ident->symbol; - auto* func = builder_.AST().Functions().Find(ident->symbol()); + auto* func = builder_.AST().Functions().Find(ident->symbol); if (func == nullptr) { diagnostics_.add_error(diag::System::Writer, "Unable to find function: " + - builder_.Symbols().NameFor(ident->symbol())); + builder_.Symbols().NameFor(ident->symbol)); return false; } @@ -484,8 +479,8 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, { ScopedParen sp(pre); - for (size_t i = 0; i < expr->args().size(); i++) { - auto* arg = expr->args()[i]; + for (size_t i = 0; i < expr->args.size(); i++) { + auto* arg = expr->args[i]; if (i > 0) { pre << ", "; } @@ -511,7 +506,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, pre << "InterlockedOr"; { ScopedParen sp(pre); - if (!EmitExpression(pre, expr->args()[0])) { + if (!EmitExpression(pre, expr->args[0])) { return false; } pre << ", 0, " << result; @@ -541,11 +536,11 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, out << "InterlockedExchange"; { ScopedParen sp(out); - if (!EmitExpression(out, expr->args()[0])) { + if (!EmitExpression(out, expr->args[0])) { return false; } out << ", "; - if (!EmitExpression(out, expr->args()[1])) { + if (!EmitExpression(out, expr->args[1])) { return false; } out << ", " << result; @@ -553,9 +548,9 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, return true; } case sem::IntrinsicType::kAtomicCompareExchangeWeak: { - auto* dest = expr->args()[0]; - auto* compare_value = expr->args()[1]; - auto* value = expr->args()[2]; + auto* dest = expr->args[0]; + auto* compare_value = expr->args[1]; + auto* value = expr->args[2]; std::string compare = UniqueIdentifier("atomic_compare_value"); @@ -631,9 +626,9 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, bool GeneratorImpl::EmitSelectCall(std::ostream& out, ast::CallExpression* expr) { - auto* expr_false = expr->args()[0]; - auto* expr_true = expr->args()[1]; - auto* expr_cond = expr->args()[2]; + auto* expr_false = expr->args[0]; + auto* expr_true = expr->args[1]; + auto* expr_cond = expr->args[2]; ScopedParen paren(out); if (!EmitExpression(out, expr_cond)) { return false; @@ -657,7 +652,7 @@ bool GeneratorImpl::EmitSelectCall(std::ostream& out, bool GeneratorImpl::EmitModfCall(std::ostream& out, ast::CallExpression* expr, const sem::Intrinsic* intrinsic) { - if (expr->args().size() == 1) { + if (expr->args.size() == 1) { return CallIntrinsicHelper( out, expr, intrinsic, [&](TextBuffer* b, const std::vector& params) { @@ -694,11 +689,11 @@ bool GeneratorImpl::EmitModfCall(std::ostream& out, // DEPRECATED out << "modf"; ScopedParen sp(out); - if (!EmitExpression(out, expr->args()[0])) { + if (!EmitExpression(out, expr->args[0])) { return false; } out << ", "; - if (!EmitExpression(out, expr->args()[1])) { + if (!EmitExpression(out, expr->args[1])) { return false; } return true; @@ -707,7 +702,7 @@ bool GeneratorImpl::EmitModfCall(std::ostream& out, bool GeneratorImpl::EmitFrexpCall(std::ostream& out, ast::CallExpression* expr, const sem::Intrinsic* intrinsic) { - if (expr->args().size() == 1) { + if (expr->args.size() == 1) { return CallIntrinsicHelper( out, expr, intrinsic, [&](TextBuffer* b, const std::vector& params) { @@ -961,7 +956,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, using Usage = sem::ParameterUsage; auto& signature = intrinsic->Signature(); - auto arguments = expr->args(); + auto arguments = expr->args; // Returns the argument with the given usage auto arg = [&](Usage usage) { @@ -1261,14 +1256,14 @@ bool GeneratorImpl::EmitCase(ast::CaseStatement* stmt) { if (stmt->IsDefault()) { line() << "default: {"; } else { - for (auto* selector : stmt->selectors()) { + for (auto* selector : stmt->selectors) { auto out = line(); out << "case "; if (!EmitLiteral(out, selector)) { return false; } out << ":"; - if (selector == stmt->selectors().back()) { + if (selector == stmt->selectors.back()) { out << " {"; } } @@ -1276,10 +1271,10 @@ bool GeneratorImpl::EmitCase(ast::CaseStatement* stmt) { { ScopedIndent si(this); - if (!EmitStatements(stmt->body()->statements())) { + if (!EmitStatements(stmt->body->statements)) { return false; } - if (!last_is_break_or_fallthrough(stmt->body())) { + if (!last_is_break_or_fallthrough(stmt->body)) { line() << "break;"; } } @@ -1300,7 +1295,7 @@ bool GeneratorImpl::EmitConstructor(std::ostream& out, bool GeneratorImpl::EmitScalarConstructor( std::ostream& out, ast::ScalarConstructorExpression* expr) { - return EmitLiteral(out, expr->literal()); + return EmitLiteral(out, expr->literal); } bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, @@ -1309,15 +1304,15 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, // If the type constructor is empty then we need to construct with the zero // value for all components. - if (expr->values().empty()) { + if (expr->values.empty()) { return EmitZeroValue(out, type); } // For single-value vector initializers, swizzle the scalar to the right // vector dimension using .x const bool is_single_value_vector_init = - type->is_scalar_vector() && expr->values().size() == 1 && - TypeOf(expr->values()[0])->UnwrapRef()->is_scalar(); + type->is_scalar_vector() && expr->values.size() == 1 && + TypeOf(expr->values[0])->UnwrapRef()->is_scalar(); auto it = structure_builders_.find(As(type)); if (it != structure_builders_.end()) { @@ -1335,7 +1330,7 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, } bool first = true; - for (auto* e : expr->values()) { + for (auto* e : expr->values) { if (!first) { out << ", "; } @@ -1403,7 +1398,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& out, ast::Expression* expr) { bool GeneratorImpl::EmitIdentifier(std::ostream& out, ast::IdentifierExpression* expr) { - out << builder_.Symbols().NameFor(expr->symbol()); + out << builder_.Symbols().NameFor(expr->symbol); return true; } @@ -1411,25 +1406,25 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { { auto out = line(); out << "if ("; - if (!EmitExpression(out, stmt->condition())) { + if (!EmitExpression(out, stmt->condition)) { return false; } out << ") {"; } - if (!EmitStatementsWithIndent(stmt->body()->statements())) { + if (!EmitStatementsWithIndent(stmt->body->statements)) { return false; } - for (auto* e : stmt->else_statements()) { - if (e->HasCondition()) { + for (auto* e : stmt->else_statements) { + if (e->condition) { line() << "} else {"; increment_indent(); { auto out = line(); out << "if ("; - if (!EmitExpression(out, e->condition())) { + if (!EmitExpression(out, e->condition)) { return false; } out << ") {"; @@ -1438,15 +1433,15 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { line() << "} else {"; } - if (!EmitStatementsWithIndent(e->body()->statements())) { + if (!EmitStatementsWithIndent(e->body->statements)) { return false; } } line() << "}"; - for (auto* e : stmt->else_statements()) { - if (e->HasCondition()) { + for (auto* e : stmt->else_statements) { + if (e->condition) { decrement_indent(); line() << "}"; } @@ -1457,14 +1452,14 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { bool GeneratorImpl::EmitFunction(ast::Function* func) { auto* sem = builder_.Sem().Get(func); - if (ast::HasDecoration(func->decorations())) { + if (ast::HasDecoration(func->decorations)) { // An internal function. Do not emit. return true; } { auto out = line(); - auto name = builder_.Symbols().NameFor(func->symbol()); + auto name = builder_.Symbols().NameFor(func->symbol); // If the function returns an array, then we need to declare a typedef for // this. if (sem->ReturnType()->Is()) { @@ -1513,14 +1508,14 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { // storage buffers and a uint4[N] for uniform buffers. if (!EmitTypeAndName( out, type, v->StorageClass(), v->Access(), - builder_.Symbols().NameFor(v->Declaration()->symbol()))) { + builder_.Symbols().NameFor(v->Declaration()->symbol))) { return false; } } out << ") {"; } - if (!EmitStatementsWithIndent(func->body()->statements())) { + if (!EmitStatementsWithIndent(func->body->statements)) { return false; } @@ -1530,7 +1525,7 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { } bool GeneratorImpl::EmitGlobalVariable(ast::Variable* global) { - if (global->is_const()) { + if (global->is_const) { return EmitProgramConstVariable(global); } @@ -1560,7 +1555,7 @@ bool GeneratorImpl::EmitUniformVariable(const sem::Variable* var) { auto* type = var->Type()->UnwrapRef(); auto out = line(); if (!EmitTypeAndName(out, type, ast::StorageClass::kUniform, var->Access(), - builder_.Symbols().NameFor(decl->symbol()))) { + builder_.Symbols().NameFor(decl->symbol))) { return false; } out << ";"; @@ -1573,7 +1568,7 @@ bool GeneratorImpl::EmitStorageVariable(const sem::Variable* var) { auto* type = var->Type()->UnwrapRef(); auto out = line(); if (!EmitTypeAndName(out, type, ast::StorageClass::kStorage, var->Access(), - builder_.Symbols().NameFor(decl->symbol()))) { + builder_.Symbols().NameFor(decl->symbol))) { return false; } @@ -1586,7 +1581,7 @@ bool GeneratorImpl::EmitHandleVariable(const sem::Variable* var) { auto* decl = var->Declaration(); auto out = line(); - auto name = builder_.Symbols().NameFor(decl->symbol()); + auto name = builder_.Symbols().NameFor(decl->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->StorageClass(), var->Access(), name)) { return false; @@ -1600,14 +1595,14 @@ bool GeneratorImpl::EmitPrivateVariable(const sem::Variable* var) { auto* decl = var->Declaration(); auto out = line(); - auto name = builder_.Symbols().NameFor(decl->symbol()); + auto name = builder_.Symbols().NameFor(decl->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->StorageClass(), var->Access(), name)) { return false; } out << " = "; - if (auto* constructor = decl->constructor()) { + if (auto* constructor = decl->constructor) { if (!EmitExpression(out, constructor)) { return false; } @@ -1627,13 +1622,13 @@ bool GeneratorImpl::EmitWorkgroupVariable(const sem::Variable* var) { out << "groupshared "; - auto name = builder_.Symbols().NameFor(decl->symbol()); + auto name = builder_.Symbols().NameFor(decl->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->StorageClass(), var->Access(), name)) { return false; } - if (auto* constructor = decl->constructor()) { + if (auto* constructor = decl->constructor) { out << " = "; if (!EmitExpression(out, constructor)) { return false; @@ -1739,7 +1734,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { { auto out = line(); - if (func->pipeline_stage() == ast::PipelineStage::kCompute) { + if (func->PipelineStage() == ast::PipelineStage::kCompute) { // Emit the layout(local_size) attributes. auto wgsize = func_sem->workgroup_size(); out << "layout("; @@ -1764,14 +1759,14 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { out << ") in;" << std::endl; } - out << func->return_type()->FriendlyName(builder_.Symbols()); + out << func->return_type->FriendlyName(builder_.Symbols()); - out << " " << builder_.Symbols().NameFor(func->symbol()) << "("; + out << " " << builder_.Symbols().NameFor(func->symbol) << "("; bool first = true; // Emit entry point parameters. - for (auto* var : func->params()) { + for (auto* var : func->params) { auto* sem = builder_.Sem().Get(var); auto* type = sem->Type(); if (!type->Is()) { @@ -1787,7 +1782,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { first = false; if (!EmitTypeAndName(out, type, sem->StorageClass(), sem->Access(), - builder_.Symbols().NameFor(var->symbol()))) { + builder_.Symbols().NameFor(var->symbol))) { return false; } } @@ -1798,11 +1793,11 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { { ScopedIndent si(this); - if (!EmitStatements(func->body()->statements())) { + if (!EmitStatements(func->body->statements)) { return false; } - if (!Is(func->get_last_statement())) { + if (!Is(func->body->Last())) { ast::ReturnStatement ret(ProgramID(), Source{}); if (!EmitStatement(&ret)) { return false; @@ -1815,18 +1810,18 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { auto out = line(); // Declare entry point input variables - for (auto* var : func->params()) { + for (auto* var : func->params) { auto* sem = builder_.Sem().Get(var); auto* str = sem->Type()->As(); for (auto* member : str->Members()) { if (ast::HasDecoration( - member->Declaration()->decorations())) { + member->Declaration()->decorations)) { continue; } if (!EmitTypeAndName( out, member->Type(), ast::StorageClass::kInput, ast::Access::kReadWrite, - builder_.Symbols().NameFor(member->Declaration()->symbol()))) { + builder_.Symbols().NameFor(member->Declaration()->symbol))) { return false; } out << ";" << std::endl; @@ -1838,13 +1833,13 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { if (return_type) { for (auto* member : return_type->Members()) { if (ast::HasDecoration( - member->Declaration()->decorations())) { + member->Declaration()->decorations)) { continue; } if (!EmitTypeAndName( out, member->Type(), ast::StorageClass::kOutput, ast::Access::kReadWrite, - builder_.Symbols().NameFor(member->Declaration()->symbol()))) { + builder_.Symbols().NameFor(member->Declaration()->symbol))) { return false; } out << ";" << std::endl; @@ -1854,7 +1849,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { // Create a main() function which calls the entry point. out << "void main() {" << std::endl; std::string printed_name; - for (auto* var : func->params()) { + for (auto* var : func->params) { out << " "; auto* sem = builder_.Sem().Get(var); if (!EmitTypeAndName(out, sem->Type(), sem->StorageClass(), sem->Access(), @@ -1866,20 +1861,20 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { auto* str = type->As(); for (auto* member : str->Members()) { std::string name = - builder_.Symbols().NameFor(member->Declaration()->symbol()); + builder_.Symbols().NameFor(member->Declaration()->symbol); out << " inputs." << name << " = "; if (auto* builtin = ast::GetDecoration( - member->Declaration()->decorations())) { - if (builtin_type(builtin->value()) != member->Type()) { + member->Declaration()->decorations)) { + if (builtin_type(builtin->builtin) != member->Type()) { if (!EmitType(out, member->Type(), ast::StorageClass::kNone, ast::Access::kReadWrite, "")) { return false; } out << "("; - out << builtin_to_string(builtin->value()); + out << builtin_to_string(builtin->builtin); out << ")"; } else { - out << builtin_to_string(builtin->value()); + out << builtin_to_string(builtin->builtin); } } else { out << name; @@ -1893,8 +1888,8 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { << "outputs;" << std::endl; out << " outputs = "; } - out << builder_.Symbols().NameFor(func->symbol()); - if (func->params().empty()) { + out << builder_.Symbols().NameFor(func->symbol); + if (func->params.empty()) { out << "()"; } else { out << "(inputs)"; @@ -1905,11 +1900,11 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { if (str) { for (auto* member : str->Members()) { std::string name = - builder_.Symbols().NameFor(member->Declaration()->symbol()); + builder_.Symbols().NameFor(member->Declaration()->symbol); out << " "; if (auto* builtin = ast::GetDecoration( - member->Declaration()->decorations())) { - out << builtin_to_string(builtin->value()); + member->Declaration()->decorations)) { + out << builtin_to_string(builtin->builtin); } else { out << name; } @@ -1924,20 +1919,19 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { bool GeneratorImpl::EmitLiteral(std::ostream& out, ast::Literal* lit) { if (auto* l = lit->As()) { - out << (l->IsTrue() ? "true" : "false"); + out << (l->value ? "true" : "false"); } else if (auto* fl = lit->As()) { - if (std::isinf(fl->value())) { - out << (fl->value() >= 0 ? "asfloat(0x7f800000u)" - : "asfloat(0xff800000u)"); - } else if (std::isnan(fl->value())) { + if (std::isinf(fl->value)) { + out << (fl->value >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)"); + } else if (std::isnan(fl->value)) { out << "asfloat(0x7fc00000u)"; } else { - out << FloatToString(fl->value()) << "f"; + out << FloatToString(fl->value) << "f"; } } else if (auto* sl = lit->As()) { - out << sl->value(); + out << sl->value; } else if (auto* ul = lit->As()) { - out << ul->value() << "u"; + out << ul->value << "u"; } else { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); return false; @@ -2022,8 +2016,8 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const sem::Type* type) { bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { auto emit_continuing = [this, stmt]() { - if (stmt->has_continuing()) { - if (!EmitBlock(stmt->continuing())) { + if (stmt->continuing && !stmt->continuing->Empty()) { + if (!EmitBlock(stmt->continuing)) { return false; } } @@ -2034,7 +2028,7 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { line() << "while (true) {"; { ScopedIndent si(this); - if (!EmitStatements(stmt->body()->statements())) { + if (!EmitStatements(stmt->body->statements)) { return false; } if (!emit_continuing()) { @@ -2057,7 +2051,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { }); TextBuffer init_buf; - if (auto* init = stmt->initializer()) { + if (auto* init = stmt->initializer) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &init_buf); if (!EmitStatement(init)) { return false; @@ -2066,7 +2060,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { TextBuffer cond_pre; std::stringstream cond_buf; - if (auto* cond = stmt->condition()) { + if (auto* cond = stmt->condition) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &cond_pre); if (!EmitExpression(cond_buf, cond)) { return false; @@ -2074,7 +2068,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { } TextBuffer cont_buf; - if (auto* cont = stmt->continuing()) { + if (auto* cont = stmt->continuing) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &cont_buf); if (!EmitStatement(cont)) { return false; @@ -2089,7 +2083,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { // If the for-loop has multi-statement initializer, or is going to be emitted // as a `while(true)` loop, then declare the initializer statement(s) before // the loop. - if (init_buf.lines.size() > 1 || (stmt->initializer() && emit_as_loop)) { + if (init_buf.lines.size() > 1 || (stmt->initializer && emit_as_loop)) { current_buffer_->Append(init_buf); init_buf.lines.clear(); // Don't emit the initializer again in the 'for' } @@ -2108,12 +2102,12 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { line() << "}"; }); - if (stmt->condition()) { + if (stmt->condition) { current_buffer_->Append(cond_pre); line() << "if (!(" << cond_buf.str() << ")) { break; }"; } - if (!EmitStatements(stmt->body()->statements())) { + if (!EmitStatements(stmt->body->statements)) { return false; } @@ -2145,7 +2139,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { { auto emit_continuing = [] { return true; }; TINT_SCOPED_ASSIGNMENT(emit_continuing_, emit_continuing); - if (!EmitStatementsWithIndent(stmt->body()->statements())) { + if (!EmitStatementsWithIndent(stmt->body->statements)) { return false; } } @@ -2157,15 +2151,15 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { bool GeneratorImpl::EmitMemberAccessor(std::ostream& out, ast::MemberAccessorExpression* expr) { - if (!EmitExpression(out, expr->structure())) { + if (!EmitExpression(out, expr->structure)) { return false; } out << "."; // Swizzles output the name directly if (builder_.Sem().Get(expr)->Is()) { - out << builder_.Symbols().NameFor(expr->member()->symbol()); - } else if (!EmitExpression(out, expr->member())) { + out << builder_.Symbols().NameFor(expr->member->symbol); + } else if (!EmitExpression(out, expr->member)) { return false; } @@ -2173,10 +2167,10 @@ bool GeneratorImpl::EmitMemberAccessor(std::ostream& out, } bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) { - if (stmt->has_value()) { + if (stmt->value) { auto out = line(); out << "return "; - if (!EmitExpression(out, stmt->value())) { + if (!EmitExpression(out, stmt->value)) { return false; } out << ";"; @@ -2198,10 +2192,10 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) { } if (auto* c = stmt->As()) { auto out = line(); - if (!TypeOf(c->expr())->Is()) { + if (!TypeOf(c->expr)->Is()) { out << "(void) "; } - if (!EmitCall(out, c->expr())) { + if (!EmitCall(out, c->expr)) { return false; } out << ";"; @@ -2233,7 +2227,7 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) { return EmitSwitch(s); } if (auto* v = stmt->As()) { - return EmitVariable(v->variable()); + return EmitVariable(v->variable); } diagnostics_.add_error( @@ -2246,7 +2240,7 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) { { // switch(expr) { auto out = line(); out << "switch("; - if (!EmitExpression(out, stmt->condition())) { + if (!EmitExpression(out, stmt->condition)) { return false; } out << ") {"; @@ -2254,7 +2248,7 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) { { ScopedIndent si(this); - for (auto* s : stmt->body()) { + for (auto* s : stmt->body) { if (!EmitCase(s)) { return false; } @@ -2476,7 +2470,7 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { std::string pre, post; if (auto* decl = mem->Declaration()) { - for (auto* deco : decl->decorations()) { + for (auto* deco : decl->decorations) { if (deco->As()) { auto& pipeline_stage_uses = str->PipelineStageUses(); if (pipeline_stage_uses.size() != 1) { @@ -2485,8 +2479,8 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { } } else if (auto* interpolate = deco->As()) { - auto mod = interpolation_to_modifiers(interpolate->type(), - interpolate->sampling()); + auto mod = interpolation_to_modifiers(interpolate->type, + interpolate->sampling); if (mod.empty()) { diagnostics_.add_error(diag::System::Writer, "unsupported interpolation"); @@ -2512,10 +2506,10 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { bool GeneratorImpl::EmitUnaryOp(std::ostream& out, ast::UnaryOpExpression* expr) { - switch (expr->op()) { + switch (expr->op) { case ast::UnaryOp::kIndirection: case ast::UnaryOp::kAddressOf: - return EmitExpression(out, expr->expr()); + return EmitExpression(out, expr->expr); case ast::UnaryOp::kComplement: out << "~"; break; @@ -2528,7 +2522,7 @@ bool GeneratorImpl::EmitUnaryOp(std::ostream& out, } out << "("; - if (!EmitExpression(out, expr->expr())) { + if (!EmitExpression(out, expr->expr)) { return false; } @@ -2542,7 +2536,7 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) { auto* type = sem->Type()->UnwrapRef(); // TODO(dsinclair): Handle variable decorations - if (!var->decorations().empty()) { + if (!var->decorations.empty()) { diagnostics_.add_error(diag::System::Writer, "Variable decorations are not handled yet"); return false; @@ -2551,14 +2545,14 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) { auto out = line(); // TODO(senorblanco): handle const if (!EmitTypeAndName(out, type, sem->StorageClass(), sem->Access(), - builder_.Symbols().NameFor(var->symbol()))) { + builder_.Symbols().NameFor(var->symbol))) { return false; } out << " = "; - if (var->constructor()) { - if (!EmitExpression(out, var->constructor())) { + if (var->constructor) { + if (!EmitExpression(out, var->constructor)) { return false; } } else { @@ -2572,14 +2566,14 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) { } bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { - for (auto* d : var->decorations()) { + for (auto* d : var->decorations) { if (!d->Is()) { diagnostics_.add_error(diag::System::Writer, "Decorated const values not valid"); return false; } } - if (!var->is_const()) { + if (!var->is_const) { diagnostics_.add_error(diag::System::Writer, "Expected a const value"); return false; } @@ -2593,10 +2587,10 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { line() << "#ifndef " << kSpecConstantPrefix << const_id; - if (var->constructor() != nullptr) { + if (var->constructor != nullptr) { auto out = line(); out << "#define " << kSpecConstantPrefix << const_id << " "; - if (!EmitExpression(out, var->constructor())) { + if (!EmitExpression(out, var->constructor)) { return false; } } else { @@ -2607,7 +2601,7 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { auto out = line(); out << "const "; if (!EmitTypeAndName(out, type, sem->StorageClass(), sem->Access(), - builder_.Symbols().NameFor(var->symbol()))) { + builder_.Symbols().NameFor(var->symbol))) { return false; } out << " = " << kSpecConstantPrefix << const_id << ";"; @@ -2616,11 +2610,11 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { auto out = line(); out << "const "; if (!EmitTypeAndName(out, type, sem->StorageClass(), sem->Access(), - builder_.Symbols().NameFor(var->symbol()))) { + builder_.Symbols().NameFor(var->symbol))) { return false; } out << " = "; - if (!EmitExpression(out, var->constructor())) { + if (!EmitExpression(out, var->constructor)) { return false; } out << ";"; @@ -2690,7 +2684,7 @@ bool GeneratorImpl::CallIntrinsicHelper(std::ostream& out, { ScopedParen sp(out); bool first = true; - for (auto* arg : call->args()) { + for (auto* arg : call->args) { if (!first) { out << ", "; } diff --git a/src/writer/glsl/generator_impl_case_test.cc b/src/writer/glsl/generator_impl_case_test.cc index 10d1c51047..e12a4966e6 100644 --- a/src/writer/glsl/generator_impl_case_test.cc +++ b/src/writer/glsl/generator_impl_case_test.cc @@ -31,7 +31,7 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( case 5: { break; } @@ -46,7 +46,7 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( case 5: { break; } @@ -63,7 +63,7 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( case 5: { /* fallthrough */ } @@ -80,7 +80,7 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( case 5: case 6: { break; @@ -96,7 +96,7 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case_Default) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( default: { break; } diff --git a/src/writer/glsl/generator_impl_intrinsic_texture_test.cc b/src/writer/glsl/generator_impl_intrinsic_texture_test.cc index 16075d83ac..e053753560 100644 --- a/src/writer/glsl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/glsl/generator_impl_intrinsic_texture_test.cc @@ -236,8 +236,8 @@ class GlslGeneratorIntrinsicTextureTest TEST_P(GlslGeneratorIntrinsicTextureTest, Call) { auto param = GetParam(); - param.buildTextureVariable(this); - param.buildSamplerVariable(this); + param.BuildTextureVariable(this); + param.BuildSamplerVariable(this); auto* call = Call(param.function, param.args(this)); auto* stmt = ast::intrinsic::test::ReturnsVoid(param.overload) diff --git a/src/writer/hlsl/generator.cc b/src/writer/hlsl/generator.cc index 2f9a58a7df..ce172f9a99 100644 --- a/src/writer/hlsl/generator.cc +++ b/src/writer/hlsl/generator.cc @@ -45,8 +45,8 @@ Result Generate(const Program* program, const Options& options) { // Collect the list of entry points in the sanitized program. for (auto* func : sanitized_result.program.AST().Functions()) { if (func->IsEntryPoint()) { - auto name = sanitized_result.program.Symbols().NameFor(func->symbol()); - result.entry_points.push_back({name, func->pipeline_stage()}); + auto name = sanitized_result.program.Symbols().NameFor(func->symbol); + result.entry_points.push_back({name, func->PipelineStage()}); } } diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 90eeaa0687..b690e89bed 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -99,16 +99,16 @@ const char* image_format_to_rwtexture_type(ast::ImageFormat image_format) { // Helper for writing " : register(RX, spaceY)", where R is the register, X is // the binding point binding value, and Y is the binding point group value. struct RegisterAndSpace { - RegisterAndSpace(char r, ast::Variable::BindingPoint bp) + RegisterAndSpace(char r, ast::VariableBindingPoint bp) : reg(r), binding_point(bp) {} char const reg; - ast::Variable::BindingPoint const binding_point; + ast::VariableBindingPoint const binding_point; }; std::ostream& operator<<(std::ostream& s, const RegisterAndSpace& rs) { - s << " : register(" << rs.reg << rs.binding_point.binding->value() - << ", space" << rs.binding_point.group->value() << ")"; + s << " : register(" << rs.reg << rs.binding_point.binding->value << ", space" + << rs.binding_point.group->value << ")"; return s; } @@ -286,19 +286,19 @@ bool GeneratorImpl::EmitDynamicVectorAssignment( return false; } - auto* ast_access_expr = stmt->lhs()->As(); + auto* ast_access_expr = stmt->lhs->As(); auto out = line(); out << name << "("; - if (!EmitExpression(out, ast_access_expr->array())) { + if (!EmitExpression(out, ast_access_expr->array)) { return false; } out << ", "; - if (!EmitExpression(out, ast_access_expr->idx_expr())) { + if (!EmitExpression(out, ast_access_expr->index)) { return false; } out << ", "; - if (!EmitExpression(out, stmt->rhs())) { + if (!EmitExpression(out, stmt->rhs)) { return false; } out << ");"; @@ -308,12 +308,12 @@ bool GeneratorImpl::EmitDynamicVectorAssignment( bool GeneratorImpl::EmitArrayAccessor(std::ostream& out, ast::ArrayAccessorExpression* expr) { - if (!EmitExpression(out, expr->array())) { + if (!EmitExpression(out, expr->array)) { return false; } out << "["; - if (!EmitExpression(out, expr->idx_expr())) { + if (!EmitExpression(out, expr->index)) { return false; } out << "]"; @@ -340,7 +340,7 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, return false; } out << "("; - if (!EmitExpression(out, expr->expr())) { + if (!EmitExpression(out, expr->expr)) { return false; } out << ")"; @@ -348,9 +348,9 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, } bool GeneratorImpl::EmitAssign(ast::AssignmentStatement* stmt) { - if (auto* idx = stmt->lhs()->As()) { - if (auto* vec = TypeOf(idx->array())->UnwrapRef()->As()) { - auto* rhs_sem = builder_.Sem().Get(idx->idx_expr()); + if (auto* idx = stmt->lhs->As()) { + if (auto* vec = TypeOf(idx->array)->UnwrapRef()->As()) { + auto* rhs_sem = builder_.Sem().Get(idx->index); if (!rhs_sem->ConstantValue().IsValid()) { return EmitDynamicVectorAssignment(stmt, vec); } @@ -358,11 +358,11 @@ bool GeneratorImpl::EmitAssign(ast::AssignmentStatement* stmt) { } auto out = line(); - if (!EmitExpression(out, stmt->lhs())) { + if (!EmitExpression(out, stmt->lhs)) { return false; } out << " = "; - if (!EmitExpression(out, stmt->rhs())) { + if (!EmitExpression(out, stmt->rhs)) { return false; } out << ";"; @@ -370,20 +370,20 @@ bool GeneratorImpl::EmitAssign(ast::AssignmentStatement* stmt) { } bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { - if (expr->op() == ast::BinaryOp::kLogicalAnd || - expr->op() == ast::BinaryOp::kLogicalOr) { + if (expr->op == ast::BinaryOp::kLogicalAnd || + expr->op == ast::BinaryOp::kLogicalOr) { auto name = UniqueIdentifier(kTempNamePrefix); { auto pre = line(); pre << "bool " << name << " = "; - if (!EmitExpression(pre, expr->lhs())) { + if (!EmitExpression(pre, expr->lhs)) { return false; } pre << ";"; } - if (expr->op() == ast::BinaryOp::kLogicalOr) { + if (expr->op == ast::BinaryOp::kLogicalOr) { line() << "if (!" << name << ") {"; } else { line() << "if (" << name << ") {"; @@ -393,7 +393,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { ScopedIndent si(this); auto pre = line(); pre << name << " = "; - if (!EmitExpression(pre, expr->rhs())) { + if (!EmitExpression(pre, expr->rhs)) { return false; } pre << ";"; @@ -405,21 +405,21 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { return true; } - auto* lhs_type = TypeOf(expr->lhs())->UnwrapRef(); - auto* rhs_type = TypeOf(expr->rhs())->UnwrapRef(); + auto* lhs_type = TypeOf(expr->lhs)->UnwrapRef(); + auto* rhs_type = TypeOf(expr->rhs)->UnwrapRef(); // Multiplying by a matrix requires the use of `mul` in order to get the // type of multiply we desire. - if (expr->op() == ast::BinaryOp::kMultiply && + if (expr->op == ast::BinaryOp::kMultiply && ((lhs_type->Is() && rhs_type->Is()) || (lhs_type->Is() && rhs_type->Is()) || (lhs_type->Is() && rhs_type->Is()))) { // Matrices are transposed, so swap LHS and RHS. out << "mul("; - if (!EmitExpression(out, expr->rhs())) { + if (!EmitExpression(out, expr->rhs)) { return false; } out << ", "; - if (!EmitExpression(out, expr->lhs())) { + if (!EmitExpression(out, expr->lhs)) { return false; } out << ")"; @@ -430,12 +430,12 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { out << "("; TINT_DEFER(out << ")"); - if (!EmitExpression(out, expr->lhs())) { + if (!EmitExpression(out, expr->lhs)) { return false; } out << " "; - switch (expr->op()) { + switch (expr->op) { case ast::BinaryOp::kAnd: out << "&"; break; @@ -492,7 +492,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { case ast::BinaryOp::kDivide: out << "/"; - if (auto val = program_->Sem().Get(expr->rhs())->ConstantValue()) { + if (auto val = program_->Sem().Get(expr->rhs)->ConstantValue()) { // Integer divide by zero is a DXC compile error, and undefined behavior // in WGSL. Replace the 0 with 1. if (val.Type()->Is() && val.Elements()[0].i32 == 0) { @@ -515,7 +515,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { } out << " "; - if (!EmitExpression(out, expr->rhs())) { + if (!EmitExpression(out, expr->rhs)) { return false; } @@ -538,7 +538,7 @@ bool GeneratorImpl::EmitStatementsWithIndent(const ast::StatementList& stmts) { bool GeneratorImpl::EmitBlock(const ast::BlockStatement* stmt) { line() << "{"; - if (!EmitStatementsWithIndent(stmt->statements())) { + if (!EmitStatementsWithIndent(stmt->statements)) { return false; } line() << "}"; @@ -551,15 +551,15 @@ bool GeneratorImpl::EmitBreak(ast::BreakStatement*) { } bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { - const auto& args = expr->args(); - auto* ident = expr->func(); + const auto& args = expr->args; + auto* ident = expr->func; auto* call = builder_.Sem().Get(expr); auto* target = call->Target(); if (auto* func = target->As()) { if (ast::HasDecoration< transform::CalculateArrayLength::BufferSizeIntrinsic>( - func->Declaration()->decorations())) { + func->Declaration()->decorations)) { // Special function generated by the CalculateArrayLength transform for // calling X.GetDimensions(Y) if (!EmitExpression(out, args[0])) { @@ -575,7 +575,7 @@ bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { if (auto* intrinsic = ast::GetDecoration( - func->Declaration()->decorations())) { + func->Declaration()->decorations)) { switch (intrinsic->storage_class) { case ast::StorageClass::kUniform: return EmitUniformBufferAccess(out, expr, intrinsic); @@ -602,7 +602,7 @@ bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { } else if (intrinsic->Type() == sem::IntrinsicType::kIsNormal) { return EmitIsNormalCall(out, expr, intrinsic); } else if (intrinsic->Type() == sem::IntrinsicType::kIgnore) { - return EmitExpression(out, expr->args()[0]); + return EmitExpression(out, expr->args[0]); } else if (intrinsic->IsDataPacking()) { return EmitDataPackingCall(out, expr, intrinsic); } else if (intrinsic->IsDataUnpacking()) { @@ -635,14 +635,14 @@ bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { return true; } - auto name = builder_.Symbols().NameFor(ident->symbol()); - auto caller_sym = ident->symbol(); + auto name = builder_.Symbols().NameFor(ident->symbol); + auto caller_sym = ident->symbol; - auto* func = builder_.AST().Functions().Find(ident->symbol()); + auto* func = builder_.AST().Functions().Find(ident->symbol); if (func == nullptr) { diagnostics_.add_error(diag::System::Writer, "Unable to find function: " + - builder_.Symbols().NameFor(ident->symbol())); + builder_.Symbols().NameFor(ident->symbol)); return false; } @@ -669,7 +669,7 @@ bool GeneratorImpl::EmitUniformBufferAccess( std::ostream& out, ast::CallExpression* expr, const transform::DecomposeMemoryAccess::Intrinsic* intrinsic) { - const auto& args = expr->args(); + const auto& args = expr->args; auto* offset_arg = builder_.Sem().Get(args[1]); uint32_t scalar_offset_value = 0; @@ -808,7 +808,7 @@ bool GeneratorImpl::EmitStorageBufferAccess( std::ostream& out, ast::CallExpression* expr, const transform::DecomposeMemoryAccess::Intrinsic* intrinsic) { - const auto& args = expr->args(); + const auto& args = expr->args; using Op = transform::DecomposeMemoryAccess::Intrinsic::Op; using DataType = transform::DecomposeMemoryAccess::Intrinsic::DataType; @@ -1057,7 +1057,7 @@ bool GeneratorImpl::EmitStorageAtomicCall( case Op::kAtomicStore: { // HLSL does not have an InterlockedStore, so we emulate it with // InterlockedExchange and discard the returned value - auto* value_ty = TypeOf(expr->args()[2])->UnwrapRef(); + auto* value_ty = TypeOf(expr->args[2])->UnwrapRef(); auto name = UniqueIdentifier("atomicStore"); { auto fn = line(&buf); @@ -1088,7 +1088,7 @@ bool GeneratorImpl::EmitStorageAtomicCall( return name; } case Op::kAtomicCompareExchangeWeak: { - auto* value_ty = TypeOf(expr->args()[2])->UnwrapRef(); + auto* value_ty = TypeOf(expr->args[2])->UnwrapRef(); auto name = UniqueIdentifier("atomicCompareExchangeWeak"); { @@ -1151,7 +1151,7 @@ bool GeneratorImpl::EmitStorageAtomicCall( { ScopedParen sp(out); bool first = true; - for (auto* arg : expr->args()) { + for (auto* arg : expr->args) { if (!first) { out << ", "; } @@ -1189,8 +1189,8 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, { ScopedParen sp(pre); - for (size_t i = 0; i < expr->args().size(); i++) { - auto* arg = expr->args()[i]; + for (size_t i = 0; i < expr->args.size(); i++) { + auto* arg = expr->args[i]; if (i > 0) { pre << ", "; } @@ -1220,7 +1220,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, pre << "InterlockedOr"; { ScopedParen sp(pre); - if (!EmitExpression(pre, expr->args()[0])) { + if (!EmitExpression(pre, expr->args[0])) { return false; } pre << ", 0, " << result; @@ -1250,11 +1250,11 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, out << "InterlockedExchange"; { ScopedParen sp(out); - if (!EmitExpression(out, expr->args()[0])) { + if (!EmitExpression(out, expr->args[0])) { return false; } out << ", "; - if (!EmitExpression(out, expr->args()[1])) { + if (!EmitExpression(out, expr->args[1])) { return false; } out << ", " << result; @@ -1262,9 +1262,9 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, return true; } case sem::IntrinsicType::kAtomicCompareExchangeWeak: { - auto* dest = expr->args()[0]; - auto* compare_value = expr->args()[1]; - auto* value = expr->args()[2]; + auto* dest = expr->args[0]; + auto* compare_value = expr->args[1]; + auto* value = expr->args[2]; std::string compare = UniqueIdentifier("atomic_compare_value"); @@ -1340,9 +1340,9 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out, bool GeneratorImpl::EmitSelectCall(std::ostream& out, ast::CallExpression* expr) { - auto* expr_false = expr->args()[0]; - auto* expr_true = expr->args()[1]; - auto* expr_cond = expr->args()[2]; + auto* expr_false = expr->args[0]; + auto* expr_true = expr->args[1]; + auto* expr_cond = expr->args[2]; ScopedParen paren(out); if (!EmitExpression(out, expr_cond)) { return false; @@ -1621,7 +1621,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, using Usage = sem::ParameterUsage; auto& signature = intrinsic->Signature(); - auto arguments = expr->args(); + auto arguments = expr->args; // Returns the argument with the given usage auto arg = [&](Usage usage) { @@ -2057,18 +2057,18 @@ std::string GeneratorImpl::generate_builtin_name( } bool GeneratorImpl::EmitCase(ast::SwitchStatement* s, size_t case_idx) { - auto* stmt = s->body()[case_idx]; + auto* stmt = s->body[case_idx]; if (stmt->IsDefault()) { line() << "default: {"; } else { - for (auto* selector : stmt->selectors()) { + for (auto* selector : stmt->selectors) { auto out = line(); out << "case "; if (!EmitLiteral(out, selector)) { return false; } out << ":"; - if (selector == stmt->selectors().back()) { + if (selector == stmt->selectors.back()) { out << " {"; } } @@ -2081,23 +2081,23 @@ bool GeneratorImpl::EmitCase(ast::SwitchStatement* s, size_t case_idx) { }); // Emit the case statement - if (!EmitStatements(stmt->body()->statements())) { + if (!EmitStatements(stmt->body->statements)) { return false; } // Inline all fallthrough case statements. FXC cannot handle fallthroughs. - while (tint::Is(stmt->body()->last())) { + while (tint::Is(stmt->body->Last())) { case_idx++; - stmt = s->body()[case_idx]; + stmt = s->body[case_idx]; // Generate each fallthrough case statement in a new block. This is done to // prevent symbol collision of variables declared in these cases statements. - if (!EmitBlock(stmt->body())) { + if (!EmitBlock(stmt->body)) { return false; } } if (!tint::IsAnyOf( - stmt->body()->last())) { + stmt->body->Last())) { line() << "break;"; } @@ -2115,7 +2115,7 @@ bool GeneratorImpl::EmitConstructor(std::ostream& out, bool GeneratorImpl::EmitScalarConstructor( std::ostream& out, ast::ScalarConstructorExpression* expr) { - return EmitLiteral(out, expr->literal()); + return EmitLiteral(out, expr->literal); } bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, @@ -2124,7 +2124,7 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, // If the type constructor is empty then we need to construct with the zero // value for all components. - if (expr->values().empty()) { + if (expr->values.empty()) { return EmitZeroValue(out, type); } @@ -2133,8 +2133,8 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, // For single-value vector initializers, swizzle the scalar to the right // vector dimension using .x const bool is_single_value_vector_init = - type->is_scalar_vector() && expr->values().size() == 1 && - TypeOf(expr->values()[0])->UnwrapRef()->is_scalar(); + type->is_scalar_vector() && expr->values.size() == 1 && + TypeOf(expr->values[0])->UnwrapRef()->is_scalar(); auto it = structure_builders_.find(As(type)); if (it != structure_builders_.end()) { @@ -2155,7 +2155,7 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, } bool first = true; - for (auto* e : expr->values()) { + for (auto* e : expr->values) { if (!first) { out << ", "; } @@ -2223,7 +2223,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& out, ast::Expression* expr) { bool GeneratorImpl::EmitIdentifier(std::ostream& out, ast::IdentifierExpression* expr) { - out << builder_.Symbols().NameFor(expr->symbol()); + out << builder_.Symbols().NameFor(expr->symbol); return true; } @@ -2231,25 +2231,25 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { { auto out = line(); out << "if ("; - if (!EmitExpression(out, stmt->condition())) { + if (!EmitExpression(out, stmt->condition)) { return false; } out << ") {"; } - if (!EmitStatementsWithIndent(stmt->body()->statements())) { + if (!EmitStatementsWithIndent(stmt->body->statements)) { return false; } - for (auto* e : stmt->else_statements()) { - if (e->HasCondition()) { + for (auto* e : stmt->else_statements) { + if (e->condition) { line() << "} else {"; increment_indent(); { auto out = line(); out << "if ("; - if (!EmitExpression(out, e->condition())) { + if (!EmitExpression(out, e->condition)) { return false; } out << ") {"; @@ -2258,15 +2258,15 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { line() << "} else {"; } - if (!EmitStatementsWithIndent(e->body()->statements())) { + if (!EmitStatementsWithIndent(e->body->statements)) { return false; } } line() << "}"; - for (auto* e : stmt->else_statements()) { - if (e->HasCondition()) { + for (auto* e : stmt->else_statements) { + if (e->condition) { decrement_indent(); line() << "}"; } @@ -2277,14 +2277,14 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { bool GeneratorImpl::EmitFunction(ast::Function* func) { auto* sem = builder_.Sem().Get(func); - if (ast::HasDecoration(func->decorations())) { + if (ast::HasDecoration(func->decorations)) { // An internal function. Do not emit. return true; } { auto out = line(); - auto name = builder_.Symbols().NameFor(func->symbol()); + auto name = builder_.Symbols().NameFor(func->symbol); // If the function returns an array, then we need to declare a typedef for // this. if (sem->ReturnType()->Is()) { @@ -2333,14 +2333,14 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { // storage buffers and a uint4[N] for uniform buffers. if (!EmitTypeAndName( out, type, v->StorageClass(), v->Access(), - builder_.Symbols().NameFor(v->Declaration()->symbol()))) { + builder_.Symbols().NameFor(v->Declaration()->symbol))) { return false; } } out << ") {"; } - if (!EmitStatementsWithIndent(func->body()->statements())) { + if (!EmitStatementsWithIndent(func->body->statements)) { return false; } @@ -2350,7 +2350,7 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { } bool GeneratorImpl::EmitGlobalVariable(ast::Variable* global) { - if (global->is_const()) { + if (global->is_const) { return EmitProgramConstVariable(global); } @@ -2377,7 +2377,7 @@ bool GeneratorImpl::EmitGlobalVariable(ast::Variable* global) { bool GeneratorImpl::EmitUniformVariable(const sem::Variable* var) { auto* decl = var->Declaration(); - auto binding_point = decl->binding_point(); + auto binding_point = decl->BindingPoint(); auto* type = var->Type()->UnwrapRef(); auto* str = type->As(); @@ -2387,7 +2387,7 @@ bool GeneratorImpl::EmitUniformVariable(const sem::Variable* var) { << "variables with uniform storage must be structure"; } - auto name = builder_.Symbols().NameFor(decl->symbol()); + auto name = builder_.Symbols().NameFor(decl->symbol); line() << "cbuffer cbuffer_" << name << RegisterAndSpace('b', binding_point) << " {"; @@ -2411,12 +2411,12 @@ bool GeneratorImpl::EmitStorageVariable(const sem::Variable* var) { auto* type = var->Type()->UnwrapRef(); auto out = line(); if (!EmitTypeAndName(out, type, ast::StorageClass::kStorage, var->Access(), - builder_.Symbols().NameFor(decl->symbol()))) { + builder_.Symbols().NameFor(decl->symbol))) { return false; } out << RegisterAndSpace(var->Access() == ast::Access::kRead ? 't' : 'u', - decl->binding_point()) + decl->BindingPoint()) << ";"; return true; @@ -2427,7 +2427,7 @@ bool GeneratorImpl::EmitHandleVariable(const sem::Variable* var) { auto* unwrapped_type = var->Type()->UnwrapRef(); auto out = line(); - auto name = builder_.Symbols().NameFor(decl->symbol()); + auto name = builder_.Symbols().NameFor(decl->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->StorageClass(), var->Access(), name)) { return false; @@ -2445,9 +2445,9 @@ bool GeneratorImpl::EmitHandleVariable(const sem::Variable* var) { } if (register_space) { - auto bp = decl->binding_point(); - out << " : register(" << register_space << bp.binding->value() << ", space" - << bp.group->value() << ")"; + auto bp = decl->BindingPoint(); + out << " : register(" << register_space << bp.binding->value << ", space" + << bp.group->value << ")"; } out << ";"; @@ -2460,14 +2460,14 @@ bool GeneratorImpl::EmitPrivateVariable(const sem::Variable* var) { out << "static "; - auto name = builder_.Symbols().NameFor(decl->symbol()); + auto name = builder_.Symbols().NameFor(decl->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->StorageClass(), var->Access(), name)) { return false; } out << " = "; - if (auto* constructor = decl->constructor()) { + if (auto* constructor = decl->constructor) { if (!EmitExpression(out, constructor)) { return false; } @@ -2487,13 +2487,13 @@ bool GeneratorImpl::EmitWorkgroupVariable(const sem::Variable* var) { out << "groupshared "; - auto name = builder_.Symbols().NameFor(decl->symbol()); + auto name = builder_.Symbols().NameFor(decl->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->StorageClass(), var->Access(), name)) { return false; } - if (auto* constructor = decl->constructor()) { + if (auto* constructor = decl->constructor) { out << " = "; if (!EmitExpression(out, constructor)) { return false; @@ -2568,7 +2568,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { { auto out = line(); - if (func->pipeline_stage() == ast::PipelineStage::kCompute) { + if (func->PipelineStage() == ast::PipelineStage::kCompute) { // Emit the workgroup_size attribute. auto wgsize = func_sem->workgroup_size(); out << "[numthreads("; @@ -2592,14 +2592,14 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { out << ")]" << std::endl; } - out << func->return_type()->FriendlyName(builder_.Symbols()); + out << func->return_type->FriendlyName(builder_.Symbols()); - out << " " << builder_.Symbols().NameFor(func->symbol()) << "("; + out << " " << builder_.Symbols().NameFor(func->symbol) << "("; bool first = true; // Emit entry point parameters. - for (auto* var : func->params()) { + for (auto* var : func->params) { auto* sem = builder_.Sem().Get(var); auto* type = sem->Type(); if (!type->Is()) { @@ -2615,7 +2615,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { first = false; if (!EmitTypeAndName(out, type, sem->StorageClass(), sem->Access(), - builder_.Symbols().NameFor(var->symbol()))) { + builder_.Symbols().NameFor(var->symbol))) { return false; } } @@ -2626,11 +2626,11 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { { ScopedIndent si(this); - if (!EmitStatements(func->body()->statements())) { + if (!EmitStatements(func->body->statements)) { return false; } - if (!Is(func->get_last_statement())) { + if (!Is(func->body->Last())) { ast::ReturnStatement ret(ProgramID(), Source{}); if (!EmitStatement(&ret)) { return false; @@ -2645,20 +2645,19 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { bool GeneratorImpl::EmitLiteral(std::ostream& out, ast::Literal* lit) { if (auto* l = lit->As()) { - out << (l->IsTrue() ? "true" : "false"); + out << (l->value ? "true" : "false"); } else if (auto* fl = lit->As()) { - if (std::isinf(fl->value())) { - out << (fl->value() >= 0 ? "asfloat(0x7f800000u)" - : "asfloat(0xff800000u)"); - } else if (std::isnan(fl->value())) { + if (std::isinf(fl->value)) { + out << (fl->value >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)"); + } else if (std::isnan(fl->value)) { out << "asfloat(0x7fc00000u)"; } else { - out << FloatToString(fl->value()) << "f"; + out << FloatToString(fl->value) << "f"; } } else if (auto* sl = lit->As()) { - out << sl->value(); + out << sl->value; } else if (auto* ul = lit->As()) { - out << ul->value() << "u"; + out << ul->value << "u"; } else { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); return false; @@ -2721,8 +2720,8 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const sem::Type* type) { bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { auto emit_continuing = [this, stmt]() { - if (stmt->has_continuing()) { - if (!EmitBlock(stmt->continuing())) { + if (stmt->continuing && !stmt->continuing->Empty()) { + if (!EmitBlock(stmt->continuing)) { return false; } } @@ -2733,7 +2732,7 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { line() << "while (true) {"; { ScopedIndent si(this); - if (!EmitStatements(stmt->body()->statements())) { + if (!EmitStatements(stmt->body->statements)) { return false; } if (!emit_continuing()) { @@ -2756,7 +2755,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { }); TextBuffer init_buf; - if (auto* init = stmt->initializer()) { + if (auto* init = stmt->initializer) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &init_buf); if (!EmitStatement(init)) { return false; @@ -2765,7 +2764,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { TextBuffer cond_pre; std::stringstream cond_buf; - if (auto* cond = stmt->condition()) { + if (auto* cond = stmt->condition) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &cond_pre); if (!EmitExpression(cond_buf, cond)) { return false; @@ -2773,7 +2772,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { } TextBuffer cont_buf; - if (auto* cont = stmt->continuing()) { + if (auto* cont = stmt->continuing) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &cont_buf); if (!EmitStatement(cont)) { return false; @@ -2788,7 +2787,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { // If the for-loop has multi-statement initializer, or is going to be emitted // as a `while(true)` loop, then declare the initializer statement(s) before // the loop. - if (init_buf.lines.size() > 1 || (stmt->initializer() && emit_as_loop)) { + if (init_buf.lines.size() > 1 || (stmt->initializer && emit_as_loop)) { current_buffer_->Append(init_buf); init_buf.lines.clear(); // Don't emit the initializer again in the 'for' } @@ -2807,12 +2806,12 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { line() << "}"; }); - if (stmt->condition()) { + if (stmt->condition) { current_buffer_->Append(cond_pre); line() << "if (!(" << cond_buf.str() << ")) { break; }"; } - if (!EmitStatements(stmt->body()->statements())) { + if (!EmitStatements(stmt->body->statements)) { return false; } @@ -2844,7 +2843,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { { auto emit_continuing = [] { return true; }; TINT_SCOPED_ASSIGNMENT(emit_continuing_, emit_continuing); - if (!EmitStatementsWithIndent(stmt->body()->statements())) { + if (!EmitStatementsWithIndent(stmt->body->statements)) { return false; } } @@ -2856,15 +2855,15 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { bool GeneratorImpl::EmitMemberAccessor(std::ostream& out, ast::MemberAccessorExpression* expr) { - if (!EmitExpression(out, expr->structure())) { + if (!EmitExpression(out, expr->structure)) { return false; } out << "."; // Swizzles output the name directly if (builder_.Sem().Get(expr)->Is()) { - out << builder_.Symbols().NameFor(expr->member()->symbol()); - } else if (!EmitExpression(out, expr->member())) { + out << builder_.Symbols().NameFor(expr->member->symbol); + } else if (!EmitExpression(out, expr->member)) { return false; } @@ -2872,10 +2871,10 @@ bool GeneratorImpl::EmitMemberAccessor(std::ostream& out, } bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) { - if (stmt->has_value()) { + if (stmt->value) { auto out = line(); out << "return "; - if (!EmitExpression(out, stmt->value())) { + if (!EmitExpression(out, stmt->value)) { return false; } out << ";"; @@ -2897,10 +2896,10 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) { } if (auto* c = stmt->As()) { auto out = line(); - if (!TypeOf(c->expr())->Is()) { + if (!TypeOf(c->expr)->Is()) { out << "(void) "; } - if (!EmitCall(out, c->expr())) { + if (!EmitCall(out, c->expr)) { return false; } out << ";"; @@ -2932,7 +2931,7 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) { return EmitSwitch(s); } if (auto* v = stmt->As()) { - return EmitVariable(v->variable()); + return EmitVariable(v->variable); } diagnostics_.add_error( @@ -2945,7 +2944,7 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) { { // switch(expr) { auto out = line(); out << "switch("; - if (!EmitExpression(out, stmt->condition())) { + if (!EmitExpression(out, stmt->condition)) { return false; } out << ") {"; @@ -2953,7 +2952,7 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) { { ScopedIndent si(this); - for (size_t i = 0; i < stmt->body().size(); i++) { + for (size_t i = 0; i < stmt->body.size(); i++) { if (!EmitCase(stmt, i)) { return false; } @@ -3180,7 +3179,7 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { std::string pre, post; if (auto* decl = mem->Declaration()) { - for (auto* deco : decl->decorations()) { + for (auto* deco : decl->decorations) { if (auto* location = deco->As()) { auto& pipeline_stage_uses = str->PipelineStageUses(); if (pipeline_stage_uses.size() != 1) { @@ -3190,22 +3189,22 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { if (pipeline_stage_uses.count( sem::PipelineStageUsage::kVertexInput)) { - post += " : TEXCOORD" + std::to_string(location->value()); + post += " : TEXCOORD" + std::to_string(location->value); } else if (pipeline_stage_uses.count( sem::PipelineStageUsage::kVertexOutput)) { - post += " : TEXCOORD" + std::to_string(location->value()); + post += " : TEXCOORD" + std::to_string(location->value); } else if (pipeline_stage_uses.count( sem::PipelineStageUsage::kFragmentInput)) { - post += " : TEXCOORD" + std::to_string(location->value()); + post += " : TEXCOORD" + std::to_string(location->value); } else if (pipeline_stage_uses.count( sem::PipelineStageUsage::kFragmentOutput)) { - post += " : SV_Target" + std::to_string(location->value()); + post += " : SV_Target" + std::to_string(location->value); } else { TINT_ICE(Writer, diagnostics_) << "invalid use of location decoration"; } } else if (auto* builtin = deco->As()) { - auto attr = builtin_to_attribute(builtin->value()); + auto attr = builtin_to_attribute(builtin->builtin); if (attr.empty()) { diagnostics_.add_error(diag::System::Writer, "unsupported builtin"); @@ -3214,8 +3213,8 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { post += " : " + attr; } else if (auto* interpolate = deco->As()) { - auto mod = interpolation_to_modifiers(interpolate->type(), - interpolate->sampling()); + auto mod = interpolation_to_modifiers(interpolate->type, + interpolate->sampling); if (mod.empty()) { diagnostics_.add_error(diag::System::Writer, "unsupported interpolation"); @@ -3232,7 +3231,7 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { ast::StructMemberOffsetDecoration, ast::StructMemberSizeDecoration>()) { TINT_ICE(Writer, diagnostics_) - << "unhandled struct member attribute: " << deco->name(); + << "unhandled struct member attribute: " << deco->Name(); return false; } } @@ -3254,10 +3253,10 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { bool GeneratorImpl::EmitUnaryOp(std::ostream& out, ast::UnaryOpExpression* expr) { - switch (expr->op()) { + switch (expr->op) { case ast::UnaryOp::kIndirection: case ast::UnaryOp::kAddressOf: - return EmitExpression(out, expr->expr()); + return EmitExpression(out, expr->expr); case ast::UnaryOp::kComplement: out << "~"; break; @@ -3270,7 +3269,7 @@ bool GeneratorImpl::EmitUnaryOp(std::ostream& out, } out << "("; - if (!EmitExpression(out, expr->expr())) { + if (!EmitExpression(out, expr->expr)) { return false; } @@ -3284,25 +3283,25 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) { auto* type = sem->Type()->UnwrapRef(); // TODO(dsinclair): Handle variable decorations - if (!var->decorations().empty()) { + if (!var->decorations.empty()) { diagnostics_.add_error(diag::System::Writer, "Variable decorations are not handled yet"); return false; } auto out = line(); - if (var->is_const()) { + if (var->is_const) { out << "const "; } if (!EmitTypeAndName(out, type, sem->StorageClass(), sem->Access(), - builder_.Symbols().NameFor(var->symbol()))) { + builder_.Symbols().NameFor(var->symbol))) { return false; } out << " = "; - if (var->constructor()) { - if (!EmitExpression(out, var->constructor())) { + if (var->constructor) { + if (!EmitExpression(out, var->constructor)) { return false; } } else { @@ -3316,14 +3315,14 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) { } bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { - for (auto* d : var->decorations()) { + for (auto* d : var->decorations) { if (!d->Is()) { diagnostics_.add_error(diag::System::Writer, "Decorated const values not valid"); return false; } } - if (!var->is_const()) { + if (!var->is_const) { diagnostics_.add_error(diag::System::Writer, "Expected a const value"); return false; } @@ -3337,10 +3336,10 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { line() << "#ifndef " << kSpecConstantPrefix << const_id; - if (var->constructor() != nullptr) { + if (var->constructor != nullptr) { auto out = line(); out << "#define " << kSpecConstantPrefix << const_id << " "; - if (!EmitExpression(out, var->constructor())) { + if (!EmitExpression(out, var->constructor)) { return false; } } else { @@ -3351,7 +3350,7 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { auto out = line(); out << "static const "; if (!EmitTypeAndName(out, type, sem->StorageClass(), sem->Access(), - builder_.Symbols().NameFor(var->symbol()))) { + builder_.Symbols().NameFor(var->symbol))) { return false; } out << " = " << kSpecConstantPrefix << const_id << ";"; @@ -3360,11 +3359,11 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { auto out = line(); out << "static const "; if (!EmitTypeAndName(out, type, sem->StorageClass(), sem->Access(), - builder_.Symbols().NameFor(var->symbol()))) { + builder_.Symbols().NameFor(var->symbol))) { return false; } out << " = "; - if (!EmitExpression(out, var->constructor())) { + if (!EmitExpression(out, var->constructor)) { return false; } out << ";"; @@ -3434,7 +3433,7 @@ bool GeneratorImpl::CallIntrinsicHelper(std::ostream& out, { ScopedParen sp(out); bool first = true; - for (auto* arg : call->args()) { + for (auto* arg : call->args) { if (!first) { out << ", "; } diff --git a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc index b19864dc64..ff9cf34a84 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc @@ -331,8 +331,8 @@ class HlslGeneratorIntrinsicTextureTest TEST_P(HlslGeneratorIntrinsicTextureTest, Call) { auto param = GetParam(); - param.buildTextureVariable(this); - param.buildSamplerVariable(this); + param.BuildTextureVariable(this); + param.BuildSamplerVariable(this); auto* call = Call(param.function, param.args(this)); auto* stmt = ast::intrinsic::test::ReturnsVoid(param.overload) diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 3ecf89b9d8..510b649229 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -77,12 +77,7 @@ namespace msl { namespace { bool last_is_break_or_fallthrough(const ast::BlockStatement* stmts) { - if (stmts->empty()) { - return false; - } - - return stmts->last()->Is() || - stmts->last()->Is(); + return IsAnyOf(stmts->Last()); } class ScopedBitCast { @@ -192,7 +187,7 @@ bool GeneratorImpl::Generate() { } for (auto* var : program_->AST().GlobalVariables()) { - if (var->is_const()) { + if (var->is_const) { if (!EmitProgramConstVariable(var)) { return false; } @@ -250,7 +245,7 @@ bool GeneratorImpl::EmitTypeDecl(const sem::Type* ty) { bool GeneratorImpl::EmitArrayAccessor(std::ostream& out, ast::ArrayAccessorExpression* expr) { bool paren_lhs = - !expr->array() + !expr->array ->IsAnyOf(); @@ -258,7 +253,7 @@ bool GeneratorImpl::EmitArrayAccessor(std::ostream& out, if (paren_lhs) { out << "("; } - if (!EmitExpression(out, expr->array())) { + if (!EmitExpression(out, expr->array)) { return false; } if (paren_lhs) { @@ -267,7 +262,7 @@ bool GeneratorImpl::EmitArrayAccessor(std::ostream& out, out << "["; - if (!EmitExpression(out, expr->idx_expr())) { + if (!EmitExpression(out, expr->index)) { return false; } out << "]"; @@ -283,7 +278,7 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, } out << ">("; - if (!EmitExpression(out, expr->expr())) { + if (!EmitExpression(out, expr->expr)) { return false; } @@ -294,13 +289,13 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, bool GeneratorImpl::EmitAssign(ast::AssignmentStatement* stmt) { auto out = line(); - if (!EmitExpression(out, stmt->lhs())) { + if (!EmitExpression(out, stmt->lhs)) { return false; } out << " = "; - if (!EmitExpression(out, stmt->rhs())) { + if (!EmitExpression(out, stmt->rhs)) { return false; } @@ -313,7 +308,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { auto emit_op = [&] { out << " "; - switch (expr->op()) { + switch (expr->op) { case ast::BinaryOp::kAnd: out << "&"; break; @@ -402,19 +397,19 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { return {}; }; - auto* lhs_type = TypeOf(expr->lhs())->UnwrapRef(); - auto* rhs_type = TypeOf(expr->rhs())->UnwrapRef(); + auto* lhs_type = TypeOf(expr->lhs)->UnwrapRef(); + auto* rhs_type = TypeOf(expr->rhs)->UnwrapRef(); // Handle fmod - if (expr->op() == ast::BinaryOp::kModulo && + if (expr->op == ast::BinaryOp::kModulo && lhs_type->is_float_scalar_or_vector()) { out << "fmod"; ScopedParen sp(out); - if (!EmitExpression(out, expr->lhs())) { + if (!EmitExpression(out, expr->lhs)) { return false; } out << ", "; - if (!EmitExpression(out, expr->rhs())) { + if (!EmitExpression(out, expr->rhs)) { return false; } return true; @@ -439,7 +434,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { { ScopedBitCast lhs_uint_cast(this, out, lhs_type, unsigned_type_of(target_type)); - if (!EmitExpression(out, expr->lhs())) { + if (!EmitExpression(out, expr->lhs)) { return false; } } @@ -449,7 +444,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { { ScopedBitCast rhs_uint_cast(this, out, rhs_type, unsigned_type_of(target_type)); - if (!EmitExpression(out, expr->rhs())) { + if (!EmitExpression(out, expr->rhs)) { return false; } } @@ -468,14 +463,14 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { { ScopedBitCast lhs_uint_cast(this, out, lhs_type, unsigned_type_of(lhs_type)); - if (!EmitExpression(out, expr->lhs())) { + if (!EmitExpression(out, expr->lhs)) { return false; } } if (!emit_op()) { return false; } - if (!EmitExpression(out, expr->rhs())) { + if (!EmitExpression(out, expr->rhs)) { return false; } return true; @@ -483,13 +478,13 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { // Emit as usual ScopedParen sp(out); - if (!EmitExpression(out, expr->lhs())) { + if (!EmitExpression(out, expr->lhs)) { return false; } if (!emit_op()) { return false; } - if (!EmitExpression(out, expr->rhs())) { + if (!EmitExpression(out, expr->rhs)) { return false; } @@ -502,21 +497,21 @@ bool GeneratorImpl::EmitBreak(ast::BreakStatement*) { } bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { - auto* ident = expr->func(); + auto* ident = expr->func; auto* call = program_->Sem().Get(expr); if (auto* intrinsic = call->Target()->As()) { return EmitIntrinsicCall(out, expr, intrinsic); } - auto* func = program_->AST().Functions().Find(ident->symbol()); + auto* func = program_->AST().Functions().Find(ident->symbol); if (func == nullptr) { diagnostics_.add_error(diag::System::Writer, "Unable to find function: " + - program_->Symbols().NameFor(ident->symbol())); + program_->Symbols().NameFor(ident->symbol)); return false; } - out << program_->Symbols().NameFor(ident->symbol()) << "("; + out << program_->Symbols().NameFor(ident->symbol) << "("; bool first = true; auto* func_sem = program_->Sem().Get(func); @@ -526,7 +521,7 @@ bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { out << ", "; } first = false; - out << program_->Symbols().NameFor(var->Declaration()->symbol()); + out << program_->Symbols().NameFor(var->Declaration()->symbol); } for (const auto& data : func_sem->ReferencedStorageBufferVariables()) { @@ -535,10 +530,10 @@ bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { out << ", "; } first = false; - out << program_->Symbols().NameFor(var->Declaration()->symbol()); + out << program_->Symbols().NameFor(var->Declaration()->symbol); } - const auto& args = expr->args(); + const auto& args = expr->args; for (auto* arg : args) { if (!first) { out << ", "; @@ -580,7 +575,7 @@ bool GeneratorImpl::EmitIntrinsicCall(std::ostream& out, } else { out << "float2(as_type("; } - if (!EmitExpression(out, expr->args()[0])) { + if (!EmitExpression(out, expr->args[0])) { return false; } out << "))"; @@ -598,14 +593,14 @@ bool GeneratorImpl::EmitIntrinsicCall(std::ostream& out, } case sem::IntrinsicType::kIgnore: { out << "(void) "; - if (!EmitExpression(out, expr->args()[0])) { + if (!EmitExpression(out, expr->args[0])) { return false; } return true; } case sem::IntrinsicType::kLength: { - auto* sem = builder_.Sem().Get(expr->args()[0]); + auto* sem = builder_.Sem().Get(expr->args[0]); if (sem->Type()->UnwrapRef()->is_scalar()) { // Emulate scalar overload using fabs(x). name = "fabs"; @@ -614,16 +609,16 @@ bool GeneratorImpl::EmitIntrinsicCall(std::ostream& out, } case sem::IntrinsicType::kDistance: { - auto* sem = builder_.Sem().Get(expr->args()[0]); + auto* sem = builder_.Sem().Get(expr->args[0]); if (sem->Type()->UnwrapRef()->is_scalar()) { // Emulate scalar overload using fabs(x - y); out << "fabs"; ScopedParen sp(out); - if (!EmitExpression(out, expr->args()[0])) { + if (!EmitExpression(out, expr->args[0])) { return false; } out << " - "; - if (!EmitExpression(out, expr->args()[1])) { + if (!EmitExpression(out, expr->args[1])) { return false; } return true; @@ -642,8 +637,7 @@ bool GeneratorImpl::EmitIntrinsicCall(std::ostream& out, out << name << "("; bool first = true; - const auto& args = expr->args(); - for (auto* arg : args) { + for (auto* arg : expr->args) { if (!first) { out << ", "; } @@ -665,8 +659,8 @@ bool GeneratorImpl::EmitAtomicCall(std::ostream& out, out << name; { ScopedParen sp(out); - for (size_t i = 0; i < expr->args().size(); i++) { - auto* arg = expr->args()[i]; + for (size_t i = 0; i < expr->args.size(); i++) { + auto* arg = expr->args[i]; if (i > 0) { out << ", "; } @@ -713,7 +707,7 @@ bool GeneratorImpl::EmitAtomicCall(std::ostream& out, return call("atomic_exchange_explicit", true); case sem::IntrinsicType::kAtomicCompareExchangeWeak: { - auto* ptr_ty = TypeOf(expr->args()[0])->UnwrapRef()->As(); + auto* ptr_ty = TypeOf(expr->args[0])->UnwrapRef()->As(); auto sc = ptr_ty->StorageClass(); auto func = utils::GetOrCreate( @@ -765,7 +759,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, using Usage = sem::ParameterUsage; auto& signature = intrinsic->Signature(); - auto arguments = expr->args(); + auto arguments = expr->args; // Returns the argument with the given usage auto arg = [&](Usage usage) { @@ -1236,14 +1230,14 @@ bool GeneratorImpl::EmitCase(ast::CaseStatement* stmt) { if (stmt->IsDefault()) { line() << "default: {"; } else { - for (auto* selector : stmt->selectors()) { + for (auto* selector : stmt->selectors) { auto out = line(); out << "case "; if (!EmitLiteral(out, selector)) { return false; } out << ":"; - if (selector == stmt->selectors().back()) { + if (selector == stmt->selectors.back()) { out << " {"; } } @@ -1252,13 +1246,13 @@ bool GeneratorImpl::EmitCase(ast::CaseStatement* stmt) { { ScopedIndent si(this); - for (auto* s : *stmt->body()) { + for (auto* s : stmt->body->statements) { if (!EmitStatement(s)) { return false; } } - if (!last_is_break_or_fallthrough(stmt->body())) { + if (!last_is_break_or_fallthrough(stmt->body)) { line() << "break;"; } } @@ -1299,7 +1293,7 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, } int i = 0; - for (auto* e : expr->values()) { + for (auto* e : expr->values) { if (i > 0) { out << ", "; } @@ -1307,7 +1301,7 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, if (auto* struct_ty = type->As()) { // Emit field designators for structures to account for padding members. auto* member = struct_ty->Members()[i]->Declaration(); - auto name = program_->Symbols().NameFor(member->symbol()); + auto name = program_->Symbols().NameFor(member->symbol); out << "." << name << "="; } @@ -1366,19 +1360,19 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const sem::Type* type) { bool GeneratorImpl::EmitScalarConstructor( std::ostream& out, ast::ScalarConstructorExpression* expr) { - return EmitLiteral(out, expr->literal()); + return EmitLiteral(out, expr->literal); } bool GeneratorImpl::EmitLiteral(std::ostream& out, ast::Literal* lit) { if (auto* l = lit->As()) { - out << (l->IsTrue() ? "true" : "false"); + out << (l->value ? "true" : "false"); } else if (auto* fl = lit->As()) { - if (std::isinf(fl->value())) { - out << (fl->value() >= 0 ? "INFINITY" : "-INFINITY"); - } else if (std::isnan(fl->value())) { + if (std::isinf(fl->value)) { + out << (fl->value >= 0 ? "INFINITY" : "-INFINITY"); + } else if (std::isnan(fl->value)) { out << "NAN"; } else { - out << FloatToString(fl->value()) << "f"; + out << FloatToString(fl->value) << "f"; } } else if (auto* sl = lit->As()) { // MSL (and C++) parse `-2147483648` as a `long` because it parses unary @@ -1387,13 +1381,13 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, ast::Literal* lit) { // issues with `long` to `int` casts, emit `(2147483647 - 1)` instead, which // ensures the expression type is `int`. const auto int_min = std::numeric_limits::min(); - if (sl->value_as_i32() == int_min) { + if (sl->ValueAsI32() == int_min) { out << "(" << int_min + 1 << " - 1)"; } else { - out << sl->value(); + out << sl->value; } } else if (auto* ul = lit->As()) { - out << ul->value() << "u"; + out << ul->value << "u"; } else { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); return false; @@ -1458,7 +1452,7 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { if (!EmitType(out, func_sem->ReturnType(), "")) { return false; } - out << " " << program_->Symbols().NameFor(func->symbol()) << "("; + out << " " << program_->Symbols().NameFor(func->symbol) << "("; bool first = true; for (const auto& data : func_sem->ReferencedUniformVariables()) { @@ -1473,7 +1467,7 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { if (!EmitType(out, var->Type()->UnwrapRef(), "")) { return false; } - out << "& " << program_->Symbols().NameFor(var->Declaration()->symbol()); + out << "& " << program_->Symbols().NameFor(var->Declaration()->symbol); } for (const auto& data : func_sem->ReferencedStorageBufferVariables()) { @@ -1491,10 +1485,10 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { if (!EmitType(out, var->Type()->UnwrapRef(), "")) { return false; } - out << "& " << program_->Symbols().NameFor(var->Declaration()->symbol()); + out << "& " << program_->Symbols().NameFor(var->Declaration()->symbol); } - for (auto* v : func->params()) { + for (auto* v : func->params) { if (!first) { out << ", "; } @@ -1503,20 +1497,20 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { auto* type = program_->Sem().Get(v)->Type(); std::string param_name = - "const " + program_->Symbols().NameFor(v->symbol()); + "const " + program_->Symbols().NameFor(v->symbol); if (!EmitType(out, type, param_name)) { return false; } // Parameter name is output as part of the type for arrays and pointers. if (!type->Is() && !type->Is()) { - out << " " << program_->Symbols().NameFor(v->symbol()); + out << " " << program_->Symbols().NameFor(v->symbol); } } out << ") {"; } - if (!EmitStatementsWithIndent(func->body()->statements())) { + if (!EmitStatementsWithIndent(func->body->statements)) { return false; } @@ -1592,18 +1586,18 @@ std::string GeneratorImpl::interpolation_to_attribute( bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { auto* func_sem = program_->Sem().Get(func); - auto func_name = program_->Symbols().NameFor(func->symbol()); + auto func_name = program_->Symbols().NameFor(func->symbol); { auto out = line(); - EmitStage(out, func->pipeline_stage()); - out << " " << func->return_type()->FriendlyName(program_->Symbols()); + EmitStage(out, func->PipelineStage()); + out << " " << func->return_type->FriendlyName(program_->Symbols()); out << " " << func_name << "("; // Emit entry point parameters. bool first = true; - for (auto* var : func->params()) { + for (auto* var : func->params) { if (!first) { out << ", "; } @@ -1611,7 +1605,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { auto* type = program_->Sem().Get(var)->Type()->UnwrapRef(); - auto param_name = program_->Symbols().NameFor(var->symbol()); + auto param_name = program_->Symbols().NameFor(var->symbol); if (!EmitType(out, type, param_name)) { return false; } @@ -1623,39 +1617,39 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { if (type->Is()) { out << " [[stage_in]]"; } else if (type->is_handle()) { - auto bp = var->binding_point(); + auto bp = var->BindingPoint(); if (bp.group == nullptr || bp.binding == nullptr) { TINT_ICE(Writer, diagnostics_) << "missing binding attributes for entry point parameter"; return false; } - if (bp.group->value() != 0) { + if (bp.group->value != 0) { TINT_ICE(Writer, diagnostics_) << "encountered non-zero resource group index (use " "BindingRemapper to fix)"; return false; } - if (var->type()->Is()) { - out << " [[sampler(" << bp.binding->value() << ")]]"; - } else if (var->type()->Is()) { - out << " [[texture(" << bp.binding->value() << ")]]"; + if (var->type->Is()) { + out << " [[sampler(" << bp.binding->value << ")]]"; + } else if (var->type->Is()) { + out << " [[texture(" << bp.binding->value << ")]]"; } else { TINT_ICE(Writer, diagnostics_) << "invalid handle type entry point parameter"; return false; } - } else if (auto* ptr = var->type()->As()) { - if (ptr->storage_class() == ast::StorageClass::kWorkgroup) { + } else if (auto* ptr = var->type->As()) { + if (ptr->storage_class == ast::StorageClass::kWorkgroup) { auto& allocations = workgroup_allocations_[func_name]; out << " [[threadgroup(" << allocations.size() << ")]]"; - allocations.push_back(program_->Sem().Get(ptr->type())->Size()); + allocations.push_back(program_->Sem().Get(ptr->type)->Size()); } else { TINT_ICE(Writer, diagnostics_) << "invalid pointer storage class for entry point parameter"; return false; } } else { - auto& decos = var->decorations(); + auto& decos = var->decorations; bool builtin_found = false; for (auto* deco : decos) { auto* builtin = deco->As(); @@ -1665,7 +1659,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { builtin_found = true; - auto attr = builtin_to_attribute(builtin->value()); + auto attr = builtin_to_attribute(builtin->builtin); if (attr.empty()) { diagnostics_.add_error(diag::System::Writer, "unknown builtin"); return false; @@ -1693,7 +1687,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { diagnostics_.add_error( diag::System::Writer, "unable to find binding information for uniform: " + - program_->Symbols().NameFor(var->Declaration()->symbol())); + program_->Symbols().NameFor(var->Declaration()->symbol)); return false; } // auto* set = data.second.set; @@ -1704,8 +1698,8 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { if (!EmitType(out, var->Type()->UnwrapRef(), "")) { return false; } - out << "& " << program_->Symbols().NameFor(var->Declaration()->symbol()) - << " [[buffer(" << binding->value() << ")]]"; + out << "& " << program_->Symbols().NameFor(var->Declaration()->symbol) + << " [[buffer(" << binding->value << ")]]"; } for (auto data : func_sem->ReferencedStorageBufferVariables()) { @@ -1729,8 +1723,8 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { if (!EmitType(out, var->Type()->UnwrapRef(), "")) { return false; } - out << "& " << program_->Symbols().NameFor(var->Declaration()->symbol()) - << " [[buffer(" << binding->value() << ")]]"; + out << "& " << program_->Symbols().NameFor(var->Declaration()->symbol) + << " [[buffer(" << binding->value << ")]]"; } out << ") {"; @@ -1739,11 +1733,11 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { { ScopedIndent si(this); - if (!EmitStatements(func->body()->statements())) { + if (!EmitStatements(func->body->statements)) { return false; } - if (!Is(func->get_last_statement())) { + if (!Is(func->body->Last())) { ast::ReturnStatement ret(ProgramID{}, Source{}); if (!EmitStatement(&ret)) { return false; @@ -1757,14 +1751,14 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { bool GeneratorImpl::EmitIdentifier(std::ostream& out, ast::IdentifierExpression* expr) { - out << program_->Symbols().NameFor(expr->symbol()); + out << program_->Symbols().NameFor(expr->symbol); return true; } bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { auto emit_continuing = [this, stmt]() { - if (stmt->has_continuing()) { - if (!EmitBlock(stmt->continuing())) { + if (stmt->continuing && !stmt->continuing->Empty()) { + if (!EmitBlock(stmt->continuing)) { return false; } } @@ -1775,7 +1769,7 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { line() << "while (true) {"; { ScopedIndent si(this); - if (!EmitStatements(stmt->body()->statements())) { + if (!EmitStatements(stmt->body->statements)) { return false; } if (!emit_continuing()) { @@ -1789,7 +1783,7 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { TextBuffer init_buf; - if (auto* init = stmt->initializer()) { + if (auto* init = stmt->initializer) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &init_buf); if (!EmitStatement(init)) { return false; @@ -1798,7 +1792,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { TextBuffer cond_pre; std::stringstream cond_buf; - if (auto* cond = stmt->condition()) { + if (auto* cond = stmt->condition) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &cond_pre); if (!EmitExpression(cond_buf, cond)) { return false; @@ -1806,7 +1800,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { } TextBuffer cont_buf; - if (auto* cont = stmt->continuing()) { + if (auto* cont = stmt->continuing) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &cont_buf); if (!EmitStatement(cont)) { return false; @@ -1822,7 +1816,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { // as a `while(true)` loop, then declare the initializer statement(s) before // the loop in a new block. bool nest_in_block = - init_buf.lines.size() > 1 || (stmt->initializer() && emit_as_loop); + init_buf.lines.size() > 1 || (stmt->initializer && emit_as_loop); if (nest_in_block) { line() << "{"; increment_indent(); @@ -1850,12 +1844,12 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { line() << "}"; }); - if (stmt->condition()) { + if (stmt->condition) { current_buffer_->Append(cond_pre); line() << "if (!(" << cond_buf.str() << ")) { break; }"; } - if (!EmitStatements(stmt->body()->statements())) { + if (!EmitStatements(stmt->body->statements)) { return false; } @@ -1887,7 +1881,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { { auto emit_continuing = [] { return true; }; TINT_SCOPED_ASSIGNMENT(emit_continuing_, emit_continuing); - if (!EmitStatementsWithIndent(stmt->body()->statements())) { + if (!EmitStatementsWithIndent(stmt->body->statements)) { return false; } } @@ -1908,25 +1902,25 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { { auto out = line(); out << "if ("; - if (!EmitExpression(out, stmt->condition())) { + if (!EmitExpression(out, stmt->condition)) { return false; } out << ") {"; } - if (!EmitStatementsWithIndent(stmt->body()->statements())) { + if (!EmitStatementsWithIndent(stmt->body->statements)) { return false; } - for (auto* e : stmt->else_statements()) { - if (e->HasCondition()) { + for (auto* e : stmt->else_statements) { + if (e->condition) { line() << "} else {"; increment_indent(); { auto out = line(); out << "if ("; - if (!EmitExpression(out, e->condition())) { + if (!EmitExpression(out, e->condition)) { return false; } out << ") {"; @@ -1935,15 +1929,15 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { line() << "} else {"; } - if (!EmitStatementsWithIndent(e->body()->statements())) { + if (!EmitStatementsWithIndent(e->body->statements)) { return false; } } line() << "}"; - for (auto* e : stmt->else_statements()) { - if (e->HasCondition()) { + for (auto* e : stmt->else_statements) { + if (e->condition) { decrement_indent(); line() << "}"; } @@ -1954,14 +1948,14 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { bool GeneratorImpl::EmitMemberAccessor(std::ostream& out, ast::MemberAccessorExpression* expr) { bool paren_lhs = - !expr->structure() + !expr->structure ->IsAnyOf(); if (paren_lhs) { out << "("; } - if (!EmitExpression(out, expr->structure())) { + if (!EmitExpression(out, expr->structure)) { return false; } if (paren_lhs) { @@ -1972,8 +1966,8 @@ bool GeneratorImpl::EmitMemberAccessor(std::ostream& out, // Swizzles get written out directly if (program_->Sem().Get(expr)->Is()) { - out << program_->Symbols().NameFor(expr->member()->symbol()); - } else if (!EmitExpression(out, expr->member())) { + out << program_->Symbols().NameFor(expr->member->symbol); + } else if (!EmitExpression(out, expr->member)) { return false; } @@ -1983,9 +1977,9 @@ bool GeneratorImpl::EmitMemberAccessor(std::ostream& out, bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) { auto out = line(); out << "return"; - if (stmt->has_value()) { + if (stmt->value) { out << " "; - if (!EmitExpression(out, stmt->value())) { + if (!EmitExpression(out, stmt->value)) { return false; } } @@ -1996,7 +1990,7 @@ bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) { bool GeneratorImpl::EmitBlock(const ast::BlockStatement* stmt) { line() << "{"; - if (!EmitStatementsWithIndent(stmt->statements())) { + if (!EmitStatementsWithIndent(stmt->statements)) { return false; } @@ -2017,7 +2011,7 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) { } if (auto* c = stmt->As()) { auto out = line(); - if (!EmitCall(out, c->expr())) { + if (!EmitCall(out, c->expr)) { return false; } out << ";"; @@ -2049,7 +2043,7 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) { return EmitSwitch(s); } if (auto* v = stmt->As()) { - auto* var = program_->Sem().Get(v->variable()); + auto* var = program_->Sem().Get(v->variable); return EmitVariable(var); } @@ -2077,7 +2071,7 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) { { auto out = line(); out << "switch("; - if (!EmitExpression(out, stmt->condition())) { + if (!EmitExpression(out, stmt->condition)) { return false; } out << ") {"; @@ -2085,7 +2079,7 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) { { ScopedIndent si(this); - for (auto* s : stmt->body()) { + for (auto* s : stmt->body) { if (!EmitCase(s)) { return false; } @@ -2438,9 +2432,9 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { // Emit decorations if (auto* decl = mem->Declaration()) { - for (auto* deco : decl->decorations()) { + for (auto* deco : decl->decorations) { if (auto* builtin = deco->As()) { - auto attr = builtin_to_attribute(builtin->value()); + auto attr = builtin_to_attribute(builtin->builtin); if (attr.empty()) { diagnostics_.add_error(diag::System::Writer, "unknown builtin"); return false; @@ -2455,23 +2449,23 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { if (pipeline_stage_uses.count( sem::PipelineStageUsage::kVertexInput)) { - out << " [[attribute(" + std::to_string(loc->value()) + ")]]"; + out << " [[attribute(" + std::to_string(loc->value) + ")]]"; } else if (pipeline_stage_uses.count( sem::PipelineStageUsage::kVertexOutput)) { - out << " [[user(locn" + std::to_string(loc->value()) + ")]]"; + out << " [[user(locn" + std::to_string(loc->value) + ")]]"; } else if (pipeline_stage_uses.count( sem::PipelineStageUsage::kFragmentInput)) { - out << " [[user(locn" + std::to_string(loc->value()) + ")]]"; + out << " [[user(locn" + std::to_string(loc->value) + ")]]"; } else if (pipeline_stage_uses.count( sem::PipelineStageUsage::kFragmentOutput)) { - out << " [[color(" + std::to_string(loc->value()) + ")]]"; + out << " [[color(" + std::to_string(loc->value) + ")]]"; } else { TINT_ICE(Writer, diagnostics_) << "invalid use of location decoration"; } } else if (auto* interpolate = deco->As()) { - auto attr = interpolation_to_attribute(interpolate->type(), - interpolate->sampling()); + auto attr = interpolation_to_attribute(interpolate->type, + interpolate->sampling); if (attr.empty()) { diagnostics_.add_error(diag::System::Writer, "unknown interpolation attribute"); @@ -2485,7 +2479,7 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { ast::StructMemberAlignDecoration, ast::StructMemberSizeDecoration>()) { TINT_ICE(Writer, diagnostics_) - << "unhandled struct member attribute: " << deco->name(); + << "unhandled struct member attribute: " << deco->Name(); } } } @@ -2519,8 +2513,8 @@ bool GeneratorImpl::EmitUnaryOp(std::ostream& out, ast::UnaryOpExpression* expr) { // Handle `-e` when `e` is signed, so that we ensure that if `e` is the // largest negative value, it returns `e`. - auto* expr_type = TypeOf(expr->expr())->UnwrapRef(); - if (expr->op() == ast::UnaryOp::kNegation && + auto* expr_type = TypeOf(expr->expr)->UnwrapRef(); + if (expr->op == ast::UnaryOp::kNegation && expr_type->is_signed_scalar_or_vector()) { auto fn = utils::GetOrCreate(unary_minus_funcs_, expr_type, [&]() -> std::string { @@ -2557,14 +2551,14 @@ bool GeneratorImpl::EmitUnaryOp(std::ostream& out, }); out << fn << "("; - if (!EmitExpression(out, expr->expr())) { + if (!EmitExpression(out, expr->expr)) { return false; } out << ")"; return true; } - switch (expr->op()) { + switch (expr->op) { case ast::UnaryOp::kAddressOf: out << "&"; break; @@ -2583,7 +2577,7 @@ bool GeneratorImpl::EmitUnaryOp(std::ostream& out, } out << "("; - if (!EmitExpression(out, expr->expr())) { + if (!EmitExpression(out, expr->expr)) { return false; } @@ -2595,7 +2589,7 @@ bool GeneratorImpl::EmitUnaryOp(std::ostream& out, bool GeneratorImpl::EmitVariable(const sem::Variable* var) { auto* decl = var->Declaration(); - for (auto* deco : decl->decorations()) { + for (auto* deco : decl->decorations) { if (!deco->Is()) { TINT_ICE(Writer, diagnostics_) << "unexpected variable decoration"; return false; @@ -2622,8 +2616,8 @@ bool GeneratorImpl::EmitVariable(const sem::Variable* var) { auto* type = var->Type()->UnwrapRef(); - std::string name = program_->Symbols().NameFor(decl->symbol()); - if (decl->is_const()) { + std::string name = program_->Symbols().NameFor(decl->symbol); + if (decl->is_const) { name = "const " + name; } if (!EmitType(out, type, name)) { @@ -2634,9 +2628,9 @@ bool GeneratorImpl::EmitVariable(const sem::Variable* var) { out << " " << name; } - if (decl->constructor() != nullptr) { + if (decl->constructor != nullptr) { out << " = "; - if (!EmitExpression(out, decl->constructor())) { + if (!EmitExpression(out, decl->constructor)) { return false; } } else if (var->StorageClass() == ast::StorageClass::kPrivate || @@ -2653,14 +2647,14 @@ bool GeneratorImpl::EmitVariable(const sem::Variable* var) { } bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { - for (auto* d : var->decorations()) { + for (auto* d : var->decorations) { if (!d->Is()) { diagnostics_.add_error(diag::System::Writer, "Decorated const values not valid"); return false; } } - if (!var->is_const()) { + if (!var->is_const) { diagnostics_.add_error(diag::System::Writer, "Expected a const value"); return false; } @@ -2668,19 +2662,19 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { auto out = line(); out << "constant "; auto* type = program_->Sem().Get(var)->Type()->UnwrapRef(); - if (!EmitType(out, type, program_->Symbols().NameFor(var->symbol()))) { + if (!EmitType(out, type, program_->Symbols().NameFor(var->symbol))) { return false; } if (!type->Is()) { - out << " " << program_->Symbols().NameFor(var->symbol()); + out << " " << program_->Symbols().NameFor(var->symbol); } auto* global = program_->Sem().Get(var); if (global && global->IsPipelineConstant()) { out << " [[function_constant(" << global->ConstantId() << ")]]"; - } else if (var->constructor() != nullptr) { + } else if (var->constructor != nullptr) { out << " = "; - if (!EmitExpression(out, var->constructor())) { + if (!EmitExpression(out, var->constructor)) { return false; } } @@ -2817,7 +2811,7 @@ bool GeneratorImpl::CallIntrinsicHelper(std::ostream& out, { ScopedParen sp(out); bool first = true; - for (auto* arg : call->args()) { + for (auto* arg : call->args) { if (!first) { out << ", "; } diff --git a/src/writer/msl/generator_impl_case_test.cc b/src/writer/msl/generator_impl_case_test.cc index 42b94826fd..7aff22148f 100644 --- a/src/writer/msl/generator_impl_case_test.cc +++ b/src/writer/msl/generator_impl_case_test.cc @@ -31,7 +31,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( case 5: { break; } @@ -46,7 +46,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( case 5: { break; } @@ -63,7 +63,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( case 5: { /* fallthrough */ } @@ -80,7 +80,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( case 5: case 6: { break; @@ -96,7 +96,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case_Default) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( default: { break; } diff --git a/src/writer/msl/generator_impl_intrinsic_texture_test.cc b/src/writer/msl/generator_impl_intrinsic_texture_test.cc index 5101add77b..d0b77ea263 100644 --- a/src/writer/msl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/msl/generator_impl_intrinsic_texture_test.cc @@ -241,8 +241,8 @@ class MslGeneratorIntrinsicTextureTest TEST_P(MslGeneratorIntrinsicTextureTest, Call) { auto param = GetParam(); - param.buildTextureVariable(this); - param.buildSamplerVariable(this); + param.BuildTextureVariable(this); + param.BuildSamplerVariable(this); auto* call = create(Expr(param.function), param.args(this)); diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 0de0335466..f37ffd10dd 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -86,25 +86,20 @@ uint32_t pipeline_stage_to_execution_model(ast::PipelineStage stage) { } bool LastIsFallthrough(const ast::BlockStatement* stmts) { - return !stmts->empty() && stmts->last()->Is(); + return !stmts->Empty() && stmts->Last()->Is(); } // A terminator is anything which will cause a SPIR-V terminator to be emitted. // This means things like breaks, fallthroughs and continues which all emit an // OpBranch or return for the OpReturn emission. bool LastIsTerminator(const ast::BlockStatement* stmts) { - if (stmts->empty()) { - return false; - } - - auto* last = stmts->last(); - if (last->Is() || last->Is() || - last->Is() || last->Is() || - last->Is()) { + if (IsAnyOf(stmts->Last())) { return true; } - if (auto* block = last->As()) { + if (auto* block = As(stmts->Last())) { return LastIsTerminator(block); } @@ -393,17 +388,17 @@ bool Builder::GenerateLabel(uint32_t id) { } bool Builder::GenerateAssignStatement(ast::AssignmentStatement* assign) { - auto lhs_id = GenerateExpression(assign->lhs()); + auto lhs_id = GenerateExpression(assign->lhs); if (lhs_id == 0) { return false; } - auto rhs_id = GenerateExpression(assign->rhs()); + auto rhs_id = GenerateExpression(assign->rhs); if (rhs_id == 0) { return false; } // If the thing we're assigning is a reference then we must load it first. - auto* type = TypeOf(assign->rhs()); + auto* type = TypeOf(assign->rhs); rhs_id = GenerateLoadIfNeeded(type, rhs_id); return GenerateStore(lhs_id, rhs_id); @@ -444,7 +439,7 @@ bool Builder::GenerateDiscardStatement(ast::DiscardStatement*) { } bool Builder::GenerateEntryPoint(ast::Function* func, uint32_t id) { - auto stage = pipeline_stage_to_execution_model(func->pipeline_stage()); + auto stage = pipeline_stage_to_execution_model(func->PipelineStage()); if (stage == SpvExecutionModelMax) { error_ = "Unknown pipeline stage provided"; return false; @@ -452,7 +447,7 @@ bool Builder::GenerateEntryPoint(ast::Function* func, uint32_t id) { OperandList operands = { Operand::Int(stage), Operand::Int(id), - Operand::String(builder_.Symbols().NameFor(func->symbol()))}; + Operand::String(builder_.Symbols().NameFor(func->symbol))}; auto* func_sem = builder_.Sem().Get(func); for (const auto* var : func_sem->ReferencedModuleVariables()) { @@ -464,9 +459,9 @@ bool Builder::GenerateEntryPoint(ast::Function* func, uint32_t id) { } uint32_t var_id; - if (!scope_stack_.get(var->Declaration()->symbol(), &var_id)) { + if (!scope_stack_.get(var->Declaration()->symbol, &var_id)) { error_ = "unable to find ID for global variable: " + - builder_.Symbols().NameFor(var->Declaration()->symbol()); + builder_.Symbols().NameFor(var->Declaration()->symbol); return false; } @@ -481,11 +476,11 @@ bool Builder::GenerateExecutionModes(ast::Function* func, uint32_t id) { auto* func_sem = builder_.Sem().Get(func); // WGSL fragment shader origin is upper left - if (func->pipeline_stage() == ast::PipelineStage::kFragment) { + if (func->PipelineStage() == ast::PipelineStage::kFragment) { push_execution_mode( spv::Op::OpExecutionMode, {Operand::Int(id), Operand::Int(SpvExecutionModeOriginUpperLeft)}); - } else if (func->pipeline_stage() == ast::PipelineStage::kCompute) { + } else if (func->PipelineStage() == ast::PipelineStage::kCompute) { auto& wgsize = func_sem->workgroup_size(); // Check if the workgroup_size uses pipeline-overridable constants. @@ -548,7 +543,7 @@ bool Builder::GenerateExecutionModes(ast::Function* func, uint32_t id) { } for (auto builtin : func_sem->ReferencedBuiltinVariables()) { - if (builtin.second->value() == ast::Builtin::kFragDepth) { + if (builtin.second->builtin == ast::Builtin::kFragDepth) { push_execution_mode( spv::Op::OpExecutionMode, {Operand::Int(id), Operand::Int(SpvExecutionModeDepthReplacing)}); @@ -601,7 +596,7 @@ bool Builder::GenerateFunction(ast::Function* func_ast) { push_debug(spv::Op::OpName, {Operand::Int(func_id), - Operand::String(builder_.Symbols().NameFor(func_ast->symbol()))}); + Operand::String(builder_.Symbols().NameFor(func_ast->symbol))}); auto ret_id = GenerateTypeIfNeeded(func->ReturnType()); if (ret_id == 0) { @@ -627,16 +622,16 @@ bool Builder::GenerateFunction(ast::Function* func_ast) { push_debug(spv::Op::OpName, {Operand::Int(param_id), Operand::String(builder_.Symbols().NameFor( - param->Declaration()->symbol()))}); + param->Declaration()->symbol))}); params.push_back(Instruction{spv::Op::OpFunctionParameter, {Operand::Int(param_type_id), param_op}}); - scope_stack_.set(param->Declaration()->symbol(), param_id); + scope_stack_.set(param->Declaration()->symbol, param_id); } push_function(Function{definition_inst, result_op(), std::move(params)}); - for (auto* stmt : *func_ast->body()) { + for (auto* stmt : func_ast->body->statements) { if (!GenerateStatement(stmt)) { return false; } @@ -653,7 +648,7 @@ bool Builder::GenerateFunction(ast::Function* func_ast) { scope_stack_.pop_scope(); - func_symbol_to_id_[func_ast->symbol()] = func_id; + func_symbol_to_id_[func_ast->symbol] = func_id; return true; } @@ -685,23 +680,23 @@ uint32_t Builder::GenerateFunctionTypeIfNeeded(const sem::Function* func) { bool Builder::GenerateFunctionVariable(ast::Variable* var) { uint32_t init_id = 0; - if (var->has_constructor()) { - init_id = GenerateExpression(var->constructor()); + if (var->constructor) { + init_id = GenerateExpression(var->constructor); if (init_id == 0) { return false; } - auto* type = TypeOf(var->constructor()); + auto* type = TypeOf(var->constructor); if (type->Is()) { init_id = GenerateLoadIfNeeded(type, init_id); } } - if (var->is_const()) { - if (!var->has_constructor()) { + if (var->is_const) { + if (!var->constructor) { error_ = "missing constructor for constant"; return false; } - scope_stack_.set(var->symbol(), init_id); + scope_stack_.set(var->symbol, init_id); spirv_id_to_variable_[init_id] = var; return true; } @@ -717,7 +712,7 @@ bool Builder::GenerateFunctionVariable(ast::Variable* var) { push_debug(spv::Op::OpName, {Operand::Int(var_id), - Operand::String(builder_.Symbols().NameFor(var->symbol()))}); + Operand::String(builder_.Symbols().NameFor(var->symbol))}); // TODO(dsinclair) We could detect if the constructor is fully const and emit // an initializer value for the variable instead of doing the OpLoad. @@ -729,13 +724,13 @@ bool Builder::GenerateFunctionVariable(ast::Variable* var) { Operand::Int(ConvertStorageClass(sc)), Operand::Int(null_id)}); - if (var->has_constructor()) { + if (var->constructor) { if (!GenerateStore(var_id, init_id)) { return false; } } - scope_stack_.set(var->symbol(), var_id); + scope_stack_.set(var->symbol, var_id); spirv_id_to_variable_[var_id] = var; return true; @@ -751,24 +746,24 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { auto* type = sem->Type()->UnwrapRef(); uint32_t init_id = 0; - if (var->has_constructor()) { - if (!var->constructor()->Is()) { + if (var->constructor) { + if (!var->constructor->Is()) { error_ = "scalar constructor expected"; return false; } init_id = GenerateConstructorExpression( - var, var->constructor()->As(), true); + var, var->constructor->As(), true); if (init_id == 0) { return false; } } - if (var->is_const()) { - if (!var->has_constructor()) { + if (var->is_const) { + if (!var->constructor) { // Constants must have an initializer unless they have an override // decoration. - if (!ast::HasDecoration(var->decorations())) { + if (!ast::HasDecoration(var->decorations)) { error_ = "missing constructor for constant"; return false; } @@ -796,9 +791,9 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { } push_debug(spv::Op::OpName, {Operand::Int(init_id), - Operand::String(builder_.Symbols().NameFor(var->symbol()))}); + Operand::String(builder_.Symbols().NameFor(var->symbol))}); - scope_stack_.set_global(var->symbol(), init_id); + scope_stack_.set_global(var->symbol, init_id); spirv_id_to_variable_[init_id] = var; return true; } @@ -817,12 +812,12 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { push_debug(spv::Op::OpName, {Operand::Int(var_id), - Operand::String(builder_.Symbols().NameFor(var->symbol()))}); + Operand::String(builder_.Symbols().NameFor(var->symbol))}); OperandList ops = {Operand::Int(type_id), result, Operand::Int(ConvertStorageClass(sc))}; - if (var->has_constructor()) { + if (var->constructor) { ops.push_back(Operand::Int(init_id)); } else { auto* st = type->As(); @@ -861,30 +856,30 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { push_type(spv::Op::OpVariable, std::move(ops)); - for (auto* deco : var->decorations()) { + for (auto* deco : var->decorations) { if (auto* builtin = deco->As()) { push_annot(spv::Op::OpDecorate, {Operand::Int(var_id), Operand::Int(SpvDecorationBuiltIn), Operand::Int( - ConvertBuiltin(builtin->value(), sem->StorageClass()))}); + ConvertBuiltin(builtin->builtin, sem->StorageClass()))}); } else if (auto* location = deco->As()) { push_annot(spv::Op::OpDecorate, {Operand::Int(var_id), Operand::Int(SpvDecorationLocation), - Operand::Int(location->value())}); + Operand::Int(location->value)}); } else if (auto* interpolate = deco->As()) { - AddInterpolationDecorations(var_id, interpolate->type(), - interpolate->sampling()); + AddInterpolationDecorations(var_id, interpolate->type, + interpolate->sampling); } else if (deco->Is()) { push_annot(spv::Op::OpDecorate, {Operand::Int(var_id), Operand::Int(SpvDecorationInvariant)}); } else if (auto* binding = deco->As()) { push_annot(spv::Op::OpDecorate, {Operand::Int(var_id), Operand::Int(SpvDecorationBinding), - Operand::Int(binding->value())}); + Operand::Int(binding->value)}); } else if (auto* group = deco->As()) { push_annot(spv::Op::OpDecorate, {Operand::Int(var_id), Operand::Int(SpvDecorationDescriptorSet), - Operand::Int(group->value())}); + Operand::Int(group->value)}); } else if (deco->Is()) { // Spec constants are handled elsewhere } else if (!deco->Is()) { @@ -893,18 +888,18 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { } } - scope_stack_.set_global(var->symbol(), var_id); + scope_stack_.set_global(var->symbol, var_id); spirv_id_to_variable_[var_id] = var; return true; } bool Builder::GenerateArrayAccessor(ast::ArrayAccessorExpression* expr, AccessorInfo* info) { - auto idx_id = GenerateExpression(expr->idx_expr()); + auto idx_id = GenerateExpression(expr->index); if (idx_id == 0) { return 0; } - auto* type = TypeOf(expr->idx_expr()); + auto* type = TypeOf(expr->index); idx_id = GenerateLoadIfNeeded(type, idx_id); // If the source is a reference, we access chain into it. @@ -926,8 +921,8 @@ bool Builder::GenerateArrayAccessor(ast::ArrayAccessorExpression* expr, auto extract_id = extract.to_i(); // If the index is a literal, we use OpCompositeExtract. - if (auto* scalar = expr->idx_expr()->As()) { - auto* literal = scalar->literal()->As(); + if (auto* scalar = expr->index->As()) { + auto* literal = scalar->literal->As(); if (!literal) { TINT_ICE(Writer, builder_.Diagnostics()) << "bad literal in array accessor"; @@ -937,7 +932,7 @@ bool Builder::GenerateArrayAccessor(ast::ArrayAccessorExpression* expr, if (!push_function_inst(spv::Op::OpCompositeExtract, {Operand::Int(result_type_id), extract, Operand::Int(info->source_id), - Operand::Int(literal->value_as_u32())})) { + Operand::Int(literal->ValueAsU32())})) { return false; } @@ -1108,10 +1103,10 @@ uint32_t Builder::GenerateAccessorExpression(ast::Expression* expr) { while (true) { if (auto* array = source->As()) { accessors.insert(accessors.begin(), source); - source = array->array(); + source = array->array; } else if (auto* member = source->As()) { accessors.insert(accessors.begin(), source); - source = member->structure(); + source = member->structure; } else { break; } @@ -1169,12 +1164,12 @@ uint32_t Builder::GenerateAccessorExpression(ast::Expression* expr) { uint32_t Builder::GenerateIdentifierExpression( ast::IdentifierExpression* expr) { uint32_t val = 0; - if (scope_stack_.get(expr->symbol(), &val)) { + if (scope_stack_.get(expr->symbol, &val)) { return val; } error_ = "unable to find variable with identifier: " + - builder_.Symbols().NameFor(expr->symbol()); + builder_.Symbols().NameFor(expr->symbol); return 0; } @@ -1199,13 +1194,13 @@ uint32_t Builder::GenerateUnaryOpExpression(ast::UnaryOpExpression* expr) { auto result = result_op(); auto result_id = result.to_i(); - auto val_id = GenerateExpression(expr->expr()); + auto val_id = GenerateExpression(expr->expr); if (val_id == 0) { return 0; } spv::Op op = spv::Op::OpNop; - switch (expr->op()) { + switch (expr->op) { case ast::UnaryOp::kComplement: op = spv::Op::OpNot; break; @@ -1227,7 +1222,7 @@ uint32_t Builder::GenerateUnaryOpExpression(ast::UnaryOpExpression* expr) { return val_id; } - val_id = GenerateLoadIfNeeded(TypeOf(expr->expr()), val_id); + val_id = GenerateLoadIfNeeded(TypeOf(expr->expr), val_id); auto type_id = GenerateTypeIfNeeded(TypeOf(expr)); if (type_id == 0) { @@ -1265,7 +1260,7 @@ uint32_t Builder::GenerateConstructorExpression( ast::ConstructorExpression* expr, bool is_global_init) { if (auto* scalar = expr->As()) { - return GenerateLiteralIfNeeded(var, scalar->literal()); + return GenerateLiteralIfNeeded(var, scalar->literal); } if (auto* type = expr->As()) { return GenerateTypeConstructorExpression(type, is_global_init); @@ -1286,8 +1281,8 @@ bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) { auto* tc = constructor->As(); auto* result_type = TypeOf(tc)->UnwrapRef(); - for (size_t i = 0; i < tc->values().size(); ++i) { - auto* e = tc->values()[i]; + for (size_t i = 0; i < tc->values.size(); ++i) { + auto* e = tc->values[i]; if (!e->Is()) { if (is_global_init) { @@ -1333,7 +1328,7 @@ bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) { uint32_t Builder::GenerateTypeConstructorExpression( ast::TypeConstructorExpression* init, bool is_global_init) { - auto& values = init->values(); + auto& values = init->values; auto* result_type = TypeOf(init); @@ -1343,7 +1338,7 @@ uint32_t Builder::GenerateTypeConstructorExpression( } std::ostringstream out; - out << "__const_" << init->type()->FriendlyName(builder_.Symbols()) << "_"; + out << "__const_" << init->type->FriendlyName(builder_.Symbols()) << "_"; result_type = result_type->UnwrapRef(); bool constructor_is_const = is_constructor_const(init, is_global_init); @@ -1665,16 +1660,16 @@ uint32_t Builder::GenerateLiteralIfNeeded(ast::Variable* var, if (auto* l = lit->As()) { constant.kind = ScalarConstant::Kind::kBool; - constant.value.b = l->IsTrue(); + constant.value.b = l->value; } else if (auto* sl = lit->As()) { constant.kind = ScalarConstant::Kind::kI32; - constant.value.i32 = sl->value(); + constant.value.i32 = sl->value; } else if (auto* ul = lit->As()) { constant.kind = ScalarConstant::Kind::kU32; - constant.value.u32 = ul->value(); + constant.value.u32 = ul->value; } else if (auto* fl = lit->As()) { constant.kind = ScalarConstant::Kind::kF32; - constant.value.f32 = fl->value(); + constant.value.f32 = fl->value; } else { error_ = "unknown literal type"; return 0; @@ -1809,11 +1804,11 @@ uint32_t Builder::GenerateConstantVectorSplatIfNeeded(const sem::Vector* type, uint32_t Builder::GenerateShortCircuitBinaryExpression( ast::BinaryExpression* expr) { - auto lhs_id = GenerateExpression(expr->lhs()); + auto lhs_id = GenerateExpression(expr->lhs); if (lhs_id == 0) { return false; } - lhs_id = GenerateLoadIfNeeded(TypeOf(expr->lhs()), lhs_id); + lhs_id = GenerateLoadIfNeeded(TypeOf(expr->lhs), lhs_id); // Get the ID of the basic block where control flow will diverge. It's the // last basic block generated for the left-hand-side of the operator. @@ -1853,11 +1848,11 @@ uint32_t Builder::GenerateShortCircuitBinaryExpression( if (!GenerateLabel(block_id)) { return 0; } - auto rhs_id = GenerateExpression(expr->rhs()); + auto rhs_id = GenerateExpression(expr->rhs); if (rhs_id == 0) { return 0; } - rhs_id = GenerateLoadIfNeeded(TypeOf(expr->rhs()), rhs_id); + rhs_id = GenerateLoadIfNeeded(TypeOf(expr->rhs), rhs_id); // Get the block ID of the last basic block generated for the right-hand-side // expression. That block will be an immediate predecessor to the merge block. @@ -1976,17 +1971,17 @@ uint32_t Builder::GenerateBinaryExpression(ast::BinaryExpression* expr) { return GenerateShortCircuitBinaryExpression(expr); } - auto lhs_id = GenerateExpression(expr->lhs()); + auto lhs_id = GenerateExpression(expr->lhs); if (lhs_id == 0) { return 0; } - lhs_id = GenerateLoadIfNeeded(TypeOf(expr->lhs()), lhs_id); + lhs_id = GenerateLoadIfNeeded(TypeOf(expr->lhs), lhs_id); - auto rhs_id = GenerateExpression(expr->rhs()); + auto rhs_id = GenerateExpression(expr->rhs); if (rhs_id == 0) { return 0; } - rhs_id = GenerateLoadIfNeeded(TypeOf(expr->rhs()), rhs_id); + rhs_id = GenerateLoadIfNeeded(TypeOf(expr->rhs), rhs_id); auto result = result_op(); auto result_id = result.to_i(); @@ -1998,8 +1993,8 @@ uint32_t Builder::GenerateBinaryExpression(ast::BinaryExpression* expr) { // Handle int and float and the vectors of those types. Other types // should have been rejected by validation. - auto* lhs_type = TypeOf(expr->lhs())->UnwrapRef(); - auto* rhs_type = TypeOf(expr->rhs())->UnwrapRef(); + auto* lhs_type = TypeOf(expr->lhs)->UnwrapRef(); + auto* rhs_type = TypeOf(expr->rhs)->UnwrapRef(); // Handle matrix-matrix addition and subtraction if ((expr->IsAdd() || expr->IsSubtract()) && lhs_type->is_float_matrix() && @@ -2213,7 +2208,7 @@ bool Builder::GenerateBlockStatement(const ast::BlockStatement* stmt) { bool Builder::GenerateBlockStatementWithoutScoping( const ast::BlockStatement* stmt) { - for (auto* block_stmt : *stmt) { + for (auto* block_stmt : stmt->statements) { if (!GenerateStatement(block_stmt)) { return false; } @@ -2222,7 +2217,7 @@ bool Builder::GenerateBlockStatementWithoutScoping( } uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) { - auto* ident = expr->func(); + auto* ident = expr->func; auto* call = builder_.Sem().Get(expr); auto* target = call->Target(); if (auto* intrinsic = target->As()) { @@ -2239,16 +2234,16 @@ uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) { OperandList ops = {Operand::Int(type_id), result}; - auto func_id = func_symbol_to_id_[ident->symbol()]; + auto func_id = func_symbol_to_id_[ident->symbol]; if (func_id == 0) { error_ = "unable to find called function: " + - builder_.Symbols().NameFor(ident->symbol()); + builder_.Symbols().NameFor(ident->symbol); return 0; } ops.push_back(Operand::Int(func_id)); size_t arg_idx = 0; - for (auto* arg : expr->args()) { + for (auto* arg : expr->args) { auto id = GenerateExpression(arg); if (id == 0) { return 0; @@ -2313,7 +2308,7 @@ uint32_t Builder::GenerateIntrinsic(ast::CallExpression* call, // and loads it if necessary. Returns 0 on error. auto get_param_as_value_id = [&](size_t i, bool generate_load = true) -> uint32_t { - auto* arg = call->args()[i]; + auto* arg = call->args[i]; auto* param = intrinsic->Parameters()[i]; auto val_id = GenerateExpression(arg); if (val_id == 0) { @@ -2346,19 +2341,19 @@ uint32_t Builder::GenerateIntrinsic(ast::CallExpression* call, op = spv::Op::OpAll; break; case IntrinsicType::kArrayLength: { - if (call->args().empty()) { + if (call->args.empty()) { error_ = "missing param for runtime array length"; return 0; } - auto* arg = call->args()[0]; + auto* arg = call->args[0]; auto* address_of = arg->As(); - if (!address_of || address_of->op() != ast::UnaryOp::kAddressOf) { + if (!address_of || address_of->op != ast::UnaryOp::kAddressOf) { error_ = "arrayLength() expected pointer to member access, got " + std::string(address_of->TypeInfo().name); return 0; } - auto* array_expr = address_of->expr(); + auto* array_expr = address_of->expr; auto* accessor = array_expr->As(); if (!accessor) { @@ -2368,13 +2363,13 @@ uint32_t Builder::GenerateIntrinsic(ast::CallExpression* call, return 0; } - auto struct_id = GenerateExpression(accessor->structure()); + auto struct_id = GenerateExpression(accessor->structure); if (struct_id == 0) { return 0; } params.push_back(Operand::Int(struct_id)); - auto* type = TypeOf(accessor->structure())->UnwrapRef(); + auto* type = TypeOf(accessor->structure)->UnwrapRef(); if (!type->Is()) { error_ = "invalid type (" + type->type_name() + ") for runtime array length"; @@ -2382,7 +2377,7 @@ uint32_t Builder::GenerateIntrinsic(ast::CallExpression* call, } // Runtime array must be the last member in the structure params.push_back(Operand::Int(uint32_t( - type->As()->Declaration()->members().size() - 1))); + type->As()->Declaration()->members.size() - 1))); if (!push_function_inst(spv::Op::OpArrayLength, params)) { return 0; @@ -2638,7 +2633,7 @@ uint32_t Builder::GenerateIntrinsic(ast::CallExpression* call, return 0; } - for (size_t i = 0; i < call->args().size(); i++) { + for (size_t i = 0; i < call->args.size(); i++) { if (auto val_id = get_param_as_value_id(i)) { params.emplace_back(Operand::Int(val_id)); } else { @@ -2660,7 +2655,7 @@ bool Builder::GenerateTextureIntrinsic(ast::CallExpression* call, using Usage = sem::ParameterUsage; auto& signature = intrinsic->Signature(); - auto arguments = call->args(); + auto arguments = call->args; // Generates the given expression, returning the operand ID auto gen = [&](ast::Expression* expr) { @@ -3136,18 +3131,18 @@ bool Builder::GenerateAtomicIntrinsic(ast::CallExpression* call, return false; } - uint32_t pointer_id = GenerateExpression(call->args()[0]); + uint32_t pointer_id = GenerateExpression(call->args[0]); if (pointer_id == 0) { return false; } uint32_t value_id = 0; - if (call->args().size() > 1) { - value_id = GenerateExpression(call->args().back()); + if (call->args.size() > 1) { + value_id = GenerateExpression(call->args.back()); if (value_id == 0) { return false; } - value_id = GenerateLoadIfNeeded(TypeOf(call->args().back()), value_id); + value_id = GenerateLoadIfNeeded(TypeOf(call->args.back()), value_id); if (value_id == 0) { return false; } @@ -3251,12 +3246,12 @@ bool Builder::GenerateAtomicIntrinsic(ast::CallExpression* call, value, }); case sem::IntrinsicType::kAtomicCompareExchangeWeak: { - auto comparator = GenerateExpression(call->args()[1]); + auto comparator = GenerateExpression(call->args[1]); if (comparator == 0) { return false; } - auto* value_sem_type = TypeOf(call->args()[2]); + auto* value_sem_type = TypeOf(call->args[2]); auto value_type = GenerateTypeIfNeeded(value_sem_type); if (value_type == 0) { @@ -3382,15 +3377,15 @@ uint32_t Builder::GenerateBitcastExpression(ast::BitcastExpression* expr) { return 0; } - auto val_id = GenerateExpression(expr->expr()); + auto val_id = GenerateExpression(expr->expr); if (val_id == 0) { return 0; } - val_id = GenerateLoadIfNeeded(TypeOf(expr->expr()), val_id); + val_id = GenerateLoadIfNeeded(TypeOf(expr->expr), val_id); // Bitcast does not allow same types, just emit a CopyObject auto* to_type = TypeOf(expr)->UnwrapRef(); - auto* from_type = TypeOf(expr->expr())->UnwrapRef(); + auto* from_type = TypeOf(expr->expr)->UnwrapRef(); if (to_type->type_name() == from_type->type_name()) { if (!push_function_inst( spv::Op::OpCopyObject, @@ -3465,17 +3460,17 @@ bool Builder::GenerateConditionalBlock( auto* else_stmt = else_stmts[cur_else_idx]; // Handle the else case by just outputting the statements. - if (!else_stmt->HasCondition()) { - if (!GenerateBlockStatement(else_stmt->body())) { + if (!else_stmt->condition) { + if (!GenerateBlockStatement(else_stmt->body)) { return false; } } else { - if (!GenerateConditionalBlock(else_stmt->condition(), else_stmt->body(), + if (!GenerateConditionalBlock(else_stmt->condition, else_stmt->body, cur_else_idx + 1, else_stmts)) { return false; } } - if (!LastIsTerminator(else_stmt->body())) { + if (!LastIsTerminator(else_stmt->body)) { if (!push_function_inst(spv::Op::OpBranch, {Operand::Int(merge_block_id)})) { return false; @@ -3503,25 +3498,25 @@ bool Builder::GenerateIfStatement(ast::IfStatement* stmt) { // if (cond) {} else {break;} // } auto is_just_a_break = [](ast::BlockStatement* block) { - return block && (block->size() == 1) && - block->last()->Is(); + return block && (block->statements.size() == 1) && + block->Last()->Is(); }; - if (is_just_a_break(stmt->body()) && !stmt->has_else_statements()) { + if (is_just_a_break(stmt->body) && stmt->else_statements.empty()) { // It's a break-if. TINT_ASSERT(Writer, !backedge_stack_.empty()); - const auto cond_id = GenerateExpression(stmt->condition()); + const auto cond_id = GenerateExpression(stmt->condition); backedge_stack_.back() = Backedge(spv::Op::OpBranchConditional, {Operand::Int(cond_id), Operand::Int(ci.break_target_id), Operand::Int(ci.loop_header_id)}); return true; - } else if (stmt->body()->empty()) { - const auto& es = stmt->else_statements(); - if (es.size() == 1 && !es.back()->HasCondition() && - is_just_a_break(es.back()->body())) { + } else if (stmt->body->Empty()) { + const auto& es = stmt->else_statements; + if (es.size() == 1 && !es.back()->condition && + is_just_a_break(es.back()->body)) { // It's a break-unless. TINT_ASSERT(Writer, !backedge_stack_.empty()); - const auto cond_id = GenerateExpression(stmt->condition()); + const auto cond_id = GenerateExpression(stmt->condition); backedge_stack_.back() = Backedge(spv::Op::OpBranchConditional, {Operand::Int(cond_id), Operand::Int(ci.loop_header_id), @@ -3531,8 +3526,8 @@ bool Builder::GenerateIfStatement(ast::IfStatement* stmt) { } } - if (!GenerateConditionalBlock(stmt->condition(), stmt->body(), 0, - stmt->else_statements())) { + if (!GenerateConditionalBlock(stmt->condition, stmt->body, 0, + stmt->else_statements)) { return false; } return true; @@ -3544,11 +3539,11 @@ bool Builder::GenerateSwitchStatement(ast::SwitchStatement* stmt) { merge_stack_.push_back(merge_block_id); - auto cond_id = GenerateExpression(stmt->condition()); + auto cond_id = GenerateExpression(stmt->condition); if (cond_id == 0) { return false; } - cond_id = GenerateLoadIfNeeded(TypeOf(stmt->condition()), cond_id); + cond_id = GenerateLoadIfNeeded(TypeOf(stmt->condition), cond_id); auto default_block = result_op(); auto default_block_id = default_block.to_i(); @@ -3556,7 +3551,7 @@ bool Builder::GenerateSwitchStatement(ast::SwitchStatement* stmt) { OperandList params = {Operand::Int(cond_id), Operand::Int(default_block_id)}; std::vector case_ids; - for (const auto* item : stmt->body()) { + for (const auto* item : stmt->body) { if (item->IsDefault()) { case_ids.push_back(default_block_id); continue; @@ -3566,14 +3561,14 @@ bool Builder::GenerateSwitchStatement(ast::SwitchStatement* stmt) { auto block_id = block.to_i(); case_ids.push_back(block_id); - for (auto* selector : item->selectors()) { + for (auto* selector : item->selectors) { auto* int_literal = selector->As(); if (!int_literal) { error_ = "expected integer literal for switch case label"; return false; } - params.push_back(Operand::Int(int_literal->value_as_u32())); + params.push_back(Operand::Int(int_literal->ValueAsU32())); params.push_back(Operand::Int(block_id)); } } @@ -3588,7 +3583,7 @@ bool Builder::GenerateSwitchStatement(ast::SwitchStatement* stmt) { } bool generated_default = false; - auto& body = stmt->body(); + auto& body = stmt->body; // We output the case statements in order they were entered in the original // source. Each fallthrough goes to the next case entry, so is a forward // branch, otherwise the branch is to the merge block which comes after @@ -3603,11 +3598,11 @@ bool Builder::GenerateSwitchStatement(ast::SwitchStatement* stmt) { if (!GenerateLabel(case_ids[i])) { return false; } - if (!GenerateBlockStatement(item->body())) { + if (!GenerateBlockStatement(item->body)) { return false; } - if (LastIsFallthrough(item->body())) { + if (LastIsFallthrough(item->body)) { if (i == (body.size() - 1)) { // This case is caught by Resolver validation TINT_UNREACHABLE(Writer, builder_.Diagnostics()); @@ -3617,7 +3612,7 @@ bool Builder::GenerateSwitchStatement(ast::SwitchStatement* stmt) { {Operand::Int(case_ids[i + 1])})) { return false; } - } else if (!LastIsTerminator(item->body())) { + } else if (!LastIsTerminator(item->body)) { if (!push_function_inst(spv::Op::OpBranch, {Operand::Int(merge_block_id)})) { return false; @@ -3641,12 +3636,12 @@ bool Builder::GenerateSwitchStatement(ast::SwitchStatement* stmt) { } bool Builder::GenerateReturnStatement(ast::ReturnStatement* stmt) { - if (stmt->has_value()) { - auto val_id = GenerateExpression(stmt->value()); + if (stmt->value) { + auto val_id = GenerateExpression(stmt->value); if (val_id == 0) { return false; } - val_id = GenerateLoadIfNeeded(TypeOf(stmt->value()), val_id); + val_id = GenerateLoadIfNeeded(TypeOf(stmt->value), val_id); if (!push_function_inst(spv::Op::OpReturnValue, {Operand::Int(val_id)})) { return false; } @@ -3703,12 +3698,12 @@ bool Builder::GenerateLoopStatement(ast::LoopStatement* stmt) { // manage scope outside of GenerateBlockStatement. scope_stack_.push_scope(); - if (!GenerateBlockStatementWithoutScoping(stmt->body())) { + if (!GenerateBlockStatementWithoutScoping(stmt->body)) { return false; } // We only branch if the last element of the body didn't already branch. - if (!LastIsTerminator(stmt->body())) { + if (!LastIsTerminator(stmt->body)) { if (!push_function_inst(spv::Op::OpBranch, {Operand::Int(continue_block_id)})) { return false; @@ -3718,10 +3713,10 @@ bool Builder::GenerateLoopStatement(ast::LoopStatement* stmt) { if (!GenerateLabel(continue_block_id)) { return false; } - if (stmt->has_continuing()) { - continuing_stack_.emplace_back(stmt->continuing()->last(), loop_header_id, + if (stmt->continuing && !stmt->continuing->Empty()) { + continuing_stack_.emplace_back(stmt->continuing->Last(), loop_header_id, merge_block_id); - if (!GenerateBlockStatementWithoutScoping(stmt->continuing())) { + if (!GenerateBlockStatementWithoutScoping(stmt->continuing)) { return false; } continuing_stack_.pop_back(); @@ -3754,7 +3749,7 @@ bool Builder::GenerateStatement(ast::Statement* stmt) { return GenerateBreakStatement(b); } if (auto* c = stmt->As()) { - return GenerateCallExpression(c->expr()) != 0; + return GenerateCallExpression(c->expr) != 0; } if (auto* c = stmt->As()) { return GenerateContinueStatement(c); @@ -3787,7 +3782,7 @@ bool Builder::GenerateStatement(ast::Statement* stmt) { } bool Builder::GenerateVariableDeclStatement(ast::VariableDeclStatement* stmt) { - return GenerateFunctionVariable(stmt->variable()); + return GenerateFunctionVariable(stmt->variable); } uint32_t Builder::GenerateTypeIfNeeded(const sem::Type* type) { diff --git a/src/writer/spirv/builder_intrinsic_texture_test.cc b/src/writer/spirv/builder_intrinsic_texture_test.cc index bb28957345..a8f60c80b8 100644 --- a/src/writer/spirv/builder_intrinsic_texture_test.cc +++ b/src/writer/spirv/builder_intrinsic_texture_test.cc @@ -3169,8 +3169,8 @@ INSTANTIATE_TEST_SUITE_P( TEST_P(IntrinsicTextureTest, Call) { auto param = GetParam(); - auto* texture = param.buildTextureVariable(this); - auto* sampler = param.buildSamplerVariable(this); + auto* texture = param.BuildTextureVariable(this); + auto* sampler = param.BuildSamplerVariable(this); auto* call = Call(param.function, param.args(this)); auto* stmt = ast::intrinsic::test::ReturnsVoid(param.overload) @@ -3197,8 +3197,8 @@ TEST_P(IntrinsicTextureTest, Call) { TEST_P(IntrinsicTextureTest, ValidateSPIRV) { auto param = GetParam(); - param.buildTextureVariable(this); - param.buildSamplerVariable(this); + param.BuildTextureVariable(this); + param.BuildSamplerVariable(this); auto* call = Call(param.function, param.args(this)); @@ -3220,8 +3220,8 @@ TEST_P(IntrinsicTextureTest, OutsideFunction_IsError) { // The point of this test is to try to generate the texture // intrinsic call outside a function. - auto* texture = param.buildTextureVariable(this); - auto* sampler = param.buildSamplerVariable(this); + auto* texture = param.BuildTextureVariable(this); + auto* sampler = param.BuildSamplerVariable(this); auto* call = Call(param.function, param.args(this)); auto* stmt = ast::intrinsic::test::ReturnsVoid(param.overload) diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index c226b1f3b5..68133bb862 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -96,8 +96,8 @@ bool GeneratorImpl::Generate() { bool GeneratorImpl::EmitTypeDecl(const ast::TypeDecl* ty) { if (auto* alias = ty->As()) { auto out = line(); - out << "type " << program_->Symbols().NameFor(alias->symbol()) << " = "; - if (!EmitType(out, alias->type())) { + out << "type " << program_->Symbols().NameFor(alias->name) << " = "; + if (!EmitType(out, alias->type)) { return false; } out << ";"; @@ -147,14 +147,14 @@ bool GeneratorImpl::EmitExpression(std::ostream& out, ast::Expression* expr) { bool GeneratorImpl::EmitArrayAccessor(std::ostream& out, ast::ArrayAccessorExpression* expr) { bool paren_lhs = - !expr->array() + !expr->array ->IsAnyOf(); if (paren_lhs) { out << "("; } - if (!EmitExpression(out, expr->array())) { + if (!EmitExpression(out, expr->array)) { return false; } if (paren_lhs) { @@ -162,7 +162,7 @@ bool GeneratorImpl::EmitArrayAccessor(std::ostream& out, } out << "["; - if (!EmitExpression(out, expr->idx_expr())) { + if (!EmitExpression(out, expr->index)) { return false; } out << "]"; @@ -173,14 +173,14 @@ bool GeneratorImpl::EmitArrayAccessor(std::ostream& out, bool GeneratorImpl::EmitMemberAccessor(std::ostream& out, ast::MemberAccessorExpression* expr) { bool paren_lhs = - !expr->structure() + !expr->structure ->IsAnyOf(); if (paren_lhs) { out << "("; } - if (!EmitExpression(out, expr->structure())) { + if (!EmitExpression(out, expr->structure)) { return false; } if (paren_lhs) { @@ -189,18 +189,18 @@ bool GeneratorImpl::EmitMemberAccessor(std::ostream& out, out << "."; - return EmitExpression(out, expr->member()); + return EmitExpression(out, expr->member); } bool GeneratorImpl::EmitBitcast(std::ostream& out, ast::BitcastExpression* expr) { out << "bitcast<"; - if (!EmitType(out, expr->type())) { + if (!EmitType(out, expr->type)) { return false; } out << ">("; - if (!EmitExpression(out, expr->expr())) { + if (!EmitExpression(out, expr->expr)) { return false; } @@ -209,13 +209,13 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, } bool GeneratorImpl::EmitCall(std::ostream& out, ast::CallExpression* expr) { - if (!EmitExpression(out, expr->func())) { + if (!EmitExpression(out, expr->func)) { return false; } out << "("; bool first = true; - const auto& args = expr->args(); + const auto& args = expr->args; for (auto* arg : args) { if (!first) { out << ", "; @@ -242,14 +242,14 @@ bool GeneratorImpl::EmitConstructor(std::ostream& out, bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, ast::TypeConstructorExpression* expr) { - if (!EmitType(out, expr->type())) { + if (!EmitType(out, expr->type)) { return false; } out << "("; bool first = true; - for (auto* e : expr->values()) { + for (auto* e : expr->values) { if (!first) { out << ", "; } @@ -267,18 +267,18 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out, bool GeneratorImpl::EmitScalarConstructor( std::ostream& out, ast::ScalarConstructorExpression* expr) { - return EmitLiteral(out, expr->literal()); + return EmitLiteral(out, expr->literal); } bool GeneratorImpl::EmitLiteral(std::ostream& out, ast::Literal* lit) { if (auto* bl = lit->As()) { - out << (bl->IsTrue() ? "true" : "false"); + out << (bl->value ? "true" : "false"); } else if (auto* fl = lit->As()) { - out << FloatToBitPreservingString(fl->value()); + out << FloatToBitPreservingString(fl->value); } else if (auto* sl = lit->As()) { - out << sl->value(); + out << sl->value; } else if (auto* ul = lit->As()) { - out << ul->value() << "u"; + out << ul->value << "u"; } else { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); return false; @@ -288,66 +288,66 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, ast::Literal* lit) { bool GeneratorImpl::EmitIdentifier(std::ostream& out, ast::IdentifierExpression* expr) { - out << program_->Symbols().NameFor(expr->symbol()); + out << program_->Symbols().NameFor(expr->symbol); return true; } bool GeneratorImpl::EmitFunction(ast::Function* func) { - if (func->decorations().size()) { - if (!EmitDecorations(line(), func->decorations())) { + if (func->decorations.size()) { + if (!EmitDecorations(line(), func->decorations)) { return false; } } { auto out = line(); - out << "fn " << program_->Symbols().NameFor(func->symbol()) << "("; + out << "fn " << program_->Symbols().NameFor(func->symbol) << "("; bool first = true; - for (auto* v : func->params()) { + for (auto* v : func->params) { if (!first) { out << ", "; } first = false; - if (!v->decorations().empty()) { - if (!EmitDecorations(out, v->decorations())) { + if (!v->decorations.empty()) { + if (!EmitDecorations(out, v->decorations)) { return false; } out << " "; } - out << program_->Symbols().NameFor(v->symbol()) << " : "; + out << program_->Symbols().NameFor(v->symbol) << " : "; - if (!EmitType(out, v->type())) { + if (!EmitType(out, v->type)) { return false; } } out << ")"; - if (!func->return_type()->Is() || - !func->return_type_decorations().empty()) { + if (!func->return_type->Is() || + !func->return_type_decorations.empty()) { out << " -> "; - if (!func->return_type_decorations().empty()) { - if (!EmitDecorations(out, func->return_type_decorations())) { + if (!func->return_type_decorations.empty()) { + if (!EmitDecorations(out, func->return_type_decorations)) { return false; } out << " "; } - if (!EmitType(out, func->return_type())) { + if (!EmitType(out, func->return_type)) { return false; } } - if (func->body()) { + if (func->body) { out << " {"; } } - if (func->body()) { - if (!EmitStatementsWithIndent(func->body()->statements())) { + if (func->body) { + if (!EmitStatementsWithIndent(func->body->statements)) { return false; } line() << "}"; @@ -388,20 +388,20 @@ bool GeneratorImpl::EmitAccess(std::ostream& out, const ast::Access access) { bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { if (auto* ary = ty->As()) { - for (auto* deco : ary->decorations()) { + for (auto* deco : ary->decorations) { if (auto* stride = deco->As()) { - out << "[[stride(" << stride->stride() << ")]] "; + out << "[[stride(" << stride->stride << ")]] "; } } out << "array<"; - if (!EmitType(out, ary->type())) { + if (!EmitType(out, ary->type)) { return false; } if (!ary->IsRuntimeArray()) { out << ", "; - if (!EmitExpression(out, ary->Size())) { + if (!EmitExpression(out, ary->count)) { return false; } } @@ -414,26 +414,26 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { } else if (ty->Is()) { out << "i32"; } else if (auto* mat = ty->As()) { - out << "mat" << mat->columns() << "x" << mat->rows() << "<"; - if (!EmitType(out, mat->type())) { + out << "mat" << mat->columns << "x" << mat->rows << "<"; + if (!EmitType(out, mat->type)) { return false; } out << ">"; } else if (auto* ptr = ty->As()) { - out << "ptr<" << ptr->storage_class() << ", "; - if (!EmitType(out, ptr->type())) { + out << "ptr<" << ptr->storage_class << ", "; + if (!EmitType(out, ptr->type)) { return false; } - if (ptr->access() != ast::Access::kUndefined) { + if (ptr->access != ast::Access::kUndefined) { out << ", "; - if (!EmitAccess(out, ptr->access())) { + if (!EmitAccess(out, ptr->access)) { return false; } } out << ">"; } else if (auto* atomic = ty->As()) { out << "atomic<"; - if (!EmitType(out, atomic->type())) { + if (!EmitType(out, atomic->type)) { return false; } out << ">"; @@ -462,7 +462,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { return false; } - switch (texture->dim()) { + switch (texture->dim) { case ast::TextureDimension::k1d: out << "1d"; break; @@ -489,23 +489,23 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { if (auto* sampled = texture->As()) { out << "<"; - if (!EmitType(out, sampled->type())) { + if (!EmitType(out, sampled->type)) { return false; } out << ">"; } else if (auto* ms = texture->As()) { out << "<"; - if (!EmitType(out, ms->type())) { + if (!EmitType(out, ms->type)) { return false; } out << ">"; } else if (auto* storage = texture->As()) { out << "<"; - if (!EmitImageFormat(out, storage->image_format())) { + if (!EmitImageFormat(out, storage->format)) { return false; } out << ", "; - if (!EmitAccess(out, storage->access())) { + if (!EmitAccess(out, storage->access)) { return false; } out << ">"; @@ -514,15 +514,15 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { } else if (ty->Is()) { out << "u32"; } else if (auto* vec = ty->As()) { - out << "vec" << vec->size() << "<"; - if (!EmitType(out, vec->type())) { + out << "vec" << vec->width << "<"; + if (!EmitType(out, vec->type)) { return false; } out << ">"; } else if (ty->Is()) { out << "void"; } else if (auto* tn = ty->As()) { - out << program_->Symbols().NameFor(tn->name()); + out << program_->Symbols().NameFor(tn->name); } else { diagnostics_.add_error( diag::System::Writer, @@ -533,12 +533,12 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { } bool GeneratorImpl::EmitStructType(const ast::Struct* str) { - if (str->decorations().size()) { - if (!EmitDecorations(line(), str->decorations())) { + if (str->decorations.size()) { + if (!EmitDecorations(line(), str->decorations)) { return false; } } - line() << "struct " << program_->Symbols().NameFor(str->name()) << " {"; + line() << "struct " << program_->Symbols().NameFor(str->name) << " {"; auto add_padding = [&](uint32_t size) { line() << "[[size(" << size << ")]]"; @@ -550,7 +550,7 @@ bool GeneratorImpl::EmitStructType(const ast::Struct* str) { increment_indent(); uint32_t offset = 0; - for (auto* mem : str->members()) { + for (auto* mem : str->members) { // TODO(crbug.com/tint/798) move the [[offset]] decoration handling to the // transform::Wgsl sanitizer. if (auto* mem_sem = program_->Sem().Get(mem)) { @@ -566,8 +566,8 @@ bool GeneratorImpl::EmitStructType(const ast::Struct* str) { // by the SPIR-V reader and are consumed by the Resolver(). These should not // be emitted, but instead struct padding fields should be emitted. ast::DecorationList decorations_sanitized; - decorations_sanitized.reserve(mem->decorations().size()); - for (auto* deco : mem->decorations()) { + decorations_sanitized.reserve(mem->decorations.size()); + for (auto* deco : mem->decorations) { if (!deco->Is()) { decorations_sanitized.emplace_back(deco); } @@ -580,8 +580,8 @@ bool GeneratorImpl::EmitStructType(const ast::Struct* str) { } auto out = line(); - out << program_->Symbols().NameFor(mem->symbol()) << " : "; - if (!EmitType(out, mem->type())) { + out << program_->Symbols().NameFor(mem->symbol) << " : "; + if (!EmitType(out, mem->type)) { return false; } out << ";"; @@ -593,19 +593,19 @@ bool GeneratorImpl::EmitStructType(const ast::Struct* str) { } bool GeneratorImpl::EmitVariable(std::ostream& out, ast::Variable* var) { - if (!var->decorations().empty()) { - if (!EmitDecorations(out, var->decorations())) { + if (!var->decorations.empty()) { + if (!EmitDecorations(out, var->decorations)) { return false; } out << " "; } - if (var->is_const()) { + if (var->is_const) { out << "let"; } else { out << "var"; - auto sc = var->declared_storage_class(); - auto ac = var->declared_access(); + auto sc = var->declared_storage_class; + auto ac = var->declared_access; if (sc != ast::StorageClass::kNone || ac != ast::Access::kUndefined) { out << "<" << sc; if (ac != ast::Access::kUndefined) { @@ -618,18 +618,18 @@ bool GeneratorImpl::EmitVariable(std::ostream& out, ast::Variable* var) { } } - out << " " << program_->Symbols().NameFor(var->symbol()); + out << " " << program_->Symbols().NameFor(var->symbol); - if (auto* ty = var->type()) { + if (auto* ty = var->type) { out << " : "; if (!EmitType(out, ty)) { return false; } } - if (var->constructor() != nullptr) { + if (var->constructor != nullptr) { out << " = "; - if (!EmitExpression(out, var->constructor())) { + if (!EmitExpression(out, var->constructor)) { return false; } } @@ -649,7 +649,7 @@ bool GeneratorImpl::EmitDecorations(std::ostream& out, first = false; if (auto* workgroup = deco->As()) { - auto values = workgroup->values(); + auto values = workgroup->Values(); out << "workgroup_size("; for (int i = 0; i < 3; i++) { if (values[i]) { @@ -665,34 +665,34 @@ bool GeneratorImpl::EmitDecorations(std::ostream& out, } else if (deco->Is()) { out << "block"; } else if (auto* stage = deco->As()) { - out << "stage(" << stage->value() << ")"; + out << "stage(" << stage->stage << ")"; } else if (auto* binding = deco->As()) { - out << "binding(" << binding->value() << ")"; + out << "binding(" << binding->value << ")"; } else if (auto* group = deco->As()) { - out << "group(" << group->value() << ")"; + out << "group(" << group->value << ")"; } else if (auto* location = deco->As()) { - out << "location(" << location->value() << ")"; + out << "location(" << location->value << ")"; } else if (auto* builtin = deco->As()) { - out << "builtin(" << builtin->value() << ")"; + out << "builtin(" << builtin->builtin << ")"; } else if (auto* interpolate = deco->As()) { - out << "interpolate(" << interpolate->type(); - if (interpolate->sampling() != ast::InterpolationSampling::kNone) { - out << ", " << interpolate->sampling(); + out << "interpolate(" << interpolate->type; + if (interpolate->sampling != ast::InterpolationSampling::kNone) { + out << ", " << interpolate->sampling; } out << ")"; } else if (deco->Is()) { out << "invariant"; } else if (auto* override_deco = deco->As()) { out << "override"; - if (override_deco->HasValue()) { - out << "(" << override_deco->value() << ")"; + if (override_deco->has_value) { + out << "(" << override_deco->value << ")"; } } else if (auto* size = deco->As()) { - out << "size(" << size->size() << ")"; + out << "size(" << size->size << ")"; } else if (auto* align = deco->As()) { - out << "align(" << align->align() << ")"; + out << "align(" << align->align << ")"; } else if (auto* stride = deco->As()) { - out << "stride(" << stride->stride() << ")"; + out << "stride(" << stride->stride << ")"; } else if (auto* internal = deco->As()) { out << "internal(" << internal->InternalName() << ")"; } else { @@ -709,12 +709,12 @@ bool GeneratorImpl::EmitDecorations(std::ostream& out, bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { out << "("; - if (!EmitExpression(out, expr->lhs())) { + if (!EmitExpression(out, expr->lhs)) { return false; } out << " "; - switch (expr->op()) { + switch (expr->op) { case ast::BinaryOp::kAnd: out << "&"; break; @@ -776,7 +776,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { } out << " "; - if (!EmitExpression(out, expr->rhs())) { + if (!EmitExpression(out, expr->rhs)) { return false; } @@ -786,7 +786,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { bool GeneratorImpl::EmitUnaryOp(std::ostream& out, ast::UnaryOpExpression* expr) { - switch (expr->op()) { + switch (expr->op) { case ast::UnaryOp::kAddressOf: out << "&"; break; @@ -805,7 +805,7 @@ bool GeneratorImpl::EmitUnaryOp(std::ostream& out, } out << "("; - if (!EmitExpression(out, expr->expr())) { + if (!EmitExpression(out, expr->expr)) { return false; } @@ -816,7 +816,7 @@ bool GeneratorImpl::EmitUnaryOp(std::ostream& out, bool GeneratorImpl::EmitBlock(const ast::BlockStatement* stmt) { line() << "{"; - if (!EmitStatementsWithIndent(stmt->statements())) { + if (!EmitStatementsWithIndent(stmt->statements)) { return false; } line() << "}"; @@ -836,7 +836,7 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) { } if (auto* c = stmt->As()) { auto out = line(); - if (!EmitCall(out, c->expr())) { + if (!EmitCall(out, c->expr)) { return false; } out << ";"; @@ -867,7 +867,7 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) { return EmitSwitch(s); } if (auto* v = stmt->As()) { - return EmitVariable(line(), v->variable()); + return EmitVariable(line(), v->variable); } diagnostics_.add_error( @@ -893,13 +893,13 @@ bool GeneratorImpl::EmitStatementsWithIndent(const ast::StatementList& stmts) { bool GeneratorImpl::EmitAssign(ast::AssignmentStatement* stmt) { auto out = line(); - if (!EmitExpression(out, stmt->lhs())) { + if (!EmitExpression(out, stmt->lhs)) { return false; } out << " = "; - if (!EmitExpression(out, stmt->rhs())) { + if (!EmitExpression(out, stmt->rhs)) { return false; } @@ -921,7 +921,7 @@ bool GeneratorImpl::EmitCase(ast::CaseStatement* stmt) { out << "case "; bool first = true; - for (auto* selector : stmt->selectors()) { + for (auto* selector : stmt->selectors) { if (!first) { out << ", "; } @@ -934,7 +934,7 @@ bool GeneratorImpl::EmitCase(ast::CaseStatement* stmt) { out << ": {"; } - if (!EmitStatementsWithIndent(stmt->body()->statements())) { + if (!EmitStatementsWithIndent(stmt->body->statements)) { return false; } @@ -956,21 +956,21 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { { auto out = line(); out << "if ("; - if (!EmitExpression(out, stmt->condition())) { + if (!EmitExpression(out, stmt->condition)) { return false; } out << ") {"; } - if (!EmitStatementsWithIndent(stmt->body()->statements())) { + if (!EmitStatementsWithIndent(stmt->body->statements)) { return false; } - for (auto* e : stmt->else_statements()) { - if (e->HasCondition()) { + for (auto* e : stmt->else_statements) { + if (e->condition) { auto out = line(); out << "} elseif ("; - if (!EmitExpression(out, e->condition())) { + if (!EmitExpression(out, e->condition)) { return false; } out << ") {"; @@ -978,7 +978,7 @@ bool GeneratorImpl::EmitIf(ast::IfStatement* stmt) { line() << "} else {"; } - if (!EmitStatementsWithIndent(e->body()->statements())) { + if (!EmitStatementsWithIndent(e->body->statements)) { return false; } } @@ -997,14 +997,14 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { line() << "loop {"; increment_indent(); - if (!EmitStatements(stmt->body()->statements())) { + if (!EmitStatements(stmt->body->statements)) { return false; } - if (stmt->has_continuing()) { + if (stmt->continuing && !stmt->continuing->Empty()) { line(); line() << "continuing {"; - if (!EmitStatementsWithIndent(stmt->continuing()->statements())) { + if (!EmitStatementsWithIndent(stmt->continuing->statements)) { return false; } line() << "}"; @@ -1018,7 +1018,7 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { TextBuffer init_buf; - if (auto* init = stmt->initializer()) { + if (auto* init = stmt->initializer) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &init_buf); if (!EmitStatement(init)) { return false; @@ -1026,7 +1026,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { } TextBuffer cont_buf; - if (auto* cont = stmt->continuing()) { + if (auto* cont = stmt->continuing) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &cont_buf); if (!EmitStatement(cont)) { return false; @@ -1055,7 +1055,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { out << "; "; - if (auto* cond = stmt->condition()) { + if (auto* cond = stmt->condition) { if (!EmitExpression(out, cond)) { return false; } @@ -1081,7 +1081,7 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { out << " {"; } - if (!EmitStatementsWithIndent(stmt->body()->statements())) { + if (!EmitStatementsWithIndent(stmt->body->statements)) { return false; } @@ -1093,9 +1093,9 @@ bool GeneratorImpl::EmitForLoop(ast::ForLoopStatement* stmt) { bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) { auto out = line(); out << "return"; - if (stmt->has_value()) { + if (stmt->value) { out << " "; - if (!EmitExpression(out, stmt->value())) { + if (!EmitExpression(out, stmt->value)) { return false; } } @@ -1107,7 +1107,7 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) { { auto out = line(); out << "switch("; - if (!EmitExpression(out, stmt->condition())) { + if (!EmitExpression(out, stmt->condition)) { return false; } out << ") {"; @@ -1115,7 +1115,7 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) { { ScopedIndent si(this); - for (auto* s : stmt->body()) { + for (auto* s : stmt->body) { if (!EmitCase(s)) { return false; } diff --git a/src/writer/wgsl/generator_impl_case_test.cc b/src/writer/wgsl/generator_impl_case_test.cc index e03ee56e5c..92b20db8d9 100644 --- a/src/writer/wgsl/generator_impl_case_test.cc +++ b/src/writer/wgsl/generator_impl_case_test.cc @@ -30,7 +30,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Case) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( case 5: { break; } @@ -47,7 +47,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( case 5, 6: { break; } @@ -62,7 +62,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_Default) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error(); + ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.error(); EXPECT_EQ(gen.result(), R"( default: { break; }