Remove name fields

This CL removes the name fields from the various AST nodes now that the
symbols are used everywhere.

Change-Id: I73e8fa8958aa6e6f0159b12b63176b12c418f525
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36762
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2021-01-11 16:24:32 +00:00 committed by dan sinclair
parent e65e4bd2c5
commit c8c31560de
23 changed files with 117 additions and 171 deletions

View File

@ -40,8 +40,8 @@ Variable* Builder::Var(const std::string& name,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations) {
auto* var = create<Variable>(mod->RegisterSymbol(name), name, storage, type,
false, constructor, decorations);
auto* var = create<Variable>(mod->RegisterSymbol(name), storage, type, false,
constructor, decorations);
OnVariableBuilt(var);
return var;
}
@ -52,8 +52,8 @@ Variable* Builder::Var(const Source& source,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations) {
auto* var = create<Variable>(source, mod->RegisterSymbol(name), name, storage,
type, false, constructor, decorations);
auto* var = create<Variable>(source, mod->RegisterSymbol(name), storage, type,
false, constructor, decorations);
OnVariableBuilt(var);
return var;
}
@ -69,8 +69,8 @@ Variable* Builder::Const(const std::string& name,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations) {
auto* var = create<Variable>(mod->RegisterSymbol(name), name, storage, type,
true, constructor, decorations);
auto* var = create<Variable>(mod->RegisterSymbol(name), storage, type, true,
constructor, decorations);
OnVariableBuilt(var);
return var;
}
@ -81,8 +81,8 @@ Variable* Builder::Const(const Source& source,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations) {
auto* var = create<Variable>(source, mod->RegisterSymbol(name), name, storage,
type, true, constructor, decorations);
auto* var = create<Variable>(source, mod->RegisterSymbol(name), storage, type,
true, constructor, decorations);
OnVariableBuilt(var);
return var;
}

View File

