writer/msl: Fix all tests that had unreachable AST nodes

By making nodes reachable, the resolver has now caught a whole lot of additional problems, which have been fixed in this CL.

Some of these broken tests were attempting to use private and workgroup variables as function-scope declarations.
This is not legal, and these have been moved to module-scope variables.

Bug: tint:469
Change-Id: I1fc3a10fa0e39e1c290a13323277d6e9257778c4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48048
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton
2021-04-19 16:52:42 +00:00
committed by Commit Bot service account
parent 917b14b626
commit b8ea59149e
20 changed files with 174 additions and 212 deletions

View File

@@ -594,6 +594,10 @@ class ProgramBuilder {
return expr;
}
/// Passthrough for nullptr
/// @return nullptr
ast::IdentifierExpression* Expr(std::nullptr_t) { return nullptr; }
/// @param name the identifier name
/// @return an ast::IdentifierExpression with the given name
ast::IdentifierExpression* Expr(const std::string& name) {
@@ -606,6 +610,12 @@ class ProgramBuilder {
return create<ast::IdentifierExpression>(symbol);
}
/// @param variable the AST variable
/// @return an ast::IdentifierExpression with the variable's symbol
ast::IdentifierExpression* Expr(ast::Variable* variable) {
return create<ast::IdentifierExpression>(variable->symbol());
}
/// @param source the source information
/// @param name the identifier name
/// @return an ast::IdentifierExpression with the given name
@@ -1252,9 +1262,10 @@ class ProgramBuilder {
/// @param condition the else condition expression
/// @param body the else body
/// @returns the else statement pointer
ast::ElseStatement* Else(ast::Expression* condition,
ast::BlockStatement* body) {
return create<ast::ElseStatement>(condition, body);
template <typename CONDITION>
ast::ElseStatement* Else(CONDITION&& condition, ast::BlockStatement* body) {
return create<ast::ElseStatement>(Expr(std::forward<CONDITION>(condition)),
body);
}
/// Creates a ast::IfStatement with input condition, body, and optional
@@ -1263,14 +1274,14 @@ class ProgramBuilder {
/// @param body the if statement body
/// @param elseStatements optional variadic else statements
/// @returns the if statement pointer
template <typename... ElseStatements>
ast::IfStatement* If(ast::Expression* condition,
template <typename CONDITION, typename... ELSE_STATEMENTS>
ast::IfStatement* If(CONDITION&& condition,
ast::BlockStatement* body,
ElseStatements&&... elseStatements) {
ELSE_STATEMENTS&&... elseStatements) {
return create<ast::IfStatement>(
condition, body,
Expr(std::forward<CONDITION>(condition)), body,
ast::ElseStatementList{
std::forward<ElseStatements>(elseStatements)...});
std::forward<ELSE_STATEMENTS>(elseStatements)...});
}
/// Creates a ast::AssignmentStatement with input lhs and rhs expressions