mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 14:25:56 +00:00
Implement syntax for getting and setting fields of constructors.
Estimated hours taken: 70 Implement syntax for getting and setting fields of constructors. compiler/make_hlds.m: Add information about field definitions to the module_info. Check that user-defined field access functions for exported fields are also exported, otherwise predicates in other modules could use a different method to access a field than predicates in module defining the field. Add a `predicate preds_add_implicit_report_error' to allow that check to be performed for functions which are added to the module_info by some means other than a `:- func' declaration. Parse field access goals and expressions. Add predicates `insert_arg_unifications_with_supplied_contexts', and `append_arg_unification', which allow more control over the contexts given to the added unifications. These are useful because the field value for an update is really an argument of the inner-most update function call, while the input term is an argument of the outer-most function call. compiler/prog_io_dcg.m: Allow DCG goals of the form `:=(DCGArg)', which unifies `DCGArg' with the output DCG argument, ignoring the input DCG argument. The rationale for this change is that if we have convenient syntax for updating parts of a DCG argument, we should also have convenient syntax for updating the whole DCG argument. compiler/typecheck.m: Add a default clause for field access functions for which the user has supplied type and mode declarations but no clauses. Typecheck field access function calls. Use `io__write_list' to remove some duplication of code to write out comma separated lists of error descriptions. compiler/post_typecheck.m: Expand field accessor goals into the equivalent unifications. They are expanded inline rather than generating new get and set predicates for field name to avoid having to work out how to mode the generated predicates. Remove an unnecessary goal traversal to qualify function calls and constructors. That code is now called from purity.m. compiler/prog_data.m: compiler/prog_io.m: compiler/mercury_to_goedel.m: compiler/mercury_to_mercury.m: Store field names as `sym_name's rather than strings. Use a `maybe' type rather than an empty string to designate an unlabelled field. compiler/hlds_data.m: Define data structures to hold information about the field names visible in a module. compiler/hlds_module.m: Add a field to type module_info to hold information about the fields visible in a module. compiler/hlds_pred.m: Add predicates to identify field access function names, and to handle the arguments of field access functions. compiler/make_hlds.m: compiler/hlds_goal.m: compiler/modecheck_call.m: compiler/higher_order.m: compiler/purity.m: compiler/polymorphism.m: compiler/dnf.m: compiler/cse_detection.m: compiler/lambda.m: Move `create_atomic_unification' from make_hlds.m to hlds_goal.m because it is used by several other modules. compiler/hlds_goal.m: Add a version of goal_info_init which takes the context of the goal, for use by make_hlds.m. compiler/type_util.m: Add a predicate `type_util__get_type_and_cons_defn' to get the hlds_type_defn and hlds_cons_defn for a user-defined constructor. compiler/prog_util.m: Add predicates to add and remove prefixes or suffixes from the unqualified part of a sym_name. compiler/prog_out.m: Add a predicate to convert a `sym_name/arity' to a string. compiler/hlds_out.m: Add `hlds_out__simple_call_id_to_string' to convert a `pred_or_func - sym_name/arity' to a string for use in error messages. compiler/purity.m: Thread through the pred_info so that the expansion of field accessor goals can add new variables. compiler/mercury_to_mercury.m: library/ops.m: Reduce precedence of `^/2' for use as a field name separator. Add operator `^'/1 to designate which side of the `:=' is the field name in a DCG field access goal. Add operator `:=/2' for field update expressions. doc/reference_manual.texi: Document the new syntax. doc/transition_guide.texi: Document the new operators. tests/hard_coded/Mmakefile: tests/hard_coded/record_syntax.m: tests/hard_coded/record_syntax.exp: tests/invalid/Mmakefile: tests/invalid/record_syntax_errors.m: tests/invalid/record_syntax_errors.err_exp: Test cases.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
%-----------------------------------------------------------------------------%
|
||||
% Copyright (C) 1994-1999 The University of Melbourne.
|
||||
% Copyright (C) 1994-2000 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.
|
||||
%-----------------------------------------------------------------------------%
|
||||
@@ -61,6 +61,33 @@
|
||||
:- pred match_sym_name(sym_name, sym_name).
|
||||
:- mode match_sym_name(in, in) is semidet.
|
||||
|
||||
% remove_sym_name_prefix(SymName0, Prefix, SymName)
|
||||
% succeeds iff
|
||||
% SymName and SymName0 have the same module qualifier
|
||||
% and the unqualified part of SymName0 has the given prefix
|
||||
% and the unqualified part of SymName is the unqualified
|
||||
% part of SymName0 with the prefix removed
|
||||
:- pred remove_sym_name_prefix(sym_name, string, sym_name).
|
||||
:- mode remove_sym_name_prefix(in, in, out) is semidet.
|
||||
:- mode remove_sym_name_prefix(out, in, in) is det.
|
||||
|
||||
% remove_sym_name_suffix(SymName0, Suffix, SymName)
|
||||
% succeeds iff
|
||||
% SymName and SymName0 have the same module qualifier
|
||||
% and the unqualified part of SymName0 has the given suffix
|
||||
% and the unqualified part of SymName is the unqualified
|
||||
% part of SymName0 with the suffix removed
|
||||
:- pred remove_sym_name_suffix(sym_name, string, sym_name).
|
||||
:- mode remove_sym_name_suffix(in, in, out) is semidet.
|
||||
|
||||
% add_sym_name_suffix(SymName0, Suffix, SymName)
|
||||
% succeeds iff
|
||||
% SymName and SymName0 have the same module qualifier
|
||||
% and the unqualified part of SymName is the unqualified
|
||||
% part of SymName0 with the suffix added
|
||||
:- pred add_sym_name_suffix(sym_name, string, sym_name).
|
||||
:- mode add_sym_name_suffix(in, in, out) is det.
|
||||
|
||||
% insert_module_qualifier(ModuleName, SymName0, SymName):
|
||||
% prepend the specified ModuleName onto the module
|
||||
% qualifiers in SymName0, giving SymName.
|
||||
@@ -321,6 +348,26 @@ match_sym_name(unqualified(Name), qualified(_, Name)).
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
remove_sym_name_prefix(qualified(Module, Name0), Prefix,
|
||||
qualified(Module, Name)) :-
|
||||
string__append(Prefix, Name, Name0).
|
||||
remove_sym_name_prefix(unqualified(Name0), Prefix, unqualified(Name)) :-
|
||||
string__append(Prefix, Name, Name0).
|
||||
|
||||
remove_sym_name_suffix(qualified(Module, Name0), Suffix,
|
||||
qualified(Module, Name)) :-
|
||||
string__remove_suffix(Name0, Suffix, Name).
|
||||
remove_sym_name_suffix(unqualified(Name0), Suffix, unqualified(Name)) :-
|
||||
string__remove_suffix(Name0, Suffix, Name).
|
||||
|
||||
add_sym_name_suffix(qualified(Module, Name0), Suffix,
|
||||
qualified(Module, Name)) :-
|
||||
string__append(Name0, Suffix, Name).
|
||||
add_sym_name_suffix(unqualified(Name0), Suffix, unqualified(Name)) :-
|
||||
string__append(Name0, Suffix, Name).
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
make_pred_name_with_context(ModuleName, Prefix,
|
||||
PredOrFunc, PredName, Line, Counter, SymName) :-
|
||||
make_pred_name(ModuleName, Prefix, yes(PredOrFunc), PredName,
|
||||
|
||||
Reference in New Issue
Block a user