get_library_components_from_op_ast_state_l(_, CarryComponents, _, [], CarryComponents, Acc, NewAcc, AssignedIds) :-
!,
NewAcc = Acc,
AssignedIds = [].
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [Ast|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
Ast = b(rlevent(_Name,_Section,_Status,_Params,Guard,_Theorems,Actions,_VWitnesses,_PWitnesses,_Unmod,_AbstractEvents),_,_),
!,
get_library_components_for_params_from_pred(Guard, Acc, NewAcc1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, Actions, _, NewAcc1, NewAcc2, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, T, NewCarryComponentsAcc, NewAcc2, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(Substitution,_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
Substitution =.. [Functor,Assignments],
( Functor = parallel
; Functor = sequence
),
!,
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, Assignments, _, Acc, NewAcc, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, T, NewCarryComponentsAcc, NewAcc, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(Node,_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
Node =.. [Functor,_Ids,Pred,Substitutions],
( Functor = let
; Functor = any
),
!,
get_library_components_for_params_from_pred(Pred, Acc, NewAcc1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, Substitutions, CarryComponentsAcc, NewAcc1, NewAcc2, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponentsAcc, AssigningVar, T, NewCarryComponentsAcc, NewAcc2, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(precondition(Pred,Substitution),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
get_library_components_for_params_from_pred(Pred, Acc, NewAcc1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, [Substitution], _, NewAcc1, NewAcc2, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, T, NewCarryComponentsAcc, NewAcc2, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(select([Substitution1],Substitution),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, [Substitution,Substitution1], _, Acc, NewAcc, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, T, NewCarryComponentsAcc, NewAcc, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(select(Substitutions),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, Substitutions, CarryComponentsAcc, Acc, NewAcc, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponentsAcc, AssigningVar, T, NewCarryComponentsAcc, NewAcc, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(select_when(Pred,Substitution),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
get_library_components_for_params_from_pred(Pred, Acc, NewAcc1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, [Substitution], CarryComponentsAcc, NewAcc1, NewAcc2, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponentsAcc, AssigningVar, T, NewCarryComponentsAcc, NewAcc2, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(if_then_else(Pred,If,Else),subst,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, [Pred], CarryComponentsAccPred, Acc, _, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, [if_then_else|CarryComponentsAccPred], AssigningVar, [If,Else], CarryComponentsAcc, Acc, NewAcc1, AssignedIds2),
extend_ground_truth_for_vars(ExcludeVars, [global_ground_truth_vars], [if_then_else|CarryComponentsAccPred], NewAcc1, NewAcc2),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponentsAcc, AssigningVar, T, NewCarryComponentsAcc, NewAcc2, UsedComponents, AssignedIds3),
append([AssignedIds1,AssignedIds2,AssignedIds3], AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(if_then_else(Pred,If,Else),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
% if_then_else expression
get_library_components_from_op_ast_state(ExcludeVars, [if_then_else|CarryComponents], AssigningVar, [Pred,If,Else], CarryComponentsAcc, Acc, NewAcc, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponentsAcc, AssigningVar, T, NewCarryComponentsAcc, NewAcc, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(if(SubstitutionList),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
extend_ground_truth_for_vars(ExcludeVars, [global_ground_truth_vars], [if_then_else], Acc, NewAcc1),
get_library_components_from_op_ast_state(ExcludeVars, [if_then_else|CarryComponents], AssigningVar, SubstitutionList, _, NewAcc1, NewAcc2, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, T, NewCarryComponentsAcc, NewAcc2, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(if_elsif(Condition,Substitution),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
get_library_components_from_op_ast_state(ExcludeVars, [], AssigningVar, [Condition], CarryComponentsAccPred, Acc, _, AssignedIds1),
extend_ground_truth_for_vars(ExcludeVars, [global_ground_truth_vars], [if_then_else|CarryComponentsAccPred], Acc, NewAcc1),
get_library_components_from_op_ast_state(ExcludeVars, [if_then_else|CarryComponentsAccPred], AssigningVar, [Substitution], _, NewAcc1, NewAcc2, AssignedIds2),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, T, NewCarryComponentsAcc, NewAcc2, UsedComponents, AssignedIds3),
append([AssignedIds1,AssignedIds2,AssignedIds3], AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(assign(Ids,Assignments),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
get_library_components_from_assignments(ExcludeVars, CarryComponents, Ids, Assignments, Acc, NewAcc1, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, T, NewCarryComponentsAcc, NewAcc1, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(identifier(_Name),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, T, NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(skip,subst,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
!,
b_get_machine_variables(MachineVars),
findall(N, member(b(identifier(N),_,_), MachineVars), MachineVarNames),
extend_ground_truth_for_vars(ExcludeVars, MachineVarNames, [skip|CarryComponents], Acc, NewAcc),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, T, NewCarryComponentsAcc, NewAcc, UsedComponents, AssignedIds1),
append(MachineVarNames, AssignedIds1, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, none, [b(assign_single_id(b(identifier(Name),_,_),b(identifier(Name),_,_)),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, [Name|AssignedIds]) :-
!,
extend_ground_truth_for_vars(ExcludeVars, [Name], [skip|CarryComponents], Acc, NewAcc),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, none, T, NewCarryComponentsAcc, NewAcc, UsedComponents, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, none, [b(assign_single_id(b(identifier(Name),_,_),_),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, [Name|AssignedIds]) :-
% exclude assignments of operation return values
member(b(identifier(Name),_,_), ExcludeVars),
!,
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, none, T, NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, none, [b(assign_single_id(b(identifier(Name),_,_),Arg),_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, [Name|AssignedIds]) :-
!,
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, none, [Arg], CarryComponentsAcc, Acc, NewAcc1, AssignedIds1),
extend_ground_truth_for_vars(ExcludeVars, [Name], CarryComponentsAcc, NewAcc1, NewAcc2),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, none, T, NewCarryComponentsAcc, NewAcc2, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, none, [b(Node,_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
% treat becomes_element_of and becomes_such like assignments when collecting components since the semantics do not matter here
Node =.. [Functor,Ids,Arg],
( Functor == becomes_element_of
; Functor == becomes_such
),
!,
findall(Name, member(b(identifier(Name),_,_), Ids), IdNames),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, none, [Arg], CarryComponentsAcc, Acc, NewAcc1, AssignedIds1),
extend_ground_truth_for_vars(ExcludeVars, IdNames, [Functor|CarryComponentsAcc], NewAcc1, NewAcc2),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, none, T, NewCarryComponentsAcc, NewAcc2, UsedComponents, AssignedIds2),
append([IdNames, AssignedIds1, AssignedIds2], AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [Constant|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
get_constant_component(Constant, ConstantComponent),
!,
% do not duplicate constant components for the same constant value
( explicit_component_not_collected_yet(Constant) ->
CarryComponents2 = [ConstantComponent|CarryComponents]
; CarryComponents2 = CarryComponents
),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents2, AssigningVar, T, NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(Node,_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
Node =.. [Component|Args],
\+ member(Component, [assign_single_id,assign,choice]),
explicit_component_not_collected_yet(b(Node,_,_)),
!,
get_library_components_from_op_ast_state_l(ExcludeVars, [Component|CarryComponents], AssigningVar, Args, CarryComponentsAcc, Acc, NewAcc, AssignedIds),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponentsAcc, AssigningVar, T, NewCarryComponentsAcc, NewAcc, UsedComponents, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [List|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
is_list(List),
!,
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, List, CarryComponentsAcc, Acc, NewAcc, AssignedIds1),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponentsAcc, AssigningVar, T, NewCarryComponentsAcc, NewAcc, UsedComponents, AssignedIds2),
append(AssignedIds1, AssignedIds2, AssignedIds).
get_library_components_from_op_ast_state_l(ExcludeVars, CarryComponents, AssigningVar, [b(Node,_,_)|T], NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds) :-
( skip_record_for_operator(Node) ->
!,
fail
; true
),
functor(Node, Functor, _),
( \+ explicit_component_not_collected_yet(b(Node,_,_)) ->
true
; add_warning(get_library_components_from_op_ast, 'Warning: Skipped component with functor:', [Functor,Node])
),
get_library_components_from_op_ast_state(ExcludeVars, CarryComponents, AssigningVar, T, NewCarryComponentsAcc, Acc, UsedComponents, AssignedIds).