1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
24 var is_variable
= false
26 var is_parameter_name
= false
27 var class_objc
: nullable ObjcClass = null
28 var method_objc
: ObjcMethod is noinit
29 var attribute_objc
: ObjcAttribute is noinit
30 var param
: Param is noinit
31 var model
= new ObjcModel
33 redef fun visit
(n
) do n
.accept_objc
(self)
37 fun accept_objc
(v
: Interpretor) do visit_children
(v
)
41 redef fun accept_objc
(v
) do
45 redef class Nlines_interface
46 redef fun accept_objc
(v
) do
47 var interface_block
= n_interface_block
48 var inheritance_block
= n_inheritance
50 if interface_block
!= null then
51 for class_objc
in v
.model
.classes
do
52 if class_objc
.name
== n_class
.text
then
53 v
.class_objc
= class_objc
56 if v
.class_objc
== null then
57 v
.class_objc
= new ObjcClass(n_class
.text
)
58 v
.model
.classes
.add
(v
.class_objc
)
60 if inheritance_block
!= null then v
.enter_visit
(inheritance_block
)
61 v
.enter_visit
(interface_block
)
66 redef class Ninheritance_add
67 redef fun accept_objc
(v
) do
68 var additional
= n_additional
69 v
.enter_visit
(n_classe
)
70 if additional
!= null then v
.enter_visit
(additional
)
74 redef class Nclasse_class
75 redef fun accept_objc
(v
) do
76 v
.class_objc
.super_names
.add
(n_class
.text
)
80 redef class Nadditional_add
81 redef fun accept_objc
(v
) do
82 v
.enter_visit
(n_classe
)
86 redef class Ninterface_block_instance
87 redef fun accept_objc
(v
) do
88 v
.enter_visit
(n_instance_declaration
)
92 redef class Ninstance_declaration_signature
93 redef fun accept_objc
(v
) do
94 v
.enter_visit
(n_signature_block
)
98 redef class Ninstance_declaration_property
99 redef fun accept_objc
(v
) do
100 v
.enter_visit
(n_property_declaration
)
104 redef class Nproperty_declaration_property
105 redef fun accept_objc
(v
) do
106 v
.enter_visit
(n_property
)
110 redef class Nsignature_block_signature
111 redef fun accept_objc
(v
) do
112 if n_signature
.children
.to_s
.has
("signature_named") or n_signature
.children
.to_s
.has
("signature_single") then
113 v
.method_objc
= new ObjcMethod
115 v
.enter_visit
(n_scope
)
117 var signature_return_type
= n_signature_return_type
118 if signature_return_type
!= null then v
.enter_visit
(signature_return_type
)
120 v
.enter_visit
(n_signature
)
122 v
.class_objc
.methods
.add
(v
.method_objc
)
127 redef class Nscope_instance
128 redef fun accept_objc
(v
) do
129 v
.method_objc
.scope
= '-'
133 redef class Nscope_class
134 redef fun accept_objc
(v
) do
135 v
.method_objc
.scope
= '+'
139 redef class Nsignature_return_type_return
140 redef fun accept_objc
(v
) do
141 v
.enter_visit
(n_type
)
145 redef class Nsignature_named
146 redef fun accept_objc
(v
) do
149 v
.enter_visit
(n_left
)
150 v
.is_parameter_name
= true
151 v
.enter_visit
(n_right
)
152 v
.is_parameter_name
= false
153 v
.enter_visit
(n_signature_type
)
155 v
.method_objc
.params
.add
(v
.param
)
159 redef class Nsignature_single
160 redef fun accept_objc
(v
) do
162 v
.param
.is_single
= true
163 v
.enter_visit
(n_term
)
164 v
.method_objc
.params
.add
(v
.param
)
168 redef class Nsignature_type_anonymous
169 redef fun accept_objc
(v
) do
170 v
.enter_visit
(n_type
)
171 v
.method_objc
.is_commented
= true
175 redef class Nsignature_type_table
176 redef fun accept_objc
(v
) do
177 v
.enter_visit
(n_type
)
178 v
.param
.is_table
= true
182 redef class Nsignature_type_pointer
183 redef fun accept_objc
(v
) do
184 v
.enter_visit
(n_type
)
185 v
.param
.is_pointer
= true
189 redef class Nsignature_type_unsigned
190 redef fun accept_objc
(v
) do
191 v
.method_objc
.is_commented
= true
192 v
.param
.is_pointer
= true
196 redef class Nsignature_type_protocol
197 redef fun accept_objc
(v
) do
198 v
.enter_visit
(n_type
)
199 v
.method_objc
.is_commented
= true
203 redef class Nsignature_type_normal
204 redef fun accept_objc
(v
) do
205 v
.enter_visit
(n_type
)
209 redef class Nterm_private
210 redef fun accept_objc
(v
) do
211 if v
.is_parameter_name
then
212 v
.param
.variable_name
= n_private
.text
213 else if v
.is_variable
then
214 v
.attribute_objc
.name
= n_private
.text
216 v
.param
.name
= n_private
.text
221 redef class Nterm_class
222 redef fun accept_objc
(v
) do
223 if v
.is_parameter_name
then
224 v
.param
.variable_name
= n_class
.text
225 else if v
.is_variable
then
226 v
.attribute_objc
.name
= n_class
.text
228 v
.param
.name
= n_class
.text
233 redef class Nterm_var
234 redef fun accept_objc
(v
) do
235 if v
.is_parameter_name
then
236 v
.param
.variable_name
= n_id
.text
237 else if v
.is_variable
then
238 v
.attribute_objc
.name
= n_id
.text
240 v
.param
.name
= n_id
.text
245 redef class Nproperty_property
246 redef fun accept_objc
(v
) do
247 var protocol
= n_protocols
248 if protocol
== null then
250 v
.attribute_objc
= new ObjcAttribute
251 v
.enter_visit
(n_left
)
252 v
.enter_visit
(n_type
)
253 v
.class_objc
.attributes
.add
(v
.attribute_objc
)
254 v
.is_variable
= false
259 redef class Ntype_type
260 redef fun accept_objc
(v
) do
261 v
.enter_visit
(n_data_type
)
265 redef class Ndata_type_more
266 redef fun accept_objc
(v
) do
267 v
.enter_visit
(n_more_type
)
271 redef class Ndata_type_otype
272 redef fun accept_objc
(v
) do
273 if v
.is_variable
then
274 v
.attribute_objc
.return_type
= n_class
.text
275 else if v
.is_method
then
276 v
.method_objc
.return_type
= n_class
.text
278 v
.param
.return_type
= n_class
.text
283 redef class Nmore_type_stype
284 redef fun accept_objc
(v
) do
285 v
.enter_visit
(n_specific_type
)
289 redef class Nmore_type_ptype
290 redef fun accept_objc
(v
) do
291 v
.enter_visit
(n_primitive_type
)
295 redef class Nspecific_type_i
296 redef fun accept_objc
(v
) do
297 if v
.is_variable
then
298 v
.attribute_objc
.return_type
= "id"
299 else if v
.is_method
then
300 v
.method_objc
.return_type
= "id"
302 v
.param
.return_type
= "id"
307 redef class Nspecific_type_b
308 redef fun accept_objc
(v
) do
309 if v
.is_variable
then
310 v
.attribute_objc
.return_type
= "Bool"
311 else if v
.is_method
then
312 v
.method_objc
.return_type
= "Bool"
314 v
.param
.return_type
= "Bool"
319 redef class Nspecific_type_val
320 redef fun accept_objc
(v
) do
321 if v
.is_variable
then
322 v
.attribute_objc
.return_type
= "va_list"
323 else if v
.is_method
then
324 v
.method_objc
.return_type
= "va_list"
326 v
.param
.return_type
= "va_list"
331 redef class Nspecific_type_v
332 redef fun accept_objc
(v
) do
333 if v
.is_variable
then
334 v
.attribute_objc
.return_type
= "void"
335 else if v
.is_method
then
336 v
.method_objc
.return_type
= "void"
338 v
.param
.return_type
= "void"
343 redef class Nprimitive_type_ui8
344 redef fun accept_objc
(v
) do
345 if v
.is_variable
then
346 v
.attribute_objc
.return_type
= "uint8_t"
347 else if v
.is_method
then
348 v
.method_objc
.return_type
= "uint8_t"
350 v
.param
.return_type
= "uint8_t"
355 redef class Nprimitive_type_ui16
356 redef fun accept_objc
(v
) do
357 if v
.is_variable
then
358 v
.attribute_objc
.return_type
= "uint16_t"
359 else if v
.is_method
then
360 v
.method_objc
.return_type
= "uint16_t"
362 v
.param
.return_type
= "uint16_t"
367 redef class Nprimitive_type_ui32
368 redef fun accept_objc
(v
) do
369 if v
.is_variable
then
370 v
.attribute_objc
.return_type
= "uint32_t"
371 else if v
.is_method
then
372 v
.method_objc
.return_type
= "uint32_t"
374 v
.param
.return_type
= "uint32_t"
379 redef class Nprimitive_type_ui64
380 redef fun accept_objc
(v
) do
381 if v
.is_variable
then
382 v
.attribute_objc
.return_type
= "uint64_t"
383 else if v
.is_method
then
384 v
.method_objc
.return_type
= "uint64_t"
386 v
.param
.return_type
= "uint64_t"
391 redef class Nprimitive_type_i8
392 redef fun accept_objc
(v
) do
393 if v
.is_variable
then
394 v
.attribute_objc
.return_type
= "int8_t"
395 else if v
.is_method
then
396 v
.method_objc
.return_type
= "int8_t"
398 v
.param
.return_type
= "int8_t"
403 redef class Nprimitive_type_i16
404 redef fun accept_objc
(v
) do
405 if v
.is_variable
then
406 v
.attribute_objc
.return_type
= "int16_t"
407 else if v
.is_method
then
408 v
.method_objc
.return_type
= "int16_t"
410 v
.param
.return_type
= "int16_t"
415 redef class Nprimitive_type_i32
416 redef fun accept_objc
(v
) do
417 if v
.is_variable
then
418 v
.attribute_objc
.return_type
= "int32_t"
419 else if v
.is_method
then
420 v
.method_objc
.return_type
= "int32_t"
422 v
.param
.return_type
= "int32_t"
427 redef class Nprimitive_type_i64
428 redef fun accept_objc
(v
) do
429 if v
.is_variable
then
430 v
.attribute_objc
.return_type
= "int64_t"
431 else if v
.is_method
then
432 v
.method_objc
.return_type
= "int64_t"
434 v
.param
.return_type
= "int64_t"
439 redef class Nprimitive_type_uc
440 redef fun accept_objc
(v
) do
441 if v
.is_variable
then
442 v
.attribute_objc
.return_type
= "unichar"
443 else if v
.is_method
then
444 v
.method_objc
.return_type
= "unichar"
446 v
.param
.return_type
= "unichar"
451 redef class Nprimitive_type_c
452 redef fun accept_objc
(v
) do
453 if v
.is_variable
then
454 v
.attribute_objc
.return_type
= "char"
455 else if v
.is_method
then
456 v
.method_objc
.return_type
= "char"
458 v
.param
.return_type
= "char"
463 redef class Nprimitive_type_s
464 redef fun accept_objc
(v
) do
465 if v
.is_variable
then
466 v
.attribute_objc
.return_type
= "short"
467 else if v
.is_method
then
468 v
.method_objc
.return_type
= "short"
470 v
.param
.return_type
= "short"
475 redef class Nprimitive_type_si
476 redef fun accept_objc
(v
) do
477 if v
.is_variable
then
478 v
.attribute_objc
.return_type
= "short int"
479 else if v
.is_method
then
480 v
.method_objc
.return_type
= "short int"
482 v
.param
.return_type
= "short int"
487 redef class Nprimitive_type_i
488 redef fun accept_objc
(v
) do
489 if v
.is_variable
then
490 v
.attribute_objc
.return_type
= "int"
491 else if v
.is_method
then
492 v
.method_objc
.return_type
= "int"
494 v
.param
.return_type
= "int"
499 redef class Nprimitive_type_l
500 redef fun accept_objc
(v
) do
501 if v
.is_variable
then
502 v
.attribute_objc
.return_type
= "long"
503 else if v
.is_method
then
504 v
.method_objc
.return_type
= "long"
506 v
.param
.return_type
= "long"
511 redef class Nprimitive_type_li
512 redef fun accept_objc
(v
) do
513 if v
.is_variable
then
514 v
.attribute_objc
.return_type
= "long int"
515 else if v
.is_method
then
516 v
.method_objc
.return_type
= "long int"
518 v
.param
.return_type
= "long int"
523 redef class Nprimitive_type_ll
524 redef fun accept_objc
(v
) do
525 if v
.is_variable
then
526 v
.attribute_objc
.return_type
= "long long"
527 else if v
.is_method
then
528 v
.method_objc
.return_type
= "long long"
530 v
.param
.return_type
= "long long"
535 redef class Nprimitive_type_lli
536 redef fun accept_objc
(v
) do
537 if v
.is_variable
then
538 v
.attribute_objc
.return_type
= "long long int"
539 else if v
.is_method
then
540 v
.method_objc
.return_type
= "long long int"
542 v
.param
.return_type
= "long long int"
547 redef class Nprimitive_type_f
548 redef fun accept_objc
(v
) do
549 if v
.is_variable
then
550 v
.attribute_objc
.return_type
= "float"
551 else if v
.is_method
then
552 v
.method_objc
.return_type
= "float"
554 v
.param
.return_type
= "float"
559 redef class Nprimitive_type_d
560 redef fun accept_objc
(v
) do
561 if v
.is_variable
then
562 v
.attribute_objc
.return_type
= "double"
563 else if v
.is_method
then
564 v
.method_objc
.return_type
= "double"
566 v
.param
.return_type
= "double"
571 redef class Nprimitive_type_ld
572 redef fun accept_objc
(v
) do
573 if v
.is_variable
then
574 v
.attribute_objc
.return_type
= "long double"
575 else if v
.is_method
then
576 v
.method_objc
.return_type
= "long double"
578 v
.param
.return_type
= "long double"