#![allow(
clippy::enum_glob_use,
clippy::match_same_arms,
clippy::struct_field_names,
clippy::wildcard_imports
)]
#![allow(
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
clippy::cast_sign_loss
)]
use super::*;
#[inline]
pub(crate) fn init(
node: &Node,
stats: &mut Stats,
is_func_space: bool,
is_unit: bool,
) -> (usize, usize) {
let start = node.start_row();
let end = node.end_row();
if is_func_space {
stats.sloc.start = start;
stats.sloc.end = end;
stats.sloc.unit = is_unit;
}
(start, end)
}
#[inline]
pub(crate) fn add_cloc_lines(stats: &mut Stats, start: usize, end: usize) {
let comment_diff = end - start;
let is_comment_after_code_line = stats.ploc.lines.contains(&start);
if is_comment_after_code_line && comment_diff == 0 {
add_code_comment_line(stats, start);
} else if is_comment_after_code_line && comment_diff > 0 {
add_code_comment_line(stats, start);
add_only_comment_lines(stats, start + 1, end);
} else {
add_only_comment_lines(stats, start, end);
stats.cloc.comment_line_end = Some(end);
}
}
#[inline]
pub(crate) fn check_comment_ends_on_code_line(stats: &mut Stats, start_code_line: usize) {
if let Some(end) = stats.cloc.comment_line_end
&& end == start_code_line
&& !stats.ploc.lines.contains(&start_code_line)
{
stats.cloc.only_comment_line_starts.remove(&start_code_line);
add_code_comment_line(stats, start_code_line);
}
}
#[inline]
pub(crate) fn add_code_comment_line(stats: &mut Stats, line: usize) {
stats.cloc.code_comment_line_starts.insert(line);
}
#[inline]
pub(crate) fn add_only_comment_lines(stats: &mut Stats, start: usize, end: usize) {
stats.cloc.only_comment_line_starts.extend(start..=end);
}
#[inline]
pub(crate) fn add_multiline_string_ploc(node: &Node, stats: &mut Stats, start: usize, end: usize) {
if node
.parent()
.is_none_or(|parent| parent.start_row() != start)
{
check_comment_ends_on_code_line(stats, start);
stats.ploc.lines.insert(start);
}
(start + 1..=end).for_each(|line| {
stats.ploc.lines.insert(line);
});
}