@@ -617,7 +617,6 @@ class FORTRAN : public Language {
617
617
// Current class parameters
618
618
String *f_class; // !< Proxy code in currently generated class
619
619
Hash *d_method_overloads; // !< Overloaded subroutine -> overload names
620
- List *d_constructors; // !< Overloaded subroutine -> overload names
621
620
622
621
// Inside of the 'enum' definitions
623
622
List *d_enum_public; // !< List of enumerator values
@@ -693,7 +692,7 @@ class FORTRAN : public Language {
693
692
* \brief Constructor.
694
693
*/
695
694
FORTRAN::FORTRAN () :
696
- d_emitted_mangled(NULL ), d_callbacks(NULL ), d_overloads(NULL ), d_private_overloads(NULL ), f_class(NULL ), d_method_overloads(NULL ), d_constructors( NULL ),
695
+ d_emitted_mangled(NULL ), d_callbacks(NULL ), d_overloads(NULL ), d_private_overloads(NULL ), f_class(NULL ), d_method_overloads(NULL ),
697
696
d_enum_public(NULL ) {
698
697
699
698
// Mark this language as supporting directors
@@ -999,14 +998,20 @@ void FORTRAN::write_module(String *filename) {
999
998
1000
999
// Overloads and renamed module procedures
1001
1000
for (Iterator kv = First (d_overloads); kv.key ; kv = Next (kv)) {
1001
+ Iterator proc_name_list = First (kv.item );
1002
+ if (!proc_name_list.item ) {
1003
+ // Skip empty overload list, probably from lack of class constructors
1004
+ continue ;
1005
+ }
1006
+
1002
1007
Printv (out,
1003
1008
" interface " , kv.key , " \n "
1004
1009
" module procedure " ,
1005
1010
NULL );
1006
1011
1007
1012
// Write overloaded procedure names
1008
1013
int line_length = 19 ;
1009
- line_length = print_wrapped_list (out, First (kv. item ) , line_length);
1014
+ line_length = print_wrapped_list (out, proc_name_list , line_length);
1010
1015
Printv (out, " \n end interface\n " , NULL );
1011
1016
if (!GetFlag (d_private_overloads, kv.key )) {
1012
1017
Printv (out, " public :: " , kv.key , " \n " , NULL );
@@ -2430,12 +2435,15 @@ int FORTRAN::classHandler(Node *n) {
2430
2435
// Initialize output strings that will be added by 'functionHandler'.
2431
2436
d_method_overloads = NewHash ();
2432
2437
2433
- // Constructors
2434
- d_constructors = NewList ();
2435
-
2436
2438
// Add an assignment function to the class node
2437
2439
this ->add_assignment_operator (n);
2438
2440
2441
+ // Add overload entry for constructors (must do this outside of `add_overload` since the class name already exists as a symbol)
2442
+ ASSERT_OR_PRINT_NODE (!Getattr (d_overloads, fsymname), n);
2443
+ Setattr (d_overloads, fsymname, NewList ());
2444
+ // The derived type is already marked as public, so don't add the additional "public" declaration
2445
+ SetFlag (d_private_overloads, fsymname);
2446
+
2439
2447
// Assignment operator means we're guaranteed to have at least one method, so it's OK to unconditionally put 'contains'
2440
2448
Printv (f_class, " contains\n " , NULL );
2441
2449
}
@@ -2475,39 +2483,25 @@ int FORTRAN::classHandler(Node *n) {
2475
2483
Delete (f_class);
2476
2484
f_class = NULL ;
2477
2485
2478
- // Print constructor interfaces
2479
- if (d_constructors && (Len (d_constructors) > 0 )) {
2480
- Printf (f_fdecl, " interface %s\n " , fsymname);
2481
- for (Iterator it = First (d_constructors); it.item ; it = Next (it)) {
2482
- Printf (f_fdecl, " module procedure %s\n " , it.item );
2483
- }
2484
- Printf (f_fdecl, " end interface\n " );
2485
- Setattr (n, " fortran:constructors" , d_constructors);
2486
- Delete (d_constructors);
2487
- d_constructors = NULL ;
2488
- }
2489
-
2490
2486
return SWIG_OK;
2491
2487
}
2492
2488
2493
2489
/* -------------------------------------------------------------------------
2494
2490
* \brief Extra stuff for constructors.
2495
2491
*/
2496
2492
int FORTRAN::constructorHandler (Node *n) {
2497
- // Add swigf_ to constructor name
2498
- String *fname = proxy_name_construct (this ->getNSpace (), " create" , Getattr (n, " sym:name" ));
2493
+ // Set fortran symname of this function to the class symname
2494
+ Setattr (n, " fortran:name" , Getattr (this ->getCurrentClass (), " fortran:name" ));
2495
+
2496
+ // Make constructor method name conform to other interface wrapper names
2497
+ String *fname = proxy_name_construct (this ->getNSpace (), " new" , Getattr (n, " sym:name" ));
2499
2498
Setattr (n, " fortran:fname" , fname);
2500
2499
Delete (fname);
2501
2500
2502
2501
// Override the result variable name
2503
2502
Setattr (n, " wrap:fresult" , " self" );
2504
- // Don't generate a public interface
2505
- SetFlag (n, " fortran:private" );
2506
2503
2507
2504
Language::constructorHandler (n);
2508
- if (!GetFlag (n, " fortran:ignore" )) {
2509
- Append (d_constructors, Getattr (n, " wrap:fname" ));
2510
- }
2511
2505
return SWIG_OK;
2512
2506
}
2513
2507
@@ -2524,8 +2518,8 @@ int FORTRAN::destructorHandler(Node *n) {
2524
2518
UnsetFlag (n, " feature:except" );
2525
2519
}
2526
2520
2527
- // Add swigf_ to constructor name
2528
- String *fname = proxy_name_construct (this ->getNSpace (), " release " , Getattr (n, " sym:name" ));
2521
+ // Make destructor method name conform to other interface wrapper names
2522
+ String *fname = proxy_name_construct (this ->getNSpace (), Getattr (n, " sym:name" ), " release " );
2529
2523
Setattr (n, " fortran:fname" , fname);
2530
2524
Delete (fname);
2531
2525
0 commit comments