ocarina-fe_aadl-parser-components-connections.adb 24.2 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--              OCARINA.FE_AADL.PARSER.COMPONENTS.CONNECTIONS               --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--          Copyright (C) 2008-2011, European Space Agency (ESA).           --
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
--                                                                          --
-- 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 Locations;
with Ocarina.FE_AADL.Lexer;
with Ocarina.FE_AADL.Parser.Identifiers;
with Ocarina.FE_AADL.Parser.Components.Modes;
with Ocarina.FE_AADL.Parser.Properties;

with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.Tokens;

with Ocarina.Builder.AADL.Components.Connections;

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

   function P_Connection_Reference
     (Code : Parsing_Code)
     return Types.Node_Id;

   ------------------
   -- P_Connection --
   ------------------

   --  AADL_V1
   --  connection ::=
   --     port_connection | parameter_connection | access_connection

   --  connection_refinement ::=   port_connection_refinement
   --                            | parameter_connection_refinement
   --                            | access_connection_refinement

   --  port_connection ::=   data_connection | event_connection
   --                      | event_data_connection | port_group_connection

   --  data_connection ::= [ defining_data_connection_identifier :]
   --     data port source_unique_port_identifier
   --               ( immediate_connection_symbol | delayed_connection_symbol )
   --               destination_unique_port_identifier
   --        [ { { property_association }+ } ] [ in_modes_and_transitions ] ;

   --  immediate_connection_symbol ::= ->
   --  delayed_connection_symbol   ::= ->>

   --  event_connection ::= [ defining_event_connection_identifier :]
   --     event port source_unique_port_identifier
   --             -> destination_unique_port_identifier
   --        [ { { property_association }+ } ] [ in_modes_and_transitions ] ;

   --  event_data_connection ::= [ defining_event_data_connection_identifier :]
   --     event data port source_unique_port_identifier
   --                  -> destination_unique_port_identifier
   --        [ { { property_association }+ } ] [ in_modes_and_transitions ] ;

   --  port_group_connection ::= [ defining_port_group_connection_identifier :]
   --     port group source_unique_port_group_identifier
   --             -> destination_unique_port_group_identifier
   --        [ { { property_association }+ } ] [ in_modes_and_transitions ] ;

   --  port_connection_refinement ::=
   --     connection_identifier : refined to
   --     ( data port | event port | event data port | port group )
   --        ( ( { { property_association }+ } [ in_modes_and_transitions ] )
   --          | in_modes_and_transitions ) ;

   --  parameter_connection ::= [ defining_parameter_connection_identifier :]
   --     parameter source_unique_parameter_identifier
   --            -> destination_unique_parameter_identifier
   --        [ { { property_association }+ } ] [ in_modes ] ;

   --  parameter_connection_refinement ::=
   --     connection_identifier : refined to parameter
   --       { { property_association }+ } [ in_modes ] ;

   --  access_connection ::= [ access_connection_identifier :]
   --     ( bus | data ) access unique_access provider_identifier
   --                        -> unique_access_requirer_identifier
   --       [ { { property_association }+ } ] [ in_modes ] ;

   --  access_connection_refinement ::=
   --     connection_identifier : refined to ( bus | data ) access
   --       { { property_association }+ } [ in_modes ] ;

   --  AADL_V2
   --  connection ::=
   --     [ defining_connection_identifier : ]
   --         ( feature_connection | port_connection | parameter_connection
   --           | access_connection | feature_group_connection )
   --          [ { { property_association }+ } ]
   --          [ in_modes_and_transitions ] ;

   --  connection_refinement ::=
   --     defining_connection_identifier : refined to
   --       [ feature_connection_refinement | port_connection_refinement
   --         | parameter_connection_refinement | access_connection_refinement
   --         | feature_group_connection_refinement ]
   --       [ { { property_association }+ } ]
   --       [ in_modes_and_transitions ] ;

   --  feature_connection ::=
   --     source_feature_reference connection_symbol
   --     destination_feature_reference

   --  connection_symbol ::=
   --     directional_connection_symbol | bidirectional_connection_symbol

   --  directional_connection_symbol ::= ->
   --  bidirectional_connection_symbol ::= <->

   --  feature_connection_refinement ::=
   --     source_feature_reference connection_symbol
   --     destination_feature_reference

   --  port_connection ::=
   --     port source_port_connection_reference connection_symbol
   --     destination_port_connection_reference

   --  port_connection_refinement ::=
   --     port [ source_port_connection_reference connection_symbol
   --     destination_port_connection_reference ]

   --  Note: data port, event data port, and event port connections
   --  are replaced by port connections in AADL V2

   --  parameter_connection ::=
   --     parameter source_parameter_reference directional_connection_symbol
   --     destination_parameter_reference

   --  parameter_connection_refinement ::=
   --     parameter

   --  access_connection ::=
   --     [ bus | subprogram | subprogram group | data ] access
   --     access_provider_reference connection_symbol access_requirer_reference

   --  access_connection_refinement ::=
   --     [ bus | subprogram | subprogram group | data ] access

   --  feature_group_connection ::=
   --     feature group source_feature_group_reference
   --       bidirectional_connection_symbol destination_feature_group_reference

   --  feature_group_connection_refinement ::=
   --     feature group

   function P_Connection
     (Container : Types.Node_Id;
      Refinable : Boolean)
     return Types.Node_Id
   is
      use Locations;
      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Lexer;
      use Ocarina.ME_AADL.Tokens;
      use Ocarina.FE_AADL.Parser.Identifiers;
      use Ocarina.FE_AADL.Parser.Components.Modes;
      use Ocarina.FE_AADL.Parser.Properties;
      use Ocarina.Builder.AADL.Components.Connections;

      Connection      : Node_Id;
      Identifier      : Node_Id;
      Is_Refinement   : Boolean;
      Is_Bidirect     : Boolean          := False;
      Category        : Connection_Type;
      Source          : Node_Id          := No_Node;
      Destination     : Node_Id          := No_Node;
      In_Modes        : Node_Id;
      OK              : Boolean;
      Code            : Parsing_Code;
      Loc             : Location;
      Start_Loc       : Location         := No_Location;
      Properties_Loc  : Location;

   begin
      P_Identifier_Refined_To (Refinable_To_RT (Refinable), True,
                               PC_Connection, PC_Connection_Refinement,
                               T_Semicolon, Identifier, Is_Refinement, OK);
      if not OK then
         return No_Node;
      end if;

      if Present (Identifier) then
         --  update Start_Loc
         Start_Loc := Ocarina.ME_AADL.AADL_Tree.Nodes.Loc (Identifier);
      end if;

      if Is_Refinement then
         Code := PC_Connection_Refinement;
      else
         Code := PC_Connection;
      end if;

      --  parsing connection category
      Save_Lexer (Loc);
      Scan_Token;

      if Start_Loc = No_Location then
         Start_Loc := Token_Location;
      end if;

      case Token is
         when T_Data =>        --  data_connection or access_connection
            Scan_Token;

            case Token is
               when T_Port =>      --  data_connection
                  if AADL_Version = AADL_V1 then
                     Category := CT_Data;

                     if Is_Refinement then
                        Code := PC_Data_Connection_Refinement;
                     else
                        Code := PC_Data_Connection;
                     end if;
                  else
                     DPE (PC_Data_Connection, EMC_Not_Allowed_In_AADL_V2);
                     Skip_Tokens (T_Semicolon);
                     return No_Node;
                  end if;

               when T_Access =>    --  access_connection
                  Category := CT_Access_Data;
                  if Is_Refinement then
                     Code := PC_Access_Connection_Refinement;
                  else
                     Code := PC_Access_Connection;
                  end if;

               when others =>
                  DPE (Code, (T_Port, T_Access));
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
            end case;

         when T_Event =>       --  event_connection or event_data_connection
            if AADL_Version = AADL_V1 then
               Scan_Token;
               case Token is
                  when T_Data =>      --  event_data_connection
                     if Is_Refinement then
                        Code := PC_Event_Data_Connection_Refinement;
                     else
                        Code := PC_Event_Data_Connection;
                     end if;

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

                     Category := CT_Event_Data;

                  when T_Port =>      --  event_connection

                     Category := CT_Event;
                     if Is_Refinement then
                        Code := PC_Event_Connection_Refinement;
                     else
                        Code := PC_Event_Connection;
                     end if;

                  when others =>
                     DPE (PC_Event_Data_Connection, ((T_Data, T_Port)));
                     Skip_Tokens (T_Semicolon);
                     return No_Node;
               end case;
            else
               DPE (PC_Event_Data_Connection, EMC_Not_Allowed_In_AADL_V2);
               Skip_Tokens (T_Semicolon);
               return No_Node;
            end if;

         when T_Port =>  --  port_group_connection
            if AADL_Version = AADL_V1 then
               if Is_Refinement then
                  Code := PC_Feature_Group_Connection_Refinement;
               else
                  Code := PC_Feature_Group_Connection;
               end if;

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

               Category := CT_Feature_Group;
            else
               if Is_Refinement then
                  Code := PC_Port_Connection_Refinement;
               else
                  Code := PC_Port_Connection;
               end if;
               Category := CT_Port_Connection;
               --  represent event, event data and data connection in AADL_V2

            end if;

         when T_Feature =>  --  feature_group_connection
            if AADL_Version = AADL_V2 then
               if Is_Refinement then
                  Code := PC_Feature_Group_Connection_Refinement;
               else
                  Code := PC_Feature_Group_Connection;
               end if;

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

               Category := CT_Feature_Group;
            else
               DPE (PC_Feature_Group_Connection, EMC_Not_Allowed_In_AADL_V1);
               Skip_Tokens (T_Semicolon);
               return No_Node;
            end if;

         when T_Parameter =>   --  parameter_connection
            Category := CT_Parameter;
            if Is_Refinement then
               Code := PC_Parameter_Connection_Refinement;
            else
               Code := PC_Parameter_Connection;
            end if;

         when T_Bus =>         --  access_connection
            if Is_Refinement then
               Code := PC_Access_Connection_Refinement;
            else
               Code := PC_Access_Connection;
            end if;

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

            Category := CT_Access_Bus;

         when T_Subprogram =>
            if AADL_Version = AADL_V2 then

               if Is_Refinement then
                  Code := PC_Access_Connection_Refinement;
               else
                  Code := PC_Access_Connection;
               end if;

               Scan_Token;
               if Token = T_Group then
                  Category := CT_Access_Subprogram_Group;
                  Scan_Token;
               else
                  Category := CT_Access_Subprogram;
               end if;

               if Token /= T_Access then
                  DPE (Code, T_Access);
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
               end if;

            else
               DPE (PC_Connection, EMC_Not_Allowed_In_AADL_V2);
               Skip_Tokens (T_Semicolon);
               return No_Node;
            end if;

         when T_Virtual =>
            Scan_Token;
            if Token /= T_Bus then
               DPE (PC_Connection, T_Bus);
               Skip_Tokens (T_Semicolon);
               return No_Node;
            end if;

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

            Category := CT_Access_Virtual_Bus;

