/[eiffelstudio]/branches/eth/eve/Src/Eiffel/API/evaluated_type/named_tuple_type_a.e
ViewVC logotype

Contents of /branches/eth/eve/Src/Eiffel/API/evaluated_type/named_tuple_type_a.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94556 - (show annotations)
Fri Feb 28 09:44:00 2014 UTC (5 years, 9 months ago) by jasonw
File size: 7527 byte(s)
<<Merged from trunk#94547.>>
1 note
2 description: "Tuples whose actual generic parameters are named."
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 NAMED_TUPLE_TYPE_A
10
11 inherit
12 TUPLE_TYPE_A
13 rename
14 make as old_make
15 redefine
16 check_labels, is_named_tuple, process
17 end
18
19 SHARED_NAMES_HEAP
20 export
21 {NONE} all
22 end
23
24 create
25 make
26
27 feature {NONE} -- Initialization
28
29 make (a_class_id: INTEGER; g: like generics; n: like names)
30 -- Create new instance of NAMED_TUPLE_TYPE_A.
31 require
32 a_class_id_positive: a_class_id > 0
33 g_not_void: g /= Void
34 n_not_void: n /= Void
35 same_count: g.count = n.count
36 do
37 old_make (a_class_id, g)
38 names := n
39 ensure
40 class_id_set: class_id = a_class_id
41 generics_set: generics = g
42 names_set: names = n
43 end
44
45 feature -- Visitor
46
47 process (v: TYPE_A_VISITOR)
48 -- Process current element.
49 do
50 v.process_named_tuple_type_a (Current)
51 end
52
53 feature -- Status report
54
55 is_named_tuple: BOOLEAN = True
56 -- Current is a labelled TUPLE.
57
58 label_position_by_id (a_id: INTEGER): INTEGER
59 -- If present, position of `a_id' in Current, otherwise `0'.
60 do
61 if a_id > 0 then
62 Result := names.index_of (a_id, 0) + 1
63 end
64 ensure
65 label_position_non_negative: Result >= 0
66 end
67
68 label_position (a_name: STRING): INTEGER
69 -- If present, position of `a_name' in Current, otherwise `0'.
70 require
71 a_name_not_void: a_name /= Void
72 a_name_not_empty: not a_name.is_empty
73 local
74 l_name_id: INTEGER
75 do
76 l_name_id := names_heap.id_of (a_name)
77 if l_name_id > 0 then
78 Result := names.index_of (l_name_id, 0) + 1
79 end
80 ensure
81 label_position_non_negative: Result >= 0
82 end
83
84 label_name (i: INTEGER): STRING
85 -- Name of `i-th' label of Current.
86 require
87 valid_index: generics.valid_index (i)
88 do
89 Result := names_heap.item (names.item (i - 1))
90 ensure
91 label_name_not_void: Result /= Void
92 end
93
94 feature -- Checking
95
96 check_labels (a_context_class: CLASS_C; a_node: TYPE_AS)
97 -- Check validity of `labels' of current in `a_context_class'.
98 local
99 l_named_tuple_node: NAMED_TUPLE_TYPE_AS
100 l_vreg: VREG
101 l_vrft: VRFT
102 i, nb, l_name_id: INTEGER
103 l_names: like names
104 l_is_tuple_class_available: BOOLEAN
105 l_feat_tbl: FEATURE_TABLE
106 l_pos: INTEGER
107 do
108 -- First check the current names.
109 l_named_tuple_node ?= a_node
110 l_is_tuple_class_available := system.tuple_class.is_compiled and then
111 (not system.tuple_class.compiled_class.degree_4_needed or else system.tuple_class.compiled_class.degree_4_processed)
112 if l_is_tuple_class_available then
113 l_feat_tbl := system.tuple_class.compiled_class.feature_table
114 end
115 from
116 i := 0
117 l_names := names
118 nb := l_names.count
119 until
120 i = nb
121 loop
122 l_name_id := l_names.item (i)
123 -- Check if we have unique names.
124 if i < nb then
125 l_pos := l_names.index_of (l_name_id, i + 1)
126 if l_pos >= 0 then
127 create l_vreg
128 l_vreg.set_class (a_context_class)
129 if context.current_feature /= Void then
130 l_vreg.set_feature (context.current_feature)
131 end
132 if l_named_tuple_node /= Void and then attached l_named_tuple_node.i_th_type_declaration (l_pos + 1) as l_node then
133 l_vreg.set_location (l_node.start_location)
134 elseif a_node /= Void then
135 l_vreg.set_location (a_node.start_location)
136 end
137 l_vreg.set_entity_name (names_heap.item (l_name_id))
138 error_handler.insert_error (l_vreg)
139 end
140 end
141 -- Check that we do not conflict with a feature of the TUPLE class.
142 if l_is_tuple_class_available then
143 l_feat_tbl.search_id (l_name_id)
144 if l_feat_tbl.found then
145 create l_vrft
146 l_vrft.set_class (a_context_class)
147 if context.current_feature /= Void then
148 l_vrft.set_feature (context.current_feature)
149 end
150 if l_named_tuple_node /= Void and then attached l_named_tuple_node.i_th_type_declaration (i + 1) as l_node then
151 l_vrft.set_location (l_node.start_location)
152 elseif a_node /= Void then
153 l_vrft.set_location (a_node.start_location)
154 end
155 l_vrft.set_other_feature (l_feat_tbl.found_item)
156 error_handler.insert_error (l_vrft)
157 end
158 else
159 add_future_checking (a_context_class, agent check_tuple_feature_clash (a_context_class, context.current_feature, l_name_id, a_node, i + 1))
160 end
161 i := i + 1
162 end
163 -- Then check the potential errors in the type used in the named tuple.
164 Precursor (a_context_class, a_node)
165 end
166
167 feature {NONE} -- Implementation: access
168
169 names: SPECIAL [INTEGER]
170 -- List of all names appearing in tuple type for specifying arguments.
171
172 feature {NONE} -- Checking
173
174 check_tuple_feature_clash (a_context_class: CLASS_C; a_context_feature: FEATURE_I; a_name_id: INTEGER; a_node: TYPE_AS; a_pos: INTEGER)
175 -- Check that `a_name_id' is not the same as a feature of TUPLE.
176 require
177 a_context_class_not_void: a_context_class /= Void
178 a_name_id_positive: a_name_id > 0
179 a_pos_positive: a_pos > 0
180 a_pos_valid: a_pos <= generics.count
181 has_tuple_class: system.tuple_class /= Void
182 has_tuple_class_compiled: system.tuple_class.is_compiled
183 has_tuple_class_features: not system.tuple_class.compiled_class.degree_4_needed or else system.tuple_class.compiled_class.degree_4_processed
184 local
185 l_feat_tbl: FEATURE_TABLE
186 l_vrft: VRFT
187 do
188 l_feat_tbl := system.tuple_class.compiled_class.feature_table
189 l_feat_tbl.search_id (a_name_id)
190 if l_feat_tbl.found then
191 create l_vrft
192 l_vrft.set_class (a_context_class)
193 if a_context_feature /= Void then
194 l_vrft.set_feature (a_context_feature)
195 end
196 if
197 attached {NAMED_TUPLE_TYPE_AS} a_node as l_tuple_node and then
198 attached l_tuple_node.i_th_type_declaration (a_pos) as l_node
199 then
200 l_vrft.set_location (l_node.start_location)
201 elseif a_node /= Void then
202 l_vrft.set_location (a_node.start_location)
203 end
204 l_vrft.set_other_feature (l_feat_tbl.found_item)
205 error_handler.insert_error (l_vrft)
206 end
207 end
208
209 invariant
210 generics_not_void: generics /= Void
211 generics_not_empty: generics.count > 0
212 names_not_void: names /= Void
213 names_not_empty: names.count > 0
214
215 note
216 copyright: "Copyright (c) 1984-2014, Eiffel Software"
217 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
218 licensing_options: "http://www.eiffel.com/licensing"
219 copying: "[
220 This file is part of Eiffel Software's Eiffel Development Environment.
221
222 Eiffel Software's Eiffel Development Environment is free
223 software; you can redistribute it and/or modify it under
224 the terms of the GNU General Public License as published
225 by the Free Software Foundation, version 2 of the License
226 (available at the URL listed under "license" above).
227
228 Eiffel Software's Eiffel Development Environment is
229 distributed in the hope that it will be useful, but
230 WITHOUT ANY WARRANTY; without even the implied warranty
231 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
232 See the GNU General Public License for more details.
233
234 You should have received a copy of the GNU General Public
235 License along with Eiffel Software's Eiffel Development
236 Environment; if not, write to the Free Software Foundation,
237 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
238 ]"
239 source: "[
240 Eiffel Software
241 5949 Hollister Ave., Goleta, CA 93117 USA
242 Telephone 805-685-1006, Fax 805-685-6869
243 Website http://www.eiffel.com
244 Customer support http://support.eiffel.com
245 ]"
246 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23