mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 09:25:25 +00:00
Add semantic::VariableUser
Derives from semantic::Expression. Maps to ast::IdentifierExpressions that resolve to a variable. Breaks pure-immutability of semantic::Variable, as we have discussed in the past. Change-Id: I362d4d1ed61291282a60626b84fb15566655fb14 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46627 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
e93d46fcbc
commit
86c2cbfb7e
@@ -37,9 +37,9 @@ class Expression : public Castable<Expression, Node> {
|
||||
/// @param declaration the AST node
|
||||
/// @param type the resolved type of the expression
|
||||
/// @param statement the statement that owns this expression
|
||||
explicit Expression(ast::Expression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement);
|
||||
Expression(ast::Expression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement);
|
||||
|
||||
/// @return the resolved type of the expression
|
||||
type::Type* Type() const { return type_; }
|
||||
|
||||
@@ -14,21 +14,26 @@
|
||||
|
||||
#include "src/semantic/variable.h"
|
||||
|
||||
#include "src/ast/identifier_expression.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::semantic::Variable);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::semantic::VariableUser);
|
||||
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
Variable::Variable(const ast::Variable* declaration,
|
||||
type::Type* type,
|
||||
ast::StorageClass storage_class,
|
||||
std::vector<const Expression*> users)
|
||||
: declaration_(declaration),
|
||||
type_(type),
|
||||
storage_class_(storage_class),
|
||||
users_(std::move(users)) {}
|
||||
ast::StorageClass storage_class)
|
||||
: declaration_(declaration), type_(type), storage_class_(storage_class) {}
|
||||
|
||||
Variable::~Variable() = default;
|
||||
|
||||
VariableUser::VariableUser(ast::IdentifierExpression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement,
|
||||
semantic::Variable* variable)
|
||||
: Base(declaration, type, statement), variable_(variable) {}
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace semantic {
|
||||
class StructMember;
|
||||
|
||||
/// A vector of StructMember pointers.
|
||||
using StructMemberList = std::vector<StructMember*>;
|
||||
using StructMemberList = std::vector<const StructMember*>;
|
||||
|
||||
/// Metadata to capture how a structure is used in a shader module.
|
||||
enum class PipelineStageUsage {
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace tint {
|
||||
|
||||
// Forward declarations
|
||||
namespace ast {
|
||||
class IdentifierExpression;
|
||||
class Variable;
|
||||
} // namespace ast
|
||||
namespace type {
|
||||
@@ -32,6 +33,8 @@ class Type;
|
||||
|
||||
namespace semantic {
|
||||
|
||||
class VariableUser;
|
||||
|
||||
/// Variable holds the semantic information for variables.
|
||||
class Variable : public Castable<Variable, Node> {
|
||||
public:
|
||||
@@ -39,11 +42,9 @@ class Variable : public Castable<Variable, Node> {
|
||||
/// @param declaration the AST declaration node
|
||||
/// @param type the variable type
|
||||
/// @param storage_class the variable storage class
|
||||
/// @param users the expressions that use the variable
|
||||
explicit Variable(const ast::Variable* declaration,
|
||||
type::Type* type,
|
||||
ast::StorageClass storage_class,
|
||||
std::vector<const Expression*> users);
|
||||
Variable(const ast::Variable* declaration,
|
||||
type::Type* type,
|
||||
ast::StorageClass storage_class);
|
||||
|
||||
/// Destructor
|
||||
~Variable() override;
|
||||
@@ -58,13 +59,37 @@ class Variable : public Castable<Variable, Node> {
|
||||
ast::StorageClass StorageClass() const { return storage_class_; }
|
||||
|
||||
/// @returns the expressions that use the variable
|
||||
const std::vector<const Expression*>& Users() const { return users_; }
|
||||
const std::vector<const VariableUser*>& Users() const { return users_; }
|
||||
|
||||
/// @param user the user to add
|
||||
void AddUser(const VariableUser* user) { users_.emplace_back(user); }
|
||||
|
||||
private:
|
||||
const ast::Variable* const declaration_;
|
||||
type::Type* const type_;
|
||||
ast::StorageClass const storage_class_;
|
||||
std::vector<const Expression*> const users_;
|
||||
std::vector<const VariableUser*> users_;
|
||||
};
|
||||
|
||||
/// VariableUser holds the semantic information for an identifier expression
|
||||
/// node that resolves to a variable.
|
||||
class VariableUser : public Castable<VariableUser, Expression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param declaration the AST identifier node
|
||||
/// @param type the resolved type of the expression
|
||||
/// @param statement the statement that owns this expression
|
||||
/// @param variable the semantic variable
|
||||
VariableUser(ast::IdentifierExpression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement,
|
||||
semantic::Variable* variable);
|
||||
|
||||
/// @returns the variable that this expression refers to
|
||||
const semantic::Variable* Variable() const { return variable_; }
|
||||
|
||||
private:
|
||||
semantic::Variable const* const variable_;
|
||||
};
|
||||
|
||||
} // namespace semantic
|
||||
|
||||
Reference in New Issue
Block a user