Skip to content

Commit

Permalink
Removed dead code for generating non-projection class definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Oct 31, 2023
1 parent 3d0715a commit 180bb91
Showing 1 changed file with 0 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,6 @@ import WindowsMetadata
import struct Foundation.UUID

extension SwiftAssemblyModuleFileWriter {
internal func writeClass(_ classDefinition: ClassDefinition) throws {
try sourceFileWriter.writeClass(
documentation: projection.getDocumentationComment(classDefinition),
visibility: SwiftProjection.toVisibility(classDefinition.visibility, inheritableClass: !classDefinition.isSealed),
final: classDefinition.isSealed,
name: projection.toTypeName(classDefinition),
typeParameters: classDefinition.genericParams.map { $0.name },
base: projection.toBaseType(classDefinition.base),
protocolConformances: classDefinition.baseInterfaces.compactMap { try projection.toBaseType($0.interface.asBoundType) }) { writer throws in
try writeTypeAliasesForBaseGenericArgs(of: classDefinition, to: writer)
try writeClassMembers(classDefinition, to: writer)
}
}

fileprivate func writeTypeAliasesForBaseGenericArgs(of typeDefinition: TypeDefinition, to writer: SwiftTypeDefinitionWriter) throws {
var baseTypes = try typeDefinition.baseInterfaces.map { try $0.interface.asBoundType }
if let base = try typeDefinition.base {
baseTypes.insert(base, at: 0)
}

var typeAliases: Collections.OrderedDictionary<String, SwiftType> = .init()
for baseType in baseTypes {
for (i, genericArg) in baseType.genericArgs.enumerated() {
typeAliases[baseType.definition.genericParams[i].name] = try projection.toType(genericArg)
}
}

for entry in typeAliases {
writer.writeTypeAlias(visibility: .public, name: entry.key, typeParameters: [], target: entry.value)
}
}

fileprivate func writeClassMembers(_ classDefinition: ClassDefinition, to writer: SwiftTypeDefinitionWriter) throws {
for property in classDefinition.properties {
if let getter = try property.getter, getter.isPublic {
try writer.writeComputedProperty(
visibility: .public,
static: property.isStatic,
override: getter.isOverride,
name: projection.toMemberName(property),
type: projection.toReturnType(property.type),
throws: true,
get: { $0.writeNotImplemented() },
set: nil)
}

if let setter = try property.setter, setter.isPublic {
// Swift does not support throwing setters, so generate a method
try writer.writeFunc(
visibility: .public,
static: property.isStatic,
override: setter.isOverride,
name: projection.toMemberName(property),
parameters: [.init(label: "_", name: "newValue", type: projection.toType(property.type))],
throws: true) { $0.writeNotImplemented() }
}
}

for method in classDefinition.methods {
guard SwiftProjection.toVisibility(method.visibility) == .public else { continue }
guard method.nameKind == .regular else { continue }
if let constructor = method as? Constructor {
try writer.writeInit(
visibility: .public,
override: try projection.isOverriding(constructor),
parameters: method.params.map { try projection.toParameter($0) },
throws: true) { $0.writeNotImplemented() }
}
else {
try writer.writeFunc(
visibility: .public,
static: method.isStatic,
override: method.isOverride,
name: projection.toMemberName(method),
typeParameters: method.genericParams.map { $0.name },
parameters: method.params.map { try projection.toParameter($0) },
throws: true,
returnType: projection.toReturnTypeUnlessVoid(method.returnType)) { $0.writeNotImplemented() }
}
}
}

internal func writeClassProjection(_ classDefinition: ClassDefinition) throws {
let typeName = try projection.toTypeName(classDefinition)
if classDefinition.isAbstract && classDefinition.isSealed {
Expand Down

0 comments on commit 180bb91

Please sign in to comment.