summary refs log tree commit diff stats
path: root/lib/genode_cpp
ModeNameSize
-rw-r--r--signals.h860log stats plain blame
-rw-r--r--syslocks.h1175log stats plain blame
-rw-r--r--threads.h1638log stats plain blame
itle='author Zahary Karadjov <zahary@gmail.com> 2012-03-29 16:03:51 +0300 committer Zahary Karadjov <zahary@gmail.com> 2012-03-31 18:50:48 +0300 typedesc and expr params' href='/ahoang/Nim/commit/compiler/ccgtypes.nim?h=devel&id=22dc76a361c70af93403dfbf2610c8d49111637c'>22dc76a36 ^
e25474154 ^

72af7e682 ^
b654aa399 ^
38710b614 ^
ecc009093 ^

f25c638dc ^
38710b614 ^
f25c638dc ^



ecc009093 ^


9605435f2 ^


ecc009093 ^
72af7e682 ^






b654aa399 ^
72af7e682 ^
c0b8a7931 ^

3b43cff0f ^


72af7e682 ^
3b43cff0f ^
860cbd310 ^
3b43cff0f ^

e25474154 ^
74c6c8c90 ^
b654aa399 ^












































f25c638dc ^
72af7e682 ^


e25474154 ^

39049e151 ^

e817d5436 ^
8319e2411 ^
860cbd310 ^
74c6c8c90 ^
e25474154 ^
8319e2411 ^

860cbd310 ^
b234b082b ^



e25474154 ^
92b8fac94 ^
178a85cd2 ^
990dc2d71 ^







178a85cd2 ^
26eae7d00 ^
e25474154 ^
b5d8e8bfa ^
f265c3e86 ^

990dc2d71 ^
51de278bd ^
f265c3e86 ^
98e5beb93 ^
f5c3eb6a2 ^
e25474154 ^
178a85cd2 ^

e25474154 ^
178a85cd2 ^
e25474154 ^





f265c3e86 ^
5b0d8246f ^
4196757de ^
990dc2d71 ^
49fa421ba ^
09ac351a6 ^



e25474154 ^
f265c3e86 ^

632aece19 ^
f265c3e86 ^

e2d38a57e ^
e25474154 ^
f47165af1 ^


92b8fac94 ^
178a85cd2 ^

af1e94187 ^


e75e42191 ^
178a85cd2 ^
e75e42191 ^

178a85cd2 ^
e75e42191 ^

860cbd310 ^
178a85cd2 ^
e25474154 ^

85d83fd8c ^



e75e42191 ^
e25474154 ^



f265c3e86 ^
e75e42191 ^
e25474154 ^
e75e42191 ^
5b0d8246f ^
e25474154 ^
85d83fd8c ^

e75e42191 ^
85d83fd8c ^

e25474154 ^
85d83fd8c ^
178a85cd2 ^


f265c3e86 ^
178a85cd2 ^
e25474154 ^
e25474154 ^
860cbd310 ^
e25474154 ^
22318ce8a ^
e25474154 ^
860cbd310 ^
e25474154 ^
4b0ba5e3f ^


e25474154 ^
178a85cd2 ^
5b0d8246f ^
2f066395b ^
e4c432387 ^

b731e6ef1 ^
dce8949b9 ^
178a85cd2 ^
e25474154 ^
178a85cd2 ^
e25474154 ^
178a85cd2 ^
e25474154 ^

178a85cd2 ^
03ba0f3e2 ^
e25474154 ^
178a85cd2 ^

e817d5436 ^
e25474154 ^
af1e94187 ^
e25474154 ^


3b43cff0f ^
178a85cd2 ^
860cbd310 ^
178a85cd2 ^
39049e151 ^
178a85cd2 ^
39049e151 ^
178a85cd2 ^
e2d38a57e ^


3847348fd ^
b731e6ef1 ^
178a85cd2 ^
3b43cff0f ^
178a85cd2 ^
ff02ce2d5 ^
3b43cff0f ^




178a85cd2 ^
3b43cff0f ^
b5a8e34ae ^
f47165af1 ^




e25474154 ^
2808b7f9a ^
178a85cd2 ^
2808b7f9a ^

860cbd310 ^
39049e151 ^
178a85cd2 ^
e25474154 ^
860cbd310 ^
5506e8491 ^
39049e151 ^

5506e8491 ^
178a85cd2 ^
e65c296bc ^
5506e8491 ^
178a85cd2 ^
860cbd310 ^

178a85cd2 ^
860cbd310 ^
178a85cd2 ^
860cbd310 ^
178a85cd2 ^
860cbd310 ^

178a85cd2 ^
860cbd310 ^

39049e151 ^
5506e8491 ^
860cbd310 ^
92b8fac94 ^
2808b7f9a ^
39049e151 ^
2808b7f9a ^


860cbd310 ^
2808b7f9a ^




860cbd310 ^

178a85cd2 ^
860cbd310 ^

2808b7f9a ^



860cbd310 ^

2808b7f9a ^



39049e151 ^
d82d430cb ^

2808b7f9a ^
af1e94187 ^
2808b7f9a ^
178a85cd2 ^
2808b7f9a ^
178a85cd2 ^
2808b7f9a ^


39049e151 ^
3b43cff0f ^
2808b7f9a ^
178a85cd2 ^
39049e151 ^

2808b7f9a ^

d82d430cb ^

2808b7f9a ^
39049e151 ^


2808b7f9a ^







39049e151 ^
2808b7f9a ^

af1e94187 ^
2808b7f9a ^
39049e151 ^
af1e94187 ^
39049e151 ^

2808b7f9a ^
39049e151 ^

178a85cd2 ^
39049e151 ^

2808b7f9a ^
39049e151 ^




178a85cd2 ^
39049e151 ^
e25474154 ^
178a85cd2 ^
e25474154 ^
540e244cf ^
ecc009093 ^
92b8fac94 ^
178a85cd2 ^

39049e151 ^

e25474154 ^

178a85cd2 ^

39049e151 ^
178a85cd2 ^
22318ce8a ^
39049e151 ^
860cbd310 ^


39049e151 ^
178a85cd2 ^
e25474154 ^
178a85cd2 ^
860cbd310 ^
178a85cd2 ^
860cbd310 ^


178a85cd2 ^
39049e151 ^


9dfd8fea1 ^
39049e151 ^
e25474154 ^
9dfd8fea1 ^
39049e151 ^
19eeb3556 ^
860cbd310 ^
b47d9b7b9 ^
632aece19 ^
860cbd310 ^


e25474154 ^
e75e42191 ^





39049e151 ^
e75e42191 ^
178a85cd2 ^

39049e151 ^
5e9ce88da ^

e75e42191 ^


39049e151 ^
e25474154 ^
178a85cd2 ^
39049e151 ^
e25474154 ^

39049e151 ^

e25474154 ^

1e45bb79a ^
39049e151 ^

1e45bb79a ^

178a85cd2 ^
1e45bb79a ^

178a85cd2 ^
1e45bb79a ^
178a85cd2 ^

1e45bb79a ^
178a85cd2 ^
1e45bb79a ^
e25474154 ^
e65c296bc ^
178a85cd2 ^
3a13706d7 ^
e25474154 ^
178a85cd2 ^

3a13706d7 ^
e25474154 ^
178a85cd2 ^
39049e151 ^
1e45bb79a ^
3847348fd ^
178a85cd2 ^
39049e151 ^
178a85cd2 ^
39049e151 ^

e25474154 ^
39049e151 ^



178a85cd2 ^
39049e151 ^




e25474154 ^
1ebf1aaa8 ^


























860cbd310 ^




e25474154 ^
860cbd310 ^
e25474154 ^
860cbd310 ^


178a85cd2 ^
e75e42191 ^
860cbd310 ^

e25474154 ^


b731e6ef1 ^
74c6c8c90 ^
860cbd310 ^
74c6c8c90 ^
860cbd310 ^
22318ce8a ^
178a85cd2 ^
990dc2d71 ^

22318ce8a ^

e84834db7 ^
22318ce8a ^


39049e151 ^
22318ce8a ^

860cbd310 ^
39049e151 ^
860cbd310 ^

22318ce8a ^
e25474154 ^
860cbd310 ^
39049e151 ^
860cbd310 ^

22318ce8a ^
e25474154 ^
39049e151 ^
860cbd310 ^
22318ce8a ^
4d56b7da5 ^
860cbd310 ^


69966a711 ^
b234b082b ^
69966a711 ^

860cbd310 ^
69966a711 ^











72af7e682 ^









22318ce8a ^
860cbd310 ^

39049e151 ^
d82d430cb ^
178a85cd2 ^
e25474154 ^
39049e151 ^

632aece19 ^
39049e151 ^
178a85cd2 ^
632aece19 ^
e25474154 ^
178a85cd2 ^
e25474154 ^

