Skip to main content

rust_code_analysis_code_split/
traits.rs

1use std::path::Path;
2use std::sync::Arc;
3
4use crate::abc::Abc;
5use crate::alterator::Alterator;
6use crate::checker::Checker;
7use crate::cognitive::Cognitive;
8use crate::cyclomatic::Cyclomatic;
9use crate::exit::Exit;
10use crate::getter::Getter;
11use crate::halstead::Halstead;
12use crate::langs::*;
13use crate::loc::Loc;
14use crate::mi::Mi;
15use crate::nargs::NArgs;
16use crate::node::Node;
17use crate::nom::Nom;
18use crate::npa::Npa;
19use crate::npm::Npm;
20use crate::parser::Filter;
21use crate::preproc::PreprocResults;
22use crate::wmc::Wmc;
23
24/// A trait for callback functions.
25///
26/// Allows to call a private library function, getting as result
27/// its output value.
28pub trait Callback {
29    /// The output type returned by the callee
30    type Res;
31    /// The input type used by the caller to pass the arguments to the callee
32    type Cfg;
33
34    /// Calls a function inside the library and returns its value
35    fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res;
36}
37
38pub trait LanguageInfo {
39    type BaseLang;
40
41    fn get_lang() -> LANG;
42    fn get_lang_name() -> &'static str;
43}
44
45#[doc(hidden)]
46pub trait ParserTrait {
47    type Checker: Alterator + Checker;
48    type Getter: Getter;
49    type Cognitive: Cognitive;
50    type Cyclomatic: Cyclomatic;
51    type Halstead: Halstead;
52    type Loc: Loc;
53    type Nom: Nom;
54    type Mi: Mi;
55    type NArgs: NArgs;
56    type Exit: Exit;
57    type Wmc: Wmc;
58    type Abc: Abc;
59    type Npm: Npm;
60    type Npa: Npa;
61
62    fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self;
63    fn get_language(&self) -> LANG;
64    fn get_root(&self) -> Node<'_>;
65    fn get_code(&self) -> &[u8];
66    fn get_filters(&self, filters: &[String]) -> Filter;
67}
68
69pub(crate) trait Search<'a> {
70    fn first_occurrence(&self, pred: fn(u16) -> bool) -> Option<Node<'a>>;
71    fn act_on_node(&self, pred: &mut dyn FnMut(&Node<'a>));
72    fn first_child(&self, pred: fn(u16) -> bool) -> Option<Node<'a>>;
73    fn act_on_child(&self, action: &mut dyn FnMut(&Node<'a>));
74}