mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 09:25:25 +00:00
[semantic] Add semantic::Variable::Users()
Returns a list of ast::IdentifierExpression* nodes that reference the variable. Change-Id: I36f475c6ddf5482f9ae9b432190405625f379f0d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41661 Commit-Queue: James Price <jrprice@google.com> Auto-Submit: James Price <jrprice@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
45b18ce064
commit
c9af597997
@@ -26,9 +26,12 @@ namespace semantic {
|
||||
class Call : public Castable<Call, Expression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param declaration the AST node
|
||||
/// @param target the call target
|
||||
/// @param statement the statement that owns this expression
|
||||
explicit Call(const CallTarget* target, Statement* statement);
|
||||
explicit Call(ast::Expression* declaration,
|
||||
const CallTarget* target,
|
||||
Statement* statement);
|
||||
|
||||
/// Destructor
|
||||
~Call() override;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#ifndef SRC_SEMANTIC_EXPRESSION_H_
|
||||
#define SRC_SEMANTIC_EXPRESSION_H_
|
||||
|
||||
#include "src/ast/expression.h"
|
||||
#include "src/semantic/node.h"
|
||||
|
||||
namespace tint {
|
||||
@@ -33,9 +34,12 @@ namespace semantic {
|
||||
class Expression : public Castable<Expression, Node> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param declaration the AST node
|
||||
/// @param type the resolved type of the expression
|
||||
/// @param statement the statement that owns this expression
|
||||
explicit Expression(type::Type* type, Statement* statement);
|
||||
explicit Expression(ast::Expression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement);
|
||||
|
||||
/// @return the resolved type of the expression
|
||||
type::Type* Type() const { return type_; }
|
||||
@@ -43,7 +47,11 @@ class Expression : public Castable<Expression, Node> {
|
||||
/// @return the statement that owns this expression
|
||||
Statement* Stmt() const { return statement_; }
|
||||
|
||||
/// @returns the AST node
|
||||
ast::Expression* Declaration() const { return declaration_; }
|
||||
|
||||
private:
|
||||
ast::Expression* declaration_;
|
||||
type::Type* const type_;
|
||||
Statement* const statement_;
|
||||
};
|
||||
|
||||
@@ -26,10 +26,12 @@ class MemberAccessorExpression
|
||||
: public Castable<MemberAccessorExpression, Expression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param declaration the AST node
|
||||
/// @param type the resolved type of the expression
|
||||
/// @param statement the statement that owns this expression
|
||||
/// @param is_swizzle true if this member access is for a vector swizzle
|
||||
MemberAccessorExpression(type::Type* type,
|
||||
MemberAccessorExpression(ast::Expression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement,
|
||||
bool is_swizzle);
|
||||
|
||||
|
||||
@@ -19,8 +19,10 @@ TINT_INSTANTIATE_CLASS_ID(tint::semantic::Call);
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
Call::Call(const CallTarget* target, Statement* statement)
|
||||
: Base(target->ReturnType(), statement), target_(target) {}
|
||||
Call::Call(ast::Expression* declaration,
|
||||
const CallTarget* target,
|
||||
Statement* statement)
|
||||
: Base(declaration, target->ReturnType(), statement), target_(target) {}
|
||||
|
||||
Call::~Call() = default;
|
||||
|
||||
|
||||
@@ -21,8 +21,12 @@ TINT_INSTANTIATE_CLASS_ID(tint::semantic::Expression);
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
Expression::Expression(type::Type* type, Statement* statement)
|
||||
: type_(type->UnwrapIfNeeded()), statement_(statement) {}
|
||||
Expression::Expression(ast::Expression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement)
|
||||
: declaration_(declaration),
|
||||
type_(type->UnwrapIfNeeded()),
|
||||
statement_(statement) {}
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
|
||||
@@ -19,10 +19,11 @@ TINT_INSTANTIATE_CLASS_ID(tint::semantic::MemberAccessorExpression);
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
MemberAccessorExpression::MemberAccessorExpression(type::Type* type,
|
||||
MemberAccessorExpression::MemberAccessorExpression(ast::Expression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement,
|
||||
bool is_swizzle)
|
||||
: Base(type, statement), is_swizzle_(is_swizzle) {}
|
||||
: Base(declaration, type, statement), is_swizzle_(is_swizzle) {}
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
|
||||
@@ -19,8 +19,12 @@ TINT_INSTANTIATE_CLASS_ID(tint::semantic::Variable);
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
Variable::Variable(ast::Variable* declaration, ast::StorageClass storage_class)
|
||||
: declaration_(declaration), storage_class_(storage_class) {}
|
||||
Variable::Variable(ast::Variable* declaration,
|
||||
ast::StorageClass storage_class,
|
||||
std::vector<const Expression*> users)
|
||||
: declaration_(declaration),
|
||||
storage_class_(storage_class),
|
||||
users_(std::move(users)) {}
|
||||
|
||||
Variable::~Variable() = default;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "src/ast/storage_class.h"
|
||||
#include "src/semantic/expression.h"
|
||||
#include "src/semantic/node.h"
|
||||
#include "src/type/sampler_type.h"
|
||||
|
||||
@@ -40,8 +41,10 @@ class Variable : public Castable<Variable, Node> {
|
||||
/// Constructor
|
||||
/// @param declaration the AST declaration node
|
||||
/// @param storage_class the variable storage class
|
||||
/// @param users the expressions that use the variable
|
||||
explicit Variable(ast::Variable* declaration,
|
||||
ast::StorageClass storage_class);
|
||||
ast::StorageClass storage_class,
|
||||
std::vector<const Expression*> users);
|
||||
|
||||
/// Destructor
|
||||
~Variable() override;
|
||||
@@ -52,9 +55,13 @@ class Variable : public Castable<Variable, Node> {
|
||||
/// @returns the storage class for the variable
|
||||
ast::StorageClass StorageClass() const { return storage_class_; }
|
||||
|
||||
/// @returns the expressions that use the variable
|
||||
const std::vector<const Expression*>& Users() const { return users_; }
|
||||
|
||||
private:
|
||||
ast::Variable* const declaration_;
|
||||
ast::StorageClass const storage_class_;
|
||||
std::vector<const Expression*> const users_;
|
||||
};
|
||||
|
||||
} // namespace semantic
|
||||
|
||||
Reference in New Issue
Block a user