Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | // Copyright 2020 The Dawn & Tint Authors |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are met: |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 5 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | // 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | // list of conditions and the following disclaimer. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 8 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | // 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 Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 27 | |
Ben Clayton | dc68d5c | 2023-08-01 00:37:35 +0000 | [diff] [blame] | 28 | #include "src/tint/utils/symbol/symbol.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 29 | |
| 30 | #include <utility> |
| 31 | |
| 32 | namespace tint { |
| 33 | |
| 34 | Symbol::Symbol() = default; |
| 35 | |
dan sinclair | 637a2fe | 2023-07-24 21:11:41 +0000 | [diff] [blame] | 36 | Symbol::Symbol(uint32_t val, tint::GenerationID pid, std::string_view name) |
| 37 | : val_(val), generation_id_(pid), name_(name) {} |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 38 | |
| 39 | Symbol::Symbol(const Symbol& o) = default; |
| 40 | |
| 41 | Symbol::Symbol(Symbol&& o) = default; |
| 42 | |
| 43 | Symbol::~Symbol() = default; |
| 44 | |
| 45 | Symbol& Symbol::operator=(const Symbol& o) = default; |
| 46 | |
| 47 | Symbol& Symbol::operator=(Symbol&& o) = default; |
| 48 | |
| 49 | bool Symbol::operator==(const Symbol& other) const { |
Ben Clayton | f848af2 | 2023-07-28 16:37:32 +0000 | [diff] [blame] | 50 | TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(generation_id_, other.generation_id_); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 51 | return val_ == other.val_; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Ben Clayton | 75b1867 | 2022-11-29 21:17:37 +0000 | [diff] [blame] | 54 | bool Symbol::operator!=(const Symbol& other) const { |
Ben Clayton | f848af2 | 2023-07-28 16:37:32 +0000 | [diff] [blame] | 55 | TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(generation_id_, other.generation_id_); |
Ben Clayton | 75b1867 | 2022-11-29 21:17:37 +0000 | [diff] [blame] | 56 | return val_ != other.val_; |
| 57 | } |
| 58 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 59 | bool Symbol::operator<(const Symbol& other) const { |
Ben Clayton | f848af2 | 2023-07-28 16:37:32 +0000 | [diff] [blame] | 60 | TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(generation_id_, other.generation_id_); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 61 | return val_ < other.val_; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | std::string Symbol::to_str() const { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 65 | return "$" + std::to_string(val_); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 66 | } |
| 67 | |
dan sinclair | e16ed7c | 2023-04-19 16:58:12 +0000 | [diff] [blame] | 68 | std::string_view Symbol::NameView() const { |
| 69 | return name_; |
| 70 | } |
| 71 | |
dan sinclair | b353ebe | 2023-04-18 19:31:21 +0000 | [diff] [blame] | 72 | std::string Symbol::Name() const { |
| 73 | return std::string(name_); |
| 74 | } |
| 75 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 76 | } // namespace tint |