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>
This commit is contained in:
parent
5d64f60a60
commit
5585f0789c
|
@ -52,10 +52,15 @@ Symbol SymbolTable::Get(const std::string& name) const {
|
||||||
|
|
||||||
std::string SymbolTable::NameFor(const Symbol symbol) const {
|
std::string SymbolTable::NameFor(const Symbol symbol) const {
|
||||||
auto it = symbol_to_name_.find(symbol);
|
auto it = symbol_to_name_.find(symbol);
|
||||||
if (it == symbol_to_name_.end())
|
if (it == symbol_to_name_.end()) {
|
||||||
return "";
|
return symbol.to_str();
|
||||||
|
}
|
||||||
|
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Symbol SymbolTable::New() {
|
||||||
|
return Symbol(next_symbol_++);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
|
@ -58,6 +58,9 @@ class SymbolTable {
|
||||||
/// @returns the symbol name or "" if not found
|
/// @returns the symbol name or "" if not found
|
||||||
std::string NameFor(const Symbol symbol) const;
|
std::string NameFor(const Symbol symbol) const;
|
||||||
|
|
||||||
|
/// @returns a new, unnamed symbol
|
||||||
|
Symbol New();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The value to be associated to the next registered symbol table entry.
|
// The value to be associated to the next registered symbol table entry.
|
||||||
uint32_t next_symbol_ = 1;
|
uint32_t next_symbol_ = 1;
|
||||||
|
|
|
@ -42,7 +42,7 @@ TEST_F(SymbolTableTest, ReturnsNameForSymbol) {
|
||||||
|
|
||||||
TEST_F(SymbolTableTest, ReturnsBlankForMissingSymbol) {
|
TEST_F(SymbolTableTest, ReturnsBlankForMissingSymbol) {
|
||||||
SymbolTable s;
|
SymbolTable s;
|
||||||
EXPECT_EQ("", s.NameFor(Symbol(2)));
|
EXPECT_EQ("tint_symbol_2", s.NameFor(Symbol(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SymbolTableTest, ReturnsInvalidForBlankString) {
|
TEST_F(SymbolTableTest, ReturnsInvalidForBlankString) {
|
||||||
|
|
Loading…
Reference in New Issue