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_RUNTIME_FFI_CLASSES_ETS_FIELD_H_ 17 #define PANDA_PLUGINS_ETS_RUNTIME_FFI_CLASSES_ETS_FIELD_H_ 18 19 #include "libpandafile/file.h" 20 #include "plugins/ets/runtime/types/ets_type.h" 21 #include "runtime/include/field.h" 22 23 namespace ark::ets { 24 25 class EtsClass; 26 class EtsString; 27 28 class EtsField { 29 public: 30 EtsClass *GetDeclaringClass() const; 31 32 EtsClass *GetType() const; 33 GetEtsType()34 EtsType GetEtsType() const 35 { 36 return ConvertPandaTypeToEtsType(GetCoreType()->GetType()); 37 } 38 GetAccessFlags()39 uint32_t GetAccessFlags() const 40 { 41 return GetCoreType()->GetAccessFlags(); 42 } 43 GetFieldId()44 uint32_t GetFieldId() const 45 { 46 return GetCoreType()->GetFileId().GetOffset(); 47 } 48 GetOffset()49 size_t GetOffset() const 50 { 51 return GetCoreType()->GetOffset(); 52 } 53 GetRuntimeField()54 Field *GetRuntimeField() 55 { 56 return GetCoreType(); 57 } 58 GetName()59 const char *GetName() const 60 { 61 return reinterpret_cast<const char *>(GetCoreType()->GetName().data); 62 } 63 64 PANDA_PUBLIC_API EtsString *GetNameString() const; 65 IsPublic()66 bool IsPublic() const 67 { 68 return GetCoreType()->IsPublic(); 69 } 70 IsPrivate()71 bool IsPrivate() const 72 { 73 return GetCoreType()->IsPrivate(); 74 } 75 IsProtected()76 bool IsProtected() const 77 { 78 return GetCoreType()->IsProtected(); 79 } 80 IsReadonly()81 bool IsReadonly() const 82 { 83 // NOTE(shumilov-petr): Need to dump extra info in frontend 84 return false; 85 } 86 IsStatic()87 bool IsStatic() const 88 { 89 return GetCoreType()->IsStatic(); 90 } 91 92 bool IsDeclaredIn(const EtsClass *klass) const; 93 FromRuntimeField(Field * field)94 static EtsField *FromRuntimeField(Field *field) 95 { 96 return reinterpret_cast<EtsField *>(field); 97 } 98 FromRuntimeField(const Field * field)99 static const EtsField *FromRuntimeField(const Field *field) 100 { 101 return reinterpret_cast<const EtsField *>(field); 102 } 103 GetCoreType()104 Field *GetCoreType() 105 { 106 return reinterpret_cast<Field *>(this); 107 } 108 GetCoreType()109 const Field *GetCoreType() const 110 { 111 return reinterpret_cast<const Field *>(this); 112 } 113 114 PANDA_PUBLIC_API const char *GetTypeDescriptor() const; 115 116 EtsField() = delete; 117 ~EtsField() = delete; 118 NO_COPY_SEMANTIC(EtsField); 119 NO_MOVE_SEMANTIC(EtsField); 120 }; 121 122 } // namespace ark::ets 123 124 #endif // PANDA_PLUGINS_ETS_RUNTIME_FFI_CLASSES_ETS_FIELD_H_ 125