Debian Codegraph @

core/object/script_backtrace.h

raw symbols SCIP
1 /**************************************************************************/
2 /* script_backtrace.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/object/ref_counted.h"
34
35 class ScriptLanguage;
36
37 class ScriptBacktrace : public RefCounted {
38 GDCLASS(ScriptBacktrace, RefCounted);
39
40 struct StackVariable {
41 String name;
42 Variant value;
43 };
44
45 struct StackFrame {
46 LocalVector<StackVariable> local_variables;
47 LocalVector<StackVariable> member_variables;
48 String function;
49 String file;
50 int line = 0;
51 };
52
53 LocalVector<StackFrame> stack_frames;
54 LocalVector<StackVariable> global_variables;
55 String language_name;
56
57 static void _store_variables(const List<String> &p_names, const List<Variant> &p_values, LocalVector<StackVariable> &r_variables);
58
59 protected:
60 static void _bind_methods();
61
62 public:
63 ScriptBacktrace() = default;
64 ScriptBacktrace(ScriptLanguage *p_language, bool p_include_variables = false);
65
66 String get_language_name() const { return language_name; }
67
68 bool is_empty() const { return stack_frames.is_empty(); }
69 int get_frame_count() const { return stack_frames.size(); }
70 String get_frame_function(int p_index) const;
71 String get_frame_file(int p_index) const;
72 int get_frame_line(int p_index) const;
73
74 int get_global_variable_count() const { return global_variables.size(); }
75 String get_global_variable_name(int p_variable_index) const;
76 Variant get_global_variable_value(int p_variable_index) const;
77
78 int get_local_variable_count(int p_frame_index) const;
79 String get_local_variable_name(int p_frame_index, int p_variable_index) const;
80 Variant get_local_variable_value(int p_frame_index, int p_variable_index) const;
81
82 int get_member_variable_count(int p_frame_index) const;
83 String get_member_variable_name(int p_frame_index, int p_variable_index) const;
84 Variant get_member_variable_value(int p_frame_index, int p_variable_index) const;
85
86 String format(int p_indent_all = 0, int p_indent_frames = 4) const;
87 virtual String _to_string() override { return format(); }
88 };