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_TYPES_STACKTRACE_ELEMENT_H 17 #define PANDA_PLUGINS_ETS_RUNTIME_TYPES_STACKTRACE_ELEMENT_H 18 19 #include "mem/object_pointer.h" 20 #include "plugins/ets/runtime/types/ets_object.h" 21 #include "plugins/ets/runtime/types/ets_string.h" 22 #include "types/ets_primitives.h" 23 24 namespace ark::ets { 25 26 class EtsStackTraceElement : public ObjectHeader { 27 public: 28 EtsStackTraceElement() = delete; 29 ~EtsStackTraceElement() = delete; 30 31 NO_COPY_SEMANTIC(EtsStackTraceElement); 32 NO_MOVE_SEMANTIC(EtsStackTraceElement); 33 AsObject()34 EtsObject *AsObject() 35 { 36 return EtsObject::FromCoreType(this); 37 } 38 AsObject()39 const EtsObject *AsObject() const 40 { 41 return EtsObject::FromCoreType(this); 42 } 43 SetClassName(EtsString * className)44 inline void SetClassName(EtsString *className) 45 { 46 ObjectAccessor::SetObject(this, MEMBER_OFFSET(EtsStackTraceElement, className_), 47 className->AsObject()->GetCoreType()); 48 } 49 SetMethodName(EtsString * methodName)50 inline void SetMethodName(EtsString *methodName) 51 { 52 ObjectAccessor::SetObject(this, MEMBER_OFFSET(EtsStackTraceElement, methodName_), 53 methodName->AsObject()->GetCoreType()); 54 } 55 SetSourceFileName(EtsString * sourceFileName)56 inline void SetSourceFileName(EtsString *sourceFileName) 57 { 58 ObjectAccessor::SetObject(this, MEMBER_OFFSET(EtsStackTraceElement, sourceFileName_), 59 sourceFileName->AsObject()->GetCoreType()); 60 } 61 SetLineNumber(EtsInt lineNumber)62 inline void SetLineNumber(EtsInt lineNumber) 63 { 64 ObjectAccessor::SetPrimitive(this, MEMBER_OFFSET(EtsStackTraceElement, lineNumber_), lineNumber); 65 } 66 Create(EtsCoroutine * etsCoroutine)67 inline static EtsStackTraceElement *Create(EtsCoroutine *etsCoroutine) 68 { 69 EtsClass *klass = etsCoroutine->GetPandaVM()->GetClassLinker()->GetClass( 70 panda_file_items::class_descriptors::STACK_TRACE_ELEMENT.data()); 71 EtsObject *etsObject = EtsObject::Create(etsCoroutine, klass); 72 return reinterpret_cast<EtsStackTraceElement *>(etsObject); 73 } 74 75 private: 76 ObjectPointer<EtsString> className_; 77 ObjectPointer<EtsString> methodName_; 78 ObjectPointer<EtsString> sourceFileName_; 79 FIELD_UNUSED EtsInt lineNumber_; // note alignment 80 }; 81 82 } // namespace ark::ets 83 #endif