860cbd310 ^
22318ce8a ^
860cbd310 ^
178a85cd2 ^
39049e151 ^
5506e8491 ^
860cbd310 ^


178a85cd2 ^

8319e2411 ^




e65c296bc ^
178a85cd2 ^
ff02ce2d5 ^
178a85cd2 ^
39049e151 ^

860cbd310 ^
22318ce8a ^

860cbd310 ^

22318ce8a ^

39049e151 ^

22318ce8a ^
860cbd310 ^
22318ce8a ^

860cbd310 ^
1ebf1aaa8 ^









860cbd310 ^
b47d9b7b9 ^
1ebf1aaa8 ^




ecc009093 ^
1ebf1aaa8 ^



860cbd310 ^
174205bca ^
860cbd310 ^
1ebf1aaa8 ^
22318ce8a ^



860cbd310 ^






22318ce8a ^
860cbd310 ^








178a85cd2 ^
860cbd310 ^

39049e151 ^
22318ce8a ^
860cbd310 ^

22318ce8a ^

39049e151 ^
22318ce8a ^
b234b082b ^
860cbd310 ^
2024e1335 ^




39049e151 ^
f5c3eb6a2 ^
e25474154 ^
b9afdffb3 ^
92b8fac94 ^
e25474154 ^
d1c84328a ^

e25474154 ^
39049e151 ^
ade67f1ab ^
e25474154 ^

161f6f722 ^



39049e151 ^
161f6f722 ^

4b0ba5e3f ^
39049e151 ^
161f6f722 ^


39049e151 ^

161f6f722 ^
39049e151 ^
178a85cd2 ^
161f6f722 ^


178a85cd2 ^
e25474154 ^
178a85cd2 ^
e25474154 ^

139562cc6 ^


39049e151 ^
178a85cd2 ^
39049e151 ^
c3e790b1e ^
e25474154 ^
74c6c8c90 ^
3ac6bd8ae ^
39049e151 ^
538b06a12 ^
39049e151 ^
c3e790b1e ^
39049e151 ^
ade67f1ab ^
3b43cff0f ^
e25474154 ^
abe9dfafe ^

139562cc6 ^
39049e151 ^

139562cc6 ^

39049e151 ^
e25474154 ^
48dd9679b ^

39049e151 ^


e25474154 ^

39049e151 ^
e25474154 ^
32aa46a88 ^
b20663ce1 ^
bd2d146c7 ^
e25474154 ^

178a85cd2 ^
39049e151 ^

860cbd310 ^
39049e151 ^
178a85cd2 ^
39049e151 ^
e25474154 ^


178a85cd2 ^
e25474154 ^
178a85cd2 ^
39049e151 ^
32aa46a88 ^
39049e151 ^

e25474154 ^
39049e151 ^

3b43cff0f ^
9c4440393 ^


178a85cd2 ^
39049e151 ^
e75e42191 ^
e25474154 ^
39049e151 ^
4577751ba ^



178a85cd2 ^
92b8fac94 ^
860cbd310 ^
5b789f2da ^
39049e151 ^
5b789f2da ^

39049e151 ^
5b789f2da ^
860cbd310 ^
e25474154 ^
178a85cd2 ^
5b789f2da ^
178a85cd2 ^
860cbd310 ^
178a85cd2 ^
4b0ba5e3f ^
39049e151 ^
178a85cd2 ^
5b789f2da ^
39049e151 ^
860cbd310 ^
39049e151 ^

5b789f2da ^
39049e151 ^
178a85cd2 ^
e25474154 ^
5b789f2da ^



39049e151 ^
e25474154 ^
ff02ce2d5 ^
860cbd310 ^
178a85cd2 ^

39049e151 ^

178a85cd2 ^
5b789f2da ^

860cbd310 ^
e25474154 ^
178a85cd2 ^

e25474154 ^
178a85cd2 ^

5b789f2da ^

178a85cd2 ^
39049e151 ^
e25474154 ^
178a85cd2 ^
39049e151 ^

178a85cd2 ^
39049e151 ^

e25474154 ^
178a85cd2 ^
5b789f2da ^
32dd1e5d3 ^


860cbd310 ^
32dd1e5d3 ^
e25474154 ^
178a85cd2 ^
39049e151 ^
e75e42191 ^
39049e151 ^
5b789f2da ^
e75e42191 ^
860cbd310 ^
39049e151 ^
15909c7be ^

3a13706d7 ^
d3c8f1ab2 ^
15909c7be ^
e25474154 ^
860cbd310 ^
39049e151 ^
18bec94e2 ^

178a85cd2 ^
4b0ba5e3f ^
39049e151 ^
178a85cd2 ^
18bec94e2 ^

39049e151 ^

178a85cd2 ^
632aece19 ^
178a85cd2 ^
860cbd310 ^
39049e151 ^

178a85cd2 ^
39049e151 ^


e25474154 ^
39049e151 ^
e25474154 ^



e75e42191 ^
4b0ba5e3f ^
6ff8752be ^
39049e151 ^


6ff8752be ^

178a85cd2 ^
e25474154 ^
6ff8752be ^

1a8c6fb49 ^

39049e151 ^
1a8c6fb49 ^
39049e151 ^

6ff8752be ^
39049e151 ^
6ff8752be ^
4b0ba5e3f ^

39049e151 ^



e25474154 ^
178a85cd2 ^
39049e151 ^


178a85cd2 ^
39049e151 ^
6ff8752be ^

39049e151 ^
e25474154 ^
39049e151 ^
e25474154 ^
e75e42191 ^
e25474154 ^
39049e151 ^

e25474154 ^
39049e151 ^
e75e42191 ^
e25474154 ^
632aece19 ^


121d4e0fc ^
632aece19 ^
121d4e0fc ^

632aece19 ^
03ba0f3e2 ^


03ba0f3e2 ^


39049e151 ^
9673e4f2d ^
39049e151 ^
9673e4f2d ^

39049e151 ^
9673e4f2d ^
860cbd310 ^
3b43cff0f ^
860cbd310 ^


39049e151 ^
178a85cd2 ^
860cbd310 ^


9604df843 ^
4841b6390 ^

860cbd310 ^
9604df843 ^
ff02ce2d5 ^

39049e151 ^


e25474154 ^
b47d9b7b9 ^
e2d38a57e ^
39049e151 ^
f47165af1 ^


632aece19 ^

39049e151 ^
632aece19 ^
860cbd310 ^

03ba0f3e2 ^
e75e42191 ^
ab6f79340 ^
b234b082b ^
39049e151 ^
e75e42191 ^
4841b6390 ^


e75e42191 ^

4841b6390 ^
7a249eb8c ^


860cbd310 ^
92b8fac94 ^
9673e4f2d ^


