ocarina-fe_aadl-parser-properties.adb 39.8 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
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--    O C A R I N A . F E _ A A D L . P A R S E R . P R O P E R T I E S     --
--                                                                          --
--                                 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 Namet;  use Namet;

with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.Property_Sets; use Ocarina.Property_Sets;

with Ocarina.FE_AADL.Lexer;
with Ocarina.ME_AADL.Tokens;
with Ocarina.FE_AADL.Parser.Identifiers;
with Ocarina.FE_AADL.Parser.Namespaces;
with Ocarina.FE_AADL.Parser.Components;
with Ocarina.FE_AADL.Parser.Components.Modes;
with Ocarina.FE_AADL.Parser.Properties.Values;

with Ocarina.Builder.AADL.Properties;
with Ocarina.ME_AADL.AADL_Tree.Entities;
with Ocarina.ME_AADL.AADL_Tree.Entities.Properties;

use Ocarina.ME_AADL;
use Ocarina.ME_AADL.AADL_Tree.Entities.Properties;

package body Ocarina.FE_AADL.Parser.Properties is

   function P_Property_Definition_Declaration
     (Identifier   : Node_Id;
      Property_Set : Node_Id)
     return Node_Id;
   --  Current token is ':'

   function P_Property_Owner_Or_Category
     (Container : Node_Id)
    return Node_Id;

   function P_Property_Owner_Category return Node_Id;

   ----------------------------
   -- P_Property_Association --
   ----------------------------

   function P_Property_Association (Container : Node_Id) return Node_Id is

      use Ocarina.ME_AADL.Tokens;

   begin
      if AADL_Version = AADL_V1 then
         return P_Property_Association (Container     => Container,
                                        Property_Type => PAT_Simple);

      else
         return P_Property_Association
           (Container     => Container,
            Property_Type => PAT_Simple_Or_Contained);
      end if;

   end P_Property_Association;

   --------------------------------------------------------
   -- P_Property_Association_In_Component_Implementation --
   --------------------------------------------------------

   function P_Property_Association_In_Component_Implementation
     (Container : Node_Id)
     return Node_Id
   is
   begin
      return P_Property_Association (Container     => Container,
                                     Property_Type => PAT_Simple_Or_Contained);
   end P_Property_Association_In_Component_Implementation;

   ----------------------------
   -- P_Property_Association --
   ----------------------------

   --  AADL_V1
   --  property_association ::=
   --     [ property_set_identifier :: ] property_name_identifier ( => | +=> )
   --     [ constant ] property_value [ in_binding ] [ in_modes ] ;

   --  access_property_association ::=
   --     [ property_set_identifier :: ] property_name_identifier ( => | +=> )
   --     [ constant ] access property_value [ in_binding ] [ in_modes ] ;

   --  contained_property_association ::=
   --     [ property_set_identifier :: ] property_name_identifier ( => | +=> )
   --     [ constant ] property_value
   --     applies to contained_unit_identifier { . contained_unit_identifier }*
   --     [ in_binding ] [ in_modes ] ;

   --  property_value ::= single_property_value | property_list_value

   --  single_property_value ::= property_expression

   --  property_list_value ::=
   --     ( [ property_expression { , property_expression }* ] )

   --  in_binding ::= in binding ( platform_classifier_reference
   --                                 { , platform_classifier_reference }* )

   --  platform_classifier_reference ::=   processor_classifier_reference
   --                                    | memory_classifier_reference
   --                                    | bus_classsifer_reference

   --  AADL_V2
   --  property_association ::=
   --     [ property_set_identifier :: ] property_name_identifier ( => | +=> )
   --     [ constant ] property_value [ in_binding ] [ in_modes ] ;

   --  contained_property_association ::=
   --     [ property_set_identifier :: ] property_name_identifier ( => | +=> )
   --     [ constant ] property_value
   --     applies to contained_model_element_path
   --                   { , contained_model_element_path }*
   --     [ in_binding ] [ in_modes ] ;

   --  contained_model_element_path ::=
   --     ( contained_model_element { . contained_model_element }*
   --       [ annex_path ] )
   --     | annex_path

   --  contained_model_element ::=
   --     named_element_identifier | named_element_array_selection_identifier

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

   --  property_value ::= single_property_value | property_list_value

   --  single_property_value ::= property_expression

   --  property_list_value ::=
   --     ( [ property_expression { , property_expression }* ] )

   --  in_binding ::=
   --    in binding ( platform_classifier_reference
   --                    { , platform_classifier_reference }* )

   --  platform_classifier_reference ::=
   --       processor_classifier_reference
   --     | virtual_processor_classifier_reference
   --     | bus_classifier_reference
   --     | virtual_bus_classifier_reference
   --     | memory_classifier_reference

   function P_Property_Association
     (Container     : Node_Id;
      Property_Type : Property_Association_Type)
     return Node_Id
   is
      use Lexer;
      use Ocarina.ME_AADL.Tokens;

      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Ocarina.ME_AADL.AADL_Tree.Nutils;
      use Ocarina.Builder.AADL.Properties;

      use Ocarina.FE_AADL.Parser.Components.Modes;
      use Ocarina.FE_AADL.Parser.Identifiers;
      use Ocarina.FE_AADL.Parser.Properties.Values;

      pragma Assert (Container /= No_Node);

      Property                 : Node_Id;   --  output
      Property_Name_Identifier : Node_Id;
      Contained_Elt            : Node_Id;
      Is_Additive              : Boolean;
      Is_Constant              : Boolean;
      Is_Access                : Boolean;
      Prop_Value               : Node_Id;
      Applies                  : List_Id := No_List;
      In_Binding               : Node_Id := No_Node;
      In_Modes                 : Node_Id := No_Node;
      Code                     : Parsing_Code;
      Binding_Loc              : Location;
      Loc                      : Location;
      Property_Loc             : Location;
      Item                     : Node_Id;
