Remove IdentifierExpression::name().

This CL removes the name method from IdentifierExpression. The usages
have been converted over to the symbol.

Change-Id: Id751c2fc4a43bd5414fbaf8a8a66ecffb3838e48
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36801
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair 2021-01-11 16:24:32 +00:00 committed by dan sinclair
parent 4ac6568821
commit e65e4bd2c5
23 changed files with 188 additions and 172 deletions

View File

@ -42,8 +42,6 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
/// @returns the symbol for the identifier
Symbol symbol() const { return sym_; }
/// @returns the name part of the identifier
std::string name() const { return name_; }
/// Sets the intrinsic for this identifier
/// @param i the intrinsic to set

View File

@ -25,13 +25,11 @@ using IdentifierExpressionTest = TestHelper;
TEST_F(IdentifierExpressionTest, Creation) {
auto* i = Expr("ident");
EXPECT_EQ(i->symbol(), Symbol(1));
EXPECT_EQ(i->name(), "ident");
}
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
auto* i = Expr(Source{Source::Location{20, 2}}, "ident");
EXPECT_EQ(i->symbol(), Symbol(1));
EXPECT_EQ(i->name(), "ident");
auto src = i->source();
EXPECT_EQ(src.range.begin.line, 20u);

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, AndExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -42,7 +42,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
ASSERT_TRUE(e->lhs()->Is<ast::IdentifierExpression>());
auto* ident = e->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(e->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(e->rhs()->Is<ast::ScalarConstructorExpression>());
@ -77,7 +77,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
auto* ident = mem->member()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "d");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("d"));
ASSERT_TRUE(mem->structure()->Is<ast::ArrayAccessorExpression>());
auto* ary = mem->structure()->As<ast::ArrayAccessorExpression>();
@ -93,18 +93,18 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
mem = ary->array()->As<ast::MemberAccessorExpression>();
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
ident = mem->member()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "c");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("c"));
ASSERT_TRUE(mem->structure()->Is<ast::MemberAccessorExpression>());
mem = mem->structure()->As<ast::MemberAccessorExpression>();
ASSERT_TRUE(mem->structure()->Is<ast::IdentifierExpression>());
ident = mem->structure()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
ident = mem->member()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "b");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("b"));
}
TEST_F(ParserImplTest, AssignmentStmt_MissingEqual) {

View File

@ -37,8 +37,8 @@ TEST_F(ParserImplTest, Statement_Call) {
auto* c = e->As<ast::CallStatement>()->expr();
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
auto* func = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(func->name(), "a");
auto* ident = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
EXPECT_EQ(c->params().size(), 0u);
}
@ -55,8 +55,8 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) {
auto* c = e->As<ast::CallStatement>()->expr();
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
auto* func = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(func->name(), "a");
auto* ident = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
EXPECT_EQ(c->params().size(), 3u);
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, InclusiveOrExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, LogicalAndExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, LogicalOrExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -85,7 +85,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -42,7 +42,7 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ConstantIndex) {
ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>());
auto* ident = ary->array()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
@ -64,7 +64,7 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ExpressionIndex) {
ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>());
auto* ident = ary->array()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(ary->idx_expr()->Is<ast::BinaryExpression>());
}
@ -112,7 +112,7 @@ TEST_F(ParserImplTest, PostfixExpression_Call_Empty) {
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
auto* func = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(func->name(), "a");
EXPECT_EQ(func->symbol(), p->get_module().RegisterSymbol("a"));
EXPECT_EQ(c->params().size(), 0u);
}
@ -130,7 +130,7 @@ TEST_F(ParserImplTest, PostfixExpression_Call_WithArgs) {
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
auto* func = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(func->name(), "test");
EXPECT_EQ(func->symbol(), p->get_module().RegisterSymbol("test"));
EXPECT_EQ(c->params().size(), 3u);
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());
@ -179,10 +179,12 @@ TEST_F(ParserImplTest, PostfixExpression_MemberAccessor) {
auto* m = e->As<ast::MemberAccessorExpression>();
ASSERT_TRUE(m->structure()->Is<ast::IdentifierExpression>());
EXPECT_EQ(m->structure()->As<ast::IdentifierExpression>()->name(), "a");
EXPECT_EQ(m->structure()->As<ast::IdentifierExpression>()->symbol(),
p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(m->member()->Is<ast::IdentifierExpression>());
EXPECT_EQ(m->member()->As<ast::IdentifierExpression>()->name(), "b");
EXPECT_EQ(m->member()->As<ast::IdentifierExpression>()->symbol(),
p->get_module().RegisterSymbol("b"));
}
TEST_F(ParserImplTest, PostfixExpression_MemberAccesssor_InvalidIdent) {

View File

@ -41,7 +41,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Ident) {
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
auto* ident = e->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
}
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) {

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThan) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -85,7 +85,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -108,7 +108,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftLeft) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -38,7 +38,7 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) {
auto* ary = e->As<ast::ArrayAccessorExpression>();
ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>());
auto* ident = ary->array()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->name(), "a");
EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a"));
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());