178a85cd2 ^
39049e151 ^
03ba0f3e2 ^
178a85cd2 ^
2df9b442c ^
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094

 
                            
                                         




                                                   

                        

                                                                          
                
 
                                 

                                                            
           
                                     



                                     


                                        


                                          
 






                                                    
 
                                         

                                                                          


                                                                          
                               
       
                            

                                            
                  
                   












































                                                                         
         


                                                 

                    

                                                        
                      
 
                                                              
                                                                     
                          

                        
                                     



                                                    
                      
                                                              
 







                                         
                                      
                                
               
                                    

                            
                                    
                                                                     
                                         
                                                                         
                
                                  

                         
                      
         





                                    
                                           
                         
                                                   
                  
                                                                            



                                                            
                        

                                  
                                                                         

                                  
                     
                                                                


                                                  
                                

                                            


                                                                  
 
                                     

                                                    
                                        

                                                      
                                                                        
                                               

                                           



                                                                 
                                                



                                                                     
                                  
       
                         
               
                                                            
                                

                                              
                                                                       

                                                               
                        
 


                                                                     
                                                                  
                                                           
                                                                    
 
                                                       
                                               
                                                                             
                                           
                                
 


                                     
 
                                      
                                         
                           

                                         
              
              
                                                                         
                                                
                                                       
                                                                      
         

                                                                                
             
                                                                            
                      

                              
                                                    
                  
                                                                            


                                     
                                                                     
                                                                        
                        
       
                          
 
                                                      
       


                                                          
                                          
               
               
                                               
              
                                     




                                                              
                     
                                                                    
                                                                               




                                                               
                    
 
                                       

                       
                                                             
                                      
       
                                      
                                                             
 

                                                             
 
                                                 
                                        
                                      
 

                                                                 
                          
                                  
                          
                                       
                                   

                                     
                               

                                                                                          
                                                           
                                       
                                           
                                                          
 
                                                                     


                                                                              
                                     




                                                          

                                                
                

                                                    



                                                

                                                          



                      
                                                                   

                                                              
              
                                                        
                     
       
                                                 
                                        


                                                                          
                                        
                                                                 
                                  
                               

                                                       

                                       

                                                       
         


                                                      







                                                         
                                                         

                       
                                                         
                       
                                       
                                           

                                                 
         

                                                
                                                    

                                       
                          




                                        
 
                                                            
                             
                                                         
                        
       
                                          
                                                                   

                                             

                                                         

              

                                        
                                                                               
               
                                                                           
                                                                             


                                                                
                             
                                        
                         
                            
                                  
                           


                                                                          
                      


                                               
             
                                                                      
                                                                   
                        
                                                           
           
                     
                                       
                             


                                                                
                                                          





                                                                              
                                               
                                                                  

                                                                     
                                                                                 

                                                                                                         


                                                      
                                                                                
                                                     
 
                                                                       

                                                        

                                                      

                       
 

                                                              

             
                                                 

                                          
                          
 

                                                                              
                                    
           
                                                                       
                       
                        
                                          
                                                                                  
                     

                                         
                                                                                  
                     
       
                                
 
                                           
                                  
                                     
       

                         
 



                                                     
                                        




                                                          
 


























                                                                               




                                                                            
                                
                                                 
                                      


                                                                   
                          
                                 

                                                                           


                                                                             
             
                         
                                                                        
                                                  
                                                    
                                        
                                                                    

                                                                   

                                      
                   


                                                             
                                                    

                                                                   
                                                     
                            

                                 
                  
                                                                 
                                                   
                                

                               
         
                                             
                                                  
                               
                            
                                                       


                                           
                     
                                           

                                                               
                                 











                                                                   









                                                                                    
            

                                         
                           
                                                         
                             
                                                                      

                                                                         
           
                                                  
                                              
                                    
                                     
                

                                                                          
                                               
                     
                                           
                               
                                                             
                                       


                                                 

                                                            




                                                 
                                                    
                                           
                                                                  
           

                                    
             

                                                              

                                         

                                                   

                                                 
                       
                                                              

                                                                             
                                          









                                                                
                                                                           
                                                              




                                                             
 



                                                  
                                    
                                         
                                                               
                        



                                                






                                                           
                       








                                                             
                                 

                                                                                      
                                                               
                                        

                                                              

                                                                            
                                                           
           
                                                                   
                             




                                                                                   
                                        
                                                      
                                                 
       
                                                    
                

                   
 
                                                
                          

                                        



                                 
                                                                         

                          
                         
                         


                                                                              

                                                                       
         
                                                
                                            


                                   
                                         
           
                             

                                          


                                                           
                                                 
     
                         
                               
                                           
                                  
                               
                                
         
                                
                                    
                        
                          
                                                                   
                                                   

                                                                              
                          

                                                                       

                 
                                                          
 

                                                                               


                                                          

                  
                                                                             
                      
                           
                                
                                   

                               
 

                                                        
                                       
                         
                                                                         
                                             


                                                             
                                               
                                                               
                
                                                                    
                              

                                               
 

                                                                   
                                             


                                                      
       
                    
                                                  
 
                                                                        



                                                                       
                        
                                                             
                                                                            
 
                                                                        

                                                 
                                                                  
 
                                                                              
             
               
                      
              
                                                        
               
                              
                                                                           
                               
                                
                                                                        
                                                          

                                                                              
         
                                                                             
               
                                   



                                                   
                                              
                                                              
                                                   
                                                                       

                                                     

                                                               
                                      

                                          
                                                         
                 

                          
                                                                     

                                            

                                                       
                         
                                                                              
                    
               

                                                           
                

                                                  
                                                               
           
                     


                                                                
                                                             
                                                                             
                                                
 
                                                                  
                                                                 
                                                             
                         
                                
                                                 
                                                          

                     
                             
                             
                 
 
                                                                 
                                                  

                           
                
                            
                                                                              
                                    

                              

                                                                      
                                                  
                            
                                     
                                                                        

                                                                            
       


                                                           
 
                                                      



                                                                          
                                   
                               
                             


                                                       

                                
                                  
                                       

                                 

                                                                         
                                               
         

                                                   
                                                          
                                                                               
                     

                                



                                                                      
                                                            
                                                                                


                                                                              
                                                                       
                                                     

                             
                                                         
 
                                                     
                            
                                   
                         

                                                                             
 
                                                       
                                                                    
 


                                                                  
                                             
                               

                                      
 


                                                               


               
                                                         
               
                                                                              

                       
                                              
                  
                                                   
 


                                             
                                        
 


                                 
                                                       

                                                            
                                             
                                            

                                


                                                        
             
                                      
                                                                            
                                                


                                                       

                               
                                                  
         

                                      
                       
                                   
                                     
                                                               
                                                                        
                                                    


                                                       

                                                    
                                                


                                                                         
                                        
                                                     


                                          
                                                 
                                        
 
                                           
         
#
#
#           The Nim Compiler
#        (c) Copyright 2016 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# included from cgen.nim

# ------------------------- Name Mangling --------------------------------

import sighashes

proc isKeyword(w: PIdent): bool =
  # Nim and C++ share some keywords
  # it's more efficient to test the whole Nim keywords range
  case w.id
  of ccgKeywordsLow..ccgKeywordsHigh,
     nimKeywordsLow..nimKeywordsHigh,
     ord(wInline): return true
  else: return false

proc mangleField(name: PIdent): string =
  result = mangle(name.s)
  if isKeyword(name):
    result[0] = result[0].toUpperAscii
    # Mangling makes everything lowercase,
    # but some identifiers are C keywords

when false:
  proc hashOwner(s: PSym): SigHash =
    var m = s
    while m.kind != skModule: m = m.owner
    let p = m.owner
    assert p.kind == skPackage
    result = gDebugInfo.register(p.name.s, m.name.s)

proc idOrSig(m: BModule; s: PSym): Rope =
  if s.kind in routineKinds and s.typ != nil and sfExported in s.flags and
     s.typ.callConv != ccInline:
    # signatures for exported routines are reliable enough to
    # produce a unique name and this means produced C++ is more stable wrt
    # Nim changes:
    result = rope($hashProc(s))
  else:
    result = "_" & rope s.id

proc mangleName(m: BModule; s: PSym): Rope =
  result = s.loc.r
  if result == nil:
    let keepOrigName = s.kind in skLocalVars - {skForVar} and
      {sfFromGeneric, sfGlobal, sfShadowed, sfGenSym} * s.flags == {} and
      not isKeyword(s.name)
    # Even with all these inefficient checks, the bootstrap
    # time is actually improved. This is probably because so many
    # rope concatenations are now eliminated.
    #
    # sfFromGeneric is needed in order to avoid multiple
    # definitions of certain variables generated in transf with
    # names such as:
    # `r`, `res`
    # I need to study where these come from.
    #
    # about sfShadowed:
    # consider the following Nim code:
    #   var x = 10
    #   block:
    #     var x = something(x)
    # The generated C code will be:
    #   NI x;
    #   x = 10;
    #   {
    #     NI x;
    #     x = something(x); // Oops, x is already shadowed here
    #   }
    # Right now, we work-around by not keeping the original name
    # of the shadowed variable, but we can do better - we can
    # create an alternative reference to it in the outer scope and
    # use that in the inner scope.
    #
    # about isCKeyword:
    # Nim variable names can be C keywords.
    # We need to avoid such names in the generated code.
    #
    # about sfGlobal:
    # This seems to be harder - a top level extern variable from
    # another modules can have the same name as a local one.
    # Maybe we should just implement sfShadowed for them too.
    #
    # about skForVar:
    # These are not properly scoped now - we need to add blocks
    # around for loops in transf
    result = s.name.s.mangle.rope
    if keepOrigName:
      result.add "0"
    else:
      add(result, m.idOrSig(s))
      #add(result, ~"_")
      #add(result, rope(hashOwner(s).BiggestInt))
    s.loc.r = result

proc typeName(typ: PType): Rope =
  result = if typ.sym != nil: typ.sym.name.s.mangle.rope
           else: ~"TY"

proc getTypeName(m: BModule; typ: PType; sig: SigHash): Rope =
  if typ.sym != nil and {sfImportc, sfExportc} * typ.sym.flags != {}:
    result = typ.sym.loc.r
  else:
    if typ.loc.r == nil:
      typ.loc.r = typ.typeName & $sig
    else:
      when defined(debugSigHashes):
        # check consistency:
        assert($typ.loc.r == $(typ.typeName & $sig))
    result = typ.loc.r
  if result == nil: internalError("getTypeName: " & $typ.kind)

proc mapSetType(typ: PType): TCTypeKind =
  case int(getSize(typ))
  of 1: result = ctInt8
  of 2: result = ctInt16
  of 4: result = ctInt32
  of 8: result = ctInt64
  else: result = ctArray

