writer/spirv: Inherit TestHelperBase from ast::Builder

Exposes all the AST builder helpers to the spirv writer tests

Change-Id: Ie6709cc9f941a52899285ad476e8b4fc7ee9e4d6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32983
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-17 16:12:08 +00:00 committed by Commit Bot service account
parent 2d86bf4c32
commit 655638c4a8
1 changed files with 11 additions and 14 deletions

View File

@ -19,6 +19,7 @@
#include <utility> #include <utility>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/builder.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/context.h" #include "src/context.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
@ -30,28 +31,24 @@ namespace spirv {
/// Helper class for testing /// Helper class for testing
template <typename BASE> template <typename BASE>
class TestHelperBase : public BASE { class TestHelperBase : public ast::BuilderWithContext, public BASE {
public: public:
TestHelperBase() : td(&ctx, &mod), b(&ctx, &mod) {} TestHelperBase() : td(ctx, &mod), b(ctx, &mod) {}
~TestHelperBase() = default; ~TestHelperBase() = default;
/// Creates a new `ast::Node` owned by the Context. When the Context is
/// destructed, the `ast::Node` will also be destructed.
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
T* create(ARGS&&... args) {
return ctx.create<T>(std::forward<ARGS>(args)...);
}
/// The context
Context ctx;
/// The module /// The module
ast::Module mod; ast::Module mod;
/// The type determiner /// The type determiner
TypeDeterminer td; TypeDeterminer td;
/// The generator /// The generator
Builder b; spirv::Builder b;
protected:
/// Called whenever a new variable is built with `Var()`.
/// @param var the variable that was built
void OnVariableBuilt(ast::Variable* var) override {
td.RegisterVariableForTesting(var);
}
}; };
using TestHelper = TestHelperBase<testing::Test>; using TestHelper = TestHelperBase<testing::Test>;