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
|
C
C File: ExceptionTest_Fib_Impl.f
C Symbol: ExceptionTest.Fib-v1.0
C Symbol Type: class
C Babel Version: 0.10.2
C Description: Server-side implementation for ExceptionTest.Fib
C
C WARNING: Automatically generated; only changes within splicers preserved
C
C babel-version = 0.10.2
C
C
C Symbol "ExceptionTest.Fib" (version 1.0)
C
C This class holds the method <code>getFib</code> that generates the
C requested Fibonacci numbers.
C
C DO-NOT-DELETE splicer.begin(_miscellaneous_code_start)
C Nothing needed here...
C DO-NOT-DELETE splicer.end(_miscellaneous_code_start)
C
C Class constructor called when the class is created.
C
subroutine ExceptionTest_Fib__ctor_fi(self)
implicit none
C in ExceptionTest.Fib self
integer*8 self
C DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._ctor)
C Nothing needed here...
C DO-NOT-DELETE splicer.end(ExceptionTest.Fib._ctor)
end
C
C Class destructor called when the class is deleted.
C
subroutine ExceptionTest_Fib__dtor_fi(self)
implicit none
C in ExceptionTest.Fib self
integer*8 self
C DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._dtor)
C Nothing needed here...
C DO-NOT-DELETE splicer.end(ExceptionTest.Fib._dtor)
end
C
C Static class initializer called exactly once before any user-defined method is dispatched
C
subroutine ExceptionTest_Fib__load_fi()
implicit none
C DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._load)
C Insert the implementation here...
C DO-NOT-DELETE splicer.end(ExceptionTest.Fib._load)
end
C
C <p>
C Generate the requested Fibonacci number or generate exceptions if
C the input Fibonacci number is invalid or if any of the maximum depth
C or maximum value parameters are exceeded. The last argument of the
C method should be zero.
C </p>
C <p>
C The algorithm should be similar to the <code>Java</code> code below.
C </p>
C <pre>
C public int getFib(int n, int max_depth, int max_value, int depth)
C throws NegativeValueException, FibException {
C
C if (n < 0) {
C throw new NegativeValueException("n negative");
C
C } else if (depth > max_depth) {
C throw new TooDeepException("too deep");
C
C } else if (n == 0) {
C return 1;
C
C } else if (n == 1) {
C return 1;
C
C } else {
C int a = getFib(n-1, max_depth, max_value, depth+1);
C int b = getFib(n-2, max_depth, max_value, depth+1);
C if (a + b > max_value) {
C throw new TooBigException("too big");
C }
C return a + b;
C }
C }
C </pre>
C
subroutine ExceptionTest_Fib_getFib_fi(self, n, max_depth,
& max_value, depth, retval, exception)
implicit none
C in ExceptionTest.Fib self
integer*8 self
C in int n
integer*4 n
C in int max_depth
integer*4 max_depth
C in int max_value
integer*4 max_value
C in int depth
integer*4 depth
C out int retval
integer*4 retval
C out sidl.BaseInterface exception
integer*8 exception
C DO-NOT-DELETE splicer.begin(ExceptionTest.Fib.getFib)
character*(*) myfilename
parameter(myfilename='ExceptionTest_Fib_Impl.f')
integer*4 a, b
retval = 0
if (n .lt. 0) then
call ExceptionTest_NegativeValueException__create_f(exception)
if (exception .ne. 0) then
call ExceptionTest_NegativeValueException_setNote_f(
$ exception,
$ 'called with negative n')
call ExceptionTest_NegativeValueException_add_f(
$ exception,
$ myfilename,
$ 57,
$ 'ExceptionTest_Fib_getFib_impl')
return
endif
else if (depth .gt. max_depth) then
call ExceptionTest_TooDeepException__create_f(exception)
if (exception .ne. 0) then
call ExceptionTest_TooDeepException_setNote_f(
$ exception,
$ 'exceeded specified recursion depth')
call ExceptionTest_TooDeepException_add_f(
$ exception,
$ myfilename,
$ 70,
$ 'ExceptionTest_Fib_getFib_impl')
return
endif
else if (n .eq. 0) then
retval = 1
else if (n .eq. 1) then
retval = 1
else
C
C Note that we must call the stub version of this method
C because g77 does not (currently) support recursion.
C
call ExceptionTest_Fib_getFib_f(self,
$ n-1,
$ max_depth,
$ max_value,
$ depth+1,
$ a,
$ exception)
if (exception .ne. 0) then
call sidl_SIDLException_add_f(
$ exception,
$ myfilename,
$ 90,
$ 'ExceptionTest_Fib_getFib_impl')
return
endif
C
C Note that we must call the stub version of this method
C because g77 does not (currently) support recursion.
C
call ExceptionTest_Fib_getFib_f(self,
$ n-2,
$ max_depth,
$ max_value,
$ depth+1,
$ b,
$ exception)
if (exception .ne. 0) then
call sidl_SIDLException_add_f(
$ exception,
$ myfilename,
$ 105,
$ 'ExceptionTest_Fib_getFib_impl')
return
endif
retval = a+b
if (retval .gt. max_value) then
retval = 0
call ExceptionTest_TooBigException__create_f(exception)
if (exception .ne. 0) then
call ExceptionTest_TooBigException_setNote_f(
$ exception,
$ 'result exceeds specified maximum value')
call ExceptionTest_TooBigException_add_f(
$ exception,
$ myfilename,
$ 103,
$ 'ExceptionTest_Fib_getFib_impl')
return
endif
endif
endif
C DO-NOT-DELETE splicer.end(ExceptionTest.Fib.getFib)
end
C DO-NOT-DELETE splicer.begin(_miscellaneous_code_end)
C Nothing needed here...
C DO-NOT-DELETE splicer.end(_miscellaneous_code_end)
|