location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,LocationVarName,[LocationVarNode|RUsedLVars],IfThenElseAst) :-
LocationVarNode = b(identifier(LocationVarName),_,Info) ,
member(LocationVarNode,LocationVarsOut) ,
subset([synthesis(type,Type),synthesis(Component,output)],Info) ,
atom_concat(if_then_else,_,Component) , ! ,
% find the location variable of the statement's condition
get_location_var_node_by_info_term(LocationVarsIn,synthesis(Component,condition),b(identifier(ConditionName),_,_)) ,
location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,ConditionName,ConditionUsedLVars,ConditionAst) ,
% find location variables for truth and falsity outputs of the if_then_else statement
get_location_var_node_by_info_term(LocationVarsIn,synthesis(Component,true_out),b(identifier(TrueOutName),_,_)) ,
location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,TrueOutName,TrueOutUsedLVars,TrueOutAst) ,
get_location_var_node_by_info_term(LocationVarsIn,synthesis(Component,false_out),b(identifier(FalseOutName),_,_)) ,
location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,FalseOutName,FalseOutUsedLVars,FalseOutAst) ,
append([ConditionUsedLVars,TrueOutUsedLVars,FalseOutUsedLVars],RUsedLVars) ,
IfThenElseAst = b(if_then_else(ConditionAst,TrueOutAst,FalseOutAst),Type,[]).
location_to_ast(_,_,_,LocationVarsOut,_,_,LocationVarName,[LocationVarNode],IdNode) :-
LocationVarNode = b(identifier(LocationVarName),_,Info) ,
member(LocationVarNode,LocationVarsOut) ,
(subset([synthesis(_,output),synthesis(machineconstant,IdNode)],Info) ;
subset([synthesis(_,output),synthesis(operationparameter,IdNode)],Info)) , !.
location_to_ast(_,_,_,LocationVarsOut,_,_,LocationVarName,[LocationVarNode],AST) :-
LocationVarNode = b(identifier(LocationVarName),_,Info) ,
member(LocationVarNode,LocationVarsOut) ,
subset([synthesis(ConstantName,output),synthesis(type,Type)],Info) ,
atom_concat(constant_set,_,ConstantName) , ! ,
% export as infinite set
get_single_constant_or_set_operator_id(Type,_,AST).
location_to_ast(_,_,_,LocationVarsOut,_,_,LocationVarName,[LocationVarNode],Node) :-
LocationVarNode = b(identifier(LocationVarName),_,Info) ,
member(LocationVarNode,LocationVarsOut) ,
member(synthesis(ConstantName,output),Info) ,
member(synthesis(ParamType,ParamName),Info) ,
(ParamType = param_single ; ParamType = param_set) ,
atom_concat(constant,_,ConstantName) , ! ,
member(synthesis(type,Type),Info) ,
(Type = set(global(Independent)) ; Type = global(Independent)) ,
(ParamType = param_set
-> Node = b(set_extension([b(identifier(ParamName),global(Independent),Info)]),set(global(Independent)),Info)
; ParamType = param_single ,
Node = b(identifier(ParamName),global(Independent),Info)).
location_to_ast(_,_,_,LocationVarsOut,_,Bindings,LocationVarName,[LocationVarNode],Node) :-
LocationVarNode = b(identifier(LocationVarName),_,Info) ,
member(LocationVarNode,LocationVarsOut) ,
member(synthesis(ConstantName,output),Info) ,
atom_concat(constant,_,ConstantName) , ! ,
% get constant solution, either integer or boolean
get_variable_value_from_bindings(Bindings, ConstantName, ProBValue),
member(synthesis(type,Type),Info) ,
Node = b(value(ProBValue),Type,Info).
location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,LocationVarName,[LocationVarNode|RUsedLVars],AstNode) :-
LocationVarNode = b(identifier(LocationVarName),_,InfoOut) ,
member(LocationVarNode,LocationVarsOut) ,
subset([synthesis(Component,output),synthesis(type,Type)],InfoOut) ,
synthesis_util:delete_numbers_from_atom(Component,ComponentName) ,
member(ComponentName,[negation,card,size,max,min,general_union,general_intersection,reverse,range,domain,skip,convert_bool,first,last]) , ! ,
% find input location variables
get_location_var_node_by_info_term(LocationVarsIn,synthesis(Component,input),b(identifier(InName),_,_)) ,
location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,InName,RUsedLVars,InputAST) ,
Node =.. [ComponentName,InputAST] ,
single_input_location_to_ast_aux(ComponentName,b(Node,Type,InfoOut),InputAST,AstNode).
location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,LocationVarName,UsedLVars,AST) :-
LocationVarNode = b(identifier(LocationVarName),_Type,InfoOut) ,
member(LocationVarNode,LocationVarsOut) , ! ,
member(synthesis(Component,output),InfoOut) ,
% find input location variables
get_location_var_node_by_info_term(LocationVarsIn,synthesis(Component,left_input),b(identifier(InName1),_,_)) ,
get_location_var_node_by_info_term(LocationVarsIn,synthesis(Component,right_input),b(identifier(InName2),_,_)) ,
location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,InName1,
LeftUsedLVars,LeftInputAST) ,
location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,InName2,
RightUsedLVars,RightInputAST) ,
synthesis_util:delete_numbers_from_atom(Component,ComponentName) ,
% get the type from the output nodes information
member(synthesis(type,Type),InfoOut) ,
Node =.. [ComponentName,LeftInputAST,RightInputAST] ,
append([[LocationVarNode],LeftUsedLVars,RightUsedLVars],UsedLVars) ,
set_type(b(Node,Type,InfoOut),AST).
location_to_ast(_,CurrentVars,LocationVarsIn,_,Parameter,Bindings,LocationVarName,[],b(identifier(VarName),Type,Info)) :-
get_variable_value_from_bindings(Bindings, LocationVarName, ProBValue),
ProBValue = int(Value),
Value < Parameter , ! ,
get_varname_for_input_enumeration(LocationVarsIn,Value,VarName) ,
member(b(identifier(VarName),Type,Info),CurrentVars).
location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,LocationVarName,UsedLVars,AST) :-
get_variable_value_from_bindings(Bindings, LocationVarName, ProBValue),
ProBValue = int(Value),
Value >= Parameter ,
% temporary output variable
LocationOut = b(identifier(LocationOutName),_,_) ,
% get output defined at corresponding location
get_variable_value_from_bindings(Bindings, LocationOutName, ProBValue),
ProBValue = int(Value),
LocationVarName \= LocationOutName ,
member(LocationOut,LocationVarsOut) ,
location_to_ast(Library,CurrentVars,LocationVarsIn,LocationVarsOut,Parameter,Bindings,
LocationOutName,UsedLVars,AST).