Skip to content

Commit b533424

Browse files
committed
Replace fclassname with fortranclassname for consistency with other languages
1 parent 4d78a17 commit b533424

File tree

6 files changed

+46
-45
lines changed

6 files changed

+46
-45
lines changed

Doc/Manual/src/Fortran.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,15 +1689,16 @@ Fortran compiler), `release` should be called on every proxy class instance.
16891689
SWIG's default Fortran type (the `ftype` typemap) for generic types such as
16901690
classes (`SWIGTYPE`) is:
16911691
```swig
1692-
%typemap(ftype) SWIGTYPE "type($fclassname)"
1692+
%typemap(ftype) SWIGTYPE "type($fortranclassname)"
16931693
```
1694-
The special symbol `$fclassname` is replaced by the symbolic name of the class
1695-
that matches the typemap. For example, if `std::vector<double>` is
1694+
The special symbol `$fortranclassname` is replaced by the symbolic name (i.e. the Fortran
1695+
identifier in the proxy code) of the class that matches the typemap.
1696+
For example, if `std::vector<double>` is
16961697
instantiated:
16971698
```swig
16981699
%template(Vec_Dbl) std::vector<double>;
16991700
```
1700-
then `Vec_Dbl`, the name of the derived type, will replace `$fclassname`.
1701+
then `Vec_Dbl`, the name of the derived type, will replace `$fortranclassname`.
17011702

17021703
If a class has *not* been wrapped but is encountered (e.g. in a function
17031704
argument or return value), a warning will be emitted: no Fortran

Lib/fortran/bindc.swg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* ------------------------------------------------------------------------- */
44

55
// Declare a generic `FORTRAN_STRUCT_TYPE` as a native type.
6-
// Rather than being an intrinsic type `integer(C_INT)` it's a derived type `type($fclassname)`
7-
%fortran_intrinsic(FORTRAN_STRUCT_TYPE, type($fclassname))
6+
// Rather than being an intrinsic type `integer(C_INT)` it's a derived type `type($fortranclassname)`
7+
%fortran_intrinsic(FORTRAN_STRUCT_TYPE, type($fortranclassname))
88
// Avoid 'C99 forbids casting nonscalar type 'XY' to the same type'
99
%typemap(in) FORTRAN_STRUCT_TYPE "$1 = *$input;"
1010
%typemap(out) FORTRAN_STRUCT_TYPE "$result = $1;"

Lib/fortran/boost_shared_ptr.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* SP-owned copy of the obtained value.
6363
* ------------------------------------------------------------------------- */
6464
%typemap(in, noblock=1, fragment="SWIG_check_sp_nonnull") CONST TYPE ($&1_type argp = 0) {
65-
SWIG_check_sp_nonnull($input->cptr, "$1_ltype", "$fclassname", "$decl", return $null)
65+
SWIG_check_sp_nonnull($input->cptr, "$1_ltype", "$fortranclassname", "$decl", return $null)
6666
argp = static_cast<SWIGSP__*>($input->cptr)->get();
6767
$1 = *argp;
6868
}
@@ -102,7 +102,7 @@
102102
* Original class by reference. Add null checks.
103103
* ------------------------------------------------------------------------- */
104104
%typemap(in, noblock=1, fragment="SWIG_check_sp_nonnull") CONST TYPE & {
105-
SWIG_check_sp_nonnull($input->cptr, "$1_ltype", "$fclassname", "$decl", return $null)
105+
SWIG_check_sp_nonnull($input->cptr, "$1_ltype", "$fortranclassname", "$decl", return $null)
106106
$1 = (TYPE*)static_cast<SWIGSP__*>($input->cptr)->get();
107107
}
108108