proc mapType(typ: PType): TCTypeKind =
  ## Maps a Nim type to a C type
  case typ.kind
  of tyNone, tyStmt: result = ctVoid
  of tyBool: result = ctBool
  of tyChar: result = ctChar
  of tySet: result = mapSetType(typ)
  of tyOpenArray, tyArrayConstr, tyArray, tyVarargs: result = ctArray
  of tyObject, tyTuple: result = ctStruct
  of tyGenericBody, tyGenericInst, tyGenericParam, tyDistinct, tyOrdinal,
     tyTypeDesc:
    result = mapType(lastSon(typ))
  of tyEnum:
    if firstOrd(typ) < 0:
      result = ctInt32
    else:
      case int(getSize(typ))
      of 1: result = ctUInt8
      of 2: result = ctUInt16
      of 4: result = ctInt32
      of 8: result = ctInt64
      else: internalError("mapType")
  of tyRange: result = mapType(typ.sons[0])
  of tyPtr, tyVar, tyRef:
    var base = skipTypes(typ.lastSon, typedescInst)
    case base.kind
    of tyOpenArray, tyArrayConstr, tyArray, tyVarargs: result = ctPtrToArray
    #of tySet:
    #  if mapSetType(base) == ctArray: result = ctPtrToArray
    #  else: result = ctPtr
    # XXX for some reason this breaks the pegs module
    else: result = ctPtr
  of tyPointer: result = ctPtr
  of tySequence: result = ctNimSeq
  of tyProc: result = if typ.callConv != ccClosure: ctProc else: ctStruct
  of tyString: result = ctNimStr
  of tyCString: result = ctCString
  of tyInt..tyUInt64:
    result = TCTypeKind(ord(typ.kind) - ord(tyInt) + ord(ctInt))
  of tyStatic:
    if typ.n != nil: result = mapType(lastSon typ)
    else: internalError("mapType")
  else: internalError("mapType")

proc mapReturnType(typ: PType): TCTypeKind =
  #if skipTypes(typ, typedescInst).kind == tyArray: result = ctPtr
  #else:
  result = mapType(typ)

proc isImportedType(t: PType): bool =
  result = t.sym != nil and sfImportc in t.sym.flags

proc isImportedCppType(t: PType): bool =
  result = t.sym != nil and sfInfixCall in t.sym.flags

proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope
proc needsComplexAssignment(typ: PType): bool =
  result = containsGarbageCollectedRef(typ)

proc isObjLackingTypeField(typ: PType): bool {.inline.} =
  result = (typ.kind == tyObject) and ((tfFinal in typ.flags) and
      (typ.sons[0] == nil) or isPureObject(typ))

proc isInvalidReturnType(rettype: PType): bool =
  # Arrays and sets cannot be returned by a C procedure, because C is
  # such a poor programming language.
  # We exclude records with refs too. This enhances efficiency and
  # is necessary for proper code generation of assignments.
  if rettype == nil: result = true
  else:
    case mapType(rettype)
    of ctArray:
      result = not (skipTypes(rettype, typedescInst).kind in
          {tyVar, tyRef, tyPtr})
    of ctStruct:
      let t = skipTypes(rettype, typedescInst)
      if rettype.isImportedCppType or t.isImportedCppType: return false
      result = needsComplexAssignment(t) or
          (t.kind == tyObject and not isObjLackingTypeField(t))
    else: result = false

const
  CallingConvToStr: array[TCallingConvention, string] = ["N_NIMCALL",
    "N_STDCALL", "N_CDECL", "N_SAFECALL",
    "N_SYSCALL", # this is probably not correct for all platforms,
                 # but one can #define it to what one wants
    "N_INLINE", "N_NOINLINE", "N_FASTCALL", "N_CLOSURE", "N_NOCONV"]

proc cacheGetType(tab: TypeCache; sig: SigHash): Rope =
  # returns nil if we need to declare this type
  # since types are now unique via the ``getUniqueType`` mechanism, this slow
  # linear search is not necessary anymore:
  result = tab.getOrDefault(sig)

proc getTempName(m: BModule): Rope =
  result = m.tmpBase & rope(m.labels)
  inc m.labels

proc ccgIntroducedPtr(s: PSym): bool =
  var pt = skipTypes(s.typ, typedescInst)
  assert skResult != s.kind
  if tfByRef in pt.flags: return true
  elif tfByCopy in pt.flags: return false
  case pt.kind
  of tyObject:
    if (optByRef in s.options) or (getSize(pt) > platform.floatSize * 2):
      result = true           # requested anyway
    elif (tfFinal in pt.flags) and (pt.sons[0] == nil):
      result = false          # no need, because no subtyping possible
    else:
      result = true           # ordinary objects are always passed by reference,
                              # otherwise casting doesn't work
  of tyTuple:
    result = (getSize(pt) > platform.floatSize*2) or (optByRef in s.options)
  else: result = false

proc fillResult(param: PSym) =
  fillLoc(param.loc, locParam, param.typ, ~"Result",
          OnStack)
  if mapReturnType(param.typ) != ctArray and isInvalidReturnType(param.typ):
    incl(param.loc.flags, lfIndirect)
    param.loc.s = OnUnknown

proc typeNameOrLiteral(m: BModule; t: PType, literal: string): Rope =
  if t.sym != nil and sfImportc in t.sym.flags and t.sym.magic == mNone:
    result = t.sym.loc.r
  else:
    result = rope(literal)

proc getSimpleTypeDesc(m: BModule, typ: PType): Rope =
  const
    NumericalTypeToStr: array[tyInt..tyUInt64, string] = [
      "NI", "NI8", "NI16", "NI32", "NI64",
      "NF", "NF32", "NF64", "NF128",
      "NU", "NU8", "NU16", "NU32", "NU64"]
  case typ.kind
  of tyPointer:
    result = typeNameOrLiteral(m, typ, "void*")
  of tyString:
    discard cgsym(m, "NimStringDesc")
    result = typeNameOrLiteral(m, typ, "NimStringDesc*")
  of tyCString: result = typeNameOrLiteral(m, typ, "NCSTRING")
  of tyBool: result = typeNameOrLiteral(m, typ, "NIM_BOOL")
  of tyChar: result = typeNameOrLiteral(m, typ, "NIM_CHAR")
  of tyNil: result = typeNameOrLiteral(m, typ, "0")
  of tyInt..tyUInt64:
    result = typeNameOrLiteral(m, typ, NumericalTypeToStr[typ.kind])
  of tyDistinct, tyRange, tyOrdinal: result = getSimpleTypeDesc(m, typ.sons[0])
  of tyStatic:
    if typ.n != nil: result = getSimpleTypeDesc(m, lastSon typ)
    else: internalError("tyStatic for getSimpleTypeDesc")
  of tyGenericInst:
    result = getSimpleTypeDesc(m, lastSon typ)
  else: result = nil

proc pushType(m: BModule, typ: PType) =
  add(m.typeStack, typ)

proc getTypePre(m: BModule, typ: PType; sig: SigHash): Rope =
  if typ == nil: result = rope("void")
  else:
    result = getSimpleTypeDesc(m, typ)
    if result == nil: result = cacheGetType(m.typeCache, sig)

proc structOrUnion(t: PType): Rope =
  (if tfUnion in t.flags: rope("union") else: rope("struct"))

proc getForwardStructFormat(m: BModule): string =
  if m.compileToCpp: result = "$1 $2;$n"
  else: result = "typedef $1 $2 $2;$n"

proc getTypeForward(m: BModule, typ: PType; sig: SigHash): Rope =
  result = cacheGetType(m.forwTypeCache, sig)
  if result != nil: return
  result = getTypePre(m, typ, sig)
  if result != nil: return
  case typ.skipTypes(abstractInst).kind
  of tySequence, tyTuple, tyObject:
    result = getTypeName(m, typ, sig)
    m.forwTypeCache[sig] = result
    if not isImportedType(typ):
      addf(m.s[cfsForwardTypes], "/* getTypeForward: $1 $2 $3 */", [rope typeToString typ,
          rope typ.id, rope m.module.id])
      addf(m.s[cfsForwardTypes], getForwardStructFormat(m),
          [structOrUnion(typ), result])
    doAssert m.forwTypeCache[sig] == result
  else: internalError("getTypeForward(" & $typ.kind & ')')

proc getTypeDescWeak(m: BModule; t: PType; check: var IntSet): Rope =
  ## like getTypeDescAux but creates only a *weak* dependency. In other words
  ## we know we only need a pointer to it so we only generate a struct forward
  ## declaration:
  let etB = t.skipTypes(abstractInst)
  case etB.kind
  of tyObject, tyTuple:
    if isImportedCppType(etB) and t.kind == tyGenericInst:
      result = getTypeDescAux(m, t, check)
    else:
      result = getTypeForward(m, t, hashType(t))
      pushType(m, t)
  of tySequence:
    result = getTypeForward(m, t, hashType(t)) & "*"
    pushType(m, t)
  else:
    result = getTypeDescAux(m, t, check)