@ -166,7 +166,7 @@ class TypesBuilder {
/// @param type the alias type
/// @returns the alias pointer
type::Alias* alias(const std::string& name, type::Type* type) const {
return mod_->create<type::Alias>(mod_->RegisterSymbol(name), name, type);
return mod_->create<type::Alias>(mod_->RegisterSymbol(name), type);
}
/// @return the tint AST pointer to type `T` with the given StorageClass.
@ -180,7 +180,7 @@ class TypesBuilder {
/// @param impl the struct implementation
/// @returns a struct pointer
type::Struct* struct_(const std::string& name, ast::Struct* impl) const {
return mod_->create<type::Struct>(mod_->RegisterSymbol(name), name, impl);
return mod_->create<type::Struct>(mod_->RegisterSymbol(name), impl);
}
private:
@ -227,21 +227,20 @@ class Builder {
/// @param name the identifier name
/// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const std::string& name) {
return create<IdentifierExpression>(mod->RegisterSymbol(name), name);
return create<IdentifierExpression>(mod->RegisterSymbol(name));
}
/// @param source the source information
/// @param name the identifier name
/// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const Source& source, const std::string& name) {
return create<IdentifierExpression>(source, mod->RegisterSymbol(name),
name);
return create<IdentifierExpression>(source, mod->RegisterSymbol(name));
}
/// @param name the identifier name
/// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const char* name) {
return create<IdentifierExpression>(mod->RegisterSymbol(name), name);
return create<IdentifierExpression>(mod->RegisterSymbol(name));
}
/// @param value the boolean value
@ -620,9 +619,9 @@ class Builder {
type::Type* type,
ast::StatementList body,
ast::FunctionDecorationList decorations) {
return mod->create<ast::Function>(
source, mod->RegisterSymbol(name), name, params, type,
create<ast::BlockStatement>(body), decorations);
return mod->create<ast::Function>(source, mod->RegisterSymbol(name), params,
type, create<ast::BlockStatement>(body),
decorations);
}
/// Creates a Function
@ -637,7 +636,7 @@ class Builder {
type::Type* type,
ast::StatementList body,
ast::FunctionDecorationList decorations) {
return create<ast::Function>(mod->RegisterSymbol(name), name, params, type,
return create<ast::Function>(mod->RegisterSymbol(name), params, type,
create<ast::BlockStatement>(body),
decorations);
}
@ -650,8 +649,8 @@ class Builder {
StructMember* Member(const Source& source,
const std::string& name,
type::Type* type) {
return mod->create<StructMember>(source, mod->RegisterSymbol(name), name,
type, StructMemberDecorationList{});
return mod->create<StructMember>(source, mod->RegisterSymbol(name), type,
StructMemberDecorationList{});
}
/// Creates a StructMember
@ -659,8 +658,8 @@ class Builder {
/// @param type the struct member type
/// @returns the struct member pointer
StructMember* Member(const std::string& name, type::Type* type) {
return mod->create<StructMember>(source_, mod->RegisterSymbol(name), name,
type, StructMemberDecorationList{});
return mod->create<StructMember>(source_, mod->RegisterSymbol(name), type,
StructMemberDecorationList{});
}
/// Creates a StructMember
@ -671,8 +670,8 @@ class Builder {
StructMember* Member(const std::string& name,
type::Type* type,
StructMemberDecorationList decos) {
return mod->create<StructMember>(source_, mod->RegisterSymbol(name), name,
type, decos);
return mod->create<StructMember>(source_, mod->RegisterSymbol(name), type,
decos);
}
/// Creates a new Node owned by the Module, with the explicit Source.

View File

@ -32,14 +32,12 @@ namespace ast {
Function::Function(const Source& source,
Symbol symbol,
const std::string& name,
VariableList params,
type::Type* return_type,
BlockStatement* body,
FunctionDecorationList decorations)
: Base(source),
symbol_(symbol),
name_(name),
params_(std::move(params)),
return_type_(return_type),
body_(body),
@ -228,7 +226,7 @@ const Statement* Function::get_last_statement() const {
Function* Function::Clone(CloneContext* ctx) const {
return ctx->mod->create<Function>(
ctx->Clone(source()), ctx->Clone(symbol()), name_, ctx->Clone(params_),
ctx->Clone(source()), ctx->Clone(symbol()), ctx->Clone(params_),
ctx->Clone(return_type_), ctx->Clone(body_), ctx->Clone(decorations_));
}
@ -240,7 +238,7 @@ bool Function::IsValid() const {
if (body_ == nullptr || !body_->IsValid()) {
return false;
}
if (name_.length() == 0 || !symbol_.IsValid()) {
if (!symbol_.IsValid()) {
return false;
}
if (return_type_ == nullptr) {

View File

@ -54,14 +54,12 @@ class Function : public Castable<Function, Node> {
/// Create a function
/// @param source the variable source
/// @param symbol the function symbol
/// @param name the function name
/// @param params the function parameters
/// @param return_type the return type
/// @param body the function body
/// @param decorations the function decorations
Function(const Source& source,
Symbol symbol,
const std::string& name,
VariableList params,
type::Type* return_type,
BlockStatement* body,
@ -73,8 +71,6 @@ class Function : public Castable<Function, Node> {
/// @returns the function symbol
Symbol symbol() const { return symbol_; }
/// @returns the function name
const std::string& name_for_clone() { return name_; }
/// @returns the function params
const VariableList& params() const { return params_; }
@ -184,7 +180,7 @@ class Function : public Castable<Function, Node> {
/// @return the newly cloned node
Function* Clone(CloneContext* ctx) const override;
/// @returns true if the name and type are both present
/// @returns true if the symbol and type are both present
bool IsValid() const override;
/// Writes a representation of the node to the output stream
@ -203,7 +199,6 @@ class Function : public Castable<Function, Node> {
ReferencedSampledTextureVariablesImpl(bool multisampled) const;
Symbol const symbol_;
std::string const name_;
VariableList const params_;
type::Type* const return_type_;
BlockStatement* const body_;

View File

@ -22,10 +22,8 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::IdentifierExpression);
namespace tint {
namespace ast {
IdentifierExpression::IdentifierExpression(const Source& source,
Symbol sym,
const std::string& name)
: Base(source), sym_(sym), name_(name) {}
IdentifierExpression::IdentifierExpression(const Source& source, Symbol sym)
: Base(source), sym_(sym) {}
IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
@ -33,7 +31,7 @@ IdentifierExpression::~IdentifierExpression() = default;
IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const {
return ctx->mod->create<IdentifierExpression>(ctx->Clone(source()),
ctx->Clone(symbol()), name_);
ctx->Clone(symbol()));
}
bool IdentifierExpression::IsValid() const {

View File

@ -16,7 +16,6 @@
#define SRC_AST_IDENTIFIER_EXPRESSION_H_
#include <memory>
#include <string>
#include <utility>
#include "src/ast/expression.h"
@ -32,10 +31,7 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
/// Constructor
/// @param source the source
/// @param sym the symbol for the identifier
/// @param name the name
IdentifierExpression(const Source& source,
Symbol sym,
const std::string& name);
IdentifierExpression(const Source& source, Symbol sym);
/// Move constructor
IdentifierExpression(IdentifierExpression&&);
~IdentifierExpression() override;
@ -82,7 +78,6 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
IdentifierExpression(const IdentifierExpression&) = delete;
Symbol const sym_;
std::string const name_;
Intrinsic intrinsic_ = Intrinsic::kNone; // Semantic info
std::unique_ptr<intrinsic::Signature> intrinsic_sig_; // Semantic info

View File

@ -25,12 +25,10 @@ namespace ast {
StructMember::StructMember(const Source& source,
const Symbol& sym,
const std::string& name,
type::Type* type,
StructMemberDecorationList decorations)
: Base(source),
symbol_(sym),
name_(name),
type_(type),
decorations_(std::move(decorations)) {}
@ -57,13 +55,13 @@ uint32_t StructMember::offset() const {
}
StructMember* StructMember::Clone(CloneContext* ctx) const {
return ctx->mod->create<StructMember>(
ctx->Clone(source()), ctx->Clone(symbol_), name_, ctx->Clone(type_),
return ctx->mod->create<StructMember>(ctx->Clone(source()),
ctx->Clone(symbol_), ctx->Clone(type_),
ctx->Clone(decorations_));
}
bool StructMember::IsValid() const {
if (name_.empty() || type_ == nullptr || !symbol_.IsValid()) {
if (type_ == nullptr || !symbol_.IsValid()) {
return false;
}
for (auto* deco : decorations_) {

View File

@ -17,7 +17,6 @@
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
@ -35,12 +34,10 @@ class StructMember : public Castable<StructMember, Node> {
/// Create a new struct member statement
/// @param source The input source for the struct member statement
/// @param sym The struct member symbol
/// @param name The struct member name
/// @param type The struct member type
/// @param decorations The struct member decorations
StructMember(const Source& source,
const Symbol& sym,
const std::string& name,
type::Type* type,
StructMemberDecorationList decorations);
/// Move constructor
@ -81,7 +78,6 @@ class StructMember : public Castable<StructMember, Node> {
StructMember(const StructMember&) = delete;
Symbol const symbol_;
std::string const name_;
type::Type* const type_;
StructMemberDecorationList const decorations_;
};

View File

@ -25,8 +25,8 @@ namespace tint {
namespace ast {
namespace type {
Alias::Alias(const Symbol& sym, const std::string& name, Type* subtype)
: symbol_(sym), name_(name), subtype_(subtype) {
Alias::Alias(const Symbol& sym, Type* subtype)
: symbol_(sym), subtype_(subtype) {
assert(subtype_);
}
@ -47,8 +47,7 @@ uint64_t Alias::BaseAlignment(MemoryLayout mem_layout) const {
}
Alias* Alias::Clone(CloneContext* ctx) const {
return ctx->mod->create<Alias>(ctx->Clone(symbol()), name_,
ctx->Clone(subtype_));
return ctx->mod->create<Alias>(ctx->Clone(symbol()), ctx->Clone(subtype_));
}
} // namespace type

View File

@ -29,9 +29,8 @@ class Alias : public Castable<Alias, Type> {
public:
/// Constructor
/// @param sym the symbol for the alias
/// @param name the alias name
/// @param subtype the alias'd type
Alias(const Symbol& sym, const std::string& name, Type* subtype);
Alias(const Symbol& sym, Type* subtype);
/// Move constructor
Alias(Alias&&);
/// Destructor
@ -42,7 +41,7 @@ class Alias : public Castable<Alias, Type> {
/// @returns the alias type
Type* type() const { return subtype_; }
/// @returns the name for this type
/// @returns the type_name for this type
std::string type_name() const override;
/// @param mem_layout type of memory layout to use in calculation.
@ -62,7 +61,6 @@ class Alias : public Castable<Alias, Type> {
private:
Symbol const symbol_;
std::string const name_;
Type* const subtype_;
};

View File

@ -30,8 +30,8 @@ namespace tint {
namespace ast {
namespace type {
Struct::Struct(const Symbol& sym, const std::string& name, ast::Struct* impl)
: symbol_(sym), name_(name), struct_(impl) {}
Struct::Struct(const Symbol& sym, ast::Struct* impl)
: symbol_(sym), struct_(impl) {}
Struct::Struct(Struct&&) = default;
@ -84,8 +84,7 @@ uint64_t Struct::BaseAlignment(MemoryLayout mem_layout) const {
}
Struct* Struct::Clone(CloneContext* ctx) const {
return ctx->mod->create<Struct>(ctx->Clone(symbol()), name_,
ctx->Clone(struct_));
return ctx->mod->create<Struct>(ctx->Clone(symbol()), ctx->Clone(struct_));
}
} // namespace type

View File

@ -31,9 +31,8 @@ class Struct : public Castable<Struct, Type> {
public:
/// Constructor
/// @param sym the symbol representing the struct
/// @param name the name of the struct
/// @param impl the struct data
Struct(const Symbol& sym, const std::string& name, ast::Struct* impl);
Struct(const Symbol& sym, ast::Struct* impl);
/// Move constructor
Struct(Struct&&);
~Struct() override;
@ -44,7 +43,7 @@ class Struct : public Castable<Struct, Type> {
/// @returns true if the struct has a block decoration
bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); }
/// @returns the struct name
/// @returns the struct
ast::Struct* impl() const { return struct_; }
/// @returns the name for the type
@ -67,7 +66,6 @@ class Struct : public Castable<Struct, Type> {
private:
Symbol const symbol_;
std::string const name_;
ast::Struct* const struct_;
uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const;

View File

@ -27,7 +27,6 @@ namespace ast {
Variable::Variable(const Source& source,
const Symbol& sym,
const std::string& name,
StorageClass sc,
type::Type* type,
bool is_const,
@ -35,7 +34,6 @@ Variable::Variable(const Source& source,
VariableDecorationList decorations)
: Base(source),
symbol_(sym),
name_(name),
type_(type),
is_const_(is_const),
constructor_(constructor),
@ -85,13 +83,13 @@ uint32_t Variable::constant_id() const {
Variable* Variable::Clone(CloneContext* ctx) const {
return ctx->mod->create<Variable>(ctx->Clone(source()), ctx->Clone(symbol_),
name_, storage_class(), ctx->Clone(type()),
storage_class(), ctx->Clone(type()),
is_const_, ctx->Clone(constructor()),
ctx->Clone(decorations_));
}
bool Variable::IsValid() const {
if (name_.length() == 0 || !symbol_.IsValid()) {
if (!symbol_.IsValid()) {
return false;
}
if (type_ == nullptr) {

View File

@ -17,7 +17,6 @@
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
@ -83,7 +82,6 @@ class Variable : public Castable<Variable, Node> {
/// Create a variable
/// @param source the variable source
/// @param sym the variable symbol
/// @param name the variables name
/// @param sc the variable storage class
/// @param type the value type
/// @param is_const true if the variable is const
@ -91,7 +89,6 @@ class Variable : public Castable<Variable, Node> {
/// @param decorations the variable decorations
Variable(const Source& source,
const Symbol& sym,
const std::string& name,
StorageClass sc,
type::Type* type,
bool is_const,
@ -166,7 +163,6 @@ class Variable : public Castable<Variable, Node> {
Variable(const Variable&) = delete;
Symbol const symbol_;
std::string const name_;
// The value type if a const or formal paramter, and the store type if a var
type::Type* const type_;
bool const is_const_;

View File

@ -787,7 +787,7 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
const auto& top = statements_stack_.back();
auto* cond = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(guard_name), guard_name);
Source{}, ast_module_.RegisterSymbol(guard_name));
auto* builder = AddStatementBuilder<IfStatementBuilder>(cond);
PushNewStatementBlock(
@ -862,8 +862,8 @@ bool FunctionEmitter::Emit() {
auto* body = create<ast::BlockStatement>(Source{}, statements);
ast_module_.AddFunction(
create<ast::Function>(decl.source, ast_module_.RegisterSymbol(decl.name),
decl.name, std::move(decl.params), decl.return_type,
body, std::move(decl.decorations)));
std::move(decl.params), decl.return_type, body,
std::move(decl.decorations)));
// Maintain the invariant by repopulating the one and only element.
statements_stack_.clear();
@ -2013,8 +2013,8 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
auto name = namer_.Name(id);
return TypedExpression{
parser_impl_.ConvertType(def_use_mgr_->GetDef(id)->type_id()),
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name)};
create<ast::IdentifierExpression>(Source{},
ast_module_.RegisterSymbol(name))};
}
if (singly_used_values_.count(id)) {
auto expr = std::move(singly_used_values_[id]);
@ -2034,10 +2034,9 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
case SpvOpVariable: {
// This occurs for module-scope variables.
auto name = namer_.Name(inst->result_id());
return TypedExpression{
parser_impl_.ConvertType(inst->type_id()),
return TypedExpression{parser_impl_.ConvertType(inst->type_id()),
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name)};
Source{}, ast_module_.RegisterSymbol(name))};
}
default:
break;
@ -2269,7 +2268,6 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
auto* guard_var =
create<ast::Variable>(Source{}, // source
ast_module_.RegisterSymbol(guard_name), // symbol
guard_name, // name
ast::StorageClass::kFunction, // storage_class
parser_impl_.Bool(), // type
false, // is_const
@ -2676,7 +2674,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
return create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(flow_guard), flow_guard),
Source{}, ast_module_.RegisterSymbol(flow_guard)),
MakeFalse(Source{}));
}
@ -2798,7 +2796,6 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
auto* var = create<ast::Variable>(
Source{}, // source
ast_module_.RegisterSymbol(phi_var_name), // symbol
phi_var_name, // name
ast::StorageClass::kFunction, // storage_class
parser_impl_.ConvertType(def_inst->type_id()), // type
false, // is_const
@ -2837,7 +2834,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
AddStatement(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(var_name), var_name),
Source{}, ast_module_.RegisterSymbol(var_name)),
expr.expr));
}
}
@ -2874,8 +2871,8 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
// Emit an assignment of the expression to the hoisted variable.
AddStatement(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), namer_.Name(result_id)),
create<ast::IdentifierExpression>(Source{},
ast_module_.RegisterSymbol(name)),
ast_expr.expr));
return true;
}
@ -3014,8 +3011,7 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
TypedExpression expr{
parser_impl_.ConvertType(inst.type_id()),
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(def_info->phi_var),
def_info->phi_var)};
Source{}, ast_module_.RegisterSymbol(def_info->phi_var))};
return EmitConstDefOrWriteToHoistedVar(inst, expr);
}
@ -3074,8 +3070,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(unary_builtin_name),
unary_builtin_name),
Source{}, ast_module_.RegisterSymbol(unary_builtin_name)),
std::move(params))};
}
@ -3181,7 +3176,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(
}
auto* func = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name);
Source{}, ast_module_.RegisterSymbol(name));
ast::ExpressionList operands;
ast::type::Type* first_operand_type = nullptr;
// All parameters to GLSL.std.450 extended instructions are IDs.
@ -3207,20 +3202,20 @@ ast::IdentifierExpression* FunctionEmitter::Swizzle(uint32_t i) {
}
const char* names[] = {"x", "y", "z", "w"};
return create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(names[i & 3]), names[i & 3]);
Source{}, ast_module_.RegisterSymbol(names[i & 3]));
}
ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) {
switch (n) {
case 1:
return create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol("x"), "x");
return create<ast::IdentifierExpression>(Source{},
ast_module_.RegisterSymbol("x"));
case 2:
return create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol("xy"), "xy");
Source{}, ast_module_.RegisterSymbol("xy"));
case 3:
return create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol("xyz"), "xyz");
Source{}, ast_module_.RegisterSymbol("xyz"));
default:
break;
}
@ -3315,7 +3310,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto name = namer_.Name(base_id);
current_expr.expr = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name);
Source{}, ast_module_.RegisterSymbol(name));
current_expr.type = parser_impl_.ConvertType(ptr_ty_id);
}
}
@ -3408,7 +3403,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto name =
namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val));
auto* member_access = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name);
Source{}, ast_module_.RegisterSymbol(name));
next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, member_access);
@ -3529,7 +3524,7 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
}
auto name = namer_.GetMemberName(current_type_id, uint32_t(index_val));
auto* member_access = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name);
Source{}, ast_module_.RegisterSymbol(name));
next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, member_access);
@ -3933,7 +3928,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
// We ignore function attributes such as Inline, DontInline, Pure, Const.
auto name = namer_.Name(inst.GetSingleWordInOperand(0));
auto* function = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name);
Source{}, ast_module_.RegisterSymbol(name));
ast::ExpressionList params;
for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) {
@ -3962,7 +3957,7 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall(
ss << intrinsic;
auto name = ss.str();
auto* ident = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name);
Source{}, ast_module_.RegisterSymbol(name));
ident->set_intrinsic(intrinsic);
ast::ExpressionList params;
@ -4009,7 +4004,7 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol("select"), "select"),
Source{}, ast_module_.RegisterSymbol("select")),
std::move(params))};
}
return {};
@ -4035,7 +4030,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
}
auto name = namer_.Name(image->result_id());
params.push_back(create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name));
Source{}, ast_module_.RegisterSymbol(name)));
const auto opcode = inst.opcode();
if (IsSampledImageAccess(opcode)) {
@ -4048,7 +4043,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
}
auto param_name = namer_.Name(sampler->result_id());
params.push_back(create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(param_name), param_name));
Source{}, ast_module_.RegisterSymbol(param_name)));
}
ast::type::Pointer* texture_ptr_type =
@ -4214,7 +4209,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
}
auto* ident = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(builtin_name), builtin_name);
Source{}, ast_module_.RegisterSymbol(builtin_name));
auto* call_expr =
create<ast::CallExpression>(Source{}, ident, std::move(params));
@ -4556,14 +4551,14 @@ TypedExpression FunctionEmitter::MakeArrayLength(
}
auto* member_ident = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(field_name), field_name);
Source{}, ast_module_.RegisterSymbol(field_name));
auto* member_access = create<ast::MemberAccessorExpression>(
Source{}, MakeExpression(struct_ptr_id).expr, member_ident);
// Generate the intrinsic function call.
std::string call_ident_str = "arrayLength";
auto* call_ident = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(call_ident_str), call_ident_str);
Source{}, ast_module_.RegisterSymbol(call_ident_str));
call_ident->set_intrinsic(ast::Intrinsic::kArrayLength);
ast::ExpressionList params{member_access};