425
426
427
428
429
430
431
432
433
         when T_Access =>
            --  In AADLv2, we can have just
            if AADL_Version = AADL_V2 then
               Category := CT_Access;

            else
               raise Program_Error;
            end if;

434
435
436
437
438
439
440
441
442
443
444
445
         when others =>
            if Present (Identifier) then
               case AADL_Version is
                  when AADL_V1 =>
                     DPE (Code, (T_Data, T_Event, T_Bus, T_Port, T_Parameter));
                  when AADL_V2 =>
                     DPE (Code, (T_Data, T_Bus, T_Port,
                                 T_Parameter, T_Subprogram, T_Virtual));
               end case;
               Skip_Tokens (T_Semicolon);
               return No_Node;
            else
446
447
448
449
450
               --  Nothing was parsed, try to parse other stuff

               --  XXX WRONG WRONG WRONG, should be either none, or
               --  raise an error

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
               Restore_Lexer (Loc);
               return No_Node;
            end if;
      end case;

      --  parse connection source et destination

      if not Is_Refinement then
         Source := P_Connection_Reference (Code);

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

         Scan_Token;
         if Token /= T_Direct_Connection then
            case Token is
               when T_Delayed_Connection =>
                  Category := CT_Data_Delayed;

               when T_Bidirect_Connection =>
                  Is_Bidirect := True;

               when others =>
                  if AADL_Version = AADL_V1 then
                     DPE (Code, (T_Direct_Connection, T_Delayed_Connection));
                  else
                     DPE (Code, (T_Direct_Connection,
                                 T_Bidirect_Connection));
                  end if;
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
            end case;
         end if;

         Destination := P_Connection_Reference (Code);

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

      --  parse properties and in_modes

      Save_Lexer (Properties_Loc);
      --  We save the location of the properties, as we have to parse
      --  it later (after the connection node has been created)

      Connection := Add_New_Connection (Loc           => Start_Loc,
                                        Name          => Identifier,
                                        Comp_Impl     => Container,
                                        Category      => Category,
                                        Destination   => Destination,
                                        Source        => Source,
                                        Is_Refinement => Is_Refinement,
                                        Is_Bidirect   => Is_Bidirect,
                                        In_Modes      => No_Node);

      OK := P_Property_Associations (Connection, True, PAT_Simple, Code);

      if not OK then
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      Save_Lexer (Loc);
      Scan_Token;
      if No (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Connection)) then
         --  Property_Associations are not defined,
         --  In_Modes_And_Transitions must exist if Is_Refinement = TRUE

         if Is_Refinement and then Token /= T_In then
            DPE (Code, (T_In, T_Left_Curly_Bracket));
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      end if;

      if Token = T_In then
         case Category is
            when CT_Data
              | CT_Data_Delayed
              | CT_Port_Connection
              | CT_Event_Data
              | CT_Event
              | CT_Feature_Group =>
               In_Modes := P_In_Modes (PC_In_Modes_And_Transitions);

            when CT_Parameter
              | CT_Access_Bus
              | CT_Access_Data
              | CT_Access_Subprogram
              | CT_Access_Subprogram_Group
