ocarina-fe_aadl-parser-components-flows.adb 27.7 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
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--                 OCARINA.FE_AADL.PARSER.COMPONENTS.FLOWS                  --
--                                                                          --
--                                 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 Locations;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.FE_AADL.Lexer;
with Ocarina.ME_AADL.Tokens;
with Ocarina.FE_AADL.Parser.Identifiers;
with Ocarina.FE_AADL.Parser.Components.Modes;
with Ocarina.FE_AADL.Parser.Properties;
with Ocarina.Builder.AADL.Components.Flows;

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

   use Lexer;
   use Ocarina.ME_AADL.Tokens;
   use Locations;
   use Ocarina.ME_AADL.AADL_Tree.Nodes;
   use Ocarina.ME_AADL.AADL_Tree.Nutils;
   use Parser.Properties;
   use Parser.Identifiers;
   use Parser.Components.Modes;
   use Ocarina.Builder.AADL.Components.Flows;

   function P_Flow_Implementation
     (Identifier    : Node_Id;
      Container     : Node_Id;
      Is_Refinement : Boolean;
      Is_End_To_End : Boolean;
      Category      : Flow_Category)
     return Node_Id;
   --  Parse Flow_Implementation, Flow_Implementation_Refinement
   --  End_To_End_Flow_Spec and End_To_End_Flow_Refinement

   function P_Flow_Spec
     (Identifier    : Node_Id;
      Container     : Node_Id;
      Is_Refinement : Boolean;
      Category      : Flow_Category)
     return Node_Id;
   --  This function is called in P_Flow_Spec (Boolean) to make this
   --  function body shorter and easier to read

   ---------------------------
   -- P_Flow_Implementation --
   ---------------------------

   --  flow_source_implementation ::= flow_identifier : flow source
   --     { subcomponent_flow_identifier -> connection_identifier -> }*
   --     flow_feature_identifier

   --  flow_sink_implementation ::= flow_identifier : flow sink
   --     flow_feature_identifier
   --     { -> connection_identifier -> subcomponent_flow_identifier }*

   --  flow_path_implementation ::= flow_identifier : flow path
   --     source_flow_feature_identifier
   --     [ { -> connection_identifier -> subcomponent_flow_identifier }+
   --     -> connection_identifier ]
   --     -> sink_flow_feature_identifier

   --  end_to_end_flow_spec ::= flow_identifier : end to end flow
   --     start_subcomponent_flow_identifier
   --        { -> connection_identifier
   --          -> flow_path_subcomponent_flow_identifier }*
   --     -> connection_identifier -> end_subcomponent_flow_identifier
   --     [ { ( property_association }+ } ]
   --     [ in_modes_and_transitions ] ;

   --  flow_source_implementation_refinement ::=
   --     flow_identifier : refined to flow source
   --     ( { { property_association }+ } [ in_modes_and_transitions ]
   --       | in_modes_and_transitions ) ;

   --  flow_sink_implementation_refinement ::=
   --     flow_identifier : refined to flow sink
   --     ( { { property_association }+ } [ in_modes_and_transitions ]
   --       | in_modes_and_transitions ) ;

   --  flow_path_implementation_refinement ::=
   --     flow_identifier : refined to flow path
   --     ( { { property_association }+ } [ in_modes_and_transitions ]
   --       | in_modes_and_transitions ) ;

   --  end_to_end_flow_refinement ::=
   --     defining_identifier : refined to end to end flow
   --     ( { { property_association }+ } [ in_modes_and_transitions ]
   --       | in_modes_and_transitions ) ;

   --  subcomponent_flow_identifier ::=
   --     subcomponent_identifier . flow_spec_identifier

   function P_Flow_Implementation
     (Identifier    : Node_Id;
      Container     : Node_Id;
      Is_Refinement : Boolean;
      Is_End_To_End : Boolean;
      Category      : Flow_Category)
     return Node_Id
   is
      Flow_Impl   : Node_Id;
      Connections : List_Id;
      Modes_Trans : Node_Id := No_Node;  --  modes and transitions
      Code        : Parsing_Code;
      Loc         : Location;
      OK          : Boolean;
      Item        : Node_Id;
      Source_Flow : Node_Id := No_Node;
      Sink_Flow   : Node_Id := No_Node;
   begin
      if Is_End_To_End then
         if Is_Refinement then
            Code := PC_End_To_End_Flow_Refinement;
         else
            Code := PC_End_To_End_Flow_Spec;
         end if;
      else
         case Category is
            when FC_Source =>
               if Is_Refinement then
                  Code := PC_Flow_Source_Implementation_Refinement;
               else
                  Code := PC_Flow_Source_Implementation;
               end if;
            when FC_Sink =>
               if Is_Refinement then
                  Code := PC_Flow_Sink_Implementation_Refinement;
               else
                  Code := PC_Flow_Sink_Implementation;
               end if;
            when FC_Path =>
               if Is_Refinement then
                  Code := PC_Flow_Path_Implementation_Refinement;
               else
                  Code := PC_Flow_Path_Implementation;
               end if;
         end case;
      end if;

      if not Is_Refinement then
         --  Parse connections

         Connections := New_List (K_List_Id, Token_Location);

         loop
            Save_Lexer (Loc);
            Scan_Token;

            if Token = T_Semicolon or else Token = T_Left_Curly_Bracket then
               Restore_Lexer (Loc);
               exit;
            end if;

            Restore_Lexer (Loc);
            Item := P_Entity_Reference (Code);

            if Present (Item) then
               Append_Node_To_List (Item, Connections);
            else
               --  Error when parsing item, ignores tokens ---> Delimiter; quit
               Skip_Tokens (T_Semicolon, False);
               Connections := No_List;
            end if;

            Save_Lexer (Loc);
            Scan_Token; --  consume "->"

            if Token = T_Semicolon
              or else Token = T_Left_Curly_Bracket
              or else Token = T_In
            then
               Restore_Lexer (Loc);
               exit;
            end if;

            if Token /= T_Direct_Connection then
               DPE (Code, (T_Semicolon, T_Left_Curly_Bracket, T_In));
               Skip_Tokens (T_Semicolon, False);
               Connections := No_List;
               exit;
            end if;
         end loop;

         if No (Connections) or else Is_Empty (Connections) then
            Skip_Tokens (T_Semicolon);
            return No_Node;
         else
            --  According to the AADL grammar some of the elements in
            --  the X -> Y -> Z ... chain are different from the rest
            --  of the elements. We relocate them to special fields ti
            --  make the analysis simpler. We also perform some
            --  implicit syntactic rules on the number of the
            --  remaining elements in the list (odd or even) depending
            --  on the flow nature.

            if Is_End_To_End then
               --  The list must contain at least two elements

               if Length (Connections) < 3 then
                  DPE (Code, EMC_At_Least_Three_Elements_Expected);
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
               end if;
               --  The first entity reference is the start identifier

               Source_Flow := First_Node (Connections);
               Remove_Node_From_List (Source_Flow, Connections);

               --  The last entity reference is the end identifier

               Sink_Flow := Last_Node (Connections);
               Remove_Node_From_List (Sink_Flow, Connections);

               --  According to the grammar the remaining number
               --  of element in the connection list must be
               --  odd.

               if Length (Connections) mod 2 = 0 then
                  --  We display en error message expecting an
                  --  odd number because we already removed two.

                  DPE (Code, EMC_Odd_Number_Of_Element_Expected);
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
               end if;
            else
               case Category is
                  when FC_Source =>
                     --  The last entity reference is the ultimate
                     --  source.

                     Source_Flow := Last_Node (Connections);
                     Remove_Node_From_List (Source_Flow, Connections);

                     --  According to the grammar the remaining number
                     --  of element in the connection list must be
                     --  even.

                     if Length (Connections) mod 2 /= 0 then
                        --  We display en error message expecting an
                        --  odd number because we already removed one.

                        DPE (Code, EMC_Odd_Number_Of_Element_Expected);
                        Skip_Tokens (T_Semicolon);
                        return No_Node;
                     end if;

                  when FC_Sink =>
                     --  The first entity reference is the sink
                     --  entrypoint.

                     Sink_Flow := First_Node (Connections);
                     Remove_Node_From_List (Sink_Flow, Connections);

                     --  According to the grammar the remaining number
                     --  of element in the connection list must be
                     --  even.

                     if Length (Connections) mod 2 /= 0 then
                        --  We display en error message expecting an
                        --  odd number because we already removed one.

                        DPE (Code, EMC_Odd_Number_Of_Element_Expected);
                        Skip_Tokens (T_Semicolon);
                        return No_Node;
                     end if;

                  when FC_Path =>
                     --  The list must contain at least two elements

                     if Length (Connections) < 2 then
                        DPE (Code, EMC_At_Least_Tow_Elements_Expected);
                        Skip_Tokens (T_Semicolon);
                        return No_Node;
                     end if;

                     --  The first entity reference is the path source

                     Source_Flow := First_Node (Connections);
                     Remove_Node_From_List (Source_Flow, Connections);

                     --  The last entity reference is the path sink

                     Sink_Flow := Last_Node (Connections);
                     Remove_Node_From_List (Sink_Flow, Connections);

                     --  According to the grammar the remaining number
                     --  of element in the connection list must be
                     --  zero or odd.

                     if Length (Connections) /= 0 and then
                       Length (Connections) mod 2 = 0
                     then
                        --  We display en error message expecting an
                        --  odd number because we already removed two.

                        DPE (Code, EMC_Odd_Number_Of_Element_Expected);
                        Skip_Tokens (T_Semicolon);
                        return No_Node;
                     end if;
               end case;
            end if;

            if not Is_Empty (Connections) then
               Set_Loc (Node_Id (Connections),
                        Ocarina.ME_AADL.AADL_Tree.Nodes.Loc (First_Node
                                                               (Connections)));
            end if;
         end if;
      end if;

      if Is_End_To_End then
         Flow_Impl := Add_New_End_To_End_Flow_Spec
           (Loc           => Ocarina.ME_AADL.AADL_Tree.Nodes.Loc (Identifier),
            Container     => Container,
            Name          => Identifier,
            Is_Refinement => Is_Refinement,
            In_Modes      => Modes_Trans,
            Source_Flow   => Source_Flow,
            Sink_Flow     => Sink_Flow);
      else
         Flow_Impl := Add_New_Flow_Implementation
           (Loc           => Ocarina.ME_AADL.AADL_Tree.Nodes.Loc (Identifier),
            Container     => Container,
            Name          => Identifier,
            Category      => Category,
            Is_Refinement => Is_Refinement,
            In_Modes      => Modes_Trans,
            Source_Flow   => Source_Flow,
            Sink_Flow     => Sink_Flow);
      end if;

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

      if not OK 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;

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_In then
         Modes_Trans := P_In_Modes (Code => PC_In_Modes_And_Transitions);

         if No (Modes_Trans) then
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      else
         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;

      if Present (Flow_Impl) and then not Is_Refinement then
         Set_Connections (Flow_Impl, Connections);
      end if;

      Set_In_Modes (Flow_Impl, Modes_Trans);

      return Flow_Impl;
   end P_Flow_Implementation;

   ---------------------------------------------------
   -- P_Flow_Implementation_Or_End_To_End_Flow_Spec --
   ---------------------------------------------------

   --  flow_implementation ::=
   --     (   flow_source_implementation
   --       | flow_sink_implementation
   --       | flow_path_implementation )
   --     [ { { property_association }+ } ]
   --     [ in_modes_and_transitions ] ;

   --  flow_implementation_refinement ::=
   --       flow_source_implementation_refinement
   --     | flow_sink_implementation_refinement
   --     | flow_path_implementation_refinement

   function P_Flow_Implementation_Or_End_To_End_Flow_Spec
     (Container : Node_Id;
      Refinable : Boolean)
     return Node_Id
   is
      Loc           : Location;
      Identifier    : Node_Id;
      Is_Refinement : Boolean        := False;
      Is_End_To_End : Boolean;
      Category      : Flow_Category;
