File: ExceptionTest_Fib_Impl.F90

package info (click to toggle)
babel 0.10.2-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 43,932 kB
  • ctags: 29,707
  • sloc: java: 74,695; ansic: 73,142; cpp: 40,649; sh: 18,411; f90: 10,062; fortran: 6,727; python: 6,406; makefile: 3,866; xml: 118; perl: 48
file content (249 lines) | stat: -rw-r--r-- 7,302 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
! 
! File:          ExceptionTest_Fib_Impl.F90
! Symbol:        ExceptionTest.Fib-v1.0
! Symbol Type:   class
! Babel Version: 0.10.2
! Description:   Server-side implementation for ExceptionTest.Fib
! 
! WARNING: Automatically generated; only changes within splicers preserved
! 
! babel-version = 0.10.2
! 


! 
! Symbol "ExceptionTest.Fib" (version 1.0)
! 
! This class holds the method <code>getFib</code> that generates the
! requested Fibonacci numbers.
! 


#include "ExceptionTest_Fib_fAbbrev.h"
#include "ExceptionTest_NegativeValueException_fAbbrev.h"
#include "ExceptionTest_FibException_fAbbrev.h"
#include "sidl_ClassInfo_fAbbrev.h"
#include "sidl_BaseInterface_fAbbrev.h"
#include "sidl_BaseException_fAbbrev.h"
#include "sidl_BaseClass_fAbbrev.h"
! DO-NOT-DELETE splicer.begin(_miscellaneous_code_start)
#include "ExceptionTest_TooBigException_fAbbrev.h"
#include "ExceptionTest_TooDeepException_fAbbrev.h"
! DO-NOT-DELETE splicer.end(_miscellaneous_code_start)




! 
! Class constructor called when the class is created.
! 

recursive subroutine ExceptionTest_Fib__ctor_mi(self)
  use ExceptionTest_Fib
  use ExceptionTest_Fib_impl
  ! DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._ctor.use)
  ! Insert use statements here...
  ! DO-NOT-DELETE splicer.end(ExceptionTest.Fib._ctor.use)
  implicit none
  type(ExceptionTest_Fib_t) :: self ! in

! DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._ctor)
! Nothing needed here...
! DO-NOT-DELETE splicer.end(ExceptionTest.Fib._ctor)
end subroutine ExceptionTest_Fib__ctor_mi


! 
! Class destructor called when the class is deleted.
! 

recursive subroutine ExceptionTest_Fib__dtor_mi(self)
  use ExceptionTest_Fib
  use ExceptionTest_Fib_impl
  ! DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._dtor.use)
  ! Insert use statements here...
  ! DO-NOT-DELETE splicer.end(ExceptionTest.Fib._dtor.use)
  implicit none
  type(ExceptionTest_Fib_t) :: self ! in

! DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._dtor)
! Nothing needed here...
! DO-NOT-DELETE splicer.end(ExceptionTest.Fib._dtor)
end subroutine ExceptionTest_Fib__dtor_mi


! 
! Static class initializer called exactly once before any user-defined method is dispatched
! 

recursive subroutine ExceptionTest_Fib__load_mi()
  use ExceptionTest_Fib
  use ExceptionTest_Fib_impl
  ! DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._load.use)
  ! Insert use statements here...
  ! DO-NOT-DELETE splicer.end(ExceptionTest.Fib._load.use)
  implicit none

! DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._load)
! Insert the implementation here...
! DO-NOT-DELETE splicer.end(ExceptionTest.Fib._load)
end subroutine ExceptionTest_Fib__load_mi


! 
! <p>
! Generate the requested Fibonacci number or generate exceptions if
! the input Fibonacci number is invalid or if any of the maximum depth
! or maximum value parameters are exceeded.  The last argument of the
! method should be zero.
! </p>
! <p>
! The algorithm should be similar to the <code>Java</code> code below.
! </p>
! <pre>
! public int getFib(int n, int max_depth, int max_value, int depth)
!     throws NegativeValueException, FibException {
! 
!   if (n < 0) {
!     throw new NegativeValueException("n negative");
! 
!   } else if (depth > max_depth) {
!     throw new TooDeepException("too deep");
! 
!   } else if (n == 0) {
!     return 1;
! 
!   } else if (n == 1) {
!     return 1;
! 
!   } else {
!     int a = getFib(n-1, max_depth, max_value, depth+1);
!     int b = getFib(n-2, max_depth, max_value, depth+1);
!     if (a + b > max_value) {
!       throw new TooBigException("too big");
!     }
!     return a + b;
!   }
! } 
! </pre>
! 

