1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
public import SWBUtil
/// A SourceTree enum describes the root of the path of a Reference object, for those subclasses of Reference which use the SourceTree-Path model.
public enum SourceTree: Equatable, CustomDebugStringConvertible, Sendable {
/// A Reference whose SourceTree is Absolute has its absolute path fully described by its path variable.
case absolute
/// A Reference whose SourceTree is GroupRelative defines its path in terms of the path of its parent group.
case groupRelative
/// A Reference whose SourceTree is BuildSetting relative defines its path as relative to the evaluated value of the build setting name in the enum's associated value.
//
// FIXME: This should be a MacroExpressionSource.
case buildSetting(String)
public var debugDescription: String {
switch self {
case .absolute: return ".absolute"
case .groupRelative: return ".groupRelative"
case .buildSetting(let s): return ".buildSetting(\(s))"
}
}
}
// MARK: SerializableCodable
extension SourceTree: PendingSerializableCodable {
public init(fromLegacy deserializer: any Deserializer) throws {
try deserializer.beginAggregate(2)
switch try deserializer.deserialize() as Int {
case 0:
try deserializer.deserializeNilThrow()
self = .absolute
case 1:
try deserializer.deserializeNilThrow()
self = .groupRelative
case 2:
self = .buildSetting(try deserializer.deserialize())
case let v:
throw DeserializerError.unexpectedValue("Unexpected type code (\(v))")
}
}
public func legacySerialize<T: Serializer>(to serializer: T) {
serializer.serializeAggregate(2) {
switch self {
case .absolute:
serializer.serialize(0 as Int)
serializer.serializeNil()
case .groupRelative:
serializer.serialize(1 as Int)
serializer.serializeNil()
case .buildSetting(let value):
serializer.serialize(2 as Int)
serializer.serialize(value)
}
}
}
}
|