Skip to content

Commit 5d32f38

Browse files
authored
fix: internal filemarker (#1294)
1 parent 61cc308 commit 5d32f38

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

compiler/plc_ast/src/pre_processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn process_global_variables(unit: &mut CompilationUnit, id_provider: &mut IdProv
189189
data_type_declaration: ref_ty.unwrap_or(global_var.data_type_declaration.clone()),
190190
initializer: None,
191191
address: None,
192-
location: SourceLocation::internal(),
192+
location: global_var.location.clone(),
193193
};
194194
mangled_globals.push(internal_mangled_var);
195195
}

compiler/plc_source/src/source_location.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,14 @@ impl SourceLocation {
331331
SourceLocation { span: CodeSpan::None, file: FileMarker::Internal }
332332
}
333333

334+
/// creates an internal SymbolLocation but specifies the CompilationUnit/File it was encountered in.
335+
/// This can be necessary when checking if dependencies are located within the same unit as the internally generated
336+
/// element
337+
pub fn internal_in_unit(unit: Option<&'static str>) -> Self {
338+
let Some(unit) = unit else { return Self::internal() };
339+
SourceLocation { span: CodeSpan::None, file: FileMarker::File(unit) }
340+
}
341+
334342
pub fn is_internal(&self) -> bool {
335343
self.file.is_internal() && self.span == CodeSpan::None
336344
}

src/index/tests/index_tests.rs

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,17 @@ fn aliased_hardware_access_variable_creates_global_var_for_address() {
17951795
linkage: Internal,
17961796
binding: None,
17971797
source_location: SourceLocation {
1798-
span: None,
1798+
span: Range(
1799+
TextLocation {
1800+
line: 2,
1801+
column: 12,
1802+
offset: 36,
1803+
}..TextLocation {
1804+
line: 2,
1805+
column: 15,
1806+
offset: 39,
1807+
},
1808+
),
17991809
},
18001810
varargs: None,
18011811
}
@@ -1936,7 +1946,17 @@ fn address_used_in_2_aliases_only_created_once() {
19361946
linkage: Internal,
19371947
binding: None,
19381948
source_location: SourceLocation {
1939-
span: None,
1949+
span: Range(
1950+
TextLocation {
1951+
line: 2,
1952+
column: 12,
1953+
offset: 36,
1954+
}..TextLocation {
1955+
line: 2,
1956+
column: 15,
1957+
offset: 39,
1958+
},
1959+
),
19401960
},
19411961
varargs: None,
19421962
},
@@ -1975,7 +1995,17 @@ fn aliased_variable_with_in_or_out_directions_create_the_same_variable() {
19751995
linkage: Internal,
19761996
binding: None,
19771997
source_location: SourceLocation {
1978-
span: None,
1998+
span: Range(
1999+
TextLocation {
2000+
line: 2,
2001+
column: 12,
2002+
offset: 36,
2003+
}..TextLocation {
2004+
line: 2,
2005+
column: 15,
2006+
offset: 39,
2007+
},
2008+
),
19792009
},
19802010
varargs: None,
19812011
},
@@ -1996,7 +2026,17 @@ fn aliased_variable_with_in_or_out_directions_create_the_same_variable() {
19962026
linkage: Internal,
19972027
binding: None,
19982028
source_location: SourceLocation {
1999-
span: None,
2029+
span: Range(
2030+
TextLocation {
2031+
line: 4,
2032+
column: 12,
2033+
offset: 112,
2034+
}..TextLocation {
2035+
line: 4,
2036+
column: 16,
2037+
offset: 116,
2038+
},
2039+
),
20002040
},
20012041
varargs: None,
20022042
},
@@ -2033,7 +2073,17 @@ fn if_two_aliased_var_of_different_types_use_the_same_address_the_first_wins() {
20332073
linkage: Internal,
20342074
binding: None,
20352075
source_location: SourceLocation {
2036-
span: None,
2076+
span: Range(
2077+
TextLocation {
2078+
line: 2,
2079+
column: 12,
2080+
offset: 36,
2081+
}..TextLocation {
2082+
line: 2,
2083+
column: 15,
2084+
offset: 39,
2085+
},
2086+
),
20372087
},
20382088
varargs: None,
20392089
},

0 commit comments

Comments
 (0)