File: type_integer.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 (474 lines) | stat: -rw-r--r-- 12,549 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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
-- 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 TYPE_INTEGER
   --
   -- Handling of the "INTEGER" type mark. This class handles all
   -- variants of the "INTEGER" type mark: "INTEGER_8", "INTEGER_16",
   -- "INTEGER_32", "INTEGER_64" and "INTEGER_GENERAL"
   --

inherit
   TYPE_BASIC_EIFFEL_EXPANDED
      redefine pretty_print
      end

creation integer_8, integer_16, integer_32, integer_64, integer,
   integer_general

feature {TYPE_INTEGER_VISITOR}

   accept(visitor: TYPE_INTEGER_VISITOR) is
      do
         visitor.visit_type_integer(Current)
      end

feature

   is_integer: BOOLEAN is true

   is_boolean,
   is_character,
   is_real,
   is_double,
   is_pointer: BOOLEAN is false

   is_integer_general: BOOLEAN is
      do
	 Result := format_code = Code_integer_general
      end

   id: INTEGER is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
	    Result := 1
	 when Code_integer_16 then
	    Result := 10
	 when Code_integer, Code_integer_32 then
	    Result := 2
	 when Code_integer_64, Code_integer_general then
	    Result := 11
	 end
      end

   c_sizeof: INTEGER is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
	    Result := 1
	 when Code_integer_16 then
	    Result := 2
	 when Code_integer, Code_integer_32 then
	    Result := 4
	 when Code_integer_64, Code_integer_general then
	    Result := 8
	 end
      end

   smallest_ancestor(other: E_TYPE): E_TYPE is
      local
         other_rt: E_TYPE
      do
         other_rt := other.run_type
         if other_rt.is_integer then
	    if Current.is_a(other_rt) then
	       Result := other_rt
	    else
	       error_handler.cancel
	       Result := Current
	    end
	 elseif other_rt.is_real then
            Result := other
         elseif other_rt.is_double then
            Result := other
         else
	    Result := smallest_ancestor_end_hook(other_rt)
         end
      end

   is_a(other: E_TYPE): BOOLEAN is
      local
	 other_type_integer: TYPE_INTEGER
      do
         if other.is_integer then
	    other_type_integer ?= other.run_type
            Result := c_sizeof <= other_type_integer.c_sizeof
         elseif other.is_double or else other.is_real then
            Result := true
         else
	    Result := is_a_end_hook(other.run_type)
	 end
	 if not Result then
	    error_handler.type_error(Current, other)
	 end
      end

   to_runnable(ct: E_TYPE): like Current is
      do
         Result := Current
         if base_class /= Void then
	    if run_class = Void then
	       check false end
	    end
	 end
      end

   written_mark, run_time_mark: STRING is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
	    Result := as_integer_8
	 when Code_integer_16 then
	    Result := as_integer_16
	 when Code_integer, Code_integer_32 then
	    Result := as_integer
	 when Code_integer_64, Code_integer_general then
	    Result := as_integer_64
	 end
      end

   pretty_print is
      local
	 actual_written_mark: STRING
      do
	 inspect
	    format_code
	 when Code_integer_8 then
	    actual_written_mark := as_integer_8
	 when Code_integer_16 then
	    actual_written_mark := as_integer_16
	 when Code_integer then
	    actual_written_mark := as_integer
	 when Code_integer_32 then
	    actual_written_mark := as_integer_32
	 when Code_integer_64 then
	    actual_written_mark := as_integer_64
	 when Code_integer_general then
	    actual_written_mark := as_integer_general
	 end
	 pretty_printer.put_string(actual_written_mark)
      end

   c_type_for_argument_in(str: STRING) is
      do
	 str.extend('T')
	 inspect
	    format_code
	 when Code_integer_8 then
	    str.extend('1')
	 when Code_integer, Code_integer_32 then
	    str.extend('2')
	 when Code_integer_16 then
	    str.extend('1')
	    str.extend('0')
	 when Code_integer_64, Code_integer_general then
	    str.extend('1')
	    str.extend('1')
	 end
      end

   jvm_descriptor_in(str: STRING) is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
	    str.extend('B')
	 when Code_integer_16 then
	    str.extend('S')
	 when Code_integer, Code_integer_32 then
	    str.extend('I')
	 when Code_integer_64, Code_integer_general then
	    str.extend('J')
	 end
      end

   jvm_return_code is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
             code_attribute.opcode_ireturn
	 when Code_integer_16 then
             code_attribute.opcode_ireturn
	 when Code_integer, Code_integer_32 then
            code_attribute.opcode_ireturn
	 when Code_integer_64, Code_integer_general then
             code_attribute.opcode_lreturn
	 end
      end

   jvm_push_local(offset: INTEGER) is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
            code_attribute.opcode_iload(offset)
	 when Code_integer_16 then
            code_attribute.opcode_iload(offset)
	 when Code_integer, Code_integer_32 then
            code_attribute.opcode_iload(offset)
	 when Code_integer_64, Code_integer_general then
            code_attribute.opcode_lload(offset)
	 end
      end

   jvm_push_default: INTEGER is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
            code_attribute.opcode_iconst_0
	 when Code_integer_16 then
            code_attribute.opcode_iconst_0
	 when Code_integer, Code_integer_32 then
            code_attribute.opcode_iconst_0
	 when Code_integer_64, Code_integer_general then
            code_attribute.opcode_iconst_0
	 end
         Result := 1
      end

   jvm_write_local_creation, jvm_write_local(offset: INTEGER) is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
            code_attribute.opcode_istore(offset)
	 when Code_integer_16 then
            code_attribute.opcode_istore(offset)
	 when Code_integer, Code_integer_32 then
            code_attribute.opcode_istore(offset)
	 when Code_integer_64, Code_integer_general then
            code_attribute.opcode_lstore(offset)
	 end
      end

   jvm_xnewarray is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
            code_attribute.opcode_newarray(8)
	 when Code_integer_16 then
            code_attribute.opcode_newarray(9)
	 when Code_integer, Code_integer_32 then
            code_attribute.opcode_newarray(10)
	 when Code_integer_64, Code_integer_general then
            code_attribute.opcode_newarray(11)
	 end
      end

   jvm_xastore is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
            code_attribute.opcode_bastore
	 when Code_integer_16 then
            code_attribute.opcode_sastore
	 when Code_integer, Code_integer_32 then
            code_attribute.opcode_iastore
	 when Code_integer_64, Code_integer_general then
            code_attribute.opcode_lastore
	 end
      end

   jvm_xaload is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
            code_attribute.opcode_baload
	 when Code_integer_16 then
            code_attribute.opcode_saload
	 when Code_integer, Code_integer_32 then
            code_attribute.opcode_iaload
	 when Code_integer_64, Code_integer_general then
            code_attribute.opcode_laload
	 end
      end

   jvm_if_x_eq: INTEGER is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
            Result := code_attribute.opcode_if_icmpeq
	 when Code_integer_16 then
            Result := code_attribute.opcode_if_icmpeq
	 when Code_integer, Code_integer_32 then
            Result := code_attribute.opcode_if_icmpeq
	 when Code_integer_64, Code_integer_general then
            code_attribute.opcode_lsub
            Result := code_attribute.opcode_ifeq
	 end
      end

   jvm_if_x_ne: INTEGER is
      do
	 inspect
	    format_code
	 when Code_integer_8 then
            Result := code_attribute.opcode_if_icmpne
	 when Code_integer_16 then
            Result := code_attribute.opcode_if_icmpne
	 when Code_integer, Code_integer_32 then
            Result := code_attribute.opcode_if_icmpne
	 when Code_integer_64, Code_integer_general then
            code_attribute.opcode_lsub
            Result := code_attribute.opcode_ifne
	 end
      end

   jvm_to_reference is
      local
         rc: RUN_CLASS; idx: INTEGER; ca: like code_attribute
      do
         ca := code_attribute
	 rc := actual_reference(Void).run_class
         rc.jvm_basic_new
         ca.opcode_dup_x1
         ca.opcode_swap
         idx := rc.jvm_constant_pool_index
         idx := constant_pool.idx_fieldref4(idx,as_item,fz_i)
         ca.opcode_putfield(idx,-2)
      end

   jvm_expanded_from_reference(other: E_TYPE): INTEGER is
      local
         rc: RUN_CLASS; idx: INTEGER; ca: like code_attribute
      do
         ca := code_attribute
         rc := actual_reference(Void).run_class
         rc.opcode_checkcast
         idx := rc.jvm_constant_pool_index
         idx := constant_pool.idx_fieldref4(idx,as_item,fz_i)
         ca.opcode_getfield(idx,0)
         Result := 1
      end

   jvm_convert_to(destination: E_TYPE): INTEGER is
      local
	 type_integer: TYPE_INTEGER
      do
         if destination.is_reference then
            jvm_to_reference
            Result := 1
         elseif destination.is_real then
            code_attribute.opcode_i2f
            Result := 1
         elseif destination.is_double then
            code_attribute.opcode_i2d
            Result := 2
         else
	    type_integer ?= destination.run_type
	    inspect
	       type_integer.c_sizeof
	    when 1 then
	       code_attribute.opcode_i2b
	       Result := 1
	    when 2 then
	       code_attribute.opcode_i2s
	       Result := 1
	    when 4 then
	       Result := 1
	    when 8 then
	       code_attribute.opcode_i2l
	       Result := 2
	    end
         end
      end

