Skip to content

Commit 9a347a3

Browse files
committed
rust: rename semantic module trait
1 parent fe038c1 commit 9a347a3

File tree

9 files changed

+47
-45
lines changed

9 files changed

+47
-45
lines changed

rust/bear/src/recognition.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use std::convert::TryFrom;
55

66
/// Responsible for recognizing the semantic meaning of the executed commands.
77
///
8-
/// The recognition logic is implemented in the `tools` module. Here we only handle
8+
/// The recognition logic is implemented in the `interpreters` module. Here we only handle
99
/// the errors and logging them to the console.
1010
pub struct Recognition {
11-
tool: Box<dyn semantic::Tool>,
11+
interpreter: Box<dyn semantic::Interpreter>,
1212
}
1313

1414
impl TryFrom<&config::Main> for Recognition {
@@ -27,20 +27,20 @@ impl TryFrom<&config::Main> for Recognition {
2727
.collect(),
2828
_ => vec![],
2929
};
30-
let tool = semantic::tools::Builder::new()
30+
let interpreter = semantic::interpreters::Builder::new()
3131
.compilers_to_recognize(compilers_to_include.as_slice())
3232
.compilers_to_exclude(compilers_to_exclude.as_slice())
3333
.build();
3434

3535
Ok(Recognition {
36-
tool: Box::new(tool),
36+
interpreter: Box::new(interpreter),
3737
})
3838
}
3939
}
4040