View File

@ -948,8 +948,8 @@ ast::type::Type* ParserImpl::ConvertType(
}
const auto member_name = namer_.GetMemberName(type_id, member_index);
auto* ast_struct_member = create<ast::StructMember>(
Source{}, ast_module_.RegisterSymbol(member_name), member_name,
ast_member_ty, std::move(ast_member_decorations));
Source{}, ast_module_.RegisterSymbol(member_name), ast_member_ty,
std::move(ast_member_decorations));
ast_members.push_back(ast_struct_member);
}
if (is_per_vertex_struct) {
@ -965,7 +965,7 @@ ast::type::Type* ParserImpl::ConvertType(
auto name = namer_.GetName(type_id);
auto* result = ast_module_.create<ast::type::Struct>(
ast_module_.RegisterSymbol(name), name, ast_struct);
ast_module_.RegisterSymbol(name), ast_struct);
id_to_type_[type_id] = result;
if (num_non_writable_members == members.size()) {
read_only_struct_types_.insert(result);
@ -1132,7 +1132,7 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id,
}
const auto name = namer_.GetName(type_id);
auto* ast_alias_type = ast_module_.create<ast::type::Alias>(
ast_module_.RegisterSymbol(name), name, ast_underlying_type);
ast_module_.RegisterSymbol(name), ast_underlying_type);
// Record this new alias as the AST type for this SPIR-V ID.
id_to_type_[type_id] = ast_alias_type;
ast_module_.AddConstructedType(ast_alias_type);
@ -1311,7 +1311,6 @@ ast::Variable* ParserImpl::MakeVariable(
std::string name = namer_.Name(id);
return create<ast::Variable>(Source{}, // source
ast_module_.RegisterSymbol(name), // symbol
name, // name
sc, // storage_class
type, // type
is_const, // is_const

View File

@ -434,7 +434,6 @@ Maybe<ast::Variable*> ParserImpl::global_variable_decl(
return create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
decl->storage_class, // storage_class
decl->type, // type
false, // is_const
@ -463,7 +462,6 @@ Maybe<ast::Variable*> ParserImpl::global_constant_decl() {
return create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
ast::StorageClass::kNone, // storage_class
decl->type, // type
true, // is_const
@ -941,7 +939,7 @@ Maybe<ast::type::Type*> ParserImpl::type_alias() {
return add_error(peek(), "invalid type alias");
auto* alias = module_.create<ast::type::Alias>(
module_.RegisterSymbol(name.value), name.value, type.value);
module_.RegisterSymbol(name.value), type.value);
register_constructed(name.value, alias);
return alias;
@ -1195,7 +1193,7 @@ Maybe<std::unique_ptr<ast::type::Struct>> ParserImpl::struct_decl(
return Failure::kErrored;
return std::make_unique<ast::type::Struct>(
module_.RegisterSymbol(name.value), name.value,
module_.RegisterSymbol(name.value),
create<ast::Struct>(source, std::move(body.value),
std::move(struct_decos.value)));
}
@ -1249,9 +1247,9 @@ Expect<ast::StructMember*> ParserImpl::expect_struct_member(
if (!expect("struct member", Token::Type::kSemicolon))
return Failure::kErrored;
return create<ast::StructMember>(
decl->source, module_.RegisterSymbol(decl->name), decl->name, decl->type,
std::move(member_decos.value));
return create<ast::StructMember>(decl->source,
module_.RegisterSymbol(decl->name),
decl->type, std::move(member_decos.value));
}
// function_decl
@ -1287,8 +1285,8 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
return Failure::kErrored;
return create<ast::Function>(
header->source, module_.RegisterSymbol(header->name), header->name,
header->params, header->return_type, body.value, func_decos.value);
header->source, module_.RegisterSymbol(header->name), header->params,
header->return_type, body.value, func_decos.value);
}
// function_type_decl
@ -1358,7 +1356,6 @@ Expect<ast::VariableList> ParserImpl::expect_param_list() {
auto* var =
create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
ast::StorageClass::kNone, // storage_class
decl->type, // type
true, // is_const
@ -1630,7 +1627,6 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
auto* var =
create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
ast::StorageClass::kNone, // storage_class
decl->type, // type
true, // is_const
@ -1660,7 +1656,6 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
auto* var =
create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
decl->storage_class, // storage_class
decl->type, // type
false, // is_const
@ -2046,10 +2041,10 @@ Maybe<ast::CallStatement*> ParserImpl::func_call_stmt() {
return Failure::kErrored;
return create<ast::CallStatement>(
Source{}, create<ast::CallExpression>(
source,
Source{},
create<ast::CallExpression>(source,
create<ast::IdentifierExpression>(
source, module_.RegisterSymbol(name), name),
source, module_.RegisterSymbol(name)),
std::move(params)));
}
@ -2122,7 +2117,7 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
if (match(Token::Type::kIdentifier))
return create<ast::IdentifierExpression>(
t.source(), module_.RegisterSymbol(t.to_str()), t.to_str());
t.source(), module_.RegisterSymbol(t.to_str()));
auto type = type_decl();
if (type.errored)
@ -2198,7 +2193,7 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
return postfix_expr(create<ast::MemberAccessorExpression>(
ident.source, prefix,
create<ast::IdentifierExpression>(
ident.source, module_.RegisterSymbol(ident.value), ident.value)));
ident.source, module_.RegisterSymbol(ident.value))));
}
return prefix;

