blob: 1256236ea685cfe2de1c6577069c787eb8d48869 [file] [log] [blame]
Austin Engcc2516a2023-10-17 20:57:54 +00001// Copyright 2020 The Dawn & Tint Authors
Ryan Harrisondbc13af2022-02-21 15:19:07 +00002//
Austin Engcc2516a2023-10-17 20:57:54 +00003// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
Ryan Harrisondbc13af2022-02-21 15:19:07 +00005//
Austin Engcc2516a2023-10-17 20:57:54 +00006// 1. Redistributions of source code must retain the above copyright notice, this
7// list of conditions and the following disclaimer.
Ryan Harrisondbc13af2022-02-21 15:19:07 +00008//
Austin Engcc2516a2023-10-17 20:57:54 +00009// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12//
13// 3. Neither the name of the copyright holder nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Ryan Harrisondbc13af2022-02-21 15:19:07 +000027
Ben Claytondc68d5c2023-08-01 00:37:35 +000028#include "src/tint/utils/symbol/symbol.h"
Ryan Harrisondbc13af2022-02-21 15:19:07 +000029
30#include <utility>
31
32namespace tint {
33
34Symbol::Symbol() = default;
35
dan sinclair637a2fe2023-07-24 21:11:41 +000036Symbol::Symbol(uint32_t val, tint::GenerationID pid, std::string_view name)
37 : val_(val), generation_id_(pid), name_(name) {}
Ryan Harrisondbc13af2022-02-21 15:19:07 +000038
39Symbol::Symbol(const Symbol& o) = default;
40
41Symbol::Symbol(Symbol&& o) = default;
42
43Symbol::~Symbol() = default;
44
45Symbol& Symbol::operator=(const Symbol& o) = default;
46
47Symbol& Symbol::operator=(Symbol&& o) = default;
48
49bool Symbol::operator==(const Symbol& other) const {
Ben Claytonf848af22023-07-28 16:37:32 +000050 TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(generation_id_, other.generation_id_);
dan sinclair41e4d9a2022-05-01 14:40:55 +000051 return val_ == other.val_;
Ryan Harrisondbc13af2022-02-21 15:19:07 +000052}
53
Ben Clayton75b18672022-11-29 21:17:37 +000054bool Symbol::operator!=(const Symbol& other) const {
Ben Claytonf848af22023-07-28 16:37:32 +000055 TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(generation_id_, other.generation_id_);
Ben Clayton75b18672022-11-29 21:17:37 +000056 return val_ != other.val_;
57}
58
Ryan Harrisondbc13af2022-02-21 15:19:07 +000059bool Symbol::operator<(const Symbol& other) const {
Ben Claytonf848af22023-07-28 16:37:32 +000060 TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(generation_id_, other.generation_id_);
dan sinclair41e4d9a2022-05-01 14:40:55 +000061 return val_ < other.val_;
Ryan Harrisondbc13af2022-02-21 15:19:07 +000062}
63
64std::string Symbol::to_str() const {
dan sinclair41e4d9a2022-05-01 14:40:55 +000065 return "$" + std::to_string(val_);
Ryan Harrisondbc13af2022-02-21 15:19:07 +000066}
67
dan sinclaire16ed7c2023-04-19 16:58:12 +000068std::string_view Symbol::NameView() const {
69 return name_;
70}
71
dan sinclairb353ebe2023-04-18 19:31:21 +000072std::string Symbol::Name() const {
73 return std::string(name_);
74}
75
Ryan Harrisondbc13af2022-02-21 15:19:07 +000076} // namespace tint