[m-rev.] diff: clean up prog_util.m
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon Jan 12 17:45:32 AEDT 2004
compiler/prog_util.m:
Bring this module into line with our current coding standards:
use predmode declarations and state variable syntax when appropriate,
and change argument order where this enables use of state variables.
compiler/prog_io_dcg.m:
Conform to changed argument order in a predicate exported by
prog_util.m.
Zoltan.
cvs diff: Diffing .
Index: prog_io_dcg.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_io_dcg.m,v
retrieving revision 1.23
diff -u -b -r1.23 prog_io_dcg.m
--- prog_io_dcg.m 31 Oct 2003 03:27:28 -0000 1.23
+++ prog_io_dcg.m 6 Jan 2004 15:29:22 -0000
@@ -260,7 +260,7 @@
Goal = (A1 ; B2) - Context
;
Var = VarB,
- prog_util__rename_in_goal(A1, VarA, VarB, A2),
+ prog_util__rename_in_goal(VarA, VarB, A1, A2),
Goal = (A2 ; B1) - Context
)
).
@@ -471,7 +471,7 @@
% don't need to do the substitution in the condition.
Var = VarElse,
- prog_util__rename_in_goal(Then1, VarThen, VarElse, Then),
+ prog_util__rename_in_goal(VarThen, VarElse, Then1, Then),
Else = Else1
),
Goal = if_then_else(SomeVars, StateVars, Cond, Then, Else) - Context.
Index: prog_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_util.m,v
retrieving revision 1.65
diff -u -b -r1.65 prog_util.m
--- prog_util.m 5 Nov 2003 03:17:42 -0000 1.65
+++ prog_util.m 6 Jan 2004 15:29:22 -0000
@@ -77,38 +77,34 @@
% Succeeds iff the specified module is one of the
% builtin modules listed above which are automatically imported.
-:- pred any_mercury_builtin_module(sym_name).
-:- mode any_mercury_builtin_module(in) is semidet.
+:- pred any_mercury_builtin_module(sym_name::in) is semidet.
%-----------------------------------------------------------------------------%
% Given a symbol name, return its unqualified name.
-:- pred unqualify_name(sym_name, string).
-:- mode unqualify_name(in, out) is det.
+:- pred unqualify_name(sym_name::in, string::out) is det.
% sym_name_get_module_name(SymName, DefaultModName, ModName):
% Given a symbol name, return the module qualifier(s).
% If the symbol is unqualified, then return the specified default
% module name.
%
-:- pred sym_name_get_module_name(sym_name, module_name, module_name).
-:- mode sym_name_get_module_name(in, in, out) is det.
+:- pred sym_name_get_module_name(sym_name::in, module_name::in,
+ module_name::out) is det.
% string_to_sym_name(String, Separator, SymName):
% Convert a string, possibly prefixed with
% module qualifiers (separated by Separator),
% into a symbol name.
%
-:- pred string_to_sym_name(string, string, sym_name).
-:- mode string_to_sym_name(in, in, out) is det.
+:- pred string_to_sym_name(string::in, string::in, sym_name::out) is det.
% match_sym_name(PartialSymName, CompleteSymName):
% succeeds iff there is some sequence of module qualifiers
% which when prefixed to PartialSymName gives CompleteSymName.
%
-:- pred match_sym_name(sym_name, sym_name).
-:- mode match_sym_name(in, in) is semidet.
+:- pred match_sym_name(sym_name::in, sym_name::in) is semidet.
% remove_sym_name_prefix(SymName0, Prefix, SymName)
% succeeds iff
@@ -126,32 +122,31 @@
% and the unqualified part of SymName0 has the given suffix
% and the unqualified part of SymName is the unqualified
% part of SymName0 with the suffix removed
-:- pred remove_sym_name_suffix(sym_name, string, sym_name).
-:- mode remove_sym_name_suffix(in, in, out) is semidet.
+:- pred remove_sym_name_suffix(sym_name::in, string::in, sym_name::out)
+ is semidet.
% add_sym_name_suffix(SymName0, Suffix, SymName)
% succeeds iff
% SymName and SymName0 have the same module qualifier
% and the unqualified part of SymName is the unqualified
% part of SymName0 with the suffix added
-:- pred add_sym_name_suffix(sym_name, string, sym_name).
-:- mode add_sym_name_suffix(in, in, out) is det.
+:- pred add_sym_name_suffix(sym_name::in, string::in, sym_name::out) is det.
% insert_module_qualifier(ModuleName, SymName0, SymName):
% prepend the specified ModuleName onto the module
% qualifiers in SymName0, giving SymName.
-:- pred insert_module_qualifier(string, sym_name, sym_name).
-:- mode insert_module_qualifier(in, in, out) is det.
+:- pred insert_module_qualifier(string::in, sym_name::in, sym_name::out)
+ is det.
% Given a possible module qualified sym_name and a list of
% argument types and a context, construct a term. This is
% used to construct types.
-:- pred construct_qualified_term(sym_name, list(term(T)), term(T)).
-:- mode construct_qualified_term(in, in, out) is det.
+:- pred construct_qualified_term(sym_name::in, list(term(T))::in,
+ term(T)::out) is det.
-:- pred construct_qualified_term(sym_name, list(term(T)), prog_context, term(T)).
-:- mode construct_qualified_term(in, in, in, out) is det.
+:- pred construct_qualified_term(sym_name::in, list(term(T))::in,
+ prog_context::in, term(T)::out) is det.
% Given a sym_name return the top level qualifier of that name.
:- func outermost_qualifier(sym_name) = string.
@@ -174,24 +169,21 @@
%
% Create a predicate name with context, e.g. for introduced
% lambda or deforestation predicates.
-:- pred make_pred_name(module_name, string, maybe(pred_or_func),
- string, new_pred_id, sym_name).
-:- mode make_pred_name(in, in, in, in, in, out) is det.
+:- pred make_pred_name(module_name::in, string::in, maybe(pred_or_func)::in,
+ string::in, new_pred_id::in, sym_name::out) is det.
% make_pred_name_with_context(ModuleName, Prefix, PredOrFunc, PredName,
% Line, Counter, SymName).
%
% Create a predicate name with context, e.g. for introduced
% lambda or deforestation predicates.
-:- pred make_pred_name_with_context(module_name, string, pred_or_func,
- string, int, int, sym_name).
-:- mode make_pred_name_with_context(in, in, in, in, in, in, out) is det.
+:- pred make_pred_name_with_context(module_name::in, string::in,
+ pred_or_func::in, string::in, int::in, int::in, sym_name::out) is det.
:- type new_pred_id
---> counter(int, int) % Line number, Counter
; type_subst(tvarset, type_subst)
- ; unused_args(list(int))
- .
+ ; unused_args(list(int)).
%-----------------------------------------------------------------------------%
@@ -207,18 +199,18 @@
:- type maybe_modes == maybe(list(mode)).
-:- pred split_types_and_modes(list(type_and_mode), list(type), maybe_modes).
-:- mode split_types_and_modes(in, out, out) is det.
+:- pred split_types_and_modes(list(type_and_mode)::in, list(type)::out,
+ maybe_modes::out) is det.
-:- pred split_type_and_mode(type_and_mode, type, maybe(mode)).
-:- mode split_type_and_mode(in, out, out) is det.
+:- pred split_type_and_mode(type_and_mode::in, (type)::out, maybe(mode)::out)
+ is det.
%-----------------------------------------------------------------------------%
% Perform a substitution on a goal.
-:- pred prog_util__rename_in_goal(goal, prog_var, prog_var, goal).
-:- mode prog_util__rename_in_goal(in, in, in, out) is det.
+:- pred prog_util__rename_in_goal(prog_var::in, prog_var::in,
+ goal::in, goal::out) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -275,7 +267,6 @@
construct_qualified_term(unqualified(Name), Args, Context, Term) :-
Term = term__functor(term__atom(Name), Args, Context).
-
construct_qualified_term(SymName, Args, Term) :-
term__context_init(Context),
construct_qualified_term(SymName, Args, Context, Term).
@@ -293,17 +284,14 @@
split_types_and_modes(TypesAndModes, Types, MaybeModes) :-
split_types_and_modes_2(TypesAndModes, yes, Types, Modes, Result),
- (
- Result = yes
- ->
+ ( Result = yes ->
MaybeModes = yes(Modes)
;
MaybeModes = no
).
-:- pred split_types_and_modes_2(list(type_and_mode), bool,
- list(type), list(mode), bool).
-:- mode split_types_and_modes_2(in, in, out, out, out) is det.
+:- pred split_types_and_modes_2(list(type_and_mode)::in, bool::in,
+ list(type)::out, list(mode)::out, bool::out) is det.
% T = type, M = mode, TM = combined type and mode
split_types_and_modes_2([], Result, [], [], Result).
@@ -317,8 +305,8 @@
% trd: this should never happen because prog_io.m will detect
% these cases
-:- pred split_type_and_mode(type_and_mode, bool, type, mode, bool).
-:- mode split_type_and_mode(in, in, out, out, out) is det.
+:- pred split_type_and_mode(type_and_mode::in, bool::in,
+ (type)::out, (mode)::out, bool::out) is det.
split_type_and_mode(type_only(T), _, T, (free -> free), no).
split_type_and_mode(type_and_mode(T,M), R, T, M, R).
@@ -328,92 +316,86 @@
%-----------------------------------------------------------------------------%
-prog_util__rename_in_goal(Goal0 - Context, OldVar, NewVar, Goal - Context) :-
- prog_util__rename_in_goal_expr(Goal0, OldVar, NewVar, Goal).
+prog_util__rename_in_goal(OldVar, NewVar, Goal0 - Context, Goal - Context) :-
+ prog_util__rename_in_goal_expr(OldVar, NewVar, Goal0, Goal).
-:- pred prog_util__rename_in_goal_expr(goal_expr, prog_var, prog_var,
- goal_expr).
-:- mode prog_util__rename_in_goal_expr(in, in, in, out) is det.
+:- pred prog_util__rename_in_goal_expr(prog_var::in, prog_var::in,
+ goal_expr::in, goal_expr::out) is det.
-prog_util__rename_in_goal_expr((GoalA0, GoalB0), OldVar, NewVar,
+prog_util__rename_in_goal_expr(OldVar, NewVar, (GoalA0, GoalB0),
(GoalA, GoalB)) :-
- prog_util__rename_in_goal(GoalA0, OldVar, NewVar, GoalA),
- prog_util__rename_in_goal(GoalB0, OldVar, NewVar, GoalB).
-prog_util__rename_in_goal_expr((GoalA0 & GoalB0), OldVar, NewVar,
+ prog_util__rename_in_goal(OldVar, NewVar, GoalA0, GoalA),
+ prog_util__rename_in_goal(OldVar, NewVar, GoalB0, GoalB).
+prog_util__rename_in_goal_expr(OldVar, NewVar, (GoalA0 & GoalB0),
(GoalA & GoalB)) :-
- prog_util__rename_in_goal(GoalA0, OldVar, NewVar, GoalA),
- prog_util__rename_in_goal(GoalB0, OldVar, NewVar, GoalB).
-prog_util__rename_in_goal_expr(true, _Var, _NewVar, true).
-prog_util__rename_in_goal_expr((GoalA0; GoalB0), OldVar, NewVar,
+ prog_util__rename_in_goal(OldVar, NewVar, GoalA0, GoalA),
+ prog_util__rename_in_goal(OldVar, NewVar, GoalB0, GoalB).
+prog_util__rename_in_goal_expr(_OldVar, _NewVar, true, true).
+prog_util__rename_in_goal_expr(OldVar, NewVar, (GoalA0; GoalB0),
(GoalA; GoalB)) :-
- prog_util__rename_in_goal(GoalA0, OldVar, NewVar, GoalA),
- prog_util__rename_in_goal(GoalB0, OldVar, NewVar, GoalB).
-prog_util__rename_in_goal_expr(fail, _Var, _NewVar, fail).
-prog_util__rename_in_goal_expr(not(Goal0), OldVar, NewVar, not(Goal)) :-
- prog_util__rename_in_goal(Goal0, OldVar, NewVar, Goal).
-prog_util__rename_in_goal_expr(some(Vars0, Goal0), OldVar, NewVar,
+ prog_util__rename_in_goal(OldVar, NewVar, GoalA0, GoalA),
+ prog_util__rename_in_goal(OldVar, NewVar, GoalB0, GoalB).
+prog_util__rename_in_goal_expr(_Var, _NewVar, fail, fail).
+prog_util__rename_in_goal_expr(OldVar, NewVar, not(Goal0), not(Goal)) :-
+ prog_util__rename_in_goal(OldVar, NewVar, Goal0, Goal).
+prog_util__rename_in_goal_expr(OldVar, NewVar, some(Vars0, Goal0),
some(Vars, Goal)) :-
- prog_util__rename_in_vars(Vars0, OldVar, NewVar, Vars),
- prog_util__rename_in_goal(Goal0, OldVar, NewVar, Goal).
-prog_util__rename_in_goal_expr(some_state_vars(Vars0, Goal0), OldVar, NewVar,
+ prog_util__rename_in_vars(OldVar, NewVar, Vars0, Vars),
+ prog_util__rename_in_goal(OldVar, NewVar, Goal0, Goal).
+prog_util__rename_in_goal_expr(OldVar, NewVar, some_state_vars(Vars0, Goal0),
some_state_vars(Vars, Goal)) :-
- prog_util__rename_in_vars(Vars0, OldVar, NewVar, Vars),
- prog_util__rename_in_goal(Goal0, OldVar, NewVar, Goal).
-prog_util__rename_in_goal_expr(all(Vars0, Goal0), OldVar, NewVar,
+ prog_util__rename_in_vars(OldVar, NewVar, Vars0, Vars),
+ prog_util__rename_in_goal(OldVar, NewVar, Goal0, Goal).
+prog_util__rename_in_goal_expr(OldVar, NewVar, all(Vars0, Goal0),
all(Vars, Goal)) :-
- prog_util__rename_in_vars(Vars0, OldVar, NewVar, Vars),
- prog_util__rename_in_goal(Goal0, OldVar, NewVar, Goal).
-prog_util__rename_in_goal_expr(all_state_vars(Vars0, Goal0), OldVar, NewVar,
+ prog_util__rename_in_vars(OldVar, NewVar, Vars0, Vars),
+ prog_util__rename_in_goal(OldVar, NewVar, Goal0, Goal).
+prog_util__rename_in_goal_expr(OldVar, NewVar, all_state_vars(Vars0, Goal0),
all_state_vars(Vars, Goal)) :-
- prog_util__rename_in_vars(Vars0, OldVar, NewVar, Vars),
- prog_util__rename_in_goal(Goal0, OldVar, NewVar, Goal).
-prog_util__rename_in_goal_expr(implies(GoalA0, GoalB0), OldVar, NewVar,
+ prog_util__rename_in_vars(OldVar, NewVar, Vars0, Vars),
+ prog_util__rename_in_goal(OldVar, NewVar, Goal0, Goal).
+prog_util__rename_in_goal_expr(OldVar, NewVar, implies(GoalA0, GoalB0),
implies(GoalA, GoalB)) :-
- prog_util__rename_in_goal(GoalA0, OldVar, NewVar, GoalA),
- prog_util__rename_in_goal(GoalB0, OldVar, NewVar, GoalB).
-prog_util__rename_in_goal_expr(equivalent(GoalA0, GoalB0), OldVar, NewVar,
+ prog_util__rename_in_goal(OldVar, NewVar, GoalA0, GoalA),
+ prog_util__rename_in_goal(OldVar, NewVar, GoalB0, GoalB).
+prog_util__rename_in_goal_expr(OldVar, NewVar, equivalent(GoalA0, GoalB0),
equivalent(GoalA, GoalB)) :-
- prog_util__rename_in_goal(GoalA0, OldVar, NewVar, GoalA),
- prog_util__rename_in_goal(GoalB0, OldVar, NewVar, GoalB).
-prog_util__rename_in_goal_expr(if_then(Vars0, StateVars0, Cond0, Then0),
- OldVar, NewVar,
+ prog_util__rename_in_goal(OldVar, NewVar, GoalA0, GoalA),
+ prog_util__rename_in_goal(OldVar, NewVar, GoalB0, GoalB).
+prog_util__rename_in_goal_expr(OldVar, NewVar,
+ if_then(Vars0, StateVars0, Cond0, Then0),
if_then(Vars, StateVars, Cond, Then)) :-
- prog_util__rename_in_vars(Vars0, OldVar, NewVar, Vars),
- prog_util__rename_in_vars(StateVars0, OldVar, NewVar, StateVars),
- prog_util__rename_in_goal(Cond0, OldVar, NewVar, Cond),
- prog_util__rename_in_goal(Then0, OldVar, NewVar, Then).
-prog_util__rename_in_goal_expr(
+ prog_util__rename_in_vars(OldVar, NewVar, Vars0, Vars),
+ prog_util__rename_in_vars(OldVar, NewVar, StateVars0, StateVars),
+ prog_util__rename_in_goal(OldVar, NewVar, Cond0, Cond),
+ prog_util__rename_in_goal(OldVar, NewVar, Then0, Then).
+prog_util__rename_in_goal_expr(OldVar, NewVar,
if_then_else(Vars0, StateVars0, Cond0, Then0, Else0),
- OldVar, NewVar,
if_then_else(Vars, StateVars, Cond, Then, Else)) :-
- prog_util__rename_in_vars(Vars0, OldVar, NewVar, Vars),
- prog_util__rename_in_vars(StateVars0, OldVar, NewVar, StateVars),
- prog_util__rename_in_goal(Cond0, OldVar, NewVar, Cond),
- prog_util__rename_in_goal(Then0, OldVar, NewVar, Then),
- prog_util__rename_in_goal(Else0, OldVar, NewVar, Else).
-prog_util__rename_in_goal_expr(call(SymName, Terms0, Purity), OldVar, NewVar,
+ prog_util__rename_in_vars(OldVar, NewVar, Vars0, Vars),
+ prog_util__rename_in_vars(OldVar, NewVar, StateVars0, StateVars),
+ prog_util__rename_in_goal(OldVar, NewVar, Cond0, Cond),
+ prog_util__rename_in_goal(OldVar, NewVar, Then0, Then),
+ prog_util__rename_in_goal(OldVar, NewVar, Else0, Else).
+prog_util__rename_in_goal_expr(OldVar, NewVar, call(SymName, Terms0, Purity),
call(SymName, Terms, Purity)) :-
- term__substitute_list(Terms0, OldVar, term__variable(NewVar),
- Terms).
-prog_util__rename_in_goal_expr(unify(TermA0, TermB0, Purity), OldVar, NewVar,
+ term__substitute_list(Terms0, OldVar, term__variable(NewVar), Terms).
+prog_util__rename_in_goal_expr(OldVar, NewVar, unify(TermA0, TermB0, Purity),
unify(TermA, TermB, Purity)) :-
- term__substitute(TermA0, OldVar, term__variable(NewVar),
- TermA),
- term__substitute(TermB0, OldVar, term__variable(NewVar),
- TermB).
-
-:- pred prog_util__rename_in_vars(list(prog_var), prog_var, prog_var,
- list(prog_var)).
-:- mode prog_util__rename_in_vars(in, in, in, out) is det.
+ term__substitute(TermA0, OldVar, term__variable(NewVar), TermA),
+ term__substitute(TermB0, OldVar, term__variable(NewVar), TermB).
+
+:- pred prog_util__rename_in_vars(prog_var::in, prog_var::in,
+ list(prog_var)::in, list(prog_var)::out) is det.
-prog_util__rename_in_vars([], _, _, []).
-prog_util__rename_in_vars([Var0 | Vars0], OldVar, NewVar, [Var | Vars]) :-
+prog_util__rename_in_vars(_, _, [], []).
+prog_util__rename_in_vars(OldVar, NewVar, [Var0 | Vars0], [Var | Vars]) :-
( Var0 = OldVar ->
Var = NewVar
;
Var = Var0
),
- prog_util__rename_in_vars(Vars0, OldVar, NewVar, Vars).
+ prog_util__rename_in_vars(OldVar, NewVar, Vars0, Vars).
%-----------------------------------------------------------------------------%
@@ -520,15 +502,15 @@
[s(Prefix), s(PFS), s(PredName), s(PredIdStr)], Name),
SymName = qualified(ModuleName, Name).
-:- pred list_to_string(pred(T, string), list(T), string).
-:- mode list_to_string(pred(in, out) is det, in, out) is det.
+:- pred list_to_string(pred(T, string)::in(pred(in, out) is det),
+ list(T)::in, string::out) is det.
list_to_string(Pred, List, String) :-
list_to_string_2(Pred, List, Strings, ["]"]),
string__append_list(["[" | Strings], String).
-:- pred list_to_string_2(pred(T, string), list(T), list(string), list(string)).
-:- mode list_to_string_2(pred(in, out) is det, in, out, in) is det.
+:- pred list_to_string_2(pred(T, string)::in(pred(in, out) is det),
+ list(T)::in, list(string)::out, list(string)::in) is det.
list_to_string_2(_, []) --> [].
list_to_string_2(Pred, [T | Ts]) -->
cvs diff: Diffing notes
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list