View File

@ -45,7 +45,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
auto p = parser("type a = B");
ast::type::Struct str(p->get_module().RegisterSymbol("B"), "B", {});
ast::type::Struct str(p->get_module().RegisterSymbol("B"), {});
p->register_constructed("B", &str);
auto t = p->type_alias();

View File

@ -50,7 +50,7 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
auto* int_type = mod.create<ast::type::I32>();
auto* alias_type =
mod.create<ast::type::Alias>(mod.RegisterSymbol("A"), "A", int_type);
mod.create<ast::type::Alias>(mod.RegisterSymbol("A"), int_type);
p->register_constructed("A", alias_type);

View File

@ -53,7 +53,6 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
auto* pointsize_var = out.module.create<ast::Variable>(
Source{}, // source
out.module.RegisterSymbol(kPointSizeVar), // symbol
kPointSizeVar, // name
ast::StorageClass::kOutput, // storage_class
f32, // type
false, // is_const
@ -69,7 +68,7 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
auto* one = out.module.create<ast::ScalarConstructorExpression>(
Source{}, out.module.create<ast::FloatLiteral>(Source{}, f32, 1.0f));
auto* pointsize_ident = out.module.create<ast::IdentifierExpression>(
Source{}, out.module.RegisterSymbol(kPointSizeVar), kPointSizeVar);
Source{}, out.module.RegisterSymbol(kPointSizeVar));
auto* pointsize_assign = out.module.create<ast::AssignmentStatement>(
Source{}, pointsize_ident, one);

