summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/resolver.rs11
-rw-r--r--src/source_unit.rs11
2 files changed, 20 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.
diff --git a/src/source_unit.rs b/src/source_unit.rs
index 9c51ccb..28cc854 100644
--- a/src/source_unit.rs
+++ b/src/source_unit.rs
@@ -118,6 +118,17 @@ impl SourceUnit {
}
}
+impl PartialEq for SourceUnit {
+ fn eq(&self, other: &SourceUnit) -> bool {
+ if let Ok(this_path) = self.main.path.canonicalize() {
+ if let Ok(other_path) = other.main.path.canonicalize() {
+ return this_path == other_path;
+ }
+ }
+ return false;
+ }
+}
+
pub struct SourceFile {
pub path: PathBuf,