mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-09 21:47:47 +00:00
Add semantic::Variable::Type() and use it instead of ast::Variable::type()
In anticipation of adding support for type inference, no longer use ast::Variable::type() everywhere, as it will eventually return nullptr for type-inferred variables. Instead, the Resolver now stores the final resolved type into the semantic::Variable, and nearly all code now makes use of that. ast::Variable::type() has been renamed to ast::Variable::declared_type() to help make its usage clear, and to distinguish it from semantic::Variable::Type(). Fixed tests that failed after this change because variables were missing VariableDeclStatements, so there was no path to the variables during resolving, and thus no semantic info generated for them. Bug: tint:672 Change-Id: I0125e2f555839a4892248dc6739a72e9c7f51b1e Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46100 Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
d7f23f5c75
commit
9ef17472e8
@@ -125,7 +125,9 @@ std::string Function::type_name() const {
|
||||
|
||||
out << "__func" + return_type_->type_name();
|
||||
for (auto* param : params_) {
|
||||
out << param->type()->type_name();
|
||||
// No need for the semantic::Variable here, functions params must have a
|
||||
// type
|
||||
out << param->declared_type()->type_name();
|
||||
}
|
||||
|
||||
return out.str();
|
||||
|
||||
@@ -25,20 +25,20 @@ namespace ast {
|
||||
|
||||
Variable::Variable(const Source& source,
|
||||
const Symbol& sym,
|
||||
StorageClass sc,
|
||||
type::Type* type,
|
||||
StorageClass declared_storage_class,
|
||||
type::Type* declared_type,
|
||||
bool is_const,
|
||||
Expression* constructor,
|
||||
DecorationList decorations)
|
||||
: Base(source),
|
||||
symbol_(sym),
|
||||
type_(type),
|
||||
declared_type_(declared_type),
|
||||
is_const_(is_const),
|
||||
constructor_(constructor),
|
||||
decorations_(std::move(decorations)),
|
||||
declared_storage_class_(sc) {
|
||||
declared_storage_class_(declared_storage_class) {
|
||||
TINT_ASSERT(symbol_.IsValid());
|
||||
TINT_ASSERT(type_);
|
||||
TINT_ASSERT(declared_type_);
|
||||
}
|
||||
|
||||
Variable::Variable(Variable&&) = default;
|
||||
@@ -94,7 +94,7 @@ uint32_t Variable::constant_id() const {
|
||||
Variable* Variable::Clone(CloneContext* ctx) const {
|
||||
auto src = ctx->Clone(source());
|
||||
auto sym = ctx->Clone(symbol());
|
||||
auto* ty = ctx->Clone(type());
|
||||
auto* ty = ctx->Clone(declared_type());
|
||||
auto* ctor = ctx->Clone(constructor());
|
||||
auto decos = ctx->Clone(decorations());
|
||||
return ctx->dst->create<Variable>(src, sym, declared_storage_class(), ty,
|
||||
@@ -111,7 +111,7 @@ void Variable::info_to_str(const semantic::Info& sem,
|
||||
out << (var_sem ? var_sem->StorageClass() : declared_storage_class())
|
||||
<< std::endl;
|
||||
make_indent(out, indent);
|
||||
out << type_->type_name() << std::endl;
|
||||
out << declared_type_->type_name() << std::endl;
|
||||
}
|
||||
|
||||
void Variable::constructor_to_str(const semantic::Info& sem,
|
||||
|
||||
@@ -79,15 +79,15 @@ class Variable : public Castable<Variable, Node> {
|
||||
/// Create a variable
|
||||
/// @param source the variable source
|
||||
/// @param sym the variable symbol
|
||||
/// @param sc the declared storage class
|
||||
/// @param type the value type
|
||||
/// @param declared_storage_class the declared storage class
|
||||
/// @param declared_type the declared variable type
|
||||
/// @param is_const true if the variable is const
|
||||
/// @param constructor the constructor expression
|
||||
/// @param decorations the variable decorations
|
||||
Variable(const Source& source,
|
||||
const Symbol& sym,
|
||||
StorageClass sc,
|
||||
type::Type* type,
|
||||
StorageClass declared_storage_class,
|
||||
type::Type* declared_type,
|
||||
bool is_const,
|
||||
Expression* constructor,
|
||||
DecorationList decorations);
|
||||
@@ -99,8 +99,8 @@ class Variable : public Castable<Variable, Node> {
|
||||
/// @returns the variable symbol
|
||||
const Symbol& symbol() const { return symbol_; }
|
||||
|
||||
/// @returns the variable's type.
|
||||
type::Type* type() const { return type_; }
|
||||
/// @returns the declared type
|
||||
type::Type* declared_type() const { return declared_type_; }
|
||||
|
||||
/// @returns the declared storage class
|
||||
StorageClass declared_storage_class() const {
|
||||
@@ -166,7 +166,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
|
||||
Symbol const symbol_;
|
||||
// The value type if a const or formal paramter, and the store type if a var
|
||||
type::Type* const type_;
|
||||
type::Type* const declared_type_;
|
||||
bool const is_const_;
|
||||
Expression* const constructor_;
|
||||
DecorationList const decorations_;
|
||||
|
||||
@@ -27,7 +27,7 @@ TEST_F(VariableTest, Creation) {
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->declared_storage_class(), StorageClass::kFunction);
|
||||
EXPECT_EQ(v->type(), ty.i32());
|
||||
EXPECT_EQ(v->declared_type(), ty.i32());
|
||||
EXPECT_EQ(v->source().range.begin.line, 0u);
|
||||
EXPECT_EQ(v->source().range.begin.column, 0u);
|
||||
EXPECT_EQ(v->source().range.end.line, 0u);
|
||||
@@ -41,7 +41,7 @@ TEST_F(VariableTest, CreationWithSource) {
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->declared_storage_class(), StorageClass::kPrivate);
|
||||
EXPECT_EQ(v->type(), ty.f32());
|
||||
EXPECT_EQ(v->declared_type(), ty.f32());
|
||||
EXPECT_EQ(v->source().range.begin.line, 27u);
|
||||
EXPECT_EQ(v->source().range.begin.column, 4u);
|
||||
EXPECT_EQ(v->source().range.end.line, 27u);
|
||||
@@ -55,7 +55,7 @@ TEST_F(VariableTest, CreationEmpty) {
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->declared_storage_class(), StorageClass::kWorkgroup);
|
||||
EXPECT_EQ(v->type(), ty.i32());
|
||||
EXPECT_EQ(v->declared_type(), ty.i32());
|
||||
EXPECT_EQ(v->source().range.begin.line, 27u);
|
||||
EXPECT_EQ(v->source().range.begin.column, 4u);
|
||||
EXPECT_EQ(v->source().range.end.line, 27u);
|
||||
|
||||
Reference in New Issue
Block a user