ocarina-backends-expander.adb 25.6 KB
Newer Older
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--            O C A R I N A . B A C K E N D S . E X P A N D E R             --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE.      --
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. Ocarina is distributed in the hope that it will be useful, but     --
-- WITHOUT ANY WARRANTY; without even the implied warranty of               --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27 28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29 30 31
--                                                                          --
------------------------------------------------------------------------------

yoogx's avatar
yoogx committed
32 33 34
with Locations;     use Locations;
with Ocarina.Namet; use Ocarina.Namet;
with Utils;         use Utils;
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

with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;

with Ocarina.Instances.Properties;

with Ocarina.Backends.Utils;
with Ocarina.Backends.Properties;
with Ocarina.Backends.Messages;

package body Ocarina.Backends.Expander is

   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Nutils;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.Instances.Properties;
   use Ocarina.Backends.Properties;
   use Ocarina.Backends.Messages;

   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   package AIU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;

   procedure Expand_Architecture_Instance (E : Node_Id);
   procedure Expand_Component_Instance (E : Node_Id);
   procedure Expand_Data_Instance (E : Node_Id);
   procedure Expand_Process_Instance (E : Node_Id);
   procedure Expand_Subprogram_Instance (E : Node_Id);
   procedure Expand_System_Instance (E : Node_Id);
   procedure Expand_Thread_Instance (E : Node_Id);

   Instance_Root : Node_Id := No_Node;

   function Internal_Expanded_Name (E : Node_Id) return Name_Id;
   function Expanded (E : Node_Id) return Boolean;
   procedure Set_Expanded (E : Node_Id);
   --  Routines to control the expansion of component instances

   ------------
   -- Expand --
   ------------

   procedure Expand (E : Node_Id) is
   begin
      case Kind (E) is
         when K_Architecture_Instance =>
            Expand_Architecture_Instance (E);

         when K_Component_Instance =>
            Expand_Component_Instance (E);

         when others =>
            null;
      end case;

      if No (E) then
94 95 96 97
         Display_Error
           ("Cannot expand AADL models",
            Fatal   => True,
            Warning => False);
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
      end if;
   end Expand;

   ----------------------------------
   -- Expand_Architecture_Instance --
   ----------------------------------

   procedure Expand_Architecture_Instance (E : Node_Id) is
   begin
      Instance_Root := E;
      Expand (Root_System (E));
      Instance_Root := No_Node;
   end Expand_Architecture_Instance;

   -------------------------------
   -- Expand_Component_Instance --
   -------------------------------

   procedure Expand_Component_Instance (E : Node_Id) is
117 118 119 120 121 122
      Category : constant Component_Category := Get_Category_Of_Component (E);
      N        : Node_Id;
      I        : Node_Id;
      F        : Node_Id;
      K        : Node_Id;
      L        : Node_Id;
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
   begin
      if Expanded (E) then
         return;
      else
         Set_Expanded (E);
      end if;

      --  This part of the code is considered as unstable
      --  at this time.

      if not Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
            if Kind (F) = K_Feature_Group_Spec_Instance then
               if not Is_Empty (Features (F)) then
                  I := First_Node (Features (F));

                  while Present (I) loop
                     if Category = CC_Subprogram then
143 144 145 146
                        N :=
                          Ocarina.ME_AADL.AADL_Instances.Nutils.New_Node
                            (K_Parameter_Instance,
                             AIN.Loc (I));
147
                     else
148 149 150 151
                        N :=
                          Ocarina.ME_AADL.AADL_Instances.Nutils.New_Node
                            (AIN.Kind (I),
                             AIN.Loc (I));
152
                        AIN.Set_Identifier (N, AIU.Copy_Node (Identifier (I)));
153 154 155
                     end if;

                     if Kind (I) = K_Port_Spec_Instance then
156 157
                        AIN.Set_Is_Event (N, AIN.Is_Event (I));
                        AIN.Set_Is_Data (N, AIN.Is_Data (I));
158 159
                        AIN.Set_Is_In (N, AIN.Is_In (I));
                        AIN.Set_Is_Out (N, AIN.Is_Out (I));
160 161 162
                     end if;

                     AIN.Set_Corresponding_Instance
163 164 165 166 167
                       (N,
                        AIN.Corresponding_Instance (I));
                     AIN.Set_Sources (N, AIN.Sources (I));
                     AIN.Set_Destinations (N, AIN.Destinations (I));
                     AIN.Set_Parent_Component (N, AIN.Parent_Component (F));
