Remove tint::Source(size_t, size_t) constructor
This was a temporary overload to break up the changes into smaller chunks. Change all call sites to use one of the other constructors. Bug: tint:282 Change-Id: I500fe9700d22f72312827808caa22f7feef7b294 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31440 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
74023424da
commit
fc5a9cfaf7
|
@ -38,7 +38,8 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
|
|||
auto ary = std::make_unique<IdentifierExpression>("ary");
|
||||
auto idx = std::make_unique<IdentifierExpression>("idx");
|
||||
|
||||
ArrayAccessorExpression exp(Source{20, 2}, std::move(ary), std::move(idx));
|
||||
ArrayAccessorExpression exp(Source{Source::Location{20, 2}}, std::move(ary),
|
||||
std::move(idx));
|
||||
auto src = exp.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -39,7 +39,8 @@ TEST_F(AssignmentStatementTest, CreationWithSource) {
|
|||
auto lhs = std::make_unique<ast::IdentifierExpression>("lhs");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("rhs");
|
||||
|
||||
AssignmentStatement stmt(Source{20, 2}, std::move(lhs), std::move(rhs));
|
||||
AssignmentStatement stmt(Source{Source::Location{20, 2}}, std::move(lhs),
|
||||
std::move(rhs));
|
||||
auto src = stmt.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -42,8 +42,8 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) {
|
|||
auto lhs = std::make_unique<IdentifierExpression>("lhs");
|
||||
auto rhs = std::make_unique<IdentifierExpression>("rhs");
|
||||
|
||||
BinaryExpression r(Source{20, 2}, BinaryOp::kEqual, std::move(lhs),
|
||||
std::move(rhs));
|
||||
BinaryExpression r(Source{Source::Location{20, 2}}, BinaryOp::kEqual,
|
||||
std::move(lhs), std::move(rhs));
|
||||
auto src = r.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -39,7 +39,7 @@ TEST_F(BitcastExpressionTest, CreateWithSource) {
|
|||
type::F32Type f32;
|
||||
auto expr = std::make_unique<IdentifierExpression>("expr");
|
||||
|
||||
BitcastExpression exp(Source{20, 2}, &f32, std::move(expr));
|
||||
BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, std::move(expr));
|
||||
auto src = exp.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -60,7 +60,7 @@ TEST_F(BlockStatementTest, Creation_WithInsert) {
|
|||
}
|
||||
|
||||
TEST_F(BlockStatementTest, Creation_WithSource) {
|
||||
BlockStatement b(Source{20, 2});
|
||||
BlockStatement b(Source{Source::Location{20, 2}});
|
||||
auto src = b.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace {
|
|||
using BreakStatementTest = testing::Test;
|
||||
|
||||
TEST_F(BreakStatementTest, Creation_WithSource) {
|
||||
BreakStatement stmt(Source{20, 2});
|
||||
BreakStatement stmt(Source{Source::Location{20, 2}});
|
||||
auto src = stmt.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -44,7 +44,7 @@ TEST_F(CallExpressionTest, Creation) {
|
|||
|
||||
TEST_F(CallExpressionTest, Creation_WithSource) {
|
||||
auto func = std::make_unique<IdentifierExpression>("func");
|
||||
CallExpression stmt(Source{20, 2}, std::move(func), {});
|
||||
CallExpression stmt(Source{Source::Location{20, 2}}, std::move(func), {});
|
||||
auto src = stmt.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -74,7 +74,8 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
|
|||
auto body = std::make_unique<BlockStatement>();
|
||||
body->append(std::make_unique<DiscardStatement>());
|
||||
|
||||
CaseStatement c(Source{20, 2}, std::move(b), std::move(body));
|
||||
CaseStatement c(Source{Source::Location{20, 2}}, std::move(b),
|
||||
std::move(body));
|
||||
auto src = c.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace {
|
|||
using ContinueStatementTest = testing::Test;
|
||||
|
||||
TEST_F(ContinueStatementTest, Creation_WithSource) {
|
||||
ContinueStatement stmt(Source{20, 2});
|
||||
ContinueStatement stmt(Source{Source::Location{20, 2}});
|
||||
auto src = stmt.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -45,7 +45,7 @@ TEST_F(DecoratedVariableTest, Creation) {
|
|||
}
|
||||
|
||||
TEST_F(DecoratedVariableTest, CreationWithSource) {
|
||||
Source s{27, 4};
|
||||
Source s{Source::Location{27, 4}};
|
||||
type::F32Type t;
|
||||
auto var = std::make_unique<Variable>(s, "i", StorageClass::kPrivate, &t);
|
||||
DecoratedVariable dv(std::move(var));
|
||||
|
|
|
@ -31,7 +31,7 @@ TEST_F(DiscardStatementTest, Creation) {
|
|||
}
|
||||
|
||||
TEST_F(DiscardStatementTest, Creation_WithSource) {
|
||||
DiscardStatement stmt(Source{20, 2});
|
||||
DiscardStatement stmt(Source{Source::Location{20, 2}});
|
||||
EXPECT_EQ(stmt.line(), 20u);
|
||||
EXPECT_EQ(stmt.column(), 2u);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,8 @@ TEST_F(ElseStatementTest, Creation) {
|
|||
}
|
||||
|
||||
TEST_F(ElseStatementTest, Creation_WithSource) {
|
||||
ElseStatement e(Source{20, 2}, std::make_unique<BlockStatement>());
|
||||
ElseStatement e(Source{Source::Location{20, 2}},
|
||||
std::make_unique<BlockStatement>());
|
||||
auto src = e.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -29,7 +29,7 @@ TEST_F(FallthroughStatementTest, Creation) {
|
|||
}
|
||||
|
||||
TEST_F(FallthroughStatementTest, Creation_WithSource) {
|
||||
FallthroughStatement stmt(Source{20, 2});
|
||||
FallthroughStatement stmt(Source{Source::Location{20, 2}});
|
||||
auto src = stmt.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -56,7 +56,8 @@ TEST_F(FunctionTest, Creation_WithSource) {
|
|||
params.push_back(
|
||||
std::make_unique<Variable>("var", StorageClass::kNone, &i32));
|
||||
|
||||
Function f(Source{20, 2}, "func", std::move(params), &void_type);
|
||||
Function f(Source{Source::Location{20, 2}}, "func", std::move(params),
|
||||
&void_type);
|
||||
auto src = f.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -28,7 +28,7 @@ TEST_F(IdentifierExpressionTest, Creation) {
|
|||
}
|
||||
|
||||
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
|
||||
IdentifierExpression i(Source{20, 2}, "ident");
|
||||
IdentifierExpression i(Source{Source::Location{20, 2}}, "ident");
|
||||
EXPECT_EQ(i.name(), "ident");
|
||||
|
||||
auto src = i.source();
|
||||
|
|
|
@ -43,7 +43,7 @@ TEST_F(IfStatementTest, Creation_WithSource) {
|
|||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<DiscardStatement>());
|
||||
|
||||
IfStatement stmt(Source{20, 2}, std::move(cond), std::move(body));
|
||||
IfStatement stmt(Source{Source::Location{20, 2}}, std::move(cond), std::move(body));
|
||||
auto src = stmt.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -50,7 +50,8 @@ TEST_F(LoopStatementTest, Creation_WithSource) {
|
|||
auto continuing = std::make_unique<BlockStatement>();
|
||||
continuing->append(std::make_unique<DiscardStatement>());
|
||||
|
||||
LoopStatement l(Source{20, 2}, std::move(body), std::move(continuing));
|
||||
LoopStatement l(Source{Source::Location{20, 2}}, std::move(body),
|
||||
std::move(continuing));
|
||||
auto src = l.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -41,7 +41,8 @@ TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
|
|||
auto str = std::make_unique<IdentifierExpression>("structure");
|
||||
auto mem = std::make_unique<IdentifierExpression>("member");
|
||||
|
||||
MemberAccessorExpression stmt(Source{20, 2}, std::move(str), std::move(mem));
|
||||
MemberAccessorExpression stmt(Source{Source::Location{20, 2}}, std::move(str),
|
||||
std::move(mem));
|
||||
auto src = stmt.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -34,7 +34,7 @@ TEST_F(ReturnStatementTest, Creation) {
|
|||
}
|
||||
|
||||
TEST_F(ReturnStatementTest, Creation_WithSource) {
|
||||
ReturnStatement r(Source{20, 2});
|
||||
ReturnStatement r(Source{Source::Location{20, 2}});
|
||||
auto src = r.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -35,7 +35,7 @@ TEST_F(ScalarConstructorExpressionTest, Creation) {
|
|||
TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) {
|
||||
ast::type::BoolType bool_type;
|
||||
auto b = std::make_unique<BoolLiteral>(&bool_type, true);
|
||||
ScalarConstructorExpression c(Source{20, 2}, std::move(b));
|
||||
ScalarConstructorExpression c(Source{Source::Location{20, 2}}, std::move(b));
|
||||
auto src = c.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -43,7 +43,7 @@ TEST_F(StructMemberTest, Creation) {
|
|||
|
||||
TEST_F(StructMemberTest, CreationWithSource) {
|
||||
type::I32Type i32;
|
||||
Source s{27, 4};
|
||||
Source s{Source::Location{27, 4}};
|
||||
|
||||
StructMember st{s, "a", &i32, {}};
|
||||
EXPECT_EQ(st.name(), "a");
|
||||
|
|
|
@ -70,7 +70,8 @@ TEST_F(StructTest, CreationWithSourceAndDecorations) {
|
|||
StructDecorationList decos;
|
||||
decos.push_back(StructDecoration::kBlock);
|
||||
|
||||
Struct s{Source{27, 4}, std::move(decos), std::move(members)};
|
||||
Struct s{Source{Source::Location{27, 4}}, std::move(decos),
|
||||
std::move(members)};
|
||||
EXPECT_EQ(s.members().size(), 1u);
|
||||
ASSERT_EQ(s.decorations().size(), 1u);
|
||||
EXPECT_EQ(s.decorations()[0], StructDecoration::kBlock);
|
||||
|
|
|
@ -51,7 +51,7 @@ TEST_F(SwitchStatementTest, Creation) {
|
|||
TEST_F(SwitchStatementTest, Creation_WithSource) {
|
||||
auto ident = std::make_unique<IdentifierExpression>("ident");
|
||||
|
||||
SwitchStatement stmt(Source{20, 2}, std::move(ident), CaseStatementList());
|
||||
SwitchStatement stmt(Source{Source::Location{20, 2}}, std::move(ident), CaseStatementList());
|
||||
auto src = stmt.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -46,7 +46,8 @@ TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
|
|||
ExpressionList expr;
|
||||
expr.push_back(std::make_unique<IdentifierExpression>("expr"));
|
||||
|
||||
TypeConstructorExpression t(Source{20, 2}, &f32, std::move(expr));
|
||||
TypeConstructorExpression t(Source{Source::Location{20, 2}}, &f32,
|
||||
std::move(expr));
|
||||
auto src = t.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -36,7 +36,8 @@ TEST_F(UnaryOpExpressionTest, Creation) {
|
|||
|
||||
TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
|
||||
auto ident = std::make_unique<IdentifierExpression>("ident");
|
||||
UnaryOpExpression u(Source{20, 2}, UnaryOp::kNot, std::move(ident));
|
||||
UnaryOpExpression u(Source{Source::Location{20, 2}}, UnaryOp::kNot,
|
||||
std::move(ident));
|
||||
auto src = u.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
|
|
@ -37,7 +37,7 @@ TEST_F(VariableDeclStatementTest, Creation_WithSource) {
|
|||
type::F32Type f32;
|
||||
auto var = std::make_unique<Variable>("a", StorageClass::kNone, &f32);
|
||||
|
||||
VariableDeclStatement stmt(Source{20, 2}, std::move(var));
|
||||
VariableDeclStatement stmt(Source{Source::Location{20, 2}}, std::move(var));
|
||||
auto src = stmt.source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
|
@ -71,7 +71,7 @@ TEST_F(VariableDeclStatementTest, ToStr) {
|
|||
type::F32Type f32;
|
||||
auto var = std::make_unique<Variable>("a", StorageClass::kNone, &f32);
|
||||
|
||||
VariableDeclStatement stmt(Source{20, 2}, std::move(var));
|
||||
VariableDeclStatement stmt(Source{Source::Location{20, 2}}, std::move(var));
|
||||
std::ostringstream out;
|
||||
stmt.to_str(out, 2);
|
||||
EXPECT_EQ(out.str(), R"( VariableDeclStatement{
|
||||
|
|
|
@ -37,7 +37,7 @@ TEST_F(VariableTest, Creation) {
|
|||
}
|
||||
|
||||
TEST_F(VariableTest, CreationWithSource) {
|
||||
Source s{27, 4};
|
||||
Source s{Source::Location{27, 4}};
|
||||
type::F32Type t;
|
||||
Variable v(s, "i", StorageClass::kPrivate, &t);
|
||||
|
||||
|
@ -49,7 +49,7 @@ TEST_F(VariableTest, CreationWithSource) {
|
|||
}
|
||||
|
||||
TEST_F(VariableTest, CreationEmpty) {
|
||||
Source s{27, 4};
|
||||
Source s{Source::Location{27, 4}};
|
||||
Variable v;
|
||||
v.set_source(s);
|
||||
v.set_storage_class(StorageClass::kWorkgroup);
|
||||
|
|
|
@ -474,12 +474,12 @@ bool ParserImpl::ParseInternalModule() {
|
|||
}
|
||||
|
||||
void ParserImpl::RegisterLineNumbers() {
|
||||
Source::Location instruction_number{0, 0};
|
||||
Source::Location instruction_number{};
|
||||
|
||||
// Has there been an OpLine since the last OpNoLine or start of the module?
|
||||
bool in_op_line_scope = false;
|
||||
// The source location provided by the most recent OpLine instruction.
|
||||
Source::Location op_line_source{0, 0};
|
||||
Source::Location op_line_source{};
|
||||
const bool run_on_debug_insts = true;
|
||||
module_->ForEachInst(
|
||||
[this, &in_op_line_scope, &op_line_source,
|
||||
|
|
|
@ -26,48 +26,48 @@ namespace {
|
|||
using TokenTest = testing::Test;
|
||||
|
||||
TEST_F(TokenTest, ReturnsStr) {
|
||||
Token t(Token::Type::kStringLiteral, Source{1, 1}, "test string");
|
||||
Token t(Token::Type::kStringLiteral, Source{}, "test string");
|
||||
EXPECT_EQ(t.to_str(), "test string");
|
||||
}
|
||||
|
||||
TEST_F(TokenTest, ReturnsF32) {
|
||||
Token t1(Source{1, 1}, -2.345f);
|
||||
Token t1(Source{}, -2.345f);
|
||||
EXPECT_EQ(t1.to_f32(), -2.345f);
|
||||
|
||||
Token t2(Source{1, 1}, 2.345f);
|
||||
Token t2(Source{}, 2.345f);
|
||||
EXPECT_EQ(t2.to_f32(), 2.345f);
|
||||
}
|
||||
|
||||
TEST_F(TokenTest, ReturnsI32) {
|
||||
Token t1(Source{1, 1}, -2345);
|
||||
Token t1(Source{}, -2345);
|
||||
EXPECT_EQ(t1.to_i32(), -2345);
|
||||
|
||||
Token t2(Source{1, 1}, 2345);
|
||||
Token t2(Source{}, 2345);
|
||||
EXPECT_EQ(t2.to_i32(), 2345);
|
||||
}
|
||||
|
||||
TEST_F(TokenTest, HandlesMaxI32) {
|
||||
Token t1(Source{1, 1}, std::numeric_limits<int32_t>::max());
|
||||
Token t1(Source{}, std::numeric_limits<int32_t>::max());
|
||||
EXPECT_EQ(t1.to_i32(), std::numeric_limits<int32_t>::max());
|
||||
}
|
||||
|
||||
TEST_F(TokenTest, HandlesMinI32) {
|
||||
Token t1(Source{1, 1}, std::numeric_limits<int32_t>::min());
|
||||
Token t1(Source{}, std::numeric_limits<int32_t>::min());
|
||||
EXPECT_EQ(t1.to_i32(), std::numeric_limits<int32_t>::min());
|
||||
}
|
||||
|
||||
TEST_F(TokenTest, ReturnsU32) {
|
||||
Token t2(Source{1, 1}, 2345u);
|
||||
Token t2(Source{}, 2345u);
|
||||
EXPECT_EQ(t2.to_u32(), 2345u);
|
||||
}
|
||||
|
||||
TEST_F(TokenTest, ReturnsMaxU32) {
|
||||
Token t1(Source{1, 1}, std::numeric_limits<uint32_t>::max());
|
||||
Token t1(Source{}, std::numeric_limits<uint32_t>::max());
|
||||
EXPECT_EQ(t1.to_u32(), std::numeric_limits<uint32_t>::max());
|
||||
}
|
||||
|
||||
TEST_F(TokenTest, Source) {
|
||||
Token t(Token::Type::kUintLiteral, Source{3, 9});
|
||||
Token t(Token::Type::kUintLiteral, Source{Source::Location{3, 9}});
|
||||
EXPECT_EQ(t.line(), 3u);
|
||||
EXPECT_EQ(t.column(), 9u);
|
||||
}
|
||||
|
|
|
@ -74,13 +74,6 @@ class Source {
|
|||
/// Constructs the Source with the Range |rng| and File |f|.
|
||||
inline Source(const Range& rng, File const* f) : range(rng), file(f) {}
|
||||
|
||||
/// Constructs the Source with the zero-length range starting at |line| and
|
||||
/// |column| with a null File.
|
||||
/// TODO(bclayton): Remove this constructor.
|
||||
/// It purely exists to break up changes into bite sized pieces.
|
||||
inline explicit Source(size_t line, size_t column)
|
||||
: Source(Location{line, column}) {}
|
||||
|
||||
Range range;
|
||||
File const* file = nullptr;
|
||||
};
|
||||
|
|
|
@ -102,7 +102,7 @@ class TypeDeterminerTestWithParam : public TypeDeterminerHelper,
|
|||
|
||||
TEST_F(TypeDeterminerTest, Error_WithEmptySource) {
|
||||
FakeStmt s;
|
||||
s.set_source(Source{0, 0});
|
||||
s.set_source(Source{});
|
||||
|
||||
EXPECT_FALSE(td()->DetermineResultType(&s));
|
||||
EXPECT_EQ(td()->error(),
|
||||
|
@ -111,7 +111,7 @@ TEST_F(TypeDeterminerTest, Error_WithEmptySource) {
|
|||
|
||||
TEST_F(TypeDeterminerTest, Stmt_Error_Unknown) {
|
||||
FakeStmt s;
|
||||
s.set_source(Source{2, 30});
|
||||
s.set_source(Source{Source::Location{2, 30}});
|
||||
|
||||
EXPECT_FALSE(td()->DetermineResultType(&s));
|
||||
EXPECT_EQ(td()->error(),
|
||||
|
@ -400,7 +400,8 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) {
|
|||
ast::type::F32Type f32;
|
||||
ast::ExpressionList call_params;
|
||||
auto call_expr = std::make_unique<ast::CallExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>(Source{12, 34}, "func"),
|
||||
std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "func"),
|
||||
std::move(call_params));
|
||||
ast::VariableList params0;
|
||||
auto func_main =
|
||||
|
@ -454,7 +455,7 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl_ModuleScope) {
|
|||
|
||||
TEST_F(TypeDeterminerTest, Expr_Error_Unknown) {
|
||||
FakeExpr e;
|
||||
e.set_source(Source{2, 30});
|
||||
e.set_source(Source{Source::Location{2, 30}});
|
||||
|
||||
EXPECT_FALSE(td()->DetermineResultType(&e));
|
||||
EXPECT_EQ(td()->error(), "2:30: unknown expression for type determination");
|
||||
|
|
|
@ -49,7 +49,8 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
|
|||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&f32, 3.14f)));
|
||||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>(Source{12, 34}, "a");
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "a");
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
ast::CaseStatementList body;
|
||||
|
@ -89,7 +90,7 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
|
|||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(std::make_unique<ast::SwitchStatement>(
|
||||
Source{12, 34}, std::move(cond), std::move(body)));
|
||||
Source{Source::Location{12, 34}}, std::move(cond), std::move(body)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block.get()));
|
||||
|
@ -133,7 +134,8 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
|
|||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block->append(std::make_unique<ast::SwitchStatement>(
|
||||
Source{12, 34}, std::move(cond), std::move(switch_body)));
|
||||
Source{Source::Location{12, 34}}, std::move(cond),
|
||||
std::move(switch_body)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(block.get())) << td()->error();
|
||||
EXPECT_FALSE(v()->ValidateStatements(block.get()));
|
||||
|
@ -162,7 +164,8 @@ TEST_F(ValidateControlBlockTest,
|
|||
ast::CaseSelectorList csl;
|
||||
csl.push_back(std::make_unique<ast::UintLiteral>(&u32, 1));
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
Source{12, 34}, std::move(csl), std::make_unique<ast::BlockStatement>()));
|
||||
Source{Source::Location{12, 34}}, std::move(csl),
|
||||
std::make_unique<ast::BlockStatement>()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
|
@ -201,7 +204,8 @@ TEST_F(ValidateControlBlockTest,
|
|||
ast::CaseSelectorList csl;
|
||||
csl.push_back(std::make_unique<ast::SintLiteral>(&i32, -1));
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
Source{12, 34}, std::move(csl), std::make_unique<ast::BlockStatement>()));
|
||||
Source{Source::Location{12, 34}}, std::move(csl),
|
||||
std::make_unique<ast::BlockStatement>()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
|
@ -245,7 +249,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
|
|||
csl_2.push_back(std::make_unique<ast::UintLiteral>(&u32, 2));
|
||||
csl_2.push_back(std::make_unique<ast::UintLiteral>(&u32, 2));
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
Source{12, 34}, std::move(csl_2),
|
||||
Source{Source::Location{12, 34}}, std::move(csl_2),
|
||||
std::make_unique<ast::BlockStatement>()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
|
@ -292,7 +296,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
|
|||
csl_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
csl_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 10));
|
||||
switch_body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
Source{12, 34}, std::move(csl_2),
|
||||
Source{Source::Location{12, 34}}, std::move(csl_2),
|
||||
std::make_unique<ast::BlockStatement>()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
|
@ -326,8 +330,8 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
|
|||
auto cond = std::make_unique<ast::IdentifierExpression>("a");
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
block_default->append(
|
||||
std::make_unique<ast::FallthroughStatement>(Source{12, 34}));
|
||||
block_default->append(std::make_unique<ast::FallthroughStatement>(
|
||||
Source{Source::Location{12, 34}}));
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
std::move(default_csl), std::move(block_default)));
|
||||
|
@ -361,7 +365,8 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
|
|||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
Source{12, 34}, std::move(default_csl), std::move(block_default)));
|
||||
Source{Source::Location{12, 34}}, std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
ast::CaseSelectorList case_csl;
|
||||
case_csl.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
auto block_case = std::make_unique<ast::BlockStatement>();
|
||||
|
@ -397,7 +402,8 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
|
|||
auto block_default = std::make_unique<ast::BlockStatement>();
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(std::make_unique<ast::CaseStatement>(
|
||||
Source{12, 34}, std::move(default_csl), std::move(block_default)));
|
||||
Source{Source::Location{12, 34}}, std::move(default_csl),
|
||||
std::move(block_default)));
|
||||
|
||||
auto block = std::make_unique<ast::BlockStatement>();
|
||||
block->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
|
|
|
@ -47,8 +47,8 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
|
|||
|
||||
ast::VariableList params;
|
||||
ast::type::VoidType void_type;
|
||||
auto func = std::make_unique<ast::Function>(Source{12, 34}, "func",
|
||||
std::move(params), &void_type);
|
||||
auto func = std::make_unique<ast::Function>(
|
||||
Source{Source::Location{12, 34}}, "func", std::move(params), &void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
func->set_body(std::move(body));
|
||||
|
@ -64,8 +64,8 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
|
|||
// fn func -> void {}
|
||||
ast::type::VoidType void_type;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>(Source{12, 34}, "func",
|
||||
std::move(params), &void_type);
|
||||
auto func = std::make_unique<ast::Function>(
|
||||
Source{Source::Location{12, 34}}, "func", std::move(params), &void_type);
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
@ -104,8 +104,8 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
|
|||
auto return_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
body->append(std::make_unique<ast::ReturnStatement>(Source{12, 34},
|
||||
std::move(return_expr)));
|
||||
body->append(std::make_unique<ast::ReturnStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(return_expr)));
|
||||
func->set_body(std::move(body));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
|
@ -127,8 +127,8 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
|
|||
auto return_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
body->append(std::make_unique<ast::ReturnStatement>(Source{12, 34},
|
||||
std::move(return_expr)));
|
||||
body->append(std::make_unique<ast::ReturnStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(return_expr)));
|
||||
func->set_body(std::move(body));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
|
@ -157,7 +157,7 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
|
|||
|
||||
ast::VariableList params_copy;
|
||||
auto func_copy = std::make_unique<ast::Function>(
|
||||
Source{12, 34}, "func", std::move(params_copy), &i32);
|
||||
Source{Source::Location{12, 34}}, "func", std::move(params_copy), &i32);
|
||||
auto body_copy = std::make_unique<ast::BlockStatement>();
|
||||
auto return_expr_copy = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
|
@ -181,7 +181,8 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
|
|||
ast::type::VoidType void_type;
|
||||
ast::ExpressionList call_params;
|
||||
auto call_expr = std::make_unique<ast::CallExpression>(
|
||||
Source{12, 34}, std::make_unique<ast::IdentifierExpression>("func"),
|
||||
Source{Source::Location{12, 34}},
|
||||
std::make_unique<ast::IdentifierExpression>("func"),
|
||||
std::move(call_params));
|
||||
ast::VariableList params0;
|
||||
auto func0 =
|
||||
|
@ -204,7 +205,8 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
|
|||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32);
|
||||
ast::ExpressionList call_params;
|
||||
auto call_expr = std::make_unique<ast::CallExpression>(
|
||||
Source{12, 34}, std::make_unique<ast::IdentifierExpression>("func"),
|
||||
Source{Source::Location{12, 34}},
|
||||
std::make_unique<ast::IdentifierExpression>("func"),
|
||||
std::move(call_params));
|
||||
var->set_constructor(std::move(call_expr));
|
||||
ast::VariableList params0;
|
||||
|
@ -229,8 +231,8 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
|
|||
// fn vtx_main() -> i32 { return 0; }
|
||||
ast::type::I32Type i32;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>(Source{12, 34}, "vtx_main",
|
||||
std::move(params), &i32);
|
||||
auto func = std::make_unique<ast::Function>(
|
||||
Source{Source::Location{12, 34}}, "vtx_main", std::move(params), &i32);
|
||||
auto return_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 0));
|
||||
|
||||
|
@ -255,8 +257,9 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
|
|||
ast::VariableList params;
|
||||
params.push_back(
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &i32));
|
||||
auto func = std::make_unique<ast::Function>(Source{12, 34}, "vtx_func",
|
||||
std::move(params), &void_type);
|
||||
auto func = std::make_unique<ast::Function>(Source{Source::Location{12, 34}},
|
||||
"vtx_func", std::move(params),
|
||||
&void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
@ -278,8 +281,8 @@ TEST_F(ValidateFunctionTest, PipelineStageNamePair_MustBeUnique_Fail) {
|
|||
// fn main() -> void { return; }
|
||||
ast::type::VoidType void_type;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>(Source{5, 6}, "main",
|
||||
std::move(params), &void_type);
|
||||
auto func = std::make_unique<ast::Function>(
|
||||
Source{Source::Location{5, 6}}, "main", std::move(params), &void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
@ -287,8 +290,8 @@ TEST_F(ValidateFunctionTest, PipelineStageNamePair_MustBeUnique_Fail) {
|
|||
std::make_unique<ast::StageDecoration>(ast::PipelineStage::kVertex));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
func = std::make_unique<ast::Function>(Source{12, 34}, "main",
|
||||
std::move(params), &void_type);
|
||||
func = std::make_unique<ast::Function>(Source{Source::Location{12, 34}},
|
||||
"main", std::move(params), &void_type);
|
||||
body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
@ -310,8 +313,8 @@ TEST_F(ValidateFunctionTest, PipelineStageNamePair_MustBeUnique_Pass) {
|
|||
// fn main() -> void { return; }
|
||||
ast::type::VoidType void_type;
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>(Source{5, 6}, "main",
|
||||
std::move(params), &void_type);
|
||||
auto func = std::make_unique<ast::Function>(
|
||||
Source{Source::Location{5, 6}}, "main", std::move(params), &void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
@ -319,8 +322,8 @@ TEST_F(ValidateFunctionTest, PipelineStageNamePair_MustBeUnique_Pass) {
|
|||
std::make_unique<ast::StageDecoration>(ast::PipelineStage::kVertex));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
func = std::make_unique<ast::Function>(Source{12, 34}, "main",
|
||||
std::move(params), &void_type);
|
||||
func = std::make_unique<ast::Function>(Source{Source::Location{12, 34}},
|
||||
"main", std::move(params), &void_type);
|
||||
body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
|
|
@ -134,7 +134,7 @@ bool ValidatorImpl::ValidateFunctions(const ast::FunctionList& funcs) {
|
|||
}
|
||||
|
||||
if (pipeline_count == 0) {
|
||||
set_error(Source{0, 0},
|
||||
set_error(Source{},
|
||||
"v-0003: At least one of vertex, fragment or compute shader must "
|
||||
"be present");
|
||||
return false;
|
||||
|
|
|
@ -68,8 +68,8 @@ TEST_F(ValidatorTest, DISABLED_AssignToScalar_Fail) {
|
|||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("my_var");
|
||||
ast::AssignmentStatement assign(Source{12, 34}, std::move(lhs),
|
||||
std::move(rhs));
|
||||
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
|
||||
std::move(lhs), std::move(rhs));
|
||||
|
||||
// TODO(sarahM0): Invalidate assignment to scalar.
|
||||
ASSERT_TRUE(v()->has_error());
|
||||
|
@ -81,11 +81,12 @@ TEST_F(ValidatorTest, UsingUndefinedVariable_Fail) {
|
|||
// b = 2;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(Source{12, 34}, "b");
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "b");
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto assign = std::make_unique<ast::AssignmentStatement>(
|
||||
Source{12, 34}, std::move(lhs), std::move(rhs));
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs));
|
||||
|
||||
EXPECT_FALSE(td()->DetermineResultType(assign.get()));
|
||||
EXPECT_EQ(td()->error(),
|
||||
|
@ -98,13 +99,14 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
|
|||
// }
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(Source{12, 34}, "b");
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "b");
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
Source{12, 34}, std::move(lhs), std::move(rhs)));
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_FALSE(td()->DetermineStatements(body.get()));
|
||||
EXPECT_EQ(td()->error(),
|
||||
|
@ -126,8 +128,8 @@ TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
|
|||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
auto* rhs_ptr = rhs.get();
|
||||
|
||||
ast::AssignmentStatement assign(Source{12, 34}, std::move(lhs),
|
||||
std::move(rhs));
|
||||
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
|
||||
std::move(lhs), std::move(rhs));
|
||||
td()->RegisterVariableForTesting(var.get());
|
||||
EXPECT_TRUE(td()->DetermineResultType(&assign)) << td()->error();
|
||||
ASSERT_NE(lhs_ptr->result_type(), nullptr);
|
||||
|
@ -153,8 +155,8 @@ TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
|
|||
std::make_unique<ast::FloatLiteral>(&f32, 2.3f));
|
||||
auto* rhs_ptr = rhs.get();
|
||||
|
||||
ast::AssignmentStatement assign(Source{12, 34}, std::move(lhs),
|
||||
std::move(rhs));
|
||||
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
|
||||
std::move(lhs), std::move(rhs));
|
||||
td()->RegisterVariableForTesting(var.get());
|
||||
EXPECT_TRUE(td()->DetermineResultType(&assign)) << td()->error();
|
||||
ASSERT_NE(lhs_ptr->result_type(), nullptr);
|
||||
|
@ -187,7 +189,7 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
|
|||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
Source{12, 34}, std::move(lhs), std::move(rhs)));
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(body.get())) << td()->error();
|
||||
ASSERT_NE(lhs_ptr->result_type(), nullptr);
|
||||
|
@ -217,7 +219,7 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
|
|||
ast::BlockStatement block;
|
||||
block.append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
block.append(std::make_unique<ast::AssignmentStatement>(
|
||||
Source{12, 34}, std::move(lhs), std::move(rhs)));
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(&block)) << td()->error();
|
||||
ASSERT_NE(lhs_ptr->result_type(), nullptr);
|
||||
|
@ -234,7 +236,8 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
|
|||
// var<in> gloabl_var: f32;
|
||||
ast::type::F32Type f32;
|
||||
auto global_var = std::make_unique<ast::Variable>(
|
||||
Source{12, 34}, "global_var", ast::StorageClass::kInput, &f32);
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kInput,
|
||||
&f32);
|
||||
mod()->AddGlobalVariable(std::move(global_var));
|
||||
EXPECT_TRUE(v()->ValidateGlobalVariables(mod()->global_variables()))
|
||||
<< v()->error();
|
||||
|
@ -244,7 +247,8 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
|||
// var gloabl_var: f32;
|
||||
ast::type::F32Type f32;
|
||||
auto global_var = std::make_unique<ast::Variable>(
|
||||
Source{12, 34}, "global_var", ast::StorageClass::kNone, &f32);
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kNone,
|
||||
&f32);
|
||||
mod()->AddGlobalVariable(std::move(global_var));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_FALSE(v()->Validate(mod()));
|
||||
|
@ -255,7 +259,8 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
|||
// const<in> gloabl_var: f32;
|
||||
ast::type::F32Type f32;
|
||||
auto global_var = std::make_unique<ast::Variable>(
|
||||
Source{12, 34}, "global_var", ast::StorageClass::kInput, &f32);
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kInput,
|
||||
&f32);
|
||||
global_var->set_is_const(true);
|
||||
|
||||
mod()->AddGlobalVariable(std::move(global_var));
|
||||
|
@ -270,7 +275,8 @@ TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
|
|||
// const gloabl_var: f32;
|
||||
ast::type::F32Type f32;
|
||||
auto global_var = std::make_unique<ast::Variable>(
|
||||
Source{12, 34}, "global_var", ast::StorageClass::kNone, &f32);
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kNone,
|
||||
&f32);
|
||||
global_var->set_is_const(true);
|
||||
|
||||
mod()->AddGlobalVariable(std::move(global_var));
|
||||
|
@ -291,8 +297,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
|
|||
std::make_unique<ast::FloatLiteral>(&f32, 2.1)));
|
||||
mod()->AddGlobalVariable(std::move(global_var));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(Source{12, 34},
|
||||
"not_global_var");
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "not_global_var");
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.14f));
|
||||
|
||||
|
@ -302,7 +308,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
|
|||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
Source{12, 34}, std::move(lhs), std::move(rhs)));
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
func->set_body(std::move(body));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
|
@ -336,7 +342,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
|||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
Source{12, 34}, std::move(lhs), std::move(rhs)));
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
func->add_decoration(
|
||||
|
@ -364,7 +370,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
|
|||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(Source{12, 34}, "a");
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "a");
|
||||
auto* lhs_ptr = lhs.get();
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.14f));
|
||||
|
@ -374,7 +381,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
|
|||
outer_body->append(
|
||||
std::make_unique<ast::IfStatement>(std::move(cond), std::move(body)));
|
||||
outer_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
Source{12, 34}, std::move(lhs), std::move(rhs)));
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(outer_body.get())) << td()->error();
|
||||
ASSERT_NE(lhs_ptr->result_type(), nullptr);
|
||||
|
@ -394,7 +401,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
|
|||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0)));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(Source{12, 34}, "a");
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>(
|
||||
Source{Source::Location{12, 34}}, "a");
|
||||
auto* lhs_ptr = lhs.get();
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.14f));
|
||||
|
@ -404,7 +412,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
|
|||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
Source{12, 34}, std::move(lhs), std::move(rhs)));
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
auto outer_body = std::make_unique<ast::BlockStatement>();
|
||||
outer_body->append(
|
||||
|
@ -429,7 +437,8 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
|||
mod()->AddGlobalVariable(std::move(var0));
|
||||
|
||||
auto var1 = std::make_unique<ast::Variable>(
|
||||
Source{12, 34}, "global_var1", ast::StorageClass::kPrivate, &f32);
|
||||
Source{Source::Location{12, 34}}, "global_var1",
|
||||
ast::StorageClass::kPrivate, &f32);
|
||||
var1->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 0)));
|
||||
mod()->AddGlobalVariable(std::move(var1));
|
||||
|
@ -450,7 +459,8 @@ TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
|
|||
mod()->AddGlobalVariable(std::move(var0));
|
||||
|
||||
auto var1 = std::make_unique<ast::Variable>(
|
||||
Source{12, 34}, "global_var", ast::StorageClass::kPrivate, &f32);
|
||||
Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kPrivate, &f32);
|
||||
var1->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 0)));
|
||||
mod()->AddGlobalVariable(std::move(var1));
|
||||
|
@ -481,7 +491,7 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
|
|||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
Source{12, 34}, std::move(lhs), std::move(rhs)));
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(body.get())) << td()->error();
|
||||
ASSERT_NE(lhs_ptr->result_type(), nullptr);
|
||||
|
@ -515,8 +525,8 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
|
|||
auto func =
|
||||
std::make_unique<ast::Function>("my_func", std::move(params), &void_type);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(Source{12, 34},
|
||||
std::move(var)));
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(var)));
|
||||
func->set_body(std::move(body));
|
||||
auto* func_ptr = func.get();
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
@ -552,7 +562,7 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
|
|||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
Source{12, 34}, std::move(var_a_float)));
|
||||
Source{Source::Location{12, 34}}, std::move(var_a_float)));
|
||||
func->set_body(std::move(body));
|
||||
auto* func_ptr = func.get();
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
@ -590,7 +600,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
|||
outer_body->append(
|
||||
std::make_unique<ast::IfStatement>(std::move(cond), std::move(body)));
|
||||
outer_body->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
Source{12, 34}, std::move(var_a_float)));
|
||||
Source{Source::Location{12, 34}}, std::move(var_a_float)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(outer_body.get())) << td()->error();
|
||||
EXPECT_TRUE(v()->ValidateStatements(outer_body.get())) << v()->error();
|
||||
|
@ -619,8 +629,8 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
|
|||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(Source{12, 34},
|
||||
std::move(var)));
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(var)));
|
||||
|
||||
auto outer_body = std::make_unique<ast::BlockStatement>();
|
||||
outer_body->append(
|
||||
|
@ -652,8 +662,8 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
|||
auto func0 =
|
||||
std::make_unique<ast::Function>("func0", std::move(params0), &void_type);
|
||||
auto body0 = std::make_unique<ast::BlockStatement>();
|
||||
body0->append(std::make_unique<ast::VariableDeclStatement>(Source{12, 34},
|
||||
std::move(var0)));
|
||||
body0->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, std::move(var0)));
|
||||
body0->append(std::make_unique<ast::ReturnStatement>());
|
||||
func0->set_body(std::move(body0));
|
||||
|
||||
|
@ -661,8 +671,8 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
|||
auto func1 =
|
||||
std::make_unique<ast::Function>("func1", std::move(params1), &void_type);
|
||||
auto body1 = std::make_unique<ast::BlockStatement>();
|
||||
body1->append(std::make_unique<ast::VariableDeclStatement>(Source{13, 34},
|
||||
std::move(var1)));
|
||||
body1->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{13, 34}}, std::move(var1)));
|
||||
body1->append(std::make_unique<ast::ReturnStatement>());
|
||||
func1->set_body(std::move(body1));
|
||||
func1->add_decoration(
|
||||
|
@ -694,7 +704,7 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
|
|||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
Source{12, 34}, std::move(lhs), std::move(rhs)));
|
||||
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineStatements(body.get())) << td()->error();
|
||||
ASSERT_NE(lhs_ptr->result_type(), nullptr);
|
||||
|
|
Loading…
Reference in New Issue