prime_or_unprime_variables_in_ast(prime, VarsToConsider, b(identifier(ID),Type,Info), PrimedID) :-
( member(ID, VarsToConsider)
; VarsToConsider = []
),
!,
prime_identifier(b(identifier(ID),Type,Info), PrimedID).
prime_or_unprime_variables_in_ast(prime, VarsToConsider, b(identifier(ID),Type,Info), Ast) :-
!,
\+ member(ID, VarsToConsider),
Ast = b(identifier(ID),Type,Info).
prime_or_unprime_variables_in_ast(unprime, VarsToConsider, b(identifier(ID),Type,Info), UnprimedID) :-
( member(ID, VarsToConsider)
; VarsToConsider = []
),
!,
( is_primed_id(ID)
->
remove_prime(b(identifier(ID),Type,Info), UnprimedID)
; UnprimedID = b(identifier(ID),Type,Info)
).
prime_or_unprime_variables_in_ast(unprime, VarsToConsider, b(identifier(ID),Type,Info), Ast) :-
!,
\+ member(ID, VarsToConsider),
Ast = b(identifier(ID),Type,Info).
prime_or_unprime_variables_in_ast(_, _, b(Node,Type,Info), Ast) :-
( Node = integer(_)
; Node = value(_)
; Node = integer_set(_)
; Node = string(_)
; Node =.. [_]
),
!,
Ast = b(Node,Type,Info).
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, b(Node,Type,Info), b(NewNode,Type,Info)) :-
Node = parallel(Assignments),
maplist(prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider), Assignments, NewAssignments),
NewNode = parallel(NewAssignments).
prime_or_unprime_variables_in_ast(_, _, b(Node,Type,Info), b(Node,Type,Info)) :-
functor(Node, OpType, _),
( OpType = comprehension_set
; OpType = set_extension
; OpType = sequence_extension
),
!.
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, b(Node,Type,Info), b(NewNode,Type,Info)) :-
Node =.. [Op,In],
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, In, NewIn),
NewNode =.. [Op,NewIn].
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, b(exists(Ids,Pred),Type,Info), b(exists(NewIds,NewPred),Type,Info)) :-
maplist(prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider), Ids, NewIds),
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, Pred, NewPred).
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, b(Node,Type,Info), b(NewNode,Type,Info)) :-
Node =.. [Op,In1,In2],
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, In1, NewIn1),
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, In2, NewIn2),
NewNode =.. [Op,NewIn1,NewIn2].
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, b(forall(Ids,Left,Right),Type,Info), b(forall(NewIds,NewLeft,NewRight),Type,Info)) :-
maplist(prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider), Ids, NewIds),
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, Left, NewLeft),
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, Right, NewRight).
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, b(Node,Type,Info), b(NewNode,Type,Info)) :-
% e.g. if_then_else
Node =.. [Op,In1,In2,In3],
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, In1, NewIn1),
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, In2, NewIn2),
prime_or_unprime_variables_in_ast(PrimeType, VarsToConsider, In3, NewIn3),
NewNode =.. [Op,NewIn1,NewIn2,NewIn3].