@@ -75,69 +75,6 @@ def _human_readable_identifier(
75
75
return result
76
76
77
77
78
- def _verify_structure_name_collisions (
79
- symbol_table : intermediate .SymbolTable ,
80
- ) -> List [Error ]:
81
- """Verify that the C++ names of the structures do not collide."""
82
- observed_type_names : Dict [
83
- Identifier ,
84
- Union [
85
- intermediate .Enumeration ,
86
- intermediate .AbstractClass ,
87
- intermediate .ConcreteClass ,
88
- ],
89
- ] = dict ()
90
-
91
- errors = [] # type: List[Error]
92
-
93
- # region Inter-structure collisions
94
-
95
- for enum_or_cls in itertools .chain (symbol_table .enumerations , symbol_table .classes ):
96
- names : List [Identifier ]
97
-
98
- if isinstance (enum_or_cls , intermediate .Enumeration ):
99
- names = [cpp_naming .enum_name (enum_or_cls .name )]
100
- elif isinstance (enum_or_cls , intermediate .AbstractClass ):
101
- names = [cpp_naming .interface_name (enum_or_cls .name )]
102
- elif isinstance (enum_or_cls , intermediate .ConcreteClass ):
103
- names = [
104
- cpp_naming .interface_name (enum_or_cls .name ),
105
- cpp_naming .class_name (enum_or_cls .name ),
106
- ]
107
- else :
108
- assert_never (enum_or_cls )
109
-
110
- for name in names :
111
- other = observed_type_names .get (name , None )
112
-
113
- if other is not None :
114
- errors .append (
115
- Error (
116
- enum_or_cls .parsed .node ,
117
- f"The C++ name { name !r} "
118
- f"of the { _human_readable_identifier (enum_or_cls )} "
119
- f"collides with the C++ name "
120
- f"of the { _human_readable_identifier (other )} " ,
121
- )
122
- )
123
- else :
124
- observed_type_names [name ] = enum_or_cls
125
-
126
- # endregion
127
-
128
- # region Intra-structure collisions
129
-
130
- for our_type in symbol_table .our_types :
131
- collision_error = _verify_intra_structure_collisions (our_type = our_type )
132
-
133
- if collision_error is not None :
134
- errors .append (collision_error )
135
-
136
- # endregion
137
-
138
- return errors
139
-
140
-
141
78
def _verify_intra_structure_collisions (
142
79
our_type : intermediate .OurType ,
143
80
) -> Optional [Error ]:
@@ -265,6 +202,69 @@ def _verify_intra_structure_collisions(
265
202
return None
266
203
267
204
205
+ def _verify_structure_name_collisions (
206
+ symbol_table : intermediate .SymbolTable ,
207
+ ) -> List [Error ]:
208
+ """Verify that the C++ names of the structures do not collide."""
209
+ observed_type_names : Dict [
210
+ Identifier ,
211
+ Union [
212
+ intermediate .Enumeration ,
213
+ intermediate .AbstractClass ,
214
+ intermediate .ConcreteClass ,
215
+ ],
216
+ ] = dict ()
217
+
218
+ errors = [] # type: List[Error]
219
+
220
+ # region Inter-structure collisions
221
+
222
+ for enum_or_cls in itertools .chain (symbol_table .enumerations , symbol_table .classes ):
223
+ names : List [Identifier ]
224
+
225
+ if isinstance (enum_or_cls , intermediate .Enumeration ):
226
+ names = [cpp_naming .enum_name (enum_or_cls .name )]
227
+ elif isinstance (enum_or_cls , intermediate .AbstractClass ):
228
+ names = [cpp_naming .interface_name (enum_or_cls .name )]
229
+ elif isinstance (enum_or_cls , intermediate .ConcreteClass ):
230
+ names = [
231
+ cpp_naming .interface_name (enum_or_cls .name ),
232
+ cpp_naming .class_name (enum_or_cls .name ),
233
+ ]
234
+ else :
235
+ assert_never (enum_or_cls )
236
+
237
+ for name in names :
238
+ other = observed_type_names .get (name , None )
239
+
240
+ if other is not None :
241
+ errors .append (
242
+ Error (
243
+ enum_or_cls .parsed .node ,
244
+ f"The C++ name { name !r} "
245
+ f"of the { _human_readable_identifier (enum_or_cls )} "
246
+ f"collides with the C++ name "
247
+ f"of the { _human_readable_identifier (other )} " ,
248
+ )
249
+ )
250
+ else :
251
+ observed_type_names [name ] = enum_or_cls
252
+
253
+ # endregion
254
+
255
+ # region Intra-structure collisions
256
+
257
+ for our_type in symbol_table .our_types :
258
+ collision_error = _verify_intra_structure_collisions (our_type = our_type )
259
+
260
+ if collision_error is not None :
261
+ errors .append (collision_error )
262
+
263
+ # endregion
264
+
265
+ return errors
266
+
267
+
268
268
class VerifiedIntermediateSymbolTable (intermediate .SymbolTable ):
269
269
"""Represent a verified symbol table which can be used for code generation."""
270
270
0 commit comments