View File

@ -67,7 +67,6 @@ ast::Variable* clone_variable_with_new_name(ast::CloneContext* ctx,
return ctx->mod->create<ast::Variable>(
ctx->Clone(in->source()), // source
ctx->mod->RegisterSymbol(new_name), // symbol
new_name, // name
in->storage_class(), // storage_class
ctx->Clone(in->type()), // type
in->is_const(), // is_const
@ -205,8 +204,8 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) {
member_dec.push_back(
mod->create<ast::StructMemberOffsetDecoration>(Source{}, offset));
members.push_back(mod->create<ast::StructMember>(
Source{}, mod->RegisterSymbol(kFirstVertexName), kFirstVertexName,
u32_type, std::move(member_dec)));
Source{}, mod->RegisterSymbol(kFirstVertexName), u32_type,
std::move(member_dec)));
vertex_index_offset_ = offset;
offset += 4;
}
@ -216,8 +215,8 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) {
member_dec.push_back(
mod->create<ast::StructMemberOffsetDecoration>(Source{}, offset));
members.push_back(mod->create<ast::StructMember>(
Source{}, mod->RegisterSymbol(kFirstInstanceName), kFirstInstanceName,
u32_type, std::move(member_dec)));
Source{}, mod->RegisterSymbol(kFirstInstanceName), u32_type,
std::move(member_dec)));
instance_index_offset_ = offset;
offset += 4;
}
@ -226,13 +225,12 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) {
decos.push_back(mod->create<ast::StructBlockDecoration>(Source{}));
auto* struct_type = mod->create<ast::type::Struct>(
mod->RegisterSymbol(kStructName), kStructName,
mod->RegisterSymbol(kStructName),
mod->create<ast::Struct>(Source{}, std::move(members), std::move(decos)));
auto* idx_var = mod->create<ast::Variable>(
Source{}, // source
mod->RegisterSymbol(kBufferName), // symbol
kBufferName, // name
ast::StorageClass::kUniform, // storage_class
struct_type, // type
false, // is_const
@ -254,22 +252,21 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
const std::string& field_name,
ast::Variable* buffer_var,
ast::Module* mod) {
auto* buffer = mod->create<ast::IdentifierExpression>(
Source{}, buffer_var->symbol(), mod->SymbolToName(buffer_var->symbol()));
auto* buffer =
mod->create<ast::IdentifierExpression>(Source{}, buffer_var->symbol());
auto lhs_name = kIndexOffsetPrefix + original_name;
auto* constructor = mod->create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kAdd,
mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(lhs_name), lhs_name),
mod->create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol(lhs_name)),
mod->create<ast::MemberAccessorExpression>(
Source{}, buffer,
mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(field_name), field_name)));
Source{}, mod->RegisterSymbol(field_name))));
auto* var =
mod->create<ast::Variable>(Source{}, // source
mod->RegisterSymbol(original_name), // symbol
original_name, // name
ast::StorageClass::kNone, // storage_class
mod->create<ast::type::U32>(), // type
true, // is_const

View File

@ -32,7 +32,7 @@ ast::Function* Transform::CloneWithStatementsAtStart(
statements.emplace_back(ctx->Clone(s));
}
return ctx->mod->create<ast::Function>(
ctx->Clone(in->source()), ctx->Clone(in->symbol()), in->name_for_clone(),
ctx->Clone(in->source()), ctx->Clone(in->symbol()),
ctx->Clone(in->params()), ctx->Clone(in->return_type()),
ctx->mod->create<ast::BlockStatement>(ctx->Clone(in->body()->source()),
statements),

View File

@ -168,7 +168,6 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
auto* var = out->create<ast::Variable>(
Source{}, // source
out->RegisterSymbol(vertex_index_name), // symbol
vertex_index_name, // name
ast::StorageClass::kInput, // storage_class
GetI32Type(), // type
false, // is_const
@ -216,7 +215,6 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
auto* var = out->create<ast::Variable>(
Source{}, // source
out->RegisterSymbol(instance_index_name), // symbol
instance_index_name, // name
ast::StorageClass::kInput, // storage_class
GetI32Type(), // type
false, // is_const
@ -244,7 +242,6 @@ void VertexPulling::State::ConvertVertexInputVariablesToPrivate() {
v = out->create<ast::Variable>(
Source{}, // source
v->symbol(), // symbol
out->SymbolToName(v->symbol()), // name
ast::StorageClass::kPrivate, // storage_class
v->type(), // type
false, // is_const
@ -273,14 +270,14 @@ void VertexPulling::State::AddVertexStorageBuffers() {
out->create<ast::StructMemberOffsetDecoration>(Source{}, 0u));
members.push_back(out->create<ast::StructMember>(
Source{}, out->RegisterSymbol(kStructBufferName), kStructBufferName,
internal_array_type, std::move(member_dec)));
Source{}, out->RegisterSymbol(kStructBufferName), internal_array_type,
std::move(member_dec)));
ast::StructDecorationList decos;
decos.push_back(out->create<ast::StructBlockDecoration>(Source{}));
auto* struct_type = out->create<ast::type::Struct>(
out->RegisterSymbol(kStructName), kStructName,
out->RegisterSymbol(kStructName),
out->create<ast::Struct>(Source{}, std::move(members), std::move(decos)));
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
@ -289,7 +286,6 @@ void VertexPulling::State::AddVertexStorageBuffers() {
auto* var = out->create<ast::Variable>(
Source{}, // source
out->RegisterSymbol(name), // symbol
name, // name
ast::StorageClass::kStorageBuffer, // storage_class
struct_type, // type
false, // is_const
@ -315,7 +311,6 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
Source{}, out->create<ast::Variable>(
Source{}, // source
out->RegisterSymbol(kPullingPosVarName), // symbol
kPullingPosVarName, // name
ast::StorageClass::kFunction, // storage_class
GetI32Type(), // type
false, // is_const
@ -343,7 +338,7 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
: instance_index_name;
// Identifier to index by
auto* index_identifier = out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(name), name);
Source{}, out->RegisterSymbol(name));
// An expression for the start of the read in the buffer in bytes
auto* pos_value = out->create<ast::BinaryExpression>(
@ -362,7 +357,7 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
stmts.emplace_back(out->create<ast::AssignmentStatement>(
Source{},
out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(ident_name), ident_name),
Source{}, out->RegisterSymbol(ident_name)),
AccessByFormat(i, attribute_desc.format)));
}
}
@ -377,7 +372,7 @@ ast::Expression* VertexPulling::State::GenUint(uint32_t value) const {
ast::Expression* VertexPulling::State::CreatePullingPositionIdent() const {
return out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(kPullingPosVarName), kPullingPosVarName);
Source{}, out->RegisterSymbol(kPullingPosVarName));
}
ast::Expression* VertexPulling::State::AccessByFormat(
@ -421,10 +416,9 @@ ast::Expression* VertexPulling::State::AccessU32(uint32_t buffer,
out->create<ast::MemberAccessorExpression>(
Source{},
out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(vbuf_name), vbuf_name),
Source{}, out->RegisterSymbol(vbuf_name)),
out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(kStructBufferName),
kStructBufferName)),
Source{}, out->RegisterSymbol(kStructBufferName))),
out->create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kDivide, pos,
GenUint(4)));
}