1 /** 2 * Copyright (c) 2021-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_TYPEAPI_METHOD_H_ 17 #define PANDA_PLUGINS_ETS_TYPEAPI_METHOD_H_ 18 19 #include "mem/object_pointer.h" 20 #include "plugins/ets/runtime/types/ets_object.h" 21 #include "plugins/ets/runtime/types/ets_primitives.h" 22 #include "plugins/ets/runtime/types/ets_string.h" 23 #include "plugins/ets/runtime/types/ets_typeapi.h" 24 #include "plugins/ets/runtime/types/ets_typeapi_type.h" 25 26 namespace ark::ets { 27 28 namespace test { 29 class EtsTypeAPITest; 30 } // namespace test 31 32 class EtsCoroutine; 33 34 class EtsTypeAPIMethod : public ObjectHeader { 35 public: 36 EtsTypeAPIMethod() = delete; 37 ~EtsTypeAPIMethod() = delete; 38 39 NO_COPY_SEMANTIC(EtsTypeAPIMethod); 40 NO_MOVE_SEMANTIC(EtsTypeAPIMethod); 41 42 static EtsTypeAPIMethod *Create(EtsCoroutine *etsCoroutine = EtsCoroutine::GetCurrent()); 43 AsObject()44 EtsObject *AsObject() 45 { 46 return EtsObject::FromCoreType(this); 47 } 48 AsObject()49 const EtsObject *AsObject() const 50 { 51 return EtsObject::FromCoreType(this); 52 } 53 FromEtsObject(EtsObject * field)54 static EtsTypeAPIMethod *FromEtsObject(EtsObject *field) 55 { 56 return reinterpret_cast<EtsTypeAPIMethod *>(field); 57 } 58 SetMethodType(EtsTypeAPIType * methodType)59 void SetMethodType(EtsTypeAPIType *methodType) 60 { 61 ASSERT(methodType != nullptr); 62 ObjectAccessor::SetObject(this, MEMBER_OFFSET(EtsTypeAPIMethod, methodType_), methodType->GetCoreType()); 63 } 64 SetName(EtsString * name)65 void SetName(EtsString *name) 66 { 67 ASSERT(name != nullptr); 68 ObjectAccessor::SetObject(this, MEMBER_OFFSET(EtsTypeAPIMethod, name_), name->AsObject()->GetCoreType()); 69 } 70 SetAccessMod(EtsTypeAPIAccessModifier accessMod)71 void SetAccessMod(EtsTypeAPIAccessModifier accessMod) 72 { 73 ObjectAccessor::SetPrimitive(this, MEMBER_OFFSET(EtsTypeAPIMethod, accessMod_), accessMod); 74 } 75 SetAttributes(EtsInt attr)76 void SetAttributes(EtsInt attr) 77 { 78 ObjectAccessor::SetPrimitive(this, MEMBER_OFFSET(EtsTypeAPIMethod, attr_), attr); 79 } 80 81 private: 82 ObjectPointer<EtsTypeAPIType> methodType_; 83 ObjectPointer<EtsString> name_; 84 FIELD_UNUSED EtsInt attr_; // note alignment 85 FIELD_UNUSED EtsByte accessMod_; 86 87 friend class test::EtsTypeAPITest; 88 }; 89 90 } // namespace ark::ets 91 92 #endif // PANDA_PLUGINS_ETS_TYPEAPI_METHOD_H 93