Skip to content

Commit

Permalink
Renamed SwiftProjection to Projection.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Sep 15, 2024
1 parent f0a1aaf commit ebf17f9
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 108 deletions.
8 changes: 4 additions & 4 deletions Generator/Sources/ProjectionModel/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import DotNetMetadata
import DotNetXMLDocs

public final class Module {
public unowned let projection: SwiftProjection
public unowned let projection: Projection
public let name: String
public let abiModuleName: String
public let flattenNamespaces: Bool
Expand All @@ -15,7 +15,7 @@ public final class Module {

public private(set) var genericInstantiationsByDefinition = [TypeDefinition: [[TypeNode]]]()

internal init(projection: SwiftProjection, name: String, flattenNamespaces: Bool = false) {
internal init(projection: Projection, name: String, flattenNamespaces: Bool = false) {
self.projection = projection
self.name = name
self.abiModuleName = name + CAbi.moduleSuffix
Expand Down Expand Up @@ -60,7 +60,7 @@ public final class Module {

public func getNamespaceModuleName(namespace: String) -> String {
precondition(!flattenNamespaces)
return "\(name)_\(SwiftProjection.toCompactNamespace(namespace))"
return "\(name)_\(Projection.toCompactNamespace(namespace))"
}

internal func getName(_ typeDefinition: TypeDefinition, namespaced: Bool = true) throws -> String {
Expand All @@ -73,7 +73,7 @@ public final class Module {
result += try getName(enclosingType, namespaced: namespaced) + "_"
}
else if namespaced && !flattenNamespaces {
result += typeDefinition.namespace.flatMap { SwiftProjection.toCompactNamespace($0) + "_" } ?? ""
result += typeDefinition.namespace.flatMap { Projection.toCompactNamespace($0) + "_" } ?? ""
}

result += typeDefinition.nameWithoutGenericArity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import CodeWriters
import DotNetMetadata
import WindowsMetadata

extension SwiftProjection {
extension Projection {
public func toABIType(_ type: BoundType) throws -> SwiftType {
if let classDefinition = type.definition as? ClassDefinition {
// The ABI representation of a (non-static) class is that of its default interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import DotNetMetadata
import DotNetXMLDocs
import WindowsMetadata

extension SwiftProjection {
extension Projection {
public static func toVisibility(_ visibility: DotNetMetadata.Visibility, inheritableClass: Bool = false) -> SwiftVisibility {
switch visibility {
case .compilerControlled: return .fileprivate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import CodeWriters
import DotNetMetadata
import DotNetXMLDocs

extension SwiftProjection {
extension Projection {
public func getDocumentation(_ typeDefinition: TypeDefinition) -> MemberDocumentation? {
guard let documentation = assembliesToModules[typeDefinition.assembly]?.documentation else { return nil }
return documentation.members[.type(toDocumentationTypeReference(typeDefinition))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CodeWriters
import DotNetMetadata

extension SwiftProjection {
extension Projection {
internal func toParamName(_ param: ParamBase) -> String {
switch param {
case is ReturnParam: "_result"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import DotNetMetadata
import WindowsMetadata
import CodeWriters

extension SwiftProjection {
extension Projection {
public func toType(_ type: TypeNode) throws -> SwiftType {
switch type {
case let .bound(type):
Expand Down Expand Up @@ -116,7 +116,7 @@ extension SwiftProjection {
else {
return .chain([
.init(projectionTypeName),
.init(try SwiftProjection.toProjectionInstantiationTypeName(genericArgs: type.genericArgs))
.init(try Projection.toProjectionInstantiationTypeName(genericArgs: type.genericArgs))
])
}
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Collections
import DotNetMetadata
import DotNetXMLDocs

public class SwiftProjection {
public class Projection {
internal struct AssemblyEntry {
var module: Module
var documentation: AssemblyDocumentation?
Expand Down
22 changes: 11 additions & 11 deletions Generator/Sources/SwiftWinRT/Writing/ABIProjectionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CodeWriters
import struct Foundation.UUID

/// Writes a type or extension providing the ABIProjection conformance for a given projected WinRT type.
internal func writeABIProjectionConformance(_ typeDefinition: TypeDefinition, genericArgs: [TypeNode]?, projection: SwiftProjection, to writer: SwiftSourceFileWriter) throws {
internal func writeABIProjectionConformance(_ typeDefinition: TypeDefinition, genericArgs: [TypeNode]?, projection: Projection, to writer: SwiftSourceFileWriter) throws {
if SupportModules.WinRT.getBuiltInTypeKind(typeDefinition) == .definitionAndProjection {
// The support module already defines a projection, just import and reexport it.
if typeDefinition.isReferenceType {
Expand Down Expand Up @@ -70,7 +70,7 @@ internal func writeABIProjectionConformance(_ typeDefinition: TypeDefinition, ge
type: .identifier(projection.toProjectionTypeName(typeDefinition))) { writer in
try writeInterfaceOrDelegateProjectionType(
typeDefinition.bindType(genericArgs: genericArgs),
projectionName: try SwiftProjection.toProjectionInstantiationTypeName(genericArgs: genericArgs),
projectionName: try Projection.toProjectionInstantiationTypeName(genericArgs: genericArgs),
projection: projection,
to: writer)
}
Expand All @@ -79,15 +79,15 @@ internal func writeABIProjectionConformance(_ typeDefinition: TypeDefinition, ge
// Generic type definition. Create a namespace for projections of specializations.
// public enum IVectorProjection {}
try writer.writeEnum(
visibility: SwiftProjection.toVisibility(typeDefinition.visibility),
visibility: Projection.toVisibility(typeDefinition.visibility),
name: projection.toProjectionTypeName(typeDefinition)) { _ in }
}
}

/// Writes an extension to a struct to provide the ABIProjection conformance.
fileprivate func writeStructProjectionExtension(
_ structDefinition: StructDefinition,
projection: SwiftProjection,
projection: Projection,
to writer: SwiftSourceFileWriter) throws {
let isInert = try projection.isProjectionInert(structDefinition)

Expand Down Expand Up @@ -139,7 +139,7 @@ fileprivate func writeStructProjectionExtension(
for (index, field) in fields.enumerated() {
if index > 0 { output.write(",", endLine: true) }
try writeStructABIToSwiftInitializerParam(
abiValueName: "value", abiFieldName: field.name, swiftFieldName: SwiftProjection.toMemberName(field),
abiValueName: "value", abiFieldName: field.name, swiftFieldName: Projection.toMemberName(field),
typeProjection: projection.getTypeProjection(field.type), to: output)
}
}
Expand All @@ -162,7 +162,7 @@ fileprivate func writeStructProjectionExtension(
for (index, field) in fields.enumerated() {
if index > 0 { output.write(",", endLine: true) }
try writeStructSwiftToABIInitializerParam(
swiftValueName: "value", swiftFieldName: SwiftProjection.toMemberName(field), abiFieldName: field.name,
swiftValueName: "value", swiftFieldName: Projection.toMemberName(field), abiFieldName: field.name,
typeProjection: projection.getTypeProjection(field.type), to: output)
}
}
Expand Down Expand Up @@ -252,7 +252,7 @@ fileprivate func writeIReferenceIDProperty(propertyName: String, parameterizedID
fileprivate func writeClassProjectionType(
_ classDefinition: ClassDefinition,
defaultInterface: BoundInterface,
projection: SwiftProjection,
projection: Projection,
to writer: SwiftSourceFileWriter) throws {
assert(!classDefinition.isStatic)

Expand All @@ -262,7 +262,7 @@ fileprivate func writeClassProjectionType(

let projectionTypeName = try projection.toProjectionTypeName(classDefinition)
try writer.writeClass(
visibility: SwiftProjection.toVisibility(classDefinition.visibility),
visibility: Projection.toVisibility(classDefinition.visibility),
name: projectionTypeName, protocolConformances: [ projectionProtocol ]) { writer throws in
let typeName = try projection.toTypeName(classDefinition)

Expand Down Expand Up @@ -295,7 +295,7 @@ fileprivate func writeClassProjectionType(
fileprivate func writeInterfaceOrDelegateProjectionType(
_ type: BoundType,
projectionName: String,
projection: SwiftProjection,
projection: Projection,
to writer: some SwiftDeclarationWriter) throws {
precondition(type.definition is InterfaceDefinition || type.definition is DelegateDefinition)
let projectionProtocol = type.definition is InterfaceDefinition
Expand All @@ -304,7 +304,7 @@ fileprivate func writeInterfaceOrDelegateProjectionType(
// Projections of generic instantiations are not owned by any specific module.
// Making them internal avoids clashes between redundant definitions across modules.
try writer.writeEnum(
visibility: type.genericArgs.isEmpty ? SwiftProjection.toVisibility(type.definition.visibility) : .internal,
visibility: type.genericArgs.isEmpty ? Projection.toVisibility(type.definition.visibility) : .internal,
name: projectionName,
protocolConformances: [ projectionProtocol ]) { writer throws in

Expand Down Expand Up @@ -361,7 +361,7 @@ internal func writeReferenceTypeProjectionConformance(
apiType: BoundType, abiType: BoundType,
wrapImpl: (_ writer: inout SwiftStatementWriter, _ paramName: String) throws -> Void,
toCOMImpl: ((_ writer: inout SwiftStatementWriter, _ paramName: String) throws -> Void)? = nil,
projection: SwiftProjection,
projection: Projection,
to writer: SwiftTypeDefinitionWriter) throws {
writer.writeTypeAlias(visibility: .public, name: "SwiftObject",
target: try projection.toType(apiType.asNode).unwrapOptional())
Expand Down
4 changes: 2 additions & 2 deletions Generator/Sources/SwiftWinRT/Writing/COMImportClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal func writeCOMImportClass(
visibility: SwiftVisibility,
name: String,
projectionName: String,
projection: SwiftProjection,
projection: Projection,
to writer: SwiftTypeDefinitionWriter) throws {
let importBaseTypeName: String
let protocolConformances: [SwiftType]
Expand Down Expand Up @@ -66,7 +66,7 @@ internal func writeCOMImportClass(

/// Gathers all generic arguments from the given interfaces and writes them as type aliases
/// For example, if an interface is IMap<String, Int32>, write K = String and V = Int32
internal func writeGenericTypeAliases(interfaces: [BoundInterface], projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
internal func writeGenericTypeAliases(interfaces: [BoundInterface], projection: Projection, to writer: SwiftTypeDefinitionWriter) throws {
var typeAliases = OrderedDictionary<String, SwiftType>()

for interface in interfaces {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ProjectionModel
import CodeWriters
import struct Foundation.UUID

internal func writeCOMInteropExtension(abiType: BoundType, projection: SwiftProjection, to writer: SwiftSourceFileWriter) throws {
internal func writeCOMInteropExtension(abiType: BoundType, projection: Projection, to writer: SwiftSourceFileWriter) throws {
let abiSwiftType = try projection.toABIType(abiType)
let visibility: SwiftVisibility = abiType.genericArgs.isEmpty ? .public : .internal

Expand Down Expand Up @@ -69,15 +69,15 @@ internal func toIIDExpression(_ uuid: UUID) throws -> String {
fileprivate func writeCOMInteropMethod(
_ method: Method, typeGenericArgs: [TypeNode],
visibility: SwiftVisibility, methodKind: ABIMethodKind,
projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
projection: Projection, to writer: SwiftTypeDefinitionWriter) throws {
let abiMethodName = try method.findAttribute(OverloadAttribute.self)?.methodName ?? method.name
let (paramProjections, returnProjection) = try projection.getParamProjections(
method: method, genericTypeArgs: typeGenericArgs, abiKind: methodKind)

// Generic instantiations can exist in multiple modules, so use internal visibility to avoid collisions
try writer.writeFunc(
visibility: visibility,
name: SwiftProjection.toInteropMethodName(method),
name: Projection.toInteropMethodName(method),
params: paramProjections.map { $0.toSwiftParam() },
throws: true, returnType: returnProjection.map { $0.typeProjection.swiftType }) { writer in
try writeSwiftToABICall(
Expand Down
26 changes: 13 additions & 13 deletions Generator/Sources/SwiftWinRT/Writing/ClassDefinition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ProjectionModel
import WindowsMetadata
import struct Foundation.UUID

internal func writeClassDefinition(_ classDefinition: ClassDefinition, projection: SwiftProjection, to writer: SwiftSourceFileWriter) throws {
internal func writeClassDefinition(_ classDefinition: ClassDefinition, projection: Projection, to writer: SwiftSourceFileWriter) throws {
let classKind = try ClassKind(classDefinition)
let interfaces = try ClassInterfaces(of: classDefinition, kind: classKind)
let typeName = try projection.toTypeName(classDefinition)
Expand Down Expand Up @@ -39,7 +39,7 @@ internal func writeClassDefinition(_ classDefinition: ClassDefinition, projectio

try writer.writeClass(
documentation: projection.getDocumentationComment(classDefinition),
visibility: SwiftProjection.toVisibility(classDefinition.visibility, inheritableClass: !classDefinition.isSealed),
visibility: Projection.toVisibility(classDefinition.visibility, inheritableClass: !classDefinition.isSealed),
final: classDefinition.isSealed, name: typeName, base: base, protocolConformances: protocolConformances) { writer in
try writeClassMembers(
classDefinition, interfaces: interfaces, kind: classKind,
Expand All @@ -52,7 +52,7 @@ internal func writeClassDefinition(_ classDefinition: ClassDefinition, projectio

try writer.writeEnum(
documentation: projection.getDocumentationComment(classDefinition),
visibility: SwiftProjection.toVisibility(classDefinition.visibility),
visibility: Projection.toVisibility(classDefinition.visibility),
name: typeName) { writer in
try writeClassMembers(
classDefinition, interfaces: interfaces, kind: .static,
Expand Down Expand Up @@ -135,7 +135,7 @@ fileprivate struct ClassInterfaces {

fileprivate func writeClassMembers(
_ classDefinition: ClassDefinition, interfaces: ClassInterfaces, kind: ClassKind,
projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
projection: Projection, to writer: SwiftTypeDefinitionWriter) throws {
try writeGenericTypeAliases(interfaces: classDefinition.baseInterfaces.map { try $0.interface }, projection: projection, to: writer)

try writeClassInterfaceImplementations(
Expand All @@ -158,7 +158,7 @@ fileprivate func writeClassMembers(

fileprivate func writeClassInterfaceImplementations(
_ classDefinition: ClassDefinition, interfaces: ClassInterfaces, kind: ClassKind,
projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
projection: Projection, to writer: SwiftTypeDefinitionWriter) throws {
if interfaces.hasDefaultFactory {
writeMarkComment(forInterface: "IActivationFactory", to: writer)
try writeDefaultActivatableInitializer(classDefinition, projection: projection, to: writer)
Expand Down Expand Up @@ -208,7 +208,7 @@ fileprivate func writeClassInterfaceImplementations(

fileprivate func writeClassInterfaceProperties(
_ classDefinition: ClassDefinition, interfaces: ClassInterfaces, kind: ClassKind,
projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
projection: Projection, to writer: SwiftTypeDefinitionWriter) throws {
// Instance properties, initializers and deinit
if kind.isComposable, let defaultInterface = interfaces.default {
try SecondaryInterfaces.writeDeclaration(
Expand Down Expand Up @@ -241,7 +241,7 @@ fileprivate func writeClassInterfaceProperties(

fileprivate func writeClassOverrideSupport(
_ classDefinition: ClassDefinition, interfaces: [BoundInterface],
projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
projection: Projection, to writer: SwiftTypeDefinitionWriter) throws {
let outerPropertySuffix = "outer"

for interface in interfaces {
Expand Down Expand Up @@ -292,7 +292,7 @@ fileprivate func writeMarkComment(forInterface interfaceName: String, to writer:

fileprivate func writeComposableInitializers(
_ classDefinition: ClassDefinition, factoryInterface: InterfaceDefinition, base: ClassDefinition?,
projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
projection: Projection, to writer: SwiftTypeDefinitionWriter) throws {
let propertyName = SecondaryInterfaces.getPropertyName(factoryInterface.bind())

for method in factoryInterface.methods {
Expand All @@ -311,7 +311,7 @@ fileprivate func writeComposableInitializers(
let innerObjectParamName = params[params.count - 1].name
output.writeFullLine("(\(outerObjectParamName), \(innerObjectParamName): inout IInspectablePointer?) in")
try writeInteropMethodCall(
name: SwiftProjection.toInteropMethodName(method), params: params, returnParam: returnParam,
name: Projection.toInteropMethodName(method), params: params, returnParam: returnParam,
thisPointer: .init(name: "Self.\(propertyName)", lazy: true),
projection: projection, to: writer.output)
}
Expand All @@ -321,7 +321,7 @@ fileprivate func writeComposableInitializers(

fileprivate func writeDefaultActivatableInitializer(
_ classDefinition: ClassDefinition,
projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
projection: Projection, to writer: SwiftTypeDefinitionWriter) throws {
let documentationComment: SwiftDocumentationComment?
if let constructor = classDefinition.findConstructor(arity: 0, inherited: false) {
documentationComment = try projection.getDocumentationComment(constructor)
Expand All @@ -340,7 +340,7 @@ fileprivate func writeDefaultActivatableInitializer(
fileprivate func writeActivatableInitializers(
_ classDefinition: ClassDefinition,
activationFactory: InterfaceDefinition,
projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
projection: Projection, to writer: SwiftTypeDefinitionWriter) throws {
let propertyName = SecondaryInterfaces.getPropertyName(activationFactory.bind())
for method in activationFactory.methods {
let (params, returnParam) = try projection.getParamProjections(method: method, genericTypeArgs: [], abiKind: .activationFactory)
Expand All @@ -356,7 +356,7 @@ fileprivate func writeActivatableInitializers(
let output = writer.output
output.write("self.init(_wrapping: ")
try writeInteropMethodCall(
name: SwiftProjection.toInteropMethodName(method), params: params, returnParam: returnParam,
name: Projection.toInteropMethodName(method), params: params, returnParam: returnParam,
thisPointer: .init(name: "Self.\(propertyName)", lazy: true),
projection: projection, to: writer.output)
output.write(")")
Expand All @@ -366,7 +366,7 @@ fileprivate func writeActivatableInitializers(
}

fileprivate func writeSupportComposableInitializers(
defaultInterface: BoundInterface, projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
defaultInterface: BoundInterface, projection: Projection, to writer: SwiftTypeDefinitionWriter) throws {
// public init(_wrapping inner: COMReference<CWinRTComponent.SWRT_IFoo>) {
// super.init(_wrapping: inner.cast())
// }
Expand Down
Loading

0 comments on commit ebf17f9

Please sign in to comment.