| 1 | :- multifile generate/2. | |
| 2 | ||
| 3 | :- use_module(synthesis(synthesis_util),[find_typed_identifier_uses_with_info/2]). | |
| 4 | ||
| 5 | % return explicit bindings as terms bind/2 and the used identifier nodes | |
| 6 | generate(prob_state_bindlist(AST),Bindings:TypedIDs) :- | |
| 7 | find_typed_identifier_uses_with_info(AST,TypedIDs) , | |
| 8 | maplist(ast_ids_to_bindlist,TypedIDs,Bindings) , !. | |
| 9 | % unbound bindlist | |
| 10 | generate(prob_state_bindlist(AST,Options),Bindings:TypedIDs) :- | |
| 11 | member(unbound,Options) , | |
| 12 | find_typed_identifier_uses_with_info(AST,TypedIDs) , | |
| 13 | findall(bind(ID,_),member(b(identifier(ID),_,_),TypedIDs),Bindings) , !. | |
| 14 | ||
| 15 | % generate a binding for an identifier | |
| 16 | ast_ids_to_bindlist(b(identifier(Name),record(FieldList),_),bind(Name,Record)) :- | |
| 17 | FieldList = [field(_,Type)|_] , | |
| 18 | NType =.. [Type,[]] , | |
| 19 | findall(FieldName,member(field(FieldName,_),FieldList),NameList) , | |
| 20 | generate(prob_ast_record(NType,[names:NameList]),Record). | |
| 21 | ast_ids_to_bindlist(b(identifier(Name),Type,_),bind(Name,Value)) :- | |
| 22 | % add options to inner type for generation | |
| 23 | inner_type(Type,Inner,Outter) , | |
| 24 | % options for integer, other types ignore this option | |
| 25 | NewInner =.. [Inner,[small,positive,nozero]] , | |
| 26 | surround_type(NewInner,Outter,TempType) , | |
| 27 | gen_type(TempType,value,NewType) , | |
| 28 | generate(NewType,Value). |