Add SymbolTable::{new,update_symbols}
This commit is contained in:
parent
1ce64cb2f8
commit
41106f4c3a
59
src/main.rs
59
src/main.rs
@ -46,6 +46,26 @@ pub struct SymbolTable {
|
|||||||
active: bool,
|
active: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SymbolTable {
|
||||||
|
fn new(symbols: HashMap<String, Symbol>) -> Self {
|
||||||
|
Self {
|
||||||
|
symbols,
|
||||||
|
breakpoints: IndexSet::new(),
|
||||||
|
active: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_symbols(&mut self, symbols: HashMap<String, Symbol>) {
|
||||||
|
self.breakpoints = self
|
||||||
|
.breakpoints
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.filter(|sym| symbols.contains_key(sym))
|
||||||
|
.collect::<IndexSet<_>>();
|
||||||
|
self.symbols = symbols;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type SymbolTables = IndexMap<String, SymbolTable>;
|
pub type SymbolTables = IndexMap<String, SymbolTable>;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
@ -167,11 +187,7 @@ fn main() -> Result<(), ReplError> {
|
|||||||
let table_name = Path::new(&path).file_name().unwrap().to_str().unwrap();
|
let table_name = Path::new(&path).file_name().unwrap().to_str().unwrap();
|
||||||
symbol_tables.insert(
|
symbol_tables.insert(
|
||||||
table_name.to_string(),
|
table_name.to_string(),
|
||||||
SymbolTable {
|
SymbolTable::new(read_symbol_table(path).unwrap()),
|
||||||
symbols: read_symbol_table(path).unwrap(),
|
|
||||||
breakpoints: IndexSet::new(),
|
|
||||||
active: true,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -469,31 +485,18 @@ fn main() -> Result<(), ReplError> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let symbols = read_symbol_table(file_path)?;
|
let symbols = read_symbol_table(file_path)?;
|
||||||
let (breakpoints, active) =
|
if let Some(table) = state.symbol_tables.get_mut(table_name) {
|
||||||
if let Some(table) = state.symbol_tables.get(table_name) {
|
table.update_symbols(symbols);
|
||||||
(
|
} else {
|
||||||
table
|
state
|
||||||
.breakpoints
|
.symbol_tables
|
||||||
.iter()
|
.insert(table_name.to_string(), SymbolTable::new(symbols));
|
||||||
.cloned()
|
};
|
||||||
.filter(|sym| symbols.contains_key(sym))
|
|
||||||
.collect::<IndexSet<_>>(),
|
|
||||||
table.active,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
(IndexSet::new(), true)
|
|
||||||
};
|
|
||||||
if !args.get_flag("append") {
|
if !args.get_flag("append") {
|
||||||
|
let table = state.symbol_tables.remove(table_name).unwrap();
|
||||||
state.symbol_tables.clear();
|
state.symbol_tables.clear();
|
||||||
}
|
state.symbol_tables.insert(table_name.to_string(), table);
|
||||||
state.symbol_tables.insert(
|
};
|
||||||
table_name.to_string(),
|
|
||||||
SymbolTable {
|
|
||||||
symbols,
|
|
||||||
breakpoints,
|
|
||||||
active,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user