proc paramStorageLoc(param: PSym): TStorageLoc =
  if param.typ.skipTypes({tyVar, tyTypeDesc}).kind notin {
          tyArray, tyOpenArray, tyVarargs, tyArrayConstr}:
    result = OnStack
  else:
    result = OnUnknown

proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
                   check: var IntSet, declareEnvironment=true;
                   weakDep=false) =
  params = nil
  if t.sons[0] == nil or isInvalidReturnType(t.sons[0]):
    rettype = ~"void"
  else:
    rettype = getTypeDescAux(m, t.sons[0], check)
  for i in countup(1, sonsLen(t.n) - 1):
    if t.n.sons[i].kind != nkSym: internalError(t.n.info, "genProcParams")
    var param = t.n.sons[i].sym
    if isCompileTimeOnly(param.typ): continue
    if params != nil: add(params, ~", ")
    fillLoc(param.loc, locParam, param.typ, mangleName(m, param),
            param.paramStorageLoc)
    if ccgIntroducedPtr(param):
      add(params, getTypeDescWeak(m, param.typ, check))
      add(params, ~"*")
      incl(param.loc.flags, lfIndirect)
      param.loc.s = OnUnknown
    elif weakDep:
      add(params, getTypeDescWeak(m, param.typ, check))
    else:
      add(params, getTypeDescAux(m, param.typ, check))
    add(params, ~" ")
    add(params, param.loc.r)
    # declare the len field for open arrays:
    var arr = param.typ
    if arr.kind == tyVar: arr = arr.sons[0]
    var j = 0
    while arr.kind in {tyOpenArray, tyVarargs}:
      # this fixes the 'sort' bug:
      if param.typ.kind == tyVar: param.loc.s = OnUnknown
      # need to pass hidden parameter:
      addf(params, ", NI $1Len$2", [param.loc.r, j.rope])
      inc(j)
      arr = arr.sons[0]
  if t.sons[0] != nil and isInvalidReturnType(t.sons[0]):
    var arr = t.sons[0]
    if params != nil: add(params, ", ")
    if mapReturnType(t.sons[0]) != ctArray:
      add(params, getTypeDescWeak(m, arr, check))
      add(params, "*")
    else:
      add(params, getTypeDescAux(m, arr, check))
    addf(params, " Result", [])
  if t.callConv == ccClosure and declareEnvironment:
    if params != nil: add(params, ", ")
    add(params, "void* ClEnv")
  if tfVarargs in t.flags:
    if params != nil: add(params, ", ")
    add(params, "...")
  if params == nil: add(params, "void)")
  else: add(params, ")")
  params = "(" & params

proc mangleRecFieldName(field: PSym, rectype: PType): Rope =
  if (rectype.sym != nil) and
      ({sfImportc, sfExportc} * rectype.sym.flags != {}):
    result = field.loc.r
  else:
    result = rope(mangleField(field.name))
  if result == nil: internalError(field.info, "mangleRecFieldName")

proc genRecordFieldsAux(m: BModule, n: PNode,
                        accessExpr: Rope, rectype: PType,
                        check: var IntSet): Rope =
  result = nil
  case n.kind
  of nkRecList:
    for i in countup(0, sonsLen(n) - 1):
      add(result, genRecordFieldsAux(m, n.sons[i], accessExpr, rectype, check))
  of nkRecCase:
    if n.sons[0].kind != nkSym: internalError(n.info, "genRecordFieldsAux")
    add(result, genRecordFieldsAux(m, n.sons[0], accessExpr, rectype, check))
    let uname = rope(mangle(n.sons[0].sym.name.s) & 'U')
    let ae = if accessExpr != nil: "$1.$2" % [accessExpr, uname]
             else: uname
    var unionBody: Rope = nil
    for i in countup(1, sonsLen(n) - 1):
      case n.sons[i].kind
      of nkOfBranch, nkElse:
        let k = lastSon(n.sons[i])
        if k.kind != nkSym:
          let sname = "S" & rope(i)
          let a = genRecordFieldsAux(m, k, "$1.$2" % [ae, sname], rectype,
                                     check)
          if a != nil:
            add(unionBody, "struct {")
            add(unionBody, a)
            addf(unionBody, "} $1;$n", [sname])
        else:
          add(unionBody, genRecordFieldsAux(m, k, ae, rectype, check))
      else: internalError("genRecordFieldsAux(record case branch)")
    if unionBody != nil:
      addf(result, "union{$n$1} $2;$n", [unionBody, uname])
  of nkSym:
    let field = n.sym
    if field.typ.kind == tyVoid: return
    #assert(field.ast == nil)
    let sname = mangleRecFieldName(field, rectype)
    let ae = if accessExpr != nil: "$1.$2" % [accessExpr, sname]
             else: sname
    fillLoc(field.loc, locField, field.typ, ae, OnUnknown)
    # for importcpp'ed objects, we only need to set field.loc, but don't
    # have to recurse via 'getTypeDescAux'. And not doing so prevents problems
    # with heavily templatized C++ code:
    if not isImportedCppType(rectype):
      let fieldType = field.loc.t.skipTypes(abstractInst)
      if fieldType.kind == tyArray and tfUncheckedArray in fieldType.flags:
        addf(result, "$1 $2[SEQ_DECL_SIZE];$n",
            [getTypeDescAux(m, fieldType.elemType, check), sname])
      elif fieldType.kind == tySequence:
        # we need to use a weak dependency here for trecursive_table.
        addf(result, "$1 $2;$n", [getTypeDescWeak(m, field.loc.t, check), sname])
      elif field.bitsize != 0:
        addf(result, "$1 $2:$3;$n", [getTypeDescAux(m, field.loc.t, check), sname, rope($field.bitsize)])
      else:
        # don't use fieldType here because we need the
        # tyGenericInst for C++ template support
        addf(result, "$1 $2;$n", [getTypeDescAux(m, field.loc.t, check), sname])
  else: internalError(n.info, "genRecordFieldsAux()")

proc getRecordFields(m: BModule, typ: PType, check: var IntSet): Rope =
  result = genRecordFieldsAux(m, typ.n, nil, typ, check)

proc getRecordDesc(m: BModule, typ: PType, name: Rope,
                   check: var IntSet): Rope =
  # declare the record:
  var hasField = false

  var attribute: Rope =
    if tfPacked in typ.flags: rope(CC[cCompiler].packedPragma)
    else: nil

  result = ropecg(m, CC[cCompiler].structStmtFmt,
    [structOrUnion(typ), name, attribute])

  if typ.kind == tyObject:

    if typ.sons[0] == nil:
      if (typ.sym != nil and sfPure in typ.sym.flags) or tfFinal in typ.flags:
        appcg(m, result, " {$n", [])
      else:
        appcg(m, result, " {$n#TNimType* m_type;$n", [name, attribute])
        hasField = true
    elif m.compileToCpp:
      appcg(m, result, " : public $1 {$n",
                      [getTypeDescAux(m, typ.sons[0].skipTypes(skipPtrs), check)])
      hasField = true
    else:
      appcg(m, result, " {$n  $1 Sup;$n",
                      [getTypeDescAux(m, typ.sons[0].skipTypes(skipPtrs), check)])
      hasField = true
  else:
    addf(result, " {$n", [name])

  let desc = getRecordFields(m, typ, check)
  if desc == nil and not hasField:
    addf(result, "char dummy;$n", [])
  else:
    add(result, desc)
  add(result, "};" & tnl)

proc getTupleDesc(m: BModule, typ: PType, name: Rope,
                  check: var IntSet): Rope =
  result = "$1 $2 {$n" % [structOrUnion(typ), name]
  var desc: Rope = nil
  for i in countup(0, sonsLen(typ) - 1):
    addf(desc, "$1 Field$2;$n",
         [getTypeDescAux(m, typ.sons[i], check), rope(i)])
  if desc == nil: add(result, "char dummy;" & tnl)
  else: add(result, desc)
  add(result, "};" & tnl)

proc scanCppGenericSlot(pat: string, cursor, outIdx, outStars: var int): bool =
  # A helper proc for handling cppimport patterns, involving numeric
  # placeholders for generic types (e.g. '0, '**2, etc).
  # pre: the cursor must be placed at the ' symbol
  # post: the cursor will be placed after the final digit
  # false will returned if the input is not recognized as a placeholder
  inc cursor
  let begin = cursor
  while pat[cursor] == '*': inc cursor
  if pat[cursor] in Digits:
    outIdx = pat[cursor].ord - '0'.ord
    outStars = cursor - begin
    inc cursor
    return true
  else:
    return false

proc resolveStarsInCppType(typ: PType, idx, stars: int): PType =
  # XXX: we should catch this earlier and report it as a semantic error
  if idx >= typ.len: internalError "invalid apostrophe type parameter index"

  result = typ.sons[idx]
  for i in 1..stars:
    if result != nil and result.len > 0:
      result = if result.kind == tyGenericInst: result.sons[1]
               else: result.elemType

