From 676c6841ed203ab1247dbe0fbfb700333728ded8 Mon Sep 17 00:00:00 2001 From: Davide Date: Thu, 5 Feb 2026 11:12:22 +0100 Subject: [PATCH 1/3] Make expanded members public --- Sources/SWONMacros/Decoding.swift | 4 ++-- Sources/SWONMacros/Encoding.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/SWONMacros/Decoding.swift b/Sources/SWONMacros/Decoding.swift index 42ac486..808f985 100644 --- a/Sources/SWONMacros/Decoding.swift +++ b/Sources/SWONMacros/Decoding.swift @@ -155,12 +155,12 @@ struct SWONDecodeMacro: MemberMacro { } return [ DeclSyntax(stringLiteral: """ - init(fromSWON root: swon_t) throws { + public init(fromSWON root: swon_t) throws { \(assignments.joined(separator: "\n")) } """), DeclSyntax(stringLiteral: """ - init(fromJSON json: String) throws { + public init(fromJSON json: String) throws { var root = swon_t() defer { swon_free(&root) } guard swon_parse(&root, json) == SWONResultValid else { diff --git a/Sources/SWONMacros/Encoding.swift b/Sources/SWONMacros/Encoding.swift index 71c8f66..daab5e5 100644 --- a/Sources/SWONMacros/Encoding.swift +++ b/Sources/SWONMacros/Encoding.swift @@ -194,7 +194,7 @@ struct SWONEncodeMacro: MemberMacro { // ) return [ DeclSyntax(stringLiteral: """ - func toSWON() throws -> swon_t { + public func toSWON() throws -> swon_t { var root = swon_t() guard swon_create_object(&root) else { throw SWONError.invalid("Unable to create root") @@ -208,7 +208,7 @@ struct SWONEncodeMacro: MemberMacro { } """), DeclSyntax(stringLiteral: """ - func toJSON() throws -> String { + public func toJSON() throws -> String { var item = try toSWON() defer { swon_free(&item) } guard let cjson = swon_encode(item) else { From eafb6ecf5773411a7e86d2423c4cdc4a31d44bd7 Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 6 Feb 2026 11:41:21 +0100 Subject: [PATCH 2/3] Get access modifier from decl list --- Sources/SWONMacros/Helpers.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sources/SWONMacros/Helpers.swift b/Sources/SWONMacros/Helpers.swift index 0e00cfc..782e550 100644 --- a/Sources/SWONMacros/Helpers.swift +++ b/Sources/SWONMacros/Helpers.swift @@ -79,6 +79,26 @@ extension EnumDeclSyntax { } } +extension DeclModifierListSyntax { + var accessLevel: String { + for modifier in self { + switch modifier.name.tokenKind { + case .keyword(.public): + return "public" + case .keyword(.internal): + return "internal" + case .keyword(.fileprivate): + return "fileprivate" + case .keyword(.private): + return "private" + default: + continue + } + } + return "" + } +} + struct SWONMessage: DiagnosticMessage { let severity: DiagnosticSeverity = .note let message: String From 31ca466878bdcc28c0c89e6dbd8a2ffaf47faf6a Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 6 Feb 2026 11:42:38 +0100 Subject: [PATCH 3/3] Match declaration access modifier --- Sources/SWONMacros/Decoding.swift | 5 +++-- Sources/SWONMacros/Encoding.swift | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/SWONMacros/Decoding.swift b/Sources/SWONMacros/Decoding.swift index 808f985..3c2f0c2 100644 --- a/Sources/SWONMacros/Decoding.swift +++ b/Sources/SWONMacros/Decoding.swift @@ -153,14 +153,15 @@ struct SWONDecodeMacro: MemberMacro { """) } } + let accessLevel = declaration.modifiers.accessLevel return [ DeclSyntax(stringLiteral: """ - public init(fromSWON root: swon_t) throws { + \(accessLevel) init(fromSWON root: swon_t) throws { \(assignments.joined(separator: "\n")) } """), DeclSyntax(stringLiteral: """ - public init(fromJSON json: String) throws { + \(accessLevel) init(fromJSON json: String) throws { var root = swon_t() defer { swon_free(&root) } guard swon_parse(&root, json) == SWONResultValid else { diff --git a/Sources/SWONMacros/Encoding.swift b/Sources/SWONMacros/Encoding.swift index daab5e5..f3e6abb 100644 --- a/Sources/SWONMacros/Encoding.swift +++ b/Sources/SWONMacros/Encoding.swift @@ -192,9 +192,10 @@ struct SWONEncodeMacro: MemberMacro { // message: SWONMessage(message: "Assignments: \(assignments)") // ) // ) + let accessLevel = declaration.modifiers.accessLevel return [ DeclSyntax(stringLiteral: """ - public func toSWON() throws -> swon_t { + \(accessLevel) func toSWON() throws -> swon_t { var root = swon_t() guard swon_create_object(&root) else { throw SWONError.invalid("Unable to create root") @@ -208,7 +209,7 @@ struct SWONEncodeMacro: MemberMacro { } """), DeclSyntax(stringLiteral: """ - public func toJSON() throws -> String { + \(accessLevel) func toJSON() throws -> String { var item = try toSWON() defer { swon_free(&item) } guard let cjson = swon_encode(item) else {