ast: Use IdentifierExpression for call targets
They are always identifiers, and this removes unnecessary type casting from usages of CallExpression::func(). Change-Id: I7a11dc10658abab578395e20ad830cd5bc5a5b71 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51960 Auto-Submit: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
e5fdd58352
commit
28ec968b4f
|
@ -23,7 +23,7 @@ namespace ast {
|
||||||
|
|
||||||
CallExpression::CallExpression(ProgramID program_id,
|
CallExpression::CallExpression(ProgramID program_id,
|
||||||
const Source& source,
|
const Source& source,
|
||||||
Expression* func,
|
IdentifierExpression* func,
|
||||||
ExpressionList params)
|
ExpressionList params)
|
||||||
: Base(program_id, source), func_(func), params_(params) {
|
: Base(program_id, source), func_(func), params_(params) {
|
||||||
TINT_ASSERT(func_);
|
TINT_ASSERT(func_);
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
|
// Forward declarations.
|
||||||
|
class IdentifierExpression;
|
||||||
|
|
||||||
/// A call expression
|
/// A call expression
|
||||||
class CallExpression : public Castable<CallExpression, Expression> {
|
class CallExpression : public Castable<CallExpression, Expression> {
|
||||||
public:
|
public:
|
||||||
|
@ -30,14 +33,14 @@ class CallExpression : public Castable<CallExpression, Expression> {
|
||||||
/// @param params the parameters
|
/// @param params the parameters
|
||||||
CallExpression(ProgramID program_id,
|
CallExpression(ProgramID program_id,
|
||||||
const Source& source,
|
const Source& source,
|
||||||
Expression* func,
|
IdentifierExpression* func,
|
||||||
ExpressionList params);
|
ExpressionList params);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
CallExpression(CallExpression&&);
|
CallExpression(CallExpression&&);
|
||||||
~CallExpression() override;
|
~CallExpression() override;
|
||||||
|
|
||||||
/// @returns the func
|
/// @returns the func
|
||||||
Expression* func() const { return func_; }
|
IdentifierExpression* func() const { return func_; }
|
||||||
/// @returns the parameters
|
/// @returns the parameters
|
||||||
const ExpressionList& params() const { return params_; }
|
const ExpressionList& params() const { return params_; }
|
||||||
|
|
||||||
|
@ -58,7 +61,7 @@ class CallExpression : public Castable<CallExpression, Expression> {
|
||||||
private:
|
private:
|
||||||
CallExpression(const CallExpression&) = delete;
|
CallExpression(const CallExpression&) = delete;
|
||||||
|
|
||||||
Expression* const func_;
|
IdentifierExpression* const func_;
|
||||||
ExpressionList const params_;
|
ExpressionList const params_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,7 @@ TEST_F(ParserImplTest, Statement_Call) {
|
||||||
ASSERT_TRUE(e->Is<ast::CallStatement>());
|
ASSERT_TRUE(e->Is<ast::CallStatement>());
|
||||||
auto* c = e->As<ast::CallStatement>()->expr();
|
auto* c = e->As<ast::CallStatement>()->expr();
|
||||||
|
|
||||||
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
|
EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a"));
|
||||||
auto* ident = c->func()->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
EXPECT_EQ(c->params().size(), 0u);
|
EXPECT_EQ(c->params().size(), 0u);
|
||||||
}
|
}
|
||||||
|
@ -49,9 +47,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) {
|
||||||
ASSERT_TRUE(e->Is<ast::CallStatement>());
|
ASSERT_TRUE(e->Is<ast::CallStatement>());
|
||||||
auto* c = e->As<ast::CallStatement>()->expr();
|
auto* c = e->As<ast::CallStatement>()->expr();
|
||||||
|
|
||||||
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
|
EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a"));
|
||||||
auto* ident = c->func()->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
EXPECT_EQ(c->params().size(), 3u);
|
EXPECT_EQ(c->params().size(), 3u);
|
||||||
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());
|
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
|
@ -70,9 +66,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams_TrailingComma) {
|
||||||
ASSERT_TRUE(e->Is<ast::CallStatement>());
|
ASSERT_TRUE(e->Is<ast::CallStatement>());
|
||||||
auto* c = e->As<ast::CallStatement>()->expr();
|
auto* c = e->As<ast::CallStatement>()->expr();
|
||||||
|
|
||||||
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
|
EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a"));
|
||||||
auto* ident = c->func()->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
EXPECT_EQ(c->params().size(), 2u);
|
EXPECT_EQ(c->params().size(), 2u);
|
||||||
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());
|
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
|
|
|
@ -100,9 +100,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_Empty) {
|
||||||
ASSERT_TRUE(e->Is<ast::CallExpression>());
|
ASSERT_TRUE(e->Is<ast::CallExpression>());
|
||||||
auto* c = e->As<ast::CallExpression>();
|
auto* c = e->As<ast::CallExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
|
EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("a"));
|
||||||
auto* func = c->func()->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(func->symbol(), p->builder().Symbols().Get("a"));
|
|
||||||
|
|
||||||
EXPECT_EQ(c->params().size(), 0u);
|
EXPECT_EQ(c->params().size(), 0u);
|
||||||
}
|
}
|
||||||
|
@ -118,9 +116,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_WithArgs) {
|
||||||
ASSERT_TRUE(e->Is<ast::CallExpression>());
|
ASSERT_TRUE(e->Is<ast::CallExpression>());
|
||||||
auto* c = e->As<ast::CallExpression>();
|
auto* c = e->As<ast::CallExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
|
EXPECT_EQ(c->func()->symbol(), p->builder().Symbols().Get("test"));
|
||||||
auto* func = c->func()->As<ast::IdentifierExpression>();
|
|
||||||
EXPECT_EQ(func->symbol(), p->builder().Symbols().Get("test"));
|
|
||||||
|
|
||||||
EXPECT_EQ(c->params().size(), 3u);
|
EXPECT_EQ(c->params().size(), 3u);
|
||||||
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());
|
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
|
|
|
@ -1626,16 +1626,8 @@ bool Resolver::Call(ast::CallExpression* call) {
|
||||||
return false;
|
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());
|
Mark(call->func());
|
||||||
auto* ident = call->func()->As<ast::IdentifierExpression>();
|
auto* ident = call->func();
|
||||||
if (!ident) {
|
|
||||||
diagnostics_.add_error("call target is not an identifier", call->source());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto name = builder_->Symbols().NameFor(ident->symbol());
|
auto name = builder_->Symbols().NameFor(ident->symbol());
|
||||||
|
|
||||||
auto intrinsic_type = sem::ParseIntrinsicType(name);
|
auto intrinsic_type = sem::ParseIntrinsicType(name);
|
||||||
|
|
|
@ -871,7 +871,7 @@ Output Renamer::Run(const Program* in, const DataMap&) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sem->Target()->Is<sem::Intrinsic>()) {
|
if (sem->Target()->Is<sem::Intrinsic>()) {
|
||||||
preserve.emplace(call->func()->As<ast::IdentifierExpression>());
|
preserve.emplace(call->func());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -461,13 +461,8 @@ bool GeneratorImpl::EmitBreak(std::ostream& out, ast::BreakStatement*) {
|
||||||
bool GeneratorImpl::EmitCall(std::ostream& pre,
|
bool GeneratorImpl::EmitCall(std::ostream& pre,
|
||||||
std::ostream& out,
|
std::ostream& out,
|
||||||
ast::CallExpression* expr) {
|
ast::CallExpression* expr) {
|
||||||
auto* ident = expr->func()->As<ast::IdentifierExpression>();
|
|
||||||
if (ident == nullptr) {
|
|
||||||
diagnostics_.add_error("invalid function name");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto& params = expr->params();
|
const auto& params = expr->params();
|
||||||
|
auto* ident = expr->func();
|
||||||
auto* call = builder_.Sem().Get(expr);
|
auto* call = builder_.Sem().Get(expr);
|
||||||
auto* target = call->Target();
|
auto* target = call->Target();
|
||||||
|
|
||||||
|
|
|
@ -319,13 +319,7 @@ std::string GeneratorImpl::current_ep_var_name(VarType type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
||||||
auto* ident = expr->func()->As<ast::IdentifierExpression>();
|
auto* ident = expr->func();
|
||||||
|
|
||||||
if (ident == nullptr) {
|
|
||||||
diagnostics_.add_error("invalid function name");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* call = program_->Sem().Get(expr);
|
auto* call = program_->Sem().Get(expr);
|
||||||
if (auto* intrinsic = call->Target()->As<sem::Intrinsic>()) {
|
if (auto* intrinsic = call->Target()->As<sem::Intrinsic>()) {
|
||||||
if (intrinsic->IsTexture()) {
|
if (intrinsic->IsTexture()) {
|
||||||
|
|
|
@ -1892,13 +1892,7 @@ bool Builder::GenerateBlockStatementWithoutScoping(
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) {
|
uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) {
|
||||||
auto* ident = expr->func()->As<ast::IdentifierExpression>();
|
auto* ident = expr->func();
|
||||||
|
|
||||||
if (ident == nullptr) {
|
|
||||||
error_ = "invalid function name";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* call = builder_.Sem().Get(expr);
|
auto* call = builder_.Sem().Get(expr);
|
||||||
auto* target = call->Target();
|
auto* target = call->Target();
|
||||||
if (auto* intrinsic = target->As<sem::Intrinsic>()) {
|
if (auto* intrinsic = target->As<sem::Intrinsic>()) {
|
||||||
|
|
Loading…
Reference in New Issue