mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-09 22:56:06 +00:00
This Cl adds a Symbol representing the function name to the function AST. The symbol is added alongside the name for now. When all usages of the function name are removed then the string version will be removed from the constructor. Change-Id: Ib2450e5fe531e988b25bb7d2937acc6af2187871 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35220 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com> Auto-Submit: dan sinclair <dsinclair@chromium.org>
62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
// Copyright 2020 The Tint Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "src/symbol_table.h"
|
|
|
|
namespace tint {
|
|
|
|
SymbolTable::SymbolTable() = default;
|
|
|
|
SymbolTable::SymbolTable(const SymbolTable&) = default;
|
|
|
|
SymbolTable::SymbolTable(SymbolTable&&) = default;
|
|
|
|
SymbolTable::~SymbolTable() = default;
|
|
|
|
SymbolTable& SymbolTable::operator=(const SymbolTable& other) = default;
|
|
|
|
SymbolTable& SymbolTable::operator=(SymbolTable&&) = default;
|
|
|
|
Symbol SymbolTable::Register(const std::string& name) {
|
|
if (name == "")
|
|
return Symbol();
|
|
|
|
auto it = name_to_symbol_.find(name);
|
|
if (it != name_to_symbol_.end())
|
|
return it->second;
|
|
|
|
Symbol sym(next_symbol_);
|
|
++next_symbol_;
|
|
|
|
name_to_symbol_[name] = sym;
|
|
symbol_to_name_[sym.value()] = name;
|
|
|
|
return sym;
|
|
}
|
|
|
|
Symbol SymbolTable::GetSymbol(const std::string& name) const {
|
|
auto it = name_to_symbol_.find(name);
|
|
return it != name_to_symbol_.end() ? it->second : Symbol();
|
|
}
|
|
|
|
std::string SymbolTable::NameFor(const Symbol symbol) const {
|
|
auto it = symbol_to_name_.find(symbol.value());
|
|
if (it == symbol_to_name_.end())
|
|
return "";
|
|
|
|
return it->second;
|
|
}
|
|
|
|
} // namespace tint
|