ast: Move Module function methods to FunctionList

Module will be split into Module (immutable) and ModuleBuilder (mutable).
By moving these methods to the FunctionList, we can deduplicate a bunch of common logic.

Bug: tint:390
Change-Id: I3fd85200aae4e8dc3d5afce8c9aaa6512809a3a0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38363
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2021-01-21 18:45:50 +00:00
committed by Commit Bot service account
parent 281b602f59
commit 6761160dc1
38 changed files with 354 additions and 305 deletions

View File

@@ -859,7 +859,7 @@ bool FunctionEmitter::Emit() {
auto& statements = statements_stack_[0].GetStatements();
auto* body = create<ast::BlockStatement>(Source{}, statements);
ast_module_.AddFunction(
ast_module_.Functions().Add(
create<ast::Function>(decl.source, ast_module_.RegisterSymbol(decl.name),
std::move(decl.params), decl.return_type, body,
std::move(decl.decorations)));

View File

@@ -378,7 +378,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (func.errored)
errored = true;
if (func.matched) {
module_.AddFunction(func.value);
module_.Functions().Add(func.value);
return true;
}

View File

@@ -135,8 +135,8 @@ TEST_F(ParserImplTest, GlobalDecl_Function) {
ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_module();
ASSERT_EQ(m.functions().size(), 1u);
EXPECT_EQ(m.SymbolToName(m.functions()[0]->symbol()), "main");
ASSERT_EQ(m.Functions().size(), 1u);
EXPECT_EQ(m.SymbolToName(m.Functions()[0]->symbol()), "main");
}
TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) {
@@ -145,8 +145,8 @@ TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) {
ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_module();
ASSERT_EQ(m.functions().size(), 1u);
EXPECT_EQ(m.SymbolToName(m.functions()[0]->symbol()), "main");
ASSERT_EQ(m.Functions().size(), 1u);
EXPECT_EQ(m.SymbolToName(m.Functions()[0]->symbol()), "main");
}
TEST_F(ParserImplTest, GlobalDecl_Function_Invalid) {

View File

@@ -15,8 +15,8 @@
#include "src/reader/wgsl/parser_impl.h"
#include "gtest/gtest.h"
#include "src/type/i32_type.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
#include "src/type/i32_type.h"
namespace tint {
namespace reader {
@@ -40,7 +40,7 @@ fn main() -> void {
ASSERT_TRUE(p->Parse()) << p->error();
auto& m = p->get_module();
ASSERT_EQ(1u, m.functions().size());
ASSERT_EQ(1u, m.Functions().size());
ASSERT_EQ(1u, m.global_variables().size());
}

View File

@@ -42,7 +42,7 @@ fn main() -> void {
ASSERT_TRUE(p.Parse()) << p.error();
auto m = p.module();
ASSERT_EQ(1u, m.functions().size());
ASSERT_EQ(1u, m.Functions().size());
ASSERT_EQ(1u, m.global_variables().size());
}