Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions Sources/Meta/Reference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ public enum ReferenceName: Hashable, MetaSwiftConvertible {
case custom(String)
}

public enum CastingType: Hashable, MetaSwiftConvertible {
case strict(TypeIdentifier)
case optional(TypeIdentifier)

public var swiftString: String {
switch self {
case .strict(let typeIdentifier):
return " as \(typeIdentifier.reference.swiftString)"
case .optional(let typeIdentifier):
return " as? \(typeIdentifier.reference.swiftString)"
}
}
}

public enum Reference: Hashable, MetaSwiftConvertible, Node {
case type(TypeIdentifier)
case name(ReferenceName)
Expand All @@ -25,7 +39,7 @@ public enum Reference: Hashable, MetaSwiftConvertible, Node {
case optionalTry
case `throw`
case block(FunctionBody)
case `as`
case `as`(CastingType)
case none
indirect case dot(Reference, Reference)
indirect case assemble(Reference, Reference)
Expand Down Expand Up @@ -147,8 +161,8 @@ extension Reference {
return "throw "
case .block(let block):
return block.swiftString.prefixed(" ")
case .as:
return " as "
case .as(let castingType):
return castingType.swiftString
case .none:
return ""
}
Expand Down