Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gdscript/gdscript.h
20871 views
1
/**************************************************************************/
2
/* gdscript.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 "gdscript_function.h"
34
35
#include "core/debugger/engine_debugger.h"
36
#include "core/debugger/script_debugger.h"
37
#include "core/doc_data.h"
38
#include "core/io/resource_loader.h"
39
#include "core/io/resource_saver.h"
40
#include "core/object/script_language.h"
41
#include "core/templates/rb_set.h"
42
43
class GDScriptNativeClass : public RefCounted {
44
GDCLASS(GDScriptNativeClass, RefCounted);
45
46
StringName name;
47
48
protected:
49
bool _get(const StringName &p_name, Variant &r_ret) const;
50
static void _bind_methods();
51
52
public:
53
_FORCE_INLINE_ const StringName &get_name() const { return name; }
54
Variant _new();
55
Object *instantiate();
56
virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override;
57
GDScriptNativeClass(const StringName &p_name);
58
};
59
60
class GDScript : public Script {
61
GDCLASS(GDScript, Script);
62
bool tool = false;
63
bool valid = false;
64
bool reloading = false;
65
bool _is_abstract = false;
66
67
struct MemberInfo {
68
int index = 0;
69
StringName setter;
70
StringName getter;
71
GDScriptDataType data_type;
72
PropertyInfo property_info;
73
};
74
75
struct ClearData {
76
RBSet<GDScriptFunction *> functions;
77
RBSet<Ref<Script>> scripts;
78
void clear() {
79
functions.clear();
80
scripts.clear();
81
}
82
};
83
84
friend class GDScriptInstance;
85
friend class GDScriptFunction;
86
friend class GDScriptAnalyzer;
87
friend class GDScriptCompiler;
88
friend class GDScriptDocGen;
89
friend class GDScriptLambdaCallable;
90
friend class GDScriptLambdaSelfCallable;
91
friend class GDScriptLanguage;
92
friend struct GDScriptUtilityFunctionsDefinitions;
93
94
Ref<GDScriptNativeClass> native;
95
Ref<GDScript> base;
96
GDScript *_owner = nullptr; //for subclasses
97
98
// Members are just indices to the instantiated script.
99
HashMap<StringName, MemberInfo> member_indices; // Includes member info of all base GDScript classes.
100
HashSet<StringName> members; // Only members of the current class.
101
102
// Only static variables of the current class.
103
HashMap<StringName, MemberInfo> static_variables_indices;
104
Vector<Variant> static_variables; // Static variable values.
105
106
HashMap<StringName, Variant> constants;
107
HashMap<StringName, GDScriptFunction *> member_functions;
108
HashMap<StringName, Ref<GDScript>> subclasses;
109
HashMap<StringName, MethodInfo> _signals;
110
Dictionary rpc_config;
111
112
public:
113
struct LambdaInfo {
114
int capture_count;
115
bool use_self;
116
};
117
118
private:
119
HashMap<GDScriptFunction *, LambdaInfo> lambda_info;
120
121
public:
122
class UpdatableFuncPtr {
123
friend class GDScript;
124
125
GDScriptFunction *ptr = nullptr;
126
GDScript *script = nullptr;
127
List<UpdatableFuncPtr *>::Element *list_element = nullptr;
128
129
public:
130
GDScriptFunction *operator->() const { return ptr; }
131
operator GDScriptFunction *() const { return ptr; }
132
133
UpdatableFuncPtr(GDScriptFunction *p_function);
134
~UpdatableFuncPtr();
135
};
136
137
private:
138
// List is used here because a ptr to elements are stored, so the memory locations need to be stable
139
List<UpdatableFuncPtr *> func_ptrs_to_update;
140
Mutex func_ptrs_to_update_mutex;
141
142
void _recurse_replace_function_ptrs(const HashMap<GDScriptFunction *, GDScriptFunction *> &p_replacements) const;
143
144
#ifdef TOOLS_ENABLED
145
// For static data storage during hot-reloading.
146
HashMap<StringName, MemberInfo> old_static_variables_indices;
147
Vector<Variant> old_static_variables;
148
void _save_old_static_data();
149
void _restore_old_static_data();
150
151
HashMap<StringName, int> member_lines;
152
HashMap<StringName, Variant> member_default_values;
153
List<PropertyInfo> members_cache;
154
HashMap<StringName, Variant> member_default_values_cache;
155
Ref<GDScript> base_cache;
156
HashSet<ObjectID> inheriters_cache;
157
bool source_changed_cache = false;
158
bool placeholder_fallback_enabled = false;
159
void _update_exports_values(HashMap<StringName, Variant> &values, List<PropertyInfo> &propnames);
160
161
StringName doc_class_name;
162
DocData::ClassDoc doc;
163
Vector<DocData::ClassDoc> docs;
164
void _add_doc(const DocData::ClassDoc &p_doc);
165
void _clear_doc();
166
#endif
167
168
GDScriptFunction *initializer = nullptr; // Direct pointer to `new()`/`_init()` member function, faster to locate.
169
170
GDScriptFunction *implicit_initializer = nullptr; // `@implicit_new()` special function.
171
GDScriptFunction *implicit_ready = nullptr; // `@implicit_ready()` special function.
172
GDScriptFunction *static_initializer = nullptr; // `@static_initializer()` special function.
173
174
Error _static_init();
175
void _static_default_init(); // Initialize static variables with default values based on their types.
176
177
RBSet<Object *> instances;
178
bool destructing = false;
179
bool clearing = false;
180
//exported members
181
String source;
182
Vector<uint8_t> binary_tokens;
183
String path;
184
bool path_valid = false; // False if using default path.
185
StringName local_name; // Inner class identifier or `class_name`.
186
StringName global_name; // `class_name`.
187
String fully_qualified_name;
188
String simplified_icon_path;
189
SelfList<GDScript> script_list;
190
191
SelfList<GDScriptFunctionState>::List pending_func_states;
192
193
GDScriptFunction *_super_constructor(GDScript *p_script);
194
void _super_implicit_constructor(GDScript *p_script, GDScriptInstance *p_instance, Callable::CallError &r_error);
195
GDScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, Callable::CallError &r_error);
196
197
String _get_debug_path() const;
198
199
#ifdef TOOLS_ENABLED
200
HashSet<PlaceHolderScriptInstance *> placeholders;
201
//void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
202
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override;
203
void _update_exports_down(bool p_base_exports_changed);
204
#endif
205
206
#ifdef DEBUG_ENABLED
207
HashMap<ObjectID, List<Pair<StringName, Variant>>> pending_reload_state;
208
#endif
209
210
bool _update_exports(bool *r_err = nullptr, bool p_recursive_call = false, PlaceHolderScriptInstance *p_instance_to_update = nullptr, bool p_base_exports_changed = false);
211
212
void _save_orphaned_subclasses();
213
214
void _get_script_property_list(List<PropertyInfo> *r_list, bool p_include_base) const;
215
void _get_script_method_list(List<MethodInfo> *r_list, bool p_include_base) const;
216
void _get_script_signal_list(List<MethodInfo> *r_list, bool p_include_base) const;
217
218
protected:
219
bool _get(const StringName &p_name, Variant &r_ret) const;
220
bool _set(const StringName &p_name, const Variant &p_value);
221
void _get_property_list(List<PropertyInfo> *p_properties) const;
222
223
Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override;
224
225
static void _bind_methods();
226
227
public:
228
#ifdef DEBUG_ENABLED
229
static String debug_get_script_name(const Ref<Script> &p_script);
230
#endif
231
232
static String canonicalize_path(const String &p_path);
233
_FORCE_INLINE_ static bool is_canonically_equal_paths(const String &p_path_a, const String &p_path_b) {
234
return canonicalize_path(p_path_a) == canonicalize_path(p_path_b);
235
}
236
237
_FORCE_INLINE_ StringName get_local_name() const { return local_name; }
238
239
void clear();
240
241
// Cancels all functions of the script that are are waiting to be resumed after using await.
242
void cancel_pending_functions(bool warn);
243
244
virtual bool is_valid() const override { return valid; }
245
246
bool inherits_script(const Ref<Script> &p_script) const override;
247
248
GDScript *find_class(const String &p_qualified_name);
249
bool has_class(const GDScript *p_script);
250
GDScript *get_root_script();
251
bool is_root_script() const { return _owner == nullptr; }
252
String get_fully_qualified_name() const { return fully_qualified_name; }
253
const HashMap<StringName, Ref<GDScript>> &get_subclasses() const { return subclasses; }
254
const HashMap<StringName, Variant> &get_constants() const { return constants; }
255
const HashSet<StringName> &get_members() const { return members; }
256
const GDScriptDataType &get_member_type(const StringName &p_member) const {
257
CRASH_COND(!member_indices.has(p_member));
258
return member_indices[p_member].data_type;
259
}
260
const Ref<GDScriptNativeClass> &get_native() const { return native; }
261
262
_FORCE_INLINE_ const HashMap<StringName, GDScriptFunction *> &get_member_functions() const { return member_functions; }
263
_FORCE_INLINE_ const HashMap<GDScriptFunction *, LambdaInfo> &get_lambda_info() const { return lambda_info; }
264
265
_FORCE_INLINE_ const GDScriptFunction *get_implicit_initializer() const { return implicit_initializer; }
266
_FORCE_INLINE_ const GDScriptFunction *get_implicit_ready() const { return implicit_ready; }
267
_FORCE_INLINE_ const GDScriptFunction *get_static_initializer() const { return static_initializer; }
268
269
virtual bool has_script_signal(const StringName &p_signal) const override;
270
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override;
271
272
bool is_tool() const override { return tool; }
273
bool is_abstract() const override { return _is_abstract; }
274
Ref<GDScript> get_base() const;
275
276
const HashMap<StringName, MemberInfo> &debug_get_member_indices() const { return member_indices; }
277
const HashMap<StringName, GDScriptFunction *> &debug_get_member_functions() const; //this is debug only
278
StringName debug_get_member_by_index(int p_idx) const;
279
StringName debug_get_static_var_by_index(int p_idx) const;
280
281
Variant _new(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
282
virtual bool can_instantiate() const override;
283
284
virtual Ref<Script> get_base_script() const override;
285
virtual StringName get_global_name() const override;
286
287
virtual StringName get_instance_base_type() const override; // this may not work in all scripts, will return empty if so
288
virtual ScriptInstance *instance_create(Object *p_this) override;
289
virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override;
290
virtual bool instance_has(const Object *p_this) const override;
291
292
virtual bool has_source_code() const override;
293
virtual String get_source_code() const override;
294
virtual void set_source_code(const String &p_code) override;
295
virtual void update_exports() override;
296
297
#ifdef TOOLS_ENABLED
298
virtual StringName get_doc_class_name() const override { return doc_class_name; }
299
virtual Vector<DocData::ClassDoc> get_documentation() const override { return docs; }
300
virtual String get_class_icon_path() const override;
301
#endif // TOOLS_ENABLED
302
303
virtual Error reload(bool p_keep_state = false) override;
304
305
virtual void set_path_cache(const String &p_path) override;
306
virtual void set_path(const String &p_path, bool p_take_over = false) override;
307
String get_script_path() const;
308
Error load_source_code(const String &p_path);
309
310
void set_binary_tokens_source(const Vector<uint8_t> &p_binary_tokens);
311
const Vector<uint8_t> &get_binary_tokens_source() const;
312
Vector<uint8_t> get_as_binary_tokens() const;
313
314
bool get_property_default_value(const StringName &p_property, Variant &r_value) const override;
315
316
virtual void get_script_method_list(List<MethodInfo> *p_list) const override;
317
virtual bool has_method(const StringName &p_method) const override;
318
virtual bool has_static_method(const StringName &p_method) const override;
319
320
virtual int get_script_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const override;
321
322
virtual MethodInfo get_method_info(const StringName &p_method) const override;
323
324
virtual void get_script_property_list(List<PropertyInfo> *p_list) const override;
325
326
virtual ScriptLanguage *get_language() const override;
327
328
virtual int get_member_line(const StringName &p_member) const override {
329
#ifdef TOOLS_ENABLED
330
if (member_lines.has(p_member)) {
331
return member_lines[p_member];
332
}
333
#endif
334
return -1;
335
}
336
337
virtual void get_constants(HashMap<StringName, Variant> *p_constants) override;
338
virtual void get_members(HashSet<StringName> *p_members) override;
339
340
virtual const Variant get_rpc_config() const override;
341
342
#ifdef TOOLS_ENABLED
343
virtual bool is_placeholder_fallback_enabled() const override { return placeholder_fallback_enabled; }
344
#endif
345
346
GDScript();
347
~GDScript();
348
};
349
350
class GDScriptInstance : public ScriptInstance {
351
friend class GDScript;
352
friend class GDScriptFunction;
353
friend class GDScriptLambdaCallable;
354
friend class GDScriptLambdaSelfCallable;
355
friend class GDScriptCompiler;
356
friend class GDScriptCache;
357
friend struct GDScriptUtilityFunctionsDefinitions;
358
359
ObjectID owner_id;
360
Object *owner = nullptr;
361
Ref<GDScript> script;
362
#ifdef DEBUG_ENABLED
363
HashMap<StringName, int> member_indices_cache; //used only for hot script reloading
364
#endif
365
Vector<Variant> members;
366
367
SelfList<GDScriptFunctionState>::List pending_func_states;
368
369
void _call_implicit_ready_recursively(GDScript *p_script);
370
371
public:
372
virtual Object *get_owner() { return owner; }
373
374
virtual bool set(const StringName &p_name, const Variant &p_value);
375
virtual bool get(const StringName &p_name, Variant &r_ret) const;
376
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
377
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const;
378
virtual void validate_property(PropertyInfo &p_property) const;
379
380
virtual bool property_can_revert(const StringName &p_name) const;
381
virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const;
382
383
virtual void get_method_list(List<MethodInfo> *p_list) const;
384
virtual bool has_method(const StringName &p_method) const;
385
386
virtual int get_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const;
387
388
virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
389
390
Variant debug_get_member_by_index(int p_idx) const { return members[p_idx]; }
391
392
virtual void notification(int p_notification, bool p_reversed = false);
393
String to_string(bool *r_valid);
394
395
virtual Ref<Script> get_script() const;
396
397
virtual ScriptLanguage *get_language();
398
399
void set_path(const String &p_path);
400
401
void reload_members();
402
403
virtual const Variant get_rpc_config() const;
404
405
GDScriptInstance() {}
406
~GDScriptInstance();
407
};
408
409
class GDScriptLanguage : public ScriptLanguage {
410
friend class GDScriptFunctionState;
411
412
static GDScriptLanguage *singleton;
413
414
bool finishing = false;
415
416
Variant *_global_array = nullptr;
417
Vector<Variant> global_array;
418
HashMap<StringName, int> globals;
419
HashMap<StringName, Variant> named_globals;
420
Vector<int> global_array_empty_indexes;
421
422
struct CallLevel {
423
Variant *stack = nullptr;
424
GDScriptFunction *function = nullptr;
425
GDScriptInstance *instance = nullptr;
426
int *ip = nullptr;
427
int *line = nullptr;
428
CallLevel *prev = nullptr; // Reverse linked list (stack).
429
};
430
431
static thread_local int _debug_parse_err_line;
432
static thread_local String _debug_parse_err_file;
433
static thread_local String _debug_error;
434
435
static thread_local CallLevel *_call_stack;
436
static thread_local uint32_t _call_stack_size;
437
uint32_t _debug_max_call_stack = 0;
438
439
bool track_call_stack = false;
440
bool track_locals = false;
441
442
static CallLevel *_get_stack_level(uint32_t p_level);
443
444
void _add_global(const StringName &p_name, const Variant &p_value);
445
void _remove_global(const StringName &p_name);
446
447
String _get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path, bool *r_is_abstract, bool *r_is_tool, LocalVector<String> &r_visited) const;
448
449
friend class GDScriptInstance;
450
451
Mutex mutex;
452
453
friend class GDScript;
454
455
SelfList<GDScript>::List script_list;
456
friend class GDScriptFunction;
457
458
SelfList<GDScriptFunction>::List function_list;
459
#ifdef DEBUG_ENABLED
460
bool profiling;
461
bool profile_native_calls;
462
uint64_t script_frame_time;
463
#endif
464
465
HashMap<String, ObjectID> orphan_subclasses;
466
467
#ifdef TOOLS_ENABLED
468
void _extension_loaded(const Ref<GDExtension> &p_extension);
469
void _extension_unloading(const Ref<GDExtension> &p_extension);
470
#endif
471
472
public:
473
bool debug_break(const String &p_error, bool p_allow_continue = true);
474
bool debug_break_parse(const String &p_file, int p_line, const String &p_error);
475
476
_FORCE_INLINE_ void enter_function(CallLevel *call_level, GDScriptInstance *p_instance, GDScriptFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) {
477
if (!track_call_stack) {
478
return;
479
}
480
481
#ifdef DEBUG_ENABLED
482
ScriptDebugger *script_debugger = EngineDebugger::get_script_debugger();
483
if (script_debugger != nullptr && script_debugger->get_lines_left() > 0 && script_debugger->get_depth() >= 0) {
484
script_debugger->set_depth(script_debugger->get_depth() + 1);
485
}
486
#endif
487
488
if (unlikely(_call_stack_size >= _debug_max_call_stack)) {
489
_debug_error = vformat("Stack overflow (stack size: %s). Check for infinite recursion in your script.", _debug_max_call_stack);
490
491
#ifdef DEBUG_ENABLED
492
if (script_debugger != nullptr) {
493
script_debugger->debug(this);
494
}
495
#endif
496
497
return;
498
}
499
500
call_level->prev = _call_stack;
501
_call_stack = call_level;
502
call_level->stack = p_stack;
503
call_level->instance = p_instance;
504
call_level->function = p_function;
505
call_level->ip = p_ip;
506
call_level->line = p_line;
507
_call_stack_size++;
508
}
509
510
_FORCE_INLINE_ void exit_function() {
511
if (!track_call_stack) {
512
return;
513
}
514
515
#ifdef DEBUG_ENABLED
516
ScriptDebugger *script_debugger = EngineDebugger::get_script_debugger();
517
if (script_debugger && script_debugger->get_lines_left() > 0 && script_debugger->get_depth() >= 0) {
518
script_debugger->set_depth(script_debugger->get_depth() - 1);
519
}
520
#endif
521
522
if (unlikely(_call_stack_size == 0)) {
523
#ifdef DEBUG_ENABLED
524
if (script_debugger) {
525
_debug_error = "Stack Underflow (Engine Bug)";
526
script_debugger->debug(this);
527
} else {
528
ERR_PRINT("Stack underflow! (Engine Bug)");
529
}
530
#else // !DEBUG_ENABLED
531
ERR_PRINT("Stack underflow! (Engine Bug)");
532
#endif
533
return;
534
}
535
536
_call_stack_size--;
537
_call_stack = _call_stack->prev;
538
}
539
540
virtual Vector<StackInfo> debug_get_current_stack_info() override {
541
Vector<StackInfo> csi;
542
csi.resize(_call_stack_size);
543
CallLevel *cl = _call_stack;
544
uint32_t idx = 0;
545
while (cl) {
546
csi.write[idx].line = *cl->line;
547
if (cl->function) {
548
csi.write[idx].func = cl->function->get_name();
549
csi.write[idx].file = cl->function->get_script()->get_script_path();
550
}
551
idx++;
552
cl = cl->prev;
553
}
554
return csi;
555
}
556
557
struct {
558
StringName _init;
559
StringName _static_init;
560
StringName _notification;
561
StringName _set;
562
StringName _get;
563
StringName _get_property_list;
564
StringName _validate_property;
565
StringName _property_can_revert;
566
StringName _property_get_revert;
567
StringName _script_source;
568
569
} strings;
570
571
_FORCE_INLINE_ bool should_track_call_stack() const { return track_call_stack; }
572
_FORCE_INLINE_ bool should_track_locals() const { return track_locals; }
573
_FORCE_INLINE_ int get_global_array_size() const { return global_array.size(); }
574
_FORCE_INLINE_ Variant *get_global_array() { return _global_array; }
575
_FORCE_INLINE_ const HashMap<StringName, int> &get_global_map() const { return globals; }
576
_FORCE_INLINE_ const HashMap<StringName, Variant> &get_named_globals_map() const { return named_globals; }
577
// These two functions should be used when behavior needs to be consistent between in-editor and running the scene
578
bool has_any_global_constant(const StringName &p_name) { return named_globals.has(p_name) || globals.has(p_name); }
579
Variant get_any_global_constant(const StringName &p_name);
580
581
_FORCE_INLINE_ static GDScriptLanguage *get_singleton() { return singleton; }
582
583
virtual String get_name() const override;
584
585
/* LANGUAGE FUNCTIONS */
586
virtual void init() override;
587
virtual String get_type() const override;
588
virtual String get_extension() const override;
589
virtual void finish() override;
590
591
/* EDITOR FUNCTIONS */
592
virtual Vector<String> get_reserved_words() const override;
593
virtual bool is_control_flow_keyword(const String &p_keywords) const override;
594
virtual Vector<String> get_comment_delimiters() const override;
595
virtual Vector<String> get_doc_comment_delimiters() const override;
596
virtual Vector<String> get_string_delimiters() const override;
597
virtual bool is_using_templates() override;
598
virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const override;
599
virtual Vector<ScriptTemplate> get_built_in_templates(const StringName &p_object) override;
600
virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override;
601
virtual bool supports_builtin_mode() const override;
602
virtual bool supports_documentation() const override;
603
virtual bool can_inherit_from_file() const override { return true; }
604
virtual int find_function(const String &p_function, const String &p_code) const override;
605
virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const override;
606
virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) override;
607
#ifdef TOOLS_ENABLED
608
virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) override;
609
#endif
610
virtual String _get_indentation() const;
611
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override;
612
virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) override;
613
virtual void add_named_global_constant(const StringName &p_name, const Variant &p_value) override;
614
virtual void remove_named_global_constant(const StringName &p_name) override;
615
616
/* DEBUGGER FUNCTIONS */
617
618
virtual String debug_get_error() const override;
619
virtual int debug_get_stack_level_count() const override;
620
virtual int debug_get_stack_level_line(int p_level) const override;
621
virtual String debug_get_stack_level_function(int p_level) const override;
622
virtual String debug_get_stack_level_source(int p_level) const override;
623
virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
624
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
625
virtual ScriptInstance *debug_get_stack_level_instance(int p_level) override;
626
virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
627
virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1) override;
628
629
virtual void reload_all_scripts() override;
630
virtual void reload_scripts(const Array &p_scripts, bool p_soft_reload) override;
631
virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override;
632
633
virtual void frame() override;
634
635
virtual void get_public_functions(List<MethodInfo> *p_functions) const override;
636
virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const override;
637
virtual void get_public_annotations(List<MethodInfo> *p_annotations) const override;
638
639
virtual void profiling_start() override;
640
virtual void profiling_stop() override;
641
virtual void profiling_set_save_native_calls(bool p_enable) override;
642
void profiling_collate_native_call_data(bool p_accumulated);
643
644
virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override;
645
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override;
646
647
/* LOADER FUNCTIONS */
648
649
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
650
651
/* GLOBAL CLASSES */
652
653
virtual bool handles_global_class_type(const String &p_type) const override;
654
virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr, bool *r_is_abstract = nullptr, bool *r_is_tool = nullptr) const override;
655
656
void add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass);
657
Ref<GDScript> get_orphan_subclass(const String &p_qualified_name);
658
659
Ref<GDScript> get_script_by_fully_qualified_name(const String &p_name);
660
661
GDScriptLanguage();
662
~GDScriptLanguage();
663
};
664
665
class ResourceFormatLoaderGDScript : public ResourceFormatLoader {
666
GDSOFTCLASS(ResourceFormatLoaderGDScript, ResourceFormatLoader);
667
668
public:
669
virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE) override;
670
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
671
virtual bool handles_type(const String &p_type) const override;
672
virtual String get_resource_type(const String &p_path) const override;
673
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false) override;
674
virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes) override;
675
};
676
677
class ResourceFormatSaverGDScript : public ResourceFormatSaver {
678
GDSOFTCLASS(ResourceFormatSaverGDScript, ResourceFormatSaver);
679
680
public:
681
virtual Error save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags = 0) override;
682
virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const override;
683
virtual bool recognize(const Ref<Resource> &p_resource) const override;
684
};
685
686