mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-18 19:03:45 +00:00
compiler/parse_tree_out.m:
As a first step toward disallowing any module qualification on the names
of constants in foreign_enum pragmas, do not generate any such qualifiers
when writing foreign_enum pragmas to interface files.
compiler/parse_pragma.m:
When reading in constant names in foreign_enum pragmas, insist on any
module qualification to be for the current module. This is to allow
the checks for this error to be removed from the rest of the compiler,
which will be needed when the representation of foreign_enums is changed
to store constant names as just strings, not sym_names.
compiler/options.m:
Provide a mechanism to test whether the installed compiler has this change.
The second step of this change will require this first step in order to
avoid problems with module qualified constant names in .int files.
doc/reference_manual.texi:
Make the proposed rule against module qualification of constants
in foreign_enums explicit.
tests/hard_coded/foreign_enum_mod2.m:
Delete qualifiers on constant names.
73 lines
1.4 KiB
Mathematica
73 lines
1.4 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module foreign_enum_mod2.
|
|
:- interface.
|
|
|
|
:- type instrument.
|
|
|
|
:- type ingredient
|
|
---> eggs
|
|
; sugar
|
|
; flour
|
|
; milk.
|
|
|
|
:- func my_instrument = instrument.
|
|
|
|
:- implementation.
|
|
|
|
:- type instrument
|
|
---> violin
|
|
; piano
|
|
; xylophone.
|
|
|
|
:- type foo
|
|
---> foo
|
|
; bar
|
|
; baz.
|
|
|
|
my_instrument = piano.
|
|
|
|
% This should end up in the .int file.
|
|
%
|
|
:- pragma foreign_enum("C", ingredient/0, [
|
|
eggs - "EGGS",
|
|
sugar - "SUGAR",
|
|
flour - "FLOUR",
|
|
milk - "MILK"
|
|
]).
|
|
|
|
% As should this.
|
|
% XXX not currently supported in Java grade.
|
|
%:- pragma foreign_enum("Java", ingredient/0, [
|
|
% eggs - "Ingredient.EGGS",
|
|
% sugar - "Ingredient.SUGAR",
|
|
% flour - "Ingredient.FLOUR",
|
|
% milk - "Ingredient.MILK"
|
|
%]).
|
|
|
|
% This shouldn't since the type is not exported.
|
|
%
|
|
:- pragma foreign_enum("C", foo/0, [
|
|
foo - "3",
|
|
bar - "4",
|
|
baz - "5"
|
|
]).
|
|
|
|
% This shouldn't since the type is abstract.
|
|
%
|
|
:- pragma foreign_enum("C", instrument/0, [
|
|
violin - "100",
|
|
piano - "200",
|
|
xylophone - "300"
|
|
]).
|
|
|
|
:- pragma foreign_decl("C", "
|
|
|
|
#define EGGS 10
|
|
#define SUGAR 20
|
|
#define FLOUR 30
|
|
#define MILK 40
|
|
").
|