From 3eaa4509849edebeab759a9bc38feea3d1d7dd07 Mon Sep 17 00:00:00 2001 From: James Price Date: Tue, 9 Feb 2021 21:26:21 +0000 Subject: [PATCH] [ast] Add ast::Module::AddFunction() Remove the non-const ast::Module::Functions() getter. Change-Id: I365eece04837ee6bd51147d226c73e04ce5d9bd4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41300 Reviewed-by: Ben Clayton Reviewed-by: dan sinclair Commit-Queue: James Price --- src/ast/module.h | 7 ++++--- src/ast/module_test.cc | 2 +- src/clone_context.cc | 2 +- src/program_builder.h | 4 ++-- src/program_test.cc | 2 +- src/reader/spirv/function.cc | 2 +- src/reader/wgsl/parser_impl.cc | 2 +- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ast/module.h b/src/ast/module.h index c094c7cfb2..8ecedf3ede 100644 --- a/src/ast/module.h +++ b/src/ast/module.h @@ -71,11 +71,12 @@ class Module : public Castable { return constructed_types_; } - /// @returns the functions declared in the translation unit - const FunctionList& Functions() const { return functions_; } + /// Add a function to the Builder + /// @param func the function to add + void AddFunction(ast::Function* func) { functions_.push_back(func); } /// @returns the functions declared in the translation unit - FunctionList& Functions() { return functions_; } + const FunctionList& Functions() const { return functions_; } /// @returns true if all required fields in the AST are present. bool IsValid() const override; diff --git a/src/ast/module_test.cc b/src/ast/module_test.cc index f534c0a3d1..f20f4b084f 100644 --- a/src/ast/module_test.cc +++ b/src/ast/module_test.cc @@ -117,7 +117,7 @@ TEST_F(ModuleTest, IsValid_Function) { } TEST_F(ModuleTest, IsValid_Null_Function) { - AST().Functions().Add(nullptr); + AST().AddFunction(nullptr); Program program(std::move(*this)); EXPECT_FALSE(program.AST().IsValid()); } diff --git a/src/clone_context.cc b/src/clone_context.cc index 618148e350..7991540da0 100644 --- a/src/clone_context.cc +++ b/src/clone_context.cc @@ -37,7 +37,7 @@ void CloneContext::Clone() { dst->AST().AddGlobalVariable(Clone(var)); } for (auto* func : src->AST().Functions()) { - dst->AST().Functions().Add(Clone(func)); + dst->AST().AddFunction(Clone(func)); } } diff --git a/src/program_builder.h b/src/program_builder.h index 14758e48b8..c7c8bb5df0 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -917,7 +917,7 @@ class ProgramBuilder { auto* func = create(source, Symbols().Register(name), params, type, create(body), decorations); - AST().Functions().Add(func); + AST().AddFunction(func); return func; } @@ -936,7 +936,7 @@ class ProgramBuilder { auto* func = create(Symbols().Register(name), params, type, create(body), decorations); - AST().Functions().Add(func); + AST().AddFunction(func); return func; } diff --git a/src/program_test.cc b/src/program_test.cc index 2d5047ab04..6058d02c26 100644 --- a/src/program_test.cc +++ b/src/program_test.cc @@ -111,7 +111,7 @@ TEST_F(ProgramTest, IsValid_Function) { } TEST_F(ProgramTest, IsValid_Null_Function) { - AST().Functions().Add(nullptr); + AST().AddFunction(nullptr); Program program(std::move(*this)); EXPECT_FALSE(program.IsValid()); diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index b68b9c9c84..535c50299b 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -888,7 +888,7 @@ bool FunctionEmitter::Emit() { auto& statements = statements_stack_[0].GetStatements(); auto* body = create(Source{}, statements); - builder_.AST().Functions().Add( + builder_.AST().AddFunction( create(decl.source, builder_.Symbols().Register(decl.name), std::move(decl.params), decl.return_type, body, std::move(decl.decorations))); diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 5680c8960f..415688e535 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -375,7 +375,7 @@ Expect ParserImpl::expect_global_decl() { if (func.errored) errored = true; if (func.matched) { - builder_.AST().Functions().Add(func.value); + builder_.AST().AddFunction(func.value); return true; }