const
  irrelevantForBackend = {tyGenericBody, tyGenericInst, tyGenericInvocation,
                          tyDistinct, tyRange, tyStatic}

proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
  # returns only the type's name
  var t = origTyp.skipTypes(irrelevantForBackend)
  if t.sym != nil: useHeader(m, t.sym)
  if t != origTyp and origTyp.sym != nil: useHeader(m, origTyp.sym)
  let sig = hashType(origTyp)
  result = getTypePre(m, t, sig)
  if result != nil: return
  if containsOrIncl(check, t.id):
    if not (isImportedCppType(origTyp) or isImportedCppType(t)):
      internalError("cannot generate C type for: " & typeToString(origTyp))
    # XXX: this BUG is hard to fix -> we need to introduce helper structs,
    # but determining when this needs to be done is hard. We should split
    # C type generation into an analysis and a code generation phase somehow.
  case t.kind
  of tyRef, tyPtr, tyVar:
    var star = if t.kind == tyVar and tfVarIsPtr notin origTyp.flags and
                    compileToCpp(m): "&" else: "*"
    var et = origTyp.skipTypes(abstractInst).lastSon
    var etB = et.skipTypes(abstractInst)
    if etB.kind in {tyArrayConstr, tyArray, tyOpenArray, tyVarargs}:
      # this is correct! sets have no proper base type, so we treat
      # ``var set[char]`` in `getParamTypeDesc`
      et = elemType(etB)
      etB = et.skipTypes(abstractInst)
      star[0] = '*'
    case etB.kind
    of tyObject, tyTuple:
      if isImportedCppType(etB) and et.kind == tyGenericInst:
        result = getTypeDescAux(m, et, check) & star
      else:
        # no restriction! We have a forward declaration for structs
        let name = getTypeForward(m, et, hashType et)
        result = name & star
        m.typeCache[sig] = result
        pushType(m, et)
    of tySequence:
      # no restriction! We have a forward declaration for structs
      let name = getTypeForward(m, et, hashType et)
      result = name & "*" & star
      m.typeCache[sig] = result
      pushType(m, et)
    else:
      # else we have a strong dependency  :-(
      result = getTypeDescAux(m, et, check) & star
      m.typeCache[sig] = result
  of tyOpenArray, tyVarargs:
    result = getTypeDescWeak(m, t.sons[0], check) & "*"
    m.typeCache[sig] = result
  of tyEnum:
    result = cacheGetType(m.typeCache, sig)
    if result == nil:
      result = getTypeName(m, origTyp, sig)
      if not (isImportedCppType(t) or
          (sfImportc in t.sym.flags and t.sym.magic == mNone)):
        m.typeCache[sig] = result
        var size: int
        if firstOrd(t) < 0:
          addf(m.s[cfsTypes], "typedef NI32 $1;$n", [result])
          size = 4
        else:
          size = int(getSize(t))
          case size
          of 1: addf(m.s[cfsTypes], "typedef NU8 $1;$n", [result])
          of 2: addf(m.s[cfsTypes], "typedef NU16 $1;$n", [result])
          of 4: addf(m.s[cfsTypes], "typedef NI32 $1;$n", [result])
          of 8: addf(m.s[cfsTypes], "typedef NI64 $1;$n", [result])
          else: internalError(t.sym.info, "getTypeDescAux: enum")
        when false:
          let owner = hashOwner(t.sym)
          if not gDebugInfo.hasEnum(t.sym.name.s, t.sym.info.line, owner):
            var vals: seq[(string, int)] = @[]
            for i in countup(0, t.n.len - 1):
              assert(t.n.sons[i].kind == nkSym)
              let field = t.n.sons[i].sym
              vals.add((field.name.s, field.position.int))
            gDebugInfo.registerEnum(EnumDesc(size: size, owner: owner, id: t.sym.id,
              name: t.sym.name.s, values: vals))
  of tyProc:
    result = getTypeName(m, origTyp, sig)
    m.typeCache[sig] = result
    var rettype, desc: Rope
    genProcParams(m, t, rettype, desc, check, true, true)
    if not isImportedType(t):
      if t.callConv != ccClosure: # procedure vars may need a closure!
        addf(m.s[cfsTypes], "typedef $1_PTR($2, $3) $4;$n",
             [rope(CallingConvToStr[t.callConv]), rettype, result, desc])
      else:
        addf(m.s[cfsTypes], "typedef struct {$n" &
            "N_NIMCALL_PTR($2, ClPrc) $3;$n" &
            "void* ClEnv;$n} $1;$n",
             [result, rettype, desc])
  of tySequence:
    # we cannot use getTypeForward here because then t would be associated
    # with the name of the struct, not with the pointer to the struct:
    result = cacheGetType(m.forwTypeCache, sig)
    if result == nil:
      result = getTypeName(m, origTyp, sig)
      if not isImportedType(t):
        addf(m.s[cfsForwardTypes], getForwardStructFormat(m),
            [structOrUnion(t), result])
      m.forwTypeCache[sig] = result
    assert(cacheGetType(m.typeCache, sig) == nil)
    m.typeCache[sig] = result & "*"
    if not isImportedType(t):
      if skipTypes(t.sons[0], typedescInst).kind != tyEmpty:
        const
          cppSeq = "struct $2 : #TGenericSeq {$n"
          cSeq = "struct $2 {$n" &
                 "  #TGenericSeq Sup;$n"
        appcg(m, m.s[cfsSeqTypes],
            (if m.compileToCpp: cppSeq else: cSeq) &
            "  $1 data[SEQ_DECL_SIZE];$n" &
            "};$n", [getTypeDescAux(m, t.sons[0], check), result])
      else:
        result = rope("TGenericSeq")
    add(result, "*")
  of tyArray:
    var n: BiggestInt = lengthOrd(t)
    if n <= 0: n = 1   # make an array of at least one element
    result = getTypeName(m, origTyp, sig)
    m.typeCache[sig] = result
    if not isImportedType(t):
      let foo = getTypeDescAux(m, t.sons[1], check)
      addf(m.s[cfsTypes], "typedef $1 $2[$3];$n",
           [foo, result, rope(n)])
  of tyObject, tyTuple:
    if isImportedCppType(t) and origTyp.kind == tyGenericInst:
      # for instantiated templates we do not go through the type cache as the
      # the type cache is not aware of 'tyGenericInst'.
      let cppName = getTypeName(m, t, sig)
      var i = 0
      var chunkStart = 0
      while i < cppName.data.len:
        if cppName.data[i] == '\'':
          var chunkEnd = <i
          var idx, stars: int
          if scanCppGenericSlot(cppName.data, i, idx, stars):
            result.add cppName.data.substr(chunkStart, chunkEnd)
            chunkStart = i

            let typeInSlot = resolveStarsInCppType(origTyp, idx + 1, stars)
            if typeInSlot == nil or typeInSlot.kind == tyVoid:
              result.add(~"void")
            else:
              result.add getTypeDescAux(m, typeInSlot, check)
        else:
          inc i

      if chunkStart != 0:
        result.add cppName.data.substr(chunkStart)
      else:
        result = cppName & "<"
        for i in 1 .. origTyp.len-2:
          if i > 1: result.add(" COMMA ")
          result.add(getTypeDescAux(m, origTyp.sons[i], check))
        result.add("> ")
      # always call for sideeffects:
      assert t.kind != tyTuple
      discard getRecordDesc(m, t, result, check)
    else:
      when false:
        if t.sym != nil and t.sym.name.s == "KeyValuePair":
          if t == origTyp:
            echo "wtf: came here"
            writeStackTrace()
            quit 1
      result = cacheGetType(m.forwTypeCache, sig)
      if result == nil:
        when false:
          if t.sym != nil and t.sym.name.s == "KeyValuePair":
            # or {sfImportc, sfExportc} * t.sym.flags == {}:
            if t.loc.r != nil:
              echo t.kind, " ", hashType t
              echo origTyp.kind, " ", sig
            assert t.loc.r == nil
        result = getTypeName(m, origTyp, sig)
        m.forwTypeCache[sig] = result
        if not isImportedType(t):
          addf(m.s[cfsForwardTypes], "/* tyObject: $1 $2 $3 */", [rope typeToString t,
            rope t.id, rope m.module.id])
          addf(m.s[cfsForwardTypes], getForwardStructFormat(m),
             [structOrUnion(t), result])
        doAssert m.forwTypeCache[sig] == result
      m.typeCache[sig] = result # always call for sideeffects:
      let recdesc = if t.kind != tyTuple: getRecordDesc(m, t, result, check)
                    else: getTupleDesc(m, t, result, check)
      if not isImportedType(t): add(m.s[cfsTypes], recdesc)
  of tySet:
    result = getTypeName(m, t.lastSon, hashType t.lastSon) & "_Set"
    m.typeCache[sig] = result
    if not isImportedType(t):
      let s = int(getSize(t))
      case s
      of 1, 2, 4, 8: addf(m.s[cfsTypes], "typedef NU$2 $1;$n", [result, rope(s*8)])
      else: addf(m.s[cfsTypes], "typedef NU8 $1[$2];$n",
             [result, rope(getSize(t))])
  of tyGenericInst, tyDistinct, tyOrdinal, tyTypeDesc:
    result = getTypeDescAux(m, lastSon(t), check)
  else:
    internalError("getTypeDescAux(" & $t.kind & ')')
    result = nil
  # fixes bug #145:
  excl(check, t.id)

