From 067704f1cd6e169d8c9382b755a26c4880a2f941 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sun, 8 Oct 2023 16:22:25 -0500 Subject: [PATCH] Add a keyword for abstract classes in GDScript Co-authored-by: Danil Alexeev --- doc/classes/ScriptExtension.xml | 2 +- editor/create_dialog.cpp | 4 + modules/gdscript/gdscript.cpp | 1 + modules/gdscript/gdscript.h | 3 +- modules/gdscript/gdscript_analyzer.cpp | 13 ++- modules/gdscript/gdscript_compiler.cpp | 1 + modules/gdscript/gdscript_editor.cpp | 2 +- modules/gdscript/gdscript_parser.cpp | 97 ++++++++++++++----- modules/gdscript/gdscript_parser.h | 19 ++-- modules/gdscript/gdscript_tokenizer.cpp | 4 + modules/gdscript/gdscript_tokenizer.h | 1 + .../errors/construct_abstract_class.gd | 10 ++ .../errors/construct_abstract_class.out | 3 + .../construct_abstract_script.notest.gd | 1 + .../features/extend_abstract_class.gd | 9 +- .../parser/errors/duplicate_abstract.gd | 7 ++ .../parser/errors/duplicate_abstract.out | 2 + 17 files changed, 137 insertions(+), 42 deletions(-) create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/construct_abstract_class.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/construct_abstract_class.out create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/construct_abstract_script.notest.gd create mode 100644 modules/gdscript/tests/scripts/parser/errors/duplicate_abstract.gd create mode 100644 modules/gdscript/tests/scripts/parser/errors/duplicate_abstract.out diff --git a/doc/classes/ScriptExtension.xml b/doc/classes/ScriptExtension.xml index 0a4b81d442..17742534b1 100644 --- a/doc/classes/ScriptExtension.xml +++ b/doc/classes/ScriptExtension.xml @@ -162,7 +162,7 @@ - Returns [code]true[/code] if the script is an abstract script. An abstract script does not have a constructor and cannot be instantiated. + Returns [code]true[/code] if the script is an abstract script. Abstract scripts cannot be instantiated directly, instead other scripts should inherit them. Abstract scripts will be either unselectable or hidden in the Create New Node dialog (unselectable if there are non-abstract classes inheriting it, otherwise hidden). diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 1301960ad1..906f1a2a4a 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -219,6 +219,10 @@ bool CreateDialog::_should_hide_type(const StringName &p_type) const { i = script_path.find_char('/', i + 1); } } + // Abstract scripts cannot be instantiated. + String path = ScriptServer::get_global_class_path(p_type); + Ref