211
212

      Parse_List_Of_Properties : Boolean := True;
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
   begin
      Save_Lexer (Loc);
      Scan_Token;
      Save_Lexer (Property_Loc);

      if Token /= T_Identifier then
         --  can not parse Property_Association, try another stuff
         Restore_Lexer (Loc);
         return No_Node;
      else
         Restore_Lexer (Loc);
      end if;

      case Property_Type is
         when PAT_Simple =>
            Code := PC_Property_Association;
         when PAT_Access =>
            Code := PC_Access_Property_Association;
         when PAT_Simple_Or_Contained =>
            Code := PC_Property_Association_Or_Contained_Property_Association;
      end case;

      Property_Name_Identifier := P_Entity_Reference (Code);

      if No (Property_Name_Identifier) then
         --  error when parsing identifiers, quit
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      Scan_Token;

      if Token = T_Association then
         Is_Additive := False;
      elsif Token = T_Additive_Association then
         Is_Additive := True;
      else
         DPE (Code, (T_Association, T_Additive_Association));
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_Constant then
         Is_Constant := True;
      else
         Restore_Lexer (Loc);
         Is_Constant := False;
      end if;

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_Access then
         case AADL_Version is
            when AADL_V1 =>
               if Property_Type = PAT_Access then
                  Is_Access := True;
               else
                  DPE (Code, EMC_Access_Property_Association_Is_Not_Allowed);
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
               end if;

            when AADL_V2 =>
               DPE (Code, EMC_Not_Allowed_In_AADL_V2);
               Skip_Tokens (T_Semicolon);
               return No_Node;
         end case;
      else
