Skip to content

Commit ff7ae7a

Browse files
committed
rust: tarnsformation module is part of semantic pakcage
1 parent 7e45025 commit ff7ae7a

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

rust/bear/src/modes/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
mod input;
44
mod intercept;
55
mod recognition;
6-
mod transformation;
76

87
use crate::ipc::Envelope;
98
use crate::output::OutputWriter;
@@ -14,7 +13,8 @@ use intercept::{CollectorService, InterceptEnvironment};
1413
use recognition::Recognition;
1514
use std::io::BufWriter;
1615
use std::process::ExitCode;
17-
use transformation::Transformation;
16+
use crate::semantic::Transform;
17+
use crate::semantic::transformation::Transformation;
1818

1919
/// Declare the environment variables used by the intercept mode.
2020
pub const KEY_DESTINATION: &str = "INTERCEPT_REPORTER_ADDRESS";

rust/bear/src/semantic/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
//! ones that are relevant to build a JSON compilation database.
1212
1313
pub mod interpreters;
14+
pub mod transformation;
1415

1516
use super::ipc::Execution;
1617
use std::path::PathBuf;
18+
use crate::semantic;
1719

1820
/// Represents an executed command semantic.
1921
#[derive(Debug, PartialEq)]
@@ -63,3 +65,12 @@ pub enum Recognition<T> {
6365
/// The command was not recognized.
6466
Unknown,
6567
}
68+
69+
/// Responsible to transform the semantic of an executed command.
70+
///
71+
/// It conditionally removes compiler calls based on compiler names or flags.
72+
/// It can also alter the compiler flags of the compiler calls. The actions
73+
/// are defined in the configuration this module is given.
74+
pub trait Transform {
75+
fn apply(&self, _: CompilerCall) -> Option<CompilerCall>;
76+
}

rust/bear/src/modes/transformation.rs renamed to rust/bear/src/semantic/transformation.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
//! It can also alter the compiler flags of the compiler calls. The actions
77
//! are defined in the configuration this module is given.
88
9-
use super::super::semantic;
10-
use super::config;
9+
use crate::semantic;
10+
use crate::config;
11+
use crate::semantic::Transform;
1112

1213
pub enum Transformation {
1314
None,
@@ -30,34 +31,34 @@ impl From<&config::Output> for Transformation {
3031
}
3132
}
3233

33-
impl Transformation {
34-
pub fn apply(&self, input: semantic::CompilerCall) -> Option<semantic::CompilerCall> {
34+
impl Transform for Transformation {
35+
fn apply(&self, input: semantic::CompilerCall) -> Option<semantic::CompilerCall> {
3536
let semantic::CompilerCall {
3637
compiler,
3738
passes,
3839
working_dir,
3940
} = &input;
4041
match self.lookup(compiler) {
4142
Some(config::Compiler {
42-
ignore: config::Ignore::Always,
43-
..
44-
}) => None,
43+
ignore: config::Ignore::Always,
44+
..
45+
}) => None,
4546
Some(config::Compiler {
46-
ignore: config::Ignore::Conditional,
47-
arguments,
48-
..
49-
}) => {
47+
ignore: config::Ignore::Conditional,
48+
arguments,
49+
..
50+
}) => {
5051
if Self::filter(arguments, passes) {
5152
None
5253
} else {
5354
Some(input)
5455
}
5556
}
5657
Some(config::Compiler {
57-
ignore: config::Ignore::Never,
58-
arguments,
59-
..
60-
}) => {
58+
ignore: config::Ignore::Never,
59+
arguments,
60+
..
61+
}) => {
6162
let new_passes = Transformation::execute(arguments, passes);
6263
Some(semantic::CompilerCall {
6364
compiler: compiler.clone(),
@@ -68,7 +69,9 @@ impl Transformation {
6869
None => Some(input),
6970
}
7071
}
72+
}
7173

74+
impl Transformation {
7275
// TODO: allow multiple matches for the same compiler
7376
fn lookup(&self, compiler: &std::path::Path) -> Option<&config::Compiler> {
7477
match self {

0 commit comments

Comments
 (0)