ast: Simplify SizeExprToString()

Clean up as recommended in review:
https://dawn-review.googlesource.com/c/tint/+/66380/6/src/ast/array.cc#34

Change-Id: I70d66ab552de4a4a4d869aedd2f3c3d9f59d2712
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66603
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-10-15 18:45:40 +00:00 committed by Tint LUCI CQ
parent 9e631b1645
commit 8c9458271c
1 changed files with 3 additions and 6 deletions

View File

@ -26,12 +26,9 @@ namespace ast {
namespace {
// Returns the string representation of an array size expression.
std::string SizeExprToString(const ast::Expression* size,
const SymbolTable* symbols = nullptr) {
const SymbolTable& symbols) {
if (auto* ident = size->As<ast::IdentifierExpression>()) {
if (symbols) {
return symbols->NameFor(ident->symbol);
}
return "<unknown>";
return symbols.NameFor(ident->symbol);
}
if (auto* scalar = size->As<ast::ScalarConstructorExpression>()) {
auto* literal = scalar->literal->As<ast::IntLiteral>();
@ -65,7 +62,7 @@ std::string Array::FriendlyName(const SymbolTable& symbols) const {
}
out << "array<" << type->FriendlyName(symbols);
if (!IsRuntimeArray()) {
out << ", " << SizeExprToString(count, &symbols);
out << ", " << SizeExprToString(count, symbols);
}
out << ">";
return out.str();