Files
mercury/compiler/parse_types.m
Zoltan Somogyi 99334e8469 Switch to structured item sequence numbers.
compiler/prog_data.m:
    Define a data type that encodes the distinction between valid
    and dummy item sequence numbers in the type. Previously, different
    parts of the compiler expressed this distinction in two different ways,
    either using "-1" to represent a dummy sequence number, or using "no"
    in a maybe(int) type.

compiler/prog_item.m:
    Use the new type instead of plain "int" as the sequence number in items.

compiler/hlds_pred.m:
    Use the new type instead of plain "int" as the sequence number
    in cur_user_decl_infos. Document the fact that the presence of a
    cur_user_decl_info in a pred_info does NOT guarantee a valid
    item sequence number.

compiler/add_foreign_proc.m:
    When adding a foreign_proc to the HLDS, pass a whole item_pragma_info,
    not its components. (This change is what this diff started as, before
    the item_seq_num changes overwhelmed it.)

compiler/accumulator.m:
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_special_pred.m:
compiler/check_typeclass.m:
compiler/comp_unit_interface.m:
compiler/decide_type_repn.m:
compiler/default_func_mode.m:
compiler/hlds_clauses.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/make_hlds_passes.m:
compiler/par_loop_control.m:
compiler/parse_class.m:
compiler/parse_dcg_goal.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_mutable.m:
compiler/parse_pragma.m:
compiler/parse_pragma_analysis.m:
compiler/parse_pragma_foreign.m:
compiler/parse_pragma_tabling.m:
compiler/parse_type_defn.m:
compiler/parse_type_repn.m:
compiler/parse_types.m:
compiler/proc_requests.m:
compiler/prog_mutable.m:
compiler/split_parse_tree_src.m:
compiler/stm_expand.m:
compiler/style_checks.m:
compiler/table_gen.m:
    Conform to the changes above.
2021-05-19 13:27:27 +10:00

137 lines
5.2 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_util.
:- 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_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(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(list(error_spec)).
% The term was completely dealt with during parsing, which
% may have generated some messages. If it did, they are attached;
% otherwise, the list will be empty.
%
% As of this writing, this is 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_component).
%---------------------------------------------------------------------------%
:- implementation.
:- import_module parse_tree.item_util.
iom_desc_pieces(IOM) = Pieces :-
(
IOM = iom_item(Item),
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(_Specs),
Pieces = []
).
%---------------------------------------------------------------------------%
:- end_module parse_tree.parse_types.
%---------------------------------------------------------------------------%