[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 <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
James Price 2021-02-09 21:26:21 +00:00 committed by Commit Bot service account
parent cd17ea88e3
commit 3eaa450984
7 changed files with 11 additions and 10 deletions

View File

@ -71,11 +71,12 @@ class Module : public Castable<Module, Node> {
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;

View File

@ -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());
}

View File

@ -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));
}
}

View File

@ -917,7 +917,7 @@ class ProgramBuilder {
auto* func =
create<ast::Function>(source, Symbols().Register(name), params, type,
create<ast::BlockStatement>(body), decorations);
AST().Functions().Add(func);
AST().AddFunction(func);
return func;
}
@ -936,7 +936,7 @@ class ProgramBuilder {
auto* func =
create<ast::Function>(Symbols().Register(name), params, type,
create<ast::BlockStatement>(body), decorations);
AST().Functions().Add(func);
AST().AddFunction(func);
return func;
}

View File

@ -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());

View File

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

View File

@ -375,7 +375,7 @@ Expect<bool> 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;
}