1 /* 2 * Copyright (c) 2021 - 2023 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 #include "boxingConverter.h" 17 #include "checker/types/ets/types.h" 18 #include "checker/ETSchecker.h" 19 #include "util/helpers.h" 20 #include "checker/ets/primitiveWrappers.h" 21 22 namespace ark::es2panda::checker { 23 ETSTypeFromSource(ETSChecker const *checker, Type const *source)24checker::ETSObjectType *BoxingConverter::ETSTypeFromSource(ETSChecker const *checker, Type const *source) 25 { 26 auto getSignature = [](checker::TypeFlag typeKind) { 27 switch (typeKind) { 28 case checker::TypeFlag::ETS_BOOLEAN: { 29 return compiler::Signatures::BUILTIN_BOOLEAN_CLASS; 30 } 31 case checker::TypeFlag::BYTE: { 32 return compiler::Signatures::BUILTIN_BYTE_CLASS; 33 } 34 case checker::TypeFlag::SHORT: { 35 return compiler::Signatures::BUILTIN_SHORT_CLASS; 36 } 37 case checker::TypeFlag::CHAR: { 38 return compiler::Signatures::BUILTIN_CHAR_CLASS; 39 } 40 case checker::TypeFlag::INT: { 41 return compiler::Signatures::BUILTIN_INT_CLASS; 42 } 43 case checker::TypeFlag::LONG: { 44 return compiler::Signatures::BUILTIN_LONG_CLASS; 45 } 46 case checker::TypeFlag::FLOAT: { 47 return compiler::Signatures::BUILTIN_FLOAT_CLASS; 48 } 49 case checker::TypeFlag::DOUBLE: { 50 return compiler::Signatures::BUILTIN_DOUBLE_CLASS; 51 } 52 default: 53 UNREACHABLE(); 54 } 55 }; 56 57 auto wrapMap = checker->PrimitiveWrapper(); 58 return wrapMap.find(getSignature(checker::ETSChecker::TypeKind(source)))->second.first; 59 } 60 61 } // namespace ark::es2panda::checker 62