Add SymbolTable::New()
Generates a new unnamed symbol.
Useful for creating temporaries in transforms.
Change-Id: I3aa037e4a6b2d400f24e01bbb3555af68da26748
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41480
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/symbol_table.cc b/src/symbol_table.cc
index a814875..16f28d2 100644
--- a/src/symbol_table.cc
+++ b/src/symbol_table.cc
@@ -52,10 +52,15 @@
std::string SymbolTable::NameFor(const Symbol symbol) const {
auto it = symbol_to_name_.find(symbol);
- if (it == symbol_to_name_.end())
- return "";
+ if (it == symbol_to_name_.end()) {
+ return symbol.to_str();
+ }
return it->second;
}
+Symbol SymbolTable::New() {
+ return Symbol(next_symbol_++);
+}
+
} // namespace tint
diff --git a/src/symbol_table.h b/src/symbol_table.h
index f57e468..107fe16 100644
--- a/src/symbol_table.h
+++ b/src/symbol_table.h
@@ -58,6 +58,9 @@
/// @returns the symbol name or "" if not found
std::string NameFor(const Symbol symbol) const;
+ /// @returns a new, unnamed symbol
+ Symbol New();
+
private:
// The value to be associated to the next registered symbol table entry.
uint32_t next_symbol_ = 1;
diff --git a/src/symbol_table_test.cc b/src/symbol_table_test.cc
index 306127b..e72f738 100644
--- a/src/symbol_table_test.cc
+++ b/src/symbol_table_test.cc
@@ -42,7 +42,7 @@
TEST_F(SymbolTableTest, ReturnsBlankForMissingSymbol) {
SymbolTable s;
- EXPECT_EQ("", s.NameFor(Symbol(2)));
+ EXPECT_EQ("tint_symbol_2", s.NameFor(Symbol(2)));
}
TEST_F(SymbolTableTest, ReturnsInvalidForBlankString) {