summaryrefslogtreecommitdiff
path: root/src/source_unit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/source_unit.rs')
-rw-r--r--src/source_unit.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/source_unit.rs b/src/source_unit.rs
index 7ee6993..bc6d4ab 100644
--- a/src/source_unit.rs
+++ b/src/source_unit.rs
@@ -115,6 +115,29 @@ pub struct Symbol {
pub role: SymbolRole,
}
+impl Symbol {
+ /// True if this symbol is a valid definition for a reference symbol
+ pub fn defines(&self, reference: &Symbol) -> bool {
+ self.name == reference.name &&
+ std::iter::zip(&self.namespace, &reference.namespace).all(|(a, b)| a == b)
+ }
+}
+
+impl PartialEq for Symbol {
+ fn eq(&self, other: &Symbol) -> bool {
+ self.name == other.name && self.namespace == other.namespace
+ }
+}
+
+impl std::fmt::Debug for Symbol {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+ for name in &self.namespace {
+ write!(f, "{name}:")?
+ }
+ write!(f, "{}", self.name)
+ }
+}
+
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum SymbolRole {
Definition(DefinitionType),