• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2023-2025 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_PLUGINS_ETS_RUNTIME_TYPES_ETS_BOX_PRIMITIVE_INL_H
17 #define PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_BOX_PRIMITIVE_INL_H
18 
19 #include "macros.h"
20 #include "plugins/ets/runtime/types/ets_box_primitive.h"
21 #include "plugins/ets/runtime/ets_class_linker_extension.h"
22 
23 namespace ark::ets {
24 template <typename T>
Create(EtsCoroutine * coro,T value)25 EtsBoxPrimitive<T> *EtsBoxPrimitive<T>::Create(EtsCoroutine *coro, T value)
26 {
27     auto *instance = reinterpret_cast<EtsBoxPrimitive<T> *>(ObjectHeader::Create(coro, GetBoxClass(coro)));
28     ASSERT(instance != nullptr);
29     instance->SetValue(value);
30     return instance;
31 }
32 
33 template <typename T>
GetEtsBoxClass(EtsCoroutine * coro)34 EtsClass *EtsBoxPrimitive<T>::GetEtsBoxClass(EtsCoroutine *coro)
35 {
36     auto ptypes = PlatformTypes(coro);
37     EtsClass *boxClass = nullptr;
38 
39     if constexpr (std::is_same<T, EtsBoolean>::value) {
40         boxClass = ptypes->coreBoolean;
41     } else if constexpr (std::is_same<T, EtsByte>::value) {
42         boxClass = ptypes->coreByte;
43     } else if constexpr (std::is_same<T, EtsChar>::value) {
44         boxClass = ptypes->coreChar;
45     } else if constexpr (std::is_same<T, EtsShort>::value) {
46         boxClass = ptypes->coreShort;
47     } else if constexpr (std::is_same<T, EtsInt>::value) {
48         boxClass = ptypes->coreInt;
49     } else if constexpr (std::is_same<T, EtsLong>::value) {
50         boxClass = ptypes->coreLong;
51     } else if constexpr (std::is_same<T, EtsFloat>::value) {
52         boxClass = ptypes->coreFloat;
53     } else if constexpr (std::is_same<T, EtsDouble>::value) {
54         boxClass = ptypes->coreDouble;
55     }
56     ASSERT(boxClass != nullptr);
57     ASSERT(boxClass->IsBoxed());
58     return boxClass;
59 }
60 
61 template <typename T>
GetBoxClass(EtsCoroutine * coro)62 Class *EtsBoxPrimitive<T>::GetBoxClass(EtsCoroutine *coro)
63 {
64     return GetEtsBoxClass(coro)->GetRuntimeClass();
65 }
66 
67 }  // namespace ark::ets
68 
69 #endif  // PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_BOX_PRIMITIVE_INL_H
70