File: when_list.e

package info (click to toggle)
smarteiffel 1.1-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 12,288 kB
  • ctags: 40,785
  • sloc: ansic: 35,791; lisp: 4,036; sh: 1,783; java: 895; ruby: 613; python: 209; makefile: 115; csh: 78; cpp: 50
file content (437 lines) | stat: -rw-r--r-- 9,857 bytes parent folder | download | duplicates (2)
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
-- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries
--
-- SmartEiffel is  free software;  you can redistribute it and/or  modify it
-- under  the terms of the  GNU General Public License, as published by  the
-- Free Software Foundation; either version 2, or (at your option) any later
-- version.
-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT 
-- ANY WARRANTY;  without  even the implied warranty  of MERCHANTABILITY  or
-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-- more details.  You should have received a copy of  the GNU General Public
-- License along with SmartEiffel;  see the file COPYING.  If not,  write to
-- the Free Software Foundation,  Inc., 59 Temple Place - Suite 330,  Boston, 
-- MA 02111-1307, USA.
--
-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.
--			   - University of Nancy 1 - FRANCE
-- Copyright(C) 2003:      INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne
--			   - University of Nancy 2 - FRANCE
--
--		 Dominique COLNET, Suzanne COLLIN, Olivier ZENDRA,
--			   Philippe RIBET, Cyril ADRIAN
--
-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
--
class WHEN_LIST

inherit GLOBALS

creation {E_INSPECT} make

creation {E_INSPECT, WHEN_LIST} from_when_list

