• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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/reference_type.h"
16 
17 #include "src/program_builder.h"
18 
19 TINT_INSTANTIATE_TYPEINFO(tint::sem::Reference);
20 
21 namespace tint {
22 namespace sem {
23 
Reference(const Type * subtype,ast::StorageClass storage_class,ast::Access access)24 Reference::Reference(const Type* subtype,
25                      ast::StorageClass storage_class,
26                      ast::Access access)
27     : subtype_(subtype), storage_class_(storage_class), access_(access) {
28   TINT_ASSERT(Semantic, !subtype->Is<Reference>());
29   TINT_ASSERT(Semantic, access != ast::Access::kUndefined);
30 }
31 
type_name() const32 std::string Reference::type_name() const {
33   std::ostringstream out;
34   out << "__ref_" << storage_class_ << subtype_->type_name() << "__" << access_;
35   return out.str();
36 }
37 
FriendlyName(const SymbolTable & symbols) const38 std::string Reference::FriendlyName(const SymbolTable& symbols) const {
39   std::ostringstream out;
40   out << "ref<";
41   if (storage_class_ != ast::StorageClass::kNone) {
42     out << storage_class_ << ", ";
43   }
44   out << subtype_->FriendlyName(symbols) << ", " << access_;
45   out << ">";
46   return out.str();
47 }
48 
49 Reference::Reference(Reference&&) = default;
50 
51 Reference::~Reference() = default;
52 
53 }  // namespace sem
54 }  // namespace tint
55