Skip to content

Commit b92f73c

Browse files
committed
simplify the semantic module
1 parent 995a1ca commit b92f73c

File tree

3 files changed

+16
-35
lines changed

3 files changed

+16
-35
lines changed

bear/src/output/writers.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use super::formats::{FileFormat, JsonCompilationDatabase, JsonSemanticDatabase};
44
use crate::semantic::clang::{DuplicateEntryFilter, Entry};
5-
use crate::semantic::Formattable;
65
use crate::{config, semantic};
76
use anyhow::Context;
87
use std::{fs, io, path};

bear/src/semantic/command.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
//! It defines how to classify arguments, group them, and convert them into entries
66
//! for the final compilation database.
77
8-
use crate::semantic::{clang, EntryFormat, Formattable};
8+
use crate::config;
9+
use crate::semantic::clang;
910
use serde::{Deserialize, Serialize};
1011
use std::path::PathBuf;
1112

@@ -85,14 +86,12 @@ impl CompilerCommand {
8586
.collect(),
8687
}
8788
}
88-
}
8989

90-
impl Formattable for CompilerCommand {
9190
/// Converts the compiler command into a list of entries for the compilation database.
9291
///
9392
/// It processes the command arguments, identifies source files, and constructs
9493
/// entries with the executable, arguments, working directory, and output file if present.
95-
fn to_entries(&self, config: &EntryFormat) -> Vec<clang::Entry> {
94+
pub(super) fn to_entries(&self, config: &config::EntryFormat) -> Vec<clang::Entry> {
9695
// Find all source files in the arguments
9796
let source_files: Vec<String> = self
9897
.arguments
@@ -144,6 +143,7 @@ impl Formattable for CompilerCommand {
144143
#[cfg(test)]
145144
mod test {
146145
use super::*;
146+
use crate::config::EntryFormat;
147147

148148
#[test]
149149
fn test_compiler_command_to_entries_single_source() {

bear/src/semantic/mod.rs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,13 @@
44
//!
55
//! This module provides traits and types for recognizing the semantic meaning of executed commands
66
//! (such as compilers or interpreters) and for formatting their output into structured entries.
7-
//!
8-
//! # Main Components
9-
//!
10-
//! - [`Command`]: Enum representing recognized command types.
11-
//! - [`Interpreter`]: Trait for recognizing the semantic meaning of an `Execution`.
12-
//! - [`Formattable`]: Trait for converting recognized commands into output entries.
13-
//! - [`EntryFormat`]: Configuration for formatting output entries.
14-
//!
15-
//! Implementers of [`Interpreter`] analyze an `Execution` and determine if it matches a known command.
16-
//! If recognized, they return a boxed [`Command`] representing the semantic meaning of the execution.
17-
//!
18-
//! The [`Formattable`] trait allows recognized commands to be transformed into output entries (e.g.,
19-
//! for a compilation database), using the provided [`EntryFormat`].
207
218
pub mod clang;
229
pub mod command;
2310
pub mod interpreters;
2411

2512
use super::intercept::Execution;
26-
use crate::config::EntryFormat;
13+
use crate::config;
2714
use serde::{Deserialize, Serialize};
2815
use std::fmt::Debug;
2916

@@ -41,6 +28,17 @@ pub enum Command {
4128
Filtered(String),
4229
}
4330

31+
impl Command {
32+
/// Converts the command into compilation database entries.
33+
pub fn to_entries(&self, config: &config::EntryFormat) -> Vec<clang::Entry> {
34+
match self {
35+
Command::Compiler(cmd) => cmd.to_entries(config),
36+
Command::Ignored(_) => vec![],
37+
Command::Filtered(_) => vec![],
38+
}
39+
}
40+
}
41+
4442
/// Responsible for recognizing the semantic meaning of an executed command.
4543
///
4644
/// Implementers of this trait analyze an [`Execution`] and determine if it matches
@@ -50,19 +48,3 @@ pub trait Interpreter: Send {
5048
/// An [`Option<Command>`] containing the recognized command, or `None` if not recognized.
5149
fn recognize(&self, execution: &Execution) -> Option<Command>;
5250
}
53-
54-
/// Trait for types that can be formatted into output entries.
55-
pub trait Formattable {
56-
/// Converts the command into a list of entries, using the provided format configuration.
57-
fn to_entries(&self, config: &EntryFormat) -> Vec<clang::Entry>;
58-
}
59-
60-
impl Formattable for Command {
61-
fn to_entries(&self, config: &EntryFormat) -> Vec<clang::Entry> {
62-
match self {
63-
Command::Compiler(cmd) => cmd.to_entries(config),
64-
Command::Ignored(_) => vec![],
65-
Command::Filtered(_) => vec![],
66-
}
67-
}
68-
}

0 commit comments

Comments
 (0)