Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove matching handlers config for now #63

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
members = [
"bin",
"matching",
"matching_handlers",
"merge",
"parsing",
"model"
Expand Down
1 change: 0 additions & 1 deletion bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ merge = { path = "../merge" }
model = { path = "../model" }
parsing = { path = "../parsing" }
matching = { path = "../matching" }
matching_handlers = { path = "../matching_handlers" }
assert_cmd = "2.0.12"
clap = { version = "4.4.8", features = ["derive"] }
log = { workspace = true }
Expand Down
20 changes: 9 additions & 11 deletions bin/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
fmt::{self, Display},
};

use matching::{matching_configuration, MatchingEntry};
use matching::MatchingEntry;
use parsing::ParserConfiguration;

#[derive(Debug)]
Expand Down Expand Up @@ -62,27 +62,27 @@ pub fn run_tool_on_merge_scenario(
let base_tree =
parsing::parse_string(base, &parser_configuration).map_err(ExecutionError::ParsingError)?;
log::info!("Finished parsing base file");

log::info!("Started parsing left file");
let left_tree =
parsing::parse_string(left, &parser_configuration).map_err(ExecutionError::ParsingError)?;
log::info!("Finished parsing left file");

log::info!("Started parsing right file");
let right_tree = parsing::parse_string(right, &parser_configuration)
.map_err(ExecutionError::ParsingError)?;
log::info!("Finished parsing right file");

let matching_configuration = matching_configuration::MatchingConfiguration::from(language);
log::info!("Started calculation of matchings between left and base");
let matchings_left_base =
matching::calculate_matchings(&left_tree, &base_tree, &matching_configuration);
let matchings_left_base = matching::calculate_matchings(&left_tree, &base_tree);
log::info!("Finished calculation of matchings between left and base");

log::info!("Started calculation of matchings between right and base");
let matchings_right_base =
matching::calculate_matchings(&right_tree, &base_tree, &matching_configuration);
let matchings_right_base = matching::calculate_matchings(&right_tree, &base_tree);
log::info!("Finished calculation of matchings between right and base");

log::info!("Started calculation of matchings between left and right");
let matchings_left_right =
matching::calculate_matchings(&left_tree, &right_tree, &matching_configuration);
let matchings_left_right = matching::calculate_matchings(&left_tree, &right_tree);
log::info!("Finished calculation of matchings between left and right");

log::info!("Starting merge of the trees");
Expand Down Expand Up @@ -119,10 +119,8 @@ pub fn run_diff_on_files(
.map_err(ExecutionError::ParsingError)?;
log::info!("Finished parsing right file");

let matching_configuration = matching_configuration::MatchingConfiguration::from(language);
log::info!("Started calculation of matchings between left and right");
let matchings_left_right =
matching::calculate_matchings(&left_tree_root, &right_tree_root, &matching_configuration);
let matchings_left_right = matching::calculate_matchings(&left_tree_root, &right_tree_root);
log::info!("Finished calculation of matchings between left and right");

Ok(matchings_left_right
Expand Down
1 change: 0 additions & 1 deletion matching/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"

[dependencies]
model = { path = "../model" }
matching_handlers = { path = "../matching_handlers" }
unordered-pair = "0.2.4"
log = { workspace = true }
pathfinding = "4.9.1"
Expand Down
12 changes: 4 additions & 8 deletions matching/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
mod matches;
mod matching;
pub mod matching_configuration;
mod matching_entry;
mod matchings;
pub mod ordered;
pub mod unordered;

use matches::Matches;
use matching_configuration::MatchingConfiguration;
pub use matching_entry::MatchingEntry;
pub use matchings::Matchings;
use unordered_pair::UnorderedPair;

pub fn calculate_matchings<'a>(
left: &'a model::CSTNode,
right: &'a model::CSTNode,
config: &'a MatchingConfiguration<'a>,
) -> Matchings<'a> {
if !left.matches(right) {
return Matchings::empty();
Expand All @@ -28,9 +25,9 @@ pub fn calculate_matchings<'a>(
) => {
if non_terminal_left.are_children_unordered && non_terminal_right.are_children_unordered
{
unordered::calculate_matchings(left, right, config)
unordered::calculate_matchings(left, right)
} else {
ordered::calculate_matchings(left, right, config)
ordered::calculate_matchings(left, right)
}
}
(
Expand All @@ -57,7 +54,7 @@ pub fn calculate_matchings<'a>(

#[cfg(test)]
mod tests {
use crate::{calculate_matchings, matching_configuration::MatchingConfiguration};
use crate::calculate_matchings;
use model::{cst_node::Terminal, CSTNode, Point};

#[test]
Expand All @@ -79,8 +76,7 @@ mod tests {
is_block_end_delimiter: false,
});

let matching_configuration = MatchingConfiguration::default();
let matchings = calculate_matchings(&left, &right, &matching_configuration);
let matchings = calculate_matchings(&left, &right);

let left_right_matching = matchings.get_matching_entry(&left, &right).unwrap();
assert_eq!(1, left_right_matching.score);
Expand Down
23 changes: 0 additions & 23 deletions matching/src/matching_configuration.rs

This file was deleted.

29 changes: 8 additions & 21 deletions matching/src/ordered/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
matches::Matches, matching_configuration::MatchingConfiguration, matching_entry::MatchingEntry,
Matchings,
};
use crate::{matches::Matches, matching_entry::MatchingEntry, Matchings};
use model::{cst_node::NonTerminal, CSTNode};
use unordered_pair::UnorderedPair;

Expand All @@ -21,11 +18,7 @@ impl<'a> Default for Entry<'a> {
}
}

pub fn calculate_matchings<'a>(
left: &'a CSTNode,
right: &'a CSTNode,
config: &'a MatchingConfiguration<'a>,
) -> Matchings<'a> {
pub fn calculate_matchings<'a>(left: &'a CSTNode, right: &'a CSTNode) -> Matchings<'a> {
match (left, right) {
(
CSTNode::NonTerminal(NonTerminal {
Expand All @@ -50,7 +43,7 @@ pub fn calculate_matchings<'a>(
let left_child = children_left.get(i - 1).unwrap();
let right_child = children_right.get(j - 1).unwrap();

let w = crate::calculate_matchings(left_child, right_child, config);
let w = crate::calculate_matchings(left_child, right_child);
let matching = w
.get_matching_entry(left_child, right_child)
.unwrap_or_default();
Expand Down Expand Up @@ -103,7 +96,6 @@ pub fn calculate_matchings<'a>(

#[cfg(test)]
mod tests {
use crate::MatchingConfiguration;
use model::{
cst_node::{NonTerminal, Terminal},
language, CSTNode, Language, Point,
Expand Down Expand Up @@ -138,8 +130,7 @@ mod tests {
..Default::default()
});

let matching_configuration = MatchingConfiguration::default();
let matchings = super::calculate_matchings(&left, &right, &matching_configuration);
let matchings = super::calculate_matchings(&left, &right);

let child_matching = matchings.get_matching_entry(&child, &child);
assert!(child_matching.is_some());
Expand Down Expand Up @@ -185,8 +176,7 @@ mod tests {
..Default::default()
});

let matching_configuration = MatchingConfiguration::from(Language::Java);
let matchings = super::calculate_matchings(&left, &right, &matching_configuration);
let matchings = super::calculate_matchings(&left, &right);
assert!(matchings
.get_matching_entry(&left_child, &right_child)
.is_none())
Expand Down Expand Up @@ -230,8 +220,7 @@ mod tests {
..Default::default()
});

let matching_configuration = MatchingConfiguration::from(language::Language::Java);
let matchings = super::calculate_matchings(&left, &right, &matching_configuration);
let matchings = super::calculate_matchings(&left, &right);

let left_right_matchings = matchings.get_matching_entry(&left, &right).unwrap();
assert_eq!(2, left_right_matchings.score);
Expand Down Expand Up @@ -268,8 +257,7 @@ mod tests {
..Default::default()
});

let matching_configuration = MatchingConfiguration::from(language::Language::Java);
let matchings = super::calculate_matchings(&left, &right, &matching_configuration);
let matchings = super::calculate_matchings(&left, &right);

let left_right_matchings = matchings.get_matching_entry(&left, &right).unwrap();
assert_eq!(2, left_right_matchings.score);
Expand Down Expand Up @@ -317,8 +305,7 @@ mod tests {
..Default::default()
});

let matching_configuration = MatchingConfiguration::default();
let matchings = super::calculate_matchings(&left, &right, &matching_configuration);
let matchings = super::calculate_matchings(&left, &right);

let intermediate_matching = matchings
.get_matching_entry(&intermediate, &intermediate)
Expand Down
5 changes: 2 additions & 3 deletions matching/src/unordered/assignment_problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use model::{cst_node::NonTerminal, CSTNode};
use pathfinding::{kuhn_munkres::Weights, matrix};
use unordered_pair::UnorderedPair;

use crate::{matching_configuration::MatchingConfiguration, MatchingEntry, Matchings};
use crate::{MatchingEntry, Matchings};

pub fn calculate_matchings<'a>(
left: &'a CSTNode<'a>,
right: &'a CSTNode<'a>,
config: &'a MatchingConfiguration<'a>,
) -> crate::Matchings<'a> {
match (left, right) {
(
Expand All @@ -34,7 +33,7 @@ pub fn calculate_matchings<'a>(
children_right
.iter()
.map(|right_child| {
let w = crate::calculate_matchings(left_child, right_child, config);
let w = crate::calculate_matchings(left_child, right_child);
let matching = w
.get_matching_entry(left_child, right_child)
.unwrap_or_default();
Expand Down
6 changes: 2 additions & 4 deletions matching/src/unordered/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::matching_configuration::MatchingConfiguration;
use model::cst_node::NonTerminal;

mod assignment_problem;
Expand All @@ -7,7 +6,6 @@ mod unique_label;
pub fn calculate_matchings<'a>(
left: &'a model::CSTNode<'a>,
right: &'a model::CSTNode<'a>,
config: &'a MatchingConfiguration<'a>,
) -> crate::Matchings<'a> {
match (left, right) {
(model::CSTNode::NonTerminal(left_nt), model::CSTNode::NonTerminal(right_nt)) => {
Expand All @@ -17,14 +15,14 @@ pub fn calculate_matchings<'a>(
left.kind(),
right.kind()
);
unique_label::calculate_matchings(left, right, config)
unique_label::calculate_matchings(left, right)
} else {
log::debug!(
"Matching children of \"{}\" with \"{}\" using assignment problem matching.",
left.kind(),
right.kind()
);
assignment_problem::calculate_matchings(left, right, config)
assignment_problem::calculate_matchings(left, right)
}
}
_ => unreachable!("Unordered matching is only supported for non-terminals."),
Expand Down
11 changes: 3 additions & 8 deletions matching/src/unordered/unique_label.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use model::{cst_node::NonTerminal, CSTNode};
use unordered_pair::UnorderedPair;

use crate::{matching_configuration::MatchingConfiguration, MatchingEntry, Matchings};
use crate::{MatchingEntry, Matchings};

pub fn calculate_matchings<'a>(
left: &'a CSTNode,
right: &'a CSTNode,
config: &'a MatchingConfiguration<'a>,
) -> crate::Matchings<'a> {
pub fn calculate_matchings<'a>(left: &'a CSTNode, right: &'a CSTNode) -> crate::Matchings<'a> {
match (left, right) {
(
CSTNode::NonTerminal(NonTerminal {
Expand Down Expand Up @@ -39,8 +35,7 @@ pub fn calculate_matchings<'a>(
};

if is_same_identifier {
let child_matchings =
crate::calculate_matchings(child_left, child_right, config);
let child_matchings = crate::calculate_matchings(child_left, child_right);

if let Some(matching_entry) =
child_matchings.get_matching_entry(child_left, child_right)
Expand Down
4 changes: 1 addition & 3 deletions matching/tests/perfect_matching.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use matching::matching_configuration::MatchingConfiguration;
use model::language::Language;
use parsing::ParserConfiguration;

Expand Down Expand Up @@ -43,8 +42,7 @@ fn the_perfect_matching_calculation_is_correct() -> Result<(), Box<dyn std::erro
&config,
)?;

let matching_configuration = MatchingConfiguration::from(Language::Java);
let matchings = matching::calculate_matchings(&left, &right, &matching_configuration);
let matchings = matching::calculate_matchings(&left, &right);
assert!(
matchings
.get_matching_entry(&left, &right)
Expand Down
10 changes: 0 additions & 10 deletions matching_handlers/Cargo.toml

This file was deleted.

6 changes: 0 additions & 6 deletions matching_handlers/src/java/mod.rs

This file was deleted.

Loading
Loading