168 169 170 171 172 173 174 175

                     if not Is_Empty (Sources (F)) then

                        K := First_Node (Sources (F));

                        L := No_Node;

                        while Present (K) loop
176 177 178 179
                           L :=
                             Find_Name_In_List
                               (Name (Identifier (I)),
                                Features (Item (K)));
180 181 182 183 184 185 186 187 188

                           if L /= No_Node then
                              exit;
                           end if;

                           K := Next_Node (K);
                        end loop;

                        if L = No_Node then
189 190 191 192
                           Display_Error
                             ("Cannot expand port/feature group",
                              Fatal   => True,
                              Warning => False);
193 194 195
                        end if;

                        Append_Node_To_List
196
                          (Make_Node_Container (L, Extra_Item (K)),
197
                           Sources (N));
198 199

                        Append_Node_To_List
200
                          (Make_Node_Container (N, Extra_Item (K)),
201
                           Destinations (L));
202 203 204 205 206 207 208 209
                     end if;

                     if not Is_Empty (Destinations (F)) then
                        K := First_Node (Destinations (F));

                        L := No_Node;

                        while Present (K) loop
210 211 212 213
                           L :=
                             Find_Name_In_List
                               (Name (Identifier (I)),
                                Features (Item (K)));
214 215 216 217 218 219 220 221 222

                           if L /= No_Node then
                              exit;
                           end if;

                           K := Next_Node (K);
                        end loop;

                        if L = No_Node then
223 224 225 226
                           Display_Error
                             ("Cannot expand port/feature group",
                              Fatal   => True,
                              Warning => False);
227 228 229
                        end if;

                        Append_Node_To_List
230
                          (Make_Node_Container (L, Extra_Item (K)),
231
                           Destinations (N));
232 233

                        Append_Node_To_List
234
                          (Make_Node_Container (N, Extra_Item (K)),
235
                           Sources (L));
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
                     end if;

                     AIU.Append_Node_To_List (N, Features (E));

                     I := Next_Node (I);
                  end loop;
               end if;
               I := Next_Node (F);
               AIU.Remove_Node_From_List (F, Features (E));
               F := I;
            else
               F := Next_Node (F);
            end if;
         end loop;
      end if;

      case Category is
         when CC_Data =>
            Expand_Data_Instance (E);

         when CC_Process =>
            Expand_Process_Instance (E);

         when CC_Subprogram =>
            Expand_Subprogram_Instance (E);

         when CC_System =>
            Expand_System_Instance (E);

         when CC_Thread =>
            Expand_Thread_Instance (E);

         when others =>
            null;
      end case;
   end Expand_Component_Instance;

   --------------------------
   -- Expand_Data_Instance --
   --------------------------

   procedure Expand_Data_Instance (E : Node_Id) is
      Data_Representation : Supported_Data_Representation;
      S                   : Node_Id;

      use Ocarina.ME_AADL.AADL_Tree.Nodes;
   begin
      --  Expand all the subcomponents of the data

      if not Is_Empty (AIN.Subcomponents (E)) then
         S := AIN.First_Node (AIN.Subcomponents (E));
         while Present (S) loop
            --  Expand the component instance corresponding to the
            --  subcomponent S.

            Expand (Corresponding_Instance (S));
            S := AIN.Next_Node (S);
         end loop;
      end if;

      Data_Representation := Get_Data_Representation (E);

      case Data_Representation is
         when Data_Struct | Data_With_Accessors =>

            --  There are two ways to define data structure in AADL:
            --
            --  1) using subcomponents, or
            --  2) using the "Element_Names" property.
            --
            --  Before giving the instance tree to the generators, we
            --  modify all data structures defined using the
            --  "Element_Names" property into ones using the
            --  subcomponents.

            declare
               Fields : constant Name_Array := Get_Element_Names (E);
               Types  : constant List_Id    := Get_Base_Type (E);
               F      : Node_Id;
               N      : Node_Id;
            begin
               if Fields'Length = 0 then
                  --  The data component has no Element_Names property
                  --  defined, hence we have nothing to do.

                  return;
               end if;

               if AIN.Subcomponents (E) = No_List then
                  AIN.Set_Subcomponents (E, New_List (K_List_Id, No_Location));
               else
                  Display_Located_Error
                    (AIN.Loc (E),
329 330
                     "A data component cannot have both subcomponents" &
                     " and Element_Names",
331 332 333 334 335 336
                     Fatal => False);
               end if;

               F := ATN.First_Node (Types);

               for J in Fields'Range loop