Lib/fortran/classes.swg

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) {
323323
%typemap(imtype, fragment="SwigClassWrapper_f")
324324
SWIGTYPE
325325
"type(SwigClassWrapper)"
326-
%typemap(ftype, in="type($&fclassname), intent(in)", nofortransubroutine=1) SWIGTYPE
327-
"type($&fclassname)"
326+
%typemap(ftype, in="type($&fortranclassname), intent(in)", nofortransubroutine=1) SWIGTYPE
327+
"type($&fortranclassname)"
328328

329329
%typemap(in, noblock=1, fragment="SWIG_check_nonnull") SWIGTYPE {
330-
SWIG_check_nonnull(*$input, "$1_ltype", "$&fclassname", "$decl", return $null);
330+
SWIG_check_nonnull(*$input, "$1_ltype", "$&fortranclassname", "$decl", return $null);
331331
$1 = *(($&1_ltype)($input->cptr));
332332
}
333333

@@ -352,8 +352,8 @@ SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) {
352352
// Raw pointers act mostly like value types, but they don't have to accept the exact type (polymorphic input, non-polymorphic output). Intent is 'in' because
353353
// we're not modifying the pointer or memory status.
354354
%apply SWIGTYPE { SWIGTYPE* };
355-
%typemap(ftype, in="class($fclassname), intent(in)", nofortransubroutine=1) SWIGTYPE*
356-
"type($fclassname)"
355+
%typemap(ftype, in="class($fortranclassname), intent(in)", nofortransubroutine=1) SWIGTYPE*
356+
"type($fortranclassname)"
357357
%typemap(in, noblock=1) SWIGTYPE* {
358358
$1 = ($1_ltype)$input->cptr;
359359
}
@@ -373,7 +373,7 @@ SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) {
373373
// Check for non-null reference inputs
374374
%apply SWIGTYPE* { SWIGTYPE& };
375375
%typemap(in, noblock=1, fragment="SWIG_check_nonnull") SWIGTYPE& {
376-
SWIG_check_nonnull(*$input, "$1_type", "$fclassname", "$decl", return $null);
376+
SWIG_check_nonnull(*$input, "$1_type", "$fortranclassname", "$decl", return $null);
377377
$1 = ($1_ltype)$input->cptr;
378378
}
379379

@@ -397,15 +397,15 @@ SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) {
397397

398398
// Check for non-null class input "self"
399399
%typemap(in, noblock=1, fragment="SWIG_check_nonnull") SWIGTYPE *self {
400-
SWIG_check_nonnull(*$input, "$1_type", "$*fclassname", "$decl", return $null);
400+
SWIG_check_nonnull(*$input, "$1_type", "$*fortranclassname", "$decl", return $null);
401401
$1 = ($1_ltype)$input->cptr;
402402
}
403403

404404
// On assignment, copy pointer to input wrapper class
405405
%typemap(imtype, in="type(SwigClassWrapper), intent(inout)", fragment="SwigClassWrapper_f") SWIGTYPE *ASSIGNMENT_SELF
406406
"type(SwigClassWrapper)"
407-
%typemap(ftype, in="class($fclassname), intent(inout)", nofortransubroutine=1) SWIGTYPE *ASSIGNMENT_SELF
408-
"type($fclassname)"
407+
%typemap(ftype, in="class($fortranclassname), intent(inout)", nofortransubroutine=1) SWIGTYPE *ASSIGNMENT_SELF
408+
"type($fortranclassname)"
409409

410410
// Assignment operates directly on $input, not $1
411411
%typemap(in) SWIGTYPE *ASSIGNMENT_SELF "(void)sizeof($1);";
@@ -414,8 +414,8 @@ SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) {
414414
}
415415

416416
// Prevent ambiguous overloads by requiring the RHS to be the exact type
417-
%typemap(ftype, in="type($fclassname), intent(in)", nofortransubroutine=1) SWIGTYPE &ASSIGNMENT_OTHER
418-
"type($fclassname)"
417+
%typemap(ftype, in="type($fortranclassname), intent(in)", nofortransubroutine=1) SWIGTYPE &ASSIGNMENT_OTHER
418+
"type($fortranclassname)"
419419
%typemap(in) SWIGTYPE &ASSIGNMENT_OTHER = SWIGTYPE *ASSIGNMENT_SELF;
420420

421421
%apply SWIGTYPE *ASSIGNMENT_SELF { SWIGTYPE *DESTRUCTOR_SELF };

