Context object owns a TypeManager
Add a Context::Reset method to clear state. Hide the member behind an accessor. Change-Id: Iafb7c39249f66f70c5a99a8ed1c69f2c0238834f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17742 Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
parent
20145170fc
commit
a8cd18e9e7
|
@ -252,10 +252,7 @@ int main(int argc, const char** argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tint::TypeManager type_manager;
|
|
||||||
|
|
||||||
tint::Context ctx;
|
tint::Context ctx;
|
||||||
ctx.type_mgr = &type_manager;
|
|
||||||
|
|
||||||
std::unique_ptr<tint::reader::Reader> reader;
|
std::unique_ptr<tint::reader::Reader> reader;
|
||||||
#if TINT_BUILD_WGSL_READER
|
#if TINT_BUILD_WGSL_READER
|
||||||
|
@ -267,7 +264,7 @@ int main(int argc, const char** argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
reader = std::make_unique<tint::reader::wgsl::Parser>(
|
reader = std::make_unique<tint::reader::wgsl::Parser>(
|
||||||
ctx, std::string(data.begin(), data.end()));
|
&ctx, std::string(data.begin(), data.end()));
|
||||||
}
|
}
|
||||||
#endif // TINT_BUILD_WGSL_READER
|
#endif // TINT_BUILD_WGSL_READER
|
||||||
|
|
||||||
|
@ -279,7 +276,7 @@ int main(int argc, const char** argv) {
|
||||||
if (!ReadFile<uint32_t>(options.input_filename, &data)) {
|
if (!ReadFile<uint32_t>(options.input_filename, &data)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
reader = std::make_unique<tint::reader::spirv::Parser>(ctx, data);
|
reader = std::make_unique<tint::reader::spirv::Parser>(&ctx, data);
|
||||||
}
|
}
|
||||||
#endif // TINT_BUILD_SPV_READER
|
#endif // TINT_BUILD_SPV_READER
|
||||||
|
|
||||||
|
|
|
@ -181,6 +181,8 @@ set(TINT_LIB_SRCS
|
||||||
ast/variable_decoration.h
|
ast/variable_decoration.h
|
||||||
ast/variable_statement.cc
|
ast/variable_statement.cc
|
||||||
ast/variable_statement.h
|
ast/variable_statement.h
|
||||||
|
context.h
|
||||||
|
context.cc
|
||||||
reader/reader.cc
|
reader/reader.cc
|
||||||
reader/reader.h
|
reader/reader.h
|
||||||
source.h
|
source.h
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright 2020 The Tint Authors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "src/context.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "src/type_manager.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
|
||||||
|
Context::Context() = default;
|
||||||
|
|
||||||
|
Context::~Context() = default;
|
||||||
|
|
||||||
|
void Context::Reset() {
|
||||||
|
type_mgr_.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace tint
|
|
@ -21,9 +21,19 @@ namespace tint {
|
||||||
|
|
||||||
/// Context object for Tint. Holds various global resources used through
|
/// Context object for Tint. Holds various global resources used through
|
||||||
/// the system.
|
/// the system.
|
||||||
struct Context {
|
class Context {
|
||||||
/// Manager to hold all of the various type objects
|
public:
|
||||||
TypeManager* type_mgr = nullptr;
|
/// Constructs a context with an empty type manager.
|
||||||
|
Context();
|
||||||
|
/// Destructor
|
||||||
|
~Context();
|
||||||
|
/// Resets the state of this context.
|
||||||
|
void Reset();
|
||||||
|
|
||||||
|
TypeManager& type_mgr() { return type_mgr_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
TypeManager type_mgr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace reader {
|
namespace reader {
|
||||||
|
|
||||||
Reader::Reader(const Context& ctx) : ctx_(ctx) {}
|
Reader::Reader(Context* ctx) : ctx_(*ctx) {}
|
||||||
|
|
||||||
Reader::~Reader() = default;
|
Reader::~Reader() = default;
|
||||||
|
|
||||||
|
|
|
@ -42,15 +42,15 @@ class Reader {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param ctx the context object
|
/// @param ctx the context object, must be non-null
|
||||||
explicit Reader(const Context& ctx);
|
explicit Reader(Context* ctx);
|
||||||
|
|
||||||
/// Sets the error string
|
/// Sets the error string
|
||||||
/// @param msg the error message
|
/// @param msg the error message
|
||||||
void set_error(const std::string& msg) { error_ = msg; }
|
void set_error(const std::string& msg) { error_ = msg; }
|
||||||
|
|
||||||
/// The Tint context object
|
/// The Tint context object
|
||||||
const Context& ctx_;
|
Context& ctx_;
|
||||||
|
|
||||||
/// An error message, if an error was encountered
|
/// An error message, if an error was encountered
|
||||||
std::string error_;
|
std::string error_;
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace tint {
|
||||||
namespace reader {
|
namespace reader {
|
||||||
namespace spirv {
|
namespace spirv {
|
||||||
|
|
||||||
Parser::Parser(const Context& ctx, const std::vector<uint32_t>& spv_binary)
|
Parser::Parser(Context* ctx, const std::vector<uint32_t>& spv_binary)
|
||||||
: Reader(ctx), impl_(std::make_unique<ParserImpl>(ctx, spv_binary)) {}
|
: Reader(ctx), impl_(std::make_unique<ParserImpl>(ctx, spv_binary)) {}
|
||||||
|
|
||||||
Parser::~Parser() = default;
|
Parser::~Parser() = default;
|
||||||
|
|
|
@ -31,9 +31,9 @@ class ParserImpl;
|
||||||
class Parser : public Reader {
|
class Parser : public Reader {
|
||||||
public:
|
public:
|
||||||
/// Creates a new parser
|
/// Creates a new parser
|
||||||
/// @param ctx the context object
|
/// @param ctx the non-null context object
|
||||||
/// @param input the input data to parse
|
/// @param input the input data to parse
|
||||||
Parser(const Context& ctx, const std::vector<uint32_t>& input);
|
Parser(Context* ctx, const std::vector<uint32_t>& input);
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Parser() override;
|
~Parser() override;
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,7 @@ const spv_target_env kTargetEnv = SPV_ENV_WEBGPU_0;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ParserImpl::ParserImpl(const Context& ctx,
|
ParserImpl::ParserImpl(Context* ctx, const std::vector<uint32_t>& spv_binary)
|
||||||
const std::vector<uint32_t>& spv_binary)
|
|
||||||
: Reader(ctx),
|
: Reader(ctx),
|
||||||
spv_binary_(spv_binary),
|
spv_binary_(spv_binary),
|
||||||
fail_stream_(&success_, &errors_),
|
fail_stream_(&success_, &errors_),
|
||||||
|
@ -76,11 +75,6 @@ ParserImpl::ParserImpl(const Context& ctx,
|
||||||
ParserImpl::~ParserImpl() = default;
|
ParserImpl::~ParserImpl() = default;
|
||||||
|
|
||||||
bool ParserImpl::Parse() {
|
bool ParserImpl::Parse() {
|
||||||
if (ctx_.type_mgr == nullptr) {
|
|
||||||
Fail() << "Missing type manager";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!success_) {
|
if (!success_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -134,18 +128,18 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) {
|
||||||
|
|
||||||
switch (spirv_type->kind()) {
|
switch (spirv_type->kind()) {
|
||||||
case spvtools::opt::analysis::Type::kVoid:
|
case spvtools::opt::analysis::Type::kVoid:
|
||||||
result = ctx_.type_mgr->Get(std::make_unique<ast::type::VoidType>());
|
result = ctx_.type_mgr().Get(std::make_unique<ast::type::VoidType>());
|
||||||
break;
|
break;
|
||||||
case spvtools::opt::analysis::Type::kBool:
|
case spvtools::opt::analysis::Type::kBool:
|
||||||
result = ctx_.type_mgr->Get(std::make_unique<ast::type::BoolType>());
|
result = ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
|
||||||
break;
|
break;
|
||||||
case spvtools::opt::analysis::Type::kInteger: {
|
case spvtools::opt::analysis::Type::kInteger: {
|
||||||
const auto* int_ty = spirv_type->AsInteger();
|
const auto* int_ty = spirv_type->AsInteger();
|
||||||
if (int_ty->width() == 32) {
|
if (int_ty->width() == 32) {
|
||||||
if (int_ty->IsSigned()) {
|
if (int_ty->IsSigned()) {
|
||||||
result = ctx_.type_mgr->Get(std::make_unique<ast::type::I32Type>());
|
result = ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
|
||||||
} else {
|
} else {
|
||||||
result = ctx_.type_mgr->Get(std::make_unique<ast::type::U32Type>());
|
result = ctx_.type_mgr().Get(std::make_unique<ast::type::U32Type>());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Fail() << "unhandled integer width: " << int_ty->width();
|
Fail() << "unhandled integer width: " << int_ty->width();
|
||||||
|
@ -155,7 +149,7 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) {
|
||||||
case spvtools::opt::analysis::Type::kFloat: {
|
case spvtools::opt::analysis::Type::kFloat: {
|
||||||
const auto* float_ty = spirv_type->AsFloat();
|
const auto* float_ty = spirv_type->AsFloat();
|
||||||
if (float_ty->width() == 32) {
|
if (float_ty->width() == 32) {
|
||||||
result = ctx_.type_mgr->Get(std::make_unique<ast::type::F32Type>());
|
result = ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>());
|
||||||
} else {
|
} else {
|
||||||
Fail() << "unhandled float width: " << float_ty->width();
|
Fail() << "unhandled float width: " << float_ty->width();
|
||||||
}
|
}
|
||||||
|
@ -166,7 +160,7 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) {
|
||||||
const auto num_elem = vec_ty->element_count();
|
const auto num_elem = vec_ty->element_count();
|
||||||
auto* ast_elem_ty = ConvertType(type_mgr_->GetId(vec_ty->element_type()));
|
auto* ast_elem_ty = ConvertType(type_mgr_->GetId(vec_ty->element_type()));
|
||||||
if (ast_elem_ty != nullptr) {
|
if (ast_elem_ty != nullptr) {
|
||||||
result = ctx_.type_mgr->Get(
|
result = ctx_.type_mgr().Get(
|
||||||
std::make_unique<ast::type::VectorType>(ast_elem_ty, num_elem));
|
std::make_unique<ast::type::VectorType>(ast_elem_ty, num_elem));
|
||||||
}
|
}
|
||||||
// In the error case, we'll already have emitted a diagnostic.
|
// In the error case, we'll already have emitted a diagnostic.
|
||||||
|
@ -180,7 +174,7 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) {
|
||||||
const auto num_columns = mat_ty->element_count();
|
const auto num_columns = mat_ty->element_count();
|
||||||
auto* ast_scalar_ty = ConvertType(type_mgr_->GetId(scalar_ty));
|
auto* ast_scalar_ty = ConvertType(type_mgr_->GetId(scalar_ty));
|
||||||
if (ast_scalar_ty != nullptr) {
|
if (ast_scalar_ty != nullptr) {
|
||||||
result = ctx_.type_mgr->Get(std::make_unique<ast::type::MatrixType>(
|
result = ctx_.type_mgr().Get(std::make_unique<ast::type::MatrixType>(
|
||||||
ast_scalar_ty, num_rows, num_columns));
|
ast_scalar_ty, num_rows, num_columns));
|
||||||
}
|
}
|
||||||
// In the error case, we'll already have emitted a diagnostic.
|
// In the error case, we'll already have emitted a diagnostic.
|
||||||
|
|
|
@ -45,9 +45,9 @@ namespace spirv {
|
||||||
class ParserImpl : Reader {
|
class ParserImpl : Reader {
|
||||||
public:
|
public:
|
||||||
/// Creates a new parser
|
/// Creates a new parser
|
||||||
/// @param ctx the context object
|
/// @param ctx the non-null context object
|
||||||
/// @param input the input data to parse
|
/// @param input the input data to parse
|
||||||
ParserImpl(const Context& ctx, const std::vector<uint32_t>& input);
|
ParserImpl(Context* ctx, const std::vector<uint32_t>& input);
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~ParserImpl() override;
|
~ParserImpl() override;
|
||||||
|
|
||||||
|
|
|
@ -34,26 +34,24 @@ class SpvParserTest : public testing::Test {
|
||||||
~SpvParserTest() = default;
|
~SpvParserTest() = default;
|
||||||
|
|
||||||
/// Sets up the test helper
|
/// Sets up the test helper
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
/// Tears down the test helper
|
/// Tears down the test helper
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the parser from the helper
|
/// Retrieves the parser from the helper
|
||||||
/// @param input the string to parse
|
/// @param input the string to parse
|
||||||
/// @returns the parser implementation
|
/// @returns the parser implementation
|
||||||
ParserImpl* parser(const std::vector<uint32_t>& input) {
|
ParserImpl* parser(const std::vector<uint32_t>& input) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, input);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, input);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace spirv
|
} // namespace spirv
|
||||||
|
|
|
@ -30,7 +30,7 @@ using ParserTest = testing::Test;
|
||||||
TEST_F(ParserTest, Uint32VecEmpty) {
|
TEST_F(ParserTest, Uint32VecEmpty) {
|
||||||
std::vector<uint32_t> data;
|
std::vector<uint32_t> data;
|
||||||
Context ctx;
|
Context ctx;
|
||||||
Parser p(ctx, data);
|
Parser p(&ctx, data);
|
||||||
EXPECT_FALSE(p.Parse());
|
EXPECT_FALSE(p.Parse());
|
||||||
// TODO(dneto): What message?
|
// TODO(dneto): What message?
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace tint {
|
||||||
namespace reader {
|
namespace reader {
|
||||||
namespace wgsl {
|
namespace wgsl {
|
||||||
|
|
||||||
Parser::Parser(const Context& ctx, const std::string& input)
|
Parser::Parser(Context* ctx, const std::string& input)
|
||||||
: Reader(ctx), impl_(std::make_unique<ParserImpl>(ctx, input)) {}
|
: Reader(ctx), impl_(std::make_unique<ParserImpl>(ctx, input)) {}
|
||||||
|
|
||||||
Parser::~Parser() = default;
|
Parser::~Parser() = default;
|
||||||
|
|
|
@ -30,9 +30,9 @@ class ParserImpl;
|
||||||
class Parser : public Reader {
|
class Parser : public Reader {
|
||||||
public:
|
public:
|
||||||
/// Creates a new parser
|
/// Creates a new parser
|
||||||
/// @param ctx the context object
|
/// @param ctx the non-null context object
|
||||||
/// @param input the input string to parse
|
/// @param input the input string to parse
|
||||||
Parser(const Context& ctx, const std::string& input);
|
Parser(Context* ctx, const std::string& input);
|
||||||
~Parser() override;
|
~Parser() override;
|
||||||
|
|
||||||
/// Run the parser
|
/// Run the parser
|
||||||
|
|
|
@ -71,8 +71,8 @@ namespace tint {
|
||||||
namespace reader {
|
namespace reader {
|
||||||
namespace wgsl {
|
namespace wgsl {
|
||||||
|
|
||||||
ParserImpl::ParserImpl(const Context& ctx, const std::string& input)
|
ParserImpl::ParserImpl(Context* ctx, const std::string& input)
|
||||||
: ctx_(ctx), lexer_(std::make_unique<Lexer>(input)) {}
|
: ctx_(*ctx), lexer_(std::make_unique<Lexer>(input)) {}
|
||||||
|
|
||||||
ParserImpl::~ParserImpl() = default;
|
ParserImpl::~ParserImpl() = default;
|
||||||
|
|
||||||
|
@ -134,11 +134,6 @@ ast::type::Type* ParserImpl::get_alias(const std::string& name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParserImpl::Parse() {
|
bool ParserImpl::Parse() {
|
||||||
if (ctx_.type_mgr == nullptr) {
|
|
||||||
set_error(peek(), "missing type manager");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
translation_unit();
|
translation_unit();
|
||||||
return !has_error();
|
return !has_error();
|
||||||
}
|
}
|
||||||
|
@ -690,7 +685,7 @@ ast::type::AliasType* ParserImpl::type_alias() {
|
||||||
}
|
}
|
||||||
|
|
||||||
str->set_name(name);
|
str->set_name(name);
|
||||||
type = ctx_.type_mgr->Get(std::move(str));
|
type = ctx_.type_mgr().Get(std::move(str));
|
||||||
}
|
}
|
||||||
if (type == nullptr) {
|
if (type == nullptr) {
|
||||||
set_error(peek(), "invalid type for alias");
|
set_error(peek(), "invalid type for alias");
|
||||||
|
@ -698,7 +693,7 @@ ast::type::AliasType* ParserImpl::type_alias() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto alias =
|
auto alias =
|
||||||
ctx_.type_mgr->Get(std::make_unique<ast::type::AliasType>(name, type));
|
ctx_.type_mgr().Get(std::make_unique<ast::type::AliasType>(name, type));
|
||||||
register_alias(name, alias);
|
register_alias(name, alias);
|
||||||
|
|
||||||
return alias->AsAlias();
|
return alias->AsAlias();
|
||||||
|
@ -738,19 +733,19 @@ ast::type::Type* ParserImpl::type_decl() {
|
||||||
}
|
}
|
||||||
if (t.IsBool()) {
|
if (t.IsBool()) {
|
||||||
next(); // Consume the peek
|
next(); // Consume the peek
|
||||||
return ctx_.type_mgr->Get(std::make_unique<ast::type::BoolType>());
|
return ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
|
||||||
}
|
}
|
||||||
if (t.IsF32()) {
|
if (t.IsF32()) {
|
||||||
next(); // Consume the peek
|
next(); // Consume the peek
|
||||||
return ctx_.type_mgr->Get(std::make_unique<ast::type::F32Type>());
|
return ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>());
|
||||||
}
|
}
|
||||||
if (t.IsI32()) {
|
if (t.IsI32()) {
|
||||||
next(); // Consume the peek
|
next(); // Consume the peek
|
||||||
return ctx_.type_mgr->Get(std::make_unique<ast::type::I32Type>());
|
return ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
|
||||||
}
|
}
|
||||||
if (t.IsU32()) {
|
if (t.IsU32()) {
|
||||||
next(); // Consume the peek
|
next(); // Consume the peek
|
||||||
return ctx_.type_mgr->Get(std::make_unique<ast::type::U32Type>());
|
return ctx_.type_mgr().Get(std::make_unique<ast::type::U32Type>());
|
||||||
}
|
}
|
||||||
if (t.IsVec2() || t.IsVec3() || t.IsVec4()) {
|
if (t.IsVec2() || t.IsVec3() || t.IsVec4()) {
|
||||||
return type_decl_vector(t);
|
return type_decl_vector(t);
|
||||||
|
@ -806,7 +801,7 @@ ast::type::Type* ParserImpl::type_decl_pointer(Token t) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx_.type_mgr->Get(
|
return ctx_.type_mgr().Get(
|
||||||
std::make_unique<ast::type::PointerType>(subtype, sc));
|
std::make_unique<ast::type::PointerType>(subtype, sc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -839,7 +834,7 @@ ast::type::Type* ParserImpl::type_decl_vector(Token t) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx_.type_mgr->Get(
|
return ctx_.type_mgr().Get(
|
||||||
std::make_unique<ast::type::VectorType>(subtype, count));
|
std::make_unique<ast::type::VectorType>(subtype, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -880,7 +875,7 @@ ast::type::Type* ParserImpl::type_decl_array(Token t) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx_.type_mgr->Get(
|
return ctx_.type_mgr().Get(
|
||||||
std::make_unique<ast::type::ArrayType>(subtype, size));
|
std::make_unique<ast::type::ArrayType>(subtype, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -920,7 +915,7 @@ ast::type::Type* ParserImpl::type_decl_matrix(Token t) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx_.type_mgr->Get(
|
return ctx_.type_mgr().Get(
|
||||||
std::make_unique<ast::type::MatrixType>(subtype, rows, columns));
|
std::make_unique<ast::type::MatrixType>(subtype, rows, columns));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1214,7 +1209,7 @@ ast::type::Type* ParserImpl::function_type_decl() {
|
||||||
auto t = peek();
|
auto t = peek();
|
||||||
if (t.IsVoid()) {
|
if (t.IsVoid()) {
|
||||||
next(); // Consume the peek
|
next(); // Consume the peek
|
||||||
return ctx_.type_mgr->Get(std::make_unique<ast::type::VoidType>());
|
return ctx_.type_mgr().Get(std::make_unique<ast::type::VoidType>());
|
||||||
}
|
}
|
||||||
return type_decl();
|
return type_decl();
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,9 +57,9 @@ class Lexer;
|
||||||
class ParserImpl {
|
class ParserImpl {
|
||||||
public:
|
public:
|
||||||
/// Creates a new parser
|
/// Creates a new parser
|
||||||
/// @param ctx the context object
|
/// @param ctx the non-null context object
|
||||||
/// @param input the input string to parse
|
/// @param input the input string to parse
|
||||||
ParserImpl(const Context& ctx, const std::string& input);
|
ParserImpl(Context* ctx, const std::string& input);
|
||||||
~ParserImpl();
|
~ParserImpl();
|
||||||
|
|
||||||
/// Run the parser
|
/// Run the parser
|
||||||
|
@ -351,7 +351,7 @@ class ParserImpl {
|
||||||
ast::type::Type* type_decl_array(Token t);
|
ast::type::Type* type_decl_array(Token t);
|
||||||
ast::type::Type* type_decl_matrix(Token t);
|
ast::type::Type* type_decl_matrix(Token t);
|
||||||
|
|
||||||
const Context& ctx_;
|
Context& ctx_;
|
||||||
std::string error_;
|
std::string error_;
|
||||||
std::unique_ptr<Lexer> lexer_;
|
std::unique_ptr<Lexer> lexer_;
|
||||||
std::deque<Token> token_queue_;
|
std::deque<Token> token_queue_;
|
||||||
|
|
|
@ -36,22 +36,20 @@ class BuiltinTest : public testing::TestWithParam<BuiltinData> {
|
||||||
BuiltinTest() = default;
|
BuiltinTest() = default;
|
||||||
~BuiltinTest() = default;
|
~BuiltinTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(BuiltinTest, Parses) {
|
TEST_P(BuiltinTest, Parses) {
|
||||||
|
|
|
@ -38,22 +38,20 @@ class DerivativeModifierTest
|
||||||
DerivativeModifierTest() = default;
|
DerivativeModifierTest() = default;
|
||||||
~DerivativeModifierTest() = default;
|
~DerivativeModifierTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(DerivativeModifierTest, Parses) {
|
TEST_P(DerivativeModifierTest, Parses) {
|
||||||
|
|
|
@ -36,22 +36,20 @@ class PipelineStageTest : public testing::TestWithParam<PipelineStageData> {
|
||||||
PipelineStageTest() = default;
|
PipelineStageTest() = default;
|
||||||
~PipelineStageTest() = default;
|
~PipelineStageTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(PipelineStageTest, Parses) {
|
TEST_P(PipelineStageTest, Parses) {
|
||||||
|
|
|
@ -36,22 +36,20 @@ class StorageClassTest : public testing::TestWithParam<StorageClassData> {
|
||||||
StorageClassTest() = default;
|
StorageClassTest() = default;
|
||||||
~StorageClassTest() = default;
|
~StorageClassTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(StorageClassTest, Parses) {
|
TEST_P(StorageClassTest, Parses) {
|
||||||
|
|
|
@ -37,22 +37,20 @@ class StructDecorationTest
|
||||||
StructDecorationTest() = default;
|
StructDecorationTest() = default;
|
||||||
~StructDecorationTest() = default;
|
~StructDecorationTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(StructDecorationTest, Parses) {
|
TEST_P(StructDecorationTest, Parses) {
|
||||||
|
|
|
@ -34,29 +34,27 @@ class ParserImplTest : public testing::Test {
|
||||||
~ParserImplTest() = default;
|
~ParserImplTest() = default;
|
||||||
|
|
||||||
/// Sets up the test helper
|
/// Sets up the test helper
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
/// Tears down the test helper
|
/// Tears down the test helper
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the parser from the helper
|
/// Retrieves the parser from the helper
|
||||||
/// @param str the string to parse
|
/// @param str the string to parse
|
||||||
/// @returns the parser implementation
|
/// @returns the parser implementation
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @returns the type manager
|
/// @returns the type manager
|
||||||
TypeManager* tm() { return &tm_; }
|
TypeManager* tm() { return &(ctx_.type_mgr()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace wgsl
|
} // namespace wgsl
|
||||||
|
|
|
@ -125,22 +125,20 @@ class VecTest : public testing::TestWithParam<VecData> {
|
||||||
VecTest() = default;
|
VecTest() = default;
|
||||||
~VecTest() = default;
|
~VecTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(VecTest, Parse) {
|
TEST_P(VecTest, Parse) {
|
||||||
|
@ -163,22 +161,20 @@ class VecMissingGreaterThanTest : public testing::TestWithParam<VecData> {
|
||||||
VecMissingGreaterThanTest() = default;
|
VecMissingGreaterThanTest() = default;
|
||||||
~VecMissingGreaterThanTest() = default;
|
~VecMissingGreaterThanTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(VecMissingGreaterThanTest, Handles_Missing_GreaterThan) {
|
TEST_P(VecMissingGreaterThanTest, Handles_Missing_GreaterThan) {
|
||||||
|
@ -200,22 +196,20 @@ class VecMissingLessThanTest : public testing::TestWithParam<VecData> {
|
||||||
VecMissingLessThanTest() = default;
|
VecMissingLessThanTest() = default;
|
||||||
~VecMissingLessThanTest() = default;
|
~VecMissingLessThanTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(VecMissingLessThanTest, Handles_Missing_GreaterThan) {
|
TEST_P(VecMissingLessThanTest, Handles_Missing_GreaterThan) {
|
||||||
|
@ -237,22 +231,20 @@ class VecBadType : public testing::TestWithParam<VecData> {
|
||||||
VecBadType() = default;
|
VecBadType() = default;
|
||||||
~VecBadType() = default;
|
~VecBadType() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(VecBadType, Handles_Unknown_Type) {
|
TEST_P(VecBadType, Handles_Unknown_Type) {
|
||||||
|
@ -274,22 +266,20 @@ class VecMissingType : public testing::TestWithParam<VecData> {
|
||||||
VecMissingType() = default;
|
VecMissingType() = default;
|
||||||
~VecMissingType() = default;
|
~VecMissingType() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(VecMissingType, Handles_Missing_Type) {
|
TEST_P(VecMissingType, Handles_Missing_Type) {
|
||||||
|
@ -493,22 +483,20 @@ class MatrixTest : public testing::TestWithParam<MatrixData> {
|
||||||
MatrixTest() = default;
|
MatrixTest() = default;
|
||||||
~MatrixTest() = default;
|
~MatrixTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(MatrixTest, Parse) {
|
TEST_P(MatrixTest, Parse) {
|
||||||
|
@ -539,22 +527,20 @@ class MatrixMissingGreaterThanTest : public testing::TestWithParam<MatrixData> {
|
||||||
MatrixMissingGreaterThanTest() = default;
|
MatrixMissingGreaterThanTest() = default;
|
||||||
~MatrixMissingGreaterThanTest() = default;
|
~MatrixMissingGreaterThanTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
TEST_P(MatrixMissingGreaterThanTest, Handles_Missing_GreaterThan) {
|
TEST_P(MatrixMissingGreaterThanTest, Handles_Missing_GreaterThan) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
@ -581,22 +567,20 @@ class MatrixMissingLessThanTest : public testing::TestWithParam<MatrixData> {
|
||||||
MatrixMissingLessThanTest() = default;
|
MatrixMissingLessThanTest() = default;
|
||||||
~MatrixMissingLessThanTest() = default;
|
~MatrixMissingLessThanTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
TEST_P(MatrixMissingLessThanTest, Handles_Missing_GreaterThan) {
|
TEST_P(MatrixMissingLessThanTest, Handles_Missing_GreaterThan) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
@ -623,22 +607,20 @@ class MatrixBadType : public testing::TestWithParam<MatrixData> {
|
||||||
MatrixBadType() = default;
|
MatrixBadType() = default;
|
||||||
~MatrixBadType() = default;
|
~MatrixBadType() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
TEST_P(MatrixBadType, Handles_Unknown_Type) {
|
TEST_P(MatrixBadType, Handles_Unknown_Type) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
@ -665,22 +647,20 @@ class MatrixMissingType : public testing::TestWithParam<MatrixData> {
|
||||||
MatrixMissingType() = default;
|
MatrixMissingType() = default;
|
||||||
~MatrixMissingType() = default;
|
~MatrixMissingType() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
TEST_P(MatrixMissingType, Handles_Missing_Type) {
|
TEST_P(MatrixMissingType, Handles_Missing_Type) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
|
@ -36,22 +36,20 @@ class VariableStorageTest : public testing::TestWithParam<VariableStorageData> {
|
||||||
VariableStorageTest() = default;
|
VariableStorageTest() = default;
|
||||||
~VariableStorageTest() = default;
|
~VariableStorageTest() = default;
|
||||||
|
|
||||||
void SetUp() { ctx_.type_mgr = &tm_; }
|
void SetUp() { ctx_.Reset(); }
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
impl_ = nullptr;
|
impl_ = nullptr;
|
||||||
ctx_.type_mgr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
ParserImpl* parser(const std::string& str) {
|
||||||
impl_ = std::make_unique<ParserImpl>(ctx_, str);
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
return impl_.get();
|
return impl_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
TypeManager tm_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(VariableStorageTest, Parses) {
|
TEST_P(VariableStorageTest, Parses) {
|
||||||
|
|
|
@ -25,19 +25,15 @@ namespace {
|
||||||
using ParserTest = testing::Test;
|
using ParserTest = testing::Test;
|
||||||
|
|
||||||
TEST_F(ParserTest, Empty) {
|
TEST_F(ParserTest, Empty) {
|
||||||
TypeManager tm;
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
ctx.type_mgr = &tm;
|
Parser p(&ctx, "");
|
||||||
Parser p(ctx, "");
|
|
||||||
ASSERT_TRUE(p.Parse()) << p.error();
|
ASSERT_TRUE(p.Parse()) << p.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserTest, DISABLED_Parses) {
|
TEST_F(ParserTest, DISABLED_Parses) {
|
||||||
TypeManager tm;
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
ctx.type_mgr = &tm;
|
|
||||||
|
|
||||||
Parser p(ctx, R"(
|
Parser p(&ctx, R"(
|
||||||
import "GLSL.std.430" as glsl;
|
import "GLSL.std.430" as glsl;
|
||||||
|
|
||||||
[[location 0]] var<out> gl_FragColor : vec4<f32>;
|
[[location 0]] var<out> gl_FragColor : vec4<f32>;
|
||||||
|
@ -56,7 +52,7 @@ fn main() -> void {
|
||||||
|
|
||||||
TEST_F(ParserTest, DISABLED_HandlesError) {
|
TEST_F(ParserTest, DISABLED_HandlesError) {
|
||||||
Context ctx;
|
Context ctx;
|
||||||
Parser p(ctx, R"(
|
Parser p(&ctx, R"(
|
||||||
import "GLSL.std.430" as glsl;
|
import "GLSL.std.430" as glsl;
|
||||||
|
|
||||||
fn main() -> { # missing return type
|
fn main() -> { # missing return type
|
||||||
|
|
|
@ -22,6 +22,10 @@ TypeManager::TypeManager() = default;
|
||||||
|
|
||||||
TypeManager::~TypeManager() = default;
|
TypeManager::~TypeManager() = default;
|
||||||
|
|
||||||
|
void TypeManager::Reset() {
|
||||||
|
types_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
ast::type::Type* TypeManager::Get(std::unique_ptr<ast::type::Type> type) {
|
ast::type::Type* TypeManager::Get(std::unique_ptr<ast::type::Type> type) {
|
||||||
auto name = type->type_name();
|
auto name = type->type_name();
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,21 @@ class TypeManager {
|
||||||
TypeManager();
|
TypeManager();
|
||||||
~TypeManager();
|
~TypeManager();
|
||||||
|
|
||||||
|
/// Clears all registered types.
|
||||||
|
void Reset();
|
||||||
|
|
||||||
/// Get the given type from the type manager
|
/// Get the given type from the type manager
|
||||||
/// @param type The type to register
|
/// @param type The type to register
|
||||||
/// @return the pointer to the registered type
|
/// @return the pointer to the registered type
|
||||||
ast::type::Type* Get(std::unique_ptr<ast::type::Type> type);
|
ast::type::Type* Get(std::unique_ptr<ast::type::Type> type);
|
||||||
|
|
||||||
|
/// Returns the type map, for testing purposes.
|
||||||
|
/// @returns the mapping from name string to type.
|
||||||
|
const std::unordered_map<std::string, std::unique_ptr<ast::type::Type>>&
|
||||||
|
TypesForTesting() {
|
||||||
|
return types_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::unique_ptr<ast::type::Type>> types_;
|
std::unordered_map<std::string, std::unique_ptr<ast::type::Type>> types_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,5 +52,18 @@ TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) {
|
||||||
EXPECT_TRUE(t2->IsU32());
|
EXPECT_TRUE(t2->IsU32());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TypeManagerTest, ResetClearsPreviousData) {
|
||||||
|
TypeManager tm;
|
||||||
|
auto t = tm.Get(std::make_unique<ast::type::I32Type>());
|
||||||
|
ASSERT_NE(t, nullptr);
|
||||||
|
|
||||||
|
EXPECT_FALSE(tm.TypesForTesting().empty());
|
||||||
|
tm.Reset();
|
||||||
|
EXPECT_TRUE(tm.TypesForTesting().empty());
|
||||||
|
|
||||||
|
auto t2 = tm.Get(std::make_unique<ast::type::I32Type>());
|
||||||
|
ASSERT_NE(t2, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
Loading…
Reference in New Issue