Use foliage traits
This commit is contained in:
parent
e6cf79ad1e
commit
07322f041c
@ -21,15 +21,3 @@ pub(crate) trait VariableDeclarationID
|
||||
fn variable_declaration_id(&self,
|
||||
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>) -> usize;
|
||||
}
|
||||
|
||||
pub(crate) trait GetOrCreateFunctionDeclaration
|
||||
{
|
||||
fn get_or_create_function_declaration(&self, name: &str, arity: usize)
|
||||
-> std::rc::Rc<foliage::FunctionDeclaration>;
|
||||
}
|
||||
|
||||
pub(crate) trait GetOrCreatePredicateDeclaration
|
||||
{
|
||||
fn get_or_create_predicate_declaration(&self, name: &str, arity: usize)
|
||||
-> std::rc::Rc<foliage::PredicateDeclaration>;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ pub(crate) fn choose_value_in_term<C>(term: &clingo::ast::Term,
|
||||
variable_declaration_stack: &foliage::VariableDeclarationStackLayer)
|
||||
-> Result<foliage::Formula, crate::Error>
|
||||
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))
|
||||
|
@ -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<foliage::FunctionDeclaration>
|
||||
{
|
||||
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<foliage::PredicateDeclaration>
|
||||
{
|
||||
let mut predicate_declarations = self.predicate_declarations.borrow_mut();
|
||||
|
@ -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<HeadType<'a>, 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
|
||||
|
@ -2,8 +2,8 @@ pub(crate) fn translate_body_term<C>(body_term: &clingo::ast::Term, sign: clingo
|
||||
context: &C, variable_declaration_stack: &foliage::VariableDeclarationStackLayer)
|
||||
-> Result<foliage::Formula, crate::Error>
|
||||
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<C>(body_literal: &clingo::ast::BodyLiteral,
|
||||
context: &C, variable_declaration_stack: &foliage::VariableDeclarationStackLayer)
|
||||
-> Result<foliage::Formula, crate::Error>
|
||||
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<C>(body_literals: &[clingo::ast::BodyLiteral], cont
|
||||
variable_declaration_stack: &foliage::VariableDeclarationStackLayer)
|
||||
-> Result<foliage::Formulas, crate::Error>
|
||||
where
|
||||
C: crate::traits::GetOrCreateFunctionDeclaration
|
||||
+ crate::traits::GetOrCreatePredicateDeclaration
|
||||
C: foliage::FindOrCreateFunctionDeclaration
|
||||
+ foliage::FindOrCreatePredicateDeclaration
|
||||
+ crate::traits::AssignVariableDeclarationDomain
|
||||
{
|
||||
body_literals.iter()
|
||||
|
Loading…
Reference in New Issue
Block a user