From 3e67c5dba6b67ec37ef49b36d86bf80fb697be56 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 23 Nov 2020 19:30:55 +0000 Subject: [PATCH] Move type_manager to the ast dir/namespace First step to moving this to the `ast::Module`. Also remove a bunch of redundant includes to `type_manager.h` as this is already included in `context.h` Bug: tint:307 Bug: tint:337 Change-Id: Ic4baffa7b76ddefa29f56f758c25b1003ef40888 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33665 Commit-Queue: Ben Clayton Reviewed-by: David Neto --- BUILD.gn | 6 +++--- include/tint/tint.h | 2 +- src/CMakeLists.txt | 6 +++--- src/{ => ast}/type_manager.cc | 4 +++- src/{ => ast}/type_manager.h | 8 +++++--- src/{ => ast}/type_manager_test.cc | 10 +++++----- src/context.cc | 1 - src/context.h | 6 +++--- src/reader/spirv/parser_impl.cc | 1 - src/reader/spirv/parser_impl_convert_type_test.cc | 1 - src/reader/spirv/parser_impl_named_types_test.cc | 1 - src/reader/wgsl/parser_impl.cc | 1 - src/reader/wgsl/parser_impl_function_type_decl_test.cc | 1 - src/reader/wgsl/parser_impl_param_list_test.cc | 1 - src/reader/wgsl/parser_impl_primary_expression_test.cc | 1 - src/reader/wgsl/parser_impl_struct_body_decl_test.cc | 1 - src/reader/wgsl/parser_impl_struct_member_test.cc | 1 - src/reader/wgsl/parser_impl_test_helper.h | 4 ++-- src/reader/wgsl/parser_impl_type_alias_test.cc | 1 - src/reader/wgsl/parser_impl_type_decl_test.cc | 1 - src/transform/bound_array_accessors_transform.cc | 1 - src/validator/validator_test_helper.cc | 2 -- 22 files changed, 25 insertions(+), 36 deletions(-) rename src/{ => ast}/type_manager.cc (93%) rename src/{ => ast}/type_manager.h (92%) rename src/{ => ast}/type_manager_test.cc (93%) diff --git a/BUILD.gn b/BUILD.gn index 0b2fdcc5f0..5199a59077 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -371,6 +371,8 @@ source_set("libtint_core_src") { "src/ast/type_constructor_expression.h", "src/ast/type_decoration.cc", "src/ast/type_decoration.h", + "src/ast/type_manager.cc", + "src/ast/type_manager.h", "src/ast/uint_literal.cc", "src/ast/uint_literal.h", "src/ast/unary_op.cc", @@ -416,8 +418,6 @@ source_set("libtint_core_src") { "src/transform/vertex_pulling_transform.h", "src/type_determiner.cc", "src/type_determiner.h", - "src/type_manager.cc", - "src/type_manager.h", "src/validator/validator.cc", "src/validator/validator.h", "src/validator/validator_impl.cc", @@ -797,6 +797,7 @@ source_set("tint_unittests_core_src") { "src/ast/type/u32_type_test.cc", "src/ast/type/vector_type_test.cc", "src/ast/type_constructor_expression_test.cc", + "src/ast/type_manager_test.cc", "src/ast/uint_literal_test.cc", "src/ast/unary_op_expression_test.cc", "src/ast/variable_decl_statement_test.cc", @@ -810,7 +811,6 @@ source_set("tint_unittests_core_src") { "src/transform/bound_array_accessors_transform_test.cc", "src/transform/vertex_pulling_transform_test.cc", "src/type_determiner_test.cc", - "src/type_manager_test.cc", "src/validator/validator_control_block_test.cc", "src/validator/validator_function_test.cc", "src/validator/validator_test.cc", diff --git a/include/tint/tint.h b/include/tint/tint.h index e09537c39c..5d9a84a793 100644 --- a/include/tint/tint.h +++ b/include/tint/tint.h @@ -19,6 +19,7 @@ // headers will need to be moved to include/tint/. #include "src/ast/pipeline_stage.h" +#include "src/ast/type_manager.h" #include "src/context.h" #include "src/diagnostic/printer.h" #include "src/inspector/inspector.h" @@ -28,7 +29,6 @@ #include "src/transform/manager.h" #include "src/transform/vertex_pulling_transform.h" #include "src/type_determiner.h" -#include "src/type_manager.h" #include "src/validator/validator.h" #include "src/writer/writer.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 94aceb0258..90dc67c041 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -192,6 +192,8 @@ set(TINT_LIB_SRCS ast/type/vector_type.h ast/type/void_type.cc ast/type/void_type.h + ast/type_manager.cc + ast/type_manager.h ast/uint_literal.cc ast/uint_literal.h ast/unary_op.cc @@ -237,8 +239,6 @@ set(TINT_LIB_SRCS transform/vertex_pulling_transform.h type_determiner.cc type_determiner.h - type_manager.cc - type_manager.h validator/validator.cc validator/validator.h validator/validator_impl.cc @@ -407,6 +407,7 @@ set(TINT_TEST_SRCS ast/type/u32_type_test.cc ast/type/vector_type_test.cc ast/type_constructor_expression_test.cc + ast/type_manager_test.cc ast/uint_literal_test.cc ast/unary_op_expression_test.cc ast/variable_decl_statement_test.cc @@ -420,7 +421,6 @@ set(TINT_TEST_SRCS transform/bound_array_accessors_transform_test.cc transform/vertex_pulling_transform_test.cc type_determiner_test.cc - type_manager_test.cc validator/validator_control_block_test.cc validator/validator_function_test.cc validator/validator_test.cc diff --git a/src/type_manager.cc b/src/ast/type_manager.cc similarity index 93% rename from src/type_manager.cc rename to src/ast/type_manager.cc index 88569ce26f..616628718b 100644 --- a/src/type_manager.cc +++ b/src/ast/type_manager.cc @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/type_manager.h" +#include "src/ast/type_manager.h" #include namespace tint { +namespace ast { TypeManager::TypeManager() = default; @@ -35,4 +36,5 @@ ast::type::Type* TypeManager::Get(std::unique_ptr type) { return types_.find(name)->second.get(); } +} // namespace ast } // namespace tint diff --git a/src/type_manager.h b/src/ast/type_manager.h similarity index 92% rename from src/type_manager.h rename to src/ast/type_manager.h index f7f5601126..8f4eb9983b 100644 --- a/src/type_manager.h +++ b/src/ast/type_manager.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_TYPE_MANAGER_H_ -#define SRC_TYPE_MANAGER_H_ +#ifndef SRC_AST_TYPE_MANAGER_H_ +#define SRC_AST_TYPE_MANAGER_H_ #include #include @@ -23,6 +23,7 @@ #include "src/ast/type/type.h" namespace tint { +namespace ast { /// The type manager holds all the pointers to the known types. class TypeManager { @@ -58,6 +59,7 @@ class TypeManager { std::unordered_map> types_; }; +} // namespace ast } // namespace tint -#endif // SRC_TYPE_MANAGER_H_ +#endif // SRC_AST_TYPE_MANAGER_H_ diff --git a/src/type_manager_test.cc b/src/ast/type_manager_test.cc similarity index 93% rename from src/type_manager_test.cc rename to src/ast/type_manager_test.cc index 784eedd611..4bbd9a91fd 100644 --- a/src/type_manager_test.cc +++ b/src/ast/type_manager_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/type_manager.h" +#include "src/ast/type_manager.h" #include "gtest/gtest.h" #include "src/ast/test_helper.h" @@ -25,14 +25,14 @@ namespace { using TypeManagerTest = testing::Test; TEST_F(TypeManagerTest, GetUnregistered) { - TypeManager tm; + ast::TypeManager tm; auto* t = tm.Get(std::make_unique()); ASSERT_NE(t, nullptr); EXPECT_TRUE(t->IsI32()); } TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) { - TypeManager tm; + ast::TypeManager tm; auto* t = tm.Get(std::make_unique()); ASSERT_NE(t, nullptr); EXPECT_TRUE(t->IsI32()); @@ -42,7 +42,7 @@ TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) { } TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) { - TypeManager tm; + ast::TypeManager tm; auto* t = tm.Get(std::make_unique()); ASSERT_NE(t, nullptr); EXPECT_TRUE(t->IsI32()); @@ -54,7 +54,7 @@ TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) { } TEST_F(TypeManagerTest, ResetClearsPreviousData) { - TypeManager tm; + ast::TypeManager tm; auto* t = tm.Get(std::make_unique()); ASSERT_NE(t, nullptr); diff --git a/src/context.cc b/src/context.cc index e72ee82216..fff10523ae 100644 --- a/src/context.cc +++ b/src/context.cc @@ -18,7 +18,6 @@ #include "src/ast/node.h" #include "src/namer.h" -#include "src/type_manager.h" namespace tint { diff --git a/src/context.h b/src/context.h index 300b1130f1..072ab86878 100644 --- a/src/context.h +++ b/src/context.h @@ -22,8 +22,8 @@ #include #include +#include "src/ast/type_manager.h" #include "src/namer.h" -#include "src/type_manager.h" namespace tint { @@ -46,13 +46,13 @@ class Context { void Reset(); /// @returns the Type Manager - TypeManager& type_mgr() { return type_mgr_; } + ast::TypeManager& type_mgr() { return type_mgr_; } /// @returns the namer object Namer* namer() const { return namer_.get(); } private: - TypeManager type_mgr_; + ast::TypeManager type_mgr_; std::unique_ptr namer_; }; diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index f6a1489750..c0bf2c7b39 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -80,7 +80,6 @@ #include "src/reader/spirv/enum_converter.h" #include "src/reader/spirv/function.h" #include "src/reader/spirv/usage.h" -#include "src/type_manager.h" namespace tint { namespace reader { diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc index 5cbb1e0192..d403ee45e8 100644 --- a/src/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/reader/spirv/parser_impl_convert_type_test.cc @@ -27,7 +27,6 @@ #include "src/reader/spirv/parser_impl.h" #include "src/reader/spirv/parser_impl_test_helper.h" #include "src/reader/spirv/spirv_tools_helpers_test.h" -#include "src/type_manager.h" namespace tint { namespace reader { diff --git a/src/reader/spirv/parser_impl_named_types_test.cc b/src/reader/spirv/parser_impl_named_types_test.cc index 3b7e933731..0cc904d332 100644 --- a/src/reader/spirv/parser_impl_named_types_test.cc +++ b/src/reader/spirv/parser_impl_named_types_test.cc @@ -25,7 +25,6 @@ #include "src/reader/spirv/parser_impl.h" #include "src/reader/spirv/parser_impl_test_helper.h" #include "src/reader/spirv/spirv_tools_helpers_test.h" -#include "src/type_manager.h" namespace tint { namespace reader { diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 8773fd0665..0b8fb24777 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -70,7 +70,6 @@ #include "src/ast/variable_decl_statement.h" #include "src/ast/workgroup_decoration.h" #include "src/reader/wgsl/lexer.h" -#include "src/type_manager.h" namespace tint { namespace reader { diff --git a/src/reader/wgsl/parser_impl_function_type_decl_test.cc b/src/reader/wgsl/parser_impl_function_type_decl_test.cc index 9fb2711f5b..58bf1e42b6 100644 --- a/src/reader/wgsl/parser_impl_function_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_function_type_decl_test.cc @@ -20,7 +20,6 @@ #include "src/ast/type/void_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" -#include "src/type_manager.h" namespace tint { namespace reader { diff --git a/src/reader/wgsl/parser_impl_param_list_test.cc b/src/reader/wgsl/parser_impl_param_list_test.cc index a969b90eac..b1b2bf58b2 100644 --- a/src/reader/wgsl/parser_impl_param_list_test.cc +++ b/src/reader/wgsl/parser_impl_param_list_test.cc @@ -21,7 +21,6 @@ #include "src/ast/variable.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" -#include "src/type_manager.h" namespace tint { namespace reader { diff --git a/src/reader/wgsl/parser_impl_primary_expression_test.cc b/src/reader/wgsl/parser_impl_primary_expression_test.cc index 4d1cc5e7d1..1a60ddc045 100644 --- a/src/reader/wgsl/parser_impl_primary_expression_test.cc +++ b/src/reader/wgsl/parser_impl_primary_expression_test.cc @@ -25,7 +25,6 @@ #include "src/ast/unary_op_expression.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" -#include "src/type_manager.h" namespace tint { namespace reader { 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 767273b665..49a2437619 100644 --- a/src/reader/wgsl/parser_impl_struct_body_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_body_decl_test.cc @@ -16,7 +16,6 @@ #include "src/ast/type/i32_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" -#include "src/type_manager.h" namespace tint { namespace reader { diff --git a/src/reader/wgsl/parser_impl_struct_member_test.cc b/src/reader/wgsl/parser_impl_struct_member_test.cc index 867f53cbf2..b46b456649 100644 --- a/src/reader/wgsl/parser_impl_struct_member_test.cc +++ b/src/reader/wgsl/parser_impl_struct_member_test.cc @@ -17,7 +17,6 @@ #include "src/ast/type/i32_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" -#include "src/type_manager.h" namespace tint { namespace reader { diff --git a/src/reader/wgsl/parser_impl_test_helper.h b/src/reader/wgsl/parser_impl_test_helper.h index 6a6f1f5c65..db44780eaa 100644 --- a/src/reader/wgsl/parser_impl_test_helper.h +++ b/src/reader/wgsl/parser_impl_test_helper.h @@ -46,7 +46,7 @@ class ParserImplTest : public testing::Test { } /// @returns the type manager - TypeManager* tm() { return &(ctx_.type_mgr()); } + ast::TypeManager* tm() { return &(ctx_.type_mgr()); } private: std::vector> files_; @@ -72,7 +72,7 @@ class ParserImplTestWithParam : public testing::TestWithParam { } /// @returns the type manager - TypeManager* tm() { return &(ctx_.type_mgr()); } + ast::TypeManager* tm() { return &(ctx_.type_mgr()); } private: std::vector> files_; diff --git a/src/reader/wgsl/parser_impl_type_alias_test.cc b/src/reader/wgsl/parser_impl_type_alias_test.cc index 02360d6d70..000c115ae6 100644 --- a/src/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/reader/wgsl/parser_impl_type_alias_test.cc @@ -19,7 +19,6 @@ #include "src/ast/type/struct_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" -#include "src/type_manager.h" namespace tint { namespace reader { diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index ffec52dbbb..32895dca0e 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -28,7 +28,6 @@ #include "src/ast/type/vector_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" -#include "src/type_manager.h" namespace tint { namespace reader { diff --git a/src/transform/bound_array_accessors_transform.cc b/src/transform/bound_array_accessors_transform.cc index 4aebfebb32..f305c5e648 100644 --- a/src/transform/bound_array_accessors_transform.cc +++ b/src/transform/bound_array_accessors_transform.cc @@ -41,7 +41,6 @@ #include "src/ast/unary_op_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" -#include "src/type_manager.h" namespace tint { namespace transform { diff --git a/src/validator/validator_test_helper.cc b/src/validator/validator_test_helper.cc index d35efd2e4f..9f2ae159f7 100644 --- a/src/validator/validator_test_helper.cc +++ b/src/validator/validator_test_helper.cc @@ -16,8 +16,6 @@ #include -#include "src/type_manager.h" - namespace tint { ValidatorTestHelper::ValidatorTestHelper() {