1 // Copyright 2020 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/symbol.h"
16
17 #include <utility>
18
19 namespace tint {
20
21 Symbol::Symbol() = default;
22
Symbol(uint32_t val,tint::ProgramID program_id)23 Symbol::Symbol(uint32_t val, tint::ProgramID program_id)
24 : val_(val), program_id_(program_id) {}
25
26 #if TINT_SYMBOL_STORE_DEBUG_NAME
Symbol(uint32_t val,tint::ProgramID program_id,std::string debug_name)27 Symbol::Symbol(uint32_t val, tint::ProgramID program_id, std::string debug_name)
28 : val_(val), program_id_(program_id), debug_name_(std::move(debug_name)) {}
29 #endif
30
31 Symbol::Symbol(const Symbol& o) = default;
32
33 Symbol::Symbol(Symbol&& o) = default;
34
35 Symbol::~Symbol() = default;
36
37 Symbol& Symbol::operator=(const Symbol& o) = default;
38
39 Symbol& Symbol::operator=(Symbol&& o) = default;
40
operator ==(const Symbol & other) const41 bool Symbol::operator==(const Symbol& other) const {
42 TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(Symbol, program_id_,
43 other.program_id_);
44 return val_ == other.val_;
45 }
46
operator <(const Symbol & other) const47 bool Symbol::operator<(const Symbol& other) const {
48 TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(Symbol, program_id_,
49 other.program_id_);
50 return val_ < other.val_;
51 }
52
to_str() const53 std::string Symbol::to_str() const {
54 return "$" + std::to_string(val_);
55 }
56
57 } // namespace tint
58