• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 
16 #ifndef PANDA_VERIFICATION_TYPE_TYPE_TYPE_H_
17 #define PANDA_VERIFICATION_TYPE_TYPE_TYPE_H_
18 
19 #include "type_sort.h"
20 #include "type_index.h"
21 #include "type_info.h"
22 
23 #include "type_system_kind.h"
24 
25 namespace panda::verifier {
26 class TypeSystem;
27 class TypeSet;
28 class TypeParam;
29 class TypeParams;
30 
31 class Type {
32 public:
33     Type() = default;
34     Type(const Type &) = default;
35     Type(Type &&) = default;
36     Type &operator=(const Type &) = default;
37     Type &operator=(Type &&) = default;
38     ~Type() = default;
39 
40     bool operator==(const Type &t) const;
41 
42     bool operator!=(const Type &t) const;
43 
44     const Type &operator<<(const Type &t) const;
45 
46     // def subtyping a << (b | c) << d
47     const TypeSet &operator<<(const TypeSet &s) const;
48 
49     // a workaround for absence of mutualy-recursive classes in C++
50     template <typename...>
51     TypeSet operator|(const Type &t) const;
52 
53     template <typename...>
54     TypeParam operator+() const;
55 
56     template <typename...>
57     TypeParam operator-() const;
58 
59     template <typename...>
60     TypeParam operator~() const;
61 
62     // subtyping relation: <=
63     bool operator<=(const Type &rhs) const;
64     bool operator<=(const TypeParams &rhs) const;
65 
66     SortIdx Sort() const;
67 
68     size_t Arity() const;
69 
70     template <typename...>
71     TypeParams Params() const;
72 
73     size_t ParamsSize() const;
74 
75     TypeSystem &GetTypeSystem() const;
76 
77     TypeSystemKind GetTypeSystemKind() const;
78 
79     bool IsValid() const;
80 
81     bool IsTop() const;
82 
83     bool IsBot() const;
84 
85     TypeSet operator&(const Type &rhs) const;
86 
87     TypeSet operator&(const TypeSet &rhs) const;
88 
89     template <typename...>
90     TypeParam operator*(TypeVariance variance) const;
91 
92     template <typename Handler>
93     void ForAllParams(Handler &&handler) const;
94 
95     template <typename Handler>
96     void ForAllSupertypes(Handler &&handler) const;
97 
98     template <typename Handler>
99     void ForAllSupertypesOfSort(SortIdx sort, Handler &&handler) const;
100 
101     template <typename Handler>
102     void ForAllSubtypes(Handler &&handler) const;
103 
104     template <typename Handler>
105     void ForAllSubtypesOfSort(SortIdx sort, Handler &&handler) const;
106 
107 private:
Type(TypeSystemKind kind,TypeIdx idx)108     Type(TypeSystemKind kind, TypeIdx idx) : Idx_ {kind, idx} {}
109 
110     TypeIdx Index() const;
111 
112     TaggedIndex<TypeSystemKind> Idx_;
113 
114     friend class TypeSystem;
115     friend class TypeParam;
116     friend class ParametricType;
117     friend class PandaTypes;
118     friend class TypeSet;
119 
120     template <typename SortNames>
121     friend class TypeImage;
122 
123     friend struct std::hash<Type>;
124 };
125 }  // namespace panda::verifier
126 
127 namespace std {
128 template <>
129 struct hash<panda::verifier::Type> {
130     size_t operator()(const panda::verifier::Type &type) const
131     {
132         return static_cast<size_t>(type.Index());
133     }
134 };
135 }  // namespace std
136 
137 #endif  // PANDA_VERIFICATION_TYPE_TYPE_TYPE_H_
138