mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-12 22:56:09 +00:00
wgsl parser: replace almost all sem::Type* with typ::Type where possible
All that remains in the wgsl parser that references sem::Type* are the register_constructed funcs/types, and adding an ast::ExternalTexture type. Also: * Added specialization of OperatorArrow for type::TypePairs that returns the value by reference so that operator-> can chain properly. * In a few places where we expect the type to implicitly cast to a pointer for a bool expression, e.g. `if (type)` or `TINT_ASSERT(type)`, I added access to the `.sem` member of the TypePair. I tried adding an implicit cast to bool, but this results in ambiguity in gtest for equality comparisons. * Constified more type pointers in type nodes * Replaced header includes with forward declares in wgsl/parser_impl.h Bug: tint:724 Change-Id: Ie0875aa4d4a5e830e3466ac40c63cd185f357200 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48881 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
6e2ed30be3
commit
73fdc16c33
@@ -27,7 +27,7 @@ Function::Function(ProgramID program_id,
|
||||
const Source& source,
|
||||
Symbol symbol,
|
||||
VariableList params,
|
||||
sem::Type* return_type,
|
||||
typ::Type return_type,
|
||||
BlockStatement* body,
|
||||
DecorationList decorations,
|
||||
DecorationList return_type_decorations)
|
||||
@@ -45,7 +45,7 @@ Function::Function(ProgramID program_id,
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(param, program_id);
|
||||
}
|
||||
TINT_ASSERT(symbol_.IsValid());
|
||||
TINT_ASSERT(return_type_);
|
||||
TINT_ASSERT(return_type_.sem);
|
||||
for (auto* deco : decorations_) {
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(deco, program_id);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ Function* Function::Clone(CloneContext* ctx) const {
|
||||
auto src = ctx->Clone(source());
|
||||
auto sym = ctx->Clone(symbol());
|
||||
auto p = ctx->Clone(params_);
|
||||
auto* ret = ctx->Clone(return_type_);
|
||||
auto ret = ctx->Clone(return_type_);
|
||||
auto* b = ctx->Clone(body_);
|
||||
auto decos = ctx->Clone(decorations_);
|
||||
auto ret_decos = ctx->Clone(return_type_decorations_);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "src/ast/location_decoration.h"
|
||||
#include "src/ast/pipeline_stage.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/typepair.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -48,7 +49,7 @@ class Function : public Castable<Function, Node> {
|
||||
const Source& source,
|
||||
Symbol symbol,
|
||||
VariableList params,
|
||||
sem::Type* return_type,
|
||||
typ::Type return_type,
|
||||
BlockStatement* body,
|
||||
DecorationList decorations,
|
||||
DecorationList return_type_decorations);
|
||||
@@ -76,7 +77,7 @@ class Function : public Castable<Function, Node> {
|
||||
bool IsEntryPoint() const { return pipeline_stage() != PipelineStage::kNone; }
|
||||
|
||||
/// @returns the function return type.
|
||||
sem::Type* return_type() const { return return_type_; }
|
||||
typ::Type return_type() const { return return_type_; }
|
||||
|
||||
/// @returns the decorations attached to the function return type.
|
||||
const DecorationList& return_type_decorations() const {
|
||||
@@ -114,7 +115,7 @@ class Function : public Castable<Function, Node> {
|
||||
|
||||
Symbol const symbol_;
|
||||
VariableList const params_;
|
||||
sem::Type* const return_type_;
|
||||
typ::Type const return_type_;
|
||||
BlockStatement* const body_;
|
||||
DecorationList const decorations_;
|
||||
DecorationList const return_type_decorations_;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ast {
|
||||
|
||||
Pointer::Pointer(ProgramID program_id,
|
||||
const Source& source,
|
||||
Type* subtype,
|
||||
Type* const subtype,
|
||||
ast::StorageClass storage_class)
|
||||
: Base(program_id, source),
|
||||
subtype_(subtype),
|
||||
|
||||
@@ -33,14 +33,14 @@ class Pointer : public Castable<Pointer, Type> {
|
||||
/// @param storage_class the storage class of the pointer
|
||||
Pointer(ProgramID program_id,
|
||||
const Source& source,
|
||||
Type* subtype,
|
||||
Type* const subtype,
|
||||
ast::StorageClass storage_class);
|
||||
/// Move constructor
|
||||
Pointer(Pointer&&);
|
||||
~Pointer() override;
|
||||
|
||||
/// @returns the pointee type
|
||||
Type* type() const { return subtype_; }
|
||||
Type* type() const { return const_cast<Type*>(subtype_); }
|
||||
/// @returns the storage class of the pointer
|
||||
ast::StorageClass storage_class() const { return storage_class_; }
|
||||
|
||||
@@ -58,7 +58,7 @@ class Pointer : public Castable<Pointer, Type> {
|
||||
Pointer* Clone(CloneContext* ctx) const override;
|
||||
|
||||
private:
|
||||
Type* const subtype_;
|
||||
Type const* const subtype_;
|
||||
ast::StorageClass const storage_class_;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace ast {
|
||||
SampledTexture::SampledTexture(ProgramID program_id,
|
||||
const Source& source,
|
||||
TextureDimension dim,
|
||||
Type* type)
|
||||
Type const* type)
|
||||
: Base(program_id, source, dim), type_(type) {
|
||||
TINT_ASSERT(type_);
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ class SampledTexture : public Castable<SampledTexture, Texture> {
|
||||
SampledTexture(ProgramID program_id,
|
||||
const Source& source,
|
||||
TextureDimension dim,
|
||||
Type* type);
|
||||
Type const* type);
|
||||
/// Move constructor
|
||||
SampledTexture(SampledTexture&&);
|
||||
~SampledTexture() override;
|
||||
|
||||
/// @returns the subtype of the sampled texture
|
||||
Type* type() const { return type_; }
|
||||
Type* type() const { return const_cast<Type*>(type_); }
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
@@ -55,7 +55,7 @@ class SampledTexture : public Castable<SampledTexture, Texture> {
|
||||
SampledTexture* Clone(CloneContext* ctx) const override;
|
||||
|
||||
private:
|
||||
Type* const type_;
|
||||
Type const* const type_;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
|
||||
@@ -27,13 +27,13 @@ Variable::Variable(ProgramID program_id,
|
||||
const Source& source,
|
||||
const Symbol& sym,
|
||||
StorageClass declared_storage_class,
|
||||
const sem::Type* declared_type,
|
||||
const typ::Type type,
|
||||
bool is_const,
|
||||
Expression* constructor,
|
||||
DecorationList decorations)
|
||||
: Base(program_id, source),
|
||||
symbol_(sym),
|
||||
declared_type_(declared_type),
|
||||
type_(type),
|
||||
is_const_(is_const),
|
||||
constructor_(constructor),
|
||||
decorations_(std::move(decorations)),
|
||||
@@ -41,7 +41,7 @@ Variable::Variable(ProgramID program_id,
|
||||
TINT_ASSERT(symbol_.IsValid());
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id);
|
||||
// no type means we must have a constructor to infer it
|
||||
TINT_ASSERT(declared_type_ || constructor);
|
||||
TINT_ASSERT(type_.sem || constructor);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(constructor, program_id);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,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(declared_type());
|
||||
auto ty = ctx->Clone(type());
|
||||
auto* ctor = ctx->Clone(constructor());
|
||||
auto decos = ctx->Clone(decorations());
|
||||
return ctx->dst->create<Variable>(src, sym, declared_storage_class(), ty,
|
||||
@@ -90,8 +90,8 @@ void Variable::info_to_str(const sem::Info& sem,
|
||||
out << (var_sem ? var_sem->StorageClass() : declared_storage_class())
|
||||
<< std::endl;
|
||||
make_indent(out, indent);
|
||||
if (declared_type_) {
|
||||
out << declared_type_->type_name() << std::endl;
|
||||
if (type_.sem) {
|
||||
out << type_->type_name() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
/// @param source the variable source
|
||||
/// @param sym the variable symbol
|
||||
/// @param declared_storage_class the declared storage class
|
||||
/// @param declared_type the declared variable type
|
||||
/// @param type the declared variable type
|
||||
/// @param is_const true if the variable is const
|
||||
/// @param constructor the constructor expression
|
||||
/// @param decorations the variable decorations
|
||||
@@ -103,7 +103,7 @@ class Variable : public Castable<Variable, Node> {
|
||||
const Source& source,
|
||||
const Symbol& sym,
|
||||
StorageClass declared_storage_class,
|
||||
const sem::Type* declared_type,
|
||||
typ::Type type,
|
||||
bool is_const,
|
||||
Expression* constructor,
|
||||
DecorationList decorations);
|
||||
@@ -116,9 +116,11 @@ class Variable : public Castable<Variable, Node> {
|
||||
const Symbol& symbol() const { return symbol_; }
|
||||
|
||||
/// @returns the declared type
|
||||
sem::Type* declared_type() const {
|
||||
return const_cast<sem::Type*>(declared_type_);
|
||||
}
|
||||
// TODO(crbug.com/tint/697): Remove and use type() instead
|
||||
sem::Type* declared_type() const { return const_cast<sem::Type*>(type_.sem); }
|
||||
|
||||
/// @returns the variable type
|
||||
typ::Type type() const { return type_; }
|
||||
|
||||
/// @returns the declared storage class
|
||||
StorageClass declared_storage_class() const {
|
||||
@@ -177,7 +179,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
|
||||
const sem::Type* const declared_type_;
|
||||
typ::Type const type_;
|
||||
bool const is_const_;
|
||||
Expression* const constructor_;
|
||||
DecorationList const decorations_;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ast {
|
||||
|
||||
Vector::Vector(ProgramID program_id,
|
||||
const Source& source,
|
||||
Type* subtype,
|
||||
Type const* subtype,
|
||||
uint32_t size)
|
||||
: Base(program_id, source), subtype_(subtype), size_(size) {
|
||||
TINT_ASSERT(size_ > 1);
|
||||
|
||||
@@ -32,14 +32,14 @@ class Vector : public Castable<Vector, Type> {
|
||||
/// @param size the number of elements in the vector
|
||||
Vector(ProgramID program_id,
|
||||
const Source& source,
|
||||
Type* subtype,
|
||||
Type const* subtype,
|
||||
uint32_t size);
|
||||
/// Move constructor
|
||||
Vector(Vector&&);
|
||||
~Vector() override;
|
||||
|
||||
/// @returns the type of the vector elements
|
||||
Type* type() const { return subtype_; }
|
||||
Type* type() const { return const_cast<Type*>(subtype_); }
|
||||
/// @returns the size of the vector
|
||||
uint32_t size() const { return size_; }
|
||||
|
||||
@@ -57,7 +57,7 @@ class Vector : public Castable<Vector, Type> {
|
||||
Vector* Clone(CloneContext* ctx) const override;
|
||||
|
||||
private:
|
||||
Type* const subtype_;
|
||||
Type const* const subtype_;
|
||||
uint32_t const size_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user