mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
Add semantic::Variable, use it.
Pull the mutable semantic field from ast::Variable and into a new semantic::Variable node. Have the TypeDeterminer create these semantic::Variable nodes. Bug: tint:390 Change-Id: Ia13f5e7b065941ed66ea5a86c6ccb288071feff3 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40063 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
401b96b9bb
commit
b17aea159c
@@ -19,6 +19,7 @@
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
#include "src/clone_context.h"
|
||||
#include "src/program_builder.h"
|
||||
#include "src/semantic/variable.h"
|
||||
|
||||
TINT_INSTANTIATE_CLASS_ID(tint::ast::Variable);
|
||||
|
||||
@@ -38,7 +39,7 @@ Variable::Variable(const Source& source,
|
||||
is_const_(is_const),
|
||||
constructor_(constructor),
|
||||
decorations_(std::move(decorations)),
|
||||
storage_class_(sc) {}
|
||||
declared_storage_class_(sc) {}
|
||||
|
||||
Variable::Variable(Variable&&) = default;
|
||||
|
||||
@@ -91,10 +92,10 @@ uint32_t Variable::constant_id() const {
|
||||
}
|
||||
|
||||
Variable* Variable::Clone(CloneContext* ctx) const {
|
||||
return ctx->dst->create<Variable>(ctx->Clone(source()), ctx->Clone(symbol_),
|
||||
storage_class(), ctx->Clone(type()),
|
||||
is_const_, ctx->Clone(constructor()),
|
||||
ctx->Clone(decorations_));
|
||||
return ctx->dst->create<Variable>(
|
||||
ctx->Clone(source()), ctx->Clone(symbol_), declared_storage_class(),
|
||||
ctx->Clone(type()), is_const_, ctx->Clone(constructor()),
|
||||
ctx->Clone(decorations_));
|
||||
}
|
||||
|
||||
bool Variable::IsValid() const {
|
||||
@@ -110,13 +111,15 @@ bool Variable::IsValid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Variable::info_to_str(const semantic::Info&,
|
||||
void Variable::info_to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
auto* var_sem = sem.Get(this);
|
||||
make_indent(out, indent);
|
||||
out << symbol_.to_str() << std::endl;
|
||||
make_indent(out, indent);
|
||||
out << storage_class_ << std::endl;
|
||||
out << (var_sem ? var_sem->StorageClass() : declared_storage_class())
|
||||
<< std::endl;
|
||||
make_indent(out, indent);
|
||||
out << type_->type_name() << std::endl;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
/// Create a variable
|
||||
/// @param source the variable source
|
||||
/// @param sym the variable symbol
|
||||
/// @param sc the variable storage class
|
||||
/// @param sc the declared storage class
|
||||
/// @param type the value type
|
||||
/// @param is_const true if the variable is const
|
||||
/// @param constructor the constructor expression
|
||||
@@ -107,12 +107,10 @@ class Variable : public Castable<Variable, Node> {
|
||||
/// @returns the variable's type.
|
||||
type::Type* type() const { return type_; }
|
||||
|
||||
/// Sets the storage class
|
||||
/// @param sc the storage class
|
||||
void set_storage_class(StorageClass sc) { storage_class_ = sc; }
|
||||
/// @returns the storage class
|
||||
StorageClass storage_class() const { return storage_class_; }
|
||||
|
||||
/// @returns the declared storage class
|
||||
StorageClass declared_storage_class() const {
|
||||
return declared_storage_class_;
|
||||
}
|
||||
/// @returns the constructor expression or nullptr if none set
|
||||
Expression* constructor() const { return constructor_; }
|
||||
/// @returns true if the variable has an constructor
|
||||
@@ -126,7 +124,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
|
||||
/// @returns true if the decorations include a LocationDecoration
|
||||
bool HasLocationDecoration() const;
|
||||
/// @returns true if the deocrations include a BuiltinDecoration
|
||||
/// @returns true if the decorations include a BuiltinDecoration
|
||||
bool HasBuiltinDecoration() const;
|
||||
/// @returns true if the decorations include a ConstantIdDecoration
|
||||
bool HasConstantIdDecoration() const;
|
||||
@@ -182,8 +180,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
bool const is_const_;
|
||||
Expression* const constructor_;
|
||||
VariableDecorationList const decorations_;
|
||||
|
||||
StorageClass storage_class_ = StorageClass::kNone; // Semantic info
|
||||
StorageClass const declared_storage_class_;
|
||||
};
|
||||
|
||||
/// A list of variables
|
||||
|
||||
@@ -30,7 +30,7 @@ TEST_F(VariableTest, Creation) {
|
||||
auto* v = Var("my_var", StorageClass::kFunction, ty.i32());
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->storage_class(), StorageClass::kFunction);
|
||||
EXPECT_EQ(v->declared_storage_class(), StorageClass::kFunction);
|
||||
EXPECT_EQ(v->type(), ty.i32());
|
||||
EXPECT_EQ(v->source().range.begin.line, 0u);
|
||||
EXPECT_EQ(v->source().range.begin.column, 0u);
|
||||
@@ -44,7 +44,7 @@ TEST_F(VariableTest, CreationWithSource) {
|
||||
"i", StorageClass::kPrivate, ty.f32(), nullptr, VariableDecorationList{});
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->storage_class(), StorageClass::kPrivate);
|
||||
EXPECT_EQ(v->declared_storage_class(), StorageClass::kPrivate);
|
||||
EXPECT_EQ(v->type(), ty.f32());
|
||||
EXPECT_EQ(v->source().range.begin.line, 27u);
|
||||
EXPECT_EQ(v->source().range.begin.column, 4u);
|
||||
@@ -59,7 +59,7 @@ TEST_F(VariableTest, CreationEmpty) {
|
||||
VariableDecorationList{});
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->storage_class(), StorageClass::kWorkgroup);
|
||||
EXPECT_EQ(v->declared_storage_class(), StorageClass::kWorkgroup);
|
||||
EXPECT_EQ(v->type(), ty.i32());
|
||||
EXPECT_EQ(v->source().range.begin.line, 27u);
|
||||
EXPECT_EQ(v->source().range.begin.column, 4u);
|
||||
|
||||
Reference in New Issue
Block a user