libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_call_stack.hpp
1#ifndef GIMBAL_CALL_STACK_HPP
2#define GIMBAL_CALL_STACK_HPP
3
4#include "gimbal_call_stack.h"
5#include "../types/gimbal_typedefs.hpp"
6#include "../types/gimbal_result.hpp"
7//#include "../containers/gimbal_generics.hpp"
8
9
10namespace gbl {
11
13public:
14 SourceLocation(const char* pFile, const char* pFunc, GblSize line, GblSize col):
15 GblSourceLocation{pFile, pFunc, line, col} {}
16
17 SourceLocation(void) {
18 memset(this, 0, sizeof(SourceLocation));
19 }
20 SourceLocation(const GblSourceLocation& rhs) {
21 memcpy(this, &rhs, sizeof(GblSourceLocation));
22 }
23
24 const char* getFilePath(void) const { return pFile; }
25 const char* getFileName(void) const { return pFile; }
26 const char* getFunctionName(void) const { return pFunc; }
27 GblSize getLineNumber(void) const { return line; }
28 GblSize getColumn(void) const { return column; }
29
30 bool isValid(void) const;
31 std::string toPrettyString(void) const;
32
33 //C++20 std::source_location compat
34 //comparison operators (check if further in same file/function)
35
36};
37
38GBL_CHECK_C_CPP_TYPE_COMPAT(SourceLocation, GblSourceLocation);
39
40
41class CallRecord: public GblCallRecord {
42public:
43
44 template<typename R>
46 CallRecord(R resultValue, const char* pMessage=nullptr, GblObject* pObject=nullptr, SourceLocation srcLoc={}) noexcept:
48
49 CallRecord(Result result, const char* pMessage=nullptr, GblObject* pObject=nullptr, SourceLocation srcLoc={}) noexcept;
50
51 CallRecord(const GblCallRecord& other) {
52 memcpy(this, &other, sizeof(GblCallRecord));
53 }
54
55 Handle* getHandle(void) const;
56 Result getResult(void) const { return this->result; }
57 const SourceLocation& getSource(void) const {
58 return static_cast<const SourceLocation&>(srcLocation);
59 }
60
61
62 const char* getMessage(void) const { return message; }
63 std::string getSourceString(void) const;
64
65 std::string toString(void) const;
66
67};
68
69GBL_CHECK_C_CPP_TYPE_COMPAT(CallRecord, GblCallRecord);
70
71
72
73class StackFrame: public GblStackFrame {
74public:
75 StackFrame(GblObject* pObject=nullptr, GBL_RESULT initialResult=GBL_RESULT_UNKNOWN, SourceLocation entryLoc=SourceLocation()) {
76 GBL_API_STACK_FRAME_CONSTRUCT(this, pObject, initialResult, entryLoc);
77
78 }
79 //StackFrame(const GblStackFrame& rhs);
80/*
81 StackFrame& operator=(const GblStackFrame& rhs) {
82 memcpy(this, &rhs, sizeof(GblStackFrame));
83 return *this;
84 }
85*/
86 auto getSourceCurrent(void) const -> const SourceLocation&;
87 auto getSourceEntry(void) const -> const SourceLocation& { return *static_cast<const SourceLocation*>(&sourceEntry);}
88 auto getCallRecord(void) const -> const CallRecord& { return *static_cast<const CallRecord*>(&record); }
89 auto getCallRecord(void) -> CallRecord&;
90 GblObject* getObject(void) const;
91 GblContext* getContext(void) const;
92 void* getHandleUd(void) const;
93 void* getContextUd(void) const;
94
95 bool isValid(void) const;
96};
97
98GBL_CHECK_C_CPP_TYPE_COMPAT(StackFrame, GblStackFrame);
99
100
101inline CallRecord::CallRecord(Result result, const char* pMessage, GblObject* pObject, SourceLocation srcLoc) noexcept {
102 GBL_CALL_RECORD_CONSTRUCT(this, pObject, result.getCode(), srcLoc, "%s", pMessage? pMessage : result.toString());
103}
104
105
106
107}
108
109#endif // GIMBAL_CALL_STACK_HPP