recursive subroutine ExceptionTest_Fib_getFib_mi(self, n, max_depth,           &
  max_value, depth, retval, exception)
  use ExceptionTest_Fib
  use ExceptionTest_NegativeValueException
  use ExceptionTest_FibException
  use sidl_BaseInterface
  use ExceptionTest_Fib_impl
  ! DO-NOT-DELETE splicer.begin(ExceptionTest.Fib.getFib.use)
  use ExceptionTest_TooBigException
  use ExceptionTest_TooDeepException
  ! DO-NOT-DELETE splicer.end(ExceptionTest.Fib.getFib.use)
  implicit none
  type(ExceptionTest_Fib_t) :: self ! in
  integer (selected_int_kind(9)) :: n ! in
  integer (selected_int_kind(9)) :: max_depth ! in
  integer (selected_int_kind(9)) :: max_value ! in
  integer (selected_int_kind(9)) :: depth ! in
  integer (selected_int_kind(9)) :: retval ! out
  type(sidl_BaseInterface_t) :: exception ! out

! DO-NOT-DELETE splicer.begin(ExceptionTest.Fib.getFib)
  type(ExceptionTest_NegativeValueException_t) :: negexc
  type(ExceptionTest_TooDeepException_t) :: deepexc
  type(ExceptionTest_TooBigException_t) :: toobigexc
  type(ExceptionTest_FibException_t) :: fibexc
  character (len=*) myfilename 
  parameter(myfilename='ExceptionTest_Fib_Impl.f')
  integer(selected_int_kind(9)) a, b
  retval = 0
  if (n .lt. 0) then
     call new(negexc)
     if (not_null(negexc)) then
        call setNote(negexc, &
             'called with negative n')
        call add( &
             negexc, myfilename, 57, 'ExceptionTest_Fib_getFib_impl')
        call cast(negexc, exception)
        return
     endif
  else if (depth .gt. max_depth) then
     call new(deepexc)
     if (not_null(deepexc)) then
        call setNote( deepexc, &
             'exceeded specified recursion depth')
        call add( deepexc, &
             myfilename, 70, 'ExceptionTest_Fib_getFib_impl')
        call cast(deepexc, exception)
        return
     endif
  else if (n .eq. 0) then
     retval = 1
  else if (n .eq. 1) then
     retval = 1
  else 
   ! 
   ! Note that we must call the stub version of this method
   ! because g77 does not (currently) support recursion.
   ! 
     call getFib(self, &
          n-1, &
          max_depth, & 
          max_value, &
          depth+1, & 
          a, &
          exception)
     call cast(exception, fibexc)
     if (not_null(fibexc)) then
        call add( &
             fibexc, &
             myfilename, &
             90, &
             'ExceptionTest_Fib_getFib_impl')
        return
     endif
   ! 
   ! Note that we must call the stub version of this method
   ! because g77 does not (currently) support recursion.
   ! 
     call getFib(self, &
          n-2, &
          max_depth, &
          max_value, &
          depth+1, &
          b, &
          exception)
     call cast(exception, fibexc)
     if (not_null(fibexc)) then
        call add( &
             fibexc, &
             myfilename, &
             105,  &
             'ExceptionTest_Fib_getFib_impl')
        return
     endif
     retval = a+b
     if (retval .gt. max_value) then
        retval = 0
        call new(toobigexc)
        if (not_null(toobigexc)) then
           call setNote( &
                toobigexc, &
                'result exceeds specified maximum value')
           call add( &
                toobigexc, &
                myfilename, &
                103, &
                'ExceptionTest_Fib_getFib_impl')
           call cast(toobigexc, exception)
           return
        endif
     endif
  endif
! DO-NOT-DELETE splicer.end(ExceptionTest.Fib.getFib)
end subroutine ExceptionTest_Fib_getFib_mi


! DO-NOT-DELETE splicer.begin(_miscellaneous_code_end)
! Nothing needed here...
! DO-NOT-DELETE splicer.end(_miscellaneous_code_end)