-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathtraits.rs
More file actions
85 lines (73 loc) · 2.43 KB
/
traits.rs
File metadata and controls
85 lines (73 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use std::path::Path;
use std::sync::Arc;
use crate::abc::Abc;
use crate::alterator::Alterator;
use crate::checker::Checker;
use crate::cognitive::Cognitive;
use crate::cyclomatic::Cyclomatic;
use crate::exit::Exit;
use crate::getter::Getter;
use crate::halstead::Halstead;
use crate::langs::*;
use crate::loc::Loc;
use crate::mi::Mi;
use crate::nargs::NArgs;
use crate::node::Node;
use crate::nom::Nom;
use crate::npa::Npa;
use crate::npm::Npm;
use crate::parser::Filter;
use crate::preproc::PreprocResults;
use crate::wmc::Wmc;
/// A trait for callback functions.
///
/// Allows to call a private library function, getting as result
/// its output value.
pub trait Callback {
/// The output type returned by the callee
type Res;
/// The input type used by the caller to pass the arguments to the callee
type Cfg;
/// Calls a function inside the library and returns its value
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res;
}
pub trait LanguageInfo {
type BaseLang;
fn get_lang() -> LANG;
fn get_lang_name() -> &'static str;
}
#[doc(hidden)]
pub trait ParserTrait {
type Checker: Alterator + Checker;
type Getter: Getter;
type Cognitive: Cognitive;
type Cyclomatic: Cyclomatic;
type Halstead: Halstead;
type Loc: Loc;
type Nom: Nom;
type Mi: Mi;
type NArgs: NArgs;
type Exit: Exit;
type Wmc: Wmc;
type Abc: Abc;
type Npm: Npm;
type Npa: Npa;
fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self;
fn get_language(&self) -> LANG;
fn get_root(&self) -> Node<'_>;
fn get_code(&self) -> &[u8];
fn get_filters(&self, filters: &[String]) -> Filter;
}
/// Search trait for AST node traversal.
pub trait Search<'a> {
/// Starting from this node, gets the first occurrence that meets the predicate.
fn first_occurrence(&self, pred: fn(u16) -> bool) -> Option<Node<'a>>;
/// Starting from this node, gets all nodes that meet the given predicate.
fn all_occurrences(&self, pred: fn(u16) -> bool) -> Vec<Node<'a>>;
/// Apply the given predicate on this node and all descendants.
fn act_on_node(&self, pred: &mut dyn FnMut(&Node<'a>));
/// Starting from this node, gets the first child that meets the predicate.
fn first_child(&self, pred: fn(u16) -> bool) -> Option<Node<'a>>;
/// Apply the given action on node's immediate children.
fn act_on_child(&self, action: &mut dyn FnMut(&Node<'a>));
}