ocarina-fe_aadl-parser-annexes.adb 9.68 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--       O C A R I N A . F E _ A A D L . P A R S E R . A N N E X E S        --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE.      --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--                                                                          --
-- 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.                     --
--                                                                          --
-- 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
--                                                                          --
------------------------------------------------------------------------------

with Locations;
with Ocarina.FE_AADL.Lexer;
with Ocarina.FE_AADL.Parser.Identifiers;
with Ocarina.FE_AADL.Parser.Components.Modes;
with Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.Tokens;
with Ocarina.Builder.AADL.Annexes;
with Ocarina.Parser;
with Ocarina.Options;

package body Ocarina.FE_AADL.Parser.Annexes is

   function P_Annex
     (Namespace           : Types.Node_Id;
      Code                : Parsing_Code;
48
      Private_Declaration : Boolean) return Node_Id;
49
50
51
52
53
54
55
56
57
   --  Parse Annex_Library or Annex_Subclause, current token must be 'annex'

   -------------
   -- P_Annex --
   -------------

   function P_Annex
     (Namespace           : Types.Node_Id;
      Code                : Parsing_Code;
58
59
      Private_Declaration : Boolean) return Node_Id
   is
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

      use Lexer;
      use Locations;
      use Ocarina.FE_AADL.Parser.Identifiers;
      use Ocarina.FE_AADL.Parser.Components.Modes;
      use Ocarina.ME_AADL.Tokens;
      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Ocarina.Builder.AADL.Annexes;
      use Ocarina.Parser;
      use Ocarina.Options;

      Annex           : Node_Id;   --  output
      Annex_Root      : Node_Id           := No_Node;
      Identifier      : Node_Id;
      In_Modes        : Node_Id           := No_Node;
      Loc             : Location;
      Loc_Start_Annex : Location;
77
      Annex_Content   : Name_Id           := No_Name;
78
79
80
81
82
83
84
85
86
87
88
89
      Annex_Location  : constant Location := Token_Location;
   begin

      Identifier := P_Identifier (No_Node);
      if Identifier = No_Node then
         DPE (Code, T_Identifier);
         Skip_Tokens ((T_End_Annex, T_Semicolon));
         return No_Node;
      end if;

      Scan_Token;

90
      if AADL_Version = AADL_V2 and then Token = T_None then
91
92
93
94
         Annex_Content := No_Name;
      elsif Token = T_Begin_Annex then
         Save_Lexer (Loc_Start_Annex);
         if Perform_Annex_Action (Name (Identifier)) then
95
96
97
98
99
100
            Annex_Root := Parse
              (Name (Identifier),
               No_Node,
               Loc_Start_Annex,
               No_Location,
               Namespace);
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
         end if;

         --  Do not display error message if No_Node because if there are
         --  errors when annex parsing, errors messages were already displaying
         --  so continue to parse AADL_Specification and just raise a warning

         if No (Annex_Root) then
            Restore_Lexer (Loc_Start_Annex);
            Scan_Raw_Text (T_End_Annex);
            Annex_Content := Raw_Text_Value;
         end if;

         Scan_Token;
         if Token /= T_End_Annex then
            DPE (Code, T_End_Annex);
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      else
         DPE (Code, T_Begin_Annex);
         Skip_Tokens ((T_End_Annex, T_Semicolon));
         return No_Node;
      end if;

      Save_Lexer (Loc);
      Scan_Token;

      --  AADLv2 Parse In_Modes in Annex_Subclause
      if AADL_Version = AADL_V2
        and then Code = PC_Annex_Subclause
        and then Token = T_In
      then
         In_Modes := P_In_Modes (PC_In_Modes);

         if No (In_Modes) then
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;

         Save_Lexer (Loc);
         Scan_Token;
      end if;

      if Token /= T_Semicolon then
         DPE (Code, T_Semicolon);
         Restore_Lexer (Loc);
         return No_Node;
      end if;

      if Code = PC_Annex_Library then
