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