Skip to content

Commit

Permalink
update macro and tests to include .array usage flag (#284)
Browse files Browse the repository at this point in the history
* 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 <pcbeard@.mac.com>

* 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 <pcbeard@mac.com>
Co-authored-by: pcbeard <pcbeard@.mac.com>
Co-authored-by: Miguel de Icaza <miguel@gnome.org>
  • Loading branch information
4 people authored Dec 10, 2023
1 parent 5ba1cf9 commit 1d002ef
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
14 changes: 7 additions & 7 deletions Sources/SwiftGodotMacroLibrary/MacroGodot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down
50 changes: 25 additions & 25 deletions Tests/SwiftGodotMacrosTests/MacroGodotExportCategoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
Loading

0 comments on commit 1d002ef

Please sign in to comment.