1/* 2 * Copyright (c) 2021-2024 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 ES2PANDA_COMPILER_CHECKER_ETS_UNBOXING_CONVERTER_H 17#define ES2PANDA_COMPILER_CHECKER_ETS_UNBOXING_CONVERTER_H 18 19#include "checker/ets/typeConverter.h" 20#include "checker/types/ets/etsObjectType.h" 21 22namespace ark::es2panda::checker { 23 24class UnboxingConverter : public TypeConverter { 25public: 26 UnboxingConverter(ETSChecker *checker, TypeRelation *relation, Type *source) 27 : TypeConverter(checker, relation, nullptr, source) 28 { 29 if (!source->IsETSObjectType()) { 30 relation->Result(false); 31 return; 32 } 33 34 SetResult(GlobalTypeFromSource(checker, source->AsETSObjectType())); 35 relation->Result(source != Result()); 36 } 37 38 UnboxingConverter(ETSChecker *checker, TypeRelation *relation, Type *source, Type *target) 39 : TypeConverter(checker, relation, target, source) 40 { 41 SetResult(Source()); 42 43 if (!Source()->IsETSObjectType() || relation->IsTrue()) { 44 return; 45 } 46 47 SetResult(GlobalTypeFromSource(checker, source->AsETSObjectType())); 48 49 Relation()->Result(Result()->TypeFlags() == target->TypeFlags()); 50 } 51 52 static checker::Type *GlobalTypeFromSource(checker::ETSChecker const *checker, ETSObjectType *type); 53}; 54} // namespace ark::es2panda::checker 55 56#endif 57