4141
impl Recognition {
4242
pub fn apply(&self, execution: Execution) -> Option<semantic::Meaning> {
43-
match self.tool.recognize(&execution) {
43+
match self.interpreter.recognize(&execution) {
4444
semantic::Recognition::Success(semantic::Meaning::Ignored) => {
4545
log::debug!("execution recognized, but ignored: {:?}", execution);
4646
None

rust/bear/src/semantic/tools/combinators.rs renamed to rust/bear/src/semantic/interpreters/combinators.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22

3-
use super::super::{Meaning, Recognition, Tool};
3+
use super::super::{Interpreter, Meaning, Recognition};
44
use intercept::Execution;
55

6-
/// Represents a set of tools, where any of them can recognize the semantic.
7-
/// The evaluation is done in the order of the tools. The first one which
6+
/// Represents a set of interpreters, where any of them can recognize the semantic.
7+
/// The evaluation is done in the order of the interpreters. The first one which
88
/// recognizes the semantic will be returned as result.
99
pub(super) struct Any {
10-
tools: Vec<Box<dyn Tool>>,
10+
interpreters: Vec<Box<dyn Interpreter>>,
1111
}
1212

1313
impl Any {
14-
pub(super) fn new(tools: Vec<Box<dyn Tool>>) -> impl Tool {
15-
Any { tools }
14+
pub(super) fn new(tools: Vec<Box<dyn Interpreter>>) -> impl Interpreter {
15+
Any {
16+
interpreters: tools,
17+
}
1618
}
1719
}
1820

19-
impl Tool for Any {
21+
impl Interpreter for Any {
2022
fn recognize(&self, x: &Execution) -> Recognition<Meaning> {
21-
for tool in &self.tools {
23+
for tool in &self.interpreters {
2224
match tool.recognize(x) {
2325
Recognition::Unknown => continue,
2426
result => return result,
@@ -39,7 +41,7 @@ mod test {
3941
#[test]
4042
fn test_any_when_no_match() {
4143
let sut = Any {
42-
tools: vec![
44+
interpreters: vec![
4345
Box::new(MockTool::NotRecognize),
4446
Box::new(MockTool::NotRecognize),
4547
Box::new(MockTool::NotRecognize),
@@ -57,7 +59,7 @@ mod test {
5759
#[test]
5860
fn test_any_when_match() {
5961
let sut = Any {
60-
tools: vec![
62+
interpreters: vec![
6163
Box::new(MockTool::NotRecognize),
6264
Box::new(MockTool::Recognize),
6365
Box::new(MockTool::NotRecognize),
@@ -75,7 +77,7 @@ mod test {
7577
#[test]
7678
fn test_any_when_match_fails() {
7779
let sut = Any {
78-
tools: vec![
80+
interpreters: vec![
7981
Box::new(MockTool::NotRecognize),
8082
Box::new(MockTool::RecognizeFailed),
8183
Box::new(MockTool::Recognize),
@@ -97,7 +99,7 @@ mod test {
9799
NotRecognize,
98100
}
99101

100-
impl Tool for MockTool {
102+
impl Interpreter for MockTool {
101103
fn recognize(&self, _: &Execution) -> Recognition<Meaning> {
102104
match self {
103105
MockTool::Recognize => Recognition::Success(Meaning::Ignored),

rust/bear/src/semantic/tools/gcc.rs renamed to rust/bear/src/semantic/interpreters/gcc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ use nom::branch::alt;
44
use nom::multi::many1;
55
use nom::sequence::preceded;
66

7-
use super::super::{Meaning, Recognition, Tool};
7+
use super::super::{Interpreter, Meaning, Recognition};
88
use intercept::Execution;
99
use internal::Argument;
1010

1111
pub(super) struct Gcc {}
1212

1313
impl Gcc {
14-
pub(super) fn new() -> Box<dyn Tool> {
14+
pub(super) fn new() -> Box<dyn Interpreter> {
1515
Box::new(Gcc {})
1616
}
1717
}
1818

19-
impl Tool for Gcc {
19+
impl Interpreter for Gcc {
2020
fn recognize(&self, execution: &Execution) -> Recognition<Meaning> {
2121
let mut parser = preceded(
2222
internal::compiler,

rust/bear/src/semantic/tools/generic.rs renamed to rust/bear/src/semantic/interpreters/generic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::collections::HashSet;
44
use std::path::PathBuf;
55
use std::vec;
66

7-
use super::super::{CompilerPass, Meaning, Recognition, Tool};
7+
use super::super::{CompilerPass, Interpreter, Meaning, Recognition};
88
use super::matchers::source::looks_like_a_source_file;
99
use intercept::Execution;
1010

@@ -14,13 +14,13 @@ pub(super) struct Generic {
1414
}
1515

1616
impl Generic {
17-
pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Tool> {
17+
pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Interpreter> {
1818
let executables = compilers.iter().map(|compiler| compiler.clone()).collect();
1919
Box::new(Self { executables })
2020
}
2121
}
2222

23-
impl Tool for Generic {
23+
impl Interpreter for Generic {
2424
/// This tool is a naive implementation only considering:
2525
/// - the executable name,
2626
/// - one of the arguments is a source file,

rust/bear/src/semantic/tools/ignore.rs renamed to rust/bear/src/semantic/interpreters/ignore.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::collections::HashSet;
44
use std::path::PathBuf;
55

6-
use super::super::{Meaning, Recognition, Tool};
6+
use super::super::{Interpreter, Meaning, Recognition};
77
use intercept::Execution;
88

99
/// A tool to ignore a command execution by executable name.
@@ -12,19 +12,19 @@ pub(super) struct IgnoreByPath {
1212
}
1313

1414
impl IgnoreByPath {
15-
pub(super) fn new() -> Box<dyn Tool> {
15+
pub(super) fn new() -> Box<dyn Interpreter> {
1616
let executables = COREUTILS_FILES.iter().map(PathBuf::from).collect();
1717
Box::new(Self { executables })
1818
}
1919

20-
pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Tool> {
20+
pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Interpreter> {
2121
let executables = compilers.iter().map(|compiler| compiler.clone()).collect();
2222
Box::new(Self { executables })
2323
}
2424
}
2525

2626
/// A tool to ignore a command execution by arguments.
27-
impl Tool for IgnoreByPath {
27+
impl Interpreter for IgnoreByPath {
2828
fn recognize(&self, execution: &Execution) -> Recognition<Meaning> {
2929
if self.executables.contains(&execution.executable) {
3030
Recognition::Success(Meaning::Ignored)

rust/bear/src/semantic/tools/mod.rs renamed to rust/bear/src/semantic/interpreters/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
use std::path::PathBuf;
44

5-
use super::tools::combinators::Any;
6-
use super::tools::generic::Generic;
7-
use super::tools::ignore::IgnoreByPath;
8-
use super::Tool;
5+
use super::interpreters::combinators::Any;
6+
use super::interpreters::generic::Generic;
7+
use super::interpreters::ignore::IgnoreByPath;
8+
use super::Interpreter;
99

1010
mod combinators;
1111
mod gcc;
@@ -16,15 +16,15 @@ mod matchers;
1616
/// A builder for creating a tool which can recognize the semantic of a compiler,
1717
/// or ignore known non-compilers.
1818
pub struct Builder {
19-
tools: Vec<Box<dyn Tool>>,
19+
interpreters: Vec<Box<dyn Interpreter>>,
2020
}
2121

2222
impl Builder {
2323
/// Creates a new builder with default settings.
2424
pub fn new() -> Self {
2525
// FIXME: replace generic with gcc, when it's implemented
2626
Builder {
27-
tools: vec![
27+
interpreters: vec![
2828
// ignore executables which are not compilers,
2929
IgnoreByPath::new(),
3030
// recognize default compiler
@@ -34,26 +34,26 @@ impl Builder {
3434
}
3535

3636
/// Factory method to create a new tool from the builder.
37-
pub fn build(self) -> impl Tool {
38-
Any::new(self.tools)
37+
pub fn build(self) -> impl Interpreter {
38+
Any::new(self.interpreters)
3939
}
4040

41-
/// Adds new tools to recognize as compilers by executable name.
41+
/// Adds new interpreters to recognize as compilers by executable name.
4242
pub fn compilers_to_recognize(mut self, compilers: &[PathBuf]) -> Self {
4343
if !compilers.is_empty() {
44-
// Add the new compilers at the end of the tools.
44+
// Add the new compilers at the end of the interpreters.
4545
let tool = Generic::from(compilers);
46-
self.tools.push(tool);
46+
self.interpreters.push(tool);
4747
}
4848
self
4949
}
5050

51-
/// Adds new tools to recognize as non-compilers by executable names.
51+
/// Adds new interpreters to recognize as non-compilers by executable names.
5252
pub fn compilers_to_exclude(mut self, compilers: &[PathBuf]) -> Self {
5353
if !compilers.is_empty() {
54-
// Add these new compilers at the front of the tools.
54+
// Add these new compilers at the front of the interpreters.
5555
let tool = IgnoreByPath::from(compilers);
56-
self.tools.insert(0, tool);
56+
self.interpreters.insert(0, tool);
5757
}
5858
self
5959
}

rust/bear/src/semantic/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22

3-
pub mod tools;
3+
pub mod interpreters;
44

55
use intercept::Execution;
66
use std::path::PathBuf;
@@ -33,9 +33,9 @@ pub enum CompilerPass {
3333
///
3434
/// A single tool has a potential to recognize a command execution and
3535
/// identify the semantic of that command. This abstraction is also can
36-
/// represent a set of tools, and the recognition process can be distributed
37-
/// amongst the tools.
38-
pub trait Tool: Send {
36+
/// represent a set of interpreters, and the recognition process can be
37+
/// distributed amongst the interpreters.
38+
pub trait Interpreter: Send {
3939
fn recognize(&self, _: &Execution) -> Recognition<Meaning>;
4040
}
4141

0 commit comments

Comments
 (0)