mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 23:26:24 +00:00
ast::Builder: Add shortcuts to the Program methods
This builder will be merged into ProgramBuilder, where these will become methods. To breakup this change, perform the refactoring as a separate change. Bug: tint:390 Change-Id: I2c9151cd9f198e99d88eaf296dd994293df6c425 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38720 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -324,21 +324,20 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
|
||||
|
||||
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{}));
|
||||
AST().AddGlobalVariable(Var(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||
ast::VariableDecorationList{}));
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateGlobalVariables(mod->AST().GlobalVariables()))
|
||||
<< v.error();
|
||||
EXPECT_TRUE(v.ValidateGlobalVariables(AST().GlobalVariables())) << v.error();
|
||||
}
|
||||
|
||||
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{}));
|
||||
AST().AddGlobalVariable(Var(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kNone, ty.f32(), nullptr,
|
||||
ast::VariableDecorationList{}));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
@@ -350,9 +349,9 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
||||
|
||||
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{}));
|
||||
AST().AddGlobalVariable(Const(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||
ast::VariableDecorationList{}));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
@@ -365,9 +364,9 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
||||
|
||||
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{}));
|
||||
AST().AddGlobalVariable(Const(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kNone, ty.f32(), nullptr,
|
||||
ast::VariableDecorationList{}));
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
@@ -380,9 +379,9 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
|
||||
// fn my_func() -> f32 {
|
||||
// not_global_var = 3.14f;
|
||||
// }
|
||||
mod->AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
|
||||
ty.f32(), Expr(2.1f),
|
||||
ast::VariableDecorationList{}));
|
||||
AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
|
||||
ty.f32(), Expr(2.1f),
|
||||
ast::VariableDecorationList{}));
|
||||
|
||||
SetSource(Source{Source::Location{12, 34}});
|
||||
auto* lhs = Expr("not_global_var");
|
||||
@@ -394,7 +393,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
|
||||
Source{Source::Location{12, 34}}, lhs, rhs),
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
mod->AST().Functions().Add(func);
|
||||
AST().Functions().Add(func);
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
@@ -409,9 +408,9 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
mod->AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
|
||||
ty.f32(), Expr(2.1f),
|
||||
ast::VariableDecorationList{}));
|
||||
AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
|
||||
ty.f32(), Expr(2.1f),
|
||||
ast::VariableDecorationList{}));
|
||||
|
||||
auto* func = Func(
|
||||
"my_func", ast::VariableList{}, ty.void_(),
|
||||
@@ -423,7 +422,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
mod->AST().Functions().Add(func);
|
||||
AST().Functions().Add(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
@@ -502,17 +501,16 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
||||
// var global_var1 : i32 = 0;
|
||||
auto* var0 = Var("global_var0", ast::StorageClass::kPrivate, ty.f32(),
|
||||
Expr(0.1f), ast::VariableDecorationList{});
|
||||
mod->AST().AddGlobalVariable(var0);
|
||||
AST().AddGlobalVariable(var0);
|
||||
|
||||
auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var1",
|
||||
ast::StorageClass::kPrivate, ty.f32(), Expr(0),
|
||||
ast::VariableDecorationList{});
|
||||
mod->AST().AddGlobalVariable(var1);
|
||||
AST().AddGlobalVariable(var1);
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.ValidateGlobalVariables(mod->AST().GlobalVariables()))
|
||||
<< v.error();
|
||||
EXPECT_TRUE(v.ValidateGlobalVariables(AST().GlobalVariables())) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
|
||||
@@ -520,16 +518,16 @@ TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
|
||||
// var global_var : i32 = 0;
|
||||
auto* var0 = Var("global_var", ast::StorageClass::kPrivate, ty.f32(),
|
||||
Expr(0.1f), ast::VariableDecorationList{});
|
||||
mod->AST().AddGlobalVariable(var0);
|
||||
AST().AddGlobalVariable(var0);
|
||||
|
||||
auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var",
|
||||
ast::StorageClass::kPrivate, ty.i32(), Expr(0),
|
||||
ast::VariableDecorationList{});
|
||||
mod->AST().AddGlobalVariable(var1);
|
||||
AST().AddGlobalVariable(var1);
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_FALSE(v.ValidateGlobalVariables(mod->AST().GlobalVariables()));
|
||||
EXPECT_FALSE(v.ValidateGlobalVariables(AST().GlobalVariables()));
|
||||
EXPECT_EQ(v.error(),
|
||||
"12:34 v-0011: redeclared global identifier 'global_var'");
|
||||
}
|
||||
@@ -570,7 +568,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
|
||||
|
||||
auto* global_var = Var("a", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
|
||||
ast::VariableDecorationList{});
|
||||
mod->AST().AddGlobalVariable(global_var);
|
||||
AST().AddGlobalVariable(global_var);
|
||||
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
@@ -582,7 +580,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
mod->AST().Functions().Add(func);
|
||||
AST().Functions().Add(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error();
|
||||
@@ -612,7 +610,7 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
mod->AST().Functions().Add(func);
|
||||
AST().Functions().Add(func);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error();
|
||||
@@ -711,8 +709,8 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
mod->AST().Functions().Add(func0);
|
||||
mod->AST().Functions().Add(func1);
|
||||
AST().Functions().Add(func0);
|
||||
AST().Functions().Add(func1);
|
||||
|
||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user