Files
mercury/compiler/parse_types.m
Zoltan Somogyi 307b1dc148 Split up error_util.m into five modules.
compiler/error_spec.m:
    This new module contains the part of the old error_util.m that defines
    the error_spec type, and some functions that can help construct pieces
    of error_specs. Most modules of the compiler that deal with errors
    will need to import only this part of the old error_util.m.

    This change also renames the format_component type to format_piece,
    which matches our long-standing naming convention for variables containing
    (lists of) values of this type.

compiler/write_error_spec.m:
    This new module contains the part of the old error_util.m that
    writes out error specs, and converts them to strings.

    This diff marks as obsolete the versions of predicates that
    write out error specs to the current output stream, without
    *explicitly* specifying the intended stream.

compiler/error_sort.m:
    This new module contains the part of the old error_util.m that
    sorts lists of error specs and error msgs.

compiler/error_type_util.m:
    This new module contains the part of the old error_util.m that
    convert types to format_pieces that generate readable output.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Include and document the new modules.

compiler/error_util.m:
    The code remaining in the original error_util.m consists of
    general utility predicates and functions that don't fit into
    any of the modules above.

    Delete an unneeded pair of I/O states from the argument list
    of a predicate.

compiler/file_util.m:
    Move the unable_to_open_file predicate here from error_util.m,
    since it belongs here. Mark another predicate that writes
    to the current output stream as obsolete.

compiler/hlds_error_util.m:
    Mark two predicates that wrote out error_spec to the current output
    stream as obsolete, and add versions that take an explicit output stream.

compiler/Mercury.options:
    Compile the modules that call the newly obsoleted predicates
    with --no-warn-obsolete, for the time being.

compiler/*.m:
    Conform to the changes above, mostly by updating import_module
    declarations, and renaming format_component to format_piece.
2022-10-12 20:50:16 +11:00

146 lines
5.5 KiB
Mathematica

%-----------------------------------------------------------------------------e
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------e
% Copyright (C) 2015 The Mercury team.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%---------------------------------------------------------------------------%
%
% This module defines a type used by several modules that parse items
% and/or markers.
%
%---------------------------------------------------------------------------%
:- module parse_tree.parse_types.
:- interface.
:- import_module mdbcomp.
:- import_module mdbcomp.sym_name.
:- import_module parse_tree.error_spec.
:- import_module parse_tree.prog_data.
:- import_module parse_tree.prog_item.
:- import_module recompilation.
:- import_module list.
:- import_module one_or_more.
% This type represents the result of parsing one term.
:- type item_or_marker
---> iom_item(item)
% The term contains an item.
; iom_item_and_error_specs(item, list(error_spec))
% The term contains an item. This item has errors that we want
% to report, but from which we have recovered in a useful
% though probably not perfect manner.
; iom_marker_include(one_or_more(item_include))
% The term contains an `:- include_module' declaration.
; iom_marker_avail(one_or_more(item_avail))
% The term contains an `:- import_module' or `:- use_module'
% declaration.
; iom_marker_fim(item_fim)
% The term contains a `:- pragma foreign_import_module'
% declaration.
; iom_marker_version_numbers(module_item_version_numbers)
% The term was a record of the version numbers of the items
% in an interface file.
; iom_marker_src_file(string)
% The term was a pragma specifying the new filename.
; iom_marker_module_start(module_name, prog_context, item_seq_num)
% The term was a `:- module' declaration. The arguments give
% the module's name, and the context and sequence number of the
% declaration. The module name is exactly what was in the
% declaration; it is NOT implicitly module qualified by the
% enclosing module.
; iom_marker_module_end(module_name, prog_context, item_seq_num)
% The term was a `:- end_module' declaration. The arguments give
% the module's name, and the context and sequence number of the
% declaration. Again, the module name as is, and not implicitly
% module qualified.
; iom_marker_section(module_section, prog_context, item_seq_num)
% The term was a `:- interface' or `:- implementation' declaration.
% The arguments give the section's kind, and the context
% and sequence number of the declaration.
; iom_handled_no_error
; iom_handled_error(list(error_spec)).
% The term was completely dealt with during parsing.
% If there was an error, one or more messages for it are attached.
%
% As of this writing, these are used only for require_feature_set
% pragmas that don't require any features, and for version_number
% items recorded by old compiler versions in a now-obsolete format.
:- func iom_desc_pieces(item_or_marker) = list(format_piece).
%---------------------------------------------------------------------------%
:- implementation.
:- import_module parse_tree.item_util.
iom_desc_pieces(IOM) = Pieces :-
(
( IOM = iom_item(Item)
; IOM = iom_item_and_error_specs(Item, _Specs)
),
Pieces = item_desc_pieces(Item)
;
IOM = iom_marker_include(_),
Pieces = [words("an"), decl("include_module"), words("declaration")]
;
IOM = iom_marker_avail(one_or_more(HeadAvail, _TailAvails)),
(
HeadAvail = avail_import(_),
Pieces = [words("an"), decl("import_module"),
words("declaration")]
;
HeadAvail = avail_use(_),
Pieces = [words("a"), decl("use_module"), words("declaration")]
)
;
IOM = iom_marker_fim(_),
Pieces = [words("a"), pragma_decl("foreign_import_module"),
words("declaration")]
;
IOM = iom_marker_version_numbers(_),
Pieces = [words("a version number map")]
;
IOM = iom_marker_src_file(_),
Pieces = [words("a"), pragma_decl("source_file"), words("declaration")]
;
IOM = iom_marker_module_start(_, _, _),
Pieces = [words("a"), decl("module"), words("declaration")]
;
IOM = iom_marker_module_end(_, _, _),
Pieces = [words("an"), decl("end_module"), words("declaration")]
;
IOM = iom_marker_section(SectionKind, _, _),
(
SectionKind = ms_interface,
Pieces = [words("an"), decl("interface"), words("declaration")]
;
SectionKind = ms_implementation,
Pieces = [words("an"), decl("implementation"),
words("declaration")]
)
;
( IOM = iom_handled_no_error
; IOM = iom_handled_error(_Specs)
),
Pieces = []
).
%---------------------------------------------------------------------------%
:- end_module parse_tree.parse_types.
%---------------------------------------------------------------------------%