Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
helje5 committed Apr 7, 2024
2 parents c33488d + 2e4ade0 commit cbf71d0
Show file tree
Hide file tree
Showing 55 changed files with 907 additions and 305 deletions.
13 changes: 10 additions & 3 deletions Package@swift-5.10.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import PackageDescription

#if swift(>=5.10)
let settings = [ SwiftSetting.enableExperimentalFeature("StrictConcurrency") ]
#else
let settings = [ SwiftSetting ]()
#endif

var package = Package(
name: "Lighter",

Expand All @@ -28,7 +34,7 @@ var package = Package(
// generated models and such.
// Note that Lighter isn't that useful w/o code generation (i.e. as a
// standalone lib).
.target(name: "Lighter"),
.target(name: "Lighter", swiftSettings: settings),


// MARK: - Plugin Support
Expand All @@ -37,14 +43,15 @@ var package = Package(
// Swift source code.
.target(name : "LighterCodeGenAST",
path : "Plugins/Libraries/LighterCodeGenAST",
exclude : [ "README.md" ]),
exclude : [ "README.md" ], swiftSettings: settings),

// This library contains all the code generation, to be used by different
// clients.
.target(name : "LighterGeneration",
dependencies : [ "LighterCodeGenAST", "SQLite3Schema" ],
path : "Plugins/Libraries/LighterGeneration",
exclude : [ "README.md", "LighterConfiguration/README.md" ]),
exclude : [ "README.md", "LighterConfiguration/README.md" ],
swiftSettings: settings),


// MARK: - Tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

// Yes, this isn't particularily nice, but does the job. Keep in mind that
Expand All @@ -14,10 +14,10 @@
public final class CodeGenerator {

/// The configuration of the CodeGenerator.
public struct Configuration: Equatable {
public struct Configuration: Equatable, Sendable {

/// How comments should be rendered.
public enum CommentStyle: String {
public enum CommentStyle: String, Sendable {
case dashes = "//", tripleDashes = "///"
case stars = "*", doubleStars = "**"
case noComments = ""
Expand Down
82 changes: 60 additions & 22 deletions Plugins/Libraries/LighterCodeGenAST/Generation/GenStructures.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

public extension CodeGenerator {
Expand All @@ -12,31 +12,69 @@ public extension CodeGenerator {
omitPublic : Bool = false)
{
assert(value.type != nil || value.value != nil)

func writeBody() {
if value.public && !omitPublic { append("public ") }
if `static` { append("static ") }
append(value.let ? "let " : "var ")
append(tickedWhenReserved(value.name))
if let type = value.type {
append(configuration.propertyTypeSeparator) // " : "
append(string(for: type))
}
if let value = value.value {
append(configuration.propertyValueSeparator) // " = "
append(string(for: value))
}
appendEOL()
}

func writePlain() {
if let ( major, minor ) = value.minimumSwiftVersion {
assert(major >= 5)
writeln("#if swift(>=\(major).\(minor))")
}

writePropertyComment(value.comment)
appendIndent()
writeBody()

if let ( major, minor ) = value.minimumSwiftVersion {
assert(major >= 5)
writeln("#if swift(>=\(major).\(minor))")
if let ( major, minor ) = value.minimumSwiftVersion {
assert(major >= 5)
writeln("#endif // swift(>=\(major).\(minor))")
}
}

writePropertyComment(value.comment)
appendIndent()
if value.public && !omitPublic { append("public ") }
if `static` { append("static ") }
append(value.let ? "let " : "var ")
append(tickedWhenReserved(value.name))
if let type = value.type {
append(configuration.propertyTypeSeparator) // " : "
append(string(for: type))
}
if let value = value.value {
append(configuration.propertyValueSeparator) // " = "
append(string(for: value))
}
appendEOL()
if value.nonIsolatedUnsafe {
if let ( major, minor ) = value.minimumSwiftVersion,
(major > 5) || (major >= 5 && minor >= 10)
{
writePlain()
}
else {
writeln("#if swift(>=5.10)")

if let ( major, minor ) = value.minimumSwiftVersion {
assert(major >= 5)
writeln("#endif // swift(>=\(major).\(minor))")
writePropertyComment(value.comment)
appendIndent()
append("nonisolated(unsafe) ")
writeBody()

if let ( major, minor ) = value.minimumSwiftVersion {
assert(major >= 5)
writeln("#elseif swift(>=\(major).\(minor))")
}
else {
writeln("#else")
}

writePropertyComment(value.comment)
appendIndent()
writeBody()
writeln("#endif")
}
}
else {
writePlain()
}
}

Expand Down
12 changes: 6 additions & 6 deletions Plugins/Libraries/LighterCodeGenAST/Nodes/Expression.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
* An AST node for various Swift expressions.
*/
public indirect enum Expression: Equatable {
public indirect enum Expression: Equatable, Sendable {

/// The operators for ``compare(lhs:operator:rhs:)`` expressions.
public enum Operator: String {
public enum Operator: String, Sendable {
case equal = "=="
case notEqual = "!="
case greaterThanOrEqual = ">="
Expand Down Expand Up @@ -82,12 +82,12 @@ public indirect enum Expression: Equatable {
*
* Used as the value for ``Expression/functionCall(_:)``.
*/
public struct FunctionCall: Equatable {
public struct FunctionCall: Equatable, Sendable {

/**
* A parameter passed as part of the function call.
*/
public struct Parameter: Equatable {
public struct Parameter: Equatable, Sendable {

/// The keyword/label of the parameter, can be `nil` if it is a wildcard
/// (unlabled) parameter.
Expand All @@ -105,7 +105,7 @@ public struct FunctionCall: Equatable {
/**
* A trailing closure attached to a function call.
*/
public struct TrailingClosure: Equatable {
public struct TrailingClosure: Equatable, Sendable {

/// The parameter list of the trailing closure (e.g. `( a, b ) in`).
public let parameters: [ String ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
* A comment for a function.
*
* Has all the function specific things, like parameters and such.
*/
public struct FunctionComment: Equatable {
public struct FunctionComment: Equatable, Sendable {

/// A comment for a function parameter.
public struct Parameter: Equatable {
public struct Parameter: Equatable, Sendable {

/// The name of the function parameter being documented.
public var name : String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
Expand All @@ -19,7 +19,7 @@
* where C1: SQLColumn, C2: SQLColumn, T == C1.T, T == C2.T
* ```
*/
public struct FunctionDeclaration: Equatable {
public struct FunctionDeclaration: Equatable, Sendable {

/// Is the function public?
public let `public` : Bool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
Expand All @@ -9,7 +9,7 @@
*
* Plus extra annotations like ``inlinable`` and the ``comment``.
*/
public struct FunctionDefinition: Equatable {
public struct FunctionDefinition: Equatable, Sendable {

/// Whether the definition is `@inlinable` (included in the module header).
public var inlinable : Bool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

public extension FunctionDeclaration {

/// A parameter, like `from table: KeyPath<Self.RecordTypes, T.Type>`
/// Or: `limit: Int? = nil`
struct Parameter: Equatable {
struct Parameter: Equatable, Sendable {

/// The "label" of the parameter, e.g. the `from` in `select(from table:)`.
/// Can be `nil` for a wildcard (`_`).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
* A generic constraint attached to a ``FunctionDeclaration`` generic parameter
* or an ``Extension``.
*/
public enum GenericConstraint: Equatable {
public enum GenericConstraint: Equatable, Sendable {

/// `C1: SQLColumn`
case conformance(name: String, type: TypeReference)
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Libraries/LighterCodeGenAST/Nodes/Literal.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
* A Swift literal
*
* E.g. as used in default values like: `limit: Int? = nil` (the `nil`).
*/
public enum Literal: Equatable {
public enum Literal: Equatable, Sendable {

/// `nil`
case `nil`
Expand Down
6 changes: 3 additions & 3 deletions Plugins/Libraries/LighterCodeGenAST/Nodes/Statement.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
* An AST node for a Swift statement.
*/
public enum Statement: Equatable {
public enum Statement: Equatable, Sendable {

/**
* A pair for an `if`, `else if` statement, consisting of a condition and the
* associated ``Statement``s.
*/
public struct ConditionStatementPair: Equatable {
public struct ConditionStatementPair: Equatable, Sendable {

/// The condition that must be true to have the ``statements`` executed.
public var condition : Expression
Expand Down
17 changes: 12 additions & 5 deletions Plugins/Libraries/LighterCodeGenAST/Nodes/Struct.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
Expand All @@ -11,8 +11,10 @@ public struct Struct {
/**
* An instance variable of a ``Struct``.
*/
public struct InstanceVariable {
public struct InstanceVariable: Sendable {

/// Whether the definition is `nonisolated(unsafe)`, requires Swift 5.10+
public var nonIsolatedUnsafe : Bool
/// Is the property public?
public var `public` : Bool
/// Is the property readonly.
Expand All @@ -31,7 +33,9 @@ public struct Struct {
public var minimumSwiftVersion : ( major: Int, minor: Int )?

/// Initialize a new instance variable node.
public init(public: Bool = true, `let`: Bool = true, _ name: String,
public init(nonIsolatedUnsafe: Bool = false,
public: Bool = true, `let`: Bool = true,
_ name: String,
type: TypeReference? = nil, value: Expression? = nil,
minimumSwiftVersion : ( major: Int, minor: Int )? = nil,
comment: String? = nil)
Expand All @@ -43,6 +47,7 @@ public struct Struct {
self.value = value
self.minimumSwiftVersion = minimumSwiftVersion
self.comment = comment
self.nonIsolatedUnsafe = nonIsolatedUnsafe
}
}

Expand Down Expand Up @@ -159,11 +164,13 @@ public extension Struct.InstanceVariable {
}

/// Initialize a new instance variable node for a `var`.
static func `var`(public: Bool = true, _ name: String, _ type: TypeReference,
static func `var`(nonIsolatedUnsafe: Bool = false,
public: Bool = true, _ name: String, _ type: TypeReference,
comment: String? = nil)
-> Self
{
.init(public: `public`, let: false, name, type: type, value: nil,
.init(nonIsolatedUnsafe: nonIsolatedUnsafe, public: `public`,
let: false, name, type: type, value: nil,
comment: comment)
}
}
4 changes: 2 additions & 2 deletions Plugins/Libraries/LighterCodeGenAST/Nodes/TypeReference.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
* A reference to some type, e.g. `Void` or `Person` or `Int`.
*/
public indirect enum TypeReference: Equatable {
public indirect enum TypeReference: Equatable, Sendable {

/// `Void`
case void
Expand Down

0 comments on commit cbf71d0

Please sign in to comment.