File: implicit_cast.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 (371 lines) | stat: -rw-r--r-- 8,399 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
-- 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 IMPLICIT_CAST
   --
   -- To memorize an implicit legal cast from one type to another.
   -- This invisible expression is used for all kinds of implicit
   -- conversions:
   --   from INTEGER to REAL
   --   from INTEGER to DOUBLE,
   --   from REAL to DOUBLE,
   --   from INTEGER to reference INTEGER,
   --   from INTEGER_8 to reference INTEGER_8,
   --   ...
   --   from FOO to reference FOO,
   --   ...

inherit EXPRESSION

creation {ASSIGNMENT_HANDLER} make

feature

   is_manifest_string: BOOLEAN is
      do
         Result := expression.is_manifest_string
      end

   extra_bracket_flag: BOOLEAN is
      do
	 Result := expression.extra_bracket_flag
      end
   
   to_integer_or_error: INTEGER is
      do
	 to_integer_error
      end

   result_type: E_TYPE is
      do
         Result := destination_type
      end

   is_void: BOOLEAN is
      do
         Result := expression.is_void
      end

   start_lookup_class: BASE_CLASS is
      do
         Result := result_type.base_class
      end

   is_writable: BOOLEAN is
      do
         Result := expression.is_writable
      end

   is_result: BOOLEAN is
      do
         Result := expression.is_result
      end

   is_current: BOOLEAN is
      do
         Result := expression.is_current
      end

   assertion_check(tag: CHARACTER) is
      do
         expression.assertion_check(tag)
      end

   is_static: BOOLEAN is
      do
         Result := expression.is_static
      end

   once_pre_computable: BOOLEAN is
      do
         Result := expression.once_pre_computable
      end

   isa_dca_inline_argument: INTEGER is
      do
         Result := expression.isa_dca_inline_argument
      end

   dca_inline_argument(formal_arg_type: E_TYPE) is
      do
         expression.dca_inline_argument(formal_arg_type)
      end

   compile_to_c is
      local
	 i: INTEGER
      do
         c_wrapper_opening
	 if source_type.is_reference then
	    -- To promote automatically reference INTEGER_* type:
	    cpp.put_character('(')
	    from
	       i := 1
	    until
	       conversion.item(i) = 't'
	    loop
	       cpp.put_character(conversion.item(i))
	       i := i + 1
	    end
	    cpp.put_string(fz_70)
	    expression.compile_to_c
	    cpp.put_character(')')
	 else
	    expression.mapping_c_target(source_type)
	 end
         c_wrapper_closing
      end

   mapping_c_target(target_type: E_TYPE) is
      do
	 compile_to_c
      end

   mapping_c_arg(formal_arg_type: E_TYPE) is
      do
	 compile_to_c
      end

   afd_check is
      do
         expression.afd_check
      end

   safety_check is
      do
         expression.safety_check
      end

   collect_c_tmp is
      do
          expression.collect_c_tmp
      end

   c_frame_descriptor(format, locals: STRING) is
      do
	 expression.c_frame_descriptor(format,locals)
      end

   compile_to_jvm is
      local
         space: INTEGER
      do
         expression.compile_to_jvm
         space := source_type.jvm_convert_to(destination_type)
      end

   compile_target_to_jvm is
      local
         space: INTEGER
      do
         expression.compile_target_to_jvm
         space := source_type.jvm_convert_to(destination_type)
      end

   compile_to_jvm_into(dest: E_TYPE): INTEGER is
      do
         compile_to_jvm
         Result := destination_type.jvm_convert_to(dest)
      end

   jvm_branch_if_false: INTEGER is
      do
         Result := expression.jvm_branch_if_false
      end

   jvm_branch_if_true: INTEGER is
      do
         Result := expression.jvm_branch_if_true
      end

   use_current: BOOLEAN is
      do
         Result := expression.use_current
      end

   stupid_switch(run_time_set: RUN_TIME_SET): BOOLEAN is
      do
         Result := expression.stupid_switch(run_time_set)
      end

   side_effect_free: BOOLEAN is
      do
         Result := expression.side_effect_free
      end

   to_runnable(ct: E_TYPE): EXPRESSION is
      do
         Result := expression.to_runnable(ct)
      end

   simplify_1_: EXPRESSION is
      do
	 Result := simplify(expression.simplify_1_)
      end
   
   simplify_2: EXPRESSION is
      do
	 Result := simplify(expression.simplify_2)
      end
   
   start_position: POSITION is
      do
         Result := expression.start_position
      end

   bracketed_pretty_print, pretty_print is
      do
         expression.pretty_print
      end

   print_as_target is
      do
         expression.print_as_target
      end

   short is
      do
         expression.short
      end

   short_target is
      do
         expression.short_target
      end

   precedence: INTEGER is
      do
         Result := expression.precedence
      end

   jvm_assign_creation, jvm_assign is
      do
         expression.jvm_assign
      end

feature {C_PRETTY_PRINTER}

   original_expression: EXPRESSION is
      do
         Result := expression
      end

feature {IMPLICIT_CAST_VISITOR}

   accept(visitor: IMPLICIT_CAST_VISITOR) is
      do
         visitor.visit_implicit_cast(Current)
      end

feature {NONE}

   expression : EXPRESSION
         -- The wrapped `expression' with it's `source_type'.

   source_type, destination_type: E_TYPE

   conversion: STRING
	 -- If mandatory, the name of the C conversion function (to 
	 -- avoid too many C code generation).
   
   make(e: like expression; dt: like destination_type) is
      require
         e.result_type.run_time_mark /= dt.run_time_mark
	 e.result_type.is_a(dt)
      do
         expression := e
         source_type := e.result_type.run_type
         destination_type := dt.run_type
	 if source_type.is_expanded and then destination_type.is_expanded
	  then
	    -- May be two INTEGERs of different size or some REAL 
	    -- value converted into DOUBLE for example.
	 else
	    conversion := assignment_handler.register(source_type,
						      destination_type)
	 end
	 if source_type.is_bit and then destination_type.is_reference then
	    smart_eiffel.bit_n_ref_is_nyi_error(e.start_position)
	 end
      ensure
         expression = e
         source_type = e.result_type.run_type
         destination_type = dt.run_type
      end

   simplify(e: like expression): EXPRESSION is
      local
	 ic: INTEGER_CONSTANT; rc: REAL_CONSTANT; rt: E_TYPE
      do
	 rt := result_type
	 if rt.is_double or else rt.is_real then
	    ic ?= e
	    if ic /= Void then
	       create {REAL_CONSTANT}
	          Result.from_double(start_position, ic.value_memory, rt)
	    else
	       rc ?= e
	       if rc /= Void then
		  rc.set_result_type(rt)
	          Result := rc
	       else
		  Result := Current
	       end
	    end
	 elseif rt.is_integer then
	    ic ?= e
	    if ic /= Void then
	       Result := ic
	    else
	       Result := Current
	    end
	 else
	    Result := Current
	 end
      end
   
   c_wrapper_opening is
      do
	 if conversion = Void then
	    cpp.put_string(once "/*IC*/")
	    destination_type.mapping_cast
	 else
	    cpp.put_string(conversion)
	 end
	 cpp.put_character('(')
      end

   c_wrapper_closing is
      do
	 cpp.put_character(')')
      end

invariant

   source_type.run_type = source_type
   
   destination_type.run_type = destination_type
   
end -- IMPLICIT_CAST