mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-21 00:39:37 +00:00
Estimated hours taken: 8
Branches: main
compiler/modules.m:
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/bytecode_data.m:
compiler/prog_io_util.m:
Bring these modules up to date with our current coding style. Use
predmode declarations and state variable syntax where appropriate.
Fix inconsistent indentation. Print more error messages using
error_util.m for printing error messages.
compiler/trace_param.m:
Add a new predicate for use by the updated code in handle_options.m.
compiler/error_util.m:
compiler/hlds_error_util.m:
Make error_util.m to be a submodule of parse_tree.m, not hlds.m.
Most of its predicates are not dependent on HLDS data structures.
Move the ones that are into a new module, hlds_error_util, that
is a submodule of hlds.m. Overall, this reduces the dependence
of submodules of parse_tree.m, including modules.m, on submodules
of hlds.m.
compiler/notes/compiler_design.html:
Update the documentation of compiler modes to account for
hlds_error_util.m.
compiler/hlds.m:
compiler/parse_tree.m:
Update the list of included submodules.
compiler/*.m:
Update module imports and module qualifications as needed for the
change above.
tests/invalid/*.{exp,exp2}:
Update the expected outputs of a bunch of test cases to reflect the new
format of some warning messages due to the user error_util; they now
observe line length limits, and print contexts in some cases where they
were previously missing.
120 lines
3.7 KiB
Mathematica
120 lines
3.7 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-2004 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% error_util.m
|
|
% Main author: zs.
|
|
%
|
|
% This module contains code that can be helpful in the formatting of
|
|
% error messages. It builds upon parse_tree__error_util, and extends it
|
|
% with predicates that access HLDS data structures.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module hlds__hlds_error_util.
|
|
|
|
:- interface.
|
|
|
|
:- import_module hlds__hlds_module.
|
|
:- import_module hlds__hlds_pred.
|
|
:- import_module parse_tree__prog_data.
|
|
:- import_module parse_tree__error_util.
|
|
|
|
:- import_module assoc_list, list, std_util.
|
|
|
|
% Predicates to convert a predicate names to strings.
|
|
|
|
:- pred describe_one_pred_name(module_info::in, pred_id::in,
|
|
string::out) is det.
|
|
|
|
:- pred describe_several_pred_names(module_info::in,
|
|
list(pred_id)::in, list(format_component)::out) is det.
|
|
|
|
:- pred describe_one_proc_name(module_info::in, pred_proc_id::in,
|
|
string::out) is det.
|
|
|
|
:- pred describe_several_proc_names(module_info::in,
|
|
list(pred_proc_id)::in, list(format_component)::out) is det.
|
|
|
|
:- pred describe_one_call_site(module_info::in,
|
|
pair(pred_proc_id, prog_context)::in, string::out) is det.
|
|
|
|
:- pred describe_several_call_sites(module_info::in,
|
|
assoc_list(pred_proc_id, prog_context)::in,
|
|
list(format_component)::out) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module parse_tree__prog_out.
|
|
:- import_module parse_tree__prog_util.
|
|
|
|
:- import_module string, list, term.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% The code of this predicate duplicates the functionality of
|
|
% hlds_out__write_pred_id. Changes here should be made there as well.
|
|
|
|
describe_one_pred_name(Module, PredId, Piece) :-
|
|
module_info_pred_info(Module, PredId, PredInfo),
|
|
ModuleName = pred_info_module(PredInfo),
|
|
prog_out__sym_name_to_string(ModuleName, ModuleNameString),
|
|
PredName = pred_info_name(PredInfo),
|
|
Arity = pred_info_arity(PredInfo),
|
|
PredOrFunc = pred_info_is_pred_or_func(PredInfo),
|
|
PredOrFuncPart = pred_or_func_to_string(PredOrFunc),
|
|
adjust_func_arity(PredOrFunc, OrigArity, Arity),
|
|
(
|
|
pred_info_get_goal_type(PredInfo, promise(PromiseType))
|
|
->
|
|
Piece = "`" ++ promise_to_string(PromiseType) ++ "' declaration"
|
|
;
|
|
string__int_to_string(OrigArity, ArityPart),
|
|
string__append_list([
|
|
PredOrFuncPart,
|
|
" `",
|
|
ModuleNameString,
|
|
".",
|
|
PredName,
|
|
"/",
|
|
ArityPart,
|
|
"'"], Piece)
|
|
).
|
|
|
|
describe_several_pred_names(Module, PredId, Pieces) :-
|
|
list__map(describe_one_pred_name(Module), PredId, Pieces0),
|
|
list_to_pieces(Pieces0, Pieces).
|
|
|
|
describe_one_proc_name(Module, proc(PredId, ProcId), Piece) :-
|
|
describe_one_pred_name(Module, PredId, PredPiece),
|
|
proc_id_to_int(ProcId, ProcIdInt),
|
|
string__int_to_string(ProcIdInt, ProcIdPart),
|
|
string__append_list([
|
|
PredPiece,
|
|
" mode ",
|
|
ProcIdPart
|
|
], Piece).
|
|
|
|
describe_several_proc_names(Module, PPIds, Pieces) :-
|
|
list__map(describe_one_proc_name(Module), PPIds, Pieces0),
|
|
list_to_pieces(Pieces0, Pieces).
|
|
|
|
describe_one_call_site(Module, PPId - Context, Piece) :-
|
|
describe_one_proc_name(Module, PPId, ProcName),
|
|
term__context_file(Context, FileName),
|
|
term__context_line(Context, LineNumber),
|
|
string__int_to_string(LineNumber, LineNumberPart),
|
|
string__append_list([
|
|
ProcName,
|
|
" at ",
|
|
FileName,
|
|
":",
|
|
LineNumberPart
|
|
], Piece).
|
|
|
|
describe_several_call_sites(Module, Sites, Pieces) :-
|
|
list__map(describe_one_call_site(Module), Sites, Pieces0),
|
|
list_to_pieces(Pieces0, Pieces).
|