Skip to content

Commit 8dba6ae

Browse files
committed
Allow private module procedures
1 parent 06a1cc6 commit 8dba6ae

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

Source/Modules/fortran.cxx

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ class FORTRAN : public Language {
550550

551551
// Module-wide procedure interfaces
552552
Hash *d_overloads; //!< Overloaded subroutine -> overload names
553+
Hash *d_private_overloads; //!< Overloaded subroutine flagged for 'private' use
553554

554555
// Current class parameters
555556
String *f_class; //!< Proxy code in currently generated class
@@ -585,7 +586,9 @@ class FORTRAN : public Language {
585586
virtual String *makeParameterName(Node *n, Parm *p, int arg_num, bool is_setter = false) const;
586587
virtual void replaceSpecialVariables(String *method, String *tm, Parm *parm);
587588

588-
FORTRAN() : d_emitted_mangled(NULL), d_callbacks(NULL), d_overloads(NULL), f_class(NULL), d_method_overloads(NULL), d_constructors(NULL), d_enum_public(NULL) {}
589+
FORTRAN() :
590+
d_emitted_mangled(NULL), d_callbacks(NULL), d_overloads(NULL), d_private_overloads(NULL), f_class(NULL), d_method_overloads(NULL), d_constructors(NULL),
591+
d_enum_public(NULL) {}
589592

590593
private:
591594
Wrapper *cfuncWrapper(Node *n);
@@ -608,6 +611,8 @@ class FORTRAN : public Language {
608611
bool is_wrapped_type(SwigType *classnametype);
609612
bool is_wrapped_class(Node *n);
610613

614+
// Add n overloaded
615+
int add_overload(String *fsymname, Node *n, String *fname, bool is_private);
611616
// Add lowercase symbol (fortran) to the module's namespace
612617
int add_fsymbol(String *s, Node *n);
613618
// Whether the current class is a BIND(C) struct
@@ -729,6 +734,7 @@ int FORTRAN::top(Node *n) {
729734
d_emitted_mangled = NewHash();
730735
d_callbacks = NewHash();
731736
d_overloads = NewHash();
737+
d_private_overloads = NewHash();
732738

733739
// >>> PROCESS
734740

@@ -769,6 +775,7 @@ int FORTRAN::top(Node *n) {
769775

770776
// Clean up files and other data
771777
Delete(d_overloads);
778+
Delete(d_private_overloads);
772779
Delete(d_callbacks);
773780
Delete(d_emitted_mangled);
774781
Delete(f_fsubprograms);
@@ -855,11 +862,10 @@ void FORTRAN::write_module(String *filename) {
855862
// Write overloaded procedure names
856863
int line_length = 19;
857864
line_length = print_wrapped_list(out, First(kv.item), line_length);
858-
Printv(out,
859-
"\n"
860-
" end interface\n"
861-
" public :: ", kv.key, "\n",
862-
NULL);
865+
Printv(out, "\n end interface\n", NULL);
866+
if (!GetFlag(d_private_overloads, kv.key)) {
867+
Printv(out, " public :: ", kv.key, "\n", NULL);
868+
}
863869
}
864870

865871
if (Len(f_fabstract) > 0) {
@@ -1133,6 +1139,7 @@ int FORTRAN::functionWrapper(Node *n) {
11331139

11341140
// >>> GENERATE CODE FOR MODULE INTERFACE
11351141

1142+
bool fprivate = GetFlag(n, "fortran:private");
11361143
if (member) {
11371144
// Wrapping a member function
11381145
ASSERT_OR_PRINT_NODE(!this->is_bindc_struct(), n);
@@ -1142,7 +1149,7 @@ int FORTRAN::functionWrapper(Node *n) {
11421149

11431150
String *qualifiers = NewStringEmpty();
11441151

1145-
if (generic || GetFlag(n, "fortran:private")) {
1152+
if (generic || fprivate) {
11461153
Append(qualifiers, ", private");
11471154
}
11481155
if (String *extra_quals = Getattr(n, "fortran:procedure")) {
@@ -1167,22 +1174,11 @@ int FORTRAN::functionWrapper(Node *n) {
11671174
// Declare a private procedure
11681175
Printv(f_class, fname, "\n", NULL);
11691176
}
1170-
} else if (GetFlag(n, "fortran:private")) {
1171-
/* Don't write the public accessor */
11721177
} else if (fsymname) {
1173-
// The module function name is aliased, and perhaps overloaded.
1174-
// Append this function name to the list of overloaded names
1175-
// for the symbol. The 'public' access specification gets added later.
1176-
List *overloads = Getattr(d_overloads, fsymname);
1177-
if (!overloads) {
1178-
// If this is the first overload, make sure the symname is added to the global scope
1179-
if (add_fsymbol(fsymname, n) == SWIG_NOWRAP)
1180-
return SWIG_NOWRAP;
1181-
overloads = NewList();
1182-
Setattr(d_overloads, fsymname, overloads);
1183-
}
1184-
Append(overloads, fname);
1185-
} else {
1178+
int result = this->add_overload(fsymname, n, fname, fprivate);
1179+
if (result == SWIG_NOWRAP)
1180+
return SWIG_NOWRAP;
1181+
} else if (!fprivate) {
11861182
// Expose the proxy function with its native name
11871183
ASSERT_OR_PRINT_NODE(fname && Len(fname) > 0, n);
11881184
Printv(f_fdecl, " public :: ", fname, "\n", NULL);
@@ -3221,6 +3217,31 @@ bool FORTRAN::is_wrapped_class(Node *n) {
32213217
return result;
32223218
}
32233219

3220+
/* -------------------------------------------------------------------------
3221+
* \brief Add an overload for the generic method "fsymname" and the specific
3222+
* procedure name "fname".
3223+
*
3224+
* Return SWIG_NOWRAP if the name conflicts.
3225+
*/
3226+
int FORTRAN::add_overload(String *fsymname, Node *n, String *fname, bool is_private) {
3227+
// The module function name is aliased, and perhaps overloaded.
3228+
// Append this function name to the list of overloaded names
3229+
// for the symbol. The 'public' access specification gets added later.
3230+
List *overloads = Getattr(d_overloads, fsymname);
3231+
if (!overloads) {
3232+
// If this is the first overload, make sure the symname is added to the global scope
3233+
if (add_fsymbol(fsymname, n) == SWIG_NOWRAP)
3234+
return SWIG_NOWRAP;
3235+
overloads = NewList();
3236+
Setattr(d_overloads, fsymname, overloads);
3237+
}
3238+
Append(overloads, fname);
3239+
if (is_private) {
3240+
SetFlag(d_private_overloads, fsymname);
3241+
}
3242+
return SWIG_OK;
3243+
}
3244+
32243245
/* -------------------------------------------------------------------------
32253246
* \brief Add lowercase symbol since fortran is case insensitive
32263247
*

0 commit comments

Comments
 (0)