File: run_require.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 (264 lines) | stat: -rw-r--r-- 6,376 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
-- 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 RUN_REQUIRE
   --
   -- A RUN_REQUIRE is composed with all inherited E_REQUIRE.
   --

inherit GLOBALS

creation {ASSERTION_COLLECTOR} make

feature

   side_effect_free: BOOLEAN is
      do
	 -- *** TO DO ***
      end
   
   short is
      local
         i: INTEGER
      do
         from
            list.item(1).short(once "hook401",once "      require%N")
            i := 2
         until
            i > list.upper
         loop
            list.item(i).short(once "hook402",once "      require else %N")
            i := i + 1
         end
         short_print.hook(once "hook403")
      end

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

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

   compile_to_c is
      local
         i: INTEGER
      do
         if list.upper = 1 then
            cpp.put_string(once "se_require_uppermost_flag=1;%N")
            list.first.compile_to_c
         else
            cpp.put_string(once "se_require_uppermost_flag=0;%N%
                           %se_require_last_result=1;%N")
            list.first.compile_to_c
            from
               i := 2
            until
               i > list.upper
            loop
               if i = list.upper then
                  cpp.put_string(once "se_require_uppermost_flag=1;%N")
               end
               cpp.put_string(once "if(!se_require_last_result){%N%
                              %se_require_last_result=1;%N")
               list.item(i).compile_to_c
               cpp.put_string(fz_12)
               i := i + 1
            end
         end
      end

   compile_to_jvm is
      local
         i: INTEGER
         ca: like code_attribute
      do
	 ca := code_attribute
	 if list.upper = 1 then
	    list.first.compile_to_jvm(true)
	    ca.opcode_pop
	 else
	    sucess.clear
	    from
	       i := 1
	    until
	       i > (list.upper - 1)
	    loop
	       list.item(i).compile_to_jvm(false)
	       sucess.add_last(ca.opcode_ifne)
	       i := i + 1
	    end
	    list.item(i).compile_to_jvm(true)
	    ca.opcode_pop
	    ca.resolve_with(sucess)
         end
      end

feature {RUN_FEATURE}

   verify_scoop(allowed: FORMAL_ARG_LIST) is
      local
         i: INTEGER
      do
         list.first.verify_scoop(allowed)
         from
            i := 2
         until
            i > list.upper
         loop
            list.item(i).verify_scoop(allowed)
            i := i + 1
         end
      end

   c_scoop_while is
         -- Compile the first part of the "do...while" loop (just before 
         -- trying to lock the arguments' processors
      do
         cpp.put_string(once "{int se_guard;%Ndo {%Nse_guard=1;%N")
      end

   c_scoop_if_not_guard is
         -- Compile and test the guards
      local
         i: INTEGER
      do
         list.first.c_scoop
         from
            i := 2
         until
            i > list.upper
         loop
            list.item(i).c_scoop
            cpp.put_string(fz_12)
            i := i + 1
         end
         cpp.put_string(once "if (!se_guard) {%N")
      end

   c_scoop_guard is
         -- Close the guard section (last part of the "do...while" loop)
      do
         cpp.put_string(once "}%N} while(!se_guard);%N}%N")
      end

feature {ASSERTION_COLLECTOR}

   add(r: E_REQUIRE) is
      require
         r /= Void
      local
         i: INTEGER
         r2: E_REQUIRE
         bc, bc2: BASE_CLASS
      do
         list.add_last(r)
         from
            bc := r.start_position.base_class
            i := list.upper
         until
            i = 1
         loop
            r2 := list.item(i - 1)
            bc2 := r2.start_position.base_class
            if bc.is_subclass_of(bc2) then
               list.swap(i,i-1)
               i := i - 1
            else
               i := 1
            end
         end
      end

feature {ONCE_ROUTINE_POOL}

   clear_run_feature is
      local
         i: INTEGER
      do
         from
            i := list.upper
         until
            i = 0
         loop
            list.item(i).clear_run_feature
            i := i - 1
         end
      end

feature {RUN_REQUIRE_VISITOR}

   accept(visitor: RUN_REQUIRE_VISITOR) is
      do
         visitor.visit_run_require(Current)
      end

feature {NONE}

   list: ARRAY[E_REQUIRE]
         -- From bottom to the top of the inheritance graph.
         -- Order is important because one at least must be true
         -- following bottom up order.

   make(first: E_REQUIRE) is
      do
         !!list.with_capacity(4,1)
         list.add_last(first)
      end

   sucess: FIXED_ARRAY[INTEGER] is
         -- To reach the sucessful code.
      once
         !!Result.with_capacity(4)
      end

invariant

   list.lower = 1

   not list.is_empty

end -- RUN_REQUIRE