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