151
152
153
154
155
156
         Annex :=
           Add_New_Annex_Library
             (Annex_Location,
              Identifier,
              Namespace,
              Is_Private => Private_Declaration);
157
      else
158
159
160
161
162
163
         Annex :=
           Add_New_Annex_Subclause
             (Annex_Location,
              Identifier,
              Namespace,
              In_Modes);
164
165
      end if;

166
167
      if Present (Annex) then
         Set_Annex_Content (Annex, Annex_Content);
168
169
170
171
172

         if Code = PC_Annex_Subclause then
            Set_Corresponding_Annex (Annex, Annex_Root);
         end if;

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
         return Annex;
      else
         return No_Node;
      end if;
   end P_Annex;

   ---------------------
   -- P_Annex_Library --
   ---------------------

   --  annex_library ::=
   --     annex annex_identifier
   --       ( ( {** annex_specific_reusable_constructs **} ) | none ) ;

   function P_Annex_Library
     (Namespace           : Types.Node_Id;
189
190
      Private_Declaration : Boolean := False) return Node_Id
   is
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
   begin
      return P_Annex (Namespace, PC_Annex_Library, Private_Declaration);
   end P_Annex_Library;

   -----------------------
   -- P_Annex_Subclause --
   -----------------------

   --  annex_subclause ::=
   --     annex annex_identifier
   --       ( ( {** annex_specific_language_constructs **} ) | none )
   --       [ in_modes ];

   function P_Annex_Subclause (Namespace : Types.Node_Id) return Node_Id is
   begin
      return P_Annex (Namespace, PC_Annex_Subclause, False);
   end P_Annex_Subclause;

   ------------------
   -- P_Annex_Path --
   ------------------

   --  AADL_V2
   --  annex_path ::=
   --     [ { annex_identifier } ] { ** model_element_identifier }+

   function P_Annex_Path (Container : Types.Node_Id) return Node_Id is

      use Lexer;
      use Locations;
      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Ocarina.ME_AADL.AADL_Tree.Nutils;
      use Ocarina.FE_AADL.Parser.Identifiers;
      use Ocarina.ME_AADL.Tokens;
      use Ocarina.Builder.AADL.Annexes;

      Start_Loc        : Location;
      Loc              : Location;
229
230
231
      Annex_Identifier : Node_Id := No_Node;
      Elt_Identifier   : Node_Id := No_Node;
      List_Identifiers : List_Id := No_List;
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
      Annex_Node       : Node_Id;
   begin
      Save_Lexer (Start_Loc);

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_Left_Curly_Bracket then
         Annex_Identifier := P_Identifier (No_Node);

         Scan_Token;
         if Token /= T_Right_Curly_Bracket then
            DPE (PC_Annex_Path);
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      else
         Restore_Lexer (Loc);
      end if;

      Save_Lexer (Loc);
      Scan_Token;

      List_Identifiers := New_List (K_List_Id, Loc);

      loop
         if Token = T_Multiply then
            Save_Lexer (Loc);
            Scan_Token;

            if Token /= T_Multiply then
               DPE (PC_Annex_Path);
               Skip_Tokens (T_Semicolon);
               return No_Node;
            else
               Elt_Identifier := P_Identifier (No_Node);

               if No (Elt_Identifier) then
                  DPE (PC_Annex_Path, T_Identifier);
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
               else
                  Append_Node_To_List (Elt_Identifier, List_Identifiers);
               end if;
            end if;

         else
            exit;
         end if;
      end loop;

      if Is_Empty (List_Identifiers) then
         DPE (PC_Annex_Path, EMC_List_Is_Empty);
         Skip_Tokens (T_Semicolon);
         return No_Node;
      else
288
289
290
291
292
293
         Annex_Node :=
           Add_New_Annex_Path
             (Start_Loc,
              Container,
              Annex_Identifier,
              List_Identifiers);
294
295
296
297
298
299
300
301
302
303
304
305
306
      end if;

      if No (Annex_Node) then
         DPE (PC_Annex_Path);
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      return Annex_Node;

   end P_Annex_Path;

end Ocarina.FE_AADL.Parser.Annexes;