proc getTypeDesc(m: BModule, typ: PType): Rope =
  var check = initIntSet()
  result = getTypeDescAux(m, typ, check)

type
  TClosureTypeKind = enum
    clHalf, clHalfWithEnv, clFull

proc getClosureType(m: BModule, t: PType, kind: TClosureTypeKind): Rope =
  assert t.kind == tyProc
  var check = initIntSet()
  result = getTempName(m)
  var rettype, desc: Rope
  genProcParams(m, t, rettype, desc, check, declareEnvironment=kind != clHalf)
  if not isImportedType(t):
    if t.callConv != ccClosure or kind != clFull:
      addf(m.s[cfsTypes], "typedef $1_PTR($2, $3) $4;$n",
           [rope(CallingConvToStr[t.callConv]), rettype, result, desc])
    else:
      addf(m.s[cfsTypes], "typedef struct {$n" &
          "N_NIMCALL_PTR($2, ClPrc) $3;$n" &
          "void* ClEnv;$n} $1;$n",
           [result, rettype, desc])

proc finishTypeDescriptions(m: BModule) =
  var i = 0
  while i < len(m.typeStack):
    discard getTypeDesc(m, m.typeStack[i])
    inc(i)

template cgDeclFrmt*(s: PSym): string = s.constraint.strVal

proc genProcHeader(m: BModule, prc: PSym): Rope =
  var
    rettype, params: Rope
  genCLineDir(result, prc.info)
  # using static is needed for inline procs
  if lfExportLib in prc.loc.flags:
    if isHeaderFile in m.flags:
      result.add "N_LIB_IMPORT "
    else:
      result.add "N_LIB_EXPORT "
  elif prc.typ.callConv == ccInline:
    result.add "static "
  var check = initIntSet()
  fillLoc(prc.loc, locProc, prc.typ, mangleName(m, prc), OnUnknown)
  genProcParams(m, prc.typ, rettype, params, check)
  # careful here! don't access ``prc.ast`` as that could reload large parts of
  # the object graph!
  if prc.constraint.isNil:
    addf(result, "$1($2, $3)$4",
         [rope(CallingConvToStr[prc.typ.callConv]), rettype, prc.loc.r,
         params])
  else:
    result = prc.cgDeclFrmt % [rettype, prc.loc.r, params]

# ------------------ type info generation -------------------------------------

proc genTypeInfo(m: BModule, t: PType): Rope
proc getNimNode(m: BModule): Rope =
  result = "$1[$2]" % [m.typeNodesName, rope(m.typeNodes)]
  inc(m.typeNodes)

proc genTypeInfoAuxBase(m: BModule; typ, origType: PType; name, base: Rope) =
  var nimtypeKind: int
  #allocMemTI(m, typ, name)
  if isObjLackingTypeField(typ):
    nimtypeKind = ord(tyPureObject)
  else:
    nimtypeKind = ord(typ.kind)

  var size: Rope
  if tfIncompleteStruct in typ.flags: size = rope"void*"
  else: size = getTypeDesc(m, origType)
  addf(m.s[cfsTypeInit3],
       "$1.size = sizeof($2);$n" & "$1.kind = $3;$n" & "$1.base = $4;$n",
       [name, size, rope(nimtypeKind), base])
  # compute type flags for GC optimization
  var flags = 0
  if not containsGarbageCollectedRef(typ): flags = flags or 1
  if not canFormAcycle(typ): flags = flags or 2
  #else MessageOut("can contain a cycle: " & typeToString(typ))
  if flags != 0:
    addf(m.s[cfsTypeInit3], "$1.flags = $2;$n", [name, rope(flags)])
  discard cgsym(m, "TNimType")
  addf(m.s[cfsVars], "TNimType $1; /* $2 */$n",
       [name, rope(typeToString(typ))])

proc genTypeInfoAux(m: BModule, typ, origType: PType, name: Rope) =
  var base: Rope
  if sonsLen(typ) > 0 and typ.sons[0] != nil:
    var x = typ.sons[0]
    if typ.kind == tyObject: x = x.skipTypes(skipPtrs)
    base = genTypeInfo(m, x)
  else:
    base = rope("0")
  genTypeInfoAuxBase(m, typ, origType, name, base)

proc discriminatorTableName(m: BModule, objtype: PType, d: PSym): Rope =
  # bugfix: we need to search the type that contains the discriminator:
  var objtype = objtype
  while lookupInRecord(objtype.n, d.name) == nil:
    objtype = objtype.sons[0]
  if objtype.sym == nil:
    internalError(d.info, "anonymous obj with discriminator")
  result = "NimDT_$1_$2" % [rope($hashType(objtype)), rope(d.name.s.mangle)]

proc discriminatorTableDecl(m: BModule, objtype: PType, d: PSym): Rope =
  discard cgsym(m, "TNimNode")
  var tmp = discriminatorTableName(m, objtype, d)
  result = "TNimNode* $1[$2];$n" % [tmp, rope(lengthOrd(d.typ)+1)]

proc genObjectFields(m: BModule, typ, origType: PType, n: PNode, expr: Rope) =
  case n.kind
  of nkRecList:
    var L = sonsLen(n)
    if L == 1:
      genObjectFields(m, typ, origType, n.sons[0], expr)
    elif L > 0:
      var tmp = getTempName(m)
      addf(m.s[cfsTypeInit1], "static TNimNode* $1[$2];$n", [tmp, rope(L)])
      for i in countup(0, L-1):
        var tmp2 = getNimNode(m)
        addf(m.s[cfsTypeInit3], "$1[$2] = &$3;$n", [tmp, rope(i), tmp2])
        genObjectFields(m, typ, origType, n.sons[i], tmp2)
      addf(m.s[cfsTypeInit3], "$1.len = $2; $1.kind = 2; $1.sons = &$3[0];$n",
           [expr, rope(L), tmp])
    else:
      addf(m.s[cfsTypeInit3], "$1.len = $2; $1.kind = 2;$n", [expr, rope(L)])
  of nkRecCase:
    assert(n.sons[0].kind == nkSym)
    var field = n.sons[0].sym
    var tmp = discriminatorTableName(m, typ, field)
    var L = lengthOrd(field.typ)
    assert L > 0
    addf(m.s[cfsTypeInit3], "$1.kind = 3;$n" &
        "$1.offset = offsetof($2, $3);$n" & "$1.typ = $4;$n" &
        "$1.name = $5;$n" & "$1.sons = &$6[0];$n" &
        "$1.len = $7;$n", [expr, getTypeDesc(m, origType), field.loc.r,
                           genTypeInfo(m, field.typ),
                           makeCString(field.name.s),
                           tmp, rope(L)])
    addf(m.s[cfsData], "TNimNode* $1[$2];$n", [tmp, rope(L+1)])
    for i in countup(1, sonsLen(n)-1):
      var b = n.sons[i]           # branch
      var tmp2 = getNimNode(m)
      genObjectFields(m, typ, origType, lastSon(b), tmp2)
      case b.kind
      of nkOfBranch:
        if sonsLen(b) < 2:
          internalError(b.info, "genObjectFields; nkOfBranch broken")
        for j in countup(0, sonsLen(b) - 2):
          if b.sons[j].kind == nkRange:
            var x = int(getOrdValue(b.sons[j].sons[0]))
            var y = int(getOrdValue(b.sons[j].sons[1]))
            while x <= y:
              addf(m.s[cfsTypeInit3], "$1[$2] = &$3;$n", [tmp, rope(x), tmp2])
              inc(x)
          else:
            addf(m.s[cfsTypeInit3], "$1[$2] = &$3;$n",
                 [tmp, rope(getOrdValue(b.sons[j])), tmp2])
      of nkElse:
        addf(m.s[cfsTypeInit3], "$1[$2] = &$3;$n",
             [tmp, rope(L), tmp2])
      else: internalError(n.info, "genObjectFields(nkRecCase)")
  of nkSym:
    var field = n.sym
    if field.bitsize == 0:
      addf(m.s[cfsTypeInit3], "$1.kind = 1;$n" &
          "$1.offset = offsetof($2, $3);$n" & "$1.typ = $4;$n" &
          "$1.name = $5;$n", [expr, getTypeDesc(m, origType),
          field.loc.r, genTypeInfo(m, field.typ), makeCString(field.name.s)])
  else: internalError(n.info, "genObjectFields")

