ocarina-backends-ada_tree-generator-spark.adb 6.92 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--                OCARINA.BACKENDS.ADA_TREE.GENERATOR.SPARK                 --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--       Copyright (C) 2009 Telecom ParisTech, 2010-2015 ESA & ISAE.        --
10
--                                                                          --
11
12
13
14
15
16
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. 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.                     --
17
--                                                                          --
18
19
20
21
22
23
24
25
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27
28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29
30
31
--                                                                          --
------------------------------------------------------------------------------

yoogx's avatar
yoogx committed
32
33
with Ocarina.Namet;  use Ocarina.Namet;
with Ocarina.Output; use Ocarina.Output;
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

with Ocarina.Backends.Ada_Tree.Nodes;
with Ocarina.Backends.Ada_Tree.Nutils;
with Ocarina.Backends.Ada_Tree.Generator;
package body Ocarina.Backends.Ada_Tree.Generator.Spark is

   use Ocarina.Backends.Ada_Tree.Generator;
   use Ocarina.Backends.Ada_Tree.Nodes;
   use Ocarina.Backends.Ada_Tree.Nutils;

   procedure Write (T : Token_Type);

   -----------
   -- Write --
   -----------

   procedure Write (T : Token_Type) is
   begin
      Write_Name (Token_Image (T));
   end Write;

   ----------------------------------
   -- Generate_Inherit_Annotations --
   ----------------------------------

   procedure Generate_Inherit_Annotations (N : Node_Id) is
      P  : Node_Id;
      LS : List_Id := No_List;
      LB : List_Id := No_List;
   begin

      --  Initialize withed package lists for a package specification
      if Kind (N) = K_Package_Specification then
         LS := Withed_Packages (N);
68
69
70
         LB :=
           Withed_Packages (Package_Implementation (Package_Declaration (N)));
      --  Initialize withed package lists for a subprogram specification
71
72
      elsif Kind (N) = K_Subprogram_Specification then
         LS := Withed_Packages (N);
73
74
75
76
77
78
         if Subprogram_Implementation (Main_Subprogram_Unit (N)) /=
           No_Node
         then
            LB :=
              Withed_Packages
                (Subprogram_Implementation (Main_Subprogram_Unit (N)));
79
         end if;
80
81
      --  Initialize withed package lists for a subprogram implementation
      elsif Kind (N) = K_Subprogram_Implementation then
82
83
         LS := Withed_Packages (N);
         if Subprogram_Specification (Main_Subprogram_Unit (N)) /= No_Node then
84
85
86
            LB :=
              Withed_Packages
                (Subprogram_Specification (Main_Subprogram_Unit (N)));
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
         end if;
      end if;

      --  inherit clauses for package specification
      if not Is_Empty (LS) then
         Increment_Indentation;
         Write (Tok_Annotation);
         Write_Space;
         Write (Tok_Inherit);
         Write_Space;
         P := First_Node (LS);
         loop
            Generate (Defining_Identifier (P));
            P := Next_Node (P);
            exit when No (P);
            Write (Tok_Comma);
            Write_Eol;
            Write (Tok_Annotation);
            Write_Indentation (7);
         end loop;
      end if;

      --  inherit clauses for package implementation
      if Is_Empty (Withed_Packages (N)) and then not Is_Empty (LB) then
         Increment_Indentation;
         Write (Tok_Annotation);
         Write_Space;
         Write (Tok_Inherit);
         Write_Space;
      elsif not Is_Empty (LS) and then not Is_Empty (LB) then
         Write (Tok_Comma);
         Write_Eol;
         Write (Tok_Annotation);
         Write_Indentation (7);
      end if;
      if not Is_Empty (LB) then
         P := First_Node (LB);
         loop
            Generate (Defining_Identifier (P));
            P := Next_Node (P);
            exit when No (P);
            Write (Tok_Comma);
            Write_Eol;
            Write (Tok_Annotation);
            Write_Indentation (7);
         end loop;
      end if;
      if not Is_Empty (LS) or else not Is_Empty (LB) then
         Write (Tok_Semicolon);
         Write_Eol;
         Decrement_Indentation;
      end if;
   end Generate_Inherit_Annotations;

   -----------------------------
   -- Generate_Own_Annotation --
   -----------------------------

   procedure Generate_Own_Annotation (N : Node_Id) is
   begin

      case Own_Mode (N) is
         when Mode_In =>
            null;

         when Mode_Out =>
            Write (Tok_Out);
            Write_Space;

         when Mode_Inout =>
            Write (Tok_In);
            Write_Space;
            Write (Tok_Out);
            Write_Space;
      end case;

      if Is_Protected (N) then
         Write (Tok_Protected);
         Write_Space;
      end if;
      Generate (Variable (N));
   end Generate_Own_Annotation;

   ----------------------------------
   -- Generate_Own_Annotation_List --
   ----------------------------------

   procedure Generate_Own_Annotation_List (L : List_Id) is
      P : Node_Id;
   begin
      P := First_Node (L);
      Write (Tok_Annotation);
      Write_Space;
      Write (Tok_Own);
      loop
         Write_Indentation;
         Write_Space;
         Generate (P);
         P := Next_Node (P);
         exit when No (P);
         Write (Tok_Semicolon);
         Write_Eol;
         Write (Tok_Annotation);
      end loop;
      Write (Tok_Semicolon);
      Write_Eol;
   end Generate_Own_Annotation_List;

end Ocarina.Backends.Ada_Tree.Generator.Spark;