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