From 07322f041c7509b003c61b62e6059833ce5084d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Fri, 17 Apr 2020 04:10:23 +0200 Subject: [PATCH] Use foliage traits --- src/traits.rs | 12 ------------ src/translate/common/choose_value_in_term.rs | 4 ++-- src/translate/verify_properties/context.rs | 8 ++++---- src/translate/verify_properties/head_type.rs | 4 ++-- src/translate/verify_properties/translate_body.rs | 14 +++++++------- 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 9409c77..b2eee25 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -21,15 +21,3 @@ pub(crate) trait VariableDeclarationID fn variable_declaration_id(&self, variable_declaration: &std::rc::Rc) -> usize; } - -pub(crate) trait GetOrCreateFunctionDeclaration -{ - fn get_or_create_function_declaration(&self, name: &str, arity: usize) - -> std::rc::Rc; -} - -pub(crate) trait GetOrCreatePredicateDeclaration -{ - fn get_or_create_predicate_declaration(&self, name: &str, arity: usize) - -> std::rc::Rc; -} diff --git a/src/translate/common/choose_value_in_term.rs b/src/translate/common/choose_value_in_term.rs index 14aea4e..92dd760 100644 --- a/src/translate/common/choose_value_in_term.rs +++ b/src/translate/common/choose_value_in_term.rs @@ -12,7 +12,7 @@ pub(crate) fn choose_value_in_term(term: &clingo::ast::Term, variable_declaration_stack: &foliage::VariableDeclarationStackLayer) -> Result where - C: crate::traits::GetOrCreateFunctionDeclaration + C: foliage::FindOrCreateFunctionDeclaration + crate::traits::AssignVariableDeclarationDomain { match term.term_type() @@ -50,7 +50,7 @@ where .map_err(|error| crate::Error::new_logic("clingo error").with(error))?; let constant_declaration = - context.get_or_create_function_declaration(constant_name, 0); + context.find_or_create_function_declaration(constant_name, 0); let function = foliage::Term::function(constant_declaration, vec![]); Ok(choose_value_in_primitive(Box::new(function), variable_declaration)) diff --git a/src/translate/verify_properties/context.rs b/src/translate/verify_properties/context.rs index 6300221..4d1b3b5 100644 --- a/src/translate/verify_properties/context.rs +++ b/src/translate/verify_properties/context.rs @@ -66,9 +66,9 @@ impl crate::traits::InputConstantDeclarationDomain for Context } } -impl crate::traits::GetOrCreateFunctionDeclaration for Context +impl foliage::FindOrCreateFunctionDeclaration for Context { - fn get_or_create_function_declaration(&self, name: &str, arity: usize) + fn find_or_create_function_declaration(&self, name: &str, arity: usize) -> std::rc::Rc { let mut function_declarations = self.function_declarations.borrow_mut(); @@ -92,9 +92,9 @@ impl crate::traits::GetOrCreateFunctionDeclaration for Context } } -impl crate::traits::GetOrCreatePredicateDeclaration for Context +impl foliage::FindOrCreatePredicateDeclaration for Context { - fn get_or_create_predicate_declaration(&self, name: &str, arity: usize) + fn find_or_create_predicate_declaration(&self, name: &str, arity: usize) -> std::rc::Rc { let mut predicate_declarations = self.predicate_declarations.borrow_mut(); diff --git a/src/translate/verify_properties/head_type.rs b/src/translate/verify_properties/head_type.rs index 9ee4436..01d6c0e 100644 --- a/src/translate/verify_properties/head_type.rs +++ b/src/translate/verify_properties/head_type.rs @@ -15,14 +15,14 @@ pub(crate) enum HeadType<'a> pub(crate) fn determine_head_type<'a, C>(head_literal: &'a clingo::ast::HeadLiteral, context: &C) -> Result, crate::Error> where - C: crate::traits::GetOrCreatePredicateDeclaration + C: foliage::FindOrCreatePredicateDeclaration { let create_head_atom = |function: &'a clingo::ast::Function| -> Result<_, crate::Error> { let function_name = function.name() .map_err(|error| crate::Error::new_decode_identifier(error))?; - let predicate_declaration = context.get_or_create_predicate_declaration(function_name, + let predicate_declaration = context.find_or_create_predicate_declaration(function_name, function.arguments().len()); Ok(HeadAtom diff --git a/src/translate/verify_properties/translate_body.rs b/src/translate/verify_properties/translate_body.rs index dbb358a..9103d23 100644 --- a/src/translate/verify_properties/translate_body.rs +++ b/src/translate/verify_properties/translate_body.rs @@ -2,8 +2,8 @@ pub(crate) fn translate_body_term(body_term: &clingo::ast::Term, sign: clingo context: &C, variable_declaration_stack: &foliage::VariableDeclarationStackLayer) -> Result where - C: crate::traits::GetOrCreateFunctionDeclaration - + crate::traits::GetOrCreatePredicateDeclaration + C: foliage::FindOrCreateFunctionDeclaration + + foliage::FindOrCreatePredicateDeclaration + crate::traits::AssignVariableDeclarationDomain { let function = match body_term.term_type() @@ -14,7 +14,7 @@ where let function_name = function.name().map_err(|error| crate::Error::new_decode_identifier(error))?; - let predicate_declaration = context.get_or_create_predicate_declaration(function_name, + let predicate_declaration = context.find_or_create_predicate_declaration(function_name, function.arguments().len()); let parameters = function.arguments().iter().map(|_| @@ -68,8 +68,8 @@ pub(crate) fn translate_body_literal(body_literal: &clingo::ast::BodyLiteral, context: &C, variable_declaration_stack: &foliage::VariableDeclarationStackLayer) -> Result where - C: crate::traits::GetOrCreateFunctionDeclaration - + crate::traits::GetOrCreatePredicateDeclaration + C: foliage::FindOrCreateFunctionDeclaration + + foliage::FindOrCreatePredicateDeclaration + crate::traits::AssignVariableDeclarationDomain { match body_literal.sign() @@ -145,8 +145,8 @@ pub(crate) fn translate_body(body_literals: &[clingo::ast::BodyLiteral], cont variable_declaration_stack: &foliage::VariableDeclarationStackLayer) -> Result where - C: crate::traits::GetOrCreateFunctionDeclaration - + crate::traits::GetOrCreatePredicateDeclaration + C: foliage::FindOrCreateFunctionDeclaration + + foliage::FindOrCreatePredicateDeclaration + crate::traits::AssignVariableDeclarationDomain { body_literals.iter()