[m-rev.] [reuse] diff: move alias-printing/parsing to prog_io_pasr
Nancy Mazur
Nancy.Mazur at cs.kuleuven.ac.be
Fri Jun 25 17:16:45 AEST 2004
Hi,
===================================================================
Estimated hours taken: 0.5
Branches: reuse
pa_alias.m:
pa_alias_as.m:
pa_alias_set.m:
prog_io_pasr.m:
Move printing/parsing routines for alias-types to prog_io_pasr.
Index: pa_alias.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_alias.m,v
retrieving revision 1.1.2.20
diff -u -r1.1.2.20 pa_alias.m
--- pa_alias.m 25 Jun 2004 06:23:25 -0000 1.1.2.20
+++ pa_alias.m 25 Jun 2004 07:08:13 -0000
@@ -20,7 +20,6 @@
:- import_module structure_reuse__sr_live. % XXX should be removed, eventually.
:- import_module set, list.
-:- import_module io, string, term.
%-------------------------------------------------------------------%
%-- exported types
@@ -40,13 +39,6 @@
hlds_goal__unification::in, hlds_goal__hlds_goal_info::in,
list(alias)::out) is det.
- % printing routines
-:- pred print(proc_info::in, pred_info::in, string::in, string::in,
- alias::in, io__state::di, io__state::uo) is det.
-
- % parsing routines
-:- pred parse_term(term(T)::in , alias::out) is det.
-
:- pred live_from_in_use(set(prog_var)::in, list(alias)::in,
live_set::out) is det.
@@ -66,64 +58,11 @@
:- import_module possible_alias__pa_selector.
:- import_module possible_alias__pa_sr_util.
-:- import_module varset, require, int, map, std_util.
-
-%-------------------------------------------------------------------%
-% printing routines
-%-------------------------------------------------------------------%
-
-print(ProcInfo, PredInfo, FrontString, EndString, Alias0, !IO) :-
- proc_info_varset(ProcInfo, ProgVarSet),
- pred_info_typevarset(PredInfo, TypeVarSet),
- Alias0 = D1 - D2,
- io__write_string(FrontString, !IO),
- io__write_string("pair(", !IO),
- print_datastruct(ProgVarSet, TypeVarSet, D1, !IO),
- io__write_string(" , ", !IO),
- print_datastruct(ProgVarSet, TypeVarSet, D2, !IO),
- io__write_string(") ", !IO),
- io__write_string(EndString, !IO).
+:- import_module varset, require, int, map, std_util, string.
%-------------------------------------------------------------------%
% parsing routines
%-------------------------------------------------------------------%
-
-pa_alias__parse_term(Term, A) :-
- (
- Term = term__functor(term__atom(Cons), Args, _)
- ->
- (
- Cons = "pair"
- ->
- (
- Args = [ First, Second ]
- ->
- parse_datastruct(First, D1),
- parse_datastruct(Second, D2),
- A = D1 - D2
- ;
- list__length(Args, L),
- string__int_to_string(L,LS),
- string__append_list(
- [ "(pa_alias) parse_term: ",
- "wrong number of arguments. `-'/",
- LS," should be `-'/2"],Msg),
- error(Msg)
- )
- ;
- term__det_term_to_type(Term, Type),
- varset__init(V),
- StringTerm = mercury_type_to_string(V, Type),
- string__append_list([
- "(pa_alias) parse_term: ",
- "wrong constructor. `",
- StringTerm,
- "' should be `pair'"],Msg),
- error(Msg)
- )
- ;
- error("(pa_alias) parse_term: term is not a functor")
- ).
% contains_one_of_vars(SET, ALIAS, DATA)
% returns true if ALIAS = DATA1 - DATA,
Index: pa_alias_as.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_alias_as.m,v
retrieving revision 1.1.2.38
diff -u -r1.1.2.38 pa_alias_as.m
--- pa_alias_as.m 25 Jun 2004 06:23:25 -0000 1.1.2.38
+++ pa_alias_as.m 25 Jun 2004 07:08:20 -0000
@@ -1092,7 +1092,7 @@
CONS = "[|]",
Args = [ AliasTerm, Rest]
->
- pa_alias__parse_term(AliasTerm, Alias),
+ prog_io_pasr__parse_alias(AliasTerm, Alias),
parse_list_alias_term(Rest, RestAliases),
Aliases = [ Alias | RestAliases ]
;
Index: pa_alias_set.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_alias_set.m,v
retrieving revision 1.1.2.14
diff -u -r1.1.2.14 pa_alias_set.m
--- pa_alias_set.m 25 Jun 2004 02:33:50 -0000 1.1.2.14
+++ pa_alias_set.m 25 Jun 2004 07:08:26 -0000
@@ -142,6 +142,7 @@
:- import_module possible_alias__pa_alias.
:- import_module possible_alias__pa_selector.
:- import_module possible_alias__pa_datastruct.
+:- import_module parse_tree__prog_io_pasr.
:- import_module std_util.
:- import_module int, bool, assoc_list.
@@ -685,6 +686,8 @@
print_brief(MaybeThreshold, PredInfo, ProcInfo, AliasList,
StartingString, MiddleString, EndString) -->
+ { proc_info_varset(ProcInfo, ProgVarSet) },
+ { pred_info_typevarset(PredInfo, TypeVarSet) },
% { to_pair_alias_list(AliasSet, AliasList) },
(
{ MaybeThreshold = yes(Limit) }
@@ -694,7 +697,7 @@
{ NewList = AliasList }
),
io__write_list(NewList, MiddleString,
- pa_alias__print(ProcInfo, PredInfo, StartingString,
+ print_alias(ProgVarSet, TypeVarSet, StartingString,
EndString)),
(
{ MaybeThreshold = yes(_) }
Index: prog_io_pasr.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/prog_io_pasr.m,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 prog_io_pasr.m
--- prog_io_pasr.m 25 Jun 2004 06:23:26 -0000 1.1.2.1
+++ prog_io_pasr.m 25 Jun 2004 07:08:28 -0000
@@ -20,13 +20,18 @@
% Printing routines.
%-----------------------------------------------------------------------------%
%
-% 1. selectors.
+% 1. selector.
:- pred print_selector(tvarset::in, selector::in, io__state::di,
io__state::uo) is det.
-% 2. datastructs.
+% 2. datastruct.
:- pred print_datastruct(prog_varset::in, tvarset::in, datastruct::in,
io__state::di, io__state::uo) is det.
+
+% 3. alias.
+:- pred print_alias(prog_varset::in, tvarset::in, string::in, string::in,
+ alias::in, io__state::di, io__state::uo) is det.
+
%-----------------------------------------------------------------------------%
% Transform to string routines.
@@ -49,10 +54,13 @@
% Parsing routines.
%-----------------------------------------------------------------------------%
-% 1. selectors.
+% 1. selector.
:- pred parse_selector(term(T)::in, selector::out) is det.
-% 2. datastructs.
+% 2. datastruct.
:- pred parse_datastruct(term(T)::in, datastruct::out) is det.
+% 3. alias.
+:- pred parse_alias(term(T)::in , alias::out) is det.
+
%-----------------------------------------------------------------------------%
@@ -63,7 +71,7 @@
:- import_module parse_tree__mercury_to_mercury.
:- import_module parse_tree__prog_io.
-:- import_module string, list, require, bool, varset.
+:- import_module string, list, require, bool, varset, std_util.
%-----------------------------------------------------------------------------%
print_selector(TVarSet, Selector, !IO) :-
@@ -76,6 +84,15 @@
print_selector(TypeVarSet, DataStruct^sc_selector, !IO),
io__write_string(")", !IO).
+print_alias(ProgVarSet, TypeVarSet, FrontString, EndString, Alias0, !IO) :-
+ Alias0 = D1 - D2,
+ io__write_string(FrontString, !IO),
+ io__write_string("pair(", !IO),
+ print_datastruct(ProgVarSet, TypeVarSet, D1, !IO),
+ io__write_string(" , ", !IO),
+ print_datastruct(ProgVarSet, TypeVarSet, D2, !IO),
+ io__write_string(") ", !IO),
+ io__write_string(EndString, !IO).
%-----------------------------------------------------------------------------%
to_user_declared_selector(TVarSet, Selector, String):-
(
@@ -127,7 +144,7 @@
String = mercury_type_to_string(TVarSet, Type).
%-----------------------------------------------------------------------------%
-% 2. datastructs.
+% 2. datastruct.
to_user_declared_datastruct(ProgVarSet, TypeVarSet, Data, String):-
Data = selected_cel(ProgVar, Selector),
varset__lookup_name(ProgVarSet, ProgVar, ProgName),
@@ -141,7 +158,7 @@
% Parsing routines.
%-----------------------------------------------------------------------------%
%
-% 1. selectors.
+% 1. selector.
parse_selector(Term, Sel):-
(
Term = term__functor(term__atom(Cons), Args, _)
@@ -211,7 +228,7 @@
).
%-----------------------------------------------------------------------------%
-% 2. datastructs.
+% 2. datastruct.
parse_datastruct(TERM, Data) :-
(
TERM = term__functor(term__atom(CONS), Args, _)
@@ -246,4 +263,43 @@
;
error("(prog_io_pasr) parse_datastruct: term not a functor")
).
+
+%-----------------------------------------------------------------------------%
+% 3. alias
+parse_alias(Term, A) :-
+ (
+ Term = term__functor(term__atom(Cons), Args, _)
+ ->
+ (
+ Cons = "pair"
+ ->
+ (
+ Args = [ First, Second ]
+ ->
+ parse_datastruct(First, D1),
+ parse_datastruct(Second, D2),
+ A = D1 - D2
+ ;
+ list__length(Args, L),
+ string__int_to_string(L,LS),
+ string__append_list(
+ [ "(prog_io_pasr) parse_alias: ",
+ "wrong number of arguments. `-'/",
+ LS," should be `-'/2"],Msg),
+ error(Msg)
+ )
+ ;
+ term__det_term_to_type(Term, Type),
+ varset__init(V),
+ StringTerm = mercury_type_to_string(V, Type),
+ string__append_list([
+ "(prog_io_pasr) parse_alias: ",
+ "wrong constructor. `",
+ StringTerm,
+ "' should be `pair'"],Msg),
+ error(Msg)
+ )
+ ;
+ error("(prog_io_pasr) parse_alias: term is not a functor")
+ ).
--
nancy.mazur at cs.kuleuven.ac.be ------------ Katholieke Universiteit Leuven -
tel: +32-16-327596 - fax: +32-16-327996 ------- Dept. of Computer Science -
--------------------------------------------------------------------------
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