337
                  N := New_Node (K_Subcomponent_Instance, AIN.Loc (E));
338 339 340
                  AIN.Set_Identifier
                    (N,
                     Make_Identifier
341 342 343 344
                       (AIN.Loc (E),
                        To_Lower (Fields (J)),
                        Fields (J),
                        N));
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
                  Set_Corresponding_Declaration (N, No_Node);
                  Set_Destinations (N, New_List (K_List_Id, No_Location));
                  Set_Corresponding_Instance
                    (N,
                     Ocarina.ME_AADL.AADL_Tree.Nodes.Entity (F));

                  Append_Node_To_List (N, AIN.Subcomponents (E));

                  F := ATN.Next_Node (F);
               end loop;
            end;

            --  Expand the subcomponents of the data that have been
            --  created

            S := AIN.First_Node (AIN.Subcomponents (E));
            while Present (S) loop
               --  Expand the component instance corresponding to the
               --  subcomponent S.

               Expand (Corresponding_Instance (S));
               S := AIN.Next_Node (S);
            end loop;

         when Data_Array =>

            --  There are two ways to define data array in AADL:
            --
            --  1) using subcomponents, or
            --  2) using the "data_model::base_type" property.
            --
            --  Before giving the instance tree to the generators, we
            --  modify all data structures defined using the
            --  "base_name" property into ones using the
            --  subcomponents.

            declare
382 383 384
               Types : constant List_Id := Get_Base_Type (E);
               F     : Node_Id;
               N     : Node_Id;
385 386 387 388 389 390
            begin
               if AIN.Subcomponents (E) = No_List then
                  AIN.Set_Subcomponents (E, New_List (K_List_Id, No_Location));
               else
                  Display_Located_Error
                    (AIN.Loc (E),
391 392
                     "A data component cannot have both subcomponents" &
                     " and Element_Names",
393 394 395 396 397 398
                     Fatal => False);
               end if;

               F := ATN.First_Node (Types);

               while Present (F) loop
399
                  N := New_Node (K_Subcomponent_Instance, AIN.Loc (E));
400 401
                  AIN.Set_Identifier
                    (N,
402
                     Ocarina.ME_AADL.AADL_Instances.Nodes.Identifier (E));
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
                  Set_Corresponding_Declaration (N, No_Node);
                  Set_Destinations (N, New_List (K_List_Id, No_Location));
                  Set_Corresponding_Instance
                    (N,
                     Ocarina.ME_AADL.AADL_Tree.Nodes.Entity (F));

                  Append_Node_To_List (N, AIN.Subcomponents (E));

                  F := ATN.Next_Node (F);
               end loop;
            end;

            --  Expand the subcomponents of the data that have been
            --  created

            S := AIN.First_Node (AIN.Subcomponents (E));
            while Present (S) loop
               --  Expand the component instance corresponding to the
               --  subcomponent S.

               Expand (Corresponding_Instance (S));
               S := AIN.Next_Node (S);
            end loop;

         when others =>
            null;

      end case;
   end Expand_Data_Instance;

   -----------------------------
   -- Expand_Process_Instance --
   -----------------------------

   procedure Expand_Process_Instance (E : Node_Id) is
      S : Node_Id;
   begin
      --  Expand all the subcomponents of the process

      if not Is_Empty (Subcomponents (E)) then
         S := First_Node (Subcomponents (E));
         while Present (S) loop
            --  Expand the component instance corresponding to the
            --  subcomponent S.

            Expand (Corresponding_Instance (S));
            S := Next_Node (S);
         end loop;
      end if;
   end Expand_Process_Instance;

   --------------------------------
   -- Expand_Subprogram_Instance --
   --------------------------------

   procedure Expand_Subprogram_Instance (E : Node_Id) is
      Call_Seq : Node_Id;
      Spg_Call : Node_Id;
      F        : Node_Id;
   begin
      --  Expand all data types in the features

      if not Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
            if Kind (F) /= K_Feature_Group_Spec_Instance
470 471
              and then Present (Corresponding_Instance (F))
            then
472 473 474 475 476 477 478
               Expand (Corresponding_Instance (F));
            end if;

            F := Next_Node (F);
         end loop;
      end if;

