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_INDEX_H_ 17 #define PANDA_VERIFICATION_TYPE_TYPE_INDEX_H_ 18 19 #include "verification/util/lazy.h" 20 #include "verification/util/relation.h" 21 #include "verification/util/tagged_index.h" 22 23 #include "runtime/include/mem/panda_containers.h" 24 25 namespace panda::verifier { 26 enum class TypeVariance { INVARIANT, COVARIANT, CONTRVARIANT, __LAST__ = CONTRVARIANT }; 27 28 using TypeIdx = size_t; 29 using VectorIdx = PandaVector<TypeIdx>; 30 31 class TypeParamIdx : public TaggedIndex<TypeVariance> { 32 using Base = TaggedIndex<TypeVariance>; 33 34 public: TypeParamIdx(TypeIdx idx,TypeVariance variance)35 TypeParamIdx(TypeIdx idx, TypeVariance variance) : Base {variance, idx} {} 36 ~TypeParamIdx() = default; 37 TypeParamIdx &operator+() 38 { 39 Base::SetTag(TypeVariance::COVARIANT); 40 return *this; 41 } 42 TypeParamIdx &operator-() 43 { 44 Base::SetTag(TypeVariance::CONTRVARIANT); 45 return *this; 46 } 47 TypeParamIdx &operator~() 48 { 49 Base::SetTag(TypeVariance::INVARIANT); 50 return *this; 51 } Variance()52 TypeVariance Variance() const 53 { 54 return Base::GetTag(); 55 } 56 }; 57 58 using TypeParamsIdx = PandaVector<TypeParamIdx>; 59 } // namespace panda::verifier 60 61 #endif // PANDA_VERIFICATION_TYPE_TYPE_INDEX_H_ 62