Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rust-code-analysis for mozilla-central #270

Merged
merged 2 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions rust-code-analysis-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ fn act_on_file(language: Option<LANG>, path: PathBuf, cfg: &Config) -> std::io::
action::<Dump>(&language, source, &path, pr, cfg)
} else if cfg.metrics {
if let Some(output_format) = &cfg.output_format {
let space = get_function_spaces(&language, source, &path, pr).unwrap();
output_format.dump_formats(&space, &path, &cfg.output, cfg.pretty)
if let Some(space) = get_function_spaces(&language, source, &path, pr) {
output_format.dump_formats(&space, &path, &cfg.output, cfg.pretty)
} else {
Ok(())
}
} else {
let cfg = MetricsCfg { path };
action::<Metrics>(&language, source, &cfg.path.clone(), pr, cfg)
Expand Down
25 changes: 14 additions & 11 deletions src/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,26 @@ fn compute_halstead_and_mi<'a, T: ParserTrait>(state: &mut State<'a>) {
}

fn finalize<'a, T: ParserTrait>(state_stack: &mut Vec<State<'a>>, diff_level: usize) {
if state_stack.is_empty() {
return;
}
for _ in 0..diff_level {
if state_stack.len() <= 1 {
if state_stack.len() == 1 {
let mut last_state = state_stack.last_mut().unwrap();
compute_halstead_and_mi::<T>(&mut last_state);
break;
}

let mut state = state_stack.pop().unwrap();
compute_halstead_and_mi::<T>(&mut state);
} else {
let mut state = state_stack.pop().unwrap();
compute_halstead_and_mi::<T>(&mut state);

let mut last_state = state_stack.last_mut().unwrap();
last_state.halstead_maps.merge(&state.halstead_maps);
compute_halstead_and_mi::<T>(&mut last_state);
let mut last_state = state_stack.last_mut().unwrap();
last_state.halstead_maps.merge(&state.halstead_maps);
compute_halstead_and_mi::<T>(&mut last_state);

// Merge function spaces
last_state.space.metrics.merge(&state.space.metrics);
last_state.space.spaces.push(state.space);
// Merge function spaces
last_state.space.metrics.merge(&state.space.metrics);
last_state.space.spaces.push(state.space);
}
}
}

Expand Down