ocarina-backends-c_tree-nutils.adb 75.8 KB
Newer Older
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
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--       O C A R I N A . B A C K E N D S . C _ T R E E . N U T I L S        --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--               Copyright (C) 2008-2009, GET-Telecom Paris.                --
--                                                                          --
-- Ocarina  is free software;  you  can  redistribute  it and/or  modify    --
-- it under terms of the GNU General Public License as published by the     --
-- Free Software Foundation; either version 2, or (at your option) any      --
-- later version. Ocarina is distributed  in  the  hope  that it will be    --
-- useful, but WITHOUT ANY WARRANTY;  without even the implied warranty of  --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received  a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING.   --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA.                                       --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable to be   --
-- covered  by the  GNU  General  Public  License. This exception does not  --
-- however invalidate  any other reasons why the executable file might be   --
-- covered by the GNU Public License.                                       --
--                                                                          --
--                 Ocarina is maintained by the Ocarina team                --
--                       (ocarina-users@listes.enst.fr)                     --
--                                                                          --
------------------------------------------------------------------------------

with GNAT.Table;
with GNAT.Case_Util;

with Charset;   use Charset;
with Locations; use Locations;
with Namet;     use Namet;
with Utils;     use Utils;

with Ocarina.Backends;
with Ocarina.Backends.C_Common.Mapping;
with Ocarina.Backends.PO_HI_C.Runtime;
with Ocarina.Backends.POK_C;
with Ocarina.Backends.POK_C.Runtime;
with Ocarina.Backends.Utils;
with Ocarina.Backends.Messages;
with Ocarina.Backends.C_Tree.Nutils;
with Ocarina.Backends.C_Values;
with Ocarina.Backends.Properties;

with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.Instances.Queries;

use Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.Backends;
use Ocarina.Backends.Utils;
use Ocarina.Backends.Messages;
use Ocarina.Backends.Properties;
use Ocarina.Backends.C_Common.Mapping;
use Ocarina.Backends.C_Values;

use Ocarina.Instances.Queries;

