Skip to content

Commit 0734657

Browse files
authored
Merge pull request #162 from swig-fortran/fortrilinos-fixes
Fixes for updating ForTrilinos
2 parents 1cac386 + d867471 commit 0734657

File tree

8 files changed

+43
-94
lines changed

8 files changed

+43
-94
lines changed

Examples/test-suite/fortran/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ CPP_TEST_CASES = \
2626
fortran_naming \
2727
fortran_onlywrapped \
2828
fortran_overloads \
29+
fortran_std_span \
2930
fortran_subroutine \
3031
li_std_set \
3132
complextest \

Examples/test-suite/fortran/string_constants_runme.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ program string_constants_runme
88
implicit none
99
type(things) :: foo
1010
! note: Z'deadbeef' and O'777' are used to generate hex and oct constants
11-
character(C_CHAR), parameter :: CR = char(Z'0D', C_CHAR)
12-
character(C_CHAR), parameter :: LF = char(O'12', C_CHAR)
11+
character(C_CHAR), parameter :: CR = char(int(Z'0D'), C_CHAR)
12+
character(C_CHAR), parameter :: LF = char(int(O'12'), C_CHAR)
1313
character(kind=C_CHAR, len=*), parameter :: &
1414
expected_aa3 = "A" // CR // "B" // LF // "C"
1515
character(kind=C_CHAR, len=:), allocatable :: actual_aa3

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+
%}

Examples/test-suite/fortran_std_span.i

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ class span
1111
typedef int index_type;
1212
typedef _Tp* pointer;
1313

14-
span() : d_ptr(NULL), d_size(0) {}
15-
span(pointer d, index_type s) : d_ptr(d), d_size(s) {}
16-
span(pointer first, pointer last) : d_ptr(first), d_size(last - first) {}
14+
span() : ptr_(NULL), size_(0) {}
15+
span(pointer d, index_type s) : ptr_(d), size_(s) {}
16+
span(pointer first, pointer last) : ptr_(first), size_(last - first) {}
1717

18-
pointer data() const { return d_ptr; }
19-
index_type size() const { return d_size; }
18+
pointer data() const { return ptr_; }
19+
index_type size() const { return size_; }
2020

2121
private:
22-
pointer d_ptr;
23-
index_type d_size;
22+
pointer ptr_;
23+
index_type size_;
2424
};
2525
} // namespace std
2626

@@ -30,6 +30,8 @@ class span
3030

3131
%template() std::span<int>;
3232
%template() std::span<const int>;
33+
%template() std::span<unsigned int>;
34+
%template() std::span<const unsigned int>;
3335

3436
%inline %{
3537
std::span<int> get_by_value() {

Lib/fortran/fortranarray.swg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ end subroutine}
9797
%typemap(imtype) CPPTYPE& = CPPTYPE;
9898
%typemap(ctype) CPPTYPE& = CPPTYPE;
9999

100-
// Update the resulting Fortran pointer.
101-
//%typemap(fargout, match="argout", noblock=1) CPPTYPE& = VTYPE[]&;
100+
// Update the resulting Fortran pointer, but only by reference (not const ref)
101+
%typemap(fargout, match="fin", noblock=1) CPPTYPE& = VTYPE ARRAY[];
102+
%typemap(fargout, noblock=1) const CPPTYPE& {};
102103
%enddef
103104

Lib/fortran/fundamental.swg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ end subroutine}
203203

204204
// Define proxy code typemaps for an array of this type
205205
%fortran_typemap_finout(CTYPE[], CTYPE ARRAY[])
206-
206+
%typemap(fargout, fragment="SWIG_fout"{CTYPE[]}, noblock=1) CTYPE ARRAY[] {
207+
call %fortrantm(fout, CTYPE[])($1, $input)
208+
}
209+
%typemap(fargout) CTYPE const ARRAY[] = CTYPE ARRAY[];
207210
%enddef
208211

209212
/*!
@@ -225,6 +228,8 @@ end subroutine}
225228

226229
%typemap(fin) DSTTYPE ARRAY[] = SRCTYPE ARRAY[];
227230
%typemap(fout) DSTTYPE ARRAY[] = SRCTYPE ARRAY[];
231+
%typemap(fargout) DSTTYPE ARRAY[] = SRCTYPE ARRAY[];
232+
%typemap(fargout) DSTTYPE const ARRAY[] = SRCTYPE const ARRAY[];
228233
%enddef
229234

230235
/* -------------------------------------------------------------------------

Lib/fortran/std_container.i

Lines changed: 0 additions & 75 deletions
This file was deleted.

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)