proc genObjectInfo(m: BModule, typ, origType: PType, name: Rope) =
  if typ.kind == tyObject: genTypeInfoAux(m, typ, origType, name)
  else: genTypeInfoAuxBase(m, typ, origType, name, rope("0"))
  var tmp = getNimNode(m)
  if not isImportedCppType(typ):
    genObjectFields(m, typ, origType, typ.n, tmp)
  addf(m.s[cfsTypeInit3], "$1.node = &$2;$n", [name, tmp])
  var t = typ.sons[0]
  while t != nil:
    t = t.skipTypes(skipPtrs)
    t.flags.incl tfObjHasKids
    t = t.sons[0]

proc genTupleInfo(m: BModule, typ, origType: PType, name: Rope) =
  genTypeInfoAuxBase(m, typ, typ, name, rope("0"))
  var expr = getNimNode(m)
  var length = sonsLen(typ)
  if length > 0:
    var tmp = getTempName(m)
    addf(m.s[cfsTypeInit1], "static TNimNode* $1[$2];$n", [tmp, rope(length)])
    for i in countup(0, length - 1):
      var a = typ.sons[i]
      var tmp2 = getNimNode(m)
      addf(m.s[cfsTypeInit3], "$1[$2] = &$3;$n", [tmp, rope(i), tmp2])
      addf(m.s[cfsTypeInit3], "$1.kind = 1;$n" &
          "$1.offset = offsetof($2, Field$3);$n" &
          "$1.typ = $4;$n" &
          "$1.name = \"Field$3\";$n",
           [tmp2, getTypeDesc(m, origType), rope(i), genTypeInfo(m, a)])
    addf(m.s[cfsTypeInit3], "$1.len = $2; $1.kind = 2; $1.sons = &$3[0];$n",
         [expr, rope(length), tmp])
  else:
    addf(m.s[cfsTypeInit3], "$1.len = $2; $1.kind = 2;$n",
         [expr, rope(length)])
  addf(m.s[cfsTypeInit3], "$1.node = &$2;$n", [name, expr])

proc genEnumInfo(m: BModule, typ: PType, name: Rope) =
  # Type information for enumerations is quite heavy, so we do some
  # optimizations here: The ``typ`` field is never set, as it is redundant
  # anyway. We generate a cstring array and a loop over it. Exceptional
  # positions will be reset after the loop.
  genTypeInfoAux(m, typ, typ, name)
  var nodePtrs = getTempName(m)
  var length = sonsLen(typ.n)
  addf(m.s[cfsTypeInit1], "static TNimNode* $1[$2];$n",
       [nodePtrs, rope(length)])
  var enumNames, specialCases: Rope
  var firstNimNode = m.typeNodes
  var hasHoles = false
  for i in countup(0, length - 1):
    assert(typ.n.sons[i].kind == nkSym)
    var field = typ.n.sons[i].sym
    var elemNode = getNimNode(m)
    if field.ast == nil:
      # no explicit string literal for the enum field, so use field.name:
      add(enumNames, makeCString(field.name.s))
    else:
      add(enumNames, makeCString(field.ast.strVal))
    if i < length - 1: add(enumNames, ", " & tnl)
    if field.position != i or tfEnumHasHoles in typ.flags:
      addf(specialCases, "$1.offset = $2;$n", [elemNode, rope(field.position)])
      hasHoles = true
  var enumArray = getTempName(m)
  var counter = getTempName(m)
  addf(m.s[cfsTypeInit1], "NI $1;$n", [counter])
  addf(m.s[cfsTypeInit1], "static char* NIM_CONST $1[$2] = {$n$3};$n",
       [enumArray, rope(length), enumNames])
  addf(m.s[cfsTypeInit3], "for ($1 = 0; $1 < $2; $1++) {$n" &
      "$3[$1+$4].kind = 1;$n" & "$3[$1+$4].offset = $1;$n" &
      "$3[$1+$4].name = $5[$1];$n" & "$6[$1] = &$3[$1+$4];$n" & "}$n", [counter,
      rope(length), m.typeNodesName, rope(firstNimNode), enumArray, nodePtrs])
  add(m.s[cfsTypeInit3], specialCases)
  addf(m.s[cfsTypeInit3],
       "$1.len = $2; $1.kind = 2; $1.sons = &$3[0];$n$4.node = &$1;$n",
       [getNimNode(m), rope(length), nodePtrs, name])
  if hasHoles:
    # 1 << 2 is {ntfEnumHole}
    addf(m.s[cfsTypeInit3], "$1.flags = 1<<2;$n", [name])

proc genSetInfo(m: BModule, typ: PType, name: Rope) =
  assert(typ.sons[0] != nil)
  genTypeInfoAux(m, typ, typ, name)
  var tmp = getNimNode(m)
  addf(m.s[cfsTypeInit3], "$1.len = $2; $1.kind = 0;$n" & "$3.node = &$1;$n",
       [tmp, rope(firstOrd(typ)), name])

proc genArrayInfo(m: BModule, typ: PType, name: Rope) =
  genTypeInfoAuxBase(m, typ, typ, name, genTypeInfo(m, typ.sons[1]))

proc fakeClosureType(owner: PSym): PType =
  # we generate the same RTTI as for a tuple[pointer, ref tuple[]]
  result = newType(tyTuple, owner)
  result.rawAddSon(newType(tyPointer, owner))
  var r = newType(tyRef, owner)
  r.rawAddSon(newType(tyTuple, owner))
  result.rawAddSon(r)

type
  TTypeInfoReason = enum  ## for what do we need the type info?
    tiNew,                ## for 'new'

include ccgtrav

proc genDeepCopyProc(m: BModule; s: PSym; result: Rope) =
  genProc(m, s)
  addf(m.s[cfsTypeInit3], "$1.deepcopy =(void* (N_RAW_NIMCALL*)(void*))$2;$n",
     [result, s.loc.r])

proc genTypeInfo(m: BModule, t: PType): Rope =
  let origType = t
  var t = skipTypes(origType, irrelevantForBackend)

  let sig = hashType(origType)
  result = m.typeInfoMarker.getOrDefault(sig)
  if result != nil:
    return "(&".rope & result & ")".rope

  result = "NTI$1" % [rope($sig)]
  m.typeInfoMarker[sig] = result

  let owner = t.skipTypes(typedescPtrs).owner.getModule
  if owner != m.module:
    # make sure the type info is created in the owner module
    discard genTypeInfo(owner.bmod, origType)
    # reference the type info as extern here
    discard cgsym(m, "TNimType")
    discard cgsym(m, "TNimNode")
    addf(m.s[cfsVars], "extern TNimType $1; /* $2 */$n",
         [result, rope(typeToString(t))])
    return "(&".rope & result & ")".rope
  case t.kind
  of tyEmpty, tyVoid: result = rope"0"
  of tyPointer, tyBool, tyChar, tyCString, tyString, tyInt..tyUInt64, tyVar:
    genTypeInfoAuxBase(m, t, t, result, rope"0")
  of tyStatic:
    if t.n != nil: result = genTypeInfo(m, lastSon t)
    else: internalError("genTypeInfo(" & $t.kind & ')')
  of tyProc:
    if t.callConv != ccClosure:
      genTypeInfoAuxBase(m, t, t, result, rope"0")
    else:
      let x = fakeClosureType(t.owner)
      genTupleInfo(m, x, x, result)
  of tySequence, tyRef:
    genTypeInfoAux(m, t, t, result)
    if gSelectedGC >= gcMarkAndSweep:
      let markerProc = genTraverseProc(m, origType, sig, tiNew)
      addf(m.s[cfsTypeInit3], "$1.marker = $2;$n", [result, markerProc])
  of tyPtr, tyRange: genTypeInfoAux(m, t, t, result)
  of tyArrayConstr, tyArray: genArrayInfo(m, t, result)
  of tySet: genSetInfo(m, t, result)
  of tyEnum: genEnumInfo(m, t, result)
  of tyObject: genObjectInfo(m, t, origType, result)
  of tyTuple:
    # if t.n != nil: genObjectInfo(m, t, result)
    # else:
    # BUGFIX: use consistently RTTI without proper field names; otherwise
    # results are not deterministic!
    genTupleInfo(m, t, origType, result)
  else: internalError("genTypeInfo(" & $t.kind & ')')
  if t.deepCopy != nil:
    genDeepCopyProc(m, t.deepCopy, result)
  elif origType.deepCopy != nil:
    genDeepCopyProc(m, origType.deepCopy, result)
  result = "(&".rope & result & ")".rope

proc genTypeSection(m: BModule, n: PNode) =
  discard