285
286
287
         if AADL_Version = AADL_V1
           and then Property_Type = PAT_Access
         then
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
            if Is_Constant then
               DPE (Code, T_Access);
            else
               DPE (Code, (T_Constant, T_Access));
            end if;

            Skip_Tokens (T_Semicolon);
            return No_Node;
         else
            Restore_Lexer (Loc);
            Is_Access := False;
         end if;
      end if;

      --  Parse Property_Value

      Save_Lexer (Loc);
      Scan_Token;

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
      --  The AADLv2 BNF is ambiguous, a string starting with a '('
      --  can either be a list of property expressions e.g. "(foo,
      --  bard);"_or_ a single_expression containing a record term,
      --  e.g. "(foo => 1; bar =>2;)". This look ahead loop scans
      --  token to see which case we are currently processing.

      declare
         Loc2 : Location;
      begin
         Save_Lexer (Loc2);
         if Token = T_Left_Parenthesis then
            while Token /= T_Right_Parenthesis loop
               Scan_Token;
               if Token = T_Semicolon then
                  Parse_List_Of_Properties := False;
               end if;
            end loop;
         else
            Parse_List_Of_Properties := False;
         end if;
         Restore_Lexer (Loc2);
      end;

      if Parse_List_Of_Properties then
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
436
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
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
         Save_Lexer (Loc);
         Scan_Token;

         if Token = T_Right_Parenthesis then
            --  Property_List_Value is empty
            Prop_Value := Node_Id (New_List (K_List_Id, Loc));
            Set_Kind (Prop_Value, K_Property_List_Value);
            Set_First_Node (List_Id (Prop_Value), No_Node);
            Set_Last_Node (List_Id (Prop_Value), No_Node);
         else
            Restore_Lexer (Loc);

            Prop_Value := Node_Id (P_Items_List (P_Property_Expression'Access,
                                                 No_Node,
                                                 T_Comma, T_Right_Parenthesis,
                                                 PC_Property_List_Value));
            if No (Prop_Value) then
               --  error when parsing Property_Expression list, quit
               Skip_Tokens (T_Semicolon);
               return No_Node;
            end if;

            Set_Kind (Prop_Value, K_Property_List_Value);
         end if;
      else
         Restore_Lexer (Loc);
         Prop_Value := P_Property_Expression (No_Node);

         if No (Prop_Value) then
            --  error when parsing Property_Expression, quit
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      end if;

      --  Parse 'applies to ...'

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_Applies then
         if Property_Type /= PAT_Simple_Or_Contained then
            DPE (Code, EMC_Contained_Property_Association_Is_Not_Allowed);
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;

         --  now we know that Contained_Property_Association is being parsed
         Code := PC_Contained_Property_Association;

         Scan_Token;

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

         case AADL_Version is
            when AADL_V1 =>
               Save_Lexer (Loc);

               Contained_Elt := P_Contained_Element_Path (Container);

               if Contained_Elt /= No_Node then
                  Applies := New_List (K_List_Id, Loc);
                  Append_Node_To_List (Contained_Elt, Applies);
               else
                  DPE (Code, T_Identifier);
                  Skip_Tokens (T_Semicolon);
                  return No_Node;
               end if;

            when AADL_V2 =>
               Applies := P_Items_List (P_Contained_Element_Path'Access,
                                        Container,
                                        T_Comma);
         end case;

         if No (Applies) then
            DPE (Code, T_Identifier);
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      else
         Restore_Lexer (Loc);
         Applies := No_List;
      end if;

      --  Parse In_Binding

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_In then
         Save_Lexer (Binding_Loc);
         Scan_Token;

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

            In_Binding := New_Node (K_In_Binding, Binding_Loc);
            Set_Binding (In_Binding, New_List (K_List_Id, Binding_Loc));

            loop
               Save_Lexer (Loc);
               Scan_Token;

               if Token = T_Right_Parenthesis then
                  Restore_Lexer (Loc);
                  exit;
               end if;

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

               if Present (Item) then
                  Append_Node_To_List (Item, Binding (In_Binding));
               else
                  Skip_Tokens (T_Right_Parenthesis, False);
                  In_Binding := No_Node;
                  exit;
               end if;

               Scan_Token;

               if Token = T_Right_Parenthesis then
                  exit;
               end if;

               if Token /= T_Comma then
                  Skip_Tokens (T_Right_Parenthesis, False);
                  In_Binding := No_Node;
               end if;
            end loop;

            if No (In_Binding) then
               --  error when parsing In_Binding, quit
               Skip_Tokens (T_Semicolon);
               return No_Node;
            end if;

         elsif Token = T_Modes then
            --  In_Modes will be parsed in next section
            Restore_Lexer (Loc);
            In_Binding := No_Node;

         else
            DPE (Code, (T_Binding, T_Modes));
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      else
         Restore_Lexer (Loc);
         In_Binding := No_Node;
      end if;

      --  Parse In_Modes

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_In then
         In_Modes := P_In_Modes (PC_In_Modes);

         if No (In_Modes) then
            --  error when parsing In_Modes, quit
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      else
         Restore_Lexer (Loc);
         In_Modes := No_Node;
      end if;

      --  Parse ';'

      Save_Lexer (Loc);
      Scan_Token;

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

      --  The actual name of the property association is the
      --  concatenation of its property set and its name inside
      --  this property set.

      declare
         Full_Name_Identifier : constant Node_Id :=
           New_Node (K_Identifier, Property_Loc);
         Prop_Set_Id : constant Node_Id :=
           Namespace_Identifier (Property_Name_Identifier);
         Prop_Name_Id : constant Node_Id :=
           Identifier (Property_Name_Identifier);
      begin
         if Prop_Set_Id /= No_Node then
            Get_Name_String (Name (Prop_Set_Id));
            Add_Str_To_Name_Buffer (Image (T_Colon_Colon));
            Add_Str_To_Name_Buffer (Get_Name_String (Name (Prop_Name_Id)));
            Set_Name (Full_Name_Identifier, Name_Find);

            Get_Name_String
              (Ocarina.ME_AADL.AADL_Tree.Nodes.Display_Name (Prop_Set_Id));
            Add_Str_To_Name_Buffer (Image (T_Colon_Colon));
            Add_Str_To_Name_Buffer (Get_Name_String
                                    (Display_Name (Prop_Name_Id)));
            Set_Display_Name (Full_Name_Identifier, Name_Find);
         else
            Get_Name_String (Name (Prop_Name_Id));
            Set_Name (Full_Name_Identifier, Name_Find);

            Get_Name_String (Display_Name (Prop_Name_Id));
            Set_Display_Name (Full_Name_Identifier, Name_Find);
         end if;

         Property := Add_New_Property_Association
           (Loc => Ocarina.ME_AADL.AADL_Tree.Nodes.Loc (Full_Name_Identifier),
            Name => Full_Name_Identifier,
            Container => Container,
            Property_Name => Property_Name_Identifier,
            Is_Additive => Is_Additive,
            Is_Constant => Is_Constant,
            Is_Access => Is_Access,
            Property_Value => Prop_Value,
            In_Binding => In_Binding,
            Applies_To => Applies,
            In_Modes => In_Modes);
      end;

      pragma Assert (Property /= No_Node);
      --  Container may be No_Node if it is to be created later. Then
      --  the parser will parse again the property associations,
      --  giving the container. So, we just check the syntax this
      --  time.

      return Property;
   end P_Property_Association;

   -----------------------------
   -- P_Property_Associations --
   -----------------------------

   --     ( [ { { Property_Association }+ } ] )
   --  or (   { { Property_Association }+ }   )

   function P_Property_Associations
     (Container     : Node_Id;
      Optional      : Boolean;
      Property_Type : Property_Association_Type;
      Code          : Parsing_Code)
     return Boolean
   is
      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Ocarina.ME_AADL.AADL_Tree.Nutils;
      use Lexer;
      use Ocarina.ME_AADL.Tokens;

      pragma Assert (Container /= No_Node);

      Property : Node_Id;
      Loc      : Location;
      Success : Boolean := True;
      Number_Of_Items : Integer := 0;
   begin
      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_Left_Curly_Bracket then
         loop
            Save_Lexer (Loc);
            Property := P_Property_Association
              (Container     => Container,
               Property_Type => Property_Type);

            if No (Property) then
               if Token_Location = Loc then
                  --  Error when parsing the first token of
                  --  property_association, display error message

                  DPE (Code, (T_Identifier, T_Right_Curly_Bracket));
               end if;

               --  If the error is caused by a missing semi-colon and
               --  the property association we deal with is the last
               --  one, we must skip tokens until a '}', otherwise,
               --  we skip token until a ';'.

               if Token /= T_Right_Curly_Bracket then
                  Skip_Tokens (T_Semicolon);
               end if;

               Success := False;
            else
               Number_Of_Items := Number_Of_Items + 1;
            end if;

            Save_Lexer (Loc);
            Scan_Token;

            exit when Token = T_Right_Curly_Bracket or else not Success;
            Restore_Lexer (Loc);
         end loop;

         Success := Number_Of_Items /= 0 and then Success;
      else
         if not Optional then
            --  Property_Associations must be defined
            DPE (Code, T_Left_Curly_Bracket);
            Skip_Tokens (T_Semicolon);
            Success := False;
         else
            Restore_Lexer (Loc);
         end if;
      end if;

      return Success;
   end P_Property_Associations;

   ---------------------------------------
   -- P_Property_Definition_Declaration --
   ---------------------------------------

   --  AADL_V1
   --  property_name_declaration ::=
   --     defining_property_name_identifier : [ access ] [ inherit ]
   --        ( single_valued_property | multi_valued_property )
   --     applies to ( ( property_owner_category
   --                       { , property_owner_category }* | all ) ) ;

   --  AADL_V2
   --  property_definition_declaration ::=
   --     defining_property_name_identifier : [ inherit ]
   --        ( single_valued_property | multi_valued_property )
   --     applies to ( ( property_owner { , property_owner }* | all ) );

   function P_Property_Definition_Declaration
     (Identifier   : Node_Id;
      Property_Set : Node_Id)
     return Node_Id
   is
      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Ocarina.ME_AADL.AADL_Tree.Nutils;
      use Lexer;
      use Ocarina.ME_AADL.Tokens;
      use Ocarina.FE_AADL.Parser.Properties.Values;
      use Ocarina.FE_AADL.Parser.Identifiers;
      use Ocarina.Builder.AADL.Properties;

      Is_Access                 : Boolean;
      Is_All                    : Boolean;
      Is_Inherit                : Boolean;
      Is_A_List                 : Boolean;
      Property                  : Node_Id;
      Single_Default_Value      : Node_Id;
      Property_Definition_Value : Node_Id;
      Multiple_Default_Value    : List_Id;
      Owner_Categories          : List_Id;
      Loc                       : Location;
   begin
      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_Access then
         case AADL_Version is
            when AADL_V1 =>
               Is_Access := True;
            when AADL_V2 =>
               DPE (PC_Property_Definition_Declaration,
                    EMC_Not_Allowed_In_AADL_V2);
         end case;
      else
         Is_Access := False;
         Restore_Lexer (Loc);
      end if;

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_Inherit then
         Is_Inherit := True;
      else
         Is_Inherit := False;
         Restore_Lexer (Loc);
      end if;

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_List then
         Is_A_List := True;
         Property_Definition_Value := P_Multi_Valued_Property;
         Single_Default_Value := No_Node;

         if Property_Definition_Value /= No_Node then
            Multiple_Default_Value :=
              Property_Expressions (Property_Definition_Value);
         else
            Multiple_Default_Value := No_List;
         end if;

      else
         Restore_Lexer (Loc);
         Is_A_List := False;
         Property_Definition_Value := P_Single_Valued_Property;
         Multiple_Default_Value := No_List;

         if Property_Definition_Value /= No_Node then
            Single_Default_Value :=
              Property_Expression (Property_Definition_Value);
         else
            Single_Default_Value := No_Node;
         end if;
      end if;

      if Property_Definition_Value = No_Node then
         --  error when parsing Single_Valued_Property, quit
         --  Note that a Multi_Valued_Property can be empty
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      Scan_Token;

      if Token /= T_Applies then
         DPE (PC_Property_Definition_Declaration, T_Applies);
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      Scan_Token;

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

      Scan_Token;

      if Token /= T_Left_Parenthesis then
         DPE (PC_Property_Definition_Declaration, T_Left_Parenthesis);
         Skip_Tokens (T_Semicolon);
         return No_Node;
      end if;

      Save_Lexer (Loc);
      Scan_Token;

      if Token = T_All then
         Is_All := True;
         Owner_Categories := No_List;

         Scan_Token;

         if Token /= T_Right_Parenthesis then
            DPE (PC_Property_Definition_Declaration, T_Right_Parenthesis);
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      else
         Is_All := False;
         Restore_Lexer (Loc);
         Owner_Categories := P_Items_List (P_Property_Owner_Or_Category'Access,
                                           No_Node,
                                           T_Comma, T_Right_Parenthesis,
                                           PC_Property_Definition_Declaration);
         if No (Owner_Categories) then
            --  error when parsing property_owner_category list, quit
            Skip_Tokens (T_Semicolon);
            return No_Node;
         end if;
      end if;

      Save_Lexer (Loc);
      Scan_Token;

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

      Property := Add_New_Property_Definition_Declaration
        (Loc => Ocarina.ME_AADL.AADL_Tree.Nodes.Loc (Identifier),
         Property_Set            => Property_Set,
         Name                    => Identifier,
         Is_Access               => Is_Access,
         Is_Inherit              => Is_Inherit,
         Single_Default_Value    => Single_Default_Value,
         Multiple_Default_Value  => Multiple_Default_Value,
         Property_Name_Type      => Property_Type_Designator
           (Property_Definition_Value),
         Property_Type_Is_A_List => Is_A_List,
         Applies_To_All          => Is_All,
         Applies_To              => Owner_Categories);
      return Property;
   end P_Property_Definition_Declaration;

   -------------------------------
   -- P_Property_Owner_Category --
   -------------------------------

   --  property_owner_category ::=
   --       component_category [ classifier_reference ]
   --     | mode | port group | flow
   --     | [ event ] [ data ] port
   --     | server subprogram
   --     | [ connection_type ] connections

   --  connection_type ::= port group | [ event ] [ data ] port | access

   function P_Property_Owner_Category return Node_Id is
      use Ocarina.ME_AADL.AADL_Tree.Nodes;
      use Ocarina.ME_AADL.AADL_Tree.Nutils;
      use Ocarina.ME_AADL.AADL_Tree.Entities;
      use Ocarina.Builder.AADL.Properties;
      use Lexer;
      use Ocarina.ME_AADL.Tokens;
      use FE_AADL.Parser.Identifiers;
      use FE_AADL.Parser.Components;

      Owner_Category : Node_Id;
      Category       : Named_Element;
      Comp_Cat       : Component_Category := CC_Unknown;
      Classifier_Ref : Node_Id := No_Node;
      Loc            : Location;

   begin
      Scan_Token;
      Owner_Category := New_Node (K_Named_Element, Token_Location);
      case Token is
         when T_Mode =>
            Category := PO_Mode;

         when T_Port =>
            Save_Lexer (Loc);
            Scan_Token;
            case Token is
               when T_Group =>
                  Save_Lexer (Loc);
                  Scan_Token;
                  if Token = T_Connections then
                     Category := PO_Port_Group_Connections;
                  else
                     Restore_Lexer (Loc);
                     Category := PO_Port_Group;
                  end if;

               when T_Connections =>
                  Category := PO_Port_Connections;

               when others =>
                  Restore_Lexer (Loc);
                  Category := PO_Port;
            end case;

         when T_Flow =>
            Category := PO_Flow;

         when T_Event =>
            Scan_Token;
            case Token is
               when T_Port =>
                  Save_Lexer (Loc);
                  Scan_Token;
                  if Token = T_Connections then
                     Category := PO_Event_Port_Connections;
                  else
                     Restore_Lexer (Loc);
                     Category := PO_Event_Port;
                  end if;

               when T_Data =>
                  Scan_Token;
                  if Token /= T_Port then
                     DPE (PC_Property_Owner_Category, T_Port);
                     return No_Node;
                  end if;

                  Save_Lexer (Loc);
                  Scan_Token;
                  if Token = T_Connections then
                     Category := PO_Event_Data_Port_Connections;
                  else
                     Restore_Lexer (Loc);
                     Category := PO_Event_Data_Port;
                  end if;

               when others =>
                  DPE (PC_Property_Owner_Category, (T_Port, T_Data));
                  return No_Node;
            end case;

         when T_Data =>
            Save_Lexer (Loc);
            Scan_Token;
            if Token = T_Port then
               Save_Lexer (Loc);
               Scan_Token;
               if Token = T_Connections then
                  Category := PO_Data_Port_Connections;
               else
                  Restore_Lexer (Loc);
                  Category := PO_Data_Port;
               end if;
            else
               Restore_Lexer (Loc);
               Category := PO_Component_Category;
               Comp_Cat := CC_Data;
            end if;

         when T_Server =>
            Scan_Token;
            if Token /= T_Subprogram then
               DPE (PC_Property_Owner_Category, T_Subprogram);
               return No_Node;
            end if;
            Category := PO_Server_Subprogram;

         when T_Parameter =>
            Save_Lexer (Loc);
            Scan_Token;
            if Token = T_Connections then
               Category := PO_Parameter_Connections;
            else
               Restore_Lexer (Loc);
               Category := PO_Parameter;
            end if;

         when T_Access =>
            Scan_Token;
            if Token /= T_Connections then
               DPE (PC_Property_Owner_Category, T_Connections);
               return No_Node;
            end if;
            Category := PO_Access_Connection;

         when T_Connections =>
            Category := PO_Connections;

         when T_Subprogram
           | T_Thread
           | T_Process
           | T_Memory
           | T_Processor
           | T_Bus
           | T_Device
           | T_Virtual
           | T_System =>
            Category := PO_Component_Category;
            Comp_Cat := P_Component_Category;

         when others =>
            DPE (PC_Property_Owner_Category);
            return No_Node;
      end case;

      if Category = PO_Component_Category then
         Save_Lexer (Loc);
         Scan_Token;

         if Token = T_Identifier then