File: parent_list.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 (767 lines) | stat: -rw-r--r-- 19,945 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
-- 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 PARENT_LIST
   --
   -- To store the parent list of a class.
   --

inherit
   GLOBALS
   VISITABLE

creation make

feature

   base_class: BASE_CLASS
         -- Where the parent list is written.

   start_position: POSITION
         -- Of the keyword "inherit".

   heading_comment: COMMENT
         -- Global comment of the inherit clause.

   count: INTEGER is
      do
         Result := list.count
      end

   up_to_any_in(pl: FIXED_ARRAY[BASE_CLASS]) is
      local
         i: INTEGER
         p: PARENT
         bc: BASE_CLASS
      do
         from
            i := list.upper
         until
            i < list.lower
         loop
            p := list.item(i)
            bc := p.base_class
            if not pl.fast_has(bc) then
               pl.add_last(bc)
            end
            i := i - 1
         end
         from
            i := list.upper
         until
            i < list.lower
         loop
            p := list.item(i)
            bc := p.base_class
            if bc /= class_any then
               bc.up_to_any_in(pl)
            end
            i := i - 1
         end
      end

   base_class_name: CLASS_NAME is
      do
         Result := base_class.name
      end

   has_redefine(fn: FEATURE_NAME): BOOLEAN is
      require
         fn /= Void
      local
         i: INTEGER
      do
         from
            i := list.upper
         until
            Result or else i < list.lower
         loop
            Result := list.item(i).has_redefine(fn)
            i := i - 1
         end
      end

