Skip to content

Commit e92f27c

Browse files
committed
Swift SIL: add some APIs to Location
* `hasValidLineNumber` * `isAutoGenerated` * `isDebugSteppable`
1 parent 0ff8663 commit e92f27c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

SwiftCompilerSources/Sources/SIL/Location.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public struct Location: Equatable, CustomStringConvertible {
2525
Location(bridged: SILLocation_getAutogeneratedLocation(bridged))
2626
}
2727

28+
public var hasValidLineNumber: Bool { bridged.hasValidLineNumber() }
29+
public var isAutoGenerated: Bool { bridged.isAutoGenerated() }
30+
31+
public var isDebugSteppable: Bool { hasValidLineNumber && !isAutoGenerated }
32+
2833
public static func ==(lhs: Location, rhs: Location) -> Bool {
2934
SILLocation_equal(lhs.bridged, rhs.bridged)
3035
}

include/swift/SIL/SILLocation.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ class SILLocation {
307307
}
308308
explicit operator bool() const { return !isNull(); }
309309

310+
bool hasValidLineNumber() const {
311+
if (isNull())
312+
return false;
313+
if (isFilenameAndLocation() && getFilenameAndLocation()->line == 0)
314+
return false;
315+
return true;
316+
}
317+
310318
/// Return true if this location is backed by an AST node.
311319
bool isASTNode() const {
312320
switch (getStorageKind()) {
@@ -691,6 +699,8 @@ class SILDebugLocation {
691699
: debugScope(debugScope), location(location) {}
692700
SILLocation getLocation() const { return location; }
693701
const SILDebugScope *getScope() const { return debugScope; }
702+
bool hasValidLineNumber() const { return location.hasValidLineNumber(); }
703+
bool isAutoGenerated() const { return location.isAutoGenerated(); }
694704
operator bool() const { return bool(location) && debugScope; }
695705
};
696706

0 commit comments

Comments
 (0)