436
      Code          : Parsing_Code := PC_Flow_Implementation;
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
      OK            : Boolean;
   begin

      case AADL_Version is
         when AADL_V1 =>
            P_Identifier_Refined_To
              (Refinable_To_RT (Refinable),
               False,
               PC_Flow_Implementation,
               PC_Flow_Implementation_Refinement,
               T_Semicolon,
               Identifier,
               Is_Refinement,
               OK);

            if not OK then
               return No_Node;
            end if;

         when AADL_V2 =>
            Save_Lexer (Loc);
            Scan_Token;

            if Token /= T_Identifier then
               return No_Node;
            else
               Identifier := Make_Current_Identifier (No_Node);
            end if;

            Scan_Token;
            if Token /= T_Colon then
               DPE (PC_Flow_Implementation, T_Colon);
               Skip_Tokens (T_Semicolon);
               return No_Node;
            end if;
      end case;

      Scan_Token;

      case Token is
         when T_Flow =>
            --  Flow_Implementation or Flow_Implementation_Refinement

            Is_End_To_End := False;

            if Is_Refinement then
               Code := PC_Flow_Implementation_Refinement;
            else
               Code := PC_Flow_Implementation;
            end if;

            Scan_Token;

            case Token is
               when T_Source =>
                  Category := FC_Source;
               when T_Sink   =>
                  Category := FC_Sink;
               when T_Path   =>
                  Category := FC_Path;

               when others   =>
                  DPE (Code, (T_Source, T_Sink, T_Path));
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
            end case;

         when T_End =>
            --  End_To_End_Flow_Spec or End_To_End_Flow_Refinement

            Is_End_To_End := True;

            if Is_Refinement then
               Code := PC_End_To_End_Flow_Refinement;
            else
               Code := PC_End_To_End_Flow_Spec;
            end if;

            Scan_Token;      --  consume 'to'

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

            Scan_Token;      --  consume 'end'

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

            Scan_Token;      --  consume 'flow'

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

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

      return P_Flow_Implementation
        (Identifier    => Identifier,
         Container     => Container,
         Is_Refinement => Is_Refinement,
         Is_End_To_End => Is_End_To_End,
         Category      => Category);
   end P_Flow_Implementation_Or_End_To_End_Flow_Spec;

   -----------------
   -- P_Flow_Spec --
   -----------------

   --  AADL_V1
   --  flow_spec ::= flow_source_spec | flow_sink_spec | flow_path_spec

   --  flow_spec_refinement ::=   flow_source_spec_refinement
   --                           | flow_sink_spec_refinement
   --                           | flow_path_spec_refinement

   --  flow_source_spec ::=
   --     defining_identifier : flow source flow_feature_identifier
   --        [ { { property_association }+ } ] ;

   --  flow_sink_spec ::=
   --     defining_identifier : flow sink flow_feature_identifier
   --        [ { { property_association }+ } ] ;

   --  flow_path_spec ::=
   --     defining_identifier : flow path
   --        source_flow_feature_identifier -> sink_flow_feature_identifier
   --        [ { { property_association }+ } ] ;

   --  flow_source_spec_refinement ::=
   --     defining_identifier : refined to flow source
   --        { { property_association }+ } ;

   --  flow_sink_spec_refinement ::=
   --     defining_identifier : refined to flow sink
   --        { { property_association }+ } ;

   --  flow_path_spec_refinement ::=
   --     defining_identifier : refined to flow path
   --        { { property_association }+ } ;

   --  AADL_V2
   --  flow_spec ::= flow_source_spec | flow_sink_spec | flow_path_spec

   --  flow_spec_refinement ::=   flow_source_spec_refinement
   --                           | flow_sink_spec_refinement
   --                           | flow_path_spec_refinement

   --  flow_source_spec ::=
   --     defining_flow_identifier : flow source out_flow_feature_identifier
   --        [ { { property_association }+ } ] [ in_modes ] ;

   --  flow_sink_spec ::=
   --      defining_flow_identifier : flow sink in_flow_feature_identifier
   --         [ { { property_association }+ } ] [ in_modes ] ;

   --  flow_path_spec ::=
   --     defining_flow_identifier : flow path
   --        in_flow_feature_identifier -> out_flow_feature_identifier
   --        [ { { property_association }+ } ] [ in_modes ] ;

   --  flow_source_spec_refinement ::=
   --     defining_flow_identifier : refined to flow source
   --        { { property_association }+ } [ in_modes ] ;

   --  flow_sink_spec_refinement ::=
   --     defining_flow_identifier : refined to flow sink
   --        { { property_association }+ } [ in_modes ] ;

   --  flow_path_spec_refinement ::=
   --     defining_flow_identifier : refined to flow path
   --        { { property_association }+ } [ in_modes ] ;

   function P_Flow_Spec
     (Container : Node_Id;
      Refinable : Boolean)
     return Node_Id
   is
      Identifier    : Node_Id;
      Is_Refinement : Boolean;
      OK            : Boolean;
      Category      : Flow_Category;
      Code          : Parsing_Code;
   begin
      P_Identifier_Refined_To
        (Refinable_To_RT (Refinable),
         False,
         PC_Flow_Spec,
         PC_Flow_Spec_Refinement,
         T_Semicolon,
         Identifier,
         Is_Refinement,
         OK);

      if not OK then
         return No_Node;
      end if;

      if Is_Refinement then
         Code := PC_Flow_Spec_Refinement;
      else
         Code := PC_Flow_Spec;
      end if;

      Scan_Token;

      if Token = T_Flow then
         Scan_Token;

         case Token is
            when T_Source =>
               Category := FC_Source;
            when T_Sink   =>
               Category := FC_Sink;
            when T_Path   =>
               Category := FC_Path;

            when others   =>
               DPE (Code, (T_Source, T_Sink, T_Path));
               Skip_Tokens (T_Semicolon);
               return No_Node;
         end case;
      else
         DPE (Code, T_Flow);
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      return P_Flow_Spec (Identifier    => Identifier,
                          Container     => Container,
                          Is_Refinement => Is_Refinement,
                          Category      => Category);
   end P_Flow_Spec;

   -----------------
   -- P_Flow_Spec --
   -----------------

   --  AADL_V1
   --  flow_feature_identifier ::=   port_identifier
   --                              | parameter_identifier
   --                              | port_group_identifier
   --                              | port_group_identifier . port_identifier

   --  AADL_V2
   --  flow_feature_identifier ::=
   --     feature_identifier
   --   | feature_group_identifier
   --   | feature_group_identifier . feature_identifier
   --   | feature_group_identifier . feature_group_identifie

   function P_Flow_Spec
     (Identifier    : Node_Id;
      Container     : Node_Id;
      Is_Refinement : Boolean;
      Category      : Flow_Category)
     return Node_Id
   is
      Flow_Spec   : Node_Id;
      In_Modes    : Node_Id;
      Source_Flow : Node_Id := No_Node;
      Sink_Flow   : Node_Id := No_Node;
      Code        : Parsing_Code;
      OK          : Boolean;
      Loc         : Location;

      --  Sub-function determining parsing code to display error messages

      function Flow_Parsing_Code return Parsing_Code;
      pragma Inline (Flow_Parsing_Code);

      -----------------------
      -- Flow_Parsing_Code --
      -----------------------

      function Flow_Parsing_Code return Parsing_Code is
      begin
         if Is_Refinement then
            case Category is
               when FC_Source => return PC_Flow_Source_Spec_Refinement;
               when FC_Sink   => return PC_Flow_Sink_Spec_Refinement;
               when FC_Path   => return PC_Flow_Path_Spec_Refinement;
            end case;
         else
            case Category is
               when FC_Source => return PC_Flow_Source_Spec;
               when FC_Sink   => return PC_Flow_Sink_Spec;
               when FC_Path   => return PC_Flow_Path_Spec;
            end case;
         end if;
      end Flow_Parsing_Code;

   begin
      Code := Flow_Parsing_Code;

      if not Is_Refinement then
         --  Parse flow_feature_identifier(s)
         case Category is
            when FC_Source =>
               Source_Flow := P_Entity_Reference (Code);

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

            when FC_Sink =>
               Sink_Flow := P_Entity_Reference (Code);

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

            when FC_Path =>
               Source_Flow := P_Entity_Reference (Code);

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

               Scan_Token;  --  Consume "->"

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

               Sink_Flow := P_Entity_Reference (Code);

               if No (Sink_Flow) then
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
               end if;
         end case;
      end if;

      Flow_Spec := Add_New_Flow_Spec
        (Loc           => Ocarina.ME_AADL.AADL_Tree.Nodes.Loc (Identifier),
         Comp_Type     => Container,
         Name          => Identifier,
         Category      => Category,
         Is_Refinement => Is_Refinement,
         Sink_Flow     => Sink_Flow,
         Source_Flow   => Source_Flow);

      OK := P_Property_Associations
        (Flow_Spec,
         not Is_Refinement,
         PAT_Simple,
         Code);

      Save_Lexer (Loc);
      Scan_Token;
      if 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;

         Set_In_Modes (Flow_Spec, In_Modes);
      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;

      if not OK then
         return No_Node;
      end if;

      return Flow_Spec;
   end P_Flow_Spec;

end Ocarina.FE_AADL.Parser.Components.Flows;