479
      --  Expand all the call sequences of the subprogram
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

      if not Is_Empty (Calls (E)) then
         Call_Seq := First_Node (Calls (E));

         while Present (Call_Seq) loop
            --  For each call sequence expand all the called
            --  subprograms.

            if not Is_Empty (Subprogram_Calls (Call_Seq)) then
               Spg_Call := First_Node (Subprogram_Calls (Call_Seq));

               while Present (Spg_Call) loop
                  Expand (Corresponding_Instance (Spg_Call));

                  Spg_Call := Next_Node (Spg_Call);
               end loop;
            end if;

            Call_Seq := Next_Node (Call_Seq);
         end loop;
      end if;
   end Expand_Subprogram_Instance;

   ----------------------------
   -- Expand_System_Instance --
   ----------------------------

   procedure Expand_System_Instance (E : Node_Id) is
      S : Node_Id;
   begin
      --  Expand all the subcomponents of the system

      if not Is_Empty (Subcomponents (E)) then
         S := First_Node (Subcomponents (E));
         while Present (S) loop
            --  Expand the component instance corresponding to the
            --  subcomponent S.

            Expand (Corresponding_Instance (S));
            S := Next_Node (S);
         end loop;
      end if;
   end Expand_System_Instance;

   ----------------------------
   -- Expand_Thread_Instance --
   ----------------------------

   procedure Expand_Thread_Instance (E : Node_Id) is
      Call_Seq : Node_Id;
      Spg_Call : Node_Id;
      F        : Node_Id;
532 533 534 535 536 537
      P        : constant Supported_Thread_Dispatch_Protocol :=
        Get_Thread_Dispatch_Protocol (E);
      K : constant Supported_Thread_Implementation :=
        Get_Thread_Implementation_Kind (E);
      N : Node_Id;
      G : Node_Id;
538 539 540 541 542 543 544 545
   begin
      --  Expand all data types

      if not Is_Empty (Features (E)) then
         F := First_Node (Features (E));

         while Present (F) loop
            if Kind (F) = K_Port_Spec_Instance
546 547
              and then Ocarina.ME_AADL.AADL_Instances.Nodes.Is_Data (F)
            then
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
               Expand (Corresponding_Instance (F));
            end if;

            F := Next_Node (F);
         end loop;
      end if;

      --  Expand all the call sequences of the thread

      if not Is_Empty (Calls (E)) then
         Call_Seq := First_Node (Calls (E));

         while Present (Call_Seq) loop
            --  For each call sequence expand all the called
            --  subprograms.

            if not Is_Empty (Subprogram_Calls (Call_Seq)) then
               Spg_Call := First_Node (Subprogram_Calls (Call_Seq));

               while Present (Spg_Call) loop
                  Expand (Corresponding_Instance (Spg_Call));

                  Spg_Call := Next_Node (Spg_Call);
               end loop;
            end if;

            Call_Seq := Next_Node (Call_Seq);
         end loop;
      end if;

      --  If the thread is a Hybrid thread, we add a new fake event
      --  port called Period_Event_. This port will receive the
      --  messages from the hybrid tasks driver.

      if P = Thread_Hybrid then
         N := New_Node (K_Port_Spec_Instance, No_Location);
         Set_Is_In (N, True);
         Set_Is_Out (N, False);
         Set_Is_Event (N, True);
         Set_Is_Data (N, False);
         Set_Identifier
589 590 591 592 593 594
           (N,
            Make_Identifier
              (No_Location,
               Get_String_Name ("period_event_"),
               Get_String_Name ("Period_Event_"),
               N));
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
         Set_Sources (N, New_List (K_List_Id, No_Location));
         Set_Destinations (N, New_List (K_List_Id, No_Location));
         Set_Parent_Component (N, E);

         --  If the thread implementation kind is
         --  Thread_With_Port_Compute_Entrypoint, then, the port
         --  must also have a compute entry point. We relocate the
         --  compute entrypoint of the thread to be the one of the
         --  extra added port.

         if K = Thread_With_Port_Compute_Entrypoint then
            declare
               use Ocarina.Backends.Utils;
               use ATN;

               Mode    : Name_Id;
               CE      : Node_Id;
               C       : Node_Id := No_Node;
               Success : Boolean := True;
               M       : Node_Id;
            begin
