• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SRC_SEM_POINTER_TYPE_H_
16 #define SRC_SEM_POINTER_TYPE_H_
17 
18 #include <string>
19 
20 #include "src/ast/access.h"
21 #include "src/ast/storage_class.h"
22 #include "src/sem/type.h"
23 
24 namespace tint {
25 namespace sem {
26 
27 /// A pointer type.
28 class Pointer : public Castable<Pointer, Type> {
29  public:
30   /// Constructor
31   /// @param subtype the pointee type
32   /// @param storage_class the storage class of the pointer
33   /// @param access the resolved access control of the reference
34   Pointer(const Type* subtype,
35           ast::StorageClass storage_class,
36           ast::Access access);
37 
38   /// Move constructor
39   Pointer(Pointer&&);
40   ~Pointer() override;
41 
42   /// @returns the pointee type
StoreType()43   const Type* StoreType() const { return subtype_; }
44 
45   /// @returns the storage class of the pointer
StorageClass()46   ast::StorageClass StorageClass() const { return storage_class_; }
47 
48   /// @returns the access control of the reference
Access()49   ast::Access Access() const { return access_; }
50 
51   /// @returns the name for this type
52   std::string type_name() const override;
53 
54   /// @param symbols the program's symbol table
55   /// @returns the name for this type that closely resembles how it would be
56   /// declared in WGSL.
57   std::string FriendlyName(const SymbolTable& symbols) const override;
58 
59  private:
60   Type const* const subtype_;
61   ast::StorageClass const storage_class_;
62   ast::Access const access_;
63 };
64 
65 }  // namespace sem
66 }  // namespace tint
67 
68 #endif  // SRC_SEM_POINTER_TYPE_H_
69