Debian Codegraph @

modules/gdscript/gdscript.h

raw symbols SCIP
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 void unload_static() const;
343
344 #ifdef TOOLS_ENABLED
345 virtual bool is_placeholder_fallback_enabled() const override { return placeholder_fallback_enabled; }
346 #endif
347
348 GDScript();
349 ~GDScript();
350 };
351
352 class GDScriptInstance : public ScriptInstance {
353 friend class GDScript;
354 friend class GDScriptFunction;
355 friend class GDScriptLambdaCallable;
356 friend class GDScriptLambdaSelfCallable;
357 friend class GDScriptCompiler;
358 friend class GDScriptCache;
359 friend struct GDScriptUtilityFunctionsDefinitions;
360
361 ObjectID owner_id;
362 Object *owner = nullptr;
363 Ref<GDScript> script;
364 #ifdef DEBUG_ENABLED
365 HashMap<StringName, int> member_indices_cache; //used only for hot script reloading
366 #endif
367 Vector<Variant> members;
368
369 SelfList<GDScriptFunctionState>::List pending_func_states;
370
371 void _call_implicit_ready_recursively(GDScript *p_script);
372
373 public:
374 virtual Object *get_owner() { return owner; }
375
376 virtual bool set(const StringName &p_name, const Variant &p_value);
377 virtual bool get(const StringName &p_name, Variant &r_ret) const;
378 virtual void get_property_list(List<PropertyInfo> *p_properties) const;
379 virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const;
380 virtual void validate_property(PropertyInfo &p_property) const;
381
382 virtual bool property_can_revert(const StringName &p_name) const;
383 virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const;
384
385 virtual void get_method_list(List<MethodInfo> *p_list) const;
386 virtual bool has_method(const StringName &p_method) const;
387
388 virtual int get_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const;
389
390 virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
391
392 Variant debug_get_member_by_index(int p_idx) const { return members[p_idx]; }
393
394 virtual void notification(int p_notification, bool p_reversed = false);
395 String to_string(bool *r_valid);
396
397 virtual Ref<Script> get_script() const;
398
399 virtual ScriptLanguage *get_language();
400
401 void set_path(const String &p_path);
402
403 void reload_members();
404
405 virtual const Variant get_rpc_config() const;
406
407 GDScriptInstance() {}
408 ~GDScriptInstance();
409 };
410
411 class GDScriptLanguage : public ScriptLanguage {
412 friend class GDScriptFunctionState;
413
414 static GDScriptLanguage *singleton;
415
416 bool finishing = false;
417
418 Variant *_global_array = nullptr;
419 Vector<Variant> global_array;
420 HashMap<StringName, int> globals;
421 HashMap<StringName, Variant> named_globals;
422 Vector<int> global_array_empty_indexes;
423
424 struct CallLevel {
425 Variant *stack = nullptr;
426 GDScriptFunction *function = nullptr;
427 GDScriptInstance *instance = nullptr;
428 int *ip = nullptr;
429 int *line = nullptr;
430 CallLevel *prev = nullptr; // Reverse linked list (stack).
431 };
432
433 static thread_local int _debug_parse_err_line;
434 static thread_local String _debug_parse_err_file;
435 static thread_local String _debug_error;
436
437 static thread_local CallLevel *_call_stack;
438 static thread_local uint32_t _call_stack_size;
439 uint32_t _debug_max_call_stack = 0;
440
441 bool track_call_stack = false;
442 bool track_locals = false;
443
444 static CallLevel *_get_stack_level(uint32_t p_level);
445
446 void _add_global(const StringName &p_name, const Variant &p_value);
447 void _remove_global(const StringName &p_name);
448
449 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;
450
451 friend class GDScriptInstance;
452
453 Mutex mutex;
454
455 friend class GDScript;
456
457 SelfList<GDScript>::List script_list;
458 friend class GDScriptFunction;
459
460 SelfList<GDScriptFunction>::List function_list;
461 #ifdef DEBUG_ENABLED
462 bool profiling;
463 bool profile_native_calls;
464 uint64_t script_frame_time;
465 #endif
466
467 HashMap<String, ObjectID> orphan_subclasses;
468
469 #ifdef TOOLS_ENABLED
470 void _extension_loaded(const Ref<GDExtension> &p_extension);
471 void _extension_unloading(const Ref<GDExtension> &p_extension);
472 #endif
473
474 public:
475 bool debug_break(const String &p_error, bool p_allow_continue = true);
476 bool debug_break_parse(const String &p_file, int p_line, const String &p_error);
477
478 _FORCE_INLINE_ void enter_function(CallLevel *call_level, GDScriptInstance *p_instance, GDScriptFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) {
479 if (!track_call_stack) {
480 return;
481 }
482
483 #ifdef DEBUG_ENABLED
484 ScriptDebugger *script_debugger = EngineDebugger::get_script_debugger();
485 if (script_debugger != nullptr && script_debugger->get_lines_left() > 0 && script_debugger->get_depth() >= 0) {
486 script_debugger->set_depth(script_debugger->get_depth() + 1);
487 }
488 #endif
489
490 if (unlikely(_call_stack_size >= _debug_max_call_stack)) {
491 _debug_error = vformat("Stack overflow (stack size: %s). Check for infinite recursion in your script.", _debug_max_call_stack);
492
493 #ifdef DEBUG_ENABLED
494 if (script_debugger != nullptr) {
495 script_debugger->debug(this);
496 }
497 #endif
498
499 return;
500 }
501
502 call_level->prev = _call_stack;
503 _call_stack = call_level;
504 call_level->stack = p_stack;
505 call_level->instance = p_instance;
506 call_level->function = p_function;
507 call_level->ip = p_ip;
508 call_level->line = p_line;
509 _call_stack_size++;
510 }
511
512 _FORCE_INLINE_ void exit_function() {
513 if (!track_call_stack) {
514 return;
515 }
516
517 #ifdef DEBUG_ENABLED
518 ScriptDebugger *script_debugger = EngineDebugger::get_script_debugger();
519 if (script_debugger && script_debugger->get_lines_left() > 0 && script_debugger->get_depth() >= 0) {
520 script_debugger->set_depth(script_debugger->get_depth() - 1);
521 }
522 #endif
523
524 if (unlikely(_call_stack_size == 0)) {
525 #ifdef DEBUG_ENABLED
526 if (script_debugger) {
527 _debug_error = "Stack Underflow (Engine Bug)";
528 script_debugger->debug(this);
529 } else {
530 ERR_PRINT("Stack underflow! (Engine Bug)");
531 }
532 #else // !DEBUG_ENABLED
533 ERR_PRINT("Stack underflow! (Engine Bug)");
534 #endif
535 return;
536 }
537
538 _call_stack_size--;
539 _call_stack = _call_stack->prev;
540 }
541
542 virtual Vector<StackInfo> debug_get_current_stack_info() override {
543 Vector<StackInfo> csi;
544 csi.resize(_call_stack_size);
545 CallLevel *cl = _call_stack;
546 uint32_t idx = 0;
547 while (cl) {
548 csi.write[idx].line = *cl->line;
549 if (cl->function) {
550 csi.write[idx].func = cl->function->get_name();
551 csi.write[idx].file = cl->function->get_script()->get_script_path();
552 }
553 idx++;
554 cl = cl->prev;
555 }
556 return csi;
557 }
558
559 struct {
560 StringName _init;
561 StringName _static_init;
562 StringName _notification;
563 StringName _set;
564 StringName _get;
565 StringName _get_property_list;
566 StringName _validate_property;
567 StringName _property_can_revert;
568 StringName _property_get_revert;
569 StringName _script_source;
570
571 } strings;
572
573 _FORCE_INLINE_ bool should_track_call_stack() const { return track_call_stack; }
574 _FORCE_INLINE_ bool should_track_locals() const { return track_locals; }
575 _FORCE_INLINE_ int get_global_array_size() const { return global_array.size(); }
576 _FORCE_INLINE_ Variant *get_global_array() { return _global_array; }
577 _FORCE_INLINE_ const HashMap<StringName, int> &get_global_map() const { return globals; }
578 _FORCE_INLINE_ const HashMap<StringName, Variant> &get_named_globals_map() const { return named_globals; }
579 // These two functions should be used when behavior needs to be consistent between in-editor and running the scene
580 bool has_any_global_constant(const StringName &p_name) { return named_globals.has(p_name) || globals.has(p_name); }
581 Variant get_any_global_constant(const StringName &p_name);
582
583 _FORCE_INLINE_ static GDScriptLanguage *get_singleton() { return singleton; }
584
585 virtual String get_name() const override;
586
587 /* LANGUAGE FUNCTIONS */
588 virtual void init() override;
589 virtual String get_type() const override;
590 virtual String get_extension() const override;
591 virtual void finish() override;
592
593 /* EDITOR FUNCTIONS */
594 virtual Vector<String> get_reserved_words() const override;
595 virtual bool is_control_flow_keyword(const String &p_keywords) const override;
596 virtual Vector<String> get_comment_delimiters() const override;
597 virtual Vector<String> get_doc_comment_delimiters() const override;
598 virtual Vector<String> get_string_delimiters() const override;
599 virtual bool is_using_templates() override;
600 virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const override;
601 virtual Vector<ScriptTemplate> get_built_in_templates(const StringName &p_object) override;
602 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;
603 virtual Script *create_script() const override;
604 virtual bool supports_builtin_mode() const override;
605 virtual bool supports_documentation() const override;
606 virtual bool can_inherit_from_file() const override { return true; }
607 virtual int find_function(const String &p_function, const String &p_code) const override;
608 virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const override;
609 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;
610 #ifdef TOOLS_ENABLED
611 virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) override;
612 #endif
613 virtual String _get_indentation() const;
614 virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override;
615 virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) override;
616 virtual void add_named_global_constant(const StringName &p_name, const Variant &p_value) override;
617 virtual void remove_named_global_constant(const StringName &p_name) override;
618
619 /* DEBUGGER FUNCTIONS */
620
621 virtual String debug_get_error() const override;
622 virtual int debug_get_stack_level_count() const override;
623 virtual int debug_get_stack_level_line(int p_level) const override;
624 virtual String debug_get_stack_level_function(int p_level) const override;
625 virtual String debug_get_stack_level_source(int p_level) const override;
626 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;
627 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;
628 virtual ScriptInstance *debug_get_stack_level_instance(int p_level) override;
629 virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
630 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;
631
632 virtual void reload_all_scripts() override;
633 virtual void reload_scripts(const Array &p_scripts, bool p_soft_reload) override;
634 virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override;
635
636 virtual void frame() override;
637
638 virtual void get_public_functions(List<MethodInfo> *p_functions) const override;
639 virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const override;
640 virtual void get_public_annotations(List<MethodInfo> *p_annotations) const override;
641
642 virtual void profiling_start() override;
643 virtual void profiling_stop() override;
644 virtual void profiling_set_save_native_calls(bool p_enable) override;
645 void profiling_collate_native_call_data(bool p_accumulated);
646
647 virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override;
648 virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override;
649
650 /* LOADER FUNCTIONS */
651
652 virtual void get_recognized_extensions(List<String> *p_extensions) const override;
653
654 /* GLOBAL CLASSES */
655
656 virtual bool handles_global_class_type(const String &p_type) const override;
657 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;
658
659 void add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass);
660 Ref<GDScript> get_orphan_subclass(const String &p_qualified_name);
661
662 Ref<GDScript> get_script_by_fully_qualified_name(const String &p_name);
663
664 GDScriptLanguage();
665 ~GDScriptLanguage();
666 };
667
668 class ResourceFormatLoaderGDScript : public ResourceFormatLoader {
669 GDSOFTCLASS(ResourceFormatLoaderGDScript, ResourceFormatLoader);
670
671 public:
672 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;
673 virtual void get_recognized_extensions(List<String> *p_extensions) const override;
674 virtual bool handles_type(const String &p_type) const override;
675 virtual String get_resource_type(const String &p_path) const override;
676 virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false) override;
677 virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes) override;
678 };
679
680 class ResourceFormatSaverGDScript : public ResourceFormatSaver {
681 GDSOFTCLASS(ResourceFormatSaverGDScript, ResourceFormatSaver);
682
683 public:
684 virtual Error save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags = 0) override;
685 virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const override;
686 virtual bool recognize(const Ref<Resource> &p_resource) const override;
687 };