big_code_analysis/
traits.rs1#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
8
9use std::path::Path;
10use std::sync::Arc;
11
12use crate::abc::Abc;
13use crate::alterator::Alterator;
14use crate::checker::Checker;
15use crate::cognitive::Cognitive;
16use crate::cyclomatic::Cyclomatic;
17use crate::exit::Exit;
18use crate::getter::Getter;
19use crate::halstead::Halstead;
20use crate::langs::*;
21use crate::loc::Loc;
22use crate::mi::Mi;
23use crate::nargs::NArgs;
24use crate::node::Node;
25use crate::nom::Nom;
26use crate::npa::Npa;
27use crate::npm::Npm;
28use crate::parser::Filter;
29use crate::preproc::PreprocResults;
30use crate::tokens::Tokens;
31use crate::wmc::Wmc;
32
33pub trait Callback {
38 type Res;
40 type Cfg;
42
43 fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res;
45}
46
47pub trait LanguageInfo {
52 type BaseLang;
54
55 fn get_lang() -> LANG;
57 fn get_lang_name() -> &'static str;
59}
60
61#[doc(hidden)]
71pub trait ParserTrait {
72 type Checker: Alterator + Checker;
73 type Getter: Getter;
74 type Cognitive: Cognitive;
75 type Cyclomatic: Cyclomatic;
76 type Halstead: Halstead;
77 type Loc: Loc;
78 type Nom: Nom;
79 type Mi: Mi;
80 type NArgs: NArgs;
81 type Exit: Exit;
82 type Wmc: Wmc;
83 type Abc: Abc;
84 type Npm: Npm;
85 type Npa: Npa;
86 type Tokens: Tokens;
87
88 fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self;
89 fn get_language(&self) -> LANG;
90 fn get_root(&self) -> Node<'_>;
91 fn get_code(&self) -> &[u8];
92 fn get_filters(&self, filters: &[String]) -> Filter;
93}
94
95pub(crate) trait Search<'a> {
96 fn first_occurrence(&self, pred: fn(u16) -> bool) -> Option<Node<'a>>;
97 fn act_on_node(&self, pred: &mut dyn FnMut(&Node<'a>));
98 fn first_child(&self, pred: fn(u16) -> bool) -> Option<Node<'a>>;
99 fn act_on_child(&self, action: &mut dyn FnMut(&Node<'a>));
100}