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