Skip to content

Commit d867471

Browse files
committed
Fix enum int parameter construction
Previously, when %fortranconst is globally enabled but %nofortranconst is applied to an enum type, the enum value would be wrapped as an `integer, parameter`.
1 parent dd5e330 commit d867471

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Examples/test-suite/fortran_global_const.i

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,18 @@ typedef enum {
5050

5151
%}
5252

53+
/* Test wrapping everything */
54+
%fortranconst;
55+
%nofortranconst NFCEnum;
56+
57+
%inline %{
58+
typedef enum {
59+
FCSierra = 1,
60+
FCJuliet
61+
} FCEnum;
62+
63+
typedef enum {
64+
NFCWhiskey = 0x123
65+
} NFCEnum;
66+
67+
%}

Source/Modules/fortran.cxx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ int fix_fortran_dims(Node *n, const char *tmap_name, String *typemap) {
167167
}
168168

169169
/* -------------------------------------------------------------------------
170-
* \brief Determine whether to wrap an enum as a value.
170+
* \brief Determine whether to wrap an enum as a fortran parameter.
171171
*/
172-
bool is_native_enum(Node *n) {
172+
bool is_native_enum_decl(Node *n) {
173173
String *enum_feature = Getattr(n, "feature:fortran:const");
174174
if (!enum_feature) {
175175
// Determine from enum values
@@ -2897,7 +2897,7 @@ int FORTRAN::enumDeclaration(Node *n) {
28972897

28982898
// Determine whether to add enum as a native fortran enumeration. If false,
28992899
// the values are all wrapped as constants. Only create the list if values are defined.
2900-
bool is_native = is_native_enum(n) && firstChild(n);
2900+
bool is_native = is_native_enum_decl(n) && firstChild(n);
29012901

29022902
// Check all enum values and update their names
29032903
for (Node *c = firstChild(n); c; c = nextSibling(c)) {
@@ -3021,25 +3021,25 @@ int FORTRAN::callbackfunctionHandler(Node *n) {
30213021
* and enum values.
30223022
*
30233023
* - Native enum values will become enumerators
3024-
* - Constants marked with `%fortranconst` will be rendered as *named constants*
30253024
* - Non-native enum values become C-bound external constants
3025+
* - Constants marked with `%fortranconst` will be rendered as *named constants*
30263026
* - Constants marked with `%fortranbindc` also become C-bound external constants
30273027
* - All other types will generate `getter` functions that return native fortran types.
30283028
*/
30293029
int FORTRAN::constantWrapper(Node *n) {
30303030
enum {
30313031
NATIVE_ENUM,
3032-
NATIVE_CONSTANT,
30333032
EXTERN_ENUM,
3033+
NATIVE_CONSTANT,
30343034
EXTERN_CONSTANT
30353035
} constant_type;
30363036

30373037
if (d_enum_public) {
30383038
constant_type = NATIVE_ENUM;
3039-
} else if (GetFlag(n, "feature:fortran:const") || Getattr(n, "feature:fortran:constvalue")) {
3040-
constant_type = NATIVE_CONSTANT;
30413039
} else if (Cmp(nodeType(n), "enumitem") == 0) {
30423040
constant_type = EXTERN_ENUM;
3041+
} else if (GetFlag(n, "feature:fortran:const") || Getattr(n, "feature:fortran:constvalue")) {
3042+
constant_type = NATIVE_CONSTANT;
30433043
} else if (GetFlag(n, "feature:fortran:bindc") && has_constant_storage(n)) {
30443044
constant_type = EXTERN_CONSTANT;
30453045
} else {

0 commit comments

Comments
 (0)