/[eiffelstudio]/branches/eth/eve/Src/library/memory_analyzer/ma_route_to_once_searcher.e
ViewVC logotype

Contents of /branches/eth/eve/Src/library/memory_analyzer/ma_route_to_once_searcher.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 92684 - (show annotations)
Fri Jun 7 15:28:53 2013 UTC (6 years, 7 months ago) by jasonw
File size: 13045 byte(s)
<<Merged from trunk#92682.>>
1 note
2 description: "Objects that ..."
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date: "$Date$"
6 revision: "$Revision$"
7
8 class
9 MA_ROUTE_TO_ONCE_SEARCHER
10
11 create
12 make
13
14 feature {NONE} -- Initialization
15
16 make (a_mediator: like snapshot_mediator; a_panel: EV_FRAME)
17 -- Init
18 require
19 a_mediator_not_void: a_mediator /= Void
20 a_panel_not_void: a_panel /= Void
21 do
22 result_panel := a_panel
23 snapshot_mediator := a_mediator
24 end
25
26 feature -- Commands
27
28 build_next_route
29 -- Build next route
30 local
31 l_info_box: EV_INFORMATION_DIALOG
32 do
33 name_table := snapshot_mediator.name_table
34 reference_table := snapshot_mediator.reference_table
35 once_objects_table := snapshot_mediator.once_object_table
36 start_index := snapshot_mediator.selected_index
37 if name_table = Void or reference_table = Void or start_index = 0 then
38 create l_info_box.make_with_text ("Static object information is not collected.%N%
39 %Or start point is not selected.%N%
40 %Please select a start point in Object Grid%N%
41 %and refresh again with Collecting Statics enabled.")
42 l_info_box.show
43 else
44 build
45 end
46 end
47
48 reset
49 -- Reset
50 do
51 start_index := 0
52 name_table := Void
53 reference_table := Void
54 wipe_out_results
55 end
56
57 feature {NONE} -- Results
58
59 result_panel: EV_FRAME
60 -- Panel to put result grid
61
62 grid: detachable EV_GRID
63 -- Result grid
64
65 fill_results
66 -- Fill result
67 require
68 set: attached reference_table
69 set: attached name_table
70 set: attached route_stack
71 local
72 l_array: LIST [like start_index]
73 l_item: EV_GRID_LABEL_ITEM
74 l_column: INTEGER
75 l_text: STRING
76 l_next_index: like start_index
77 l_field_name: detachable STRING
78 l_once: STRING
79 l_last: BOOLEAN
80 l_tuple: detachable TUPLE [referee: like start_index; data: detachable ANY]
81 l_reference_table: like reference_table
82 l_name_table: like name_table
83 l_name_table_item: detachable STRING
84 l_grid: like grid
85 l_route_stack: like route_stack
86 do
87 if attached grid then
88 l_grid := grid
89 else
90 create l_grid
91 grid := l_grid
92 init_grid (l_grid)
93 result_panel.extend (l_grid)
94 end
95 check l_grid /= Void end -- Implied by previous if clause
96 l_column := l_grid.column_count + 1
97 l_route_stack := route_stack
98 check attached l_route_stack end -- Implied by precondition `set'
99 l_array := l_route_stack.linear_representation
100 l_grid.set_row_count_to (l_array.count.max (l_grid.row_count))
101 l_grid.set_column_count_to (l_column)
102 l_grid.column (l_column).set_title ("Route" + l_column.out)
103 from
104 l_array.start
105 until
106 l_array.after
107 loop
108 if not l_array.islast then
109 l_next_index := l_array [l_array.index + 1]
110 else
111 l_last := True
112 end
113 if not l_last then
114 l_reference_table := reference_table
115 check l_reference_table /= Void end -- Implied by precondition `set'
116 l_tuple := l_reference_table.references_by_referee (l_next_index).item (l_array.item)
117 if l_tuple /= Void then
118 if attached {STRING} l_tuple.data as l_string then
119 l_field_name := l_string
120 else
121 --|FIXME: 2012/04/06 Shouldn't this be "(unknown)", instead of setting it Void? See review#7644004.
122 l_field_name := Void
123 end
124 else
125 l_field_name := once "(unknown)"
126 end
127 else
128 --|FIXME: 2012/04/06 Shouldn't this be "(unknown)", instead of setting it Void? See review#7644004.
129 l_field_name := Void
130 end
131 if l_field_name = Void then
132 l_field_name := once ""
133 else
134 l_field_name := l_field_name.twin
135 l_field_name.prepend (".")
136 end
137 -- Optimization, since we know that only the first object is once object.
138 if l_array.isfirst then
139 l_once := once "*"
140 else
141 l_once := once ""
142 end
143 l_name_table := name_table
144 check l_name_table /= Void end -- Implied by precondition `set'
145 l_name_table_item := l_name_table.item (l_array.item)
146 check l_name_table_item /= Void end -- FIXME: Implied by ...?
147 l_text := l_once + l_array.item.out + once ": {" + l_name_table_item + once "}" + l_field_name
148 create l_item.make_with_text (l_text)
149 l_item.set_tooltip (l_text)
150 l_grid.set_item (l_column, l_array.index, l_item)
151 l_array.forth
152 end
153 end
154
155 wipe_out_results
156 -- Wipe out all results.
157 do
158 result_panel.wipe_out
159 grid := Void
160 end
161
162 init_grid (a_grid: EV_GRID)
163 -- Init grid with copy funcion.
164 require
165 a_grid_not_void: a_grid /= Void
166 do
167 a_grid.enable_multiple_item_selection
168 a_grid.enable_selection_key_handling
169 a_grid.key_press_actions.extend (agent on_grid_key_pressed)
170 end
171
172 on_grid_key_pressed (a_key: EV_KEY)
173 -- Support Copy.
174 require
175 a_key_not_void: a_key /= Void
176 grid_set: attached grid
177 local
178 l_env: EV_ENVIRONMENT
179 l_grid: like grid
180 do
181 create l_env
182 if attached l_env.application as l_app and then l_app.ctrl_pressed then
183 inspect a_key.code
184 when {EV_KEY_CONSTANTS}.key_a then
185 l_grid := grid
186 check l_grid /= Void end -- Implied by precondition `grid_set'
187 select_all_row (l_grid)
188 when {EV_KEY_CONSTANTS}.key_c then
189 l_grid := grid
190 check l_grid /= Void end -- Implied by precondition `grid_set'
191 if not l_grid.selected_items.is_empty then
192 copy_selected_items (l_grid)
193 end
194 else
195 end
196 end
197 end
198
199 select_all_row (a_grid: EV_GRID)
200 -- Select all rows of `a_grid'.
201 require
202 a_grid_not_void: a_grid /= Void
203 local
204 i, l_count: INTEGER
205 do
206 l_count := a_grid.row_count
207 from
208 i := 1
209 until
210 i > l_count
211 loop
212 a_grid.row (i).enable_select
213 i := i + 1
214 end
215 end
216
217 copy_selected_items (a_grid: EV_GRID)
218 -- Copy all selected items in `a_grid'.
219 require
220 a_grid_not_void: a_grid /= Void
221 local
222 i, j, l_column_count, l_row_count, l_column_selected_count: INTEGER
223 l_column: EV_GRID_COLUMN
224 l_row: EV_GRID_ROW
225 l_text: STRING_32
226 l_states: SPECIAL [INTEGER]
227 l_none, l_part, l_full: INTEGER
228 l_has_full: BOOLEAN
229 clipboard: EV_CLIPBOARD
230 do
231 -- Constants for column states.
232 l_none := 1
233 l_part := 2
234 l_full := 3
235
236 l_column_count := a_grid.column_count
237 l_row_count := a_grid.row_count
238 create l_states.make_filled (0, l_column_count + 1)
239 create l_text.make (100)
240 from
241 i := 1
242 until
243 i > l_column_count
244 loop
245 l_column := a_grid.column (i)
246 l_column_selected_count := l_column.selected_items.count
247 if l_column_selected_count = l_column.count then
248 l_states.put (l_full, i)
249 l_has_full := True
250 elseif l_column_selected_count = 0 then
251 l_states.put (l_none, i)
252 else
253 l_states.put (l_part, i)
254 end
255 i := i + 1
256 end
257 -- Put titles, if has full selected column.
258 if l_has_full then
259 from
260 i := 1
261 until
262 i > l_column_count
263 loop
264 if l_states.item (i) /= l_none then
265 l_column := a_grid.column (i)
266 l_text.append (l_column.title)
267 l_text.append ("%T")
268 end
269 i := i + 1
270 end
271 l_text.append ("%N")
272 end
273
274 from
275 i := 1
276 until
277 i > l_row_count
278 loop
279 l_row := a_grid.row (i)
280 if not l_row.selected_items.is_empty then
281 from
282 j := 1
283 until
284 j > l_column_count
285 loop
286 if l_states.item (j) /= l_none then
287 if attached {EV_GRID_LABEL_ITEM} l_row.item (j) as l_text_item and then l_text_item.is_selected then
288 l_text.append (l_text_item.text)
289 l_text.append ("%T")
290 else
291 l_text.append ("%T")
292 end
293 end
294 j := j + 1
295 end
296 l_text.append ("%N")
297 end
298 i := i + 1
299 end
300 if attached (create {EV_ENVIRONMENT}).application as l_app then
301 clipboard := l_app.clipboard
302 clipboard.set_text (l_text)
303 else
304 check False end -- Implied by application is running
305 end
306 end
307
308 feature {NONE} -- Implementation
309
310 build
311 -- Build route.
312 require
313 set: attached reference_table
314 local
315 l_reference_table: like reference_table
316 l_route_stack: like route_stack
317 do
318 create l_route_stack.make (1000)
319 route_stack := l_route_stack
320 l_reference_table := reference_table
321 check l_reference_table /= Void end -- Implied by precondition `set'
322 create visited_references.make (l_reference_table.referee_count)
323 if deep_visit_node (start_index) then
324 -- Found route
325 check
326 route_stack_not_empty: not l_route_stack.is_empty
327 end
328 fill_results
329 remove_last_link_to_once
330 end
331 end
332
333 start_index: NATURAL
334 -- Start index of the object
335
336 snapshot_mediator: MA_OBJECT_SNAPSHOT_MEDIATOR
337 -- Snapshot mediator
338
339 name_table: detachable HASH_TABLE [STRING, like start_index]
340 -- Names of type of objects
341
342 reference_table: detachable MA_REFERENCES_TABLE [like start_index, like start_index]
343 -- All object relations
344
345 once_objects_table: detachable HASH_TABLE [like start_index, like start_index]
346 -- All once objects
347
348 feature {NONE} -- Implementation
349
350 deep_visit_node (a_referee: like start_index): BOOLEAN
351 -- Deep visit a node, Ture is found once object.
352 require
353 set: attached reference_table
354 set: attached route_stack
355 set: attached visited_references
356 local
357 l_all_referrers, l_visited_referrers: HASH_TABLE [TUPLE [like start_index, detachable ANY], like start_index]
358 l_referrer: like start_index
359 l_all_referrers_count: INTEGER
360 l_visited_references: like visited_references
361 l_reference_table: like reference_table
362 l_route_stack: like route_stack
363 do
364 if is_visited (a_referee) then
365 Result := False
366 else
367 l_route_stack := route_stack
368 check l_route_stack /= Void end -- Implied by precondition `set'
369 l_route_stack.put (a_referee)
370 l_reference_table := reference_table
371 check l_reference_table /= Void end -- Implied by precondition `set'
372 l_all_referrers := l_reference_table.references_by_referee (a_referee)
373 l_all_referrers_count := l_all_referrers.count
374 if l_all_referrers_count = 0 then
375 -- We reach the end. No referrer.
376 if is_once_object (a_referee) then
377 Result := True
378 else
379 Result := False
380 end
381 elseif is_once_object (a_referee) then
382 Result := True
383 else
384 l_visited_references := visited_references
385 check attached l_visited_references end -- Implied by precondition `set'
386 l_visited_referrers := l_visited_references.references_by_referee (a_referee)
387 if l_all_referrers_count = l_visited_referrers.count then
388 -- Go back one
389 Result := False
390 l_route_stack.remove
391 else
392 from
393 l_all_referrers.start
394 until
395 l_all_referrers.after or Result
396 loop
397 l_referrer := l_all_referrers.key_for_iteration
398 if not l_visited_referrers.has_key (l_referrer) then
399 l_visited_references.extend (l_referrer, a_referee, Void)
400 Result := deep_visit_node (l_referrer)
401 end
402 l_all_referrers.forth
403 end
404 if not Result then
405 l_route_stack.remove
406 end
407 end
408 end
409 end
410 end
411
412 remove_last_link_to_once
413 -- Remove last found link to once in `reference_table'.
414 -- So that next searching will not return found routes anymore.
415 require
416 ready: attached reference_table
417 local
418 l_referrer, l_referee: like start_index
419 l_route: ARRAYED_LIST [like start_index]
420 do
421 if attached route_stack as l_route_stack and then l_route_stack.count > 1 then
422 l_route := l_route_stack.linear_representation
423 l_referrer := l_route [1]
424 l_referee := l_route [2]
425 if attached reference_table as l_table then
426 l_table.remove (l_referrer, l_referee)
427 else
428 check False end -- Implied by precondition `ready'
429 end
430 end
431 end
432
433 is_visited (a_node: like start_index): BOOLEAN
434 -- Is `a_node' visited?
435 require
436 set: attached route_stack
437 local
438 l_route_stack: like route_stack
439 do
440 l_route_stack := route_stack
441 check l_route_stack /= Void end -- Implied by precondition `set'
442 Result := l_route_stack.has (a_node)
443 end
444
445 is_once_object (a_object: like start_index): BOOLEAN
446 -- Is `a_object' once?
447 require
448 set: attached once_objects_table
449 local
450 l_table: like once_objects_table
451 do
452 l_table := once_objects_table
453 check attached l_table end -- Implied by precondition `set'
454 Result := l_table.has (a_object)
455 end
456
457 route_stack: detachable ARRAYED_STACK [like start_index]
458
459 visited_references: detachable MA_REFERENCES_TABLE [like start_index, like start_index]
460 -- Visited references.
461 -- `visited_backable_nodes.references_by_referee (a_node)' gives all visited references to `a_node'.
462
463 invariant
464 snapshot_mediator_not_void: snapshot_mediator /= Void
465 result_panel_not_void: result_panel /= Void
466
467 note
468 copyright: "Copyright (c) 1984-2012, Eiffel Software and others"
469 license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
470 source: "[
471 Eiffel Software
472 5949 Hollister Ave., Goleta, CA 93117 USA
473 Telephone 805-685-1006, Fax 805-685-6869
474 Website http://www.eiffel.com
475 Customer support http://support.eiffel.com
476 ]"
477
478
479
480 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23