13
14:- module(parse_util, [ generate_facts/1,
15 update_facts/2,
16 assert_new_node/4,
17 cleanup_nodes/0,
18 cleanup_nodes/1,
19 cleanup_computed_facts/0]). 20
21:- reexport('pdt_factbase.pl'). 22:- ensure_loaded('util/walking_prolog_files.pl'). 23:- use_module(preparser). 24:- use_module(predicates). 25:- use_module(load_graph). 26:- use_module(modules_and_visibility). 27:- use_module(literal_parser). 28:- use_module(cross_reference_builder). 29
30generate_facts(Project):-
31 cleanup_nodes,
32 walking_file_list(Project,parse,1),
33 build_load_graph,
34 derive_all_predicates,
35 derive_directive_collections,
36 compute_all_predicate_properties,
37 compute_visibility_graph,
38 parse_bodies,
39 derive_edges.
40
60
61update_facts(File, Project):-
62 cleanup_nodes(File),
63 cleanup_computed_facts,
64 walking_file_list([File|Project],parse,1),
65 build_load_graph,
66 derive_predicates_of_files([File|Project]),
67 derive_directive_collection_of_files([File|Project]),
68 compute_predicate_properties_for_files([File|Project]),
69 compute_visibility_graph,
70 parse_bodies,
71 derive_edges.
72
93
94
95
100cleanup_nodes:-
101 retractall(fileT(_,_,_)),
102 retractall(literalT(_,_,_,_,_,_)),
103 retractall(metaT(_,_,_,_,_,_)),
104 retractall(headT(_,_,_,_,_)),
105 retractall(clauseT(_,_,_,_,_)),
106 retractall(directiveT(_,_,_)),
107 retractall(operatorT(_,_,_,_,_,_,_,_)),
108 retractall(predicateT(_,_,_,_,_)),
109 retractall(onloadT(_,_,_)),
110 retractall(dynamicT(_,_)),
111 retractall(load_dir(_,_,_)),
112 retractall(import_dir(_,_)),
113 retractall(export_dir(_,_)),
114 retractall(library_dir(_,_,_)),
115 retractall(property_dir(_,_,_)),
116 retractall(transparentT(_,_)),
117 retractall(multifileT(_,_)),
118 retractall(meta_predT(_,_)),
119 retractall(termT(_,_)),
120 retractall(filePosT(_,_,_)),
121 retractall(literalT_ri(_,_,_,_)),
122 retractall(fileT_ri(_,_)),
123 retractall(predicateT_ri(_,_,_,_)),
124 retractall(pred_edge(_,_)),
125 retractall(onload_edge(_,_)),
126 retractall(pos_and_vars(_,_,_)),
127 retractall(error(_,_,_)),
128 retractall(warning(_,_,_)),
129 cleanup_computed_facts,
130 ctc_id_init_pdt.
131
132cleanup_computed_facts:-
133 retractall(call_edge(_,_)),
134
135 retractall(load_edge(_,_,_,_)),
136 retractall(call_built_in(_,_,_,_)),
137
138 retractall(meta_predT(_,found)).
139
140
141cleanup_nodes(File):-
142 fileT_ri(File,Id), !,
143 clean_file_entries(Id),
144 retractall(fileT_ri(File,Id)),
145 retractall(fileT(Id,_,_)),
146 retractall(error(_,_,Id)). 147cleanup_nodes(_).
148
149
150
151clean_file_entries(FileId):-
152 directiveT(DirId,FileId,_),
153 termT(DirId,_),
154 clean_directives(DirId),
159 clean_general_references_to(DirId),
160 retractall(directiveT(DirId,_,_)),
161 fail.
162clean_file_entries(FileId):-
163 clauseT(ClauseId,FileId,_,_,_),
164 clean_clause_references(ClauseId),
165 clean_general_references_to(ClauseId),
166 retractall(clauseT(ClauseId,_,_,_,_)),
167 fail.
168clean_file_entries(FileId):-
169 predicateT(PredId,FileId,_,_,_),
170 retractall(predicateT(PredId,_,_,_,_)),
171 retractall(predicateT_ri(_,_,_,PredId)),
172 fail.
173clean_file_entries(FileId):-
174 onloadT(Id,FileId,_),
175 retractall(onloadT(Id,_,_)),
176 fail.
177clean_file_entries(_).
178
179
180
181clean_clause_references(ClauseId):-
182 headT(HeadId,ClauseId,_,_,_),
183 clean_clause_references(HeadId),
184 retractall(headT(HeadId,_,_,_,_,_)),
185 fail.
186clean_clause_references(ClauseId):-
187 literalT(LitId,_,ClauseId,_,_,_),
188 clean_clause_references(LitId),
189 retractall(literalT(LitId,_,ClauseId,M,F,A)),
190 retractall(literalT_ri(F,A,M,LitId)),
191 retractall(metaT(LitId,_,ClauseId,_,_,_)),
192 retractall(pred_edge(ClauseId,_)),
193 fail.
194clean_clause_references(_).
195
196
197
198clean_directives(DirectiveId):-
199 retractall(import_dir(_,DirectiveId)),
200 retractall(export_dir(_,DirectiveId)),
201 retractall(load_dir(DirectiveId,_,_)),
202 retractall(property_dir(DirectiveId,_,_)),
203 retractall(library_dir(_,_,DirectiveId)),
204 retractall(meta_pred(_,DirectiveId)),
205 retractall(onload_edge(DirectiveId,_)).
206
207
208
209clean_general_references_to(Id):-
210 retractall(termT(Id,_)),
211 retractall(filePosT(Id,_,_)),
212 retractall(warning(Id,_,_)),
213 retractall(pos_and_vars(Id,_,_)).
214
215
222assert_new_node(Term,From,To,Id):-
223 new_node_id_pdt(Id),
224 assert(termT(Id,Term)),
225 Length is To - From,
226 assert(filePosT(Id,From,Length))