• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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_SUBTYPING_CLOSURE_HPP
17 #define _PANDA_SUBTYPING_CLOSURE_HPP
18 
19 #include "type_sort.h"
20 #include "type_index.h"
21 #include "type_info.h"
22 
23 #include "runtime/include/mem/panda_containers.h"
24 
25 namespace panda::verifier {
26 class SubtypingClosureInfo {
27 public:
28     SubtypingClosureInfo() = default;
29     SubtypingClosureInfo(SubtypingClosureInfo &&) = default;
30     SubtypingClosureInfo(const SubtypingClosureInfo &) = delete;
31     SubtypingClosureInfo &operator=(SubtypingClosureInfo &&) = default;
32     SubtypingClosureInfo &operator=(const SubtypingClosureInfo &) = delete;
33     ~SubtypingClosureInfo() = default;
Empty()34     bool Empty() const
35     {
36         return Empty_;
37     }
Clear()38     void Clear()
39     {
40         for (auto &map_sort_to_type : ArityToSortToTypes_) {
41             for (auto &sort_to_type : map_sort_to_type) {
42                 sort_to_type.second.clear();
43             }
44         }
45         Empty_ = true;
46     }
AddType(SortIdx sort,TypeNum type,size_t arity)47     void AddType(SortIdx sort, TypeNum type, size_t arity)
48     {
49         if (arity >= ArityToSortToTypes_.size()) {
50             ArityToSortToTypes_.resize(arity + 1);
51         }
52         ArityToSortToTypes_[arity][sort].insert(type);
53         Empty_ = false;
54     }
55     template <typename Proc>
ForAllTypeClasses(Proc process)56     void ForAllTypeClasses(Proc process) const
57     {
58         for (auto &map_sort_to_types : ArityToSortToTypes_) {
59             for (auto &sort_to_types : map_sort_to_types) {
60                 process(sort_to_types.second);
61             }
62         }
63     }
swap(SubtypingClosureInfo & other)64     void swap(SubtypingClosureInfo &other)  // NOLINT(readability-identifier-naming)
65     {
66         std::swap(ArityToSortToTypes_, other.ArityToSortToTypes_);
67         std::swap(Empty_, other.Empty_);
68     }
69 
70 private:
71     // arity -> sort -> instances
72     PandaVector<PandaUnorderedMap<SortIdx, PandaUnorderedSet<TypeNum>>> ArityToSortToTypes_;
73     bool Empty_ = true;
74 };
75 }  // namespace panda::verifier
76 
77 #endif  // !_PANDA_SUBTYPING_CLOSURE_HPP
78