[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>
diff --git a/src/ast/module.h b/src/ast/module.h
index c094c7c..8ecedf3 100644
--- a/src/ast/module.h
+++ b/src/ast/module.h
@@ -71,11 +71,12 @@
     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 f534c0a..f20f4b0 100644
--- a/src/ast/module_test.cc
+++ b/src/ast/module_test.cc
@@ -117,7 +117,7 @@
 }
 
 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 618148e..7991540 100644
--- a/src/clone_context.cc
+++ b/src/clone_context.cc
@@ -37,7 +37,7 @@
     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 14758e4..c7c8bb5 100644
--- a/src/program_builder.h
+++ b/src/program_builder.h
@@ -917,7 +917,7 @@
     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 @@
     auto* func =
         create<ast::Function>(Symbols().Register(name), params, type,
                               create<ast::BlockStatement>(body), decorations);
-    AST().Functions().Add(func);
+    AST().AddFunction(func);
     return func;
   }
 
diff --git a/src/program_test.cc b/src/program_test.cc
index 2d5047a..6058d02 100644
--- a/src/program_test.cc
+++ b/src/program_test.cc
@@ -111,7 +111,7 @@
 }
 
 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 b68b9c9..535c502 100644
--- a/src/reader/spirv/function.cc
+++ b/src/reader/spirv/function.cc
@@ -888,7 +888,7 @@
 
   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)));
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc
index 5680c89..415688e 100644
--- a/src/reader/wgsl/parser_impl.cc
+++ b/src/reader/wgsl/parser_impl.cc
@@ -375,7 +375,7 @@
   if (func.errored)
     errored = true;
   if (func.matched) {
-    builder_.AST().Functions().Add(func.value);
+    builder_.AST().AddFunction(func.value);
     return true;
   }