Skip to content

Commit

Permalink
Assess review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
twelho committed Jun 21, 2021
1 parent 3d4e2ff commit e6deed4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion tools/kicad_rs/src/bin/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ fn main() -> DynamicResult<()> {
let file = SchematicFile::load(path)?;
let mut schematic = parse_schematic(&file, String::new())?;

// Index the parsed schematic and use the index to evaluate it
// Index the parsed schematic and use the index to evaluate it. The
// index links to the schematic using mutable references, so that's
// why the schematic itself needs to be passed in as mutable here.
let mut index = eval::index_schematic(&mut schematic)?;
eval::evaluate_schematic(&mut index)?;

Expand Down
18 changes: 9 additions & 9 deletions tools/kicad_rs/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,31 @@ pub fn index_schematic(sch: &mut Schematic) -> DynamicResult<SheetIndex> {

pub fn evaluate_schematic(index: &mut SheetIndex) -> DynamicResult<()> {
// Perform resolving recursively in depth-first order
for v in index.map.values_mut() {
if let Node::Sheet(sub_index) = v {
for node in index.map.values_mut() {
if let Node::Sheet(sub_index) = node {
evaluate_schematic(sub_index)?;
}
}

// Collect all attributes for all components
let mut paths = Vec::new();
for (k, v) in index.map.iter() {
if let Node::Component(idx) = v {
for a in idx.keys() {
paths.push(vec![k.into(), a.into()].into())
for (node_ref, node) in index.map.iter() {
if let Node::Component(component_index) = node {
for a in component_index.keys() {
paths.push(vec![node_ref.into(), a.into()].into())
}
}
}

// Evaluate all the collected attributes
for p in paths.iter() {
evaluate(index, p)?;
for path in paths.iter() {
evaluate(index, path)?;
}

Ok(())
}

fn evaluate<'a>(idx: &mut SheetIndex, p: &Path) -> DynamicResult<()> {
fn evaluate(idx: &mut SheetIndex, p: &Path) -> DynamicResult<()> {
let entry = idx
.resolve_entry(p.iter())
.ok_or(errorf("entry not found"))?;
Expand Down

0 comments on commit e6deed4

Please sign in to comment.