resolver: Implement Behavior Analysis

This change implements the behavior analysis for expressions and
statements as described in:
https://www.w3.org/TR/WGSL/#behaviors

This CL makes no changes to the validation rules. This will be done as a
followup change.

Bug: tint:1302
Change-Id: If0a251a7982ea15ff5d93b54a5cc5ed03ba60608
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68408
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2021-12-03 15:49:34 +00:00
committed by Tint LUCI CQ
parent bf39c8fb19
commit 3298625760
10 changed files with 940 additions and 60 deletions

View File

@@ -68,7 +68,7 @@ class Expression : public Castable<Expression, Node> {
const sem::Type* const type_;
const Statement* const statement_;
const Constant constant_;
sem::Behaviors behaviors_;
sem::Behaviors behaviors_{sem::Behavior::kNext};
};
} // namespace sem

View File

@@ -240,6 +240,12 @@ class Function : public Castable<Function, CallTarget> {
/// @returns true if this function has a discard statement
bool HasDiscard() const { return has_discard_; }
/// @return the behaviors of this function
const sem::Behaviors& Behaviors() const { return behaviors_; }
/// @return the behaviors of this function
sem::Behaviors& Behaviors() { return behaviors_; }
private:
VariableBindings TransitivelyReferencedSamplerVariablesImpl(
ast::SamplerKind kind) const;
@@ -257,6 +263,7 @@ class Function : public Castable<Function, CallTarget> {
std::vector<const Call*> callsites_;
std::vector<const Function*> ancestor_entry_points_;
bool has_discard_ = false;
sem::Behaviors behaviors_{sem::Behavior::kNext};
};
} // namespace sem

View File

@@ -110,8 +110,7 @@ class Statement : public Castable<Statement, Node> {
const ast::Statement* const declaration_;
const CompoundStatement* const parent_;
const sem::Function* const function_;
sem::Behaviors behaviors_;
sem::Behaviors behaviors_{sem::Behavior::kNext};
};
/// CompoundStatement is the base class of statements that can hold other