/[eiffelstudio]/branches/Eiffel_56_new_consumer/Src/dotnet/consumer/cache/cache_reader.e
ViewVC logotype

Contents of /branches/Eiffel_56_new_consumer/Src/dotnet/consumer/cache/cache_reader.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56340 - (show annotations)
Thu Dec 22 23:14:08 2005 UTC (14 years, 1 month ago) by paulb
File size: 9394 byte(s)
Added feature `reset_info' to allow clients to force retrieval of updated cache information on calling `info'
1 indexing
2 description: "Read content of Eiffel Assembly Cache"
3 date: "$Date$"
4 revision: "$Revision$"
5
6 class
7 CACHE_READER
8
9 inherit
10 CACHE_PATH
11 export
12 {ANY} all
13 end
14
15 SHARED_CACHE_MUTEX_GUARD
16 export
17 {NONE} all
18 end
19
20 create
21 default_create
22
23 feature -- Access
24
25 consumed_assemblies: ARRAY [CONSUMED_ASSEMBLY] is
26 -- Returns all completed consumed assemblies
27 local
28 l_assemblies: ARRAYED_LIST [CONSUMED_ASSEMBLY]
29 do
30 if is_initialized then
31 create l_assemblies.make_from_array (info.assemblies)
32 from
33 l_assemblies.start
34 until
35 l_assemblies.after
36 loop
37 if l_assemblies.item /= Void and then not l_assemblies.item.is_consumed then
38 l_assemblies.remove
39 else
40 l_assemblies.forth
41 end
42 end
43 Result := l_assemblies
44 end
45 end
46
47 consumed_assembly_from_path (a_path: STRING): CONSUMED_ASSEMBLY is
48 -- Find a consumed assembly in cache that matches `a_path'.
49 require
50 non_void_path: a_path /= Void
51 valid_path: not a_path.is_empty
52 local
53 l_path: STRING
54 i: INTEGER
55 l_consumed_assemblies: ARRAY [CONSUMED_ASSEMBLY]
56 do
57 l_consumed_assemblies := info.assemblies
58 from
59 i := 1
60 until
61 i > l_consumed_assemblies.count or Result /= Void
62 loop
63 if l_consumed_assemblies.item (i) /= Void then
64 if l_path = Void then
65 l_path := l_consumed_assemblies.item (i).format_path (a_path)
66 end
67 if l_consumed_assemblies.item (i).has_same_ready_formatted_path (l_path) then
68 Result := l_consumed_assemblies.item (i)
69 end
70 end
71 i := i + 1
72 end
73 end
74
75 assembly_types (a_assembly: CONSUMED_ASSEMBLY): CONSUMED_ASSEMBLY_TYPES is
76 -- Assembly information from EAC
77 require
78 non_void_assembly: a_assembly /= Void
79 valid_assembly: is_assembly_in_cache (a_assembly.gac_path, True)
80 local
81 des: EIFFEL_DESERIALIZER
82 do
83 create des
84 des.deserialize (absolute_assembly_path_from_consumed_assembly (a_assembly) + assembly_types_file_name, 0)
85 Result ?= des.deserialized_object
86 ensure
87 non_void_info: Result /= Void
88 end
89
90 consumed_type_from_dotnet_type_name (a_assembly: CONSUMED_ASSEMBLY; a_type: STRING): CONSUMED_TYPE is
91 -- Type information from type `type' contained in `ca'
92 require
93 a_assembly_not_void: a_assembly /= Void
94 a_assembly_is_in_consumed_cache: is_assembly_in_cache (a_assembly.gac_path, True)
95 a_type_not_void: a_type /= Void
96 not_a_type_empty: not a_type.is_empty
97 local
98 l_des: EIFFEL_DESERIALIZER
99 l_type_path: STRING
100 l_pos: INTEGER
101 do
102 l_pos := type_position_from_type_name (a_assembly, a_type)
103 if l_pos >= 0 then
104 create l_des
105 l_type_path := absolute_assembly_path_from_consumed_assembly (a_assembly) + classes_file_name
106 l_des.deserialize (l_type_path, l_pos)
107 Result ?= l_des.deserialized_object
108 end
109 ensure
110 non_void_result: Result /= Void
111 end
112
113 consumed_type_from_consumed_referenced_type (a_assembly: CONSUMED_ASSEMBLY; a_crt: CONSUMED_REFERENCED_TYPE): CONSUMED_TYPE is
114 -- Type information from consumed referenced type `crt'.
115 require
116 non_void_assembly: a_assembly /= Void
117 valid_assembly: is_assembly_in_cache (a_assembly.gac_path, True)
118 non_void_referenced_type: a_crt /= Void
119 local
120 l_ca_mapping: CONSUMED_ASSEMBLY_MAPPING
121 l_name: STRING
122 do
123 l_ca_mapping := assembly_mapping_from_consumed_assembly (a_assembly)
124
125 if a_crt.is_by_ref then
126 l_name := a_crt.name.twin
127 l_name.keep_head (l_name.count - 1)
128 else
129 l_name := a_crt.name
130 end
131
132 Result := consumed_type_from_dotnet_type_name (l_ca_mapping.assemblies @ a_crt.assembly_id, l_name)
133 ensure
134 non_void_info: Result /= Void
135 end
136
137 assembly_mapping_from_consumed_assembly (a_assembly: CONSUMED_ASSEMBLY): CONSUMED_ASSEMBLY_MAPPING is
138 -- Assembly information from EAC for `a_assembly'.
139 require
140 non_void_assembly: a_assembly /= Void
141 valid_assembly: is_assembly_in_cache (a_assembly.gac_path, True)
142 local
143 des: EIFFEL_DESERIALIZER
144 do
145 create des
146 des.deserialize (absolute_assembly_path_from_consumed_assembly (a_assembly) + Assembly_mapping_file_name, 0)
147 Result ?= des.deserialized_object
148 ensure
149 non_void_info: Result /= Void
150 end
151
152 consumed_type (a_type: SYSTEM_TYPE): CONSUMED_TYPE is
153 -- Consumed type corresponding to `a_type'.
154 require
155 a_type_not_void: a_type /= Void
156 a_type_is_in_cache: is_type_in_cache (a_type)
157 local
158 l_des: EIFFEL_DESERIALIZER
159 l_ca: CONSUMED_ASSEMBLY
160 l_pos: INTEGER
161 do
162 l_pos := type_position_from_type (a_type)
163 if l_pos >= 0 then
164 l_ca := consumed_assembly_from_path (a_type.assembly.location)
165 if l_ca /= Void then
166 create l_des
167 l_des.deserialize (absolute_type_path (l_ca), l_pos)
168 Result ?= l_des.deserialized_object
169 end
170 end
171 ensure
172 non_void_consumed_type: Result /= Void
173 end
174
175 client_assemblies (a_assembly: CONSUMED_ASSEMBLY): ARRAY [CONSUMED_ASSEMBLY] is
176 -- List of assemblies in EAC depending on `a_assembly'.
177 require
178 non_void_assembly: a_assembly /= Void
179 local
180 l_client_assemblies: ARRAYED_LIST [CONSUMED_ASSEMBLY]
181 l_referenced_assemblies: like assembly_mapping_from_consumed_assembly
182 l_assemblies: like consumed_assemblies
183 i: INTEGER
184 do
185 l_assemblies := consumed_assemblies
186 create l_client_assemblies.make (l_assemblies.count)
187 from
188 i := 1
189 until
190 i > l_assemblies.count
191 loop
192 if l_assemblies.item (i) /= Void then
193 l_referenced_assemblies := assembly_mapping_from_consumed_assembly (l_assemblies.item (i))
194 if l_referenced_assemblies.assemblies.has (a_assembly) then
195 l_client_assemblies.extend (l_assemblies.item (i))
196 end
197 end
198 i := i + 1
199 end
200 Result := l_client_assemblies
201 end
202
203 feature -- Status Report
204
205 is_initialized: BOOLEAN is
206 -- Is EAC correctly installed?
207 do
208 Result := (create {RAW_FILE}.make (Absolute_info_path)).exists
209 end
210
211 is_assembly_in_cache (a_path: STRING; a_consumed: BOOLEAN): BOOLEAN is
212 -- Is `a_path' in cache and if `a_consumed' has it been consumed
213 require
214 non_void_path: a_path /= Void
215 valid_path: not a_path.is_empty
216 local
217 l_ca: CONSUMED_ASSEMBLY
218 do
219 l_ca := consumed_assembly_from_path (a_path)
220 Result := l_ca /= Void and (not a_consumed or l_ca.is_consumed)
221 end
222
223 is_type_in_cache (a_type: SYSTEM_TYPE): BOOLEAN is
224 -- Is `a_type' in EAC?
225 require
226 non_void_type: a_type /= Void
227 local
228 l_ca: CONSUMED_ASSEMBLY
229 l_type_path: STRING
230 l_pos: INTEGER
231 do
232 l_pos := type_position_from_type (a_type)
233 if l_pos >= 0 then
234 l_ca := consumed_assembly_from_path (a_type.assembly.location)
235 if l_ca /= Void then
236 l_type_path := absolute_type_path (l_ca)
237 if l_type_path /= Void and not l_type_path.is_empty then
238 Result := (create {RAW_FILE}.make (l_type_path)).exists
239 end
240 end
241 end
242 end
243
244 feature {CACHE_WRITER} -- Implementation
245
246 info: CACHE_INFO is
247 -- Information on EAC content
248 require
249 non_void_clr_version: clr_version /= Void
250 local
251 des: EIFFEL_DESERIALIZER
252 l_ci: CACHE_INFO
253 do
254 guard.lock
255 if internal_info.item = Void then
256 if is_initialized then
257 create des
258 des.deserialize (Absolute_info_path, 0)
259 if des.successful then
260 l_ci ?= des.deserialized_object
261 if l_ci /= Void then
262 internal_info.put (l_ci)
263 end
264 end
265 end
266 if internal_info.item = Void then
267 -- cache info is not initalized or is outdated
268 internal_info.put (create {CACHE_INFO}.make)
269 (create {EIFFEL_SERIALIZER}).serialize (internal_info.item, absolute_info_path, False)
270 end
271 end
272 Result := internal_info.item
273 guard.unlock
274 ensure
275 non_void_if_initialized: is_initialized implies Result /= Void
276 end
277
278 feature -- Reset
279
280 reset_info is
281 -- Causes `info' to be reevaluated.
282 -- WARNING: Use this with caution. `reset_info' should not be called
283 -- when in the middle of a batch operation.
284 do
285 internal_info.put (Void)
286 ensure
287 internal_info_item_not_attached: internal_info.item = Void
288 end
289
290 feature {NONE} -- Implementation
291
292 internal_info: CELL [CACHE_INFO] is
293 -- cache `info'
294 once
295 create Result
296 end
297
298 type_position_from_type (a_type: SYSTEM_TYPE): INTEGER is
299 -- retrieve type position from `a_type' in `a_assembly'.
300 -- `-1' if not found.
301 require
302 a_type_not_void: a_type /= Void
303 local
304 l_ca: CONSUMED_ASSEMBLY
305 do
306 l_ca := consumed_assembly_from_path (a_type.assembly.location)
307 if l_ca /= Void then
308 Result := type_position_from_type_name (l_ca, a_type.full_name)
309 else
310 Result := -1
311 end
312 ensure
313 valid_result: Result =-1 or Result >= 0
314 end
315
316 type_position_from_type_name (a_assembly: CONSUMED_ASSEMBLY; a_type: STRING): INTEGER is
317 -- retrieve type position from `a_type' in `a_assembly'.
318 -- `-1' if not found.
319 require
320 a_assembly_not_void: a_assembly /= Void
321 a_type_not_void: a_type /= Void
322 not_a_type_empty: not a_type.is_empty
323 local
324 l_types: like assembly_types
325 i: INTEGER
326 do
327 l_types := assembly_types (a_assembly)
328 Result := -1
329 if l_types /= Void then
330 from
331 i := 1
332 until
333 i > l_types.count
334 or else Result >= 0
335 or else l_types.dotnet_names @ i = Void
336 loop
337 if (l_types.dotnet_names @ i).is_equal (a_type) then
338 Result := l_types.positions.item (i)
339 else
340 i := i + 1
341 end
342 end
343 end
344 ensure
345 valid_result: Result =-1 or Result >= 0
346 end
347
348 end -- class CACHE_READER

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23