package body Ocarina.Backends.C_Tree.Nutils is

   package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
   package CV  renames Ocarina.Backends.C_Values;
   package CTU renames Ocarina.Backends.C_Tree.Nutils;
   package CTN renames Ocarina.Backends.C_Tree.Nodes;
   package PHCR renames Ocarina.Backends.PO_HI_C.Runtime;
   package PKR renames Ocarina.Backends.POK_C.Runtime;

   Keyword_Suffix : constant String := "%C";
   --  Used to mark C keywords and avoid collision with other languages

   type Entity_Stack_Entry is record
      Current_File    : Node_Id;
      Current_Entity  : Node_Id;
   end record;

   No_Depth : constant Int := -1;
   package Entity_Stack is
      new GNAT.Table (Entity_Stack_Entry, Int, No_Depth + 1, 10, 10);

   use Entity_Stack;

   procedure New_Operator
     (O : Operator_Type;
      I : String := "");

   ------------------------
   -- Add_Prefix_To_Name --
   ------------------------

   function Add_Prefix_To_Name
     (Prefix : String;
      Name   : Name_Id)
     return Name_Id
   is
   begin
      Set_Str_To_Name_Buffer (Prefix);
      Get_Name_String_And_Append (Name);
      return Name_Find;
   end Add_Prefix_To_Name;

   ------------------------
   -- Add_Suffix_To_Name --
   ------------------------

   function Add_Suffix_To_Name
     (Suffix : String;
      Name   : Name_Id)
     return Name_Id
   is
   begin
      Get_Name_String (Name);
      Add_Str_To_Name_Buffer (Suffix);
      return Name_Find;
   end Add_Suffix_To_Name;

   -----------------------------
   -- Remove_Suffix_From_Name --
   -----------------------------

   function Remove_Suffix_From_Name
     (Suffix : String;
      Name   : Name_Id)
     return Name_Id
   is
      Length   : Natural;
      Temp_Str : String (1 .. Suffix'Length);
   begin
      Set_Str_To_Name_Buffer (Suffix);
      Length := Name_Len;
      Get_Name_String (Name);
      if Name_Len > Length then
         Temp_Str := Name_Buffer (Name_Len - Length + 1 .. Name_Len);
         if Suffix = Temp_Str then
            Set_Str_To_Name_Buffer (Name_Buffer (1 .. Name_Len - Length));
            return Name_Find;
         end if;
      end if;
      return Name;
   end Remove_Suffix_From_Name;

   -------------------------
   -- Append_Node_To_List --
   -------------------------

   procedure Append_Node_To_List (E : Node_Id; L : List_Id) is
      Last : Node_Id;

   begin
      Last := CTN.Last_Node (L);
      if No (Last) then
         CTN.Set_First_Node (L, E);
      else
         CTN.Set_Next_Node (Last, E);
      end if;
      Last := E;
      while Present (Last) loop
         CTN.Set_Last_Node (L, Last);
         Last := CTN.Next_Node (Last);
      end loop;
   end Append_Node_To_List;

   -----------------------
   -- Insert_After_Node --
   -----------------------

   procedure Insert_After_Node (E : Node_Id; N : Node_Id) is
      Next : constant Node_Id := CTN.Next_Node (N);
   begin
      CTN.Set_Next_Node (N, E);
      CTN.Set_Next_Node (E, Next);
   end Insert_After_Node;

   ------------------------
   -- Insert_Before_Node --
   ------------------------

   procedure Insert_Before_Node (E : Node_Id; N : Node_Id; L : List_Id) is
      Entity : Node_Id;
   begin
      Entity := CTN.First_Node (L);
      if Entity = N then
         CTN.Set_Next_Node (E, Entity);
         CTN.Set_First_Node (L, E);
      else
         while Present (Entity) loop
            exit when CTN.Next_Node (Entity) = N;
            Entity := CTN.Next_Node (Entity);
         end loop;

         Insert_After_Node (E, Entity);
      end if;
   end Insert_Before_Node;

   ---------------
   -- Copy_Node --
   ---------------

   function Copy_Node (N : Node_Id) return Node_Id is
      C : Node_Id;
   begin
      case CTN.Kind (N) is
         when K_Defining_Identifier =>
            C := New_Node (K_Defining_Identifier);
            CTN.Set_Name (C, CTN.Name (N));
            CTN.Set_Corresponding_Node (C, CTN.Corresponding_Node (N));

         when K_Function_Specification =>
            C := New_Node (K_Function_Specification);
            CTN.Set_Defining_Identifier
              (C, CTU.Copy_Node (Defining_Identifier (N)));
            CTN.Set_Parameters (C, CTN.Parameters (N));
            CTN.Set_Return_Type (C, CTN.Return_Type (N));

         when K_Include_Clause =>
            C := New_Node (K_Include_Clause);
            CTN.Set_Header_Name
               (C, CTU.Copy_Node (Header_Name (N)));
            CTN.Set_Is_Local (C, CTN.Is_Local (N));

         when K_Literal =>
            C := New_Node (K_Literal);
            CTN.Set_Value (C, CTN.Value (N));

         when K_Ifdef_Clause =>
            C := New_Node (K_Ifdef_Clause);
            CTN.Set_Negation (C, Negation (N));
            CTN.Set_Then_Statements (C, Then_Statements (N));
            CTN.Set_Else_Statements (C, Else_Statements (N));
            CTN.Set_Clause (C, Copy_Node (Clause (N)));

         when others =>
            raise Program_Error;
      end case;
      return C;
   end Copy_Node;

   ---------------------
   -- Message_Comment --
   ---------------------

   function Message_Comment (M : Name_Id) return Node_Id is
      C : Node_Id;
   begin
      C := Make_C_Comment (M);
      return C;
   end Message_Comment;

   ---------------------
   -- Message_Comment --
   ---------------------

   function Message_Comment (M : String) return Node_Id is
      C : Node_Id;
   begin
      Set_Str_To_Name_Buffer (M);
      C := Make_C_Comment (Name_Find);
      return C;
   end Message_Comment;

   -----------
   -- Image --
   -----------

   function Image (T : Token_Type) return String is
      S : String := Token_Type'Image (T);
   begin
      To_Lower (S);
      return S (5 .. S'Last);
   end Image;

   -----------
   -- Image --
   -----------

   function Image (O : Operator_Type) return String is
      S : String := Operator_Type'Image (O);
   begin
      To_Lower (S);
      for I in S'First .. S'Last loop
         if S (I) = '_' then
            S (I) := ' ';
         end if;
      end loop;
      return S (4 .. S'Last);
   end Image;

   ----------------
   -- Initialize --
   ----------------

   procedure Initialize is
   begin
      --  Initialize Nutils only once

      if Initialized then
         return;
      end if;

      Initialized := True;

      --  Keywords.
      for I in Keyword_Type loop
         New_Token (I);
      end loop;

      --  Graphic Characters
      New_Token (Tok_And, "&&");
      New_Token (Tok_Xor, "^");
      New_Token (Tok_Sharp, "#");
      New_Token (Tok_Or, "||");
      New_Token (Tok_Left_Brace, "{");
      New_Token (Tok_Right_Brace, "}");
      New_Token (Tok_Mod, "%");
      New_Token (Tok_Not, "!");
      New_Token (Tok_Ampersand, "&");
      New_Token (Tok_Minus, "-");
      New_Token (Tok_Underscore, "_");
      New_Token (Tok_Plus, "+");
      New_Token (Tok_Asterisk, "*");
      New_Token (Tok_Slash, "/");
      New_Token (Tok_Dot, ".");
      New_Token (Tok_Apostrophe, "'");
      New_Token (Tok_Left_Paren, "(");
      New_Token (Tok_Right_Paren, ")");
      New_Token (Tok_Left_Hook, "[");
      New_Token (Tok_Right_Hook, "]");
      New_Token (Tok_Comma, ",");
      New_Token (Tok_Less, "<");
      New_Token (Tok_Equal, "=");
      New_Token (Tok_Equal_Equal, "==");
      New_Token (Tok_Greater, ">");
      New_Token (Tok_Not_Equal, "!=");
      New_Token (Tok_Greater_Equal, ">=");
      New_Token (Tok_Less_Equal, "<=");
      New_Token (Tok_Colon, ":");
      New_Token (Tok_Greater_Greater, ">>");
      New_Token (Tok_Less_Less, "<<");
      New_Token (Tok_Quote, """");
      New_Token (Tok_Semicolon, ";");
      New_Token (Tok_Arrow, "->");
      New_Token (Tok_Vertical_Bar, "|");

      for O in Op_And .. Op_Or_Else loop
         New_Operator (O);
      end loop;
      New_Operator (Op_And_Symbol, "&");
      New_Operator (Op_Double_Asterisk, "**");
      New_Operator (Op_Asterisk, "**");
      New_Operator (Op_Minus, "-");
      New_Operator (Op_Plus, "+");
      New_Operator (Op_Asterisk, "*");
      New_Operator (Op_Slash, "/");
      New_Operator (Op_Less, "<");
      New_Operator (Op_Equal, "=");
      New_Operator (Op_Equal_Equal, "==");
      New_Operator (Op_Greater, ">");
      New_Operator (Op_Not_Equal, "!=");
      New_Operator (Op_Greater_Equal, ">=");
      New_Operator (Op_Less_Equal, "<=");
      New_Operator (Op_Greater_Greater, ">>");
      New_Operator (Op_Less_Less, "<<");
      New_Operator (Op_Semicolon, ";");
      New_Operator (Op_Arrow, "=>");
      New_Operator (Op_Vertical_Bar, "|");

      for A in Attribute_Id loop
         Set_Str_To_Name_Buffer (Attribute_Id'Image (A));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
         AN (A) := Name_Find;
      end loop;

      for C in Constant_Id loop
         Set_Str_To_Name_Buffer (Constant_Id'Image (C));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         CONST (C) := To_Upper (Name_Find);
      end loop;

      for P in Parameter_Id loop
         Set_Str_To_Name_Buffer (Parameter_Id'Image (P));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
         PN (P) := Name_Find;
      end loop;

      for F in Function_Id loop
         Set_Str_To_Name_Buffer (Function_Id'Image (F));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         FN (F) := To_Lower (Name_Find);
      end loop;

      for T in Type_Id loop
         Set_Str_To_Name_Buffer (Type_Id'Image (T));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         TN (T) := To_Lower (Name_Find);
      end loop;

      for V in Variable_Id loop
         Set_Str_To_Name_Buffer (Variable_Id'Image (V));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         VN (V) := To_Lower (Name_Find);
      end loop;

      for V in Member_Id loop
         Set_Str_To_Name_Buffer (Member_Id'Image (V));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));

         MN (V) := To_Lower (Name_Find);
      end loop;
   end Initialize;

   -----------
   -- Reset --
   -----------

   procedure Reset is
   begin
      Entity_Stack.Init;

      Initialized := False;
   end Reset;

   --------------
   -- Is_Empty --
   --------------

   function Is_Empty (L : List_Id) return Boolean is
   begin
      return L = No_List or else No (CTN.First_Node (L));
   end Is_Empty;

   ------------
   -- Length --
   ------------

   function Length (L : List_Id) return Natural is
      N : Node_Id;
      C : Natural := 0;
   begin
      if not Is_Empty (L) then
         N := CTN.First_Node (L);

         while Present (N) loop
            C := C + 1;
            N := CTN.Next_Node (N);
         end loop;
      end if;

      return C;
   end Length;

   --------------------
   -- Make_C_Comment --
   --------------------

   function Make_C_Comment
     (N                 : Name_Id;
      Has_Header_Spaces : Boolean := True)
     return Node_Id
   is
      C : Node_Id;
   begin
      C := New_Node (K_C_Comment);
      Set_Defining_Identifier (C, New_Node (K_Defining_Identifier));
      CTN.Set_Name (Defining_Identifier (C), N);
      CTN.Set_Has_Header_Spaces (C, Has_Header_Spaces);
      return C;
   end Make_C_Comment;

   -------------------------------
   -- Make_Assignment_Statement --
   -------------------------------

   function Make_Assignment_Statement
     (Variable_Identifier : Node_Id;
      Expression          : Node_Id)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_Assignment_Statement);
      Set_Defining_Identifier (N, Variable_Identifier);
      Set_Expression (N, Expression);
      return N;
   end Make_Assignment_Statement;

   ------------------------------
   -- Make_Defining_Identifier --
   ------------------------------

   function Make_Defining_Identifier
     (Name         : Name_Id;
      C_Conversion : Boolean := True;
      Ada_Conversion : Boolean := False;
      Pointer      : Boolean := False)
     return Node_Id
   is
      N : Node_Id;

   begin
      N := New_Node (K_Defining_Identifier);
      if C_Conversion then
         CTN.Set_Name (N, To_C_Name (Name, Ada_Conversion));
      else
         CTN.Set_Name (N, Name);
      end if;

      if Pointer then
         CTN.Set_Is_Pointer (N, True);
      end if;

      return N;
   end Make_Defining_Identifier;

   ---------------------
   -- Make_Expression --
   ---------------------

   function Make_Expression
     (Left_Expr  : Node_Id;
      Operator   : Operator_Type := Op_None;
      Right_Expr : Node_Id := No_Node)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_Expression);
      Set_Left_Expression (N, Left_Expr);
      Set_Operator (N, Operator_Type'Pos (Operator));
      Set_Right_Expression (N, Right_Expr);
      return N;
   end Make_Expression;

   ------------------------
   -- Make_For_Statement --
   ------------------------

   function Make_For_Statement
     (Defining_Identifier : Node_Id;
      Pre_Cond            : Node_Id;
      Condition           : Node_Id;
      Post_Cond           : Node_Id;
      Statements          : List_Id)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_For_Statement);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Pre_Cond (N, Pre_Cond);
      Set_Condition (N, Condition);
      Set_Post_Cond (N, Post_Cond);
      Set_Statements (N, Statements);
      return N;
   end Make_For_Statement;

   ------------------
   -- Make_Literal --
   ------------------

   function Make_Literal (Value : Value_Id) return Node_Id is
      N : Node_Id;
   begin
      N := New_Node (K_Literal);
      CTN.Set_Value (N, Value);
      return N;
   end Make_Literal;

   -------------------------
   -- Make_Loop_Statement --
   -------------------------

   function Make_While_Statement
     (Condition           : Node_Id;
      Statements          : List_Id)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_While_Statement);
      Set_Condition (N, Condition);
      Set_Statements (N, Statements);
      return N;
   end Make_While_Statement;

   --------------------------------
   -- Make_Full_Type_Declaration --
   --------------------------------

   function Make_Full_Type_Declaration
     (Defining_Identifier : Node_Id;
      Type_Definition     : Node_Id)
     return Node_Id
   is
      N : Node_Id;

   begin
      N := New_Node (K_Full_Type_Declaration);
      Set_Type_Name (N, Defining_Identifier);
      Set_Type_Definition (N, Type_Definition);
      return N;
   end Make_Full_Type_Declaration;

   -----------------------
   -- Make_If_Statement --
   -----------------------

   function Make_If_Statement
     (Condition        : Node_Id;
      Statements       : List_Id;
      Else_Statements  : List_Id := No_List)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_If_Statement);
      Set_Condition (N, Condition);
      Set_Statements (N, Statements);
      Set_Else_Statements (N, Else_Statements);
      return N;
   end Make_If_Statement;

   ------------------
   -- Make_List_Id --
   ------------------

   function Make_List_Id
     (N1 : Node_Id;
      N2 : Node_Id := No_Node;
      N3 : Node_Id := No_Node)
     return List_Id
   is
      L : List_Id;
   begin
      L := New_List (K_List_Id);
      Append_Node_To_List (N1, L);
      if Present (N2) then
         Append_Node_To_List (N2, L);

         if Present (N3) then
            Append_Node_To_List (N3, L);
         end if;
      end if;
      return L;
   end Make_List_Id;

   ----------------------------------
   -- Make_Parameter_Specification --
   ----------------------------------

   function Make_Parameter_Specification
     (Defining_Identifier : Node_Id;
      Parameter_Type      : Node_Id := No_Node)
     return                Node_Id
   is
      P : Node_Id;

   begin
      P := New_Node (K_Parameter_Specification);
      Set_Defining_Identifier (P, Defining_Identifier);
      Set_Parameter_Type (P, Parameter_Type);
      return P;
   end Make_Parameter_Specification;

   ---------------------------
   -- Make_Return_Statement --
   ---------------------------

   function Make_Return_Statement
     (Expression : Node_Id := No_Node)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_Return_Statement);
      if Expression /= No_Node then
         Set_Expression (N, Expression);
      end if;
      return N;
   end Make_Return_Statement;

   ---------------------------------
   -- Make_Function_Specification --
   ---------------------------------

   function Make_Function_Specification
     (Defining_Identifier     : Node_Id;
      Parameters              : List_Id := No_List;
      Return_Type             : Node_Id := No_Node)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node           (K_Function_Specification);
      Set_Parameters          (N, Parameters);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Return_Type         (N, Return_Type);
      return N;
   end Make_Function_Specification;

   ----------------------------------
   -- Make_Function_Implementation --
   ----------------------------------

   function Make_Function_Implementation
     (Specification : Node_Id;
      Declarations  : List_Id;
      Statements    : List_Id)

     return Node_Id
   is
      N : Node_Id;

   begin
      N := New_Node (K_Function_Implementation);
      Set_Specification (N, Specification);
      CTN.Set_Declarations (N, Declarations);
      Set_Statements (N, Statements);
      return N;
   end Make_Function_Implementation;

   -----------------------------
   -- Make_Member_Declaration --
   -----------------------------

   function Make_Member_Declaration
     (Defining_Identifier : Node_Id;
      Used_Type           : Node_Id)
     return                Node_Id
   is
      P : Node_Id;
   begin
      P := New_Node (K_Member_Declaration);
      Set_Defining_Identifier (P, Defining_Identifier);
      Set_Used_Type (P, Used_Type);
      return P;
   end Make_Member_Declaration;

   -------------------------------
   -- Make_Variable_Declaration --
   -------------------------------

   function Make_Variable_Declaration
     (Defining_Identifier : Node_Id;
      Used_Type           : Node_Id)
     return                Node_Id
   is
      P : Node_Id;
   begin
      P := New_Node (K_Variable_Declaration);
      Set_Defining_Identifier (P, Defining_Identifier);
      Set_Used_Type (P, Used_Type);
      return P;
   end Make_Variable_Declaration;

   ---------------------------
   -- Make_Variable_Address --
   ---------------------------

   function Make_Variable_Address
     (Expression : Node_Id)
     return                Node_Id
   is
      P : Node_Id;
   begin
      P := New_Node (K_Variable_Address);
      Set_Expression (P, Expression);
      return P;
   end Make_Variable_Address;

   ------------------------------------
   -- Make_Extern_Entity_Declaration --
   ------------------------------------

   function Make_Extern_Entity_Declaration
     (Entity : Node_Id)
     return                Node_Id
   is
      P : Node_Id;
   begin
      P := New_Node (K_Extern_Entity_Declaration);
      CTN.Set_Entity (P, Entity);
      return P;
   end Make_Extern_Entity_Declaration;

   ---------------------------
   -- Make_Struct_Aggregate --
   ---------------------------

   function Make_Struct_Aggregate
     (Defining_Identifier : Node_Id := No_Node;
      Members             : List_Id)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_Struct_Aggregate);
      if Defining_Identifier /= No_Node then
         Set_Defining_Identifier (N, Defining_Identifier);
      end if;
      Set_Struct_Members (N, Members);
      return N;
   end Make_Struct_Aggregate;

   --------------------------
   -- Make_Union_Aggregate --
   --------------------------

   function Make_Union_Aggregate
     (Defining_Identifier : Node_Id := No_Node;
      Members             : List_Id)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_Union_Aggregate);
      if Defining_Identifier /= No_Node then
         Set_Defining_Identifier (N, Defining_Identifier);
      end if;
      Set_Union_Members (N, Members);
      return N;
   end Make_Union_Aggregate;

   -------------------------
   -- Make_Enum_Aggregate --
   -------------------------

   function Make_Enum_Aggregate
     (Members    : List_Id)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_Enum_Aggregate);
      Set_Enum_Members (N, Members);
      return N;
   end Make_Enum_Aggregate;

   -----------------------
   -- Make_Call_Profile --
   -----------------------

   function Make_Call_Profile
     (Defining_Identifier   : Node_Id;
      Parameters : List_Id := No_List)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_Call_Profile);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Parameters (N, Parameters);
      return N;
   end Make_Call_Profile;

   ---------------------
   -- Make_Macro_Call --
   ---------------------

   function Make_Macro_Call
     (Defining_Identifier   : Node_Id;
      Parameters : List_Id := No_List)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_Macro_Call);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Parameters (N, Parameters);
      return N;
   end Make_Macro_Call;

   -------------------------
   -- Make_Type_Attribute --
   -------------------------

   function Make_Type_Attribute
     (Designator : Node_Id;
      Attribute  : Attribute_Id)
     return Node_Id
   is
      procedure Get_Scoped_Name_String (S : Node_Id);

      ----------------------------
      -- Get_Scoped_Name_String --
      ----------------------------

      procedure Get_Scoped_Name_String (S : Node_Id) is
      begin
         Get_Name_String_And_Append (CTN.Name (Defining_Identifier (S)));
      end Get_Scoped_Name_String;

   begin
      Name_Len := 0;
      Get_Scoped_Name_String (Designator);
      Add_Char_To_Name_Buffer (''');
      Get_Name_String_And_Append (AN (Attribute));
      return Make_Defining_Identifier (Name_Find);
   end Make_Type_Attribute;

   --------------------------
   -- Make_Type_Conversion --
   --------------------------

   function Make_Type_Conversion
     (Subtype_Mark : Node_Id;
      Expression   : Node_Id)
     return Node_Id
   is
      N : Node_Id;
   begin
      N := New_Node (K_Type_Conversion);
      Set_Subtype_Mark (N, Subtype_Mark);
      Set_Expression (N, Expression);
      return N;
   end Make_Type_Conversion;

   -------------------------
   -- Make_Comment_Header --
   -------------------------

   procedure Make_Comment_Header (Header : List_Id) is
      N : Node_Id;
   begin
      --  Appending the comment header lines to the file header

      Set_Str_To_Name_Buffer
        ("***************************************************");
      N := Make_C_Comment (Name_Find, False);
      Append_Node_To_List (N, Header);

      Set_Str_To_Name_Buffer
        ("This file was automatically generated by Ocarina ");
      N := Make_C_Comment (Name_Find);
      Append_Node_To_List (N, Header);

      Set_Str_To_Name_Buffer
        ("Do NOT hand-modify this file, as your            ");
      N := Make_C_Comment (Name_Find);
      Append_Node_To_List (N, Header);

      Set_Str_To_Name_Buffer
        ("changes will be lost when you re-run Ocarina     ");
      N := Make_C_Comment (Name_Find);
      Append_Node_To_List (N, Header);

      Set_Str_To_Name_Buffer
        ("***************************************************");
      N := Make_C_Comment (Name_Find, False);
      Append_Node_To_List (N, Header);

   end Make_Comment_Header;

   -----------------
   -- Next_N_Node --
   -----------------

   function Next_N_Node (N : Node_Id; Num : Natural) return Node_Id is
      Result : Node_Id := N;
   begin
      for I in 1 .. Num loop
         Result := CTN.Next_Node (Result);
      end loop;

      return Result;
   end Next_N_Node;

   --------------
   -- New_List --
   --------------

   function New_List
     (Kind : CTN.Node_Kind;
      From : Node_Id := No_Node)
     return List_Id is
      N : Node_Id;

   begin
      CTN.Entries.Increment_Last;
      N := CTN.Entries.Last;
      CTN.Entries.Table (N) := CTN.Default_Node;
      Set_Kind (N, Kind);
      if Present (From) then
         CTN.Set_Loc  (N, CTN.Loc (From));
      else
         CTN.Set_Loc  (N, No_Location);
      end if;
      return List_Id (N);
   end New_List;
For faster browsing, not all history is shown. View entire blame