mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
ast::TypesBuilder: Change const fields to getters
This is required in order to support move operators for TypesBuilder. Bug: tint:390 Change-Id: I9667bda5f5be267df092f5cd94dc40db053ae6e2 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38555 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -42,7 +42,7 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
|
||||
// switch (a) {
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(3.14f),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(3.14f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseStatementList body;
|
||||
@@ -71,7 +71,7 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
|
||||
// switch (a) {
|
||||
// case 1: {}
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseSelectorList csl;
|
||||
@@ -104,7 +104,7 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
|
||||
// case 1: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
@@ -146,12 +146,12 @@ TEST_F(ValidateControlBlockTest,
|
||||
// case 1: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
ast::CaseSelectorList csl;
|
||||
csl.push_back(create<ast::UintLiteral>(ty.u32, 1));
|
||||
csl.push_back(create<ast::UintLiteral>(ty.u32(), 1));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, csl,
|
||||
create<ast::BlockStatement>(ast::StatementList{})));
|
||||
@@ -181,7 +181,7 @@ TEST_F(ValidateControlBlockTest,
|
||||
// case -1: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.u32, Expr(2u),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.u32(), Expr(2u),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
@@ -216,18 +216,18 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
|
||||
// case 2, 2: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.u32, Expr(3u),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.u32(), Expr(3u),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
ast::CaseSelectorList csl_1;
|
||||
csl_1.push_back(create<ast::UintLiteral>(ty.u32, 0));
|
||||
csl_1.push_back(create<ast::UintLiteral>(ty.u32(), 0));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
csl_1, create<ast::BlockStatement>(ast::StatementList{})));
|
||||
|
||||
ast::CaseSelectorList csl_2;
|
||||
csl_2.push_back(create<ast::UintLiteral>(ty.u32, 2));
|
||||
csl_2.push_back(create<ast::UintLiteral>(ty.u32, 2));
|
||||
csl_2.push_back(create<ast::UintLiteral>(ty.u32(), 2));
|
||||
csl_2.push_back(create<ast::UintLiteral>(ty.u32(), 2));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, csl_2,
|
||||
create<ast::BlockStatement>(ast::StatementList{})));
|
||||
@@ -257,7 +257,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
|
||||
// case 0,1,2,10: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
@@ -298,7 +298,7 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
|
||||
// switch (a) {
|
||||
// default: { fallthrough; }
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
@@ -330,7 +330,7 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
|
||||
// default: {}
|
||||
// case 5: {}
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
@@ -361,7 +361,7 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
|
||||
// default: {}
|
||||
// }
|
||||
|
||||
auto* my_int = ty.alias("MyInt", ty.u32);
|
||||
auto* my_int = ty.alias("MyInt", ty.u32());
|
||||
auto* var = Var("a", ast::StorageClass::kNone, my_int, Expr(2u),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
|
||||
@@ -38,11 +38,11 @@ class ValidateFunctionTest : public ValidatorTestHelper,
|
||||
TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
|
||||
// [[stage(vertex)]]
|
||||
// fn func -> void { var a:i32 = 2; }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* func = Func(
|
||||
Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.void_,
|
||||
Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
},
|
||||
@@ -64,7 +64,7 @@ TEST_F(ValidateFunctionTest,
|
||||
// fn func -> void {}
|
||||
auto* func =
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
|
||||
ty.void_, ast::StatementList{},
|
||||
ty.void_(), ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
@@ -80,11 +80,11 @@ TEST_F(ValidateFunctionTest,
|
||||
TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||
// fn func -> int { var a:i32 = 2; }
|
||||
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* func = Func(Source{Source::Location{12, 34}}, "func",
|
||||
ast::VariableList{}, ty.i32,
|
||||
ast::VariableList{}, ty.i32(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
},
|
||||
@@ -104,7 +104,7 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
|
||||
// fn func -> int {}
|
||||
auto* func =
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
|
||||
ty.i32, ast::StatementList{}, ast::FunctionDecorationList{});
|
||||
ty.i32(), ast::StatementList{}, ast::FunctionDecorationList{});
|
||||
mod->AST().Functions().Add(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
@@ -120,7 +120,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
|
||||
// [[stage(vertex)]]
|
||||
// fn func -> void { return; }
|
||||
auto* func =
|
||||
Func("func", ast::VariableList{}, ty.void_,
|
||||
Func("func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
@@ -139,7 +139,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
|
||||
|
||||
TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
|
||||
// fn func -> void { return 2; }
|
||||
auto* func = Func("func", ast::VariableList{}, ty.void_,
|
||||
auto* func = Func("func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(
|
||||
Source{Source::Location{12, 34}}, Expr(2)),
|
||||
@@ -160,7 +160,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
|
||||
|
||||
TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
|
||||
// fn func -> f32 { return 2; }
|
||||
auto* func = Func("func", ast::VariableList{}, ty.f32,
|
||||
auto* func = Func("func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(
|
||||
Source{Source::Location{12, 34}}, Expr(2)),
|
||||
@@ -182,14 +182,14 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
|
||||
TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
|
||||
// fn func -> i32 { return 2; }
|
||||
// fn func -> i32 { return 2; }
|
||||
auto* func = Func("func", ast::VariableList{}, ty.i32,
|
||||
auto* func = Func("func", ast::VariableList{}, ty.i32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Expr(2)),
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
auto* func_copy = Func(Source{Source::Location{12, 34}}, "func",
|
||||
ast::VariableList{}, ty.i32,
|
||||
ast::VariableList{}, ty.i32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Expr(2)),
|
||||
},
|
||||
@@ -212,7 +212,7 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
|
||||
auto* call_expr = create<ast::CallExpression>(
|
||||
Source{Source::Location{12, 34}}, Expr("func"), call_params);
|
||||
|
||||
auto* func0 = Func("func", ast::VariableList{}, ty.f32,
|
||||
auto* func0 = Func("func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::CallStatement>(call_expr),
|
||||
create<ast::ReturnStatement>(),
|
||||
@@ -233,10 +233,10 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
|
||||
ast::ExpressionList call_params;
|
||||
auto* call_expr = create<ast::CallExpression>(
|
||||
Source{Source::Location{12, 34}}, Expr("func"), call_params);
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, call_expr,
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), call_expr,
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* func0 = Func("func", ast::VariableList{}, ty.i32,
|
||||
auto* func0 = Func("func", ast::VariableList{}, ty.i32(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::ReturnStatement>(Expr(2)),
|
||||
@@ -255,14 +255,15 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
|
||||
TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
|
||||
// [[stage(vertex)]]
|
||||
// fn vtx_main() -> i32 { return 0; }
|
||||
auto* func = Func(
|
||||
Source{Source::Location{12, 34}}, "vtx_main", ast::VariableList{}, ty.i32,
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Expr(0)),
|
||||
},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
auto* func =
|
||||
Func(Source{Source::Location{12, 34}}, "vtx_main", ast::VariableList{},
|
||||
ty.i32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Expr(0)),
|
||||
},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
mod->AST().Functions().Add(func);
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
@@ -279,9 +280,9 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
|
||||
// fn vtx_func(a : i32) -> void { return; }
|
||||
auto* func =
|
||||
Func(Source{Source::Location{12, 34}}, "vtx_func",
|
||||
ast::VariableList{Var("a", ast::StorageClass::kNone, ty.i32, nullptr,
|
||||
ast::VariableDecorationList{})},
|
||||
ty.void_,
|
||||
ast::VariableList{Var("a", ast::StorageClass::kNone, ty.i32(),
|
||||
nullptr, ast::VariableDecorationList{})},
|
||||
ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
@@ -305,7 +306,7 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
|
||||
// [[stage(vertex)]]
|
||||
// fn main() -> void { return; }
|
||||
auto* func = Func(
|
||||
Source{Source::Location{12, 34}}, "main", ast::VariableList{}, ty.void_,
|
||||
Source{Source::Location{12, 34}}, "main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
@@ -329,7 +330,7 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
|
||||
// [[stage(vertex)]]
|
||||
// fn vtx_func() -> void { return; }
|
||||
auto* func =
|
||||
Func("vtx_func", ast::VariableList{}, ty.void_,
|
||||
Func("vtx_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
@@ -347,7 +348,7 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
|
||||
|
||||
TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
|
||||
// fn vtx_func() -> void { return; }
|
||||
auto* func = Func("vtx_func", ast::VariableList{}, ty.void_,
|
||||
auto* func = Func("vtx_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
|
||||
@@ -64,7 +64,7 @@ TEST_F(ValidatorTest, AssignToScalar_Fail) {
|
||||
// var my_var : i32 = 2;
|
||||
// 1 = my_var;
|
||||
|
||||
auto* var = Var("my_var", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("my_var", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* lhs = Expr(1);
|
||||
@@ -119,7 +119,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
|
||||
TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
|
||||
// var a :i32 = 2;
|
||||
// a = 2
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
@@ -140,7 +140,7 @@ TEST_F(ValidatorTest, AssignCompatibleTypesThroughAlias_Pass) {
|
||||
// alias myint = i32;
|
||||
// var a :myint = 2;
|
||||
// a = 2
|
||||
auto* myint = ty.alias("myint", ty.i32);
|
||||
auto* myint = ty.alias("myint", ty.i32());
|
||||
auto* var = Var("a", ast::StorageClass::kNone, myint, Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
@@ -162,9 +162,9 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInferRHSLoad_Pass) {
|
||||
// var a :i32 = 2;
|
||||
// var b :i32 = 3;
|
||||
// a = b;
|
||||
auto* var_a = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var_a = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var_b = Var("b", ast::StorageClass::kNone, ty.i32, Expr(3),
|
||||
auto* var_b = Var("b", ast::StorageClass::kNone, ty.i32(), Expr(3),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
@@ -187,7 +187,7 @@ TEST_F(ValidatorTest, AssignThroughPointer_Pass) {
|
||||
// const b : ptr<function,i32> = a;
|
||||
// b = 2;
|
||||
const auto func = ast::StorageClass::kFunction;
|
||||
auto* var_a = Var("a", func, ty.i32, Expr(2), {});
|
||||
auto* var_a = Var("a", func, ty.i32(), Expr(2), {});
|
||||
auto* var_b = Const("b", ast::StorageClass::kNone, ty.pointer<int>(func),
|
||||
Expr("a"), {});
|
||||
|
||||
@@ -213,7 +213,7 @@ TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
|
||||
// a = 2.3;
|
||||
// }
|
||||
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
@@ -241,7 +241,7 @@ TEST_F(ValidatorTest, AssignThroughPointerWrongeStoreType_Fail) {
|
||||
// const b : ptr<function,f32> = a;
|
||||
// b = 2;
|
||||
const auto priv = ast::StorageClass::kFunction;
|
||||
auto* var_a = Var("a", priv, ty.f32, Expr(2), {});
|
||||
auto* var_a = Var("a", priv, ty.f32(), Expr(2), {});
|
||||
auto* var_b = Const("b", ast::StorageClass::kNone, ty.pointer<float>(priv),
|
||||
Expr("a"), {});
|
||||
|
||||
@@ -269,7 +269,7 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
|
||||
// var a :i32 = 2;
|
||||
// a = 2
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
@@ -296,7 +296,7 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
|
||||
// a = 2.3;
|
||||
// }
|
||||
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
@@ -326,7 +326,7 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
|
||||
// var<in> gloabl_var: f32;
|
||||
mod->AST().AddGlobalVariable(Var(
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kInput,
|
||||
ty.f32, nullptr, ast::VariableDecorationList{}));
|
||||
ty.f32(), nullptr, ast::VariableDecorationList{}));
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -338,7 +338,7 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
||||
// var gloabl_var: f32;
|
||||
mod->AST().AddGlobalVariable(Var(
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kNone,
|
||||
ty.f32, nullptr, ast::VariableDecorationList{}));
|
||||
ty.f32(), nullptr, ast::VariableDecorationList{}));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
@@ -352,7 +352,7 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
||||
// const<in> gloabl_var: f32;
|
||||
mod->AST().AddGlobalVariable(Const(
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kInput,
|
||||
ty.f32, nullptr, ast::VariableDecorationList{}));
|
||||
ty.f32(), nullptr, ast::VariableDecorationList{}));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
@@ -367,7 +367,7 @@ TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
|
||||
// const gloabl_var: f32;
|
||||
mod->AST().AddGlobalVariable(Const(
|
||||
Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kNone,
|
||||
ty.f32, nullptr, ast::VariableDecorationList{}));
|
||||
ty.f32(), nullptr, ast::VariableDecorationList{}));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
@@ -381,14 +381,14 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
|
||||
// not_global_var = 3.14f;
|
||||
// }
|
||||
mod->AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
|
||||
ty.f32, Expr(2.1f),
|
||||
ty.f32(), Expr(2.1f),
|
||||
ast::VariableDecorationList{}));
|
||||
|
||||
SetSource(Source{Source::Location{12, 34}});
|
||||
auto* lhs = Expr("not_global_var");
|
||||
auto* rhs = Expr(3.14f);
|
||||
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.f32,
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, lhs, rhs),
|
||||
@@ -410,11 +410,11 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
||||
// }
|
||||
|
||||
mod->AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
|
||||
ty.f32, Expr(2.1f),
|
||||
ty.f32(), Expr(2.1f),
|
||||
ast::VariableDecorationList{}));
|
||||
|
||||
auto* func = Func(
|
||||
"my_func", ast::VariableList{}, ty.void_,
|
||||
"my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}},
|
||||
Expr("global_var"), Expr(3.14f)),
|
||||
@@ -437,7 +437,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
|
||||
// if (true) { var a : f32 = 2.0; }
|
||||
// a = 3.14;
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* cond = Expr(true);
|
||||
@@ -470,7 +470,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
|
||||
// var a : f32 = 2.0;
|
||||
// if (true) { a = 3.14; }
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
SetSource(Source{Source::Location{12, 34}});
|
||||
@@ -500,12 +500,12 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
|
||||
TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
||||
// var global_var0 : f32 = 0.1;
|
||||
// var global_var1 : i32 = 0;
|
||||
auto* var0 = Var("global_var0", ast::StorageClass::kPrivate, ty.f32,
|
||||
auto* var0 = Var("global_var0", ast::StorageClass::kPrivate, ty.f32(),
|
||||
Expr(0.1f), ast::VariableDecorationList{});
|
||||
mod->AST().AddGlobalVariable(var0);
|
||||
|
||||
auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var1",
|
||||
ast::StorageClass::kPrivate, ty.f32, Expr(0),
|
||||
ast::StorageClass::kPrivate, ty.f32(), Expr(0),
|
||||
ast::VariableDecorationList{});
|
||||
mod->AST().AddGlobalVariable(var1);
|
||||
|
||||
@@ -518,12 +518,12 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
||||
TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
|
||||
// var global_var : f32 = 0.1;
|
||||
// var global_var : i32 = 0;
|
||||
auto* var0 = Var("global_var", ast::StorageClass::kPrivate, ty.f32,
|
||||
auto* var0 = Var("global_var", ast::StorageClass::kPrivate, ty.f32(),
|
||||
Expr(0.1f), ast::VariableDecorationList{});
|
||||
mod->AST().AddGlobalVariable(var0);
|
||||
|
||||
auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kPrivate, ty.i32, Expr(0),
|
||||
ast::StorageClass::kPrivate, ty.i32(), Expr(0),
|
||||
ast::VariableDecorationList{});
|
||||
mod->AST().AddGlobalVariable(var1);
|
||||
|
||||
@@ -539,7 +539,7 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
|
||||
// const a :i32 = 2;
|
||||
// a = 2
|
||||
// }
|
||||
auto* var = Const("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Const("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* lhs = Expr("a");
|
||||
@@ -568,14 +568,14 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
auto* global_var = Var("a", ast::StorageClass::kPrivate, ty.f32, Expr(2.1f),
|
||||
auto* global_var = Var("a", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
|
||||
ast::VariableDecorationList{});
|
||||
mod->AST().AddGlobalVariable(global_var);
|
||||
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.void_,
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, var),
|
||||
@@ -598,13 +598,13 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
|
||||
// var a :i32 = 2;
|
||||
// var a :f21 = 2.0;
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* var_a_float = Var("a", ast::StorageClass::kNone, ty.f32, Expr(0.1f),
|
||||
auto* var_a_float = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(0.1f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.void_,
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::VariableDeclStatement>(
|
||||
@@ -628,7 +628,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
||||
// if (true) { var a : f32 = 2.0; }
|
||||
// var a : f32 = 3.14;
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* cond = Expr(true);
|
||||
@@ -636,7 +636,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
});
|
||||
|
||||
auto* var_a_float = Var("a", ast::StorageClass::kNone, ty.f32, Expr(3.1f),
|
||||
auto* var_a_float = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(3.1f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
@@ -659,10 +659,10 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
|
||||
// var a : f32 = 3.14;
|
||||
// if (true) { var a : f32 = 2.0; }
|
||||
// }
|
||||
auto* var_a_float = Var("a", ast::StorageClass::kNone, ty.f32, Expr(3.1f),
|
||||
auto* var_a_float = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(3.1f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* cond = Expr(true);
|
||||
@@ -686,13 +686,13 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
|
||||
TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
||||
// func0 { var a : f32 = 2.0; return; }
|
||||
// func1 { var a : f32 = 3.0; return; }
|
||||
auto* var0 = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f),
|
||||
auto* var0 = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* var1 = Var("a", ast::StorageClass::kNone, ty.void_, Expr(1.0f),
|
||||
auto* var1 = Var("a", ast::StorageClass::kNone, ty.void_(), Expr(1.0f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
auto* func0 = Func("func0", ast::VariableList{}, ty.void_,
|
||||
auto* func0 = Func("func0", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, var0),
|
||||
@@ -701,7 +701,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
auto* func1 =
|
||||
Func("func1", ast::VariableList{}, ty.void_,
|
||||
Func("func1", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{13, 34}}, var1),
|
||||
@@ -726,7 +726,7 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
|
||||
// var a :i32;
|
||||
// a = 2;
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32, nullptr,
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), nullptr,
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
td()->RegisterVariableForTesting(var);
|
||||
@@ -751,16 +751,16 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
|
||||
TEST_F(ValidatorTest, IsStorable_Void) {
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.IsStorable(ty.void_));
|
||||
EXPECT_FALSE(v.IsStorable(ty.void_()));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Scalar) {
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.IsStorable(ty.bool_));
|
||||
EXPECT_TRUE(v.IsStorable(ty.i32));
|
||||
EXPECT_TRUE(v.IsStorable(ty.u32));
|
||||
EXPECT_TRUE(v.IsStorable(ty.f32));
|
||||
EXPECT_TRUE(v.IsStorable(ty.bool_()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.i32()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.u32()));
|
||||
EXPECT_TRUE(v.IsStorable(ty.f32()));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Vector) {
|
||||
@@ -799,14 +799,14 @@ TEST_F(ValidatorTest, IsStorable_Pointer) {
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_AliasVoid) {
|
||||
auto* alias = ty.alias("myalias", ty.void_);
|
||||
auto* alias = ty.alias("myalias", ty.void_());
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.IsStorable(alias));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_AliasI32) {
|
||||
auto* alias = ty.alias("myalias", ty.i32);
|
||||
auto* alias = ty.alias("myalias", ty.i32());
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.IsStorable(alias));
|
||||
@@ -815,13 +815,13 @@ TEST_F(ValidatorTest, IsStorable_AliasI32) {
|
||||
TEST_F(ValidatorTest, IsStorable_ArraySizedOfStorable) {
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.IsStorable(ty.array(ty.i32, 5)));
|
||||
EXPECT_TRUE(v.IsStorable(ty.array(ty.i32(), 5)));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_ArraySizedOfNonStorable) {
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.IsStorable(ty.array(ty.void_, 5)));
|
||||
EXPECT_FALSE(v.IsStorable(ty.array(ty.void_(), 5)));
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_ArrayUnsizedOfStorable) {
|
||||
@@ -837,7 +837,7 @@ TEST_F(ValidatorTest, IsStorable_ArrayUnsizedOfNonStorable) {
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Struct_AllMembersStorable) {
|
||||
ast::StructMemberList members{Member("a", ty.i32), Member("b", ty.f32)};
|
||||
ast::StructMemberList members{Member("a", ty.i32()), Member("b", ty.f32())};
|
||||
auto* s = create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
|
||||
auto* s_ty = ty.struct_("mystruct", s);
|
||||
ValidatorImpl& v = Build();
|
||||
@@ -847,7 +847,7 @@ TEST_F(ValidatorTest, IsStorable_Struct_AllMembersStorable) {
|
||||
|
||||
TEST_F(ValidatorTest, IsStorable_Struct_SomeMembersNonStorable) {
|
||||
auto* ptr_ty = ty.pointer<int>(ast::StorageClass::kPrivate);
|
||||
ast::StructMemberList members{Member("a", ty.i32), Member("b", ptr_ty)};
|
||||
ast::StructMemberList members{Member("a", ty.i32()), Member("b", ptr_ty)};
|
||||
auto* s = create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
|
||||
auto* s_ty = ty.struct_("mystruct", s);
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -45,7 +45,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsLast_Pass) {
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(create<ast::StructBlockDecoration>());
|
||||
auto* st =
|
||||
create<ast::Struct>(ast::StructMemberList{Member("vf", ty.f32),
|
||||
create<ast::Struct>(ast::StructMemberList{Member("vf", ty.f32()),
|
||||
Member("rt", ty.array<f32>())},
|
||||
decos);
|
||||
|
||||
@@ -66,7 +66,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsLastNoBlock_Fail) {
|
||||
|
||||
ast::StructDecorationList decos;
|
||||
auto* st =
|
||||
create<ast::Struct>(ast::StructMemberList{Member("vf", ty.f32),
|
||||
create<ast::Struct>(ast::StructMemberList{Member("vf", ty.f32()),
|
||||
Member("rt", ty.array<f32>())},
|
||||
decos);
|
||||
|
||||
@@ -95,7 +95,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsNotLast_Fail) {
|
||||
auto* rt = Member("rt", ty.array<f32>());
|
||||
SetSource(Source{});
|
||||
auto* st = create<ast::Struct>(
|
||||
ast::StructMemberList{rt, Member("vf", ty.f32)}, decos);
|
||||
ast::StructMemberList{rt, Member("vf", ty.f32())}, decos);
|
||||
|
||||
auto* struct_type = ty.struct_("Foo", st);
|
||||
|
||||
@@ -122,7 +122,7 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsNotLast_Fail) {
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(create<ast::StructBlockDecoration>());
|
||||
auto* st = create<ast::Struct>(
|
||||
ast::StructMemberList{Member("b", alias), Member("a", ty.u32)}, decos);
|
||||
ast::StructMemberList{Member("b", alias), Member("a", ty.u32())}, decos);
|
||||
|
||||
auto* struct_type = ty.struct_("s", st);
|
||||
mod->AST().AddConstructedType(struct_type);
|
||||
@@ -148,7 +148,7 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsLast_Pass) {
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(create<ast::StructBlockDecoration>());
|
||||
auto* st = create<ast::Struct>(
|
||||
ast::StructMemberList{Member("a", ty.u32), Member("b", alias)}, decos);
|
||||
ast::StructMemberList{Member("a", ty.u32()), Member("b", alias)}, decos);
|
||||
|
||||
auto* struct_type = ty.struct_("s", st);
|
||||
mod->AST().AddConstructedType(struct_type);
|
||||
@@ -164,7 +164,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
|
||||
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.array<i32>());
|
||||
auto* func =
|
||||
Func("func", ast::VariableList{}, ty.void_,
|
||||
Func("func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Source{Source::Location{12, 34}}, var),
|
||||
@@ -192,7 +192,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
|
||||
Var(Source{Source::Location{12, 34}}, "a", ast::StorageClass::kNone,
|
||||
ty.array<i32>(), nullptr, ast::VariableDecorationList{});
|
||||
|
||||
auto* func = Func("func", ast::VariableList{param}, ty.void_,
|
||||
auto* func = Func("func", ast::VariableList{param}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
@@ -200,7 +200,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
|
||||
mod->AST().Functions().Add(func);
|
||||
|
||||
auto* main =
|
||||
Func("main", ast::VariableList{}, ty.void_,
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user