View File

@ -504,8 +504,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
ast::CallExpression* expr) {
if (ast::intrinsic::IsDerivative(ident->intrinsic())) {
if (expr->params().size() != 1) {
set_error(expr->source(),
"incorrect number of parameters for " + ident->name());
set_error(expr->source(), "incorrect number of parameters for " +
mod_->SymbolToName(ident->symbol()));
return false;
}
@ -525,8 +525,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
}
if (ast::intrinsic::IsFloatClassificationIntrinsic(ident->intrinsic())) {
if (expr->params().size() != 1) {
set_error(expr->source(),
"incorrect number of parameters for " + ident->name());
set_error(expr->source(), "incorrect number of parameters for " +
mod_->SymbolToName(ident->symbol()));
return false;
}
@ -548,7 +548,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
if (!texture_param->result_type()
->UnwrapPtrIfNeeded()
->Is<ast::type::Texture>()) {
set_error(expr->source(), "invalid first argument for " + ident->name());
set_error(expr->source(), "invalid first argument for " +
mod_->SymbolToName(ident->symbol()));
return false;
}
ast::type::Texture* texture = texture_param->result_type()
@ -658,9 +659,10 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
if (expr->params().size() != param.count) {
set_error(expr->source(),
"incorrect number of parameters for " + ident->name() +
", got " + std::to_string(expr->params().size()) +
" and expected " + std::to_string(param.count));
"incorrect number of parameters for " +
mod_->SymbolToName(ident->symbol()) + ", got " +
std::to_string(expr->params().size()) + " and expected " +
std::to_string(param.count));
return false;
}
@ -701,8 +703,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
}
if (ident->intrinsic() == ast::Intrinsic::kOuterProduct) {
if (expr->params().size() != 2) {
set_error(expr->source(),
"incorrect number of parameters for " + ident->name());
set_error(expr->source(), "incorrect number of parameters for " +
mod_->SymbolToName(ident->symbol()));
return false;
}
@ -710,7 +712,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
auto* param1_type = expr->params()[1]->result_type()->UnwrapPtrIfNeeded();
if (!param0_type->Is<ast::type::Vector>() ||
!param1_type->Is<ast::type::Vector>()) {
set_error(expr->source(), "invalid parameter type for " + ident->name());
set_error(expr->source(), "invalid parameter type for " +
mod_->SymbolToName(ident->symbol()));
return false;
}
@ -723,7 +726,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
if (ident->intrinsic() == ast::Intrinsic::kSelect) {
if (expr->params().size() != 3) {
set_error(expr->source(), "incorrect number of parameters for " +
ident->name() + " expected 3 got " +
mod_->SymbolToName(ident->symbol()) +
" expected 3 got " +
std::to_string(expr->params().size()));
return false;
}
@ -742,13 +746,14 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
}
}
if (data == nullptr) {
error_ = "unable to find intrinsic " + ident->name();
error_ = "unable to find intrinsic " + mod_->SymbolToName(ident->symbol());
return false;
}
if (expr->params().size() != data->param_count) {
set_error(expr->source(), "incorrect number of parameters for " +
ident->name() + ". Expected " +
mod_->SymbolToName(ident->symbol()) +
". Expected " +
std::to_string(data->param_count) + " got " +
std::to_string(expr->params().size()));
return false;
@ -764,7 +769,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
if (!result_types.back()->is_float_scalar_or_vector() &&
!result_types.back()->is_integer_scalar_or_vector()) {
set_error(expr->source(),
"incorrect type for " + ident->name() + ". " +
"incorrect type for " +
mod_->SymbolToName(ident->symbol()) + ". " +
"Requires float or int, scalar or vector values");
return false;
}
@ -772,7 +778,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
case IntrinsicDataType::kFloatScalarOrVector:
if (!result_types.back()->is_float_scalar_or_vector()) {
set_error(expr->source(),
"incorrect type for " + ident->name() + ". " +
"incorrect type for " +
mod_->SymbolToName(ident->symbol()) + ". " +
"Requires float scalar or float vector values");
return false;
}
@ -781,14 +788,16 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
case IntrinsicDataType::kIntScalarOrVector:
if (!result_types.back()->is_integer_scalar_or_vector()) {
set_error(expr->source(),
"incorrect type for " + ident->name() + ". " +
"incorrect type for " +
mod_->SymbolToName(ident->symbol()) + ". " +
"Requires integer scalar or integer vector values");
return false;
}
break;
case IntrinsicDataType::kFloatVector:
if (!result_types.back()->is_float_vector()) {
set_error(expr->source(), "incorrect type for " + ident->name() +
set_error(expr->source(), "incorrect type for " +
mod_->SymbolToName(ident->symbol()) +
". " + "Requires float vector values");
return false;
}
@ -796,7 +805,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
result_types.back()->As<ast::type::Vector>()->size() !=
data->vector_size) {
set_error(expr->source(), "incorrect vector size for " +
ident->name() + ". " + "Requires " +
mod_->SymbolToName(ident->symbol()) +
". " + "Requires " +
std::to_string(data->vector_size) +
" elements");
return false;
@ -804,7 +814,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
break;
case IntrinsicDataType::kMatrix:
if (!result_types.back()->Is<ast::type::Matrix>()) {
set_error(expr->source(), "incorrect type for " + ident->name() +
set_error(expr->source(), "incorrect type for " +
mod_->SymbolToName(ident->symbol()) +
". Requires matrix value");
return false;
}
@ -815,8 +826,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
// Verify all the parameter types match
for (size_t i = 1; i < data->param_count; ++i) {
if (result_types[0] != result_types[i]) {
set_error(expr->source(),
"mismatched parameter types for " + ident->name());
set_error(expr->source(), "mismatched parameter types for " +
mod_->SymbolToName(ident->symbol()));
return false;
}
}
@ -891,143 +902,144 @@ bool TypeDeterminer::DetermineIdentifier(ast::IdentifierExpression* expr) {
}
bool TypeDeterminer::SetIntrinsicIfNeeded(ast::IdentifierExpression* ident) {
if (ident->name() == "abs") {
auto name = mod_->SymbolToName(ident->symbol());
if (name == "abs") {
ident->set_intrinsic(ast::Intrinsic::kAbs);
} else if (ident->name() == "acos") {
} else if (name == "acos") {
ident->set_intrinsic(ast::Intrinsic::kAcos);
} else if (ident->name() == "all") {
} else if (name == "all") {
ident->set_intrinsic(ast::Intrinsic::kAll);
} else if (ident->name() == "any") {
} else if (name == "any") {
ident->set_intrinsic(ast::Intrinsic::kAny);
} else if (ident->name() == "arrayLength") {
} else if (name == "arrayLength") {
ident->set_intrinsic(ast::Intrinsic::kArrayLength);
} else if (ident->name() == "asin") {
} else if (name == "asin") {
ident->set_intrinsic(ast::Intrinsic::kAsin);
} else if (ident->name() == "atan") {
} else if (name == "atan") {
ident->set_intrinsic(ast::Intrinsic::kAtan);
} else if (ident->name() == "atan2") {
} else if (name == "atan2") {
ident->set_intrinsic(ast::Intrinsic::kAtan2);
} else if (ident->name() == "ceil") {
} else if (name == "ceil") {
ident->set_intrinsic(ast::Intrinsic::kCeil);
} else if (ident->name() == "clamp") {
} else if (name == "clamp") {
ident->set_intrinsic(ast::Intrinsic::kClamp);
} else if (ident->name() == "cos") {
} else if (name == "cos") {
ident->set_intrinsic(ast::Intrinsic::kCos);
} else if (ident->name() == "cosh") {
} else if (name == "cosh") {
ident->set_intrinsic(ast::Intrinsic::kCosh);
} else if (ident->name() == "countOneBits") {
} else if (name == "countOneBits") {
ident->set_intrinsic(ast::Intrinsic::kCountOneBits);
} else if (ident->name() == "cross") {
} else if (name == "cross") {
ident->set_intrinsic(ast::Intrinsic::kCross);
} else if (ident->name() == "determinant") {
} else if (name == "determinant") {
ident->set_intrinsic(ast::Intrinsic::kDeterminant);
} else if (ident->name() == "distance") {
} else if (name == "distance") {
ident->set_intrinsic(ast::Intrinsic::kDistance);
} else if (ident->name() == "dot") {
} else if (name == "dot") {
ident->set_intrinsic(ast::Intrinsic::kDot);
} else if (ident->name() == "dpdx") {
} else if (name == "dpdx") {
ident->set_intrinsic(ast::Intrinsic::kDpdx);
} else if (ident->name() == "dpdxCoarse") {
} else if (name == "dpdxCoarse") {
ident->set_intrinsic(ast::Intrinsic::kDpdxCoarse);
} else if (ident->name() == "dpdxFine") {
} else if (name == "dpdxFine") {
ident->set_intrinsic(ast::Intrinsic::kDpdxFine);
} else if (ident->name() == "dpdy") {
} else if (name == "dpdy") {
ident->set_intrinsic(ast::Intrinsic::kDpdy);
} else if (ident->name() == "dpdyCoarse") {
} else if (name == "dpdyCoarse") {
ident->set_intrinsic(ast::Intrinsic::kDpdyCoarse);
} else if (ident->name() == "dpdyFine") {
} else if (name == "dpdyFine") {
ident->set_intrinsic(ast::Intrinsic::kDpdyFine);
} else if (ident->name() == "exp") {
} else if (name == "exp") {
ident->set_intrinsic(ast::Intrinsic::kExp);
} else if (ident->name() == "exp2") {
} else if (name == "exp2") {
ident->set_intrinsic(ast::Intrinsic::kExp2);
} else if (ident->name() == "faceForward") {
} else if (name == "faceForward") {
ident->set_intrinsic(ast::Intrinsic::kFaceForward);
} else if (ident->name() == "floor") {
} else if (name == "floor") {
ident->set_intrinsic(ast::Intrinsic::kFloor);
} else if (ident->name() == "fma") {
} else if (name == "fma") {
ident->set_intrinsic(ast::Intrinsic::kFma);
} else if (ident->name() == "fract") {
} else if (name == "fract") {
ident->set_intrinsic(ast::Intrinsic::kFract);
} else if (ident->name() == "frexp") {
} else if (name == "frexp") {
ident->set_intrinsic(ast::Intrinsic::kFrexp);
} else if (ident->name() == "fwidth") {
} else if (name == "fwidth") {
ident->set_intrinsic(ast::Intrinsic::kFwidth);
} else if (ident->name() == "fwidthCoarse") {
} else if (name == "fwidthCoarse") {
ident->set_intrinsic(ast::Intrinsic::kFwidthCoarse);
} else if (ident->name() == "fwidthFine") {
} else if (name == "fwidthFine") {
ident->set_intrinsic(ast::Intrinsic::kFwidthFine);
} else if (ident->name() == "inverseSqrt") {
} else if (name == "inverseSqrt") {
ident->set_intrinsic(ast::Intrinsic::kInverseSqrt);
} else if (ident->name() == "isFinite") {
} else if (name == "isFinite") {
ident->set_intrinsic(ast::Intrinsic::kIsFinite);
} else if (ident->name() == "isInf") {
} else if (name == "isInf") {
ident->set_intrinsic(ast::Intrinsic::kIsInf);
} else if (ident->name() == "isNan") {
} else if (name == "isNan") {
ident->set_intrinsic(ast::Intrinsic::kIsNan);
} else if (ident->name() == "isNormal") {
} else if (name == "isNormal") {
ident->set_intrinsic(ast::Intrinsic::kIsNormal);
} else if (ident->name() == "ldexp") {
} else if (name == "ldexp") {
ident->set_intrinsic(ast::Intrinsic::kLdexp);
} else if (ident->name() == "length") {
} else if (name == "length") {
ident->set_intrinsic(ast::Intrinsic::kLength);
} else if (ident->name() == "log") {
} else if (name == "log") {
ident->set_intrinsic(ast::Intrinsic::kLog);
} else if (ident->name() == "log2") {
} else if (name == "log2") {
ident->set_intrinsic(ast::Intrinsic::kLog2);
} else if (ident->name() == "max") {
} else if (name == "max") {
ident->set_intrinsic(ast::Intrinsic::kMax);
} else if (ident->name() == "min") {
} else if (name == "min") {
ident->set_intrinsic(ast::Intrinsic::kMin);
} else if (ident->name() == "mix") {
} else if (name == "mix") {
ident->set_intrinsic(ast::Intrinsic::kMix);
} else if (ident->name() == "modf") {
} else if (name == "modf") {
ident->set_intrinsic(ast::Intrinsic::kModf);
} else if (ident->name() == "normalize") {
} else if (name == "normalize") {
ident->set_intrinsic(ast::Intrinsic::kNormalize);
} else if (ident->name() == "outerProduct") {
} else if (name == "outerProduct") {
ident->set_intrinsic(ast::Intrinsic::kOuterProduct);
} else if (ident->name() == "pow") {
} else if (name == "pow") {
ident->set_intrinsic(ast::Intrinsic::kPow);
} else if (ident->name() == "reflect") {
} else if (name == "reflect") {
ident->set_intrinsic(ast::Intrinsic::kReflect);
} else if (ident->name() == "reverseBits") {
} else if (name == "reverseBits") {
ident->set_intrinsic(ast::Intrinsic::kReverseBits);
} else if (ident->name() == "round") {
} else if (name == "round") {
ident->set_intrinsic(ast::Intrinsic::kRound);
} else if (ident->name() == "select") {
} else if (name == "select") {
ident->set_intrinsic(ast::Intrinsic::kSelect);
} else if (ident->name() == "sign") {
} else if (name == "sign") {
ident->set_intrinsic(ast::Intrinsic::kSign);
} else if (ident->name() == "sin") {
} else if (name == "sin") {
ident->set_intrinsic(ast::Intrinsic::kSin);
} else if (ident->name() == "sinh") {
} else if (name == "sinh") {
ident->set_intrinsic(ast::Intrinsic::kSinh);
} else if (ident->name() == "smoothStep") {
} else if (name == "smoothStep") {
ident->set_intrinsic(ast::Intrinsic::kSmoothStep);
} else if (ident->name() == "sqrt") {
} else if (name == "sqrt") {
ident->set_intrinsic(ast::Intrinsic::kSqrt);
} else if (ident->name() == "step") {
} else if (name == "step") {
ident->set_intrinsic(ast::Intrinsic::kStep);
} else if (ident->name() == "tan") {
} else if (name == "tan") {
ident->set_intrinsic(ast::Intrinsic::kTan);
} else if (ident->name() == "tanh") {
} else if (name == "tanh") {
ident->set_intrinsic(ast::Intrinsic::kTanh);
} else if (ident->name() == "textureLoad") {
} else if (name == "textureLoad") {
ident->set_intrinsic(ast::Intrinsic::kTextureLoad);
} else if (ident->name() == "textureStore") {
} else if (name == "textureStore") {
ident->set_intrinsic(ast::Intrinsic::kTextureStore);
} else if (ident->name() == "textureSample") {
} else if (name == "textureSample") {
ident->set_intrinsic(ast::Intrinsic::kTextureSample);
} else if (ident->name() == "textureSampleBias") {
} else if (name == "textureSampleBias") {
ident->set_intrinsic(ast::Intrinsic::kTextureSampleBias);
} else if (ident->name() == "textureSampleCompare") {
} else if (name == "textureSampleCompare") {
ident->set_intrinsic(ast::Intrinsic::kTextureSampleCompare);
} else if (ident->name() == "textureSampleGrad") {
} else if (name == "textureSampleGrad") {
ident->set_intrinsic(ast::Intrinsic::kTextureSampleGrad);
} else if (ident->name() == "textureSampleLevel") {
} else if (name == "textureSampleLevel") {
ident->set_intrinsic(ast::Intrinsic::kTextureSampleLevel);
} else if (ident->name() == "trunc") {
} else if (name == "trunc") {
ident->set_intrinsic(ast::Intrinsic::kTrunc);
} else {
return false;

View File

@ -81,21 +81,6 @@ bool last_is_break_or_fallthrough(const ast::BlockStatement* stmts) {
stmts->last()->Is<ast::FallthroughStatement>();
}
std::string get_buffer_name(ast::Expression* expr) {
for (;;) {
if (auto* ident = expr->As<ast::IdentifierExpression>()) {
return ident->name();
} else if (auto* member = expr->As<ast::MemberAccessorExpression>()) {
expr = member->structure();
} else if (auto* array = expr->As<ast::ArrayAccessorExpression>()) {
expr = array->array();
} else {
break;
}
}
return "";
}
uint32_t convert_swizzle_to_index(const std::string& swizzle) {
if (swizzle == "r" || swizzle == "x") {
return 0;
@ -684,17 +669,18 @@ bool GeneratorImpl::EmitCall(std::ostream& pre,
return true;
}
auto name = ident->name();
auto caller_sym = module_->GetSymbol(name);
auto name = namer_->NameFor(ident->symbol());
auto caller_sym = ident->symbol();
auto it = ep_func_name_remapped_.find(current_ep_sym_.to_str() + "_" +
caller_sym.to_str());
if (it != ep_func_name_remapped_.end()) {
name = it->second;
}
auto* func = module_->FindFunctionBySymbol(module_->GetSymbol(ident->name()));
auto* func = module_->FindFunctionBySymbol(ident->symbol());
if (func == nullptr) {
error_ = "Unable to find function: " + name;
error_ =
"Unable to find function: " + module_->SymbolToName(ident->symbol());
return false;
}
@ -782,7 +768,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre,
break;
default:
error_ = "Internal compiler error: Unhandled texture intrinsic '" +
ident->name() + "'";
module_->SymbolToName(ident->symbol()) + "'";
return false;
}
@ -885,7 +871,7 @@ std::string GeneratorImpl::generate_builtin_name(ast::CallExpression* expr) {
case ast::Intrinsic::kMax:
case ast::Intrinsic::kMin:
case ast::Intrinsic::kClamp:
out = ident->name();
out = module_->SymbolToName(ident->symbol());
break;
case ast::Intrinsic::kFaceForward:
out = "faceforward";
@ -900,7 +886,8 @@ std::string GeneratorImpl::generate_builtin_name(ast::CallExpression* expr) {
out = "smoothstep";
break;
default:
error_ = "Unknown builtin method: " + ident->name();
error_ =
"Unknown builtin method: " + module_->SymbolToName(ident->symbol());
return "";
}
@ -1948,9 +1935,12 @@ bool GeneratorImpl::is_storage_buffer_access(
ast::MemberAccessorExpression* expr) {
auto* structure = expr->structure();
auto* data_type = structure->result_type()->UnwrapAll();
// TODO(dsinclair): Swizzle
//
// If the data is a multi-element swizzle then we will not load the swizzle
// portion through the Load command.
if (data_type->Is<ast::type::Vector>() && expr->member()->name().size() > 1) {
if (data_type->Is<ast::type::Vector>() &&
module_->SymbolToName(expr->member()->symbol()).size() > 1) {
return false;
}
@ -2364,6 +2354,21 @@ bool GeneratorImpl::EmitProgramConstVariable(std::ostream& out,
return true;
}
std::string GeneratorImpl::get_buffer_name(ast::Expression* expr) {
for (;;) {
if (auto* ident = expr->As<ast::IdentifierExpression>()) {
return namer_->NameFor(ident->symbol());
} else if (auto* member = expr->As<ast::MemberAccessorExpression>()) {
expr = member->structure();
} else if (auto* array = expr->As<ast::ArrayAccessorExpression>()) {
expr = array->array();
} else {
break;
}
}
return "";
}
} // namespace hlsl
} // namespace writer
} // namespace tint

View File

@ -387,6 +387,7 @@ class GeneratorImpl {
};
std::string current_ep_var_name(VarType type);
std::string get_buffer_name(ast::Expression* expr);
std::string error_;
size_t indent_ = 0;

View File

@ -563,17 +563,18 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
return true;
}
auto name = ident->name();
auto caller_sym = module_->GetSymbol(name);
auto name = namer_->NameFor(ident->symbol());
auto caller_sym = ident->symbol();
auto it = ep_func_name_remapped_.find(current_ep_sym_.to_str() + "_" +
caller_sym.to_str());
if (it != ep_func_name_remapped_.end()) {
name = it->second;
}
auto* func = module_->FindFunctionBySymbol(module_->GetSymbol(ident->name()));
auto* func = module_->FindFunctionBySymbol(ident->symbol());
if (func == nullptr) {
error_ = "Unable to find function: " + name;
error_ =
"Unable to find function: " + module_->SymbolToName(ident->symbol());
return false;
}
@ -678,7 +679,7 @@ bool GeneratorImpl::EmitTextureCall(ast::CallExpression* expr) {
break;
default:
error_ = "Internal compiler error: Unhandled texture intrinsic '" +
ident->name() + "'";
module_->SymbolToName(ident->symbol()) + "'";
return false;
}
@ -805,7 +806,7 @@ std::string GeneratorImpl::generate_builtin_name(
case ast::Intrinsic::kTrunc:
case ast::Intrinsic::kSign:
case ast::Intrinsic::kClamp:
out += ident->name();
out += module_->SymbolToName(ident->symbol());
break;
case ast::Intrinsic::kAbs:
if (ident->result_type()->Is<ast::type::F32>()) {
@ -841,7 +842,8 @@ std::string GeneratorImpl::generate_builtin_name(
out += "rsqrt";
break;
default:
error_ = "Unknown import method: " + ident->name();
error_ =
"Unknown import method: " + module_->SymbolToName(ident->symbol());
return "";
}
return out;

View File

@ -441,12 +441,6 @@ bool Builder::GenerateEntryPoint(ast::Function* func, uint32_t id) {
return false;
}
// TODO(dsinclair): This should be using the namer to update the entry point
// name to a non-user provided string. Disable for now until we can update
// the inspector and land the same change in MSL / HLSL to all roll into Dawn
// at the same time.
// OperandList operands = {Operand::Int(stage), Operand::Int(id),
// Operand::String(func->name())};
OperandList operands = {Operand::Int(stage), Operand::Int(id),
Operand::String(namer_->NameFor(func->symbol()))};
@ -1119,7 +1113,8 @@ uint32_t Builder::GenerateIdentifierExpression(
return val;
}
error_ = "unable to find variable with identifier: " + expr->name();
error_ = "unable to find variable with identifier: " +
mod_->SymbolToName(expr->symbol());
return 0;
}
@ -1821,7 +1816,8 @@ uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) {
auto func_id = func_symbol_to_id_[ident->symbol().value()];
if (func_id == 0) {
error_ = "unable to find called function: " + ident->name();
error_ = "unable to find called function: " +
mod_->SymbolToName(ident->symbol());
return 0;
}
ops.push_back(Operand::Int(func_id));
@ -1951,7 +1947,7 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident,
auto inst_id =
intrinsic_to_glsl_method(ident->result_type(), ident->intrinsic());
if (inst_id == 0) {
error_ = "unknown method " + ident->name();
error_ = "unknown method " + mod_->SymbolToName(ident->symbol());
return 0;
}
@ -1962,7 +1958,8 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident,
}
if (op == spv::Op::OpNop) {
error_ = "unable to determine operator for: " + ident->name();
error_ = "unable to determine operator for: " +
mod_->SymbolToName(ident->symbol());
return 0;
}
@ -2173,7 +2170,8 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident,
}
if (op == spv::Op::OpNop) {
error_ = "unable to determine operator for: " + ident->name();
error_ = "unable to determine operator for: " +
mod_->SymbolToName(ident->symbol());
return false;
}

View File

@ -338,7 +338,7 @@ bool GeneratorImpl::EmitLiteral(ast::Literal* lit) {
bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) {
auto* ident = expr->As<ast::IdentifierExpression>();
out_ << ident->name();
out_ << module_.SymbolToName(ident->symbol());
return true;
}