1 | % (c) 2009 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(zparameters,[insert_parameter/4]). | |
6 | ||
7 | :- use_module(library(lists)). | |
8 | ||
9 | :- use_module(probsrc(tools)). | |
10 | ||
11 | :- use_module(subexpressions). | |
12 | ||
13 | :- use_module(probsrc(module_information)). | |
14 | :- module_info(group,proz). | |
15 | :- module_info(description,'This module provides functionality to replace a Z schema\'s parameter by expressions'). | |
16 | ||
17 | %******************************************************************************** | |
18 | % insert_parameter | |
19 | insert_parameter(Exprs,[],[],Exprs) :- !. | |
20 | insert_parameter(Exprs,Params,Values,Result) :- insert_parameter2(Exprs,Params,Values,Result). | |
21 | ||
22 | insert_parameter2([],_,_,[]) :- !. | |
23 | insert_parameter2([E|ERest],Params,Values,[P|PRest]) :- | |
24 | !,insert_parameter2(E,Params,Values,P), | |
25 | insert_parameter2(ERest,Params,Values,PRest). | |
26 | insert_parameter2(ref(Name,P),Params,Values,ref(Value,P)) :- | |
27 | !, | |
28 | (nth0(N,Params,Name) -> nth0(N,Values,Value) ; Value = Name). | |
29 | insert_parameter2(Expr,Params,Values,Result) :- | |
30 | znamespace(Expr,Outer,Inner,Names,NOuter,NInner,Result), | |
31 | !, | |
32 | insert_parameter2(Outer,Params,Values,NOuter), | |
33 | remove_params(Params,Values,Names,NParams,NValues), | |
34 | insert_parameter(Inner,NParams,NValues,NInner). | |
35 | insert_parameter2(Expr,Params,Values,Result) :- | |
36 | zexpr_conversion(Expr,Subs,PSubs,Result), | |
37 | insert_parameter2(Subs,Params,Values,PSubs). | |
38 | ||
39 | remove_params([],[],_,[],[]). | |
40 | remove_params([P|PRest],[V|VRest],Names,Params,Values) :- | |
41 | (member(P,Names) -> | |
42 | (Params = OParams, Values = OValues); | |
43 | (Params = [P|OParams], Values = [V|OValues])), | |
44 | remove_params(PRest,VRest,Names,OParams,OValues). |