compiler: Support Querying For Files In Preprocessed Code

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-11 07:26:29 -04:00
parent f0f7a660a6
commit 0e2b13be93
5 changed files with 58 additions and 0 deletions
+20
View File
@@ -129,6 +129,22 @@ public struct FileSourceLocation: Equatable, CustomStringConvertible {
return "\(location)"
}).joined(separator: ",") + ")"
}
public func pathForLocation(_ location: Int) -> FilePath? {
let queried_location = SourceLocation(location, 1)
if !self.location.contains(queried_location) {
return .none
}
for nested in self.nested {
if nested.location.contains(queried_location) {
return nested.pathForLocation(location)
}
}
return self.getPath()
}
}
/// Represent preprocessed P4 code.
@@ -197,6 +213,10 @@ public struct SourceCode {
public func getLocations() -> FileSourceLocation {
return self.locations
}
public func pathForLocation(_ location: Int) -> FilePath? {
return self.locations.pathForLocation(location)
}
}
func do_preprocess(