@@ -550,6 +550,7 @@ class FORTRAN : public Language {
550
550
551
551
// Module-wide procedure interfaces
552
552
Hash *d_overloads; // !< Overloaded subroutine -> overload names
553
+ Hash *d_private_overloads; // !< Overloaded subroutine flagged for 'private' use
553
554
554
555
// Current class parameters
555
556
String *f_class; // !< Proxy code in currently generated class
@@ -585,7 +586,9 @@ class FORTRAN : public Language {
585
586
virtual String *makeParameterName (Node *n, Parm *p, int arg_num, bool is_setter = false ) const ;
586
587
virtual void replaceSpecialVariables (String *method, String *tm, Parm *parm);
587
588
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 ) {}
589
592
590
593
private:
591
594
Wrapper *cfuncWrapper (Node *n);
@@ -608,6 +611,8 @@ class FORTRAN : public Language {
608
611
bool is_wrapped_type (SwigType *classnametype);
609
612
bool is_wrapped_class (Node *n);
610
613
614
+ // Add n overloaded
615
+ int add_overload (String *fsymname, Node *n, String *fname, bool is_private);
611
616
// Add lowercase symbol (fortran) to the module's namespace
612
617
int add_fsymbol (String *s, Node *n);
613
618
// Whether the current class is a BIND(C) struct
@@ -729,6 +734,7 @@ int FORTRAN::top(Node *n) {
729
734
d_emitted_mangled = NewHash ();
730
735
d_callbacks = NewHash ();
731
736
d_overloads = NewHash ();
737
+ d_private_overloads = NewHash ();
732
738
733
739
// >>> PROCESS
734
740
@@ -769,6 +775,7 @@ int FORTRAN::top(Node *n) {
769
775
770
776
// Clean up files and other data
771
777
Delete (d_overloads);
778
+ Delete (d_private_overloads);
772
779
Delete (d_callbacks);
773
780
Delete (d_emitted_mangled);
774
781
Delete (f_fsubprograms);
@@ -855,11 +862,10 @@ void FORTRAN::write_module(String *filename) {
855
862
// Write overloaded procedure names
856
863
int line_length = 19 ;
857
864
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
+ }
863
869
}
864
870
865
871
if (Len (f_fabstract) > 0 ) {
@@ -1133,6 +1139,7 @@ int FORTRAN::functionWrapper(Node *n) {
1133
1139
1134
1140
// >>> GENERATE CODE FOR MODULE INTERFACE
1135
1141
1142
+ bool fprivate = GetFlag (n, " fortran:private" );
1136
1143
if (member) {
1137
1144
// Wrapping a member function
1138
1145
ASSERT_OR_PRINT_NODE (!this ->is_bindc_struct (), n);
@@ -1142,7 +1149,7 @@ int FORTRAN::functionWrapper(Node *n) {
1142
1149
1143
1150
String *qualifiers = NewStringEmpty ();
1144
1151
1145
- if (generic || GetFlag (n, " fortran:private " ) ) {
1152
+ if (generic || fprivate ) {
1146
1153
Append (qualifiers, " , private" );
1147
1154
}
1148
1155
if (String *extra_quals = Getattr (n, " fortran:procedure" )) {
@@ -1167,22 +1174,11 @@ int FORTRAN::functionWrapper(Node *n) {
1167
1174
// Declare a private procedure
1168
1175
Printv (f_class, fname, " \n " , NULL );
1169
1176
}
1170
- } else if (GetFlag (n, " fortran:private" )) {
1171
- /* Don't write the public accessor */
1172
1177
} 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) {
1186
1182
// Expose the proxy function with its native name
1187
1183
ASSERT_OR_PRINT_NODE (fname && Len (fname) > 0 , n);
1188
1184
Printv (f_fdecl, " public :: " , fname, " \n " , NULL );
@@ -3221,6 +3217,31 @@ bool FORTRAN::is_wrapped_class(Node *n) {
3221
3217
return result;
3222
3218
}
3223
3219
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
+
3224
3245
/* -------------------------------------------------------------------------
3225
3246
* \brief Add lowercase symbol since fortran is case insensitive
3226
3247
*
0 commit comments