[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:
parent
cd17ea88e3
commit
3eaa450984
|
@ -71,11 +71,12 @@ class Module : public Castable<Module, Node> {
|
||||||
return constructed_types_;
|
return constructed_types_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @returns the functions declared in the translation unit
|
/// Add a function to the Builder
|
||||||
const FunctionList& Functions() const { return functions_; }
|
/// @param func the function to add
|
||||||
|
void AddFunction(ast::Function* func) { functions_.push_back(func); }
|
||||||
|
|
||||||
/// @returns the functions declared in the translation unit
|
/// @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.
|
/// @returns true if all required fields in the AST are present.
|
||||||
bool IsValid() const override;
|
bool IsValid() const override;
|
||||||
|
|
|
@ -117,7 +117,7 @@ TEST_F(ModuleTest, IsValid_Function) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ModuleTest, IsValid_Null_Function) {
|
TEST_F(ModuleTest, IsValid_Null_Function) {
|
||||||
AST().Functions().Add(nullptr);
|
AST().AddFunction(nullptr);
|
||||||
Program program(std::move(*this));
|
Program program(std::move(*this));
|
||||||
EXPECT_FALSE(program.AST().IsValid());
|
EXPECT_FALSE(program.AST().IsValid());
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ void CloneContext::Clone() {
|
||||||
dst->AST().AddGlobalVariable(Clone(var));
|
dst->AST().AddGlobalVariable(Clone(var));
|
||||||
}
|
}
|
||||||
for (auto* func : src->AST().Functions()) {
|
for (auto* func : src->AST().Functions()) {
|
||||||
dst->AST().Functions().Add(Clone(func));
|
dst->AST().AddFunction(Clone(func));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -917,7 +917,7 @@ class ProgramBuilder {
|
||||||
auto* func =
|
auto* func =
|
||||||
create<ast::Function>(source, Symbols().Register(name), params, type,
|
create<ast::Function>(source, Symbols().Register(name), params, type,
|
||||||
create<ast::BlockStatement>(body), decorations);
|
create<ast::BlockStatement>(body), decorations);
|
||||||
AST().Functions().Add(func);
|
AST().AddFunction(func);
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,7 +936,7 @@ class ProgramBuilder {
|
||||||
auto* func =
|
auto* func =
|
||||||
create<ast::Function>(Symbols().Register(name), params, type,
|
create<ast::Function>(Symbols().Register(name), params, type,
|
||||||
create<ast::BlockStatement>(body), decorations);
|
create<ast::BlockStatement>(body), decorations);
|
||||||
AST().Functions().Add(func);
|
AST().AddFunction(func);
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ TEST_F(ProgramTest, IsValid_Function) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ProgramTest, IsValid_Null_Function) {
|
TEST_F(ProgramTest, IsValid_Null_Function) {
|
||||||
AST().Functions().Add(nullptr);
|
AST().AddFunction(nullptr);
|
||||||
|
|
||||||
Program program(std::move(*this));
|
Program program(std::move(*this));
|
||||||
EXPECT_FALSE(program.IsValid());
|
EXPECT_FALSE(program.IsValid());
|
||||||
|
|
|
@ -888,7 +888,7 @@ bool FunctionEmitter::Emit() {
|
||||||
|
|
||||||
auto& statements = statements_stack_[0].GetStatements();
|
auto& statements = statements_stack_[0].GetStatements();
|
||||||
auto* body = create<ast::BlockStatement>(Source{}, statements);
|
auto* body = create<ast::BlockStatement>(Source{}, statements);
|
||||||
builder_.AST().Functions().Add(
|
builder_.AST().AddFunction(
|
||||||
create<ast::Function>(decl.source, builder_.Symbols().Register(decl.name),
|
create<ast::Function>(decl.source, builder_.Symbols().Register(decl.name),
|
||||||
std::move(decl.params), decl.return_type, body,
|
std::move(decl.params), decl.return_type, body,
|
||||||
std::move(decl.decorations)));
|
std::move(decl.decorations)));
|
||||||
|
|
|
@ -375,7 +375,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
|
||||||
if (func.errored)
|
if (func.errored)
|
||||||
errored = true;
|
errored = true;
|
||||||
if (func.matched) {
|
if (func.matched) {
|
||||||
builder_.AST().Functions().Add(func.value);
|
builder_.AST().AddFunction(func.value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue