[m-rev.] diff: cleanup prog_io.m
Julien Fischer
juliensf at cs.mu.OZ.AU
Fri Jul 16 02:27:10 AEST 2004
Estimated hours taken: 1.5
Branches: main
Bring prog_io.m more into line with our current coding
standards.
compiler/prog_io.m:
Use predmode syntax throughout.
Use state variables, reordering arguments where
necessary to facilitate this.
Remove a duplicate module import.
Replace calls to require.error/1 with calls to
unexpected.
Fix some indentation and layout problems, wrap
lines that are longer > 79 chars.
Julien.
Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.227
diff -u -r1.227 prog_io.m
--- compiler/prog_io.m 30 Jun 2004 02:48:08 -0000 1.227
+++ compiler/prog_io.m 15 Jul 2004 15:28:54 -0000
@@ -264,7 +264,7 @@
:- import_module libs__globals.
:- import_module libs__options.
-:- import_module parse_tree__modules.
+:- import_module parse_tree__error_util.
:- import_module parse_tree__modules.
:- import_module parse_tree__prog_io_dcg.
:- import_module parse_tree__prog_io_goal.
@@ -283,39 +283,41 @@
prog_io__read_module(OpenFile, DefaultModuleName,
ReturnTimestamp, Error, FileData, ModuleName,
- Messages, Items, MaybeModuleTimestamp) -->
+ Messages, Items, MaybeModuleTimestamp, !IO) :-
prog_io__read_module_2(OpenFile, DefaultModuleName,
no, ReturnTimestamp, Error, FileData, ModuleName,
- Messages, Items, MaybeModuleTimestamp).
+ Messages, Items, MaybeModuleTimestamp, !IO).
prog_io__read_module_if_changed(OpenFile, DefaultModuleName,
OldTimestamp, Error, FileData, ModuleName, Messages,
- Items, MaybeModuleTimestamp) -->
+ Items, MaybeModuleTimestamp, !IO) :-
prog_io__read_module_2(OpenFile, DefaultModuleName,
yes(OldTimestamp), yes, Error, FileData,
- ModuleName, Messages, Items, MaybeModuleTimestamp).
+ ModuleName, Messages, Items, MaybeModuleTimestamp, !IO).
-prog_io__read_opt_file(FileName, DefaultModuleName, Error, Messages, Items) -->
- globals__io_lookup_accumulating_option(intermod_directories, Dirs),
+prog_io__read_opt_file(FileName, DefaultModuleName, Error, Messages, Items,
+ !IO) :-
+ globals__io_lookup_accumulating_option(intermod_directories, Dirs,
+ !IO),
prog_io__read_module_2(search_for_file(Dirs, FileName),
DefaultModuleName, no, no, Error, _, ModuleName,
- Messages, Items, _),
+ Messages, Items, _, !IO),
check_module_has_expected_name(FileName,
- DefaultModuleName, ModuleName).
+ DefaultModuleName, ModuleName, !IO).
-check_module_has_expected_name(FileName, ExpectedName, ActualName) -->
- ( { ActualName \= ExpectedName } ->
- { prog_out__sym_name_to_string(ActualName, ActualString) },
- { prog_out__sym_name_to_string(ExpectedName, ExpectedString) },
+check_module_has_expected_name(FileName, ExpectedName, ActualName, !IO) :-
+ ( ActualName \= ExpectedName ->
+ prog_out__sym_name_to_string(ActualName, ActualString),
+ prog_out__sym_name_to_string(ExpectedName, ExpectedString),
io__write_strings([
"Error: file `", FileName,
"' contains the wrong module.\n",
"Expected module `", ExpectedString,
"', found module `", ActualString, "'.\n"
- ]),
- io__set_exit_status(1)
+ ], !IO),
+ io__set_exit_status(1, !IO)
;
- []
+ true
).
@@ -327,40 +329,38 @@
% and then reverse them afterwards. (Using difference lists would require
% late-input modes.)
-:- pred prog_io__read_module_2(open_file(T), module_name,
- maybe(timestamp), bool, module_error, maybe(T), module_name,
- message_list, item_list, maybe(io__res(timestamp)),
- io__state, io__state).
-:- mode prog_io__read_module_2(in(open_file), in, in, in,
- out, out, out, out, out, out, di, uo) is det.
+:- pred prog_io__read_module_2(open_file(T)::in(open_file),
+ module_name::in, maybe(timestamp)::in, bool::in, module_error::out,
+ maybe(T)::out, module_name::out, message_list::out, item_list::out,
+ maybe(io__res(timestamp))::out, io::di, io::uo) is det.
prog_io__read_module_2(OpenFile, DefaultModuleName,
MaybeOldTimestamp, ReturnTimestamp, Error,
MaybeFileData, ModuleName, Messages, Items,
- MaybeModuleTimestamp) -->
- io__input_stream(OldInputStream),
- OpenFile(OpenResult),
- (
- { OpenResult = ok(FileData) },
- { MaybeFileData = yes(FileData) },
- ( { ReturnTimestamp = yes } ->
- io__input_stream_name(InputStreamName),
+ MaybeModuleTimestamp, !IO) :-
+ io__input_stream(OldInputStream, !IO),
+ OpenFile(OpenResult, !IO),
+ (
+ OpenResult = ok(FileData),
+ MaybeFileData = yes(FileData),
+ ( ReturnTimestamp = yes ->
+ io__input_stream_name(InputStreamName, !IO),
io__file_modification_time(InputStreamName,
- TimestampResult),
+ TimestampResult, !IO),
(
- { TimestampResult = ok(Timestamp) },
- { MaybeModuleTimestamp = yes(
- ok(time_t_to_timestamp(Timestamp))) }
+ TimestampResult = ok(Timestamp),
+ MaybeModuleTimestamp = yes(
+ ok(time_t_to_timestamp(Timestamp)))
;
- { TimestampResult = error(IOError) },
- { MaybeModuleTimestamp = yes(error(IOError)) }
+ TimestampResult = error(IOError),
+ MaybeModuleTimestamp = yes(error(IOError))
)
;
- { MaybeModuleTimestamp = no }
+ MaybeModuleTimestamp = no
),
(
- { MaybeOldTimestamp = yes(OldTimestamp) },
- { MaybeModuleTimestamp = yes(ok(OldTimestamp)) }
+ MaybeOldTimestamp = yes(OldTimestamp),
+ MaybeModuleTimestamp = yes(ok(OldTimestamp))
->
%
% XXX Currently smart recompilation won't work
@@ -369,34 +369,32 @@
% be disabled and prog_io__read_module should
% never be passed an old timestamp.
%
- { ModuleName = DefaultModuleName },
- { Items = [] },
- { Error = no_module_errors },
- { Messages = [] }
+ ModuleName = DefaultModuleName,
+ Items = [],
+ Error = no_module_errors,
+ Messages = []
;
read_all_items(DefaultModuleName, ModuleName,
- Messages, Items, Error)
+ Messages, Items, Error, !IO)
),
- io__set_input_stream(OldInputStream, ModuleInputStream),
- io__close_input(ModuleInputStream)
+ io__set_input_stream(OldInputStream, ModuleInputStream, !IO),
+ io__close_input(ModuleInputStream, !IO)
;
- { OpenResult = error(Message0) },
- io__progname_base("mercury_compile", Progname),
- {
- Message = Progname ++ ": " ++ Message0,
- dummy_term(Term),
- Messages = [Message - Term],
- Error = fatal_module_errors,
- Items = [],
- ModuleName = DefaultModuleName,
- MaybeFileData = no,
- MaybeModuleTimestamp = no
- }
- ).
-
-search_for_file(Dirs, FileName, Result) -->
- search_for_file_returning_dir(Dirs, FileName, Result0),
- {
+ OpenResult = error(Message0),
+ io__progname_base("mercury_compile", Progname, !IO),
+ Message = Progname ++ ": " ++ Message0,
+ dummy_term(Term),
+ Messages = [Message - Term],
+ Error = fatal_module_errors,
+ Items = [],
+ ModuleName = DefaultModuleName,
+ MaybeFileData = no,
+ MaybeModuleTimestamp = no
+ ).
+
+search_for_file(Dirs, FileName, Result, !IO) :-
+ search_for_file_returning_dir(Dirs, FileName, Result0, !IO),
+ (
Result0 = ok(Dir),
( dir__this_directory(Dir) ->
PathName = FileName
@@ -407,55 +405,56 @@
;
Result0 = error(Message),
Result = error(Message)
- }.
+ ).
-search_for_file_returning_dir(Dirs, FileName, R) -->
- search_for_file_returning_dir(Dirs, Dirs, FileName, R).
+search_for_file_returning_dir(Dirs, FileName, R, !IO) :-
+ search_for_file_returning_dir(Dirs, Dirs, FileName, R, !IO).
:- pred search_for_file_returning_dir(list(dir_name)::in, list(dir_name)::in,
file_name::in, maybe_error(dir_name)::out, io::di, io::uo) is det.
-search_for_file_returning_dir([], AllDirs, FileName, error(Msg)) -->
- { Msg = append_list(["cannot find `", FileName, "' in directories ",
- string__join_list(", ", AllDirs)]) }.
-search_for_file_returning_dir([Dir | Dirs], AllDirs, FileName, R) -->
- { dir__this_directory(Dir) ->
+search_for_file_returning_dir([], AllDirs, FileName, error(Msg), !IO) :-
+ Msg = append_list(["cannot find `", FileName, "' in directories ",
+ string__join_list(", ", AllDirs)]).
+search_for_file_returning_dir([Dir | Dirs], AllDirs, FileName, R, !IO) :-
+ ( dir__this_directory(Dir) ->
ThisFileName = FileName
;
ThisFileName = dir__make_path_name(Dir, FileName)
- },
- io__see(ThisFileName, R0),
- ( { R0 = ok } ->
- { R = ok(Dir) }
+ ),
+ io__see(ThisFileName, R0, !IO),
+ ( R0 = ok ->
+ R = ok(Dir)
;
- search_for_file_returning_dir(Dirs, AllDirs, FileName, R)
+ search_for_file_returning_dir(Dirs, AllDirs, FileName, R, !IO)
).
-search_for_module_source(Dirs, ModuleName, MaybeFileName) -->
- search_for_module_source(Dirs, ModuleName, ModuleName, MaybeFileName).
+search_for_module_source(Dirs, ModuleName, MaybeFileName, !IO) :-
+ search_for_module_source(Dirs, ModuleName, ModuleName, MaybeFileName,
+ !IO).
:- pred search_for_module_source(list(dir_name)::in,
module_name::in, module_name::in, maybe_error(file_name)::out,
io::di, io::uo) is det.
-search_for_module_source(Dirs, ModuleName, PartialModuleName, Result) -->
- module_name_to_file_name(PartialModuleName, ".m", no, FileName),
- search_for_file(Dirs, FileName, Result0),
+search_for_module_source(Dirs, ModuleName, PartialModuleName, Result, !IO) :-
+ module_name_to_file_name(PartialModuleName, ".m", no, FileName, !IO),
+ search_for_file(Dirs, FileName, Result0, !IO),
(
- { Result0 = ok(_) },
- { Result = Result0 }
+ Result0 = ok(_),
+ Result = Result0
;
- { Result0 = error(_) },
+ Result0 = error(_),
(
- { PartialModuleName1 =
- drop_one_qualifier(PartialModuleName) }
+ PartialModuleName1 =
+ drop_one_qualifier(PartialModuleName)
->
search_for_module_source(Dirs, ModuleName,
- PartialModuleName1, Result)
+ PartialModuleName1, Result, !IO)
;
- { sym_name_to_string(ModuleName, ModuleNameStr) },
- { Result = error("can't find source for module `" ++
- ModuleNameStr ++ "'") }
+ sym_name_to_string(ModuleName, ModuleNameStr),
+ Result = error("can't find source for module `" ++
+ ModuleNameStr ++ "'")
)
).
@@ -544,7 +543,8 @@
;
% if there's no `:- module' declaration at this point, it is
% an internal error -- read_first_item should have inserted one
- error("check_end_module: no `:- module' declaration")
+ unexpected(this_file,
+ "check_end_module: no `:- module' declaration")
).
%-----------------------------------------------------------------------------%
@@ -570,38 +570,38 @@
%-----------------------------------------------------------------------------%
-find_module_name(FileName, MaybeModuleName) -->
- io__open_input(FileName, OpenRes),
+find_module_name(FileName, MaybeModuleName, !IO) :-
+ io__open_input(FileName, OpenRes, !IO),
(
- { OpenRes = ok(InputStream) },
- io__set_input_stream(InputStream, OldInputStream),
- { string__remove_suffix(FileName, ".m", PartialFileName0) ->
+ OpenRes = ok(InputStream),
+ io__set_input_stream(InputStream, OldInputStream, !IO),
+ ( string__remove_suffix(FileName, ".m", PartialFileName0) ->
PartialFileName = PartialFileName0
;
PartialFileName = FileName
- },
- { dir__basename(PartialFileName, BaseName0) ->
+ ),
+ ( dir__basename(PartialFileName, BaseName0) ->
BaseName = BaseName0
;
BaseName = ""
- },
- { file_name_to_module_name(BaseName, DefaultModuleName) },
+ ),
+ file_name_to_module_name(BaseName, DefaultModuleName),
read_first_item(DefaultModuleName, FileName,
- ModuleName, RevMessages, _, _, _),
- { MaybeModuleName = yes(ModuleName) },
- prog_out__write_messages(list__reverse(RevMessages)),
- io__set_input_stream(OldInputStream, _),
- io__close_input(InputStream)
- ;
- { OpenRes = error(Error) },
- io__progname_base("mercury_compile", Progname),
- io__write_string(Progname),
- io__write_string(": error opening `"),
- io__write_string(FileName),
- io__write_string("': "),
- io__write_string(io__error_message(Error)),
- io__write_string(".\n"),
- { MaybeModuleName = no }
+ ModuleName, RevMessages, _, _, _, !IO),
+ MaybeModuleName = yes(ModuleName),
+ prog_out__write_messages(list__reverse(RevMessages), !IO),
+ io__set_input_stream(OldInputStream, _, !IO),
+ io__close_input(InputStream, !IO)
+ ;
+ OpenRes = error(Error),
+ io__progname_base("mercury_compile", Progname, !IO),
+ io__write_string(Progname, !IO),
+ io__write_string(": error opening `", !IO),
+ io__write_string(FileName, !IO),
+ io__write_string("': ", !IO),
+ io__write_string(io__error_message(Error), !IO),
+ io__write_string(".\n", !IO),
+ MaybeModuleName = no
).
% Read a source file from standard in, first reading in
@@ -619,7 +619,7 @@
:- pred read_all_items(module_name::in, module_name::out,
message_list::out, item_list::out, module_error::out,
- io__state::di, io__state::uo) is det.
+ io::di, io::uo) is det.
read_all_items(DefaultModuleName, ModuleName, Messages, Items, Error, !IO) :-
%
@@ -670,7 +670,7 @@
%
:- pred read_first_item(module_name::in, file_name::in, module_name::out,
message_list::out, item_list::out, maybe(read_term)::out,
- module_error::out, io__state::di, io__state::uo) is det.
+ module_error::out, io::di, io::uo) is det.
read_first_item(DefaultModuleName, SourceFileName, ModuleName,
Messages, Items, MaybeSecondTerm, Error, !IO) :-
@@ -773,17 +773,16 @@
Error = no_module_errors
).
-:- pred make_module_decl(module_name, term__context, item_and_context).
-:- mode make_module_decl(in, in, out) is det.
+:- pred make_module_decl(module_name::in, term__context::in,
+ item_and_context::out) is det.
make_module_decl(ModuleName, Context, Item - Context) :-
varset__init(EmptyVarSet),
ModuleDefn = module(ModuleName),
Item = module_defn(EmptyVarSet, ModuleDefn).
-:- pred maybe_add_warning(bool, read_term, term__context, string,
- message_list, message_list).
-:- mode maybe_add_warning(in, in, in, in, in, out) is det.
+:- pred maybe_add_warning(bool::in, read_term::in, term__context::in,
+ string::in, message_list::in, message_list::out) is det.
maybe_add_warning(DoWarn, MaybeTerm, Context, Warning, Messages0, Messages) :-
( DoWarn = yes ->
@@ -807,7 +806,7 @@
:- pred read_items_loop(module_name::in, file_name::in,
message_list::in, message_list::out, item_list::in, item_list::out,
- module_error::in,module_error::out, io__state::di, io__state::uo)
+ module_error::in,module_error::out, io::di, io::uo)
is det.
read_items_loop(ModuleName, SourceFileName, !Msgs, !Items, !Error, !IO) :-
@@ -820,7 +819,7 @@
:- pred read_items_loop_2(maybe_item_or_eof::in, module_name::in,
file_name::in, message_list::in, message_list::out,
item_list::in, item_list::out, module_error::in, module_error::out,
- io__state::di, io__state::uo) is det.
+ io::di, io::uo) is det.
% do a switch on the type of the next item
@@ -909,32 +908,32 @@
% read_item/1 reads a single item, and if it is a valid term
% parses it.
-:- type maybe_item_or_eof ---> eof
- ; syntax_error(file_name, int)
- ; error(string, term)
- ; ok(item, term__context).
-
-:- pred read_item(module_name, file_name, maybe_item_or_eof,
- io__state, io__state).
-:- mode read_item(in, in, out, di, uo) is det.
-
-read_item(ModuleName, SourceFileName, MaybeItem) -->
- parser__read_term(SourceFileName, MaybeTerm),
- { process_read_term(ModuleName, MaybeTerm, MaybeItem) }.
+:- type maybe_item_or_eof
+ ---> eof
+ ; syntax_error(file_name, int)
+ ; error(string, term)
+ ; ok(item, term__context).
+
+:- pred read_item(module_name::in, file_name::in, maybe_item_or_eof::out,
+ io::di, io::uo) is det.
-:- pred process_read_term(module_name, read_term, maybe_item_or_eof).
-:- mode process_read_term(in, in, out) is det.
+read_item(ModuleName, SourceFileName, MaybeItem, !IO) :-
+ parser__read_term(SourceFileName, MaybeTerm, !IO),
+ process_read_term(ModuleName, MaybeTerm, MaybeItem).
+
+:- pred process_read_term(module_name::in, read_term::in,
+ maybe_item_or_eof::out) is det.
process_read_term(_ModuleName, eof, eof).
process_read_term(_ModuleName, error(ErrorMsg, LineNumber),
- syntax_error(ErrorMsg, LineNumber)).
+ syntax_error(ErrorMsg, LineNumber)).
process_read_term(ModuleName, term(VarSet, Term),
- MaybeItemOrEof) :-
+ MaybeItemOrEof) :-
parse_item(ModuleName, VarSet, Term, MaybeItem),
convert_item(MaybeItem, MaybeItemOrEof).
-:- pred convert_item(maybe_item_and_context, maybe_item_or_eof).
-:- mode convert_item(in, out) is det.
+:- pred convert_item(maybe_item_and_context::in, maybe_item_or_eof::out)
+ is det.
convert_item(ok(Item, Context), ok(Item, Context)).
convert_item(error(M, T), error(M, T)).
@@ -996,8 +995,8 @@
add_context(R3, TheContext, Result)
).
-:- pred process_pred_clause(maybe_functor, prog_varset, goal, maybe1(item)).
-:- mode process_pred_clause(in, in, in, out) is det.
+:- pred process_pred_clause(maybe_functor::in, prog_varset::in, goal::in,
+ maybe1(item)::out) is det.
process_pred_clause(ok(Name, Args0), VarSet, Body,
ok(clause(VarSet, predicate, Name, Args, Body))) :-
@@ -1005,9 +1004,8 @@
process_pred_clause(error(ErrMessage, Term0), _, _, error(ErrMessage, Term)) :-
term__coerce(Term0, Term).
-:- pred process_func_clause(maybe_functor, term, prog_varset, goal,
- maybe1(item)).
-:- mode process_func_clause(in, in, in, in, out) is det.
+:- pred process_func_clause(maybe_functor::in, term::in, prog_varset::in,
+ goal::in, maybe1(item)::out) is det.
process_func_clause(ok(Name, Args0), Result0, VarSet, Body,
ok(clause(VarSet, function, Name, Args, Body))) :-
@@ -1046,9 +1044,9 @@
% representation of that declaration. Attributes is a list
% of enclosing declaration attributes, in the order innermost to
% outermost.
-:- pred parse_decl_2(module_name, varset, term, decl_attrs,
- maybe_item_and_context).
-:- mode parse_decl_2(in, in, in, in, out) is det.
+ %
+:- pred parse_decl_2(module_name::in, varset::in, term::in, decl_attrs::in,
+ maybe_item_and_context::out) is det.
parse_decl_2(ModuleName, VarSet, F, Attributes, Result) :-
(
@@ -1077,9 +1075,9 @@
% representation of that declaration. Attributes is a list
% of enclosing declaration attributes, in the order outermost to
% innermost.
-:- pred process_decl(module_name, varset, string, list(term), decl_attrs,
- maybe1(item)).
-:- mode process_decl(in, in, in, in, in, out) is semidet.
+ %
+:- pred process_decl(module_name::in, varset::in, string::in, list(term)::in,
+ decl_attrs::in, maybe1(item)::out) is semidet.
process_decl(ModuleName, VarSet, "type", [TypeDecl], Attributes, Result) :-
parse_type_decl(ModuleName, VarSet, TypeDecl, Attributes, Result).
@@ -1361,8 +1359,8 @@
;
( VersionNumberTerm = term__functor(_, _, Context) ->
- Msg =
-"interface file needs to be recreated, the version numbers are out of date",
+ Msg = "interface file needs to be recreated, " ++
+ "the version numbers are out of date",
dummy_term_with_context(Context, DummyTerm),
Warning = item_warning(yes(warn_smart_recompilation),
Msg, DummyTerm),
@@ -1374,8 +1372,8 @@
)
).
-:- pred parse_decl_attribute(string, list(term), decl_attribute, term).
-:- mode parse_decl_attribute(in, in, out, out) is semidet.
+:- pred parse_decl_attribute(string::in, list(term)::in, decl_attribute::out,
+ term::out) is semidet.
parse_decl_attribute("impure", [Decl], purity(impure), Decl).
parse_decl_attribute("semipure", [Decl], purity(semipure), Decl).
@@ -1391,37 +1389,35 @@
parse_list_of_vars(TVars, TVarsList).
parse_decl_attribute("solver", [Decl], solver_type, Decl).
-:- pred check_no_attributes(maybe1(T), decl_attrs, maybe1(T)).
-:- mode check_no_attributes(in, in, out) is det.
+:- pred check_no_attributes(maybe1(T)::in, decl_attrs::in,
+ maybe1(T)::out) is det.
check_no_attributes(Result0, Attributes, Result) :-
(
Result0 = ok(_),
Attributes = [Attr - Term | _]
->
- attribute_description(Attr, AttrDescr),
+ AttrDescr = attribute_description(Attr),
string__append(AttrDescr, " not allowed here", Message),
Result = error(Message, Term)
;
Result = Result0
).
-:- pred attribute_description(decl_attribute, string).
-:- mode attribute_description(in, out) is det.
+:- func attribute_description(decl_attribute) = string.
-attribute_description(purity(_), "purity specifier").
-attribute_description(quantifier(univ, _), "universal quantifier (`all')").
-attribute_description(quantifier(exist, _), "existential quantifier (`some')").
-attribute_description(constraints(univ, _), "type class constraint (`<=')").
-attribute_description(constraints(exist, _),
- "existentially quantified type class constraint (`=>')").
-attribute_description(solver_type, "solver type specifier").
+attribute_description(purity(_)) = "purity specifier".
+attribute_description(quantifier(univ, _)) = "universal quantifier (`all')".
+attribute_description(quantifier(exist, _)) = "existential quantifier (`some')".
+attribute_description(constraints(univ, _)) = "type class constraint (`<=')".
+attribute_description(constraints(exist, _)) =
+ "existentially quantified type class constraint (`=>')".
+attribute_description(solver_type) = "solver type specifier".
%-----------------------------------------------------------------------------%
-:- pred parse_promise(module_name, promise_type, varset, list(term), decl_attrs,
- maybe1(item)).
-:- mode parse_promise(in, in, in, in, in, out) is semidet.
+:- pred parse_promise(module_name::in, promise_type::in, varset::in,
+ list(term)::in, decl_attrs::in, maybe1(item)::out) is semidet.
parse_promise(ModuleName, PromiseType, VarSet, [Term], Attributes, Result) :-
varset__coerce(VarSet, ProgVarSet0),
@@ -1437,7 +1433,7 @@
Goal = Goal0
)
;
- get_quant_vars(univ, ModuleName, Attributes, [], _, UnivVars0),
+ get_quant_vars(univ, ModuleName, Attributes, _, [], UnivVars0),
list__map(term__coerce_var, UnivVars0, UnivVars),
Goal0 = Goal
),
@@ -1446,8 +1442,8 @@
%-----------------------------------------------------------------------------%
-:- pred parse_type_decl(module_name, varset, term, decl_attrs, maybe1(item)).
-:- mode parse_type_decl(in, in, in, in, out) is det.
+:- pred parse_type_decl(module_name::in, varset::in, term::in, decl_attrs::in,
+ maybe1(item)::out) is det.
parse_type_decl(ModuleName, VarSet, TypeDecl, Attributes, Result) :-
(
@@ -1466,21 +1462,20 @@
% (don't bother at the moment, since we ignore
% conditions anyhow :-)
-:- pred make_type_defn(varset, condition, processed_type_body, item).
-:- mode make_type_defn(in, in, in, out) is det.
+:- pred make_type_defn(varset::in, condition::in, processed_type_body::in,
+ item::out) is det.
make_type_defn(VarSet0, Cond, processed_type_body(Name, Args, TypeDefn),
type_defn(VarSet, Name, Args, TypeDefn, Cond)) :-
varset__coerce(VarSet0, VarSet).
-:- pred make_external(varset, sym_name_specifier, item).
-:- mode make_external(in, in, out) is det.
+:- pred make_external(varset::in, sym_name_specifier::in, item::out) is det.
make_external(VarSet0, SymSpec, module_defn(VarSet, external(SymSpec))) :-
varset__coerce(VarSet0, VarSet).
-:- pred get_is_solver_type(decl_attrs, is_solver_type, decl_attrs).
-:- mode get_is_solver_type(in, out, out) is det.
+:- pred get_is_solver_type(decl_attrs::in, is_solver_type::out,
+ decl_attrs::out) is det.
get_is_solver_type(Attributes0, IsSolverType, Attributes) :-
( Attributes0 = [solver_type - _ | Attributes1] ->
@@ -1493,31 +1488,32 @@
%-----------------------------------------------------------------------------%
- % add a warning message to the list of messages
-
-:- pred add_warning(string, term, message_list, message_list).
-:- mode add_warning(in, in, in, out) is det.
+ % Add a warning message to the list of messages.
+ %
+:- pred add_warning(string::in, term::in, message_list::in, message_list::out)
+ is det.
add_warning(Warning, Term, Msgs, [Msg - Term | Msgs]) :-
string__append("Warning: ", Warning, Msg).
- % add an error message to the list of messages
-
-:- pred add_error(string, term, message_list, message_list).
-:- mode add_error(in, in, in, out) is det.
+ % Add an error message to the list of messages.
+ %
+:- pred add_error(string::in, term::in, message_list::in, message_list::out)
+ is det.
add_error(Error, Term, Msgs, [Msg - Term | Msgs]) :-
string__append("Error: ", Error, Msg).
%-----------------------------------------------------------------------------%
+
% parse_type_decl_type(Term, Condition, Result) succeeds
% if Term is a "type" type declaration, and binds Condition
% to the condition for that declaration (if any), and Result to
% a representation of the declaration.
-
-:- pred parse_type_decl_type(module_name, string, list(term), decl_attrs,
- condition, maybe1(processed_type_body)).
-:- mode parse_type_decl_type(in, in, in, in, out, out) is semidet.
+ %
+:- pred parse_type_decl_type(module_name::in, string::in, list(term)::in,
+ decl_attrs::in, condition::out, maybe1(processed_type_body)::out)
+ is semidet.
parse_type_decl_type(ModuleName, "--->", [H, B], Attributes0, Condition, R) :-
/* get_condition(...), */
@@ -1537,9 +1533,9 @@
% parse_type_decl_pred(ModuleName, VarSet, Pred, Attributes, Result)
% succeeds if Pred is a predicate type declaration, and binds Result
% to a representation of the declaration.
-:- pred parse_type_decl_pred(module_name, varset, term, decl_attrs,
- maybe1(item)).
-:- mode parse_type_decl_pred(in, in, in, in, out) is det.
+ %
+:- pred parse_type_decl_pred(module_name::in, varset::in, term::in,
+ decl_attrs::in, maybe1(item)::out) is det.
parse_type_decl_pred(ModuleName, VarSet, Pred, Attributes, R) :-
get_condition(Pred, Body, Condition),
@@ -1601,9 +1597,9 @@
% parse_type_decl_func(ModuleName, Varset, Func, Attributes, Result)
% succeeds if Func is a function type declaration, and binds Result to
% a representation of the declaration.
-:- pred parse_type_decl_func(module_name, varset, term, decl_attrs,
- maybe1(item)).
-:- mode parse_type_decl_func(in, in, in, in, out) is det.
+ %
+:- pred parse_type_decl_func(module_name::in, varset::in, term::in,
+ decl_attrs::in, maybe1(item)::out) is det.
parse_type_decl_func(ModuleName, VarSet, Func, Attributes, R) :-
get_condition(Func, Body, Condition),
@@ -1717,7 +1713,7 @@
).
:- pred parse_equality_or_comparison_pred_term(string::in, term::in,
- term::out) is semidet.
+ term::out) is semidet.
parse_equality_or_comparison_pred_term(EqOrComp, Term, PredNameTerm) :-
Term = term__functor(term__atom("is"),
@@ -1733,9 +1729,9 @@
% to a representation of the determinism condition of Term0, if any,
% and binds Term to the other part of Term0. If Term0 does not
% contain a determinism, then Determinism is bound to `unspecified'.
-
-:- pred get_determinism(term, term, maybe1(maybe(determinism))).
-:- mode get_determinism(in, out, out) is det.
+ %
+:- pred get_determinism(term::in, term::out, maybe1(maybe(determinism))::out)
+ is det.
get_determinism(B, Body, Determinism) :-
(
@@ -1759,8 +1755,8 @@
% Process the `with_inst` part of a declaration of the form:
% :- mode p(int) `with_inst` (pred(in, out) is det).
-:- pred get_with_inst(term, term, maybe1(maybe(inst))).
-:- mode get_with_inst(in, out, out) is det.
+ %
+:- pred get_with_inst(term::in, term::out, maybe1(maybe(inst))::out) is det.
get_with_inst(Body0, Body, WithInst) :-
(
@@ -1771,7 +1767,7 @@
WithInst = ok(yes(Inst))
;
WithInst = error("invalid inst in `with_inst`",
- Body0)
+ Body0)
),
Body = Body1
;
@@ -1779,8 +1775,7 @@
WithInst = ok(no)
).
-:- pred get_with_type(term, term, maybe(type)).
-:- mode get_with_type(in, out, out) is det.
+:- pred get_with_type(term::in, term::out, maybe(type)::out) is det.
get_with_type(Body0, Body, WithType) :-
(
@@ -1801,9 +1796,8 @@
% to a representation of the 'where' condition of Term0, if any,
% and binds Term to the other part of Term0. If Term0 does not
% contain a condition, then Condition is bound to true.
-
-:- pred get_condition(term, term, condition).
-:- mode get_condition(in, out, out) is det.
+ %
+:- pred get_condition(term::in, term::out, condition::out) is det.
get_condition(Body, Body, true).
@@ -1843,14 +1837,14 @@
%-----------------------------------------------------------------------------%
% This is for "Head == Body" (equivalence) definitions.
-:- pred process_eqv_type(module_name, term, term, maybe1(processed_type_body)).
-:- mode process_eqv_type(in, in, in, out) is det.
+:- pred process_eqv_type(module_name::in, term::in, term::in,
+ maybe1(processed_type_body)::out) is det.
process_eqv_type(ModuleName, Head, Body, Result) :-
parse_type_defn_head(ModuleName, Head, Body, Result0),
process_eqv_type_2(Result0, Body, Result).
-:- pred process_eqv_type_2(maybe_functor, term, maybe1(processed_type_body)).
-:- mode process_eqv_type_2(in, in, out) is det.
+:- pred process_eqv_type_2(maybe_functor::in, term::in,
+ maybe1(processed_type_body)::out) is det.
process_eqv_type_2(error(Error, Term), _, error(Error, Term)).
process_eqv_type_2(ok(Name, Args0), Body0, Result) :-
% check that all the variables in the body occur in the head
@@ -1861,7 +1855,7 @@
)
->
Result = error("free type parameter in RHS of type definition",
- Body0)
+ Body0)
;
list__map(term__coerce, Args0, Args),
convert_type(Body0, Body),
@@ -1875,17 +1869,20 @@
% binds Result to a representation of the type information about the
% TypeHead.
% This is for "Head ---> Body" (constructor) definitions.
-:- pred process_du_type(module_name, term, term, is_solver_type,
- maybe1(maybe(unify_compare)), maybe1(processed_type_body)).
-:- mode process_du_type(in, in, in, in, in, out) is det.
+ %
+:- pred process_du_type(module_name::in, term::in, term::in,
+ is_solver_type::in, maybe1(maybe(unify_compare))::in,
+ maybe1(processed_type_body)::out) is det.
+
process_du_type(ModuleName, Head, Body, IsSolverType, EqualityPred, Result) :-
parse_type_defn_head(ModuleName, Head, Body, Result0),
process_du_type_2(ModuleName, Result0, Body, IsSolverType,
EqualityPred, Result).
-:- pred process_du_type_2(module_name, maybe_functor, term, is_solver_type,
- maybe1(maybe(unify_compare)), maybe1(processed_type_body)).
-:- mode process_du_type_2(in, in, in, in, in, out) is det.
+:- pred process_du_type_2(module_name::in, maybe_functor::in, term::in,
+ is_solver_type::in, maybe1(maybe(unify_compare))::in,
+ maybe1(processed_type_body)::out) is det.
+
process_du_type_2(_, error(Error, Term), _, _, _, error(Error, Term)).
process_du_type_2(ModuleName, ok(Functor, Args0), Body, IsSolverType,
MaybeEqualityPred, Result) :-
@@ -1908,7 +1905,7 @@
->
Result = error(
"free type parameter in RHS of type definition",
- Body)
+ Body)
% check that all type variables in existential quantifiers
% do not occur in the head
@@ -1917,11 +1914,13 @@
;
list__member(Ctor, Constrs),
Ctor = ctor(ExistQVars, _Constraints, _CtorName,
- _CtorArgs),
+ _CtorArgs),
list__member(Var, ExistQVars),
term__contains_var_list(Args, Var)
->
- Result = error( "type variable has overlapping scopes (explicit type quantifier shadows argument type)", Body)
+ Result = error("type variable has overlapping " ++
+ "scopes (explicit type quantifier shadows " ++
+ "argument type)", Body)
% check that all type variables in existential quantifiers
% occur somewhere in the constructor argument types
@@ -1929,14 +1928,14 @@
;
list__member(Ctor, Constrs),
Ctor = ctor(ExistQVars, _Constraints, _CtorName,
- CtorArgs),
+ CtorArgs),
list__member(Var, ExistQVars),
assoc_list__values(CtorArgs, CtorArgTypes),
\+ term__contains_var_list(CtorArgTypes, Var)
->
- Result = error(
-"type variable in existential quantifier does not occur in arguments of constructor",
- Body)
+ Result = error("type variable in existential " ++
+ "quantifier does not occur in arguments " ++
+ "of constructor", Body)
% check that all type variables in existential constraints
% occur in the existential quantifiers
% (XXX is this check overly conservative? Perhaps we should
@@ -1947,14 +1946,16 @@
;
list__member(Ctor, Constrs),
Ctor = ctor(ExistQVars, Constraints, _CtorName,
- _CtorArgs),
+ _CtorArgs),
list__member(Constraint, Constraints),
Constraint = constraint(_Name, ConstraintArgs),
term__contains_var_list(ConstraintArgs, Var),
\+ list__member(Var, ExistQVars)
->
- Result = error("type variables in class constraints introduced with `=>' must be explicitly existentially quantified using `some'",
- Body)
+ Result = error("type variables in class " ++
+ "constraints introduced with `=>' must " ++
+ "be explicitly existentially quantified " ++
+ "using `some'", Body)
;
(
MaybeEqualityPred = ok(EqualityPred),
@@ -1976,10 +1977,10 @@
% checks that its argument is well formed, and if it is,
% binds Result to a representation of the type information about the
% TypeHead.
+ %
+:- pred process_abstract_type(module_name::in, term::in, decl_attrs::in,
+ maybe1(processed_type_body)::out) is det.
-:- pred process_abstract_type(module_name, term, decl_attrs,
- maybe1(processed_type_body)).
-:- mode process_abstract_type(in, in, in, out) is det.
process_abstract_type(ModuleName, Head, Attributes0, Result) :-
dummy_term(Body),
parse_type_defn_head(ModuleName, Head, Body, Result0),
@@ -1987,9 +1988,9 @@
process_abstract_type_2(Result0, IsSolverType, Result1),
check_no_attributes(Result1, Attributes, Result).
-:- pred process_abstract_type_2(maybe_functor, is_solver_type,
- maybe1(processed_type_body)).
-:- mode process_abstract_type_2(in, in, out) is det.
+:- pred process_abstract_type_2(maybe_functor::in, is_solver_type::in,
+ maybe1(processed_type_body)::out) is det.
+
process_abstract_type_2(error(Error, Term), _, error(Error, Term)).
process_abstract_type_2(ok(Functor, Args0), IsSolverType,
ok(processed_type_body(Functor, Args,
@@ -2016,14 +2017,16 @@
parse_type_defn_head_2(R, Body, Head, Result)
).
-:- pred parse_type_defn_head_2(maybe_functor, term, term, maybe_functor).
-:- mode parse_type_defn_head_2(in, in, in, out) is det.
+:- pred parse_type_defn_head_2(maybe_functor::in, term::in, term::in,
+ maybe_functor::out) is det.
+
parse_type_defn_head_2(error(Msg, Term), _, _, error(Msg, Term)).
parse_type_defn_head_2(ok(Name, Args), Body, Head, Result) :-
parse_type_defn_head_3(Name, Args, Body, Head, Result).
-:- pred parse_type_defn_head_3(sym_name, list(term), term, term, maybe_functor).
-:- mode parse_type_defn_head_3(in, in, in, in, out) is det.
+:- pred parse_type_defn_head_3(sym_name::in, list(term)::in, term::in, term::in,
+ maybe_functor::out) is det.
+
parse_type_defn_head_3(Name, Args, _Body, Head, Result) :-
% check that all the head args are variables
( %%% some [Arg]
@@ -2052,26 +2055,29 @@
% Convert a list of terms separated by semi-colons
% (known as a "disjunction", even thought the terms aren't goals
% in this case) into a list of constructors
+ %
+:- pred convert_constructors(module_name::in, term::in,
+ list(constructor)::out) is semidet.
-:- pred convert_constructors(module_name, term, list(constructor)).
-:- mode convert_constructors(in, in, out) is semidet.
convert_constructors(ModuleName, Body, Constrs) :-
disjunction_to_list(Body, List),
convert_constructors_2(ModuleName, List, Constrs).
% true if input argument is a valid list of constructors
+ %
+:- pred convert_constructors_2(module_name::in, list(term)::in,
+ list(constructor)::out) is semidet.
-:- pred convert_constructors_2(module_name, list(term), list(constructor)).
-:- mode convert_constructors_2(in, in, out) is semidet.
convert_constructors_2(_, [], []).
convert_constructors_2(ModuleName, [Term | Terms], [Constr | Constrs]) :-
convert_constructor(ModuleName, Term, Constr),
convert_constructors_2(ModuleName, Terms, Constrs).
% true if input argument is a valid constructor.
+ %
+:- pred convert_constructor(module_name::in, term::in, constructor::out)
+ is semidet.
-:- pred convert_constructor(module_name, term, constructor).
-:- mode convert_constructor(in, in, out) is semidet.
convert_constructor(ModuleName, Term0, Result) :-
(
Term0 = term__functor(term__atom("some"), [Vars, Term1], _)
@@ -2105,11 +2111,10 @@
% parse a `:- pred p(...)' declaration or a
% `:- func f(...) `with_type` t' declaration
-
-:- pred process_pred_or_func(pred_or_func, module_name, varset, term,
- condition, maybe(type), maybe(inst), maybe(determinism),
- decl_attrs, maybe1(item)).
-:- mode process_pred_or_func(in, in, in, in, in, in, in, in, in, out) is det.
+ %
+:- pred process_pred_or_func(pred_or_func::in, module_name::in, varset::in,
+ term::in, condition::in, maybe(type)::in, maybe(inst)::in,
+ maybe(determinism)::in, decl_attrs::in, maybe1(item)::out) is det.
process_pred_or_func(PredOrFunc, ModuleName, VarSet, PredType, Cond, WithType,
WithInst, MaybeDet, Attributes0, Result) :-
@@ -2179,10 +2184,9 @@
PredType)
).
process_pred_or_func_2(_, error(M, T),
- _, _, _, _, _, _, _, _, _, _, error(M, T)).
+ _, _, _, _, _, _, _, _, _, _, error(M, T)).
-:- pred get_purity(decl_attrs, purity, decl_attrs).
-:- mode get_purity(in, out, out) is det.
+:- pred get_purity(decl_attrs::in, purity::out, decl_attrs::out) is det.
get_purity(Attributes0, Purity, Attributes) :-
( Attributes0 = [purity(Purity0) - _ | Attributes1] ->
@@ -2214,9 +2218,9 @@
% error).
% Attributes is bound to the remaining attributes.
-:- pred get_class_context_and_inst_constraints(module_name, decl_attrs,
- decl_attrs, maybe3(existq_tvars, class_constraints, inst_var_sub)).
-:- mode get_class_context_and_inst_constraints(in, in, out, out) is det.
+:- pred get_class_context_and_inst_constraints(module_name::in,
+ decl_attrs::in, decl_attrs::out,
+ maybe3(existq_tvars, class_constraints, inst_var_sub)::out) is det.
get_class_context_and_inst_constraints(ModuleName, RevAttributes0,
RevAttributes, MaybeContext) :-
@@ -2255,24 +2259,23 @@
% error message.)
list__reverse(RevAttributes0, Attributes0),
- get_quant_vars(univ, ModuleName, Attributes0, [],
- Attributes1, _UnivQVars),
- get_quant_vars(exist, ModuleName, Attributes1, [],
- Attributes2, ExistQVars0),
+ get_quant_vars(univ, ModuleName, Attributes0, Attributes1,
+ [], _UnivQVars),
+ get_quant_vars(exist, ModuleName, Attributes1, Attributes2,
+ [], ExistQVars0),
list__map(term__coerce_var, ExistQVars0, ExistQVars),
get_constraints(univ, ModuleName, Attributes2,
- Attributes3, MaybeUnivConstraints),
+ Attributes3, MaybeUnivConstraints),
get_constraints(exist, ModuleName, Attributes3,
- Attributes, MaybeExistConstraints),
+ Attributes, MaybeExistConstraints),
list__reverse(Attributes, RevAttributes),
combine_quantifier_results(MaybeUnivConstraints, MaybeExistConstraints,
- ExistQVars, MaybeContext).
+ ExistQVars, MaybeContext).
-:- pred combine_quantifier_results(maybe_class_and_inst_constraints,
- maybe_class_and_inst_constraints, existq_tvars,
- maybe3(existq_tvars, class_constraints, inst_var_sub)).
-:- mode combine_quantifier_results(in, in, in, out) is det.
+:- pred combine_quantifier_results(maybe_class_and_inst_constraints::in,
+ maybe_class_and_inst_constraints::in, existq_tvars::in,
+ maybe3(existq_tvars, class_constraints, inst_var_sub)::out) is det.
combine_quantifier_results(error(Msg, Term), _, _, error(Msg, Term)).
combine_quantifier_results(ok(_, _), error(Msg, Term), _, error(Msg, Term)).
@@ -2281,58 +2284,53 @@
ok(ExistQVars, constraints(UnivConstraints, ExistConstraints),
InstConstraints0 `map__merge` InstConstraints1)).
-:- pred get_quant_vars(quantifier_type, module_name, decl_attrs, list(var),
- decl_attrs, list(var)).
-:- mode get_quant_vars(in, in, in, in, out, out) is det.
+:- pred get_quant_vars(quantifier_type::in, module_name::in, decl_attrs::in,
+ decl_attrs::out, list(var)::in, list(var)::out) is det.
-get_quant_vars(QuantType, ModuleName, Attributes0, Vars0,
- Attributes, Vars) :-
+get_quant_vars(QuantType, ModuleName, !Attributes, !Vars) :-
(
- Attributes0 = [quantifier(QuantType, Vars1) - _ | Attributes1]
+ !.Attributes =
+ [quantifier(QuantType, QuantVars) - _ | !:Attributes]
->
- list__append(Vars0, Vars1, Vars2),
- get_quant_vars(QuantType, ModuleName, Attributes1, Vars2,
- Attributes, Vars)
+ list__append(!.Vars, QuantVars, !:Vars),
+ get_quant_vars(QuantType, ModuleName, !Attributes, !Vars)
;
- Attributes = Attributes0,
- Vars = Vars0
+ true
).
-:- pred get_constraints(quantifier_type, module_name, decl_attrs, decl_attrs,
- maybe_class_and_inst_constraints).
-:- mode get_constraints(in, in, in, out, out) is det.
+:- pred get_constraints(quantifier_type::in, module_name::in,
+ decl_attrs::in, decl_attrs::out, maybe_class_and_inst_constraints::out)
+ is det.
-get_constraints(QuantType, ModuleName, Attributes0, Attributes,
- MaybeConstraints) :-
+get_constraints(QuantType, ModuleName, !Attributes, MaybeConstraints) :-
(
- Attributes0 = [constraints(QuantType, ConstraintsTerm) - _Term
- | Attributes1]
+ !.Attributes =
+ [constraints(QuantType, ConstraintsTerm) - _Term
+ | !:Attributes]
->
parse_class_and_inst_constraints(ModuleName, ConstraintsTerm,
MaybeConstraints0),
% there may be more constraints of the same type --
% collect them all and combine them
- get_constraints(QuantType, ModuleName, Attributes1,
- Attributes, MaybeConstraints1),
+ get_constraints(QuantType, ModuleName, !Attributes,
+ MaybeConstraints1),
combine_constraint_list_results(MaybeConstraints1,
MaybeConstraints0, MaybeConstraints)
;
- Attributes = Attributes0,
MaybeConstraints = ok([], map__init)
).
-:- pred combine_constraint_list_results(maybe_class_and_inst_constraints,
- maybe_class_and_inst_constraints, maybe_class_and_inst_constraints).
-:- mode combine_constraint_list_results(in, in, out) is det.
+:- pred combine_constraint_list_results(maybe_class_and_inst_constraints::in,
+ maybe_class_and_inst_constraints::in,
+ maybe_class_and_inst_constraints::out) is det.
combine_constraint_list_results(error(Msg, Term), _, error(Msg, Term)).
combine_constraint_list_results(ok(_, _), error(Msg, Term), error(Msg, Term)).
combine_constraint_list_results(ok(CC0, IC0), ok(CC1, IC1),
ok(CC0 ++ CC1, IC0 `map__merge` IC1)).
-:- pred get_existential_constraints_from_term(module_name, term, term,
- maybe1(list(class_constraint))).
-:- mode get_existential_constraints_from_term(in, in, out, out) is det.
+:- pred get_existential_constraints_from_term(module_name::in, term::in,
+ term::out, maybe1(list(class_constraint))::out) is det.
get_existential_constraints_from_term(ModuleName, PredType0, PredType,
MaybeExistentialConstraints) :-
@@ -2352,16 +2350,15 @@
% Verify that among the arguments of a :- pred declaration,
% either all arguments specify a mode or none of them do.
-
-:- pred verify_type_and_mode_list(list(type_and_mode)).
-:- mode verify_type_and_mode_list(in) is semidet.
+ %
+:- pred verify_type_and_mode_list(list(type_and_mode)::in) is semidet.
verify_type_and_mode_list([]).
verify_type_and_mode_list([First | Rest]) :-
verify_type_and_mode_list_2(Rest, First).
-:- pred verify_type_and_mode_list_2(list(type_and_mode), type_and_mode).
-:- mode verify_type_and_mode_list_2(in, in) is semidet.
+:- pred verify_type_and_mode_list_2(list(type_and_mode)::in, type_and_mode::in)
+ is semidet.
verify_type_and_mode_list_2([], _).
verify_type_and_mode_list_2([Head | Tail], First) :-
@@ -2377,10 +2374,9 @@
%-----------------------------------------------------------------------------%
% parse a `:- func p(...)' declaration
-
-:- pred process_func(module_name, varset, term, condition,
- maybe(determinism), decl_attrs, maybe1(item)).
-:- mode process_func(in, in, in, in, in, in, out) is det.
+ %
+:- pred process_func(module_name::in, varset::in, term::in, condition::in,
+ maybe(determinism)::in, decl_attrs::in, maybe1(item)::out) is det.
process_func(ModuleName, VarSet, Term, Cond, MaybeDet, Attributes0, Result) :-
get_class_context_and_inst_constraints(ModuleName, Attributes0,
@@ -2395,10 +2391,9 @@
Result = error(String, ErrorTerm)
).
-:- pred process_func_2(module_name, varset, term, condition,
- maybe(determinism), existq_tvars, class_constraints, inst_var_sub,
- decl_attrs, maybe1(item)).
-:- mode process_func_2(in, in, in, in, in, in, in, in, in, out) is det.
+:- pred process_func_2(module_name::in, varset::in, term::in, condition::in,
+ maybe(determinism)::in, existq_tvars::in, class_constraints::in,
+ inst_var_sub::in, decl_attrs::in, maybe1(item)::out) is det.
process_func_2(ModuleName, VarSet, Term, Cond, MaybeDet,
ExistQVars, Constraints, InstConstraints, Attributes, Result) :-
@@ -2509,7 +2504,7 @@
%-----------------------------------------------------------------------------%
% parse a `:- mode p(...)' declaration
-
+ %
:- pred process_mode(module_name::in, varset::in, term::in, condition::in,
decl_attrs::in, maybe(inst)::in, maybe(determinism)::in,
maybe1(item)::out) is det.
@@ -2523,7 +2518,7 @@
FuncTerm = desugar_field_access(FuncTerm0)
->
parse_implicitly_qualified_term(ModuleName, FuncTerm, Term,
- "function `:- mode' declaration", R),
+ "function `:- mode' declaration", R),
process_func_mode(R, ModuleName, FuncTerm, ReturnTypeTerm,
Term, VarSet, MaybeDet, Cond, Attributes, Result)
;
@@ -2639,8 +2634,8 @@
user_defined_mode(Name, Args)) :-
list__map(constrain_inst_vars_in_inst(InstConstraints), Args0, Args).
-:- pred constrain_inst_vars_in_inst(inst_var_sub, inst, inst).
-:- mode constrain_inst_vars_in_inst(in, in, out) is det.
+:- pred constrain_inst_vars_in_inst(inst_var_sub::in, (inst)::in, (inst)::out)
+ is det.
constrain_inst_vars_in_inst(_, any(U), any(U)).
constrain_inst_vars_in_inst(_, free, free).
@@ -2682,17 +2677,16 @@
abstract_inst(N, Is)) :-
list__map(constrain_inst_vars_in_inst(InstConstraints), Is0, Is).
-:- pred constrain_inst_vars_in_pred_inst_info(inst_var_sub, pred_inst_info,
- pred_inst_info).
-:- mode constrain_inst_vars_in_pred_inst_info(in, in, out) is det.
+:- pred constrain_inst_vars_in_pred_inst_info(inst_var_sub::in,
+ pred_inst_info::in, pred_inst_info::out) is det.
constrain_inst_vars_in_pred_inst_info(InstConstraints, PII0, PII) :-
PII0 = pred_inst_info(PredOrFunc, Modes0, Det),
list__map(constrain_inst_vars_in_mode(InstConstraints), Modes0, Modes),
PII = pred_inst_info(PredOrFunc, Modes, Det).
-:- pred constrain_inst_vars_in_inst_name(inst_var_sub, inst_name, inst_name).
-:- mode constrain_inst_vars_in_inst_name(in, in, out) is det.
+:- pred constrain_inst_vars_in_inst_name(inst_var_sub::in, inst_name::in,
+ inst_name::out) is det.
constrain_inst_vars_in_inst_name(InstConstraints, Name0, Name) :-
( Name0 = user_inst(SymName, Args0) ->
@@ -2708,79 +2702,81 @@
inst_var_constraints_are_consistent_in_modes(Modes) :-
inst_var_constraints_are_consistent_in_modes(Modes, map__init, _).
-:- pred inst_var_constraints_are_consistent_in_modes(list(mode),
- inst_var_sub, inst_var_sub).
-:- mode inst_var_constraints_are_consistent_in_modes(in, in, out) is semidet.
+:- pred inst_var_constraints_are_consistent_in_modes(list(mode)::in,
+ inst_var_sub::in, inst_var_sub::out) is semidet.
-inst_var_constraints_are_consistent_in_modes(Modes) -->
- list__foldl(inst_var_constraints_are_consistent_in_mode, Modes).
+inst_var_constraints_are_consistent_in_modes(Modes, !IVS) :-
+ list__foldl(inst_var_constraints_are_consistent_in_mode, Modes,
+ !IVS).
:- pred inst_var_constraints_are_consistent_in_type_and_modes(
- list(type_and_mode)).
-:- mode inst_var_constraints_are_consistent_in_type_and_modes(in) is semidet.
+ list(type_and_mode)::in) is semidet.
inst_var_constraints_are_consistent_in_type_and_modes(TypeAndModes) :-
- list__foldl((pred(TypeAndMode::in, in, out) is semidet -->
- ( { TypeAndMode = type_only(_) }
- ; { TypeAndMode = type_and_mode(_, Mode) },
- inst_var_constraints_are_consistent_in_mode(Mode)
+ list__foldl((pred(TypeAndMode::in, !.IVS::in, !:IVS::out) is semidet :-
+ ( TypeAndMode = type_only(_)
+ ; TypeAndMode = type_and_mode(_, Mode),
+ inst_var_constraints_are_consistent_in_mode(Mode, !IVS)
)), TypeAndModes, map__init, _).
-:- pred inst_var_constraints_are_consistent_in_mode(mode, inst_var_sub,
- inst_var_sub).
-:- mode inst_var_constraints_are_consistent_in_mode(in, in, out) is semidet.
-
-inst_var_constraints_are_consistent_in_mode(InitialInst -> FinalInst) -->
- inst_var_constraints_are_consistent_in_inst(InitialInst),
- inst_var_constraints_are_consistent_in_inst(FinalInst).
-inst_var_constraints_are_consistent_in_mode(user_defined_mode(_, ArgInsts)) -->
- inst_var_constraints_are_consistent_in_insts(ArgInsts).
-
-:- pred inst_var_constraints_are_consistent_in_insts(list(inst), inst_var_sub,
- inst_var_sub).
-:- mode inst_var_constraints_are_consistent_in_insts(in, in, out) is semidet.
-
-inst_var_constraints_are_consistent_in_insts(Insts) -->
- list__foldl(inst_var_constraints_are_consistent_in_inst, Insts).
-
-:- pred inst_var_constraints_are_consistent_in_inst(inst, inst_var_sub,
- inst_var_sub).
-:- mode inst_var_constraints_are_consistent_in_inst(in, in, out) is semidet.
-
-inst_var_constraints_are_consistent_in_inst(any(_)) --> [].
-inst_var_constraints_are_consistent_in_inst(free) --> [].
-inst_var_constraints_are_consistent_in_inst(free(_)) --> [].
-inst_var_constraints_are_consistent_in_inst(bound(_, BoundInsts)) -->
- list__foldl((pred(functor(_, Insts)::in, in, out) is semidet -->
- inst_var_constraints_are_consistent_in_insts(Insts)),
- BoundInsts).
-inst_var_constraints_are_consistent_in_inst(ground(_, GroundInstInfo)) -->
- ( { GroundInstInfo = none }
- ; { GroundInstInfo = higher_order(pred_inst_info(_, Modes, _)) },
- inst_var_constraints_are_consistent_in_modes(Modes)
- ).
-inst_var_constraints_are_consistent_in_inst(not_reached) --> [].
-inst_var_constraints_are_consistent_in_inst(inst_var(_)) -->
- { error("inst_var_constraints_are_consistent_in_inst: unconstrained inst_var") }.
-inst_var_constraints_are_consistent_in_inst(defined_inst(InstName)) -->
- ( { InstName = user_inst(_, Insts) } ->
- inst_var_constraints_are_consistent_in_insts(Insts)
+:- pred inst_var_constraints_are_consistent_in_mode((mode)::in, inst_var_sub::in,
+ inst_var_sub::out) is semidet.
+
+inst_var_constraints_are_consistent_in_mode(InitialInst -> FinalInst, !IVS) :-
+ inst_var_constraints_are_consistent_in_inst(InitialInst, !IVS),
+ inst_var_constraints_are_consistent_in_inst(FinalInst, !IVS).
+inst_var_constraints_are_consistent_in_mode(user_defined_mode(_, ArgInsts),
+ !IVS) :-
+ inst_var_constraints_are_consistent_in_insts(ArgInsts, !IVS).
+
+:- pred inst_var_constraints_are_consistent_in_insts(list(inst)::in,
+ inst_var_sub::in, inst_var_sub::out) is semidet.
+
+inst_var_constraints_are_consistent_in_insts(Insts, !IVS) :-
+ list__foldl(inst_var_constraints_are_consistent_in_inst, Insts, !IVS).
+
+:- pred inst_var_constraints_are_consistent_in_inst((inst)::in, inst_var_sub::in,
+ inst_var_sub::out) is semidet.
+
+inst_var_constraints_are_consistent_in_inst(any(_), !IVS).
+inst_var_constraints_are_consistent_in_inst(free, !IVS).
+inst_var_constraints_are_consistent_in_inst(free(_), !IVS).
+inst_var_constraints_are_consistent_in_inst(bound(_, BoundInsts), !IVS) :-
+ list__foldl(
+ (pred(functor(_, Insts)::in, !.IVS::in, !:IVS::out) is semidet :-
+ inst_var_constraints_are_consistent_in_insts(Insts, !IVS)
+ ),
+ BoundInsts, !IVS).
+inst_var_constraints_are_consistent_in_inst(ground(_, GroundInstInfo), !IVS) :-
+ (
+ GroundInstInfo = none
+ ;
+ GroundInstInfo = higher_order(pred_inst_info(_, Modes, _)),
+ inst_var_constraints_are_consistent_in_modes(Modes, !IVS)
+ ).
+inst_var_constraints_are_consistent_in_inst(not_reached, !IVS).
+inst_var_constraints_are_consistent_in_inst(inst_var(_), _, _) :-
+ unexpected(this_file,
+ "inst_var_constraints_are_consistent_in_inst: unconstrained inst_var").
+inst_var_constraints_are_consistent_in_inst(defined_inst(InstName), !IVS) :-
+ ( InstName = user_inst(_, Insts) ->
+ inst_var_constraints_are_consistent_in_insts(Insts, !IVS)
;
- []
+ true
).
-inst_var_constraints_are_consistent_in_inst(abstract_inst(_, Insts)) -->
- inst_var_constraints_are_consistent_in_insts(Insts).
+inst_var_constraints_are_consistent_in_inst(abstract_inst(_, Insts), !IVS) :-
+ inst_var_constraints_are_consistent_in_insts(Insts, !IVS).
inst_var_constraints_are_consistent_in_inst(
- constrained_inst_vars(InstVars, Inst)) -->
- set__fold((pred(InstVar::in, in, out) is semidet -->
- ( Inst0 =^ map__elem(InstVar) ->
+ constrained_inst_vars(InstVars, Inst), !IVS) :-
+ set__fold((pred(InstVar::in, !.IVS::in, !:IVS::out) is semidet :-
+ ( Inst0 = !.IVS ^ map__elem(InstVar) ->
% Check that the inst_var constraint is consistent with
% the previous constraint on this inst_var.
- { Inst = Inst0 }
+ Inst = Inst0
;
- ^ map__elem(InstVar) := Inst
- )), InstVars),
- inst_var_constraints_are_consistent_in_inst(Inst).
+ !:IVS = !.IVS ^ map__elem(InstVar) := Inst
+ )), InstVars, !IVS),
+ inst_var_constraints_are_consistent_in_inst(Inst, !IVS).
%-----------------------------------------------------------------------------%
@@ -2790,8 +2786,9 @@
% `=' as well. Since `=' was once the standard operator, make
% sure warnings are given before it is phased out.
%
-:- pred parse_inst_decl(module_name, varset, term, maybe1(item)).
-:- mode parse_inst_decl(in, in, in, out) is det.
+:- pred parse_inst_decl(module_name::in, varset::in, term::in,
+ maybe1(item)::out) is det.
+
parse_inst_decl(ModuleName, VarSet, InstDefn, Result) :-
(
InstDefn = term__functor(term__atom(Op), [H, B], _Context),
@@ -2827,16 +2824,16 @@
% Parse a `:- inst <Head> ---> <Body>.' definition.
%
-:- pred convert_inst_defn(module_name, term, term, maybe1(processed_inst_body)).
-:- mode convert_inst_defn(in, in, in, out) is det.
+:- pred convert_inst_defn(module_name::in, term::in, term::in,
+ maybe1(processed_inst_body)::out) is det.
+
convert_inst_defn(ModuleName, Head, Body, Result) :-
parse_implicitly_qualified_term(ModuleName,
Head, Body, "inst definition", R),
convert_inst_defn_2(R, Head, Body, Result).
-:- pred convert_inst_defn_2(maybe_functor, term, term,
- maybe1(processed_inst_body)).
-:- mode convert_inst_defn_2(in, in, in, out) is det.
+:- pred convert_inst_defn_2(maybe_functor::in, term::in, term::in,
+ maybe1(processed_inst_body)::out) is det.
convert_inst_defn_2(error(M, T), _, _, error(M, T)).
convert_inst_defn_2(ok(Name, ArgTerms), Head, Body, Result) :-
@@ -2898,17 +2895,17 @@
inst_defn
).
-:- pred convert_abstract_inst_defn(module_name, term,
- maybe1(processed_inst_body)).
-:- mode convert_abstract_inst_defn(in, in, out) is det.
+:- pred convert_abstract_inst_defn(module_name::in, term::in,
+ maybe1(processed_inst_body)::out) is det.
+
convert_abstract_inst_defn(ModuleName, Head, Result) :-
parse_implicitly_qualified_term(ModuleName, Head, Head,
"inst definition", R),
convert_abstract_inst_defn_2(R, Head, Result).
-:- pred convert_abstract_inst_defn_2(maybe_functor, term,
- maybe1(processed_inst_body)).
-:- mode convert_abstract_inst_defn_2(in, in, out) is det.
+:- pred convert_abstract_inst_defn_2(maybe_functor::in, term::in,
+ maybe1(processed_inst_body)::out) is det.
+
convert_abstract_inst_defn_2(error(M, T), _, error(M, T)).
convert_abstract_inst_defn_2(ok(Name, ArgTerms), Head, Result) :-
(
@@ -2932,8 +2929,8 @@
Result = error("inst parameters must be variables", Head)
).
-:- pred make_inst_defn(varset, condition, processed_inst_body, item).
-:- mode make_inst_defn(in, in, in, out) is det.
+:- pred make_inst_defn(varset::in, condition::in, processed_inst_body::in,
+ item::out) is det.
make_inst_defn(VarSet0, Cond, processed_inst_body(Name, Params, InstDefn),
inst_defn(VarSet, Name, Params, InstDefn, Cond)) :-
@@ -2942,9 +2939,9 @@
%-----------------------------------------------------------------------------%
% parse a `:- mode foo :: ...' or `:- mode foo = ...' definition.
-
-:- pred parse_mode_decl(module_name, varset, term, decl_attrs, maybe1(item)).
-:- mode parse_mode_decl(in, in, in, in, out) is det.
+ %
+:- pred parse_mode_decl(module_name::in, varset::in, term::in, decl_attrs::in,
+ maybe1(item)::out) is det.
parse_mode_decl(ModuleName, VarSet, ModeDefn, Attributes, Result) :-
( %%% some [H, B]
@@ -2979,8 +2976,8 @@
% Before phasing it out, a deprecated syntax warning should be
% given for a version or two.
%
-:- pred mode_op(term, term, term).
-:- mode mode_op(in, out, out) is semidet.
+:- pred mode_op(term::in, term::out, term::out) is semidet.
+
mode_op(term__functor(term__atom(Op), [H, B], _), H, B) :-
( Op = "==" ; Op = "::" ).
@@ -2991,17 +2988,17 @@
mode_defn
).
-:- pred convert_mode_defn(module_name, term, term,
- maybe1(processed_mode_body)).
-:- mode convert_mode_defn(in, in, in, out) is det.
+:- pred convert_mode_defn(module_name::in, term::in, term::in,
+ maybe1(processed_mode_body)::out) is det.
+
convert_mode_defn(ModuleName, Head, Body, Result) :-
parse_implicitly_qualified_term(ModuleName, Head, Head,
"mode definition", R),
convert_mode_defn_2(R, Head, Body, Result).
-:- pred convert_mode_defn_2(maybe_functor, term, term,
- maybe1(processed_mode_body)).
-:- mode convert_mode_defn_2(in, in, in, out) is det.
+:- pred convert_mode_defn_2(maybe_functor::in, term::in, term::in,
+ maybe1(processed_mode_body)::out) is det.
+
convert_mode_defn_2(error(M, T), _, _, error(M, T)).
convert_mode_defn_2(ok(Name, ArgTerms), Head, Body, Result) :-
(
@@ -3046,16 +3043,17 @@
Result = error("mode parameters must be variables", Head)
).
-:- pred convert_type_and_mode_list(inst_var_sub, list(term),
- list(type_and_mode)).
-:- mode convert_type_and_mode_list(in, in, out) is semidet.
+:- pred convert_type_and_mode_list(inst_var_sub::in, list(term)::in,
+ list(type_and_mode)::out) is semidet.
+
convert_type_and_mode_list(_, [], []).
convert_type_and_mode_list(InstConstraints, [H0|T0], [H|T]) :-
convert_type_and_mode(InstConstraints, H0, H),
convert_type_and_mode_list(InstConstraints, T0, T).
-:- pred convert_type_and_mode(inst_var_sub, term, type_and_mode).
-:- mode convert_type_and_mode(in, in, out) is semidet.
+:- pred convert_type_and_mode(inst_var_sub::in, term::in, type_and_mode::out)
+ is semidet.
+
convert_type_and_mode(InstConstraints, Term, Result) :-
(
Term = term__functor(term__atom("::"), [TypeTerm, ModeTerm],
@@ -3070,8 +3068,9 @@
Result = type_only(Type)
).
-:- pred make_mode_defn(varset, condition, processed_mode_body, item).
-:- mode make_mode_defn(in, in, in, out) is det.
+:- pred make_mode_defn(varset::in, condition::in, processed_mode_body::in,
+ item::out) is det.
+
make_mode_defn(VarSet0, Cond, processed_mode_body(Name, Params, ModeDefn),
mode_defn(VarSet, Name, Params, ModeDefn, Cond)) :-
varset__coerce(VarSet0, VarSet).
@@ -3079,39 +3078,41 @@
%-----------------------------------------------------------------------------%
:- type maker(T1, T2) == pred(T1, T2).
-:- mode maker :: pred(in, out) is det.
+:- mode maker == in(pred(in, out) is det).
-:- pred parse_symlist_decl(parser(T), maker(list(T), sym_list),
- maker(sym_list, module_defn),
- term, decl_attrs, varset, maybe1(item)).
-:- mode parse_symlist_decl(parser, maker, maker, in, in, in, out) is det.
+:- pred parse_symlist_decl(parser(T)::parser, maker(list(T), sym_list)::maker,
+ maker(sym_list, module_defn)::maker, term::in, decl_attrs::in,
+ varset::in, maybe1(item)::out) is det.
parse_symlist_decl(ParserPred, MakeSymListPred, MakeModuleDefnPred,
- Term, Attributes, VarSet, Result) :-
+ Term, Attributes, VarSet, Result) :-
parse_list(ParserPred, Term, Result0),
process_maybe1(make_module_defn(MakeSymListPred, MakeModuleDefnPred,
- VarSet), Result0, Result1),
+ VarSet), Result0, Result1),
check_no_attributes(Result1, Attributes, Result).
-:- pred make_module_defn(maker(T, sym_list), maker(sym_list, module_defn),
- varset, T, item).
-:- mode make_module_defn(maker, maker, in, in, out) is det.
+:- pred make_module_defn(maker(T, sym_list)::maker,
+ maker(sym_list, module_defn)::maker, varset::in, T::in,
+ item::out) is det.
+
make_module_defn(MakeSymListPred, MakeModuleDefnPred, VarSet0, T,
module_defn(VarSet, ModuleDefn)) :-
varset__coerce(VarSet0, VarSet),
- call(MakeSymListPred, T, SymList),
- call(MakeModuleDefnPred, SymList, ModuleDefn).
+ MakeSymListPred(T, SymList),
+ MakeModuleDefnPred(SymList, ModuleDefn).
%-----------------------------------------------------------------------------%
-:- pred process_maybe1(maker(T1, T2), maybe1(T1), maybe1(T2)).
-:- mode process_maybe1(maker, in, out) is det.
-process_maybe1(Maker, ok(X), ok(Y)) :- call(Maker, X, Y).
+:- pred process_maybe1(maker(T1, T2)::maker, maybe1(T1)::in,
+ maybe1(T2)::out) is det.
+
+process_maybe1(Maker, ok(X), ok(Y)) :- Maker(X, Y).
process_maybe1(_, error(M, T), error(M, T)).
-:- pred process_maybe1_to_t(maker(T1, maybe1(T2)), maybe1(T1), maybe1(T2)).
-:- mode process_maybe1_to_t(maker, in, out) is det.
-process_maybe1_to_t(Maker, ok(X), Y) :- call(Maker, X, Y).
+:- pred process_maybe1_to_t(maker(T1, maybe1(T2))::maker,
+ maybe1(T1)::in, maybe1(T2)::out) is det.
+
+process_maybe1_to_t(Maker, ok(X), Y) :- Maker(X, Y).
process_maybe1_to_t(_, error(M, T), error(M, T)).
%-----------------------------------------------------------------------------%
@@ -3165,8 +3166,7 @@
% module(ModuleSpecifier)
% Matches all symbols in the specified module.
-:- pred parse_symbol_specifier(term, maybe1(sym_specifier)).
-:- mode parse_symbol_specifier(in, out) is det.
+:- pred parse_symbol_specifier(term::in, maybe1(sym_specifier)::out) is det.
parse_symbol_specifier(MainTerm, Result) :-
( MainTerm = term__functor(term__atom(Functor), [Term], _Context) ->
@@ -3237,8 +3237,8 @@
is det.
make_module_symbol_specifier(ModuleSpec, module(ModuleSpec)).
-:- pred cons_specifier_to_sym_specifier(cons_specifier, sym_specifier).
-:- mode cons_specifier_to_sym_specifier(in, out) is det.
+:- pred cons_specifier_to_sym_specifier(cons_specifier::in, sym_specifier::out)
+ is det.
cons_specifier_to_sym_specifier(sym(SymSpec), sym(SymSpec)).
cons_specifier_to_sym_specifier(typed(SymSpec), typed_sym(SymSpec)).
@@ -3247,8 +3247,8 @@
% A ModuleSpecifier is just an sym_name.
-:- pred parse_module_specifier(term, maybe1(module_specifier)).
-:- mode parse_module_specifier(in, out) is det.
+:- pred parse_module_specifier(term::in, maybe1(module_specifier)::out) is det.
+
parse_module_specifier(Term, Result) :-
parse_symbol_name(Term, Result).
@@ -3258,14 +3258,17 @@
% as a special case, so that we can report a better error
% message for that case.
-:- pred parse_module_name(module_name, term, maybe1(module_name)).
-:- mode parse_module_name(in, in, out) is det.
+:- pred parse_module_name(module_name::in, term::in,
+ maybe1(module_name)::out) is det.
+
parse_module_name(DefaultModuleName, Term, Result) :-
(
Term = term__variable(_)
->
dummy_term(ErrorContext),
- Result = error("module names starting with capital letters must be quoted using single quotes (e.g. "":- module 'Foo'."")", ErrorContext)
+ Result = error("module names starting with capital " ++
+ "letters must be quoted using single " ++
+ "quotes (e.g. "":- module 'Foo'."")", ErrorContext)
;
parse_implicitly_qualified_symbol_name(DefaultModuleName,
Term, Result)
@@ -3341,8 +3344,8 @@
).
process_typed_predicate_specifier(error(Msg, Term), error(Msg, Term)).
-:- pred make_arity_predicate_specifier(sym_name_specifier, pred_specifier).
-:- mode make_arity_predicate_specifier(in, out) is det.
+:- pred make_arity_predicate_specifier(sym_name_specifier::in,
+ pred_specifier::out) is det.
make_arity_predicate_specifier(Result, sym(Result)).
@@ -3351,8 +3354,8 @@
% Parsing the name & argument types of a constructor specifier is
% exactly the same as parsing a predicate specifier...
-:- pred parse_arg_types_specifier(term, maybe1(pred_specifier)).
-:- mode parse_arg_types_specifier(in, out) is det.
+:- pred parse_arg_types_specifier(term::in, maybe1(pred_specifier)::out)
+ is det.
parse_arg_types_specifier(Term, Result) :-
(
@@ -3370,21 +3373,23 @@
% ... but we have to convert the result back into the appropriate
% format.
-:- pred process_typed_constructor_specifier(maybe1(pred_specifier),
- maybe1(type), maybe1(cons_specifier)).
-:- mode process_typed_constructor_specifier(in, in, out) is det.
+:- pred process_typed_constructor_specifier(maybe1(pred_specifier)::in,
+ maybe1(type)::in, maybe1(cons_specifier)::out) is det.
+
process_typed_constructor_specifier(error(Msg, Term), _, error(Msg, Term)).
process_typed_constructor_specifier(ok(_), error(Msg, Term), error(Msg, Term)).
process_typed_constructor_specifier(ok(NameArgs), ok(ResType), ok(Result)) :-
process_typed_cons_spec_2(NameArgs, ResType, Result).
-:- pred process_typed_cons_spec_2(pred_specifier, type, cons_specifier).
-:- mode process_typed_cons_spec_2(in, in, out) is det.
+:- pred process_typed_cons_spec_2(pred_specifier::in, (type)::in,
+ cons_specifier::out) is det.
+
process_typed_cons_spec_2(sym(Name), Res, typed(name_res(Name, Res))).
process_typed_cons_spec_2(name_args(Name, Args), Res,
- typed(name_args_res(Name, Args, Res))).
+ typed(name_args_res(Name, Args, Res))).
:- pred make_untyped_cons_spec(pred_specifier::in, cons_specifier::out) is det.
+
make_untyped_cons_spec(sym(Name), sym(Name)).
make_untyped_cons_spec(name_args(Name, Args), typed(name_args(Name, Args))).
@@ -3396,8 +3401,8 @@
% Matches only symbols of the specified arity.
%
-:- pred parse_symbol_name_specifier(term, maybe1(sym_name_specifier)).
-:- mode parse_symbol_name_specifier(in, out) is det.
+:- pred parse_symbol_name_specifier(term::in,
+ maybe1(sym_name_specifier)::out) is det.
parse_symbol_name_specifier(Term, Result) :-
root_module_name(DefaultModule),
@@ -3502,9 +3507,8 @@
)
).
-:- pred parse_implicitly_qualified_symbol_name(module_name, term,
- maybe1(sym_name)).
-:- mode parse_implicitly_qualified_symbol_name(in, in, out) is det.
+:- pred parse_implicitly_qualified_symbol_name(module_name::in, term::in,
+ maybe1(sym_name)::out) is det.
parse_implicitly_qualified_symbol_name(DefaultModName, Term, Result) :-
parse_symbol_name(Term, Result0),
@@ -3517,7 +3521,9 @@
SymName = qualified(ModName, _),
\+ match_sym_name(ModName, DefaultModName)
->
- Result = error("module qualifier in definition does not match preceding `:- module' declaration", Term)
+ Result = error("module qualifier in definition " ++
+ "does not match preceding `:- module' " ++
+ "declaration", Term)
;
unqualify_name(SymName, UnqualName),
Result = ok(qualified(DefaultModName, UnqualName))
@@ -3554,7 +3560,9 @@
\+ match_sym_name(ModName, DefaultModName)
->
term__coerce(Term, ErrorTerm),
- Result = error("module qualifier in definition does not match preceding `:- module' declaration", ErrorTerm)
+ Result = error("module qualifier in definition " ++
+ "does not match preceding `:- module' " ++
+ "declaration", ErrorTerm)
;
unqualify_name(SymName, UnqualName),
Result = ok(qualified(DefaultModName, UnqualName), Args)
@@ -3628,24 +3636,21 @@
%-----------------------------------------------------------------------------%
-% A FuncSpecifier is just a constructur name specifier.
-
-:- pred parse_function_specifier(term, maybe1(func_specifier)).
-:- mode parse_function_specifier(in, out) is det.
+ % A FuncSpecifier is just a constructor name specifier.
+ %
+:- pred parse_function_specifier(term::in, maybe1(func_specifier)::out) is det.
parse_function_specifier(Term, Result) :-
parse_constructor_specifier(Term, Result).
-% A TypeSpecifier is just a symbol name specifier.
-
-:- pred parse_type_specifier(term, maybe1(sym_name_specifier)).
-:- mode parse_type_specifier(in, out) is det.
+ % A TypeSpecifier is just a symbol name specifier.
+ %
+:- pred parse_type_specifier(term::in, maybe1(sym_name_specifier)::out) is det.
parse_type_specifier(Term, Result) :-
parse_symbol_name_specifier(Term, Result).
-% An ADT_Specifier is just a symbol name specifier.
-
-:- pred parse_adt_specifier(term, maybe1(sym_name_specifier)).
-:- mode parse_adt_specifier(in, out) is det.
+ % An ADT_Specifier is just a symbol name specifier.
+ %
+:- pred parse_adt_specifier(term::in, maybe1(sym_name_specifier)::out) is det.
parse_adt_specifier(Term, Result) :-
parse_symbol_name_specifier(Term, Result).
@@ -3654,8 +3659,7 @@
% For the moment, an OpSpecifier is just a symbol name specifier.
% XXX We should allow specifying the fixity of an operator
-:- pred parse_op_specifier(term, maybe1(op_specifier)).
-:- mode parse_op_specifier(in, out) is det.
+:- pred parse_op_specifier(term::in, maybe1(op_specifier)::out) is det.
parse_op_specifier(Term, Result) :-
parse_symbol_name_specifier(Term, R),
process_maybe1(make_op_specifier, R, Result).
@@ -3667,14 +3671,13 @@
% types are represented just as ordinary terms
-:- pred parse_type(term, maybe1(type)).
-:- mode parse_type(in, out) is det.
+:- pred parse_type(term::in, maybe1(type)::out) is det.
+
parse_type(T0, ok(T)) :-
convert_type(T0, T).
-:- pred convert_constructor_arg_list(module_name,
- list(term), list(constructor_arg)).
-:- mode convert_constructor_arg_list(in, in, out) is semidet.
+:- pred convert_constructor_arg_list(module_name::in,
+ list(term)::in, list(constructor_arg)::out) is semidet.
convert_constructor_arg_list(_, [], []).
convert_constructor_arg_list(ModuleName, [Term | Terms], [Arg | Args]) :-
@@ -3702,4 +3705,11 @@
root_module_name(unqualified("")).
%-----------------------------------------------------------------------------%
+
+:- func this_file = string.
+
+this_file = "prog_io.m".
+
+%-----------------------------------------------------------------------------%
+:- end_module prog_io.
%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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