File: tmp_feature.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 (355 lines) | stat: -rw-r--r-- 11,134 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
-- 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
--
expanded class TMP_FEATURE
   --
   -- Temporary object used during syntax analysis.
   -- At the end, the good effective E_FEATURE is choose.
   --

inherit
   GLOBALS
   VISITABLE

feature {TMP_FEATURE_VISITOR}

   accept(visitor: TMP_FEATURE_VISITOR) is
      do
         visitor.visit_tmp_feature(Current)
      end

feature {EIFFEL_PARSER}

   arguments: FORMAL_ARG_LIST

   type: E_TYPE

   header_comment: COMMENT

   obsolete_mark: MANIFEST_STRING

   require_assertion: E_REQUIRE

   local_vars: LOCAL_VAR_LIST

   routine_body: COMPOUND

   initialize is
      do
         names.clear
         arguments := Void
         type := Void
         header_comment := Void
         obsolete_mark := Void
         require_assertion := Void
         local_vars := Void
         routine_body := Void
      end

   add_synonym(a_name: FEATURE_NAME) is
      require
         a_name /= Void
      do
         if a_name.to_string = as_void then
            error_handler.add_position(a_name.start_position)
            error_handler.append(
               "Feature `Void' cannot be redefined (builtin).")
	    error_handler.print_as_fatal_error
         end
         names.add_last(a_name)
      end

   set_arguments(args: like arguments) is
      require
         args /= Void
      do
         arguments:= args
      end

   set_type(t: like type) is
      require
         t /= Void
      do
         type := t
      ensure
         type = t
      end

   set_header_comment(hc: like header_comment) is
      do
         header_comment := hc
      end

   set_obsolete_mark(om: like obsolete_mark) is
      do
         obsolete_mark := om
      end

   set_local_vars(lv: like local_vars) is
      do
         local_vars := lv
      end

   set_require(sp: POSITION; else_flag: BOOLEAN
	       hc: COMMENT; al: FIXED_ARRAY[ASSERTION]) is
      do
         if hc /= Void or else al /= Void then
            create require_assertion.with(sp, else_flag, hc, al)
         end
      end

   set_routine_body(rb: like routine_body) is
      do
         routine_body := rb
      end

   to_writable_attribute: WRITABLE_ATTRIBUTE is
      do
         if type = Void then
            error(names.first.start_position,
                  "Bad feature definition.")
         elseif arguments /= Void then
            eiffel_parser.ecp("Attribute must not have formal arguments.")
         end
         !!Result.make(n,type)
      end

   to_cst_att_boolean(value: BOOLEAN_CONSTANT): CST_ATT_BOOLEAN is
      do
         to_cst_att_check_result_type
         if type.is_boolean then
            !!Result.make(n,type,value)
         else
            error(type.start_position,
                  "The type of this constant feature should be BOOLEAN.")
         end
      end

   to_cst_att_bit(value: BIT_CONSTANT): CST_ATT_BIT is
      do
         to_cst_att_check_result_type
         if type.is_bit then
            !!Result.make(n,type,value)
         else
            error(type.start_position,
                  "The type of this constant feature should be BIT.")
         end
      end

   to_cst_att_character(value: CHARACTER_CONSTANT): CST_ATT_CHARACTER is
      do
         to_cst_att_check_result_type
         if type.is_character then
            !!Result.make(n,type,value)
         else
            error(type.start_position,
                  "The type of this constant feature should be CHARACTER.")
         end
      end

   to_cst_att_integer(value: INTEGER_CONSTANT): CST_ATT is
      local
	 type_integer: TYPE_INTEGER; value_memory: INTEGER_64; v: like value
	 fatal_error_flag: BOOLEAN
      do
         to_cst_att_check_result_type
         if type.is_integer then
	    value_memory := value.value_memory
	    type_integer ?= type
	    inspect
	       type_integer.c_sizeof
	    when 1 then
	       fatal_error_flag := not value_memory.fit_integer_8
	    when 2 then
	       fatal_error_flag := not value_memory.fit_integer_16
	    when 4 then
	       fatal_error_flag := not value_memory.fit_integer_32
	    when 8 then
	    end
	    if fatal_error_flag then
	       v := value.to_runnable(type_integer)
	       if v.result_type.is_a(type_integer) then
	       else
		  check false end
	       end
	       error_handler.append("Bad constant attribute definition %
				    %(manifest constant value out of range).")
	       error_handler.print_as_fatal_error
	    else
	       create {CST_ATT_INTEGER} Result.make(n, type, value)
	    end
         elseif type.is_real then
            create {CST_ATT_REAL} Result.make(n, type, value.to_real_constant)
         elseif type.is_double then
            create {CST_ATT_DOUBLE} Result.make(n, type, value.to_real_constant)
         else
            error(type.start_position,
                  "The type of this constant feature should be INTEGER %
                  %REAL or DOUBLE.")
         end
      end

   to_cst_att_real(value: REAL_CONSTANT): CST_ATT is
      do
         to_cst_att_check_result_type
         if type.is_real then
            create {CST_ATT_REAL} Result.make(n,type,value)
         elseif type.is_double then
	    value.set_result_type(type)
            create {CST_ATT_DOUBLE} Result.make(n, type, value)
         else
            error_handler.add_position(type.start_position)
            error_handler.append(
             "The type of this constant feature should be REAL or DOUBLE.")
	    error_handler.print_as_fatal_error
         end
      end

   to_cst_att_string(value: MANIFEST_STRING): CST_ATT_STRING is
      do
         to_cst_att_check_result_type
         if type.is_string then
            !!Result.make(n,type,value)
         else
            error(type.start_position,
                  "The type of this constant feature should be STRING.")
         end
      end

   to_deferred_routine: DEFERRED_ROUTINE is
      do
         if type = Void then
            !DEFERRED_PROCEDURE!Result.make(n, arguments,
                                            obsolete_mark,
                                            header_comment,
                                            require_assertion)
         else
            !DEFERRED_FUNCTION!Result.make(n, arguments, type,
                                           obsolete_mark,
                                           header_comment,
                                           require_assertion)
         end
      end

   to_external_routine(native: NATIVE; alias_tag: STRING): EXTERNAL_ROUTINE is
      do
         if type = Void then
            !EXTERNAL_PROCEDURE!Result.make(n, arguments,
                                            obsolete_mark,
                                            header_comment,
                                            require_assertion,
                                            native,alias_tag)
         else
            !EXTERNAL_FUNCTION!Result.make(n, arguments, type,
                                           obsolete_mark,
                                           header_comment,
                                           require_assertion,
                                           native,alias_tag)
         end
      end

   to_once_routine: ONCE_ROUTINE is
      do
         if type = Void then
            !ONCE_PROCEDURE!Result.make(n, arguments,
                                        obsolete_mark,
                                        header_comment,
                                        require_assertion,
                                        local_vars,
                                        routine_body)
         else
            !ONCE_FUNCTION!Result.make(n, arguments, type,
                                       obsolete_mark,
                                       header_comment,
                                       require_assertion,
                                       local_vars,
                                       routine_body)
         end
      end

   to_procedure_or_function: EFFECTIVE_ROUTINE is
      do
         if type = Void then
            !E_PROCEDURE!Result.make(n, arguments,
                                   obsolete_mark,
                                   header_comment,
                                   require_assertion,
                                   local_vars,
                                   routine_body)
         else
            !E_FUNCTION!Result.make(n, arguments, type,
                                  obsolete_mark,
                                  header_comment,
                                  require_assertion,
                                  local_vars,
                                  routine_body)
         end
      end

   to_cst_att_unique: CST_ATT_UNIQUE is
      do
         if type = Void then
            error_handler.add_position(names.first.start_position)
            error_handler.append(em01)
	    error_handler.print_as_fatal_error
         elseif type.is_integer then
            !!Result.make(n,type)
         else
            error_handler.add_position(type.start_position)
            error_handler.append(em01)
	    error_handler.print_as_fatal_error
         end
      end

feature {NONE}

   names: FIXED_ARRAY[FEATURE_NAME] is
      once
         !!Result.make(8)
      end

   to_cst_att_check_result_type is
      do
         if type = Void then
            error_handler.add_position(names.first.start_position)
            error_handler.append(
               "Bad constant declaration (no result type).")
	    error_handler.print_as_fatal_error
         elseif not type.is_run_type then
            error_handler.add_position(type.start_position)
            error_handler.append("Must not use such a type for constant.")
	    error_handler.print_as_fatal_error
         end
      end

   n: FEATURE_NAME_LIST is
      require
         not names.is_empty
      do
         !!Result.make_n(names)
      end

   em01: STRING is "Unique feature must have INTEGER type."

end -- TMP_FEATURE