feature

   pretty_print is
      local
         i: INTEGER
      do
         from
            i := list.lower
         until
            i > list.upper
         loop
            list.item(i).pretty_print
            i := i + 1
            if i <= list.upper then
               pretty_printer.put_character('%N')
               pretty_printer.indent
            end
         end
      end

   start_position: POSITION is
         -- The `start_position' of the first keyword "when".
      do
         Result := list.first.start_position
      end

feature {WHEN_LIST, E_WHEN}

   e_inspect: E_INSPECT
         -- Corresponding one when checked.

feature {E_INSPECT, WHEN_LIST}

   from_when_list(wl: like Current) is
      local
         i: INTEGER; e_when: E_WHEN
      do
	 from
	    list := wl.list.twin
	    i := list.lower
	 until
	    i > list.upper
	 loop
	    !!e_when.from_e_when(list.item(i))
	    list.put(e_when,i)
	    i := i + 1
	 end
      end

feature {E_INSPECT}

   afd_check is
      local
         i: INTEGER
      do
         from
            i := list.upper
         until
            i < list.lower
         loop
            list.item(i).afd_check
            i := i - 1
         end
      end

   safety_check is
      local
         i: INTEGER
      do
         from
            i := list.upper
         until
            i < list.lower
         loop
            list.item(i).safety_check
            i := i - 1
         end
      end

feature {E_INSPECT,WHEN_LIST,MANIFEST_STRING_INSPECTOR}

   includes_integer(v: INTEGER): BOOLEAN is
      local
         i: INTEGER
      do
         from
            i := list.lower
         until
            Result or else i > list.upper
         loop
            Result := list.item(i).includes_integer(v)
            i := i + 1
         end
      end

   includes_integer_between(l,u: INTEGER): BOOLEAN is
      local
         i: INTEGER
      do
         from
            i := list.lower
         until
            Result or else i > list.upper
         loop
            Result := list.item(i).includes_integer_between(l,u)
            i := i + 1
         end
      end

   largest_range_of_values: INTEGER is
      local
         i, range: INTEGER
      do
         from
            i := list.lower
         until
            i > list.upper
         loop
            range := list.item(i).largest_range_of_values
            if range > Result then
               Result := range
            end
            i := i + 1
         end
      end

   to_runnable_integer(ei: E_INSPECT): like Current is
      require
         ei /= Void
      local
         i: INTEGER; e_when: E_WHEN
      do
         if e_inspect = Void then
            e_inspect := ei
            from
               i := list.lower
            until
               i > list.upper or else nb_errors > 0
            loop
               e_when := list.item(i).to_runnable_integer(Current)
               if e_when = Void then
                  error(start_position,em1)
               else
                  list.put(e_when,i)
               end
               i := i + 1
            end
            Result := Current
         else
            !!Result.from_when_list(Current)
            Result := Result.to_runnable_integer(ei)
         end
      ensure
         Result.e_inspect = ei
      end

   to_runnable_character(ei: E_INSPECT): like Current is
      require
         ei /= Void
      local
         i: INTEGER; e_when: E_WHEN
      do
         if e_inspect = Void then
            e_inspect := ei
            from
               i := list.lower
            until
               i > list.upper or else nb_errors > 0
            loop
               e_when := list.item(i).to_runnable_character(Current)
               if e_when = Void then
                  error(start_position,em1)
               else
                  list.put(e_when,i)
               end
               i := i + 1
            end
            Result := Current
         else
            !!Result.from_when_list(Current)
            Result := Result.to_runnable_character(ei)
         end
      ensure
         Result.e_inspect = ei
      end

   to_runnable_string(ei: E_INSPECT): like Current is
      require
         ei /= Void
      local
         i: INTEGER; e_when: E_WHEN
      do
         if e_inspect = Void then
            e_inspect := ei
            from
               i := list.lower
            until
               i > list.upper or else nb_errors > 0
            loop
               e_when := list.item(i).to_runnable_string(Current)
               if e_when = Void then
                  error(start_position,em1)
               else
                  list.put(e_when,i)
               end
               i := i + 1
            end
            Result := Current
         else
            !!Result.from_when_list(Current)
            Result := Result.to_runnable_string(ei)
         end
      ensure
         Result.e_inspect = ei
      end

   compile_to_c(else_position: POSITION) is
      local
         i: INTEGER
         last_compound: COMPOUND
      do
	 from
	    i := list.lower
	 until
	    i = list.upper
	 loop
	    list.item(i).compile_to_c
	    i := i + 1
	    if i < list.upper then
	       cpp.put_string(fz_else_alone)
	    end
	 end
	 if i > list.lower then
	    cpp.put_string(fz_else_alone)
	 end
	 if else_position.is_unknown and then ace.boost then
	    cpp.put_character('{')
	    last_compound := list.item(i).compound
	    if last_compound /= Void then
	       last_compound.compile_to_c
	    end
	    cpp.put_character('}')
	 else
	    list.item(i).compile_to_c
	 end
      end

   compile_to_c_switch(else_position: POSITION) is
      local
         i: INTEGER
         last_compound: COMPOUND
      do
	 from
	    i := list.lower
	 until
	    i = list.upper
	 loop
            list.item(i).compile_to_c_switch
	    i := i + 1
	 end
	 if else_position.is_unknown and then ace.boost then
            cpp.put_string(once "default:;%N")
	    last_compound := list.item(i).compound
	    if last_compound /= Void then
	       last_compound.compile_to_c
	    end
	 else
            list.item(i).compile_to_c_switch
	 end
      end

   compile_to_jvm(else_position: POSITION) is
      local
         remainder, i: INTEGER
      do
	 from
	    remainder := list.count
	    i := list.lower
	 until
	    remainder = 0
	 loop
	    remainder := remainder - 1
	    list.item(i).compile_to_jvm(else_position,remainder)
	    i := i + 1
         end
      end

   compile_to_jvm_resolve_branch is
      local
         i: INTEGER
      do
	 from
	    i := list.upper
	 until
	    i < list.lower
	 loop
	    list.item(i).compile_to_jvm_resolve_branch
	    i := i - 1
         end
      end


   use_current: BOOLEAN is
      local
         i: INTEGER
      do
	 from
	    i := list.upper
	 until
	     Result or else i < list.lower
	 loop
	    Result := list.item(i).use_current
	    i := i - 1
         end
      end

   stupid_switch(run_time_set: RUN_TIME_SET): BOOLEAN is
      local
         i: INTEGER
      do
	 from
	    Result := true
	    i := list.upper
	 until
	    not Result or else i < list.lower
	 loop
	    Result := list.item(i).stupid_switch(run_time_set)
	    i := i - 1
	 end
      end

feature {E_INSPECT}

   simplify_2(cc: CHARACTER_CONSTANT; ic: INTEGER_CONSTANT) is
      local
	 i: INTEGER
      do
	 from
	    i := list.lower
	 until
	    e_inspect.when_list = Void
	       or else
	    i > list.upper
	 loop
	    list.item(i).simplify_2(cc, ic)
	    i := i + 1
	 end
      end
   
   add_last(ew: E_WHEN) is
      require
         ew /= Void
      do
         list.add_last(ew)
      end

   verify_scoop(allowed: FORMAL_ARG_LIST) is
      local
         i: INTEGER
      do
         from
            i := list.upper
         until
            i < list.lower
         loop
            list.item(i).verify_scoop(allowed)
            i := i - 1
         end
      end

feature {WHEN_LIST, MANIFEST_STRING_INSPECTOR}

   list: FIXED_ARRAY[E_WHEN]

feature {WHEN_LIST_VISITOR}

   accept(visitor: WHEN_LIST_VISITOR) is
      do
         visitor.visit_when_list(Current)
      end

feature {E_WHEN}

   always_selected(compound: COMPOUND) is
      do
	 e_inspect.always_selected(compound)
      end

feature {NONE}

   make(first: E_WHEN) is
      require
	 first /= Void
      do
         !!list.with_capacity(4)
	 list.add_last(first)
      ensure
         list.first = first
      end

   fz_else_alone: STRING is " else "

   em1: STRING is "Bad when list."

end -- WHEN_LIST