[m-dev.] for review: EDCGs - diff part 2
Peter Nicholas MALKIN
pnmalk at students.cs.mu.oz.au
Fri Feb 4 00:33:20 AEDT 2000
Hi,
Detailed Desciption of Change:
compiler/make_hlds.m:
The EDCG transformation occurs in this file. The main predicates to do
this are transform/22, transform_goal/12 and transform_goal_2/13 (the
most important).
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.322
diff -u -r1.322 make_hlds.m
--- compiler/make_hlds.m 2000/01/25 04:09:47 1.322
+++ compiler/make_hlds.m 2000/02/02 08:05:23
@@ -27,6 +27,8 @@
:- import_module io, std_util, list, bool.
+:- type qual_info.
+
% parse_tree_to_hlds(ParseTree, MQInfo, EqvMap, HLDS, UndefTypes, UndefModes):
% Given MQInfo (returned by module_qual.m) and EqvMap (returned by
% equiv_type.m), converts ParseTree to HLDS.
@@ -54,7 +56,7 @@
:- import_module hlds_data, hlds_goal.
:- import_module prog_io, prog_io_goal, prog_io_dcg, prog_io_util, prog_out.
-:- import_module modules, module_qual, prog_util, options, hlds_out.
+:- import_module modules, module_qual, prog_util, options, hlds_out, edcg.
:- import_module make_tags, quantification, (inst), globals.
:- import_module code_util, unify_proc, special_pred, type_util, mode_util.
:- import_module mercury_to_mercury, passes_aux, clause_to_proc, inst_match.
@@ -62,36 +64,37 @@
:- import_module error_util.
:- import_module string, char, int, set, bintree, map, multi_map, require.
-:- import_module bag, term, varset, getopt, assoc_list, term_io.
+:- import_module term, varset, getopt, assoc_list, term_io.
parse_tree_to_hlds(module(Name, Items), MQInfo0, EqvMap, Module,
UndefTypes, UndefModes) -->
globals__io_get_globals(Globals),
{ mq_info_get_partial_qualifier_info(MQInfo0, PQInfo) },
{ module_info_init(Name, Globals, PQInfo, Module0) },
+ add_item_list_decls_pass_0(Items, Module0, Module1),
add_item_list_decls_pass_1(Items,
- item_status(local, may_be_unqualified), Module0, Module1),
+ item_status(local, may_be_unqualified), Module1, Module2),
globals__io_lookup_bool_option(statistics, Statistics),
maybe_report_stats(Statistics),
add_item_list_decls_pass_2(Items,
- item_status(local, may_be_unqualified), Module1, Module2),
+ item_status(local, may_be_unqualified), Module2, Module3),
maybe_report_stats(Statistics),
% balance the binary trees
- { module_info_optimize(Module2, Module3) },
+ { module_info_optimize(Module3, Module4) },
maybe_report_stats(Statistics),
{ init_qual_info(MQInfo0, EqvMap, Info0) },
- add_item_list_clauses(Items, local, Module3, Module4,
+ add_item_list_clauses(Items, local, Module4, Module5,
Info0, Info),
{ qual_info_get_mq_info(Info, MQInfo) },
{ mq_info_get_type_error_flag(MQInfo, UndefTypes) },
{ mq_info_get_mode_error_flag(MQInfo, UndefModes) },
{ mq_info_get_num_errors(MQInfo, MQ_NumErrors) },
- { module_info_num_errors(Module4, NumErrors0) },
+ { module_info_num_errors(Module5, NumErrors0) },
{ NumErrors is NumErrors0 + MQ_NumErrors },
- { module_info_set_num_errors(Module4, NumErrors, Module5) },
+ { module_info_set_num_errors(Module5, NumErrors, Module6) },
% the predid list is constructed in reverse order, for
% efficiency, so we return it to the correct order here.
- { module_info_reverse_predids(Module5, Module) }.
+ { module_info_reverse_predids(Module6, Module) }.
%-----------------------------------------------------------------------------%
@@ -102,6 +105,20 @@
%-----------------------------------------------------------------------------%
+ % pass 0:
+ % Add the hidden declarations one by one to the module.
+ % Must be done before the pred declarations.
+
+:- pred add_item_list_decls_pass_0(item_list, module_info, module_info,
+ io__state, io__state).
+:- mode add_item_list_decls_pass_0(in, in, out, di, uo) is det.
+
+add_item_list_decls_pass_0([], Module, Module) --> [].
+add_item_list_decls_pass_0([Item - Context | Items], Module0, Module)
+ -->
+ add_item_decl_pass_0(Item, Context, Module0, Module1),
+ add_item_list_decls_pass_0(Items, Module1, Module).
+
% pass 1:
% Add the declarations one by one to the module,
% except for type definitions and pragmas.
@@ -118,7 +135,7 @@
add_item_list_decls_pass_1(Items, Status1, Module1, Module).
% pass 2:
- % Add the type definitions and pragmas one by one to the module,
+ % Add the type definitions and pragmas one by one to the module
% and add default modes for functions with no mode declaration.
%
% Adding type definitions needs to come after we have added the
@@ -165,6 +182,21 @@
%-----------------------------------------------------------------------------%
+:- pred add_item_decl_pass_0(item, term__context, module_info, module_info,
+ io__state, io__state).
+:- mode add_item_decl_pass_0(in, in, in, out, di, uo) is det.
+
+add_item_decl_pass_0(Item, Context, Module0, Module) -->
+ ( { Item = htype_defn(_VarSet, Name, Htype) } ->
+ module_add_htype_defn(Module0, Name, Htype, Context, Module)
+ ; { Item = hmode_defn(_VarSet, Name, Hmode) } ->
+ module_add_hmode_defn(Module0, Name, Hmode, Context, Module)
+ ;
+ { Module = Module0 }
+ ).
+
+%-----------------------------------------------------------------------------%
+
% dispatch on the different types of items
:- pred add_item_decl_pass_1(item, prog_context, item_status,
@@ -172,14 +204,20 @@
:- mode add_item_decl_pass_1(in, in, in, in, out, out, di, uo) is det.
% skip clauses
-add_item_decl_pass_1(pred_clause(_, _, _, _), _, Status, Module, Status, Module)
- --> [].
+add_item_decl_pass_1(pred_clause(_, _, _, _, _), _, Status, Module, Status,
+ Module) --> [].
add_item_decl_pass_1(func_clause(_, _, _, _, _), _, Status, Module, Status,
Module) --> [].
add_item_decl_pass_1(type_defn(_, _, _), _, Status, Module, Status, Module)
--> [].
+add_item_decl_pass_1(htype_defn(_, _, _), _, Status,
+ Module, Status, Module) --> [].
+
+add_item_decl_pass_1(hmode_defn(_, _, _), _, Status,
+ Module, Status, Module) --> [].
+
add_item_decl_pass_1(inst_defn(VarSet, InstDefn, Cond), Context,
Status, Module0, Status, Module) -->
module_add_inst_defn(Module0, VarSet, InstDefn, Cond, Context,
@@ -191,12 +229,12 @@
Status, Module).
add_item_decl_pass_1(pred(TypeVarSet, InstVarSet, ExistQVars, PredName,
- TypesAndModes, MaybeDet, Cond, Purity, ClassContext),
- Context, Status, Module0, Status, Module) -->
+ TypesAndModes, HiddenForms, MaybeDet, Cond, Purity,
+ ClassContext), Context, Status, Module0, Status, Module) -->
{ init_markers(Markers) },
module_add_pred(Module0, TypeVarSet, InstVarSet, ExistQVars, PredName,
- TypesAndModes, MaybeDet, Cond, Purity, ClassContext, Markers,
- Context, Status, _, Module).
+ TypesAndModes, HiddenForms, MaybeDet, Cond, Purity,
+ ClassContext, Markers, Context, Status, _, Module).
add_item_decl_pass_1(func(TypeVarSet, InstVarSet, ExistQVars, FuncName,
TypesAndModes, RetTypeAndMode, MaybeDet, Cond, Purity,
@@ -332,6 +370,12 @@
module_add_type_defn(Module0, VarSet, TypeDefn, Cond, Context, Status,
Module).
+add_item_decl_pass_2(htype_defn(_,_,_), _Context,
+ Status, Module, Status, Module) --> [].
+
+add_item_decl_pass_2(hmode_defn(_,_,_), _Context,
+ Status, Module, Status, Module) --> [].
+
add_item_decl_pass_2(pragma(Pragma), Context, Status, Module0, Status, Module)
-->
%
@@ -520,13 +564,13 @@
add_item_decl_pass_2(assertion(_, _), _, Status, Module, Status, Module) --> [].
add_item_decl_pass_2(func_clause(_, _, _, _, _), _, Status, Module, Status,
Module) --> [].
-add_item_decl_pass_2(pred_clause(_, _, _, _), _, Status, Module, Status, Module)
- --> [].
+add_item_decl_pass_2(pred_clause(_, _, _, _, _), _, Status, Module, Status,
+ Module) --> [].
add_item_decl_pass_2(inst_defn(_, _, _), _, Status, Module, Status, Module)
--> [].
add_item_decl_pass_2(mode_defn(_, _, _), _, Status, Module, Status, Module)
--> [].
-add_item_decl_pass_2(pred(_, _, _, _, _, _, _, _, _),
+add_item_decl_pass_2(pred(_, _, _, _, _, _, _, _, _, _),
_, Status, Module, Status, Module) --> [].
add_item_decl_pass_2(pred_mode(_, _, _, _, _), _, Status, Module, Status,
Module) --> [].
@@ -612,20 +656,24 @@
{ IsAssertion = no },
module_add_func_clause(Module0, VarSet, PredName, Args, Result, Body,
Status, Context, IsAssertion, Module, Info0, Info).
-add_item_clause(pred_clause(VarSet, PredName, Args, Body), Status, Status,
- Context, Module0, Module, Info0, Info) -->
+add_item_clause(pred_clause(VarSet, PredName, Args, Body, MaybeEDCG), Status,
+ Status, Context, Module0, Module, Info0, Info) -->
check_not_exported(Status, Context, "clause"),
{ IsAssertion = no },
module_add_pred_clause(Module0, VarSet, PredName, Args, Body, Status,
- Context, IsAssertion, Module, Info0, Info).
+ Context, IsAssertion, Module, MaybeEDCG, Info0, Info).
add_item_clause(type_defn(_, _, _), Status, Status, _,
Module, Module, Info, Info) --> [].
add_item_clause(inst_defn(_, _, _), Status, Status, _,
Module, Module, Info, Info) --> [].
add_item_clause(mode_defn(_, _, _), Status, Status, _,
+ Module, Module, Info, Info) --> [].
+add_item_clause(htype_defn(_, _, _), Status, Status, _,
Module, Module, Info, Info) --> [].
-add_item_clause(pred(_, _, _, _, _, _, _, _, _), Status, Status, _,
+add_item_clause(hmode_defn(_, _, _), Status, Status, _,
Module, Module, Info, Info) --> [].
+add_item_clause(pred(_, _, _, _, _, _, _, _, _, _), Status, Status, _,
+ Module, Module, Info, Info) --> [].
add_item_clause(func(_, _, _, FuncName, TypesAndModes, _, _, _, _, _),
Status, Status, Context, Module, Module, Info, Info) -->
{ list__length(TypesAndModes, FuncArity) },
@@ -737,7 +785,7 @@
{ IsAssertion = yes },
module_add_pred_clause(Module0, VarSet, unqualified(Name),
HeadVars, Goal, Status, Context, IsAssertion, Module,
- Info0, Info).
+ no, Info0, Info).
add_item_clause(nothing, Status, Status, _, Module, Module, Info, Info) --> [].
add_item_clause(typeclass(_, _, _, _, _),
@@ -2171,17 +2219,17 @@
%-----------------------------------------------------------------------------%
:- pred module_add_pred(module_info, tvarset, inst_varset, existq_tvars,
- sym_name, list(type_and_mode), maybe(determinism), condition,
- purity, class_constraints, pred_markers, prog_context,
- item_status, maybe(pair(pred_id, proc_id)), module_info,
- io__state, io__state).
+ sym_name, list(type_and_mode), hidden_forms,
+ maybe(determinism), condition, purity, class_constraints,
+ pred_markers, prog_context, item_status, maybe(pair(pred_id,
+ proc_id)), module_info, io__state, io__state).
:- mode module_add_pred(in, in, in, in, in, in, in, in, in, in, in, in, in,
- out, out, di, uo) is det.
+ in, out, out, di, uo) is det.
module_add_pred(Module0, TypeVarSet, InstVarSet, ExistQVars, PredName,
- TypesAndModes, MaybeDet, Cond, Purity, ClassContext, Markers,
- Context, item_status(Status, NeedQual), MaybePredProcId,
- Module) -->
+ TypesAndModes, FormAndName, MaybeDet, Cond, Purity,
+ ClassContext, Markers, Context, item_status(Status, NeedQual),
+ MaybePredProcId, Module) -->
% Only preds with opt_imported clauses are tagged as opt_imported, so
% that the compiler doesn't look for clauses for other preds read in
% from optimization interfaces.
@@ -2191,9 +2239,9 @@
DeclStatus = Status
},
{ split_types_and_modes(TypesAndModes, Types, MaybeModes) },
- add_new_pred(Module0, TypeVarSet, ExistQVars, PredName, Types, Cond,
- Purity, ClassContext, Markers, Context, DeclStatus, NeedQual,
- predicate, Module1),
+ add_new_pred(Module0, TypeVarSet, ExistQVars, PredName, Types,
+ FormAndName, Cond, Purity, ClassContext, Markers, Context,
+ DeclStatus, NeedQual, predicate, Module1),
(
{ MaybeModes = yes(Modes) },
@@ -2236,9 +2284,9 @@
{ split_types_and_modes(TypesAndModes, Types, MaybeModes) },
{ split_type_and_mode(RetTypeAndMode, RetType, MaybeRetMode) },
{ list__append(Types, [RetType], Types1) },
- add_new_pred(Module0, TypeVarSet, ExistQVars, FuncName, Types1, Cond,
- Purity, ClassContext, Markers, Context, DeclStatus, NeedQual,
- function, Module1),
+ add_new_pred(Module0, TypeVarSet, ExistQVars, FuncName, Types1, [],
+ Cond, Purity, ClassContext, Markers, Context, DeclStatus,
+ NeedQual, function, Module1),
(
{ MaybeModes = yes(Modes) },
{ MaybeRetMode = yes(RetMode) }
@@ -2372,7 +2420,7 @@
{ init_markers(Markers0) },
{ add_marker(Markers0, class_method, Markers) },
module_add_pred(Module0, TypeVarSet, InstVarSet, ExistQVars,
- PredName, TypesAndModes, MaybeDet, Cond, pure,
+ PredName, TypesAndModes, [], MaybeDet, Cond, pure,
NewClassContext, Markers, Context, Status,
MaybePredIdProcId, Module)
;
@@ -2534,32 +2582,32 @@
%-----------------------------------------------------------------------------%
:- pred add_new_pred(module_info, tvarset, existq_tvars, sym_name, list(type),
- condition, purity, class_constraints, pred_markers,
- prog_context, import_status, need_qualifier,
- pred_or_func, module_info, io__state, io__state).
-:- mode add_new_pred(in, in, in, in, in, in, in, in, in, in, in, in, in, out,
- di, uo) is det.
+ hidden_forms, condition, purity,
+ class_constraints, pred_markers, prog_context, import_status,
+ need_qualifier, pred_or_func, module_info, io__state,
+ io__state).
+:- mode add_new_pred(in, in, in, in, in, in, in, in, in, in, in, in, in, in,
+ out, di, uo) is det.
% NB. Predicates are also added in lambda.m, which converts
% lambda expressions into separate predicates, so any changes may need
% to be reflected there too.
-add_new_pred(Module0, TVarSet, ExistQVars, PredName, Types, Cond, Purity,
- ClassContext, Markers0, Context, Status, NeedQual,
+add_new_pred(Module0, TVarSet, ExistQVars, PredName, Types0, FormsAndNames,
+ Cond, Purity, ClassContext, Markers0, Context, Status, NeedQual,
PredOrFunc, Module) -->
{ module_info_name(Module0, ModuleName) },
- { list__length(Types, Arity) },
+ { list__length(Types0, VisualArity) },
(
- { PredName = unqualified(_PName) },
- { module_info_incr_errors(Module0, Module) },
- unqualified_pred_error(PredName, Arity, Context)
- % All predicate names passed into this predicate should have
- % been qualified by prog_io.m, when they were first read.
- ;
- { PredName = qualified(MNameOfPred, PName) },
+ { PredName = qualified(MNameOfPred, PName) }
+ ->
+ { edcg__get_hidden_pred_types(Module0, FormsAndNames,
+ HiddenTypes) },
+ { list__append(Types0, HiddenTypes, Types) },
+ { list__length(Types, TotalArity) },
{ Module1 = Module0 },
{ module_info_get_predicate_table(Module1, PredicateTable0) },
- { clauses_info_init(Arity, ClausesInfo) },
+ { clauses_info_init(TotalArity, ClausesInfo) },
{ map__init(Proofs) },
{ purity_to_markers(Purity, PurityMarkers) },
{ markers_to_marker_list(PurityMarkers, MarkersList) },
@@ -2570,15 +2618,27 @@
)) },
{ list__foldl(AddMarker, MarkersList, Markers0, Markers) },
globals__io_lookup_string_option(aditi_user, Owner),
- { pred_info_init(ModuleName, PredName, Arity, TVarSet,
- ExistQVars, Types,
- Cond, Context, ClausesInfo, Status, Markers,
- none, PredOrFunc, ClassContext, Proofs,
- Owner, PredInfo0) },
+ { pred_info_init(ModuleName, PredName, TotalArity, VisualArity,
+ TVarSet, ExistQVars, Types, FormsAndNames, Cond,
+ Context, ClausesInfo, Status, Markers, none,
+ PredOrFunc, ClassContext, Proofs, Owner,
+ PredInfo0) },
(
- { predicate_table_search_pf_m_n_a(PredicateTable0,
- PredOrFunc, MNameOfPred, PName, Arity,
- [OrigPred|_]) }
+ (
+ { predicate_table_search_pf_m_n_a(
+ PredicateTable0, PredOrFunc,
+ MNameOfPred, PName, TotalArity,
+ [OrigPred0|_]) }
+ ->
+ { ArityType = "total" },
+ { OrigPred = OrigPred0 }
+ ;
+ { predicate_table_search_pf_m_n_a(
+ PredicateTable0, PredOrFunc,
+ MNameOfPred, PName, VisualArity,
+ [OrigPred|_]) },
+ { ArityType = "visual" }
+ )
->
( { Status \= opt_imported } ->
{ module_info_incr_errors(Module1, Module) },
@@ -2588,10 +2648,9 @@
OrigContext) },
{ hlds_out__pred_or_func_to_str(PredOrFunc,
DeclString) },
- { adjust_func_arity(PredOrFunc,
- OrigArity, Arity) },
- multiple_def_error(PredName, OrigArity,
- DeclString, Context, OrigContext)
+ multiple_def_error(PredName, VisualArity,
+ DeclString, ArityType, Context,
+ OrigContext)
;
% This can happen for exported external preds.
{ Module = Module0 }
@@ -2615,9 +2674,17 @@
;
{ PredicateTable = PredicateTable1 }
),
- { module_info_set_predicate_table(Module1,
+ edcg__check_for_dups(FormsAndNames, PredId, Context,
+ Module1, Module2),
+ { module_info_set_predicate_table(Module2,
PredicateTable, Module) }
)
+ ;
+ % { PredName = unqualified(_PName) }
+ { module_info_incr_errors(Module0, Module) },
+ unqualified_pred_error(PredName, VisualArity, Context)
+ % All predicate names passed into this predicate should have
+ % been qualified by prog_io.m, when they were first read.
).
:- pred maybe_check_field_access_function(sym_name, arity, import_status,
@@ -2904,6 +2971,7 @@
{ module_info_name(ModuleInfo0, ModuleName0) },
{ sym_name_get_module_name(PredName, ModuleName0, ModuleName) },
+ % This is the visual arity.
{ list__length(Modes, Arity) },
{ module_info_get_predicate_table(ModuleInfo0, PredicateTable0) },
(
@@ -2923,40 +2991,43 @@
{ module_info_get_predicate_table(ModuleInfo1, PredicateTable1) },
{ predicate_table_get_preds(PredicateTable1, Preds0) },
{ map__lookup(Preds0, PredId, PredInfo0) },
-
- module_do_add_mode(PredInfo0, Arity, Modes, MaybeDet, MContext,
- PredInfo, ProcId),
+ module_do_add_mode(PredInfo0, PredId, Modes, MaybeDet, MContext,
+ PredInfo, ProcId, ModuleInfo1, ModuleInfo2),
{ map__det_update(Preds0, PredId, PredInfo, Preds) },
{ predicate_table_set_preds(PredicateTable1, Preds, PredicateTable) },
- { module_info_set_predicate_table(ModuleInfo0, PredicateTable,
+ { module_info_set_predicate_table(ModuleInfo2, PredicateTable,
ModuleInfo) },
{ PredProcId = PredId - ProcId }.
-:- pred module_do_add_mode(pred_info, arity, list(mode), maybe(determinism),
- prog_context, pred_info, proc_id, io__state, io__state).
-:- mode module_do_add_mode(in, in, in, in, in, out, out, di, uo) is det.
+:- pred module_do_add_mode(pred_info, pred_id, list(mode), maybe(determinism),
+ prog_context, pred_info, proc_id,
+ module_info, module_info, io__state, io__state).
+:- mode module_do_add_mode(in, in, in, in, in, out, out, in, out,
+ di, uo) is det.
-module_do_add_mode(PredInfo0, Arity, Modes, MaybeDet, MContext,
- PredInfo, ProcId) -->
+module_do_add_mode(PredInfo0, PredId, Modes0, MaybeDet, MContext,
+ PredInfo, ProcId, ModuleInfo0, ModuleInfo) -->
% check that the determinism was specified
+ { pred_info_get_is_pred_or_func(PredInfo0, PredOrFunc) },
+ { pred_info_name(PredInfo0, PredName) },
+ { pred_info_module(PredInfo0, PredModule) },
+ { pred_info_arity(PredInfo0, TotalArity) },
+ { pred_info_visual_arity(PredInfo0, VisualArity) },
+ { PredSymName = qualified(PredModule, PredName) },
(
{ MaybeDet = no }
->
{ pred_info_import_status(PredInfo0, ImportStatus) },
- { pred_info_get_is_pred_or_func(PredInfo0, PredOrFunc) },
- { pred_info_module(PredInfo0, PredModule) },
- { pred_info_name(PredInfo0, PredName) },
- { PredSymName = qualified(PredModule, PredName) },
( { status_is_exported(ImportStatus, yes) } ->
- unspecified_det_for_exported(PredSymName, Arity,
+ unspecified_det_for_exported(PredSymName, VisualArity,
PredOrFunc, MContext)
;
globals__io_lookup_bool_option(infer_det, InferDet),
(
{ InferDet = no }
->
- unspecified_det_for_local(PredSymName, Arity,
- PredOrFunc, MContext)
+ unspecified_det_for_local(PredSymName,
+ VisualArity, PredOrFunc, MContext)
;
[]
)
@@ -2964,10 +3035,13 @@
;
[]
),
-
+ { pred_info_hidden_args(PredInfo0, FormsAndNames) },
+ edcg__get_hidden_pred_modes(FormsAndNames, Modes1, PredId,
+ MContext, ModuleInfo0, ModuleInfo),
+ { list__append(Modes0, Modes1, Modes) },
% add the mode declaration to the pred_info for this procedure.
{ ArgLives = no },
- { add_new_proc(PredInfo0, Arity, Modes, yes(Modes), ArgLives,
+ { add_new_proc(PredInfo0, TotalArity, Modes, yes(Modes), ArgLives,
MaybeDet, MContext, address_is_not_taken, PredInfo, ProcId) }.
% Whenever there is a clause or mode declaration for an undeclared
@@ -3085,12 +3159,13 @@
:- pred module_add_pred_clause(module_info, prog_varset, sym_name,
list(prog_term), goal, import_status, prog_context,
- bool, module_info, qual_info, qual_info, io__state, io__state).
-:- mode module_add_pred_clause(in, in, in, in, in, in, in, in, out,
+ bool, module_info, maybe_edcg, qual_info, qual_info, io__state,
+ io__state).
+:- mode module_add_pred_clause(in, in, in, in, in, in, in, in, out, in,
in, out, di, uo) is det.
module_add_pred_clause(ModuleInfo0, ClauseVarSet, PredName, Args, Body,
- Status, Context, IsAssertion, ModuleInfo,
+ Status, Context, IsAssertion, ModuleInfo, MaybeEDCG,
Info0, Info) -->
% print out a progress message
globals__io_lookup_bool_option(very_verbose, VeryVerbose),
@@ -3103,7 +3178,7 @@
[]
),
module_add_clause(ModuleInfo0, ClauseVarSet, PredName, Args, Body,
- Status, Context, predicate, IsAssertion, ModuleInfo,
+ Status, Context, predicate, IsAssertion, ModuleInfo, MaybeEDCG,
Info0, Info).
:- pred module_add_func_clause(module_info, prog_varset, sym_name,
@@ -3127,17 +3202,18 @@
),
{ list__append(Args0, [Result], Args) },
module_add_clause(ModuleInfo0, ClauseVarSet, FuncName, Args, Body,
- Status, Context, function, IsAssertion, ModuleInfo,
+ Status, Context, function, IsAssertion, ModuleInfo, no,
Info0, Info).
:- pred module_add_clause(module_info, prog_varset, sym_name, list(prog_term),
goal, import_status, prog_context, pred_or_func, bool,
- module_info, qual_info, qual_info, io__state, io__state).
-:- mode module_add_clause(in, in, in, in, in, in, in, in, in,
- out, in, out, di, uo) is det.
+ module_info, maybe_edcg, qual_info, qual_info, io__state,
+ io__state).
+:- mode module_add_clause(in, in, in, in, in, in, in, in, in, out,
+ in, in, out, di, uo) is det.
module_add_clause(ModuleInfo0, ClauseVarSet, PredName, Args, Body, Status,
- Context, PredOrFunc, IsAssertion, ModuleInfo,
+ Context, PredOrFunc, IsAssertion, ModuleInfo, MaybeEDCG,
Info0, Info) -->
% Lookup the pred declaration in the predicate table.
% (If it's not there, call maybe_undefined_pred_error
@@ -3271,12 +3347,35 @@
{ maybe_add_default_func_mode(PredInfo1, PredInfo2, _) },
{ pred_info_procedures(PredInfo2, Procs) },
{ map__keys(Procs, ModeIds) },
+ { module_info_edcgs(ModuleInfo0, EDCGTable) },
+ { edcg_table_get_hidden_info(EDCGTable, HiddenInfo0) },
+ { pred_info_hidden_args(PredInfo2, FormAndNames0) },
+ (
+ % EDCG warning edcg clause without "-->>" functor.
+ { MaybeEDCG = no },
+ { Body \= true - _ }, % not a fact
+ { FormAndNames0 = [_|_] }
+ ->
+ % XXX: magic number 0 for indenting
+ { error_util__describe_one_pred_name(ModuleInfo0,
+ PredId, PredDescription) },
+ { error_util__list_to_pieces(["Warning:",
+ PredDescription,
+ "should have `-->>' as functor."], Formats) },
+ error_util__report_warning(Context, 0, Formats),
+ { FormAndNames = [] }
+ ;
+ { FormAndNames = FormAndNames0 }
+ ),
clauses_info_add_clause(Clauses0, PredId, ModeIds,
ClauseVarSet, TVarSet0, Args, Body, Context,
PredOrFunc, Arity, IsAssertion, Goal,
VarSet, TVarSet, Clauses, Warnings,
- ModuleInfo1, ModuleInfo2, Info0, Info),
- {
+ ModuleInfo1, ModuleInfo2, Info0, Info, FormAndNames,
+ PredicateTable2, HiddenInfo0, HiddenInfo),
+ edcg__maybe_hidden_error(HiddenInfo, PredId, ModuleInfo2,
+ ModuleInfo3),
+ {
pred_info_set_clauses_info(PredInfo2, Clauses, PredInfo3),
(
IsAssertion = yes
@@ -3305,7 +3404,7 @@
map__det_update(Preds0, PredId, PredInfo, Preds),
predicate_table_set_preds(PredicateTable2, Preds,
PredicateTable),
- module_info_set_predicate_table(ModuleInfo2, PredicateTable,
+ module_info_set_predicate_table(ModuleInfo3, PredicateTable,
ModuleInfo)
},
( { Status \= opt_imported } ->
@@ -3489,8 +3588,6 @@
% lookup some information we need from the pred_info and proc_info
%
{ pred_info_get_is_pred_or_func(PredInfo0, PredOrFunc) },
- { pred_info_module(PredInfo0, PredModule) },
- { pred_info_name(PredInfo0, PredName) },
{ pred_info_clauses_info(PredInfo0, Clauses0) },
{ pred_info_arg_types(PredInfo0, ArgTypes) },
{ pred_info_get_purity(PredInfo0, Purity) },
@@ -3532,8 +3629,7 @@
{ PragmaImpl = ordinary(C_Code, no) },
clauses_info_add_pragma_c_code(Clauses0, Purity, Attributes,
PredId, ProcId, VarSet, PragmaVars, ArgTypes, PragmaImpl,
- Context, PredOrFunc, qualified(PredModule, PredName),
- Arity, Clauses, Info0, Info),
+ Context, PredOrFunc, Arity, Clauses, Info0, Info),
%
% Store the clauses_info etc. back into the pred_info
@@ -3670,6 +3766,61 @@
%-----------------------------------------------------------------------------%
+:- pred module_add_htype_defn(module_info, sym_name, htype_defn, term__context,
+ module_info, io__state, io__state).
+:- mode module_add_htype_defn(in, in, in, in, out, di, uo) is det.
+
+module_add_htype_defn(Module0, HiddenArg, HtypeDefn, Context, Module) -->
+ { module_info_edcgs(Module0, EDCGTable0) },
+ (
+ % Checks to see if declaration is duplicated.
+ { edcg_table_fetch_context(EDCGTable0, HiddenArg, hidden_type,
+ OriginalContext) }
+ ->
+ % Mutiple htype declarations.
+ { module_info_incr_errors(Module0, Module) },
+ multiply_defined_hidden_error(HiddenArg, hidden_type, Context,
+ OriginalContext)
+ ;
+ { edcg_table_add_htype(EDCGTable0, HiddenArg, HtypeDefn,
+ Context, EDCGTable) },
+ { module_info_set_edcgs(Module0, EDCGTable, Module) }
+ ).
+
+:- pred module_add_hmode_defn(module_info, sym_name, hmode_defn, term__context,
+ module_info, io__state, io__state).
+:- mode module_add_hmode_defn(in, in, in, in, out, di, uo) is det.
+
+module_add_hmode_defn(Module0, HiddenArg, HmodeDefn, Context, Module) -->
+ { module_info_edcgs(Module0, EDCGTable0) },
+ (
+ % Checks to see if declaration is duplicated.
+ { edcg_table_fetch_context(EDCGTable0, HiddenArg, hidden_mode,
+ OriginalContext) }
+ ->
+ % Mutiple hmode declarations.
+ { module_info_incr_errors(Module0, Module) },
+ multiply_defined_hidden_error(HiddenArg, hidden_mode, Context,
+ OriginalContext)
+ ;
+ { edcg_table_add_hmode(EDCGTable0, HiddenArg, HmodeDefn,
+ Context, EDCGTable) },
+ { module_info_set_edcgs(Module0, EDCGTable, Module) }
+ ).
+
+:- pred multiply_defined_hidden_error(sym_name, htype_or_hmode,
+ term__context, term__context, io__state, io__state).
+:- mode multiply_defined_hidden_error(in, in, in, in, di, uo) is det.
+
+multiply_defined_hidden_error(HiddenName, HtypeOrHmode, Context,
+ OriginalContext) -->
+ { htype_or_hmode_to_string(HtypeOrHmode, DeclString) },
+ multiple_def_error(HiddenName, 0, DeclString, Context,
+ OriginalContext).
+
+
+%-----------------------------------------------------------------------------%
+
:- pred module_add_pragma_c_code(pragma_c_code_attributes, sym_name,
pred_or_func, list(pragma_var), prog_varset, pragma_c_code_impl,
import_status, prog_context, module_info, module_info,
@@ -3761,8 +3912,7 @@
clauses_info_add_pragma_c_code(Clauses0, Purity,
Attributes, PredId, ProcId, VarSet,
PVars, ArgTypes, PragmaImpl, Context,
- PredOrFunc, PredName, Arity,
- Clauses, Info0, Info),
+ PredOrFunc, Arity, Clauses, Info0, Info),
{ pred_info_set_clauses_info(PredInfo1, Clauses,
PredInfo2) },
{ pred_info_set_goal_type(PredInfo2, pragmas,
@@ -4706,12 +4856,15 @@
hlds_goal::out, prog_varset::out, tvarset::out,
clauses_info::out, list(quant_warning)::out,
module_info::in, module_info::out, qual_info::in,
- qual_info::out, io__state::di, io__state::uo) is det.
+ qual_info::out, hidden_forms::in,
+ predicate_table::in, hidden_info::in,
+ hidden_info::out, io__state::di, io__state::uo) is det.
clauses_info_add_clause(ClausesInfo0, PredId, ModeIds, CVarSet, TVarSet0,
Args, Body, Context, PredOrFunc, Arity, IsAssertion, Goal,
VarSet, TVarSet0, ClausesInfo, Warnings, Module0, Module,
- Info0, Info) -->
+ Info0, Info, FormsAndNames, PredTable,
+ HiddenInfo0, HiddenInfo) -->
{ ClausesInfo0 = clauses_info(VarSet0, VarTypes0, VarTypes1,
HeadVars, ClauseList0,
TI_VarMap, TCI_VarMap) },
@@ -4719,7 +4872,8 @@
{ varset__merge_subst(VarSet0, CVarSet, VarSet1, Subst) },
transform(Subst, HeadVars, Args, Body, VarSet1, Context, PredOrFunc,
Arity, IsAssertion, Goal0, VarSet, Warnings,
- Module0, Module, Info1, Info2),
+ Module0, Module, Info1, Info2, FormsAndNames,
+ PredTable, HiddenInfo0, HiddenInfo),
{ qual_info_get_found_syntax_error(Info2, FoundError) },
{ qual_info_set_found_syntax_error(no, Info2, Info) },
(
@@ -4754,94 +4908,48 @@
:- pred clauses_info_add_pragma_c_code(clauses_info, purity,
pragma_c_code_attributes, pred_id, proc_id, prog_varset,
list(pragma_var), list(type), pragma_c_code_impl, prog_context,
- pred_or_func, sym_name, arity, clauses_info, qual_info,
+ pred_or_func, arity, clauses_info, qual_info,
qual_info, io__state, io__state) is det.
:- mode clauses_info_add_pragma_c_code(in, in, in, in, in, in, in, in, in, in,
- in, in, in, out, in, out, di, uo) is det.
+ in, in, out, in, out, di, uo) is det.
clauses_info_add_pragma_c_code(ClausesInfo0, Purity, Attributes, PredId,
ModeId, PVarSet, PVars, OrigArgTypes, PragmaImpl, Context,
- PredOrFunc, PredName, Arity, ClausesInfo, Info0, Info) -->
+ PredOrFunc, Arity, ClausesInfo, Info0, Info) -->
{
ClausesInfo0 = clauses_info(VarSet0, VarTypes, VarTypes1,
HeadVars, ClauseList, TI_VarMap, TCI_VarMap),
pragma_get_vars(PVars, Args0),
pragma_get_var_infos(PVars, ArgInfo),
- %
- % Check for arguments occurring multiple times.
- %
- bag__init(ArgBag0),
- bag__insert_list(ArgBag0, Args0, ArgBag),
- bag__to_assoc_list(ArgBag, ArgBagAL0),
- list__filter(
- (pred(Arg::in) is semidet :-
- Arg = _ - Occurrences,
- Occurrences > 1
- ), ArgBagAL0, ArgBagAL),
- assoc_list__keys(ArgBagAL, MultipleArgs)
- },
-
- ( { MultipleArgs = [_ | _] } ->
- { ClausesInfo = ClausesInfo0 },
- { Info = Info0 },
- prog_out__write_context(Context),
- io__write_string("In `:- pragma c_code' declaration for "),
- { adjust_func_arity(PredOrFunc, OrigArity, Arity) },
- hlds_out__write_simple_call_id(
- PredOrFunc - PredName/OrigArity),
- io__write_string(":\n"),
- prog_out__write_context(Context),
- io__write_string(" error: "),
- (
- { MultipleArgs = [MultipleArg] },
- io__write_string("variable `"),
- mercury_output_var(MultipleArg, PVarSet, no),
- io__write_string("' occurs multiple times\n")
- ;
- { MultipleArgs = [_, _ | _] },
- io__write_string("variables `"),
- mercury_output_vars(MultipleArgs, PVarSet, no),
- io__write_string(
- "' occur multiple times\n")
- ),
- prog_out__write_context(Context),
- io__write_string(" in the argument list.\n"),
- io__set_exit_status(1)
- ;
% merge the varsets of the proc and the new pragma_c_code
- {
- varset__merge_subst(VarSet0, PVarSet, VarSet1, Subst),
- map__apply_to_list(Args0, Subst, TermArgs),
- term__term_list_to_var_list(TermArgs, Args),
-
- % build the pragma_c_code
- goal_info_init(GoalInfo0),
- goal_info_set_context(GoalInfo0, Context, GoalInfo1),
- % Put the purity in the goal_info in case
- % this c code is inlined
- add_goal_info_purity_feature(GoalInfo1, Purity, GoalInfo),
- HldsGoal0 = pragma_c_code(Attributes, PredId, ModeId, Args,
- ArgInfo, OrigArgTypes, PragmaImpl) - GoalInfo
- },
- % Apply unifications with the head args.
- % Since the set of head vars and the set vars in the
- % pragma C code are disjoint, the unifications can be
- % implemented as substitutions, and they will be.
- insert_arg_unifications(HeadVars, TermArgs, Context,
- head(PredOrFunc, Arity), yes, HldsGoal0, VarSet1,
- HldsGoal1, VarSet2, Info0, Info),
- {
- map__init(Empty),
- implicitly_quantify_clause_body(HeadVars, HldsGoal1,
- VarSet2, Empty, HldsGoal, VarSet, _, _Warnings),
- NewClause = clause([ModeId], HldsGoal, Context),
- ClausesInfo = clauses_info(VarSet, VarTypes, VarTypes1,
- HeadVars, [NewClause|ClauseList],
- TI_VarMap, TCI_VarMap)
- }
- ).
-
+ varset__merge_subst(VarSet0, PVarSet, VarSet1, Subst),
+ map__apply_to_list(Args0, Subst, TermArgs),
+ term__term_list_to_var_list(TermArgs, Args),
+
+ % build the pragma_c_code
+ goal_info_init(GoalInfo0),
+ goal_info_set_context(GoalInfo0, Context, GoalInfo1),
+ % Put the purity in the goal_info in case this c code is inlined
+ add_goal_info_purity_feature(GoalInfo1, Purity, GoalInfo),
+ HldsGoal0 = pragma_c_code(Attributes, PredId, ModeId, Args,
+ ArgInfo, OrigArgTypes, PragmaImpl) - GoalInfo
+ },
+ % Apply unifications with the head args.
+ % Since the set of head vars and the set vars in the
+ % pragma C code are disjoint, the unifications can be
+ % implemented as substitutions, and they will be.
+ insert_arg_unifications(HeadVars, TermArgs, Context,
+ head(PredOrFunc, Arity), yes, HldsGoal0, VarSet1,
+ HldsGoal1, VarSet2, Info0, Info),
+ {
+ map__init(Empty),
+ implicitly_quantify_clause_body(HeadVars, HldsGoal1, VarSet2, Empty,
+ HldsGoal, VarSet, _, _Warnings),
+ NewClause = clause([ModeId], HldsGoal, Context),
+ ClausesInfo = clauses_info(VarSet, VarTypes, VarTypes1, HeadVars,
+ [NewClause|ClauseList], TI_VarMap, TCI_VarMap)
+ }.
:- pred allocate_vars_for_saved_vars(list(string), list(pair(prog_var, string)),
prog_varset, prog_varset).
@@ -4859,35 +4967,55 @@
prog_varset, prog_context, pred_or_func, arity, bool,
hlds_goal, prog_varset, list(quant_warning),
module_info, module_info, qual_info, qual_info,
+ hidden_forms, predicate_table,
+ hidden_info, hidden_info,
io__state, io__state).
-:- mode transform(in, in, in, in, in, in, in, in, in, out, out, out,
- in, out, in, out, di, uo) is det.
+:- mode transform(in, in, in, in, in, in, in, in, in, out, out, out, in,
+ out, in, out, in, in, in, out, di, uo) is det.
transform(Subst, HeadVars, Args0, Body, VarSet0, Context, PredOrFunc,
Arity, IsAssertion, Goal, VarSet, Warnings,
- Module0, Module, Info0, Info) -->
- transform_goal(Body, VarSet0, Subst, Goal1, VarSet1, Info0, Info1),
- { term__apply_substitution_to_list(Args0, Subst, Args) },
+ Module0, Module, Info0, Info, FormAndNames, PredTable,
+ HiddenInfo0, HiddenInfo) -->
+
+ % If Body is a fact then an underscore needs to be prefixed
+ % onto passed and consumed hidden arguments.
+ { ( Body = true - _ ->
+ Fact = yes
+ ;
+ Fact = no
+ ) },
+ { hidden_info_initial_state(FormAndNames, VarSet0, VarSet1, Fact,
+ HiddenInfo0, HiddenInfo1) },
+ transform_goal(Body, VarSet1, Subst, Goal1, VarSet2, Info0, Info1,
+ PredTable, HiddenInfo1, HiddenInfo2),
+ { edcg__get_hidden_head_args(FormAndNames, HiddenInfo1, HiddenInfo2,
+ HiddenArgs) },
+ { edcg__check_hidden_states(FormAndNames, Context,
+ HiddenInfo2, HiddenInfo) },
+ { list__append(Args0, HiddenArgs, Args1) },
+ { term__apply_substitution_to_list(Args1, Subst, Args) },
{ map__init(Empty) },
-
+
% The head variables of an assertion will always be
% variables, so it is unnecessary to insert unifications.
(
{ IsAssertion = yes }
->
{ Module = Module0 },
- { VarSet2 = VarSet1 },
+ { VarSet3 = VarSet2 },
{ Goal2 = Goal1 },
{ Info = Info0 }
;
{ Module = Module0 },
{ ArgContext = head(PredOrFunc, Arity) },
insert_arg_unifications(HeadVars, Args, Context, ArgContext,
- no, Goal1, VarSet1, Goal2, VarSet2, Info1, Info)
+ no, Goal1, VarSet2, Goal2, VarSet3, Info1, Info)
),
- { implicitly_quantify_clause_body(HeadVars, Goal2, VarSet2, Empty,
+ { implicitly_quantify_clause_body(HeadVars, Goal2, VarSet3, Empty,
Goal, VarSet, _, Warnings) }.
+
%-----------------------------------------------------------------------------%
% Convert goals from the prog_data `goal' structure into the
@@ -4904,107 +5032,146 @@
transform_goal(Goal0 - Context, VarSet0, Subst, Goal1 - GoalInfo1, VarSet,
Info0, Info) -->
+ { hidden_info_init(HiddenInfo) },
+ { predicate_table_init(PredTable) },
transform_goal_2(Goal0, Context, VarSet0, Subst, Goal1 - GoalInfo0,
- VarSet, Info0, Info),
+ VarSet, Info0, Info, PredTable, HiddenInfo, _),
{ goal_info_set_context(GoalInfo0, Context, GoalInfo1) }.
-:- pred transform_goal_2(goal_expr, prog_context, prog_varset,
- prog_substitution, hlds_goal, prog_varset,
- qual_info, qual_info, io__state, io__state).
-:- mode transform_goal_2(in, in, in, in, out, out, in, out, di, uo) is det.
+:- pred transform_goal(goal, prog_varset, prog_substitution, hlds_goal,
+ prog_varset, qual_info, qual_info, predicate_table,
+ hidden_info, hidden_info, io__state, io__state).
+:- mode transform_goal(in, in, in, out, out, in, out, in, in, out,
+ di, uo) is det.
+
+transform_goal(Goal0 - Context, VarSet0, Subst, Goal1 - GoalInfo1, VarSet,
+ Info0, Info, PredTable, HiddenInfo0, HiddenInfo) -->
+ transform_goal_2(Goal0, Context, VarSet0, Subst, Goal1 - GoalInfo0,
+ VarSet, Info0, Info, PredTable, HiddenInfo0, HiddenInfo),
+ { goal_info_set_context(GoalInfo0, Context, GoalInfo1) }.
+:- pred transform_goal_2(goal_expr, term__context, prog_varset,
+ prog_substitution, hlds_goal, prog_varset, qual_info, qual_info,
+ predicate_table, hidden_info, hidden_info, io__state,
+ io__state).
+:- mode transform_goal_2(in, in, in, in, out, out, in, out, in, in, out,
+ di, uo) is det.
+
transform_goal_2(fail, _, VarSet, _, disj([], Empty) - GoalInfo, VarSet,
- Info, Info) -->
+ Info, Info, _, HiddenInfo, HiddenInfo) -->
{ map__init(Empty) },
{ goal_info_init(GoalInfo) }.
transform_goal_2(true, _, VarSet, _, conj([]) - GoalInfo, VarSet,
- Info, Info) -->
+ Info, Info, _, HiddenInfo, HiddenInfo) -->
{ goal_info_init(GoalInfo) }.
% Convert `all [Vars] Goal' into `not some [Vars] not Goal'.
transform_goal_2(all(Vars0, Goal0), Context, VarSet0, Subst, Goal, VarSet,
- Info0, Info) -->
+ Info0, Info, PredTable, HiddenInfo0, HiddenInfo) -->
{ TransformedGoal = not(some(Vars0, not(Goal0) - Context) - Context) },
transform_goal_2(TransformedGoal, Context, VarSet0, Subst,
- Goal, VarSet, Info0, Info).
+ Goal, VarSet, Info0, Info, PredTable, HiddenInfo0, HiddenInfo).
transform_goal_2(some(Vars0, Goal0), _, VarSet0, Subst,
- some(Vars, can_remove, Goal) - GoalInfo,
- VarSet, Info0, Info) -->
+ some(Vars, can_remove, Goal) - GoalInfo, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo) -->
{ substitute_vars(Vars0, Subst, Vars) },
- transform_goal(Goal0, VarSet0, Subst, Goal, VarSet, Info0, Info),
+ transform_goal(Goal0, VarSet0, Subst, Goal, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo),
{ goal_info_init(GoalInfo) }.
-
-transform_goal_2(if_then_else(Vars0, A0, B0, C0), _, VarSet0, Subst,
- if_then_else(Vars, A, B, C, Empty) - GoalInfo, VarSet, Info0, Info)
- -->
+transform_goal_2(if_then_else(Vars0, A0, B0, C0), Context, VarSet0, Subst,
+ if_then_else(Vars, A, B, C, Empty) - GoalInfo, VarSet,
+ Info0, Info, PredTable, HiddenInfo0, HiddenInfo) -->
{ substitute_vars(Vars0, Subst, Vars) },
- transform_goal(A0, VarSet0, Subst, A, VarSet1, Info0, Info1),
- transform_goal(B0, VarSet1, Subst, B, VarSet2, Info1, Info2),
- transform_goal(C0, VarSet2, Subst, C, VarSet, Info2, Info),
+ transform_goal(A0, VarSet0, Subst, A, VarSet1, Info0, Info1,
+ PredTable, HiddenInfo0, HiddenInfo1),
+ transform_goal(B0, VarSet1, Subst, B1, VarSet2, Info1, Info2,
+ PredTable, HiddenInfo1, HiddenInfo2),
+ transform_goal(C0, VarSet2, Subst, C1, VarSet3, Info2, Info,
+ PredTable, HiddenInfo0, HiddenInfo3),
{ map__init(Empty) },
- { goal_info_init(GoalInfo) }.
+ { goal_info_init(GoalInfo) },
+ { edcg__update_if_then_else(B1, C1, Context, GoalInfo, VarSet3, VarSet,
+ HiddenInfo2, HiddenInfo3, HiddenInfo, B, C) }.
transform_goal_2(if_then(Vars0, A0, B0), Context, Subst, VarSet0,
- Goal, VarSet, Info0, Info) -->
+ Goal, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo) -->
transform_goal_2(if_then_else(Vars0, A0, B0, true - Context),
- Context, Subst, VarSet0, Goal, VarSet, Info0, Info).
-
-transform_goal_2(not(A0), _, VarSet0, Subst, Goal, VarSet, Info0, Info) -->
- transform_goal(A0, VarSet0, Subst, A, VarSet, Info0, Info),
- { goal_info_init(GoalInfo) },
- { Goal = not(A) - GoalInfo }.
-
-transform_goal_2((A0,B0), _, VarSet0, Subst, Goal, VarSet, Info0, Info) -->
- get_conj(B0, Subst, [], VarSet0, L0, VarSet1, Info0, Info1),
- get_conj(A0, Subst, L0, VarSet1, L, VarSet, Info1, Info),
- { goal_info_init(GoalInfo) },
- { conj_list_to_goal(L, GoalInfo, Goal) }.
-
-transform_goal_2((A0 & B0), _, VarSet0, Subst, Goal, VarSet, Info0, Info) -->
- get_par_conj(B0, Subst, [], VarSet0, L0, VarSet1, Info0, Info1),
- get_par_conj(A0, Subst, L0, VarSet1, L, VarSet, Info1, Info),
- { goal_info_init(GoalInfo) },
- { par_conj_list_to_goal(L, GoalInfo, Goal) }.
+ Context, Subst, VarSet0, Goal, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo).
-transform_goal_2((A0;B0), _, VarSet0, Subst, Goal, VarSet, Info0, Info) -->
- get_disj(B0, Subst, [], VarSet0, L0, VarSet1, Info0, Info1),
- get_disj(A0, Subst, L0, VarSet1, L, VarSet, Info1, Info),
+transform_goal_2(not(A0), _, VarSet0, Subst, Goal, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo) -->
+ transform_goal(A0, VarSet0, Subst, A, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo),
+ % eliminate double negations
+ { A = not(Goal1) - _ ->
+ Goal = Goal1
+ ;
+ goal_info_init(GoalInfo),
+ Goal = not(A) - GoalInfo
+ }.
+
+transform_goal_2((A0,B0), _, VarSet0, Subst, Goal, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo) -->
+ get_conj(A0, Subst, [], VarSet0, L0, VarSet1, Info0, Info1, PredTable,
+ HiddenInfo0, HiddenInfo1),
+ get_conj(B0, Subst, L0, VarSet1, L, VarSet, Info1, Info, PredTable,
+ HiddenInfo1, HiddenInfo),
+ { goal_info_init(GoalInfo) },
+ { conj_list_to_goal(L, GoalInfo, Goal) }.
+
+transform_goal_2((A0 & B0), _, VarSet0, Subst, Goal, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo) -->
+ get_par_conj(A0, Subst, [], VarSet0, L0, VarSet1, Info0, Info1,
+ PredTable, HiddenInfo0, HiddenInfo1),
+ get_par_conj(B0, Subst, L0, VarSet1, L, VarSet, Info1, Info,
+ PredTable, HiddenInfo1, HiddenInfo),
+ { goal_info_init(GoalInfo) },
+ { par_conj_list_to_goal(L, GoalInfo, Goal) }.
+
+transform_goal_2((A0;B0), _, VarSet0, Subst, Goal, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo) -->
+ get_disj(B0, Subst, [], VarSet0, L0, VarSet1, Info0, Info1,
+ PredTable, HiddenInfo0),
+ get_disj(A0, Subst, L0, VarSet1, L1, VarSet2, Info1, Info,
+ PredTable, HiddenInfo0),
{ goal_info_init(GoalInfo) },
+ { edcg__update_disj_list(L1, GoalInfo, VarSet2, VarSet, L,
+ HiddenInfo) },
{ disj_list_to_goal(L, GoalInfo, Goal) }.
transform_goal_2(implies(P, Q), Context, VarSet0, Subst, Goal, VarSet,
- Info0, Info) -->
- % `P => Q' is defined as `not (P, not Q)'
- { TransformedGoal = not( (P, not(Q) - Context) - Context ) },
- transform_goal_2(TransformedGoal, Context, VarSet0, Subst,
- Goal, VarSet, Info0, Info).
-
-transform_goal_2(equivalent(P0, Q0), _Context, VarSet0, Subst, Goal, VarSet,
- Info0, Info) -->
- %
- % `P <=> Q' is defined as `(P => Q), (Q => P)',
- % but that transformation must not be done until
- % after quantification analysis, lest the duplication of
- % the goals concerned affect the implicit quantification
- % of the variables inside them.
- %
- { goal_info_init(GoalInfo) },
- transform_goal(P0, VarSet0, Subst, P, VarSet1, Info0, Info1),
- transform_goal(Q0, VarSet1, Subst, Q, VarSet, Info1, Info),
- { Goal = bi_implication(P, Q) - GoalInfo }.
-
-transform_goal_2(call(Name, Args0, Purity), Context, VarSet0, Subst, Goal,
- VarSet, Info0, Info) -->
- (
- { Name = unqualified("\\=") },
- { Args0 = [LHS, RHS] }
- ->
- % `LHS \= RHS' is defined as `not (RHS = RHS)'
- transform_goal_2(not(unify(LHS, RHS) - Context), Context,
- VarSet0, Subst, Goal, VarSet, Info0, Info)
+ Info0, Info, PredTable, HiddenInfo0, HiddenInfo) -->
+ % `P => Q' is defined as `not (P, not Q)'
+ { TransformedGoal = not( (P, not(Q) - Context) - Context ) },
+ transform_goal_2(TransformedGoal, Context, VarSet0, Subst,
+ Goal, VarSet, Info0, Info, PredTable, HiddenInfo0, HiddenInfo).
+
+transform_goal_2(equivalent(P, Q), Context, VarSet0, Subst, Goal, VarSet,
+ Info0, Info, PredTable, HiddenInfo0, HiddenInfo) -->
+ % `P <=> Q' is defined as `(P => Q), (Q => P)'
+ { TransformedGoal = (implies(P, Q) - Context,
+ implies(Q, P) - Context) },
+ transform_goal_2(TransformedGoal, Context, VarSet0, Subst,
+ Goal, VarSet, Info0, Info, PredTable, HiddenInfo0, HiddenInfo).
+
+
+transform_goal_2(call(Name, VisualArgs0, HiddenArgs, Purity), Context,
+ VarSet0, Subst, Goal, VarSet, Info0, Info, PredTable,
+ HiddenInfo0, HiddenInfo) -->
+ (
+ { Name = unqualified("\\=") },
+ { VisualArgs0 = [LHS, RHS] },
+ { HiddenArgs = [] }
+ ->
+ % `LHS \= RHS' is defined as `not (RHS = RHS)'
+ transform_goal_2(not(unify(LHS, RHS) - Context), Context,
+ VarSet0, Subst, Goal, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo)
;
% check for a DCG field access goal:
% get: Field =^ field
@@ -5014,9 +5181,11 @@
; { Operator = ":=" }
)
->
- { term__apply_substitution_to_list(Args0, Subst, Args1) },
- transform_dcg_record_syntax(Operator, Args1, Context,
- VarSet0, Goal, VarSet, Info0, Info)
+ { term__apply_substitution_to_list(VisualArgs0, Subst,
+ VisualArgs1) },
+ transform_dcg_record_syntax(Operator, VisualArgs1, Context,
+ VarSet0, Goal, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo)
;
% check for an Aditi builtin
{ Purity = pure },
@@ -5028,86 +5197,169 @@
; Name1 = "aditi_modify"
}
->
- { term__apply_substitution_to_list(Args0, Subst, Args1) },
- transform_aditi_builtin(Name1, Args1, Context, VarSet0,
- Goal, VarSet, Info0, Info)
- ;
- { term__apply_substitution_to_list(Args0, Subst, Args) },
- { make_fresh_arg_vars(Args, VarSet0, HeadVars, VarSet1) },
- { list__length(Args, Arity) },
- (
- % check for a higher-order call,
- % i.e. a call to either call/N or ''/N.
- { Name = unqualified("call")
- ; Name = unqualified("")
- },
- { HeadVars = [PredVar | RealHeadVars] }
- ->
- {
- % initialize some fields to junk
- Modes = [],
- Det = erroneous,
-
- GenericCall = higher_order(PredVar,
- predicate, Arity),
- Call = generic_call(GenericCall,
- RealHeadVars, Modes, Det),
-
- hlds_goal__generic_call_id(GenericCall, CallId),
- Purity1 = pure
- },
- (
- { Purity = pure }
- ->
- []
- ;
- prog_out__write_context(Context),
- io__write_string("Warning: unnecessary `"),
- write_purity(Purity),
- io__write_string("' marker.\n"),
- prog_out__write_context(Context),
- io__write_string(" Higher-order goals are always pure.\n")
- )
- ;
- {
- % initialize some fields to junk
+ { term__apply_substitution_to_list(VisualArgs0, Subst,
+ VisualArgs1) },
+ transform_aditi_builtin(Name1, VisualArgs1, Context, VarSet0,
+ Goal, VarSet, Info0, Info),
+ { HiddenInfo = HiddenInfo0 }
+ ;
+ % EDCG goal
+ { Name = unqualified("-->>") },
+ { VisualArgs0 = [HiddenTerms, Body0] },
+ { HiddenArgs = [] }
+ ->
+ process_edcg_goal(HiddenTerms, Body0, VarSet0, Context, Subst,
+ Goal, VarSet, Info0, Info, PredTable, HiddenInfo0,
+ HiddenInfo)
+ ;
+ { edcg__add_hidden_args(Name, VisualArgs0, HiddenArgs,
+ VisualArgs1, VarSet0, VarSet1, Context, HiddenInfo0,
+ HiddenInfo1, PredTable) },
+ { term__apply_substitution_to_list(VisualArgs1, Subst,
+ VisualArgs) },
+ { make_fresh_arg_vars(VisualArgs, VarSet1, HeadVars, VarSet2) },
+ { list__length(VisualArgs, Arity) },
+ (
+ % check for a higher-order call,
+ % i.e. a call to either call/N or ''/N.
+ { Name = unqualified("call")
+ ; Name = unqualified("")
+ },
+ { HeadVars = [PredVar | RealHeadVars] }
+ ->
+ { % initialize some fields to junk
+ Modes = [],
+ Det = erroneous,
+
+ GenericCall = higher_order(PredVar,
+ predicate, Arity),
+ Call = generic_call(GenericCall,
+ RealHeadVars, Modes, Det),
+
+ hlds_goal__generic_call_id(GenericCall, CallId),
+ Purity1 = pure
+ },
+ (
+ { Purity = pure }
+ ->
+ []
+ ;
+ prog_out__write_context(Context),
+ io__write_string("Warning: unnecessary `"),
+ write_purity(Purity),
+ io__write_string("' marker.\n"),
+ prog_out__write_context(Context),
+ io__write_string(" Higher-order goals are always pure.\n")
+ )
+ ;
+ {
+ % initialize some fields to junk
invalid_pred_id(PredId),
- invalid_proc_id(ModeId),
+ invalid_proc_id(ModeId),
- MaybeUnifyContext = no,
- Call = call(PredId, ModeId, HeadVars, not_builtin,
- MaybeUnifyContext, Name),
+ MaybeUnifyContext = no,
+ Call = call(PredId, ModeId, HeadVars, not_builtin,
+ MaybeUnifyContext, Name),
CallId = call(predicate - Name/Arity),
- Purity1 = Purity
- }
- ),
- { goal_info_init(Context, GoalInfo0) },
- { add_goal_info_purity_feature(GoalInfo0,
- Purity1, GoalInfo) },
- { Goal0 = Call - GoalInfo },
-
- insert_arg_unifications(HeadVars, Args,
- Context, call(CallId), no,
- Goal0, VarSet1, Goal, VarSet, Info0, Info)
- ).
+ Purity1 = Purity
+ }
+ ),
+ { goal_info_init(Context, GoalInfo0) },
+ { add_goal_info_purity_feature(GoalInfo0, Purity1, GoalInfo) },
+ { Goal0 = Call - GoalInfo },
+
+ insert_arg_unifications(HeadVars, VisualArgs,
+ Context, call(CallId), no,
+ Goal0, VarSet2, Goal, VarSet, Info0, Info,
+ HiddenInfo1, HiddenInfo)
+ ).
transform_goal_2(unify(A0, B0), Context, VarSet0, Subst, Goal, VarSet,
- Info0, Info) -->
- { term__apply_substitution(A0, Subst, A) },
- { term__apply_substitution(B0, Subst, B) },
- unravel_unification(A, B, Context, explicit, [],
- VarSet0, Goal, VarSet, Info0, Info).
+ Info0, Info, _, HiddenInfo0, HiddenInfo) -->
+ { term__apply_substitution(A0, Subst, A) },
+ { term__apply_substitution(B0, Subst, B) },
+ unravel_unification(A, B, Context, explicit, [],
+ VarSet0, Goal, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo1),
+ { hidden_info_update(HiddenInfo1, HiddenInfo) }.
+
+:- pred dummy_hlds_goal(hlds_goal, term__context, prog_varset, prog_varset).
+:- mode dummy_hlds_goal(out, in, in, out) is det.
+
+dummy_hlds_goal(HLDSGoal, Context, VarSet0, VarSet) :-
+ varset__new_var(VarSet0, Var1, VarSet1),
+ varset__new_var(VarSet1, Var2, VarSet),
+ create_atomic_unification(Var1, var(Var2), Context, explicit,
+ [], HLDSGoal).
+
+ % process_edcg_goal(HiddenTerms, Body, VarSet0, Context, Subst,
+ % HldsGoal, VarSet, Info0, Info, PredTable, HiddenInfoIn,
+ % HiddenInfoOut)
+ %
+ % This predicates transforms an EDCG goal into an HLDS goal (HldsGoal).
+ % HiddenTerms is the list of hidden arguments and values in the head of
+ % the EDCG goal. Body is the body of the EDCG goal.
+:- pred process_edcg_goal(prog_term, prog_term, prog_varset,
+ term__context, prog_substitution, hlds_goal, prog_varset, qual_info,
+ qual_info, predicate_table, hidden_info, hidden_info, io__state,
+ io__state).
+:- mode process_edcg_goal(in, in, in, in, in, out, out, in, out, in,
+ in, out, di, uo) is det.
+
+process_edcg_goal(HiddenTerms, Body0, VarSet0, Context, Subst,
+ Goal, VarSet, Info0, Info, PredTable, HiddenInfo0,
+ HiddenInfo) -->
+ { edcg__sep_hidden_terms(HiddenTerms, Context,
+ HiddenInfo0, HiddenInfo1, NameAndForms, FirstNames,
+ SecondNames, FirstArgs0, SecondArgs0) },
+ { make_fresh_arg_vars(FirstArgs0, VarSet0, FirstVars, VarSet1) },
+ { make_fresh_arg_vars(SecondArgs0, VarSet1, SecondVars, VarSet2) },
+ { term__apply_substitution_to_list(FirstArgs0, Subst, FirstArgs) },
+ { term__apply_substitution_to_list(SecondArgs0, Subst, SecondArgs) },
+ { true_goal(Goal0) },
+ { CallId = call(predicate - unqualified("edcg")/0) },
+ insert_arg_unifications(FirstVars, FirstArgs,
+ Context, call(CallId), no,
+ Goal0, VarSet2, Goal1, VarSet3, Info0, Info1,
+ HiddenInfo1, HiddenInfo2),
+ append_arg_unifications(SecondVars, SecondArgs,
+ Context, call(CallId), Goal1, VarSet3, Goal2, VarSet4,
+ Info1, Info2, HiddenInfo2, HiddenInfo3),
+ % Set the hidden_info to include the state of hidden variables
+ % local to the goal.
+ { edcg__hidden_info_convert(NameAndForms, Context,
+ VarSet4, VarSet5, HiddenInfo3, HiddenInfo4) },
+ { edcg__hidden_info_vars(FirstNames, HiddenInfo4, HiddenFirstVars) },
+ { term__coerce(Body0, Body1) },
+ { parse_goal(Body1, VarSet5, Body, VarSet6) },
+ transform_goal(Body, VarSet6, Subst, Goal3, VarSet7,
+ Info2, Info3, PredTable, HiddenInfo4, HiddenInfo5),
+ { edcg__check_hidden_states(NameAndForms, Context, HiddenInfo5,
+ HiddenInfo6) },
+ { edcg__hidden_info_vars(SecondNames, HiddenInfo6, HiddenSecondVars) },
+ % Unset the states of the hidden variables local to the goal.
+ { edcg__hidden_info_revert(FirstNames, HiddenInfo3,
+ HiddenInfo6, HiddenInfo) },
+ { conjoin_goals(Goal2, Goal3, Goal4) },
+ { term__var_list_to_term_list(FirstVars, FirstTerms) },
+ append_arg_unifications(HiddenFirstVars, FirstTerms,
+ Context, call(CallId), Goal4, VarSet7, Goal5, VarSet8,
+ Info3, Info4),
+ { term__var_list_to_term_list(SecondVars, SecondTerms) },
+ append_arg_unifications(HiddenSecondVars, SecondTerms,
+ Context, call(CallId), Goal5, VarSet8, Goal, VarSet,
+ Info4, Info).
:- inst dcg_record_syntax_op = bound("=^"; ":=").
:- pred transform_dcg_record_syntax(string, list(prog_term), prog_context,
prog_varset, hlds_goal, prog_varset, qual_info, qual_info,
- io__state, io__state).
+ hidden_info, hidden_info, io__state, io__state).
:- mode transform_dcg_record_syntax(in(dcg_record_syntax_op),
- in, in, in, out, out, in, out, di, uo) is det.
+ in, in, in, out, out, in, out, in, out, di, uo) is det.
transform_dcg_record_syntax(Operator, ArgTerms0, Context, VarSet0,
- Goal, VarSet, Info0, Info) -->
+ Goal, VarSet, Info0, Info, HiddenInfo0, HiddenInfo) -->
{ goal_info_init(Context, GoalInfo) },
(
{ ArgTerms0 = [LHSTerm, RHSTerm,
@@ -5134,12 +5386,13 @@
transform_dcg_record_syntax_2(AccessType,
FieldNames, ArgTerms, Context, VarSet0, Goal,
- VarSet, Info0, Info)
+ VarSet, Info0, Info, HiddenInfo0, HiddenInfo)
;
{ MaybeFieldNames = error(Msg, ErrorTerm) },
{ invalid_goal("^", ArgTerms0, GoalInfo,
Goal, VarSet0, VarSet) },
{ qual_info_set_found_syntax_error(yes, Info0, Info) },
+ { HiddenInfo = HiddenInfo0 },
io__set_exit_status(1),
prog_out__write_context(Context),
io__write_string("In DCG field "),
@@ -5162,6 +5415,7 @@
{ invalid_goal("^", ArgTerms0, GoalInfo,
Goal, VarSet0, VarSet) },
{ qual_info_set_found_syntax_error(yes, Info0, Info) },
+ { HiddenInfo = HiddenInfo0 },
io__set_exit_status(1),
prog_out__write_context(Context),
io__write_string(
@@ -5174,13 +5428,14 @@
:- pred transform_dcg_record_syntax_2(field_access_type,
list(ctor_field_name), list(prog_term), prog_context,
- prog_varset, hlds_goal, prog_varset,
- qual_info, qual_info, io__state, io__state).
+ prog_varset, hlds_goal, prog_varset, qual_info, qual_info,
+ hidden_info, hidden_info, io__state, io__state).
:- mode transform_dcg_record_syntax_2(in, in, in, in, in, out, out,
- in, out, di, uo) is det.
+ in, out, in, out, di, uo) is det.
transform_dcg_record_syntax_2(AccessType, FieldNames, ArgTerms, Context,
- VarSet0, Goal, VarSet, Info0, Info, IO0, IO) :-
+ VarSet0, Goal, VarSet, Info0, Info, HiddenInfo0, HiddenInfo,
+ IO0, IO) :-
make_fresh_arg_vars(ArgTerms, VarSet0, ArgVars, VarSet1),
( ArgVars = [FieldValueVar, TermInputVar, TermOutputVar] ->
(
@@ -5215,7 +5470,8 @@
],
insert_arg_unifications_with_supplied_contexts(ArgVars,
ArgTerms, ArgContexts, Context, Goal0, VarSet2,
- Goal, VarSet, Info0, Info, IO0, IO)
+ Goal, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo, IO0, IO)
;
AccessType = get,
expand_dcg_field_extraction_goal(Context, explicit,
@@ -5246,7 +5502,8 @@
],
insert_arg_unifications_with_supplied_contexts(ArgVars,
ArgTerms, ArgContexts, Context, Goal0, VarSet2,
- Goal, VarSet, Info0, Info, IO0, IO)
+ Goal, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo, IO0, IO)
)
;
error("make_hlds__do_transform_dcg_record_syntax")
@@ -5513,6 +5770,9 @@
:- mode transform_aditi_builtin(in(aditi_update_str), in,
in, in, out, out, in, out, di, uo) is det.
+%-----------------------------------------------------------------------------
+ % Aditi Section.
+
transform_aditi_builtin("aditi_insert", Args0, Context, VarSet0,
Goal, VarSet, Info0, Info) -->
% Build an empty goal_info.
@@ -5970,16 +6230,34 @@
insert_arg_unifications(HeadVars, Args, Context, ArgContext, ForPragmaC,
Goal0, VarSet0, Goal, VarSet, Info0, Info) -->
+ { hidden_info_init(HiddenInfo0) },
+ insert_arg_unifications(HeadVars, Args, Context, ArgContext, ForPragmaC,
+ Goal0, VarSet0, Goal, VarSet, Info0, Info,
+ HiddenInfo0, _).
+
+:- pred insert_arg_unifications(list(prog_var), list(prog_term),
+ prog_context, arg_context, bool, hlds_goal, prog_varset,
+ hlds_goal, prog_varset, qual_info, qual_info,
+ hidden_info, hidden_info,
+ io__state, io__state).
+:- mode insert_arg_unifications(in, in, in, in, in, in, in, out,
+ out, in, out, in, out, di, uo) is det.
+
+insert_arg_unifications(HeadVars, Args, Context, ArgContext, ForPragmaC,
+ Goal0, VarSet0, Goal, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo) -->
( { HeadVars = [] } ->
{ Goal = Goal0 },
{ VarSet = VarSet0 },
- { Info = Info0 }
+ { Info = Info0 },
+ { HiddenInfo = HiddenInfo0 }
;
{ Goal0 = _ - GoalInfo0 },
{ goal_to_conj_list(Goal0, List0) },
insert_arg_unifications_2(HeadVars, Args, Context, ArgContext,
ForPragmaC, 0, List0, VarSet0, List, VarSet,
- Info0, Info),
+ Info0, Info, HiddenInfo0, HiddenInfo1),
+ { hidden_info_update(HiddenInfo1, HiddenInfo) },
{ goal_info_set_context(GoalInfo0, Context, GoalInfo) },
{ conj_list_to_goal(List, GoalInfo, Goal) }
).
@@ -5987,55 +6265,60 @@
:- pred insert_arg_unifications_2(list(prog_var), list(prog_term),
prog_context, arg_context, bool, int, list(hlds_goal),
prog_varset, list(hlds_goal), prog_varset,
- qual_info, qual_info, io__state, io__state).
+ qual_info, qual_info, hidden_info, hidden_info,
+ io__state, io__state).
:- mode insert_arg_unifications_2(in, in, in, in, in, in, in, in,
- out, out, in, out, di, uo) is det.
+ out, out, in, out, in, out, di, uo) is det.
-insert_arg_unifications_2([], [_|_], _, _, _, _, _, _, _, _, _, _) -->
+insert_arg_unifications_2([], [_|_], _, _, _, _, _, _, _, _, _, _, _, _) -->
{ error("insert_arg_unifications_2: length mismatch") }.
-insert_arg_unifications_2([_|_], [], _, _, _, _, _, _, _, _, _, _) -->
+insert_arg_unifications_2([_|_], [], _, _, _, _, _, _, _, _, _, _, _, _) -->
{ error("insert_arg_unifications_2: length mismatch") }.
insert_arg_unifications_2([], [], _, _, _, _, List, VarSet, List, VarSet,
- Info, Info) --> [].
+ Info, Info, HiddenInfo, HiddenInfo) --> [].
insert_arg_unifications_2([Var|Vars], [Arg|Args], Context, ArgContext,
- ForPragmaC, N0, List0, VarSet0, List, VarSet, Info0, Info) -->
+ ForPragmaC, N0, List0, VarSet0, List, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo) -->
{ N1 is N0 + 1 },
insert_arg_unification(Var, Arg, Context, ArgContext,
ForPragmaC, N1, List0, VarSet0, List1, VarSet1, ArgUnifyConj,
- Info0, Info1),
+ Info0, Info1, HiddenInfo0, HiddenInfo1),
(
{ ArgUnifyConj = [] }
->
insert_arg_unifications_2(Vars, Args, Context, ArgContext,
ForPragmaC, N1, List1, VarSet1, List, VarSet,
- Info1, Info)
+ Info1, Info, HiddenInfo1, HiddenInfo)
;
insert_arg_unifications_2(Vars, Args, Context, ArgContext,
ForPragmaC, N1, List1, VarSet1, List2, VarSet,
- Info1, Info),
+ Info1, Info, HiddenInfo1, HiddenInfo),
{ list__append(ArgUnifyConj, List2, List) }
).
:- pred insert_arg_unifications_with_supplied_contexts(list(prog_var),
list(prog_term), assoc_list(int, arg_context), prog_context,
hlds_goal, prog_varset, hlds_goal, prog_varset,
- qual_info, qual_info, io__state, io__state).
+ qual_info, qual_info, hidden_info, hidden_info,
+ io__state, io__state).
:- mode insert_arg_unifications_with_supplied_contexts(in, in, in, in, in, in,
- out, out, in, out, di, uo) is det.
+ out, out, in, out, in, out, di, uo) is det.
insert_arg_unifications_with_supplied_contexts(ArgVars,
ArgTerms, ArgContexts, Context, Goal0, VarSet0,
- Goal, VarSet, Info0, Info) -->
+ Goal, VarSet, Info0, Info, HiddenInfo0, HiddenInfo) -->
( { ArgVars = [] } ->
{ Goal = Goal0 },
{ VarSet = VarSet0 },
- { Info = Info0 }
+ { Info = Info0 },
+ { HiddenInfo = HiddenInfo0 }
;
{ Goal0 = _ - GoalInfo0 },
{ goal_to_conj_list(Goal0, GoalList0) },
insert_arg_unifications_with_supplied_contexts_2(ArgVars,
ArgTerms, ArgContexts, Context, GoalList0,
- VarSet0, GoalList, VarSet, Info0, Info),
+ VarSet0, GoalList, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo),
{ goal_info_set_context(GoalInfo0, Context, GoalInfo) },
{ conj_list_to_goal(GoalList, GoalInfo, Goal) }
).
@@ -6043,18 +6326,21 @@
:- pred insert_arg_unifications_with_supplied_contexts_2(list(prog_var),
list(prog_term), assoc_list(int, arg_context), prog_context,
list(hlds_goal), prog_varset, list(hlds_goal), prog_varset,
- qual_info, qual_info, io__state, io__state).
+ qual_info, qual_info, hidden_info, hidden_info,
+ io__state, io__state).
:- mode insert_arg_unifications_with_supplied_contexts_2(in, in, in, in, in,
- in, out, out, in, out, di, uo) is det.
+ in, out, out, in, out, in, out, di, uo) is det.
insert_arg_unifications_with_supplied_contexts_2(Vars, Terms, ArgContexts,
- Context, List0, VarSet0, List, VarSet, Info0, Info) -->
+ Context, List0, VarSet0, List, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo) -->
(
{ Vars = [], Terms = [], ArgContexts = [] }
->
{ List = List0 },
{ VarSet = VarSet0 },
- { Info = Info0 }
+ { Info = Info0 },
+ { HiddenInfo0 = HiddenInfo }
;
{ Vars = [Var | Vars1] },
{ Terms = [Term | Terms1] },
@@ -6062,10 +6348,10 @@
->
insert_arg_unification(Var, Term, Context, ArgContext, no,
ArgNumber, List0, VarSet0, List1, VarSet1,
- UnifyConj, Info0, Info1),
+ UnifyConj, Info0, Info1, HiddenInfo0, HiddenInfo1),
insert_arg_unifications_with_supplied_contexts_2(Vars1, Terms1,
ArgContexts1, Context, List1, VarSet1, List2, VarSet,
- Info1, Info),
+ Info1, Info, HiddenInfo1, HiddenInfo),
{ list__append(UnifyConj, List2, List) }
;
{ error("insert_arg_unifications_with_supplied_contexts") }
@@ -6074,12 +6360,14 @@
:- pred insert_arg_unification(prog_var, prog_term,
prog_context, arg_context, bool, int,
list(hlds_goal), prog_varset, list(hlds_goal), prog_varset,
- list(hlds_goal), qual_info, qual_info, io__state, io__state).
+ list(hlds_goal), qual_info, qual_info, hidden_info, hidden_info,
+ io__state, io__state).
:- mode insert_arg_unification(in, in, in, in, in, in,
- in, in, out, out, out, in, out, di, uo) is det.
+ in, in, out, out, out, in, out, in, out, di, uo) is det.
insert_arg_unification(Var, Arg, Context, ArgContext, ForPragmaC, N1,
- List0, VarSet0, List1, VarSet1, ArgUnifyConj, Info0, Info) -->
+ List0, VarSet0, List1, VarSet1, ArgUnifyConj, Info0, Info,
+ HiddenInfo0, HiddenInfo) -->
(
{ Arg = term__variable(Var) }
->
@@ -6087,30 +6375,34 @@
{ VarSet1 = VarSet0 },
{ Info = Info0 },
{ ArgUnifyConj = [] },
- { List1 = List0 }
+ { List1 = List0 },
+ { HiddenInfo = HiddenInfo0 }
;
- { Arg = term__variable(ArgVar) },
- { ForPragmaC = yes }
- ->
- % Handle unifications of the form `X = Y' by substitution
- % if this is safe.
- { Info = Info0 },
- { ArgUnifyConj = [] },
- { map__init(Subst0) },
- { map__det_insert(Subst0, ArgVar, Var, Subst) },
- { goal_util__rename_vars_in_goals(List0, no, Subst,
- List1) },
- { varset__search_name(VarSet0, ArgVar, ArgVarName) ->
- varset__name_var(VarSet0, Var, ArgVarName, VarSet1)
- ;
- VarSet1 = VarSet0
- }
+ { Arg = term__variable(ArgVar) },
+ { ForPragmaC = yes }
+ ->
+ % Handle unifications of the form `X = Y' by substitution
+ % if this is safe.
+ { Info = Info0 },
+ { ArgUnifyConj = [] },
+ { map__init(Subst0) },
+ { map__det_insert(Subst0, ArgVar, Var, Subst) },
+ { goal_util__rename_vars_in_goals(List0, no, Subst,
+ List1) },
+ { varset__search_name(VarSet0, ArgVar, ArgVarName) ->
+ varset__name_var(VarSet0, Var, ArgVarName, VarSet1)
+ ;
+ VarSet1 = VarSet0
+ },
+ { HiddenInfo = HiddenInfo0 }
+
;
{ arg_context_to_unify_context(ArgContext, N1,
UnifyMainContext, UnifySubContext) },
unravel_unification(term__variable(Var), Arg,
Context, UnifyMainContext, UnifySubContext,
- VarSet0, Goal, VarSet1, Info0, Info),
+ VarSet0, Goal, VarSet1, Info0, Info,
+ HiddenInfo0, HiddenInfo),
{ goal_to_conj_list(Goal, ArgUnifyConj) },
{ List1 = List0 }
).
@@ -6127,51 +6419,73 @@
append_arg_unifications(HeadVars, Args, Context, ArgContext, Goal0, VarSet0,
Goal, VarSet, Info0, Info) -->
+ { hidden_info_init(HiddenInfo0) },
+ append_arg_unifications(HeadVars, Args, Context, ArgContext, Goal0,
+ VarSet0, Goal, VarSet, Info0, Info, HiddenInfo0, _).
+
+:- pred append_arg_unifications(list(prog_var), list(prog_term),
+ prog_context, arg_context, hlds_goal, prog_varset, hlds_goal,
+ prog_varset, qual_info, qual_info,
+ hidden_info, hidden_info, io__state, io__state).
+:- mode append_arg_unifications(in, in, in, in, in, in,
+ out, out, in, out, in, out, di, uo) is det.
+
+append_arg_unifications(HeadVars, Args, Context, ArgContext, Goal0, VarSet0,
+ Goal, VarSet, Info0, Info, HiddenInfo0, HiddenInfo) -->
( { HeadVars = [] } ->
{ Goal = Goal0 },
{ VarSet = VarSet0 },
- { Info = Info0 }
+ { Info = Info0 },
+ { HiddenInfo = HiddenInfo0 }
;
{ Goal0 = _ - GoalInfo },
{ goal_to_conj_list(Goal0, List0) },
append_arg_unifications_2(HeadVars, Args, Context, ArgContext,
- 0, List0, VarSet0, List, VarSet, Info0, Info),
+ 0, List0, VarSet0, List, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo1),
+ { hidden_info_update(HiddenInfo1, HiddenInfo) },
{ conj_list_to_goal(List, GoalInfo, Goal) }
).
:- pred append_arg_unifications_2(list(prog_var), list(prog_term),
prog_context, arg_context, int, list(hlds_goal), prog_varset,
list(hlds_goal), prog_varset, qual_info, qual_info,
- io__state, io__state).
+ hidden_info, hidden_info, io__state, io__state).
:- mode append_arg_unifications_2(in, in, in, in, in, in, in,
- out, out, in, out, di, uo) is det.
+ out, out, in, out, in, out, di, uo) is det.
-append_arg_unifications_2([], [_|_], _, _, _, _, _, _, _, _, _) -->
+append_arg_unifications_2([], [_|_], _, _, _, _, _, _, _, _, _, _, _) -->
{ error("append_arg_unifications_2: length mismatch") }.
-append_arg_unifications_2([_|_], [], _, _, _, _, _, _, _, _, _) -->
+append_arg_unifications_2([_|_], [], _, _, _, _, _, _, _, _, _, _, _) -->
{ error("append_arg_unifications_2: length mismatch") }.
append_arg_unifications_2([], [], _, _, _, List, VarSet, List, VarSet,
- Info, Info) --> [].
+ Info, Info, HiddenInfo, HiddenInfo) --> [].
append_arg_unifications_2([Var|Vars], [Arg|Args], Context, ArgContext, N0,
- List0, VarSet0, List, VarSet, Info0, Info) -->
+ List0, VarSet0, List, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo) -->
{ N1 is N0 + 1 },
append_arg_unification(Var, Arg, Context, ArgContext,
- N1, ConjList, VarSet0, VarSet1, Info0, Info1),
+ N1, ConjList, VarSet0, VarSet1, Info0, Info1,
+ HiddenInfo0, HiddenInfo1),
{ list__append(List0, ConjList, List1) },
append_arg_unifications_2(Vars, Args, Context, ArgContext, N1,
- List1, VarSet1, List, VarSet, Info1, Info).
+ List1, VarSet1, List, VarSet, Info1, Info,
+ HiddenInfo1, HiddenInfo).
:- pred append_arg_unification(prog_var, prog_term, prog_context, arg_context,
int, list(hlds_goal), prog_varset, prog_varset,
- qual_info, qual_info, io__state, io__state).
+ qual_info, qual_info, hidden_info, hidden_info,
+ io__state, io__state).
:- mode append_arg_unification(in, in, in, in, in, out, in,
- out, in, out, di, uo) is det.
+ out, in, out, in, out, di, uo) is det.
append_arg_unification(Var, Arg, Context, ArgContext,
- N1, ConjList, VarSet0, VarSet, Info0, Info) -->
+ N1, ConjList, VarSet0, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo) -->
( { Arg = term__variable(Var) } ->
% skip unifications of the form `X = X'
{ Info = Info0 },
+ { HiddenInfo = HiddenInfo0 },
{ VarSet = VarSet0 },
{ ConjList = [] }
;
@@ -6179,7 +6493,8 @@
UnifyMainContext, UnifySubContext) },
unravel_unification(term__variable(Var), Arg,
Context, UnifyMainContext, UnifySubContext,
- VarSet0, Goal, VarSet, Info0, Info),
+ VarSet0, Goal, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo),
{ goal_to_conj_list(Goal, ConjList) }
).
@@ -6255,11 +6570,24 @@
:- mode unravel_unification(in, in, in, in, in, in, out, out,
in, out, di, uo) is det.
+unravel_unification(X, Y, Context, MainContext, SubContext, VarSet0, Goal,
+ VarSet, Info0, Info) -->
+ { hidden_info_init(HiddenInfo0) },
+ unravel_unification(X, Y, Context, MainContext, SubContext, VarSet0,
+ Goal, VarSet, Info0, Info, HiddenInfo0, _).
+
+:- pred unravel_unification(prog_term, prog_term, prog_context,
+ unify_main_context, unify_sub_contexts, prog_varset, hlds_goal,
+ prog_varset, qual_info, qual_info, hidden_info, hidden_info,
+ io__state, io__state).
+:- mode unravel_unification(in, in, in, in, in, in, out, out,
+ in, out, in, out, di, uo) is det.
+
% `X = Y' needs no unravelling.
unravel_unification(term__variable(X), term__variable(Y), Context,
- MainContext, SubContext, VarSet0, Goal, VarSet, Info, Info)
- -->
+ MainContext, SubContext, VarSet0, Goal, VarSet, Info, Info,
+ HiddenInfo, HiddenInfo) -->
{ create_atomic_unification(X, var(Y), Context, MainContext,
SubContext, Goal) },
{ VarSet0 = VarSet }.
@@ -6275,7 +6603,7 @@
unravel_unification(term__variable(X), RHS,
Context, MainContext, SubContext, VarSet0,
- Goal, VarSet, Info0, Info) -->
+ Goal, VarSet, Info0, Info, HiddenInfo0, HiddenInfo) -->
{ RHS = term__functor(F, Args, FunctorContext) },
(
% Handle explicit type qualification.
@@ -6289,7 +6617,7 @@
Context, Info0, Info1),
unravel_unification(term__variable(X), RVal,
Context, MainContext, SubContext, VarSet0,
- Goal, VarSet, Info1, Info)
+ Goal, VarSet, Info1, Info, HiddenInfo0, HiddenInfo)
;
{
% handle lambda expressions
@@ -6333,7 +6661,8 @@
build_lambda_expression(X, PredOrFunc, EvalMethod, Vars1,
Modes, Det, ParsedGoal, VarSet1,
Context, MainContext, SubContext, Goal, VarSet,
- Info1, Info)
+ Info1, Info),
+ { HiddenInfo0 = HiddenInfo }
;
{
% handle higher-order dcg pred expressions -
@@ -6359,7 +6688,8 @@
build_lambda_expression(X, predicate, EvalMethod, Vars1,
Modes, Det, ParsedGoal, VarSet1,
Context, MainContext, SubContext, Goal, VarSet,
- Info1, Info)
+ Info1, Info),
+ { HiddenInfo0 = HiddenInfo }
;
% handle if-then-else expressions
{ F = term__atom("else"),
@@ -6382,16 +6712,34 @@
Info0, Info1),
unravel_unification(term__variable(X), ThenTerm,
Context, MainContext, SubContext, VarSet22, ThenGoal,
- VarSet33, Info1, Info2),
+ VarSet33, Info1, Info2, HiddenInfo0, HiddenInfo1),
unravel_unification(term__variable(X), ElseTerm,
Context, MainContext, SubContext, VarSet33, ElseGoal,
- VarSet, Info2, Info),
+ VarSet, Info2, Info, HiddenInfo1, HiddenInfo),
{ map__init(Empty) },
{ IfThenElse = if_then_else(Vars, IfGoal, ThenGoal, ElseGoal,
Empty) },
{ goal_info_init(Context, GoalInfo) },
{ Goal = IfThenElse - GoalInfo }
;
+ { parse_qualified_term(RHS, RHS, "", MaybeFunctor) },
+ { MaybeFunctor = ok(unqualified("$"), [HiddenArg]) }
+ ->
+ { edcg__process_edcg_operator(access, HiddenArg, Context,
+ VarSet0, Var, VarSet, HiddenInfo0, HiddenInfo) },
+ { Info0 = Info },
+ { create_atomic_unification(X, var(Var), Context, MainContext,
+ SubContext, Goal) }
+ ;
+ { parse_qualified_term(RHS, RHS, "", MaybeFunctor) },
+ { MaybeFunctor = ok(unqualified("$="), [HiddenArg]) }
+ ->
+ { edcg__process_edcg_operator(change, HiddenArg, Context,
+ VarSet0, Var, VarSet, HiddenInfo0, HiddenInfo) },
+ { Info0 = Info },
+ { create_atomic_unification(X, var(Var), Context, MainContext,
+ SubContext, Goal) }
+ ;
% handle field extraction expressions
{ F = term__atom("^") },
{ Args = [InputTerm, FieldNameTerm] },
@@ -6407,7 +6755,8 @@
{ ArgContext = functor(Functor, MainContext, SubContext) },
append_arg_unifications([InputTermVar], [InputTerm],
FunctorContext, ArgContext, Goal0,
- VarSet2, Goal, VarSet, Info0, Info)
+ VarSet2, Goal, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo)
;
% handle field update expressions
{ F = term__atom(":=") },
@@ -6431,14 +6780,16 @@
{ TermArgNumber = 1 },
append_arg_unification(InputTermVar, InputTerm,
FunctorContext, TermArgContext, TermArgNumber,
- TermUnifyConj, VarSet3, VarSet4, Info0, Info1),
+ TermUnifyConj, VarSet3, VarSet4, Info0, Info1,
+ HiddenInfo0, HiddenInfo1),
{ FieldArgContext = functor(InnerFunctor,
MainContext, FieldSubContext) },
{ FieldArgNumber = 2 },
append_arg_unification(FieldValueVar, FieldValueTerm,
FunctorContext, FieldArgContext, FieldArgNumber,
- FieldUnifyConj, VarSet4, VarSet, Info1, Info),
+ FieldUnifyConj, VarSet4, VarSet, Info1, Info,
+ HiddenInfo1, HiddenInfo),
{ Goal0 = _ - GoalInfo0 },
{ goal_to_conj_list(Goal0, GoalList0) },
@@ -6463,7 +6814,8 @@
{ create_atomic_unification(X, functor(ConsId, []),
Context, MainContext, SubContext, Goal) },
{ VarSet = VarSet0 },
- { Info = Info0 }
+ { Info = Info0 },
+ { HiddenInfo = HiddenInfo0 }
;
{ make_fresh_arg_vars(FunctorArgs, VarSet0,
HeadVars, VarSet1) },
@@ -6477,17 +6829,20 @@
% with type-checking :-(
append_arg_unifications(HeadVars, FunctorArgs,
FunctorContext, ArgContext, Goal0,
- VarSet1, Goal, VarSet, Info0, Info)
+ VarSet1, Goal, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo)
)
).
% Handle `f(...) = X' in the same way as `X = f(...)'.
unravel_unification(term__functor(F, As, FC), term__variable(Y),
- C, MC, SC, VarSet0, Goal, VarSet, Info0, Info) -->
+ C, MC, SC, VarSet0, Goal, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo) -->
unravel_unification(term__variable(Y),
term__functor(F, As, FC),
- C, MC, SC, VarSet0, Goal, VarSet, Info0, Info).
+ C, MC, SC, VarSet0, Goal, VarSet, Info0, Info,
+ HiddenInfo0, HiddenInfo).
% If we find a unification of the form `f1(...) = f2(...)',
% then we replace it with `Tmp = f1(...), Tmp = f2(...)',
@@ -6498,18 +6853,20 @@
unravel_unification(term__functor(LeftF, LeftAs, LeftC),
term__functor(RightF, RightAs, RightC),
Context, MainContext, SubContext, VarSet0,
- Goal, VarSet, Info0, Info) -->
+ Goal, VarSet, Info0, Info, HiddenInfo0, HiddenInfo) -->
{ varset__new_var(VarSet0, TmpVar, VarSet1) },
unravel_unification(
term__variable(TmpVar),
term__functor(LeftF, LeftAs, LeftC),
Context, MainContext, SubContext,
- VarSet1, Goal0, VarSet2, Info0, Info1),
+ VarSet1, Goal0, VarSet2, Info0, Info1,
+ HiddenInfo0, HiddenInfo1),
unravel_unification(
term__variable(TmpVar),
term__functor(RightF, RightAs, RightC),
Context, MainContext, SubContext,
- VarSet2, Goal1, VarSet, Info1, Info),
+ VarSet2, Goal1, VarSet, Info1, Info,
+ HiddenInfo1, HiddenInfo),
{ goal_info_init(GoalInfo) },
{ goal_to_conj_list(Goal0, ConjList0) },
{ goal_to_conj_list(Goal1, ConjList1) },
@@ -6729,26 +7086,29 @@
%-----------------------------------------------------------------------------%
% get_conj(Goal, Conj0, Subst, Conj) :
-% Goal is a tree of conjuncts. Flatten it into a list (applying Subst),
-% append Conj0, and return the result in Conj.
+% Goal is a tree of conjuncts. Flatten it into a list (applying Subst),
+% append Conj0, and return the result in Conj.
:- pred get_conj(goal, prog_substitution, list(hlds_goal), prog_varset,
list(hlds_goal), prog_varset, qual_info, qual_info,
+ predicate_table, hidden_info, hidden_info,
io__state, io__state).
-:- mode get_conj(in, in, in, in, out, out, in, out, di, uo) is det.
+:- mode get_conj(in, in, in, in, out, out, in, out, in, in, out, di, uo) is det.
-get_conj(Goal, Subst, Conj0, VarSet0, Conj, VarSet, Info0, Info) -->
+get_conj(Goal, Subst, Conj0, VarSet0, Conj, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo) -->
(
{ Goal = (A,B) - _Context }
->
- get_conj(B, Subst, Conj0, VarSet0, Conj1, VarSet1,
- Info0, Info1),
- get_conj(A, Subst, Conj1, VarSet1, Conj, VarSet, Info1, Info)
- ;
+ get_conj(A, Subst, Conj0, VarSet0, Conj1, VarSet1,
+ Info0, Info1, PredTable, HiddenInfo0, HiddenInfo1),
+ get_conj(B, Subst, Conj1, VarSet1, Conj, VarSet, Info1, Info,
+ PredTable, HiddenInfo1, HiddenInfo)
+ ;
transform_goal(Goal, VarSet0, Subst, Goal1, VarSet,
- Info0, Info),
+ Info0, Info, PredTable, HiddenInfo0, HiddenInfo),
{ goal_to_conj_list(Goal1, ConjList) },
- { list__append(ConjList, Conj0, Conj) }
+ { list__append(Conj0, ConjList, Conj) }
).
% get_par_conj(Goal, ParConj0, Subst, ParConj) :
@@ -6757,45 +7117,53 @@
:- pred get_par_conj(goal, prog_substitution, list(hlds_goal), prog_varset,
list(hlds_goal), prog_varset, qual_info, qual_info,
+ predicate_table, hidden_info, hidden_info,
io__state, io__state).
-:- mode get_par_conj(in, in, in, in, out, out, in, out, di, uo) is det.
+:- mode get_par_conj(in, in, in, in, out, out, in, out, in, in, out,
+ di, uo) is det.
-get_par_conj(Goal, Subst, ParConj0, VarSet0, ParConj, VarSet, Info0, Info) -->
+get_par_conj(Goal, Subst, ParConj0, VarSet0, ParConj, VarSet, Info0, Info,
+ PredTable, HiddenInfo0, HiddenInfo) -->
(
{ Goal = (A & B) - _Context }
->
- get_par_conj(B, Subst, ParConj0, VarSet0, ParConj1, VarSet1,
- Info0, Info1),
- get_par_conj(A, Subst, ParConj1, VarSet1, ParConj, VarSet,
- Info1, Info)
+ get_par_conj(A, Subst, ParConj0, VarSet0, ParConj1, VarSet1,
+ Info0, Info1, PredTable, HiddenInfo0, HiddenInfo1),
+ get_par_conj(B, Subst, ParConj1, VarSet1, ParConj, VarSet,
+ Info1, Info, PredTable, HiddenInfo1, HiddenInfo)
;
transform_goal(Goal, VarSet0, Subst, Goal1, VarSet,
- Info0, Info),
+ Info0, Info, PredTable, HiddenInfo0, HiddenInfo),
{ goal_to_par_conj_list(Goal1, ParConjList) },
- { list__append(ParConjList, ParConj0, ParConj) }
+ { list__append(ParConj0, ParConjList, ParConj) }
).
% get_disj(Goal, Subst, Disj0, Disj) :
-% Goal is a tree of disjuncts. Flatten it into a list (applying Subst)
-% append Disj0, and return the result in Disj.
+% Goal is a tree of disjuncts. Flatten it into a list (applying Subst)
+% append Disj0, and return the result in Disj.
-:- pred get_disj(goal, prog_substitution, list(hlds_goal), prog_varset,
- list(hlds_goal), prog_varset, qual_info, qual_info,
- io__state, io__state).
-:- mode get_disj(in, in, in, in, out, out, in, out, di, uo) is det.
+:- pred get_disj(goal, prog_substitution,
+ hidden_disj_info, prog_varset, hidden_disj_info, prog_varset,
+ qual_info, qual_info, predicate_table, hidden_info,
+ io__state, io__state).
+:- mode get_disj(in, in, in, in, out, out, in, out, in, in, di, uo) is det.
-get_disj(Goal, Subst, Disj0, VarSet0, Disj, VarSet, Info0, Info) -->
- (
- { Goal = (A;B) - _Context }
- ->
- get_disj(B, Subst, Disj0, VarSet0, Disj1, VarSet1,
- Info0, Info1),
- get_disj(A, Subst, Disj1, VarSet1, Disj, VarSet, Info1, Info)
- ;
- transform_goal(Goal, VarSet0, Subst, Goal1, VarSet,
- Info0, Info),
- { Disj = [Goal1 | Disj0] }
- ).
+get_disj(Goal, Subst, Disj0, VarSet0, Disj, VarSet, Info0, Info,
+ PredTable, HiddenInfo0) -->
+ (
+ { Goal = (A;B) - _Context }
+ ->
+ get_disj(B, Subst, Disj0, VarSet0, Disj1, VarSet1,
+ Info0, Info1, PredTable, HiddenInfo0),
+ get_disj(A, Subst, Disj1, VarSet1, Disj, VarSet,
+ Info1, Info, PredTable, HiddenInfo0)
+ ;
+ { Goal = _ - Context },
+ transform_goal(Goal, VarSet0, Subst, Goal1, VarSet,
+ Info0, Info, PredTable, HiddenInfo0, HiddenInfo),
+ { Disj1 = (Goal1 - Context) - HiddenInfo },
+ { Disj = [Disj1 | Disj0] }
+ ).
%-----------------------------------------------------------------------------%
@@ -6895,11 +7263,38 @@
io__write_string(Descr),
io__write_string("' declaration.\n").
+:- pred list_multiple_def_error(predicate_table, string, string,
+ list(pair(pred_id)), io__state, io__state).
+:- mode list_multiple_def_error(in, in, in, in, di, uo) is det.
+
+list_multiple_def_error(_, _, _, []) --> [].
+list_multiple_def_error(PredTable, DefType, ArityType,
+ [PredId1 - PredId2 | Rest]) -->
+ { predicate_table_pred_info(PredTable, PredId1, PredInfo1) },
+ { predicate_table_pred_info(PredTable, PredId2, PredInfo2) },
+ { pred_info_module(PredInfo1, Module) },
+ { pred_info_name(PredInfo1, Name) },
+ { pred_info_arity(PredInfo1, Arity) },
+ { PredName = qualified(Module, Name) },
+ { pred_info_context(PredInfo1, Context1) },
+ { pred_info_context(PredInfo2, Context2) },
+ multiple_def_error(PredName, Arity, DefType, ArityType, Context1,
+ Context2),
+ list_multiple_def_error(PredTable, DefType, ArityType, Rest).
+
:- pred multiple_def_error(sym_name, int, string, prog_context, prog_context,
io__state, io__state).
:- mode multiple_def_error(in, in, in, in, in, di, uo) is det.
multiple_def_error(Name, Arity, DefType, Context, OrigContext) -->
+ multiple_def_error(Name, Arity, DefType, "visual",
+ Context, OrigContext).
+
+:- pred multiple_def_error(sym_name, int, string, string, term__context,
+ term__context, io__state, io__state).
+:- mode multiple_def_error(in, in, in, in, in, in, di, uo) is det.
+
+multiple_def_error(Name, Arity, DefType, ArityType, Context, OrigContext) -->
io__set_exit_status(1),
prog_out__write_context(Context),
io__write_string("Error: "),
@@ -6908,7 +7303,9 @@
prog_out__write_sym_name(Name),
io__write_string("/"),
io__write_int(Arity),
- io__write_string("' multiply defined.\n"),
+ io__write_string("' multiply defined for "),
+ io__write_string(ArityType),
+ io__write_string(" arity.\n"),
prog_out__write_context(OrigContext),
io__write_string(
" Here is the previous definition of "),
@@ -7245,5 +7642,3 @@
;
PragmaVars0 = []
).
-
-%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list