Files
swift-mirror/SwiftCompilerSources/Sources/SIL/Location.swift
Erik Eckstein cab62320eb Swift SIL: improvements for Location
* make `var sourceLoc` return nil if the location doesn't have a valid line number
* add `var decl`
2025-04-18 06:58:39 +02:00

56 lines
1.8 KiB
Swift

//===--- Location.swift - Source location ---------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import SILBridging
import AST
public struct Location: Equatable, CustomStringConvertible {
let bridged: BridgedLocation
public var description: String {
return String(taking: bridged.getDebugDescription())
}
public var sourceLoc: SourceLoc? {
if hasValidLineNumber {
return SourceLoc(bridged: bridged.getSourceLocation())
}
return nil
}
/// Keeps the debug scope but marks it as auto-generated.
public var autoGenerated: Location {
Location(bridged: bridged.getAutogeneratedLocation())
}
public var hasValidLineNumber: Bool { bridged.hasValidLineNumber() }
public var isAutoGenerated: Bool { bridged.isAutoGenerated() }
public var isInlined: Bool { bridged.isInlined() }
public var isDebugSteppable: Bool { hasValidLineNumber && !isAutoGenerated }
/// The `Decl` if the location refers to a declaration.
public var decl: Decl? { bridged.getDecl().decl }
public static func ==(lhs: Location, rhs: Location) -> Bool {
lhs.bridged.isEqualTo(rhs.bridged)
}
public func hasSameSourceLocation(as other: Location) -> Bool {
bridged.hasSameSourceLocation(other.bridged)
}
public static var artificialUnreachableLocation: Location {
Location(bridged: BridgedLocation.getArtificialUnreachableLocation())
}
}