From d534d6ae11d6f08bdbc3e73525d8f797b9b9cf74 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 31 Oct 2024 17:33:01 +1300 Subject: Add location() method to SourceSpan struct A SourceSpan contains up to two SourceLocations: the location of the span in the parsed source file (called in_merged), and the location of the span in an original source file as per a path comment in the parsed source file (called in_source). In places where only one location can be reported, the in_source location is preferred but is not guaranteed to exist, so the in_merged location is used as a fallback. Because this pattern is used in multiple places, it was added as a method to SourceSpan and all occurrences of the pattern were replaced with a method call. --- src/translators/symbols_generator.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/translators/symbols_generator.rs') diff --git a/src/translators/symbols_generator.rs b/src/translators/symbols_generator.rs index 6db1d46..d30facd 100644 --- a/src/translators/symbols_generator.rs +++ b/src/translators/symbols_generator.rs @@ -11,8 +11,7 @@ pub fn generate_symbols_file(semantic_tokens: &[SemanticToken]) -> String { let address = token.bytecode.location.address; if address > 0xffff { break; } let name = &definition.name; - let location = token.source.in_source.as_ref() - .unwrap_or(&token.source.in_merged); + let location = token.source.location(); symbols.push_str(&format!("{address:04x} {name} {location}\n")); } } -- cgit v1.2.3-70-g09d2