feature {BASE_CLASS}

   id_extra_information(tfw: TEXT_FILE_WRITE) is
      local
         i: INTEGER
      do
         tfw.put_integer(count)
         tfw.put_string(once " parents: ")
         from
            i := list.lower
         until
            i > list.upper
         loop
            list.item(i).id_extra_information(tfw)
            tfw.put_character(' ')
            i := i + 1
         end
      end

   up_to_original(bottom: BASE_CLASS; top_fn: FEATURE_NAME): FEATURE_NAME is
      local
         p1, p2: PARENT; fn1, fn2, new_fn: FEATURE_NAME; i: INTEGER
      do
         from
            i := list.upper
         until
            i < list.lower or else fn1 /= Void
         loop
            p1 := list.item(i)
            fn1 := p1.up_to_original(bottom,top_fn)
            i := i - 1
         end
         from
         until
            i < list.lower
         loop
            p2 := list.item(i)
            fn2 := p2.up_to_original(bottom,top_fn)
            if fn2 /= Void then
               new_fn := p2.do_rename(top_fn)
               if p2.has_select_for(new_fn) then
                  p1 := p2
                  fn1 := fn2
               end
            end
            i := i - 1
         end
         if fn1 /= Void then
            if fn1.to_string /= top_fn.to_string then
               Result := repeated_inheritance(p1,fn1,top_fn)
            else
               Result := fn1
            end
         end
      end

   original_name(top: BASE_CLASS; bottom_fn: FEATURE_NAME): FEATURE_NAME is
      require
         top /= Void
         bottom_fn /= Void
      local
         p1: PARENT; fn1: FEATURE_NAME; i: INTEGER
      do
         from
            i := list.upper
         until
            i < list.lower or else fn1 /= Void
         loop
            p1 := list.item(i)
            fn1 := p1.original_name(top,bottom_fn)
            i := i - 1
         end
         Result := fn1
         if Result = Void then
            Result := bottom_fn
            error_handler.add_position(bottom_fn.start_position)
            error_handler.append(top.name.to_string)
            error_handler.append(". PARENT_LIST.original_name, Not Yet Implemented.")
            error_handler.print_as_warning
         end
      end

   clients_for(fn: FEATURE_NAME): CLIENT_LIST is
      require
         fn /= Void
      local
         i: INTEGER; cl: CLIENT_LIST
      do
         from
            i := list.upper
         until
            i < list.lower
         loop
            cl := list.item(i).clients_for(fn)
            if Result = Void then
               Result := cl
            elseif cl /= Void then
               Result := Result.append(cl)
            end
            if Result = Void then
               i := i - 1
            elseif Result.gives_permission_to_any then
               i := list.lower - 1
            else
               i := i - 1
            end
         end
      end

   going_up(trace: FIXED_ARRAY[PARENT]; top: BASE_CLASS
            top_fn: FEATURE_NAME;): FEATURE_NAME is
      require
         top /= Void
         top_fn /= Void
      local
         i: INTEGER
         p1, p2: PARENT
         fn1, fn2: FEATURE_NAME
      do
         from
            i := list.upper
         until
            fn1 /= Void or else i < list.lower
         loop
            p1 := list.item(i)
            fn1 := p1.going_up(trace,top,top_fn)
            i := i - 1
         end
         from
         until
            i < list.lower
         loop
            p2 := list.item(i)
            fn2 := p2.going_up(trace,top,top_fn)
            if fn2 /= Void then
               if p2.has_select_for(fn2) then
                  p1 := p2
                  fn1 := fn2
               end
            end
            i := i - 1
         end
         Result := fn1
      end

   is_a_vncg(t1, t2: E_TYPE): BOOLEAN is
      require
         t1.run_type = t1
         t2.run_type = t2
         t2.generic_list /= Void
         error_handler.is_empty
      local
         i: INTEGER
      do
         from
            i := list.upper
         until
            Result or else i < list.lower
         loop
            Result := list.item(i).is_a_vncg(t1,t2)
            i := i - 1
         end
      ensure
         error_handler.is_empty
      end

   graph_node_vncg_update(site: POSITION; t1, t2: E_TYPE): BOOLEAN is
      require
	 t1.is_a(t2)
	 t1.run_type = t1
	 t2.run_type = t2
	 t2.generic_list /= Void 
      local
         i: INTEGER
      do
         from
            i := list.upper
         until
            Result or else i < list.lower
         loop
	    Result := list.item(i).graph_node_vncg_update(site,t1,t2)
            i := i - 1
         end
      end

   e_feature(fn: FEATURE_NAME): E_FEATURE is
      local
         i: INTEGER
      do
         from
            i := list.upper
         until
            Result /= Void or else i < list.lower
         loop
            Result := list.item(i).e_feature(fn)
            i := i - 1
         end
      end

   collect_invariant(rc: RUN_CLASS) is
      require
         rc /= Void
      local
         i: INTEGER
      do
         from
            i := list.upper
         until
            i < list.lower
         loop
            list.item(i).base_class.collect_invariant(rc)
            i := i - 1
         end
      end

   inherit_cycle_check is
      local
         i: INTEGER; p: PARENT; bc: BASE_CLASS
      do
         from
            i := list.upper
         until
            i < list.lower
         loop
            p := list.item(i)
            bc := p.type.base_class
            if bc = Void then
               error_handler.add_position(p.start_position)
               error_handler.append(fz_cnf)
	       error_handler.print_as_fatal_error
            else
               bc.inherit_cycle_check
            end
            i := i - 1
         end
      end

   has_parent(c: BASE_CLASS): BOOLEAN is
      require
         not c.is_any
      local
         i: INTEGER; bc: BASE_CLASS
      do
         from
            i := list.upper
         until
            Result or else i < list.lower
         loop
            bc := list.item(i).base_class
            if c = bc then
               Result := true
            elseif bc.is_subclass_of(c) then
               Result := true
            else
               i := i - 1
            end
         end
      end

   first_parent_for(c: BASE_CLASS): PARENT is
         -- Gives the first parent going to `c'.
      local
         i: INTEGER; pbc: BASE_CLASS
      do
         from
            i := list.lower
         until
            Result /= Void
         loop
            Result := list.item(i)
            pbc := Result.base_class
            if pbc = c then
            elseif pbc.is_subclass_of(c) then
            else
               Result := Void
            end
            i := i + 1
         end
      ensure
         Result /= Void
      end

   next_parent_for(c: BASE_CLASS; previous: PARENT): like previous is
         -- Gives the next one or Void.
      local
         i: INTEGER
         pbc: BASE_CLASS
      do
         from
            from
               i := list.lower
            until
               Result = previous
            loop
               Result := list.item(i)
               i := i + 1
            end
            Result := Void
         until
            Result /= Void or else i > list.upper
         loop
            Result := list.item(i)
            pbc := Result.base_class
            if pbc = c then
            elseif pbc.is_subclass_of(c) then
            else
               Result := Void
            end
            i := i + 1
         end
      end

   header_comment_for(ci: CLASS_INVARIANT) is
      local
         i: INTEGER
      do
         from
            i := list.upper
         until
            i < list.lower or else ci.header_comment /= Void
         loop
            list.item(i).base_class.header_comment_for(ci)
            i := i - 1
         end
      end

   get_started_step_1 is
      local
	 i1: INTEGER
      do
         from
            i1 := list.upper
         until
            i1 < list.lower
         loop
            list.item(i1).get_started_step_1(Current)
            i1 := i1 - 1
         end
      end
   
   get_started_step_2 is
      local
         i1, i2: INTEGER; p1, p2: PARENT
      do
         from
            i1 := list.upper
         until
            i1 < list.lower
         loop
            list.item(i1).get_started_step_2
            i1 := i1 - 1
         end
         if list.count > 1 then
            -- Checking select :
            from
               i2 := list.upper
            until
               i2 = list.lower
            loop
               from
                  i1 := list.lower
               invariant
                  i1 < i2 + 1
               variant
                  i2 - i1
               until
                  i1 = i2
               loop
                  p1 := list.item(i1)
                  p2 := list.item(i2)
                  p1.multiple_check(p2)
                  p2.multiple_check(p1)
                  i1 := i1 + 1
               end
               i2 := i2 - 1
            end
         end
      end

   look_up_for(rc: RUN_CLASS; fn: FEATURE_NAME): E_FEATURE is
      local
         i: INTEGER
         p1, p2: PARENT
         f1, f2: E_FEATURE
      do
         from
            i := list.upper
         until
            f1 /= Void or else i < list.lower
         loop
            p1 := list.item(i)
            f1 := p1.look_up_for(rc,fn)
            i := i - 1
         end
         from
         until
            i < list.lower
         loop
            p2 := list.item(i)
            f2 := p2.look_up_for(rc,fn)
            if f2 = Void then
            elseif f1 = f2 then
            elseif f2.is_not_mergeable_with(f1) then
               error_handler.add_position(start_position)
               error_handler.add_position(f1.start_position)
               error_handler.add_position(f2.start_position)
               error_handler.append(fz_ich)
               error_handler.print_as_fatal_error
            elseif f2.is_deferred then
            elseif f1.is_deferred then
               f1 := f2
               p1 := p2
            elseif p1.has_redefine(fn) then
               if p2.has_redefine(fn) then
               else
                  error_handler.add_position(fn.start_position)
                  error_handler.add_position(p2.start_position)
                  error_handler.add_position(f2.start_position)
                  error_handler.append(em1)
                  error_handler.print_as_fatal_error
               end
            elseif p2.has_redefine(fn) then
               error_handler.add_position(fn.start_position)
               error_handler.add_position(p1.start_position)
               error_handler.add_position(f1.start_position)
               error_handler.append(em1)
               error_handler.print_as_fatal_error
            else
               error_handler.add_position(p2.start_position)
               error_handler.add_position(p1.start_position)
               error_handler.add_position(f1.start_position)
               error_handler.add_position(f2.start_position)
               error_handler.append(em1)
               error_handler.print_as_fatal_error
            end
            i := i - 1
         end
         Result := f1
      end

   collect_assertion(fn: FEATURE_NAME) is
      require
         fn /= Void
      local
         i: INTEGER; p1, p2: PARENT; fn1, fn2: FEATURE_NAME
      do
         from
            i := list.upper
         until
            i < list.lower
         loop
            p2 := list.item(i)
            fn2 := p2.name_in_parent(fn)
            if fn2 /= Void and then p2.has_select_for(fn) then
               p1 := p2
               fn1 := fn2
            end
            i := i - 1
         end
         if fn1 /= Void then
            p1.base_class.collect_assertion(fn1)
         else
            from
               i := list.upper
            until
               i < list.lower
            loop
               p1 := list.item(i)
               fn1 := p1.name_in_parent(fn)
               if fn1 /= Void then
                  p1.base_class.collect_assertion(fn1)
               end
               i := i - 1
            end
         end
      end

   pretty_print is
      local
         i: INTEGER
      do
         pretty_printer.set_indent_level(0)
         if not pretty_printer.zen_mode then
            pretty_printer.skip_one_line
         end
	 pretty_printer.indent
         pretty_printer.keyword(fz_inherit)
         pretty_printer.set_indent_level(1)
	 if not pretty_printer.zen_mode then
	    pretty_printer.indent
	 end
         if heading_comment /= Void then
            heading_comment.pretty_print
         end
         from
            i := list.lower
         until
            i > list.upper
         loop
            list.item(i).pretty_print
            i := i + 1
         end
      end
   
   smallest_ancestor(type, other: E_TYPE): E_TYPE is
      require
         type.base_class.parent_list = Current
         other.base_class.parent_list /= Void
         type.is_run_type
         other.is_run_type
      local
         i: INTEGER; p: PARENT; sa: E_TYPE
      do
         from
            i := list.upper
         until
            i < list.lower
         loop
            p := list.item(i)
            sa := p.runnable_type(other)
	    if sa.run_time_mark = other.run_time_mark then
	       Result := sa
	       i := list.lower - 1
            elseif Result = Void then
	       Result := sa.smallest_ancestor(other)
            elseif sa.is_a(other) then
	       if Result.is_a(other) then
		  Result := sa.smallest_ancestor(Result)
	       else
		  error_handler.cancel
		  Result := sa
	       end
	    else
	       error_handler.cancel
            end
	    i := i - 1
         end
      ensure
         Result.is_run_type
      end

feature {PRECURSOR_CALL}

   precursor_for(pc: PRECURSOR_CALL; wrf: RUN_FEATURE): EFFECTIVE_ROUTINE is
         -- Look for the feature for `pc' which is written inside `wrf'.
      require
         pc /= Void
         wrf /= Void
      local
         i: INTEGER
         parent: PARENT
         f2: like precursor_for
      do
         from
            i := list.upper
         until
            Result /= Void or else i < list.lower
         loop
            parent := list.item(i)
            Result := parent.precursor_for(pc,wrf)
            i := i - 1
         end
         if Result = Void then
            error_handler.add_position(pc.start_position)
            error_handler.append("Precursor routine not found.")
	    error_handler.print_as_fatal_error
         end
         if base_class.all_check then
            from
            until
               i < list.lower
            loop
               parent := list.item(i)
               f2 := parent.precursor_for(pc,wrf)
               if f2 /= Void and then f2 /= Result then
                  error_handler.add_position(pc.start_position)
                  error_handler.add_position(Result.start_position)
                  error_handler.add_position(f2.start_position)
                  error_handler.append("Multiple Precursor found (%
                                       %must use { ... } ancestor selection).")
		  error_handler.print_as_fatal_error
               end
               i := i - 1
            end
         end
      end

