Skip to content

Commit

Permalink
Enforce 80 character lines (apple#135)
Browse files Browse the repository at this point in the history
Updates the swift-format config to enforce 80 character line lengths.
This was already the defacto standard in swift-mmio. Fixes any existing
violation of this line length in the repo.
  • Loading branch information
rauhul authored Dec 12, 2024
1 parent 059cd4f commit 08e0b24
Show file tree
Hide file tree
Showing 22 changed files with 373 additions and 144 deletions.
33 changes: 24 additions & 9 deletions Sources/MMIO/MMIOMacros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,46 @@ public macro Reserved(bits: UnboundedRange) =
#externalMacro(module: "MMIOMacros", type: "ReservedMacro")

@attached(accessor)
public macro ReadWrite<Range, Value>(bits: Range..., as: Value.Type = Never.self) =
public macro ReadWrite<Range, Value>(
bits: Range..., as: Value.Type = Never.self
) =
#externalMacro(module: "MMIOMacros", type: "ReadWriteMacro")
where Range: RangeExpression, Range.Bound: BinaryInteger, Value: BitFieldProjectable
where
Range: RangeExpression, Range.Bound: BinaryInteger, Value: BitFieldProjectable

@attached(accessor)
public macro ReadWrite<Value>(bits: UnboundedRange, as: Value.Type = Never.self) =
public macro ReadWrite<Value>(
bits: UnboundedRange, as: Value.Type = Never.self
) =
#externalMacro(module: "MMIOMacros", type: "ReadWriteMacro")
where Value: BitFieldProjectable

@attached(accessor)
public macro ReadOnly<Range, Value>(bits: Range..., as: Value.Type = Never.self) =
public macro ReadOnly<Range, Value>(
bits: Range..., as: Value.Type = Never.self
) =
#externalMacro(module: "MMIOMacros", type: "ReadOnlyMacro")
where Range: RangeExpression, Range.Bound: BinaryInteger, Value: BitFieldProjectable
where
Range: RangeExpression, Range.Bound: BinaryInteger, Value: BitFieldProjectable

@attached(accessor)
public macro ReadOnly<Value>(bits: UnboundedRange, as: Value.Type = Never.self) =
public macro ReadOnly<Value>(
bits: UnboundedRange, as: Value.Type = Never.self
) =
#externalMacro(module: "MMIOMacros", type: "ReadOnlyMacro")
where Value: BitFieldProjectable

@attached(accessor)
public macro WriteOnly<Range, Value>(bits: Range..., as: Value.Type = Never.self) =
public macro WriteOnly<Range, Value>(
bits: Range..., as: Value.Type = Never.self
) =
#externalMacro(module: "MMIOMacros", type: "WriteOnlyMacro")
where Range: RangeExpression, Range.Bound: BinaryInteger, Value: BitFieldProjectable
where
Range: RangeExpression, Range.Bound: BinaryInteger, Value: BitFieldProjectable

@attached(accessor)
public macro WriteOnly<Value>(bits: UnboundedRange, as: Value.Type = Never.self) =
public macro WriteOnly<Value>(
bits: UnboundedRange, as: Value.Type = Never.self
) =
#externalMacro(module: "MMIOMacros", type: "WriteOnlyMacro")
where Value: BitFieldProjectable
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ struct Argument<Container: ArgumentContainer>: ArgumentProtocol {
}

extension Argument {
init<T>(label: String) where T: ExpressibleByExprSyntax, Container == ExactlyOne<T> {
init<T>(label: String)
where T: ExpressibleByExprSyntax, Container == ExactlyOne<T> {
self.label = label
self.container = nil
}

init<T>(label: String) where T: ExpressibleByExprSyntax, Container == ZeroOrOne<T> {
init<T>(label: String)
where T: ExpressibleByExprSyntax, Container == ZeroOrOne<T> {
self.label = label
self.container = .init(parsed: nil)
}

init<T>(label: String) where T: ExpressibleByExprSyntax, Container == OneOrMore<T> {
init<T>(label: String)
where T: ExpressibleByExprSyntax, Container == OneOrMore<T> {
self.label = label
self.container = nil
}
Expand Down
11 changes: 8 additions & 3 deletions Sources/MMIOUtilities/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public func zip<Input, A, B>(
}

extension Parser {
public func map<T>(_ f: @escaping @Sendable (Output) -> T) -> Parser<Input, T> {
public func map<T>(_ f: @escaping @Sendable (Output) -> T) -> Parser<Input, T>
{
.init { input in self.run(&input).map(f) }
}
}
Expand Down Expand Up @@ -130,12 +131,16 @@ extension Parser {
zip(self, p).map { ab, c in (ab.0, ab.1, c) }
}

public func take<A, B, C, D>(_ p: Parser<Input, D>) -> Parser<Input, (A, B, C, D)>
public func take<A, B, C, D>(_ p: Parser<Input, D>) -> Parser<
Input, (A, B, C, D)
>
where Output == (A, B, C) {
zip(self, p).map { abc, d in (abc.0, abc.1, abc.2, d) }
}

public func take<A, B, C, D, E>(_ p: Parser<Input, E>) -> Parser<Input, (A, B, C, D, E)>
public func take<A, B, C, D, E>(_ p: Parser<Input, E>) -> Parser<
Input, (A, B, C, D, E)
>
where Output == (A, B, C, D) {
zip(self, p).map { abcd, e in (abcd.0, abcd.1, abcd.2, abcd.3, e) }
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/SVD/Macros/SVDMacros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
macro XMLAttribute() =
#externalMacro(module: "SVDMacros", type: "XMLMarkerMacro")

@attached(extension, names: named(init(_:)), conformances: XMLElementInitializable)
@attached(
extension, names: named(init(_:)), conformances: XMLElementInitializable)
macro XMLElement() =
#externalMacro(module: "SVDMacros", type: "XMLElementMacro")

Expand Down
12 changes: 9 additions & 3 deletions Sources/SVD/Models/SVDWriteConstraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ extension SVDWriteConstraint: Sendable {}

extension SVDWriteConstraint: XMLElementInitializable {
init(_ element: XMLElement) throws {
if let value = try? element.decode(SVDWriteConstraintWriteAsRead.self, fromChild: "writeAsRead") {
if let value = try? element.decode(
SVDWriteConstraintWriteAsRead.self, fromChild: "writeAsRead")
{
self = .writeAsRead(value)
} else if let value = try? element.decode(Bool.self, fromChild: "useEnumeratedValues") {
} else if let value = try? element.decode(
Bool.self, fromChild: "useEnumeratedValues")
{
self = .useEnumeratedValues(value)
} else if let value = try? element.decode(SVDWriteConstraintRange.self, fromChild: "range") {
} else if let value = try? element.decode(
SVDWriteConstraintRange.self, fromChild: "range")
{
self = .range(value)
} else {
throw XMLError.unknownElement(element)
Expand Down
3 changes: 2 additions & 1 deletion Sources/SVD2LLDB/DataStructures/PrefixTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ extension PrefixTree {
}

private func insert(element: Element) -> PrefixTree {
guard let tree = self.children.first(where: { $0.element == element }) else {
guard let tree = self.children.first(where: { $0.element == element })
else {
let tree = Self(element: element)
self.children.append(tree)
return tree
Expand Down
20 changes: 15 additions & 5 deletions Sources/SVD2LLDB/Extensions/SVD/SVDItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,18 @@ extension SVDRegister: SVDItem {
if let protection = registerProperties.protection {
info.append(("Protection", "\(protection)"))
}
if let dataType = self.dataType { info.append(("Data Type", "\(dataType)")) }
if let dataType = self.dataType {
info.append(("Data Type", "\(dataType)"))
}
if let modifiedWriteValues = self.modifiedWriteValues {
info.append(("Modified Write Values", "\(modifiedWriteValues)"))
}
if let writeConstraint = self.writeConstraint { info.append(("Write Constraint", "\(writeConstraint)")) }
if let readAction = self.readAction { info.append(("Read Action", "\(readAction)")) }
if let writeConstraint = self.writeConstraint {
info.append(("Write Constraint", "\(writeConstraint)"))
}
if let readAction = self.readAction {
info.append(("Read Action", "\(readAction)"))
}
if let fields = self.fields, !fields.field.isEmpty {
let description = fields.field.lazy.map(\.name).joined(separator: ", ")
info.append(("Fields", "[\(description)]"))
Expand All @@ -199,8 +205,12 @@ extension SVDField: SVDItem {
if let modifiedWriteValues = self.modifiedWriteValues {
info.append(("Modified Write Values", "\(modifiedWriteValues)"))
}
if let writeConstraint = self.writeConstraint { info.append(("Write Constraint", "\(writeConstraint)")) }
if let readAction = self.readAction { info.append(("Read Action", "\(readAction)")) }
if let writeConstraint = self.writeConstraint {
info.append(("Write Constraint", "\(writeConstraint)"))
}
if let readAction = self.readAction {
info.append(("Read Action", "\(readAction)"))
}
return info
}
}
3 changes: 2 additions & 1 deletion Sources/SVD2Swift/Extensions/Formatting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ extension String.StringInterpolation {
}

mutating func appendInterpolation(identifier: String) {
let name = identifier.replacingOccurrences(of: "-", with: "_").quotingReservedWords
let name = identifier.replacingOccurrences(of: "-", with: "_")
.quotingReservedWords
self.appendLiteral(name)
}
}
16 changes: 11 additions & 5 deletions Sources/SVD2Swift/Extensions/SVD+Export.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ extension SVDDevice {
parentTypes.append(deviceName)
}

var exportQueue = [([any SVDExportable], [String], SVDRegisterProperties)]()
var exportQueue = [
([any SVDExportable], [String], SVDRegisterProperties)
]()
exportQueue.append(([peripheral], parentTypes, self.registerProperties))

// Track indices instead of popping front to avoid O(N) pop.
Expand All @@ -121,7 +123,8 @@ extension SVDDevice {
if currentIndex != exportQueue.startIndex {
context.outputWriter.append("\n")
}
let (elements, parentTypes, registerProperties) = exportQueue[currentIndex]
let (elements, parentTypes, registerProperties) = exportQueue[
currentIndex]
if !parentTypes.isEmpty {
let parentTypeFullName = parentTypes.joined(separator: ".")
context.outputWriter.append("extension \(parentTypeFullName) {\n")
Expand Down Expand Up @@ -179,7 +182,8 @@ extension SVDPeripheral: SVDExportable {
var exports = [any SVDExportable]()
if let derivedFrom = self.derivedFrom {
// FIXME: Handle only exporting B where B deriveFrom A
context.outputWriter.append("\(context.accessLevel)typealias \(typeName) = \(derivedFrom)\n")
context.outputWriter.append(
"\(context.accessLevel)typealias \(typeName) = \(derivedFrom)\n")
} else {
context.outputWriter.append(
"""
Expand Down Expand Up @@ -297,7 +301,8 @@ extension SVDCluster: SVDExportable {
var exports = [any SVDExportable]()

if let derivedFrom = self.derivedFrom {
context.outputWriter.append("\(context.accessLevel)typealias \(self.swiftName) = \(derivedFrom)\n")
context.outputWriter.append(
"\(context.accessLevel)typealias \(self.swiftName) = \(derivedFrom)\n")
} else {

context.outputWriter.append(
Expand Down Expand Up @@ -401,7 +406,8 @@ extension SVDRegister: SVDExportable {
context.outputWriter.append("}\n")
} else {
// FIXME: warning diagnostic
print("warning: skipped exporting \(self.swiftName): unknown register size")
print(
"warning: skipped exporting \(self.swiftName): unknown register size")
}
return ([], registerProperties)
}
Expand Down
3 changes: 2 additions & 1 deletion SupportingFiles/Tools/swift-format/.swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 120,
"lineLength" : 80,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
Expand Down Expand Up @@ -62,6 +62,7 @@
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : true
},
"spacesBeforeEndOfLineComments": 2,
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 2,
"version" : 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ final class MMIOTracingInterposerEventTests: XCTestCase {
MMIOTracingInterposerEvent(load: false, address: 0x10, size: 8, value: 1))
XCTAssertEqual(
MMIOTracingInterposerEvent.store(of: UInt16(2), to: 0x10),
MMIOTracingInterposerEvent(load: false, address: 0x10, size: 16, value: 2))
MMIOTracingInterposerEvent(load: false, address: 0x10, size: 16, value: 2)
)
XCTAssertEqual(
MMIOTracingInterposerEvent.store(of: UInt32(3), to: 0x10),
MMIOTracingInterposerEvent(load: false, address: 0x10, size: 32, value: 3))
MMIOTracingInterposerEvent(load: false, address: 0x10, size: 32, value: 3)
)
XCTAssertEqual(
MMIOTracingInterposerEvent.store(of: UInt64(4), to: 0x10),
MMIOTracingInterposerEvent(load: false, address: 0x10, size: 64, value: 4))
MMIOTracingInterposerEvent(load: false, address: 0x10, size: 64, value: 4)
)
}

func test_description() {
Expand Down
21 changes: 15 additions & 6 deletions Tests/MMIOMacrosTests/Macros/RegisterBlockMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,42 @@ final class RegisterBlockMacroTests: XCTestCase {
diagnostics: [
.init(
message:
ErrorDiagnostic.expectedMemberAnnotatedWithMacro(registerBlockMemberMacros).message,
ErrorDiagnostic.expectedMemberAnnotatedWithMacro(
registerBlockMemberMacros
).message,
line: 3,
column: 3,
highlights: ["var v1: Int"],
fixIts: [
.init(message: "Insert '@RegisterBlock(offset:)' macro"),
.init(message: "Insert '@RegisterBlock(offset:stride:count:)' macro"),
.init(
message: "Insert '@RegisterBlock(offset:stride:count:)' macro"),
]),
.init(
message:
ErrorDiagnostic.expectedMemberAnnotatedWithMacro(registerBlockMemberMacros).message,
ErrorDiagnostic.expectedMemberAnnotatedWithMacro(
registerBlockMemberMacros
).message,
line: 4,
column: 3,
highlights: ["@OtherAttribute var v2: Int"],
fixIts: [
.init(message: "Insert '@RegisterBlock(offset:)' macro"),
.init(message: "Insert '@RegisterBlock(offset:stride:count:)' macro"),
.init(
message: "Insert '@RegisterBlock(offset:stride:count:)' macro"),
]),
.init(
message:
ErrorDiagnostic.expectedMemberAnnotatedWithMacro(registerBlockMemberMacros).message,
ErrorDiagnostic.expectedMemberAnnotatedWithMacro(
registerBlockMemberMacros
).message,
line: 5,
column: 3,
highlights: ["var v3: Int { willSet {} }"],
fixIts: [
.init(message: "Insert '@RegisterBlock(offset:)' macro"),
.init(message: "Insert '@RegisterBlock(offset:stride:count:)' macro"),
.init(
message: "Insert '@RegisterBlock(offset:stride:count:)' macro"),
]),
],
macros: Self.macros,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import XCTest
@testable import MMIOMacros

final class RegisterBlockOffsetMacroTests: XCTestCase {
typealias ErrorDiagnostic = MMIOMacros.ErrorDiagnostic<RegisterBlockScalarMemberMacro>
typealias ErrorDiagnostic = MMIOMacros.ErrorDiagnostic<
RegisterBlockScalarMemberMacro
>

static let macros: [String: Macro.Type] = [
"RegisterBlock": RegisterBlockScalarMemberMacro.self
Expand Down
12 changes: 9 additions & 3 deletions Tests/MMIOMacrosTests/Macros/RegisterMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ final class RegisterMacroTests: XCTestCase {
""",
diagnostics: [
.init(
message: ErrorDiagnostic.expectedMemberAnnotatedWithMacro(bitFieldMacros).message,
message: ErrorDiagnostic.expectedMemberAnnotatedWithMacro(
bitFieldMacros
).message,
line: 3,
column: 3,
highlights: ["var v1: Int"],
Expand All @@ -111,7 +113,9 @@ final class RegisterMacroTests: XCTestCase {
.init(message: "Insert '@WriteOnly(bits:as:)' macro"),
]),
.init(
message: ErrorDiagnostic.expectedMemberAnnotatedWithMacro(bitFieldMacros).message,
message: ErrorDiagnostic.expectedMemberAnnotatedWithMacro(
bitFieldMacros
).message,
line: 4,
column: 3,
highlights: ["@OtherAttribute var v2: Int"],
Expand All @@ -122,7 +126,9 @@ final class RegisterMacroTests: XCTestCase {
.init(message: "Insert '@WriteOnly(bits:as:)' macro"),
]),
.init(
message: ErrorDiagnostic.expectedMemberAnnotatedWithMacro(bitFieldMacros).message,
message: ErrorDiagnostic.expectedMemberAnnotatedWithMacro(
bitFieldMacros
).message,
line: 5,
column: 3,
highlights: ["var v3: Int { willSet {} }"],
Expand Down
Loading

0 comments on commit 08e0b24

Please sign in to comment.