feature {NONE}

   format_code: INTEGER
   	 -- Used to memorize the format of the original written notation.
   	 -- See following Code_* constant definition to know more about
   	 -- codification used to distinguished INTEGER_8, INTEGER_16,
   	 -- INTEGER_32, INTEGER_64, INTEGER and INTEGER_GENERAL.

   Code_integer_8      : INTEGER is 8
   Code_integer_16     : INTEGER is 16
   Code_integer_32     : INTEGER is 32
   Code_integer        : INTEGER is 0
   Code_integer_64     : INTEGER is 64
   Code_integer_general: INTEGER is 65

   integer_8(sp: like start_position) is
      do
	 format_code := Code_integer_8
         create base_class_name.make(as_integer_8,sp)
      end

   integer_16(sp: like start_position) is
      do
	 format_code := Code_integer_16
         create base_class_name.make(as_integer_16,sp)
      end

   integer_32(sp: like start_position) is
      do
	 format_code := Code_integer_32
         create base_class_name.make(as_integer_32,sp)
      end

   integer_64(sp: like start_position) is
      do
	 format_code := Code_integer_64
         create base_class_name.make(as_integer_64,sp)
      end

   integer(sp: like start_position) is
      do
	 format_code := Code_integer
         create base_class_name.make(as_integer,sp)
      end

   integer_general(sp: like start_position) is
      do
	 format_code := Code_integer_general
         create base_class_name.make(as_integer_general,sp)
      end

   valid_format_code: BOOLEAN is
      do
	 inspect
	    format_code
	 when Code_integer_8, Code_integer_16, Code_integer_32,
	    Code_integer, Code_integer_64, Code_integer_general
	  then
	    Result := True
	 else
	 end
      end

invariant

   valid_format_code

end -- TYPE_INTEGER