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/sem/pointer_type.h"
16
17 #include "src/program_builder.h"
18 #include "src/sem/reference_type.h"
19
20 TINT_INSTANTIATE_TYPEINFO(tint::sem::Pointer);
21
22 namespace tint {
23 namespace sem {
24
Pointer(const Type * subtype,ast::StorageClass storage_class,ast::Access access)25 Pointer::Pointer(const Type* subtype,
26 ast::StorageClass storage_class,
27 ast::Access access)
28 : subtype_(subtype), storage_class_(storage_class), access_(access) {
29 TINT_ASSERT(Semantic, !subtype->Is<Reference>());
30 TINT_ASSERT(Semantic, access != ast::Access::kUndefined);
31 }
32
type_name() const33 std::string Pointer::type_name() const {
34 std::ostringstream out;
35 out << "__ptr_" << storage_class_ << subtype_->type_name() << "__" << access_;
36 return out.str();
37 }
38
FriendlyName(const SymbolTable & symbols) const39 std::string Pointer::FriendlyName(const SymbolTable& symbols) const {
40 std::ostringstream out;
41 out << "ptr<";
42 if (storage_class_ != ast::StorageClass::kNone) {
43 out << storage_class_ << ", ";
44 }
45 out << subtype_->FriendlyName(symbols) << ", " << access_;
46 out << ">";
47 return out.str();
48 }
49
50 Pointer::Pointer(Pointer&&) = default;
51
52 Pointer::~Pointer() = default;
53
54 } // namespace sem
55 } // namespace tint
56