616
               AIN.Set_Properties (N, New_List (AIN.K_List_Id, No_Location));
617 618 619 620 621 622 623 624 625 626

               if Has_Modes (E) then

                  --  FIXME
                  --  Create a new property for each mode
                  --  instead of replacing it

                  G := AIN.First_Node (AIN.Modes (E));
                  while Present (G) loop
                     Mode := AIN.Name (AIN.Identifier (G));
627
                     CE   := Get_Thread_Compute_Entrypoint (E, Mode);
628 629 630 631 632
                     if Present (CE) then
                        C := CE;

                        pragma Assert (Present (Instance_Root));

633 634 635 636 637 638
                        Success :=
                          Add_Property_Instance
                            (Instance_Root,
                             N,
                             AIN.Corresponding_Declaration (CE),
                             Override_Mode => False);
639 640 641

                        M := Get_Port_Compute_Entrypoint (N, Mode);

642 643 644 645 646
                        if ATN.Kind
                            (ATN.Expanded_Single_Value
                               (AIN.Property_Association_Value (M))) =
                          ATN.K_Reference_Term
                        then
647 648 649 650 651 652
                           --  FIXME :
                           --  Should be do by the replace_property_instance

                           ATN.Set_Entity
                             (ATN.Reference_Term
                                (ATN.Expanded_Single_Value
653 654 655 656 657 658
                                   (AIN.Property_Association_Value (M))),
                              (ATN.Entity
                                 (ATN.Reference_Term
                                    (ATN.Expanded_Single_Value
                                       (AIN.Property_Association_Value
                                          (CE))))));
659 660 661 662 663 664 665 666 667
                        end if;
                        Remove_Node_From_List (CE, AIN.Properties (E));

                     end if;

                     G := AIN.Next_Node (G);
                  end loop;
               else
                  CE := Get_Thread_Compute_Entrypoint (E);
668
                  C  := CE;
669

670 671 672
                  AIN.Set_Properties
                    (N,
                     New_List (AIN.K_List_Id, No_Location));
673 674 675

                  pragma Assert (Present (Instance_Root));

676 677 678 679 680 681
                  Success :=
                    Replace_Property_Instance
                      (Instance_Root,
                       N,
                       CE,
                       Override_Mode => True);
682 683 684

                  M := Get_Port_Compute_Entrypoint (N);

685 686 687 688 689
                  if ATN.Kind
                      (ATN.Expanded_Single_Value
                         (AIN.Property_Association_Value (M))) =
                    ATN.K_Reference_Term
                  then
690 691 692 693 694 695
                     --  FIXME :
                     --  Should be do by the replace_property_instance

                     ATN.Set_Entity
                       (ATN.Reference_Term
                          (ATN.Expanded_Single_Value
696 697 698 699 700
                             (AIN.Property_Association_Value (M))),
                        (ATN.Entity
                           (ATN.Reference_Term
                              (ATN.Expanded_Single_Value
                                 (AIN.Property_Association_Value (CE))))));
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
                  end if;
               end if;

               if not Success then
                  raise Program_Error;
               end if;

               if No (C) then
                  --  Display an error if the user did not provide a
                  --  compute entrypoint.

                  Display_Located_Error
                    (AIN.Loc (E),
                     "Missing compute entrypoint for this hybrid thread",
                     Fatal => True);
               end if;
            end;
         end if;

         if not Is_Empty (Features (E)) then
            Append_Node_To_List (N, Features (E));
         end if;
      end if;
   end Expand_Thread_Instance;

   ----------------------------
   -- Internal_Expanded_Name --
   ----------------------------

   function Internal_Expanded_Name (E : Node_Id) return Name_Id is
      Expansion_Annotation_Name : constant String := "%expanded%";
   begin
      Set_Str_To_Name_Buffer (Expansion_Annotation_Name);
      Add_Str_To_Name_Buffer (E'Img);
      return Name_Find;
   end Internal_Expanded_Name;

   --------------
   -- Expanded --
   --------------

   function Expanded (E : Node_Id) return Boolean is
   begin
      return Get_Name_Table_Byte (Internal_Expanded_Name (E)) = 1;
   end Expanded;

   ------------------
   -- Set_Expanded --
   ------------------

   procedure Set_Expanded (E : Node_Id) is
   begin
      Set_Name_Table_Byte (Internal_Expanded_Name (E), 1);
   end Set_Expanded;

end Ocarina.Backends.Expander;