File: type_function.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 (228 lines) | stat: -rw-r--r-- 6,008 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
-- 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_FUNCTION
   --
   -- For agents of type FUNCTION as well as agents of type PREDICATE.
   --

inherit TYPE_OF_AGENT

creation make

creation {TYPE_FUNCTION} set

feature

   is_type_predicate: BOOLEAN is
      do
	 Result := res.is_boolean
      end

   to_runnable_(ct: E_TYPE): like Current is
      local
	 b: like base; so: like static_open; r:like res
      do
	 b := base.to_runnable(ct)
	 so := static_open.to_runnable(ct)
	 r := res.to_runnable(ct)
	 if b = base and then so = static_open and then r = res then
	    if run_type = Void then
	       create run_type.make(start_position,
				    b.run_type, so.run_type, r.run_type)
	       check run_type.written_runnable_flag end
	       set_open_using(so)
	       Result := Current
	    else
	       Result := Current
	    end
	 elseif run_type = Void then
	    create run_type.make(start_position, 
				 b.run_type, so.run_type, r.run_type)
	    check run_type.written_runnable_flag end
	    base := b
	    static_open := so
	    res := r
	    set_open_using(so)
	    Result := Current
	 else
	    create Result.make(start_position,
			       b.run_type, so.run_type, r.run_type)
	    check Result.written_runnable_flag end
	    if Result.written_mark = run_type.written_mark then
	       Result := Current
	    else
	       create Result.set(Current, so, Result)
	    end
	 end
      end

   written_mark: STRING is
      local
	 base_wm, static_open_wm, res_wm: STRING; predicate: BOOLEAN
      do
	 Result := written_mark_memory
	 if Result = Void then
	    predicate := is_type_predicate
	    -- To force computation of components first:
	    base_wm := base.written_mark
	    static_open_wm := static_open.written_mark
	    if not predicate then
	       res_wm := res.written_mark
	    end
	    -- Then compute the `Result':
	    Result := once "...This is a local once buffer..."
	    if predicate then
	       Result.copy(as_predicate)
	    else
	       Result.copy(as_function)
	    end
	    Result.extend('[')
	    Result.append(base_wm)
	    Result.extend(',')
	    Result.append(static_open_wm)
	    if not predicate then
	       Result.extend(',')
	       Result.append(res_wm)
	    end
	    Result.extend(']')
	    Result := string_aliaser.item(Result)
	    written_mark_memory := Result
	 end
      end

feature {E_TYPE}

   short_hook is
      local
	 predicate : BOOLEAN; bcn: like base_class_name
      do
	 predicate := is_type_predicate
	 bcn := base_class_name
	 if predicate then
	    create bcn.make(as_predicate,bcn.start_position)
	 end
	 short_print.a_magic_class_name(bcn)
         short_print.hook_or("open_sb","[")
	 base.short_hook
	 short_print.hook_or("tm_sep",",")
	 open.short_hook
	 if not predicate then
	    short_print.hook_or("tm_sep",",")
	    res.short_hook
	 end
         short_print.hook_or("close_sb","]")
      end

feature {E_AGENT, RUN_CLASS, TYPE_OF_AGENT}

   load_builtin_features is
      do
	 base_class.load_feature_call(run_type)
	 base_class.load_feature_item(run_type, res.run_type)
      end
   
feature {TYPE_FUNCTION_VISITOR}

   accept(visitor: TYPE_FUNCTION_VISITOR) is
      do
         visitor.visit_type_function(Current)
      end

feature {NONE}

   make(sp: like start_position; b: like base; so: like static_open;
	r: like res) is
      require
	 not sp.is_unknown
	 b /= Void
	 so /= Void
      do
	 start_position := sp
	 base := b
	 static_open := so
	 open ?= so
	 if r /= Void then
	    res := r
	 else
	    create {TYPE_BOOLEAN} res.make(sp)
	 end
	 create base_class_name.make(as_function, sp)
	 -- Compute `written_runnable_flag':
	 if b.is_run_type and then b.run_type = b then
	    if res.is_run_type and then res.run_type = res then
	       if so.is_run_type and then so.run_type = so then
		  written_runnable_flag := True
		  run_type := Current
	       end
	    end
	 end
      ensure
	 start_position = sp
	 base = b
	 static_open = so
	 res = r or else res.is_boolean
      end

   set(model: like Current; so: like static_open; rt: like run_type) is
      require
	 not model.written_runnable_flag
	 model.run_type /= Void
	 rt.written_runnable_flag
      do
	 start_position := model.start_position
	 base := model.base
	 static_open := so
	 res := model.res
	 base_class_name := model.base_class_name
	 run_type := rt
	 set_open_using(so)
      ensure
	 start_position = model.start_position
	 base = model.base
	 static_open = so
	 open = so.run_type
	 res = model.res
	 base_class_name = model.base_class_name
	 run_type = rt
      end
   
   is_a_(other: TYPE_OF_AGENT): BOOLEAN is
      do
	 if base.is_a(other.base) then
	    if other.open.is_a(open) then
	       if other.res /= Void then
		  Result := res.is_a(other.res)
	       else
		  Result := True
	       end
	    end
	 end
      end

invariant

   res /= Void

end -- TYPE_FUNCTION