ocarina-fe_aadl-parser-components-prototypes.adb 8.63 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--              OCARINA.FE_AADL.PARSER.COMPONENTS.PROTOTYPES                --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
yoogx's avatar
yoogx committed
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
--                                                                          --
------------------------------------------------------------------------------

--  This package gathers all the functions that are related to prototype
--  parsing.

with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Locations;

with Ocarina.ME_AADL.AADL_Tree.Nutils;

with Ocarina.ME_AADL.Tokens;
with Ocarina.FE_AADL.Lexer;
with Ocarina.FE_AADL.Parser.Identifiers;
with Ocarina.FE_AADL.Parser.Components;

with Ocarina.Builder.AADL.Components;
with Ocarina.Builder.AADL.Components.Prototypes;

package body Ocarina.FE_AADL.Parser.Components.Prototypes is

   -----------------------------------------
   -- P_Prototype_Or_Prototype_Refinement --
   -----------------------------------------

   --  AADL_V2

   --  prototype ::= defining_prototype_identifier : component_category
   --   [ unique_component_classifier_reference ]

   --  prototype_refinement ::= defining_prototype_identifier : refined to
   --      component_category [ unique_component_classifier_reference ] ;

   function P_Prototype_Or_Prototype_Refinement
63
     (Container : Ocarina.Types.Node_Id;
64
      Refinable : Boolean) return Node_Id
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
   is
      use Locations;
      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Ocarina.ME_AADL.Tokens;
      use Lexer;
      use Parser.Identifiers;
      use Ocarina.Builder.AADL.Components.Prototypes;

      Loc            : Location;
      Identifier     : Node_Id;
      Prototype      : Node_Id;
      Classifier_Ref : Node_Id;
      Category       : Component_Category;
      Code           : Parsing_Code;
      Is_Refinement  : Boolean;
      OK             : Boolean;
   begin
      P_Identifier_Refined_To
        (Refinable_To_RT (Refinable),
         False,
         PC_Prototype,
         PC_Prototype_Refinement,
         T_Semicolon,
         Identifier,
         Is_Refinement,
         OK);

      if not OK then
         return No_Node;
      end if;

      if Is_Refinement then
         Code := PC_Prototype;
      else
         Code := PC_Prototype_Refinement;
      end if;

      Scan_Token;
      Category := P_Component_Category;

      if Category = CC_Unknown then
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_Identifier then
         Restore_Lexer (Loc);
         Classifier_Ref := P_Entity_Reference (Code);

         if No (Classifier_Ref) then
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      else
         Classifier_Ref := No_Node;
         Restore_Lexer (Loc);
      end if;

126
127
128
129
130
131
132
133
      Prototype :=
        Add_New_Prototype
          (Loc            => Ocarina.ME_AADL.AADL_Tree.Nodes.Loc (Identifier),
           Name           => Identifier,
           Container      => Container,
           Classifier_Ref => Classifier_Ref,
           Category       => Category,
           Is_Refinement  => Is_Refinement);
134
135
136

      Save_Lexer (Loc);
      Scan_Token;
137
      if Token /= T_Semicolon or else Prototype = No_Node then
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
         DPE (Code, T_Semicolon);
         Restore_Lexer (Loc);
         return No_Node;
      end if;

      return Prototype;
   end P_Prototype_Or_Prototype_Refinement;

   --------------------------
   -- P_Prototype_Bindings --
   --------------------------

   --  AADL_V2

   --  prototype_bindings ::=
   --   ( prototype_binding ( , prototype_ binding )* )

yoogx's avatar
yoogx committed
155
156
   function P_Prototype_Bindings (Container : Ocarina.Types.Node_Id)
                                 return Boolean is
157
158
159
160
161
162
163
164
      use Locations;
      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Ocarina.ME_AADL.AADL_Tree.Nutils;
      use Ocarina.ME_AADL.Tokens;
      use Lexer;

      Loc                : Location;
      Prototype_Bindings : List_Id;
165
      Success            : Boolean := True;
166
167
168
169
170
171
172
173
174
   begin
      Save_Lexer (Loc);

      if Token /= T_Left_Parenthesis then
         DPE (PC_Prototype_Bindings, T_Left_Parenthesis);
         Skip_Tokens (T_Semicolon);
         Success := False;
      end if;

175
176
177
178
179
180
181
182
      Prototype_Bindings :=
        P_Items_List
          (P_Prototype_Binding'Access,
           Container,
           T_Comma,
           T_Right_Parenthesis,
           PC_Prototype_Bindings,
           False);
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
      if Is_Empty (Prototype_Bindings) then
         DPE (PC_Prototype_Bindings, EMC_List_Is_Empty);
         Skip_Tokens (T_Semicolon);
         return Success;
      else
         Set_Prototype_Bindings (Container, Prototype_Bindings);
         Success := True;
      end if;

      return Success;
   end P_Prototype_Bindings;

   -------------------------
   -- P_Prototype_Binding --
   -------------------------

   --  AADL_V2

   --  prototype_binding ::=
   --   prototype_identifier => component_category
   --    ( unique_component_classifier_reference |prototype_identifier )

yoogx's avatar
yoogx committed
205
   function P_Prototype_Binding
yoogx's avatar
yoogx committed
206
     (Container : Ocarina.Types.Node_Id) return Node_Id is
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
      use Locations;
      use Ocarina.ME_AADL.Tokens;
      use Lexer;
      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Ocarina.FE_AADL.Parser.Identifiers;
      use Ocarina.Builder.AADL.Components.Prototypes;

      Start_Loc         : Location;
      Loc               : Location;
      Identifier        : Node_Id;
      Classifier_Ref    : Node_Id;
      Prototype_Binding : Node_Id;
      Category          : Component_Category;
   begin
      Save_Lexer (Start_Loc);

      Identifier := P_Identifier (Container);
      if Identifier = No_Node then
         DPE (PC_Prototype_Binding);
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      Save_Lexer (Loc);
      Scan_Token;

      if Token /= T_Association then
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      Save_Lexer (Loc);
      Scan_Token;

      Category := P_Component_Category;
      if Category = CC_Unknown then
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      Classifier_Ref := P_Entity_Reference (PC_Prototype_Binding);
      if Classifier_Ref = No_Node then
         DPE (PC_Prototype_Binding);
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

254
255
256
257
258
259
260
      Prototype_Binding :=
        Add_New_Prototype_Binding
          (Start_Loc,
           Identifier,
           Container,
           Classifier_Ref,
           Category);
261
262
263
264
265
266
267
268
269
270
271

      if Prototype_Binding = No_Node then
         DPE (PC_Prototype_Binding);
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      return Prototype_Binding;
   end P_Prototype_Binding;

end Ocarina.FE_AADL.Parser.Components.Prototypes;