diff --git a/src/ast/call_expression.cc b/src/ast/call_expression.cc index 0ac44bf9fe..e63b41fdc7 100644 --- a/src/ast/call_expression.cc +++ b/src/ast/call_expression.cc @@ -23,7 +23,7 @@ namespace ast { CallExpression::CallExpression(ProgramID program_id, const Source& source, - Expression* func, + IdentifierExpression* func, ExpressionList params) : Base(program_id, source), func_(func), params_(params) { TINT_ASSERT(func_); diff --git a/src/ast/call_expression.h b/src/ast/call_expression.h index c366d91854..54d9711b6b 100644 --- a/src/ast/call_expression.h +++ b/src/ast/call_expression.h @@ -20,6 +20,9 @@ namespace tint { namespace ast { +// Forward declarations. +class IdentifierExpression; + /// A call expression class CallExpression : public Castable { public: @@ -30,14 +33,14 @@ class CallExpression : public Castable { /// @param params the parameters CallExpression(ProgramID program_id, const Source& source, - Expression* func, + IdentifierExpression* func, ExpressionList params); /// Move constructor CallExpression(CallExpression&&); ~CallExpression() override; /// @returns the func - Expression* func() const { return func_; } + IdentifierExpression* func() const { return func_; } /// @returns the parameters const ExpressionList& params() const { return params_; } @@ -58,7 +61,7 @@ class CallExpression : public Castable { private: CallExpression(const CallExpression&) = delete; - Expression* const func_; + IdentifierExpression* const func_; ExpressionList const params_; }; diff --git a/src/reader/wgsl/parser_impl_call_stmt_test.cc b/src/reader/wgsl/parser_impl_call_stmt_test.cc index ec41195fd2..28dc2c813d 100644 --- a/src/reader/wgsl/parser_impl_call_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_call_stmt_test.cc @@ -31,9 +31,7 @@ TEST_F(ParserImplTest, Statement_Call) { ASSERT_TRUE(e->Is()); auto* c = e->As()->expr(); - ASSERT_TRUE(c->func()->Is()); - auto* ident = c->func()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a")); EXPECT_EQ(c->params().size(), 0u); } @@ -49,9 +47,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) { ASSERT_TRUE(e->Is()); auto* c = e->As()->expr(); - ASSERT_TRUE(c->func()->Is()); - auto* ident = c->func()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a")); EXPECT_EQ(c->params().size(), 3u); EXPECT_TRUE(c->params()[0]->Is()); @@ -70,9 +66,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams_TrailingComma) { ASSERT_TRUE(e->Is()); auto* c = e->As()->expr(); - ASSERT_TRUE(c->func()->Is()); - auto* ident = c->func()->As(); - EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a")); EXPECT_EQ(c->params().size(), 2u); EXPECT_TRUE(c->params()[0]->Is()); diff --git a/src/reader/wgsl/parser_impl_singular_expression_test.cc b/src/reader/wgsl/parser_impl_singular_expression_test.cc index d74d1bf8b1..ee73c87924 100644 --- a/src/reader/wgsl/parser_impl_singular_expression_test.cc +++ b/src/reader/wgsl/parser_impl_singular_expression_test.cc @@ -100,9 +100,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_Empty) { ASSERT_TRUE(e->Is()); auto* c = e->As(); - ASSERT_TRUE(c->func()->Is()); - auto* func = c->func()->As(); - EXPECT_EQ(func->symbol(), p->builder().Symbols().Get("a")); + EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a")); EXPECT_EQ(c->params().size(), 0u); } @@ -118,9 +116,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_WithArgs) { ASSERT_TRUE(e->Is()); auto* c = e->As(); - ASSERT_TRUE(c->func()->Is()); - auto* func = c->func()->As(); - EXPECT_EQ(func->symbol(), p->builder().Symbols().Get("test")); + EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("test")); EXPECT_EQ(c->params().size(), 3u); EXPECT_TRUE(c->params()[0]->Is()); diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index e63800f56c..757da88e83 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -1626,16 +1626,8 @@ bool Resolver::Call(ast::CallExpression* call) { return false; } - // The expression has to be an identifier as you can't store function - // pointers but, if it isn't we'll just use the normal result determination - // to be on the safe side. Mark(call->func()); - auto* ident = call->func()->As(); - if (!ident) { - diagnostics_.add_error("call target is not an identifier", call->source()); - return false; - } - + auto* ident = call->func(); auto name = builder_->Symbols().NameFor(ident->symbol()); auto intrinsic_type = sem::ParseIntrinsicType(name); diff --git a/src/transform/renamer.cc b/src/transform/renamer.cc index 9cd9abdcaf..d1371b226d 100644 --- a/src/transform/renamer.cc +++ b/src/transform/renamer.cc @@ -871,7 +871,7 @@ Output Renamer::Run(const Program* in, const DataMap&) { continue; } if (sem->Target()->Is()) { - preserve.emplace(call->func()->As()); + preserve.emplace(call->func()); } } } diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 5a3621b1b8..1c2d3f05d5 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -461,13 +461,8 @@ bool GeneratorImpl::EmitBreak(std::ostream& out, ast::BreakStatement*) { bool GeneratorImpl::EmitCall(std::ostream& pre, std::ostream& out, ast::CallExpression* expr) { - auto* ident = expr->func()->As(); - if (ident == nullptr) { - diagnostics_.add_error("invalid function name"); - return 0; - } - const auto& params = expr->params(); + auto* ident = expr->func(); auto* call = builder_.Sem().Get(expr); auto* target = call->Target(); diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index e569945497..ed64bf92a5 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -319,13 +319,7 @@ std::string GeneratorImpl::current_ep_var_name(VarType type) { } bool GeneratorImpl::EmitCall(ast::CallExpression* expr) { - auto* ident = expr->func()->As(); - - if (ident == nullptr) { - diagnostics_.add_error("invalid function name"); - return 0; - } - + auto* ident = expr->func(); auto* call = program_->Sem().Get(expr); if (auto* intrinsic = call->Target()->As()) { if (intrinsic->IsTexture()) { diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index e10bab504c..a7af47f138 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -1892,13 +1892,7 @@ bool Builder::GenerateBlockStatementWithoutScoping( } uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) { - auto* ident = expr->func()->As(); - - if (ident == nullptr) { - error_ = "invalid function name"; - return 0; - } - + auto* ident = expr->func(); auto* call = builder_.Sem().Get(expr); auto* target = call->Target(); if (auto* intrinsic = target->As()) {