summaryrefslogtreecommitdiff
path: root/src/resolver.rs
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-03-08 13:52:45 +1300
committerBen Bridle <ben@derelict.engineering>2025-03-08 14:22:53 +1300
commit2daf600d4713f6feacef795fac923f5826925efb (patch)
tree5caef62e4086cccbff04c64793fedc9473a56927 /src/resolver.rs
parent869d9b4b9c6f5d095084c851af33d8590bd3edee (diff)
downloadassembler-2daf600d4713f6feacef795fac923f5826925efb.zip
Ignore source units that have already been included
There is the possibility that the same source file could be discovered twice, if the same folder is included multiple times as a library folder or if symbolic links are used that link to already-included files. These duplicate source files are now ignored, to prevent erroneous 'duplicate definition' errors from being generated.
Diffstat (limited to 'src/resolver.rs')
-rw-r--r--src/resolver.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/resolver.rs b/src/resolver.rs
index 8d3a16d..d02d80f 100644
--- a/src/resolver.rs
+++ b/src/resolver.rs
@@ -114,8 +114,15 @@ impl Resolver {
}
/// Add a set of source units that might contain definitions for unresolved symbols.
- pub fn add_library_source_units(&mut self, mut source_units: Vec<SourceUnit>) {
- self.library_source_units.append(&mut source_units);
+ pub fn add_library_source_units(&mut self, source_units: Vec<SourceUnit>) {
+ for source_unit in source_units {
+ // Discard source units that have already been included.
+ let in_included = self.source_units.iter().any(|s| s.source_unit == source_unit);
+ let in_library = self.library_source_units.iter().any(|s| *s == source_unit);
+ if !in_included && !in_library {
+ self.library_source_units.push(source_unit);
+ }
+ }
}
/// Attempt to resolve unresolved references with library source units.