Add a symbol to the Function AST node.

This Cl adds a Symbol representing the function name to the function
AST. The symbol is added alongside the name for now. When all usages of
the function name are removed then the string version will be removed
from the constructor.

Change-Id: Ib2450e5fe531e988b25bb7d2937acc6af2187871
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35220
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair
2020-12-11 18:24:53 +00:00
committed by Commit Bot service account
parent cd9e5f6e91
commit a41132fcd8
48 changed files with 923 additions and 658 deletions

View File

@@ -54,7 +54,8 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, "func", params, &void_type, body,
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
params, &void_type, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
});
@@ -71,8 +72,8 @@ TEST_F(ValidateFunctionTest,
ast::type::Void void_type;
ast::VariableList params;
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, "func", params, &void_type,
create<ast::BlockStatement>(),
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
params, &void_type, create<ast::BlockStatement>(),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
});
@@ -100,9 +101,9 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "func", params,
&i32, body, ast::FunctionDecorationList{});
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
params, &i32, body, ast::FunctionDecorationList{});
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@@ -117,8 +118,9 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
ast::type::I32 i32;
ast::VariableList params;
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, "func", params, &i32,
create<ast::BlockStatement>(), ast::FunctionDecorationList{});
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
params, &i32, create<ast::BlockStatement>(),
ast::FunctionDecorationList{});
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@@ -136,7 +138,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, "func", params, &void_type, body,
Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
});
@@ -157,7 +159,8 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
return_expr));
auto* func = create<ast::Function>(Source{}, "func", params, &void_type, body,
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"),
"func", params, &void_type, body,
ast::FunctionDecorationList{});
mod()->AddFunction(func);
@@ -180,8 +183,9 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
return_expr));
auto* func = create<ast::Function>(Source{}, "func", params, &f32, body,
ast::FunctionDecorationList{});
auto* func =
create<ast::Function>(Source{}, mod()->RegisterSymbol("func"), "func",
params, &f32, body, ast::FunctionDecorationList{});
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@@ -204,8 +208,9 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
create<ast::SintLiteral>(&i32, 2));
body->append(create<ast::ReturnStatement>(Source{}, return_expr));
auto* func = create<ast::Function>(Source{}, "func", params, &i32, body,
ast::FunctionDecorationList{});
auto* func =
create<ast::Function>(Source{}, mod()->RegisterSymbol("func"), "func",
params, &i32, body, ast::FunctionDecorationList{});
ast::VariableList params_copy;
auto* body_copy = create<ast::BlockStatement>();
@@ -213,9 +218,9 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
create<ast::SintLiteral>(&i32, 2));
body_copy->append(create<ast::ReturnStatement>(Source{}, return_expr_copy));
auto* func_copy = create<ast::Function>(Source{Source::Location{12, 34}},
"func", params_copy, &i32, body_copy,
ast::FunctionDecorationList{});
auto* func_copy = create<ast::Function>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func",
params_copy, &i32, body_copy, ast::FunctionDecorationList{});
mod()->AddFunction(func);
mod()->AddFunction(func_copy);
@@ -237,7 +242,8 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::CallStatement>(call_expr));
body0->append(create<ast::ReturnStatement>(Source{}));
auto* func0 = create<ast::Function>(Source{}, "func", params0, &f32, body0,
auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"),
"func", params0, &f32, body0,
ast::FunctionDecorationList{});
mod()->AddFunction(func0);
@@ -268,7 +274,8 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
create<ast::SintLiteral>(&i32, 2));
body0->append(create<ast::ReturnStatement>(Source{}, return_expr));
auto* func0 = create<ast::Function>(Source{}, "func", params0, &i32, body0,
auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"),
"func", params0, &i32, body0,
ast::FunctionDecorationList{});
mod()->AddFunction(func0);
@@ -288,7 +295,8 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}, return_expr));
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, "vtx_main", params, &i32, body,
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_main"),
"vtx_main", params, &i32, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
});
@@ -317,7 +325,8 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, "vtx_func", params, &void_type, body,
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_func"),
"vtx_func", params, &void_type, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
});
@@ -339,7 +348,8 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, "main", params, &void_type, body,
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("main"), "main",
params, &void_type, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}),
@@ -361,7 +371,8 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, "vtx_func", params, &void_type, body,
Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params,
&void_type, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
});
@@ -377,8 +388,9 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(Source{}, "vtx_func", params, &void_type,
body, ast::FunctionDecorationList{});
auto* func = create<ast::Function>(
Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params,
&void_type, body, ast::FunctionDecorationList{});
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();

View File

@@ -332,7 +332,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs));
auto* func = create<ast::Function>(Source{}, "my_func", params, &f32, body,
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
"my_func", params, &f32, body,
ast::FunctionDecorationList{});
mod()->AddFunction(func);
@@ -370,7 +371,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
Source{Source::Location{12, 34}}, lhs, rhs));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, "my_func", params, &void_type, body,
Source{}, mod()->RegisterSymbol("my_func"), "my_func", params, &void_type,
body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
});
@@ -587,8 +589,9 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var));
auto* func = create<ast::Function>(Source{}, "my_func", params, &void_type,
body, ast::FunctionDecorationList{});
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
"my_func", params, &void_type, body,
ast::FunctionDecorationList{});
mod()->AddFunction(func);
@@ -631,8 +634,9 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var_a_float));
auto* func = create<ast::Function>(Source{}, "my_func", params, &void_type,
body, ast::FunctionDecorationList{});
auto* func = create<ast::Function>(Source{}, mod()->RegisterSymbol("my_func"),
"my_func", params, &void_type, body,
ast::FunctionDecorationList{});
mod()->AddFunction(func);
@@ -759,8 +763,9 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
body0->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var0));
body0->append(create<ast::ReturnStatement>(Source{}));
auto* func0 = create<ast::Function>(Source{}, "func0", params0, &void_type,
body0, ast::FunctionDecorationList{});
auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func0"),
"func0", params0, &void_type, body0,
ast::FunctionDecorationList{});
ast::VariableList params1;
auto* body1 = create<ast::BlockStatement>();
@@ -768,7 +773,8 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
Source{Source::Location{13, 34}}, var1));
body1->append(create<ast::ReturnStatement>(Source{}));
auto* func1 = create<ast::Function>(
Source{}, "func1", params1, &void_type, body1,
Source{}, mod()->RegisterSymbol("func1"), "func1", params1, &void_type,
body1,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
});

View File

@@ -206,8 +206,9 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var));
auto* func = create<ast::Function>(
Source{}, "func", params, &void_type, body,
Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}),
});