File: rename_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 (217 lines) | stat: -rw-r--r-- 5,853 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
-- 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 RENAME_LIST

inherit
   GLOBALS
   VISITABLE

creation make

feature {RENAME_LIST_VISITOR}

   accept(visitor: RENAME_LIST_VISITOR) is
      do
         visitor.visit_rename_list(Current)
      end

feature

   pretty_print is
      local
         icount, i: INTEGER
      do
         pretty_printer.set_indent_level(2)
         pretty_printer.indent
         pretty_printer.keyword(once "rename")
         from
            i := list.lower
         until
            i > list.upper
         loop
            list.item(i).pretty_print
            i := i + 1
            icount := icount + 1
            if i <= list.upper then
               pretty_printer.put_string(once ", ")
               if icount > 3 then
                  icount := 0
                  pretty_printer.set_indent_level(3)
                  pretty_printer.indent
               end
            end
         end
      end

feature {PARENT}

   name_in_child(fn: FEATURE_NAME): FEATURE_NAME is
         -- Gives Void or the name of `fn' after renaming.
      require
         fn /= Void
      local
         i: INTEGER
         rp: RENAME_PAIR
         fn_to_key: STRING
         no_longer_exists: BOOLEAN
      do
         fn_to_key := fn.to_key
         Result := fn
         from
            i := list.upper
         until
            i < list.lower
         loop
            rp := list.item(i)
            if rp.old_name.to_key = fn_to_key then
               Result := rp.new_name
            elseif rp.new_name.to_key = fn_to_key then
               no_longer_exists := true
            end
            i := i - 1
         end
         if no_longer_exists and then Result = fn then
            Result := Void
         end
      end

   name_in_parent(fn: FEATURE_NAME): FEATURE_NAME is
         -- Gives Void or the name of `fn' before renaming.
      require
         fn /= Void
      local
         i: INTEGER; rp: RENAME_PAIR; fn_to_key: STRING
         no_longer_exists: BOOLEAN
      do
         fn_to_key := fn.to_key
         Result := fn
         from
            i := list.upper
         until
            i < list.lower
         loop
            rp := list.item(i)
            if rp.new_name.to_key = fn_to_key then
               Result := rp.old_name
	       i := list.lower - 1
            elseif rp.old_name.to_key = fn_to_key then
               no_longer_exists := true
            end
            i := i - 1
         end
         if no_longer_exists and then Result = fn then
            Result := Void
         end
      end

   new_name_for_step2(fn: FEATURE_NAME): FEATURE_NAME is
      require
         fn /= Void
      local
         i: INTEGER
         rp: RENAME_PAIR
         fn_to_key: STRING
      do
         fn_to_key := fn.to_key
         from
            i := list.upper
         until
            i < list.lower
         loop
            rp := list.item(i)
            if rp.old_name.to_key = fn_to_key then
               if Result = Void then
                  Result := rp.new_name
               end
            end
            i := i - 1
         end
      end

   add_last(rp: RENAME_PAIR) is
      require
         rp /= Void
      do
         list.add_last(rp)
      end

   get_started(pbc: BASE_CLASS) is
      require
         ace.all_check
      local
         i, j: INTEGER
         rp1, rp2: RENAME_PAIR
      do
         from
            i := list.upper
         until
            i < list.lower
         loop
            rp1 := list.item(i)
            if not pbc.has(rp1.old_name) then
               error_handler.add_position(rp1.old_name.start_position)
               error_handler.append(
                  "Cannot rename inexistant feature (VHRC.1).")
	       error_handler.print_as_fatal_error
            end
            i := i - 1
            from
               j := i
            until
               j < list.lower
            loop
               rp2 := list.item(j)
               if rp2.old_name.to_key = rp1.old_name.to_key then
                  error_handler.add_position(rp1.old_name.start_position)
                  error_handler.add_position(rp2.old_name.start_position)
                  error_handler.append(
                     "Multiple rename for the same feature (VHRC.2).")
		  error_handler.print_as_fatal_error
               end
               j := j - 1
            end
         end
      end

feature {NONE}

   list: FIXED_ARRAY[RENAME_PAIR]

   make(first: RENAME_PAIR) is
      require
         first /= Void
      do
         !!list.with_capacity(4)
	 list.add_last(first)
      ensure
         list.first = first
      end

invariant

   not list.is_empty

end -- RENAME_LIST