546
547
              | CT_Access_Virtual_Bus
              | CT_Access =>
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
               In_Modes := P_In_Modes (PC_In_Modes);

            when CT_Error =>
               raise Program_Error;
         end case;

         if No (In_Modes) then
            --  error when parsing In_Modes, quit

            Skip_Tokens (T_Semicolon);
            return No_Node;
         else
            Set_In_Modes (Connection, In_Modes);
         end if;
      else
         In_Modes := No_Node;
         Restore_Lexer (Loc);
      end if;

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

      Save_Lexer (Loc);
      Restore_Lexer (Properties_Loc);
      Restore_Lexer (Loc);
      return Connection;
   end P_Connection;

   ----------------------------
   -- P_Connection_Reference --
   ----------------------------

   --  feature_reference ::=
   --     component_type_feature_identifier |
   --     component_type_feature_group_identifier . feature_identifier |
   --     subcomponent_identifier . feature_identifier

   --  port_connection_reference ::=
   --     component_type_port_identifier |
   --     subcomponent_identifier . port_identifier |
   --     component_type_feature_group_identifier . element_port_identifier |
   --     component_type_port_identifier . data_element_identifier |
   --     component_type_requires_data_access_identifier |
   --     data_subcomponent_identifier |
   --     subcomponent_identifier . provides_data_access_identifier |
   --     component_type_feat._group_identifier.elt_data_access_identifier |
   --     data_subcomponent_identifier .data_subcomponent_identifier |
   --     processor . processor_port_identifier |
   --     self . event_or_event_data_source_identifier

   --  parameter_reference ::=
   --     component_type_parameter_identifier [ . parameter_identifier ] |
   --     subprogram_call_identifier . parameter_identifier |
   --     component_type_port_identifier [ . data_subcomponent_identifier ] |
   --     data_subcomponent_identifier |
   --     requires_data_access_identifier |
   --     component_type_feat._group_identifier.elt_data_access_identifier |
   --     component_type_feat._group_identifier [ . element_port_identifier ]

   --  access_reference ::=
   --     requires_access_identifier | provides_access_identifier |
   --     feature_group_identifier [ . requires_access_identifier ] |
   --     feature_group_identifier [ . provides_access_identifier ] |
   --     subcomponent_identifier . provides_access_identifier |
   --     subcomponent_identifier . requires_access_identifier |
   --     data_subprogram_subprogam_group_or_bus_subcomponent_identifier |
   --     processor . provides_subprogram_access_identifier

   --  feature_group_reference ::=
   --     component_type_feature_group_identifier |
   --     subcomponent_identifier . feature_group_identifier |
   --     component_type_feature_group_identifier .
   --     element_feature_group_identifier

   function P_Connection_Reference
     (Code : Parsing_Code)
     return Types.Node_Id
   is
      use Locations;
      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Lexer;
      use Ocarina.ME_AADL.Tokens;
      use Ocarina.FE_AADL.Parser.Identifiers;

      Loc     : Location;
      Node    : Node_Id;
   begin
      Save_Lexer (Loc);
      Scan_Token;

      case Token is
         when T_Processor | T_Self =>
            if AADL_Version = AADL_V2 then
               Scan_Token;
               if Token /= T_Dot then
                  DPE (PC_Connection_Reference, T_Dot);
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
               end if;
            else
               DPE (PC_Connection_Reference, EMC_Not_Allowed_In_AADL_V2);
               Skip_Tokens (T_Semicolon);
               return No_Node;
            end if;

         when T_Identifier =>
            Restore_Lexer (Loc);

         when others =>
            DPE (PC_Connection_Reference, (T_Processor, T_Identifier));
            Skip_Tokens (T_Semicolon);
            return No_Node;
      end case;

      Node := P_Entity_Reference (Code);
      if No (Node) then
         DPE (PC_Connection_Reference);
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      return Node;

   end P_Connection_Reference;

end Ocarina.FE_AADL.Parser.Components.Connections;