Skip to content

Commit

Permalink
Make RawSyntax a class
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoppen committed Sep 12, 2018
1 parent ab1f0f5 commit 6e1f86c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Sources/SwiftSyntax/RawSyntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fileprivate enum RawSyntaxData {
/// Represents the raw tree structure underlying the syntax tree. These nodes
/// have no notion of identity and only provide structure to the tree. They
/// are immutable and can be freely shared between syntax nodes.
struct RawSyntax {
final class RawSyntax {
fileprivate let data: RawSyntaxData
let presence: SourcePresence

Expand Down Expand Up @@ -124,6 +124,13 @@ struct RawSyntax {
}
}).value
}

/// Creates a copy of `other`.
init(_ other: RawSyntax) {
self.data = other.data
self.presence = other.presence
self.id = other.id
}

init(kind: SyntaxKind, layout: [RawSyntax?], presence: SourcePresence,
id: SyntaxNodeId? = nil) {
Expand Down Expand Up @@ -336,7 +343,7 @@ extension RawSyntax {

extension RawSyntax: Codable {
/// Creates a RawSyntax from the provided Foundation Decoder.
init(from decoder: Decoder) throws {
required convenience init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let id = try container.decodeIfPresent(SyntaxNodeId.self, forKey: .id)
let omitted = try container.decodeIfPresent(Bool.self, forKey: .omitted) ?? false
Expand All @@ -352,7 +359,7 @@ extension RawSyntax: Codable {
guard let lookupNode = lookupFunc(id) else {
throw IncrementalDecodingError.nodeLookupFailed(id)
}
self = lookupNode
self.init(lookupNode)
return
}

Expand Down

0 comments on commit 6e1f86c

Please sign in to comment.