add helpers to SymbolTables for getting tables

This commit is contained in:
pjht 2022-10-26 10:10:16 -05:00
parent 718f8cd276
commit d0f1b588f7

View File

@ -89,7 +89,7 @@ impl SymbolTables {
} }
pub fn set_active(&mut self, table: &str, active: bool) -> anyhow::Result<()> { pub fn set_active(&mut self, table: &str, active: bool) -> anyhow::Result<()> {
self.tables.get_mut(table).ok_or(InvalidSymbolTable)?.active = active; self.get_table_mut(table)?.active = active;
Ok(()) Ok(())
} }
@ -110,21 +110,12 @@ impl SymbolTables {
} }
pub fn set_breakpoint(&mut self, table: &str, symbol: String) -> anyhow::Result<()> { pub fn set_breakpoint(&mut self, table: &str, symbol: String) -> anyhow::Result<()> {
self.tables self.get_table_mut(table)?.breakpoints.insert(symbol);
.get_mut(table)
.ok_or(InvalidSymbolTable)?
.breakpoints
.insert(symbol);
Ok(()) Ok(())
} }
pub fn delete_breakpoint(&mut self, table: &str, symbol: &str) -> anyhow::Result<bool> { pub fn delete_breakpoint(&mut self, table: &str, symbol: &str) -> anyhow::Result<bool> {
Ok(self Ok(self.get_table_mut(table)?.breakpoints.shift_remove(symbol))
.tables
.get_mut(table)
.ok_or(InvalidSymbolTable)?
.breakpoints
.shift_remove(symbol))
} }
pub fn symbol_displayer(&self) -> SymbolDisplayer<'_> { pub fn symbol_displayer(&self) -> SymbolDisplayer<'_> {
@ -141,9 +132,7 @@ impl SymbolTables {
pub fn get(&self, table: &str, symbol: &str) -> anyhow::Result<&Symbol> { pub fn get(&self, table: &str, symbol: &str) -> anyhow::Result<&Symbol> {
Ok(self Ok(self
.tables .get_table(table)?
.get(table)
.ok_or(InvalidSymbolTable)?
.symbols .symbols
.get(symbol) .get(symbol)
.ok_or(InvalidSymbolName)?) .ok_or(InvalidSymbolName)?)
@ -178,4 +167,12 @@ impl SymbolTables {
pub fn parse_location_address(&self, location: &str) -> anyhow::Result<u32> { pub fn parse_location_address(&self, location: &str) -> anyhow::Result<u32> {
self.parse_location(location).map(|l| l.addr(self)) self.parse_location(location).map(|l| l.addr(self))
} }
fn get_table(&self, table: &str) -> anyhow::Result<&SymbolTable> {
Ok(self.tables.get(table).ok_or(InvalidSymbolTable)?)
}
fn get_table_mut(&mut self, table: &str) -> anyhow::Result<&mut SymbolTable> {
Ok(self.tables.get_mut(table).ok_or(InvalidSymbolTable)?)
}
} }