PageRenderTime 17ms CodeModel.GetById 13ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/semantics/code/liberty_feature_name.e

http://github.com/tybor/Liberty
Specman e | 222 lines | 178 code | 30 blank | 14 comment | 3 complexity | 58263e66705ab869d805585b6e048696 MD5 | raw file
  1-- This file is part of Liberty Eiffel.
  2--
  3-- Liberty Eiffel is free software: you can redistribute it and/or modify
  4-- it under the terms of the GNU General Public License as published by
  5-- the Free Software Foundation, version 3 of the License.
  6--
  7-- Liberty Eiffel is distributed in the hope that it will be useful,
  8-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 10-- GNU General Public License for more details.
 11--
 12-- You should have received a copy of the GNU General Public License
 13-- along with Liberty Eiffel.  If not, see <http://www.gnu.org/licenses/>.
 14--
 15class LIBERTY_FEATURE_NAME
 16
 17inherit
 18   LIBERTY_POSITIONABLE
 19      redefine is_equal, out_in_tagged_out_memory
 20      end
 21
 22insert
 23   HASHABLE
 24      redefine out_in_tagged_out_memory
 25      end
 26   COMPARABLE
 27      redefine is_equal, out_in_tagged_out_memory
 28      end
 29   LIBERTY_AST_HANDLER
 30      redefine is_equal, out_in_tagged_out_memory
 31      end
 32
 33create {ANY}
 34   make, prefixed, infixed
 35
 36create {LIBERTY_BUILDER_TOOLS, LIBERTY_FEATURE_LOCAL_CONTEXT}
 37   make_from_ast
 38
 39create {LIBERTY_TYPE_RESOLVER_IN_TYPE}
 40   make_from_ast_entity_name
 41
 42create {LIBERTY_BUILDER_TOOLS}
 43   make_regular
 44
 45create {LIBERTY_BUILDER_TOOLS, LIBERTY_PREFIX_CALL}
 46   make_prefix
 47
 48create {LIBERTY_BUILDER_TOOLS, LIBERTY_INFIX_CALL}
 49   make_infix
 50
 51feature {ANY}
 52   name: FIXED_STRING
 53   full_name: FIXED_STRING
 54
 55   out_in_tagged_out_memory is
 56      do
 57         if is_prefix then
 58            tagged_out_memory.append(once "prefix ")
 59         elseif is_infix then
 60            tagged_out_memory.append(once "infix ")
 61         end
 62         name.out_in_tagged_out_memory
 63      end
 64
 65   is_equal (other: like Current): BOOLEAN is
 66      do
 67         Result := type = other.type and then name = other.name
 68         check
 69            Result = (full_name = other.full_name)
 70         end
 71      end
 72
 73   is_regular: BOOLEAN is
 74      do
 75         Result := type = type_regular
 76      end
 77
 78   is_prefix: BOOLEAN is
 79      do
 80         Result := type = type_prefix
 81      end
 82
 83   is_infix: BOOLEAN is
 84      do
 85         Result := type = type_infix
 86      end
 87
 88   hash_code: INTEGER is
 89      do
 90         Result := full_name.hash_code
 91      end
 92
 93   infix "<" (other: like Current): BOOLEAN is
 94      do
 95         Result := full_name < other.full_name
 96      end
 97
 98feature {LIBERTY_FEATURE_NAME}
 99   type: INTEGER_8
100
101feature {}
102   make_from_ast_entity_name (ast: LIBERTY_AST_ENTITY_NAME; class_ast: LIBERTY_AST_ONE_CLASS; file: FIXED_STRING) is
103      require
104         ast /= Void
105         class_ast /= Void
106      do
107         make_regular(ast.image.image.intern, errors.semantics_position(ast.image.index, class_ast, file))
108         position := errors.semantics_position(ast.image.index, class_ast, file)
109      end
110
111   make_from_ast (ast: LIBERTY_AST_FEATURE_NAME_OR_ALIAS; class_ast: LIBERTY_AST_ONE_CLASS; file: FIXED_STRING) is
112      require
113         ast /= Void
114         class_ast /= Void
115      do
116         if ast.is_regular then
117            make_from_ast_entity_name(ast.entity_name, class_ast, file)
118         elseif ast.is_prefix then
119            make_prefix(ast.free_operator_name.image.image.intern, errors.semantics_position(ast.free_operator_name.image.index, class_ast, file))
120            position := errors.semantics_position(ast.free_operator_name.image.index, class_ast, file)
121         else
122            check ast.is_infix end
123            make_infix(ast.free_operator_name.image.image.intern, errors.semantics_position(ast.free_operator_name.image.index, class_ast, file))
124            position := errors.semantics_position(ast.free_operator_name.image.index, class_ast, file)
125         end
126      end
127
128   make_regular (a_name: like name; a_position: like position) is
129      require
130         a_name = a_name.intern
131      do
132         name := a_name
133         full_name := a_name
134         type := type_regular
135         position := a_position
136      ensure
137         name = a_name
138         type = type_regular
139         position = a_position
140      end
141
142   make_prefix (a_name: like name; a_position: like position) is
143      require
144         a_name = a_name.intern
145      do
146         name := sane_name(a_name)
147         full_name := (once "prefix " + name).intern
148         type := type_prefix
149         position := a_position
150      ensure
151         name = sane_name(a_name)
152         type = type_prefix
153         position = a_position
154      end
155
156   make_infix (a_name: like name; a_position: like position) is
157      require
158         a_name = a_name.intern
159      do
160         name := sane_name(a_name)
161         full_name := (once "infix " + name).intern
162         type := type_infix
163         position := a_position
164      ensure
165         name = sane_name(a_name)
166         type = type_infix
167         position = a_position
168      end
169
170   make (a_name: like name) is
171      require
172         a_name = a_name.intern
173      do
174         make_regular(a_name, errors.unknown_position)
175      ensure
176         name = a_name
177      end
178
179   infixed (a_name: like name) is
180      require
181         a_name = a_name.intern
182      do
183         make_infix(a_name, errors.unknown_position)
184      ensure
185         name = a_name
186      end
187
188   prefixed (a_name: like name) is
189      require
190         a_name = a_name.intern
191      do
192         make_prefix(a_name, errors.unknown_position)
193      ensure
194         name = a_name
195      end
196
197   sane_name (a_name: FIXED_STRING): FIXED_STRING is
198      do
199         if a_name.first = '"' then
200            check a_name.last = '"' end
201            Result := (a_name.substring(2, a_name.upper - 1)).intern
202         else
203            check a_name.last /= '"' end
204            Result := a_name
205         end
206      ensure
207         a_name.first = '"' implies a_name = ("%"" + Result + "%"").intern
208         a_name.first /= '"' implies Result = a_name
209      end
210
211   type_regular: INTEGER_8 is 1
212   type_prefix: INTEGER_8 is 2
213   type_infix: INTEGER_8 is 3
214
215   errors: LIBERTY_ERRORS
216
217invariant
218   name /= Void
219   full_name /= Void
220   type /= 0
221
222end