-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed SwiftProjection to Projection and moved its Module nested cla…
…ss to the top level (#289)
- Loading branch information
1 parent
d6757d3
commit ecddb1d
Showing
28 changed files
with
213 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import Collections | ||
import DotNetMetadata | ||
import DotNetXMLDocs | ||
|
||
public final class Module { | ||
public unowned let projection: Projection | ||
public let name: String | ||
public let abiModuleName: String | ||
public let flattenNamespaces: Bool | ||
private var weakReferences: Set<Unowned<Module>> = [] | ||
|
||
// OrderedSets are not sorted. Sort it lazily for stable iteration. | ||
private var lazySortedTypeDefinitions = OrderedSet<TypeDefinition>() | ||
private var typeDefinitionsSorted = true | ||
|
||
public private(set) var genericInstantiationsByDefinition = [TypeDefinition: [[TypeNode]]]() | ||
|
||
internal init(projection: Projection, name: String, flattenNamespaces: Bool = false) { | ||
self.projection = projection | ||
self.name = name | ||
self.abiModuleName = name + CAbi.moduleSuffix | ||
self.flattenNamespaces = flattenNamespaces | ||
} | ||
|
||
public var typeDefinitions: OrderedSet<TypeDefinition> { | ||
if !typeDefinitionsSorted { | ||
lazySortedTypeDefinitions.sort { $0.fullName < $1.fullName } | ||
typeDefinitionsSorted = true | ||
} | ||
return lazySortedTypeDefinitions | ||
} | ||
|
||
public var references: [Module] { weakReferences.map { $0.object } } | ||
|
||
public var isEmpty: Bool { lazySortedTypeDefinitions.isEmpty } | ||
|
||
public func addAssembly(_ assembly: Assembly, documentation: AssemblyDocumentation? = nil) { | ||
projection.addAssembly(assembly, module: self, documentation: documentation) | ||
} | ||
|
||
public func hasTypeDefinition(_ type: TypeDefinition) -> Bool { | ||
lazySortedTypeDefinitions.contains(type) | ||
} | ||
|
||
public func addTypeDefinition(_ type: TypeDefinition) { | ||
precondition(projection.getModule(type.assembly) === self) | ||
lazySortedTypeDefinitions.append(type) | ||
typeDefinitionsSorted = false | ||
} | ||
|
||
public func addGenericInstantiation(_ type: BoundType) { | ||
precondition(!type.genericArgs.isEmpty && !type.isParameterized) | ||
guard genericInstantiationsByDefinition[type.definition]?.contains(type.genericArgs) != true else { return } | ||
genericInstantiationsByDefinition[type.definition, default: []].append(type.genericArgs) | ||
} | ||
|
||
public func addReference(_ other: Module) { | ||
weakReferences.insert(Unowned(other)) | ||
} | ||
|
||
public func getNamespaceModuleName(namespace: String) -> String { | ||
precondition(!flattenNamespaces) | ||
return "\(name)_\(Projection.toCompactNamespace(namespace))" | ||
} | ||
|
||
internal func getName(_ typeDefinition: TypeDefinition, namespaced: Bool = true) throws -> String { | ||
// Map: Namespace.TypeName | ||
// To: Namespace_TypeName | ||
// Map: Namespace.Subnamespace.TypeName/NestedTypeName | ||
// To: NamespaceSubnamespace_TypeName_NestedTypeName | ||
var result: String = "" | ||
if let enclosingType = try typeDefinition.enclosingType { | ||
result += try getName(enclosingType, namespaced: namespaced) + "_" | ||
} | ||
else if namespaced && !flattenNamespaces { | ||
result += typeDefinition.namespace.flatMap { Projection.toCompactNamespace($0) + "_" } ?? "" | ||
} | ||
|
||
result += typeDefinition.nameWithoutGenericArity | ||
|
||
return result | ||
} | ||
|
||
private static func getNamespaceOrEmpty(_ type: TypeDefinition) -> String { | ||
var namespacedType = type | ||
while namespacedType.namespace == nil, let enclosingType = try? namespacedType.enclosingType { | ||
namespacedType = enclosingType | ||
} | ||
return namespacedType.namespace ?? "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...jectionModel/SwiftProjection+params.swift → ...s/ProjectionModel/Projection+params.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
Generator/Sources/ProjectionModel/ReferenceNullability.swift
This file was deleted.
Oops, something went wrong.
93 changes: 0 additions & 93 deletions
93
Generator/Sources/ProjectionModel/SwiftProjection+Module.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.