sem: Add constructor field to sem::Variable

Produces a direct SEM -> SEM pointer, reducing AST <-> SEM hopping.

Change-Id: I233b4c47d4e55b5f2c6e14ed08699a302b8fb64d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/71321
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton
2021-12-03 11:42:43 +00:00
committed by Tint LUCI CQ
parent f71784fc2b
commit 8e39ffd512
3 changed files with 121 additions and 21 deletions

View File

@@ -72,6 +72,16 @@ class Variable : public Castable<Variable, Node> {
/// @return the constant value of this expression
const Constant& ConstantValue() const { return constant_value_; }
/// @returns the variable constructor expression, or nullptr if the variable
/// does not have one.
const Expression* Constructor() const { return constructor_; }
/// Sets the variable constructor expression.
/// @param constructor the constructor expression to assign to this variable.
void SetConstructor(const Expression* constructor) {
constructor_ = constructor;
}
/// @returns the expressions that use the variable
const std::vector<const VariableUser*>& Users() const { return users_; }
@@ -81,9 +91,10 @@ class Variable : public Castable<Variable, Node> {
private:
const ast::Variable* const declaration_;
const sem::Type* const type_;
ast::StorageClass const storage_class_;
ast::Access const access_;
const ast::StorageClass storage_class_;
const ast::Access access_;
const Constant constant_value_;
const Expression* constructor_ = nullptr;
std::vector<const VariableUser*> users_;
};