Skip to content

Commit

Permalink
doc: fix docstrings for SymbolTable (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasdewally authored Feb 17, 2025
1 parent 8636432 commit 4043234
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions crates/conjure_core/src/ast/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl Declaration {
}
}

/// The name of this declaration.
pub fn name(&self) -> &Name {
&self.name
}
Expand Down
22 changes: 11 additions & 11 deletions crates/conjure_core/src/ast/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ impl SymbolTable {
}
}

// Looks up the declaration with the given name in the current scope only.
//
// Returns `None` if there is no declaration with that name in the current scope.
/// Looks up the declaration with the given name in the current scope only.
///
/// Returns `None` if there is no declaration with that name in the current scope.
pub fn lookup_local(&self, name: &Name) -> Option<Rc<Declaration>> {
self.table.get(name).cloned()
}

// Looks up the declaration with the given name, checking all enclosing scopes.
//
// Returns `None` if there is no declaration with that name in scope.
/// Looks up the declaration with the given name, checking all enclosing scopes.
///
/// Returns `None` if there is no declaration with that name in scope.
pub fn lookup(&self, name: &Name) -> Option<Rc<Declaration>> {
self.lookup_local(name).or_else(|| {
self.parent
Expand All @@ -127,9 +127,9 @@ impl SymbolTable {
})
}

// Inserts a declaration into the symbol table.
//
// Returns `None` if there is already a symbol with this name in the local scope.
/// Inserts a declaration into the symbol table.
///
/// Returns `None` if there is already a symbol with this name in the local scope.
pub fn insert(&mut self, declaration: Rc<Declaration>) -> Option<()> {
let name = declaration.name().clone();
if let Entry::Vacant(e) = self.table.entry(name) {
Expand All @@ -140,7 +140,7 @@ impl SymbolTable {
}
}

// Updates or adds a declaration in the immediate local scope.
/// Updates or adds a declaration in the immediate local scope.
pub fn update_insert(&mut self, declaration: Rc<Declaration>) {
let name = declaration.name().clone();
self.table.insert(name, declaration);
Expand All @@ -156,7 +156,7 @@ impl SymbolTable {
self.lookup_local(name).and_then(|x| x.return_type())
}

// Looks up the domain of name if it has one and is in scope.
/// Looks up the domain of name if it has one and is in scope.
pub fn domain(&self, name: &Name) -> Option<Domain> {
// TODO: do not clone here: in the future, we might want to wrap all domains in Rc's to get
// clone-on-write behaviour (saving memory in scenarios such as matrix decomposition where
Expand Down

0 comments on commit 4043234

Please sign in to comment.