Skip to content

Commit

Permalink
rust: semantic crate is part of bear
Browse files Browse the repository at this point in the history
  • Loading branch information
rizsotto committed Oct 11, 2024
1 parent 3445a2f commit 0aa9fe2
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 63 deletions.
3 changes: 1 addition & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[workspace]
members = [
"bear",
"intercept",
"semantic"
"intercept"
]
resolver = "2"

Expand Down
3 changes: 2 additions & 1 deletion rust/bear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ path = "src/bin/main.rs"

[dependencies]
intercept = { path = "../intercept" }
semantic = { path = "../semantic" }
thiserror.workspace = true
anyhow.workspace = true
lazy_static.workspace = true
Expand All @@ -33,3 +32,5 @@ log.workspace = true
env_logger.workspace = true
path-absolutize.workspace = true
shell-words.workspace = true
nom.workspace = true
regex.workspace = true
3 changes: 1 addition & 2 deletions rust/bear/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ use std::process::ExitCode;

use bear::input::EventFileReader;
use bear::output::OutputWriter;
use bear::{args, config};
use bear::{args, config, semantic};
use intercept::Execution;
use log;
use semantic;

/// Driver function of the application.
fn main() -> anyhow::Result<ExitCode> {
Expand Down
1 change: 1 addition & 0 deletions rust/bear/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod config;
mod fixtures;
pub mod input;
pub mod output;
pub mod semantic;
3 changes: 1 addition & 2 deletions rust/bear/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ use std::fs::{File, OpenOptions};
use std::io::{BufReader, BufWriter};
use std::path::{Path, PathBuf};

use super::{args, config};
use super::{args, config, semantic};
use anyhow::{anyhow, Context, Result};
use clang::Entry;
use path_absolutize::Absolutize;
use semantic;
use serde_json::Error;

pub mod clang;
Expand Down
2 changes: 0 additions & 2 deletions rust/semantic/src/lib.rs → rust/bear/src/semantic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

mod fixtures;
pub mod tools;

use intercept::Execution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use crate::{RecognitionResult, Tool};
use super::super::{RecognitionResult, Tool};
use intercept::Execution;

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

impl Any {
pub fn new(tools: Vec<Box<dyn Tool>>) -> impl Tool {
pub(super) fn new(tools: Vec<Box<dyn Tool>>) -> impl Tool {
Any { tools }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ use nom::multi::many1;
use nom::sequence::preceded;

use super::super::{Meaning, RecognitionResult, Tool};
use super::gcc::internal::Argument;
use internal::Argument;
use intercept::Execution;

pub struct Gcc {}
pub(super) struct Gcc {}

impl Gcc {
pub fn new() -> Box<dyn Tool> {
pub(super) fn new() -> Box<dyn Tool> {
Box::new(Gcc {})
}
}
Expand Down Expand Up @@ -66,8 +66,8 @@ mod internal {
use regex::Regex;
use std::path::PathBuf;

use crate::tools::matchers::source::looks_like_a_source_file;
use crate::CompilerPass;
use super::super::super::CompilerPass;
use super::super::matchers::source::looks_like_a_source_file;

#[derive(Debug, PartialEq)]
enum Language {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use super::matchers::source::looks_like_a_source_file;
use intercept::Execution;

/// A tool to recognize a compiler by executable name.
pub struct Generic {
pub(super) struct Generic {
executables: HashSet<PathBuf>,
}

impl Generic {
pub fn from(compilers: &[PathBuf]) -> Box<dyn Tool> {
pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Tool> {
let executables = compilers.iter().map(|compiler| compiler.clone()).collect();
Box::new(Self { executables })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ use super::super::{Meaning, RecognitionResult, Tool};
use intercept::Execution;

/// A tool to ignore a command execution by executable name.
pub struct IgnoreByPath {
pub(super) struct IgnoreByPath {
executables: HashSet<PathBuf>,
}

impl IgnoreByPath {
pub fn new() -> Box<dyn Tool> {
pub(super) fn new() -> Box<dyn Tool> {
let executables = COREUTILS_FILES.iter().map(PathBuf::from).collect();
Box::new(Self { executables })
}

pub fn from(compilers: &[PathBuf]) -> Box<dyn Tool> {
pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Tool> {
let executables = compilers.iter().map(|compiler| compiler.clone()).collect();
Box::new(Self { executables })
}
Expand All @@ -51,12 +51,12 @@ impl Tool for IgnoreByPath {
}
}

pub struct IgnoreByArgs {
pub(super) struct IgnoreByArgs {
args: Vec<String>,
}

impl IgnoreByArgs {
pub fn new(args: &[String]) -> Box<dyn Tool> {
pub(super) fn new(args: &[String]) -> Box<dyn Tool> {
let clones = args.iter().map(|arg| arg.clone()).collect();
Box::new(Self { args: clones })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

pub(crate) mod source;
pub(super) mod source;
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ lazy_static! {

#[cfg(test)]
mod test {
use crate::tools::matchers::source::looks_like_a_source_file;
use super::*;

#[test]
fn test_filenames() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ mod test {
use std::collections::HashMap;
use std::path::PathBuf;

use super::super::{vec_of_pathbuf, vec_of_strings};
use super::super::{Meaning, RecognitionResult};
use super::*;
use crate::{vec_of_pathbuf, vec_of_strings};
use intercept::Execution;

#[test]
Expand Down
24 changes: 0 additions & 24 deletions rust/semantic/Cargo.toml

This file was deleted.

12 changes: 0 additions & 12 deletions rust/semantic/src/fixtures.rs

This file was deleted.

0 comments on commit 0aa9fe2

Please sign in to comment.