File: goal_path.m

package info (click to toggle)
mercury 0.9-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 18,488 kB
  • ctags: 9,800
  • sloc: objc: 146,680; ansic: 51,418; sh: 6,436; lisp: 1,567; cpp: 1,040; perl: 854; makefile: 450; asm: 232; awk: 203; exp: 32; fortran: 3; csh: 1
file content (93 lines) | stat: -rw-r--r-- 3,531 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
%-----------------------------------------------------------------------------%
% Copyright (C) 1997-1999 University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%

% This module looks after goal paths, which associate each goal
% with its position in a procedure definition,

% Main author: zs.

:- module goal_path.

:- interface.

:- import_module hlds_pred, hlds_module.

:- pred goal_path__fill_slots(proc_info::in, module_info::in, proc_info::out)
	is det.

:- implementation.

:- import_module hlds_goal.
:- import_module int, list, std_util, require.

goal_path__fill_slots(Proc0, _ModuleInfo, Proc) :-
		% The ModuleInfo argument is there just for passes_aux
	proc_info_goal(Proc0, Goal0),
	fill_goal_slots(Goal0, [], Goal),
	proc_info_set_goal(Proc0, Goal, Proc).

:- pred fill_goal_slots(hlds_goal::in, goal_path::in, hlds_goal::out) is det.

fill_goal_slots(Expr0 - Info0, Path0, Expr - Info) :-
	goal_info_set_goal_path(Info0, Path0, Info),
	fill_expr_slots(Expr0, Path0, Expr).

:- pred fill_expr_slots(hlds_goal_expr::in, goal_path::in,
	hlds_goal_expr::out) is det.

fill_expr_slots(conj(Goals0), Path0, conj(Goals)) :-
	fill_conj_slots(Goals0, Path0, 0, Goals).
fill_expr_slots(par_conj(Goals0, SM), Path0, par_conj(Goals, SM)) :-
	fill_conj_slots(Goals0, Path0, 0, Goals).
fill_expr_slots(disj(Goals0, B), Path0, disj(Goals, B)) :-
	fill_disj_slots(Goals0, Path0, 0, Goals).
fill_expr_slots(switch(A, B, Cases0, D), Path0, switch(A, B, Cases, D)) :-
	fill_switch_slots(Cases0, Path0, 0, Cases).
fill_expr_slots(not(Goal0), Path0, not(Goal)) :-
	fill_goal_slots(Goal0, [neg | Path0], Goal).
fill_expr_slots(some(A, B, Goal0), Path0, some(A, B, Goal)) :-
	fill_goal_slots(Goal0, [exist | Path0], Goal).
fill_expr_slots(if_then_else(A, Cond0, Then0, Else0, E), Path0,
		if_then_else(A, Cond, Then, Else, E)) :-
	fill_goal_slots(Cond0, [ite_cond | Path0], Cond),
	fill_goal_slots(Then0, [ite_then | Path0], Then),
	fill_goal_slots(Else0, [ite_else | Path0], Else).
fill_expr_slots(call(A,B,C,D,E,F), _Path0, call(A,B,C,D,E,F)).
fill_expr_slots(generic_call(A,B,C,D), _Path0, generic_call(A,B,C,D)).
fill_expr_slots(unify(A,B,C,D,E), _Path0, unify(A,B,C,D,E)).
fill_expr_slots(pragma_c_code(A,B,C,D,E,F,G), _Path0,
		pragma_c_code(A,B,C,D,E,F,G)).
fill_expr_slots(bi_implication(_, _), _, _) :-
	% these should have been expanded out by now
	error("fill_expr_slots: unexpected bi_implication").

:- pred fill_conj_slots(list(hlds_goal)::in, goal_path::in, int::in,
	list(hlds_goal)::out) is det.

fill_conj_slots([], _, _, []).
fill_conj_slots([Goal0 | Goals0], Path0, N0, [Goal | Goals]) :-
	N1 is N0 + 1,
	fill_goal_slots(Goal0, [conj(N1) | Path0], Goal),
	fill_conj_slots(Goals0, Path0, N1, Goals).

:- pred fill_disj_slots(list(hlds_goal)::in, goal_path::in, int::in,
	list(hlds_goal)::out) is det.

fill_disj_slots([], _, _, []).
fill_disj_slots([Goal0 | Goals0], Path0, N0, [Goal | Goals]) :-
	N1 is N0 + 1,
	fill_goal_slots(Goal0, [disj(N1) | Path0], Goal),
	fill_disj_slots(Goals0, Path0, N1, Goals).

:- pred fill_switch_slots(list(case)::in, goal_path::in, int::in,
	list(case)::out) is det.

fill_switch_slots([], _, _, []).
fill_switch_slots([case(A, Goal0) | Cases0], Path0, N0,
		[case(A, Goal) | Cases]) :-
	N1 is N0 + 1,
	fill_goal_slots(Goal0, [switch(N1) | Path0], Goal),
	fill_switch_slots(Cases0, Path0, N1, Cases).