Lib/fortran/enums.swg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
// integer pointers)
1212
%fortran_unsigned(int, enum SWIGTYPE)
1313

14-
%typemap(ftype, in="integer($fclassname), intent(in)") enum SWIGTYPE
15-
"integer($fclassname)"
14+
%typemap(ftype, in="integer($fortranclassname), intent(in)") enum SWIGTYPE
15+
"integer($fortranclassname)"
1616
%typemap(out, noblock=1) enum SWIGTYPE {
1717
$result = (int)($1);
1818
}
1919
%typemap(out, noblock=1) const enum SWIGTYPE& {
2020
$result = (int)(*$1);
2121
}
2222

23-
%typemap(ftype, in="integer($*fclassname), intent(in)") const enum SWIGTYPE&
24-
"integer($*fclassname)"
23+
%typemap(ftype, in="integer($*fortranclassname), intent(in)") const enum SWIGTYPE&
24+
"integer($*fortranclassname)"
2525
%typemap(imtype) const enum SWIGTYPE& = enum SWIGTYPE;
2626
%typemap(fin) const enum SWIGTYPE& = enum SWIGTYPE;
2727
%typemap(fout) const enum SWIGTYPE& = enum SWIGTYPE;

Source/Modules/fortran.cxx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ bool return_type_needs_typedef(String *s) {
266266
* \brief Construct any necessary 'import' identifier.
267267
*
268268
* When the `imtype` is an actual `type(Foo)`, it's necessary to import the identifier Foo from the module definition scope. This function examines the
269-
* evaluated `imtype` (could be `imtype:in`, probably has $fclassname replaced)
269+
* evaluated `imtype` (could be `imtype:in`, probably has $fortranclassname replaced)
270270
*/
271271
String *make_import_string(String *imtype) {
272272
char *start = Strstr(imtype, "type(");
@@ -1672,7 +1672,7 @@ Wrapper *FORTRAN::proxyfuncWrapper(Node *n) {
16721672
// Check whether the Fortran proxy routine returns a variable, and whether
16731673
// the actual C function does
16741674

1675-
// Replace any instance of $fclassname in return type
1675+
// Replace any instance of $fortranclassname in return type
16761676
SwigType *return_cpptype = Getattr(n, "type");
16771677
this->replace_fclassname(return_cpptype, return_ftype);
16781678
this->replace_fclassname(return_cpptype, return_imtype);
@@ -2948,7 +2948,7 @@ int FORTRAN::constantWrapper(Node *n) {
29482948
wname = Copy(symname);
29492949
}
29502950

2951-
// Replace fclassname if needed
2951+
// Replace fortranclass if needed
29522952
this->replace_fclassname(c_return_type, bindc_typestr);
29532953

29542954
// Add bound variable to interfaces
@@ -2975,26 +2975,26 @@ void FORTRAN::replace_fclassname(SwigType *intype, String *tm) {
29752975
SwigType *resolvedtype = SwigType_typedef_resolve_all(intype);
29762976
SwigType *strippedtype = SwigType_strip_qualifiers(resolvedtype);
29772977

2978-
if (Strstr(tm, "$fclassname")) {
2978+
if (Strstr(tm, "$fortranclassname")) {
29792979
if (String *repl = this->get_proxyname(strippedtype)) {
2980-
Replaceall(tm, "$fclassname", repl);
2980+
Replaceall(tm, "$fortranclassname", repl);
29812981
}
29822982
}
2983-
if (Strstr(tm, "$*fclassname")) {
2983+
if (Strstr(tm, "$*fortranclassname")) {
29842984
String *repltype = Copy(strippedtype);
29852985
Delete(SwigType_pop(repltype));
29862986
if (Len(repltype) > 0) {
29872987
if (String *repl = this->get_proxyname(repltype)) {
2988-
Replaceall(tm, "$*fclassname", repl);
2988+
Replaceall(tm, "$*fortranclassname", repl);
29892989
}
29902990
}
29912991
Delete(repltype);
29922992
}
2993-
if (Strstr(tm, "$&fclassname")) {
2993+
if (Strstr(tm, "$&fortranclassname")) {
29942994
String *repltype = Copy(strippedtype);
29952995
SwigType_add_pointer(repltype);
29962996
if (String *repl = this->get_proxyname(repltype)) {
2997-
Replaceall(tm, "$&fclassname", repl);
2997+
Replaceall(tm, "$&fortranclassname", repl);
29982998
}
29992999
Delete(repltype);
30003000
}
@@ -3034,22 +3034,22 @@ String *FORTRAN::get_fsymname(Node *n, String *symname) {
30343034

30353035
/* ------------------------------------------------------------------------- */
30363036

3037-
String *FORTRAN::get_proxyname(SwigType *classnametype) {
3037+
String *FORTRAN::get_proxyname(SwigType *basetype) {
30383038
Node *n = NULL;
30393039

3040-
bool is_enum = SwigType_isenum(classnametype);
3040+
bool is_enum = SwigType_isenum(basetype);
30413041
if (is_enum) {
3042-
n = this->enumLookup(classnametype);
3042+
n = this->enumLookup(basetype);
30433043
} else {
3044-
n = this->classLookup(classnametype);
3044+
n = this->classLookup(basetype);
30453045
}
30463046

30473047
if (n && (!is_enum || is_wrapped_enum(n))) {
30483048
// Class node or enum with already-generated wrapper
30493049
return this->get_fsymname(n);
30503050
}
30513051

3052-
String *replacementname = create_mangled_fname(classnametype);
3052+
String *replacementname = create_mangled_fname(basetype);
30533053
if (Getattr(d_emitted_mangled, replacementname)) {
30543054
// Mangled type has already been emitted
30553055
return replacementname;
@@ -3059,7 +3059,7 @@ String *FORTRAN::get_proxyname(SwigType *classnametype) {
30593059
// Create a node so we can insert into the fortran symbol table
30603060
n = NewHash();
30613061
set_nodeType(n, (is_enum ? "enumforward" : "classforward"));
3062-
Setattr(n, "name", classnametype);
3062+
Setattr(n, "name", basetype);
30633063
if (this->add_fsymbol(replacementname, n) == SWIG_NOWRAP) {
30643064
ASSERT_OR_PRINT_NODE(false, n);
30653065
return NULL;
@@ -3083,12 +3083,12 @@ String *FORTRAN::get_proxyname(SwigType *classnametype) {
30833083

30843084
/* ------------------------------------------------------------------------- */
30853085

3086-
bool FORTRAN::is_wrapped_type(SwigType *classnametype) {
3087-
if (SwigType_isenum(classnametype)) {
3088-
Node *n = this->enumLookup(classnametype);
3086+
bool FORTRAN::is_wrapped_type(SwigType *basetype) {
3087+
if (SwigType_isenum(basetype)) {
3088+
Node *n = this->enumLookup(basetype);
30893089
return n && is_wrapped_enum(n);
30903090
} else {
3091-
return this->classLookup(classnametype) != NULL;
3091+
return this->classLookup(basetype) != NULL;
30923092
}
30933093
}
30943094

@@ -3118,12 +3118,12 @@ bool FORTRAN::is_wrapped_class(Node *n) {
31183118
if (!tm) {
31193119
// Somehow there's no ftype; allow it to be wrapped so the error is handled later
31203120
result = true;
3121-
} else if (Strstr(tm, "$fclassname")) {
3121+
} else if (Strstr(tm, "$fortranclassname")) {
31223122
result = this->is_wrapped_type(strippedtype);
3123-
} else if (Strstr(tm, "$*fclassname")) {
3123+
} else if (Strstr(tm, "$*fortranclassname")) {
31243124
SwigType_pop(strippedtype);
31253125
result = this->is_wrapped_type(strippedtype);
3126-
} else if (Strstr(tm, "$&fclassname")) {
3126+
} else if (Strstr(tm, "$&fortranclassname")) {
31273127
SwigType_add_pointer(strippedtype);
31283128
result = this->is_wrapped_type(strippedtype);
31293129
} else {

0 commit comments

Comments
 (0)