TD: validate continue statements bypassing body variables

We now keep track of scopes as a tree of BlockInfos that track variables
declared in each scope. For loop scopes, we store the index of the first
variable (if any) that follows the first continue statement. Using this
data structure, when parsing expressions, we validate that used
variables in continuing blocks are not bypassed by a continue statement
in the parent loop block.

Also:
* Validate that continue statements are in a loop in TD. This error is
already caught by the spir-v writer, but better to catch it here.
* Add more utility functions to ProgramBuilder to make it easier to
write tests

Fixed: tint:17
Change-Id: I967bf2cfb63062bac8dcca113d074ba0fe2152e2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44120
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Antonio Maiorano
2021-03-09 10:26:57 +00:00
committed by Commit Bot service account
parent b78251fdcd
commit fd31bbd3f1
5 changed files with 409 additions and 10 deletions

View File

@@ -35,6 +35,9 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
BlockStatement(BlockStatement&&);
~BlockStatement() override;
/// @returns the StatementList
const StatementList& list() const { return statements_; }
/// @returns true if the block is empty
bool empty() const { return statements_.empty(); }
/// @returns the number of statements directly in the block