Namer: Take a SymbolTable instead of a Program

Program is going to undergo some heavy refactoring.
Reduce unnecessary dependencies to what Namer actually wants.

Change-Id: Ie411da113a2728321c52ba0a72ae7c2139469886
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38543
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-01-26 16:57:10 +00:00
parent d542a2875f
commit 9f7a414505
3 changed files with 26 additions and 26 deletions

View File

@ -22,7 +22,7 @@
namespace tint {
Namer::Namer(Program* program) : program_(program) {}
Namer::Namer(SymbolTable* symbols) : symbols_(symbols) {}
Namer::~Namer() = default;
@ -42,7 +42,7 @@ std::string Namer::GenerateName(const std::string& prefix) {
return name;
}
MangleNamer::MangleNamer(Program* program) : Namer(program) {}
MangleNamer::MangleNamer(SymbolTable* symbols) : Namer(symbols) {}
MangleNamer::~MangleNamer() = default;
@ -50,12 +50,12 @@ std::string MangleNamer::NameFor(const Symbol& sym) {
return sym.to_str();
}
UnsafeNamer::UnsafeNamer(Program* program) : Namer(program) {}
UnsafeNamer::UnsafeNamer(SymbolTable* symbols) : Namer(symbols) {}
UnsafeNamer::~UnsafeNamer() = default;
std::string UnsafeNamer::NameFor(const Symbol& sym) {
return program_->SymbolToName(sym);
return symbols_->NameFor(sym);
}
} // namespace tint

View File

@ -19,7 +19,7 @@
#include <unordered_map>
#include <unordered_set>
#include "src/program.h"
#include "src/symbol_table.h"
namespace tint {
@ -27,8 +27,8 @@ namespace tint {
class Namer {
public:
/// Constructor
/// @param program the program this namer works with
explicit Namer(Program* program);
/// @param symbols the symbol table this namer works with
explicit Namer(SymbolTable* symbols);
/// Destructor
virtual ~Namer();
@ -48,8 +48,8 @@ class Namer {
/// @returns true if `name` has already been used
bool IsUsed(const std::string& name);
/// The program storing the symbol table
Program* program_ = nullptr;
/// The symbol table
SymbolTable* symbols_ = nullptr;
private:
// The list of names taken by the remapper
@ -60,8 +60,8 @@ class Namer {
class MangleNamer : public Namer {
public:
/// Constructor
/// @param program the program to retrieve names from
explicit MangleNamer(Program* program);
/// @param symbols the symbol table this namer works with
explicit MangleNamer(SymbolTable* symbols);
/// Destructor
~MangleNamer() override;
@ -77,8 +77,8 @@ class MangleNamer : public Namer {
class UnsafeNamer : public Namer {
public:
/// Constructor
/// @param program the program to retrieve names from
explicit UnsafeNamer(Program* program);
/// @param symbols the symbol table this namer works with
explicit UnsafeNamer(SymbolTable* symbols);
/// Destructor
~UnsafeNamer() override;

View File

@ -15,7 +15,7 @@
#include "src/namer.h"
#include "gtest/gtest.h"
#include "src/program.h"
#include "src/symbol_table.h"
namespace tint {
namespace {
@ -23,8 +23,8 @@ namespace {
using NamerTest = testing::Test;
TEST_F(NamerTest, GenerateName) {
Program m;
MangleNamer n(&m);
SymbolTable t;
MangleNamer n(&t);
EXPECT_EQ("name", n.GenerateName("name"));
EXPECT_EQ("name_0", n.GenerateName("name"));
EXPECT_EQ("name_1", n.GenerateName("name"));
@ -33,19 +33,19 @@ TEST_F(NamerTest, GenerateName) {
using MangleNamerTest = testing::Test;
TEST_F(MangleNamerTest, ReturnsName) {
Program m;
auto s = m.RegisterSymbol("my_sym");
SymbolTable t;
auto s = t.Register("my_sym");
MangleNamer n(&m);
MangleNamer n(&t);
EXPECT_EQ("tint_symbol_1", n.NameFor(s));
}
TEST_F(MangleNamerTest, ReturnsSameValueForSameName) {
Program m;
auto s1 = m.RegisterSymbol("my_sym");
auto s2 = m.RegisterSymbol("my_sym2");
SymbolTable t;
auto s1 = t.Register("my_sym");
auto s2 = t.Register("my_sym2");
MangleNamer n(&m);
MangleNamer n(&t);
EXPECT_EQ("tint_symbol_1", n.NameFor(s1));
EXPECT_EQ("tint_symbol_2", n.NameFor(s2));
EXPECT_EQ("tint_symbol_1", n.NameFor(s1));
@ -53,10 +53,10 @@ TEST_F(MangleNamerTest, ReturnsSameValueForSameName) {
using UnsafeNamerTest = testing::Test;
TEST_F(UnsafeNamerTest, ReturnsName) {
Program m;
auto s = m.RegisterSymbol("my_sym");
SymbolTable t;
auto s = t.Register("my_sym");
UnsafeNamer n(&m);
UnsafeNamer n(&t);
EXPECT_EQ("my_sym", n.NameFor(s));
}