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(dependence,[schema_dependence/2]). | |
6 | ||
7 | :- use_module(library(lists)). | |
8 | :- use_module(probsrc(tools)). | |
9 | :- use_module(z_tools). | |
10 | ||
11 | :- use_module(probsrc(module_information)). | |
12 | :- module_info(group,proz). | |
13 | :- module_info(description,'This module provides a predicate to find dependencies between Z schemas'). | |
14 | ||
15 | schema_dependence(Def,Dependencies) :- | |
16 | extract_schemas(Def,Names,Bodies), | |
17 | schema_dependence2(Names,Bodies,Dependencies1), | |
18 | check_abbreviations(Def,Dependencies1,Dependencies). | |
19 | schema_dependence2([],_,[]). | |
20 | schema_dependence2([Id|NRest],[Body|BRest],Deps) :- | |
21 | schemadeps(Id,Body,Deps1), | |
22 | append(Deps1,Deps2,Deps), | |
23 | schema_dependence2(NRest,BRest,Deps2). | |
24 | ||
25 | extract_schemas([],[],[]) :- !. | |
26 | extract_schemas([sdef(shead(Name,_),Body)|Rest], [Name|NRest],[Body|BRest]) :- | |
27 | !,extract_schemas(Rest,NRest,BRest). | |
28 | extract_schemas([defeq(shead(Name,_),Body)|Rest], [Name|NRest],[Body|BRest]) :- | |
29 | !,extract_schemas(Rest,NRest,BRest). | |
30 | extract_schemas([_|Rest],NRest,BRest) :- extract_schemas(Rest,NRest,BRest). | |
31 | ||
32 | check_abbreviations([],D,D) :- !. | |
33 | check_abbreviations([eqeq(lhs(name(Id,''),_),Body)|Rest],Deps,Result) :- | |
34 | member(dep(_,Id),Deps), | |
35 | !, | |
36 | schemadeps(Id,Body,Deps1), | |
37 | append(Deps,Deps1,NewDeps), | |
38 | check_abbreviations(Rest,NewDeps,Result). | |
39 | check_abbreviations([_|Rest],Deps,Result) :- check_abbreviations(Rest,Deps,Result). | |
40 | ||
41 | schemadeps(Id,Body,Deps) :- | |
42 | sdep(Body,LDeps), | |
43 | findall(dep(Id,D),member(D,LDeps),Deps). | |
44 | ||
45 | sdep([],[]). | |
46 | sdep([S|Rest],Deps) :- | |
47 | sdep(S,Deps1), | |
48 | sdep(Rest,Deps2), | |
49 | append_not_duplicate(Deps1,Deps2,Deps). | |
50 | sdep(sref(Id,_,_,_),[Id]). | |
51 | sdep(sand(A,B),Deps) :- sdep([A,B],Deps). | |
52 | sdep(sor(A,B),Deps) :- sdep([A,B],Deps). | |
53 | sdep(simplies(A,B),Deps) :- sdep([A,B],Deps). | |
54 | sdep(sequiv(A,B),Deps) :- sdep([A,B],Deps). | |
55 | sdep(snot(A),Deps) :- sdep(A,Deps). | |
56 | sdep(fatsemi(A,B),Deps) :- sdep([A,B],Deps). | |
57 | sdep(sforall(A,B),Deps) :- sdep([A,B],Deps). | |
58 | sdep(sexists(A,B),Deps) :- sdep([A,B],Deps). | |
59 | sdep(sexists1(A,B),Deps) :- sdep([A,B],Deps). | |
60 | sdep(hide(S,_),Deps) :- sdep(S,Deps). | |
61 | sdep(project(A,B),Deps) :- sdep([A,B],Deps). | |
62 | sdep(pre(S),Deps) :- sdep(S,Deps). | |
63 | sdep(pipe(A,B),Deps) :- sdep([A,B],Deps). | |
64 | ||
65 | sdep(body(Decls,_),Deps) :- sdep(Decls,Deps). | |
66 | sdep(text(S),Deps) :- sdep(S,Deps). | |
67 | sdep(decl(_,_),[]). | |
68 | sdep(sdecl(S),Deps) :- sdep(S,Deps). | |
69 |