compiler: Support Querying For Files In Preprocessed Code
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user