forked from Jenova-Framework/Jenova-Runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_language.cpp
More file actions
548 lines (537 loc) · 18.4 KB
/
Copy pathscript_language.cpp
File metadata and controls
548 lines (537 loc) · 18.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
/*-------------------------------------------------------------+
| |
| _________ ______ _ _____ |
| / / ____/ | / / __ \ | / / | |
| __ / / __/ / |/ / / / / | / / /| | |
| / /_/ / /___/ /| / /_/ /| |/ / ___ | |
| \____/_____/_/ |_/\____/ |___/_/ |_| |
| |
| Jenova Runtime |
| Developed by Hamid.Memar |
| |
+-------------------------------------------------------------*/
// Jenova SDK
#include "Jenova.hpp"
// Jenova Script Language Implementation
static CPPScriptLanguage* cpp_language;
CPPScriptLanguage* CPPScriptLanguage::get_singleton()
{
return cpp_language;
}
void CPPScriptLanguage::init()
{
cpp_language = memnew(CPPScriptLanguage);
Engine::get_singleton()->register_script_language(cpp_language);
}
void CPPScriptLanguage::deinit()
{
Engine::get_singleton()->unregister_script_language(cpp_language);
memdelete(cpp_language);
}
String CPPScriptLanguage::_get_name() const
{
return "C++ Script";
}
void CPPScriptLanguage::_init() {}
void CPPScriptLanguage::_finish() {}
String CPPScriptLanguage::_get_type() const
{
return jenova::GlobalSettings::JenovaScriptType;
}
String CPPScriptLanguage::_get_extension() const
{
return jenova::GlobalSettings::JenovaScriptExtension;
}
PackedStringArray CPPScriptLanguage::_get_reserved_words() const
{
static const PackedStringArray reserved_words
{
"alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept",
"auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", "char8_t", "char16_t", "char32_t",
"class", "compl", "concept", "const", "consteval", "constexpr", "const_cast", "continue", "co_await",
"co_return", "co_yield", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else",
"enum", "explicit", "export", "extern", "false", "float", "for", "friend", "goto", "if", "inline",
"int", "int32_t", "int64_t", "uint32_t", "uint64_t", "long", "size_t", "mutable", "namespace", "new",
"noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public",
"reflexpr", "register", "reinterpret_cast", "requires", "return", "short", "signed", "sizeof", "static",
"static_assert", "static_cast", "struct", "switch", "synchronized", "template", "this", "thread_local",
"throw", "true", "try", "typedef", "typeid","typename", "union", "unsigned", "using", "virtual", "void",
"volatile", "wchar_t", "while", "xor", "xor_eq", "jenova", "godot", "__int64", "__int32", "Caller", "Variant",
"include", "ifdef", "else", "endif", "pragma",
"GlobalGet", "GlobalSet", "GlobalPointer", "GlobalVariable", "GetNode", "FindNode", "GetSelf",
jenova::GlobalSettings::ScriptToolIdentifier,
jenova::GlobalSettings::ScriptBlockBeginIdentifier,
jenova::GlobalSettings::ScriptBlockEndIdentifier,
jenova::GlobalSettings::ScriptVMBeginIdentifier,
jenova::GlobalSettings::ScriptVMEndIdentifier,
jenova::GlobalSettings::ScriptSignalCallbackIdentifier,
jenova::GlobalSettings::ScriptPropertyIdentifier,
jenova::GlobalSettings::ScriptClassNameIdentifier
};
return reserved_words;
}
bool CPPScriptLanguage::_is_control_flow_keyword(const String& p_keyword) const
{
static const std::unordered_set<std::string> control_flow_keywords{
"if", "else", "switch", "case", "default", "while", "do", "for", "break", "continue", "return", "goto", "try", "catch", "throw", "co_await",
"co_return", "co_yield", "jenova", "godot", "include", "ifdef", "else", "endif", "pragma",
jenova::GlobalSettings::ScriptToolIdentifier,
jenova::GlobalSettings::ScriptBlockBeginIdentifier,
jenova::GlobalSettings::ScriptBlockEndIdentifier,
jenova::GlobalSettings::ScriptVMBeginIdentifier,
jenova::GlobalSettings::ScriptVMEndIdentifier,
jenova::GlobalSettings::ScriptSignalCallbackIdentifier,
jenova::GlobalSettings::ScriptPropertyIdentifier,
jenova::GlobalSettings::ScriptClassNameIdentifier
};
return control_flow_keywords.find(p_keyword.utf8().get_data()) != control_flow_keywords.end();
}
PackedStringArray CPPScriptLanguage::_get_comment_delimiters() const
{
PackedStringArray comment_delimiters;
comment_delimiters.push_back("/* */");
comment_delimiters.push_back("//");
return comment_delimiters;
}
PackedStringArray CPPScriptLanguage::_get_doc_comment_delimiters() const
{
PackedStringArray doc_comment_delimiters;
doc_comment_delimiters.push_back("///");
doc_comment_delimiters.push_back("/** */");
return doc_comment_delimiters;
}
PackedStringArray CPPScriptLanguage::_get_string_delimiters() const
{
PackedStringArray string_delimiters;
string_delimiters.push_back("' '");
string_delimiters.push_back("\" \"");
return string_delimiters;
}
Ref<Script> CPPScriptLanguage::_make_template(const String& p_template, const String& p_class_name, const String& p_base_class_name) const
{
// Create New C++ Script
Ref<CPPScript> script;
script.instantiate();
// Set Template
if (!p_template.is_empty()) script->set_source_code(p_template);
// Return Created Script
return script;
}
TypedArray<Dictionary> CPPScriptLanguage::_get_built_in_templates(const StringName& p_object) const
{
// Global Templates [Future : Maybe Merge to Object Class Templates?]
if (p_object == StringName("Object")) return JenovaTemplateManager::get_singleton()->GetGlobalScriptTemplates();
// Class Templates
return JenovaTemplateManager::get_singleton()->GetClassScriptTemplates(p_object);
// No Template Found
return TypedArray<Dictionary>();
}
bool CPPScriptLanguage::_is_using_templates()
{
return true;
}
Dictionary CPPScriptLanguage::_validate(const String& p_script, const String& p_path, bool p_validate_functions, bool p_validate_errors, bool p_validate_warnings, bool p_validate_safe_lines) const
{
return Dictionary();
}
String CPPScriptLanguage::_validate_path(const String& p_path) const
{
return String();
}
Object* CPPScriptLanguage::_create_script() const
{
CPPScript* script = memnew(CPPScript);
return script;
}
bool CPPScriptLanguage::_has_named_classes() const
{
return false; // Not Supprted Yet
}
bool CPPScriptLanguage::_supports_builtin_mode() const
{
return true; // Experimental
}
bool CPPScriptLanguage::_supports_documentation() const
{
return false; // Not Supprted Yet
}
bool CPPScriptLanguage::_can_inherit_from_file() const
{
return false;
}
int32_t CPPScriptLanguage::_find_function(const String& p_function, const String& p_code) const
{
return -1;
}
String CPPScriptLanguage::_make_function(const String& p_class_name, const String& p_function_name, const PackedStringArray& p_function_args) const
{
return String();
}
Error CPPScriptLanguage::_open_in_external_editor(const Ref<Script>& p_script, int32_t p_line, int32_t p_column)
{
return Error::OK;
}
bool CPPScriptLanguage::_overrides_external_editor()
{
return false;
}
Dictionary CPPScriptLanguage::_complete_code(const String& p_code, const String& p_path, Object* p_owner) const
{
return Dictionary();
}
Dictionary CPPScriptLanguage::_lookup_code(const String& p_code, const String& p_symbol, const String& p_path, Object* p_owner) const
{
return Dictionary();
}
String CPPScriptLanguage::_auto_indent_code(const String& p_code, int32_t p_from_line, int32_t p_to_line) const
{
return String();
}
bool CPPScriptLanguage::_can_make_function() const
{
return true;
}
void CPPScriptLanguage::_add_global_constant(const StringName& p_name, const Variant& p_value) {}
void CPPScriptLanguage::_add_named_global_constant(const StringName& p_name, const Variant& p_value) {}
void CPPScriptLanguage::_remove_named_global_constant(const StringName& p_name) {}
void CPPScriptLanguage::_thread_enter() {}
void CPPScriptLanguage::_thread_exit() {}
String CPPScriptLanguage::_debug_get_error() const
{
return String();
}
int32_t CPPScriptLanguage::_debug_get_stack_level_count() const
{
return 0;
}
int32_t CPPScriptLanguage::_debug_get_stack_level_line(int32_t p_level) const
{
return 0;
}
String CPPScriptLanguage::_debug_get_stack_level_function(int32_t p_level) const
{
return String();
}
Dictionary CPPScriptLanguage::_debug_get_stack_level_locals(int32_t p_level, int32_t p_max_subitems, int32_t p_max_depth)
{
return Dictionary();
}
Dictionary CPPScriptLanguage::_debug_get_stack_level_members(int32_t p_level, int32_t p_max_subitems, int32_t p_max_depth)
{
return Dictionary();
}
void* CPPScriptLanguage::_debug_get_stack_level_instance(int32_t p_level)
{
return nullptr;
}
Dictionary CPPScriptLanguage::_debug_get_globals(int32_t p_max_subitems, int32_t p_max_depth)
{
return Dictionary();
}
String CPPScriptLanguage::_debug_parse_stack_level_expression(int32_t p_level, const String& p_expression, int32_t p_max_subitems, int32_t p_max_depth)
{
return String();
}
TypedArray<Dictionary> CPPScriptLanguage::_debug_get_current_stack_info()
{
return TypedArray<Dictionary>();
}
void CPPScriptLanguage::_reload_all_scripts()
{
jenova::VerboseByID(__LINE__, "_reload_all_scripts Called");
}
void CPPScriptLanguage::_reload_scripts(const Array& p_scripts, bool p_soft_reload)
{
// Called when a script gets edited while game is running
jenova::VerboseByID(__LINE__, "_reload_scripts Called");
}
void CPPScriptLanguage::_reload_tool_script(const Ref<Script>& p_script, bool p_soft_reload)
{
jenova::VerboseByID(__LINE__, "_reload_tool_script Called");
}
PackedStringArray CPPScriptLanguage::_get_recognized_extensions() const
{
PackedStringArray array;
array.push_back(jenova::GlobalSettings::JenovaScriptExtension);
return array;
}
TypedArray<Dictionary> CPPScriptLanguage::_get_public_functions() const
{
return TypedArray<Dictionary>();
}
Dictionary CPPScriptLanguage::_get_public_constants() const
{
return Dictionary();
}
TypedArray<Dictionary> CPPScriptLanguage::_get_public_annotations() const
{
return TypedArray<Dictionary>();
}
void CPPScriptLanguage::_profiling_start()
{
jenova::Output("Jenova Profiler Started.");
}
void CPPScriptLanguage::_profiling_stop()
{
jenova::Output("Jenova Profiler Stopped.");
}
void CPPScriptLanguage::_profiling_set_save_native_calls(bool p_enable)
{
jenova::VerboseByID(__LINE__, "_profiling_set_save_native_calls : %s", p_enable ? "True" : "False");
}
int32_t CPPScriptLanguage::_profiling_get_accumulated_data(ScriptLanguageExtensionProfilingInfo* p_info_array, int32_t p_info_max)
{
return 0;
}
int32_t CPPScriptLanguage::_profiling_get_frame_data(ScriptLanguageExtensionProfilingInfo* p_info_array, int32_t p_info_max)
{
return 0;
}
void CPPScriptLanguage::_frame()
{
// Process
}
bool CPPScriptLanguage::_handles_global_class_type(const String& p_type) const
{
jenova::VerboseByID(__LINE__, "_handles_global_class_type [%s]", AS_C_STRING(p_type));
return p_type == _get_type();
}
Dictionary CPPScriptLanguage::_get_global_class_name(const String& p_path) const
{
// Remove
jenova::VerboseByID(__LINE__, "_get_global_class_name [%s]", AS_C_STRING(p_path));
// Return Global Class Name
Dictionary classInfo;
Ref<Resource> resource = ResourceLoader::get_singleton()->load(p_path);
Ref<CPPScript> cppScript = Object::cast_to<CPPScript>(resource.ptr());
if (cppScript.is_valid())
{
// Check for User-Defined Class Name
if (cppScript->has_source_code())
{
std::string className = jenova::ParseClassNameFromScriptSource(AS_STD_STRING(cppScript->get_source_code()));
if (!className.empty()) classInfo["name"] = String(className.c_str());
else classInfo["name"] = "NotFound";
}
// Create Class Info
if (classInfo["name"] == String("NotFound")) classInfo["name"] = " Jenova C++ Script";
classInfo["base_type"] = jenova::GlobalSettings::JenovaScriptType;
String iconPath = p_path.replace(p_path.get_extension(), ".svg");
if (FileAccess::file_exists(iconPath)) classInfo["icon_path"] = iconPath;
// Create Global Class If Not Exists
ProjectSettings::get_singleton()->get_global_class_list();
}
return classInfo;
}
// Jenova Script Language Implementation
static CPPHeaderLanguage* header_language;
CPPHeaderLanguage* CPPHeaderLanguage::get_singleton()
{
return header_language;
}
void CPPHeaderLanguage::init()
{
header_language = memnew(CPPHeaderLanguage);
Engine::get_singleton()->register_script_language(header_language);
}
void CPPHeaderLanguage::deinit()
{
Engine::get_singleton()->unregister_script_language(header_language);
memdelete(header_language);
}
String CPPHeaderLanguage::_get_name() const
{
return "C++ Header";
}
void CPPHeaderLanguage::_init() {}
void CPPHeaderLanguage::_finish() {}
String CPPHeaderLanguage::_get_type() const
{
return jenova::GlobalSettings::JenovaHeaderType;
}
String CPPHeaderLanguage::_get_extension() const
{
return String("hpp"); // How to add .h and .hh?
}
PackedStringArray CPPHeaderLanguage::_get_reserved_words() const
{
return CPPScriptLanguage::get_singleton()->_get_reserved_words();
}
bool CPPHeaderLanguage::_is_control_flow_keyword(const String& p_keyword) const
{
return CPPScriptLanguage::get_singleton()->_is_control_flow_keyword(p_keyword);
}
PackedStringArray CPPHeaderLanguage::_get_comment_delimiters() const
{
return CPPScriptLanguage::get_singleton()->_get_comment_delimiters();
}
PackedStringArray CPPHeaderLanguage::_get_doc_comment_delimiters() const
{
return CPPScriptLanguage::get_singleton()->_get_doc_comment_delimiters();
}
PackedStringArray CPPHeaderLanguage::_get_string_delimiters() const
{
return CPPScriptLanguage::get_singleton()->_get_string_delimiters();
}
Ref<Script> CPPHeaderLanguage::_make_template(const String& p_template, const String& p_class_name, const String& p_base_class_name) const
{
CPPHeader* script = memnew(CPPHeader);
return Ref<Script>(script);
}
TypedArray<Dictionary> CPPHeaderLanguage::_get_built_in_templates(const StringName& p_object) const
{
return TypedArray<Dictionary>();
}
bool CPPHeaderLanguage::_is_using_templates()
{
return false;
}
Dictionary CPPHeaderLanguage::_validate(const String& p_script, const String& p_path, bool p_validate_functions, bool p_validate_errors, bool p_validate_warnings, bool p_validate_safe_lines) const
{
return Dictionary();
}
String CPPHeaderLanguage::_validate_path(const String& p_path) const
{
return String();
}
Object* CPPHeaderLanguage::_create_script() const
{
CPPHeader* script = memnew(CPPHeader);
return script;
}
bool CPPHeaderLanguage::_has_named_classes() const
{
return false;
}
bool CPPHeaderLanguage::_supports_builtin_mode() const
{
return false;
}
bool CPPHeaderLanguage::_supports_documentation() const
{
return false;
}
bool CPPHeaderLanguage::_can_inherit_from_file() const
{
return false;
}
int32_t CPPHeaderLanguage::_find_function(const String& p_function, const String& p_code) const
{
return -1;
}
String CPPHeaderLanguage::_make_function(const String& p_class_name, const String& p_function_name, const PackedStringArray& p_function_args) const
{
return String();
}
Error CPPHeaderLanguage::_open_in_external_editor(const Ref<Script>& p_script, int32_t p_line, int32_t p_column)
{
return Error::OK;
}
bool CPPHeaderLanguage::_overrides_external_editor()
{
return false;
}
Dictionary CPPHeaderLanguage::_complete_code(const String& p_code, const String& p_path, Object* p_owner) const
{
return Dictionary();
}
Dictionary CPPHeaderLanguage::_lookup_code(const String& p_code, const String& p_symbol, const String& p_path, Object* p_owner) const
{
return Dictionary();
}
String CPPHeaderLanguage::_auto_indent_code(const String& p_code, int32_t p_from_line, int32_t p_to_line) const
{
return String();
}
bool CPPHeaderLanguage::_can_make_function() const
{
return false;
}
void CPPHeaderLanguage::_add_global_constant(const StringName& p_name, const Variant& p_value) {}
void CPPHeaderLanguage::_add_named_global_constant(const StringName& p_name, const Variant& p_value) {}
void CPPHeaderLanguage::_remove_named_global_constant(const StringName& p_name) {}
void CPPHeaderLanguage::_thread_enter() {}
void CPPHeaderLanguage::_thread_exit() {}
String CPPHeaderLanguage::_debug_get_error() const
{
return String();
}
int32_t CPPHeaderLanguage::_debug_get_stack_level_count() const
{
return 0;
}
int32_t CPPHeaderLanguage::_debug_get_stack_level_line(int32_t p_level) const
{
return 0;
}
String CPPHeaderLanguage::_debug_get_stack_level_function(int32_t p_level) const
{
return String();
}
Dictionary CPPHeaderLanguage::_debug_get_stack_level_locals(int32_t p_level, int32_t p_max_subitems, int32_t p_max_depth)
{
return Dictionary();
}
Dictionary CPPHeaderLanguage::_debug_get_stack_level_members(int32_t p_level, int32_t p_max_subitems, int32_t p_max_depth)
{
return Dictionary();
}
void* CPPHeaderLanguage::_debug_get_stack_level_instance(int32_t p_level)
{
return nullptr;
}
Dictionary CPPHeaderLanguage::_debug_get_globals(int32_t p_max_subitems, int32_t p_max_depth)
{
return Dictionary();
}
String CPPHeaderLanguage::_debug_parse_stack_level_expression(int32_t p_level, const String& p_expression, int32_t p_max_subitems, int32_t p_max_depth)
{
return String();
}
TypedArray<Dictionary> CPPHeaderLanguage::_debug_get_current_stack_info()
{
return TypedArray<Dictionary>();
}
void CPPHeaderLanguage::_reload_all_scripts() {}
void CPPHeaderLanguage::_reload_scripts(const Array& p_scripts, bool p_soft_reload) {}
void CPPHeaderLanguage::_reload_tool_script(const Ref<Script>& p_script, bool p_soft_reload) {}
PackedStringArray CPPHeaderLanguage::_get_recognized_extensions() const
{
PackedStringArray array;
array.push_back("h");
array.push_back("hh");
array.push_back("hpp");
return array;
}
TypedArray<Dictionary> CPPHeaderLanguage::_get_public_functions() const
{
return TypedArray<Dictionary>();
}
Dictionary CPPHeaderLanguage::_get_public_constants() const
{
return Dictionary();
}
TypedArray<Dictionary> CPPHeaderLanguage::_get_public_annotations() const
{
return TypedArray<Dictionary>();
}
void CPPHeaderLanguage::_profiling_start() {}
void CPPHeaderLanguage::_profiling_stop() {}
void CPPHeaderLanguage::_profiling_set_save_native_calls(bool p_enable) {}
int32_t CPPHeaderLanguage::_profiling_get_accumulated_data(ScriptLanguageExtensionProfilingInfo* p_info_array, int32_t p_info_max)
{
return 0;
}
int32_t CPPHeaderLanguage::_profiling_get_frame_data(ScriptLanguageExtensionProfilingInfo* p_info_array, int32_t p_info_max)
{
return 0;
}
void CPPHeaderLanguage::_frame() {}
bool CPPHeaderLanguage::_handles_global_class_type(const String& p_type) const
{
return false;
}
Dictionary CPPHeaderLanguage::_get_global_class_name(const String& p_path) const
{
return Dictionary();
}