feature {PARENT_LIST_VISITOR}

   accept(visitor: PARENT_LIST_VISITOR) is
      do
         visitor.visit_parent_list(Current)
      end

feature {PARENT_LIST_VISITOR}

   list: FIXED_ARRAY[PARENT]

feature {NONE}

   make(bc: like base_class; sp: like start_position
        hc: like heading_comment; l: like list) is
      require
         bc /= Void
         not sp.is_unknown
         not l.is_empty
      do
         base_class := bc
         heading_comment := hc
         start_position := sp
         list := l
      ensure
         base_class = bc
         start_position = sp
         heading_comment = hc
         list = l
      end

   repeated_inheritance(p1: PARENT; fn1, top_fn: FEATURE_NAME): FEATURE_NAME is
      require
         p1 /= void
         fn1 /= Void
         top_fn /= Void
      local
         i: INTEGER
         p2: PARENT
         bc1: BASE_CLASS
      do
         from
            bc1 := p1.base_class
            i := list.upper
         until
            i < list.lower
         loop
            p2 := list.item(i)
            if p1 /= p2 then
               if bc1 = p2.base_class then
                  if p2.do_rename(fn1).to_string = top_fn.to_string then
                     Result := top_fn
                  elseif p1.do_rename(fn1).to_string = top_fn.to_string then
                     Result := top_fn
                  end
               end
            end
            i := i - 1
         end
         if Result = Void then
            Result := fn1
         end
      ensure
         top_fn /= Void
      end

   em1: STRING is "Inheritance clash."

invariant

   base_class /= Void

   not list.is_empty

end -- PARENT_LIST