compiler: Use Macro to Derive CompilableStatement Implementations

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-29 17:36:15 -04:00
parent 4f6de341cc
commit d2797e1acc
4 changed files with 23 additions and 91 deletions
+3 -7
View File
@@ -439,17 +439,14 @@ public struct CliTestDeclarationMacro: PeerMacro, Sendable {
}
}
public struct DeriveCompilableStatement: PeerMacro, Sendable {
public enum DeriveCompilableStatement: MemberMacro {
public static func expansion(
of node: AttributeSyntax,
providingPeersOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
of: AttributeSyntax, providingMembersOf type: some DeclGroupSyntax, conformingTo: [TypeSyntax],
in: some MacroExpansionContext
) throws -> [DeclSyntax] {
let type_name = declaration.cast(ExtensionDeclSyntax.self).extendedType
let implementation = DeclSyntax(
"""
extension VariableDeclarationStatement: CompilableStatement {
public static func CompileStatement(
node: Node, withContext context: CompilerContext
) -> Result<P4Statement> {
@@ -458,7 +455,6 @@ public struct DeriveCompilableStatement: PeerMacro, Sendable {
case .Error(let e): .Error(e)
}
}
}
""")
return [implementation]
}