• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #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 #include "checker/types/globalTypesHolder.h"
22 
23 namespace ark::es2panda::checker {
24 
Convert(ETSChecker const * checker,Type const * source)25 checker::ETSObjectType *BoxingConverter::Convert(ETSChecker const *checker, Type const *source)
26 {
27     auto typeHolder = checker->GetGlobalTypesHolder();
28 
29     switch (checker::ETSChecker::TypeKind(source)) {
30         case checker::TypeFlag::ETS_BOOLEAN:
31             return typeHolder->GlobalETSBooleanBuiltinType()->AsETSObjectType();
32         case checker::TypeFlag::BYTE:
33             return typeHolder->GlobalByteBuiltinType()->AsETSObjectType();
34         case checker::TypeFlag::SHORT:
35             return typeHolder->GlobalShortBuiltinType()->AsETSObjectType();
36         case checker::TypeFlag::CHAR:
37             return typeHolder->GlobalCharBuiltinType()->AsETSObjectType();
38         case checker::TypeFlag::INT:
39             return typeHolder->GlobalIntegerBuiltinType()->AsETSObjectType();
40         case checker::TypeFlag::LONG:
41             return typeHolder->GlobalLongBuiltinType()->AsETSObjectType();
42         case checker::TypeFlag::FLOAT:
43             return typeHolder->GlobalFloatBuiltinType()->AsETSObjectType();
44         case checker::TypeFlag::DOUBLE:
45             return typeHolder->GlobalDoubleBuiltinType()->AsETSObjectType();
46         case checker::TypeFlag::ETS_INT_ENUM:
47         case checker::TypeFlag::ETS_STRING_ENUM:
48             return source->AsETSEnumType()->BoxedType()->AsETSObjectType();
49         default:
50             UNREACHABLE();
51     }
52 }
53 
54 }  // namespace ark::es2panda::checker
55