1 | % (c) 2016-2024 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, | |
2 | % Heinrich Heine Universitaet Duesseldorf | |
3 | % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) | |
4 | ||
5 | :- module(kernel_frozen_info,[kfi_domain/2, kfi_range/2]). | |
6 | ||
7 | :- use_module(module_information,[module_info/2]). | |
8 | :- module_info(group,kernel). | |
9 | :- module_info(description,'This module detects information about variables by using frozen.'). | |
10 | ||
11 | % light-weight CHR-style propagations | |
12 | % ideally we should rewrite this to use CHR itself or attributes | |
13 | % indeed, the code below is very limited: will find only one domain/range co-routine, | |
14 | % is quite brittle wrt the particular pending co-routine, may be expensive if lot of co-routines attached,... | |
15 | ||
16 | :- use_module(debug). | |
17 | ||
18 | kfi_domain(V,Domain) :- var(V), frozen(V,Frozen), | |
19 | attached_domain_info(Frozen,V,Domain), %print(attached(V,Domain)),nl,nl, | |
20 | debug_println(5,found_kfi_attached_domain(V,Domain)). | |
21 | ||
22 | attached_domain_info((A,B),Var,Dom) :- | |
23 | (attached_domain_info(A,Var,R) -> Dom=R ; attached_domain_info(B,Var,Dom)). | |
24 | attached_domain_info(kernel_mappings:binary_in_kernel_call2(_Module,Pred,X,Arg1,Arg2,_WF,_WF0),Var,Dom) :- | |
25 | binary_in_domain(Pred,X,Arg1,Arg2,Var,Dom). | |
26 | ||
27 | ||
28 | % to do: add other infos/co-routines | |
29 | binary_in_domain(total_function_wf,X,TFDom,_TFRange,Var, Dom) :- Var==X, Dom=TFDom. | |
30 | binary_in_domain(total_injection_wf,X,TFDom,_TFRange,Var, Dom) :- Var==X, Dom=TFDom. | |
31 | binary_in_domain(total_surjection_wf,X,TFDom,_TFRange,Var, Dom) :- Var==X, Dom=TFDom. | |
32 | binary_in_domain(total_bijection_wf,X,TFDom,_TFRange,Var, Dom) :- Var==X, Dom=TFDom. | |
33 | binary_in_domain(total_relation_wf,X,TFDom,_TFRange,Var, Dom) :- Var==X, Dom=TFDom. | |
34 | binary_in_domain(total_surjection_relation_wf,X,TFDom,_TFRange,Var, Dom) :- Var==X, Dom=TFDom. | |
35 | ||
36 | % ------------ | |
37 | ||
38 | % TO DO: for surjections we can also do kfi_range(V,Range) | |
39 | ||
40 | kfi_range(V,Ran) :- var(V), frozen(V,Frozen), | |
41 | attached_range_info(Frozen,V,Ran), print(attached_range(V,Ran)),nl,nl,debug_println(5,found_range(V,Ran)). | |
42 | ||
43 | attached_range_info((A,B),Var,Ran) :- | |
44 | (attached_range_info(A,Var,R) -> Ran=R ; attached_range_info(B,Var,Ran)). | |
45 | attached_range_info(kernel_mappings:binary_in_kernel_call2(_Module,Pred,X,Arg1,Arg2,_WF,_WF0),Var,Ran) :- | |
46 | binary_in_range(Pred,X,Arg1,Arg2,Var,Ran). | |
47 | ||
48 | ||
49 | binary_in_range(total_surjection_wf,X,_TFDom,TFRange,Var, Ran) :- Var==X, Ran=TFRange. | |
50 | binary_in_range(total_bijection_wf,X,_TFDom,TFRange,Var, Ran) :- Var==X, Ran=TFRange. | |
51 | binary_in_range(total_surjection_relation_wf,X,_TFDom,TFRange,Var, Ran) :- Var==X, Ran=TFRange. | |
52 | binary_in_range(partial_surjection_wf,X,_TFDom,TFRange,Var, Ran) :- Var==X, Ran=TFRange. | |
53 | binary_in_range(surjection_relation_wf,X,_TFDom,TFRange,Var, Ran) :- Var==X, Ran=TFRange. |