From 1d002efc8786a525c33a4d49db2ef99d73799016 Mon Sep 17 00:00:00 2001 From: Estevan Hernandez Date: Sat, 9 Dec 2023 19:08:28 -0600 Subject: [PATCH] update macro and tests to include .array usage flag (#284) * update macro and tests to include .array usage flag * adds `#exportGroup` macro #275 (#276) * adds exportCategory macro, w tests. TODO: sub category support * simplify export category logic, and add property categories immediately before their respective variable decls * change name from exportCategory to exportGroup and add prefix support w/ tests * use _mproxy_ prefix for set/get methods surfaced to Godot, to avoid breaking existing tests * forgot to update the first test * fix failing tests * add .group to usage for properties belonging to groups * fix tests * Use defer to deallocate argPtr & argMeta (#282) Co-authored-by: pcbeard * Document new #exportGroup macro * Add support for vararg methods that do not have a return value. We were avoiding the codepath that produces the temporary storage for the call to temporary storage for varargs methods. But those methods, even if they return no value are expected to pass a buffer for a return value. * update macro and tests to include .array usage flag * use spaces instead of tabs --------- Co-authored-by: pcbeard Co-authored-by: pcbeard Co-authored-by: Miguel de Icaza --- .../SwiftGodotMacroLibrary/MacroGodot.swift | 14 +++--- .../MacroGodotExportCategoryTests.swift | 50 +++++++++---------- .../MacroGodotExportCollectionTests.swift | 14 +++--- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Sources/SwiftGodotMacroLibrary/MacroGodot.swift b/Sources/SwiftGodotMacroLibrary/MacroGodot.swift index 81740adf4..36e90ca83 100644 --- a/Sources/SwiftGodotMacroLibrary/MacroGodot.swift +++ b/Sources/SwiftGodotMacroLibrary/MacroGodot.swift @@ -299,7 +299,7 @@ class GodotMacroProcessor { className: StringName("\(godotArrayTypeName)"), hint: .\(f?.description ?? "none"), hintStr: \(s?.description ?? "\"\""), - usage: \(prefix == nil ? ".default" : "[.default, .group]"))\n + usage: \(prefix == nil ? "[.default, .array]" : "[.default, .array, .group]"))\n """) ctor.append("\tclassInfo.registerMethod (name: \"\(getterName)\", flags: .default, returnValue: \(pinfo), arguments: [], function: \(className).\(proxyGetterName))\n") @@ -329,13 +329,13 @@ class GodotMacroProcessor { previousPrefix = macroExpansion.exportGroupPrefix ?? "" processExportGroup(name: name, prefix: previousPrefix ?? "") } else if let funcDecl = FunctionDeclSyntax(decl) { - try processFunction (funcDecl) - } else if let varDecl = VariableDeclSyntax(decl) { - if varDecl.isGArrayCollection { + try processFunction (funcDecl) + } else if let varDecl = VariableDeclSyntax(decl) { + if varDecl.isGArrayCollection { try processGArrayCollectionVariable(varDecl, prefix: previousPrefix) - } else { - try processVariable(varDecl, prefix: previousPrefix) - } + } else { + try processVariable(varDecl, prefix: previousPrefix) + } } else if let macroDecl = MacroExpansionDeclSyntax(decl) { try classInitSignals(macroDecl) } diff --git a/Tests/SwiftGodotMacrosTests/MacroGodotExportCategoryTests.swift b/Tests/SwiftGodotMacrosTests/MacroGodotExportCategoryTests.swift index 5ff01550b..890fde8c1 100644 --- a/Tests/SwiftGodotMacrosTests/MacroGodotExportCategoryTests.swift +++ b/Tests/SwiftGodotMacrosTests/MacroGodotExportCategoryTests.swift @@ -487,7 +487,7 @@ class Car: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_makes", flags: .default, returnValue: _pmakes, arguments: [], function: Car._mproxy_get_makes) classInfo.registerMethod (name: "set_makes", flags: .default, returnValue: nil, arguments: [_pmakes], function: Car._mproxy_set_makes) classInfo.registerProperty (_pmakes, getter: "get_makes", setter: "set_makes") @@ -497,7 +497,7 @@ class Car: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_model", flags: .default, returnValue: _pmodel, arguments: [], function: Car._mproxy_get_model) classInfo.registerMethod (name: "set_model", flags: .default, returnValue: nil, arguments: [_pmodel], function: Car._mproxy_set_model) classInfo.registerProperty (_pmodel, getter: "get_model", setter: "set_model") @@ -571,7 +571,7 @@ class Car: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_vins", flags: .default, returnValue: _pvins, arguments: [], function: Car._mproxy_get_vins) classInfo.registerMethod (name: "set_vins", flags: .default, returnValue: nil, arguments: [_pvins], function: Car._mproxy_set_vins) classInfo.registerProperty (_pvins, getter: "get_vins", setter: "set_vins") @@ -582,7 +582,7 @@ class Car: Node { className: StringName("Array[int]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_years", flags: .default, returnValue: _pyears, arguments: [], function: Car._mproxy_get_years) classInfo.registerMethod (name: "set_years", flags: .default, returnValue: nil, arguments: [_pyears], function: Car._mproxy_set_years) classInfo.registerProperty (_pyears, getter: "get_years", setter: "set_years") @@ -655,7 +655,7 @@ class Car: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_vins", flags: .default, returnValue: _pvins, arguments: [], function: Car._mproxy_get_vins) classInfo.registerMethod (name: "set_vins", flags: .default, returnValue: nil, arguments: [_pvins], function: Car._mproxy_set_vins) classInfo.registerProperty (_pvins, getter: "get_vins", setter: "set_vins") @@ -665,7 +665,7 @@ class Car: Node { className: StringName("Array[int]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_years", flags: .default, returnValue: _pyears, arguments: [], function: Car._mproxy_get_years) classInfo.registerMethod (name: "set_years", flags: .default, returnValue: nil, arguments: [_pyears], function: Car._mproxy_set_years) classInfo.registerProperty (_pyears, getter: "get_years", setter: "set_years") @@ -776,7 +776,7 @@ class Car: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_vins", flags: .default, returnValue: _pvins, arguments: [], function: Car._mproxy_get_vins) classInfo.registerMethod (name: "set_vins", flags: .default, returnValue: nil, arguments: [_pvins], function: Car._mproxy_set_vins) classInfo.registerProperty (_pvins, getter: "get_vins", setter: "set_vins") @@ -787,7 +787,7 @@ class Car: Node { className: StringName("Array[int]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_years", flags: .default, returnValue: _pyears, arguments: [], function: Car._mproxy_get_years) classInfo.registerMethod (name: "set_years", flags: .default, returnValue: nil, arguments: [_pyears], function: Car._mproxy_set_years) classInfo.registerProperty (_pyears, getter: "get_years", setter: "set_years") @@ -797,7 +797,7 @@ class Car: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_makes", flags: .default, returnValue: _pmakes, arguments: [], function: Car._mproxy_get_makes) classInfo.registerMethod (name: "set_makes", flags: .default, returnValue: nil, arguments: [_pmakes], function: Car._mproxy_set_makes) classInfo.registerProperty (_pmakes, getter: "get_makes", setter: "set_makes") @@ -807,7 +807,7 @@ class Car: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_models", flags: .default, returnValue: _pmodels, arguments: [], function: Car._mproxy_get_models) classInfo.registerMethod (name: "set_models", flags: .default, returnValue: nil, arguments: [_pmodels], function: Car._mproxy_set_models) classInfo.registerProperty (_pmodels, getter: "get_models", setter: "set_models") @@ -884,7 +884,7 @@ class Car: Node { className: StringName("Array[Node]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_makes", flags: .default, returnValue: _pmakes, arguments: [], function: Car._mproxy_get_makes) classInfo.registerMethod (name: "set_makes", flags: .default, returnValue: nil, arguments: [_pmakes], function: Car._mproxy_set_makes) classInfo.registerProperty (_pmakes, getter: "get_makes", setter: "set_makes") @@ -894,7 +894,7 @@ class Car: Node { className: StringName("Array[Node]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_model", flags: .default, returnValue: _pmodel, arguments: [], function: Car._mproxy_get_model) classInfo.registerMethod (name: "set_model", flags: .default, returnValue: nil, arguments: [_pmodel], function: Car._mproxy_set_model) classInfo.registerProperty (_pmodel, getter: "get_model", setter: "set_model") @@ -967,7 +967,7 @@ class Car: Node { className: StringName("Array[Node]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_vins", flags: .default, returnValue: _pvins, arguments: [], function: Car._mproxy_get_vins) classInfo.registerMethod (name: "set_vins", flags: .default, returnValue: nil, arguments: [_pvins], function: Car._mproxy_set_vins) classInfo.registerProperty (_pvins, getter: "get_vins", setter: "set_vins") @@ -978,7 +978,7 @@ class Car: Node { className: StringName("Array[Node]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_years", flags: .default, returnValue: _pyears, arguments: [], function: Car._mproxy_get_years) classInfo.registerMethod (name: "set_years", flags: .default, returnValue: nil, arguments: [_pyears], function: Car._mproxy_set_years) classInfo.registerProperty (_pyears, getter: "get_years", setter: "set_years") @@ -1051,7 +1051,7 @@ class Car: Node { className: StringName("Array[Node]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_vins", flags: .default, returnValue: _pvins, arguments: [], function: Car._mproxy_get_vins) classInfo.registerMethod (name: "set_vins", flags: .default, returnValue: nil, arguments: [_pvins], function: Car._mproxy_set_vins) classInfo.registerProperty (_pvins, getter: "get_vins", setter: "set_vins") @@ -1061,7 +1061,7 @@ class Car: Node { className: StringName("Array[Node]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_years", flags: .default, returnValue: _pyears, arguments: [], function: Car._mproxy_get_years) classInfo.registerMethod (name: "set_years", flags: .default, returnValue: nil, arguments: [_pyears], function: Car._mproxy_set_years) classInfo.registerProperty (_pyears, getter: "get_years", setter: "set_years") @@ -1172,7 +1172,7 @@ class Car: Node { className: StringName("Array[Node]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_vins", flags: .default, returnValue: _pvins, arguments: [], function: Car._mproxy_get_vins) classInfo.registerMethod (name: "set_vins", flags: .default, returnValue: nil, arguments: [_pvins], function: Car._mproxy_set_vins) classInfo.registerProperty (_pvins, getter: "get_vins", setter: "set_vins") @@ -1183,7 +1183,7 @@ class Car: Node { className: StringName("Array[Node]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_years", flags: .default, returnValue: _pyears, arguments: [], function: Car._mproxy_get_years) classInfo.registerMethod (name: "set_years", flags: .default, returnValue: nil, arguments: [_pyears], function: Car._mproxy_set_years) classInfo.registerProperty (_pyears, getter: "get_years", setter: "set_years") @@ -1193,7 +1193,7 @@ class Car: Node { className: StringName("Array[Node]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_makes", flags: .default, returnValue: _pmakes, arguments: [], function: Car._mproxy_get_makes) classInfo.registerMethod (name: "set_makes", flags: .default, returnValue: nil, arguments: [_pmakes], function: Car._mproxy_set_makes) classInfo.registerProperty (_pmakes, getter: "get_makes", setter: "set_makes") @@ -1203,7 +1203,7 @@ class Car: Node { className: StringName("Array[Node]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_models", flags: .default, returnValue: _pmodels, arguments: [], function: Car._mproxy_get_models) classInfo.registerMethod (name: "set_models", flags: .default, returnValue: nil, arguments: [_pmodels], function: Car._mproxy_set_models) classInfo.registerProperty (_pmodels, getter: "get_models", setter: "set_models") @@ -1385,7 +1385,7 @@ class Garage: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_reviews", flags: .default, returnValue: _previews, arguments: [], function: Garage._mproxy_get_reviews) classInfo.registerMethod (name: "set_reviews", flags: .default, returnValue: nil, arguments: [_previews], function: Garage._mproxy_set_reviews) classInfo.registerProperty (_previews, getter: "get_reviews", setter: "set_reviews") @@ -1395,7 +1395,7 @@ class Garage: Node { className: StringName("Array[CheckIn]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_check_ins", flags: .default, returnValue: _pcheckIns, arguments: [], function: Garage._mproxy_get_checkIns) classInfo.registerMethod (name: "set_check_ins", flags: .default, returnValue: nil, arguments: [_pcheckIns], function: Garage._mproxy_set_checkIns) classInfo.registerProperty (_pcheckIns, getter: "get_check_ins", setter: "set_check_ins") @@ -1416,7 +1416,7 @@ class Garage: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_days_of_operation", flags: .default, returnValue: _pdaysOfOperation, arguments: [], function: Garage._mproxy_get_daysOfOperation) classInfo.registerMethod (name: "set_days_of_operation", flags: .default, returnValue: nil, arguments: [_pdaysOfOperation], function: Garage._mproxy_set_daysOfOperation) classInfo.registerProperty (_pdaysOfOperation, getter: "get_days_of_operation", setter: "set_days_of_operation") @@ -1426,7 +1426,7 @@ class Garage: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_hours", flags: .default, returnValue: _phours, arguments: [], function: Garage._mproxy_get_hours) classInfo.registerMethod (name: "set_hours", flags: .default, returnValue: nil, arguments: [_phours], function: Garage._mproxy_set_hours) classInfo.registerProperty (_phours, getter: "get_hours", setter: "set_hours") @@ -1436,7 +1436,7 @@ class Garage: Node { className: StringName("Array[InsuranceProvider]"), hint: .none, hintStr: "", - usage: [.default, .group]) + usage: [.default, .array, .group]) classInfo.registerMethod (name: "get_insurance_providers_accepted", flags: .default, returnValue: _pinsuranceProvidersAccepted, arguments: [], function: Garage._mproxy_get_insuranceProvidersAccepted) classInfo.registerMethod (name: "set_insurance_providers_accepted", flags: .default, returnValue: nil, arguments: [_pinsuranceProvidersAccepted], function: Garage._mproxy_set_insuranceProvidersAccepted) classInfo.registerProperty (_pinsuranceProvidersAccepted, getter: "get_insurance_providers_accepted", setter: "set_insurance_providers_accepted") diff --git a/Tests/SwiftGodotMacrosTests/MacroGodotExportCollectionTests.swift b/Tests/SwiftGodotMacrosTests/MacroGodotExportCollectionTests.swift index d02015fd7..9ad581456 100644 --- a/Tests/SwiftGodotMacrosTests/MacroGodotExportCollectionTests.swift +++ b/Tests/SwiftGodotMacrosTests/MacroGodotExportCollectionTests.swift @@ -102,7 +102,7 @@ class SomeNode: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_greetings", flags: .default, returnValue: _pgreetings, arguments: [], function: SomeNode._mproxy_get_greetings) classInfo.registerMethod (name: "set_greetings", flags: .default, returnValue: nil, arguments: [_pgreetings], function: SomeNode._mproxy_set_greetings) classInfo.registerProperty (_pgreetings, getter: "get_greetings", setter: "set_greetings") @@ -255,7 +255,7 @@ class SomeNode: Node { className: StringName("Array[int]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_some_numbers", flags: .default, returnValue: _psomeNumbers, arguments: [], function: SomeNode._mproxy_get_someNumbers) classInfo.registerMethod (name: "set_some_numbers", flags: .default, returnValue: nil, arguments: [_psomeNumbers], function: SomeNode._mproxy_set_someNumbers) classInfo.registerProperty (_psomeNumbers, getter: "get_some_numbers", setter: "set_some_numbers") @@ -327,7 +327,7 @@ class SomeNode: Node { className: StringName("Array[int]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_some_numbers", flags: .default, returnValue: _psomeNumbers, arguments: [], function: SomeNode._mproxy_get_someNumbers) classInfo.registerMethod (name: "set_some_numbers", flags: .default, returnValue: nil, arguments: [_psomeNumbers], function: SomeNode._mproxy_set_someNumbers) classInfo.registerProperty (_psomeNumbers, getter: "get_some_numbers", setter: "set_some_numbers") @@ -337,7 +337,7 @@ class SomeNode: Node { className: StringName("Array[int]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_some_other_numbers", flags: .default, returnValue: _psomeOtherNumbers, arguments: [], function: SomeNode._mproxy_get_someOtherNumbers) classInfo.registerMethod (name: "set_some_other_numbers", flags: .default, returnValue: nil, arguments: [_psomeOtherNumbers], function: SomeNode._mproxy_set_someOtherNumbers) classInfo.registerProperty (_psomeOtherNumbers, getter: "get_some_other_numbers", setter: "set_some_other_numbers") @@ -411,7 +411,7 @@ class ArrayTest: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_first_names", flags: .default, returnValue: _pfirstNames, arguments: [], function: ArrayTest._mproxy_get_firstNames) classInfo.registerMethod (name: "set_first_names", flags: .default, returnValue: nil, arguments: [_pfirstNames], function: ArrayTest._mproxy_set_firstNames) classInfo.registerProperty (_pfirstNames, getter: "get_first_names", setter: "set_first_names") @@ -421,7 +421,7 @@ class ArrayTest: Node { className: StringName("Array[String]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_last_names", flags: .default, returnValue: _plastNames, arguments: [], function: ArrayTest._mproxy_get_lastNames) classInfo.registerMethod (name: "set_last_names", flags: .default, returnValue: nil, arguments: [_plastNames], function: ArrayTest._mproxy_set_lastNames) classInfo.registerProperty (_plastNames, getter: "get_last_names", setter: "set_last_names") @@ -504,7 +504,7 @@ class SomeNode: Node { className: StringName("Array[Node3D]"), hint: .none, hintStr: "", - usage: .default) + usage: [.default, .array]) classInfo.registerMethod (name: "get_greetings", flags: .default, returnValue: _pgreetings, arguments: [], function: SomeNode._mproxy_get_greetings) classInfo.registerMethod (name: "set_greetings", flags: .default, returnValue: nil, arguments: [_pgreetings], function: SomeNode._mproxy_set_greetings) classInfo.registerProperty (_pgreetings, getter: "get_greetings", setter: "set_greetings")