content
stringlengths
23
1.05M
-- Copyright (c) 2020-2021 Bartek thindil Jasicki <thindil@laeran.pl> -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- This program 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 -- along with this program. If not, see <http://www.gnu.org/licenses/>. with Ada.Strings; use Ada.Strings; with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Containers.Generic_Array_Sort; with Tcl.Ada; use Tcl.Ada; with Tcl.Tk.Ada; use Tcl.Tk.Ada; with Tcl.Tk.Ada.Event; use Tcl.Tk.Ada.Event; with Tcl.Tk.Ada.Grid; with Tcl.Tk.Ada.Widgets; use Tcl.Tk.Ada.Widgets; with Tcl.Tk.Ada.Widgets.Canvas; use Tcl.Tk.Ada.Widgets.Canvas; with Tcl.Tk.Ada.Widgets.Menu; use Tcl.Tk.Ada.Widgets.Menu; with Tcl.Tk.Ada.Widgets.Toplevel; use Tcl.Tk.Ada.Widgets.Toplevel; with Tcl.Tk.Ada.Widgets.Toplevel.MainWindow; use Tcl.Tk.Ada.Widgets.Toplevel.MainWindow; with Tcl.Tk.Ada.Widgets.TtkButton; use Tcl.Tk.Ada.Widgets.TtkButton; with Tcl.Tk.Ada.Widgets.TtkEntry.TtkComboBox; use Tcl.Tk.Ada.Widgets.TtkEntry.TtkComboBox; with Tcl.Tk.Ada.Widgets.TtkEntry.TtkSpinBox; use Tcl.Tk.Ada.Widgets.TtkEntry.TtkSpinBox; with Tcl.Tk.Ada.Widgets.TtkFrame; use Tcl.Tk.Ada.Widgets.TtkFrame; with Tcl.Tk.Ada.Widgets.TtkLabel; use Tcl.Tk.Ada.Widgets.TtkLabel; with Tcl.Tk.Ada.Widgets.TtkScrollbar; use Tcl.Tk.Ada.Widgets.TtkScrollbar; with Tcl.Tk.Ada.Winfo; use Tcl.Tk.Ada.Winfo; with Tcl.Tklib.Ada.Autoscroll; use Tcl.Tklib.Ada.Autoscroll; with Config; use Config; with CoreUI; use CoreUI; with Crew.Inventory; use Crew.Inventory; with Dialogs; use Dialogs; with Factions; use Factions; with Ships.Cargo; use Ships.Cargo; with Ships.Crew; use Ships.Crew; with Table; use Table; with Utils; use Utils; with Utils.UI; use Utils.UI; package body Ships.UI.Crew.Inventory is -- ****iv* SUCI/SUCI.InventoryTable -- FUNCTION -- Table with info about the crew member inventory -- SOURCE InventoryTable: Table_Widget (5); -- **** -- ****iv* SUCI/SUCI.MemberIndex -- FUNCTION -- The index of the selected crew member -- SOURCE MemberIndex: Positive; -- **** -- ****iv* SUCI/SUCI.Inventory_Indexes -- FUNCTION -- Indexes of the crew member items in inventory -- SOURCE Inventory_Indexes: Positive_Container.Vector; -- **** -- ****o* SUCI/SUCI.Update_Inventory_Command -- FUNCTION -- Update inventory list of the selected crew member -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. Unused -- Argc - Number of arguments passed to the command. -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- UpdateInventory memberindex page -- MemberIndex is the index of the crew member to show inventory, page -- is a number of the page of inventory list to show -- SOURCE function Update_Inventory_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Update_Inventory_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Interp); Member: Member_Data (Amount_Of_Attributes => Attributes_Amount, Amount_Of_Skills => Skills_Amount); Page: constant Positive := (if Argc = 3 then Positive'Value(CArgv.Arg(Argv, 2)) else 1); Start_Row: constant Positive := ((Page - 1) * Game_Settings.Lists_Limit) + 1; Current_Row: Positive := 1; begin MemberIndex := Positive'Value(CArgv.Arg(Argv, 1)); Member := Player_Ship.Crew(MemberIndex); if InventoryTable.Row > 1 then ClearTable(InventoryTable); end if; if Inventory_Indexes.Length /= Member.Inventory.Length then Inventory_Indexes.Clear; for I in Member.Inventory.Iterate loop Inventory_Indexes.Append(Inventory_Container.To_Index(I)); end loop; end if; Load_Inventory_Loop : for I of Inventory_Indexes loop if Current_Row < Start_Row then Current_Row := Current_Row + 1; goto End_Of_Loop; end if; AddButton (InventoryTable, GetItemName(Member.Inventory(I), False, False), "Show available item's options", "ShowInventoryMenu " & CArgv.Arg(Argv, 1) & Positive'Image(I), 1); AddProgressBar (InventoryTable, Member.Inventory(I).Durability, Default_Item_Durability, "The current durability level of the selected item.", "ShowInventoryMenu " & CArgv.Arg(Argv, 1) & Positive'Image(I), 2); if ItemIsUsed(MemberIndex, I) then AddCheckButton (InventoryTable, "The item is used by the crew member", "ShowInventoryMenu " & CArgv.Arg(Argv, 1) & Positive'Image(I), True, 3); else AddCheckButton (InventoryTable, "The item isn't used by the crew member", "ShowInventoryMenu " & CArgv.Arg(Argv, 1) & Positive'Image(I), False, 3); end if; AddButton (InventoryTable, Positive'Image(Member.Inventory(I).Amount), "The amount of the item owned by the crew member", "ShowInventoryMenu " & CArgv.Arg(Argv, 1) & Positive'Image(I), 4); AddButton (InventoryTable, Positive'Image (Member.Inventory(I).Amount * Items_List(Member.Inventory(I).ProtoIndex).Weight) & " kg", "The total weight of the items", "ShowInventoryMenu " & CArgv.Arg(Argv, 1) & Positive'Image(I), 5, True); exit Load_Inventory_Loop when InventoryTable.Row = Game_Settings.Lists_Limit + 1; <<End_Of_Loop>> end loop Load_Inventory_Loop; if Page > 1 then AddPagination (InventoryTable, "UpdateInventory " & CArgv.Arg(Argv, 1) & Positive'Image(Page - 1), (if InventoryTable.Row < Game_Settings.Lists_Limit + 1 then "" else "UpdateInventory " & CArgv.Arg(Argv, 1) & Positive'Image(Page + 1))); elsif InventoryTable.Row = Game_Settings.Lists_Limit + 1 then AddPagination (InventoryTable, "", "UpdateInventory " & CArgv.Arg(Argv, 1) & Positive'Image(Page + 1)); end if; UpdateTable(InventoryTable); return TCL_OK; end Update_Inventory_Command; -- ****it* SUCI/SUCI.Inventory_Sort_Orders -- FUNCTION -- Sorting orders for items inside various inventories -- OPTIONS -- NAMEASC - Sort items by name ascending -- NAMEDESC - Sort items by name descending -- DURABILITYASC - Sort items by durability ascending -- DURABILITYDESC - Sort items by durability descending -- TYPEASC - Sort items by type ascending -- TYPEDESC - Sort items by type descending -- AMOUNTASC - Sort items by amount ascending -- AMOUNTDESC - Sort items by amount descending -- WEIGHTASC - Sort items by total weight ascending -- WEIGHTDESC - Sort items by total weight descending -- USEDASC - Sort items by use status (mobs inventory only) ascending -- USEDDESC - Sort items by use status (mobs inventory only) descending -- NONE - No sorting items (default) -- HISTORY -- 6.4 - Added -- SOURCE type Inventory_Sort_Orders is (NAMEASC, NAMEDESC, DURABILITYASC, DURABILITYDESC, TYPEASC, TYPEDESC, AMOUNTASC, AMOUNTDESC, WEIGHTASC, WEIGHTDESC, USEDASC, USEDDESC, NONE) with Default_Value => NONE; -- **** -- ****id* SUCI/SUCI.Default_Inventory_Sort_Order -- FUNCTION -- Default sorting order for items in various inventories -- HISTORY -- 6.4 - Added -- SOURCE Default_Inventory_Sort_Order: constant Inventory_Sort_Orders := NONE; -- **** -- ****iv* SUCI/SUCI.Inventory_Sort_Order -- FUNCTION -- The current sorting order of items in various inventories -- SOURCE Inventory_Sort_Order: Inventory_Sort_Orders := Default_Inventory_Sort_Order; -- **** -- ****o* SUCI/SUCI.Sort_Crew_Inventory_Command -- FUNCTION -- Sort the selected crew member inventory -- PARAMETERS -- ClientData - Custom data send to the command. -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- SortCrewInventory x -- X is X axis coordinate where the player clicked the mouse button -- SOURCE function Sort_Crew_Inventory_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Sort_Crew_Inventory_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(Argc); Column: constant Positive := (if CArgv.Arg(Argv, 1) = "-1" then Positive'Last else Get_Column_Number (InventoryTable, Natural'Value(CArgv.Arg(Argv, 1)))); type Local_Item_Data is record Name: Unbounded_String; Damage: Float; Item_Type: Unbounded_String; Amount: Positive; Weight: Positive; Used: Boolean; Id: Positive; end record; type Inventory_Array is array(Positive range <>) of Local_Item_Data; Local_Inventory: Inventory_Array (1 .. Positive(Player_Ship.Crew(MemberIndex).Inventory.Length)); function "<"(Left, Right: Local_Item_Data) return Boolean is begin if Inventory_Sort_Order = NAMEASC and then Left.Name < Right.Name then return True; end if; if Inventory_Sort_Order = NAMEDESC and then Left.Name > Right.Name then return True; end if; if Inventory_Sort_Order = DURABILITYASC and then Left.Damage < Right.Damage then return True; end if; if Inventory_Sort_Order = DURABILITYDESC and then Left.Damage > Right.Damage then return True; end if; if Inventory_Sort_Order = TYPEASC and then Left.Item_Type < Right.Item_Type then return True; end if; if Inventory_Sort_Order = TYPEDESC and then Left.Item_Type > Right.Item_Type then return True; end if; if Inventory_Sort_Order = AMOUNTASC and then Left.Amount < Right.Amount then return True; end if; if Inventory_Sort_Order = AMOUNTDESC and then Left.Amount > Right.Amount then return True; end if; if Inventory_Sort_Order = WEIGHTASC and then Left.Weight < Right.Weight then return True; end if; if Inventory_Sort_Order = WEIGHTDESC and then Left.Weight > Right.Weight then return True; end if; if Inventory_Sort_Order = USEDASC and then Left.Used < Right.Used then return True; end if; if Inventory_Sort_Order = USEDDESC and then Left.Used > Right.Used then return True; end if; return False; end "<"; procedure Sort_Inventory is new Ada.Containers.Generic_Array_Sort (Index_Type => Positive, Element_Type => Local_Item_Data, Array_Type => Inventory_Array); begin case Column is when 1 => if Inventory_Sort_Order = NAMEASC then Inventory_Sort_Order := NAMEDESC; else Inventory_Sort_Order := NAMEASC; end if; when 2 => if Inventory_Sort_Order = DURABILITYASC then Inventory_Sort_Order := DURABILITYDESC; else Inventory_Sort_Order := DURABILITYASC; end if; when 3 => if Inventory_Sort_Order = USEDASC then Inventory_Sort_Order := USEDDESC; else Inventory_Sort_Order := USEDASC; end if; when 4 => if Inventory_Sort_Order = AMOUNTASC then Inventory_Sort_Order := AMOUNTDESC; else Inventory_Sort_Order := AMOUNTASC; end if; when 5 => if Inventory_Sort_Order = WEIGHTASC then Inventory_Sort_Order := WEIGHTDESC; else Inventory_Sort_Order := WEIGHTASC; end if; when others => null; end case; if Inventory_Sort_Order = NONE then return Update_Inventory_Command (ClientData, Interp, 2, CArgv.Empty & "UpdateInventory" & Trim(Positive'Image(MemberIndex), Left)); end if; for I in Player_Ship.Crew(MemberIndex).Inventory.Iterate loop Local_Inventory(Inventory_Container.To_Index(I)) := (Name => To_Unbounded_String (GetItemName (Player_Ship.Crew(MemberIndex).Inventory(I), False, False)), Damage => Float(Player_Ship.Crew(MemberIndex).Inventory(I).Durability) / Float(Default_Item_Durability), Item_Type => (if Items_List (Player_Ship.Crew(MemberIndex).Inventory(I).ProtoIndex) .ShowType /= Null_Unbounded_String then Items_List (Player_Ship.Crew(MemberIndex).Inventory(I).ProtoIndex) .ShowType else Items_List (Player_Ship.Crew(MemberIndex).Inventory(I).ProtoIndex) .IType), Amount => Player_Ship.Crew(MemberIndex).Inventory(I).Amount, Weight => Player_Ship.Crew(MemberIndex).Inventory(I).Amount * Items_List(Player_Ship.Crew(MemberIndex).Inventory(I).ProtoIndex) .Weight, Used => ItemIsUsed(MemberIndex, Inventory_Container.To_Index(I)), Id => Inventory_Container.To_Index(I)); end loop; Sort_Inventory(Local_Inventory); Inventory_Indexes.Clear; for Item of Local_Inventory loop Inventory_Indexes.Append(Item.Id); end loop; return Update_Inventory_Command (ClientData, Interp, 2, CArgv.Empty & "UpdateInventory" & Trim(Positive'Image(MemberIndex), Left)); end Sort_Crew_Inventory_Command; -- ****o* SUCI/SUCI.Show_Member_Inventory_Command -- FUNCTION -- Show inventory of the selected crew member -- PARAMETERS -- ClientData - Custom data send to the command. -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- ShowMemberInventory memberindex -- MemberIndex is the index of the crew member to show inventory -- SOURCE function Show_Member_Inventory_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Show_Member_Inventory_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is MemberDialog: constant Ttk_Frame := Create_Dialog (Name => ".memberdialog", Title => "Inventory of " & To_String (Player_Ship.Crew(Positive'Value(CArgv.Arg(Argv, 1))).Name), Columns => 2); YScroll: constant Ttk_Scrollbar := Create (MemberDialog & ".yscroll", "-orient vertical -command [list .memberdialog.canvas yview]"); MemberCanvas: constant Tk_Canvas := Create (MemberDialog & ".canvas", "-yscrollcommand [list " & YScroll & " set]"); MemberFrame: constant Ttk_Frame := Create(MemberCanvas & ".frame"); Height, Width: Positive := 10; FreeSpaceLabel: constant Ttk_Label := Create (MemberFrame & ".freespace", "-text {Free inventory space:" & Integer'Image (FreeInventory(Positive'Value(CArgv.Arg(Argv, 1)), 0)) & " kg} -wraplength 400"); Close_Button: constant Ttk_Button := Create (MemberDialog & ".button", "-text Close -command {CloseDialog " & MemberDialog & "}"); begin Tcl.Tk.Ada.Grid.Grid(MemberCanvas, "-padx 5 -pady 5"); Tcl.Tk.Ada.Grid.Grid (YScroll, "-row 1 -column 1 -padx 5 -pady 5 -sticky ns"); Autoscroll(YScroll); Tcl.Tk.Ada.Grid.Grid(FreeSpaceLabel); Height := Height + Positive'Value(Winfo_Get(FreeSpaceLabel, "reqheight")); InventoryTable := CreateTable (Widget_Image(MemberFrame), (To_Unbounded_String("Name"), To_Unbounded_String("Durability"), To_Unbounded_String("Used"), To_Unbounded_String("Amount"), To_Unbounded_String("Weight")), YScroll, "SortCrewInventory", "Press mouse button to sort the inventory."); if Update_Inventory_Command(ClientData, Interp, Argc, Argv) = TCL_ERROR then return TCL_ERROR; end if; Height := Height + Positive'Value(Winfo_Get(InventoryTable.Canvas, "reqheight")); Width := Positive'Value(Winfo_Get(InventoryTable.Canvas, "reqwidth")); Tcl.Tk.Ada.Grid.Grid(Close_Button, "-pady 5"); Widgets.Focus(InventoryTable.Canvas); Bind (Close_Button, "<Tab>", "{focus " & InventoryTable.Canvas & ";break}"); Bind(Close_Button, "<Escape>", "{" & Close_Button & " invoke;break}"); Bind (InventoryTable.Canvas, "<Escape>", "{" & Close_Button & " invoke;break}"); if Height > 500 then Height := 500; end if; configure (MemberFrame, "-height" & Positive'Image(Height) & " -width" & Positive'Image(Width)); configure (MemberCanvas, "-height" & Positive'Image(Height) & " -width" & Positive'Image(Width + 15)); Canvas_Create (MemberCanvas, "window", "0 0 -anchor nw -window " & MemberFrame); Tcl_Eval(Interp, "update"); configure (MemberCanvas, "-scrollregion [list " & BBox(MemberCanvas, "all") & "]"); Show_Dialog (Dialog => MemberDialog, Relative_X => 0.2, Relative_Y => 0.2); return TCL_OK; end Show_Member_Inventory_Command; -- ****o* SUCI/SUCI.Set_Use_Item_Command -- FUNCTION -- Set if item is used by a crew member or not -- PARAMETERS -- ClientData - Custom data send to the command. -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- SetUseItem memberindex itemindex -- Memberindex is the index of the crew member in which inventory item will -- be set, itemindex is the index of the item which will be set -- SOURCE function Set_Use_Item_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Set_Use_Item_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(Argc); MemberIndex: constant Positive := Positive'Value(CArgv.Arg(Argv, 1)); ItemIndex: constant Positive := Positive'Value(CArgv.Arg(Argv, 2)); ItemType: constant Unbounded_String := Items_List (Player_Ship.Crew(MemberIndex).Inventory(ItemIndex).ProtoIndex) .IType; begin if ItemIsUsed(MemberIndex, ItemIndex) then TakeOffItem(MemberIndex, ItemIndex); return Sort_Crew_Inventory_Command (ClientData, Interp, 2, CArgv.Empty & "SortCrewInventory" & "-1"); end if; if ItemType = Weapon_Type then if Items_List (Player_Ship.Crew(MemberIndex).Inventory(ItemIndex).ProtoIndex) .Value (4) = 2 and Player_Ship.Crew(MemberIndex).Equipment(2) /= 0 then ShowMessage (Text => To_String(Player_Ship.Crew(MemberIndex).Name) & " can't use this weapon because have shield equiped. Take off shield first.", Title => "Shield in use"); return TCL_OK; end if; Player_Ship.Crew(MemberIndex).Equipment(1) := ItemIndex; elsif ItemType = Shield_Type then if Player_Ship.Crew(MemberIndex).Equipment(1) > 0 then if Items_List (Player_Ship.Crew(MemberIndex).Inventory (Player_Ship.Crew(MemberIndex).Equipment(1)) .ProtoIndex) .Value (4) = 2 then ShowMessage (Text => To_String(Player_Ship.Crew(MemberIndex).Name) & " can't use shield because have equiped two-hand weapon. Take off weapon first.", Title => "Two handed weapon in use"); return TCL_OK; end if; end if; Player_Ship.Crew(MemberIndex).Equipment(2) := ItemIndex; elsif ItemType = Head_Armor then Player_Ship.Crew(MemberIndex).Equipment(3) := ItemIndex; elsif ItemType = Chest_Armor then Player_Ship.Crew(MemberIndex).Equipment(4) := ItemIndex; elsif ItemType = Arms_Armor then Player_Ship.Crew(MemberIndex).Equipment(5) := ItemIndex; elsif ItemType = Legs_Armor then Player_Ship.Crew(MemberIndex).Equipment(6) := ItemIndex; elsif Tools_List.Find_Index(Item => ItemType) /= UnboundedString_Container.No_Index then Player_Ship.Crew(MemberIndex).Equipment(7) := ItemIndex; end if; return Sort_Crew_Inventory_Command (ClientData, Interp, 2, CArgv.Empty & "SortCrewInventory" & "-1"); end Set_Use_Item_Command; -- ****o* SUCI/SUCI.Show_Move_Item_Command -- FUNCTION -- Show UI to move the selected item to the ship cargo -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- ShowMoveItem memberindex itemindex -- Memberindex is the index of the crew member in which inventory item will -- be set, itemindex is the index of the item which will be set -- SOURCE function Show_Move_Item_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Show_Move_Item_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Interp, Argc); MemberIndex: constant Positive := Positive'Value(CArgv.Arg(Argv, 1)); ItemIndex: constant Positive := Positive'Value(CArgv.Arg(Argv, 2)); ItemDialog: constant Ttk_Frame := Create_Dialog (".itemdialog", "Move " & GetItemName(Player_Ship.Crew(MemberIndex).Inventory(ItemIndex)) & " to ship cargo", 400, 2, ".memberdialog"); Button: Ttk_Button := Create (ItemDialog & ".movebutton", "-text Move -command {MoveItem " & CArgv.Arg(Argv, 1) & " " & CArgv.Arg(Argv, 2) & "}"); Label: Ttk_Label; MaxAmount: constant Positive := Player_Ship.Crew(MemberIndex).Inventory(ItemIndex).Amount; AmountBox: constant Ttk_SpinBox := Create (ItemDialog & ".amount", "-width 5 -from 1.0 -to" & Float'Image(Float(MaxAmount)) & " -validate key -validatecommand {ValidateMoveAmount" & Positive'Image(MaxAmount) & " %P}"); begin Label := Create (ItemDialog & ".amountlbl", "-text {Amount (max:" & Positive'Image(MaxAmount) & "):}"); Tcl.Tk.Ada.Grid.Grid(Label, "-padx 5"); Set(AmountBox, "1"); Tcl.Tk.Ada.Grid.Grid(AmountBox, "-column 1 -row 1"); Bind (AmountBox, "<Escape>", "{" & ItemDialog & ".cancelbutton invoke;break}"); Tcl.Tk.Ada.Grid.Grid(Button, "-padx {5 0} -pady {0 5}"); Bind (Button, "<Escape>", "{" & ItemDialog & ".cancelbutton invoke;break}"); Button := Create (ItemDialog & ".cancelbutton", "-text Cancel -command {CloseDialog " & ItemDialog & " .memberdialog;focus .memberdialog.canvas.frame.button}"); Tcl.Tk.Ada.Grid.Grid(Button, "-column 1 -row 2 -padx {0 5} -pady {0 5}"); Focus(Button); Bind(Button, "<Tab>", "{focus " & ItemDialog & ".movebutton;break}"); Bind(Button, "<Escape>", "{" & Button & " invoke;break}"); Show_Dialog(ItemDialog); return TCL_OK; end Show_Move_Item_Command; -- ****o* SUCI/SUCI.Move_Item_Command -- FUNCTION -- Move the selected item to the ship cargo -- PARAMETERS -- ClientData - Custom data send to the command. -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- MoveItem memberindex itemindex -- Memberindex is the index of the crew member in which inventory item will -- be set, itemindex is the index of the item which will be set -- SOURCE function Move_Item_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Move_Item_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(Argc); Amount: Positive; MemberIndex: constant Positive := Positive'Value(CArgv.Arg(Argv, 1)); ItemIndex: constant Positive := Positive'Value(CArgv.Arg(Argv, 2)); ItemDialog: Tk_Toplevel := Get_Widget(".itemdialog", Interp); AmountBox: constant Ttk_SpinBox := Get_Widget(ItemDialog & ".amount", Interp); TypeBox: constant Ttk_ComboBox := Get_Widget (Main_Paned & ".shipinfoframe.cargo.canvas.frame.selecttype.combo", Interp); begin Amount := Positive'Value(Get(AmountBox)); if FreeCargo (0 - (Items_List (Player_Ship.Crew(MemberIndex).Inventory(ItemIndex).ProtoIndex) .Weight * Amount)) < 0 then ShowMessage (Text => "No free space in ship cargo for that amount of " & GetItemName(Player_Ship.Crew(MemberIndex).Inventory(ItemIndex)), Title => "No free space in cargo"); return TCL_OK; end if; UpdateCargo (Ship => Player_Ship, ProtoIndex => Player_Ship.Crew(MemberIndex).Inventory(ItemIndex).ProtoIndex, Amount => Amount, Durability => Player_Ship.Crew(MemberIndex).Inventory(ItemIndex).Durability, Price => Player_Ship.Crew(MemberIndex).Inventory(ItemIndex).Price); UpdateInventory (MemberIndex => MemberIndex, Amount => (0 - Amount), InventoryIndex => ItemIndex); if (Player_Ship.Crew(MemberIndex).Order = Clean and FindItem (Inventory => Player_Ship.Crew(MemberIndex).Inventory, ItemType => Cleaning_Tools) = 0) or ((Player_Ship.Crew(MemberIndex).Order = Upgrading or Player_Ship.Crew(MemberIndex).Order = Repair) and FindItem (Inventory => Player_Ship.Crew(MemberIndex).Inventory, ItemType => Repair_Tools) = 0) then GiveOrders(Player_Ship, MemberIndex, Rest); end if; Destroy(ItemDialog); Generate(TypeBox, "<<ComboboxSelected>>"); Tcl_Eval(Interp, "CloseDialog {.itemdialog .memberdialog}"); return Sort_Crew_Inventory_Command (ClientData, Interp, 2, CArgv.Empty & "SortCrewInventory" & "-1"); end Move_Item_Command; -- ****o* SUCI/SUCI.Validate_Move_Amount_Command -- FUNCTION -- Validate amount of the item to move -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- ValidateMoveAmount -- SOURCE function Validate_Move_Amount_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Validate_Move_Amount_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Argc); Amount: Positive; begin Amount := Positive'Value(CArgv.Arg(Argv, 2)); if Amount > Positive'Value(CArgv.Arg(Argv, 1)) then Tcl_SetResult(Interp, "0"); return TCL_OK; end if; Tcl_SetResult(Interp, "1"); return TCL_OK; exception when Constraint_Error => Tcl_SetResult(Interp, "0"); return TCL_OK; end Validate_Move_Amount_Command; -- ****o* SUCI/SUCI.Show_Inventory_Item_Info_Command -- FUNCTION -- Show detailed information about the selected item in crew member -- inventory -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- ValidateMoveAmount -- SOURCE function Show_Inventory_Item_Info_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Show_Inventory_Item_Info_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Interp, Argc); begin Show_Inventory_Item_Info (".memberdialog", Positive'Value(CArgv.Arg(Argv, 2)), Positive'Value(CArgv.Arg(Argv, 1))); return TCL_OK; end Show_Inventory_Item_Info_Command; -- ****if* SUCI/SUCI.Show_Inventory_Menu_Command -- FUNCTION -- Show the menu with available the selected item options -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- ShowInventoryMenu moduleindex -- ModuleIndex is the index of the item's menu to show -- SOURCE function Show_Inventory_Menu_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Show_Inventory_Menu_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Argc); ItemMenu: Tk_Menu := Get_Widget(".itemmenu", Interp); MemberIndex: constant Positive := Positive'Value(CArgv.Arg(Argv, 1)); begin if (Winfo_Get(ItemMenu, "exists")) = "0" then ItemMenu := Create(".itemmenu", "-tearoff false"); end if; Delete(ItemMenu, "0", "end"); if ItemIsUsed(MemberIndex, Positive'Value(CArgv.Arg(Argv, 2))) then Menu.Add (ItemMenu, "command", "-label {Unequip} -command {SetUseItem " & CArgv.Arg(Argv, 1) & " " & CArgv.Arg(Argv, 2) & "}"); else Menu.Add (ItemMenu, "command", "-label {Equip} -command {SetUseItem " & CArgv.Arg(Argv, 1) & " " & CArgv.Arg(Argv, 2) & "}"); end if; Menu.Add (ItemMenu, "command", "-label {Move the item to the ship cargo} -command {ShowMoveItem " & CArgv.Arg(Argv, 1) & " " & CArgv.Arg(Argv, 2) & "}"); Menu.Add (ItemMenu, "command", "-label {Show more info about the item} -command {ShowInventoryItemInfo " & CArgv.Arg(Argv, 1) & " " & CArgv.Arg(Argv, 2) & "}"); Tk_Popup (ItemMenu, Winfo_Get(Get_Main_Window(Interp), "pointerx"), Winfo_Get(Get_Main_Window(Interp), "pointery")); return TCL_OK; end Show_Inventory_Menu_Command; procedure AddCommands is begin Add_Command("UpdateInventory", Update_Inventory_Command'Access); Add_Command("ShowMemberInventory", Show_Member_Inventory_Command'Access); Add_Command("SetUseItem", Set_Use_Item_Command'Access); Add_Command("ShowMoveItem", Show_Move_Item_Command'Access); Add_Command("MoveItem", Move_Item_Command'Access); Add_Command("ValidateMoveAmount", Validate_Move_Amount_Command'Access); Add_Command ("ShowInventoryItemInfo", Show_Inventory_Item_Info_Command'Access); Add_Command("ShowInventoryMenu", Show_Inventory_Menu_Command'Access); Add_Command("SortCrewInventory", Sort_Crew_Inventory_Command'Access); end AddCommands; end Ships.UI.Crew.Inventory;
with STRINGS_PACKAGE; use STRINGS_PACKAGE; with LATIN_FILE_NAMES; use LATIN_FILE_NAMES; with DEVELOPER_PARAMETERS; use DEVELOPER_PARAMETERS; with PREFACE; with INFLECTIONS_PACKAGE; use INFLECTIONS_PACKAGE; with DICTIONARY_PACKAGE; use DICTIONARY_PACKAGE; pragma ELABORATE(INFLECTIONS_PACKAGE); pragma ELABORATE(DICTIONARY_PACKAGE); package body ADDONS_PACKAGE is use TEXT_IO; use PART_OF_SPEECH_TYPE_IO; use TARGET_ENTRY_IO; use PART_ENTRY_IO; --use KIND_ENTRY_IO; use STEM_KEY_TYPE_IO; function EQU(C, D : CHARACTER) return BOOLEAN is begin if (D = 'u') or (D = 'v') then if (C = 'u') or (C = 'v') then return TRUE; else return FALSE; end if; else return C = D; end if; end EQU; function EQU(S, T : STRING) return BOOLEAN is begin if S'LENGTH /= T'LENGTH then return FALSE; end if; for I in 1..S'LENGTH loop if not EQU(S(S'FIRST+I-1), T(T'FIRST+I-1)) then return FALSE; end if; end loop; return TRUE; end EQU; procedure LOAD_ADDONS (FILE_NAME : in STRING) is use PART_OF_SPEECH_TYPE_IO; use TACKON_ENTRY_IO; use PREFIX_ENTRY_IO; use SUFFIX_ENTRY_IO; --use DICT_IO; S : STRING(1..100); L, LAST, TIC, PRE, SUF, TAC, PAC : INTEGER := 0; ADDONS_FILE : TEXT_IO.FILE_TYPE; D_K : constant DICTIONARY_KIND := ADDONS; POFS: PART_OF_SPEECH_TYPE; DE : DICTIONARY_ENTRY := NULL_DICTIONARY_ENTRY; MEAN : MEANING_TYPE := NULL_MEANING_TYPE; M : INTEGER := 1; --TG : TARGET_ENTRY; TN : TACKON_ENTRY; PM : PREFIX_ITEM; TS : STEM_TYPE; procedure GET_NO_COMMENT_LINE(F : in TEXT_IO.FILE_TYPE; S : out STRING; LAST : out INTEGER) is T : STRING(1..250) := (others => ' '); L : INTEGER := 0; begin LAST := 0; while not END_OF_FILE(F) loop GET_LINE(F, T, L); if L >= 2 and then (HEAD(TRIM(T), 250)(1..2) = "--" or HEAD(TRIM(T), 250)(1..2) = " ") then null; else S(1..L) := T(1..L); LAST := L; exit; end if; end loop; end GET_NO_COMMENT_LINE; procedure EXTRACT_FIX(S : in STRING; XFIX : out FIX_TYPE; XC : out CHARACTER) is ST : constant STRING := TRIM(S); L : INTEGER := ST'LENGTH; J : INTEGER := 0; begin for I in 1..L loop J := I; exit when ( (I < L) and then (ST(I+1) = ' ') ); end loop; XFIX := HEAD(ST(1..J), MAX_FIX_SIZE); if J = L then -- there is no CONNECT CHARACTER XC := ' '; return; else for I in J+1..L loop if ST(I) /= ' ' then XC := ST(I); exit; end if; end loop; end if; return; end EXTRACT_FIX; begin OPEN(ADDONS_FILE, IN_FILE, FILE_NAME); PREFACE.PUT("ADDONS"); PREFACE.PUT(" loading "); -- if DICT_IO.IS_OPEN(DICT_FILE(D_K)) then -- DICT_IO.DELETE(DICT_FILE(D_K)); -- end if; -- DICT_IO.CREATE(DICT_FILE(D_K), DICT_IO.INOUT_FILE, -- --ADD_FILE_NAME_EXTENSION(DICT_FILE_NAME, DICTIONARY_KIND'IMAGE(D_K))); -- ""); -- while not END_OF_FILE(ADDONS_FILE) loop DE := NULL_DICTIONARY_ENTRY; GET_NO_COMMENT_LINE(ADDONS_FILE, S, LAST); --TEXT_IO.PUT_LINE(S(1..LAST)); GET(S(1..LAST), POFS, L); case POFS is when TACKON => TS := HEAD(TRIM(S(L+1..LAST)), MAX_STEM_SIZE); DE.STEMS(1) := TS; GET_LINE(ADDONS_FILE, S, LAST); GET(S(1..LAST), TN, L); GET_LINE(ADDONS_FILE, S, LAST); MEAN := HEAD(S(1..LAST), MAX_MEANING_SIZE); if TN.BASE.POFS= PACK and then (TN.BASE.PACK.DECL.WHICH = 1 or TN.BASE.PACK.DECL.WHICH = 2) and then MEAN(1..9) = "PACKON w/" then PAC := PAC + 1; PACKONS (PAC).POFS:= POFS; PACKONS(PAC).TACK := TS; PACKONS(PAC).ENTR := TN; -- DICT_IO.SET_INDEX(DICT_FILE(D_K), M); -- DE.MEAN := MEAN; -- DICT_IO.WRITE(DICT_FILE(D_K), DE); PACKONS (PAC).MNPC := M; MEANS(M) := MEAN; M := M + 1; else TAC := TAC + 1; TACKONS (TAC).POFS:= POFS; TACKONS(TAC).TACK := TS; TACKONS(TAC).ENTR := TN; -- DICT_IO.SET_INDEX(DICT_FILE(D_K), M); -- DE.MEAN := MEAN; -- DICT_IO.WRITE(DICT_FILE(D_K), DE); -- --DICT_IO.WRITE(DICT_FILE(D_K), MEAN); TACKONS (TAC).MNPC := M; MEANS(M) := MEAN; M := M + 1; end if; NUMBER_OF_PACKONS := PAC; NUMBER_OF_TACKONS := TAC; when PREFIX => EXTRACT_FIX(S(L+1..LAST), PM.FIX, PM.CONNECT); GET_LINE(ADDONS_FILE, S, LAST); GET(S(1..LAST), PM.ENTR, L); GET_LINE(ADDONS_FILE, S, LAST); MEAN := HEAD(S(1..LAST), MAX_MEANING_SIZE); if PM.ENTR.ROOT = PACK then TIC := TIC + 1; TICKONS (TIC).POFS:= POFS; TICKONS(TIC).FIX := PM.FIX; TICKONS(TIC).CONNECT := PM.CONNECT; TICKONS(TIC).ENTR := PM.ENTR; -- DICT_IO.SET_INDEX(DICT_FILE(D_K), M); -- DE.MEAN := MEAN; -- DICT_IO.WRITE(DICT_FILE(D_K), DE); -- --DICT_IO.WRITE(DICT_FILE(D_K), MEAN); TICKONS (TIC).MNPC := M; MEANS(M) := MEAN; M := M + 1; else PRE := PRE + 1; PREFIXES(PRE).POFS:= POFS; PREFIXES(PRE).FIX := PM.FIX; PREFIXES(PRE).CONNECT := PM.CONNECT; PREFIXES(PRE).ENTR := PM.ENTR; -- DICT_IO.SET_INDEX(DICT_FILE(D_K), M); DE.MEAN := MEAN; -- DICT_IO.WRITE(DICT_FILE(D_K), DE); -- --DICT_IO.WRITE(DICT_FILE(D_K), MEAN); PREFIXES(PRE).MNPC := M; MEANS(M) := MEAN; M := M + 1; end if; NUMBER_OF_TICKONS := TIC; NUMBER_OF_PREFIXES := PRE; when SUFFIX => SUF := SUF + 1; SUFFIXES(SUF).POFS:= POFS; --TEXT_IO.PUT_LINE(S(1..LAST)); EXTRACT_FIX(S(L+1..LAST), SUFFIXES(SUF).FIX, SUFFIXES(SUF).CONNECT); --TEXT_IO.PUT("@1"); GET_LINE(ADDONS_FILE, S, LAST); --TEXT_IO.PUT("@2"); --TEXT_IO.PUT_LINE(S(1..LAST) & "<"); --TEXT_IO.PUT("@2"); GET(S(1..LAST), SUFFIXES(SUF).ENTR, L); --TEXT_IO.PUT("@3"); GET_LINE(ADDONS_FILE, S, LAST); --TEXT_IO.PUT("@4"); MEAN := HEAD(S(1..LAST), MAX_MEANING_SIZE); --TEXT_IO.PUT("@5"); -- -- DICT_IO.SET_INDEX(DICT_FILE(D_K), M); -- DE.MEAN := MEAN; -- DICT_IO.WRITE(DICT_FILE(D_K), DE); -- --DICT_IO.WRITE(DICT_FILE(D_K), MEAN); SUFFIXES(SUF).MNPC := M; MEANS(M) := MEAN; M := M + 1; NUMBER_OF_SUFFIXES := SUF; when others => TEXT_IO.PUT_LINE("Bad ADDON !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); TEXT_IO.PUT_LINE(S(1..LAST)); raise TEXT_IO.DATA_ERROR; end case; end loop; PREFACE.PUT(TAC, 1); PREFACE.PUT("+"); PREFACE.PUT(PAC, 2); PREFACE.PUT(" TACKONS "); PREFACE.PUT(TIC, 1); PREFACE.PUT("+"); PREFACE.PUT(PRE, 3); PREFACE.PUT(" PREFIXES "); PREFACE.PUT(SUF, 3); PREFACE.PUT(" SUFFIXES "); PREFACE.SET_COL(60); PREFACE.PUT_LINE("-- Loaded correctly"); CLOSE(ADDONS_FILE); --for I in MEANS'RANGE loop -- TEXT_IO.PUT(INTEGER'IMAGE(INTEGER(I))); TEXT_IO.PUT_LINE("--" & MEANS(I)); --end loop; exception when TEXT_IO.NAME_ERROR => PREFACE.PUT_LINE("No ADDONS file "); null; when TEXT_IO.DATA_ERROR => PREFACE.PUT_LINE(S(1..LAST)); PREFACE.PUT_LINE("No further ADDONS read "); CLOSE(ADDONS_FILE); when others => PREFACE.PUT_LINE("Exception in LOAD_ADDONS"); PREFACE.PUT_LINE(S(1..LAST)); end LOAD_ADDONS; function SUBTRACT_TACKON(W : STRING; X : TACKON_ITEM) return STRING is WD : constant STRING := TRIM(W); L : constant INTEGER := WD'LENGTH; XF : constant STRING := TRIM(X.TACK); Z : constant INTEGER := XF'LENGTH; begin --PUT_LINE("In SUB TACKON " & INTEGER'IMAGE(L) & INTEGER'IMAGE(Z)); if WORDS_MDEV(USE_TACKONS) and then L > Z and then --WD(L-Z+1..L) = XF(1..Z) then EQU(WD(L-Z+1..L), XF(1..Z)) then --PUT("In SUBTRACT_TACKON we got a hit "); PUT_LINE(X.TACK); return WD(1..L-Z); else --PUT("In SUBTRACT_TACKON NO hit "); PUT_LINE(X.TACK); return W; end if; end SUBTRACT_TACKON; function SUBTRACT_PREFIX(W : STRING; X : PREFIX_ITEM) return STEM_TYPE is WD : constant STRING := TRIM(W); XF : constant STRING := TRIM(X.FIX); Z : constant INTEGER := XF'LENGTH; ST : STEM_TYPE := HEAD(WD, MAX_STEM_SIZE); begin if WORDS_MDEV(USE_PREFIXES) and then X /= NULL_PREFIX_ITEM and then WD'LENGTH > Z and then --WD(1..Z) = XF(1..Z) and then EQU(WD(1..Z), XF(1..Z)) and then ( (X.CONNECT = ' ') or (WD(Z+1) = X.CONNECT) ) then ST(1..WD'LENGTH-Z) := WD(Z+1..WD'LAST); ST(WD'LENGTH-Z+1..MAX_STEM_SIZE) := NULL_STEM_TYPE(WD'LENGTH-Z+1..MAX_STEM_SIZE); end if; --PUT_LINE("SUBTRACT_PREFIX " & X.FIX & " FROM " & WD & " returns " & ST); return ST; end SUBTRACT_PREFIX; function SUBTRACT_SUFFIX(W : STRING; X : SUFFIX_ITEM) return STEM_TYPE is WD : constant STRING := TRIM(W); L : constant INTEGER := WD'LENGTH; XF : constant STRING := TRIM(X.FIX); Z : constant INTEGER := XF'LENGTH; ST : STEM_TYPE := HEAD(WD, MAX_STEM_SIZE); begin --PUT_LINE("In SUBTRACT_SUFFIX Z = " & INTEGER'IMAGE(Z) & --" CONNECT >" & X.CONNECT & '<'); if WORDS_MDEV(USE_SUFFIXES) and then X /= NULL_SUFFIX_ITEM and then WD'LENGTH > Z and then --WD(L-Z+1..L) = XF(1..Z) and then EQU(WD(L-Z+1..L), XF(1..Z)) and then ( (X.CONNECT = ' ') or (WD(L-Z) = X.CONNECT) ) then --PUT_LINE("In SUBTRACT_SUFFIX we got a hit"); ST(1..WD'LENGTH-Z) := WD(1..WD'LENGTH-Z); ST(WD'LENGTH-Z+1..MAX_STEM_SIZE) := NULL_STEM_TYPE(WD'LENGTH-Z+1..MAX_STEM_SIZE); end if; --PUT_LINE("SUBTRACT_SUFFIX " & X.FIX & " FROM " & WD & " returns " & ST); return ST; end SUBTRACT_SUFFIX; function ADD_PREFIX(STEM : STEM_TYPE; PREFIX : PREFIX_ITEM) return STEM_TYPE is FPX : constant STRING := TRIM(PREFIX.FIX) & STEM; begin if WORDS_MDEV(USE_PREFIXES) then return HEAD(FPX, MAX_STEM_SIZE); else return STEM; end if; end ADD_PREFIX; function ADD_SUFFIX(STEM : STEM_TYPE; SUFFIX : SUFFIX_ITEM) return STEM_TYPE is FPX : constant STRING := TRIM(STEM) & SUFFIX.FIX; begin if WORDS_MDEV(USE_SUFFIXES) then return HEAD(FPX, MAX_STEM_SIZE); else return STEM; end if; end ADD_SUFFIX; -- package body TARGET_ENTRY_IO is separate; -- package body TACKON_ENTRY_IO is separate; -- package body TACKON_LINE_IO is separate; -- package body PREFIX_ENTRY_IO is separate; -- package body PREFIX_LINE_IO is separate; -- package body SUFFIX_ENTRY_IO is separate; -- package body SUFFIX_LINE_IO is separate; package body TARGET_ENTRY_IO is use PART_OF_SPEECH_TYPE_IO; use NOUN_ENTRY_IO; use PRONOUN_ENTRY_IO; use PROPACK_ENTRY_IO; use ADJECTIVE_ENTRY_IO; use NUMERAL_ENTRY_IO; use ADVERB_ENTRY_IO; use VERB_ENTRY_IO; -- use KIND_ENTRY_IO; -- -- use NOUN_KIND_TYPE_IO; -- use PRONOUN_KIND_TYPE_IO; -- use INFLECTIONS_PACKAGE.INTEGER_IO; -- use VERB_KIND_TYPE_IO; SPACER : CHARACTER := ' '; NOUN : NOUN_ENTRY; PRONOUN : PRONOUN_ENTRY; PROPACK : PROPACK_ENTRY; ADJECTIVE : ADJECTIVE_ENTRY; NUMERAL : NUMERAL_ENTRY; ADVERB : ADVERB_ENTRY; VERB : VERB_ENTRY; -- NOUN_KIND : NOUN_KIND_TYPE; -- PRONOUN_KIND : PRONOUN_KIND_TYPE; -- PROPACK_KIND : PRONOUN_KIND_TYPE; -- NUMERAL_VALUE : NUMERAL_VALUE_TYPE; -- VERB_KIND : VERB_KIND_TYPE; --KIND : KIND_ENTRY; P : TARGET_ENTRY; procedure GET(F : in FILE_TYPE; P : out TARGET_ENTRY) is PS : TARGET_POFS_TYPE := X; begin GET(F, PS); GET(F, SPACER); case PS is when N => GET(F, NOUN); --GET(F, NOUN_KIND); P := (N, NOUN); --, NOUN_KIND); when PRON => GET(F, PRONOUN); --GET(F, PRONOUN_KIND); P := (PRON, PRONOUN); --, PRONOUN_KIND); when PACK => GET(F, PROPACK); --GET(F, PROPACK_KIND); P := (PACK, PROPACK); --, PROPACK_KIND); when ADJ => GET(F, ADJECTIVE); P := (ADJ, ADJECTIVE); when NUM => GET(F, NUMERAL); --GET(F, NUMERAL_VALUE); P := (NUM, NUMERAL); --, NUMERAL_VALUE); when ADV => GET(F, ADVERB); P := (ADV, ADVERB); when V => GET(F, VERB); --GET(F, VERB_KIND); P := (V, VERB); --, VERB_KIND); when X => P := (POFS=> X); end case; return; end GET; procedure GET(P : out TARGET_ENTRY) is PS : TARGET_POFS_TYPE := X; begin GET(PS); GET(SPACER); case PS is when N => GET(NOUN); --GET(NOUN_KIND); P := (N, NOUN); --, NOUN_KIND); when PRON => GET(PRONOUN); --GET(PRONOUN_KIND); P := (PRON, PRONOUN); --, PRONOUN_KIND); when PACK => GET(PROPACK); --GET(PROPACK_KIND); P := (PACK, PROPACK); --, PROPACK_KIND); when ADJ => GET(ADJECTIVE); P := (ADJ, ADJECTIVE); when NUM => GET(NUMERAL); --GET(NUMERAL_VALUE); P := (NUM, NUMERAL); --, NUMERAL_VALUE); when ADV => GET(ADVERB); P := (ADV, ADVERB); when V => GET(VERB); --GET(VERB_KIND); P := (V, VERB); --, VERB_KIND); when X => P := (POFS=> X); end case; return; end GET; procedure PUT(F : in FILE_TYPE; P : in TARGET_ENTRY) is C : POSITIVE := POSITIVE(COL(F)); begin PUT(F, P.POFS); PUT(F, ' '); case P.POFS is when N => PUT(F, P.N); --PUT(F, P.NOUN_KIND); when PRON => PUT(F, P.PRON); --PUT(F, P.PRONOUN_KIND); when PACK => PUT(F, P.PACK); --PUT(F, P.PROPACK_KIND); when ADJ => PUT(F, P.ADJ); when NUM => PUT(F, P.NUM); --PUT(F, P.NUMERAL_VALUE); when ADV => PUT(F, P.ADV); when V => PUT(F, P.V); --PUT(F, P.VERB_KIND); when others => null; end case; PUT(F, STRING'((INTEGER(COL(F))..TARGET_ENTRY_IO.DEFAULT_WIDTH+C-1 => ' '))); return; end PUT; procedure PUT(P : in TARGET_ENTRY) is C : POSITIVE := POSITIVE(COL); begin PUT(P.POFS); PUT(' '); case P.POFS is when N => PUT(P.N); --PUT(P.NOUN_KIND); when PRON => PUT(P.PRON); --PUT(P.PRONOUN_KIND); when PACK => PUT(P.PACK); --PUT(P.PROPACK_KIND); when ADJ => PUT(P.ADJ); when NUM => PUT(P.NUM); --PUT(P.NUMERAL_VALUE); when ADV => PUT(P.ADV); when V => PUT(P.V); --PUT(P.VERB_KIND); when others => null; end case; PUT(STRING'((INTEGER(COL)..TARGET_ENTRY_IO.DEFAULT_WIDTH+C-1 => ' '))); return; end PUT; procedure GET(S : in STRING; P : out TARGET_ENTRY; LAST : out INTEGER) is L : INTEGER := S'FIRST - 1; PS : TARGET_POFS_TYPE := X; begin GET(S, PS, L); L := L + 1; case PS is when N => GET(S(L+1..S'LAST), NOUN, LAST); --GET(S(L+1..S'LAST), NOUN_KIND, LAST); P := (N, NOUN); --, NOUN_KIND); when PRON => GET(S(L+1..S'LAST), PRONOUN, LAST); --GET(S(L+1..S'LAST), PRONOUN_KIND, LAST); P := (PRON, PRONOUN); --, PRONOUN_KIND); when PACK => GET(S(L+1..S'LAST), PROPACK, LAST); --GET(S(L+1..S'LAST), PROPACK_KIND, LAST); P := (PACK, PROPACK); --, PROPACK_KIND); when ADJ => GET(S(L+1..S'LAST), ADJECTIVE, LAST); P := (ADJ, ADJECTIVE); when NUM => GET(S(L+1..S'LAST), NUMERAL, LAST); --GET(S(L+1..S'LAST), NUMERAL_VALUE, LAST); P := (NUM, NUMERAL); --, NUMERAL_VALUE); when ADV => GET(S(L+1..S'LAST), ADVERB, LAST); P := (ADV, ADVERB); when V => GET(S(L+1..S'LAST), VERB, LAST); --GET(S(L+1..S'LAST), VERB_KIND, LAST); P := (V, VERB); --, VERB_KIND); when X => P := (POFS=> X); end case; return; end GET; procedure PUT(S : out STRING; P : in TARGET_ENTRY) is L : INTEGER := S'FIRST - 1; M : INTEGER := 0; begin M := L + PART_OF_SPEECH_TYPE_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.POFS); L := M + 1; S(L) := ' '; case P.POFS is when N => M := L + NOUN_ENTRY_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.N); -- M := L + NOUN_KIND_TYPE_IO.DEFAULT_WIDTH; -- PUT(S(L+1..M), P.NOUN_KIND); when PRON => M := L + PRONOUN_ENTRY_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.PRON); -- M := L + PRONOUN_KIND_TYPE_IO.DEFAULT_WIDTH; -- PUT(S(L+1..M), P.PRONOUN_KIND); when PACK => M := L + PROPACK_ENTRY_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.PACK); -- M := L + PRONOUN_KIND_TYPE_IO.DEFAULT_WIDTH; -- PUT(S(L+1..M), P.PROPACK_KIND); when ADJ => M := L + ADJECTIVE_ENTRY_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.ADJ); when NUM => M := L + NUMERAL_ENTRY_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.NUM); -- M := L + NUMERAL_VALUE_TYPE_IO_DEFAULT_WIDTH; -- PUT(S(L+1..M), P.PRONOUN_KIND); when ADV => M := L + ADVERB_ENTRY_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.ADV); when V => M := L + VERB_ENTRY_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.V); -- M := L + PRONOUN_KIND_TYPE_IO.DEFAULT_WIDTH; -- PUT(S(L+1..M), P.PRONOUN_KIND); when others => null; end case; S(M+1..S'LAST) := (others => ' '); end PUT; end TARGET_ENTRY_IO; package body TACKON_ENTRY_IO is SPACER : CHARACTER := ' '; procedure GET(F : in FILE_TYPE; I : out TACKON_ENTRY) is begin GET(F, I.BASE); end GET; procedure GET(I : out TACKON_ENTRY) is begin GET(I.BASE); end GET; procedure PUT(F : in FILE_TYPE; I : in TACKON_ENTRY) is begin PUT(F, I.BASE); end PUT; procedure PUT(I : in TACKON_ENTRY) is begin PUT(I.BASE); end PUT; procedure GET(S : in STRING; I : out TACKON_ENTRY; LAST : out INTEGER) is L : INTEGER := S'FIRST - 1; begin GET(S(L+1..S'LAST), I.BASE, LAST); end GET; procedure PUT(S : out STRING; I : in TACKON_ENTRY) is L : INTEGER := S'FIRST - 1; M : INTEGER := 0; begin M := L + TARGET_ENTRY_IO.DEFAULT_WIDTH; PUT(S(L+1..M), I.BASE); S(S'FIRST..S'LAST) := (others => ' '); end PUT; end TACKON_ENTRY_IO; package body PREFIX_ENTRY_IO is use PART_OF_SPEECH_TYPE_IO; use TEXT_IO; SPACER : CHARACTER := ' '; PE : PREFIX_ENTRY; procedure GET(F : in FILE_TYPE; P : out PREFIX_ENTRY) is begin GET(F, P.ROOT); GET(F, SPACER); GET(F, P.TARGET); end GET; procedure GET(P : out PREFIX_ENTRY) is begin GET(P.ROOT); GET(SPACER); GET(P.TARGET); end GET; procedure PUT(F : in FILE_TYPE; P : in PREFIX_ENTRY) is begin PUT(F, P.ROOT); PUT(F, ' '); PUT(F, P.TARGET); end PUT; procedure PUT(P : in PREFIX_ENTRY) is begin PUT(P.ROOT); PUT(' '); PUT(P.TARGET); end PUT; procedure GET(S : in STRING; P : out PREFIX_ENTRY; LAST : out INTEGER) is L : INTEGER := S'FIRST - 1; begin GET(S(L+1..S'LAST), P.ROOT, L); L := L + 1; GET(S(L+1..S'LAST), P.TARGET, LAST); end GET; procedure PUT(S : out STRING; P : in PREFIX_ENTRY) is L : INTEGER := S'FIRST - 1; M : INTEGER := 0; begin M := L + PART_OF_SPEECH_TYPE_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.ROOT); L := M + 1; S(L) := ' '; M := L + PART_OF_SPEECH_TYPE_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.TARGET); S(M+1..S'LAST) := (others => ' '); end PUT; end PREFIX_ENTRY_IO; package body SUFFIX_ENTRY_IO is use PART_OF_SPEECH_TYPE_IO; use TARGET_ENTRY_IO; use TEXT_IO; SPACER : CHARACTER := ' '; PE : SUFFIX_ENTRY; procedure GET(F : in FILE_TYPE; P : out SUFFIX_ENTRY) is begin GET(F, P.ROOT); GET(F, SPACER); GET(F, P.ROOT_KEY); GET(F, SPACER); GET(F, P.TARGET); GET(F, SPACER); GET(F, P.TARGET_KEY); end GET; procedure GET(P : out SUFFIX_ENTRY) is begin GET(P.ROOT); GET(SPACER); GET(P.ROOT_KEY); GET(SPACER); GET(P.TARGET); GET(SPACER); GET(P.TARGET_KEY); end GET; procedure PUT(F : in FILE_TYPE; P : in SUFFIX_ENTRY) is begin PUT(F, P.ROOT); PUT(F, ' '); PUT(F, P.ROOT_KEY, 2); PUT(F, ' '); PUT(F, P.TARGET); PUT(F, ' '); PUT(F, P.TARGET_KEY, 2); end PUT; procedure PUT(P : in SUFFIX_ENTRY) is begin PUT(P.ROOT); PUT(' '); PUT(P.ROOT_KEY, 2); PUT(' '); PUT(P.TARGET); PUT(' '); PUT(P.TARGET_KEY, 2); end PUT; procedure GET(S : in STRING; P : out SUFFIX_ENTRY; LAST : out INTEGER) is L : INTEGER := S'FIRST - 1; begin --TEXT_IO.PUT("#1" & INTEGER'IMAGE(L)); GET(S(L+1..S'LAST), P.ROOT, L); --TEXT_IO.PUT("#2" & INTEGER'IMAGE(L)); L := L + 1; GET(S(L+1..S'LAST), P.ROOT_KEY, L); --TEXT_IO.PUT("#3" & INTEGER'IMAGE(L)); L := L + 1; GET(S(L+1..S'LAST), P.TARGET, L); --TEXT_IO.PUT("#4" & INTEGER'IMAGE(L)); L := L + 1; GET(S(L+1..S'LAST), P.TARGET_KEY, LAST); --TEXT_IO.PUT("#5" & INTEGER'IMAGE(LAST)); end GET; procedure PUT(S : out STRING; P : in SUFFIX_ENTRY) is L : INTEGER := S'FIRST - 1; M : INTEGER := 0; begin M := L + PART_OF_SPEECH_TYPE_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.ROOT); L := M + 1; S(L) := ' '; M := L + 2; PUT(S(L+1..M), P.ROOT_KEY); L := M + 1; S(L) := ' '; M := L + TARGET_ENTRY_IO.DEFAULT_WIDTH; PUT(S(L+1..M), P.TARGET); L := M + 1; S(L) := ' '; M := L + 2; PUT(S(L+1..M), P.TARGET_KEY); S(M+1..S'LAST) := (others => ' '); end PUT; end SUFFIX_ENTRY_IO; begin -- Initiate body of ADDONS_PACKAGE --TEXT_IO.PUT_LINE("Initializing ADDONS_PACKAGE"); PREFIX_ENTRY_IO.DEFAULT_WIDTH := PART_OF_SPEECH_TYPE_IO.DEFAULT_WIDTH + 1 + PART_OF_SPEECH_TYPE_IO.DEFAULT_WIDTH; TARGET_ENTRY_IO.DEFAULT_WIDTH := PART_OF_SPEECH_TYPE_IO.DEFAULT_WIDTH + 1 + NUMERAL_ENTRY_IO.DEFAULT_WIDTH; -- Largest SUFFIX_ENTRY_IO.DEFAULT_WIDTH := PART_OF_SPEECH_TYPE_IO.DEFAULT_WIDTH + 1 + 2 + 1 + TARGET_ENTRY_IO.DEFAULT_WIDTH + 1 + 2; TACKON_ENTRY_IO.DEFAULT_WIDTH := TARGET_ENTRY_IO.DEFAULT_WIDTH; end ADDONS_PACKAGE;
Package Body Risi_Script.Types.Patterns is Function To_Indicators( Working: Half_Pattern ) return Indicator_String is begin Return Result : Indicator_String(Working'Range) do for Index in Result'Range loop Result(Index) := +Working(Index); end loop; End return; end To_Indicators; Package Body Conversions is separate; ---------------- -- MATCHING -- ---------------- Generic Type Pattern_Type is private; Type String_Type is private; with Function "+"( Right : String_Type ) return Pattern_Type is <>; with Function Index( String, Substring : Pattern_Type ) return Natural; Function Generic_Match( Pattern : Pattern_Type; Indicators : String_Type ) return Boolean; Function Generic_Match( Pattern : Pattern_Type; Indicators : String_Type ) return Boolean is (Index(String => Pattern, Substring => +Indicators) = 1); Function Match( Pattern : Half_Pattern; Indicators : Indicator_String ) return Boolean is Working : Indicator_String renames To_Indicators(Pattern); begin return Result : Boolean := Working'Length <= Indicators'Length do if Result then Result:= Working = Indicators(Working'Range); end if; end return; end Match; -------------- -- CREATE -- -------------- Function Create( Input : Variable_List ) return Half_Pattern is Use Risi_Script.Types; begin Return Result : Half_Pattern( Input'Range ) do for Index in Input'Range loop Result(Index):= Get_Enumeration(Input(Index)); end loop; end return; end Create; End Risi_Script.Types.Patterns;
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2016 onox <denkpadje@gmail.com> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. with AUnit.Assertions; with AUnit.Test_Caller; with JSON.Parsers; with JSON.Streams; with JSON.Types; package body Test_Parsers is package Types is new JSON.Types (Long_Integer, Long_Float); package Parsers is new JSON.Parsers (Types, Check_Duplicate_Keys => True); use AUnit.Assertions; package Caller is new AUnit.Test_Caller (Test); Test_Suite : aliased AUnit.Test_Suites.Test_Suite; function Suite return AUnit.Test_Suites.Access_Test_Suite is Name : constant String := "(Parsers) "; begin Test_Suite.Add_Test (Caller.Create (Name & "Parse text 'true'", Test_True_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text 'false'", Test_False_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text 'null'", Test_Null_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '""""'", Test_Empty_String_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '""test""'", Test_Non_Empty_String_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '""12.34""'", Test_Number_String_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '42'", Test_Integer_Number_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '42' as float", Test_Integer_Number_To_Float_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '3.14'", Test_Float_Number_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '[]'", Test_Empty_Array_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '[""test""]'", Test_One_Element_Array_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '[3.14, true]'", Test_Multiple_Elements_Array_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Iterate over '[false, ""test"", 0.271e1]'", Test_Array_Iterable'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Iterate over '{""foo"":[1, ""2""],""bar"":[0.271e1]}'", Test_Multiple_Array_Iterable'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '{}'", Test_Empty_Object_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '{""foo"":""bar""}'", Test_One_Member_Object_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '{""foo"":1,""bar"":2}'", Test_Multiple_Members_Object_Text'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Iterate over '{""foo"":1,""bar"":2}'", Test_Object_Iterable'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '[{""foo"":[true, 42]}]'", Test_Array_Object_Array'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Parse text '{""foo"":[null, {""bar"": 42}]}'", Test_Object_Array_Object'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Test getting array from text '{}'", Test_Object_No_Array'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Test getting object from text '{}'", Test_Object_No_Object'Access)); -- Exceptions Test_Suite.Add_Test (Caller.Create (Name & "Reject text '[3.14""test""]'", Test_Array_No_Value_Separator_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '[true'", Test_Array_No_End_Array_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '[1]2'", Test_No_EOF_After_Array_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text ''", Test_Empty_Text_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '{""foo"":1""bar"":2}'", Test_Object_No_Value_Separator_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '{""foo"",true}'", Test_Object_No_Name_Separator_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '{42:true}'", Test_Object_Key_No_String_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '{""foo"":true,}'", Test_Object_No_Second_Member_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '{""foo"":1,""foo"":2}'", Test_Object_Duplicate_Keys_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '{""foo"":}'", Test_Object_No_Value_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '{""foo"":true'", Test_Object_No_End_Object_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '{""foo"":true}[true]'", Test_No_EOF_After_Object_Exception'Access)); return Test_Suite'Access; end Suite; use Types; procedure Fail (Message : String) is begin Assert (False, Message); end Fail; procedure Test_True_Text (Object : in out Test) is Text : constant String := "true"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Boolean_Kind, "Not a boolean"); Assert (Value.Value, "Expected boolean value to be True"); end Test_True_Text; procedure Test_False_Text (Object : in out Test) is Text : constant String := "false"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Boolean_Kind, "Not a boolean"); Assert (not Value.Value, "Expected boolean value to be False"); end Test_False_Text; procedure Test_Null_Text (Object : in out Test) is Text : constant String := "null"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Null_Kind, "Not a null"); end Test_Null_Text; procedure Test_Empty_String_Text (Object : in out Test) is Text : constant String := """"""; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = String_Kind, "Not a string"); Assert (Value.Value = "", "String value not empty"); end Test_Empty_String_Text; procedure Test_Non_Empty_String_Text (Object : in out Test) is Text : constant String := """test"""; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = String_Kind, "Not a string"); Assert (Value.Value = "test", "String value not equal to 'test'"); end Test_Non_Empty_String_Text; procedure Test_Number_String_Text (Object : in out Test) is Text : constant String := """12.34"""; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = String_Kind, "Not a string"); Assert (Value.Value = "12.34", "String value not equal to 12.34''"); end Test_Number_String_Text; procedure Test_Integer_Number_Text (Object : in out Test) is Text : constant String := "42"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Integer_Kind, "Not an integer"); Assert (Value.Value = 42, "Integer value not equal to 42"); end Test_Integer_Number_Text; procedure Test_Integer_Number_To_Float_Text (Object : in out Test) is Text : constant String := "42"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Integer_Kind, "Not an integer"); Assert (Value.Value = 42.0, "Integer value not equal to 42.0"); end Test_Integer_Number_To_Float_Text; procedure Test_Float_Number_Text (Object : in out Test) is Text : constant String := "3.14"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Float_Kind, "Not a float"); Assert (Value.Value = 3.14, "Float value not equal to 3.14"); end Test_Float_Number_Text; procedure Test_Empty_Array_Text (Object : in out Test) is Text : constant String := "[]"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Array_Kind, "Not an array"); Assert (Value.Length = 0, "Expected array to be empty"); end Test_Empty_Array_Text; procedure Test_One_Element_Array_Text (Object : in out Test) is Text : constant String := "[""test""]"; String_Value_Message : constant String := "Expected string at index 1 to be equal to 'test'"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Array_Kind, "Not an array"); Assert (Value.Length = 1, "Expected length of array to be 1, got " & Value.Length'Image); begin Assert (Value.Get (1).Value = "test", String_Value_Message); exception when Constraint_Error => Fail ("Could not get string value at index 1"); end; end Test_One_Element_Array_Text; procedure Test_Multiple_Elements_Array_Text (Object : in out Test) is Text : constant String := "[3.14, true]"; Float_Value_Message : constant String := "Expected float at index 1 to be equal to 3.14"; Boolean_Value_Message : constant String := "Expected boolean at index 2 to be True"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Array_Kind, "Not an array"); Assert (Value.Length = 2, "Expected length of array to be 2"); begin Assert (Value.Get (1).Value = 3.14, Float_Value_Message); exception when Constraint_Error => Fail ("Could not get float value at index 1"); end; begin Assert (Value.Get (2).Value, Boolean_Value_Message); exception when Constraint_Error => Fail ("Could not get boolean value at index 2"); end; end Test_Multiple_Elements_Array_Text; procedure Test_Array_Iterable (Object : in out Test) is Text : constant String := "[false, ""test"", 0.271e1]"; Iterations_Message : constant String := "Unexpected number of iterations"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Array_Kind, "Not an array"); Assert (Value.Length = 3, "Expected length of array to be 3"); declare Iterations : Natural := 0; begin for Element of Value loop Iterations := Iterations + 1; if Iterations = 1 then Assert (Element.Kind = Boolean_Kind, "Not a boolean"); Assert (not Element.Value, "Expected boolean value to be False"); elsif Iterations = 2 then Assert (Element.Kind = String_Kind, "Not a string"); Assert (Element.Value = "test", "Expected string value to be 'test'"); elsif Iterations = 3 then Assert (Element.Kind = Float_Kind, "Not a float"); Assert (Element.Value = 2.71, "Expected float value to be 2.71"); end if; end loop; Assert (Iterations = Value.Length, Iterations_Message); end; end Test_Array_Iterable; procedure Test_Multiple_Array_Iterable (Object : in out Test) is Text : constant String := "{""foo"":[1, ""2""],""bar"":[0.271e1]}"; Iterations_Message : constant String := "Unexpected number of iterations"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Object_Kind, "Not an object"); Assert (Value.Length = 2, "Expected length of object to be 2"); declare Iterations : Natural := 0; begin for Element of Value.Get ("foo") loop Iterations := Iterations + 1; if Iterations = 1 then Assert (Element.Kind = Integer_Kind, "Not an integer"); Assert (Element.Value = 1, "Expected integer value to be 1"); elsif Iterations = 2 then Assert (Element.Kind = String_Kind, "Not a string"); Assert (Element.Value = "2", "Expected string value to be '2'"); end if; end loop; Assert (Iterations = Value.Get ("foo").Length, Iterations_Message); end; declare Iterations : Natural := 0; begin for Element of Value.Get ("bar") loop Iterations := Iterations + 1; if Iterations = 1 then Assert (Element.Kind = Float_Kind, "Not a float"); Assert (Element.Value = 2.71, "Expected float value to be 2.71"); end if; end loop; Assert (Iterations = Value.Get ("bar").Length, Iterations_Message); end; end Test_Multiple_Array_Iterable; procedure Test_Empty_Object_Text (Object : in out Test) is Text : constant String := "{}"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Object_Kind, "Not an object"); Assert (Value.Length = 0, "Expected object to be empty"); end Test_Empty_Object_Text; procedure Test_One_Member_Object_Text (Object : in out Test) is Text : constant String := "{""foo"":""bar""}"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Object_Kind, "Not an object"); Assert (Value.Length = 1, "Expected length of object to be 1"); Assert (Value.Get ("foo").Value = "bar", "Expected string value of 'foo' to be 'bar'"); end Test_One_Member_Object_Text; procedure Test_Multiple_Members_Object_Text (Object : in out Test) is Text : constant String := "{""foo"":1,""bar"":2}"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Object_Kind, "Not an object"); Assert (Value.Length = 2, "Expected length of object to be 2"); Assert (Value.Get ("foo").Value = 1, "Expected integer value of 'foo' to be 1"); Assert (Value.Get ("bar").Value = 2, "Expected integer value of 'bar' to be 2"); end Test_Multiple_Members_Object_Text; procedure Test_Object_Iterable (Object : in out Test) is Text : constant String := "{""foo"":1,""bar"":2}"; Iterations_Message : constant String := "Unexpected number of iterations"; All_Keys_Message : constant String := "Did not iterate over all expected keys"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Object_Kind, "Not an object"); Assert (Value.Length = 2, "Expected length of object to be 2"); declare Iterations : Natural := 0; Retrieved_Foo : Boolean := False; Retrieved_Bar : Boolean := False; begin for Key of Value loop Iterations := Iterations + 1; if Iterations in 1 .. 2 then Assert (Key.Kind = String_Kind, "Not String"); Assert (Key.Value in "foo" | "bar", "Expected string value to be equal to 'foo' or 'bar'"); Retrieved_Foo := Retrieved_Foo or Key.Value = "foo"; Retrieved_Bar := Retrieved_Bar or Key.Value = "bar"; end if; end loop; Assert (Iterations = Value.Length, Iterations_Message); Assert (Retrieved_Foo and Retrieved_Bar, All_Keys_Message); end; end Test_Object_Iterable; procedure Test_Array_Object_Array (Object : in out Test) is Text : constant String := "[{""foo"":[true, 42]}]"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Array_Kind, "Not an array"); Assert (Value.Length = 1, "Expected length of array to be 1"); begin declare Object : constant JSON_Value := Value.Get (1); begin Assert (Object.Length = 1, "Expected length of object to be 1"); declare Array_Value : constant JSON_Value := Object.Get ("foo"); begin Assert (Array_Value.Length = 2, "Expected length of array 'foo' to be 2"); Assert (Array_Value.Get (2).Value = 42, "Expected integer value at index 2 to be 42"); end; exception when Constraint_Error => Fail ("Value of 'foo' not an array"); end; exception when Constraint_Error => Fail ("First element in array not an object"); end; end Test_Array_Object_Array; procedure Test_Object_Array_Object (Object : in out Test) is Text : constant String := "{""foo"":[null, {""bar"": 42}]}"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin Assert (Value.Kind = Object_Kind, "Not an object"); Assert (Value.Length = 1, "Expected length of object to be 1"); begin declare Array_Value : constant JSON_Value := Value.Get ("foo"); begin Assert (Array_Value.Length = 2, "Expected length of array 'foo' to be 2"); declare Object : constant JSON_Value := Array_Value.Get (2); begin Assert (Object.Length = 1, "Expected length of object to be 1"); declare Integer_Value : constant JSON_Value := Object.Get ("bar"); begin Assert (Integer_Value.Value = 42, "Expected integer value of 'bar' to be 42"); end; exception when Constraint_Error => Fail ("Element 'bar' in object not an integer"); end; exception when Constraint_Error => Fail ("Value of index 2 not an object"); end; exception when Constraint_Error => Fail ("Element 'foo' in object not an array"); end; end Test_Object_Array_Object; procedure Test_Object_No_Array (Object : in out Test) is Text : constant String := "{}"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin begin declare Object : JSON_Value := Value.Get ("foo"); pragma Unreferenced (Object); begin Fail ("Expected Constraint_Error"); end; exception when Constraint_Error => null; end; begin declare Object : constant JSON_Value := Value.Get_Array_Or_Empty ("foo"); begin Assert (Object.Length = 0, "Expected empty array"); end; exception when Constraint_Error => Fail ("Unexpected Constraint_Error"); end; end Test_Object_No_Array; procedure Test_Object_No_Object (Object : in out Test) is Text : constant String := "{}"; Parser : Parsers.Parser := Parsers.Create (Text); Value : constant JSON_Value := Parser.Parse; begin begin declare Object : JSON_Value := Value.Get ("foo"); pragma Unreferenced (Object); begin Fail ("Expected Constraint_Error"); end; exception when Constraint_Error => null; end; begin declare Object : constant JSON_Value := Value.Get_Object_Or_Empty ("foo"); begin Assert (Object.Length = 0, "Expected empty object"); end; exception when Constraint_Error => Fail ("Unexpected Constraint_Error"); end; end Test_Object_No_Object; procedure Test_Empty_Text_Exception (Object : in out Test) is Text : constant String := ""; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_Empty_Text_Exception; procedure Test_Array_No_Value_Separator_Exception (Object : in out Test) is Text : constant String := "[3.14""test""]"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_Array_No_Value_Separator_Exception; procedure Test_Array_No_End_Array_Exception (Object : in out Test) is Text : constant String := "[true"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_Array_No_End_Array_Exception; procedure Test_No_EOF_After_Array_Exception (Object : in out Test) is Text : constant String := "[1]2"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_No_EOF_After_Array_Exception; procedure Test_Object_No_Value_Separator_Exception (Object : in out Test) is Text : constant String := "{""foo"":1""bar"":2}"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_Object_No_Value_Separator_Exception; procedure Test_Object_No_Name_Separator_Exception (Object : in out Test) is Text : constant String := "{""foo"",true}"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_Object_No_Name_Separator_Exception; procedure Test_Object_Key_No_String_Exception (Object : in out Test) is Text : constant String := "{42:true}"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_Object_Key_No_String_Exception; procedure Test_Object_No_Second_Member_Exception (Object : in out Test) is Text : constant String := "{""foo"":true,}"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_Object_No_Second_Member_Exception; procedure Test_Object_Duplicate_Keys_Exception (Object : in out Test) is Text : constant String := "{""foo"":1,""foo"":2}"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Constraint_Error"); end; exception when Constraint_Error => null; end Test_Object_Duplicate_Keys_Exception; procedure Test_Object_No_Value_Exception (Object : in out Test) is Text : constant String := "{""foo"":}"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_Object_No_Value_Exception; procedure Test_Object_No_End_Object_Exception (Object : in out Test) is Text : constant String := "{""foo"":true"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_Object_No_End_Object_Exception; procedure Test_No_EOF_After_Object_Exception (Object : in out Test) is Text : constant String := "{""foo"":true}[true]"; Parser : Parsers.Parser := Parsers.Create (Text); begin declare Value : JSON_Value := Parser.Parse; pragma Unreferenced (Value); begin Fail ("Expected Parse_Error"); end; exception when Parsers.Parse_Error => null; end Test_No_EOF_After_Object_Exception; end Test_Parsers;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ C H 7 -- -- -- -- S p e c -- -- -- -- $Revision$ -- -- -- Copyright (C) 1992,1993,1994 Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Types; use Types; package Sem_Ch7 is procedure Analyze_Package_Body (N : Node_Id); procedure Analyze_Package_Declaration (N : Node_Id); procedure Analyze_Package_Specification (N : Node_Id); procedure Analyze_Private_Type_Declaration (N : Node_Id); procedure End_Package_Scope (P : Entity_Id); -- Calls Uninstall_Declarations, and then pops the scope stack. procedure Exchange_Declarations (Id : Entity_Id); -- Exchange private and full declaration on entry/exit from a package -- declaration or body. The semantic links of the respective nodes -- are preserved in the exchange. procedure Install_Visible_Declarations (P : Entity_Id); procedure Install_Private_Declarations (P : Entity_Id); -- On entrance to a package body, make declarations in package spec -- immediately visible. -- When compiling the body of a package, both routines are called in -- succession. When compiling the body of a child package, the call -- to Install_Private_Declaration is immediate for private children, -- but is deffered until the compilation of the private part of the -- child for public child packages. procedure Install_Package_Entity (Id : Entity_Id); -- Basic procedure for the previous two. Places one entity on its -- visibility chain, and recurses on the visible part if the entity -- is an inner package. function Unit_Requires_Body (P : Entity_Id) return Boolean; -- Check if a unit requires a body. A specification requires a body -- if it contains declarations that require completion in a body. procedure May_Need_Implicit_Body (E : Entity_Id); -- If a package declaration contains tasks and does not require a -- body, create an implicit body at the end of the current declarative -- part to activate those tasks. function Is_Fully_Visible (Type_Id : Entity_Id) return Boolean; -- Indicates whether the Full Declaration of a private type is visible. procedure New_Private_Type (N : Node_Id; Id : Entity_Id; Def : Node_Id); -- Common processing for private type declarations and for formal -- private type declarations. For private types, N and Def are the type -- declaration node; for formal private types, Def is the formal type -- definition. procedure Uninstall_Declarations (P : Entity_Id); -- At the end of a package declaration or body, declarations in the -- visible part are no longer immediately visible, and declarations in -- the private part are not visible at all. For inner packages, place -- visible entities at the end of their homonym chains. For compilation -- units, make all entities invisible. In both cases, exchange private -- and visible declarations to restore order of elaboration. end Sem_Ch7;
with Ada.Finalization; with Ada.Strings.Unbounded; with Interfaces; package TOML with Preelaborate is pragma Warnings (Off); use type Ada.Strings.Unbounded.Unbounded_String; pragma Warnings (On); Version : constant String := "0.1"; -- Version for the ada-toml project subtype Unbounded_UTF8_String is Ada.Strings.Unbounded.Unbounded_String; type Any_Value_Kind is (TOML_Table, TOML_Array, TOML_String, TOML_Integer, TOML_Float, TOML_Boolean, TOML_Offset_Datetime, TOML_Local_Datetime, TOML_Local_Date, TOML_Local_Time); subtype Composite_Value_Kind is Any_Value_Kind range TOML_Table .. TOML_Array; subtype Atom_Value_Kind is Any_Value_Kind range TOML_String .. TOML_Local_Time; type TOML_Value is new Ada.Finalization.Controlled with private; No_TOML_Value : constant TOML_Value; -- TODO: create TOML_Value subtypes for the various kinds type Any_Integer is new Interfaces.Integer_64; -- TOML supports any integer that can be encoded in a 64-bit signed -- integer. type Valid_Float is new Interfaces.IEEE_Float_64; type Float_Kind is (Regular, NaN, Infinity); subtype Special_Float_Kind is Float_Kind range NaN .. Infinity; type Any_Float (Kind : Float_Kind := Regular) is record case Kind is when Regular => Value : Valid_Float; when Special_Float_Kind => Positive : Boolean; end case; end record; -- TOML advises to implement its float values as IEEE 754 binary64 values, -- however Ada does not provide a standard way to represent infinities and -- NaN (Not a Number), so fallback to a discriminated record to reliably -- represent TOML float. type Any_Year is range 1 .. 9999; type Any_Month is range 1 .. 12; type Any_Day is range 1 .. 31; type Any_Local_Date is record Year : Any_Year; Month : Any_Month; Day : Any_Day; end record; type Any_Hour is range 0 .. 23; type Any_Minute is range 0 .. 59; type Any_Second is range 0 .. 60; type Any_Millisecond is range 0 .. 999; type Any_Local_Offset is range -(23 * 60 + 59) .. 23 * 60 + 59; -- Offset between local time and UTC, in minutes. We allow from -23:59 to -- +23:59. type Any_Local_Time is record Hour : Any_Hour; Minute : Any_Minute; Second : Any_Second; Millisecond : Any_Millisecond; end record; type Any_Local_Datetime is record Date : Any_Local_Date; Time : Any_Local_Time; end record; type Any_Offset_Datetime is record Datetime : Any_Local_Datetime; Offset : Any_Local_Offset; Unknown_Offset : Boolean; end record with Dynamic_Predicate => not Any_Offset_Datetime.Unknown_Offset or else Any_Offset_Datetime.Offset = 0; ----------------------- -- Generic accessors -- ----------------------- function Is_Null (Value : TOML_Value) return Boolean; -- Return whether Value is a null reference function Is_Present (Value : TOML_Value) return Boolean is (not Value.Is_Null); function Kind (Value : TOML_Value) return Any_Value_Kind with Pre => Value.Is_Present; -- Return the kind of TOML node for the given Value function Equals (Left, Right : TOML_Value) return Boolean with Pre => Left.Is_Present and then Right.Is_Present; -- Return whether Left and Right refer to equivalent TOML documents. -- -- Note that this is very different from the built-in "=" operator: -- the TOML_Value type has by-reference meaning, so "=" compares identity, -- not structural equivalence. function Clone (Value : TOML_Value) return TOML_Value with Pre => Value.Is_Present; -- Return a reference to a deep copy for Value -------------------- -- Atom accessors -- -------------------- function As_Boolean (Value : TOML_Value) return Boolean with Pre => Value.Kind = TOML_Boolean; -- Return the boolean that Value represents function As_Integer (Value : TOML_Value) return Any_Integer with Pre => Value.Kind = TOML_Integer; -- Return the integer that Value represents function As_Float (Value : TOML_Value) return Any_Float with Pre => Value.Kind = TOML_Float; -- Return the float that Value represents function As_String (Value : TOML_Value) return String with Pre => Value.Kind = TOML_String; -- Return the string that Value represents function As_Unbounded_String (Value : TOML_Value) return Unbounded_UTF8_String with Pre => Value.Kind = TOML_String; -- Likewise, but return an unbounded string function As_Offset_Datetime (Value : TOML_Value) return Any_Offset_Datetime with Pre => Value.Kind = TOML_Offset_Datetime; -- Return the offset datetime that Value represents function As_Local_Datetime (Value : TOML_Value) return Any_Local_Datetime with Pre => Value.Kind = TOML_Local_Datetime; -- Return the local datetime that Value represents function As_Local_Date (Value : TOML_Value) return Any_Local_Date with Pre => Value.Kind = TOML_Local_Date; -- Return the local date that Value represents function As_Local_Time (Value : TOML_Value) return Any_Local_Time with Pre => Value.Kind = TOML_Local_Time; -- Return the local time that Value represents --------------------- -- Table accessors -- --------------------- function Has (Value : TOML_Value; Key : String) return Boolean with Pre => Value.Kind = TOML_Table; -- Return whether Value contains an entry for the given Key function Has (Value : TOML_Value; Key : Unbounded_UTF8_String) return Boolean with Pre => Value.Kind = TOML_Table; -- Likewise, but take an unbounded string type Key_Array is array (Positive range <>) of Unbounded_UTF8_String; function Keys (Value : TOML_Value) return Key_Array with Pre => Value.Kind = TOML_Table; -- Return a list for all keys in the given table. Note that the result is -- sorted. function Get (Value : TOML_Value; Key : String) return TOML_Value with Pre => Value.Has (Key); -- Return the value for the entry in Value corresponding to Key function Get (Value : TOML_Value; Key : Unbounded_UTF8_String) return TOML_Value with Pre => Value.Has (Key); -- Likewise, but take an unbounded string function Get_Or_Null (Value : TOML_Value; Key : String) return TOML_Value with Pre => Value.Kind = TOML_Table; -- If there is an entry in the Value table, return its value. Return -- No_TOML_Value otherwise. function Get_Or_Null (Value : TOML_Value; Key : Unbounded_UTF8_String) return TOML_Value with Pre => Value.Kind = TOML_Table; -- Likewise, but take an unbounded string -- The following types and primitive allow one to iterate on key/value -- entries conveniently in a simple FOR loop. type Table_Entry is record Key : Unbounded_UTF8_String; Value : TOML_Value; end record; type Table_Entry_Array is array (Positive range <>) of Table_Entry; function Iterate_On_Table (Value : TOML_Value) return Table_Entry_Array with Pre => Value.Kind = TOML_Table; -- Return an array of key/value pairs for all entries in Value. The result -- is sorted by key. --------------------- -- Array accessors -- --------------------- function Length (Value : TOML_Value) return Natural with Pre => Value.Kind = TOML_Array; -- Return the number of items in Value function Item (Value : TOML_Value; Index : Positive) return TOML_Value with Pre => Value.Kind = TOML_Array and then Index <= Value.Length; -- Return the item in Value at the given Index ------------------- -- Atom creators -- ------------------- function Create_Boolean (Value : Boolean) return TOML_Value with Post => Create_Boolean'Result.Kind = TOML_Boolean and then Create_Boolean'Result.As_Boolean = Value; -- Create a TOML boolean value function Create_Integer (Value : Any_Integer) return TOML_Value with Post => Create_Integer'Result.Kind = TOML_Integer and then Create_Integer'Result.As_Integer = Value; -- Create a TOML integer value function Create_Float (Value : Any_Float) return TOML_Value with Post => Create_Float'Result.Kind = TOML_Float and then Create_Float'Result.As_Float = Value; -- Create a TOML integer value function Create_String (Value : String) return TOML_Value with Post => Create_String'Result.Kind = TOML_String and then Create_String'Result.As_String = Value; -- Create a TOML string value. Value must be a valid UTF-8 string. function Create_String (Value : Unbounded_UTF8_String) return TOML_Value with Post => Create_String'Result.Kind = TOML_String and then Create_String'Result.As_Unbounded_String = Value; -- Create a TOML string value function Create_Offset_Datetime (Value : Any_Offset_Datetime) return TOML_Value with Post => Create_Offset_Datetime'Result.Kind = TOML_Offset_Datetime and then Create_Offset_Datetime'Result.As_Offset_Datetime = Value; -- Create a TOML offset datetime value function Create_Local_Datetime (Value : Any_Local_Datetime) return TOML_Value with Post => Create_Local_Datetime'Result.Kind = TOML_Local_Datetime and then Create_Local_Datetime'Result.As_Local_Datetime = Value; -- Create a TOML local datetime value function Create_Local_Date (Value : Any_Local_Date) return TOML_Value with Post => Create_Local_Date'Result.Kind = TOML_Local_Date and then Create_Local_Date'Result.As_Local_Date = Value; -- Create a TOML local date value function Create_Local_Time (Value : Any_Local_Time) return TOML_Value with Post => Create_Local_Time'Result.Kind = TOML_Local_Time and then Create_Local_Time'Result.As_Local_Time = Value; -- Create a TOML local date value --------------------- -- Table modifiers -- --------------------- function Create_Table return TOML_Value with Post => Create_Table'Result.Kind = TOML_Table; -- Create an empty TOML table procedure Set (Value : TOML_Value; Key : String; Entry_Value : TOML_Value) with Pre => Value.Kind = TOML_Table; -- Create an entry in Value to bind Key to Entry_Value. If Value already -- has an entry for Key, replace it. procedure Set (Value : TOML_Value; Key : Unbounded_UTF8_String; Entry_Value : TOML_Value) with Pre => Value.Kind = TOML_Table; -- Likewise, but take an unbounded string procedure Set_Default (Value : TOML_Value; Key : String; Entry_Value : TOML_Value) with Pre => Value.Kind = TOML_Table; -- If Value has an entry for Key, do nothing. Otherwise, create an entry -- binding Key to Entry_Value. procedure Set_Default (Value : TOML_Value; Key : Unbounded_UTF8_String; Entry_Value : TOML_Value) with Pre => Value.Kind = TOML_Table; -- Likewise, but take an unbounded string procedure Unset (Value : TOML_Value; Key : String) with Pre => Value.Kind = TOML_Table and then Value.Has (Key); -- Remove the Key entry in Value procedure Unset (Value : TOML_Value; Key : Unbounded_UTF8_String) with Pre => Value.Kind = TOML_Table and then Value.Has (Key); -- Likewise, but take an unbounded string function Merge (L, R : TOML_Value) return TOML_Value with Pre => L.Kind = TOML_Table and then R.Kind = TOML_Table, Post => Merge'Result.Kind = TOML_Table; -- Merge two tables. If a key is present in both, Constraint_Error is -- raised. The operation is shallow, so the result table shares values with -- L and R. function Merge (L, R : TOML_Value; Merge_Entries : not null access function (Key : Unbounded_UTF8_String; L, R : TOML_Value) return TOML_Value) return TOML_Value with Pre => L.Kind = TOML_Table and then R.Kind = TOML_Table, Post => Merge'Result.Kind = TOML_Table; -- Merge two tables. If a key is present in both, call Merge_Entries to -- resolve the conflict: use its return value for the entry in the returned -- table. --------------------- -- Array modifiers -- --------------------- function Create_Array return TOML_Value with Post => Create_Array'Result.Kind = TOML_Array; -- Create a TOML array procedure Set (Value : TOML_Value; Index : Positive; Item : TOML_Value) with Pre => Value.Kind = TOML_Array and then Index <= Value.Length; -- Replace the Index'th item in Value with Item procedure Append (Value, Item : TOML_Value) with Pre => Value.Kind = TOML_Array; -- Append Item to the Value array procedure Insert_Before (Value : TOML_Value; Index : Positive; Item : TOML_Value) with Pre => Value.Kind = TOML_Array and then Index < Value.Length + 1; -- Insert Item before the Item'th element in the Value array ------------------ -- Input/Output -- ------------------ type Source_Location is record Line, Column : Natural; end record; No_Location : constant Source_Location := (0, 0); -- Result of TOML document parsing. If the parsing was successful, contains -- the corresponding TOML value, otherwise, contains an error message that -- describes why parsing failed. type Read_Result (Success : Boolean := True) is record case Success is when False => Message : Unbounded_UTF8_String; Location : Source_Location; when True => Value : TOML_Value; end case; end record; function Load_String (Content : String) return Read_Result; -- Parse Content as a TOML document function Dump_As_String (Value : TOML_Value) return String with Pre => Value.Kind = TOML_Table; -- Serialize Value as a valid TOML document function Dump_As_Unbounded (Value : TOML_Value) return Unbounded_UTF8_String with Pre => Value.Kind = TOML_Table; -- Likewise, but return an unbounded string -- To keep this package preelaborable, subprograms that perform I/O on files -- are found in TOML.File_IO function Format_Error (Result : Read_Result) return String with Pre => not Result.Success; -- Format the error information in Result into a GNU-style diagnostic private type TOML_Value_Record; type TOML_Value_Record_Access is access all TOML_Value_Record; type TOML_Value is new Ada.Finalization.Controlled with record Value : TOML_Value_Record_Access; end record; overriding procedure Adjust (Self : in out TOML_Value); overriding procedure Finalize (Self : in out TOML_Value); No_TOML_Value : constant TOML_Value := (Ada.Finalization.Controlled with Value => null); function Create_Error (Message : String; Location : Source_Location) return Read_Result; -- Create an unsuccessful Read_Result value with the provided error -- information. function Implicitly_Created (Self : TOML_Value'Class) return Boolean with Pre => Self.Kind in TOML_Table | TOML_Array; -- Helper for parsing. Return whether Self was created implicitly procedure Set_Implicitly_Created (Self : TOML_Value'Class) with Pre => Self.Kind in TOML_Table | TOML_Array; -- Make future calls to Implicitly_Created return True for Self procedure Set_Explicitly_Created (Self : TOML_Value'Class) with Pre => Self.Kind in TOML_Table | TOML_Array; -- Make future calls to Implicitly_Created return False for Self end TOML;
private with C.gmp; package GMP is pragma Preelaborate; pragma Linker_Options ("-lgmp"); function Version return String; subtype Number_Base is Integer range 2 .. 16; type Exponent is new Long_Integer; type Precision is mod 2 ** GMP.Exponent'Size; function Default_Precision return Precision; private pragma Compile_Time_Error ( Exponent'Last /= Exponent (C.gmp.mp_exp_t'Last), "please adjust Exponent as mp_exp_t"); pragma Compile_Time_Error ( Precision'Last /= Precision (C.gmp.mp_bitcnt_t'Last), "please adjust Precision as mp_bitcnt_t"); procedure mpz_set_Long_Long_Integer ( rop : not null access C.gmp.mpz_struct; op : in Long_Long_Integer); end GMP;
with Ada.Text_IO; with Ada.Integer_Text_IO; with Ada.Containers.Ordered_Sets; package body Problem_29 is package IO renames Ada.Text_IO; package I_IO renames Ada.Integer_Text_IO; package Positive_Set is new Ada.Containers.Ordered_Sets(Positive); subtype Parameter is Integer range 2 .. 100; type Special_Array is Array(Parameter) of Boolean; Is_Special : Special_Array; count : Natural := 0; procedure Check_If_Special(a : Parameter) is set : Positive_Set.Set; procedure Add_To_Set(exponent : Positive) is number : constant Integer := a**exponent; current_exponent : Positive := exponent*2; current_number : Integer := number**2; Last_Index : Parameter := Parameter'First; begin Is_Special(number) := True; while current_number <= Parameter'Last loop Add_To_Set(current_exponent); if not set.Contains(current_exponent) then set.Insert(current_exponent); end if; current_exponent := current_exponent + exponent; current_number := current_number * number; Last_Index := Last_Index + 1; end loop; for unused in Last_Index .. Parameter'Last loop if not set.Contains(current_exponent) then set.Insert(current_exponent); end if; current_exponent := current_exponent + exponent; end loop; end Add_To_Set; begin if Is_Special(a) then -- Already handled return; end if; if Integer(a)**2 <= Parameter'Last then Add_To_Set(1); count := count + Natural(set.Length); end if; end Check_If_Special; procedure Solve is begin for index in Is_Special'Range loop Is_Special(index) := False; end loop; for a in Parameter'Range loop Check_If_Special(a); if not Is_Special(a) then count := count + Parameter'Last - Parameter'First + 1; end if; end loop; I_IO.Put(count); IO.New_Line; end Solve; end Problem_29;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2015, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of STMicroelectronics nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- -- -- -- This file is based on: -- -- -- -- @file l3gd20.h -- -- @author MCD Application Team -- -- @version V1.1.0 -- -- @date 19-June-2014 -- -- @brief This file contains all the functions prototypes for the -- -- l3gd20.c driver -- -- -- -- COPYRIGHT(c) 2014 STMicroelectronics -- ------------------------------------------------------------------------------ -- This file provides a driver for the L3GD20 gyroscope from ST -- Microelectronics. -- See datasheet "L3GD20 MEMS motion sensor: three-axis digital output -- gyroscope" DocID022116 Rev 2, dated February 2013, file number DM00036465 with Interfaces; use Interfaces; with HAL; use HAL; with HAL.SPI; use HAL.SPI; with HAL.GPIO; use HAL.GPIO; package L3GD20 is pragma Elaborate_Body; type Three_Axis_Gyroscope is tagged limited private; procedure Initialize (This : in out Three_Axis_Gyroscope; Port : Any_SPI_Port; Chip_Select : Any_GPIO_Point); -- Does device-specific initialization. Must be called prior to use. -- -- NB: does NOT init/configure SPI and GPIO IO, which must be done -- (elsewhere) prior to calling this routine. type Power_Mode_Selection is (L3GD20_Mode_Powerdown, L3GD20_Mode_Active) with Size => 8; for Power_Mode_Selection use (L3GD20_Mode_Powerdown => 16#00#, L3GD20_Mode_Active => 16#08#); type Output_Data_Rate_Selection is (L3GD20_Output_Data_Rate_95Hz, L3GD20_Output_Data_Rate_190Hz, L3GD20_Output_Data_Rate_380Hz, L3GD20_Output_Data_Rate_760Hz) with Size => 8; for Output_Data_Rate_Selection use (L3GD20_Output_Data_Rate_95Hz => 16#00#, L3GD20_Output_Data_Rate_190Hz => 16#40#, L3GD20_Output_Data_Rate_380Hz => 16#80#, L3GD20_Output_Data_Rate_760Hz => 16#C0#); -- See App Note 4505, pg 8, Table 3. function Data_Rate_Hertz (Selection : Output_Data_Rate_Selection) return Float is (case Selection is when L3GD20_Output_Data_Rate_95Hz => 95.0, when L3GD20_Output_Data_Rate_190Hz => 190.0, when L3GD20_Output_Data_Rate_380Hz => 380.0, when L3GD20_Output_Data_Rate_760Hz => 760.0); type Axes_Selection is (L3GD20_Axes_Disable, L3GD20_Y_Enable, L3GD20_X_Enable, L3GD20_Z_Enable, L3GD20_Axes_Enable) with Size => 8; for Axes_Selection use (L3GD20_X_Enable => 16#02#, L3GD20_Y_Enable => 16#01#, L3GD20_Z_Enable => 16#04#, L3GD20_Axes_Enable => 16#07#, L3GD20_Axes_Disable => 16#00#); -- See App Note 4505, pg 8, Table 3. type Bandwidth_Selection is (L3GD20_Bandwidth_1, L3GD20_Bandwidth_2, L3GD20_Bandwidth_3, L3GD20_Bandwidth_4) with Size => 8; for Bandwidth_Selection use (L3GD20_Bandwidth_1 => 16#00#, L3GD20_Bandwidth_2 => 16#10#, L3GD20_Bandwidth_3 => 16#20#, L3GD20_Bandwidth_4 => 16#30#); type Full_Scale_Selection is (L3GD20_Fullscale_250, L3GD20_Fullscale_500, L3GD20_Fullscale_2000) with Size => 8; for Full_Scale_Selection use (L3GD20_Fullscale_250 => 16#00#, L3GD20_Fullscale_500 => 16#10#, L3GD20_Fullscale_2000 => 16#20#); type Block_Data_Update_Selection is (L3GD20_BlockDataUpdate_Continous, L3GD20_BlockDataUpdate_Single) with Size => 8; for Block_Data_Update_Selection use (L3GD20_BlockDataUpdate_Continous => 16#00#, L3GD20_BlockDataUpdate_Single => 16#80#); type Endian_Data_Selection is (L3GD20_Little_Endian, L3GD20_Big_Endian) with Size => 8; for Endian_Data_Selection use (L3GD20_Little_Endian => 16#00#, L3GD20_Big_Endian => 16#40#); -- Set up the gyro behavior. Must be called prior to using the gyro. procedure Configure (This : in out Three_Axis_Gyroscope; Power_Mode : Power_Mode_Selection; Output_Data_Rate : Output_Data_Rate_Selection; Axes_Enable : Axes_Selection; Bandwidth : Bandwidth_Selection; BlockData_Update : Block_Data_Update_Selection; Endianness : Endian_Data_Selection; Full_Scale : Full_Scale_Selection); procedure Enable_Low_Pass_Filter (This : in out Three_Axis_Gyroscope); -- See App Note 4505, pg 15, Figure 5 and Table 9 for the concept. Enables -- the low pass filter LPF2 in the diagrams, for output to the data -- registers and the FIFO. The value of LPF2 is determined by the output -- data rate and bandwidth selections specified when calling procedure -- Configure. These values are shown in the App Note, pg 16, Table 11. -- The filter allows frequencies lower than the LPF2 "cutoff" value, and -- attenuates those at or above the cutoff. Note that the high pass filter -- is independent of the low pass filter. procedure Disable_Low_Pass_Filter (This : in out Three_Axis_Gyroscope); function Full_Scale_Sensitivity (This : Three_Axis_Gyroscope) return Float; -- Returns the sensitivity per LSB based on the Full_Scale_Selection -- specified to procedure Configure. Used to scale raw angle rates. Note -- that the values are already in terms of millidegrees per second per -- digit, so to use these values you should multiply, rather than divide. -- NB: These values are not measured on the specific device on the board -- in use. Instead, they are statistical averages determined at the factory -- for this component family, so you will likely need to tweak them a bit. -- High Pass Filtering functionality -- See App Note 4505, pg 17, Table 14. type High_Pass_Filter_Mode is (L3GD20_HPM_Normal_Mode_Reset, -- filter is reset by reading the Reference register L3GD20_HPM_Reference_Signal, -- output data is input - Reference register L3GD20_HPM_Normal_Mode, -- filter is reset by reading the Reference register L3GD20_HPM_Autoreset_Int) -- filter is auto-reset on configured interrupt with Size => 8; for High_Pass_Filter_Mode use (L3GD20_HPM_Normal_Mode_Reset => 16#00#, L3GD20_HPM_Reference_Signal => 16#10#, L3GD20_HPM_Normal_Mode => 16#20#, L3GD20_HPM_Autoreset_Int => 16#30#); -- See App Note 4505, pg 17, Table 13 for the resulting frequencies. As -- shown in that table, the frequencies selected by these enumerals are -- a function of the configured output data rate selected elsewhere. type High_Pass_Cutoff_Frequency is (L3GD20_HPFCF_0, L3GD20_HPFCF_1, L3GD20_HPFCF_2, L3GD20_HPFCF_3, L3GD20_HPFCF_4, L3GD20_HPFCF_5, L3GD20_HPFCF_6, L3GD20_HPFCF_7, L3GD20_HPFCF_8, L3GD20_HPFCF_9) with Size => 8; for High_Pass_Cutoff_Frequency use -- confirming (L3GD20_HPFCF_0 => 16#00#, L3GD20_HPFCF_1 => 16#01#, L3GD20_HPFCF_2 => 16#02#, L3GD20_HPFCF_3 => 16#03#, L3GD20_HPFCF_4 => 16#04#, L3GD20_HPFCF_5 => 16#05#, L3GD20_HPFCF_6 => 16#06#, L3GD20_HPFCF_7 => 16#07#, L3GD20_HPFCF_8 => 16#08#, L3GD20_HPFCF_9 => 16#09#); procedure Configure_High_Pass_Filter (This : in out Three_Axis_Gyroscope; Mode_Selection : High_Pass_Filter_Mode; Cutoff_Frequency : High_Pass_Cutoff_Frequency); procedure Enable_High_Pass_Filter (This : in out Three_Axis_Gyroscope); -- Allows frequencies higher than the cutoff specified to procedure -- Configure_High_Pass_Filter, and attenuates those at or below it. procedure Disable_High_Pass_Filter (This : in out Three_Axis_Gyroscope); function Reference_Value (This : Three_Axis_Gyroscope) return UInt8 with Inline; procedure Set_Reference (This : in out Three_Axis_Gyroscope; Value : UInt8) with Inline; -- Basic data access functionality type Gyro_Data_Status is record ZYX_Overrun : Boolean; Z_Overrun : Boolean; Y_Overrun : Boolean; X_Overrun : Boolean; ZYX_Available : Boolean; Z_Available : Boolean; Y_Available : Boolean; X_Available : Boolean; end record with Size => 8; for Gyro_Data_Status use record ZYX_Overrun at 0 range 7 .. 7; Z_Overrun at 0 range 6 .. 6; Y_Overrun at 0 range 5 .. 5; X_Overrun at 0 range 4 .. 4; ZYX_Available at 0 range 3 .. 3; Z_Available at 0 range 2 .. 2; Y_Available at 0 range 1 .. 1; X_Available at 0 range 0 .. 0; end record; function Data_Status (This : Three_Axis_Gyroscope) return Gyro_Data_Status with Inline; type Angle_Rate is new Integer_16; type Angle_Rates is record X : Angle_Rate; -- pitch, per Figure 2, pg 7 of the Datasheet Y : Angle_Rate; -- roll Z : Angle_Rate; -- yaw end record with Size => 3 * 16; for Angle_Rates use record X at 0 range 0 .. 15; Y at 2 range 0 .. 15; Z at 4 range 0 .. 15; end record; -- confirming, but required, eg for matching FIFO content format procedure Get_Raw_Angle_Rates (This : Three_Axis_Gyroscope; Rates : out Angle_Rates); -- Returns the latest data, swapping UInt8s if required by the endianess -- selected by a previous call to Configure. -- NB: does NOT check whether the gyro status indicates data are ready. -- NB: does NOT apply any sensitity scaling. -- FIFO functionality type FIFO_Modes is (L3GD20_Bypass_Mode, L3GD20_FIFO_Mode, L3GD20_Stream_Mode, L3GD20_Stream_To_FIFO_Mode, L3GD20_Bypass_To_Stream_Mode) with Size => 8; for FIFO_Modes use -- confirming (L3GD20_Bypass_Mode => 2#0000_0000#, L3GD20_FIFO_Mode => 2#0010_0000#, L3GD20_Stream_Mode => 2#0100_0000#, L3GD20_Stream_To_FIFO_Mode => 2#0110_0000#, L3GD20_Bypass_To_Stream_Mode => 2#1000_0000#); procedure Set_FIFO_Mode (This : in out Three_Axis_Gyroscope; Mode : FIFO_Modes); procedure Enable_FIFO (This : in out Three_Axis_Gyroscope); procedure Disable_FIFO (This : in out Three_Axis_Gyroscope); subtype FIFO_Level is Integer range 0 .. 31; procedure Set_FIFO_Watermark (This : in out Three_Axis_Gyroscope; Level : FIFO_Level); type Angle_Rates_FIFO_Buffer is array (FIFO_Level range <>) of Angle_Rates with Alignment => Angle_Rate'Alignment; procedure Get_Raw_Angle_Rates_FIFO (This : in out Three_Axis_Gyroscope; Buffer : out Angle_Rates_FIFO_Buffer); -- Returns the latest raw data in the FIFO, swapping UInt8s if required by -- the endianess selected by a previous call to Configure. Fills the entire -- buffer passed. -- NB: does NOT apply any sensitity scaling. function Current_FIFO_Depth (This : Three_Axis_Gyroscope) return FIFO_Level; -- The number of unread entries currently in the hardware FIFO function FIFO_Below_Watermark (This : Three_Axis_Gyroscope) return Boolean; function FIFO_Empty (This : Three_Axis_Gyroscope) return Boolean; function FIFO_Overrun (This : Three_Axis_Gyroscope) return Boolean; -- Interrupt 2 controls procedure Disable_Int2_Interrupts (This : in out Three_Axis_Gyroscope); procedure Enable_Data_Ready_Interrupt (This : in out Three_Axis_Gyroscope); procedure Disable_Data_Ready_Interrupt (This : in out Three_Axis_Gyroscope); procedure Enable_FIFO_Watermark_Interrupt (This : in out Three_Axis_Gyroscope); procedure Disable_FIFO_Watermark_Interrupt (This : in out Three_Axis_Gyroscope); procedure Enable_FIFO_Overrun_Interrupt (This : in out Three_Axis_Gyroscope); procedure Disable_FIFO_Overrun_Interrupt (This : in out Three_Axis_Gyroscope); procedure Enable_FIFO_Empty_Interrupt (This : in out Three_Axis_Gyroscope); procedure Disable_FIFO_Empty_Interrupt (This : in out Three_Axis_Gyroscope); -- Interrupt 1 facilities procedure Disable_Int1_Interrupts (This : in out Three_Axis_Gyroscope); type Sample_Counter is mod 2 ** 6; procedure Set_Duration_Counter (This : in out Three_Axis_Gyroscope; Value : Sample_Counter); -- Loads the INT1_DURATION register with the specified Value and enables -- the "wait" option so that the interrupt is not generated unless any -- sample value is beyond a threshold for the corresponding amount of time. -- The effective time is dependent on the data rate selected elsewhere. type Axes_Interrupts is (Z_High_Interrupt, Z_Low_Interrupt, Y_High_Interrupt, Y_Low_Interrupt, X_High_Interrupt, X_Low_Interrupt); procedure Enable_Event (This : in out Three_Axis_Gyroscope; Event : Axes_Interrupts); procedure Disable_Event (This : in out Three_Axis_Gyroscope; Event : Axes_Interrupts); type Axis_Sample_Threshold is new UInt16 range 0 .. 2 ** 15; -- Threshold values do not use the high-order bit procedure Set_Threshold (This : in out Three_Axis_Gyroscope; Event : Axes_Interrupts; Value : Axis_Sample_Threshold); -- Writes the two-UInt8 threshold value into the two threshold registers for -- the specified interrupt event. Does not enable the event itself. type Threshold_Event is record Axis : Axes_Interrupts; Threshold : Axis_Sample_Threshold; end record; type Threshold_Event_List is array (Positive range <>) of Threshold_Event; type Interrupt1_Active_Edge is (L3GD20_Interrupt1_High_Edge, L3GD20_Interrupt1_Low_Edge); for Interrupt1_Active_Edge use (L3GD20_Interrupt1_Low_Edge => 16#20#, L3GD20_Interrupt1_High_Edge => 16#00#); procedure Configure_Interrupt1 (This : in out Three_Axis_Gyroscope; Triggers : Threshold_Event_List; Latched : Boolean := False; Active_Edge : Interrupt1_Active_Edge := L3GD20_Interrupt1_High_Edge; Combine_Events : Boolean := False; Sample_Count : Sample_Counter := 0); -- -- If Latched is False (the hardware default value), the interrupt signal -- goes high when the interrupt condition is satisfied and returns low -- immediately if the interrupt condition is no longer verified. Otherwise, -- if Latched is True, the interrupt signal remains high even if the -- condition returns to a non-interrupt status, until a read of the -- INT1_SRC register is performed. -- -- If Combine_Events is True, all events' criteria must be -- safisfied for the interrupt to be generated; otherwise any one is -- sufficient. -- -- If Sample_Count is not zero, passes Sample_Count to a call to -- Set_Duration_Counter -- -- For every event and threshold specified in Triggers, sets the threshold -- value and enables the corresponding high or low threshold interrupt for -- that axis. For example, the following call enables the interrupt when -- the sampled value for the X axis is greater than 10 or the sample for -- the Z axis is greater than 20: -- -- Configure_Interrupt_1 -- (Latched => ... , -- Active_Edge => ... , -- Triggers => ((X_High_Interrupt, Threshold => 10), -- (Z_High_Interrupt, Threshold => 20))); -- -- For that example call, if Combine_Events is True, the interrupt is only -- generated if both thresholds are exceeded. Otherwise either one is -- sufficient for the interrupt to be generated. procedure Enable_Interrupt1 (This : in out Three_Axis_Gyroscope); procedure Disable_Interrupt1 (This : in out Three_Axis_Gyroscope); type Pin_Modes is (Push_Pull, Open_Drain); for Pin_Modes use (Push_Pull => 0, Open_Drain => 2#0001_0000#); procedure Set_Interrupt_Pin_Mode (This : in out Three_Axis_Gyroscope; Mode : Pin_Modes); type Interrupt1_Sources is record Interrupts_Active : Boolean; Z_High_Interrupt : Boolean; Z_Low_Interrupt : Boolean; Y_High_Interrupt : Boolean; Y_Low_Interrupt : Boolean; X_High_Interrupt : Boolean; X_Low_Interrupt : Boolean; end record with Size => 8; for Interrupt1_Sources use record Interrupts_Active at 0 range 6 .. 6; Z_High_Interrupt at 0 range 5 .. 5; Z_Low_Interrupt at 0 range 4 .. 4; Y_High_Interrupt at 0 range 3 .. 3; Y_Low_Interrupt at 0 range 2 .. 2; X_High_Interrupt at 0 range 1 .. 1; X_Low_Interrupt at 0 range 0 .. 0; end record; function Interrupt1_Source (This : Three_Axis_Gyroscope) return Interrupt1_Sources; -- Miscellaneous functionality procedure Sleep (This : in out Three_Axis_Gyroscope); -- See App Note 4505, pg 9 procedure Reboot (This : Three_Axis_Gyroscope); procedure Reset (This : in out Three_Axis_Gyroscope); -- writes default values to all writable registers I_Am_L3GD20 : constant := 16#D4#; function Device_Id (This : Three_Axis_Gyroscope) return UInt8; -- Will return I_Am_L3GD20 when functioning properly function Temperature (This : Three_Axis_Gyroscope) return UInt8; -- the temperature of the chip itself private type Three_Axis_Gyroscope is tagged limited record Port : Any_SPI_Port; CS : Any_GPIO_Point; end record; type Register is new UInt8; procedure Write (This : Three_Axis_Gyroscope; Addr : Register; Data : UInt8) with Inline; -- Writes Data to the specified register within the gyro chip procedure Read (This : Three_Axis_Gyroscope; Addr : Register; Data : out UInt8) with Inline; -- Reads Data from the specified register within the gyro chip procedure Read_UInt8s (This : Three_Axis_Gyroscope; Addr : Register; Buffer : out SPI_Data_8b; Count : Natural); -- Reads multiple Data from the specified register within the gyro chip -- L3GD20 Registers Who_Am_I : constant Register := 16#0F#; -- device identification CTRL_REG1 : constant Register := 16#20#; -- Control register 1 CTRL_REG2 : constant Register := 16#21#; -- Control register 2 CTRL_REG3 : constant Register := 16#22#; -- Control register 3 CTRL_REG4 : constant Register := 16#23#; -- Control register 4 CTRL_REG5 : constant Register := 16#24#; -- Control register 5 Reference : constant Register := 16#25#; -- Reference OUT_Temp : constant Register := 16#26#; -- Temperature Status : constant Register := 16#27#; -- Status OUT_X_L : constant Register := 16#28#; -- Output X low UInt8 OUT_X_H : constant Register := 16#29#; -- Output X high UInt8 OUT_Y_L : constant Register := 16#2A#; -- Output Y low UInt8 OUT_Y_H : constant Register := 16#2B#; -- Output Y high UInt8 OUT_Z_L : constant Register := 16#2C#; -- Output Z low UInt8 OUT_Z_H : constant Register := 16#2D#; -- Output Z high UInt8 FIFO_CTRL : constant Register := 16#2E#; -- FIFO control FIFO_SRC : constant Register := 16#2F#; -- FIFO src INT1_CFG : constant Register := 16#30#; -- Interrupt 1 configuration INT1_SRC : constant Register := 16#31#; -- Interrupt 1 source INT1_TSH_XH : constant Register := 16#32#; -- Interrupt 1 Threshold X INT1_TSH_XL : constant Register := 16#33#; -- Interrupt 1 Threshold X INT1_TSH_YH : constant Register := 16#34#; -- Interrupt 1 Threshold Y INT1_TSH_YL : constant Register := 16#35#; -- Interrupt 1 Threshold Y INT1_TSH_ZH : constant Register := 16#36#; -- Interrupt 1 Threshold Z INT1_TSH_ZL : constant Register := 16#37#; -- Interrupt 1 Threshold Z INT1_Duration : constant Register := 16#38#; -- Interrupt 1 Duration end L3GD20;
-- C46051A.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- CHECK THAT ENUMERATION, RECORD, ACCESS, PRIVATE, AND TASK VALUES CAN -- BE CONVERTED IF THE OPERAND AND TARGET TYPES ARE RELATED BY -- DERIVATION. -- R.WILLIAMS 9/8/86 WITH REPORT; USE REPORT; PROCEDURE C46051A IS BEGIN TEST ( "C46051A", "CHECK THAT ENUMERATION, RECORD, ACCESS, " & "PRIVATE, AND TASK VALUES CAN BE CONVERTED " & "IF THE OPERAND AND TARGET TYPES ARE " & "RELATED BY DERIVATION" ); DECLARE TYPE ENUM IS (A, AB, ABC, ABCD); E : ENUM := ABC; TYPE ENUM1 IS NEW ENUM; E1 : ENUM1 := ENUM1'VAL (IDENT_INT (2)); TYPE ENUM2 IS NEW ENUM; E2 : ENUM2 := ABC; TYPE NENUM1 IS NEW ENUM1; NE : NENUM1 := NENUM1'VAL (IDENT_INT (2)); BEGIN IF ENUM (E) /= E THEN FAILED ( "INCORRECT CONVERSION OF 'ENUM (E)'" ); END IF; IF ENUM (E1) /= E THEN FAILED ( "INCORRECT CONVERSION OF 'ENUM (E1)'" ); END IF; IF ENUM1 (E2) /= E1 THEN FAILED ( "INCORRECT CONVERSION OF 'ENUM1 (E2)'" ); END IF; IF ENUM2 (NE) /= E2 THEN FAILED ( "INCORRECT CONVERSION OF 'ENUM2 (NE)'" ); END IF; IF NENUM1 (E) /= NE THEN FAILED ( "INCORRECT CONVERSION OF 'NENUM (E)'" ); END IF; EXCEPTION WHEN OTHERS => FAILED ( "EXCEPTION RAISED DURING CONVERSION OF " & "ENUMERATION TYPES" ); END; DECLARE TYPE REC IS RECORD NULL; END RECORD; R : REC; TYPE REC1 IS NEW REC; R1 : REC1; TYPE REC2 IS NEW REC; R2 : REC2; TYPE NREC1 IS NEW REC1; NR : NREC1; BEGIN IF REC (R) /= R THEN FAILED ( "INCORRECT CONVERSION OF 'REC (R)'" ); END IF; IF REC (R1) /= R THEN FAILED ( "INCORRECT CONVERSION OF 'REC (R1)'" ); END IF; IF REC1 (R2) /= R1 THEN FAILED ( "INCORRECT CONVERSION OF 'REC1 (R2)'" ); END IF; IF REC2 (NR) /= R2 THEN FAILED ( "INCORRECT CONVERSION OF 'REC2 (NR)'" ); END IF; IF NREC1 (R) /= NR THEN FAILED ( "INCORRECT CONVERSION OF 'NREC (R)'" ); END IF; EXCEPTION WHEN OTHERS => FAILED ( "EXCEPTION RAISED DURING CONVERSION OF " & "RECORD TYPES" ); END; DECLARE TYPE REC (D : INTEGER) IS RECORD NULL; END RECORD; SUBTYPE CREC IS REC (3); R : CREC; TYPE CREC1 IS NEW REC (3); R1 : CREC1; TYPE CREC2 IS NEW REC (3); R2 : CREC2; TYPE NCREC1 IS NEW CREC1; NR : NCREC1; BEGIN IF CREC (R) /= R THEN FAILED ( "INCORRECT CONVERSION OF 'CREC (R)'" ); END IF; IF CREC (R1) /= R THEN FAILED ( "INCORRECT CONVERSION OF 'CREC (R1)'" ); END IF; IF CREC1 (R2) /= R1 THEN FAILED ( "INCORRECT CONVERSION OF 'CREC1 (R2)'" ); END IF; IF CREC2 (NR) /= R2 THEN FAILED ( "INCORRECT CONVERSION OF 'CREC2 (NR)'" ); END IF; IF NCREC1 (R) /= NR THEN FAILED ( "INCORRECT CONVERSION OF 'NCREC (R)'" ); END IF; EXCEPTION WHEN OTHERS => FAILED ( "EXCEPTION RAISED DURING CONVERSION OF " & "RECORD TYPES WITH DISCRIMINANTS" ); END; DECLARE TYPE REC IS RECORD NULL; END RECORD; TYPE ACCREC IS ACCESS REC; AR : ACCREC; TYPE ACCREC1 IS NEW ACCREC; AR1 : ACCREC1; TYPE ACCREC2 IS NEW ACCREC; AR2 : ACCREC2; TYPE NACCREC1 IS NEW ACCREC1; NAR : NACCREC1; FUNCTION F (A : ACCREC) RETURN INTEGER IS BEGIN RETURN IDENT_INT (0); END F; FUNCTION F (A : ACCREC1) RETURN INTEGER IS BEGIN RETURN IDENT_INT (1); END F; FUNCTION F (A : ACCREC2) RETURN INTEGER IS BEGIN RETURN IDENT_INT (2); END F; FUNCTION F (A : NACCREC1) RETURN INTEGER IS BEGIN RETURN IDENT_INT (3); END F; BEGIN IF F (ACCREC (AR)) /= 0 THEN FAILED ( "INCORRECT CONVERSION OF 'ACCREC (AR)'" ); END IF; IF F (ACCREC (AR1)) /= 0 THEN FAILED ( "INCORRECT CONVERSION OF 'ACCREC (AR1)'" ); END IF; IF F (ACCREC1 (AR2)) /= 1 THEN FAILED ( "INCORRECT CONVERSION OF 'ACCREC1 (AR2)'" ); END IF; IF F (ACCREC2 (NAR)) /= 2 THEN FAILED ( "INCORRECT CONVERSION OF 'ACCREC2 (NAR)'" ); END IF; IF F (NACCREC1 (AR)) /= 3 THEN FAILED ( "INCORRECT CONVERSION OF 'NACCREC (AR)'" ); END IF; EXCEPTION WHEN OTHERS => FAILED ( "EXCEPTION RAISED DURING CONVERSION OF " & "ACCESS TYPES" ); END; DECLARE TYPE REC (D : INTEGER) IS RECORD NULL; END RECORD; TYPE ACCR IS ACCESS REC; SUBTYPE CACCR IS ACCR (3); AR : CACCR; TYPE CACCR1 IS NEW ACCR (3); AR1 : CACCR1; TYPE CACCR2 IS NEW ACCR (3); AR2 : CACCR2; TYPE NCACCR1 IS NEW CACCR1; NAR : NCACCR1; FUNCTION F (A : CACCR) RETURN INTEGER IS BEGIN RETURN IDENT_INT (0); END F; FUNCTION F (A : CACCR1) RETURN INTEGER IS BEGIN RETURN IDENT_INT (1); END F; FUNCTION F (A : CACCR2) RETURN INTEGER IS BEGIN RETURN IDENT_INT (2); END F; FUNCTION F (A : NCACCR1) RETURN INTEGER IS BEGIN RETURN IDENT_INT (3); END F; BEGIN IF F (CACCR (AR)) /= 0 THEN FAILED ( "INCORRECT CONVERSION OF 'CACCR (AR)'" ); END IF; IF F (CACCR (AR1)) /= 0 THEN FAILED ( "INCORRECT CONVERSION OF 'CACCR (AR1)'" ); END IF; IF F (CACCR1 (AR2)) /= 1 THEN FAILED ( "INCORRECT CONVERSION OF 'CACCR1 (AR2)'" ); END IF; IF F (CACCR2 (NAR)) /= 2 THEN FAILED ( "INCORRECT CONVERSION OF 'CACCR2 (NAR)'" ); END IF; IF F (NCACCR1 (AR)) /= 3 THEN FAILED ( "INCORRECT CONVERSION OF 'NCACCR (AR)'" ); END IF; EXCEPTION WHEN OTHERS => FAILED ( "EXCEPTION RAISED DURING CONVERSION OF " & "CONSTRAINED ACCESS TYPES" ); END; DECLARE PACKAGE PKG1 IS TYPE PRIV IS PRIVATE; PRIVATE TYPE PRIV IS RECORD NULL; END RECORD; END PKG1; USE PKG1; PACKAGE PKG2 IS R : PRIV; TYPE PRIV1 IS NEW PRIV; R1 : PRIV1; TYPE PRIV2 IS NEW PRIV; R2 : PRIV2; END PKG2; USE PKG2; PACKAGE PKG3 IS TYPE NPRIV1 IS NEW PRIV1; NR : NPRIV1; END PKG3; USE PKG3; BEGIN IF PRIV (R) /= R THEN FAILED ( "INCORRECT CONVERSION OF 'PRIV (R)'" ); END IF; IF PRIV (R1) /= R THEN FAILED ( "INCORRECT CONVERSION OF 'PRIV (R1)'" ); END IF; IF PRIV1 (R2) /= R1 THEN FAILED ( "INCORRECT CONVERSION OF 'PRIV1 (R2)'" ); END IF; IF PRIV2 (NR) /= R2 THEN FAILED ( "INCORRECT CONVERSION OF 'PRIV2 (NR)'" ); END IF; IF NPRIV1 (R) /= NR THEN FAILED ( "INCORRECT CONVERSION OF 'NPRIV (R)'" ); END IF; EXCEPTION WHEN OTHERS => FAILED ( "EXCEPTION RAISED DURING CONVERSION OF " & "PRIVATE TYPES" ); END; DECLARE TASK TYPE TK; T : TK; TYPE TK1 IS NEW TK; T1 : TK1; TYPE TK2 IS NEW TK; T2 : TK2; TYPE NTK1 IS NEW TK1; NT : NTK1; TASK BODY TK IS BEGIN NULL; END; FUNCTION F (T : TK) RETURN INTEGER IS BEGIN RETURN IDENT_INT (0); END F; FUNCTION F (T : TK1) RETURN INTEGER IS BEGIN RETURN IDENT_INT (1); END F; FUNCTION F (T : TK2) RETURN INTEGER IS BEGIN RETURN IDENT_INT (2); END F; FUNCTION F (T : NTK1) RETURN INTEGER IS BEGIN RETURN IDENT_INT (3); END F; BEGIN IF F (TK (T)) /= 0 THEN FAILED ( "INCORRECT CONVERSION OF 'TK (T))'" ); END IF; IF F (TK (T1)) /= 0 THEN FAILED ( "INCORRECT CONVERSION OF 'TK (T1))'" ); END IF; IF F (TK1 (T2)) /= 1 THEN FAILED ( "INCORRECT CONVERSION OF 'TK1 (T2))'" ); END IF; IF F (TK2 (NT)) /= 2 THEN FAILED ( "INCORRECT CONVERSION OF 'TK2 (NT))'" ); END IF; IF F (NTK1 (T)) /= 3 THEN FAILED ( "INCORRECT CONVERSION OF 'NTK (T))'" ); END IF; EXCEPTION WHEN OTHERS => FAILED ( "EXCEPTION RAISED DURING CONVERSION OF " & "TASK TYPES" ); END; RESULT; END C46051A;
-- -- The following is based on John Maddock's extended precision -- (Boost Library) gamma function. It uses the gamma rational -- poly functions (for the range x = 1 to 3) worked out by John Maddock, -- so his Copyright will be retained. -- -------------------------------------------------------------------------- -- (C) Copyright John Maddock 2006. -- Use, modification and distribution are subject to the -- Boost Software License, Version 1.0. (See accompanying file -- LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -- --Boost Software License - Version 1.0 - August 17th, 2003 -- --Permission is hereby granted, free of charge, to any person or organization --obtaining a copy of the software and accompanying documentation covered by --this license (the "Software") to use, reproduce, display, distribute, --execute, and transmit the Software, and to prepare derivative works of the --Software, and to permit third-parties to whom the Software is furnished to --do so, all subject to the following: -- --The copyright notices in the Software and this entire statement, including --the above license grant, this restriction and the following disclaimer, --must be included in all copies of the Software, in whole or in part, and --all derivative works of the Software, unless such copies or derivative --works are solely in the form of machine-executable object code generated by --a source language processor. -- --THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT --SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE --FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, --ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER --DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------- -- -- Natural logarithm of Gamma function for positive real arguments. -- generic type Real is digits <>; package Gamma_1_to_3 is pragma Pure(Gamma_1_to_3); function Log_Gamma_1_to_3 (x : in Real) return Real; -- Only good for 1 < x < 3 private Real_Epsilon : constant Real := (+0.125) * Real'Epsilon; -- have to modify this if Real is abstract end Gamma_1_to_3;
with Datos, Ada.Text_Io; use Datos, Ada.Text_Io; with Insertar_en_Lista_Ordenada, esc, crear_lista_vacia; procedure Prueba_Insertar_en_Lista_Ordenada is Lis: Lista; procedure Pedir_Return is begin Put_Line("pulsa return para continuar "); Skip_Line; end Pedir_Return; begin Put_Line("Programa de prueba: "); Put_Line("*******************"); Put_Line("Prueba de Crear_Lista_Vacia "); Crear_Lista_Vacia(Lis); Put_Line("Ahora deberia escribir la lista vacia: "); Esc(Lis); New_Line; New_Line; Pedir_Return; Put_Line("Prueba de Insertar_Ordenado "); Put_Line("Primer caso de prueba: insertar en lista vacia "); Insertar_en_Lista_Ordenada(Lis, 5); Put_Line("Ahora deberia escribir la lista <5>: "); Esc(Lis); New_Line; New_Line; Pedir_Return; Put_Line("prueba de Insertar_Ordenado "); Put_Line("Segundo caso de prueba: insertar al final "); Insertar_en_Lista_Ordenada(Lis, 9); Put_Line("Ahora deberia escribir la lista <5, 9> "); Esc(Lis); New_Line; New_Line; Pedir_Return; Put_Line("prueba de Insertar_Ordenado "); Put_Line("Tercer caso de prueba: insertar al comienzo "); Insertar_en_Lista_Ordenada(Lis, 3); Put_Line("Ahora deberia escribir la lista <3, 5, 9> "); Esc(Lis); New_Line; New_Line; Pedir_Return; Put_Line("prueba de Insertar_Ordenado "); Put_Line("Cuarto caso de prueba: insertar en medio "); Insertar_en_Lista_Ordenada(Lis, 7); Put_Line("Ahora deberia escribir la lista <3, 5, 7, 9> "); Esc(Lis); New_Line; New_Line; Pedir_Return; Put_Line("prueba de Insertar_Ordenado "); Put_Line("Quinto caso de prueba: insertar alfinal "); Insertar_en_Lista_Ordenada(Lis, 15); Put_Line("Ahora deberia escribir la lista <3, 5, 7, 9, 15> "); Esc(Lis); New_Line; New_Line; Pedir_Return; Put_Line("Se ha acabado la prueba.Agur "); end Prueba_Insertar_en_Lista_Ordenada;
############################################################################# ## #W sml1536.ada GAP library of groups Hans Ulrich Besche ## Bettina Eick, Eamonn O'Brien ## SMALL_GROUP_LIB[ 1536 ].2nil[ 105 ] := rec( ops := [ 2, 1044,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,, 10495, 11306, 2, 7295,,, 12350, 52, 2, 9217,, 3207,,,,,,,,,,,,,,,,,,,,,, 1003, 5531,, 2,,,,,, 5531,, 2,, 5531, 2, 1003,, 5531,, 6918,,,, 11458,, 6918,, 11504,, 1003, 5530, 2, 1003,,,, 5530, 1003, 2, 5530, 1003, 2,,, 5530,, 8113,,,, 298,, 11314,, 10620,, 2489, 7072, 10967, 1559, 2, 8129, 14744, 2, 1351, 13516, 14241, 14519, 14653, 2, 11769, 11805, 2, 11853,, 14563,, 11855, 13958, 13947, 2489, 3296, 4422, 3302, 3124, 4702, 6975, 8648, 3942, 5793, 3296, 5922,,, 3991, 3302, 4422,, 4433, 6972, 7079,, 8646, 7079, 8151, 12497, 12491, 12511, 7076, 11543, 8647, 11544, 12500, 8133, 12518,, 12505, 8644, 11533, 11535, 5922, 3296, 3991, 3663, 6970, 3296, 3663, 3991, 3124, 4702, 5772, 8740, 3942, 5793, 3296, 4422, 3302, 3663, 3124, 8152, 8151, 5143, 6975, 7076, 3942, 11550, 11549, 3942, 3296, 3663, 3991, 3124, 4702, 5772, 8740, 3942, 5793, 4422, 3302, 6976, 5145, 4433, 2817, 13587, 8169, 6978, 11611, 13773, 8271, 13061, 5146, 11671, 11668, 8727, 8408, 13581, 4011, 2670,,, 2688, 5191, 2321, 5192, 12694, 2321, 12692, 5191, 3501, 5192, 5248, 8778, 13702, 12683, 3691, 9386, 12695, 12696, 8780, 7091, 4832,, 8780, 4832, 8779, 12689, 3320, 8776, 13719, 12698, 12699, 9391, 12691, 13715, 12687, 8776, 13703, 12690, 8777, 4011, 5191,, 2670,, 3501, 5191, 12682, 5248, 5192, 12867, 8778, 9389, 13700, 12693, 12688, 8989, 3323,, 12684, 9392, 12697, 7091, 13867, 12700, 12801, 11955, 2454, 3954, 7016, 2817, 11958, 11956, 5157, 7017, 12187, 3300, 7010, 12042, 12041, 8408, 11957, 8346, 8384, 3327, 3666,, 5192, 8346, 12048, 7021, 14390,, 12050, 14389, 12083, 13403, 9427, 11978, 7022, 9147, 1827,, 13186, 5275, 11971, 11970, 12054, 12047, 12049, 12051, 14398, 14396, 14392, 14391, 14405, 11969, 12120, 12701, 5166, 12165, 9913, 1585,, 12982, 5144, 5145, 13618, 5144, 3474, 6976, 8167, 5144, 7171, 8202, 8173, 11607, 8728, 12670, 9331, 13547, 13671, 6544, 1827,, 11609, 5146, 11606, 11603, 13630, 7085, 12851, 13602, 13656, 13655, 9322, 6991, 8254, 14016, 6991, 3676, 6992, 11778, 6991, 14021, 8131, 3124, 11998, 3473, 8138, 3124, 11524, 5142, 12593, 8645, 5978, 11899, 2995, 11536, 5140, 12074, 7083, 12621, 12850, 5141, 11772, 5794, 12160, 12978, 5795, 5794, 3943, 7093,, 3474, 1152,, 11751, 5944, 12597, 12788, 12637, 12562, 5944, 7262, 6544, 1827,, 14258, 5276, 12555, 12553, 11690, 12756, 7085, 12631, 14343, 11696, 14334, 14331, 6479, 9322, 5149, 3676, 2755,, 7114, 8198, 8201, 12040, 7084, 8200, 6982, 8202, 11674, 8198, 12560, 6982, 8200, 12595, 3672, 14065, 8673, 12664,, 7107, 12543, 6066, 791, 4958, 13,, 14673, 303, 11657, 11654, 11656, 11670, 11748, 8722, 8674, 12636,, 8722, 12625, 14068, 14615, 12624, 8745, 12626,, 12914, 14072, 8316, 1198, 362,, 14039, 14041, 14051, 14076, 14042, 14040, 8332, 826, 9877,, 11687, 13573, 12329, 14491, 7000, 11847, 14173, 7000, 4446, 4699, 5152, 7000, 14175, 9225, 8257, 11792, 12273, 5150, 11791, 8257, 5150, 5798, 9653, 5150, 6066, 3688,, 5150, 5798, 9653, 5150, 14135, 6433, 14123, 4958, 9589, 14501, 14124, 9589, 11826, 5799, 6996, 14046, 9639, 14140,, 14154, 14155, 14101, 14102, 14137, 14044, 9335, 14139, 14156, 14470, 14138, 14475, 14666, 9335, 8277, 8276, 8274, 5152, 4699, 9659, 5152, 4446, , 4699, 9659, 5152, 5796, 8259, 8521, 8258, 5796, 10036, 4096, 8275, 16, 8261, 3454, 13225, 8261, 11810, 3454, 13462, 7158, 8997, 3454,, 4036, 13451, 770, 8957,,, 4036, 11811, 11815, 11816, 11813, 6998, 3458, 5231, 13055, 8998, 13085,, 13471, 13472, 13333, 13334, 13083, 13052, 11842, 4698, 13477, 13479, 13098, 4698, 8262, 11817, 13226, 8262, 8878, 9006, 9243, 14624, 13084, 9243, 8878, 9006, 8256, 11789, 11793, 8256, 11819, 11823, 12189, 13067, 11822, 11820, 11830, 13524, 11828, 8986, 11829, 5171, 11839, 6999, 13526,, 8986,, 9550, 2066, 996,, 14172, 13987, 9549, 2330, 1082,,, 8291, 11848, 14174, 8291, 123, 7001, 11870, 11846, 14176, 13951, 13953, 13962, 13993, 9550, 13952, 8341, 9272,, 2005, 267,, 5796, 8259, 8521, 8275, 8258, 5796, 11831, 12374, 8265, 11525, 11553, 11983, 11590, 12503, 12830, 4691, 12289, 14252, 14248, 14266, 12275, 12306, 12411, 12251, 11659, 8867, 12870, 12857, 6510, 12608, 12810, 12918, 14431, 14370, 9757, 14515, 14340, 12271, 14630, 14360, 14364, 12294, 14629, 14361, 14363, 9757, 14344, 14336, 14357, 13112, 12266, 12915, 2090, 1003,,, 12407, 13374, 11520, 11589, 12702, 8135, 11880, 11661, 6973, 13556, 11569, 13010, 13011, 11897, 12769, 11942, 12652, 12760, 13287, 12601, 12804, 13291, 3693, 9460, 14761, 7184, 12076, 14088, 13792, 13798, 12122, 14084, 7189, 13797, 12194, 9460, 13776, 13372, 13750, 13831, 13107, 12035, 11527, 11996, 11985, 12718, 13305, 12290, 11754, 13748, 12561, 11898, 12114, 11730, 12723, 12732, 12132, 11698, 8867, 12872, 12858, 12878, 12712, 6510, 7105, 14782, 14732, 9020, 2933,,, 8895, 12873, 12860, 8895, 12565, 6510, 7105,,, 2090, 9464, 9490, 1003, 964, 1452, 382, 1256,, 472, 1256, 603, 9491, 7284, 5246, 6563, 3142, 2670, 5236, 4438, 9433, 9359, 4012, 6223, 3502, 3313, 9374, 5248, 3502,, 8804, 13627, 9425, 8783, 12761, 13818, 7092, 12709, 4832, 13614, 12798, 12768, 13829, 13633, 7092, 13072, 12749, 12705, 12703, 5240, 9353, 12715, 12710, 9353, 5240, 12795, 13626, 13785, 5240, 13794, 8789, 13616, 9391, 13720, 3142, 2670, 5236, 4012, 6223, 3502, 8783, 3142, 4438,, 7014, 7027, 8450, 11982, 12139, 11981, 12087, 7014, 7027, 8349, 8440,, 12077, 11980, 7015, 2670, 4788, 2321, 3502, 2688, 9433, 3502, 4788, 2321, 2688, 5156, 12003, 13021, 5156, 9386, 4463, 13757, 4832, 13713,, 7018, 12010,, 7054, 12089,, 12004, 8380, 12030,, 3320, 13699, 3692, 13756, 13716, 12011, 12090, 8370, 3320, 3692, 2454, 5816,,,, 2817, 3502, 3954, 1568, 2321, 8367, 12079, 5820, 6240, 13820, 5821, 12130, 9407, 7019, 3300, 9412, 8361, 8368, 8377, 5240, 13784,, 13793, 12013, 12078, 13711, 8371, 3320, 9440, 2454, 3502, 3954, 2321, 6240, 2670, 3501, 2454, 2817, 3502, 8367, 2454, 3502, 2670, 2454, 2817, 2321, 8385, 1568, 2321, 8355, 12014, 5820, 9387, 13704, 5821, 9407, 7019, 9412, 8357, 8368, 8377, 3320, 13705, 12031, 12012, 8371, 3320, 2670, 3954, 2454, 2817, 2321, 8355, 2670, 3142,, 13293, 4438, 2321, 2688, 4012, 3313, 2688, 13758, 12753, 4760, 13774, 12752, 7092, 4832, 13070, 13935, 12726, 12874, 12748, 12727, 12713, 3320, 9440,, 13714, 12725, 13069, 8789, 3142, 2670, 2321, 4012, 4760, 3142, 3485, 338,, 3313, 3327,, 13461,, 3327,, 3485, 338,, 13337, 338, 4789,,, 982, 9236, 14432,, 9059, 13309, 13205, 9080, 14404,, 13306, 9070, 13216, 146, 7134,, 7133, 4795, 146,, 5222, 1827,, 13323, 5275, 146,, , 3711, 1070,,, 14410, 9781, 9131, 9058, 14394,, 13189, 13199, 9132, 9790, 9057, 13304, 13204, 13214, 6522, 6535, 9853, 9854, 4050, 973,, 4796, 4276,, ,, 4050, 973,,, 6098,,, 6216, 5236, 9336, 7171, 2321, 2688, 9284, 6223, 9336, 9286, 9331, 7169, 9299, 13632, 13569, 9357, 14130, 13621, 13566, 13646, 13548, 13561, 13563, 3320, 3692, 13545, 13615, 13576, 13546, 13552, 6216, 9284, 5236, 6216, 7171,, 3991, 3302, 5236, 13157, 8138, 12513, 2321, 3473, 3000, 4765, 4788, 8141, 11616, 12711, 9299, 12520, 12532, 9357, 8144, 7018, 11878, 6971, 11598, 11558, 12495, 3320, 12592, 12708, 8651, 12622, 3663, 2454,,, 6974, 3124, 5186, 4765, 12001, 12000, 8169, 11577, 12716, 11557, 5821, 11622, 8144, 5140, 11561, 11555, 12524, 8651, 11994, 11992, 4422, 3663, 9777, 5247, 6093, 3686, 3327, 9034, 5247, 3327, 2319, 9038, 9093, 338, 13163, 3327, 9034, 9777, 5247, 6093, 3686, 146, 4794, 13164, 146, 9107, 9039, 9786, 14426, 13161, 9796, 7266, 13159, 146, 9106, 13170, 146, 9108, 13168, 7266, 6333, 9035, 3686, 9093, 13180, 13218, 9780, 3711, 9036, 9785, 9796, 9036, 9779, 14427, 13160, 9797, 14477, 9104, 13299, 13280, 2936, 9798, 9778, 14424, 14403, 14407, 9789, 7199, 6094, 4276, 7199, 14400, 13265, 9048, 973, 4276, 9789, 7199, 6094, 3990, 4765,, 2688, 2925, 4030, 3990, 4765,, 2688, 2925, 4030, 338, 8637, 7101,, 2925, 12854, 9591, 8886, 14355, 12455, 4766, 4478, 12454, 3176, 146, 1379, 141, 13853, 6335, 146,, 8638,, 146,, 8638, 8843, 6479, 8846, 7103, 9457, 9732, 9502, 14478,, 4927, 13915, 13905, 5915, 8848,, 4845, 7200, 5915, 8848,, 4845, 7200, 973, 8639, 12839,, 7200, 12855, 3473, 2688, 6114, 9754, 6065, 3000, 6013, 3304, 3313, 8772, 2319, 338, 13344, 5978, 8826, 13276, 12793, 5975, 8858, 12641, 9117, 8743, 8857, 12639, 3176, 146, 8748, 4791, 2009, 6149, 14106, 13319, 4793, 9130, 4799, 9122, 13272, 4268, 146, 8757, 4436, 7140, 6014, 9114, 13296, 8742, 12871, 8760, 12792, 8750, 13260, 6015, 6526, 4927, 4008, 4845, 6115, 9756, 5976, 6016, 4755, 4796, 4058, 973, 3304, 3943, 4461, 2319, 13001,, 3304, 3943, 4461, 13387, 338, 3474, 8211, 4461, 3666, 13390, 5977, 14353, 11693, 8751, 14352, 11692, 146, 7032, 11711, 146, 5850, 11710, 4794, 146, 4799, 1827, 13320, 9755, 8749, 14351, 5190, 12794, 9115, 9834, 8424, 13039, 12119, 6538, 4755, 5780, 7174, 4058, 4755, 5780, 7174, 973, 12632, 8223, 7174, 12102, 3473, 2688, 6114, 9754, 6065, 3000, 6013, 3304, 3313, 8772, 338, 13277, 12669, 8825, 5978,, 5975, 8858, 12640, 3158, 8741, 8857, 12638, 3176, 146, 8748, 9101, 13307, 6149, 13298, 13271, 4791, 4795, 4799, 5222, 13269, 4268, 146, 8757, 12623, 4436, 6014, 13270, 13295, 7083, 12869, 8760, 12791, 12629, 12628, 6015, 9842, 4927, 4008, 4845, 6115, 9756, 5976, 6016, 4755, 4796, 973, 5916, 7107,, 7190, 7227, 4030, 6416, 9200, 12969, 8873, 8882, 14075, 14622, 12470, 7228, 13,, 12465, 6028, 6417, 14614, 8875, 12475, 4030, 6416, 9200, 5916, 7107,, 7190, 7227, 13120, 13, 5227, 12466, 613, 13, 14098, 630, 13, 14654, 3324, 13,, 12463, 7122, 13,, 12468, 4954, 8967, 13426, 1069, 8641, 12892,, 7227, 12904, 14185, 1006, 8887, 8876, 2266, 12471, 8898, 12909, 14620, 12917, 6587, 5195, 8871, 12895, 14608, 9604, 9949, 12908, 8872, 12913, 14074, 6586, 8880, 12903, 14612, 12906, 4163, 16, 3017, 1362,,, 4163, 16, 2199,, 9625, 10006,, 14159, 10007, 127, 14161, 9624, 10006,, 14160, 14104, 9623, 14675,, 5, 8965, 8999,, 3017, 9654, 8966, 8999,, 3017, 14157, 16, 8968, 13079,, 9654, 13080, 6418, 3017, 10005, 14500, 6419, 14151, 10010, 14502, 9601, 9605, 9602, 127, 9607, 9609, 9608, 14680, 6610, 16, 6, 9201, 9220,, 1362, 9655,, 9203, 9220,, 14158, 16, 9202, 13439,, 9655, 13436, 6006, 1152,, 2396, 338,, 1152, 6006, 8995, 338, 5245,, 8855, 1152, 12862, 3209, 1070,, 12825, 6288, 2009,,,, 9489, 141,, 13851, 2009, 141, 9455, 13812, 1070, 13807, 2342, 146, 12827, 8885, 3209,, 8841, 7262,, 13804, 12868, 12931, 8839, 4478,, 6523, 12828, 6531, 1645, 9741, 9747, 14482, 5282, 6538, 8840, 14326,, 9451, 4284,, 12829, 12826, 9733, 8861, 14483,, 6007, 4909,, 9453, 973,, 4909, 6007, 973, 8856, 4909, 7138, 4826, 12248, 2396, 12304, 8512, 12298, 9750, 14481, 12824, 13245, 8543, 12247, 13237, 13235, 13238, 13674, 13799, 12305, 8513, 1568, 6105,, 338,, 6105, 8540, 5878, 3132, 4726, 1568, 3132, 5878, 8612, 7051, 4730,, 12260, 12259, 12267, 7048, 12265, 7049, 3979,, 146, 12258, 4727, 4729,, 8511, 2995, 1827, ,, 8518, 8510, 12279,, 12264, 12263, 5177, 8558, 7056, 2994, 13230, 13231, 2188, 6106,, 973,, 6106, 5879, 5880, 4728, 2188, 5880, 5879, 338, 13, 2396, 338,,,,,,,, 7237,, 338,,,,,,,, 7237, 141, 146, 2213, 141, 146, 2213, 9456, 9454,, 9450, 146,, 13814, 9467, 4846,, 9452, 146,, 13815, 6289, 146,, ,, 141, 6370,,, 13852, 1827, 146, 938, 1070, 4846,,, 6290, 146,,,, 13832, 13806, 13805, 6534, 13802, 13801, 6530, 9859, 6528, 9858, 3022, 6534, 5281, 9852, 13811, 13808, 13816, 13810, 9447, 5281,, 13813, 13809, 9449, 9448,, 13803, 13800, 6535, 973, 2687,,,,,,,,,,,,,,,,, 1568, 338,,,,,,, 2189, 4726, 1568,,,,,, 12408, 4730, 9227,,, 8559, 146, 12314, 3979, 8958,, , 146, 7055, 12317, 4727, 4729,, 4730, 8535,,, 12297, 2995, 1827,,, 5176, 146,,, 3668, 12281, 12280, 8552, 2819, 5177, 12321, 13113, 8558, 12316, 5883, 9834, 8546, 8545,,, 8552, 2819, 6524, 2188, 973,,,,,,, 4728, 2188,,,, ,, 338, 1219, 6476, 1152,, 4480, 338,, 1152, 6476, 14699, 4480, 4905,, 338, , 4905,, 14316, 9809, 9745, 146, 9735, 14350, 141, 146, 9731, 14347, 14414, 14289, 14288, 1070, 14303, 14290, 14296, 14416, 14315, 14301, 14307, 14306, 14300, 4277, 146,,,, 14298, 1827, 14335, 146, 4277,,, 14291, 14304, 14299, 14349, 14342, 14412, 9722, 9856, 6528, 3022, 6524, 14413, 14415, 14418, 14417, 14420, 14419, 14295, 14294, 973, 6477, 9740,, 4910, 973,, 9740, 6477, 4910, 9723,, 973,, 9723,, 1568, 6105,, 338,, 6105, 8540, 5878, 3132, 4726, 1568, 3132, 5878, 8612, 7051, 13415, 4730, 7055, 13229, 7048, 14327, 12301, 3979, 7049, 12256, 2009, 12261, 4727, 4729,, 8511, 2995, 1827,,, 8518, 12242, 12241, 12262, 12257, 12315, 5177, 12964, 7056, 14479, 2994, 2819, 5282, 9085, 2188, 6106,, 973,, 6106, 5879, 5880, 4728, 2188, 5880, 5879, 303, 4313,, 13,, 4313,, 13,, 4313,, 14656, 6058, 3225, 4884, 303, 3225, 6058, 8995,, 7237, 4884, 6497, 6058, 13146, 4313, 303, 13, , 4313,,,, 13,, 4313, 14640, 13, 2546, 770, 3225, 13, 303, 770, 3225,, 303, 13, 3225, 770, 14714, 3536, 13,,,,,,,, 14439, 4884, 303,,,,,, 13053, 13, 14708,, 303,,,,,,, 14631, 13, 303,,,,,,, 14633, 9991, 9976, 6612, 10012, 9991, 9976, 903, 14637, 9962, 10025, 2357, 10011,, 16, 9965, 9964, 4321, 6611, 9965, 9964, 14636, 1141, 10025, 9961, 4321, 6611,, 16, 9958, 9959, 2357, 10011, 9958, 9959, 16, 6612, 10012,, 903, 9972, 9956, 10024, 9960, 9957, 4321, 6611, 9960, 9957, 16, 4321, 6611,, 9972, 1141, 10024, 9955, 6421, 3548,, 14149,, 14495,, 16, 3548,,,,,, 2759, 5,,,,,,,,,,,,, 16, 11, 2208, 9004,, 16,, 9004,, 4894, 2393,, 11,, 2393,, 6071, 10026,, 2208, 16,, 10026, 6071, 6075, 955,, 4894, 11,, 955, 6075, 202, 9974,, 18,, 9974, 5305, 9973,, 16,, 9973, 8962, 9966, 14094, 202, 9966, 8962, 8954, 9963, 14092, 5305, 9963, 8954, 16, 2208,,,,,,,,,,,,,,,,, 202, 18,,,,,,, 6422, 202,,,,,, 2456, 3008, 4265, 770, 4024, 2634, 3008, 4068, 4478, 13, 4772, 4068, 4265, 2456, 2345, 9166, 2097, 1070,, 13, 2345, 6576, 13, 584,, 603, 1451, 4002, 3210, 893, 13, 13974, 3210, 893, 1451, 4002, 13, 14530, 770, 4751, 584, 3326, 13127, 3210, 3303, 584, 6499, 12609, 13, 2742, 2345, 13, 9863, 5967, 5993, 6019, 10029, 5953, 9428, 9746, 6488, 8738, 8775, 358, 687, 8702, 2463, 13300, 14339, 6494, 8724, 12776, 6487, 8690, 13763, 9744, 2675, 3219, 2466, 16, 2700, 881, 6, 1971, 3219, 2675, 16, 2466, 881, 2700, 1971, 6, 2397, 16, 2466,, 993, 6, 4267, 6507, 5273, 9867, 4270, 881, 6618, 6519, 4266, 6506, 6498, 4932, 6495, 6512, 9774, 6520, 6484, 4933, 4934, 6, 6513, 810, 16,, 955, 11,, 16, 11,, 810, 11, 955, 4751, 5782, 7165, 7025, 9706, 8523, 770, 3987, 12942, 584, 13, 3329, 8220, 3326, 9242, 770, 5881, 11701, 770, 13,, 7282, 13, 2189, 3303, 8218, 7165, 7025, 7130, 12182, 14253, 12276, 13102, 13, 3329, 584, 13, 8219, 7275, 13, 893,, 11716,, 4222, 6499, 13, 8220,, 14554, 770, 3987, 4751, 5782, 7165, 7025, 9706, 8523, 13101, 13, 3329, 584, 13, 8219, 770, 5881, 3326, 9242, 11703, 770, 13,, 7282, 5188, 2397, 7265, 810, 16, 8700, 2397, 14107, 9767, 810, 5188, 2397, 7265, 2924, 5835, 9815, 2529, 16, 4464, 5834, 6516, 7066, 6, 2924, 5835, 9815, 2529, 16, 4464, 5834, 6516, 7066, 6, 2397, 6221, 6373, 6521, 16, 2466, 6222, 7205, 7276, 2397, 6221, 6373, 6521, 16, 2466, 6222, 7205, 7276, 14377, 8527, 13466, 12336, 4932, 14375, 8525, 13464, 8572, 6618, 14376, 8526, 13465, 12335, 4932, 14374, 8524, 13463, 8572, 10030, 7265, 9710, 6521, 810, 5273, 9713, 7276, 16, 9767, 9711, 6521, 14444, 1556, 2997, 16, 4737, 1556, 2997, 955, 5902, 11, 8620, 955, 5902, 16, 11, 1556, 4809, 16, 955, 9251, 11, 810, 16,,,,,, 2456, 3008, 4265, 770, 4024, 2634, 3008, 4068, 4478, 13, 4772, 4068, 4265, 2456, 2345, 9166, 2097, 1070,, 13, 2345, 6576, 13, 584,, 603, 1451, 13, 12779,, 1451,, 12881, 770, 3326, 13,, 12613, 3210, 8691, 13, 6499, 8737, 13, 2742, 2345, 13, 9863, 5967, 5993, 6019, 10029, 5953, 9428, 9746, 6488, 1269, 2536, 358, 687, 5945, 2463, 3486, 14338, 6494, 14379, 12775, 6487, 8689, 13759, 9744, 2675, 3219, 2466, 16, 2700, 881, 6, 1971, 3219, 2675, 16, 2466, 881, 2700, 1971, 6, 16, , 6313, 4267, 6507, 5273, 9867, 4270, 881, 6618, 6519, 4266, 6506, 6498, 4932, 6495, 6512, 9774, 6520, 4934, 4933, 6483, 4934, 6, 810, 16,, 955, 11, , 16, 11,, 810, 11, 955, 3471, 3172, 2532, 6041, 3997, 3172, 3158, 281, 8918, 2097, 4069, 3229, 6425, 6556, 2679, 13, 281,, 9581, 630, 13, 3190, 12680, 565, 7078, 1136, 13, 12605, 5966, 5991, 8979, 5923, 9439, 5970, 6276, 4468, 7090, 5926, 9438, 13279, 1590, 4137, 6352, 201, 6369, 4177, 881, 6323, 237, 6351, 4136, 6367, 794, 4864, 6304, 1797, 6327, 4245, 6266, , 4890, 6, 2907, 201, 3679, 64, 201, 16, 64, 11, 12542, 8157, 9300, 4714, 2532, 3454, 12939, 3190, 982, 6143, 281, 8184, 2532, 281, 8909, 7078, 8183, 9300, 4714, 13175, 11903, 281, 3967, 12940, 3190, 982, 6143, 281, 8184, 3314, 13, 2541, 11717, 281, 13, 13997, 7077, 3696, 2907, 8680, 3696, 13345, 201, 13931, 8445, 13331, 12198, 794, 201, 7203, 8444, 3963, 3669, 13330, 12197, 13932, 8443, 794, 4245, 13933, 8442, 3963, 12389, 3696, 9308, 6373, 201, 13930, 9315, 7205, 201, 16, 7202, 9320, 6373, 14504, 8971, 8269, 201, 8486, 3679, 4698, 64, 8492, 201, 16, 8490, 64, 11, 187, 2907, 201, 16, 3471, 3172, 2532, 6041, 3997, 3172, 3158, 281, 8918, 2097, 4069, 3229, 6425, 6556, 2679, 13, 281,, 9581, 630, 2194, 5937, 3190, 13500, 565, 8706, 1136, 2194, 12604, 5966, 5991, 8979, 5923, 9439, 5970, 6276, 8736, 12678, 8657, 9438, 13278, 1590, 4137, 6352, 201, 6369, 4177, 881, 6323, 237, 6351, 4136, 6367, 794, 4864, 6304, 1797, 6327, 4245, 4890, 6267,, 259, 6, 2907, 201, 3679, 64, 201, 16, 64, 11, 2530, 1794, 770, 3718, 6044, 1794, 146, 13, 630, 1196, 146, 2712, 3229, 13,, 9897, 4263, 2530, 3718, 630, 9882, 13, 584,, 603,, 630,, 382, 630, 13,, 55, 13, 584, 619, 5968, 3175, 6493, 6032, 5965, 6250, 1556, 9947, 871, 2325, 4130, 2100, 850, 16, 2924, 850, 3504, 4286, 2466, 1362, 1497, 110, 6, 237, 4286, 4114, 6603, 6311, 4209, 110, 6, 5302, 16, 6, 1175,, 3175, 4158, 3546, 277, 4115, 2405, 16, 6604, 2074, 4119, 6606, 1433, 2405, 16, 6312, 2758, 2757,, 16, 810,,, 955, 11,, 16, 11,, 810, 11, 955, 4310, 1362, 4312, 237, 1362, 16, 237, 6, 3998, 4694, 1883, 5159, 3225, 9918, 8899, 1883, 6096, 2009, 982, 630, 8910, 2342, 146,, 8517, 4435, 3170, 8155, 630, 3301, 6602, 2189, 584, 5836, 630, 3301, 8911, 13, 1451, 8381, 1069, 13, 8364, 630, 13, 8393, 4748, 4829, 7263, 7108, 2198, 687, 2197, 4847, 13727, 8366, 13193, 12313, 13025, 14646, 4851, 5833, 9987, 9837, 13796, 5819, 4839, 12388, 9402, 9847, 4840, 9416, 9847, 1550, 10039, 8617, 14645, 12394, 13744, 8395, 10039, 9988, 2141, 3169, 3713, 7186, 1362, 4836, 2405, 4841, 4848, 16, 1099, 1556, 2997, 16, 4737, 1556, 2997, 16, 1556, 4809, 16, 4947, 5894, 2215, 5897,, 6148, 16, 2530, 1794, 770, 3718, 6044, 1794, 146, 13, 630, 1196, 146, 2712, 3229, 13,, 9897, 4263, 2530, 3718, 630, 9882, 13, 584,, 603,, 630,, 382, 630, 13,, 55, 13, 584, 619, 5968, 3175, 6493, 6032, 5965, 6250, 1556, 9947, 871, 2325, 4130, 2100, 850, 16, 2924, 850, 3504, 4286, 2466, 1362, 1497, 110, 6, 237, 4286, 4114, 6603, 6311, 4209, 110, 6, 5302, 16, 6, 1175,, 3175, 4158, 3546, 277, 4115, 2405, 16, 6604, 2074, 4119, 6606, 1433, 2405, 16, 6312, 2758, 2757,, 16, 810,,, 955, 11,, 16, 11,, 810, 11, 955, 4310, 1362, 4312, 237, 1362, 16, 237, 6, 3998, 4694, 1883, 5159, 3225, 9918, 8899, 1883, 6096, 2009, 982, 630, 8910, 2342, 146,, 8517, 4435, 3170, 8155, 630, 3301, 6602, 2189, 584, 5836, 630, 3301, 8911, 13, 1451, 8381, 1069, 13, 8364, 630, 13, 8393, 4748, 4829, 7263, 7108, 2198, 687, 2197, 4847, 12039, 12021, 12038, 12018, 12061, 12062, 4851, 5833, 9987, 3713, 6244, 4839, 5819, 14644, 13726, 13723, 4840, 13746, 13745, 1550, 7066, 2529, 13743, 8394, 14643, 12393, 7294, 2141, 3169, 3713, 7186, 1362, 4836, 2405, 4841, 4848, 16, 1556, 2997, 16, 4737, 1556, 2997, 16, 1556, 4809, 16, 4947, 5894, 2215, 5897,, 6148, 16, 3998, 1883, 770, 3718, 8919, 1883, 2009, 13, 630, 14024, 2342, 146,, 3209, 1070,, 14358, 4435, 3170, 3209, 8869, 12589, 630, 13, 584, 630, 2537, 13, 1451, 1069, 13755,, 13, 1451,, 13788, 630, 13,, 13791, 4748, 4829, 7263, 7108, 8721, 9442, 14365, 12922, 2198, 687, 2197, 4847, 9422, 871, 9431, 9441, 9414, 3713, 13762, 13826, 4851, 5302, 9399, 3713, 13760, 13825, 4839, 2141, 9398, 9838, 13761, 13824, 4840, 9465, 9406, 9838, 13764, 13827, 1550, 4864, 16, 10002, 10000, 16, 2141, 6245, 3169, 3713, 7186, 1362, 6271, 9855, 2535, 277, 4836, 2405, 4841, 4848, 9421, 9458, 9468, 2406, 1099, 16, 18, 1556, 16,,,,,, 4947, 2215, 16, 4005, 6258, 1929, 4024, 6553, 6083, 5951, 6258, 9128, 166, 4772, 6160, 9879, 2933, 6508, 6126, 14719, 14558, 6556, 3539, 2761, 6208, 3222, 1926, 3011, 2, 603, 3222, 152, 166, 6282,, 2, 2753, 1197, 3171, 1230, 603, 4024, 9556, 9880, 10088, 5954, 7185, 9748, 339, 6160, 6553, 6208, 9127, 4005, 9901, 6576, 9883, 2933, 9665, 6002, 6281, 37, 9901, 182, 3223, 1824, 2, 3223, 345, 152, 382, 6305, 1390, 1230, 345, 382, 3180, 2, 2753, 4237, 3539, 603, 166, 4176, 82, 166, 2, 82, 4128, 382, 2, 2349, 4237, 345, 382, 2750, 82, 166, 382, 82, 2750, 382, 166, 6354, 4302, 2, 603, 4302, 2327, 2, 345, 2933, 2761, 152, 2753, 166, 382, 4183, 71, 6355, 6283, 1230, 152, 1390, 1197, 71, 6321, 4131, 71, 166, 2, 81, 3222, 71, 2761,, 4146, 382, 2, 3223, 81, 71, 2933, 2, 1929, 166,,, 339, 1929,,, 2, 339,,,,, 166, 2,,,,,,,,,,,,,,,,,,,,,,,,, 12523, 8158, 9326, 8411, 14536, 12941, 14522, 5208, 8294, 6320, 9266, 9267, 8186, 8765, 1520, 5838, 10053, 2761, 4968, 6625, 2753, 5892, 13519, 12420, 3011, 8416, 14545, 12413, 1271, 516, 6326, 2, 516, 166, 8692, 13878, 14387, 4968, 8707, 13879, 6625, 5208, 1520, 339, 14715, 188, 1674, 9329, 7221, 6560, 2753, 6577, 166, 6328, 345, 603, 382, 1824, 8415, 14547, 5184, 13087, 12221, 2753, 5892, 345, 516, 188, 166, 6325, 2, 1520, 8501, 12943, 13352, 14523, 14557, 12536, 8185, 9326, 8411, 13167, 12214, 1520, 5838, 8186, 8765, 9267, 6320, 9266, 9833, 2488, 12587, 12778, 6577, 9675, 2488, 71, 2761, 6630, 720, 4487, 8588, 7221, 1133, 462,, 1457, 8570, 2, 4274,, 3695, 9327, 7221, 516, 382, 6577, 6560, 2753, 6322, 1271, 603, 382, 71, 8726, 13880, 9676, 9773, 6459, 9676, 8762, 9494, 6459, 9773, 9494, 8862, 1520, 2488, 2, 382, 4487, 9905, 6577, 4488, 2, 144, 4488, 1457, 9805, 4274, 2, 339, 3671, 2, 1133, 339, 3671,,, 2, 1133, 339, 3671, 2, 339, 6215, 2, 339, 6215, 2, 339,,,,,,, 1929, 5907, 166, 5184, 1929, 5907, 166, 5184,, 2, 981, 166, 2, 981, 1929, 166, 2, 8632, 12501,, 13694, 14320, 4032, 13121, 8654, 12782, 4778, 12473, 12456, 8852, 9204, 12481, 9794, 14428,, 8832, 2828, 9811, 14517, 4032, 9595, 9944, 5959, 9423, 9742, 339, 9908, 2738, 18, 4180,, 603, 2, 2090, 2485, 18, 2738, 6316,, 2, 514, 2090, 2485, 4264, 18,, 6616, 9865, 9909, 9861, 339, 9875, 10027, 6485, 6489, 3328, 9862, 14568, 14569, 9813, 9381, 13754,, 10094, 2090, 9380, 13790,, 10094, 9582, 2485, 77, 6272, 2, 1431,,,,,, 9730, 14359,, 14516, 9743, 14423, 9729, 14337,, 9914, 9912, 9812, 6496, 5285, 4049, 339,,,, 6467, 2,,, , 4049, 339,,,, 380, 2,,,, 339, 2,,,, 8631, 12492,, 13695, 4777, 13119, 5931, 12477, 8970, 12472, 8642, 12649,, 9811, 8830, 14208, 4777, 7223, 5924, 9435, 3309, 6042, 4134, 18, 6435, 3546, 9579, 6563, 925, 1256, 6275, 9647, 2928, 6278, 9580, 7284, 275, 9531, 9379, 13780,, 13903, 6436, 9382, 13823,, 14220, 9461, 6277, 1230, 6436, 7189, 2, 1431,,,,, 3309, 14, 6080, 3309,, 6462, 14,, 6080, 3309,, 6462, 14,,, 2,,, 6463, 14, 2, 6463, 3992, 4124, 4032, 9940, 4775, 6081, 3996, 4124, 6130, 4778, 9207, 9942, 2469, 1520, 4017, 4145, 10034, 9953, 9177, 9168, 1520, 6447, 5971, 5997, 6024, 5960, 9432, 9749, 6492, 4968, 5979, 6022, 9129, 5955, 4018, 9668, 6029, 6302, 6509, 6012, 4172, 4018, 9270, 9259, 4129, 18, 4181, 3546, 603, 6362, 4186, 2217, 6608, 2738, 4849, 4143, 6295, 516, 5246, 6297, 2756, 18, 2828, 2756, 6306, 382, 6318, 649, 6301, 1433, 4166, 1269, 188, 6286, 2090, 6260, 2694, 82, 603, 3547, 2699, 2349, 6319, 649, 3179, 6296, 6294, 516, 6298, 4133, 10004, 6261, 4127, 82, 6315, 382, 2327, 4213, 4318, 2217, 2469, 6279, 188, 6287, 4167, 2534, 5246, 6605, 1520, 2488, 2090, 382, 1768, 4318, 2705, 2488, 4844, 4749, 6491, 9596, 14607, 13428, 649, 1520, 6491, 9444, 8701, 12890, 12657, 9596, 2142, 4187, 6629, 720, 6284, 4329, 4132, 71, 6324, 4168, 5998, 12894, 12659, 9430, 8655, 9763, 6285, 6329, 7106, 7089, 5998, 9763, 9445, 8712, 4329, 6460, 2748, 2,, 4271, 2, 2359,,, 4283, 2, 339,,,,,,,,, 2143, 649, 339, 2143, 649, 2,, 12502, 8142, 13551, 12009, 13005, 14576, 4775, 9429, 13597, 11619, 12662, 2469, 14429, 8533, 14652, 5243, 8729, 14369, 8154, 12809, 13493, 13312, 8870, 13772, 8372, 14709, 603, 382, 13580, 13643, 9995, 3547, 8608, 14496, 9333, 13850, 14664, 13938, 1390, 603, 6030, 4172, 339, 2143, 4775, 2469, 10087, 10054, 4149, 2, 2090, 382, 182,, 4186, 2217, 2469, 82, 603, 649, 2699, 82, 1768, 649, 2349, 3179, 2, 382, 82, 2349, 4149, 2, 2694, 82, 2, 3547, 2469, 2349, 382, 649, 82, 3179, 603, 472, 2327, 82, 2217, 2, 5300,, 1231,, 2143, 649,, 5896, 9547, 649, 339, 8615, 2143, 5896, 649, 2,,, 4871,, 649, 339, 3670,,, 2, 5905,,, 339, 3670,,, 2, 6214,,, 339, 2,,, 3992, 4124, 4032, 9940, 4775, 6081, 3996, 4124, 6130, 4778, 9207, 9942, 2469, 1520, 4017, 4145, 10034, 9953, 9177, 9168, 1520, 6447, 5971, 5997, 6024, 5960, 9432, 9749, 6492, 4968, 5979, 6022, 9129, 5955, 4018, 9668, 6029, 6302, 6509, 6012, 4172, 4018, 9270, 9259, 4129, 18, 4181, 3546, 603, 6362, 4186, 2217, 6608, 2738, 4849, 4143, 6295, 516, 5246, 6297, 2756, 18, 2828, 2756, 6306, 382, 6318, 649, 6301, 1433, 4166, 1269, 188, 6286, 2090, 6260, 2694, 82, 603, 3547, 2699, 2349, 6319, 649, 3179, 6296, 6294, 516, 6298, 4133, 10004, 6261, 4127, 82, 6315, 382, 2327, 4213, 4318, 2217, 2469, 6279, 188, 6287, 4167, 2534, 5246, 6605, 1520, 2488, 2090, 382, 1768, 4318, 2705, 2488, 4844,, 8819, 12891, 12663, 649, 1520, 2488, 9444, 4749, 12889, 12656, 8819, 2142, 4187, 6629, 720, 6284, 4329, 4132, 71, 6324, 4168, 9446, 7106, 7089, 9430, 8652, 9762, 6285, 6329, 9466, 9446, 9762, 9445, 8670, 4329, 6460, 2, 4271, , 4283, 339, 2,,,,,,,, 2143, 649, 339, 2143, 649, 2,, 5914, 4432,, 4868, 1137,, 9218, 1553,, 1137, 6376, 733,, 6371, 984,, 154, 9795, 4916,, 9097, 4792,, 7298, 1114,, 4889, 97,, 6376, 733,, 2734, 9535, 1114,, 6375, 97,, 2, 1553, 984, 4456, 37,, 3224, 6185, 2, 97,, 6439,,,, 1114,, 5301,,,, 10001, 984,, 4889, 97,, 4868, 1137,,,, 154, 3720,,, 6371, 984,, 6375, 97,, 1137, 154, 2, 733,, 6540,,, 984, 6613, 2,, 154, 1807, 4953,,, 4770, 4493,, 3720, 154,, 9799, 3555,, 7153, 484,, 3720, 154,, 4493, 4770, 154, 2,,,, 4278, 2,, 3555, 2, 4278, 3555, 484, 154, 4456, 37,, 6613, 2,, 484, 37, 4456, 154, 2,,,,,,,, 4493, 3555, 8894, 484, 8889, 387, 5249, 2,,, 387,, 5249, 8635, 12545,, 4889, 97,, 7225, 5264,, 7154, 956,,, 2, 4808,,,, 956,, 4808, 9619, 97,, 5264, 2, 1927, 9617, 525, 9618, 484, 6185, 3224,, 4953, 1807,, 1553, 37, 8988, 3708,, 9487, 152,, 6384, 4770, 4493,, 8773, 5232,, 4432, 5914,, 1137, 1553, 4916, 4792, 1114, 97, 1553, 984, 37, 1553, 984, 3224, 484, 154, 2, 484, 154,, 2,, 154, 37, 2, 484, 154,, 37,, 154,, 2, 154, 484, 8715, 2, 1927, 956, 2,,,,,,, 1927,,,,,, 484, 6471, 3224, 1807, 1553, 37, 267, 3708, 2,, 484, 5232, 8714, 2, 1137, 733, 984, 154, 1137, 733, 984, 154, 1137, 733, 984, 154, 1137, 733, 984, 154, 733, 2734, 1114, 97, 2, 733, 2734, 1114, 97, 2, 733, 2734, 1114, 97, 2, 733, 2734, 1114, 97, 2, 1114,,,,,,,, 984, 97, 1137, 154, 984, 97, 1137, 154, 984, 97, 1137, 154, 984, 97, 1137, 154, 984, 97, 1137, 154, 984, 97, 1137, 154, 984, 97, 1137, 154, 984, 97, 1137, 154, 2, 733,,,,,,,, 984,,, 154, 1807, 984, 2,, 154, 1807, 984, 2,, 154, 1807, 984, 2,, 154, 1807, 97, 2,,,,,,,,,,,,,,, 154,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 4432, 4695, 1137, 2632, 1553, 4723, 4916, 8541, 4792, 8306, 1114, 7063, 97, 5871, 1553, 984, 37, 4741, 3224, 5873, 6179, 5183, 154, 2821, 5290, 1133, 484, 5183, 154, 2821, 6179, 5183, 2, 5290,,,, 484, 154, 37, 4741, 2, 5910, 484, 37, 4741, 484, 154, 4458, 9682, 484, 6179, 14233, 1133, 11680, 11600, 956, 2998, 7042, 2996, 2, 1927, 9682, 880, 291,, 7042, 1927, 2, 4458,, 956, , 4458, 956, 13975, 8459, 13392, 12238, 11679, 11599, 484, 3224, 5873, 1807, 4736, 1553, 1137, 733, 984, 154, 1137, 5163, 4428, 154, 1137, 5163, 4428, 154, 733, 2734, 1114, 97, 2, 5163, 2734, 8458, 5862, 2, 5163, 2734, 8458, 5862, 2, 1114,,, 5181, 2, 1114, 5181, 2, 984, 97, 1137, 154, 7062, 5871, 2632, 2821, 7062, 5871, 2632, 2821, 984, 97, 1137, 154, 4428, 5862, 1137, 154, 4428, 5862, 1137, 154, 2, 733,,,, 3135,, 733,, 3135, 984, 2,, 154, 1807, 984, 5910, 154, 4736, 984, 5910, 154, 4736,, 984, 291, 4428, 154, 1807, 984, 5181,, 97, 2,,,, 291,,,,,,, 2,,, 154,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,, 5913, 3511, 2474, 238, 13301, 9518, 9857,, 238, 6358, 1795, 4456, 2, 1114, 7298, 13937, 9872, 7153, 154, 9148, 2, 484, 154, 14166, 1807, 7121, 460, 6546, 13917, 3478, 460, 3004, 2264, 1554, 4945,, 121, 2, 154,, 1751,, 5307, 1807, 154, 166, 2942, 460, 121, 1929, 2, 102, 484, 37,, 2, 354, 166, 484, 1181, 121, 13294, 2264, 9627, 121, 3478, 1554, 3004, 121, 2, 154,, 2942, 1751, 154, 2942, 460, 13861, 6358, 1181, 460, 575, 121, 13431, 102, 1181, 575, 2, 655, 9148, 13473, 102, 7279, 13346, 2, 9860, 7154, 2, 12877, 9860, 956, 2, 1554, 121,,, 6043,, 1554,, 2, 4487,, 6472,, 1751,, 6472,, 9876, 4969, 102, 121, 4945, 2, 4956, 2140, 2, 37, 575, 14529, 956, 655, 12923, 1554, 6043,, 2, 4487, 1751, 6472, 2, 7264, 238,,, 633, 1795,, 2, 6546, 14730, 2140, 9769, 9627, 4434, 3511, 2474, 238, 1795, 1114, 121, 7121, 5913, 3478, 8994, 3004, 2264, 1554, 8758, 13347, 121, 2, 154, 13452, 2, 13349, 1751, 2, 5307, 1807, 154, 166, 2942, 460, 8994, 12583, 13285, 6546, 121, 7279, 6546, 14165, 2, 5301, 3720, 9872, 14112, 14109, 154, 2942, 14148, 460, 1181, 575, 7121, 1554, 8758, 6043, 1554, 2, 4487, 6472, 14679, 12666, 9876, 14380, 2, 4808, 9769, 2, 12912, 2140, 4808, 14108, 12584, 14121, 9857, 14322, 633, 6358, 1795, 14485, 5913, 6358, 4434, 3511, 2474, 238,,, 1795, 37, 2, 1114,,,, 484, 154, 37, 2, 484, 154, 2, 1807, 484, 154, 1181, 460, 121, 2264, 3478, 460, 3004, 2264, 1554, 4945,, 121, 2, 154,, 1751,, 5307, 1807, 154, 166, 2942, 460, 121, 1929, 2, 102, 484, 37,, 2, 166, 484, 1181, 121, 2264,, 3478, 1554, 3004, 121, 2, 154,, 2942, 1751, 154, 2942, 460, 2264, 3004, 121, 1554,,,,, 1751, 2, 228,,,,,, 1795, 238, 1181, 460, 575, 121,,,,, 37, 2, 484, 10102, 2, 6623, 6631, 102, 121, 1554, 3004,, 1751, 2, 102, 121, 1181, 575, 37, 6623, 102, 2, 121, 956, 339, 4969, 5312, 102, 2, 956,, 2140,, 956, , 2140, 956, 2, 4956, 2140, 2,, 5312,, 956,, 2,, 575, 1554, 7308, 102, 956, 2140, 4956, 37, 10042, 575, 6554, 121, 2474, 8669, 6554, 4434, 3511, 2474, 4434, 3511, 2474, 238,,, 1795, 37, 2, 1114,,,, 484, 154, 37, 2, 484, 154, 2, 1807, 484, 154, 1181, 460, 121, 2264, 3478, 460, 3004, 2264, 1554, 4945,, 121, 2, 154,, 1751,, 5307, 1807, 154, 166, 2942, 460, 121, 1929, 2, 102, 484, 37,, 2, 166, 484, 1181, 121, 2264,, 3478, 1554, 3004, 121, 2, 154,, 2942, 1751, 154, 2942, 460, 2264, 3004, 121, 1554,,,,, 1751, 2, 228,, ,,,, 1795, 238, 1181, 460, 575, 121,,,,, 37, 2, 484, 10102, 2, 6623, 6631, 102, 121, 1554, 3004,, 1751, 2, 102, 121, 1181, 575, 37, 6623, 102, 2, 121, 956, 339, 4969, 5312, 102, 2, 956,, 2140,, 956,, 2140, 956, 2, 4956, 2140, 2,, 5312,, 956,, 2,, 575, 1554, 7308, 102, 956, 2140, 4956, 37, 10042, 575, 6554, 121, 2474, 8669, 6554, 4434, 3511, 2474, 4434, 3511, 2474, 238,,, 1795,, 37, 1114, 2, 228,,, 484, 154, 37, 2, 1181, 460, 575, 121,,, 2264,, 2, 3478, 460, 2264, 4945, 1554, 121, 2, 154,, 2942, 166, 1751, 2, 460, 121, 166, 2942, 3478, 1181, 6095, 575, 121, 13882, 1929, 2, 102, 154, 484, 2, 37, 460, 1181, 121, 575,,,, 7217,, 9481, 2264, 2, 9542, 3478, 9026, 6095, 7148, 1554, 4945, 3004, 121, 2, 154, 13517, 2, 13528, 1751, 2, 2942, 166, 460, 9026, 121, 1807, 5307, 1795, 238, 228, 1181, 575, 166, 460, 121, 1554, 3004, 9481, 121, 2, 1751,, 37, 102, 2,, 4969,, 7308, 121, 575, 13490, 2, 956,, 2140,, 956, 121, 2, 1751,, 238, 7264,, 8435, 633, 2, 2140, 6043, 6095, 1554, 13007, 14027, 37, 4487, 2,, 13945, 2, 956, 13936, 2, 956, 339, 7220,, 13422, 4969, 6363, 5312, 37, 575, 7217, 4969, 6363, 339, 7220, 2, 956, 9542, 2140, 2, 13918, 956, 2, 6406, 2140, 2, 956, 6406, 6095, 1554, 7148, 4458, 6363, 7148, 7220, 6406, 4458, 2474, 11585, 1554, 4956, 6406, 6363, 3511, 1795, 460, 121, 238, 8435, 4693, 4722, 7057, 5859, 7063, 5183, 8505, 2314, 7058, 11779, 8320, 2314, 2821, 12425, 5173, 8320, 12236, 12356, 5859, 7057, 8505, 12360, 12417, 12430, 2314, 12418, 8582, 2998,, 4722, 11565, 12346, 4693, 8130, 3296, 7014, 8131, 11806, 11518, 7074, 3142, 9378, 8636, 12447, 12856, 6113, 7076, 8647, 12449, 12440, 12442, 8644, 8633, 5922, 3302, 7074, 8130, 7313, 14844, 15027, 14926, 14928, 14841, 10110, 7316, 14852, 14895, 14896, 14894, 14800, 14795, 14803, 14802, 10129, 7317, 10141, 10189, 15082, 15114, 14840, 7317, 15154, 14796, 14806, 15081, 14872, 14969, 15004, 5139, 15128, 14940, 15060, 10183, 7316, 15087, 15088, 15063, 10183, 15022, 15065, 15006, 8132, 15134, 15052, 14968, 10157, 15148, 14972, 15205, 10157, 15067, 10158, 15085, 10159, 10158, 14819, 7322, 14821, 14927, 7320, 1678, 15061, 14985, 14984, 14980, 14981, 10174, 10125, 15119, 14938, 15204, 14971, 6674, 10162, 15056, 10174, 15120, 15203, 15068, 7322, 6674, 15055, 10169, 10119, 10200, 10134, 15054, 10169, 7320, 10200, 15053, 10180, 7315, 14885, 10234, 10143, 14937, 10197, 10180, 7315, 10234, 10143, 10197, 15020, 7315, 15145, 14936, 15058, 15021, 14825, 14824, 15121, 14939, 15219, 15049, 14991, 11602, 15109, 15201, 15066, 14899, 15044, 14990, 11521, 15062, 14898, 15043, 10167, 10114, 15115, 14931, 15059, 10133, 15047, 10167, 15116, 10133, 15048, 14992, 11641, 15110, 15064, 15002, 11531, 15156, 14920, 15100, 14957, 15046, 15017, 10120, 15158, 10146, 15186, 10154, 7318, 14998, 8134, 15151, 14902, 15089, 14956, 15045, 15019, 10116, 15152, 10145, 15185, 10152, 7319, 15003, 11532, 15157, 14922, 15051, 11773, 15104, 12345, 10170, 10121, 15122, 14934, 10217, 14914, 10195, 10131, 10170, 15123, 10217, 14915, 7318, 10195, 10168, 10117, 15117, 14932, 10196, 10130, 10168, 15118, 7319, 10196, 10171, 7314, 14837, 10231, 10142, 14935, 10171, 7314, 10231, 10142, 15015, 7314, 15146, 14933, 15111, 5139, 15202, 14906, 15101, 2944, 15224, 10689, 14983, 10267, 6661, 15033, 10148, 15209, 15169, 14986, 15218, 6648, 6661, 12255, 12835, 15206, 15071, 6674, 15231, 15093, 15225, 5323, 10193, 14982, 5323, 10193, 15098, 14913, 14916, 15009, 8167, 14970, 15161, 8132, 14945, 15091, 11645, 11528, 14860, 14886, 14863, 14958, 11877, 14891, 14855, 14853, 14881, 14812, 15176, 15076, 15057, 10250, 14857, 14805, 14848, 10166, 15034, 15162, 14851, 10166, 15035, 14808, 14892, 15233, 14577, 15212, 15007, 14810, 14862, 15000, 14994, 10266, 15039, 15040, 15008, 11637, 15099, 14943, 11642, 14849, 15141, 15139, 15130, 10235, 10176, 10175, 10264, 10161,, 10240, 15132, 14847, 15140, 10176, 10175, 10161, 10240, 15133, 11651, 14811, 14867, 14856, 15126, 14946, 15112, 11547, 10265, 10153, 15173, 14947, 13985, 15153, 10244, 15135, 10139, 10269, 6668, 15177, 10245, 14942, 10260, 10151, 10224, 10112, 15228, 14948, 3239, 6645, 15210, 10261, 6667, 10233, 6653, 15230, 10246, 3239, 6670, 15214, 10260, 10151, 10223, 10111, 10265, 10153, 3239, 6645, 15211, 10261, 6667, 10232, 6651, 10269, 6668, 3239, 6670, 15213, 15127, 14949, 15113, 11552, 15229, 14959, 15131, 12143, 15232, 14918, 15178, 14900, 11802, 15042, 15189, 15188, 15191, 10253, 15184, 15194, 15192, 15183, 15181, 10253, 15217, 15236, 14903, 10257, 14908, 15239, 14904, 15193, 15179, 10257, 15180, 10138, 14905,, 14901, 12661, 14924, 2502, 3367, 14683, 14691, 14873, 1930, 13833, 15190, 14685, 10275, 14921, 10163, 15195, 14503, 15240, 14917, 14988, 15238, 14688, 10275, 10155, 10163, 15108, 15106, 11434, 15103, 11455, 15237, 15107, 10155, 14684, 15246, 15163, 14129, 15221, 14909, 14975, 15096, 15095, 11088, 15223, 12424, 14923, 12226, 14911, 14842, 14816, 10124, 14854, 14813, 15032, 15160, 10150, 14843, 14817, 15025, 14884, 14832, 10160, 15215, 14845, 14807, 14823, 10177, 14850, 14879, 15125, 10263, 10241, 14846, 10178, 14880, 15124, 15216, 10242, 15023, 14809, 14822, 15094, 10262, 10263, 10214, 15222, 10238, 10212, 10190, 15030, 10140, 14930, 10268, 15170, 10182, 10238, 10212, 10190, 10140, 10268, 10182, 15207, 15029, 15084, 14929, 15226, 15026, 14859, 14818, 10127, 14865, 14831, 14944, 14864, 14838, 14951, 14963, 14964, 6644, 14869, 10181, 14861, 14868, 14870, 15159, 14815, 14871, 15165, 15197, 15199, 15198, 10258, 14907, 10226, 10115, 14912, 15174, 14974, 14919, 15187, 14977, 15074, 15241, 10164, 4498, 14989, 14797, 10126, 14830, 14950, 14952, 10147, 10179, 14833, 15164, 15167, 10247, 10225, 10113, 15175, 14976, 14874, 14973, 4497, 14979, 10191, 10144, 15070, 14953, 14954, 15080, 14965, 15079, 14961, 10122, 14882, 6644, 10156, 10122, 6644, 10156, 15245, 14987, 14960, 10211, 4975, 6660, 6650, 10218, 10219, 10251, 10202, 10273, 10220, 10254, 10205, 4498, 6679,, 10209, 10211, 6647, 6660, 10218, 10201, 10251, 10273, 10272, 10204, 10254, 10221, 6678, 6679, 10185, 14888, 15037, 10186, 14814, 15041, 10188, 6654, 10206, 10207, 4498, 6657, 6676, 10259, 10185, 14876, 10186, 14887, 10188, 6654, 10206, 10207, 4498, 6657, 6676, 10259, 14878, 14827, 14858, 14839, 10187, 10194, 10255, 10208, 6679, 10222, 10210, 10213, 6659, 6649, 4497, 6673,, 10199, 10210, 6646, 6659, 10215, 6672, 6673, 10184, 14883, 15036, 4497, 6655, 6671, 10248, 10184, 14875, 4497, 6655, 6671, 10248, 14877, 14826, 10198, 6673, 10216, 6669, 15142, 14941, 6669, 6652, 6675, 15172, 14955, 6675, 6656, 10192, 10128, 10118, 10192, 4345, 4975, 10203, 10137, 10135, 10203, 4348, 6658, 10128, 10118, 4345, 4975, 10137, 10135, 4348, 6658, 15083, 15129, 4345, 15102, 15171, 4348, 10123, 15024, 10136, 15069, 10123, 10136, 10575, 2216, 15235, 15227, 15168, 15220, 15208, 12361, 13595, 7329, 12343, 14798, 14829, 14820, 14834, 10132, 14893, 10109, 10252, 15092, 14799, 14828, 15031, 15028, 14890, 14866, 14801, 14835, 14836, 14804, 15073, 4344, 10243, 6666, 4976, 15147, 10149, 4496, 15200, 4344, 15050, 14966, 4346, 10270, 4347, 6663, 4976, 4347, 15143, 15155, 15136, 7323, 4346, 10274, 6677, 15077, 3027, 10228, 10236, 10230,, 4496, 6664, 4343, 4344, 3027, 10249, 4342, 15166, 15182, 10228, 10230, 4496, 6664, 4343, 4344, 3027, 10249, 4342, 15105, 15234, 6662, 4976, 10276, 15137, 15242, 7323, 10271, 10173, 10239, 10172, 10229, 15149, 7321, 4344, 3027, 15150, 10173, 10172, 10229, 7321, 4344, 3027, 6665, 15090, 14962, 15097, 6665, 15078, 15196, 14967, 14978, 14910, 15244, 15243, 10237, 10227, 10256, 10237, 10227, 15138, 15075, 15072, 12521, 10108, 7313, 7317, 10110, 14897, 10109, 14889, 10165, 10189, 15144, 15005, 14999, 15038, 15086, 15014, 15016, 15001, 14993, 14996, 15013, 14995, 15012, 15011, 14997, 15010, 15018, 10165, 15247, 15248, 10108, 15249, 7074, 14925, 9280, 4982, 4504, 1351, 2489 ], nrs := [ 11736,, 248,, 332,, 315,, 1327,, 317,, 212,, 247,, 3650,, 255,, 280,, 198, , 4492,, 193,, 146,, 243,, 12554,, 124,, 80,, 94,, 480,, 82,, 101,, 103,, 1369,, 110,, 76,, 140,, 2017,, 97,, 101,, 74,, 3195,, 31,, 32,, 22,, 424,, 17,, 10,, 19,, 361,, 16,, 20,, 19,, 95,, 21,, 12,, 15,, 29261,,, 2,, 18, 2, ,, 130, 2, 428,, 24,, 79,, 25,, 234,, 15,,,, 2,, 74,, 3,, 7, 2, 96, 5,, 2, 6, 5, 6, 4, 6,,,, 6,,, 6,, 12,, 11,, 29,, 8,,,,,, 80, 7,, 4, 5, 4, 4, 4,, 2, 4,,, 4,, 8,, 20,, 9,, 17,, 137,, 6,, 4164,,,,, 8, 2,, 4,,,,,, 5,,,,,,,,, ,,, 2,,,, 2,,,, 2,,,,, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,, , 2,,,, 2,,,,,,,,, 2,,,, 2,,,,,,, 2,,,,, 2,,, 2,, 2,,,,,,,,, 2,, 2,,,,,,,,, ,,,,,, 2,,,,,,,,,,,,,, 2, 2,,,,, 2,,,,,,,,,,,,,,, 2,,,,,,,,,,,,,,,,,,,,,,,, , 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,, 2,,,,,,,, 2,,,,,,, 2,,,,,,,,,,,, , 2,,,,,,,,,,, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,, 2,,,,,,,,,,,,,,,,,,,,, ,,,,,, 2,, 2,, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,, 2,,,,,, ,, 2,, 2,,,,,,,,,,, 2,,,, 2,,,,,,,,,,,, 2,,,,,,,,,,,,,,, 2,,,,,,,,,,,,,,,,, ,,, 2, 2, 2,,,,, 2,,,,,,,,,, 2, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,,, 2,,,,,,,,,,, 2,,, 2, ,,,,,,,,, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2, 2,,,,, ,,,,, 2,,, 2, 2,,, 2,,,,,,,,,,,,, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,, 2,,,,,,, 2,,,,,,,,,,,,, 3, 3,,,,,, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,, 3, , 3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,, 2,,,,,, 2,, 2,,,,, ,,,,, 2,,, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2, 2,, 2,, 2,,,, 2,, 2,, 2,, 4, 2, 2, 2,,,,, 2,,,,,,, 2,, 4,, 4,, 2, 2, 2, 2, 2, 2,, 2,, 2,, 2, , 2,,, 2, 2,,,,,, 2, 2, 2,,,, 4, 2, 2, 2, 2,, 2,, 2, 2, 2,, 2,, 2, 4, 2, 2, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,,,,,,,,,,,,,,,,,,, 2,, 2,,,,, 2,, 2,, 2,,,, 2,,, 2,,, 2,, 2,,,, 2, ,, 2,,, 2,,,, 2,,,,, 2,,, 2,,, 2,,, 2,, 2,,, 2, 2, 2,,,,,, 2, 2,,,, 2, 2, 2,,, 2,,,, 2,,,,,, 2,,, 2,,,,,,, 2,,, 2,,, 4, 2, 4, 2,,,,,,,,,, 2,,,, 2, 2, ,,, 2,,,,,, 2,,,,, 2,, 2,,,,,, 4,, 2,,, 2, 2, 2,,, 4, 2,, 2,,,, 2,,, 2, 2,, , 4, 2,, 4,, 2,,, 2, 2,, 2,, 4, 2,, 2,, 2, 2,, 2,,,, 2,, 2, 4, 2, 4,, 2,, 2, 2, 2,, 4, 2,, 2,, 2,, 2,, 2,,, 2,, 2,,,, 2,,, 2,,,, 2,,, 2,, 4, 2, 4, 2, , 2, 2,,,, 2,, 2,,, 2,, 2,, 4,, 2,, 2,, 2,,, 4,, 2,,, 2, 2, 2,,, 4,,,,,, 2, ,,, 2,,, 4, 2,, 2,, 2,,, 2,,,,, 4, 2,,,, 2,,, 2,,,,,, 2, 2, 2, 4,, 2,, 2, 2, 2,, 4,,,,,,, 2,,, 2, 2,,,,,,,, 2,,, 2,,, 2,,,,,,,,, 2,, 8, 4,, 8, 4,,,,, ,,,,, 2,,,,,,,,,,, 2, 2,,, 2,,,, 2,, 2,,, 2, 2,, 2,,, 2, 2,,,, 4,, 2, 2, 2, 2, 4, 5, 4, 2,,,,, 2, 2,,,,,,,,,, 2,,,, 2,,,,, 2,, 2,,,,,, 4,, 2,, 4,, 2,, 2, 2, 2,, 2, 2, 2,, 4, 2, 4,,,, 2,, 2,,,,, 2,,,,,,,,,,,,, 2,, 8,,, 2, 4,, 2, 2, 2,,,,,, 2,,,,, 4,, 2,, 8,, 4, 2,,,,,,,,,,,,,, 2,, 4, 2, 2, 2,, 4, 2,,,,,,,,, 2,,,,,,,,,,, 2, 9, 2, 4,,,,,, 2,, 2,,,, 2,,,,,,,, 2,,, 2,,,,, ,,,,,,,,,,,,,,,,,,,,, 2,,, 2,, 2,,,,,,,, 2,,, 2,,,,, 2,,,,,,,,,, 16,,,, 2,, ,, 2,, 2,,,, 2,,,, 2,, 2,, 4, 4,, 4, 4,,, 2,,,,,,, 2,,,,,,,,,, 2,, 2,, 2,, 8, 8,,, 3,,,,, 2,,,,,, 2,,, 4, 2, 2, 2, 2, 2, 4, 2,,,,,,,,,,, 2,,,, 2, 16,, , 2,,,, 2,, 3,, 2,,,, 2,, 2, 2,, 2,, 2,, 2,,,,,, 2,,,,,,,,, 2,,,,,,,, 2,,, 2,,,,,,, 2,, 2,, 2,, 2,,,,,,, 2,,,,, 2,,,,,,,, 2, 2,, 2,, 2,, 2,,,,, 2,,,, 8,,,,,,,,, 2,,,,,,,,,, 2, 2,, 2,, 2,, 2,,,,,,,,,,,,,,,,,,, 2,, 8,,, 3,,,,,, ,,, 2, 2, 2, 2, 2,,,,,,,,, 8,,,,,,,, 2,,,,,,,,,, 2,,,,,,,,,,,,,,,,, 2,,,,, , 2,,, 2,,, 2,, 2,,,,,,,,,, 2,,,,, 2,,, 2,,,,,,,,,,,, 2,,, 2,,, 2,,,,,,,,,, ,,,,,,,,,, 2,, 2,, 2,,,,, 16,,, 2,, 2,, 4,, 2,, 2,,,,, 2,,,, 2,, 2,,,,, 2,, ,,, 16,,, 2,, 2,, 2,, 2,,, 2,, 2,, 2,, 2,,,,,,,,,, 2,, 2,,, 2,,,,,,,,,, 2, 2,,, 2,,,,,,, 2, 2,,,,, 2,,,,,,,, 2, 2,,,,,, 2,, 2,,,,,,, 2,, 4,, 2,, 2,, 2, 2, 2,, 2,, 2,, 4,, 2, 17, 8, 8,,,,,,,,,,,,,,,,,,,,,, 2,,,,,,,, 2,,, 2,,, ,,, 2,,,,,,,,,,,,,,,, 16,,, 2,,,, 2,, 3,, 2,,,, 2,, 2, 2,, 2,, 2,, 2,,,,, 2,,,, 4, 2, 2, 2,, 4, 2, 2, 2, 2,, 2, 2, 4, 2,, 4, 4, 4, 2, 4,, 8, 8, 4,, 2, 4, 2, 2, 4,, 2, 2, 2, 4, 4,, 4, 4, 2, 2,, 4, 2, 2,,, 2, 8, 4, 2,, 2, 2, 2,, 2,,, 2, 2, 2, 2, 2, 2,,,, 2, 2,, 2, 2,,, 4, 2, 2,, 4, 2,, 2, 2, 4,, 2, 2, 4, 2,, 4, 2, 4, 2, 4, 6, 4, 2, 2,, 4,,, 2, 4, 2, 2,, 2, 2,, 2, 4, 4, 2, 2, 4, 4, 4, 4, 4, 4, 4, 16, 16, 4, 8, 4, 8,, 2,,,,,, 2,, 2, 2, 2,, 2,,, 2, , 4, 4, 4,,, 2,, 2,,,,,,,,, 2, 2,,, 2,, 2,,,, 2, 2,,, 16,,, 2,, 2,,,,,,, 2, 2,,,, 2, 2,,, 4, 4, 4,, 2,,, 2, 2, 2,,,, 2, 2,,,, 2,,, 2,, 2,,, 2,, 2,, , 2,, 2,,, 2,, 2,,, 4,, 2,,,, 2,,, 4,, 2,,,, 2,,, 2,, 2,,, 2,, 2,,, 2,, 2,, , 2,, 2,, 4,, 2,, 2,, 2,,,, 2,, 2,, 2,, 2,, 2,, 2, 8, 8, 4, 2,, 4, 2,, 4, 4, 4, 16, 4, 4, 4, 4, 2, 2, 2,, 4, 2, 2, 2, 2,, 2, 2, 4, 2,, 4, 4, 4, 2, 4, , 8, 8, 4,, 4, 6,, 2, 4, 4,, 4, 2,, 2,, 4, 2,,,, 2, 8, 4, 2,, 2, 2, 2,, 2,, , 2,,, 2, 2, 2,,,, 2,,, 2, 2,,, 4, 2, 2,, 4, 2,, 2, 2, 4,, 2, 2, 4, 2,, 8, 6, 4, 4, 2, 2,, 4,,, 2, 4, 2, 2,, 2, 2,, 2, 2, 2, 4, 2, 4, 4, 4, 4, 4, 4, 4, 16, 16, 4, 8, 4, 8, 4, 2, 2,, 4, 2, 2, 2,, 4, 4, 2, 2,, 8, 2, 4, 2,, 4, , 4,, 4, 2,,,, 2, 2,, 2,, 2, 2,,, 2,,, 2, 4, 2,, 2, 4,, 2,, 2, 4, 2,, 2, 2, , 2, 2, 4, 2, 2, 4, 4, 4, 4, 4, 8, 4, 8, 4,, 2,,,, 2,, 2,, 2,,, 4, 4,,, 2,, ,,,, 2,, 2,, 2,,, 2, 2, 2,, 8, 4,, 2,, 2, 2,,, 2,, 2,,, 2, 2,, 2,,,,,, 2, 2, 2,, 2,,,, 2,, 2,, 2,, 2, 2,, 2,,,, 2,, 2,, 2,, 2, 4,, 2, 4,, 2, 4, 12, 4, 4, 2, 2,, 4, 2, 2, 2,, 4, 4, 2, 2,, 8, 2, 4, 2,, 4, 2, 4, 2,, 4, 2,, 2, , 2, 2,, 2,, 2, 2, 2,, 2,,, 2, 4, 2,, 2, 4,, 2,, 2, 4, 2,, 2, 2,, 2, 2, 2, 4, 2, 4, 2, 4, 4, 4, 4, 8, 4, 8, 4, 4, 4, 2, 2,, 8, 4, 2, 4,, 4, 8, 2, 2, 2,, 4, 4, 2, 2,, 8, 8, 4,, 4, 16, 4,, 8, 8, 8,, 12, 8,, 2, 2, 2, 2, 2, 2,, , 2, 4, 4, 2, 2,, 2, 2, 4, 2, 2, 2, 4, 2,, 2, 2, 4, 2, 2, 4, 2,, 2, 8, 4, 4, 2, 4, 4, 2, 2, 4, 2,, 2, 4, 4, 2, 2, 4,, 2, 4, 8, 4, 8, 4, 4, 4, 4, 4, 4, 16, 16, 4, 8, 4, 8, 4, 4, 4, 4, 8, 4, 8, 4,, 2,, 2,,,, 4, 2,,,,, 2, 2, 2,, 2, 2,,, 2,,,, 2,, 2,, 2, 4,, 4, 2,, 4, 2,, 2, 2,,, 2,, 2, 2,, 2,,,,,, 2,, 2,, 2,,, 2,, 2, 2,, 2,, 2,,,, 2,, 2, 2, 4, 2,,, 2,, 2, 2, 2, 4,, 2,, 2, , 2, 8, 4, 2,,, 2,, 2, 4, 2,, 4, 4, 2, 2,, 8, 4, 2, 4,, 4, 8, 2, 2, 2,, 4, 4, 2, 2,, 8, 8, 4,, 4, 16, 4,, 8, 8, 8,, 12, 8,, 2, 2, 2, 2, 2, 2,,, 2, 4, 4, 2, 2,, 2, 2, 4, 2, 2, 2, 4, 2,, 2, 2, 4, 2, 2, 4, 2,, 2, 8, 2, 4, 4, 4, 4, 2, 2, 4, 2,, 2, 4, 4, 2, 2, 4,, 2, 4, 8, 4, 8, 4, 4, 4, 4, 4, 4, 16, 16, 4, 8, 4, 8, 4, 4, 4, 4, 8, 4, 8, 4,, 2,, 2,,,, 4, 2,,,,, 2, 2, 2,, 2, 2,,, 2,,,, 2,, 2,, 2, 4,, 4, 2,, 4, 2,, 2, 2,,, 2,, 2, 2,,,,,,,, 2,,,,, 2,, ,, 2,,, 2,,,, 2,,, 2, 2, 4, 2,,, 2,, 2, 2, 4,, 2,, 2,, 2, 8, 4, 2,,, 2,, 2, 4, 2,, 4, 4,,,, 8, 4,, 2,, 2, 2, 2, 2, 2, 2,, 2, 2, 2, 2,, 4, 2, 4, 4,, 4, 4, 4,, 4, 2, 4, 2,, 4, 4, 4,, 2, 2,,, 2, 2,,, 2,, 2, 2, 2,, 2, 2, 2,,,, 4,, 2,,,, 4,, 2,,,, 2, 2, 2,,,, 2, 2, 2, 2, 2, 2, 2, 4, 4, 2,,, 4, 2,,, 2, , 2, 2, 2, 2, 2,, 4, 2, 4, 4, 4, 4, 16, 4, 4, 4, 4, 12, 4, 4, 2,, 2, 2, 2, 4, 2, 2,, 2, 2, 2, 2, 4, 4,,, 2, 2, 2, 2, 4, 2, 4,, 2, 4, 2, 2, 4, 2,, 4, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2,, 2, 2, 2, 2, 4,, 2, 2, 2, 2, 4, 4,,, 2, 4, 4,, 4, 2, 2, 2, 4, 2, 2, 2, 2, 4,, 4, 4, 4, 2, 2, 8, 2, 2,, 2, 8, 2,, 4, 4, 2, 2, 8, 2, 2, 2, 2, 8, 2, 2, 4, 4,, 2, 4, 4,, 2, 4, 4, 2, 4, 2, 2, 8, 2, 4, 4, 2, 2, 2, 2, 2, 4, 8, 2, 2,, 2, 4, 2, 4, 2, 8, 2,, 4, 2, 2, 4, 32, 4, 4, 4, 4, 4, 4, 4, 4, 32, 16, 16, 16, 16, 32, 2,, 2, 2, 2,, 4,, 2, 2, 2,, 4,, 2, 2, 2,, 4,, 2, 2, 2,, 2, 64,, 2,,,,,,, 2, 2,,,,,, 2, 2, 2, 2, 2,, 2,,,, 2,,, 2, 2, 4,, 2, 2, 2,,, 2, 2,, 2, 4, 4,,, 2,, 2,, 2,,, 2, 4, 2, 2, 2,, 2,,,,,, 2, 2, 2, 2, 2, 4,,, 2,,,,,, 2,,,,,, 2,,,, 2,, 2,,,,, 2,, 2, 4, 4, 2,, 2,,,,,, 2, 8, 4, 2,, 2,, 2, 2,, 2,, 4, 2, 2, 2, 2, 2,,,, 2,, 2,, 2,,, 2, 8, 4,, 2,, 2,,, 4,,,, 2, 4, 6,, 2,, 2,, 2,, 2,, 2,, 2, 16, 4, 2,, 4, 2,, 4, 4, 4, 16, 4, 4, 4,, 2,, 2,, 2,, 2, 4,, 2, 4,, 2, 4, 12, 4,,,, ,, 2,, 2,, 2,,, 2, 2,,,,, 2,,,, 2, 2, 2, 4, 2, 2,, 2, 4, 2, 8, 2, 2,, 2, 2, 2, 4, 4, 4,, 2, 2, 2, 4,, 4, 4, 2, 2, 2,, 2, 2, 4, 4, 2, 2,,, 2,,,,, 2,, ,,, 2, 2, 2, 4, 5,,, 2,,, 16,,,,, 2,,,,, 2, 2, 2, 4,,,, 2,,,,, 2,,,,, 2,,,, , 2,,, 4, 4, 4, 36, 16,,,,, 2,, 2,, 2,,,,,, 2,, 2, 2, 4, 2,, 2, 8,, 4, 2, 2, 2, 2,, 4, 2, 2, 4, 2,,, 2,,,,, 2,,,,, 2, 4,, 2, 2, 4,,, 2,,, 4, 4,,,,,,, ,,,,,, 8, 4, 4,, 2, 4,, 2, 4, 2,,,, 2, 4, 2, 2,,,,, 2, 4, 4,,,,, 2, 2, 2, 2, 2, 2,,, 2,, 2, 2,, 2, 2,, 2, 2, 2, 2, 2, 2,,, 4,, 4, 2,, 2, 2,, 2, 2, 2, 4, 2,,, 2, 4,, 2, 4, 2,, 2,, 2, 2, 4, 2,, 2,, 2, 4,,, 2, 4, 2, 2,, 2, 2, 2,, 2, 4,, 2, 4,, 2,, 2, 4, 2,, 2, 2,, 2, 4, 2,, 2, 4, 2,,,, 2, 8, 2, 2, 4, 2,,,,, 4, 2,, 2,,,,, 4, 2,, 2, 2, 4,, 2, 4, 2,,,, 2,, 2, 2, 2, 2, 2,, , 2, 2, 2, 4, 4, 4, 4, 8, 4, 2, 4, 4, 6, 4, 4, 8, 4, 4, 36, 8, 4, 8, 4, 4, 4, 4, 8, 8, 8,, 2,,,,, 2, 2,,,, 2,, 2,,, 2,, 2,,,, 2,, 2,, 2, 2,,, 2, 2, 2, , 2,,,, 2, 2, 4, 4,,, 2, 2, 2, 2, 4,, 2, 2, 2, 2, 4, 2, 4, 2, 2, 2, 8, 2, 2, 2, 4, 4,, 2, 2, 4, 4, 17, 8, 2,, 4, 4, 4, 2, 2, 2, 4, 2, 2, 4, 2, 2, 2, 4, 10, 4,, 4, 4,, 2, 2,,, 2,, 2, 8, 4, 4,, 4,, 4,, 2,, 2,, 2,, 2,, 2,, 2,, 2,, 2, 4, 4, 20, 36, 4, 2,,,, 2, 4, 2, 2,,,,, 2, 4, 4,,,,, 2, 2, 2, 2, 2, 2,,, 2,, 2, 2,, 2, 2,, 2, 2, 2, 2, 2, 2,,, 4,, 4, 2,, 2, 2,, 2, 2, 2, 4, 2, ,, 2, 4,, 2, 4, 2,, 2,, 2, 2, 4, 2,, 2,, 2, 4,,, 2, 4, 2, 2,, 2, 2, 2,, 2, 4,, 2, 4,, 2,, 2, 4, 2,, 2, 2,, 2, 4, 2,, 2, 4, 2,,,, 2, 8, 2, 4,,,,,, 4,, , 2,,,,, 4, 2,, 2, 2, 4,, 2, 4,,,,, 2,, 2, 2, 2,,,, 2, 2, 2, 12, 4, 16, 4, 4, 4, 8, 4, 4, 36, 8, 4, 8, 4, 4, 4, 4, 8, 8, 8,,,,,,,,,, 4,,,,,,, 4,,,,,,, ,,,,,,,,, 4,,,,,,, 4, 4, 4,,,,, 2, 4, 8, 5, 2,, 2, 4, 8,, 2,, 2, 4,,,,,,,, , 2,,,, 2,, 2,,,,,,, 4, 4, 4, 8, 5, 2,, 2, 8,,,, 4,, 2,, 2,,,,,,,,,,,,,,,, , 2, 4, 4, 8, 4, 4,,,, 4, 9, 2, 4, 4, 4,,,,,,, 4,, 2, 8, 4, 8, 4, 8, 8, 16, 8, 12, 4,, 2,, 2, 4,,,, 8, 4,, 2,,,,,,,,,,,,, 4, 4,,,, 4, 4,, 2,,,, 4, 4,, 2,, 2, 4,,,,,,, 4, 4,,,,,,, 4,,,,,,,, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 2, 32, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 4, 6, 2, 2, 2, 8, 16, 4, 4, 4, 4, 4, 2, 2, 4, 2, 4, 4, 2, 4, 4, 4, 4, 8, 4, 4, 4, 2, 4, 2, 4, 2, 32, 2,,, 2, 2,,, 2, 2,,, 2, 2,,, 2,, 2,,, 2,, 2,,, 2,, 2, ,, 2,, 2,,, 3, 4, 6, 4, 6, 4, 6, 4, 5,,, 2, 2,,, 2, 2,,, 2, 2,,, 2, 2,,, 2, 2,,, 2, 2,,, 2, 2,,, 2, 2, 2, 4, 6, 4, 6, 4, 6, 4, 4, 2,, 2, 2, 2, 2,, 2, 2, 2, 2,, 2, 2, 2, 2,, 2, 2, 2, 2,, 2,, 2,, 2,, 2,, 2,, 2,, 2, 17, 2, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 2,, 2,, 2,, 2,, 2,, 2,, 2,, 2, 4, 4, , 2,, 2,,,, 2,,,, 2,, 2,,, 2, 2, 11, 2,, 4, 4,, 2,, 2, 4,, 2, 2, 4,,,, 2,,, ,,, 2,,, 4, 2,,,,, 2,,, 2, 4, 4, 5, 2, 4,, 2,,,,, 4,, 2,, 2, 4, 2,,, 2,,,,, ,,,,, 2,,, 2,,,,,,,,,, 2, 4, 6, 2, 2, 2, 2, 2,,,, 2, 2,,, 2, 2,,, 2, 2,,, 2, 2,,,,,,,,, 2, 4, 5, 2,, 2,, 2,, 2, 2,, 2, 2, 2, 2,,, 2, 2,,, 2, 2,,, 2,, ,,,, 2,, 2,,,,,,,,, 3,, 2, 9, 2, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 3,, 2,, 2,, 2,, 3, 2, 4, 2, 4, 2, 4, 2, 2, 12,,,,,,,,, 2,,,, , 2,,,,,,,,,,, 2,,,,,,,,,,,, 9, 4, 2, 2,,,,, 4,,, 2, 4,, 4, 2,,,,,, 2,,,,,, ,,,,, 8, 4, 2, 2,,, 4,, 2,,,,,,,, 2,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,,,, 4,,, 7,,,,,,,,,,,,,,,,,,, 2,, 2,, 2, 2,,,,,,, 2,,,, 2,, 2,,,,,,,,,, 8, 4,,, ,,,,,, 3,,,,,,,, 2, 2,,,,,,,,, 2,,,,,,,,,,,,,,,,,, 2,,,,,,,,,,,,,,,, 2,,,,, , 2, 6, 2,,, 2,, 3,,,,,,,, 2, 2,,,,, 4, 2,,,,,,,, 9, 4, 2, 2,,,,, 4,,, 2, 4,, 4, 2,,,, 2, 2,,, 2, 2, 2,,,, 8, 4, 2, 2,,, 4,, 2,,,,,,,,,,, 2,,,, 2,, 2, 5,,,,,,,,,,,,, 4,,, 4, 4, 2,,,, 4, 4, 2,, 3,,, 4, 4, 4,,,,,, 2,,,, 3,, 3,,, 4,,, 4,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,,, 2, 6, 2,,, 2,, 3,,,,,,,, 2, 2,, ,,, 4, 2,,,,,,,, 9, 4, 2, 2,,,,, 4,,, 2, 4,, 4, 2,,,, 2, 2,,, 2, 2, 2,,,, 8, 4, 2, 2,,, 4,, 2,,,,,,,,,,, 2,,,, 2,, 2, 5,,,,,,,,,,,,, 4,,, 4, 4, 2,,, , 4, 4, 2,, 3,,, 4, 4, 4,,,,,, 2,,,, 3,, 3,,, 4,,, 4,,,,,,,,,,,,,,,,,,,, 2, ,,,,,,,,, 2, 3, 2, 3,, 2, 2,,, 2,,,,,,,,,, 3, 2, 4, 2,,,,,, 8, 4,,,,,,,, 2, ,,,,,, 4,,, 4, 2,,,,,,,,,,, 3,,,,,,,,,,,,,, 8, 4,,,,,,,,,,, 3,,,,,,,,,,,,, , 6, 4,,, 2,,,,,,, 3,,,,, 5,,,, 6,,, 2, 2,,,, 2, 2,,,, 2,,, 2,,,,, 2,,,,,,, ,,,,,, 2, 2,,,,, 3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,,,,,,,,, 2,, 2,,,,,,,,,,,,,,, ,,, 2,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,,,,,,, 2,,,,,, 2,,,,,, 2,,,, 2,, 2,,, 2, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,,,,,,,,,,,,,,, 2,, 2,, 2,, ,,,,,,,, 2,, 2,, 2,,,,,,,,,,, 2,,,,,, 2,,,,, 2,,, 2,,,, 2,,, 2,,,,,,,,,,,,, ,,,,,,,,,,,, 2, 2,, 2,,,,, 4, 2,,,,, 2,,,, 3,,, 2,,,,,,,,,,,,,,,,,,,,,,,,,, , 2,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,,,,, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,, 2, , 2,, 2,,,, 2, 2,,, 2, 2,,, 2, 2, 4,, 2, 4, 2,,,, 2, 2,,, 2, 2,,, 2, 2, 4, , 2, 4, 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,, 2,,,,,, 2,,,,, 2,,,,, 2,, 2,,,, 2,,,,, 2,, 2,,,,,,,,,,,,,,,,,,,,,,,,, 2,,,,,,,,, 2,, 2,,,,,,,,,,, 2,, 2, 2,,,,,,,,, 2, ,,, 2,,,, 2, 2,,,, 2, 2, 2,,,,,,, 2, 2,,,,,,,,,,,,,,,,,,, 2, 2, 4,, 2,, 2, , 2,, 2, 2,, 2, 2,, 4, 2,, 2,,, 2, 2,, 2, 4,,,,,,,,, 2,,,, 2, 2,,,,,,, 2,,, , 2, 2,,,,,, 2, 2, 2, 2, 2, 2,, 2, 2, 4, 2,, 2, 2,, 4, 2, 2, 4,,,,,, 2, 2,, ,,, 2, 2,,,, 2, 2, 2, 2,,, 2, 4, 2,,, 2, 4,,,,, 2, 2,,,,, 2, 2,,, 2, 2,,, 2, 2,,, 4,,, 4,,,,,,,,,,,,,,,,,,,,,, 2,,, 2,,,,,,,,,,,,, 2, 2, 4, 2,, 2, 4, , 2,,, 4, 2, 4, 4, 2, 4,,,, 2, 4, 2, 4,,,,,,, 2, 2, 4,, 2,, 4,,,,,, 2, 4,, 2,, 4,,, 4, 2, 2,,,, 2,, 2,,,, 2,, 4,,,,,,, 4, 2,,,, 2,,,,,,,,,, 2,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2,, 2 ] );
-- { dg-do run } with System; procedure SSO4 is type Short_Int is mod 2**16; type Rec1 is record F1 : Short_Int; F2 : Short_Int; end record; for Rec1 use record F1 at 0 range 0 .. 15; F2 at 0 range 16 .. 31; end record; for Rec1'Bit_Order use System.High_Order_First; for Rec1'Scalar_Storage_Order use System.High_Order_First; type Rec2 is record I1 : Integer; R1 : Rec1; end record; for Rec2 use record I1 at 0 range 0 .. 31; R1 at 4 range 0 .. 31; end record; for Rec2'Bit_Order use System.High_Order_First; for Rec2'Scalar_Storage_Order use System.High_Order_First; type Rec3 is record Data : Rec1; end record; for Rec3 use record Data at 0 range 0 .. 31; end record; for Rec3'Bit_Order use System.High_Order_First; for Rec3'Scalar_Storage_Order use System.High_Order_First; procedure Copy (Message : in Rec3) is Local : Rec2; begin Local := (I1 => 1, R1 => Message.Data); if Local.R1 /= Message.Data then raise Program_Error; end if; end; Message : Rec3; begin Message := (Data => (2, 3)); Copy(Message); end;
-- part of FreeTypeAda, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "COPYING" package FT.Errors is pragma Preelaborate; type Error_Code is (Ok, Cannot_Open_Resource, Unknown_File_Format, Invalid_File_Format, Invalid_Version, Lower_Module_Version, Invalid_Argument, Unimplemented_Feature, Invalid_Table, Invalid_Offset, Array_Too_Large, Missing_Module, Missing_Property, Invalid_Glyph_Index, Invalid_Character_Code, Invalid_Glyph_Format, Cannot_Render_Glyph, Invalid_Outline, Invalid_Composite, Too_Many_Hints, Invalid_Pixel_Size, Invalid_Handle, Invalid_Library_Handle, Invalid_Driver_Handle, Invalid_Face_Handle, Invalid_Size_Handle, Invalid_Slot_Handle, Invalid_CharMap_Handle, Invalid_Cache_Handle, Invalid_Stream_Handle, Too_Many_Drivers, Too_Many_Extensions, Out_Of_Memory, Unlisted_Object, Cannot_Open_Stream, Invalid_Stream_Seek, Invalid_Stream_Skip, Invalid_Stream_Read, Invalid_Stream_Operation, Invalid_Frame_Operation, Nested_Frame_Access, Invalid_Frame_Read, Raster_Uninitialized, Raster_Corrupted, Raster_Overflow, Raster_Negative_Height, Too_Many_Caches, Invalid_Opcode, Too_Few_Arguments, Stack_Overflow, Code_Overflow, Bad_Argument, Divide_By_Zero, Invalid_Reference, Debug_OpCode, ENDF_In_Exec_Stream, Nested_DEFS, Invalid_CodeRange, Execution_Too_Long, Too_Many_Function_Defs, Too_Many_Instruction_Defs, Table_Missing, Horiz_Header_Missing, Locations_Missing, Name_Table_Missing, CMap_Table_Missing, Hmtx_Table_Missing, Post_Table_Missing, Invalid_Horiz_Metrics, Invalid_CharMap_Format, Invalid_PPem, Invalid_Vert_Metrics, Could_Not_Find_Context, Invalid_Post_Table_Format, Invalid_Post_Table, DEF_In_Glyf_Bytecode, Missing_Bitmap, Syntax_Error, Stack_Underflow, Ignore, No_Unicode_Glyph_Name, Glyph_Too_Big, Missing_Startfont_Field, Missing_Font_Field, Missing_Size_Field, Missing_Fontboundingbox_Field, Missing_Chars_Field, Missing_Startchar_Field, Missing_Encoding_Field, Missing_Bbx_Field, Bbx_Too_Big, Corrupted_Font_Header, Corrupted_Font_Glyphs); for Error_Code use (Ok => 16#00#, Cannot_Open_Resource => 16#01#, Unknown_File_Format => 16#02#, Invalid_File_Format => 16#03#, Invalid_Version => 16#04#, Lower_Module_Version => 16#05#, Invalid_Argument => 16#06#, Unimplemented_Feature => 16#07#, Invalid_Table => 16#08#, Invalid_Offset => 16#09#, Array_Too_Large => 16#0A#, Missing_Module => 16#0B#, Missing_Property => 16#0C#, Invalid_Glyph_Index => 16#10#, Invalid_Character_Code => 16#11#, Invalid_Glyph_Format => 16#12#, Cannot_Render_Glyph => 16#13#, Invalid_Outline => 16#14#, Invalid_Composite => 16#15#, Too_Many_Hints => 16#16#, Invalid_Pixel_Size => 16#17#, Invalid_Handle => 16#20#, Invalid_Library_Handle => 16#21#, Invalid_Driver_Handle => 16#22#, Invalid_Face_Handle => 16#23#, Invalid_Size_Handle => 16#24#, Invalid_Slot_Handle => 16#25#, Invalid_CharMap_Handle => 16#26#, Invalid_Cache_Handle => 16#27#, Invalid_Stream_Handle => 16#28#, Too_Many_Drivers => 16#30#, Too_Many_Extensions => 16#31#, Out_Of_Memory => 16#40#, Unlisted_Object => 16#41#, Cannot_Open_Stream => 16#51#, Invalid_Stream_Seek => 16#52#, Invalid_Stream_Skip => 16#53#, Invalid_Stream_Read => 16#54#, Invalid_Stream_Operation => 16#55#, Invalid_Frame_Operation => 16#56#, Nested_Frame_Access => 16#57#, Invalid_Frame_Read => 16#58#, Raster_Uninitialized => 16#60#, Raster_Corrupted => 16#61#, Raster_Overflow => 16#62#, Raster_Negative_Height => 16#63#, Too_Many_Caches => 16#70#, Invalid_Opcode => 16#80#, Too_Few_Arguments => 16#81#, Stack_Overflow => 16#82#, Code_Overflow => 16#83#, Bad_Argument => 16#84#, Divide_By_Zero => 16#85#, Invalid_Reference => 16#86#, Debug_OpCode => 16#87#, ENDF_In_Exec_Stream => 16#88#, Nested_DEFS => 16#89#, Invalid_CodeRange => 16#8A#, Execution_Too_Long => 16#8B#, Too_Many_Function_Defs => 16#8C#, Too_Many_Instruction_Defs => 16#8D#, Table_Missing => 16#8E#, Horiz_Header_Missing => 16#8F#, Locations_Missing => 16#90#, Name_Table_Missing => 16#91#, CMap_Table_Missing => 16#92#, Hmtx_Table_Missing => 16#93#, Post_Table_Missing => 16#94#, Invalid_Horiz_Metrics => 16#95#, Invalid_CharMap_Format => 16#96#, Invalid_PPem => 16#97#, Invalid_Vert_Metrics => 16#98#, Could_Not_Find_Context => 16#99#, Invalid_Post_Table_Format => 16#9A#, Invalid_Post_Table => 16#9B#, DEF_In_Glyf_Bytecode => 16#9C#, Missing_Bitmap => 16#9D#, Syntax_Error => 16#A0#, Stack_Underflow => 16#A1#, Ignore => 16#A2#, No_Unicode_Glyph_Name => 16#A3#, Glyph_Too_Big => 16#A4#, Missing_Startfont_Field => 16#B0#, Missing_Font_Field => 16#B1#, Missing_Size_Field => 16#B2#, Missing_Fontboundingbox_Field => 16#B3#, Missing_Chars_Field => 16#B4#, Missing_Startchar_Field => 16#B5#, Missing_Encoding_Field => 16#B6#, Missing_Bbx_Field => 16#B7#, Bbx_Too_Big => 16#B8#, Corrupted_Font_Header => 16#B9#, Corrupted_Font_Glyphs => 16#BA#); for Error_Code'Size use Interfaces.C.int'Size; subtype Generic_Errors is Error_Code range Ok .. Missing_Property; subtype Glyph_Character_Errors is Error_Code range Invalid_Glyph_Index .. Invalid_Pixel_Size; subtype Handle_Errors is Error_Code range Invalid_Handle .. Invalid_Stream_Handle; subtype Driver_Errors is Error_Code range Too_Many_Drivers .. Too_Many_Extensions; subtype Memory_Errors is Error_Code range Out_Of_Memory .. Unlisted_Object; subtype Stream_Errors is Error_Code range Cannot_Open_Stream .. Invalid_Frame_Read; subtype Raster_Errors is Error_Code range Raster_Uninitialized .. Raster_Negative_Height; subtype Cache_Errors is Error_Code range Too_Many_Caches .. Too_Many_Caches; subtype TrueType_And_SFNT_Errors is Error_Code range Invalid_Opcode .. Missing_Bitmap; subtype CFF_CID_And_Type_1_Errors is Error_Code range Syntax_Error .. Glyph_Too_Big; subtype BDF_Errors is Error_Code range Missing_Startfont_Field .. Corrupted_Font_Glyphs; function Description (Code : Error_Code) return String; end FT.Errors;
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2017 onox <denkpadje@gmail.com> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. with System.Multiprocessors.Dispatching_Domains; with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; with Ada.Exceptions; with Orka.Futures; with Orka.Loggers; with Orka.Logging; with Orka.Simulation; with Orka.Simulation_Jobs; package body Orka.Loops is use all type Orka.Logging.Source; use all type Orka.Logging.Severity; use Orka.Logging; package Messages is new Orka.Logging.Messages (Game_Loop); function "+" (Value : Ada.Real_Time.Time_Span) return Duration renames Ada.Real_Time.To_Duration; procedure Free is new Ada.Unchecked_Deallocation (Behaviors.Behavior_Array, Behaviors.Behavior_Array_Access); function "<" (Left, Right : Behaviors.Behavior_Ptr) return Boolean is function Convert is new Ada.Unchecked_Conversion (Source => System.Address, Target => Long_Integer); begin return Convert (Left.all'Address) < Convert (Right.all'Address); end "<"; protected body Handler is procedure Stop is begin Stop_Flag := True; end Stop; procedure Set_Frame_Limit (Value : Time_Span) is begin Limit := Value; end Set_Frame_Limit; function Frame_Limit return Time_Span is (Limit); procedure Enable_Limit (Enable : Boolean) is begin Limit_Flag := Enable; end Enable_Limit; function Limit_Enabled return Boolean is (Limit_Flag); function Should_Stop return Boolean is (Stop_Flag); end Handler; protected body Scene is procedure Add (Object : Behaviors.Behavior_Ptr) is begin Behaviors_Set.Insert (Object); Modified_Flag := True; end Add; procedure Remove (Object : Behaviors.Behavior_Ptr) is begin Behaviors_Set.Delete (Object); Modified_Flag := True; end Remove; procedure Replace_Array (Target : in out Behaviors.Behavior_Array_Access) is pragma Assert (Modified); Index : Positive := 1; Count : constant Positive := Positive (Behaviors_Set.Length); begin Free (Target); Target := new Behaviors.Behavior_Array'(1 .. Count => Behaviors.Null_Behavior); -- Copy the elements from the set to the array -- for faster iteration by the game loop for Element of Behaviors_Set loop Target (Index) := Element; Index := Index + 1; end loop; Modified_Flag := False; end Replace_Array; function Modified return Boolean is (Modified_Flag); procedure Set_Camera (Camera : Cameras.Camera_Ptr) is begin Scene_Camera := Camera; end Set_Camera; function Camera return Cameras.Camera_Ptr is (Scene_Camera); end Scene; package SJ renames Simulation_Jobs; procedure Stop_Loop is begin Handler.Stop; end Stop_Loop; procedure Run_Game_Loop (Fence : not null access SJ.Fences.Buffer_Fence; Render : Simulation.Render_Ptr) is subtype Time is Ada.Real_Time.Time; Previous_Time : Time := Clock; Next_Time : Time := Previous_Time; Lag : Time_Span := Time_Span_Zero; Scene_Array : not null Behaviors.Behavior_Array_Access := Behaviors.Empty_Behavior_Array; Batch_Length : constant := 10; One_Second : constant Time_Span := Seconds (1); Frame_Counter : Natural := 0; Exceeded_Frame_Counter : Natural := 0; Clock_FPS_Start : Time := Clock; Stat_Sum : Time_Span := Time_Span_Zero; Stat_Min : Duration := To_Duration (One_Second); Stat_Max : Duration := To_Duration (-One_Second); begin Scene.Replace_Array (Scene_Array); Messages.Log (Debug, "Simulation tick resolution: " & Trim (Image (+Tick))); -- Based on http://gameprogrammingpatterns.com/game-loop.html loop declare Current_Time : constant Time := Clock; Elapsed : constant Time_Span := Current_Time - Previous_Time; begin Previous_Time := Current_Time; Lag := Lag + Elapsed; exit when Handler.Should_Stop; declare Iterations : constant Natural := Lag / Time_Step; begin Lag := Lag - Iterations * Time_Step; Scene.Camera.Update (To_Duration (Lag)); declare Fixed_Update_Job : constant Jobs.Job_Ptr := Jobs.Parallelize (SJ.Create_Fixed_Update_Job (Scene_Array, Time_Step, Iterations), SJ.Clone_Fixed_Update_Job'Access, Scene_Array'Length, Batch_Length); Finished_Job : constant Jobs.Job_Ptr := SJ.Create_Finished_Job (Scene_Array, Time_Step, Scene.Camera.View_Position, Batch_Length); Render_Scene_Job : constant Jobs.Job_Ptr := SJ.Create_Scene_Render_Job (Render, Scene_Array, Scene.Camera); Render_Start_Job : constant Jobs.Job_Ptr := SJ.Create_Start_Render_Job (Fence); Render_Finish_Job : constant Jobs.Job_Ptr := SJ.Create_Finish_Render_Job (Fence); Handle : Futures.Pointers.Mutable_Pointer; Status : Futures.Status; begin Orka.Jobs.Chain ((Render_Start_Job, Fixed_Update_Job, Finished_Job, Render_Scene_Job, Render_Finish_Job)); Job_Manager.Queue.Enqueue (Render_Start_Job, Handle); declare Frame_Future : constant Orka.Futures.Future_Access := Handle.Get.Value; begin select Frame_Future.Wait_Until_Done (Status); or delay until Current_Time + Maximum_Frame_Time; raise Program_Error with "Maximum frame time of " & Trim (Image (+Maximum_Frame_Time)) & " exceeded"; end select; end; end; end; if Scene.Modified then Scene.Replace_Array (Scene_Array); end if; declare Total_Elapsed : constant Time_Span := Clock - Clock_FPS_Start; Limit_Exceeded : constant Time_Span := Elapsed - Handler.Frame_Limit; begin Frame_Counter := Frame_Counter + 1; if Limit_Exceeded > Time_Span_Zero then Stat_Sum := Stat_Sum + Limit_Exceeded; Stat_Min := Duration'Min (Stat_Min, To_Duration (Limit_Exceeded)); Stat_Max := Duration'Max (Stat_Max, To_Duration (Limit_Exceeded)); Exceeded_Frame_Counter := Exceeded_Frame_Counter + 1; end if; if Total_Elapsed > One_Second then declare Frame_Time : constant Time_Span := Total_Elapsed / Frame_Counter; FPS : constant Integer := Integer (1.0 / To_Duration (Frame_Time)); begin Messages.Log (Debug, Trim (FPS'Image) & " FPS, frame time: " & Trim (Image (+Frame_Time))); end; if Exceeded_Frame_Counter > 0 then declare Stat_Avg : constant Duration := +(Stat_Sum / Exceeded_Frame_Counter); begin Messages.Log (Debug, " deadline missed: " & Trim (Exceeded_Frame_Counter'Image) & " (limit is " & Trim (Image (+Handler.Frame_Limit)) & ")"); Messages.Log (Debug, " avg/min/max: " & Image (Stat_Avg) & Image (Stat_Min) & Image (Stat_Max)); end; end if; Clock_FPS_Start := Clock; Frame_Counter := 0; Exceeded_Frame_Counter := 0; Stat_Sum := Time_Span_Zero; Stat_Min := To_Duration (One_Second); Stat_Max := To_Duration (Time_Span_Zero); end if; end; if Handler.Limit_Enabled then -- Do not sleep if Next_Time fell behind more than one frame -- due to high workload (FPS dropping below limit), otherwise -- the FPS will be exceeded during a subsequent low workload -- until Next_Time has catched up if Next_Time < Current_Time - Handler.Frame_Limit then Next_Time := Current_Time; else Next_Time := Next_Time + Handler.Frame_Limit; delay until Next_Time; end if; end if; end; end loop; Job_Manager.Shutdown; exception when others => Job_Manager.Shutdown; raise; end Run_Game_Loop; procedure Run_Loop (Render : not null access procedure (Scene : not null Behaviors.Behavior_Array_Access; Camera : Cameras.Camera_Ptr)) is Fence : aliased SJ.Fences.Buffer_Fence := SJ.Fences.Create_Buffer_Fence; begin declare -- Create a separate task for the game loop. The current task -- will be used to dequeue and execute GPU jobs. task Simulation; task body Simulation is begin System.Multiprocessors.Dispatching_Domains.Set_CPU (1); Run_Game_Loop (Fence'Unchecked_Access, Render); exception when Error : others => Messages.Log (Loggers.Error, Ada.Exceptions.Exception_Information (Error)); end Simulation; begin System.Multiprocessors.Dispatching_Domains.Set_CPU (1); -- Execute GPU jobs in the current task Job_Manager.Execute_GPU_Jobs; end; end Run_Loop; end Orka.Loops;
----------------------------------------------------------------------- -- awa-events -- AWA Events -- Copyright (C) 2012 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Util.Strings; with Util.Events; with Util.Beans.Objects; with Util.Beans.Basic; with Util.Beans.Objects.Maps; with ADO; -- == Introduction == -- The <b>AWA.Events</b> package defines an event framework for modules to post events -- and have Ada bean methods be invoked when these events are dispatched. Subscription to -- events is done through configuration files. This allows to configure the modules and -- integrate them together easily at configuration time. -- -- === Declaration === -- Modules define the events that they can generate by instantiating the <b>Definition</b> -- package. This is a static definition of the event. Each event is given a unique name. -- -- package Event_New_User is new AWA.Events.Definition ("new-user"); -- -- === Posting an event === -- The module can post an event to inform other modules or the system that a particular -- action occurred. The module creates the event instance of type <b>Module_Event</b> and -- populates that event with useful properties for event receivers. -- -- Event : AWA.Events.Module_Event; -- -- Event.Set_Event_Kind (Event_New_User.Kind); -- Event.Set_Parameter ("email", "harry.potter@hogwarts.org"); -- -- The module will post the event by using the <b>Send_Event</b> operation. -- -- Manager.Send_Event (Event); -- -- === Receiving an event === -- Modules or applications interested by a particular event will configure the event manager -- to dispatch the event to an Ada bean event action. The Ada bean is an object that must -- implement a procedure that matches the prototype: -- -- type Action_Bean is new Util.Beans.Basic.Readonly_Bean ...; -- procedure Action (Bean : in out Action_Bean; Event : in AWA.Events.Module_Event'Class); -- -- The Ada bean method and object are registered as other Ada beans. -- -- The configuration file indicates how to bind the Ada bean action and the event together. -- The action is specified using an EL Method Expression (See Ada EL or JSR 245). -- -- <on-event name="new_user"> -- <action>#{ada_bean.action}</action> -- </on-event> -- -- === Event queues and dispatchers === -- The *AWA.Events* framework posts events on queues and it uses a dispatcher to process them. -- There are two kinds of dispatchers: -- -- * Synchronous dispatcher process the event when it is posted. The task which posts -- the event invokes the Ada bean action. In this dispatching mode, there is no event queue. -- If the action method raises an exception, it will however be blocked. -- -- * Asynchronous dispatcher are executed by dedicated tasks. The event is put in an event -- queue. A dispatcher task processes the event and invokes the action method at a later -- time. -- -- When the event is queued, there are two types of event queues: -- -- * A Fifo memory queue manages the event and dispatches them in FIFO order. -- If the application is stopped, the events present in the Fifo queue are lost. -- -- * A persistent event queue manages the event in a similar way as the FIFO queue but -- saves them in the database. If the application is stopped, events that have not yet -- been processed will be dispatched when the application is started again. -- -- == Data Model == -- @include Queues.hbm.xml -- package AWA.Events is type Queue_Index is new Natural; type Event_Index is new Natural; -- ------------------------------ -- Event kind definition -- ------------------------------ -- This package must be instantiated for each event that a module can post. generic Name : String; package Definition is function Kind return Event_Index; pragma Inline_Always (Kind); end Definition; -- Exception raised if an event name is not found. Not_Found : exception; -- Identifies an invalid event. Invalid_Event : constant Event_Index := 0; -- Find the event runtime index given the event name. -- Raises Not_Found exception if the event name is not recognized. function Find_Event_Index (Name : in String) return Event_Index; -- ------------------------------ -- Module event -- ------------------------------ type Module_Event is new Util.Events.Event and Util.Beans.Basic.Readonly_Bean with private; type Module_Event_Access is access all Module_Event'Class; -- Set the event type which identifies the event. procedure Set_Event_Kind (Event : in out Module_Event; Kind : in Event_Index); -- Get the event type which identifies the event. function Get_Event_Kind (Event : in Module_Event) return Event_Index; -- Set a parameter on the message. procedure Set_Parameter (Event : in out Module_Event; Name : in String; Value : in String); -- Get the parameter with the given name. function Get_Parameter (Event : in Module_Event; Name : in String) return String; -- Get the value that corresponds to the parameter with the given name. overriding function Get_Value (Event : in Module_Event; Name : in String) return Util.Beans.Objects.Object; -- Get the entity identifier associated with the event. function Get_Entity_Identifier (Event : in Module_Event) return ADO.Identifier; -- Set the entity identifier associated with the event. procedure Set_Entity_Identifier (Event : in out Module_Event; Id : in ADO.Identifier); -- Copy the event properties to the map passed in <tt>Into</tt>. procedure Copy (Event : in Module_Event; Into : in out Util.Beans.Objects.Maps.Map); private type Module_Event is new Util.Events.Event and Util.Beans.Basic.Readonly_Bean with record Kind : Event_Index := Invalid_Event; Props : Util.Beans.Objects.Maps.Map; Entity : ADO.Identifier := ADO.NO_IDENTIFIER; Entity_Type : ADO.Entity_Type := ADO.NO_ENTITY_TYPE; end record; -- The index of the last event definition. Last_Event : Event_Index := 0; -- Get the event type name. function Get_Event_Type_Name (Index : in Event_Index) return Util.Strings.Name_Access; -- Make and return a copy of the event. function Copy (Event : in Module_Event) return Module_Event_Access; end AWA.Events;
with Interfaces.C, System; use type System.Address; package body FLTK.Images.RGB is procedure free_fl_rgb_image (I : in System.Address); pragma Import (C, free_fl_rgb_image, "free_fl_rgb_image"); pragma Inline (free_fl_rgb_image); function fl_rgb_image_copy (I : in System.Address; W, H : in Interfaces.C.int) return System.Address; pragma Import (C, fl_rgb_image_copy, "fl_rgb_image_copy"); pragma Inline (fl_rgb_image_copy); function fl_rgb_image_copy2 (I : in System.Address) return System.Address; pragma Import (C, fl_rgb_image_copy2, "fl_rgb_image_copy2"); pragma Inline (fl_rgb_image_copy2); procedure fl_rgb_image_color_average (I : in System.Address; C : in Interfaces.C.int; B : in Interfaces.C.C_float); pragma Import (C, fl_rgb_image_color_average, "fl_rgb_image_color_average"); pragma Inline (fl_rgb_image_color_average); procedure fl_rgb_image_desaturate (I : in System.Address); pragma Import (C, fl_rgb_image_desaturate, "fl_rgb_image_desaturate"); pragma Inline (fl_rgb_image_desaturate); procedure fl_rgb_image_draw2 (I : in System.Address; X, Y : in Interfaces.C.int); pragma Import (C, fl_rgb_image_draw2, "fl_rgb_image_draw2"); pragma Inline (fl_rgb_image_draw2); procedure fl_rgb_image_draw (I : in System.Address; X, Y, W, H, CX, CY : in Interfaces.C.int); pragma Import (C, fl_rgb_image_draw, "fl_rgb_image_draw"); pragma Inline (fl_rgb_image_draw); overriding procedure Finalize (This : in out RGB_Image) is begin if This.Void_Ptr /= System.Null_Address and then This in RGB_Image'Class then free_fl_rgb_image (This.Void_Ptr); This.Void_Ptr := System.Null_Address; end if; Finalize (Image (This)); end Finalize; function Copy (This : in RGB_Image; Width, Height : in Natural) return RGB_Image'Class is begin return Copied : RGB_Image do Copied.Void_Ptr := fl_rgb_image_copy (This.Void_Ptr, Interfaces.C.int (Width), Interfaces.C.int (Height)); end return; end Copy; function Copy (This : in RGB_Image) return RGB_Image'Class is begin return Copied : RGB_Image do Copied.Void_Ptr := fl_rgb_image_copy2 (This.Void_Ptr); end return; end Copy; procedure Color_Average (This : in out RGB_Image; Col : in Color; Amount : in Blend) is begin fl_rgb_image_color_average (This.Void_Ptr, Interfaces.C.int (Col), Interfaces.C.C_float (Amount)); end Color_Average; procedure Desaturate (This : in out RGB_Image) is begin fl_rgb_image_desaturate (This.Void_Ptr); end Desaturate; procedure Draw (This : in RGB_Image; X, Y : in Integer) is begin fl_rgb_image_draw2 (This.Void_Ptr, Interfaces.C.int (X), Interfaces.C.int (Y)); end Draw; procedure Draw (This : in RGB_Image; X, Y, W, H : in Integer; CX, CY : in Integer := 0) is begin fl_rgb_image_draw (This.Void_Ptr, Interfaces.C.int (X), Interfaces.C.int (Y), Interfaces.C.int (W), Interfaces.C.int (H), Interfaces.C.int (CX), Interfaces.C.int (CY)); end Draw; end FLTK.Images.RGB;
-- -- -- package Copyright (c) Dmitry A. Kazakov -- -- Parsers.Multiline_Source.Text_IO Luebeck -- -- Interface Winter, 2004 -- -- -- -- Last revision : 09:24 09 Apr 2010 -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public License as -- -- published by the Free Software Foundation; either version 2 of -- -- the License, or (at your option) any later version. This library -- -- 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 along with -- -- this library; if not, write to the Free Software Foundation, -- -- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. -- --____________________________________________________________________-- -- -- This package provides an implementation of code sources based on -- the standard text I/O package. -- with Ada.Text_IO; use Ada.Text_IO; package Parsers.Multiline_Source.Text_IO is -- -- Source -- The source contained by a file -- type Source (File : access File_Type) is new Multiline_Source.Source with private; -- -- Get_Line -- Overrides Parsers.Multiline_Source... -- procedure Get_Line (Code : in out Source); private type Source (File : access File_Type) is new Multiline_Source.Source with null record; end Parsers.Multiline_Source.Text_IO;
with AUnit.Reporter.Text; with AUnit.Run; with AUnit.Test_Suites; with HMAC_SHA1_Streams_Tests; with HMAC_SHA2_Streams_Tests; procedure HMAC_Tests is function Suite return AUnit.Test_Suites.Access_Test_Suite; procedure Runner is new AUnit.Run.Test_Runner (Suite); Reporter : AUnit.Reporter.Text.Text_Reporter; Test_Suite : aliased AUnit.Test_Suites.Test_Suite; function Suite return AUnit.Test_Suites.Access_Test_Suite is begin Test_Suite.Add_Test (HMAC_SHA1_Streams_Tests.Suite); Test_Suite.Add_Test (HMAC_SHA2_Streams_Tests.Suite); return Test_Suite'Unchecked_Access; end Suite; begin Reporter.Set_Use_ANSI_Colors (True); Runner (Reporter); end HMAC_Tests;
pragma Warnings (Off); pragma Style_Checks (Off); ------------------------------------------------------------------------------ -- File : Vehic002.ads -- Description : 3D model of a space vehicle. Big, mysterious ship. -- Copyright (c) Gautier de Montmollin 1999 - 2000 ------------------------------------------------------------------------------ with GLOBE_3D; package Vehic002 is procedure Create ( object : in out GLOBE_3D.p_Object_3D; scale : GLOBE_3D.Real; centre : GLOBE_3D.Point_3D; metal_door, metal_surface, bumped_blue : GLOBE_3D.Image_id ); end Vehic002;
------------------------------------------------------------------------------ -- -- -- ASIS-for-GNAT IMPLEMENTATION COMPONENTS -- -- -- -- -- -- A S I S . A D A _ E N V I R O N M E N T S . C O N T A I N E R S -- -- -- -- B o d y -- -- -- -- Copyright (c) 1995-2006, Free Software Foundation, Inc. -- -- -- -- ASIS-for-GNAT 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. ASIS-for-GNAT is distributed in the hope that it will be use- -- -- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- -- -- CHANTABILITY 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 ASIS-for-GNAT; see file -- -- COPYING. If not, write to the Free Software Foundation, 51 Franklin -- -- Street, Fifth Floor, Boston, MA 02110-1301, USA. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the -- -- Software Engineering Laboratory of the Swiss Federal Institute of -- -- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the -- -- Scientific Research Computer Center of Moscow State University (SRCC -- -- MSU), Russia, with funding partially provided by grants from the Swiss -- -- National Science Foundation and the Swiss Academy of Engineering -- -- Sciences. ASIS-for-GNAT is now maintained by AdaCore -- -- (http://www.adaccore.com). -- -- -- ------------------------------------------------------------------------------ with Asis.Exceptions; use Asis.Exceptions; with Asis.Errors; use Asis.Errors; with Asis.Compilation_Units; use Asis.Compilation_Units; with Asis.Set_Get; use Asis.Set_Get; with A4G.Contt; use A4G.Contt; with A4G.Vcheck; use A4G.Vcheck; package body Asis.Ada_Environments.Containers is Package_Name : constant String := "Asis.Ada_Environments.Containers."; -- At the moment, we implement the Container abstraction in a simplest -- possible way pointed out in section 9.1: any Context is mapped to -- a list of one Container -- -- We think that the definition of the Container abstraction in ASIS -- contains a hole. The Container remains valid only till the Context -- from which it has been obtained remains opened (the same rule as for -- other ASIS abstractions - Compilation_Unit, Element, Line, -- Record_Component, Array_Component). We failed to find the corresponding -- rule in the ASIS Standard. ----------------------- -- Local subprograms -- ----------------------- -- We can not put the access and update routines for the components of the -- Container type in Asis.Set_Get package where the access/update routines -- for other ASIS abstractions are defined, because the Container -- abstraction is defined not in Asis, but in -- Asis.Ada_Environments.Containers. If we decide to implement Containers -- in some non-trivial way, we may need to put low-level routines -- operating on Containers in some separate package function Set_Container (Cntnr : Container_Id; Cntxt : Context_Id) return Container; -- Creates the new value of the Container type, the Obtained field is set -- equal to the current ASIS OS time function Cntnr_Id (The_Container : Container) return Container_Id; function Encl_Cont_Id (The_Container : Container) return Context_Id; function Obtained (The_Container : Container) return ASIS_OS_Time; -- These functions return components of the internal Contaier structure procedure Check_Validity (The_Container : Container; Query : String); -- Checks if the argument does not belong to the closed (and possibly then -- reopened) Context. If this check fails, raises -- ASIS_Inappropriate_Container with Value_Error error status and forms -- the corresponding Diagnosis string function Is_Nil (The_Container : Container) return Boolean; -- Returns True if the container is a Nil_Container. -- This is really strange that we do not have this function in the spec. -- And the whole notion of Nil_Container seems to be ill-defined and -- as a result - useless. ------------------------------ -- Local subprograms bodies -- ------------------------------ -------------------- -- Check_Validity -- -------------------- procedure Check_Validity (The_Container : Container; Query : String) is begin if not Is_Nil (The_Container) then if not Is_Opened (Encl_Cont_Id (The_Container)) or else not Later (Opened_At (Encl_Cont_Id (The_Container)), Obtained (The_Container)) then Set_Error_Status (Status => Value_Error, Diagnosis => "Invalid Container value in " & Query); raise ASIS_Inappropriate_Container; end if; end if; end Check_Validity; -------------- -- Cntnr_Id -- -------------- function Cntnr_Id (The_Container : Container) return Container_Id is begin return The_Container.Id; end Cntnr_Id; ------------------ -- Encl_Cont_Id -- ------------------ function Encl_Cont_Id (The_Container : Container) return Context_Id is begin return The_Container.Cont_Id; end Encl_Cont_Id; ------------ -- Is_Nil -- ------------ function Is_Nil (The_Container : Container) return Boolean is begin return Cntnr_Id (The_Container) = Nil_Container_Id; end Is_Nil; -------------- -- Obtained -- -------------- function Obtained (The_Container : Container) return ASIS_OS_Time is begin return The_Container.Obtained; end Obtained; ------------------- -- Set_Container -- ------------------- function Set_Container (Cntnr : Container_Id; Cntxt : Context_Id) return Container is Result_Container : Container := Nil_Container; begin if Cntnr /= Nil_Container_Id then Result_Container := (Id => Cntnr, Cont_Id => Cntxt, Obtained => A_OS_Time); end if; return Result_Container; end Set_Container; ----------------------------------------- -- End of the local subprograms bodies -- ----------------------------------------- ----------------------- -- Compilation_Units -- ----------------------- function Compilation_Units (The_Container : Container) return Asis.Compilation_Unit_List is begin Check_Validity (The_Container, Package_Name & "Compilation_Units"); if Is_Nil (The_Container) then return Nil_Compilation_Unit_List; end if; return Compilation_Units (Enclosing_Context (The_Container)); exception when ASIS_Inappropriate_Container => raise; when ASIS_Failed => if Status_Indicator = Unhandled_Exception_Error then Add_Call_Information (Outer_Call => Package_Name & "Compilation_Units"); end if; raise; when Ex : others => Report_ASIS_Bug (Query_Name => Package_Name & "Compilation_Units", Ex => Ex); end Compilation_Units; ----------------------------- -- Compilation_Unit_Bodies -- ----------------------------- function Compilation_Unit_Bodies (The_Container : Container) return Asis.Compilation_Unit_List is begin Check_Validity (The_Container, Package_Name & "Compilation_Unit_Bodies"); if Is_Nil (The_Container) then return Nil_Compilation_Unit_List; end if; return Compilation_Unit_Bodies (Enclosing_Context (The_Container)); exception when ASIS_Inappropriate_Container => raise; when ASIS_Failed => if Status_Indicator = Unhandled_Exception_Error then Add_Call_Information (Outer_Call => Package_Name & "Compilation_Unit_Bodies"); end if; raise; when Ex : others => Report_ASIS_Bug (Query_Name => Package_Name & "Compilation_Unit_Bodies", Ex => Ex); end Compilation_Unit_Bodies; ------------------------- -- Defining_Containers -- ------------------------- function Defining_Containers (The_Context : Asis.Context) return Container_List is begin Check_Validity (The_Context, Package_Name & "Defining_Containers"); return (1 => Set_Container (First_Container_Id, Get_Cont_Id (The_Context))); exception when ASIS_Inappropriate_Container => raise; when ASIS_Failed => if Status_Indicator = Unhandled_Exception_Error then Add_Call_Information (Outer_Call => Package_Name & "Defining_Containers"); end if; raise; when Ex : others => Report_ASIS_Bug (Query_Name => Package_Name & "Defining_Containers", Ex => Ex); end Defining_Containers; ----------------------- -- Enclosing_Context -- ----------------------- function Enclosing_Context (The_Container : Container) return Asis.Context is begin Check_Validity (The_Container, Package_Name & "Enclosing_Context"); if Is_Nil (The_Container) then Set_Error_Status (Status => Value_Error, Diagnosis => "Nil_Contaier in " & Package_Name & "Enclosing_Context"); raise ASIS_Inappropriate_Container; end if; return Get_Cont (Encl_Cont_Id (The_Container)); exception when ASIS_Inappropriate_Container => raise; when ASIS_Failed => if Status_Indicator = Unhandled_Exception_Error then Add_Call_Information (Outer_Call => Package_Name & "Enclosing_Context"); end if; raise; when Ex : others => Report_ASIS_Bug (Query_Name => Package_Name & "Enclosing_Context", Ex => Ex); end Enclosing_Context; -------------- -- Is_Equal -- -------------- function Is_Equal (Left : Container; Right : Container) return Boolean is begin Check_Validity (Left, Package_Name & "Is_Equal"); Check_Validity (Right, Package_Name & "Is_Equal"); return Is_Equal (Enclosing_Context (Left), Enclosing_Context (Right)); exception when ASIS_Inappropriate_Container => raise; when ASIS_Failed => if Status_Indicator = Unhandled_Exception_Error then Add_Call_Information (Outer_Call => Package_Name & "Is_Equal"); end if; raise; when Ex : others => Report_ASIS_Bug (Query_Name => Package_Name & "Is_Equal", Ex => Ex); end Is_Equal; ------------------ -- Is_Identical -- ------------------ function Is_Identical (Left : Container; Right : Container) return Boolean is begin Check_Validity (Left, Package_Name & "Is_Identical"); Check_Validity (Right, Package_Name & "Is_Identical"); return Is_Equal (Left, Right) and then Is_Equal (Enclosing_Context (Left), Enclosing_Context (Right)); exception when ASIS_Inappropriate_Container => raise; when ASIS_Failed => if Status_Indicator = Unhandled_Exception_Error then Add_Call_Information (Outer_Call => Package_Name & "Is_Identical"); end if; raise; when Ex : others => Report_ASIS_Bug (Query_Name => Package_Name & "Is_Identical", Ex => Ex); end Is_Identical; ------------------------------- -- Library_Unit_Declarations -- ------------------------------- function Library_Unit_Declarations (The_Container : Container) return Asis.Compilation_Unit_List is begin Check_Validity (The_Container, Package_Name & "Library_Unit_Declarations"); if Is_Nil (The_Container) then return Nil_Compilation_Unit_List; end if; return Library_Unit_Declarations (Enclosing_Context (The_Container)); exception when ASIS_Inappropriate_Container => raise; when ASIS_Failed => if Status_Indicator = Unhandled_Exception_Error then Add_Call_Information (Outer_Call => Package_Name & "Library_Unit_Declarations"); end if; raise; when Ex : others => Report_ASIS_Bug (Query_Name => Package_Name & "Library_Unit_Declarations", Ex => Ex); end Library_Unit_Declarations; ---------- -- Name -- ---------- function Name (The_Container : Container) return Wide_String is begin Check_Validity (The_Container, Package_Name & "Name"); if Is_Nil (The_Container) then return Nil_Asis_Wide_String; end if; return Name (Enclosing_Context (The_Container)); exception when ASIS_Inappropriate_Container => raise; when ASIS_Failed => if Status_Indicator = Unhandled_Exception_Error then Add_Call_Information (Outer_Call => Package_Name & "Name"); end if; raise; when Ex : others => Report_ASIS_Bug (Query_Name => Package_Name & "Name", Ex => Ex); end Name; end Asis.Ada_Environments.Containers;
with Orthogonal_Polys; with text_io; use text_io; with Ada.Numerics.Generic_Elementary_Functions; procedure opolys_tst_2 is -- fit data with a nth order polynomial type Real is digits 15; package Math is new Ada.Numerics.Generic_Elementary_Functions (Real); function Sin (X : Real) return Real renames Math.Sin; function Cos (X : Real) return Real renames Math.Cos; X_Start : constant Real := 0.0; X_End : constant Real := 8.0; type array_Index is range 0..63; subtype Points_Index is array_Index range 0..32; -- This determines the maximum storage size of the Data array. -- the Data array will start at Points_Index'First and end -- at Points_Index'Last. -- Least squares fitting can be done on any sub interval of -- this array by setting the obvious parameters in the procedure -- below. type Data is array (array_Index) of Real; package LS is new Orthogonal_Polys (Real, array_Index, Data, 0.0, 1.0); -- "*", "+", "-", "/", "<", "**", "-"); use LS; ls_order : constant Coeff_Index := 24; X_axis : Data; Y_Data : Data; Weights : constant Data := (others => 1.0); Delta_X : Real; -- Variables for IO: X0, Y0: Real; X1, Y1 : Real; E : Real; Best_Fit : Poly_Data; Poly_Set : Polynomials; C : Poly_Sum_Coeffs; First : constant Points_Index := Points_Index'First; Last : constant Points_Index := Points_Index'Last; package rio is new Text_IO.FLoat_IO(Real); use rio; --------- -- Sum -- --------- function Sum (X : Real; Coeffs : Powers_Of_X_Coeffs) return Real is Result : Real := 0.0; begin Result := Coeffs(Coeff_Index'Last); for I in reverse Coeff_Index'First..Coeff_Index'Last-1 loop Result := Result * X; Result := Result + Coeffs(I); end loop; return Result; end Sum; ----------- -- Pause -- ----------- procedure Pause (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11 : string := "") is Continue : Character := ' '; begin new_line; if S0 /= "" then put_line (S0); end if; if S1 /= "" then put_line (S1); end if; if S2 /= "" then put_line (S2); end if; if S3 /= "" then put_line (S3); end if; if S4 /= "" then put_line (S4); end if; if S5 /= "" then put_line (S5); end if; if S6 /= "" then put_line (S6); end if; if S7 /= "" then put_line (S7); end if; if S8 /= "" then put_line (S8); end if; if S9 /= "" then put_line (S9); end if; if S10 /= "" then put_line (S10); end if; if S11 /= "" then put_line (S11); end if; new_line; begin Put ("Enter a character to continue: "); Get_Immediate (Continue); New_Line; exception when others => null; end; end pause; begin Delta_X := (X_end - X_Start) / Real (X_axis'Length - 1); for I in Points_Index loop X_axis(I) := X_Start + Real (I - Points_Index'First) * Delta_X; end loop; -- Want the wgts to go to zero at the points that are just before and -- just beyond the end points, so Diameter of the circle-wgt is greater -- than X_end - X_start by 2 * Delta_X. -- Diameter := X_end - X_start + 2.0 * Delta_X; -- Radius := Diameter / 2.0; -- middle := (X_end + X_start) / 2.0; -- for I in Points_Index loop -- Weights(I) := SQRT (Radius*Radius - (X_axis(I) - middle)**2); -- end loop; for I in Points_Index loop Y_Data(I) := Sin (X_axis(I)); end loop; Poly_Fit (Y_Data, X_axis, Weights, First, Last, ls_order, Best_Fit, C, Poly_Set, E); pause("Test 1: Make sinusoidal data, fit a high order polynomial to it,", "and subtract the Integral of the fit from the Integral", "of the original data."); for I in Points_Index'first+1 .. Points_Index'last loop X0 := X_axis(I-1); Y0 := Poly_Integral (X0, C, Poly_Set); X1 := X_axis(I); Y1 := Poly_Integral (X1, C, Poly_Set); new_line; put (Y1 - Y0 - (-Cos (X1) + Cos (X0)) ); put (" "); end loop; end opolys_tst_2;
package body -<full_series_name_dots>-.object is procedure pack (this: in Object_Any; buf: in out ByteBuffer) is begin null; end pack; procedure unpack (this: in out Object_Any; buf: in out ByteBuffer) is begin null; end unpack; end -<full_series_name_dots>-.object;
--- src/anet-sockets-inet.adb.orig 2016-06-29 10:26:01 UTC +++ src/anet-sockets-inet.adb @@ -52,7 +52,7 @@ package body Anet.Sockets.Inet is Res : C.int; Sock : Thin.Inet.Sockaddr_In_Type (Family => Socket_Families.Family_Inet); - Len : aliased C.int := Sock'Size / 8; + Len : aliased C.int := Thin.Inet.Sockaddr_In_Size; begin New_Socket.Sock_FD := -1; @@ -80,7 +80,7 @@ package body Anet.Sockets.Inet is Res : C.int; Sock : Thin.Inet.Sockaddr_In_Type (Family => Socket_Families.Family_Inet6); - Len : aliased C.int := Sock'Size / 8; + Len : aliased C.int := Thin.Inet.Sockaddr_In6_Size; begin New_Socket.Sock_FD := -1; @@ -129,7 +129,7 @@ package body Anet.Sockets.Inet is (Result => Thin.C_Bind (S => Socket.Sock_FD, Name => Sockaddr'Address, - Namelen => Sockaddr'Size / 8), + Namelen => Thin.Inet.Sockaddr_In_Size), Message => "Unable to bind IPv4 socket to " & To_String (Address => Address) & "," & Port'Img); end Bind; @@ -153,7 +153,7 @@ package body Anet.Sockets.Inet is (Result => Thin.C_Bind (S => Socket.Sock_FD, Name => Sockaddr'Address, - Namelen => Sockaddr'Size / 8), + Namelen => Thin.Inet.Sockaddr_In6_Size), Message => "Unable to bind IPv6 socket to " & To_String (Address => Address) & "," & Port'Img); end Bind; @@ -173,7 +173,7 @@ package body Anet.Sockets.Inet is (Result => Thin.C_Connect (S => Socket.Sock_FD, Name => Dst'Address, - Namelen => Dst'Size / 8), + Namelen => Thin.Inet.Sockaddr_In_Size), Message => "Unable to connect socket to address " & To_String (Address => Address) & " (" & Port'Img & " )"); end Connect; @@ -193,7 +193,7 @@ package body Anet.Sockets.Inet is (Result => Thin.C_Connect (S => Socket.Sock_FD, Name => Dst'Address, - Namelen => Dst'Size / 8), + Namelen => Thin.Inet.Sockaddr_In6_Size), Message => "Unable to connect socket to address " & To_String (Address => Address) & " (" & Port'Img & " )"); end Connect; @@ -432,7 +432,7 @@ package body Anet.Sockets.Inet is Len => Item'Length, Flags => 0, To => Dst'Address, - Tolen => Dst'Size / 8); + Tolen => Thin.Inet.Sockaddr_In_Size); Errno.Check_Or_Raise (Result => C.int (Res), @@ -464,7 +464,7 @@ package body Anet.Sockets.Inet is Len => Item'Length, Flags => 0, To => Dst'Address, - Tolen => Dst'Size / 8); + Tolen => Thin.Inet.Sockaddr_In6_Size); Errno.Check_Or_Raise (Result => C.int (Res),
with AUnit.Test_Suites; package MainTestSuite is function Suite return AUnit.Test_Suites.Access_Test_Suite; procedure runAll; end MainTestSuite;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.Internals.Links; with AMF.Internals.Tables.CMOF_Metamodel; with AMF.Internals.Tables.UML_Metamodel; package body AMF.Internals.Tables.Standard_Profile_L3_Metamodel.Links is ---------------- -- Initialize -- ---------------- procedure Initialize is begin Initialize_1; Initialize_2; Initialize_3; Initialize_4; Initialize_5; Initialize_6; Initialize_7; Initialize_8; Initialize_9; Initialize_10; Initialize_11; Initialize_12; Initialize_13; Initialize_14; Initialize_15; end Initialize; ------------------ -- Initialize_1 -- ------------------ procedure Initialize_1 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Classifier_Attribute_Classifier, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Classifier_Attribute_A_Classifier, Base + 4, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Classifier_Classifier_Attribute); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Classifier_Feature_Featuring_Classifier, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Classifier_Feature_Feature_Featuring_Classifier, Base + 4, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Feature_Featuring_Classifier_Classifier_Feature); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 4, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Class_Owned_Attribute_Class, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Class_Owned_Attribute_Property_Class, Base + 4, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Class_Class_Owned_Attribute); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 4, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 4, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); end Initialize_1; ------------------ -- Initialize_2 -- ------------------ procedure Initialize_2 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Classifier_Attribute_Classifier, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Classifier_Attribute_A_Classifier, Base + 5, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Classifier_Classifier_Attribute); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Classifier_Feature_Featuring_Classifier, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Classifier_Feature_Feature_Featuring_Classifier, Base + 5, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Feature_Featuring_Classifier_Classifier_Feature); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 5, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Class_Owned_Attribute_Class, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Class_Owned_Attribute_Property_Class, Base + 5, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Class_Class_Owned_Attribute); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 5, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 5, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); end Initialize_2; ------------------ -- Initialize_3 -- ------------------ procedure Initialize_3 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Classifier_Attribute_Classifier, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Classifier_Attribute_A_Classifier, Base + 6, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Classifier_Classifier_Attribute); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Classifier_Feature_Featuring_Classifier, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Classifier_Feature_Feature_Featuring_Classifier, Base + 6, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Feature_Featuring_Classifier_Classifier_Feature); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 6, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Class_Owned_Attribute_Class, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Class_Owned_Attribute_Property_Class, Base + 6, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Class_Class_Owned_Attribute); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 6, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 6, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); end Initialize_3; ------------------ -- Initialize_4 -- ------------------ procedure Initialize_4 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Typed_Element_Type_Typed_Element, Base + 4, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Typed_Element_Type_A_Typed_Element, AMF.Internals.Tables.UML_Metamodel.MC_UML_Component, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Typed_Element_Typed_Element_Type); end Initialize_4; ------------------ -- Initialize_5 -- ------------------ procedure Initialize_5 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Typed_Element_Type_Typed_Element, Base + 5, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Typed_Element_Type_A_Typed_Element, AMF.Internals.Tables.UML_Metamodel.MC_UML_Model, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Typed_Element_Typed_Element_Type); end Initialize_5; ------------------ -- Initialize_6 -- ------------------ procedure Initialize_6 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Typed_Element_Type_Typed_Element, Base + 6, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Typed_Element_Type_A_Typed_Element, AMF.Internals.Tables.UML_Metamodel.MC_UML_Model, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Typed_Element_Typed_Element_Type); end Initialize_6; ------------------ -- Initialize_7 -- ------------------ procedure Initialize_7 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Classifier_Feature_Featuring_Classifier, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Classifier_Feature_Feature_Featuring_Classifier, Base + 14, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Feature_Featuring_Classifier_Classifier_Feature); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 14, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 14, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 6, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Association_Member_End_Association, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Association_Member_End_Property_Association, Base + 14, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Association_Association_Member_End); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Association_Member_End_Association, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Association_Member_End_Property_Association, Base + 6, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Association_Association_Member_End); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 14, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Association_Owned_End_Owning_Association, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Association_Owned_End_Property_Owning_Association, Base + 14, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Owning_Association_Association_Owned_End); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 14, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); end Initialize_7; ------------------ -- Initialize_8 -- ------------------ procedure Initialize_8 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Classifier_Feature_Featuring_Classifier, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Classifier_Feature_Feature_Featuring_Classifier, Base + 12, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Feature_Featuring_Classifier_Classifier_Feature); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 12, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 12, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 4, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Association_Member_End_Association, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Association_Member_End_Property_Association, Base + 12, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Association_Association_Member_End); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Association_Member_End_Association, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Association_Member_End_Property_Association, Base + 4, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Association_Association_Member_End); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 12, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Association_Owned_End_Owning_Association, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Association_Owned_End_Property_Owning_Association, Base + 12, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Owning_Association_Association_Owned_End); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 12, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); end Initialize_8; ------------------ -- Initialize_9 -- ------------------ procedure Initialize_9 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Classifier_Feature_Featuring_Classifier, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Classifier_Feature_Feature_Featuring_Classifier, Base + 13, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Feature_Featuring_Classifier_Classifier_Feature); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 13, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 13, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 5, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Association_Member_End_Association, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Association_Member_End_Property_Association, Base + 13, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Association_Association_Member_End); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Association_Member_End_Association, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Association_Member_End_Property_Association, Base + 5, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Association_Association_Member_End); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 13, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Association_Owned_End_Owning_Association, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Association_Owned_End_Property_Owning_Association, Base + 13, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Property_Owning_Association_Association_Owned_End); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 13, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); end Initialize_9; ------------------- -- Initialize_10 -- ------------------- procedure Initialize_10 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Member_A_Namespace, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Namespace_Namespace_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 11, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Element_Owned_Element_Owner, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owned_Element_Element_Owner, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Element_Owner_Element_Owned_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Owned_Member_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Owned_Member_Named_Element_Namespace, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Named_Element_Namespace_Namespace_Owned_Member); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Package_Owned_Type_Package, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Owned_Type_Type_Package, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Type_Package_Package_Owned_Type); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Package_Owned_Type_Package, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Owned_Type_Type_Package, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Type_Package_Package_Owned_Type); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Package_Owned_Type_Package, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Owned_Type_Type_Package, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Type_Package_Package_Owned_Type); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Namespace_Package_Import_Importing_Namespace, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Namespace_Package_Import_Package_Import_Importing_Namespace, Base + 11, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Import_Importing_Namespace_Namespace_Package_Import); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Package_Packaged_Element_Owning_Package, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Packaged_Element_A_Owning_Package, Base + 8, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Owning_Package_Package_Packaged_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Package_Packaged_Element_Owning_Package, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Packaged_Element_A_Owning_Package, Base + 9, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Owning_Package_Package_Packaged_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Package_Packaged_Element_Owning_Package, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Packaged_Element_A_Owning_Package, Base + 7, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Owning_Package_Package_Packaged_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Package_Packaged_Element_Owning_Package, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Packaged_Element_A_Owning_Package, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Owning_Package_Package_Packaged_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Package_Packaged_Element_Owning_Package, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Packaged_Element_A_Owning_Package, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Owning_Package_Package_Packaged_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Package_Packaged_Element_Owning_Package, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Packaged_Element_A_Owning_Package, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Owning_Package_Package_Packaged_Element); end Initialize_10; ------------------- -- Initialize_11 -- ------------------- procedure Initialize_11 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Package_Import_Imported_Package_Package_Import, Base + 11, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Package_Import_Imported_Package_A_Package_Import, AMF.Internals.Tables.UML_Metamodel.MM_UML_UML, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Package_Import_Package_Import_Imported_Package); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Relationship_Related_Element_Relationship, Base + 11, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Relationship_Related_Element_A_Relationship, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Relationship_Relationship_Related_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Relationship_Related_Element_Relationship, Base + 11, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Relationship_Related_Element_A_Relationship, AMF.Internals.Tables.UML_Metamodel.MM_UML_UML, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Relationship_Relationship_Related_Element); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Directed_Relationship_Source_Directed_Relationship, Base + 11, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Directed_Relationship_Source_A_Directed_Relationship, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Directed_Relationship_Directed_Relationship_Source); AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Directed_Relationship_Target_Directed_Relationship, Base + 11, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Directed_Relationship_Target_A_Directed_Relationship, AMF.Internals.Tables.UML_Metamodel.MM_UML_UML, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Directed_Relationship_Directed_Relationship_Target); end Initialize_11; ------------------- -- Initialize_12 -- ------------------- procedure Initialize_12 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Typed_Element_Type_Typed_Element, Base + 12, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Typed_Element_Type_A_Typed_Element, Base + 1, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Typed_Element_Typed_Element_Type); end Initialize_12; ------------------- -- Initialize_13 -- ------------------- procedure Initialize_13 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Typed_Element_Type_Typed_Element, Base + 13, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Typed_Element_Type_A_Typed_Element, Base + 2, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Typed_Element_Typed_Element_Type); end Initialize_13; ------------------- -- Initialize_14 -- ------------------- procedure Initialize_14 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Typed_Element_Type_Typed_Element, Base + 14, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Typed_Element_Type_A_Typed_Element, Base + 3, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Typed_Element_Typed_Element_Type); end Initialize_14; ------------------- -- Initialize_15 -- ------------------- procedure Initialize_15 is begin AMF.Internals.Links.Internal_Create_Link (AMF.Internals.Tables.CMOF_Metamodel.MA_CMOF_Tag_Element_Tag, Base + 15, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_Tag_Element_A_Tag, Base + 10, AMF.Internals.Tables.CMOF_Metamodel.MP_CMOF_A_Tag_Tag_Element); end Initialize_15; end AMF.Internals.Tables.Standard_Profile_L3_Metamodel.Links;
-- { dg-do run } pragma Restrictions (No_Finalization); procedure no_final is package P is type T is tagged null record; type T1 is new T with record A : String (1..80); end record; function F return T'Class; end P; Str : String (1..80) := (1..80=>'x'); package body P is function F return T'Class is X : T1 := T1'(A => Str); begin return X; end F; end P; Obj : P.T'class := P.F; begin if P.T1 (Obj).A /= Str then raise Constraint_Error; end if; end;
-- This spec has been automatically generated from STM32L0x1.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with System; package STM32_SVD.NVIC is pragma Preelaborate; --------------- -- Registers -- --------------- -- Interrupt Priority Register 0 type IPR0_Register is record -- priority for interrupt 0 PRI_0 : STM32_SVD.Byte; -- priority for interrupt 1 PRI_1 : STM32_SVD.Byte; -- priority for interrupt 2 PRI_2 : STM32_SVD.Byte; -- priority for interrupt 3 PRI_3 : STM32_SVD.Byte; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for IPR0_Register use record PRI_0 at 0 range 0 .. 7; PRI_1 at 0 range 8 .. 15; PRI_2 at 0 range 16 .. 23; PRI_3 at 0 range 24 .. 31; end record; -- Interrupt Priority Register 1 type IPR1_Register is record -- priority for interrupt n PRI_4 : STM32_SVD.Byte; -- priority for interrupt n PRI_5 : STM32_SVD.Byte; -- priority for interrupt n PRI_6 : STM32_SVD.Byte; -- priority for interrupt n PRI_7 : STM32_SVD.Byte; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for IPR1_Register use record PRI_4 at 0 range 0 .. 7; PRI_5 at 0 range 8 .. 15; PRI_6 at 0 range 16 .. 23; PRI_7 at 0 range 24 .. 31; end record; -- Interrupt Priority Register 2 type IPR2_Register is record -- priority for interrupt n PRI_8 : STM32_SVD.Byte; -- priority for interrupt n PRI_9 : STM32_SVD.Byte; -- priority for interrupt n PRI_10 : STM32_SVD.Byte; -- priority for interrupt n PRI_11 : STM32_SVD.Byte; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for IPR2_Register use record PRI_8 at 0 range 0 .. 7; PRI_9 at 0 range 8 .. 15; PRI_10 at 0 range 16 .. 23; PRI_11 at 0 range 24 .. 31; end record; -- Interrupt Priority Register 3 type IPR3_Register is record -- priority for interrupt n PRI_12 : STM32_SVD.Byte; -- priority for interrupt n PRI_13 : STM32_SVD.Byte; -- priority for interrupt n PRI_14 : STM32_SVD.Byte; -- priority for interrupt n PRI_15 : STM32_SVD.Byte; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for IPR3_Register use record PRI_12 at 0 range 0 .. 7; PRI_13 at 0 range 8 .. 15; PRI_14 at 0 range 16 .. 23; PRI_15 at 0 range 24 .. 31; end record; -- Interrupt Priority Register 4 type IPR4_Register is record -- priority for interrupt n PRI_16 : STM32_SVD.Byte; -- priority for interrupt n PRI_17 : STM32_SVD.Byte; -- priority for interrupt n PRI_18 : STM32_SVD.Byte; -- priority for interrupt n PRI_19 : STM32_SVD.Byte; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for IPR4_Register use record PRI_16 at 0 range 0 .. 7; PRI_17 at 0 range 8 .. 15; PRI_18 at 0 range 16 .. 23; PRI_19 at 0 range 24 .. 31; end record; -- Interrupt Priority Register 5 type IPR5_Register is record -- priority for interrupt n PRI_20 : STM32_SVD.Byte; -- priority for interrupt n PRI_21 : STM32_SVD.Byte; -- priority for interrupt n PRI_22 : STM32_SVD.Byte; -- priority for interrupt n PRI_23 : STM32_SVD.Byte; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for IPR5_Register use record PRI_20 at 0 range 0 .. 7; PRI_21 at 0 range 8 .. 15; PRI_22 at 0 range 16 .. 23; PRI_23 at 0 range 24 .. 31; end record; -- Interrupt Priority Register 6 type IPR6_Register is record -- priority for interrupt n PRI_24 : STM32_SVD.Byte; -- priority for interrupt n PRI_25 : STM32_SVD.Byte; -- priority for interrupt n PRI_26 : STM32_SVD.Byte; -- priority for interrupt n PRI_27 : STM32_SVD.Byte; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for IPR6_Register use record PRI_24 at 0 range 0 .. 7; PRI_25 at 0 range 8 .. 15; PRI_26 at 0 range 16 .. 23; PRI_27 at 0 range 24 .. 31; end record; -- Interrupt Priority Register 7 type IPR7_Register is record -- priority for interrupt n PRI_28 : STM32_SVD.Byte; -- priority for interrupt n PRI_29 : STM32_SVD.Byte; -- priority for interrupt n PRI_30 : STM32_SVD.Byte; -- priority for interrupt n PRI_31 : STM32_SVD.Byte; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for IPR7_Register use record PRI_28 at 0 range 0 .. 7; PRI_29 at 0 range 8 .. 15; PRI_30 at 0 range 16 .. 23; PRI_31 at 0 range 24 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Nested Vectored Interrupt Controller type NVIC_Peripheral is record -- Interrupt Set Enable Register ISER : aliased STM32_SVD.UInt32; -- Interrupt Clear Enable Register ICER : aliased STM32_SVD.UInt32; -- Interrupt Set-Pending Register ISPR : aliased STM32_SVD.UInt32; -- Interrupt Clear-Pending Register ICPR : aliased STM32_SVD.UInt32; -- Interrupt Priority Register 0 IPR0 : aliased IPR0_Register; -- Interrupt Priority Register 1 IPR1 : aliased IPR1_Register; -- Interrupt Priority Register 2 IPR2 : aliased IPR2_Register; -- Interrupt Priority Register 3 IPR3 : aliased IPR3_Register; -- Interrupt Priority Register 4 IPR4 : aliased IPR4_Register; -- Interrupt Priority Register 5 IPR5 : aliased IPR5_Register; -- Interrupt Priority Register 6 IPR6 : aliased IPR6_Register; -- Interrupt Priority Register 7 IPR7 : aliased IPR7_Register; end record with Volatile; for NVIC_Peripheral use record ISER at 16#0# range 0 .. 31; ICER at 16#80# range 0 .. 31; ISPR at 16#100# range 0 .. 31; ICPR at 16#180# range 0 .. 31; IPR0 at 16#300# range 0 .. 31; IPR1 at 16#304# range 0 .. 31; IPR2 at 16#308# range 0 .. 31; IPR3 at 16#30C# range 0 .. 31; IPR4 at 16#310# range 0 .. 31; IPR5 at 16#314# range 0 .. 31; IPR6 at 16#318# range 0 .. 31; IPR7 at 16#31C# range 0 .. 31; end record; -- Nested Vectored Interrupt Controller NVIC_Periph : aliased NVIC_Peripheral with Import, Address => NVIC_Base; end STM32_SVD.NVIC;
with Ada.Exception_Identification.From_Here; with Ada.Exceptions.Finally; with System.Address_To_Named_Access_Conversions; with System.Growth; with System.Standard_Allocators; with System.Storage_Elements; with System.Zero_Terminated_Strings; with C.errno; with C.fcntl; with C.unistd; package body System.Native_Directories.Volumes is use Ada.Exception_Identification.From_Here; use type Storage_Elements.Storage_Offset; use type File_Size; use type C.char; use type C.char_array; use type C.char_ptr; use type C.ptrdiff_t; use type C.signed_int; use type C.signed_long; -- f_type in 64bit use type C.signed_long_long; -- f_type in x32 use type C.size_t; use type C.sys.types.fsid_t; procedure memcpy (dst, src : not null C.char_ptr; n : C.size_t) with Import, Convention => Intrinsic, External_Name => "__builtin_memcpy"; package char_ptr_Conv is new Address_To_Named_Access_Conversions (C.char, C.char_ptr); function "+" (Left : C.char_ptr; Right : C.ptrdiff_t) return C.char_ptr with Convention => Intrinsic; function "-" (Left : C.char_ptr; Right : C.char_ptr) return C.ptrdiff_t with Convention => Intrinsic; function "<" (Left, Right : C.char_ptr) return Boolean with Import, Convention => Intrinsic; pragma Inline_Always ("+"); pragma Inline_Always ("-"); function "+" (Left : C.char_ptr; Right : C.ptrdiff_t) return C.char_ptr is begin return char_ptr_Conv.To_Pointer ( char_ptr_Conv.To_Address (Left) + Storage_Elements.Storage_Offset (Right)); end "+"; function "-" (Left : C.char_ptr; Right : C.char_ptr) return C.ptrdiff_t is begin return C.ptrdiff_t ( char_ptr_Conv.To_Address (Left) - char_ptr_Conv.To_Address (Right)); end "-"; proc_self_mountinfo : aliased constant C.char_array (0 .. 20) := "/proc/self/mountinfo" & C.char'Val (0); -- 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,... -- (1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11) -- (1) mount ID -- (2) parent ID -- (3) major:minor, st_dev -- (4) root, '/' -- (5) mount point (for Directory) -- (6) mount options -- (7) optional fields -- (8) separator, '-' -- (9) filesystem type (for Format_Name) -- (10) mount source (for Device) -- (11) super options procedure Close (fd : in out C.signed_int); procedure Close (fd : in out C.signed_int) is begin if C.unistd.close (fd) < 0 then null; -- raise Use_Error end if; end Close; procedure Skip (P : in out C.char_ptr; To : C.char); procedure Skip (P : in out C.char_ptr; To : C.char) is begin while P.all /= C.char'Val (10) loop if P.all = To then P := P + 1; exit; end if; P := P + 1; end loop; end Skip; procedure Skip_Escaped (P : in out C.char_ptr; Length : out C.size_t); procedure Skip_Escaped (P : in out C.char_ptr; Length : out C.size_t) is Z : constant := C.char'Pos ('0'); D : C.char_ptr := P; begin Length := 0; while P.all /= C.char'Val (10) loop if P.all = ' ' then P := P + 1; exit; elsif P.all = '\' and then C.char_ptr'(P + 1).all in '0' .. '3' and then C.char_ptr'(P + 2).all in '0' .. '7' and then C.char_ptr'(P + 3).all in '0' .. '7' then D.all := C.char'Val ( 64 * (C.char'Pos (C.char_ptr'(P + 1).all) - Z) + 8 * (C.char'Pos (C.char_ptr'(P + 2).all) - Z) + (C.char'Pos (C.char_ptr'(P + 3).all) - Z)); P := P + 4; else if D /= P then D.all := P.all; end if; P := P + 1; end if; D := D + 1; Length := Length + 1; end loop; end Skip_Escaped; procedure Skip_Line (P : in out C.char_ptr); procedure Skip_Line (P : in out C.char_ptr) is begin while P.all /= C.char'Val (10) loop P := P + 1; end loop; P := P + 1; -- skip '\n' end Skip_Line; procedure Read_Info (FS : in out File_System); procedure Read_Info (FS : in out File_System) is package Buffer_Holder is new Growth.Scoped_Holder ( C.sys.types.ssize_t, Component_Size => C.char_array'Component_Size); Size : C.size_t := 0; begin Buffer_Holder.Reserve_Capacity (4096); -- read /proc/self/mountinfo declare package File_Holder is new Ada.Exceptions.Finally.Scoped_Holder (C.signed_int, Close); File : aliased C.signed_int; begin File := C.fcntl.open (proc_self_mountinfo (0)'Access, C.fcntl.O_RDONLY); if File < 0 then Raise_Exception (Named_IO_Exception_Id (C.errno.errno)); end if; File_Holder.Assign (File); Reading : loop loop declare Read_Size : C.sys.types.ssize_t; begin Read_Size := C.unistd.read ( File, C.void_ptr ( char_ptr_Conv.To_Address ( char_ptr_Conv.To_Pointer ( Buffer_Holder.Storage_Address) + C.ptrdiff_t (Size))), C.size_t (Buffer_Holder.Capacity) - Size); if Read_Size < 0 then Raise_Exception (IO_Exception_Id (C.errno.errno)); end if; exit Reading when Read_Size = 0; Size := Size + C.size_t (Read_Size); end; exit when Size >= C.size_t (Buffer_Holder.Capacity); end loop; -- growth declare function Grow is new Growth.Fast_Grow (C.sys.types.ssize_t); begin Buffer_Holder.Reserve_Capacity (Grow (Buffer_Holder.Capacity)); end; end loop Reading; end; -- parsing declare End_Of_Buffer : constant C.char_ptr := char_ptr_Conv.To_Pointer (Buffer_Holder.Storage_Address) + C.ptrdiff_t (Size); Line : C.char_ptr := char_ptr_Conv.To_Pointer (Buffer_Holder.Storage_Address); begin while Line < End_Of_Buffer loop declare Directory_Offset : C.ptrdiff_t; Directory_Length : C.size_t; Format_Name_Offset : C.ptrdiff_t; Format_Name_Length : C.size_t; Device_Offset : C.ptrdiff_t; Device_Length : C.size_t; statfs : aliased C.sys.statfs.struct_statfs; P : C.char_ptr := Line; begin Skip (P, To => ' '); -- mount ID Skip (P, To => ' '); -- parent ID Skip (P, To => ' '); -- major:minor Skip (P, To => ' '); -- root Directory_Offset := P - Line; -- mount point Skip_Escaped (P, Directory_Length); Skip (P, To => ' '); -- mount options loop -- optional fields Skip (P, To => ' '); exit when P.all = '-' or else P.all = C.char'Val (10); end loop; Skip (P, To => ' '); -- separator Format_Name_Offset := P - Line; -- filesystem type Skip_Escaped (P, Format_Name_Length); Device_Offset := P - Line; -- mount source Skip_Escaped (P, Device_Length); Skip_Line (P); -- super options -- matching declare End_Of_Directory : constant C.char_ptr := Line + Directory_Offset + C.ptrdiff_t (Directory_Length); Orig : constant C.char := End_Of_Directory.all; begin End_Of_Directory.all := C.char'Val (0); if C.sys.statfs.statfs ( Line + Directory_Offset, statfs'Access) < 0 then Raise_Exception (Named_IO_Exception_Id (C.errno.errno)); end if; End_Of_Directory.all := Orig; end; if statfs.f_fsid /= (val => (others => 0)) and then statfs.f_fsid = FS.Statistics.f_fsid then FS.Format_Name_Offset := Format_Name_Offset; FS.Format_Name_Length := Format_Name_Length; FS.Directory_Offset := Directory_Offset; FS.Directory_Length := Directory_Length; FS.Device_Offset := Device_Offset; FS.Device_Length := Device_Length; FS.Info := char_ptr_Conv.To_Pointer ( Standard_Allocators.Allocate ( Storage_Elements.Storage_Count (P - Line))); memcpy (FS.Info, Line, C.size_t (P - Line)); return; -- found end if; -- continue Line := P; end; end loop; end; Raise_Exception (Use_Error'Identity); -- not found end Read_Info; -- implementation function Is_Assigned (FS : File_System) return Boolean is begin return FS.Statistics.f_type /= 0; end Is_Assigned; procedure Get (Name : String; FS : aliased out File_System) is C_Name : C.char_array ( 0 .. Name'Length * Zero_Terminated_Strings.Expanding); begin Zero_Terminated_Strings.To_C (Name, C_Name (0)'Access); FS.Info := null; if C.sys.statfs.statfs (C_Name (0)'Access, FS.Statistics'Access) < 0 then Raise_Exception (Named_IO_Exception_Id (C.errno.errno)); end if; end Get; procedure Finalize (FS : in out File_System) is begin Standard_Allocators.Free (char_ptr_Conv.To_Address (FS.Info)); end Finalize; function Size (FS : File_System) return File_Size is begin return File_Size (FS.Statistics.f_blocks) * File_Size (FS.Statistics.f_bsize); end Size; function Free_Space (FS : File_System) return File_Size is begin return File_Size (FS.Statistics.f_bfree) * File_Size (FS.Statistics.f_bsize); end Free_Space; function Format_Name (FS : aliased in out File_System) return String is begin if FS.Info = null then Read_Info (FS); end if; return Zero_Terminated_Strings.Value ( FS.Info + FS.Format_Name_Offset, FS.Format_Name_Length); end Format_Name; function Directory (FS : aliased in out File_System) return String is begin if FS.Info = null then Read_Info (FS); end if; return Zero_Terminated_Strings.Value ( FS.Info + FS.Directory_Offset, FS.Directory_Length); end Directory; function Device (FS : aliased in out File_System) return String is begin if FS.Info = null then Read_Info (FS); end if; return Zero_Terminated_Strings.Value ( FS.Info + FS.Device_Offset, FS.Device_Length); end Device; function Identity (FS : File_System) return File_System_Id is begin return FS.Statistics.f_fsid; end Identity; end System.Native_Directories.Volumes;
with Predictor_2; with Text_IO; use Text_IO; with Sinu_2; with Ada.Numerics.Generic_Elementary_Functions; procedure predictor_2_demo_1 is type Real is digits 15; package Sinusoid is new Sinu_2 (Real); use Sinusoid; package Sin_Integrate is new Predictor_2 (Real, Dyn_Index, Dynamical_Variable, F, "*", "+", "-"); use Sin_Integrate; package mth is new Ada.Numerics.Generic_Elementary_Functions(Real); use mth; package rio is new Float_IO(Real); use rio; package iio is new Integer_IO(Integer); use iio; Previous_Y, Newest_Y : Dynamical_Variable; Previous_Y_dot, Newest_Y_dot : Dynamical_Variable; Final_Time, Starting_Time : Real; Previous_t, Newest_t : Real; Delta_t : Real := 1.0 / 8.0; Steps : Real := 10_000.0; begin new_line; put ("Test integrates an equation whose solution is Sin(t)."); new_line; put ("The equation is (d/dt)**2 (Y) = -Y. (Y = Sin(t) has a period of 2*Pi.)"); new_line(2); put ("Enter number of time steps (try 512): "); get (Steps); new_line; put ("Every time the integration advances this number of steps, ERROR is printed."); new_line; -- choose initial conditions Starting_Time := 0.0; Final_Time := 64.0; Previous_Y(0) := 0.0; Previous_Y_dot(0) := 1.0; Previous_Y(1) := 0.0; --unused... just too lazy to remove it. Previous_Y_dot(1) := 0.0; --unused Previous_t := Starting_Time; Delta_t := Final_Time - Starting_Time; for i in 1..28 loop Newest_t := Previous_t + Delta_t; Integrate (Final_Y => Newest_Y, -- the result (output). Final_deriv_Of_Y => Newest_y_dot, Final_Time => Newest_t, -- integrate out to here (input). Initial_Y => Previous_Y, -- input an initial condition (input). Initial_deriv_Of_Y => Previous_Y_dot, Initial_Time => Previous_t, -- start integrating here (input). No_Of_Steps => Steps); -- use this no_of_steps Previous_Y := Newest_Y; Previous_Y_dot := Newest_y_dot; Previous_t := Newest_t; --put ("Final value of numerically integrated sin: "); --put (Newest_Y(0), Aft => 7); new_line; put ("Time = t ="); put (Newest_t, Aft => 7); put (", Error = Sin(t)-Y = "); put (Sin (Real (Newest_t)) - Newest_Y(0), Aft => 7); end loop; new_line(2); put ("Total elapsed time is:"); put (Newest_t / (2.0*3.14159266), Aft => 7); put (" in units of 2 pi."); new_line(2); put ("Final Remark: this (20th order) Predictor-Corrector requires half as many"); new_line; put ("time steps per interval as the 17th order Predictor-Corrector to get near"); new_line; put ("machine precision. That means it requires about 1/12th as many evaluations"); new_line; put ("of F(t, Y) as the 8th order Runge-Kutta, (for this class of equation anyway)."); new_line; put ("If evaluation of F(t, Y) dominates overhead at run-time, as it does in most"); new_line; put ("N-body problems, then this specialized Predictor-Corrector is a good idea"); new_line; put ("here. In fact Predictor-Correctors are still commonly used in these problems."); new_line; put ("Of course the 20th order Predictor-Corrector is restricted to a special"); new_line; put ("class of differential equation: (d/dt)^2 Y = F(t, Y)."); new_line; new_line(2); end;
with Dsp.Generic_Functions; with Ada.Numerics.Complex_Types; -- -- Instantiation of Generic_Functions for Float and basic Complex -- package Dsp.Functions is new Dsp.Generic_Functions (Scalar_Type => Float, Complex_Types => Ada.Numerics.Complex_Types);
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Program.Elements.Constraints; with Program.Lexical_Elements; with Program.Elements.Expressions; package Program.Elements.Delta_Constraints is pragma Pure (Program.Elements.Delta_Constraints); type Delta_Constraint is limited interface and Program.Elements.Constraints.Constraint; type Delta_Constraint_Access is access all Delta_Constraint'Class with Storage_Size => 0; not overriding function Delta_Expression (Self : Delta_Constraint) return not null Program.Elements.Expressions.Expression_Access is abstract; not overriding function Real_Range_Constraint (Self : Delta_Constraint) return Program.Elements.Constraints.Constraint_Access is abstract; type Delta_Constraint_Text is limited interface; type Delta_Constraint_Text_Access is access all Delta_Constraint_Text'Class with Storage_Size => 0; not overriding function To_Delta_Constraint_Text (Self : aliased in out Delta_Constraint) return Delta_Constraint_Text_Access is abstract; not overriding function Delta_Token (Self : Delta_Constraint_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Range_Token (Self : Delta_Constraint_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; end Program.Elements.Delta_Constraints;
pragma License (Unrestricted); -- implementation unit required by compiler with System.Unsigned_Types; package System.Wid_LLU is pragma Pure; -- required for Modular'Width by compiler (s-widllu.ads) function Width_Long_Long_Unsigned ( Lo, Hi : Unsigned_Types.Long_Long_Unsigned) return Natural; end System.Wid_LLU;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2010-2011, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.Internals.Strings.Configuration; package body League.Application is procedure Initialize_Arguments_Environment; -- Initialize arguments list and process environment. Args : League.String_Vectors.Universal_String_Vector; Env : League.Environment_Variables.Environment_Variable_Set; App_Name : League.Strings.Universal_String; App_Version : League.Strings.Universal_String; Org_Name : League.Strings.Universal_String; Org_Domain : League.Strings.Universal_String; ---------------------- -- Application_Name -- ---------------------- function Application_Name return League.Strings.Universal_String is begin return App_Name; end Application_Name; ------------------------- -- Application_Version -- ------------------------- function Application_Version return League.Strings.Universal_String is begin return App_Version; end Application_Version; --------------- -- Arguments -- --------------- function Arguments return League.String_Vectors.Universal_String_Vector is begin return Args; end Arguments; ----------------- -- Environment -- ----------------- function Environment return League.Environment_Variables.Environment_Variable_Set is begin return Env; end Environment; -------------------------------------- -- Initialize_Arguments_Environment -- -------------------------------------- procedure Initialize_Arguments_Environment is separate; ------------------------- -- Organization_Domain -- ------------------------- function Organization_Domain return League.Strings.Universal_String is begin return Org_Domain; end Organization_Domain; ----------------------- -- Organization_Name -- ----------------------- function Organization_Name return League.Strings.Universal_String is begin return Org_Name; end Organization_Name; -------------------------- -- Set_Application_Name -- -------------------------- procedure Set_Application_Name (Name : League.Strings.Universal_String) is begin App_Name := Name; end Set_Application_Name; ----------------------------- -- Set_Application_Version -- ----------------------------- procedure Set_Application_Version (Name : League.Strings.Universal_String) is begin App_Version := Name; end Set_Application_Version; ----------------------------- -- Set_Organization_Domain -- ----------------------------- procedure Set_Organization_Domain (Name : League.Strings.Universal_String) is begin Org_Domain := Name; end Set_Organization_Domain; --------------------------- -- Set_Organization_Name -- --------------------------- procedure Set_Organization_Name (Name : League.Strings.Universal_String) is begin Org_Name := Name; end Set_Organization_Name; begin -- Setup most optimal string handler. Matreshka.Internals.Strings.Configuration.Initialize; -- Initialize arguments and environment. Initialize_Arguments_Environment; end League.Application;
with EU_Projects.Nodes.Action_Nodes; with EU_Projects.Nodes.Partners; with EU_Projects.Node_Tables; package EU_Projects.Nodes.Action_Nodes.Tasks is subtype Task_Index is Node_Index; No_Task : constant Extended_Node_Index := No_Index; type Task_Label is new Node_Label; type Project_Task is new Nodes.Action_Nodes.Action_Node with private; type Project_Task_Access is access Project_Task; subtype Task_Intensity is Float range 0.0 .. 1.0; function Image (X : Task_Intensity) return String is (Task_Intensity'Image(X)); function Value (X : String) return Task_Intensity; function Create (Label : Task_Label; Name : String; Short_Name : String; Leader : Partners.Partner_Label; Parent_WP : Node_Access; Description : String; Active_When : Action_Time; Depends_On : Nodes.Node_Label_Lists.Vector; Intensity : Task_Intensity; Node_Dir : in out Node_Tables.Node_Table) return Project_Task_Access with Post => Create'Result.Index = No_Task; -- function Index (Item : Project_Task) return Task_Index; procedure Set_Index (Tsk : in out Project_Task; Idx : Task_Index) with Pre => Tsk.Index = No_Task, Post => Tsk.Index = Idx; function Intensity (Tsk : Project_Task) return Task_Intensity; overriding function Full_Index (Item : Project_Task; Prefixed : Boolean) return String; procedure Add_Dependence (Item : in out Project_Task; Dep : in Task_Label); function Dependency_List (Item : Project_Task) return Node_Label_Lists.Vector; -- -- I use a postcondition to ensure that the access value -- refers to a WP. I need to resort to this form of "weak strong typing" -- in order to avoid circular dependencies. See comments in Nodes. -- function Parent_WP (Item : Project_Task) return Nodes.Node_Access with Post => Parent_WP'Result.Class = WP_Node; private -- package Dependence_Vectors is -- new Ada.Containers.Vectors (Index_Type => Positive, -- Element_Type => Task_Label); type Project_Task is new Nodes.Action_Nodes.Action_Node with record Depend_On : Node_Label_Lists.Vector; Parent : Node_Access; Intensity : Task_Intensity; end record; function Dependency_List (Item : Project_Task) return Node_Label_Lists.Vector is (Item.Depend_On); function Parent_WP (Item : Project_Task) return Nodes.Node_Access is (Item.Parent); overriding function Full_Index (Item : Project_Task; Prefixed : Boolean) return String is ((if Prefixed then "T" else "") & Chop (Node_Index'Image (Item.Parent_WP.Index)) & "." & Chop (Node_Index'Image (Item.Index))); function Intensity (Tsk : Project_Task) return Task_Intensity is (Tsk.Intensity); -- -- function Index (Item : Project_Task) return Task_Index -- is (Task_Index (Item.Index)); -- function Effort_Of (Item : Project_Task; -- Partner : Nodes.Partners.Partner_Label) -- return Efforts.Person_Months -- is (if Item.Partner_Effort.Contains (Partner) then -- Item.Partner_Effort (Partner) -- else -- raise Unknown_Partner); end EU_Projects.Nodes.Action_Nodes.Tasks;
pragma License (Unrestricted); -- implementation unit package Ada.Strings.Naked_Maps.General_Category is pragma Preelaborate; -- General_Category=Unassigned (Cn) function Unassigned return not null Character_Set_Access; function All_Unassigned return not null Character_Set_Access; -- Contains Unassigned + [16#110000# .. Wide_Wide_Character'Last]. -- General_Category=Uppercase_Letter (Lu) function Uppercase_Letter return not null Character_Set_Access; -- General_Category=Lowercase_Letter (Ll) function Lowercase_Letter return not null Character_Set_Access; -- General_Category=Titlecase_Letter (Lt) function Titlecase_Letter return not null Character_Set_Access; -- General_Category=Modifier_Letter (Lm) function Modifier_Letter return not null Character_Set_Access; -- General_Category=Other_Letter (Lo) function Other_Letter return not null Character_Set_Access; -- General_Category=Nonspacing_Mark (Mn) function Nonspacing_Mark return not null Character_Set_Access; -- General_Category=Enclosing_Mark (Me) function Enclosing_Mark return not null Character_Set_Access; -- General_Category=Spacing_Mark (Mc) function Spacing_Mark return not null Character_Set_Access; -- General_Category=Decimal_Number (Nd) function Decimal_Number return not null Character_Set_Access; -- General_Category=Letter_Number (Nl) function Letter_Number return not null Character_Set_Access; -- General_Category=Other_Number (No) function Other_Number return not null Character_Set_Access; -- General_Category=Space_Separator (Zs) function Space_Separator return not null Character_Set_Access; -- General_Category=Line_Separator (Zl) function Line_Separator return not null Character_Set_Access; -- General_Category=Paragraph_Separator (Zp) function Paragraph_Separator return not null Character_Set_Access; -- General_Category=Control (Cc) function Control return not null Character_Set_Access; -- General_Category=Format (Cf) function Format return not null Character_Set_Access; -- General_Category=Private_Use (Co) function Private_Use return not null Character_Set_Access; -- General_Category=Surrogate (Cs) function Surrogate return not null Character_Set_Access; -- General_Category=Dash_Punctuation (Pd) function Dash_Punctuation return not null Character_Set_Access; -- General_Category=Open_Punctuation (Ps) function Open_Punctuation return not null Character_Set_Access; -- General_Category=Close_Punctuation (Pe) function Close_Punctuation return not null Character_Set_Access; -- General_Category=Connector_Punctuation (Pc) function Connector_Punctuation return not null Character_Set_Access; -- General_Category=Other_Punctuation (Po) function Other_Punctuation return not null Character_Set_Access; -- General_Category=Math_Symbol (Sm) function Math_Symbol return not null Character_Set_Access; -- General_Category=Currency_Symbol (Sc) function Currency_Symbol return not null Character_Set_Access; -- General_Category=Modifier_Symbol (Sk) function Modifier_Symbol return not null Character_Set_Access; -- General_Category=Other_Symbol (So) function Other_Symbol return not null Character_Set_Access; -- General_Category=Initial_Punctuation (Pi) function Initial_Punctuation return not null Character_Set_Access; -- General_Category=Final_Punctuation (Pf) function Final_Punctuation return not null Character_Set_Access; end Ada.Strings.Naked_Maps.General_Category;
-- AOC 2020, Day 6 with Ada.Text_IO; use Ada.Text_IO; with Day; use Day; procedure main is anyone : constant Natural := anyone_sum("input.txt"); everyone : constant Natural := everyone_sum("input.txt"); begin put_line("Part 1: " & Natural'Image(anyone)); put_line("Part 2: " & Natural'Image(everyone)); end main;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2021, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ package USB.HAL.Device is type USB_Device_Controller is interface; type Any_USB_Device_Controller is access all USB_Device_Controller'Class; procedure Initialize (This : in out USB_Device_Controller) is abstract; procedure Start (This : in out USB_Device_Controller) is abstract; type UDC_Event_Kind is (None, Reset, Setup_Request, Transfer_Complete); type UDC_Event (Kind : UDC_Event_Kind := None) is record case Kind is when Setup_Request => Req : Setup_Data; Req_EP : EP_Id; when Transfer_Complete => EP : EP_Addr; BCNT : UInt11; -- Byte count (0 .. 1024) when others => null; end case; end record; No_Event : constant UDC_Event := (Kind => None); function Poll (This : in out USB_Device_Controller) return UDC_Event is abstract; procedure Reset (This : in out USB_Device_Controller) is abstract; -- Called when the host resets the device function Request_Buffer (This : in out USB_Device_Controller; Ep : EP_Addr; Len : UInt11; Min_Alignment : UInt8 := 1) return System.Address is abstract; -- Allocate a buffer for the given End-Point, either from RAM or interal USB -- Controller memory depending on the controller. function Valid_EP_Id (This : in out USB_Device_Controller; EP : EP_Id) return Boolean is abstract; -- Return True if the given EP is valid for this UDC. This is used by the -- stack to know the number of EPs available. procedure EP_Write_Packet (This : in out USB_Device_Controller; Ep : EP_Id; Addr : System.Address; Len : UInt32) is abstract; procedure EP_Setup (This : in out USB_Device_Controller; EP : EP_Addr; Typ : EP_Type; Max_Size : UInt16) is abstract; procedure EP_Ready_For_Data (This : in out USB_Device_Controller; EP : EP_Id; Addr : System.Address; Max_Len : UInt32; Ready : Boolean := True) is abstract; procedure EP_Stall (This : in out USB_Device_Controller; EP : EP_Addr; Set : Boolean := True) is abstract; procedure Set_Address (This : in out USB_Device_Controller; Addr : UInt7) is abstract; function Early_Address (This : USB_Device_Controller) return Boolean is abstract; -- This function should return True if Set_Address must be called during the -- processing of the SET_ADDRESS setup request instead of at the end of the -- setup request. For some reason, this is required for the USB controller -- of the STM32F series. function Img (Evt : UDC_Event) return String is (case Evt.Kind is when Setup_Request => Evt.Kind'Img & " " & Img (EP_Addr'(Evt.Req_EP, EP_Out)) & " " & Img (Evt.Req), when Transfer_Complete => Evt.Kind'Img & " " & Img (Evt.EP) & " BCNT:" & Evt.BCNT'Img, when others => Evt.Kind'Img); end USB.HAL.Device;
-- -- Copyright (C) 2022 Jeremy Grosser <jeremy@synack.me> -- -- SPDX-License-Identifier: BSD-3-Clause -- package body ADXL345 is function To_Acceleration (G_Range : DATA_FORMAT_G_Range_Field; A : HAL.UInt16) return Acceleration is use HAL; F : Acceleration; begin F := Float (A and 16#7FFF#); if (A and 16#8000#) /= 0 then F := F * (-1.0); end if; F := F / Float (2 ** 15 - 1); case G_Range is when Range_2g => F := F * 2.0; when Range_4g => F := F * 4.0; when Range_8g => F := F * 8.0; when Range_16g => F := F * 16.0; end case; return F; end To_Acceleration; end ADXL345;
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2018 onox <denkpadje@gmail.com> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. with Ada.Exceptions; with Orka.Smart_Pointers; package Orka.Futures is pragma Preelaborate; type Status is (Waiting, Running, Done, Failed) with Default_Value => Waiting; subtype Non_Failed_Status is Status range Waiting .. Done; type Future is synchronized interface; procedure Wait_Until_Done (Object : in out Future; Value : out Status) is abstract with Synchronization => By_Entry; function Current_Status (Object : Future) return Status is abstract; type Future_Access is access all Future'Class; procedure Internal_Release (Value : in out Future_Access); -- This is an internal subprogram and must not be called package Pointers is new Orka.Smart_Pointers (Future'Class, Future_Access, Internal_Release); ----------------------------------------------------------------------------- type Promise is synchronized interface and Future; procedure Set_Status (Object : in out Promise; Value : Non_Failed_Status) is abstract with Synchronization => By_Protected_Procedure; procedure Set_Failed (Object : in out Promise; Reason : Ada.Exceptions.Exception_Occurrence) is abstract with Synchronization => By_Protected_Procedure; private type Releasable_Future is limited interface; procedure Release (Object : Releasable_Future; Slot : not null Future_Access) is abstract; end Orka.Futures;
with STM32_SVD; use STM32_SVD; with STM32_SVD.NVIC; use STM32_SVD.NVIC; with STM32_SVD.SCB; use STM32_SVD.SCB; with STM32_SVD.PWR; use STM32_SVD.PWR; with STM32_SVD.EXTI; use STM32_SVD.EXTI; with STM32_SVD.RCC; use STM32_SVD.RCC; with STM32_SVD.RTC; use STM32_SVD.RTC; package body STM32GD.RTC is Days_Per_Month : constant array (0 .. 12) of Natural := ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); procedure Unlock is begin RTC_Periph.WPR.KEY := 16#CA#; RTC_Periph.WPR.KEY := 16#53#; end Unlock; procedure Lock is begin RTC_Periph.WPR.KEY := 16#FF#; end Lock; procedure Read (Date_Time : out Date_Time_Type) is begin Date_Time.Day := Natural(RTC_Periph.DR.DU) + Natural(RTC_Periph.DR.DT) * 10; Date_Time.Month := Natural(RTC_Periph.DR.MU) + Natural(RTC_Periph.DR.MT) * 10; Date_Time.Year := Natural(RTC_Periph.DR.YU) + Natural(RTC_Periph.DR.YT) * 10; Date_Time.Hour := Natural(RTC_Periph.TR.HU) + Natural(RTC_Periph.TR.HT) * 10; Date_Time.Minute := Natural(RTC_Periph.TR.MNU) + Natural(RTC_Periph.TR.MNT) * 10; Date_Time.Second := Natural(RTC_Periph.TR.SU) + Natural(RTC_Periph.TR.ST) * 10; end Read; procedure Print (Date_Time : Date_Time_Type) is begin -- Put (Integer'Image (Date_Time.Year)); -- Put (Integer'Image (Date_Time.Month)); -- Put (Integer'Image (Date_Time.Day)); -- Put (Integer'Image (Date_Time.Hour)); -- Put (Integer'Image (Date_Time.Minute)); -- Put_Line (Integer'Image (Date_Time.Second)); null; end Print; procedure Add_Seconds (Date_Time : in out Date_Time_Type ; Second_Delta : Second_Delta_Type) is Total_Seconds : Natural; begin Total_Seconds := Date_Time.Second + Date_Time.Minute * 60 + Date_Time.Hour * 60 * 60 + Second_Delta; Date_Time.Second := Total_Seconds mod 60; Date_Time.Minute := Total_Seconds mod (60 * 60) / 60; Date_Time.Hour := Total_Seconds / 3600; if Total_Seconds / (60 * 60) > Hour_Type'Last then Total_Seconds := Total_Seconds - Hour_Type'Last * (60 * 60); end if; Date_Time.Hour := Total_Seconds / (60 * 60); end Add_Seconds; procedure Add_Minutes (Date_Time : in out Date_Time_Type ; Minute_Delta : Minute_Delta_Type) is Total_Minutes : Natural; begin Total_Minutes := Date_Time.Minute + Date_Time.Hour * 60 + Minute_Delta; Date_Time.Minute := Total_Minutes mod 60; if Total_Minutes / 60 > Hour_Type'Last then Total_Minutes := Total_Minutes - Hour_Type'Last * 60; end if; Date_Time.Hour := Total_Minutes / 60; end Add_Minutes; procedure Set_Alarm (Date_Time : Date_Time_Type) is begin Unlock; RTC_Periph.ISR.ALRAF := 0; RTC_Periph.CR.ALRAE := 0; while RTC_Periph.ISR.ALRAWF = 0 loop null; end loop; RTC_Periph.ALRMAR := ( MSK1 => 0, ST => UInt3 (Date_Time.Second / 10), SU => UInt4 (Date_Time.Second mod 10), MSK2 => 0, MNT => UInt3 (Date_Time.Minute / 10), MNU => UInt4 (Date_Time.Minute mod 10), MSK3 => 0, PM => 0, HT => UInt2 (Date_Time.Hour / 10), HU => UInt4 (Date_Time.Hour mod 10), MSK4 => 1, WDSEL => 0, DT => 0, DU => 0); RTC_Periph.CR.ALRAE := 1; RTC_Periph.CR.ALRAIE := 1; Lock; EXTI_Periph.EMR.EM.Arr (17) := 1; EXTI_Periph.RTSR.RT.Arr (17) := 1; end Set_Alarm; procedure Clear_Alarm is ICPR : UInt32; begin ICPR := NVIC_Periph.ICPR; ICPR := ICPR or 2 ** 3; NVIC_Periph.ICPR := ICPR; EXTI_Periph.PR.PIF.Arr (17) := 1; Unlock; RTC_Periph.ISR.ALRAF := 0; RTC_Periph.CR.ALRAE := 0; RTC_Periph.CR.ALRAIE := 0; Lock; end Clear_Alarm; procedure Init is use STM32GD.Clock; begin RCC_Periph.APB1ENR.PWREN := 1; PWR_Periph.CR.DBP := 1; case Clock is when LSE => RCC_Periph.CSR.RTCSEL := 2#01#; pragma Compile_Time_Error (Clock = LSE and not Clock_Tree.LSE_Enabled, "LSE not enabled for RTC"); when LSI => RCC_Periph.CSR.RTCSEL := 2#10#; pragma Compile_Time_Error (Clock = LSI and not Clock_Tree.LSI_Enabled, "LSE not enabled for RTC"); when others => pragma Compile_Time_Error (Clock /= LSI and Clock /= LSE, "RTC clock needs to be LSI or LSE"); end case; RCC_Periph.CSR.RTCEN := 1; end Init; function To_Seconds (Date_Time : Date_Time_Type) return Natural is begin return Date_Time.Second + Date_Time.Minute * 60 + Date_Time.Hour * 60 * 60 + (Date_Time.Day - 1) * 24 * 60 * 60 + Days_Per_Month (Date_Time.Month - 1) * 24 * 60 * 60 + Date_Time.Year * 365 * 24 * 60 * 60; end To_Seconds; procedure Wait_For_Alarm is begin SCB.SCB_Periph.SCR.SEVEONPEND := 1; STM32GD.Wait_For_Event; Clear_Alarm; end Wait_For_Alarm; end STM32GD.RTC;
------------------------------------------------------------------------------ -- AGAR GUI LIBRARY -- -- A G A R . I N I T _ G U I -- -- S p e c -- ------------------------------------------------------------------------------ with Interfaces.C; with Interfaces.C.Strings; package Agar.Init_GUI is package C renames Interfaces.C; package CS renames Interfaces.C.Strings; function Init_Graphics (Driver : in String) return Boolean; function Init_GUI return Boolean; procedure Destroy_Graphics with Import, Convention => C, Link_Name => "AG_DestroyGraphics"; procedure Destroy_GUI with Import, Convention => C, Link_Name => "AG_DestroyGUI"; private use type C.int; function AG_InitGraphics (Driver : in CS.chars_ptr) return C.int with Import, Convention => C, Link_Name => "AG_InitGraphics"; function AG_InitGUI (Flags : in C.unsigned) return C.int with Import, Convention => C, Link_Name => "AG_InitGUI"; end Agar.Init_GUI;
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr> -- MIT license. Please refer to the LICENSE file. generic type Discrete_Type is (<>); package Apsepp.Generic_Discrete_Operations is -- Don't evaluate the pre-conditions in this package. Just let -- Constraint_Error be raised in case of violation. pragma Assertion_Policy (Pre => Ignore); function Fi return Discrete_Type is (Discrete_Type'First); function La return Discrete_Type is (Discrete_Type'Last); function Pr (X : Discrete_Type) return Discrete_Type is (Discrete_Type'Pred (X)) with Pre => X > Fi; function Su (X : Discrete_Type) return Discrete_Type is (Discrete_Type'Succ (X)) with Pre => X < La; end Apsepp.Generic_Discrete_Operations;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Fizzbuzz is Limit : Natural; begin Put_Line ("Enter how far to go for FizzBuzz:"); Get (Limit); for I in 1 .. Limit loop if I mod 3 = 0 and I mod 5 = 0 then Put_Line ("FizzBuzz"); elsif I mod 3 = 0 then Put_Line ("Fizz"); elsif I mod 5 = 0 then Put_Line ("Buzz"); else Put_Line (Integer'Image (I)); end if; end loop; end Fizzbuzz;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- P R J -- -- -- -- S p e c -- -- -- -- Copyright (C) 2001-2005, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- -- Boston, MA 02110-1301, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- The following package declares the data types for GNAT project. -- These data types may be used by GNAT Project-aware tools. -- Children of these package implements various services on these data types. -- See in particular Prj.Pars and Prj.Env. with Casing; use Casing; with Scans; use Scans; with Table; with Types; use Types; with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables; with GNAT.Dynamic_Tables; with GNAT.OS_Lib; use GNAT.OS_Lib; with System.HTable; package Prj is All_Packages : constant String_List_Access; -- Default value of parameter Packages of procedures Parse, in Prj.Pars and -- Prj.Part, indicating that all packages should be checked. type Project_Tree_Data; type Project_Tree_Ref is access all Project_Tree_Data; -- Reference to a project tree. -- Several project trees may exist in memory at the same time. No_Project_Tree : constant Project_Tree_Ref; function Default_Ada_Spec_Suffix return Name_Id; pragma Inline (Default_Ada_Spec_Suffix); -- The Name_Id for the standard GNAT suffix for Ada spec source file -- name ".ads". Initialized by Prj.Initialize. function Default_Ada_Body_Suffix return Name_Id; pragma Inline (Default_Ada_Body_Suffix); -- The Name_Id for the standard GNAT suffix for Ada body source file -- name ".adb". Initialized by Prj.Initialize. function Slash return Name_Id; pragma Inline (Slash); -- "/", used as the path of locally removed files Project_File_Extension : String := ".gpr"; -- The standard project file name extension. It is not a constant, because -- Canonical_Case_File_Name is called on this variable in the body of Prj. type Error_Warning is (Silent, Warning, Error); -- Severity of some situations, such as: no Ada sources in a project where -- Ada is one of the language. -- -- When the situation occurs, the behaviour depends on the setting: -- -- - Silent: no action -- - Warning: issue a warning, does not cause the tool to fail -- - Error: issue an error, causes the tool to fail ----------------------------------------------------- -- Multi-language Stuff That Will be Modified Soon -- ----------------------------------------------------- -- Still should be properly commented ??? type Language_Index is new Nat; No_Language_Index : constant Language_Index := 0; First_Language_Index : constant Language_Index := 1; First_Language_Indexes_Last : constant Language_Index := 5; Ada_Language_Index : constant Language_Index := First_Language_Index; C_Language_Index : constant Language_Index := Ada_Language_Index + 1; C_Plus_Plus_Language_Index : constant Language_Index := C_Language_Index + 1; Last_Language_Index : Language_Index := No_Language_Index; subtype First_Language_Indexes is Language_Index range First_Language_Index .. First_Language_Indexes_Last; type Header_Num is range 0 .. 2047; function Hash is new System.HTable.Hash (Header_Num => Header_Num); function Hash (Name : Name_Id) return Header_Num; package Language_Indexes is new System.HTable.Simple_HTable (Header_Num => Header_Num, Element => Language_Index, No_Element => No_Language_Index, Key => Name_Id, Hash => Hash, Equal => "="); -- Mapping of language names to language indexes package Language_Names is new Table.Table (Table_Component_Type => Name_Id, Table_Index_Type => Language_Index, Table_Low_Bound => 1, Table_Initial => 4, Table_Increment => 100, Table_Name => "Prj.Language_Names"); -- The table for the name of programming languages procedure Add_Language_Name (Name : Name_Id); procedure Display_Language_Name (Language : Language_Index); type Languages_In_Project is array (First_Language_Indexes) of Boolean; -- Set of supported languages used in a project No_Languages : constant Languages_In_Project := (others => False); -- No supported languages are used type Supp_Language_Index is new Nat; No_Supp_Language_Index : constant Supp_Language_Index := 0; type Supp_Language is record Index : Language_Index := No_Language_Index; Present : Boolean := False; Next : Supp_Language_Index := No_Supp_Language_Index; end record; package Present_Language_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Supp_Language, Table_Index_Type => Supp_Language_Index, Table_Low_Bound => 1, Table_Initial => 4, Table_Increment => 100); -- The table for the presence of languages with an index that is outside -- of First_Language_Indexes. type Impl_Suffix_Array is array (First_Language_Indexes) of Name_Id; -- Suffixes for the non spec sources of the different supported languages -- in a project. No_Impl_Suffixes : constant Impl_Suffix_Array := (others => No_Name); -- A default value for the non spec source suffixes type Supp_Suffix is record Index : Language_Index := No_Language_Index; Suffix : Name_Id := No_Name; Next : Supp_Language_Index := No_Supp_Language_Index; end record; package Supp_Suffix_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Supp_Suffix, Table_Index_Type => Supp_Language_Index, Table_Low_Bound => 1, Table_Initial => 4, Table_Increment => 100); -- The table for the presence of languages with an index that is outside -- of First_Language_Indexes. type Language_Kind is (GNU, other); type Name_List_Index is new Nat; No_Name_List : constant Name_List_Index := 0; type Name_Node is record Name : Name_Id := No_Name; Next : Name_List_Index := No_Name_List; end record; package Name_List_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Name_Node, Table_Index_Type => Name_List_Index, Table_Low_Bound => 1, Table_Initial => 10, Table_Increment => 100); -- The table for lists of names used in package Language_Processing type Language_Processing_Data is record Compiler_Drivers : Name_List_Index := No_Name_List; Compiler_Paths : Name_Id := No_Name; Compiler_Kinds : Language_Kind := GNU; Dependency_Options : Name_List_Index := No_Name_List; Compute_Dependencies : Name_List_Index := No_Name_List; Include_Options : Name_List_Index := No_Name_List; Binder_Drivers : Name_Id := No_Name; Binder_Driver_Paths : Name_Id := No_Name; end record; Default_Language_Processing_Data : constant Language_Processing_Data := (Compiler_Drivers => No_Name_List, Compiler_Paths => No_Name, Compiler_Kinds => GNU, Dependency_Options => No_Name_List, Compute_Dependencies => No_Name_List, Include_Options => No_Name_List, Binder_Drivers => No_Name, Binder_Driver_Paths => No_Name); type First_Language_Processing_Data is array (First_Language_Indexes) of Language_Processing_Data; Default_First_Language_Processing_Data : constant First_Language_Processing_Data := (others => Default_Language_Processing_Data); type Supp_Language_Data is record Index : Language_Index := No_Language_Index; Data : Language_Processing_Data := Default_Language_Processing_Data; Next : Supp_Language_Index := No_Supp_Language_Index; end record; package Supp_Language_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Supp_Language_Data, Table_Index_Type => Supp_Language_Index, Table_Low_Bound => 1, Table_Initial => 4, Table_Increment => 100); -- The table for language data when there are more languages than -- in First_Language_Indexes. type Other_Source_Id is new Nat; No_Other_Source : constant Other_Source_Id := 0; type Other_Source is record Language : Language_Index; -- language of the source File_Name : Name_Id; -- source file simple name Path_Name : Name_Id; -- source full path name Source_TS : Time_Stamp_Type; -- source file time stamp Object_Name : Name_Id; -- object file simple name Object_Path : Name_Id; -- object full path name Object_TS : Time_Stamp_Type; -- object file time stamp Dep_Name : Name_Id; -- dependency file simple name Dep_Path : Name_Id; -- dependency full path name Dep_TS : Time_Stamp_Type; -- dependency file time stamp Naming_Exception : Boolean := False; -- True if a naming exception Next : Other_Source_Id := No_Other_Source; end record; -- Data for a source in a language other than Ada package Other_Source_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Other_Source, Table_Index_Type => Other_Source_Id, Table_Low_Bound => 1, Table_Initial => 200, Table_Increment => 100); -- The table for sources of languages other than Ada ---------------------------------- -- End of multi-language stuff -- ---------------------------------- type Verbosity is (Default, Medium, High); -- Verbosity when parsing GNAT Project Files -- Default is default (very quiet, if no errors). -- Medium is more verbose. -- High is extremely verbose. Current_Verbosity : Verbosity := Default; -- The current value of the verbosity the project files are parsed with type Lib_Kind is (Static, Dynamic, Relocatable); type Policy is (Autonomous, Compliant, Controlled, Restricted); -- Type to specify the symbol policy, when symbol control is supported. -- See full explanation about this type in package Symbols. -- Autonomous: Create a symbol file without considering any reference -- Compliant: Try to be as compatible as possible with an existing ref -- Controlled: Fail if symbols are not the same as those in the reference -- Restricted: Restrict the symbols to those in the symbol file type Symbol_Record is record Symbol_File : Name_Id := No_Name; Reference : Name_Id := No_Name; Symbol_Policy : Policy := Autonomous; end record; -- Type to keep the symbol data to be used when building a shared library No_Symbols : constant Symbol_Record := (Symbol_File => No_Name, Reference => No_Name, Symbol_Policy => Autonomous); -- The default value of the symbol data function Empty_String return Name_Id; -- Return the Name_Id for an empty string "" type Project_Id is new Nat; No_Project : constant Project_Id := 0; -- Id of a Project File type String_List_Id is new Nat; Nil_String : constant String_List_Id := 0; type String_Element is record Value : Name_Id := No_Name; Index : Int := 0; Display_Value : Name_Id := No_Name; Location : Source_Ptr := No_Location; Flag : Boolean := False; Next : String_List_Id := Nil_String; end record; -- To hold values for string list variables and array elements. -- Component Flag may be used for various purposes. For source -- directories, it indicates if the directory contains Ada source(s). package String_Element_Table is new GNAT.Dynamic_Tables (Table_Component_Type => String_Element, Table_Index_Type => String_List_Id, Table_Low_Bound => 1, Table_Initial => 200, Table_Increment => 100); -- The table for string elements in string lists type Variable_Kind is (Undefined, List, Single); -- Different kinds of variables subtype Defined_Variable_Kind is Variable_Kind range List .. Single; -- The defined kinds of variables Ignored : constant Variable_Kind; -- Used to indicate that a package declaration must be ignored -- while processing the project tree (unknown package name). type Variable_Value (Kind : Variable_Kind := Undefined) is record Project : Project_Id := No_Project; Location : Source_Ptr := No_Location; Default : Boolean := False; case Kind is when Undefined => null; when List => Values : String_List_Id := Nil_String; when Single => Value : Name_Id := No_Name; Index : Int := 0; end case; end record; -- Values for variables and array elements. Default is True if the -- current value is the default one for the variable Nil_Variable_Value : constant Variable_Value; -- Value of a non existing variable or array element type Variable_Id is new Nat; No_Variable : constant Variable_Id := 0; type Variable is record Next : Variable_Id := No_Variable; Name : Name_Id; Value : Variable_Value; end record; -- To hold the list of variables in a project file and in packages package Variable_Element_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Variable, Table_Index_Type => Variable_Id, Table_Low_Bound => 1, Table_Initial => 200, Table_Increment => 100); -- The table of variable in list of variables type Array_Element_Id is new Nat; No_Array_Element : constant Array_Element_Id := 0; type Array_Element is record Index : Name_Id; Src_Index : Int := 0; Index_Case_Sensitive : Boolean := True; Value : Variable_Value; Next : Array_Element_Id := No_Array_Element; end record; -- Each Array_Element represents an array element and is linked (Next) -- to the next array element, if any, in the array. package Array_Element_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Array_Element, Table_Index_Type => Array_Element_Id, Table_Low_Bound => 1, Table_Initial => 200, Table_Increment => 100); -- The table that contains all array elements type Array_Id is new Nat; No_Array : constant Array_Id := 0; type Array_Data is record Name : Name_Id := No_Name; Value : Array_Element_Id := No_Array_Element; Next : Array_Id := No_Array; end record; -- Each Array_Data value represents an array. -- Value is the id of the first element. -- Next is the id of the next array in the project file or package. package Array_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Array_Data, Table_Index_Type => Array_Id, Table_Low_Bound => 1, Table_Initial => 200, Table_Increment => 100); -- The table that contains all arrays type Package_Id is new Nat; No_Package : constant Package_Id := 0; type Declarations is record Variables : Variable_Id := No_Variable; Attributes : Variable_Id := No_Variable; Arrays : Array_Id := No_Array; Packages : Package_Id := No_Package; end record; -- Contains the declarations (variables, single and array attributes, -- packages) for a project or a package in a project. No_Declarations : constant Declarations := (Variables => No_Variable, Attributes => No_Variable, Arrays => No_Array, Packages => No_Package); -- Default value of Declarations: indicates that there is no declarations type Package_Element is record Name : Name_Id := No_Name; Decl : Declarations := No_Declarations; Parent : Package_Id := No_Package; Next : Package_Id := No_Package; end record; -- A package (includes declarations that may include other packages) package Package_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Package_Element, Table_Index_Type => Package_Id, Table_Low_Bound => 1, Table_Initial => 100, Table_Increment => 100); -- The table that contains all packages function Image (Casing : Casing_Type) return String; -- Similar to 'Image (but avoid use of this attribute in compiler) function Value (Image : String) return Casing_Type; -- Similar to 'Value (but avoid use of this attribute in compiler) -- Raises Constraint_Error if not a Casing_Type image. -- The following record contains data for a naming scheme type Naming_Data is record Dot_Replacement : Name_Id := No_Name; -- The string to replace '.' in the source file name (for Ada) Dot_Repl_Loc : Source_Ptr := No_Location; -- The position in the project file source where Dot_Replacement is -- defined. Casing : Casing_Type := All_Lower_Case; -- The casing of the source file name (for Ada) Spec_Suffix : Array_Element_Id := No_Array_Element; -- The string to append to the unit name for the -- source file name of a spec. -- Indexed by the programming language. Ada_Spec_Suffix : Name_Id := No_Name; -- The suffix of the Ada spec sources Spec_Suffix_Loc : Source_Ptr := No_Location; -- The position in the project file source where -- Ada_Spec_Suffix is defined. Impl_Suffixes : Impl_Suffix_Array := No_Impl_Suffixes; Supp_Suffixes : Supp_Language_Index := No_Supp_Language_Index; -- The source suffixes of the different languages Body_Suffix : Array_Element_Id := No_Array_Element; -- The string to append to the unit name for the -- source file name of a body. -- Indexed by the programming language. Ada_Body_Suffix : Name_Id := No_Name; -- The suffix of the Ada body sources Body_Suffix_Loc : Source_Ptr := No_Location; -- The position in the project file source where -- Ada_Body_Suffix is defined. Separate_Suffix : Name_Id := No_Name; -- String to append to unit name for source file name of an Ada subunit Sep_Suffix_Loc : Source_Ptr := No_Location; -- Position in the project file source where Separate_Suffix is defined Specs : Array_Element_Id := No_Array_Element; -- An associative array mapping individual specs to source file names -- This is specific to Ada. Bodies : Array_Element_Id := No_Array_Element; -- An associative array mapping individual bodies to source file names -- This is specific to Ada. Specification_Exceptions : Array_Element_Id := No_Array_Element; -- An associative array listing spec file names that do not have the -- spec suffix. Not used by Ada. Indexed by programming language name. Implementation_Exceptions : Array_Element_Id := No_Array_Element; -- An associative array listing body file names that do not have the -- body suffix. Not used by Ada. Indexed by programming language name. end record; function Standard_Naming_Data (Tree : Project_Tree_Ref := No_Project_Tree) return Naming_Data; pragma Inline (Standard_Naming_Data); -- The standard GNAT naming scheme when Tree is No_Project_Tree. -- Otherwise, return the default naming scheme for the project tree Tree, -- which must have been Initialized. function Same_Naming_Scheme (Left, Right : Naming_Data) return Boolean; -- Returns True if Left and Right are the same naming scheme -- not considering Specs and Bodies. type Project_List is new Nat; Empty_Project_List : constant Project_List := 0; -- A list of project files type Project_Element is record Project : Project_Id := No_Project; Next : Project_List := Empty_Project_List; end record; -- Element in a list of project files. Next is the id of the next -- project file in the list. package Project_List_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Project_Element, Table_Index_Type => Project_List, Table_Low_Bound => 1, Table_Initial => 100, Table_Increment => 100); -- The table that contains the lists of project files -- The following record describes a project file representation type Project_Data is record Externally_Built : Boolean := False; Languages : Languages_In_Project := No_Languages; Supp_Languages : Supp_Language_Index := No_Supp_Language_Index; -- Indicate the different languages of the source of this project First_Referred_By : Project_Id := No_Project; -- The project, if any, that was the first to be known as importing or -- extending this project. Set by Prj.Proc.Process. Name : Name_Id := No_Name; -- The name of the project. Set by Prj.Proc.Process Display_Name : Name_Id := No_Name; -- The name of the project with the spelling of its declaration. -- Set by Prj.Proc.Process. Path_Name : Name_Id := No_Name; -- The path name of the project file. Set by Prj.Proc.Process Display_Path_Name : Name_Id := No_Name; -- The path name used for display purposes. May be different from -- Path_Name for platforms where the file names are case-insensitive. Virtual : Boolean := False; -- True for virtual extending projects Location : Source_Ptr := No_Location; -- The location in the project file source of the reserved word -- project. Set by Prj.Proc.Process. Mains : String_List_Id := Nil_String; -- List of mains specified by attribute Main. Set by Prj.Nmsc.Check Directory : Name_Id := No_Name; -- Directory where the project file resides. Set by Prj.Proc.Process Display_Directory : Name_Id := No_Name; -- comment ??? Dir_Path : String_Access; -- Same as Directory, but as an access to String. Set by -- Make.Compile_Sources.Collect_Arguments_And_Compile. Library : Boolean := False; -- True if this is a library project. Set by -- Prj.Nmsc.Language_Independent_Check. Library_Dir : Name_Id := No_Name; -- If a library project, directory where resides the library Set by -- Prj.Nmsc.Language_Independent_Check. Display_Library_Dir : Name_Id := No_Name; -- The name of the library directory, for display purposes. May be -- different from Library_Dir for platforms where the file names are -- case-insensitive. Library_TS : Time_Stamp_Type := Empty_Time_Stamp; -- The timestamp of a library file in a library project. -- Set by MLib.Prj.Check_Library. Library_Src_Dir : Name_Id := No_Name; -- If a Stand-Alone Library project, directory where the sources -- of the interfaces of the library are copied. By default, if -- attribute Library_Src_Dir is not specified, sources of the interfaces -- are not copied anywhere. Set by Prj.Nmsc.Check_Stand_Alone_Library. Display_Library_Src_Dir : Name_Id := No_Name; -- The name of the library source directory, for display purposes. -- May be different from Library_Src_Dir for platforms where the file -- names are case-insensitive. Library_ALI_Dir : Name_Id := No_Name; -- In a library project, directory where the ALI files are copied. -- If attribute Library_ALI_Dir is not specified, ALI files are -- copied in the Library_Dir. Set by Prj.Nmsc.Check_Library_Attributes. Display_Library_ALI_Dir : Name_Id := No_Name; -- The name of the library ALI directory, for display purposes. May be -- different from Library_ALI_Dir for platforms where the file names are -- case-insensitive. Library_Name : Name_Id := No_Name; -- If a library project, name of the library -- Set by Prj.Nmsc.Language_Independent_Check. Library_Kind : Lib_Kind := Static; -- If a library project, kind of library -- Set by Prj.Nmsc.Language_Independent_Check. Lib_Internal_Name : Name_Id := No_Name; -- If a library project, internal name store inside the library Set by -- Prj.Nmsc.Language_Independent_Check. Standalone_Library : Boolean := False; -- Indicate that this is a Standalone Library Project File. Set by -- Prj.Nmsc.Check. Lib_Interface_ALIs : String_List_Id := Nil_String; -- For Standalone Library Project Files, indicate the list of Interface -- ALI files. Set by Prj.Nmsc.Check. Lib_Auto_Init : Boolean := False; -- For non static Standalone Library Project Files, indicate if -- the library initialisation should be automatic. Symbol_Data : Symbol_Record := No_Symbols; -- Symbol file name, reference symbol file name, symbol policy Ada_Sources_Present : Boolean := True; -- A flag that indicates if there are Ada sources in this project file. -- There are no sources if any of the following is true: -- 1) Source_Dirs is specified as an empty list -- 2) Source_Files is specified as an empty list -- 3) Ada is not in the list of the specified Languages Other_Sources_Present : Boolean := True; -- A flag that indicates that there are non-Ada sources in this project Sources : String_List_Id := Nil_String; -- The list of all the source file names. -- Set by Prj.Nmsc.Check_Ada_Naming_Scheme. First_Other_Source : Other_Source_Id := No_Other_Source; Last_Other_Source : Other_Source_Id := No_Other_Source; -- Head and tail of the list of sources of languages other than Ada Imported_Directories_Switches : Argument_List_Access := null; -- List of the -I switches to be used when compiling sources of -- languages other than Ada. Include_Path : String_Access := null; -- Value to be used as CPATH, when using a GCC, instead of a list of -- -I switches. Include_Data_Set : Boolean := False; -- Set True when Imported_Directories_Switches or Include_Path are set Source_Dirs : String_List_Id := Nil_String; -- The list of all the source directories. -- Set by Prj.Nmsc.Language_Independent_Check. Known_Order_Of_Source_Dirs : Boolean := True; -- False, if there is any /** in the Source_Dirs, because in this case -- the ordering of the source subdirs depend on the OS. If True, -- duplicate file names in the same project file are allowed. Object_Directory : Name_Id := No_Name; -- The object directory of this project file. -- Set by Prj.Nmsc.Language_Independent_Check. Display_Object_Dir : Name_Id := No_Name; -- The name of the object directory, for display purposes. -- May be different from Object_Directory for platforms where the file -- names are case-insensitive. Exec_Directory : Name_Id := No_Name; -- The exec directory of this project file. Default is equal to -- Object_Directory. Set by Prj.Nmsc.Language_Independent_Check. Display_Exec_Dir : Name_Id := No_Name; -- The name of the exec directory, for display purposes. May be -- different from Exec_Directory for platforms where the file names are -- case-insensitive. Extends : Project_Id := No_Project; -- The reference of the project file, if any, that this project file -- extends. Set by Prj.Proc.Process. Extended_By : Project_Id := No_Project; -- The reference of the project file, if any, that extends this project -- file. Set by Prj.Proc.Process. Naming : Naming_Data := Standard_Naming_Data; -- The naming scheme of this project file. -- Set by Prj.Nmsc.Check_Naming_Scheme. First_Language_Processing : First_Language_Processing_Data := Default_First_Language_Processing_Data; -- Comment needed ??? Supp_Language_Processing : Supp_Language_Index := No_Supp_Language_Index; -- Comment needed Default_Linker : Name_Id := No_Name; Default_Linker_Path : Name_Id := No_Name; Decl : Declarations := No_Declarations; -- The declarations (variables, attributes and packages) of this -- project file. Set by Prj.Proc.Process. Imported_Projects : Project_List := Empty_Project_List; -- The list of all directly imported projects, if any. Set by -- Prj.Proc.Process. All_Imported_Projects : Project_List := Empty_Project_List; -- The list of all projects imported directly or indirectly, if any. -- Set by Make.Initialize. Ada_Include_Path : String_Access := null; -- The cached value of ADA_INCLUDE_PATH for this project file. Do not -- use this field directly outside of the compiler, use -- Prj.Env.Ada_Include_Path instead. Set by Prj.Env.Ada_Include_Path. Ada_Objects_Path : String_Access := null; -- The cached value of ADA_OBJECTS_PATH for this project file. Do not -- use this field directly outside of the compiler, use -- Prj.Env.Ada_Objects_Path instead. Set by Prj.Env.Ada_Objects_Path Include_Path_File : Name_Id := No_Name; -- The cached value of the source path temp file for this project file. -- Set by gnatmake (Prj.Env.Set_Ada_Paths). Objects_Path_File_With_Libs : Name_Id := No_Name; -- The cached value of the object path temp file (including library -- dirs) for this project file. Set by gnatmake (Prj.Env.Set_Ada_Paths). Objects_Path_File_Without_Libs : Name_Id := No_Name; -- The cached value of the object path temp file (excluding library -- dirs) for this project file. Set by gnatmake (Prj.Env.Set_Ada_Paths). Config_File_Name : Name_Id := No_Name; -- The name of the configuration pragmas file, if any. -- Set by gnatmake (Prj.Env.Create_Config_Pragmas_File). Config_File_Temp : Boolean := False; -- An indication that the configuration pragmas file is -- a temporary file that must be deleted at the end. -- Set by gnatmake (Prj.Env.Create_Config_Pragmas_File). Config_Checked : Boolean := False; -- A flag to avoid checking repetitively the configuration pragmas file. -- Set by gnatmake (Prj.Env.Create_Config_Pragmas_File). Language_Independent_Checked : Boolean := False; -- A flag that indicates that the project file has been checked -- for language independent features: Object_Directory, -- Source_Directories, Library, non empty Naming Suffixes. Checked : Boolean := False; -- A flag to avoid checking repetitively the naming scheme of -- this project file. Set by Prj.Nmsc.Check_Ada_Naming_Scheme. Seen : Boolean := False; -- A flag to mark a project as "visited" to avoid processing the same -- project several time. Need_To_Build_Lib : Boolean := False; -- Indicates that the library of a Library Project needs to be built or -- rebuilt. Depth : Natural := 0; -- The maximum depth of a project in the project graph. -- Depth of main project is 0. Unkept_Comments : Boolean := False; -- True if there are comments in the project sources that cannot -- be kept in the project tree. end record; function Empty_Project (Tree : Project_Tree_Ref) return Project_Data; -- Return the representation of an empty project in project Tree tree. -- The project tree Tree must have been Initialized and/or Reset. Project_Error : exception; -- Raised by some subprograms in Prj.Attr package Project_Table is new GNAT.Dynamic_Tables ( Table_Component_Type => Project_Data, Table_Index_Type => Project_Id, Table_Low_Bound => 1, Table_Initial => 100, Table_Increment => 100); -- The set of all project files type Spec_Or_Body is (Specification, Body_Part); type File_Name_Data is record Name : Name_Id := No_Name; Index : Int := 0; Display_Name : Name_Id := No_Name; Path : Name_Id := No_Name; Display_Path : Name_Id := No_Name; Project : Project_Id := No_Project; Needs_Pragma : Boolean := False; end record; -- File and Path name of a spec or body type File_Names_Data is array (Spec_Or_Body) of File_Name_Data; type Unit_Id is new Nat; No_Unit : constant Unit_Id := 0; type Unit_Data is record Name : Name_Id := No_Name; File_Names : File_Names_Data; end record; -- Name and File and Path names of a unit, with a reference to its -- GNAT Project File(s). package Unit_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Unit_Data, Table_Index_Type => Unit_Id, Table_Low_Bound => 1, Table_Initial => 100, Table_Increment => 100); -- Table of all units in a project tree package Units_Htable is new Simple_HTable (Header_Num => Header_Num, Element => Unit_Id, No_Element => No_Unit, Key => Name_Id, Hash => Hash, Equal => "="); -- Mapping of unit names to indexes in the Units table type Unit_Project is record Unit : Unit_Id := No_Unit; Project : Project_Id := No_Project; end record; No_Unit_Project : constant Unit_Project := (No_Unit, No_Project); package Files_Htable is new Simple_HTable (Header_Num => Header_Num, Element => Unit_Project, No_Element => No_Unit_Project, Key => Name_Id, Hash => Hash, Equal => "="); -- Mapping of file names to indexes in the Units table type Private_Project_Tree_Data is private; -- Data for a project tree that is used only by the Project Manager type Project_Tree_Data is record Present_Languages : Present_Language_Table.Instance; Supp_Suffixes : Supp_Suffix_Table.Instance; Name_Lists : Name_List_Table.Instance; Supp_Languages : Supp_Language_Table.Instance; Other_Sources : Other_Source_Table.Instance; String_Elements : String_Element_Table.Instance; Variable_Elements : Variable_Element_Table.Instance; Array_Elements : Array_Element_Table.Instance; Arrays : Array_Table.Instance; Packages : Package_Table.Instance; Project_Lists : Project_List_Table.Instance; Projects : Project_Table.Instance; Units : Unit_Table.Instance; Units_HT : Units_Htable.Instance; Files_HT : Files_Htable.Instance; Private_Part : Private_Project_Tree_Data; end record; -- Data for a project tree type Put_Line_Access is access procedure (Line : String; Project : Project_Id; In_Tree : Project_Tree_Ref); -- Use to customize error reporting in Prj.Proc and Prj.Nmsc procedure Expect (The_Token : Token_Type; Token_Image : String); -- Check that the current token is The_Token. If it is not, then -- output an error message. procedure Initialize (Tree : Project_Tree_Ref); -- This procedure must be called before using any services from the Prj -- hierarchy. Namet.Initialize must be called before Prj.Initialize. procedure Reset (Tree : Project_Tree_Ref); -- This procedure resets all the tables that are used when processing a -- project file tree. Initialize must be called before the call to Reset. procedure Register_Default_Naming_Scheme (Language : Name_Id; Default_Spec_Suffix : Name_Id; Default_Body_Suffix : Name_Id; In_Tree : Project_Tree_Ref); -- Register the default suffixes for a given language. These extensions -- will be ignored if the user has specified a new naming scheme in a -- project file. -- -- Otherwise, this information will be automatically added to Naming_Data -- when a project is processed, in the lists Spec_Suffix and Body_Suffix. generic type State is limited private; with procedure Action (Project : Project_Id; With_State : in out State); procedure For_Every_Project_Imported (By : Project_Id; In_Tree : Project_Tree_Ref; With_State : in out State); -- Call Action for each project imported directly or indirectly by project -- By. Action is called according to the order of importation: if A -- imports B, directly or indirectly, Action will be called for A before -- it is called for B. If two projects import each other directly or -- indirectly (using at least one "limited with"), it is not specified -- for which of these two projects Action will be called first. Projects -- that are extended by other projects are not considered. With_State may -- be used by Action to choose a behavior or to report some global result. ---------------------------------------------------------- -- Other multi-language stuff that may be modified soon -- ---------------------------------------------------------- function Is_Present (Language : Language_Index; In_Project : Project_Data; In_Tree : Project_Tree_Ref) return Boolean; -- Return True when Language is one of the languages used in -- project In_Project. procedure Set (Language : Language_Index; Present : Boolean; In_Project : in out Project_Data; In_Tree : Project_Tree_Ref); -- Indicate if Language is or not a language used in project In_Project function Language_Processing_Data_Of (Language : Language_Index; In_Project : Project_Data; In_Tree : Project_Tree_Ref) return Language_Processing_Data; -- Return the Language_Processing_Data for language Language in project -- In_Project. Return the default when no Language_Processing_Data are -- defined for the language. procedure Set (Language_Processing : Language_Processing_Data; For_Language : Language_Index; In_Project : in out Project_Data; In_Tree : Project_Tree_Ref); -- Set the Language_Processing_Data for language Language in project -- In_Project. function Suffix_Of (Language : Language_Index; In_Project : Project_Data; In_Tree : Project_Tree_Ref) return Name_Id; -- Return the suffix for language Language in project In_Project. Return -- No_Name when no suffix is defined for the language. procedure Set (Suffix : Name_Id; For_Language : Language_Index; In_Project : in out Project_Data; In_Tree : Project_Tree_Ref); -- Set the suffix for language Language in project In_Project private All_Packages : constant String_List_Access := null; No_Project_Tree : constant Project_Tree_Ref := null; Ignored : constant Variable_Kind := Single; Nil_Variable_Value : constant Variable_Value := (Project => No_Project, Kind => Undefined, Location => No_Location, Default => False); Virtual_Prefix : constant String := "v$"; -- The prefix for virtual extending projects. Because of the '$', which is -- normally forbidden for project names, there cannot be any name clash. Empty_Name : Name_Id; -- Name_Id for an empty name (no characters). Initialized by the call -- to procedure Initialize. procedure Add_To_Buffer (S : String; To : in out String_Access; Last : in out Natural); -- Append a String to the Buffer type Naming_Id is new Nat; package Naming_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Naming_Data, Table_Index_Type => Naming_Id, Table_Low_Bound => 1, Table_Initial => 5, Table_Increment => 100); -- Comment ??? package Path_File_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Name_Id, Table_Index_Type => Natural, Table_Low_Bound => 1, Table_Initial => 50, Table_Increment => 50); -- Table storing all the temp path file names. -- Used by Delete_All_Path_Files. package Source_Path_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Name_Id, Table_Index_Type => Natural, Table_Low_Bound => 1, Table_Initial => 50, Table_Increment => 50); -- A table to store the source dirs before creating the source path file package Object_Path_Table is new GNAT.Dynamic_Tables (Table_Component_Type => Name_Id, Table_Index_Type => Natural, Table_Low_Bound => 1, Table_Initial => 50, Table_Increment => 50); -- A table to store the object dirs, before creating the object path file type Private_Project_Tree_Data is record Namings : Naming_Table.Instance; Path_Files : Path_File_Table.Instance; Source_Paths : Source_Path_Table.Instance; Object_Paths : Object_Path_Table.Instance; Default_Naming : Naming_Data; end record; -- Comment ??? end Prj;
-- ----------------------------------------------------------------- -- -- -- -- This is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This software 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 along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, USA. -- -- -- -- ----------------------------------------------------------------- -- -- ----------------------------------------------------------------- -- -- This is a translation, to the Ada programming language, of the -- -- original C test files written by Sam Lantinga - www.libsdl.org -- -- translation made by Antonio F. Vargas - www.adapower.net/~avargas -- -- ----------------------------------------------------------------- -- -- ----------------------------------------------------------------- -- -- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING -- ----------------------------------------------------------------- -- -- SERIOUS WARNING: The Ada code in this files may, at some points, -- rely directly on pointer arithmetic which is considered very -- unsafe and PRONE TO ERROR. The AdaSDL_Framebuffer examples are -- more appropriate and easier to understand. They should be used in -- replacement of this files. Please go there. -- This file exists only for the sake of completness and to test -- AdaSDL without the dependency of AdaSDL_Framebuffer. -- ----------------------------------------------------------------- -- -- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING -- ----------------------------------------------------------------- -- with Interfaces.C.Pointers; with GNAT.OS_Lib; with SDL.Types; use SDL.Types; with SDL.Error; use SDL.Error; with Ada.Text_IO; use Ada.Text_IO; package body TestPalette_Sprogs is package It renames Interfaces; package Er renames SDL.Error; use SDL.Types.Uint8_Ptrs; use SDL.Types.Uint8_PtrOps; use type C.int; use type V.Surface_ptr; use Random_Integer; -- ====================================== procedure sdlerr (when_err : String) is begin Put_Line ("SDL error: " & when_err & " : " & Er.Get_Error); GNAT.OS_Lib.OS_Exit (1); end sdlerr; -- ====================================== -- create a background surface function make_bg (screen : V.Surface_ptr; startcol : C.int) return V.Surface_ptr is bg : V.Surface_ptr := V.CreateRGBSurface ( V.SWSURFACE, screen.w, screen.h, 8, 0, 0, 0, 0); begin if bg = null then sdlerr ("creating background surface"); end if; -- set the palette to the logical screen palette so that blits -- won't be translated V.SetColors (bg, screen.format.palette.colors, 0, 256); -- Make a wavy background pattern using colours 0-63 if V.LockSurface (bg) < 0 then sdlerr ("locking background"); end if; for i in 0 .. SCRH - 1 loop declare p : Uint8_Ptrs.Object_Pointer; d : C.int; begin p := Object_Pointer ( Pointer ( To_Pointer (bg.pixels)) + C.ptrdiff_t (i * Integer (bg.pitch))); d := 0; for j in 0 .. SCRW - 1 loop declare v : C.int := C.int'Max (d, -2); use Interfaces; begin v := C.int'Min (v, 2); if i > 0 then -- ? v := v + C.int (Object_Pointer ( Uint8_PtrOps.Pointer (p) - C.ptrdiff_t (bg.pitch) ).all) + 65 - startcol; end if; Object_Pointer ( Uint8_PtrOps.Pointer (p) + C.ptrdiff_t (j) ).all := Uint8 ( startcol + C.int ( (Unsigned_32 (v) and Unsigned_32 (63)))); d := d + C.int ( It.Shift_Right ( It.Unsigned_32 (Random (Integer_Generator)), 3) mod 3) - 1; end; end loop; end; end loop; V.UnlockSurface (bg); return bg; end make_bg; -- ====================================== -- Return a surface flipped horisontally. Only works for 8bpp; -- extensions to arbitrary bitness is left as an exercise for -- reader. function hflip (s : V.Surface_ptr) return V.Surface_ptr is z : V.Surface_ptr := V.CreateRGBSurface (V.SWSURFACE, s.w, s.h, 8, 0, 0, 0, 0); begin -- copy pallete V.SetColors (z, s.format.palette.colors, 0, s.format.palette.ncolors); if (V.LockSurface (s) < 0) or (V.LockSurface (z) < 0) then sdlerr ("locking flip images"); end if; for i in 0 .. s.h - 1 loop declare from : Uint8_Ptrs.Object_Pointer := Object_Pointer (Pointer ( To_Pointer (s.pixels)) + C.ptrdiff_t (i * C.int (s.pitch))); to : Uint8_Ptrs.Object_Pointer := Object_Pointer (Pointer ( To_Pointer (z.pixels)) + C.ptrdiff_t (i * C.int (z.pitch) + s.w - 1)); begin for j in 0 .. s.w - 1 loop Object_Pointer (Pointer(to) - C.ptrdiff_t (j)).all := Object_Pointer (Pointer (from) + C.ptrdiff_t (j)).all; end loop; V.UnlockSurface (z); V.UnlockSurface (s); end; end loop; return z; end hflip; -- ====================================== end TestPalette_Sprogs;
-- { dg-do compile } procedure Discr7 is subtype Index is Natural range 0..5; type BitString is array(Index range <>) of Boolean; pragma Pack(BitString); function Id (I : Integer) return Integer is begin return I; end; type E(D : Index) is record C : BitString(1..D); end record; subtype E0 is E(Id(0)); function F return E0 is begin return E'(D=>0, C=>(1..0=>FALSE)); end; begin null; end;
package body AOC.AOC_2019.Day02 is use Intcode; function Compute_Output (D : Day_02; Noun, Verb : Integer) return Element is Instance : Instances.Instance := D.Compiler.Instantiate; begin Instance.Opcodes (1) := Element (Noun); Instance.Opcodes (2) := Element (Verb); Instance.Run; return Instance.Opcodes (0); end Compute_Output; procedure Init (D : in out Day_02; Root : String) is begin D.Compiler.Compile (Root & "/input/2019/day02.txt"); end Init; function Part_1 (D : Day_02) return String is begin return D.Compute_Output (12, 2)'Image; end Part_1; function Part_2 (D : Day_02) return String is Result : Element; begin for Noun in 0 .. 99 loop for Verb in 0 .. 99 loop Result := D.Compute_Output (Noun, Verb); if Result = 19690720 then return Integer'Image (100 * Noun + Verb); end if; end loop; end loop; raise Program_Error with "Output was not found!"; end Part_2; end AOC.AOC_2019.Day02;
-- part of OpenGLAda, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "COPYING" with Interfaces.C.Pointers; with GL.Algebra; package GL.Types is pragma Preelaborate; -- These are the types you can and should use with OpenGL functions -- (particularly when dealing with buffer objects). -- Types that are only used internally, but may be needed when interfacing -- with OpenGL-related library APIs can be found in GL.Low_Level. -- signed integer types type Byte is new C.signed_char; type Short is new C.short; type Int is new C.int; type Long is new C.long; subtype Size is Int range 0 .. Int'Last; subtype Long_Size is Long range 0 .. Long'Last; -- unsigned integer types type UByte is new C.unsigned_char; type UShort is new C.unsigned_short; type UInt is new C.unsigned; -- floating point types ("Single" is used to avoid conflicts with Float) type Single is new C.C_float; type Double is new C.double; -- array types type UShort_Array is array (Size range <>) of aliased UShort; type Int_Array is array (Size range <>) of aliased Int; type UInt_Array is array (Size range <>) of aliased UInt; type Single_Array is array (Size range <>) of aliased Single; pragma Convention (C, UShort_Array); pragma Convention (C, Int_Array); pragma Convention (C, UInt_Array); pragma Convention (C, Single_Array); -- type descriptors type Numeric_Type is (Byte_Type, UByte_Type, Short_Type, UShort_Type, Int_Type, UInt_Type, Single_Type, Double_Type); type Signed_Numeric_Type is (Byte_Type, Short_Type, Int_Type, Single_Type, Double_Type); type Unsigned_Numeric_Type is (UByte_Type, UShort_Type, UInt_Type); -- doesn't really fit here, but there's no other place it fits better type Connection_Mode is (Points, Lines, Line_Loop, Line_Strip, Triangles, Triangle_Strip, Triangle_Fan, Quads, Quad_Strip, Polygon, Lines_Adjacency, Line_Strip_Adjacency, Triangles_Adjacency, Triangle_Strip_Adjacency, Patches); type Compare_Function is (Never, Less, Equal, LEqual, Greater, Not_Equal, GEqual, Always); type Orientation is (Clockwise, Counter_Clockwise); -- counts the number of components for vertex attributes subtype Component_Count is Int range 1 .. 4; package Bytes is new GL.Algebra (Element_Type => Byte, Index_Type => Size, Null_Value => 0, One_Value => 1); package Shorts is new GL.Algebra (Element_Type => Short, Index_Type => Size, Null_Value => 0, One_Value => 1); package Ints is new GL.Algebra (Element_Type => Int, Index_Type => Size, Null_Value => 0, One_Value => 1); package Longs is new GL.Algebra (Element_Type => Long, Index_Type => Size, Null_Value => 0, One_Value => 1); package UBytes is new GL.Algebra (Element_Type => UByte, Index_Type => Size, Null_Value => 0, One_Value => 1); package UShorts is new GL.Algebra (Element_Type => UShort, Index_Type => Size, Null_Value => 0, One_Value => 1); package UInts is new GL.Algebra (Element_Type => UInt, Index_Type => Size, Null_Value => 0, One_Value => 1); package Singles is new GL.Algebra (Element_Type => Single, Index_Type => Size, Null_Value => 0.0, One_Value => 1.0); package Doubles is new GL.Algebra (Element_Type => Double, Index_Type => Size, Null_Value => 0.0, One_Value => 1.0); -- pointer types (for use with data transfer functions package UShort_Pointers is new Interfaces.C.Pointers (Size, UShort, UShort_Array, UShort'Last); package Int_Pointers is new Interfaces.C.Pointers (Size, Int, Int_Array, Int'Last); package UInt_Pointers is new Interfaces.C.Pointers (Size, UInt, UInt_Array, UInt'Last); package Single_Pointers is new Interfaces.C.Pointers (Size, Single, Single_Array, 0.0); private for Numeric_Type use (Byte_Type => 16#1400#, UByte_Type => 16#1401#, Short_Type => 16#1402#, UShort_Type => 16#1403#, Int_Type => 16#1404#, UInt_Type => 16#1405#, Single_Type => 16#1406#, Double_Type => 16#140A#); for Numeric_Type'Size use UInt'Size; for Signed_Numeric_Type use (Byte_Type => 16#1400#, Short_Type => 16#1402#, Int_Type => 16#1404#, Single_Type => 16#1406#, Double_Type => 16#140A#); for Signed_Numeric_Type'Size use UInt'Size; for Unsigned_Numeric_Type use (UByte_Type => 16#1401#, UShort_Type => 16#1403#, UInt_Type => 16#1405#); for Unsigned_Numeric_Type'Size use UInt'Size; for Connection_Mode use (Points => 16#0000#, Lines => 16#0001#, Line_Loop => 16#0002#, Line_Strip => 16#0003#, Triangles => 16#0004#, Triangle_Strip => 16#0005#, Triangle_Fan => 16#0006#, Quads => 16#0007#, Quad_Strip => 16#0008#, Polygon => 16#0009#, Lines_Adjacency => 16#000A#, Line_Strip_Adjacency => 16#000B#, Triangles_Adjacency => 16#000C#, Triangle_Strip_Adjacency => 16#000D#, Patches => 16#000E#); for Connection_Mode'Size use UInt'Size; for Compare_Function use (Never => 16#0200#, Less => 16#0201#, Equal => 16#0202#, LEqual => 16#0203#, Greater => 16#0204#, Not_Equal => 16#0205#, GEqual => 16#0206#, Always => 16#0207#); for Compare_Function'Size use UInt'Size; for Orientation use (Clockwise => 16#0900#, Counter_Clockwise => 16#0901#); for Orientation'Size use UInt'Size; end GL.Types;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S Y S T E M . D W A R F _ L I N E S -- -- -- -- B o d y -- -- -- -- Copyright (C) 2009-2020, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it 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. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Ada.Characters.Handling; with Ada.Exceptions.Traceback; use Ada.Exceptions.Traceback; with Ada.Unchecked_Deallocation; with Ada.Containers.Generic_Array_Sort; with Interfaces; use Interfaces; with System; use System; with System.Storage_Elements; use System.Storage_Elements; with System.Address_Image; with System.IO; use System.IO; with System.Object_Reader; use System.Object_Reader; with System.Traceback_Entries; use System.Traceback_Entries; with System.Mmap; use System.Mmap; with System.Bounded_Strings; use System.Bounded_Strings; package body System.Dwarf_Lines is SSU : constant := System.Storage_Unit; function String_Length (Str : Str_Access) return Natural; -- Return the length of the C string Str --------------------------------- -- DWARF Parser Implementation -- --------------------------------- procedure Read_Initial_Length (S : in out Mapped_Stream; Len : out Offset; Is64 : out Boolean); -- Read initial length as specified by Dwarf-4 7.2.2 procedure Read_Section_Offset (S : in out Mapped_Stream; Len : out Offset; Is64 : Boolean); -- Read a section offset, as specified by Dwarf-4 7.4 procedure Read_Aranges_Entry (C : in out Dwarf_Context; Start : out Storage_Offset; Len : out Storage_Count); -- Read a single .debug_aranges pair procedure Read_Aranges_Header (C : in out Dwarf_Context; Info_Offset : out Offset; Success : out Boolean); -- Read .debug_aranges header procedure Aranges_Lookup (C : in out Dwarf_Context; Addr : Storage_Offset; Info_Offset : out Offset; Success : out Boolean); -- Search for Addr in .debug_aranges and return offset Info_Offset in -- .debug_info. procedure Skip_Form (S : in out Mapped_Stream; Form : uint32; Is64 : Boolean; Ptr_Sz : uint8); -- Advance offset in S for Form. procedure Seek_Abbrev (C : in out Dwarf_Context; Abbrev_Offset : Offset; Abbrev_Num : uint32); -- Seek to abbrev Abbrev_Num (starting from Abbrev_Offset) procedure Debug_Info_Lookup (C : in out Dwarf_Context; Info_Offset : Offset; Line_Offset : out Offset; Success : out Boolean); -- Search for stmt_list tag in Info_Offset and set Line_Offset to the -- offset in .debug_lines. Only look at the first DIE, which should be -- a compilation unit. procedure Initialize_Pass (C : in out Dwarf_Context); -- Seek to the first byte of the first prologue and prepare to make a pass -- over the line number entries. procedure Initialize_State_Machine (C : in out Dwarf_Context); -- Set all state machine registers to their specified initial values procedure Parse_Prologue (C : in out Dwarf_Context); -- Decode a DWARF statement program prologue procedure Read_And_Execute_Isn (C : in out Dwarf_Context; Done : out Boolean); -- Read an execute a statement program instruction function To_File_Name (C : in out Dwarf_Context; Code : uint32) return String; -- Extract a file name from the prologue type Callback is access procedure (C : in out Dwarf_Context); procedure For_Each_Row (C : in out Dwarf_Context; F : Callback); -- Traverse each .debug_line entry with a callback procedure Dump_Row (C : in out Dwarf_Context); -- Dump a single row function "<" (Left, Right : Search_Entry) return Boolean; -- For sorting Search_Entry procedure Sort_Search_Array is new Ada.Containers.Generic_Array_Sort (Index_Type => Natural, Element_Type => Search_Entry, Array_Type => Search_Array); procedure Symbolic_Address (C : in out Dwarf_Context; Addr : Storage_Offset; Dir_Name : out Str_Access; File_Name : out Str_Access; Subprg_Name : out String_Ptr_Len; Line_Num : out Natural); -- Symbolize one address ----------------------- -- DWARF constants -- ----------------------- -- 6.2.5.2 Standard Opcodes DW_LNS_copy : constant := 1; DW_LNS_advance_pc : constant := 2; DW_LNS_advance_line : constant := 3; DW_LNS_set_file : constant := 4; DW_LNS_set_column : constant := 5; DW_LNS_negate_stmt : constant := 6; DW_LNS_set_basic_block : constant := 7; DW_LNS_const_add_pc : constant := 8; DW_LNS_fixed_advance_pc : constant := 9; DW_LNS_set_prologue_end : constant := 10; DW_LNS_set_epilogue_begin : constant := 11; DW_LNS_set_isa : constant := 12; -- 6.2.5.3 Extended Opcodes DW_LNE_end_sequence : constant := 1; DW_LNE_set_address : constant := 2; DW_LNE_define_file : constant := 3; -- From the DWARF version 4 public review draft DW_LNE_set_discriminator : constant := 4; -- Attribute encodings DW_TAG_Compile_Unit : constant := 16#11#; DW_AT_Stmt_List : constant := 16#10#; DW_FORM_addr : constant := 16#01#; DW_FORM_block2 : constant := 16#03#; DW_FORM_block4 : constant := 16#04#; DW_FORM_data2 : constant := 16#05#; DW_FORM_data4 : constant := 16#06#; DW_FORM_data8 : constant := 16#07#; DW_FORM_string : constant := 16#08#; DW_FORM_block : constant := 16#09#; DW_FORM_block1 : constant := 16#0a#; DW_FORM_data1 : constant := 16#0b#; DW_FORM_flag : constant := 16#0c#; DW_FORM_sdata : constant := 16#0d#; DW_FORM_strp : constant := 16#0e#; DW_FORM_udata : constant := 16#0f#; DW_FORM_ref_addr : constant := 16#10#; DW_FORM_ref1 : constant := 16#11#; DW_FORM_ref2 : constant := 16#12#; DW_FORM_ref4 : constant := 16#13#; DW_FORM_ref8 : constant := 16#14#; DW_FORM_ref_udata : constant := 16#15#; DW_FORM_indirect : constant := 16#16#; DW_FORM_sec_offset : constant := 16#17#; DW_FORM_exprloc : constant := 16#18#; DW_FORM_flag_present : constant := 16#19#; DW_FORM_ref_sig8 : constant := 16#20#; --------- -- "<" -- --------- function "<" (Left, Right : Search_Entry) return Boolean is begin return Left.First < Right.First; end "<"; ----------- -- Close -- ----------- procedure Close (C : in out Dwarf_Context) is procedure Unchecked_Deallocation is new Ada.Unchecked_Deallocation (Object_File, Object_File_Access); procedure Unchecked_Deallocation is new Ada.Unchecked_Deallocation (Search_Array, Search_Array_Access); begin if C.Has_Debug then Close (C.Lines); Close (C.Abbrev); Close (C.Info); Close (C.Aranges); end if; Close (C.Obj.all); Unchecked_Deallocation (C.Obj); Unchecked_Deallocation (C.Cache); end Close; ---------- -- Dump -- ---------- procedure Dump (C : in out Dwarf_Context) is begin For_Each_Row (C, Dump_Row'Access); end Dump; -------------- -- Dump_Row -- -------------- procedure Dump_Row (C : in out Dwarf_Context) is PC : constant Integer_Address := Integer_Address (C.Registers.Address); Off : Offset; begin Tell (C.Lines, Off); Put (System.Address_Image (To_Address (PC))); Put (" "); Put (To_File_Name (C, C.Registers.File)); Put (":"); declare Image : constant String := uint32'Image (C.Registers.Line); begin Put_Line (Image (2 .. Image'Last)); end; Seek (C.Lines, Off); end Dump_Row; procedure Dump_Cache (C : Dwarf_Context) is Cache : constant Search_Array_Access := C.Cache; S : Object_Symbol; Name : String_Ptr_Len; begin if Cache = null then Put_Line ("No cache"); return; end if; for I in Cache'Range loop declare E : Search_Entry renames Cache (I); Base_Address : constant System.Address := To_Address (Integer_Address (C.Low + Storage_Count (E.First))); begin Put (System.Address_Image (Base_Address)); Put (" - "); Put (System.Address_Image (Base_Address + Storage_Count (E.Size))); Put (" l@"); Put (System.Address_Image (To_Address (Integer_Address (E.Line)))); Put (": "); S := Read_Symbol (C.Obj.all, Offset (E.Sym)); Name := Object_Reader.Name (C.Obj.all, S); Put (String (Name.Ptr (1 .. Name.Len))); New_Line; end; end loop; end Dump_Cache; ------------------ -- For_Each_Row -- ------------------ procedure For_Each_Row (C : in out Dwarf_Context; F : Callback) is Done : Boolean; begin Initialize_Pass (C); loop Read_And_Execute_Isn (C, Done); if C.Registers.Is_Row then F.all (C); end if; exit when Done; end loop; end For_Each_Row; --------------------- -- Initialize_Pass -- --------------------- procedure Initialize_Pass (C : in out Dwarf_Context) is begin Seek (C.Lines, 0); C.Next_Prologue := 0; Initialize_State_Machine (C); end Initialize_Pass; ------------------------------ -- Initialize_State_Machine -- ------------------------------ procedure Initialize_State_Machine (C : in out Dwarf_Context) is begin C.Registers := (Address => 0, File => 1, Line => 1, Column => 0, Is_Stmt => C.Prologue.Default_Is_Stmt = 0, Basic_Block => False, End_Sequence => False, Prologue_End => False, Epilogue_Begin => False, ISA => 0, Is_Row => False); end Initialize_State_Machine; --------------- -- Is_Inside -- --------------- function Is_Inside (C : Dwarf_Context; Addr : Address) return Boolean is begin return (Addr >= C.Low + C.Load_Address and then Addr <= C.High + C.Load_Address); end Is_Inside; ----------------- -- Low_Address -- ----------------- function Low_Address (C : Dwarf_Context) return System.Address is begin return C.Load_Address + C.Low; end Low_Address; ---------- -- Open -- ---------- procedure Open (File_Name : String; C : out Dwarf_Context; Success : out Boolean) is Line_Sec, Info_Sec, Abbrev_Sec, Aranges_Sec : Object_Section; Hi, Lo : uint64; begin -- Not a success by default Success := False; -- Open file C.Obj := Open (File_Name, C.In_Exception); if C.Obj = null then return; end if; Success := True; -- Get memory bounds for executable code. Note that such code -- might come from multiple sections. Get_Xcode_Bounds (C.Obj.all, Lo, Hi); C.Low := Storage_Offset (Lo); C.High := Storage_Offset (Hi); -- Create a stream for debug sections if Format (C.Obj.all) = XCOFF32 then Line_Sec := Get_Section (C.Obj.all, ".dwline"); Abbrev_Sec := Get_Section (C.Obj.all, ".dwabrev"); Info_Sec := Get_Section (C.Obj.all, ".dwinfo"); Aranges_Sec := Get_Section (C.Obj.all, ".dwarnge"); else Line_Sec := Get_Section (C.Obj.all, ".debug_line"); Abbrev_Sec := Get_Section (C.Obj.all, ".debug_abbrev"); Info_Sec := Get_Section (C.Obj.all, ".debug_info"); Aranges_Sec := Get_Section (C.Obj.all, ".debug_aranges"); end if; if Line_Sec = Null_Section or else Abbrev_Sec = Null_Section or else Info_Sec = Null_Section or else Aranges_Sec = Null_Section then pragma Annotate (CodePeer, False_Positive, "test always true", "codepeer got confused"); C.Has_Debug := False; return; end if; C.Lines := Create_Stream (C.Obj.all, Line_Sec); C.Abbrev := Create_Stream (C.Obj.all, Abbrev_Sec); C.Info := Create_Stream (C.Obj.all, Info_Sec); C.Aranges := Create_Stream (C.Obj.all, Aranges_Sec); -- All operations are successful, context is valid C.Has_Debug := True; end Open; -------------------- -- Parse_Prologue -- -------------------- procedure Parse_Prologue (C : in out Dwarf_Context) is Char : uint8; Prev : uint8; -- The most recently read character and the one preceding it Dummy : uint32; -- Destination for reads we don't care about Buf : Buffer; Off : Offset; First_Byte_Of_Prologue : Offset; Last_Byte_Of_Prologue : Offset; Max_Op_Per_Insn : uint8; pragma Unreferenced (Max_Op_Per_Insn); Prologue : Line_Info_Prologue renames C.Prologue; begin Tell (C.Lines, First_Byte_Of_Prologue); Prologue.Unit_Length := Read (C.Lines); Tell (C.Lines, Off); C.Next_Prologue := Off + Offset (Prologue.Unit_Length); Prologue.Version := Read (C.Lines); Prologue.Prologue_Length := Read (C.Lines); Tell (C.Lines, Last_Byte_Of_Prologue); Last_Byte_Of_Prologue := Last_Byte_Of_Prologue + Offset (Prologue.Prologue_Length) - 1; Prologue.Min_Isn_Length := Read (C.Lines); if Prologue.Version >= 4 then Max_Op_Per_Insn := Read (C.Lines); end if; Prologue.Default_Is_Stmt := Read (C.Lines); Prologue.Line_Base := Read (C.Lines); Prologue.Line_Range := Read (C.Lines); Prologue.Opcode_Base := Read (C.Lines); -- Opcode_Lengths is an array of Opcode_Base bytes specifying the number -- of LEB128 operands for each of the standard opcodes. for J in 1 .. uint32 (Prologue.Opcode_Base - 1) loop Prologue.Opcode_Lengths (J) := Read (C.Lines); end loop; -- The include directories table follows. This is a list of null -- terminated strings terminated by a double null. We only store -- its offset for later decoding. Tell (C.Lines, Prologue.Includes_Offset); Char := Read (C.Lines); if Char /= 0 then loop Prev := Char; Char := Read (C.Lines); exit when Char = 0 and Prev = 0; end loop; end if; -- The file_names table is next. Each record is a null terminated string -- for the file name, an unsigned LEB128 directory index, an unsigned -- LEB128 modification time, and an LEB128 file length. The table is -- terminated by a null byte. Tell (C.Lines, Prologue.File_Names_Offset); loop -- Read the filename Read_C_String (C.Lines, Buf); exit when Buf (0) = 0; Dummy := Read_LEB128 (C.Lines); -- Skip the directory index. Dummy := Read_LEB128 (C.Lines); -- Skip the modification time. Dummy := Read_LEB128 (C.Lines); -- Skip the file length. end loop; -- Check we're where we think we are. This sanity check ensures we think -- the prologue ends where the prologue says it does. It we aren't then -- we've probably gotten out of sync somewhere. Tell (C.Lines, Off); if Prologue.Unit_Length /= 0 and then Off /= Last_Byte_Of_Prologue + 1 then raise Dwarf_Error with "Parse error reading DWARF information"; end if; end Parse_Prologue; -------------------------- -- Read_And_Execute_Isn -- -------------------------- procedure Read_And_Execute_Isn (C : in out Dwarf_Context; Done : out Boolean) is Opcode : uint8; Extended_Opcode : uint8; uint32_Operand : uint32; int32_Operand : int32; uint16_Operand : uint16; Off : Offset; Extended_Length : uint32; pragma Unreferenced (Extended_Length); Obj : Object_File renames C.Obj.all; Registers : Line_Info_Registers renames C.Registers; Prologue : Line_Info_Prologue renames C.Prologue; begin Done := False; Registers.Is_Row := False; if Registers.End_Sequence then Initialize_State_Machine (C); end if; -- If we have reached the next prologue, read it. Beware of possibly -- empty blocks. -- When testing for the end of section, beware of possible zero padding -- at the end. Bail out as soon as there's not even room for at least a -- DW_LNE_end_sequence, 3 bytes from Off to Off+2. This resolves to -- Off+2 > Last_Offset_Within_Section, that is Off+2 > Section_Length-1, -- or Off+3 > Section_Length. Tell (C.Lines, Off); while Off = C.Next_Prologue loop Initialize_State_Machine (C); Parse_Prologue (C); Tell (C.Lines, Off); exit when Off + 3 > Length (C.Lines); end loop; -- Test whether we're done Tell (C.Lines, Off); -- We are finished when we either reach the end of the section, or we -- have reached zero padding at the end of the section. if Prologue.Unit_Length = 0 or else Off + 3 > Length (C.Lines) then Done := True; return; end if; -- Read and interpret an instruction Opcode := Read (C.Lines); -- Extended opcodes if Opcode = 0 then Extended_Length := Read_LEB128 (C.Lines); Extended_Opcode := Read (C.Lines); case Extended_Opcode is when DW_LNE_end_sequence => -- Mark the end of a sequence of source locations Registers.End_Sequence := True; Registers.Is_Row := True; when DW_LNE_set_address => -- Set the program counter to a word Registers.Address := Read_Address (Obj, C.Lines); when DW_LNE_define_file => -- Not implemented raise Dwarf_Error with "DWARF operator not implemented"; when DW_LNE_set_discriminator => -- Ignored int32_Operand := Read_LEB128 (C.Lines); when others => -- Fail on an unrecognized opcode raise Dwarf_Error with "DWARF operator not implemented"; end case; -- Standard opcodes elsif Opcode < Prologue.Opcode_Base then case Opcode is -- Append a row to the line info matrix when DW_LNS_copy => Registers.Basic_Block := False; Registers.Is_Row := True; -- Add an unsigned word to the program counter when DW_LNS_advance_pc => uint32_Operand := Read_LEB128 (C.Lines); Registers.Address := Registers.Address + uint64 (uint32_Operand * uint32 (Prologue.Min_Isn_Length)); -- Add a signed word to the current source line when DW_LNS_advance_line => int32_Operand := Read_LEB128 (C.Lines); Registers.Line := uint32 (int32 (Registers.Line) + int32_Operand); -- Set the current source file when DW_LNS_set_file => uint32_Operand := Read_LEB128 (C.Lines); Registers.File := uint32_Operand; -- Set the current source column when DW_LNS_set_column => uint32_Operand := Read_LEB128 (C.Lines); Registers.Column := uint32_Operand; -- Toggle the "is statement" flag. GCC doesn't seem to set this??? when DW_LNS_negate_stmt => Registers.Is_Stmt := not Registers.Is_Stmt; -- Mark the beginning of a basic block when DW_LNS_set_basic_block => Registers.Basic_Block := True; -- Advance the program counter as by the special opcode 255 when DW_LNS_const_add_pc => Registers.Address := Registers.Address + uint64 (((255 - Prologue.Opcode_Base) / Prologue.Line_Range) * Prologue.Min_Isn_Length); -- Advance the program counter by a constant when DW_LNS_fixed_advance_pc => uint16_Operand := Read (C.Lines); Registers.Address := Registers.Address + uint64 (uint16_Operand); -- The following are not implemented and ignored when DW_LNS_set_prologue_end => null; when DW_LNS_set_epilogue_begin => null; when DW_LNS_set_isa => null; -- Anything else is an error when others => raise Dwarf_Error with "DWARF operator not implemented"; end case; -- Decode a special opcode. This is a line and address increment encoded -- in a single byte 'special opcode' as described in 6.2.5.1. else declare Address_Increment : int32; Line_Increment : int32; begin Opcode := Opcode - Prologue.Opcode_Base; -- The adjusted opcode is a uint8 encoding an address increment -- and a signed line increment. The upperbound is allowed to be -- greater than int8'last so we decode using int32 directly to -- prevent overflows. Address_Increment := int32 (Opcode / Prologue.Line_Range) * int32 (Prologue.Min_Isn_Length); Line_Increment := int32 (Prologue.Line_Base) + int32 (Opcode mod Prologue.Line_Range); Registers.Address := Registers.Address + uint64 (Address_Increment); Registers.Line := uint32 (int32 (Registers.Line) + Line_Increment); Registers.Basic_Block := False; Registers.Prologue_End := False; Registers.Epilogue_Begin := False; Registers.Is_Row := True; end; end if; exception when Dwarf_Error => -- In case of errors during parse, just stop reading Registers.Is_Row := False; Done := True; end Read_And_Execute_Isn; ---------------------- -- Set_Load_Address -- ---------------------- procedure Set_Load_Address (C : in out Dwarf_Context; Addr : Address) is begin C.Load_Address := Addr; end Set_Load_Address; ------------------ -- To_File_Name -- ------------------ function To_File_Name (C : in out Dwarf_Context; Code : uint32) return String is Buf : Buffer; J : uint32; Dir_Idx : uint32; pragma Unreferenced (Dir_Idx); Mod_Time : uint32; pragma Unreferenced (Mod_Time); Length : uint32; pragma Unreferenced (Length); begin Seek (C.Lines, C.Prologue.File_Names_Offset); -- Find the entry J := 0; loop J := J + 1; Read_C_String (C.Lines, Buf); if Buf (Buf'First) = 0 then return "???"; end if; Dir_Idx := Read_LEB128 (C.Lines); Mod_Time := Read_LEB128 (C.Lines); Length := Read_LEB128 (C.Lines); exit when J = Code; end loop; return To_String (Buf); end To_File_Name; ------------------------- -- Read_Initial_Length -- ------------------------- procedure Read_Initial_Length (S : in out Mapped_Stream; Len : out Offset; Is64 : out Boolean) is Len32 : uint32; Len64 : uint64; begin Len32 := Read (S); if Len32 < 16#ffff_fff0# then Is64 := False; Len := Offset (Len32); elsif Len32 < 16#ffff_ffff# then -- Invalid length raise Constraint_Error; else Is64 := True; Len64 := Read (S); Len := Offset (Len64); end if; end Read_Initial_Length; ------------------------- -- Read_Section_Offset -- ------------------------- procedure Read_Section_Offset (S : in out Mapped_Stream; Len : out Offset; Is64 : Boolean) is begin if Is64 then Len := Offset (uint64'(Read (S))); else Len := Offset (uint32'(Read (S))); end if; end Read_Section_Offset; -------------------- -- Aranges_Lookup -- -------------------- procedure Aranges_Lookup (C : in out Dwarf_Context; Addr : Storage_Offset; Info_Offset : out Offset; Success : out Boolean) is begin Info_Offset := 0; Seek (C.Aranges, 0); while Tell (C.Aranges) < Length (C.Aranges) loop Read_Aranges_Header (C, Info_Offset, Success); exit when not Success; loop declare Start : Storage_Offset; Len : Storage_Count; begin Read_Aranges_Entry (C, Start, Len); exit when Start = 0 and Len = 0; if Addr >= Start and then Addr < Start + Len then Success := True; return; end if; end; end loop; end loop; Success := False; end Aranges_Lookup; --------------- -- Skip_Form -- --------------- procedure Skip_Form (S : in out Mapped_Stream; Form : uint32; Is64 : Boolean; Ptr_Sz : uint8) is Skip : Offset; begin case Form is when DW_FORM_addr => Skip := Offset (Ptr_Sz); when DW_FORM_block2 => Skip := Offset (uint16'(Read (S))); when DW_FORM_block4 => Skip := Offset (uint32'(Read (S))); when DW_FORM_data2 | DW_FORM_ref2 => Skip := 2; when DW_FORM_data4 | DW_FORM_ref4 => Skip := 4; when DW_FORM_data8 | DW_FORM_ref8 | DW_FORM_ref_sig8 => Skip := 8; when DW_FORM_string => while uint8'(Read (S)) /= 0 loop null; end loop; return; when DW_FORM_block | DW_FORM_exprloc => Skip := Offset (uint32'(Read_LEB128 (S))); when DW_FORM_block1 | DW_FORM_ref1 => Skip := Offset (uint8'(Read (S))); when DW_FORM_data1 | DW_FORM_flag => Skip := 1; when DW_FORM_sdata => declare Val : constant int32 := Read_LEB128 (S); pragma Unreferenced (Val); begin return; end; when DW_FORM_strp | DW_FORM_ref_addr | DW_FORM_sec_offset => Skip := (if Is64 then 8 else 4); when DW_FORM_udata | DW_FORM_ref_udata => declare Val : constant uint32 := Read_LEB128 (S); pragma Unreferenced (Val); begin return; end; when DW_FORM_flag_present => return; when DW_FORM_indirect => raise Constraint_Error; when others => raise Constraint_Error; end case; Seek (S, Tell (S) + Skip); end Skip_Form; ----------------- -- Seek_Abbrev -- ----------------- procedure Seek_Abbrev (C : in out Dwarf_Context; Abbrev_Offset : Offset; Abbrev_Num : uint32) is Num : uint32; Abbrev : uint32; Tag : uint32; Has_Child : uint8; pragma Unreferenced (Abbrev, Tag, Has_Child); begin Seek (C.Abbrev, Abbrev_Offset); Num := 1; loop exit when Num = Abbrev_Num; Abbrev := Read_LEB128 (C.Abbrev); Tag := Read_LEB128 (C.Abbrev); Has_Child := Read (C.Abbrev); loop declare Name : constant uint32 := Read_LEB128 (C.Abbrev); Form : constant uint32 := Read_LEB128 (C.Abbrev); begin exit when Name = 0 and Form = 0; end; end loop; Num := Num + 1; end loop; end Seek_Abbrev; ----------------------- -- Debug_Info_Lookup -- ----------------------- procedure Debug_Info_Lookup (C : in out Dwarf_Context; Info_Offset : Offset; Line_Offset : out Offset; Success : out Boolean) is Unit_Length : Offset; Is64 : Boolean; Version : uint16; Abbrev_Offset : Offset; Addr_Sz : uint8; Abbrev : uint32; Has_Child : uint8; pragma Unreferenced (Has_Child); begin Line_Offset := 0; Success := False; Seek (C.Info, Info_Offset); Read_Initial_Length (C.Info, Unit_Length, Is64); Version := Read (C.Info); if Version not in 2 .. 4 then return; end if; Read_Section_Offset (C.Info, Abbrev_Offset, Is64); Addr_Sz := Read (C.Info); if Addr_Sz /= (Address'Size / SSU) then return; end if; -- Read DIEs loop Abbrev := Read_LEB128 (C.Info); exit when Abbrev /= 0; end loop; -- Read abbrev table Seek_Abbrev (C, Abbrev_Offset, Abbrev); -- First ULEB128 is the abbrev code if Read_LEB128 (C.Abbrev) /= Abbrev then -- Ill formed abbrev table return; end if; -- Then the tag if Read_LEB128 (C.Abbrev) /= uint32'(DW_TAG_Compile_Unit) then -- Expect compile unit return; end if; -- Then the has child flag Has_Child := Read (C.Abbrev); loop declare Name : constant uint32 := Read_LEB128 (C.Abbrev); Form : constant uint32 := Read_LEB128 (C.Abbrev); begin exit when Name = 0 and Form = 0; if Name = DW_AT_Stmt_List then case Form is when DW_FORM_sec_offset => Read_Section_Offset (C.Info, Line_Offset, Is64); when DW_FORM_data4 => Line_Offset := Offset (uint32'(Read (C.Info))); when DW_FORM_data8 => Line_Offset := Offset (uint64'(Read (C.Info))); when others => -- Unhandled form return; end case; Success := True; return; else Skip_Form (C.Info, Form, Is64, Addr_Sz); end if; end; end loop; return; end Debug_Info_Lookup; ------------------------- -- Read_Aranges_Header -- ------------------------- procedure Read_Aranges_Header (C : in out Dwarf_Context; Info_Offset : out Offset; Success : out Boolean) is Unit_Length : Offset; Is64 : Boolean; Version : uint16; Sz : uint8; begin Success := False; Info_Offset := 0; Read_Initial_Length (C.Aranges, Unit_Length, Is64); Version := Read (C.Aranges); if Version /= 2 then return; end if; Read_Section_Offset (C.Aranges, Info_Offset, Is64); -- Read address_size (ubyte) Sz := Read (C.Aranges); if Sz /= (Address'Size / SSU) then return; end if; -- Read segment_size (ubyte) Sz := Read (C.Aranges); if Sz /= 0 then return; end if; -- Handle alignment on twice the address size declare Cur_Off : constant Offset := Tell (C.Aranges); Align : constant Offset := 2 * Address'Size / SSU; Space : constant Offset := Cur_Off mod Align; begin if Space /= 0 then Seek (C.Aranges, Cur_Off + Align - Space); end if; end; Success := True; end Read_Aranges_Header; ------------------------ -- Read_Aranges_Entry -- ------------------------ procedure Read_Aranges_Entry (C : in out Dwarf_Context; Start : out Storage_Offset; Len : out Storage_Count) is begin -- Read table if Address'Size = 32 then declare S, L : uint32; begin S := Read (C.Aranges); L := Read (C.Aranges); Start := Storage_Offset (S); Len := Storage_Count (L); end; elsif Address'Size = 64 then declare S, L : uint64; begin S := Read (C.Aranges); L := Read (C.Aranges); Start := Storage_Offset (S); Len := Storage_Count (L); end; else raise Constraint_Error; end if; end Read_Aranges_Entry; ------------------ -- Enable_Cache -- ------------------ procedure Enable_Cache (C : in out Dwarf_Context) is Cache : Search_Array_Access; begin -- Phase 1: count number of symbols. Phase 2: fill the cache. declare S : Object_Symbol; Val : uint64; Xcode_Low : constant uint64 := uint64 (C.Low); Xcode_High : constant uint64 := uint64 (C.High); Sz : uint32; Addr, Prev_Addr : uint32; Nbr_Symbols : Natural; begin for Phase in 1 .. 2 loop Nbr_Symbols := 0; S := First_Symbol (C.Obj.all); Prev_Addr := uint32'Last; while S /= Null_Symbol loop -- Discard symbols of length 0 or located outside of the -- execution code section outer boundaries. Sz := uint32 (Size (S)); Val := Value (S); if Sz > 0 and then Val >= Xcode_Low and then Val <= Xcode_High then Addr := uint32 (Val - Xcode_Low); -- Try to filter symbols at the same address. This is a best -- effort as they might not be consecutive. if Addr /= Prev_Addr then Nbr_Symbols := Nbr_Symbols + 1; Prev_Addr := Addr; if Phase = 2 then C.Cache (Nbr_Symbols) := (First => Addr, Size => Sz, Sym => uint32 (Off (S)), Line => 0); end if; end if; end if; S := Next_Symbol (C.Obj.all, S); end loop; if Phase = 1 then -- Allocate the cache Cache := new Search_Array (1 .. Nbr_Symbols); C.Cache := Cache; end if; end loop; pragma Assert (Nbr_Symbols = C.Cache'Last); end; -- Sort the cache. Sort_Search_Array (C.Cache.all); -- Set line offsets if not C.Has_Debug then return; end if; declare Info_Offset : Offset; Line_Offset : Offset; Success : Boolean; Ar_Start : Storage_Offset; Ar_Len : Storage_Count; Start, Len : uint32; First, Last : Natural; Mid : Natural; begin Seek (C.Aranges, 0); while Tell (C.Aranges) < Length (C.Aranges) loop Read_Aranges_Header (C, Info_Offset, Success); exit when not Success; Debug_Info_Lookup (C, Info_Offset, Line_Offset, Success); exit when not Success; -- Read table loop Read_Aranges_Entry (C, Ar_Start, Ar_Len); exit when Ar_Start = 0 and Ar_Len = 0; Len := uint32 (Ar_Len); Start := uint32 (Ar_Start - C.Low); -- Search START in the array First := Cache'First; Last := Cache'Last; Mid := First; -- In case of array with one element while First < Last loop Mid := First + (Last - First) / 2; if Start < Cache (Mid).First then Last := Mid - 1; elsif Start >= Cache (Mid).First + Cache (Mid).Size then First := Mid + 1; else exit; end if; end loop; -- Fill info. -- There can be overlapping symbols while Mid > Cache'First and then Cache (Mid - 1).First <= Start and then Cache (Mid - 1).First + Cache (Mid - 1).Size > Start loop Mid := Mid - 1; end loop; while Mid <= Cache'Last loop if Start < Cache (Mid).First + Cache (Mid).Size and then Start + Len > Cache (Mid).First then -- MID is within the bounds Cache (Mid).Line := uint32 (Line_Offset); elsif Start + Len <= Cache (Mid).First then -- Over exit; end if; Mid := Mid + 1; end loop; end loop; end loop; end; end Enable_Cache; ---------------------- -- Symbolic_Address -- ---------------------- procedure Symbolic_Address (C : in out Dwarf_Context; Addr : Storage_Offset; Dir_Name : out Str_Access; File_Name : out Str_Access; Subprg_Name : out String_Ptr_Len; Line_Num : out Natural) is procedure Set_Result (Match : Line_Info_Registers); -- Set results using match procedure Set_Result (Match : Line_Info_Registers) is Dir_Idx : uint32; J : uint32; Mod_Time : uint32; pragma Unreferenced (Mod_Time); Length : uint32; pragma Unreferenced (Length); begin Seek (C.Lines, C.Prologue.File_Names_Offset); -- Find the entry J := 0; loop J := J + 1; File_Name := Read_C_String (C.Lines); if File_Name (File_Name'First) = ASCII.NUL then -- End of file list, so incorrect entry return; end if; Dir_Idx := Read_LEB128 (C.Lines); Mod_Time := Read_LEB128 (C.Lines); Length := Read_LEB128 (C.Lines); exit when J = Match.File; end loop; if Dir_Idx = 0 then -- No directory Dir_Name := null; else Seek (C.Lines, C.Prologue.Includes_Offset); J := 0; loop J := J + 1; Dir_Name := Read_C_String (C.Lines); if Dir_Name (Dir_Name'First) = ASCII.NUL then -- End of directory list, so ill-formed table return; end if; exit when J = Dir_Idx; end loop; end if; Line_Num := Natural (Match.Line); end Set_Result; Addr_Int : constant uint64 := uint64 (Addr); Previous_Row : Line_Info_Registers; Info_Offset : Offset; Line_Offset : Offset; Success : Boolean; Done : Boolean; S : Object_Symbol; begin -- Initialize result Dir_Name := null; File_Name := null; Subprg_Name := (null, 0); Line_Num := 0; if C.Cache /= null then -- Look in the cache declare Addr_Off : constant uint32 := uint32 (Addr - C.Low); First, Last, Mid : Natural; begin First := C.Cache'First; Last := C.Cache'Last; Mid := First; while First <= Last loop Mid := First + (Last - First) / 2; if Addr_Off < C.Cache (Mid).First then Last := Mid - 1; elsif Addr_Off >= C.Cache (Mid).First + C.Cache (Mid).Size then First := Mid + 1; else exit; end if; end loop; if Addr_Off >= C.Cache (Mid).First and then Addr_Off < C.Cache (Mid).First + C.Cache (Mid).Size then Line_Offset := Offset (C.Cache (Mid).Line); S := Read_Symbol (C.Obj.all, Offset (C.Cache (Mid).Sym)); Subprg_Name := Object_Reader.Name (C.Obj.all, S); else -- Not found return; end if; end; else -- Search symbol S := First_Symbol (C.Obj.all); while S /= Null_Symbol loop if Spans (S, Addr_Int) then Subprg_Name := Object_Reader.Name (C.Obj.all, S); exit; end if; S := Next_Symbol (C.Obj.all, S); end loop; -- Search address in aranges table Aranges_Lookup (C, Addr, Info_Offset, Success); if not Success then return; end if; -- Search stmt_list in info table Debug_Info_Lookup (C, Info_Offset, Line_Offset, Success); if not Success then return; end if; end if; Seek (C.Lines, Line_Offset); C.Next_Prologue := 0; Initialize_State_Machine (C); Parse_Prologue (C); Previous_Row.Line := 0; -- Advance to the first entry loop Read_And_Execute_Isn (C, Done); if C.Registers.Is_Row then Previous_Row := C.Registers; exit; end if; exit when Done; end loop; -- Read the rest of the entries while Tell (C.Lines) < C.Next_Prologue loop Read_And_Execute_Isn (C, Done); if C.Registers.Is_Row then if not Previous_Row.End_Sequence and then Addr_Int >= Previous_Row.Address and then Addr_Int < C.Registers.Address then Set_Result (Previous_Row); return; elsif Addr_Int = C.Registers.Address then Set_Result (C.Registers); return; end if; Previous_Row := C.Registers; end if; exit when Done; end loop; end Symbolic_Address; ------------------- -- String_Length -- ------------------- function String_Length (Str : Str_Access) return Natural is begin for I in Str'Range loop if Str (I) = ASCII.NUL then return I - Str'First; end if; end loop; return Str'Last; end String_Length; ------------------------ -- Symbolic_Traceback -- ------------------------ procedure Symbolic_Traceback (Cin : Dwarf_Context; Traceback : AET.Tracebacks_Array; Suppress_Hex : Boolean; Symbol_Found : out Boolean; Res : in out System.Bounded_Strings.Bounded_String) is use Ada.Characters.Handling; C : Dwarf_Context := Cin; Addr_In_Traceback : Address; Offset_To_Lookup : Storage_Offset; Dir_Name : Str_Access; File_Name : Str_Access; Subprg_Name : String_Ptr_Len; Line_Num : Natural; Off : Natural; begin if not C.Has_Debug then Symbol_Found := False; return; else Symbol_Found := True; end if; for J in Traceback'Range loop -- If the buffer is full, no need to do any useless work exit when Is_Full (Res); Addr_In_Traceback := PC_For (Traceback (J)); Offset_To_Lookup := Addr_In_Traceback - C.Load_Address; Symbolic_Address (C, Offset_To_Lookup, Dir_Name, File_Name, Subprg_Name, Line_Num); if File_Name /= null then declare Last : constant Natural := String_Length (File_Name); Is_Ada : constant Boolean := Last > 3 and then To_Upper (String (File_Name (Last - 3 .. Last - 1))) = ".AD"; -- True if this is an Ada file. This doesn't take into account -- nonstandard file-naming conventions, but that's OK; this is -- purely cosmetic. It covers at least .ads, .adb, and .ada. Line_Image : constant String := Natural'Image (Line_Num); begin if Subprg_Name.Len /= 0 then -- For Ada code, Symbol_Image is in all lower case; we don't -- have the case from the original source code. But the best -- guess is Mixed_Case, so convert to that. if Is_Ada then declare Symbol_Image : String := Object_Reader.Decoded_Ada_Name (C.Obj.all, Subprg_Name); begin for K in Symbol_Image'Range loop if K = Symbol_Image'First or else not (Is_Letter (Symbol_Image (K - 1)) or else Is_Digit (Symbol_Image (K - 1))) then Symbol_Image (K) := To_Upper (Symbol_Image (K)); end if; end loop; Append (Res, Symbol_Image); end; else Off := Strip_Leading_Char (C.Obj.all, Subprg_Name); Append (Res, String (Subprg_Name.Ptr (Off .. Subprg_Name.Len))); end if; Append (Res, ' '); end if; Append (Res, "at "); Append (Res, String (File_Name (1 .. Last))); Append (Res, ':'); Append (Res, Line_Image (2 .. Line_Image'Last)); end; else if Suppress_Hex then Append (Res, "..."); else Append_Address (Res, Addr_In_Traceback); end if; if Subprg_Name.Len > 0 then Off := Strip_Leading_Char (C.Obj.all, Subprg_Name); Append (Res, ' '); Append (Res, String (Subprg_Name.Ptr (Off .. Subprg_Name.Len))); end if; Append (Res, " at ???"); end if; Append (Res, ASCII.LF); end loop; end Symbolic_Traceback; end System.Dwarf_Lines;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2009-2017, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- Internal representation of string data in the UTF-16 form. -- -- Internal representation and operations on it use several optimization -- techniques, so some important assumption must be taken into account to -- have expected results: -- -- - alignment of string's value must be compatible with alignment of the -- largest supported by platform Unsigned_X type (for portable version of -- implementation for any 32-bit or 64-bit platform) or with alignment of -- largest supported vector operand for Single Instruction Multiple Data -- instructions set when it is used to implement string operations (for -- x86_64) - to speedup memory access and satisfy typical SIMD -- requirements; -- -- - all unused code points in the last largest element must be filled by -- zero code point - to allows to use optimized version of compare -- operations. ------------------------------------------------------------------------------ pragma Ada_2012; with League; with Matreshka.Atomics.Counters; with Matreshka.Internals.Unicode.Ucd; with Matreshka.Internals.Utf16; package Matreshka.Internals.Strings is pragma Preelaborate; use type Matreshka.Internals.Utf16.Utf16_String_Index; type Utf16_String_Index_Array is array (Matreshka.Internals.Utf16.Utf16_String_Index range <>) of Matreshka.Internals.Utf16.Utf16_String_Index; type Index_Map (Length : Matreshka.Internals.Utf16.Utf16_String_Index) is record Map : Utf16_String_Index_Array (0 .. Length); end record; -- GNAT: GNAT uses fat pointers for arrays, thus makes impossible to define -- atomic compare-and-swap operations for access-to-unconstrained-array -- type. type Index_Map_Access is access all Index_Map; pragma Volatile (Index_Map_Access); type Shared_String (Capacity : Matreshka.Internals.Utf16.Utf16_String_Index) is limited record Counter : Matreshka.Atomics.Counters.Counter; -- Atomic reference counter. Unused : Matreshka.Internals.Utf16.Utf16_String_Index := 0; -- First unused element in the Value array. Length : Natural := 0; -- Precomputed length of the string in Unicode code points. Index_Map : aliased Index_Map_Access := null; pragma Atomic (Index_Map); pragma Volatile (Index_Map); -- Mapping of the string's characters index to position inside internal -- buffer. Used only if string has both BMP and non-BMP characters. -- Is built on-demand. Value : Matreshka.Internals.Utf16.Utf16_String (0 .. Capacity); -- String data. Internal data always has well-formed UTF-16 encoded -- sequence of valid Unicode code points. Validity checks proceed only -- for potentially invalid user specified data, and never proceed for -- the internal data. end record; type Shared_String_Access is access all Shared_String; Shared_Empty : aliased Shared_String := (Capacity => Standard'Maximum_Alignment / 2 - 1, Value => (others => 0), others => <>); -- Globally defined empty shared string to be used as default value. -- Reference and Dereference subprograms known about this object and -- never change its reference counter for speed optimization (atomic -- increment/decrement operations have significant perfomance penalty) -- and allows to be used in Preelaborateable_Initialization types. procedure Reference (Self : not null Shared_String_Access) with Inline => True; -- Increment reference counter. Change of reference counter of Shared_Empty -- object is prevented to provide speedup and to allow to use it to -- initialize components of Preelaborateable_Initialization types. procedure Dereference (Self : in out Shared_String_Access); -- Decrement reference counter and free resources if it reach zero value. -- Self is setted to null. Decrement of reference counter and deallocation -- of Shared_Empty object is prevented to provide minor speedup and to -- allow use it to initialize components of Preelaborateable_Initialization -- types. function Allocate (Size : Matreshka.Internals.Utf16.Utf16_String_Index) return not null Shared_String_Access; -- Allocates new instance of string with specified size. Actual size of the -- allocated string can be greater. Returns reference to Shared_Empty with -- incremented counter when Size is zero. function Can_Be_Reused (Self : not null Shared_String_Access; Size : Matreshka.Internals.Utf16.Utf16_String_Index) return Boolean; pragma Inline (Can_Be_Reused); -- Returns True when specified shared string can be reused safely. There -- are two criteria: reference counter must be one (it means this object -- is not used anywhere); and size of the object is sufficient to store -- at least specified amount of code units. procedure Mutate (Self : in out not null Shared_String_Access; Size : Matreshka.Internals.Utf16.Utf16_String_Index); -- Checks whether specified string can be reused to store data of specified -- size and prepare it to be changed; otherwise allocates new string and -- copy data. procedure Compute_Index_Map (Self : in out Shared_String); -- Compute index map. This operation is thread-safe. function Hash (Self : not null Shared_String_Access) return League.Hash_Type; -- Returns hash value for the string. MurmurHash2, by Austin Appleby is -- used. type Sort_Key_Array is array (Positive range <>) of Matreshka.Internals.Unicode.Ucd.Collation_Weight; type Shared_Sort_Key (Size : Natural) is record Counter : Matreshka.Atomics.Counters.Counter; -- Atomic reference counter. Data : Sort_Key_Array (1 .. Size); -- Sort key data. Last : Natural := 0; -- Last element in the data. end record; type Shared_Sort_Key_Access is access all Shared_Sort_Key; Shared_Empty_Key : aliased Shared_Sort_Key := (Size => 0, others => <>); -- Globally defined shared empty sort key to be used as default value. -- Reference and Dereference subprograms knoen about this object and -- never change its reference counter for speed optimization (atomic -- increment/decrement operations have significant performance penalty) -- and allows to be used in Preelaborateable_Initialization types. procedure Reference (Self : not null Shared_Sort_Key_Access) with Inline => True; -- Increment reference counter. Change of refernce counter of -- Shared_Empty_Key object is prevented to provide speedup and to allow -- to use it to initialize components of Preelaborateable_Initialization -- types. procedure Dereference (Self : in out Shared_Sort_Key_Access); -- Decrement reference counter and free resources if it reach zero value. -- Self is setted to null for safety reasons. Decrement of reference -- counter and deallocation of Shared_Empty_Key object is prevented to -- provide minor speedup and to allow to use it to initialize components -- of Preelaborateable_Initialization types. end Matreshka.Internals.Strings;
------------------------------------------------------------------------------ -- Copyright (c) 2015, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ package body Lithium.Legacy_Filters is Open_Paragraph : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('<'), 2 => Character'Pos ('p'), 3 => Character'Pos ('>')); Close_Paragraph : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('<'), 2 => Character'Pos ('/'), 3 => Character'Pos ('p'), 4 => Character'Pos ('>'), 5 => 10); Open_Emphasis : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('<'), 2 => Character'Pos ('s'), 3 => Character'Pos ('t'), 4 => Character'Pos ('r'), 5 => Character'Pos ('o'), 6 => Character'Pos ('n'), 7 => Character'Pos ('g'), 8 => Character'Pos ('>')); Close_Emphasis : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('<'), 2 => Character'Pos ('/'), 3 => Character'Pos ('s'), 4 => Character'Pos ('t'), 5 => Character'Pos ('r'), 6 => Character'Pos ('o'), 7 => Character'Pos ('n'), 8 => Character'Pos ('g'), 9 => Character'Pos ('>')); Open_Anchor : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('['), 2 => Character'Pos ('<'), 3 => Character'Pos ('a'), 4 => Character'Pos (' '), 5 => Character'Pos ('h'), 6 => Character'Pos ('r'), 7 => Character'Pos ('e'), 8 => Character'Pos ('f'), 9 => Character'Pos ('='), 10 => Character'Pos ('"')); Close_Link : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('"'), 2 => Character'Pos ('>')); Close_Anchor : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('<'), 2 => Character'Pos ('/'), 3 => Character'Pos ('a'), 4 => Character'Pos ('>'), 5 => Character'Pos (']')); Line_Break : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('<'), 2 => Character'Pos ('b'), 3 => Character'Pos ('r'), 4 => Character'Pos ('>'), 5 => 10); Greater_Than : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('&'), 2 => Character'Pos ('g'), 3 => Character'Pos ('t'), 4 => Character'Pos (';')); Less_Than : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('&'), 2 => Character'Pos ('l'), 3 => Character'Pos ('t'), 4 => Character'Pos (';')); Quote : constant Ada.Streams.Stream_Element_Array := (1 => Character'Pos ('&'), 2 => Character'Pos ('q'), 3 => Character'Pos ('u'), 4 => Character'Pos ('o'), 5 => Character'Pos ('t'), 6 => Character'Pos (';')); function Is_Space (Octet : Ada.Streams.Stream_Element) return Boolean is (Octet in 9 | 10 | 13 | 32); function Is_URI_Char (Octet : Ada.Streams.Stream_Element) return Boolean is (Octet in Character'Pos ('a') .. Character'Pos ('z') | Character'Pos ('A') .. Character'Pos ('Z') | Character'Pos ('0') .. Character'Pos ('9') | Character'Pos ('-') | Character'Pos ('_') | Character'Pos ('.') | Character'Pos ('~') | Character'Pos ('!') | Character'Pos ('*') | Character'Pos (''') | Character'Pos ('(') | Character'Pos (')') | Character'Pos (';') | Character'Pos (':') | Character'Pos ('@') | Character'Pos ('&') | Character'Pos ('=') | Character'Pos ('+') | Character'Pos ('$') | Character'Pos (',') | Character'Pos ('/') | Character'Pos ('?') | Character'Pos ('%') | Character'Pos ('#') | Character'Pos ('[') | Character'Pos (']')); function Has_Allowed_URI_Prefix (Fragment : in Ada.Streams.Stream_Element_Array) return Boolean; -- Return whether Fragment starts with an allowed URI prefix (scheme) procedure Check_URI (Data : in Ada.Streams.Stream_Element_Array; Found : out Boolean; Last : out Ada.Streams.Stream_Element_Offset); -- Return whether Data starts with a valid URI followed by ']' -- and what is the position of the clsoing mark. ------------------------------ -- Local Helper Subprograms -- ------------------------------ function Has_Allowed_URI_Prefix (Fragment : in Ada.Streams.Stream_Element_Array) return Boolean is use type Ada.Streams.Stream_Element; use type Ada.Streams.Stream_Element_Offset; begin return (Fragment'Length > 2 and then Fragment (Fragment'First) = Character'Pos ('/') and then Fragment (Fragment'First + 1) = Character'Pos ('/')) or else (Fragment'Length > 8 and then Fragment (Fragment'First) in Character'Pos ('h') | Character'Pos ('H') and then Fragment (Fragment'First + 1) in Character'Pos ('t') | Character'Pos ('T') and then Fragment (Fragment'First + 2) in Character'Pos ('t') | Character'Pos ('T') and then Fragment (Fragment'First + 3) in Character'Pos ('p') | Character'Pos ('P') and then ((Fragment (Fragment'First + 4) = Character'Pos (':') and then Fragment (Fragment'First + 5) = Character'Pos ('/') and then Fragment (Fragment'First + 6) = Character'Pos ('/')) or else (Fragment (Fragment'First + 4) in Character'Pos ('s') | Character'Pos ('S') and then Fragment (Fragment'First + 5) = Character'Pos (':') and then Fragment (Fragment'First + 6) = Character'Pos ('/') and then Fragment (Fragment'First + 7) = Character'Pos ('/')))); end Has_Allowed_URI_Prefix; procedure Check_URI (Data : in Ada.Streams.Stream_Element_Array; Found : out Boolean; Last : out Ada.Streams.Stream_Element_Offset) is use type Ada.Streams.Stream_Element; begin Found := False; if not Has_Allowed_URI_Prefix (Data) then return; end if; for I in Data'Range loop exit when Data (I) = Character'Pos (']'); Last := I; if not Is_URI_Char (Data (I)) then return; end if; end loop; Found := True; end Check_URI; ---------------------- -- Public Interface -- ---------------------- overriding procedure Apply (Object : in Filter; Output : in out Ada.Streams.Root_Stream_Type'Class; Data : in Ada.Streams.Stream_Element_Array) is pragma Unreferenced (Object); use type Ada.Streams.Stream_Element_Offset; procedure Catch_Up (To : in Ada.Streams.Stream_Element_Offset); First : Ada.Streams.Stream_Element_Offset := Data'First; Last : Ada.Streams.Stream_Element_Offset := Data'Last; Next : Ada.Streams.Stream_Element_Offset; procedure Catch_Up (To : in Ada.Streams.Stream_Element_Offset) is begin if Next < To then Output.Write (Data (Next .. To - 1)); end if; Next := To + 1; end Catch_Up; End_Of_Line : Boolean := False; In_Paragraph : Boolean := True; In_Emphasis : Boolean := False; In_Link : Boolean := False; begin Trim_Beginning : while First in Data'Range and then Data (First) in 9 | 10 | 13 | 32 loop First := First + 1; end loop Trim_Beginning; Trim_End : while Last in Data'Range and then Data (Last) in 9 | 10 | 13 | 32 loop Last := Last - 1; end loop Trim_End; Next := First; Output.Write (Open_Paragraph); for I in First .. Last loop case Data (I) is when 13 => -- CR null; when 10 => -- LF if End_Of_Line then In_Paragraph := False; End_Of_Line := False; else End_Of_Line := True; end if; when others => if End_Of_Line then Output.Write (Line_Break); End_Of_Line := False; end if; if not In_Paragraph then if In_Emphasis then Output.Write (Close_Emphasis); In_Emphasis := False; end if; Output.Write (Close_Paragraph); Output.Write (Open_Paragraph); In_Paragraph := True; end if; end case; case Data (I) is when 10 | 13 => Catch_Up (I); when Character'Pos ('"') => Catch_Up (I); Output.Write (Quote); when Character'Pos ('<') => Catch_Up (I); Output.Write (Less_Than); when Character'Pos ('>') => Catch_Up (I); Output.Write (Greater_Than); when Character'Pos ('*') => if In_Emphasis then Catch_Up (I); Output.Write (Close_Emphasis); In_Emphasis := False; elsif (I = Data'First or else Is_Space (Data (I - 1))) and then I < Data'Last and then not Is_Space (Data (I + 1)) then Catch_Up (I); Output.Write (Open_Emphasis); In_Emphasis := True; end if; when Character'Pos ('[') => declare Found : Boolean; Last : Ada.Streams.Stream_Element_Offset; begin Check_URI (Data (I + 1 .. Data'Last), Found, Last); if Found then Catch_Up (I); Output.Write (Open_Anchor); Output.Write (Data (I + 1 .. Last)); Output.Write (Close_Link); In_Link := True; end if; end; when Character'Pos (']') => if In_Link then Catch_Up (I); Output.Write (Close_Anchor); In_Link := False; end if; when others => null; end case; end loop; Catch_Up (Last + 1); if In_Emphasis then Output.Write (Close_Emphasis); end if; if In_Paragraph then Output.Write (Close_Paragraph); end if; end Apply; function Create (Arguments : in out Natools.S_Expressions.Lockable.Descriptor'Class) return Natools.Web.Filters.Filter'Class is pragma Unreferenced (Arguments); begin return Filter'(null record); end Create; end Lithium.Legacy_Filters;
-- ----------------------------------------------------------------- -- -- AdaSDL -- -- Binding to Simple Direct Media Layer -- -- Copyright (C) 2001 A.M.F.Vargas -- -- Antonio M. F. Vargas -- -- Ponta Delgada - Azores - Portugal -- -- http://www.adapower.net/~avargas -- -- E-mail: avargas@adapower.net -- -- ----------------------------------------------------------------- -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This library 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 along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, 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. -- -- ----------------------------------------------------------------- -- -- **************************************************************** -- -- This is an Ada binding to SDL ( Simple DirectMedia Layer from -- -- Sam Lantinga - www.libsld.org ) -- -- **************************************************************** -- -- In order to help the Ada programmer, the comments in this file -- -- are, in great extent, a direct copy of the original text in the -- -- SDL header files. -- -- **************************************************************** -- with System; with Interfaces.C.Strings; with SDL.Types; use SDL.Types; package SDL.Joystick is package C renames Interfaces.C; -- The pointer to a internal joystick structure used -- to identify an SDL joystick type Joystick_ptr is new System.Address; Null_Joystick_ptr : constant Joystick_ptr := Joystick_ptr (System.Null_Address); -- Function prototypes */ -- -- Count the number of joysticks attached to the system function NumJoysticks return C.int; pragma Import (C, NumJoysticks, "SDL_NumJoysticks"); -- Get the implementation dependent name of a joystick. -- This can be called before any joysticks are opened. -- If no name can be found, this function returns NULL. function JoystickName (device_index : C.int) return C.Strings.chars_ptr; pragma Import (C, JoystickName, "SDL_JoystickName"); -- Open a joystick for use - the index passed as an argument refers to -- the N'th joystick on the system. This index is the value which will -- identify this joystick in future joystick events. -- This function returns a joystick identifier, or -- NULL if an error occurred. function JoystickOpen (device_index : C.int) return Joystick_ptr; pragma Import (C, JoystickOpen, "SDL_JoystickOpen"); -- Returns 1 if the joystick has been opened, or 0 if it has not. function JoystickOpened (device_index : C.int) return C.int; pragma Import (C, JoystickOpened, "SDL_JoystickOpened"); -- Get the device index of an opened joystick. function JoystickIndex (joystick : Joystick_ptr) return C.int; pragma Import (C, JoystickIndex, "SDL_JoystickIndex"); -- Get the number of general axis controls on a joystick function JoystickNumAxes (joystick : Joystick_ptr) return C.int; pragma Import (C, JoystickNumAxes, "SDL_JoystickNumAxes"); -- Get the number of trackballs on a joystick -- Joystick trackballs have only relative motion events associated -- with them and their state cannot be polled. function JoystickNumBalls (joystick : Joystick_ptr) return C.int; pragma Import (C, JoystickNumBalls, "SDL_JoystickNumBalls"); -- Get the number of POV hats on a joystick function JoystickNumHats (joystick : Joystick_ptr) return C.int; pragma Import (C, JoystickNumHats, "SDL_JoystickNumHats"); -- Get the number of buttonYs on a joystick function JoystickNumButtons (joystick : Joystick_ptr) return C.int; pragma Import (C, JoystickNumButtons, "SDL_JoystickNumButtons"); -- Update the current state of the open joysticks. -- This is called automatically by the event loop if any joystick -- events are enabled. procedure JoystickUpdate; pragma Import (C, JoystickUpdate, "SDL_JoystickUpdate"); -- Enable/disable joystick event polling. -- If joystick events are disabled, you must call JoystickUpdate -- yourself and check the state of the joystick when you want joystick -- information. -- The state can be one of QUERY, ENABLE or IGNORE. function JoystickEventState (state : C.int) return C.int; pragma Import (C, JoystickEventState, "SDL_JoystickEventState"); -- Get the current state of an axis control on a joystick -- The state is a value ranging from -32768 to 32767. -- The axis indices start at index 0. function JoystickGetAxis ( joystick : Joystick_ptr; axis : C.int) return Sint16; pragma Import (C, JoystickGetAxis, "SDL_JoystickGetAxis"); -- Get the current state of a POV hat on a joystick -- The return value is one of the following positions: -- TO BE REMOVED type HAT_State is mod 2**16; type HAT_State is mod 2**8; for HAT_State'Size use 8; HAT_CENTERED : constant HAT_State := 16#00#; HAT_UP : constant HAT_State := 16#01#; HAT_RIGHT : constant HAT_State := 16#02#; HAT_DOWN : constant HAT_State := 16#04#; HAT_LEFT : constant HAT_State := 16#08#; HAT_RIGHTUP : constant HAT_State := (HAT_RIGHT or HAT_UP); HAT_RIGHTDOWN : constant HAT_State := (HAT_RIGHT or HAT_DOWN); HAT_LEFTUP : constant HAT_State := (HAT_LEFT or HAT_UP); HAT_LEFTDOWN : constant HAT_State := (HAT_LEFT or HAT_DOWN); -- The hat indices start at index 0. function JoystickGetHat ( joystick : Joystick_ptr; hat : C.int) return Uint8; pragma Import (C, JoystickGetHat, "SDL_JoystickGetHat"); -- Get the ball axis change since the last poll -- This returns 0, or -1 if you passed it invalid parameters. -- The ball indices start at index 0. function JoystickGetBall ( joystick : Joystick_ptr; ball : C.int; dx, dy : int_ptr) return C.int; pragma Import (C, JoystickGetBall, "SDL_JoystickGetBall"); type Joy_Button_State is mod 2**8; for Joy_Button_State'Size use 8; pragma Convention (C, Joy_Button_State); PRESSED : constant Joy_Button_State := Joy_Button_State (SDL_PRESSED); RELEASED : constant Joy_Button_State := Joy_Button_State (SDL_RELEASED); -- Get the current state of a button on a joystick -- The button indices start at index 0. function JoystickGetButton ( joystick : Joystick_ptr; button : C.int) return Joy_Button_State; pragma Import (C, JoystickGetButton, "SDL_JoystickGetButton"); -- Close a joystick previously opened with SDL_JoystickOpen procedure JoystickClose (joystick : Joystick_ptr); pragma Import (C, JoystickClose, "SDL_JoystickClose"); end SDL.Joystick;
-- C46013A.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- OBJECTIVE: -- CHECK THAT INTEGER CONVERSIONS ARE PERFORMED CORRECTLY WHEN THE -- OPERAND TYPE IS A FIXED POINT TYPE. -- HISTORY: -- JET 02/09/88 CREATED ORIGINAL TEST. WITH REPORT; USE REPORT; PROCEDURE C46013A IS TYPE FIX1 IS DELTA 2#0.01# RANGE -16#20.0# .. 16#20.0#; TYPE FIX2 IS DELTA 2#0.0001# RANGE -16#80.0# .. 16#80.0#; TYPE FIX3 IS DELTA 2#0.000001# RANGE -16#200.0# .. 16#200.0#; TYPE FIX4 IS NEW FIX1; F1 : FIX1 := 7.75; F2 : FIX2 := -111.25; F3 : FIX3 := 0.875; F4 : FIX4 := -15.25; TYPE INT IS RANGE -512 .. 512; FUNCTION IDENT (I : INT) RETURN INT IS BEGIN RETURN I * INT(IDENT_INT(1)); END IDENT; BEGIN TEST ("C46013A", "CHECK THAT INTEGER CONVERSIONS ARE PERFORMED " & "CORRECTLY WHEN THE OPERAND TYPE IS A FIXED " & "POINT TYPE"); IF INTEGER(FIX1'(-7.25)) /= IDENT_INT(-7) THEN FAILED ("INCORRECT VALUE (1)"); END IF; IF INTEGER(FIX1'(6.75)) /= IDENT_INT(7) THEN FAILED ("INCORRECT VALUE (2)"); END IF; IF INTEGER(F1) /= IDENT_INT(8) THEN FAILED ("INCORRECT VALUE (3)"); END IF; IF INT(FIX1'(-7.25)) /= IDENT(-7) THEN FAILED ("INCORRECT VALUE (4)"); END IF; IF INTEGER(FIX1'(3.33)) /= IDENT_INT(3) AND INTEGER(FIX1'(3.33)) /= IDENT_INT(4) THEN FAILED ("INCORRECT VALUE (5)"); END IF; IF INTEGER(FIX1'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX1'(-1.5)) = IDENT_INT(-1) AND INTEGER(FIX1'(1.5)) = IDENT_INT(2) AND INTEGER(FIX1'(2.5)) = IDENT_INT(3) THEN COMMENT ("FIX1 HALF VALUES ROUND UP"); ELSIF INTEGER(FIX1'(-2.5)) = IDENT_INT(-3) AND INTEGER(FIX1'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX1'(1.5)) = IDENT_INT(1) AND INTEGER(FIX1'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX1 HALF VALUES ROUND DOWN"); ELSIF INTEGER(FIX1'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX1'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX1'(1.5)) = IDENT_INT(2) AND INTEGER(FIX1'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX1 HALF VALUES ROUND TO EVEN"); ELSIF INTEGER(FIX1'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX1'(-1.5)) = IDENT_INT(-1) AND INTEGER(FIX1'(1.5)) = IDENT_INT(1) AND INTEGER(FIX1'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX1 HALF VALUES ROUND TOWARD ZERO"); ELSIF INTEGER(FIX1'(-2.5)) = IDENT_INT(-3) AND INTEGER(FIX1'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX1'(1.5)) = IDENT_INT(2) AND INTEGER(FIX1'(2.5)) = IDENT_INT(3) THEN COMMENT ("FIX1 HALF VALUES ROUND AWAY FROM ZERO"); ELSE COMMENT ("FIX1 HALF VALUES ROUND ERRATICALLY"); END IF; IF INTEGER(FIX2'(-127.9375)) /= IDENT_INT(-128) THEN FAILED ("INCORRECT VALUE (6)"); END IF; IF INTEGER(FIX2'(127.0625)) /= IDENT_INT(127) THEN FAILED ("INCORRECT VALUE (7)"); END IF; IF INTEGER(F2) /= IDENT_INT(-111) THEN FAILED ("INCORRECT VALUE (8)"); END IF; IF INT(FIX2'(-0.25)) /= IDENT(0) THEN FAILED ("INCORRECT VALUE (9)"); END IF; IF INTEGER(FIX2'(66.67)) /= IDENT_INT(67) AND INTEGER(FIX2'(66.67)) /= IDENT_INT(66) THEN FAILED ("INCORRECT VALUE (10)"); END IF; IF INTEGER(FIX2'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX2'(-1.5)) = IDENT_INT(-1) AND INTEGER(FIX2'(1.5)) = IDENT_INT(2) AND INTEGER(FIX2'(2.5)) = IDENT_INT(3) THEN COMMENT ("FIX2 HALF VALUES ROUND UP"); ELSIF INTEGER(FIX2'(-2.5)) = IDENT_INT(-3) AND INTEGER(FIX2'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX2'(1.5)) = IDENT_INT(1) AND INTEGER(FIX2'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX2 HALF VALUES ROUND DOWN"); ELSIF INTEGER(FIX2'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX2'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX2'(1.5)) = IDENT_INT(2) AND INTEGER(FIX2'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX2 HALF VALUES ROUND TO EVEN"); ELSIF INTEGER(FIX2'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX2'(-1.5)) = IDENT_INT(-1) AND INTEGER(FIX2'(1.5)) = IDENT_INT(1) AND INTEGER(FIX2'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX2 HALF VALUES ROUND TOWARD ZERO"); ELSIF INTEGER(FIX2'(-2.5)) = IDENT_INT(-3) AND INTEGER(FIX2'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX2'(1.5)) = IDENT_INT(2) AND INTEGER(FIX2'(2.5)) = IDENT_INT(3) THEN COMMENT ("FIX2 HALF VALUES ROUND AWAY FROM ZERO"); ELSE COMMENT ("FIX2 HALF VALUES ROUND ERRATICALLY"); END IF; IF INTEGER(FIX3'(-0.25)) /= IDENT_INT(0) THEN FAILED ("INCORRECT VALUE (11)"); END IF; IF INTEGER(FIX3'(511.75)) /= IDENT_INT(512) THEN FAILED ("INCORRECT VALUE (12)"); END IF; IF INTEGER(F3) /= IDENT_INT(1) THEN FAILED ("INCORRECT VALUE (13)"); END IF; IF INT(FIX3'(-7.0)) /= IDENT(-7) THEN FAILED ("INCORRECT VALUE (14)"); END IF; IF INTEGER(FIX3'(-66.67)) /= IDENT_INT(-67) AND INTEGER(FIX3'(-66.67)) /= IDENT_INT(-66) THEN FAILED ("INCORRECT VALUE (15)"); END IF; IF INTEGER(FIX3'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX3'(-1.5)) = IDENT_INT(-1) AND INTEGER(FIX3'(1.5)) = IDENT_INT(2) AND INTEGER(FIX3'(2.5)) = IDENT_INT(3) THEN COMMENT ("FIX3 HALF VALUES ROUND UP"); ELSIF INTEGER(FIX3'(-2.5)) = IDENT_INT(-3) AND INTEGER(FIX3'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX3'(1.5)) = IDENT_INT(1) AND INTEGER(FIX3'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX3 HALF VALUES ROUND DOWN"); ELSIF INTEGER(FIX3'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX3'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX3'(1.5)) = IDENT_INT(2) AND INTEGER(FIX3'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX3 HALF VALUES ROUND TO EVEN"); ELSIF INTEGER(FIX3'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX3'(-1.5)) = IDENT_INT(-1) AND INTEGER(FIX3'(1.5)) = IDENT_INT(1) AND INTEGER(FIX3'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX3 HALF VALUES ROUND TOWARD ZERO"); ELSIF INTEGER(FIX3'(-2.5)) = IDENT_INT(-3) AND INTEGER(FIX3'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX3'(1.5)) = IDENT_INT(2) AND INTEGER(FIX3'(2.5)) = IDENT_INT(3) THEN COMMENT ("FIX3 HALF VALUES ROUND AWAY FROM ZERO"); ELSE COMMENT ("FIX3 HALF VALUES ROUND ERRATICALLY"); END IF; IF INTEGER(FIX4'(-7.25)) /= IDENT_INT(-7) THEN FAILED ("INCORRECT VALUE (16)"); END IF; IF INTEGER(FIX4'(6.75)) /= IDENT_INT(7) THEN FAILED ("INCORRECT VALUE (17)"); END IF; IF INTEGER(F4) /= IDENT_INT(-15) THEN FAILED ("INCORRECT VALUE (18)"); END IF; IF INT(FIX4'(-31.75)) /= IDENT(-32) THEN FAILED ("INCORRECT VALUE (19)"); END IF; IF INTEGER(FIX4'(3.33)) /= IDENT_INT(3) AND INTEGER(FIX4'(3.33)) /= IDENT_INT(4) THEN FAILED ("INCORRECT VALUE (20)"); END IF; IF INTEGER(FIX4'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX4'(-1.5)) = IDENT_INT(-1) AND INTEGER(FIX4'(1.5)) = IDENT_INT(2) AND INTEGER(FIX4'(2.5)) = IDENT_INT(3) THEN COMMENT ("FIX4 HALF VALUES ROUND UP"); ELSIF INTEGER(FIX4'(-2.5)) = IDENT_INT(-3) AND INTEGER(FIX4'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX4'(1.5)) = IDENT_INT(1) AND INTEGER(FIX4'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX4 HALF VALUES ROUND DOWN"); ELSIF INTEGER(FIX4'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX4'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX4'(1.5)) = IDENT_INT(2) AND INTEGER(FIX4'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX4 HALF VALUES ROUND TO EVEN"); ELSIF INTEGER(FIX4'(-2.5)) = IDENT_INT(-2) AND INTEGER(FIX4'(-1.5)) = IDENT_INT(-1) AND INTEGER(FIX4'(1.5)) = IDENT_INT(1) AND INTEGER(FIX4'(2.5)) = IDENT_INT(2) THEN COMMENT ("FIX4 HALF VALUES ROUND TOWARD ZERO"); ELSIF INTEGER(FIX4'(-2.5)) = IDENT_INT(-3) AND INTEGER(FIX4'(-1.5)) = IDENT_INT(-2) AND INTEGER(FIX4'(1.5)) = IDENT_INT(2) AND INTEGER(FIX4'(2.5)) = IDENT_INT(3) THEN COMMENT ("FIX4 HALF VALUES ROUND AWAY FROM ZERO"); ELSE COMMENT ("FIX4 HALF VALUES ROUND ERRATICALLY"); END IF; RESULT; END C46013A;
with Ada.Integer_Text_IO, Ada.Text_IO; use Ada.Integer_Text_IO, Ada.Text_IO; package body IntList is function IsInList( List: in T; Number: in Integer ) return Boolean is begin return Find_Element( List, Number ) /= null; end IsInList; ------------------------------------------------------------ procedure Insert( List: in out T; Number: in Integer ) is New_Node : IntList_Node_Ptr; begin if IsInList( List, Number ) then return; end if; New_Node := new IntList_Node'(Datum => Number, Next => null); if List.Head = null then List.Head := New_Node; List.Tail := New_Node; else List.Tail.Next := New_Node; List.Tail := New_Node; end if; end Insert; ------------------------------------------------------------ procedure Remove( List: in out T; Number: in Integer ) is Node : IntList_Node_Ptr := Find_Element( List, Number ); Prev : IntList_Node_Ptr := List.Head; begin if Node = null then return; end if; if Node = List.Head then List.Head := Node.Next; else while Prev.Next /= Node loop Prev := Prev.Next; end loop; Prev.Next := Node.Next; if Node = List.Tail then List.Tail := Prev; end if; end if; -- Free( Node ); end Remove; ------------------------------------------------------------ procedure Print( List: in T ) is Next_Node : IntList_Node_Ptr := List.Head; begin while Next_Node /= null loop Put(Next_Node.Datum); New_Line; Next_Node := Next_Node.Next; end loop; end Print; ------------------------------------------------------------ function Find_Element( List: in T; Number: in Integer ) return IntList_Node_Ptr is Next_Node : IntList_Node_Ptr := List.Head; begin while Next_Node /= null loop if Next_Node.Datum = Number then return Next_Node; end if; Next_Node := Next_Node.Next; end loop; return null; end Find_Element; end IntList;
----------------------------------------------------------------------- -- util-tests-tokenizers -- Split texts into tokens -- Copyright (C) 2012 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Strings; generic type Char is (<>); type Input is array (Positive range <>) of Char; with function Index (Item : in Input; Pattern : in Input; From : in Positive; Going : in Ada.Strings.Direction := Ada.Strings.Forward) return Natural is <>; package Util.Texts.Tokenizers is pragma Preelaborate; -- Iterate over the tokens of the <b>Content</b> input. Each token is separated by -- a pattern represented by <b>Pattern</b>. For each token, call the -- procedure <b>Process</b> with the token. When <b>Going</b> is <b>Backward</b>, -- scan the input from the end. Stop iterating over the tokens when the <b>Process</b> -- procedure returns True in <b>Done</b>. procedure Iterate_Tokens (Content : in Input; Pattern : in Input; Process : access procedure (Token : in Input; Done : out Boolean); Going : in Ada.Strings.Direction := Ada.Strings.Forward); end Util.Texts.Tokenizers;
-- Copyright (c) 2020 Raspberry Pi (Trading) Ltd. -- -- SPDX-License-Identifier: BSD-3-Clause -- This spec has been automatically generated from rp2040.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package RP_SVD.SPI1 is pragma Preelaborate; --------------- -- Registers -- --------------- subtype SSPCR0_DSS_Field is HAL.UInt4; subtype SSPCR0_FRF_Field is HAL.UInt2; subtype SSPCR0_SCR_Field is HAL.UInt8; -- Control register 0, SSPCR0 on page 3-4 type SSPCR0_Register is record -- Data Size Select: 0000 Reserved, undefined operation. 0001 Reserved, -- undefined operation. 0010 Reserved, undefined operation. 0011 4-bit -- data. 0100 5-bit data. 0101 6-bit data. 0110 7-bit data. 0111 8-bit -- data. 1000 9-bit data. 1001 10-bit data. 1010 11-bit data. 1011 -- 12-bit data. 1100 13-bit data. 1101 14-bit data. 1110 15-bit data. -- 1111 16-bit data. DSS : SSPCR0_DSS_Field := 16#0#; -- Frame format: 00 Motorola SPI frame format. 01 TI synchronous serial -- frame format. 10 National Microwire frame format. 11 Reserved, -- undefined operation. FRF : SSPCR0_FRF_Field := 16#0#; -- SSPCLKOUT polarity, applicable to Motorola SPI frame format only. See -- Motorola SPI frame format on page 2-10. SPO : Boolean := False; -- SSPCLKOUT phase, applicable to Motorola SPI frame format only. See -- Motorola SPI frame format on page 2-10. SPH : Boolean := False; -- Serial clock rate. The value SCR is used to generate the transmit and -- receive bit rate of the PrimeCell SSP. The bit rate is: F SSPCLK -- CPSDVSR x (1+SCR) where CPSDVSR is an even value from 2-254, -- programmed through the SSPCPSR register and SCR is a value from -- 0-255. SCR : SSPCR0_SCR_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPCR0_Register use record DSS at 0 range 0 .. 3; FRF at 0 range 4 .. 5; SPO at 0 range 6 .. 6; SPH at 0 range 7 .. 7; SCR at 0 range 8 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- Control register 1, SSPCR1 on page 3-5 type SSPCR1_Register is record -- Loop back mode: 0 Normal serial port operation enabled. 1 Output of -- transmit serial shifter is connected to input of receive serial -- shifter internally. LBM : Boolean := False; -- Synchronous serial port enable: 0 SSP operation disabled. 1 SSP -- operation enabled. SSE : Boolean := False; -- Master or slave mode select. This bit can be modified only when the -- PrimeCell SSP is disabled, SSE=0: 0 Device configured as master, -- default. 1 Device configured as slave. MS : Boolean := False; -- Slave-mode output disable. This bit is relevant only in the slave -- mode, MS=1. In multiple-slave systems, it is possible for an -- PrimeCell SSP master to broadcast a message to all slaves in the -- system while ensuring that only one slave drives data onto its serial -- output line. In such systems the RXD lines from multiple slaves could -- be tied together. To operate in such systems, the SOD bit can be set -- if the PrimeCell SSP slave is not supposed to drive the SSPTXD line: -- 0 SSP can drive the SSPTXD output in slave mode. 1 SSP must not drive -- the SSPTXD output in slave mode. SOD : Boolean := False; -- unspecified Reserved_4_31 : HAL.UInt28 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPCR1_Register use record LBM at 0 range 0 .. 0; SSE at 0 range 1 .. 1; MS at 0 range 2 .. 2; SOD at 0 range 3 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; subtype SSPDR_DATA_Field is HAL.UInt16; -- Data register, SSPDR on page 3-6 type SSPDR_Register is record -- Transmit/Receive FIFO: Read Receive FIFO. Write Transmit FIFO. You -- must right-justify data when the PrimeCell SSP is programmed for a -- data size that is less than 16 bits. Unused bits at the top are -- ignored by transmit logic. The receive logic automatically -- right-justifies. DATA : SSPDR_DATA_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPDR_Register use record DATA at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- Status register, SSPSR on page 3-7 type SSPSR_Register is record -- Read-only. Transmit FIFO empty, RO: 0 Transmit FIFO is not empty. 1 -- Transmit FIFO is empty. TFE : Boolean; -- Read-only. Transmit FIFO not full, RO: 0 Transmit FIFO is full. 1 -- Transmit FIFO is not full. TNF : Boolean; -- Read-only. Receive FIFO not empty, RO: 0 Receive FIFO is empty. 1 -- Receive FIFO is not empty. RNE : Boolean; -- Read-only. Receive FIFO full, RO: 0 Receive FIFO is not full. 1 -- Receive FIFO is full. RFF : Boolean; -- Read-only. PrimeCell SSP busy flag, RO: 0 SSP is idle. 1 SSP is -- currently transmitting and/or receiving a frame or the transmit FIFO -- is not empty. BSY : Boolean; -- unspecified Reserved_5_31 : HAL.UInt27; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPSR_Register use record TFE at 0 range 0 .. 0; TNF at 0 range 1 .. 1; RNE at 0 range 2 .. 2; RFF at 0 range 3 .. 3; BSY at 0 range 4 .. 4; Reserved_5_31 at 0 range 5 .. 31; end record; subtype SSPCPSR_CPSDVSR_Field is HAL.UInt8; -- Clock prescale register, SSPCPSR on page 3-8 type SSPCPSR_Register is record -- Clock prescale divisor. Must be an even number from 2-254, depending -- on the frequency of SSPCLK. The least significant bit always returns -- zero on reads. CPSDVSR : SSPCPSR_CPSDVSR_Field := 16#0#; -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPCPSR_Register use record CPSDVSR at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- Interrupt mask set or clear register, SSPIMSC on page 3-9 type SSPIMSC_Register is record -- Receive overrun interrupt mask: 0 Receive FIFO written to while full -- condition interrupt is masked. 1 Receive FIFO written to while full -- condition interrupt is not masked. RORIM : Boolean := False; -- Receive timeout interrupt mask: 0 Receive FIFO not empty and no read -- prior to timeout period interrupt is masked. 1 Receive FIFO not empty -- and no read prior to timeout period interrupt is not masked. RTIM : Boolean := False; -- Receive FIFO interrupt mask: 0 Receive FIFO half full or less -- condition interrupt is masked. 1 Receive FIFO half full or less -- condition interrupt is not masked. RXIM : Boolean := False; -- Transmit FIFO interrupt mask: 0 Transmit FIFO half empty or less -- condition interrupt is masked. 1 Transmit FIFO half empty or less -- condition interrupt is not masked. TXIM : Boolean := False; -- unspecified Reserved_4_31 : HAL.UInt28 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPIMSC_Register use record RORIM at 0 range 0 .. 0; RTIM at 0 range 1 .. 1; RXIM at 0 range 2 .. 2; TXIM at 0 range 3 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; -- Raw interrupt status register, SSPRIS on page 3-10 type SSPRIS_Register is record -- Read-only. Gives the raw interrupt state, prior to masking, of the -- SSPRORINTR interrupt RORRIS : Boolean; -- Read-only. Gives the raw interrupt state, prior to masking, of the -- SSPRTINTR interrupt RTRIS : Boolean; -- Read-only. Gives the raw interrupt state, prior to masking, of the -- SSPRXINTR interrupt RXRIS : Boolean; -- Read-only. Gives the raw interrupt state, prior to masking, of the -- SSPTXINTR interrupt TXRIS : Boolean; -- unspecified Reserved_4_31 : HAL.UInt28; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPRIS_Register use record RORRIS at 0 range 0 .. 0; RTRIS at 0 range 1 .. 1; RXRIS at 0 range 2 .. 2; TXRIS at 0 range 3 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; -- Masked interrupt status register, SSPMIS on page 3-11 type SSPMIS_Register is record -- Read-only. Gives the receive over run masked interrupt status, after -- masking, of the SSPRORINTR interrupt RORMIS : Boolean; -- Read-only. Gives the receive timeout masked interrupt state, after -- masking, of the SSPRTINTR interrupt RTMIS : Boolean; -- Read-only. Gives the receive FIFO masked interrupt state, after -- masking, of the SSPRXINTR interrupt RXMIS : Boolean; -- Read-only. Gives the transmit FIFO masked interrupt state, after -- masking, of the SSPTXINTR interrupt TXMIS : Boolean; -- unspecified Reserved_4_31 : HAL.UInt28; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPMIS_Register use record RORMIS at 0 range 0 .. 0; RTMIS at 0 range 1 .. 1; RXMIS at 0 range 2 .. 2; TXMIS at 0 range 3 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; -- Interrupt clear register, SSPICR on page 3-11 type SSPICR_Register is record -- Write data bit of one shall clear (set to zero) the corresponding bit -- in the field. Clears the SSPRORINTR interrupt RORIC : Boolean := False; -- Write data bit of one shall clear (set to zero) the corresponding bit -- in the field. Clears the SSPRTINTR interrupt RTIC : Boolean := False; -- unspecified Reserved_2_31 : HAL.UInt30 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPICR_Register use record RORIC at 0 range 0 .. 0; RTIC at 0 range 1 .. 1; Reserved_2_31 at 0 range 2 .. 31; end record; -- DMA control register, SSPDMACR on page 3-12 type SSPDMACR_Register is record -- Receive DMA Enable. If this bit is set to 1, DMA for the receive FIFO -- is enabled. RXDMAE : Boolean := False; -- Transmit DMA Enable. If this bit is set to 1, DMA for the transmit -- FIFO is enabled. TXDMAE : Boolean := False; -- unspecified Reserved_2_31 : HAL.UInt30 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPDMACR_Register use record RXDMAE at 0 range 0 .. 0; TXDMAE at 0 range 1 .. 1; Reserved_2_31 at 0 range 2 .. 31; end record; subtype SSPPERIPHID0_PARTNUMBER0_Field is HAL.UInt8; -- Peripheral identification registers, SSPPeriphID0-3 on page 3-13 type SSPPERIPHID0_Register is record -- Read-only. These bits read back as 0x22 PARTNUMBER0 : SSPPERIPHID0_PARTNUMBER0_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPPERIPHID0_Register use record PARTNUMBER0 at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype SSPPERIPHID1_PARTNUMBER1_Field is HAL.UInt4; subtype SSPPERIPHID1_DESIGNER0_Field is HAL.UInt4; -- Peripheral identification registers, SSPPeriphID0-3 on page 3-13 type SSPPERIPHID1_Register is record -- Read-only. These bits read back as 0x0 PARTNUMBER1 : SSPPERIPHID1_PARTNUMBER1_Field; -- Read-only. These bits read back as 0x1 DESIGNER0 : SSPPERIPHID1_DESIGNER0_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPPERIPHID1_Register use record PARTNUMBER1 at 0 range 0 .. 3; DESIGNER0 at 0 range 4 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype SSPPERIPHID2_DESIGNER1_Field is HAL.UInt4; subtype SSPPERIPHID2_REVISION_Field is HAL.UInt4; -- Peripheral identification registers, SSPPeriphID0-3 on page 3-13 type SSPPERIPHID2_Register is record -- Read-only. These bits read back as 0x4 DESIGNER1 : SSPPERIPHID2_DESIGNER1_Field; -- Read-only. These bits return the peripheral revision REVISION : SSPPERIPHID2_REVISION_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPPERIPHID2_Register use record DESIGNER1 at 0 range 0 .. 3; REVISION at 0 range 4 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype SSPPERIPHID3_CONFIGURATION_Field is HAL.UInt8; -- Peripheral identification registers, SSPPeriphID0-3 on page 3-13 type SSPPERIPHID3_Register is record -- Read-only. These bits read back as 0x00 CONFIGURATION : SSPPERIPHID3_CONFIGURATION_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPPERIPHID3_Register use record CONFIGURATION at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype SSPPCELLID0_SSPPCELLID0_Field is HAL.UInt8; -- PrimeCell identification registers, SSPPCellID0-3 on page 3-16 type SSPPCELLID0_Register is record -- Read-only. These bits read back as 0x0D SSPPCELLID0 : SSPPCELLID0_SSPPCELLID0_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPPCELLID0_Register use record SSPPCELLID0 at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype SSPPCELLID1_SSPPCELLID1_Field is HAL.UInt8; -- PrimeCell identification registers, SSPPCellID0-3 on page 3-16 type SSPPCELLID1_Register is record -- Read-only. These bits read back as 0xF0 SSPPCELLID1 : SSPPCELLID1_SSPPCELLID1_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPPCELLID1_Register use record SSPPCELLID1 at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype SSPPCELLID2_SSPPCELLID2_Field is HAL.UInt8; -- PrimeCell identification registers, SSPPCellID0-3 on page 3-16 type SSPPCELLID2_Register is record -- Read-only. These bits read back as 0x05 SSPPCELLID2 : SSPPCELLID2_SSPPCELLID2_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPPCELLID2_Register use record SSPPCELLID2 at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype SSPPCELLID3_SSPPCELLID3_Field is HAL.UInt8; -- PrimeCell identification registers, SSPPCellID0-3 on page 3-16 type SSPPCELLID3_Register is record -- Read-only. These bits read back as 0xB1 SSPPCELLID3 : SSPPCELLID3_SSPPCELLID3_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SSPPCELLID3_Register use record SSPPCELLID3 at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; ----------------- -- Peripherals -- ----------------- type SPI1_Peripheral is record -- Control register 0, SSPCR0 on page 3-4 SSPCR0 : aliased SSPCR0_Register; -- Control register 1, SSPCR1 on page 3-5 SSPCR1 : aliased SSPCR1_Register; -- Data register, SSPDR on page 3-6 SSPDR : aliased SSPDR_Register; -- Status register, SSPSR on page 3-7 SSPSR : aliased SSPSR_Register; -- Clock prescale register, SSPCPSR on page 3-8 SSPCPSR : aliased SSPCPSR_Register; -- Interrupt mask set or clear register, SSPIMSC on page 3-9 SSPIMSC : aliased SSPIMSC_Register; -- Raw interrupt status register, SSPRIS on page 3-10 SSPRIS : aliased SSPRIS_Register; -- Masked interrupt status register, SSPMIS on page 3-11 SSPMIS : aliased SSPMIS_Register; -- Interrupt clear register, SSPICR on page 3-11 SSPICR : aliased SSPICR_Register; -- DMA control register, SSPDMACR on page 3-12 SSPDMACR : aliased SSPDMACR_Register; -- Peripheral identification registers, SSPPeriphID0-3 on page 3-13 SSPPERIPHID0 : aliased SSPPERIPHID0_Register; -- Peripheral identification registers, SSPPeriphID0-3 on page 3-13 SSPPERIPHID1 : aliased SSPPERIPHID1_Register; -- Peripheral identification registers, SSPPeriphID0-3 on page 3-13 SSPPERIPHID2 : aliased SSPPERIPHID2_Register; -- Peripheral identification registers, SSPPeriphID0-3 on page 3-13 SSPPERIPHID3 : aliased SSPPERIPHID3_Register; -- PrimeCell identification registers, SSPPCellID0-3 on page 3-16 SSPPCELLID0 : aliased SSPPCELLID0_Register; -- PrimeCell identification registers, SSPPCellID0-3 on page 3-16 SSPPCELLID1 : aliased SSPPCELLID1_Register; -- PrimeCell identification registers, SSPPCellID0-3 on page 3-16 SSPPCELLID2 : aliased SSPPCELLID2_Register; -- PrimeCell identification registers, SSPPCellID0-3 on page 3-16 SSPPCELLID3 : aliased SSPPCELLID3_Register; end record with Volatile; for SPI1_Peripheral use record SSPCR0 at 16#0# range 0 .. 31; SSPCR1 at 16#4# range 0 .. 31; SSPDR at 16#8# range 0 .. 31; SSPSR at 16#C# range 0 .. 31; SSPCPSR at 16#10# range 0 .. 31; SSPIMSC at 16#14# range 0 .. 31; SSPRIS at 16#18# range 0 .. 31; SSPMIS at 16#1C# range 0 .. 31; SSPICR at 16#20# range 0 .. 31; SSPDMACR at 16#24# range 0 .. 31; SSPPERIPHID0 at 16#FE0# range 0 .. 31; SSPPERIPHID1 at 16#FE4# range 0 .. 31; SSPPERIPHID2 at 16#FE8# range 0 .. 31; SSPPERIPHID3 at 16#FEC# range 0 .. 31; SSPPCELLID0 at 16#FF0# range 0 .. 31; SSPPCELLID1 at 16#FF4# range 0 .. 31; SSPPCELLID2 at 16#FF8# range 0 .. 31; SSPPCELLID3 at 16#FFC# range 0 .. 31; end record; SPI1_Periph : aliased SPI1_Peripheral with Import, Address => SPI1_Base; end RP_SVD.SPI1;
with DDS.Typed_DataWriter_Generic; with DDS.Typed_DataReader_Generic; with DDS.Entity_Impl; with DDS.Topic; with DDS.DomainParticipant; with DDS.Publisher; with DDS.Subscriber; generic with package Request_DataReaders is new DDS.Typed_DataReader_Generic (<>); with package Reply_DataWriters is new DDS.Typed_DataWriter_Generic (<>); package Dds.Request_Reply.Reply_Generic is type ReplierListener is interface; type ReplierListener_Access is access all ReplierListener'Class; function On_Request (Self : in out ReplierListener; Request_Data : Request_DataReaders.Treats.Data_Type) return Reply_DataWriters.Treats.Data_Type is abstract; type Ref is limited new Dds.Entity_Impl.Ref and Dds.Request_Reply.Ref with private; type Ref_Access is access all Ref'Class; generic Service_Name : Standard.String := ""; Request_Topic_Name : Standard.String := ""; Reply_Topic_Name : Standard.String := ""; package TopicReplier is type TopicReplierListener is interface and ReplierListener; function On_Request (Self : in out TopicReplierListener; Request_Data : Request_DataReaders.Treats.Data_Type) return Reply_DataWriters.Treats.Data_Type is abstract; end TopicReplier; function Create (Participant : DDS.DomainParticipant.Ref_Access; Service_Name : DDS.String; Datawriter_Qos : DDS.DataWriterQoS := DDS.Publisher.DATAWRITER_QOS_DEFAULT; Datareader_Qos : DDS.DataReaderQoS := DDS.Subscriber.DATAREADER_QOS_DEFAULT; Listener : ReplierListener_Access := null) return Ref_Access; function Create (Participant : DDS.DomainParticipant.Ref_Access; Service_Name : DDS.String; Datawriter_Qos : DDS.String; Datareader_Qos : DDS.String; Listener : ReplierListener_Access := null) return Ref_Access; function Create (Participant : DDS.DomainParticipant.Ref_Access; Service_Name : DDS.String; Request_Topic_Name : DDS.String; Reply_Topic_Name : DDS.String; Publisher : DDS.Publisher.Ref_Access; Subscriber : DDS.Subscriber.Ref_Access; Listener : ReplierListener_Access := null) return Ref_Access; function Create (Participant : DDS.DomainParticipant.Ref_Access; Service_Name : DDS.String; Request_Topic_Name : DDS.String; Reply_Topic_Name : DDS.String; Qos_Library_Name : DDS.String; Qos_Profile_Name : DDS.String; Publisher : DDS.Publisher.Ref_Access; Subscriber : DDS.Subscriber.Ref_Access; Listener : ReplierListener_access := null) return Ref_Access; function Take_Request (Self : not null access Ref; Requests : aliased Request_DataReaders.Treats.Data_Type; Sample_Info : not null access DDS.SampleInfo_Seq.Sequence) return DDS.ReturnCode_T; function Take_Request (Self : not null access Ref) return Request_DataReaders.Container'Class; function Take_Requests (Self : not null access Ref; Max_Request_Count : DDS.Long) return Request_DataReaders.Container'Class; function Read_Request (Self : not null access Ref; Requests : aliased Request_DataReaders.Treats.Data_Type; Sample_Info : not null access DDS.SampleInfo_Seq.Sequence) return DDS.ReturnCode_T; function Read_Requests (Self : not null access Ref; Requests : not null Request_DataReaders.Treats.Data_Sequences.Sequence_Access; Sample_Info : not null access DDS.SampleInfo_Seq.Sequence; Max_Request_Count : DDS.Long) return DDS.ReturnCode_T; function Read_Requests (Self : not null access Ref; Max_Request_Count : DDS.Long := DDS.Long'Last) return Request_DataReaders.Container'Class; function Receive_Request (Self : not null access Ref; Request : access Request_DataReaders.Treats.Data_Type; Info_Seq : not null access DDS.SampleInfo_Seq.Sequence; Timeout : DDS.Duration_T) return DDS.ReturnCode_T; function Receive_Requests (Self : not null access Ref; Requests : not null Request_DataReaders.Treats.Data_Sequences.Sequence_Access; Sample_Info : not null access DDS.SampleInfo_Seq.Sequence; Min_Request_Count : Request_DataReaders.Treats.Index_Type; Max_Request_Count : Request_DataReaders.Treats.Index_Type; Timeout : DDS.Duration_T) return DDS.ReturnCode_T; function Receive_Requests (Self : not null access Ref; Min_Request_Count : Request_DataReaders.Treats.Index_Type; Max_Request_Count : Request_DataReaders.Treats.Index_Type; Timeout : DDS.Duration_T) return Request_DataReaders.Container'Class; procedure Send_Reply (Self : not null access Ref; Reply : access Reply_DataWriters.Treats.Data_Type; Related_Request_Info : DDS.SampleIdentity_T); procedure Send_Reply (Self : not null access Ref; Reply : access Reply_DataWriters.Treats.Data_Type; Related_Request_Info : DDS.SampleInfo); procedure Send_Reply (Self : not null access Ref; Reply : Reply_DataWriters.Treats.Data_Type; Related_Request_Info : DDS.SampleIdentity_T); procedure Send_Reply (Self : not null access Ref; Reply : Reply_DataWriters.Treats.Data_Type; Related_Request_Info : DDS.SampleInfo); procedure Send_Reply (Self : not null access Ref; Reply : Reply_DataWriters.Treats.Data_Array; Related_Request_Info : DDS.SampleIdentity_T); procedure Send_Reply (Self : not null access Ref; Reply : Reply_DataWriters.Treats.Data_Array; Related_Request_Info : DDS.SampleInfo); procedure Return_Loan (Self : not null access Ref; Requests : not null Reply_DataWriters.Treats.Data_Sequences.Sequence_Access; Sample_Info : DDS.SampleInfo_Seq.Sequence_Access); function Get_Request_DataReader (Self : not null access Ref) return Request_DataReaders.Ref_Access; function Get_Reply_DataWriter (Self : not null access Ref) return Reply_DataWriters.Ref_Access; private type Ref is limited new Dds.Entity_Impl.Ref and Dds.Request_Reply.Ref with record Request_Topic : DDS.Topic.Ref_Access; Reply_Topic : DDS.Topic.Ref_Access; Request_DataReader : Request_DataReaders.Ref_Access; Reply_DatWriter : Reply_DataWriters.Ref_Access; end record; end Dds.Request_Reply.Reply_Generic;
-- SPDX-FileCopyrightText: 2020 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ---------------------------------------------------------------- with League.Strings; package Magics is pragma Preelaborate; function "+" (Text : Wide_Wide_String) return League.Strings.Universal_String renames League.Strings.To_Universal_String; end Magics;
----------------------------------------------------------------------- -- util-encoders-ecc -- Error Correction Code -- Copyright (C) 2019 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Interfaces; package body Util.Encoders.ECC is use Interfaces; type Byte_Table is array (Interfaces.Unsigned_8 range 0 .. 255) of Interfaces.Unsigned_8; type Parity_Table is array (Ada.Streams.Stream_Element) of Interfaces.Unsigned_8; Parity : constant Parity_Table := (16#FF#, 16#D4#, 16#D2#, 16#F9#, 16#CC#, 16#E7#, 16#E1#, 16#CA#, 16#CA#, 16#E1#, 16#E7#, 16#CC#, 16#F9#, 16#D2#, 16#D4#, 16#FF#, 16#B4#, 16#9F#, 16#99#, 16#B2#, 16#87#, 16#AC#, 16#AA#, 16#81#, 16#81#, 16#AA#, 16#AC#, 16#87#, 16#B2#, 16#99#, 16#9F#, 16#B4#, 16#B2#, 16#99#, 16#9F#, 16#B4#, 16#81#, 16#AA#, 16#AC#, 16#87#, 16#87#, 16#AC#, 16#AA#, 16#81#, 16#B4#, 16#9F#, 16#99#, 16#B2#, 16#F9#, 16#D2#, 16#D4#, 16#FF#, 16#CA#, 16#E1#, 16#E7#, 16#CC#, 16#CC#, 16#E7#, 16#E1#, 16#CA#, 16#FF#, 16#D4#, 16#D2#, 16#F9#, 16#AC#, 16#87#, 16#81#, 16#AA#, 16#9F#, 16#B4#, 16#B2#, 16#99#, 16#99#, 16#B2#, 16#B4#, 16#9F#, 16#AA#, 16#81#, 16#87#, 16#AC#, 16#E7#, 16#CC#, 16#CA#, 16#E1#, 16#D4#, 16#FF#, 16#F9#, 16#D2#, 16#D2#, 16#F9#, 16#FF#, 16#D4#, 16#E1#, 16#CA#, 16#CC#, 16#E7#, 16#E1#, 16#CA#, 16#CC#, 16#E7#, 16#D2#, 16#F9#, 16#FF#, 16#D4#, 16#D4#, 16#FF#, 16#F9#, 16#D2#, 16#E7#, 16#CC#, 16#CA#, 16#E1#, 16#AA#, 16#81#, 16#87#, 16#AC#, 16#99#, 16#B2#, 16#B4#, 16#9F#, 16#9F#, 16#B4#, 16#B2#, 16#99#, 16#AC#, 16#87#, 16#81#, 16#AA#, 16#AA#, 16#81#, 16#87#, 16#AC#, 16#99#, 16#B2#, 16#B4#, 16#9F#, 16#9F#, 16#B4#, 16#B2#, 16#99#, 16#AC#, 16#87#, 16#81#, 16#AA#, 16#E1#, 16#CA#, 16#CC#, 16#E7#, 16#D2#, 16#F9#, 16#FF#, 16#D4#, 16#D4#, 16#FF#, 16#F9#, 16#D2#, 16#E7#, 16#CC#, 16#CA#, 16#E1#, 16#E7#, 16#CC#, 16#CA#, 16#E1#, 16#D4#, 16#FF#, 16#F9#, 16#D2#, 16#D2#, 16#F9#, 16#FF#, 16#D4#, 16#E1#, 16#CA#, 16#CC#, 16#E7#, 16#AC#, 16#87#, 16#81#, 16#AA#, 16#9F#, 16#B4#, 16#B2#, 16#99#, 16#99#, 16#B2#, 16#B4#, 16#9F#, 16#AA#, 16#81#, 16#87#, 16#AC#, 16#F9#, 16#D2#, 16#D4#, 16#FF#, 16#CA#, 16#E1#, 16#E7#, 16#CC#, 16#CC#, 16#E7#, 16#E1#, 16#CA#, 16#FF#, 16#D4#, 16#D2#, 16#F9#, 16#B2#, 16#99#, 16#9F#, 16#B4#, 16#81#, 16#AA#, 16#AC#, 16#87#, 16#87#, 16#AC#, 16#AA#, 16#81#, 16#B4#, 16#9F#, 16#99#, 16#B2#, 16#B4#, 16#9F#, 16#99#, 16#B2#, 16#87#, 16#AC#, 16#AA#, 16#81#, 16#81#, 16#AA#, 16#AC#, 16#87#, 16#B2#, 16#99#, 16#9F#, 16#B4#, 16#FF#, 16#D4#, 16#D2#, 16#F9#, 16#CC#, 16#E7#, 16#E1#, 16#CA#, 16#CA#, 16#E1#, 16#E7#, 16#CC#, 16#F9#, 16#D2#, 16#D4#, 16#FF#); Bit_Count_Table : constant Byte_Table := (0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8); function Count (Data : Ada.Streams.Stream_Element) return Natural; -- Make the 3 bytes ECC code that corresponds to the data array. procedure Make (Data : in Ada.Streams.Stream_Element_Array; Code : out ECC_Code) is LP0, LP1, LP2, LP3, LP4, LP5, LP6, LP7 : Ada.Streams.Stream_Element := 0; LP8, LP9, LP10, LP11, LP12, LP13, LP14, LP15 : Ada.Streams.Stream_Element := 0; LP16, LP17 : Ada.Streams.Stream_Element := 0; I : Unsigned_16 := 0; begin for D of Data loop if (I and 16#01#) /= 0 then LP1 := LP1 xor D; else LP0 := LP0 xor D; end if; if (I and 16#02#) /= 0 then LP3 := LP3 xor D; else LP2 := LP2 xor D; end if; if (I and 16#04#) /= 0 then LP5 := LP5 xor D; else LP4 := LP4 xor D; end if; if (I and 16#08#) /= 0 then LP7 := LP7 xor D; else LP6 := LP6 xor D; end if; if (I and 16#10#) /= 0 then LP9 := LP9 xor D; else LP8 := LP8 xor D; end if; if (I and 16#20#) /= 0 then LP11 := LP11 xor D; else LP10 := LP10 xor D; end if; if (I and 16#40#) /= 0 then LP13 := LP13 xor D; else LP12 := LP12 xor D; end if; if (I and 16#80#) /= 0 then LP15 := LP15 xor D; else LP14 := LP14 xor D; end if; if Data'Length = 512 then if (I and 16#100#) /= 0 then LP17 := LP17 xor D; else LP16 := LP16 xor D; end if; end if; I := I + 1; end loop; Code (0) := Stream_Element ((Parity (LP0) and 16#01#) or Shift_Left (Parity (LP1) and 16#01#, 1) or Shift_Left (Parity (LP2) and 16#01#, 2) or Shift_Left (Parity (LP3) and 16#01#, 3) or Shift_Left (Parity (LP4) and 16#01#, 4) or Shift_Left (Parity (LP5) and 16#01#, 5) or Shift_Left (Parity (LP6) and 16#01#, 6) or Shift_Left (Parity (LP7) and 16#01#, 7)); Code (1) := Stream_Element ((Parity (LP8) and 16#01#) or Shift_Left (Parity (LP9) and 16#01#, 1) or Shift_Left (Parity (LP10) and 16#01#, 2) or Shift_Left (Parity (LP11) and 16#01#, 3) or Shift_Left (Parity (LP12) and 16#01#, 4) or Shift_Left (Parity (LP13) and 16#01#, 5) or Shift_Left (Parity (LP14) and 16#01#, 6) or Shift_Left (Parity (LP15) and 16#01#, 7)); Code (2) := Stream_Element (Shift_Left (Parity (LP15 xor LP14) and 16#fe#, 1) or Shift_Left (Parity (LP17) and 16#01#, 1) or (Parity (LP16) and 16#01#)); end Make; function Count (Data : Ada.Streams.Stream_Element) return Natural is begin return Natural (Bit_Count_Table (Interfaces.Unsigned_8 (Data))); end Count; -- ------------------------------ -- Check and correct the data array according to the expected ECC codes and current codes. -- At most one bit can be fixed and two error bits can be detected. -- ------------------------------ function Correct (Data : in out Ada.Streams.Stream_Element_Array; Expect_Code : in ECC_Code; Current_Code : in ECC_Code) return ECC_Result is Check : ECC_Code; Bits : Natural; Bit_Pos : Natural; Pos : Unsigned_16; begin Check (0) := Expect_Code (0) xor Current_Code (0); Check (1) := Expect_Code (1) xor Current_Code (1); Check (2) := Expect_Code (2) xor Current_Code (2); if (Check (0) or Check (1) or Check (2)) = 0 then return NO_ERROR; end if; Bits := Count (Check (0)) + Count (Check (1)) + Count (Check (2)); if (Bits = 11 and Data'Length = 256) or (Bits = 12 and Data'Length = 512) then Bit_Pos := Natural ((Shift_Right (Unsigned_8 (Check (2)), 3) and 16#01#) or (Shift_Right (Unsigned_8 (Check (2)), 4) and 16#02#) or (Shift_Right (Unsigned_8 (Check (2)), 5) and 16#04#)); Pos := ((Shift_Right (Unsigned_16 (Check (0)), 1) and 16#01#) or (Shift_Right (Unsigned_16 (Check (0)), 2) and 16#02#) or (Shift_Right (Unsigned_16 (Check (0)), 3) and 16#04#) or (Shift_Right (Unsigned_16 (Check (0)), 4) and 16#08#) or (Shift_Left (Unsigned_16 (Check (1)), 3) and 16#10#) or (Shift_Left (Unsigned_16 (Check (1)), 2) and 16#20#) or (Shift_Left (Unsigned_16 (Check (1)), 1) and 16#40#) or (Unsigned_16 (Check (1)) and 16#80#)); if Data'Length = 512 then Pos := Pos + (Shift_Left (Unsigned_16 (Check (2)), 7) and 16#100#); end if; Data (Stream_Element_Offset (Pos)) := Data (Stream_Element_Offset (Pos)) xor Stream_Element (Shift_Left (Unsigned_8 (1), Bit_Pos)); return CORRECTABLE_ERROR; elsif Bits = 1 then return ECC_ERROR; else return UNCORRECTABLE_ERROR; end if; end Correct; -- ------------------------------ -- Check and correct the data array according to the expected ECC codes and current codes. -- At most one bit can be fixed and two error bits can be detected. -- ------------------------------ function Correct (Data : in out Ada.Streams.Stream_Element_Array; Expect_Code : in ECC_Code) return ECC_Result is Current_Code : ECC_Code; begin Make (Data, Current_Code); return Correct (Data, Expect_Code, Current_Code); end Correct; end Util.Encoders.ECC;
pragma License (Unrestricted); -- Ada 2012 private with System; package Ada.Strings.UTF_Encoding is pragma Pure; -- Declarations common to the string encoding packages -- modified -- UTF-32 support is added. type Encoding_Scheme is ( UTF_8, UTF_16BE, UTF_16LE, UTF_32BE, UTF_32LE); -- additional subtype UTF_String is String; subtype UTF_8_String is String; subtype UTF_16_Wide_String is Wide_String; -- extended subtype UTF_32_Wide_Wide_String is Wide_Wide_String; Encoding_Error : exception; BOM_8 : aliased constant String := -- "aliased" is extended Character'Val (16#EF#) & Character'Val (16#BB#) & Character'Val (16#BF#); BOM_16BE : aliased constant String := -- "aliased" is extended Character'Val (16#FE#) & Character'Val (16#FF#); BOM_16LE : aliased constant String := -- "aliased" is extended Character'Val (16#FF#) & Character'Val (16#FE#); BOM_16 : constant Wide_String := (1 => Wide_Character'Val (16#FEFF#)); -- extended BOM_32BE : aliased constant String := Character'Val (16#00#) & Character'Val (16#00#) & Character'Val (16#FE#) & Character'Val (16#FF#); -- extended BOM_32LE : aliased constant String := Character'Val (16#FF#) & Character'Val (16#FE#) & Character'Val (16#00#) & Character'Val (16#00#); -- extended BOM_32 : constant Wide_Wide_String := (1 => Wide_Wide_Character'Val (16#0000FEFF#)); function Encoding ( Item : UTF_String; Default : Encoding_Scheme := UTF_8) return Encoding_Scheme; -- extended UTF_16_Wide_String_Scheme : constant Encoding_Scheme range UTF_16BE .. UTF_16LE; UTF_32_Wide_Wide_String_Scheme : constant Encoding_Scheme range UTF_32BE .. UTF_32LE; private use type System.Bit_Order; UTF_16_Wide_String_Scheme : constant Encoding_Scheme := Encoding_Scheme'Val ( Encoding_Scheme'Pos (UTF_16BE) * Boolean'Pos (System.Default_Bit_Order = System.High_Order_First) + Encoding_Scheme'Pos (UTF_16LE) * Boolean'Pos (System.Default_Bit_Order = System.Low_Order_First)); UTF_32_Wide_Wide_String_Scheme : constant Encoding_Scheme := Encoding_Scheme'Val ( Encoding_Scheme'Pos (UTF_32BE) * Boolean'Pos (System.Default_Bit_Order = System.High_Order_First) + Encoding_Scheme'Pos (UTF_32LE) * Boolean'Pos (System.Default_Bit_Order = System.Low_Order_First)); BOM_Table : constant array (Encoding_Scheme) of not null access constant UTF_String := ( UTF_8 => BOM_8'Access, UTF_16BE => BOM_16BE'Access, UTF_16LE => BOM_16LE'Access, UTF_32BE => BOM_32BE'Access, UTF_32LE => BOM_32LE'Access); end Ada.Strings.UTF_Encoding;
-- SPDX-FileCopyrightText: 2021 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- with Ada.Streams; with Ada.Unchecked_Conversion; with Interfaces; with System; package body LoRa is pragma Discard_Names; -- procedure puts -- (data : String) -- with Import, Convention => C, External_Name => "puts"; package Address is type Register is mod 2 **7; RegFifo : constant Register := 16#00#; RegOpMode : constant Register := 16#01#; RegFrfMsb : constant Register := 16#06#; RegFrfMid : constant Register := 16#07#; RegFrfLsb : constant Register := 16#08#; RegPaConfig : constant Register := 16#09#; RegLna : constant Register := 16#0C#; RegFifoAddrPtr : constant Register := 16#0D#; RegFifoTxBaseAddr : constant Register := 16#0E#; RegFifoRxBaseAddr : constant Register := 16#0F#; RegFifoRxCurrentAddr : constant Register := 16#10#; RegIrqFlagsMask : constant Register := 16#11#; RegIrqFlags : constant Register := 16#12#; RegRxNbBytes : constant Register := 16#13#; RegPktSnrValue : constant Register := 16#19#; RegPktRssiValue : constant Register := 16#1A#; RegModemConfig1 : constant Register := 16#1D#; RegModemConfig2 : constant Register := 16#1E#; RegSymbTimeoutLsb : constant Register := 16#1F#; RegPreambleMsb : constant Register := 16#20#; RegPreambleLsb : constant Register := 16#21#; RegModemConfig3 : constant Register := 16#26#; RegDetectOptimize : constant Register := 16#31#; RegDetectionThreshold : constant Register := 16#37#; RegSyncWord : constant Register := 16#39#; Version : constant Register := 16#42#; RegPaDac : constant Register := 16#4D#; end Address; procedure Read (Addr : Address.Register; Value : out Interfaces.Unsigned_8); procedure Write (Addr : Address.Register; Value : Interfaces.Unsigned_8); type Modulation_Scheme is (FSK, OOK); type FSK_OOK_Mode is (Sleep, Standby, FS_TX, Transmitter, FS_RX, Receiver); for FSK_OOK_Mode use (0, 1, 2, 3, 4, 5); type LoRa_Mode is (Sleep, Standby, FS_TX, Transmit, FS_RX, Receive_Continuous, Receive_Single, Channel_Activity_Detection); for LoRa_Mode use (0, 1, 2, 3, 4, 5, 6, 7); type RegOpMode (LongRangeMode : Boolean := False) is record -- This bit can be modified only in Sleep mode. A write operation on -- other device modes is ignored. LowFrequencyModeOn : Boolean; -- Access Low Frequency Mode registers case LongRangeMode is when False => ModulationType : Modulation_Scheme; FSK_OOK_Mode : LoRa.FSK_OOK_Mode; when True => AccessSharedReg : Boolean; -- Access FSK registers page in LoRa Mode (0x0D .. 0x3F) LoRa_Mode : LoRa.LoRa_Mode; end case; end record with Size => 8; for RegOpMode use record LongRangeMode at 0 range 7 .. 7; ModulationType at 0 range 5 .. 6; LowFrequencyModeOn at 0 range 3 .. 3; FSK_OOK_Mode at 0 range 0 .. 2; AccessSharedReg at 0 range 6 .. 6; LoRa_Mode at 0 range 0 .. 2; end record; function To_Byte is new Ada.Unchecked_Conversion (RegOpMode, Interfaces.Unsigned_8); type RegPaConfig is record PaSelect : Boolean; MaxPower : Natural range 0 .. 7; -- Select max output power: Pmax=10.8+0.6*MaxPower [dBm] OutputPower : Natural range 0 .. 15; -- Pout=Pmax-(15-OutputPower) if PaSelect = 0 (RFO pins) -- Pout=17-(15-OutputPower) if PaSelect = 1 (PA_BOOST pin) end record with Size => 8; for RegPaConfig use record PaSelect at 0 range 7 .. 7; MaxPower at 0 range 4 .. 6; OutputPower at 0 range 0 .. 3; end record; function To_Byte is new Ada.Unchecked_Conversion (RegPaConfig, Interfaces.Unsigned_8); type RegLNA is record LnaGain : Natural range 1 .. 6; -- LNA gain setting -- 1 = maximum gain, 6 = minimum gain LnaBoostLf : Natural range 0 .. 3 := 0; -- Low Frequency (RFI_LF) LNA current adjustment LnaBoostHf : Natural range 0 .. 3 := 0; -- High Frequency (RFI_HF) LNA current adjustment end record with Size => 8; for RegLNA use record LnaGain at 0 range 5 .. 7; LnaBoostLf at 0 range 3 .. 4; LnaBoostHf at 0 range 0 .. 1; end record; function To_Byte is new Ada.Unchecked_Conversion (RegLNA, Interfaces.Unsigned_8); type RegRxConfig is record RestartRxOnCollision : Boolean; RestartRxWithoutPllLock : Boolean; RestartRxWithPllLock : Boolean; AfcAutoOn : Boolean; AgcAutoOn : Boolean; RxTrigger : Natural range 0 .. 7; end record with Size => 8; for RegRxConfig use record RestartRxOnCollision at 0 range 7 .. 7; RestartRxWithoutPllLock at 0 range 6 .. 6; RestartRxWithPllLock at 0 range 5 .. 5; AfcAutoOn at 0 range 4 .. 4; AgcAutoOn at 0 range 3 .. 3; RxTrigger at 0 range 0 .. 2; end record; function To_Byte is new Ada.Unchecked_Conversion (RegRxConfig, Interfaces.Unsigned_8); type RegIrqFlags is record RxTimeout : Boolean; RxDone : Boolean; PayloadCrcError : Boolean; ValidHeader : Boolean; TxDone : Boolean; CadDone : Boolean; FhssChangeChannel : Boolean; CadDetected : Boolean; end record with Size => 8; for RegIrqFlags use record RxTimeout at 0 range 7 .. 7; RxDone at 0 range 6 .. 6; PayloadCrcError at 0 range 5 .. 5; ValidHeader at 0 range 4 .. 4; TxDone at 0 range 3 .. 3; CadDone at 0 range 2 .. 2; FhssChangeChannel at 0 range 1 .. 1; CadDetected at 0 range 0 .. 0; end record; function To_Byte is new Ada.Unchecked_Conversion (RegIrqFlags, Interfaces.Unsigned_8); function From_Byte is new Ada.Unchecked_Conversion (Interfaces.Unsigned_8, RegIrqFlags); type RegModemConfig1 is record Bw : Natural range 0 .. 15; CodingRate : Natural range 0 .. 7; ImplicitHeaderModeOn : Boolean; end record with Size => 8; for RegModemConfig1 use record Bw at 0 range 4 .. 7; CodingRate at 0 range 1 .. 3; ImplicitHeaderModeOn at 0 range 0 .. 0; end record; function To_Byte is new Ada.Unchecked_Conversion (RegModemConfig1, Interfaces.Unsigned_8); type RegModemConfig2 is record SpreadingFactor : Natural range 0 .. 15; -- SF rate (expressed as a base-2 logarithm) TxContinuousMode : Boolean; RxPayloadCrcOn : Boolean; SymbTimeout : Natural range 0 .. 3; end record with Size => 8; for RegModemConfig2 use record SpreadingFactor at 0 range 4 .. 7; TxContinuousMode at 0 range 3 .. 3; RxPayloadCrcOn at 0 range 2 .. 2; SymbTimeout at 0 range 0 .. 1; end record; function To_Byte is new Ada.Unchecked_Conversion (RegModemConfig2, Interfaces.Unsigned_8); type RegModemConfig3 is record LowDataRateOptimize : Boolean; -- the symbol length exceeds 16ms AgcAutoOn : Boolean; -- LNA gain set by the internal AGC loop end record with Size => 8; for RegModemConfig3 use record LowDataRateOptimize at 0 range 3 .. 3; AgcAutoOn at 0 range 2 .. 2; end record; function To_Byte is new Ada.Unchecked_Conversion (RegModemConfig3, Interfaces.Unsigned_8); type RegPaDac is record PaDac : Natural range 0 .. 7; end record with Size => 8; for RegPaDac use record PaDac at 0 range 0 .. 2; -- Enables the +20dBm option on PA_BOOST pin: -- 0x04 -> Default value -- 0x07 -> +20dBm on PA_BOOST when OutputPower=1111 end record; function To_Byte is new Ada.Unchecked_Conversion (RegPaDac, Interfaces.Unsigned_8); ---------- -- Idle -- ---------- procedure Idle is Mode : constant RegOpMode := (LongRangeMode => True, AccessSharedReg => False, LowFrequencyModeOn => False, LoRa_Mode => Standby); begin Write (Address.RegOpMode, To_Byte (Mode)); end Idle; ---------------- -- Initialize -- ---------------- procedure Initialize (Frequency : Positive) is use type Interfaces.Unsigned_8; use type Interfaces.Unsigned_64; FXOSC : constant := 32_000_000; -- Crystal oscillator frequency FSTEP_Divider : constant := 2 ** 19; -- Frequency synthesizer step = FSOSC/FSTEP_Divider Frf : constant Interfaces.Unsigned_64 := Interfaces.Unsigned_64 (Frequency) * FSTEP_Divider / FXOSC; Value : Interfaces.Unsigned_8; begin Read (Address.Version, Value); if Value /= 16#12# then raise Program_Error; end if; Sleep; -- Set frequency Write (Address.RegFrfMsb, Interfaces.Unsigned_8'Mod (Frf / 16#1_0000#)); Write (Address.RegFrfMid, Interfaces.Unsigned_8'Mod (Frf / 16#1_00#)); Write (Address.RegFrfLsb, Interfaces.Unsigned_8'Mod (Frf)); -- set base addresses Write (Address.RegFifoTxBaseAddr, 0); Write (Address.RegFifoRxBaseAddr, 0); -- set LNA boost declare LNA : constant RegLNA := (LnaGain => 1, LnaBoostLf => 0, LnaBoostHf => 3); -- Boost on, 150% LNA current begin Write (Address.RegLna, To_Byte (LNA)); end; -- set auto AGC declare ModemConfig3 : constant RegModemConfig3 := (LowDataRateOptimize => False, AgcAutoOn => True); begin Write (Address.RegModemConfig3, To_Byte (ModemConfig3)); end; -- set output power to 14 dBm declare PaConfig : constant RegPaConfig := (PaSelect => True, MaxPower => 7, OutputPower => 14 - 2); -- Pout=17-(15-OutputPower) if PaSelect = 1 (PA_BOOST pin) PaDac : constant RegPaDac := (PaDac => 4); begin Write (Address.RegPaConfig, To_Byte (PaConfig)); Write (Address.RegPaDac, To_Byte (PaDac)); end; -- declare ModemConfig2 : constant RegModemConfig2 := (SpreadingFactor => 8, TxContinuousMode => False, RxPayloadCrcOn => True, -- enable crc SymbTimeout => 0); begin Write (Address.RegDetectOptimize, 16#C3#); Write (Address.RegDetectionThreshold, 16#0A#); Write (Address.RegModemConfig2, To_Byte (ModemConfig2)); end; -- setSignalBandwidth 125_000 => 7 declare ModemConfig1 : constant RegModemConfig1 := (Bw => 7, CodingRate => 1, ImplicitHeaderModeOn => False); begin Write (Address.RegModemConfig1, To_Byte (ModemConfig1)); end; Write (Address.RegSyncWord, 16#12#); -- Value 0x34 is reserved for LoRaWAN networks -- setPreambleLength 8 Write (Address.RegPreambleMsb, 0); Write (Address.RegPreambleLsb, 8); -- Write (Address.RegSymbTimeoutLsb, 255); Write (16#40#, 0); Idle; end Initialize; -------------------- -- On_DIO_0_Raise -- -------------------- procedure On_DIO_0_Raise (Data : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset) is use type Ada.Streams.Stream_Element_Offset; Length : Interfaces.Unsigned_8; Value : Interfaces.Unsigned_8; IRQ_Flags : aliased Interfaces.Unsigned_8; Flags : RegIrqFlags with Import, Address => IRQ_Flags'Address; begin Last := Data'First - 1; Read (Address.RegIrqFlags, IRQ_Flags); -- Clear IRQ flags Write (Address.RegIrqFlags, IRQ_Flags); if not Flags.PayloadCrcError then Read (Address.RegRxNbBytes, Length); Read (Address.RegFifoRxCurrentAddr, Value); Write (Address.RegFifoAddrPtr, Value); for J in 1 .. Length loop Read (Address.RegFifo, Value); Last := Last + 1; Data (Last) := Ada.Streams.Stream_Element (Value); end loop; -- Write (Address.RegFifoAddrPtr, 0); why ??? end if; end On_DIO_0_Raise; ---------- -- Read -- ---------- procedure Read (Addr : Address.Register; Value : out Interfaces.Unsigned_8) is begin Raw_Read (Interfaces.Unsigned_8 (Addr), Value); end Read; ------------- -- Receive -- ------------- procedure Receive is use type Interfaces.Unsigned_8; Mode : constant RegOpMode := (LongRangeMode => True, AccessSharedReg => False, LowFrequencyModeOn => False, LoRa_Mode => Receive_Continuous); -- Receive_Single); begin Write (Address.RegFifoAddrPtr, 0); Write (Address.RegOpMode, To_Byte (Mode)); end Receive; ----------- -- Sleep -- ----------- procedure Sleep is Mode : constant RegOpMode := (LongRangeMode => True, AccessSharedReg => False, LowFrequencyModeOn => False, LoRa_Mode => Sleep); begin Write (Address.RegOpMode, To_Byte (Mode)); end Sleep; ----------- -- Write -- ----------- procedure Write (Addr : Address.Register; Value : Interfaces.Unsigned_8) is use type Interfaces.Unsigned_8; begin Raw_Write (16#80# or Interfaces.Unsigned_8 (Addr), Value); end Write; end LoRa;
generic type Element is (<>); with function "+" (Left, Right : Element) return Element is <>; with function "-" (Left, Right : Element) return Element is <>; package Coordinates_2D is type Coordinate_2D is record Line, Column : Element; end record; function "+" (Left, Right : Coordinate_2D) return Coordinate_2D is ((Line => Left.Line + Right.Line, Column => Left.Column + Right.Column)); function "-" (Left, Right : Coordinate_2D) return Coordinate_2D is ((Line => Left.Line - Right.Line, Column => Left.Column - Right.Column)); end Coordinates_2D;
-- -- Copyright (c) 2007, 2008 Tero Koskinen <tero.koskinen@iki.fi> -- -- Permission to use, copy, modify, and distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- with Ada.Finalization; with Ahven.AStrings; with Ahven.Long_AStrings; package Ahven.Listeners is type Test_Phase is (TEST_BEGIN, TEST_RUN, TEST_END); -- What is test doing right now? type Test_Type is (CONTAINER, ROUTINE); type Context (Phase : Test_Phase) is record Test_Name : AStrings.Bounded_String; Test_Kind : Test_Type; case Phase is when TEST_BEGIN | TEST_END => null; when TEST_RUN => Routine_Name : AStrings.Bounded_String; Message : AStrings.Bounded_String; Long_Message : Long_AStrings.Bounded_String; end case; end record; type Result_Listener is abstract new Ada.Finalization.Limited_Controlled with null record; -- Result_Listener is a listener for test results. -- Whenever a test is run, the framework calls -- registered listeners and tells them the result of the test. type Result_Listener_Class_Access is access all Result_Listener'Class; procedure Add_Pass (Listener : in out Result_Listener; Info : Context) is abstract; -- Called after test passes. procedure Add_Failure (Listener : in out Result_Listener; Info : Context) is abstract; -- Called after test fails. procedure Add_Skipped (Listener : in out Result_Listener; Info : Context); -- Called when user wants to skip the test. procedure Add_Error (Listener : in out Result_Listener; Info : Context) is abstract; -- Called after there is an error in the test. procedure Start_Test (Listener : in out Result_Listener; Info : Context) is abstract; -- Called before the test begins. This is called before Add_* procedures. procedure End_Test (Listener : in out Result_Listener; Info : Context) is abstract; -- Called after the test ends. Add_* procedures are called before this. end Ahven.Listeners;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ C H 6 -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2006, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- -- Boston, MA 02110-1301, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Atree; use Atree; with Checks; use Checks; with Debug; use Debug; with Einfo; use Einfo; with Elists; use Elists; with Errout; use Errout; with Expander; use Expander; with Exp_Ch7; use Exp_Ch7; with Exp_Tss; use Exp_Tss; with Fname; use Fname; with Freeze; use Freeze; with Itypes; use Itypes; with Lib.Xref; use Lib.Xref; with Namet; use Namet; with Lib; use Lib; with Nlists; use Nlists; with Nmake; use Nmake; with Opt; use Opt; with Output; use Output; with Rtsfind; use Rtsfind; with Sem; use Sem; with Sem_Cat; use Sem_Cat; with Sem_Ch3; use Sem_Ch3; with Sem_Ch4; use Sem_Ch4; with Sem_Ch5; use Sem_Ch5; with Sem_Ch8; use Sem_Ch8; with Sem_Ch10; use Sem_Ch10; with Sem_Ch12; use Sem_Ch12; with Sem_Disp; use Sem_Disp; with Sem_Dist; use Sem_Dist; with Sem_Elim; use Sem_Elim; with Sem_Eval; use Sem_Eval; with Sem_Mech; use Sem_Mech; with Sem_Prag; use Sem_Prag; with Sem_Res; use Sem_Res; with Sem_Util; use Sem_Util; with Sem_Type; use Sem_Type; with Sem_Warn; use Sem_Warn; with Sinput; use Sinput; with Stand; use Stand; with Sinfo; use Sinfo; with Sinfo.CN; use Sinfo.CN; with Snames; use Snames; with Stringt; use Stringt; with Style; with Stylesw; use Stylesw; with Tbuild; use Tbuild; with Uintp; use Uintp; with Urealp; use Urealp; with Validsw; use Validsw; package body Sem_Ch6 is -- The following flag is used to indicate that two formals in two -- subprograms being checked for conformance differ only in that one is -- an access parameter while the other is of a general access type with -- the same designated type. In this case, if the rest of the signatures -- match, a call to either subprogram may be ambiguous, which is worth -- a warning. The flag is set in Compatible_Types, and the warning emitted -- in New_Overloaded_Entity. May_Hide_Profile : Boolean := False; ----------------------- -- Local Subprograms -- ----------------------- procedure Analyze_Return_Type (N : Node_Id); -- Subsidiary to Process_Formals: analyze subtype mark in function -- specification, in a context where the formals are visible and hide -- outer homographs. procedure Analyze_Generic_Subprogram_Body (N : Node_Id; Gen_Id : Entity_Id); -- Analyze a generic subprogram body. N is the body to be analyzed, and -- Gen_Id is the defining entity Id for the corresponding spec. procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id); -- If a subprogram has pragma Inline and inlining is active, use generic -- machinery to build an unexpanded body for the subprogram. This body is -- subsequenty used for inline expansions at call sites. If subprogram can -- be inlined (depending on size and nature of local declarations) this -- function returns true. Otherwise subprogram body is treated normally. -- If proper warnings are enabled and the subprogram contains a construct -- that cannot be inlined, the offending construct is flagged accordingly. type Conformance_Type is (Type_Conformant, Mode_Conformant, Subtype_Conformant, Fully_Conformant); -- Conformance type used for following call, meaning matches the -- RM definitions of the corresponding terms. procedure Check_Conformance (New_Id : Entity_Id; Old_Id : Entity_Id; Ctype : Conformance_Type; Errmsg : Boolean; Conforms : out Boolean; Err_Loc : Node_Id := Empty; Get_Inst : Boolean := False; Skip_Controlling_Formals : Boolean := False); -- Given two entities, this procedure checks that the profiles associated -- with these entities meet the conformance criterion given by the third -- parameter. If they conform, Conforms is set True and control returns -- to the caller. If they do not conform, Conforms is set to False, and -- in addition, if Errmsg is True on the call, proper messages are output -- to complain about the conformance failure. If Err_Loc is non_Empty -- the error messages are placed on Err_Loc, if Err_Loc is empty, then -- error messages are placed on the appropriate part of the construct -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance -- against a formal access-to-subprogram type so Get_Instance_Of must -- be called. procedure Check_Overriding_Indicator (Subp : Entity_Id; Does_Override : Boolean); -- Verify the consistency of an overriding_indicator given for subprogram -- declaration, body, renaming, or instantiation. The flag Does_Override -- is set if the scope into which we are introducing the subprogram -- contains a type-conformant subprogram that becomes hidden by the new -- subprogram. procedure Check_Subprogram_Order (N : Node_Id); -- N is the N_Subprogram_Body node for a subprogram. This routine applies -- the alpha ordering rule for N if this ordering requirement applicable. procedure Check_Returns (HSS : Node_Id; Mode : Character; Err : out Boolean; Proc : Entity_Id := Empty); -- Called to check for missing return statements in a function body, or for -- returns present in a procedure body which has No_Return set. L is the -- handled statement sequence for the subprogram body. This procedure -- checks all flow paths to make sure they either have return (Mode = 'F', -- used for functions) or do not have a return (Mode = 'P', used for -- No_Return procedures). The flag Err is set if there are any control -- paths not explicitly terminated by a return in the function case, and is -- True otherwise. Proc is the entity for the procedure case and is used -- in posting the warning message. function Conforming_Types (T1 : Entity_Id; T2 : Entity_Id; Ctype : Conformance_Type; Get_Inst : Boolean := False) return Boolean; -- Check that two formal parameter types conform, checking both for -- equality of base types, and where required statically matching -- subtypes, depending on the setting of Ctype. procedure Enter_Overloaded_Entity (S : Entity_Id); -- This procedure makes S, a new overloaded entity, into the first visible -- entity with that name. procedure Install_Entity (E : Entity_Id); -- Make single entity visible. Used for generic formals as well procedure Install_Formals (Id : Entity_Id); -- On entry to a subprogram body, make the formals visible. Note that -- simply placing the subprogram on the scope stack is not sufficient: -- the formals must become the current entities for their names. function Is_Non_Overriding_Operation (Prev_E : Entity_Id; New_E : Entity_Id) return Boolean; -- Enforce the rule given in 12.3(18): a private operation in an instance -- overrides an inherited operation only if the corresponding operation -- was overriding in the generic. This can happen for primitive operations -- of types derived (in the generic unit) from formal private or formal -- derived types. procedure Make_Inequality_Operator (S : Entity_Id); -- Create the declaration for an inequality operator that is implicitly -- created by a user-defined equality operator that yields a boolean. procedure May_Need_Actuals (Fun : Entity_Id); -- Flag functions that can be called without parameters, i.e. those that -- have no parameters, or those for which defaults exist for all parameters procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id); -- If there is a separate spec for a subprogram or generic subprogram, the -- formals of the body are treated as references to the corresponding -- formals of the spec. This reference does not count as an actual use of -- the formal, in order to diagnose formals that are unused in the body. procedure Set_Formal_Validity (Formal_Id : Entity_Id); -- Formal_Id is an formal parameter entity. This procedure deals with -- setting the proper validity status for this entity, which depends -- on the kind of parameter and the validity checking mode. --------------------------------------------- -- Analyze_Abstract_Subprogram_Declaration -- --------------------------------------------- procedure Analyze_Abstract_Subprogram_Declaration (N : Node_Id) is Designator : constant Entity_Id := Analyze_Subprogram_Specification (Specification (N)); Scop : constant Entity_Id := Current_Scope; begin Generate_Definition (Designator); Set_Is_Abstract (Designator); New_Overloaded_Entity (Designator); Check_Delayed_Subprogram (Designator); Set_Categorization_From_Scope (Designator, Scop); if Ekind (Scope (Designator)) = E_Protected_Type then Error_Msg_N ("abstract subprogram not allowed in protected type", N); end if; Generate_Reference_To_Formals (Designator); end Analyze_Abstract_Subprogram_Declaration; ---------------------------- -- Analyze_Function_Call -- ---------------------------- procedure Analyze_Function_Call (N : Node_Id) is P : constant Node_Id := Name (N); L : constant List_Id := Parameter_Associations (N); Actual : Node_Id; begin Analyze (P); -- A call of the form A.B (X) may be an Ada05 call, which is rewritten -- as B (A, X). If the rewriting is successful, the call has been -- analyzed and we just return. if Nkind (P) = N_Selected_Component and then Name (N) /= P and then Is_Rewrite_Substitution (N) and then Present (Etype (N)) then return; end if; -- If error analyzing name, then set Any_Type as result type and return if Etype (P) = Any_Type then Set_Etype (N, Any_Type); return; end if; -- Otherwise analyze the parameters if Present (L) then Actual := First (L); while Present (Actual) loop Analyze (Actual); Check_Parameterless_Call (Actual); Next (Actual); end loop; end if; Analyze_Call (N); end Analyze_Function_Call; ------------------------------------- -- Analyze_Generic_Subprogram_Body -- ------------------------------------- procedure Analyze_Generic_Subprogram_Body (N : Node_Id; Gen_Id : Entity_Id) is Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Id); Kind : constant Entity_Kind := Ekind (Gen_Id); Body_Id : Entity_Id; New_N : Node_Id; Spec : Node_Id; begin -- Copy body and disable expansion while analyzing the generic For a -- stub, do not copy the stub (which would load the proper body), this -- will be done when the proper body is analyzed. if Nkind (N) /= N_Subprogram_Body_Stub then New_N := Copy_Generic_Node (N, Empty, Instantiating => False); Rewrite (N, New_N); Start_Generic; end if; Spec := Specification (N); -- Within the body of the generic, the subprogram is callable, and -- behaves like the corresponding non-generic unit. Body_Id := Defining_Entity (Spec); if Kind = E_Generic_Procedure and then Nkind (Spec) /= N_Procedure_Specification then Error_Msg_N ("invalid body for generic procedure ", Body_Id); return; elsif Kind = E_Generic_Function and then Nkind (Spec) /= N_Function_Specification then Error_Msg_N ("invalid body for generic function ", Body_Id); return; end if; Set_Corresponding_Body (Gen_Decl, Body_Id); if Has_Completion (Gen_Id) and then Nkind (Parent (N)) /= N_Subunit then Error_Msg_N ("duplicate generic body", N); return; else Set_Has_Completion (Gen_Id); end if; if Nkind (N) = N_Subprogram_Body_Stub then Set_Ekind (Defining_Entity (Specification (N)), Kind); else Set_Corresponding_Spec (N, Gen_Id); end if; if Nkind (Parent (N)) = N_Compilation_Unit then Set_Cunit_Entity (Current_Sem_Unit, Defining_Entity (N)); end if; -- Make generic parameters immediately visible in the body. They are -- needed to process the formals declarations. Then make the formals -- visible in a separate step. New_Scope (Gen_Id); declare E : Entity_Id; First_Ent : Entity_Id; begin First_Ent := First_Entity (Gen_Id); E := First_Ent; while Present (E) and then not Is_Formal (E) loop Install_Entity (E); Next_Entity (E); end loop; Set_Use (Generic_Formal_Declarations (Gen_Decl)); -- Now generic formals are visible, and the specification can be -- analyzed, for subsequent conformance check. Body_Id := Analyze_Subprogram_Specification (Spec); -- Make formal parameters visible if Present (E) then -- E is the first formal parameter, we loop through the formals -- installing them so that they will be visible. Set_First_Entity (Gen_Id, E); while Present (E) loop Install_Entity (E); Next_Formal (E); end loop; end if; -- Visible generic entity is callable within its own body Set_Ekind (Gen_Id, Ekind (Body_Id)); Set_Ekind (Body_Id, E_Subprogram_Body); Set_Convention (Body_Id, Convention (Gen_Id)); Set_Scope (Body_Id, Scope (Gen_Id)); Check_Fully_Conformant (Body_Id, Gen_Id, Body_Id); if Nkind (N) = N_Subprogram_Body_Stub then -- No body to analyze, so restore state of generic unit Set_Ekind (Gen_Id, Kind); Set_Ekind (Body_Id, Kind); if Present (First_Ent) then Set_First_Entity (Gen_Id, First_Ent); end if; End_Scope; return; end if; -- If this is a compilation unit, it must be made visible explicitly, -- because the compilation of the declaration, unlike other library -- unit declarations, does not. If it is not a unit, the following -- is redundant but harmless. Set_Is_Immediately_Visible (Gen_Id); Reference_Body_Formals (Gen_Id, Body_Id); Set_Actual_Subtypes (N, Current_Scope); Analyze_Declarations (Declarations (N)); Check_Completion; Analyze (Handled_Statement_Sequence (N)); Save_Global_References (Original_Node (N)); -- Prior to exiting the scope, include generic formals again (if any -- are present) in the set of local entities. if Present (First_Ent) then Set_First_Entity (Gen_Id, First_Ent); end if; Check_References (Gen_Id); end; Process_End_Label (Handled_Statement_Sequence (N), 't', Current_Scope); End_Scope; Check_Subprogram_Order (N); -- Outside of its body, unit is generic again Set_Ekind (Gen_Id, Kind); Generate_Reference (Gen_Id, Body_Id, 'b', Set_Ref => False); Style.Check_Identifier (Body_Id, Gen_Id); End_Generic; end Analyze_Generic_Subprogram_Body; ----------------------------- -- Analyze_Operator_Symbol -- ----------------------------- -- An operator symbol such as "+" or "and" may appear in context where the -- literal denotes an entity name, such as "+"(x, y) or in context when it -- is just a string, as in (conjunction = "or"). In these cases the parser -- generates this node, and the semantics does the disambiguation. Other -- such case are actuals in an instantiation, the generic unit in an -- instantiation, and pragma arguments. procedure Analyze_Operator_Symbol (N : Node_Id) is Par : constant Node_Id := Parent (N); begin if (Nkind (Par) = N_Function_Call and then N = Name (Par)) or else Nkind (Par) = N_Function_Instantiation or else (Nkind (Par) = N_Indexed_Component and then N = Prefix (Par)) or else (Nkind (Par) = N_Pragma_Argument_Association and then not Is_Pragma_String_Literal (Par)) or else Nkind (Par) = N_Subprogram_Renaming_Declaration or else (Nkind (Par) = N_Attribute_Reference and then Attribute_Name (Par) /= Name_Value) then Find_Direct_Name (N); else Change_Operator_Symbol_To_String_Literal (N); Analyze (N); end if; end Analyze_Operator_Symbol; ----------------------------------- -- Analyze_Parameter_Association -- ----------------------------------- procedure Analyze_Parameter_Association (N : Node_Id) is begin Analyze (Explicit_Actual_Parameter (N)); end Analyze_Parameter_Association; ---------------------------- -- Analyze_Procedure_Call -- ---------------------------- procedure Analyze_Procedure_Call (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); P : constant Node_Id := Name (N); Actuals : constant List_Id := Parameter_Associations (N); Actual : Node_Id; New_N : Node_Id; procedure Analyze_Call_And_Resolve; -- Do Analyze and Resolve calls for procedure call ------------------------------ -- Analyze_Call_And_Resolve -- ------------------------------ procedure Analyze_Call_And_Resolve is begin if Nkind (N) = N_Procedure_Call_Statement then Analyze_Call (N); Resolve (N, Standard_Void_Type); else Analyze (N); end if; end Analyze_Call_And_Resolve; -- Start of processing for Analyze_Procedure_Call begin -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote -- a procedure call or an entry call. The prefix may denote an access -- to subprogram type, in which case an implicit dereference applies. -- If the prefix is an indexed component (without implicit defererence) -- then the construct denotes a call to a member of an entire family. -- If the prefix is a simple name, it may still denote a call to a -- parameterless member of an entry family. Resolution of these various -- interpretations is delicate. Analyze (P); -- If this is a call of the form Obj.Op, the call may have been -- analyzed and possibly rewritten into a block, in which case -- we are done. if Analyzed (N) then return; end if; -- If error analyzing prefix, then set Any_Type as result and return if Etype (P) = Any_Type then Set_Etype (N, Any_Type); return; end if; -- Otherwise analyze the parameters if Present (Actuals) then Actual := First (Actuals); while Present (Actual) loop Analyze (Actual); Check_Parameterless_Call (Actual); Next (Actual); end loop; end if; -- Special processing for Elab_Spec and Elab_Body calls if Nkind (P) = N_Attribute_Reference and then (Attribute_Name (P) = Name_Elab_Spec or else Attribute_Name (P) = Name_Elab_Body) then if Present (Actuals) then Error_Msg_N ("no parameters allowed for this call", First (Actuals)); return; end if; Set_Etype (N, Standard_Void_Type); Set_Analyzed (N); elsif Is_Entity_Name (P) and then Is_Record_Type (Etype (Entity (P))) and then Remote_AST_I_Dereference (P) then return; elsif Is_Entity_Name (P) and then Ekind (Entity (P)) /= E_Entry_Family then if Is_Access_Type (Etype (P)) and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type and then No (Actuals) and then Comes_From_Source (N) then Error_Msg_N ("missing explicit dereference in call", N); end if; Analyze_Call_And_Resolve; -- If the prefix is the simple name of an entry family, this is -- a parameterless call from within the task body itself. elsif Is_Entity_Name (P) and then Nkind (P) = N_Identifier and then Ekind (Entity (P)) = E_Entry_Family and then Present (Actuals) and then No (Next (First (Actuals))) then -- Can be call to parameterless entry family. What appears to be the -- sole argument is in fact the entry index. Rewrite prefix of node -- accordingly. Source representation is unchanged by this -- transformation. New_N := Make_Indexed_Component (Loc, Prefix => Make_Selected_Component (Loc, Prefix => New_Occurrence_Of (Scope (Entity (P)), Loc), Selector_Name => New_Occurrence_Of (Entity (P), Loc)), Expressions => Actuals); Set_Name (N, New_N); Set_Etype (New_N, Standard_Void_Type); Set_Parameter_Associations (N, No_List); Analyze_Call_And_Resolve; elsif Nkind (P) = N_Explicit_Dereference then if Ekind (Etype (P)) = E_Subprogram_Type then Analyze_Call_And_Resolve; else Error_Msg_N ("expect access to procedure in call", P); end if; -- The name can be a selected component or an indexed component that -- yields an access to subprogram. Such a prefix is legal if the call -- has parameter associations. elsif Is_Access_Type (Etype (P)) and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type then if Present (Actuals) then Analyze_Call_And_Resolve; else Error_Msg_N ("missing explicit dereference in call ", N); end if; -- If not an access to subprogram, then the prefix must resolve to the -- name of an entry, entry family, or protected operation. -- For the case of a simple entry call, P is a selected component where -- the prefix is the task and the selector name is the entry. A call to -- a protected procedure will have the same syntax. If the protected -- object contains overloaded operations, the entity may appear as a -- function, the context will select the operation whose type is Void. elsif Nkind (P) = N_Selected_Component and then (Ekind (Entity (Selector_Name (P))) = E_Entry or else Ekind (Entity (Selector_Name (P))) = E_Procedure or else Ekind (Entity (Selector_Name (P))) = E_Function) then Analyze_Call_And_Resolve; elsif Nkind (P) = N_Selected_Component and then Ekind (Entity (Selector_Name (P))) = E_Entry_Family and then Present (Actuals) and then No (Next (First (Actuals))) then -- Can be call to parameterless entry family. What appears to be the -- sole argument is in fact the entry index. Rewrite prefix of node -- accordingly. Source representation is unchanged by this -- transformation. New_N := Make_Indexed_Component (Loc, Prefix => New_Copy (P), Expressions => Actuals); Set_Name (N, New_N); Set_Etype (New_N, Standard_Void_Type); Set_Parameter_Associations (N, No_List); Analyze_Call_And_Resolve; -- For the case of a reference to an element of an entry family, P is -- an indexed component whose prefix is a selected component (task and -- entry family), and whose index is the entry family index. elsif Nkind (P) = N_Indexed_Component and then Nkind (Prefix (P)) = N_Selected_Component and then Ekind (Entity (Selector_Name (Prefix (P)))) = E_Entry_Family then Analyze_Call_And_Resolve; -- If the prefix is the name of an entry family, it is a call from -- within the task body itself. elsif Nkind (P) = N_Indexed_Component and then Nkind (Prefix (P)) = N_Identifier and then Ekind (Entity (Prefix (P))) = E_Entry_Family then New_N := Make_Selected_Component (Loc, Prefix => New_Occurrence_Of (Scope (Entity (Prefix (P))), Loc), Selector_Name => New_Occurrence_Of (Entity (Prefix (P)), Loc)); Rewrite (Prefix (P), New_N); Analyze (P); Analyze_Call_And_Resolve; -- Anything else is an error else Error_Msg_N ("invalid procedure or entry call", N); end if; end Analyze_Procedure_Call; ------------------------------ -- Analyze_Return_Statement -- ------------------------------ procedure Analyze_Return_Statement (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Expr : Node_Id; Scope_Id : Entity_Id; Kind : Entity_Kind; R_Type : Entity_Id; begin -- Find subprogram or accept statement enclosing the return statement Scope_Id := Empty; for J in reverse 0 .. Scope_Stack.Last loop Scope_Id := Scope_Stack.Table (J).Entity; exit when Ekind (Scope_Id) /= E_Block and then Ekind (Scope_Id) /= E_Loop; end loop; pragma Assert (Present (Scope_Id)); Kind := Ekind (Scope_Id); Expr := Expression (N); if Kind /= E_Function and then Kind /= E_Generic_Function and then Kind /= E_Procedure and then Kind /= E_Generic_Procedure and then Kind /= E_Entry and then Kind /= E_Entry_Family then Error_Msg_N ("illegal context for return statement", N); elsif Present (Expr) then if Kind = E_Function or else Kind = E_Generic_Function then Set_Return_Present (Scope_Id); R_Type := Etype (Scope_Id); Set_Return_Type (N, R_Type); Analyze_And_Resolve (Expr, R_Type); -- Ada 2005 (AI-318-02): When the result type is an anonymous -- access type, apply an implicit conversion of the expression -- to that type to force appropriate static and run-time -- accessibility checks. if Ada_Version >= Ada_05 and then Ekind (R_Type) = E_Anonymous_Access_Type then Rewrite (Expr, Convert_To (R_Type, Relocate_Node (Expr))); Analyze_And_Resolve (Expr, R_Type); end if; if (Is_Class_Wide_Type (Etype (Expr)) or else Is_Dynamically_Tagged (Expr)) and then not Is_Class_Wide_Type (R_Type) then Error_Msg_N ("dynamically tagged expression not allowed!", Expr); end if; Apply_Constraint_Check (Expr, R_Type); -- Ada 2005 (AI-318-02): Return-by-reference types have been -- removed and replaced by anonymous access results. This is -- an incompatibility with Ada 95. Not clear whether this -- should be enforced yet or perhaps controllable with a -- special switch. ??? -- if Ada_Version >= Ada_05 -- and then Is_Limited_Type (R_Type) -- and then Nkind (Expr) /= N_Aggregate -- and then Nkind (Expr) /= N_Extension_Aggregate -- and then Nkind (Expr) /= N_Function_Call -- then -- Error_Msg_N -- ("(Ada 2005) illegal operand for limited return", N); -- end if; -- ??? A real run-time accessibility check is needed in cases -- involving dereferences of access parameters. For now we just -- check the static cases. if Is_Return_By_Reference_Type (Etype (Scope_Id)) and then Object_Access_Level (Expr) > Subprogram_Access_Level (Scope_Id) then Rewrite (N, Make_Raise_Program_Error (Loc, Reason => PE_Accessibility_Check_Failed)); Analyze (N); Error_Msg_N ("cannot return a local value by reference?", N); Error_Msg_NE ("\& will be raised at run time?", N, Standard_Program_Error); end if; elsif Kind = E_Procedure or else Kind = E_Generic_Procedure then Error_Msg_N ("procedure cannot return value (use function)", N); else Error_Msg_N ("accept statement cannot return value", N); end if; -- No expression present else if Kind = E_Function or Kind = E_Generic_Function then Error_Msg_N ("missing expression in return from function", N); end if; if (Ekind (Scope_Id) = E_Procedure or else Ekind (Scope_Id) = E_Generic_Procedure) and then No_Return (Scope_Id) then Error_Msg_N ("RETURN statement not allowed (No_Return)", N); end if; end if; Check_Unreachable_Code (N); end Analyze_Return_Statement; ------------------------- -- Analyze_Return_Type -- ------------------------- procedure Analyze_Return_Type (N : Node_Id) is Designator : constant Entity_Id := Defining_Entity (N); Typ : Entity_Id := Empty; begin if Result_Definition (N) /= Error then if Nkind (Result_Definition (N)) = N_Access_Definition then Typ := Access_Definition (N, Result_Definition (N)); Set_Parent (Typ, Result_Definition (N)); Set_Is_Local_Anonymous_Access (Typ); Set_Etype (Designator, Typ); -- Ada 2005 (AI-231): Static checks -- Null_Exclusion_Static_Checks needs to be extended to handle -- null exclusion checks for function specifications. ??? -- if Null_Exclusion_Present (N) then -- Null_Exclusion_Static_Checks (Param_Spec); -- end if; -- Subtype_Mark case else Find_Type (Result_Definition (N)); Typ := Entity (Result_Definition (N)); Set_Etype (Designator, Typ); if Ekind (Typ) = E_Incomplete_Type or else (Is_Class_Wide_Type (Typ) and then Ekind (Root_Type (Typ)) = E_Incomplete_Type) then Error_Msg_N ("invalid use of incomplete type", Result_Definition (N)); end if; end if; else Set_Etype (Designator, Any_Type); end if; end Analyze_Return_Type; ----------------------------- -- Analyze_Subprogram_Body -- ----------------------------- -- This procedure is called for regular subprogram bodies, generic bodies, -- and for subprogram stubs of both kinds. In the case of stubs, only the -- specification matters, and is used to create a proper declaration for -- the subprogram, or to perform conformance checks. procedure Analyze_Subprogram_Body (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Body_Spec : constant Node_Id := Specification (N); Body_Id : Entity_Id := Defining_Entity (Body_Spec); Prev_Id : constant Entity_Id := Current_Entity_In_Scope (Body_Id); Body_Deleted : constant Boolean := False; HSS : Node_Id; Spec_Id : Entity_Id; Spec_Decl : Node_Id := Empty; Last_Formal : Entity_Id := Empty; Conformant : Boolean; Missing_Ret : Boolean; P_Ent : Entity_Id; procedure Check_Inline_Pragma (Spec : in out Node_Id); -- Look ahead to recognize a pragma that may appear after the body. -- If there is a previous spec, check that it appears in the same -- declarative part. If the pragma is Inline_Always, perform inlining -- unconditionally, otherwise only if Front_End_Inlining is requested. -- If the body acts as a spec, and inlining is required, we create a -- subprogram declaration for it, in order to attach the body to inline. procedure Copy_Parameter_List (Plist : List_Id); -- Comment required ??? procedure Verify_Overriding_Indicator; -- If there was a previous spec, the entity has been entered in the -- current scope previously. If the body itself carries an overriding -- indicator, check that it is consistent with the known status of the -- entity. ------------------------- -- Check_Inline_Pragma -- ------------------------- procedure Check_Inline_Pragma (Spec : in out Node_Id) is Prag : Node_Id; Plist : List_Id; begin if not Expander_Active then return; end if; if Is_List_Member (N) and then Present (Next (N)) and then Nkind (Next (N)) = N_Pragma then Prag := Next (N); if Nkind (Prag) = N_Pragma and then (Get_Pragma_Id (Chars (Prag)) = Pragma_Inline_Always or else (Front_End_Inlining and then Get_Pragma_Id (Chars (Prag)) = Pragma_Inline)) and then Chars (Expression (First (Pragma_Argument_Associations (Prag)))) = Chars (Body_Id) then Prag := Next (N); else Prag := Empty; end if; else Prag := Empty; end if; if Present (Prag) then if Present (Spec_Id) then if List_Containing (N) = List_Containing (Unit_Declaration_Node (Spec_Id)) then Analyze (Prag); end if; else -- Create a subprogram declaration, to make treatment uniform declare Subp : constant Entity_Id := Make_Defining_Identifier (Loc, Chars (Body_Id)); Decl : constant Node_Id := Make_Subprogram_Declaration (Loc, Specification => New_Copy_Tree (Specification (N))); begin Set_Defining_Unit_Name (Specification (Decl), Subp); if Present (First_Formal (Body_Id)) then Plist := New_List; Copy_Parameter_List (Plist); Set_Parameter_Specifications (Specification (Decl), Plist); end if; Insert_Before (N, Decl); Analyze (Decl); Analyze (Prag); Set_Has_Pragma_Inline (Subp); if Get_Pragma_Id (Chars (Prag)) = Pragma_Inline_Always then Set_Is_Inlined (Subp); Set_Next_Rep_Item (Prag, First_Rep_Item (Subp)); Set_First_Rep_Item (Subp, Prag); end if; Spec := Subp; end; end if; end if; end Check_Inline_Pragma; ------------------------- -- Copy_Parameter_List -- ------------------------- procedure Copy_Parameter_List (Plist : List_Id) is Formal : Entity_Id; begin Formal := First_Formal (Body_Id); while Present (Formal) loop Append (Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Sloc (Formal), Chars => Chars (Formal)), In_Present => In_Present (Parent (Formal)), Out_Present => Out_Present (Parent (Formal)), Parameter_Type => New_Reference_To (Etype (Formal), Loc), Expression => New_Copy_Tree (Expression (Parent (Formal)))), Plist); Next_Formal (Formal); end loop; end Copy_Parameter_List; --------------------------------- -- Verify_Overriding_Indicator -- --------------------------------- procedure Verify_Overriding_Indicator is begin if Must_Override (Body_Spec) and then not Is_Overriding_Operation (Spec_Id) then Error_Msg_NE ("subprogram& is not overriding", Body_Spec, Spec_Id); elsif Must_Not_Override (Body_Spec) and then Is_Overriding_Operation (Spec_Id) then Error_Msg_NE ("subprogram& overrides inherited operation", Body_Spec, Spec_Id); end if; end Verify_Overriding_Indicator; -- Start of processing for Analyze_Subprogram_Body begin if Debug_Flag_C then Write_Str ("==== Compiling subprogram body "); Write_Name (Chars (Body_Id)); Write_Str (" from "); Write_Location (Loc); Write_Eol; end if; Trace_Scope (N, Body_Id, " Analyze subprogram"); -- Generic subprograms are handled separately. They always have a -- generic specification. Determine whether current scope has a -- previous declaration. -- If the subprogram body is defined within an instance of the same -- name, the instance appears as a package renaming, and will be hidden -- within the subprogram. if Present (Prev_Id) and then not Is_Overloadable (Prev_Id) and then (Nkind (Parent (Prev_Id)) /= N_Package_Renaming_Declaration or else Comes_From_Source (Prev_Id)) then if Is_Generic_Subprogram (Prev_Id) then Spec_Id := Prev_Id; Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id)); Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id)); Analyze_Generic_Subprogram_Body (N, Spec_Id); return; else -- Previous entity conflicts with subprogram name. Attempting to -- enter name will post error. Enter_Name (Body_Id); return; end if; -- Non-generic case, find the subprogram declaration, if one was seen, -- or enter new overloaded entity in the current scope. If the -- Current_Entity is the Body_Id itself, the unit is being analyzed as -- part of the context of one of its subunits. No need to redo the -- analysis. elsif Prev_Id = Body_Id and then Has_Completion (Body_Id) then return; else Body_Id := Analyze_Subprogram_Specification (Body_Spec); if Nkind (N) = N_Subprogram_Body_Stub or else No (Corresponding_Spec (N)) then Spec_Id := Find_Corresponding_Spec (N); -- If this is a duplicate body, no point in analyzing it if Error_Posted (N) then return; end if; -- A subprogram body should cause freezing of its own declaration, -- but if there was no previous explicit declaration, then the -- subprogram will get frozen too late (there may be code within -- the body that depends on the subprogram having been frozen, -- such as uses of extra formals), so we force it to be frozen -- here. Same holds if the body and the spec are compilation -- units. if No (Spec_Id) then Freeze_Before (N, Body_Id); elsif Nkind (Parent (N)) = N_Compilation_Unit then Freeze_Before (N, Spec_Id); end if; else Spec_Id := Corresponding_Spec (N); end if; end if; -- Do not inline any subprogram that contains nested subprograms, since -- the backend inlining circuit seems to generate uninitialized -- references in this case. We know this happens in the case of front -- end ZCX support, but it also appears it can happen in other cases as -- well. The backend often rejects attempts to inline in the case of -- nested procedures anyway, so little if anything is lost by this. -- Note that this is test is for the benefit of the back-end. There is -- a separate test for front-end inlining that also rejects nested -- subprograms. -- Do not do this test if errors have been detected, because in some -- error cases, this code blows up, and we don't need it anyway if -- there have been errors, since we won't get to the linker anyway. if Comes_From_Source (Body_Id) and then Serious_Errors_Detected = 0 then P_Ent := Body_Id; loop P_Ent := Scope (P_Ent); exit when No (P_Ent) or else P_Ent = Standard_Standard; if Is_Subprogram (P_Ent) then Set_Is_Inlined (P_Ent, False); if Comes_From_Source (P_Ent) and then Has_Pragma_Inline (P_Ent) then Cannot_Inline ("cannot inline& (nested subprogram)?", N, P_Ent); end if; end if; end loop; end if; Check_Inline_Pragma (Spec_Id); -- Case of fully private operation in the body of the protected type. -- We must create a declaration for the subprogram, in order to attach -- the protected subprogram that will be used in internal calls. if No (Spec_Id) and then Comes_From_Source (N) and then Is_Protected_Type (Current_Scope) then declare Decl : Node_Id; Plist : List_Id; Formal : Entity_Id; New_Spec : Node_Id; begin Formal := First_Formal (Body_Id); -- The protected operation always has at least one formal, namely -- the object itself, but it is only placed in the parameter list -- if expansion is enabled. if Present (Formal) or else Expander_Active then Plist := New_List; else Plist := No_List; end if; Copy_Parameter_List (Plist); if Nkind (Body_Spec) = N_Procedure_Specification then New_Spec := Make_Procedure_Specification (Loc, Defining_Unit_Name => Make_Defining_Identifier (Sloc (Body_Id), Chars => Chars (Body_Id)), Parameter_Specifications => Plist); else New_Spec := Make_Function_Specification (Loc, Defining_Unit_Name => Make_Defining_Identifier (Sloc (Body_Id), Chars => Chars (Body_Id)), Parameter_Specifications => Plist, Result_Definition => New_Occurrence_Of (Etype (Body_Id), Loc)); end if; Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec); Insert_Before (N, Decl); Spec_Id := Defining_Unit_Name (New_Spec); -- Indicate that the entity comes from source, to ensure that -- cross-reference information is properly generated. The body -- itself is rewritten during expansion, and the body entity will -- not appear in calls to the operation. Set_Comes_From_Source (Spec_Id, True); Analyze (Decl); Set_Has_Completion (Spec_Id); Set_Convention (Spec_Id, Convention_Protected); end; elsif Present (Spec_Id) then Spec_Decl := Unit_Declaration_Node (Spec_Id); Verify_Overriding_Indicator; end if; -- Place subprogram on scope stack, and make formals visible. If there -- is a spec, the visible entity remains that of the spec. if Present (Spec_Id) then Generate_Reference (Spec_Id, Body_Id, 'b', Set_Ref => False); if Is_Child_Unit (Spec_Id) then Generate_Reference (Spec_Id, Scope (Spec_Id), 'k', False); end if; if Style_Check then Style.Check_Identifier (Body_Id, Spec_Id); end if; Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id)); Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id)); if Is_Abstract (Spec_Id) then Error_Msg_N ("an abstract subprogram cannot have a body", N); return; else Set_Convention (Body_Id, Convention (Spec_Id)); Set_Has_Completion (Spec_Id); if Is_Protected_Type (Scope (Spec_Id)) then Set_Privals_Chain (Spec_Id, New_Elmt_List); end if; -- If this is a body generated for a renaming, do not check for -- full conformance. The check is redundant, because the spec of -- the body is a copy of the spec in the renaming declaration, -- and the test can lead to spurious errors on nested defaults. if Present (Spec_Decl) and then not Comes_From_Source (N) and then (Nkind (Original_Node (Spec_Decl)) = N_Subprogram_Renaming_Declaration or else (Present (Corresponding_Body (Spec_Decl)) and then Nkind (Unit_Declaration_Node (Corresponding_Body (Spec_Decl))) = N_Subprogram_Renaming_Declaration)) then Conformant := True; else Check_Conformance (Body_Id, Spec_Id, Fully_Conformant, True, Conformant, Body_Id); end if; -- If the body is not fully conformant, we have to decide if we -- should analyze it or not. If it has a really messed up profile -- then we probably should not analyze it, since we will get too -- many bogus messages. -- Our decision is to go ahead in the non-fully conformant case -- only if it is at least mode conformant with the spec. Note -- that the call to Check_Fully_Conformant has issued the proper -- error messages to complain about the lack of conformance. if not Conformant and then not Mode_Conformant (Body_Id, Spec_Id) then return; end if; end if; if Spec_Id /= Body_Id then Reference_Body_Formals (Spec_Id, Body_Id); end if; if Nkind (N) /= N_Subprogram_Body_Stub then Set_Corresponding_Spec (N, Spec_Id); -- Ada 2005 (AI-345): Restore the correct Etype: here we undo the -- work done by Analyze_Subprogram_Specification to allow the -- overriding of task, protected and interface primitives. if Comes_From_Source (Spec_Id) and then Present (First_Entity (Spec_Id)) and then Ekind (Etype (First_Entity (Spec_Id))) = E_Record_Type and then Is_Tagged_Type (Etype (First_Entity (Spec_Id))) and then Present (Abstract_Interfaces (Etype (First_Entity (Spec_Id)))) and then Present (Corresponding_Concurrent_Type (Etype (First_Entity (Spec_Id)))) then Set_Etype (First_Entity (Spec_Id), Corresponding_Concurrent_Type (Etype (First_Entity (Spec_Id)))); end if; -- Ada 2005: A formal that is an access parameter may have a -- designated type imported through a limited_with clause, while -- the body has a regular with clause. Update the types of the -- formals accordingly, so that the non-limited view of each type -- is available in the body. We have already verified that the -- declarations are type-conformant. if Ada_Version >= Ada_05 then declare F_Spec : Entity_Id; F_Body : Entity_Id; begin F_Spec := First_Formal (Spec_Id); F_Body := First_Formal (Body_Id); while Present (F_Spec) loop if Ekind (Etype (F_Spec)) = E_Anonymous_Access_Type and then From_With_Type (Designated_Type (Etype (F_Spec))) then Set_Etype (F_Spec, Etype (F_Body)); end if; Next_Formal (F_Spec); Next_Formal (F_Body); end loop; end; end if; -- Now make the formals visible, and place subprogram -- on scope stack. Install_Formals (Spec_Id); Last_Formal := Last_Entity (Spec_Id); New_Scope (Spec_Id); -- Make sure that the subprogram is immediately visible. For -- child units that have no separate spec this is indispensable. -- Otherwise it is safe albeit redundant. Set_Is_Immediately_Visible (Spec_Id); end if; Set_Corresponding_Body (Unit_Declaration_Node (Spec_Id), Body_Id); Set_Ekind (Body_Id, E_Subprogram_Body); Set_Scope (Body_Id, Scope (Spec_Id)); -- Case of subprogram body with no previous spec else if Style_Check and then Comes_From_Source (Body_Id) and then not Suppress_Style_Checks (Body_Id) and then not In_Instance then Style.Body_With_No_Spec (N); end if; New_Overloaded_Entity (Body_Id); if Nkind (N) /= N_Subprogram_Body_Stub then Set_Acts_As_Spec (N); Generate_Definition (Body_Id); Generate_Reference (Body_Id, Body_Id, 'b', Set_Ref => False, Force => True); Generate_Reference_To_Formals (Body_Id); Install_Formals (Body_Id); New_Scope (Body_Id); end if; end if; -- If this is the proper body of a stub, we must verify that the stub -- conforms to the body, and to the previous spec if one was present. -- we know already that the body conforms to that spec. This test is -- only required for subprograms that come from source. if Nkind (Parent (N)) = N_Subunit and then Comes_From_Source (N) and then not Error_Posted (Body_Id) and then Nkind (Corresponding_Stub (Parent (N))) = N_Subprogram_Body_Stub then declare Old_Id : constant Entity_Id := Defining_Entity (Specification (Corresponding_Stub (Parent (N)))); Conformant : Boolean := False; begin if No (Spec_Id) then Check_Fully_Conformant (Body_Id, Old_Id); else Check_Conformance (Body_Id, Old_Id, Fully_Conformant, False, Conformant); if not Conformant then -- The stub was taken to be a new declaration. Indicate -- that it lacks a body. Set_Has_Completion (Old_Id, False); end if; end if; end; end if; Set_Has_Completion (Body_Id); Check_Eliminated (Body_Id); if Nkind (N) = N_Subprogram_Body_Stub then return; elsif Present (Spec_Id) and then Expander_Active and then (Is_Always_Inlined (Spec_Id) or else (Has_Pragma_Inline (Spec_Id) and Front_End_Inlining)) then Build_Body_To_Inline (N, Spec_Id); end if; -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis -- if its specification we have to install the private withed units. if Is_Compilation_Unit (Body_Id) and then Scope (Body_Id) = Standard_Standard then Install_Private_With_Clauses (Body_Id); end if; -- Now we can go on to analyze the body HSS := Handled_Statement_Sequence (N); Set_Actual_Subtypes (N, Current_Scope); Analyze_Declarations (Declarations (N)); Check_Completion; Analyze (HSS); Process_End_Label (HSS, 't', Current_Scope); End_Scope; Check_Subprogram_Order (N); Set_Analyzed (Body_Id); -- If we have a separate spec, then the analysis of the declarations -- caused the entities in the body to be chained to the spec id, but -- we want them chained to the body id. Only the formal parameters -- end up chained to the spec id in this case. if Present (Spec_Id) then -- We must conform to the categorization of our spec Validate_Categorization_Dependency (N, Spec_Id); -- And if this is a child unit, the parent units must conform if Is_Child_Unit (Spec_Id) then Validate_Categorization_Dependency (Unit_Declaration_Node (Spec_Id), Spec_Id); end if; if Present (Last_Formal) then Set_Next_Entity (Last_Entity (Body_Id), Next_Entity (Last_Formal)); Set_Next_Entity (Last_Formal, Empty); Set_Last_Entity (Body_Id, Last_Entity (Spec_Id)); Set_Last_Entity (Spec_Id, Last_Formal); else Set_First_Entity (Body_Id, First_Entity (Spec_Id)); Set_Last_Entity (Body_Id, Last_Entity (Spec_Id)); Set_First_Entity (Spec_Id, Empty); Set_Last_Entity (Spec_Id, Empty); end if; end if; -- If function, check return statements if Nkind (Body_Spec) = N_Function_Specification then declare Id : Entity_Id; begin if Present (Spec_Id) then Id := Spec_Id; else Id := Body_Id; end if; if Return_Present (Id) then Check_Returns (HSS, 'F', Missing_Ret); if Missing_Ret then Set_Has_Missing_Return (Id); end if; elsif not Is_Machine_Code_Subprogram (Id) and then not Body_Deleted then Error_Msg_N ("missing RETURN statement in function body", N); end if; end; -- If procedure with No_Return, check returns elsif Nkind (Body_Spec) = N_Procedure_Specification and then Present (Spec_Id) and then No_Return (Spec_Id) then Check_Returns (HSS, 'P', Missing_Ret, Spec_Id); end if; -- Now we are going to check for variables that are never modified in -- the body of the procedure. We omit these checks if the first -- statement of the procedure raises an exception. In particular this -- deals with the common idiom of a stubbed function, which might -- appear as something like -- function F (A : Integer) return Some_Type; -- X : Some_Type; -- begin -- raise Program_Error; -- return X; -- end F; -- Here the purpose of X is simply to satisfy the (annoying) -- requirement in Ada that there be at least one return, and we -- certainly do not want to go posting warnings on X that it is not -- initialized! declare Stm : Node_Id := First (Statements (HSS)); begin -- Skip an initial label (for one thing this occurs when we are in -- front end ZCX mode, but in any case it is irrelevant). if Nkind (Stm) = N_Label then Next (Stm); end if; -- Do the test on the original statement before expansion declare Ostm : constant Node_Id := Original_Node (Stm); begin -- If explicit raise statement, return with no checks if Nkind (Ostm) = N_Raise_Statement then return; -- Check for explicit call cases which likely raise an exception elsif Nkind (Ostm) = N_Procedure_Call_Statement then if Is_Entity_Name (Name (Ostm)) then declare Ent : constant Entity_Id := Entity (Name (Ostm)); begin -- If the procedure is marked No_Return, then likely it -- raises an exception, but in any case it is not coming -- back here, so no need to check beyond the call. if Ekind (Ent) = E_Procedure and then No_Return (Ent) then return; -- If the procedure name is Raise_Exception, then also -- assume that it raises an exception. The main target -- here is Ada.Exceptions.Raise_Exception, but this name -- is pretty evocative in any context! Note that the -- procedure in Ada.Exceptions is not marked No_Return -- because of the annoying case of the null exception Id. elsif Chars (Ent) = Name_Raise_Exception then return; end if; end; end if; end if; end; end; -- Check for variables that are never modified declare E1, E2 : Entity_Id; begin -- If there is a separate spec, then transfer Never_Set_In_Source -- flags from out parameters to the corresponding entities in the -- body. The reason we do that is we want to post error flags on -- the body entities, not the spec entities. if Present (Spec_Id) then E1 := First_Entity (Spec_Id); while Present (E1) loop if Ekind (E1) = E_Out_Parameter then E2 := First_Entity (Body_Id); while Present (E2) loop exit when Chars (E1) = Chars (E2); Next_Entity (E2); end loop; if Present (E2) then Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1)); end if; end if; Next_Entity (E1); end loop; end if; -- Check references in body unless it was deleted. Note that the -- check of Body_Deleted here is not just for efficiency, it is -- necessary to avoid junk warnings on formal parameters. if not Body_Deleted then Check_References (Body_Id); end if; end; end Analyze_Subprogram_Body; ------------------------------------ -- Analyze_Subprogram_Declaration -- ------------------------------------ procedure Analyze_Subprogram_Declaration (N : Node_Id) is Designator : constant Entity_Id := Analyze_Subprogram_Specification (Specification (N)); Scop : constant Entity_Id := Current_Scope; -- Start of processing for Analyze_Subprogram_Declaration begin Generate_Definition (Designator); -- Check for RCI unit subprogram declarations against in-lined -- subprograms and subprograms having access parameter or limited -- parameter without Read and Write (RM E.2.3(12-13)). Validate_RCI_Subprogram_Declaration (N); Trace_Scope (N, Defining_Entity (N), " Analyze subprogram spec. "); if Debug_Flag_C then Write_Str ("==== Compiling subprogram spec "); Write_Name (Chars (Designator)); Write_Str (" from "); Write_Location (Sloc (N)); Write_Eol; end if; New_Overloaded_Entity (Designator); Check_Delayed_Subprogram (Designator); -- What is the following code for, it used to be -- ??? Set_Suppress_Elaboration_Checks -- ??? (Designator, Elaboration_Checks_Suppressed (Designator)); -- The following seems equivalent, but a bit dubious if Elaboration_Checks_Suppressed (Designator) then Set_Kill_Elaboration_Checks (Designator); end if; if Scop /= Standard_Standard and then not Is_Child_Unit (Designator) then Set_Categorization_From_Scope (Designator, Scop); else -- For a compilation unit, check for library-unit pragmas New_Scope (Designator); Set_Categorization_From_Pragmas (N); Validate_Categorization_Dependency (N, Designator); Pop_Scope; end if; -- For a compilation unit, set body required. This flag will only be -- reset if a valid Import or Interface pragma is processed later on. if Nkind (Parent (N)) = N_Compilation_Unit then Set_Body_Required (Parent (N), True); if Ada_Version >= Ada_05 and then Nkind (Specification (N)) = N_Procedure_Specification and then Null_Present (Specification (N)) then Error_Msg_N ("null procedure cannot be declared at library level", N); end if; end if; Generate_Reference_To_Formals (Designator); Check_Eliminated (Designator); -- Ada 2005: if procedure is declared with "is null" qualifier, -- it requires no body. if Nkind (Specification (N)) = N_Procedure_Specification and then Null_Present (Specification (N)) then Set_Has_Completion (Designator); Set_Is_Inlined (Designator); end if; end Analyze_Subprogram_Declaration; -------------------------------------- -- Analyze_Subprogram_Specification -- -------------------------------------- -- Reminder: N here really is a subprogram specification (not a subprogram -- declaration). This procedure is called to analyze the specification in -- both subprogram bodies and subprogram declarations (specs). function Analyze_Subprogram_Specification (N : Node_Id) return Entity_Id is Designator : constant Entity_Id := Defining_Entity (N); Formals : constant List_Id := Parameter_Specifications (N); function Has_Interface_Formals (T : List_Id) return Boolean; -- Ada 2005 (AI-251): Returns true if some non class-wide interface -- formal is found. --------------------------- -- Has_Interface_Formals -- --------------------------- function Has_Interface_Formals (T : List_Id) return Boolean is Param_Spec : Node_Id; Formal : Entity_Id; begin Param_Spec := First (T); while Present (Param_Spec) loop Formal := Defining_Identifier (Param_Spec); if Is_Class_Wide_Type (Etype (Formal)) then null; elsif Is_Interface (Etype (Formal)) then return True; end if; Next (Param_Spec); end loop; return False; end Has_Interface_Formals; -- Start of processing for Analyze_Subprogram_Specification begin Generate_Definition (Designator); if Nkind (N) = N_Function_Specification then Set_Ekind (Designator, E_Function); Set_Mechanism (Designator, Default_Mechanism); else Set_Ekind (Designator, E_Procedure); Set_Etype (Designator, Standard_Void_Type); end if; -- Introduce new scope for analysis of the formals and of the -- return type. Set_Scope (Designator, Current_Scope); if Present (Formals) then New_Scope (Designator); Process_Formals (Formals, N); -- Ada 2005 (AI-345): Allow overriding primitives of protected -- interfaces by means of normal subprograms. For this purpose -- temporarily use the corresponding record type as the etype -- of the first formal. if Ada_Version >= Ada_05 and then Comes_From_Source (Designator) and then Present (First_Entity (Designator)) and then (Ekind (Etype (First_Entity (Designator))) = E_Protected_Type or else Ekind (Etype (First_Entity (Designator))) = E_Task_Type) and then Present (Corresponding_Record_Type (Etype (First_Entity (Designator)))) and then Present (Abstract_Interfaces (Corresponding_Record_Type (Etype (First_Entity (Designator))))) then Set_Etype (First_Entity (Designator), Corresponding_Record_Type (Etype (First_Entity (Designator)))); end if; End_Scope; elsif Nkind (N) = N_Function_Specification then Analyze_Return_Type (N); end if; if Nkind (N) = N_Function_Specification then if Nkind (Designator) = N_Defining_Operator_Symbol then Valid_Operator_Definition (Designator); end if; May_Need_Actuals (Designator); if Is_Abstract (Etype (Designator)) and then Nkind (Parent (N)) /= N_Abstract_Subprogram_Declaration and then (Nkind (Parent (N))) /= N_Formal_Abstract_Subprogram_Declaration and then (Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration or else not Is_Entity_Name (Name (Parent (N))) or else not Is_Abstract (Entity (Name (Parent (N))))) then Error_Msg_N ("function that returns abstract type must be abstract", N); end if; end if; if Ada_Version >= Ada_05 and then Comes_From_Source (N) and then Nkind (Parent (N)) /= N_Abstract_Subprogram_Declaration and then (Nkind (N) /= N_Procedure_Specification or else not Null_Present (N)) and then Has_Interface_Formals (Formals) then Error_Msg_Name_1 := Chars (Defining_Unit_Name (Specification (Parent (N)))); Error_Msg_N ("(Ada 2005) interface subprogram % must be abstract or null", N); end if; return Designator; end Analyze_Subprogram_Specification; -------------------------- -- Build_Body_To_Inline -- -------------------------- procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id) is Decl : constant Node_Id := Unit_Declaration_Node (Subp); Original_Body : Node_Id; Body_To_Analyze : Node_Id; Max_Size : constant := 10; Stat_Count : Integer := 0; function Has_Excluded_Declaration (Decls : List_Id) return Boolean; -- Check for declarations that make inlining not worthwhile function Has_Excluded_Statement (Stats : List_Id) return Boolean; -- Check for statements that make inlining not worthwhile: any tasking -- statement, nested at any level. Keep track of total number of -- elementary statements, as a measure of acceptable size. function Has_Pending_Instantiation return Boolean; -- If some enclosing body contains instantiations that appear before -- the corresponding generic body, the enclosing body has a freeze node -- so that it can be elaborated after the generic itself. This might -- conflict with subsequent inlinings, so that it is unsafe to try to -- inline in such a case. function Has_Single_Return return Boolean; -- In general we cannot inline functions that return unconstrained -- type. However, we can handle such functions if all return statements -- return a local variable that is the only declaration in the body -- of the function. In that case the call can be replaced by that -- local variable as is done for other inlined calls. procedure Remove_Pragmas; -- A pragma Unreferenced that mentions a formal parameter has no -- meaning when the body is inlined and the formals are rewritten. -- Remove it from body to inline. The analysis of the non-inlined body -- will handle the pragma properly. function Uses_Secondary_Stack (Bod : Node_Id) return Boolean; -- If the body of the subprogram includes a call that returns an -- unconstrained type, the secondary stack is involved, and it -- is not worth inlining. ------------------------------ -- Has_Excluded_Declaration -- ------------------------------ function Has_Excluded_Declaration (Decls : List_Id) return Boolean is D : Node_Id; function Is_Unchecked_Conversion (D : Node_Id) return Boolean; -- Nested subprograms make a given body ineligible for inlining, but -- we make an exception for instantiations of unchecked conversion. -- The body has not been analyzed yet, so check the name, and verify -- that the visible entity with that name is the predefined unit. ----------------------------- -- Is_Unchecked_Conversion -- ----------------------------- function Is_Unchecked_Conversion (D : Node_Id) return Boolean is Id : constant Node_Id := Name (D); Conv : Entity_Id; begin if Nkind (Id) = N_Identifier and then Chars (Id) = Name_Unchecked_Conversion then Conv := Current_Entity (Id); elsif (Nkind (Id) = N_Selected_Component or else Nkind (Id) = N_Expanded_Name) and then Chars (Selector_Name (Id)) = Name_Unchecked_Conversion then Conv := Current_Entity (Selector_Name (Id)); else return False; end if; return Present (Conv) and then Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Conv))) and then Is_Intrinsic_Subprogram (Conv); end Is_Unchecked_Conversion; -- Start of processing for Has_Excluded_Declaration begin D := First (Decls); while Present (D) loop if (Nkind (D) = N_Function_Instantiation and then not Is_Unchecked_Conversion (D)) or else Nkind (D) = N_Protected_Type_Declaration or else Nkind (D) = N_Package_Declaration or else Nkind (D) = N_Package_Instantiation or else Nkind (D) = N_Subprogram_Body or else Nkind (D) = N_Procedure_Instantiation or else Nkind (D) = N_Task_Type_Declaration then Cannot_Inline ("cannot inline & (non-allowed declaration)?", D, Subp); return True; end if; Next (D); end loop; return False; end Has_Excluded_Declaration; ---------------------------- -- Has_Excluded_Statement -- ---------------------------- function Has_Excluded_Statement (Stats : List_Id) return Boolean is S : Node_Id; E : Node_Id; begin S := First (Stats); while Present (S) loop Stat_Count := Stat_Count + 1; if Nkind (S) = N_Abort_Statement or else Nkind (S) = N_Asynchronous_Select or else Nkind (S) = N_Conditional_Entry_Call or else Nkind (S) = N_Delay_Relative_Statement or else Nkind (S) = N_Delay_Until_Statement or else Nkind (S) = N_Selective_Accept or else Nkind (S) = N_Timed_Entry_Call then Cannot_Inline ("cannot inline & (non-allowed statement)?", S, Subp); return True; elsif Nkind (S) = N_Block_Statement then if Present (Declarations (S)) and then Has_Excluded_Declaration (Declarations (S)) then return True; elsif Present (Handled_Statement_Sequence (S)) and then (Present (Exception_Handlers (Handled_Statement_Sequence (S))) or else Has_Excluded_Statement (Statements (Handled_Statement_Sequence (S)))) then return True; end if; elsif Nkind (S) = N_Case_Statement then E := First (Alternatives (S)); while Present (E) loop if Has_Excluded_Statement (Statements (E)) then return True; end if; Next (E); end loop; elsif Nkind (S) = N_If_Statement then if Has_Excluded_Statement (Then_Statements (S)) then return True; end if; if Present (Elsif_Parts (S)) then E := First (Elsif_Parts (S)); while Present (E) loop if Has_Excluded_Statement (Then_Statements (E)) then return True; end if; Next (E); end loop; end if; if Present (Else_Statements (S)) and then Has_Excluded_Statement (Else_Statements (S)) then return True; end if; elsif Nkind (S) = N_Loop_Statement and then Has_Excluded_Statement (Statements (S)) then return True; end if; Next (S); end loop; return False; end Has_Excluded_Statement; ------------------------------- -- Has_Pending_Instantiation -- ------------------------------- function Has_Pending_Instantiation return Boolean is S : Entity_Id := Current_Scope; begin while Present (S) loop if Is_Compilation_Unit (S) or else Is_Child_Unit (S) then return False; elsif Ekind (S) = E_Package and then Has_Forward_Instantiation (S) then return True; end if; S := Scope (S); end loop; return False; end Has_Pending_Instantiation; ------------------------ -- Has_Single_Return -- ------------------------ function Has_Single_Return return Boolean is Return_Statement : Node_Id := Empty; function Check_Return (N : Node_Id) return Traverse_Result; ------------------ -- Check_Return -- ------------------ function Check_Return (N : Node_Id) return Traverse_Result is begin if Nkind (N) = N_Return_Statement then if Present (Expression (N)) and then Is_Entity_Name (Expression (N)) then if No (Return_Statement) then Return_Statement := N; return OK; elsif Chars (Expression (N)) = Chars (Expression (Return_Statement)) then return OK; else return Abandon; end if; else -- Expression has wrong form return Abandon; end if; else return OK; end if; end Check_Return; function Check_All_Returns is new Traverse_Func (Check_Return); -- Start of processing for Has_Single_Return begin return Check_All_Returns (N) = OK and then Present (Declarations (N)) and then Chars (Expression (Return_Statement)) = Chars (Defining_Identifier (First (Declarations (N)))); end Has_Single_Return; -------------------- -- Remove_Pragmas -- -------------------- procedure Remove_Pragmas is Decl : Node_Id; Nxt : Node_Id; begin Decl := First (Declarations (Body_To_Analyze)); while Present (Decl) loop Nxt := Next (Decl); if Nkind (Decl) = N_Pragma and then Chars (Decl) = Name_Unreferenced then Remove (Decl); end if; Decl := Nxt; end loop; end Remove_Pragmas; -------------------------- -- Uses_Secondary_Stack -- -------------------------- function Uses_Secondary_Stack (Bod : Node_Id) return Boolean is function Check_Call (N : Node_Id) return Traverse_Result; -- Look for function calls that return an unconstrained type ---------------- -- Check_Call -- ---------------- function Check_Call (N : Node_Id) return Traverse_Result is begin if Nkind (N) = N_Function_Call and then Is_Entity_Name (Name (N)) and then Is_Composite_Type (Etype (Entity (Name (N)))) and then not Is_Constrained (Etype (Entity (Name (N)))) then Cannot_Inline ("cannot inline & (call returns unconstrained type)?", N, Subp); return Abandon; else return OK; end if; end Check_Call; function Check_Calls is new Traverse_Func (Check_Call); begin return Check_Calls (Bod) = Abandon; end Uses_Secondary_Stack; -- Start of processing for Build_Body_To_Inline begin if Nkind (Decl) = N_Subprogram_Declaration and then Present (Body_To_Inline (Decl)) then return; -- Done already. -- Functions that return unconstrained composite types require -- secondary stack handling, and cannot currently be inlined, unless -- all return statements return a local variable that is the first -- local declaration in the body. elsif Ekind (Subp) = E_Function and then not Is_Scalar_Type (Etype (Subp)) and then not Is_Access_Type (Etype (Subp)) and then not Is_Constrained (Etype (Subp)) then if not Has_Single_Return then Cannot_Inline ("cannot inline & (unconstrained return type)?", N, Subp); return; end if; -- Ditto for functions that return controlled types, where controlled -- actions interfere in complex ways with inlining. elsif Ekind (Subp) = E_Function and then Controlled_Type (Etype (Subp)) then Cannot_Inline ("cannot inline & (controlled return type)?", N, Subp); return; end if; if Present (Declarations (N)) and then Has_Excluded_Declaration (Declarations (N)) then return; end if; if Present (Handled_Statement_Sequence (N)) then if Present (Exception_Handlers (Handled_Statement_Sequence (N))) then Cannot_Inline ("cannot inline& (exception handler)?", First (Exception_Handlers (Handled_Statement_Sequence (N))), Subp); return; elsif Has_Excluded_Statement (Statements (Handled_Statement_Sequence (N))) then return; end if; end if; -- We do not inline a subprogram that is too large, unless it is -- marked Inline_Always. This pragma does not suppress the other -- checks on inlining (forbidden declarations, handlers, etc). if Stat_Count > Max_Size and then not Is_Always_Inlined (Subp) then Cannot_Inline ("cannot inline& (body too large)?", N, Subp); return; end if; if Has_Pending_Instantiation then Cannot_Inline ("cannot inline& (forward instance within enclosing body)?", N, Subp); return; end if; -- Within an instance, the body to inline must be treated as a nested -- generic, so that the proper global references are preserved. if In_Instance then Save_Env (Scope (Current_Scope), Scope (Current_Scope)); Original_Body := Copy_Generic_Node (N, Empty, True); else Original_Body := Copy_Separate_Tree (N); end if; -- We need to capture references to the formals in order to substitute -- the actuals at the point of inlining, i.e. instantiation. To treat -- the formals as globals to the body to inline, we nest it within -- a dummy parameterless subprogram, declared within the real one. -- To avoid generating an internal name (which is never public, and -- which affects serial numbers of other generated names), we use -- an internal symbol that cannot conflict with user declarations. Set_Parameter_Specifications (Specification (Original_Body), No_List); Set_Defining_Unit_Name (Specification (Original_Body), Make_Defining_Identifier (Sloc (N), Name_uParent)); Set_Corresponding_Spec (Original_Body, Empty); Body_To_Analyze := Copy_Generic_Node (Original_Body, Empty, False); -- Set return type of function, which is also global and does not need -- to be resolved. if Ekind (Subp) = E_Function then Set_Result_Definition (Specification (Body_To_Analyze), New_Occurrence_Of (Etype (Subp), Sloc (N))); end if; if No (Declarations (N)) then Set_Declarations (N, New_List (Body_To_Analyze)); else Append (Body_To_Analyze, Declarations (N)); end if; Expander_Mode_Save_And_Set (False); Remove_Pragmas; Analyze (Body_To_Analyze); New_Scope (Defining_Entity (Body_To_Analyze)); Save_Global_References (Original_Body); End_Scope; Remove (Body_To_Analyze); Expander_Mode_Restore; if In_Instance then Restore_Env; end if; -- If secondary stk used there is no point in inlining. We have -- already issued the warning in this case, so nothing to do. if Uses_Secondary_Stack (Body_To_Analyze) then return; end if; Set_Body_To_Inline (Decl, Original_Body); Set_Ekind (Defining_Entity (Original_Body), Ekind (Subp)); Set_Is_Inlined (Subp); end Build_Body_To_Inline; ------------------- -- Cannot_Inline -- ------------------- procedure Cannot_Inline (Msg : String; N : Node_Id; Subp : Entity_Id) is begin -- Do not emit warning if this is a predefined unit which is not -- the main unit. With validity checks enabled, some predefined -- subprograms may contain nested subprograms and become ineligible -- for inlining. if Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Subp))) and then not In_Extended_Main_Source_Unit (Subp) then null; elsif Is_Always_Inlined (Subp) then -- Remove last character (question mark) to make this into an error, -- because the Inline_Always pragma cannot be obeyed. -- LLVM local Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp); elsif Ineffective_Inline_Warnings then Error_Msg_NE (Msg, N, Subp); end if; end Cannot_Inline; ----------------------- -- Check_Conformance -- ----------------------- procedure Check_Conformance (New_Id : Entity_Id; Old_Id : Entity_Id; Ctype : Conformance_Type; Errmsg : Boolean; Conforms : out Boolean; Err_Loc : Node_Id := Empty; Get_Inst : Boolean := False; Skip_Controlling_Formals : Boolean := False) is Old_Type : constant Entity_Id := Etype (Old_Id); New_Type : constant Entity_Id := Etype (New_Id); Old_Formal : Entity_Id; New_Formal : Entity_Id; procedure Conformance_Error (Msg : String; N : Node_Id := New_Id); -- Post error message for conformance error on given node. Two messages -- are output. The first points to the previous declaration with a -- general "no conformance" message. The second is the detailed reason, -- supplied as Msg. The parameter N provide information for a possible -- & insertion in the message, and also provides the location for -- posting the message in the absence of a specified Err_Loc location. ----------------------- -- Conformance_Error -- ----------------------- procedure Conformance_Error (Msg : String; N : Node_Id := New_Id) is Enode : Node_Id; begin Conforms := False; if Errmsg then if No (Err_Loc) then Enode := N; else Enode := Err_Loc; end if; Error_Msg_Sloc := Sloc (Old_Id); case Ctype is when Type_Conformant => Error_Msg_N ("not type conformant with declaration#!", Enode); when Mode_Conformant => Error_Msg_N ("not mode conformant with declaration#!", Enode); when Subtype_Conformant => Error_Msg_N ("not subtype conformant with declaration#!", Enode); when Fully_Conformant => Error_Msg_N ("not fully conformant with declaration#!", Enode); end case; Error_Msg_NE (Msg, Enode, N); end if; end Conformance_Error; -- Start of processing for Check_Conformance begin Conforms := True; -- We need a special case for operators, since they don't appear -- explicitly. if Ctype = Type_Conformant then if Ekind (New_Id) = E_Operator and then Operator_Matches_Spec (New_Id, Old_Id) then return; end if; end if; -- If both are functions/operators, check return types conform if Old_Type /= Standard_Void_Type and then New_Type /= Standard_Void_Type then if not Conforming_Types (Old_Type, New_Type, Ctype, Get_Inst) then Conformance_Error ("return type does not match!", New_Id); return; end if; -- Ada 2005 (AI-231): In case of anonymous access types check the -- null-exclusion and access-to-constant attributes must match. if Ada_Version >= Ada_05 and then Ekind (Etype (Old_Type)) = E_Anonymous_Access_Type and then (Can_Never_Be_Null (Old_Type) /= Can_Never_Be_Null (New_Type) or else Is_Access_Constant (Etype (Old_Type)) /= Is_Access_Constant (Etype (New_Type))) then Conformance_Error ("return type does not match!", New_Id); return; end if; -- If either is a function/operator and the other isn't, error elsif Old_Type /= Standard_Void_Type or else New_Type /= Standard_Void_Type then Conformance_Error ("functions can only match functions!", New_Id); return; end if; -- In subtype conformant case, conventions must match (RM 6.3.1(16)) -- If this is a renaming as body, refine error message to indicate that -- the conflict is with the original declaration. If the entity is not -- frozen, the conventions don't have to match, the one of the renamed -- entity is inherited. if Ctype >= Subtype_Conformant then if Convention (Old_Id) /= Convention (New_Id) then if not Is_Frozen (New_Id) then null; elsif Present (Err_Loc) and then Nkind (Err_Loc) = N_Subprogram_Renaming_Declaration and then Present (Corresponding_Spec (Err_Loc)) then Error_Msg_Name_1 := Chars (New_Id); Error_Msg_Name_2 := Name_Ada + Convention_Id'Pos (Convention (New_Id)); Conformance_Error ("prior declaration for% has convention %!"); else Conformance_Error ("calling conventions do not match!"); end if; return; elsif Is_Formal_Subprogram (Old_Id) or else Is_Formal_Subprogram (New_Id) then Conformance_Error ("formal subprograms not allowed!"); return; end if; end if; -- Deal with parameters -- Note: we use the entity information, rather than going directly -- to the specification in the tree. This is not only simpler, but -- absolutely necessary for some cases of conformance tests between -- operators, where the declaration tree simply does not exist! Old_Formal := First_Formal (Old_Id); New_Formal := First_Formal (New_Id); while Present (Old_Formal) and then Present (New_Formal) loop if Is_Controlling_Formal (Old_Formal) and then Is_Controlling_Formal (New_Formal) and then Skip_Controlling_Formals then goto Skip_Controlling_Formal; end if; if Ctype = Fully_Conformant then -- Names must match. Error message is more accurate if we do -- this before checking that the types of the formals match. if Chars (Old_Formal) /= Chars (New_Formal) then Conformance_Error ("name & does not match!", New_Formal); -- Set error posted flag on new formal as well to stop -- junk cascaded messages in some cases. Set_Error_Posted (New_Formal); return; end if; end if; -- Types must always match. In the visible part of an instance, -- usual overloading rules for dispatching operations apply, and -- we check base types (not the actual subtypes). if In_Instance_Visible_Part and then Is_Dispatching_Operation (New_Id) then if not Conforming_Types (Base_Type (Etype (Old_Formal)), Base_Type (Etype (New_Formal)), Ctype, Get_Inst) then Conformance_Error ("type of & does not match!", New_Formal); return; end if; elsif not Conforming_Types (Etype (Old_Formal), Etype (New_Formal), Ctype, Get_Inst) then Conformance_Error ("type of & does not match!", New_Formal); return; end if; -- For mode conformance, mode must match if Ctype >= Mode_Conformant and then Parameter_Mode (Old_Formal) /= Parameter_Mode (New_Formal) then Conformance_Error ("mode of & does not match!", New_Formal); return; end if; -- Full conformance checks if Ctype = Fully_Conformant then -- We have checked already that names match if Parameter_Mode (Old_Formal) = E_In_Parameter then -- Ada 2005 (AI-231): In case of anonymous access types check -- the null-exclusion and access-to-constant attributes must -- match. if Ada_Version >= Ada_05 and then Ekind (Etype (Old_Formal)) = E_Anonymous_Access_Type and then (Can_Never_Be_Null (Old_Formal) /= Can_Never_Be_Null (New_Formal) or else Is_Access_Constant (Etype (Old_Formal)) /= Is_Access_Constant (Etype (New_Formal))) then -- It is allowed to omit the null-exclusion in case of -- stream attribute subprograms declare TSS_Name : TSS_Name_Type; begin Get_Name_String (Chars (New_Id)); TSS_Name := TSS_Name_Type (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len)); if TSS_Name /= TSS_Stream_Read and then TSS_Name /= TSS_Stream_Write and then TSS_Name /= TSS_Stream_Input and then TSS_Name /= TSS_Stream_Output then Conformance_Error ("type of & does not match!", New_Formal); return; end if; end; end if; -- Check default expressions for in parameters declare NewD : constant Boolean := Present (Default_Value (New_Formal)); OldD : constant Boolean := Present (Default_Value (Old_Formal)); begin if NewD or OldD then -- The old default value has been analyzed because the -- current full declaration will have frozen everything -- before. The new default values have not been -- analyzed, so analyze them now before we check for -- conformance. if NewD then New_Scope (New_Id); Analyze_Per_Use_Expression (Default_Value (New_Formal), Etype (New_Formal)); End_Scope; end if; if not (NewD and OldD) or else not Fully_Conformant_Expressions (Default_Value (Old_Formal), Default_Value (New_Formal)) then Conformance_Error ("default expression for & does not match!", New_Formal); return; end if; end if; end; end if; end if; -- A couple of special checks for Ada 83 mode. These checks are -- skipped if either entity is an operator in package Standard. -- or if either old or new instance is not from the source program. if Ada_Version = Ada_83 and then Sloc (Old_Id) > Standard_Location and then Sloc (New_Id) > Standard_Location and then Comes_From_Source (Old_Id) and then Comes_From_Source (New_Id) then declare Old_Param : constant Node_Id := Declaration_Node (Old_Formal); New_Param : constant Node_Id := Declaration_Node (New_Formal); begin -- Explicit IN must be present or absent in both cases. This -- test is required only in the full conformance case. if In_Present (Old_Param) /= In_Present (New_Param) and then Ctype = Fully_Conformant then Conformance_Error ("(Ada 83) IN must appear in both declarations", New_Formal); return; end if; -- Grouping (use of comma in param lists) must be the same -- This is where we catch a misconformance like: -- A,B : Integer -- A : Integer; B : Integer -- which are represented identically in the tree except -- for the setting of the flags More_Ids and Prev_Ids. if More_Ids (Old_Param) /= More_Ids (New_Param) or else Prev_Ids (Old_Param) /= Prev_Ids (New_Param) then Conformance_Error ("grouping of & does not match!", New_Formal); return; end if; end; end if; -- This label is required when skipping controlling formals <<Skip_Controlling_Formal>> Next_Formal (Old_Formal); Next_Formal (New_Formal); end loop; if Present (Old_Formal) then Conformance_Error ("too few parameters!"); return; elsif Present (New_Formal) then Conformance_Error ("too many parameters!", New_Formal); return; end if; end Check_Conformance; ------------------------------ -- Check_Delayed_Subprogram -- ------------------------------ procedure Check_Delayed_Subprogram (Designator : Entity_Id) is F : Entity_Id; procedure Possible_Freeze (T : Entity_Id); -- T is the type of either a formal parameter or of the return type. -- If T is not yet frozen and needs a delayed freeze, then the -- subprogram itself must be delayed. --------------------- -- Possible_Freeze -- --------------------- procedure Possible_Freeze (T : Entity_Id) is begin if Has_Delayed_Freeze (T) and then not Is_Frozen (T) then Set_Has_Delayed_Freeze (Designator); elsif Is_Access_Type (T) and then Has_Delayed_Freeze (Designated_Type (T)) and then not Is_Frozen (Designated_Type (T)) then Set_Has_Delayed_Freeze (Designator); end if; end Possible_Freeze; -- Start of processing for Check_Delayed_Subprogram begin -- Never need to freeze abstract subprogram if Is_Abstract (Designator) then null; else -- Need delayed freeze if return type itself needs a delayed -- freeze and is not yet frozen. Possible_Freeze (Etype (Designator)); Possible_Freeze (Base_Type (Etype (Designator))); -- needed ??? -- Need delayed freeze if any of the formal types themselves need -- a delayed freeze and are not yet frozen. F := First_Formal (Designator); while Present (F) loop Possible_Freeze (Etype (F)); Possible_Freeze (Base_Type (Etype (F))); -- needed ??? Next_Formal (F); end loop; end if; -- Mark functions that return by reference. Note that it cannot be -- done for delayed_freeze subprograms because the underlying -- returned type may not be known yet (for private types) if not Has_Delayed_Freeze (Designator) and then Expander_Active then declare Typ : constant Entity_Id := Etype (Designator); Utyp : constant Entity_Id := Underlying_Type (Typ); begin if Is_Return_By_Reference_Type (Typ) then Set_Returns_By_Ref (Designator); elsif Present (Utyp) and then Controlled_Type (Utyp) then Set_Returns_By_Ref (Designator); end if; end; end if; end Check_Delayed_Subprogram; ------------------------------------ -- Check_Discriminant_Conformance -- ------------------------------------ procedure Check_Discriminant_Conformance (N : Node_Id; Prev : Entity_Id; Prev_Loc : Node_Id) is Old_Discr : Entity_Id := First_Discriminant (Prev); New_Discr : Node_Id := First (Discriminant_Specifications (N)); New_Discr_Id : Entity_Id; New_Discr_Type : Entity_Id; procedure Conformance_Error (Msg : String; N : Node_Id); -- Post error message for conformance error on given node. Two messages -- are output. The first points to the previous declaration with a -- general "no conformance" message. The second is the detailed reason, -- supplied as Msg. The parameter N provide information for a possible -- & insertion in the message. ----------------------- -- Conformance_Error -- ----------------------- procedure Conformance_Error (Msg : String; N : Node_Id) is begin Error_Msg_Sloc := Sloc (Prev_Loc); Error_Msg_N ("not fully conformant with declaration#!", N); Error_Msg_NE (Msg, N, N); end Conformance_Error; -- Start of processing for Check_Discriminant_Conformance begin while Present (Old_Discr) and then Present (New_Discr) loop New_Discr_Id := Defining_Identifier (New_Discr); -- The subtype mark of the discriminant on the full type has not -- been analyzed so we do it here. For an access discriminant a new -- type is created. if Nkind (Discriminant_Type (New_Discr)) = N_Access_Definition then New_Discr_Type := Access_Definition (N, Discriminant_Type (New_Discr)); else Analyze (Discriminant_Type (New_Discr)); New_Discr_Type := Etype (Discriminant_Type (New_Discr)); end if; if not Conforming_Types (Etype (Old_Discr), New_Discr_Type, Fully_Conformant) then Conformance_Error ("type of & does not match!", New_Discr_Id); return; else -- Treat the new discriminant as an occurrence of the old one, -- for navigation purposes, and fill in some semantic -- information, for completeness. Generate_Reference (Old_Discr, New_Discr_Id, 'r'); Set_Etype (New_Discr_Id, Etype (Old_Discr)); Set_Scope (New_Discr_Id, Scope (Old_Discr)); end if; -- Names must match if Chars (Old_Discr) /= Chars (Defining_Identifier (New_Discr)) then Conformance_Error ("name & does not match!", New_Discr_Id); return; end if; -- Default expressions must match declare NewD : constant Boolean := Present (Expression (New_Discr)); OldD : constant Boolean := Present (Expression (Parent (Old_Discr))); begin if NewD or OldD then -- The old default value has been analyzed and expanded, -- because the current full declaration will have frozen -- everything before. The new default values have not been -- expanded, so expand now to check conformance. if NewD then Analyze_Per_Use_Expression (Expression (New_Discr), New_Discr_Type); end if; if not (NewD and OldD) or else not Fully_Conformant_Expressions (Expression (Parent (Old_Discr)), Expression (New_Discr)) then Conformance_Error ("default expression for & does not match!", New_Discr_Id); return; end if; end if; end; -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X) if Ada_Version = Ada_83 then declare Old_Disc : constant Node_Id := Declaration_Node (Old_Discr); begin -- Grouping (use of comma in param lists) must be the same -- This is where we catch a misconformance like: -- A,B : Integer -- A : Integer; B : Integer -- which are represented identically in the tree except -- for the setting of the flags More_Ids and Prev_Ids. if More_Ids (Old_Disc) /= More_Ids (New_Discr) or else Prev_Ids (Old_Disc) /= Prev_Ids (New_Discr) then Conformance_Error ("grouping of & does not match!", New_Discr_Id); return; end if; end; end if; Next_Discriminant (Old_Discr); Next (New_Discr); end loop; if Present (Old_Discr) then Conformance_Error ("too few discriminants!", Defining_Identifier (N)); return; elsif Present (New_Discr) then Conformance_Error ("too many discriminants!", Defining_Identifier (New_Discr)); return; end if; end Check_Discriminant_Conformance; ---------------------------- -- Check_Fully_Conformant -- ---------------------------- procedure Check_Fully_Conformant (New_Id : Entity_Id; Old_Id : Entity_Id; Err_Loc : Node_Id := Empty) is Result : Boolean; -- LLVM local pragma Warnings (Off, Result); begin Check_Conformance (New_Id, Old_Id, Fully_Conformant, True, Result, Err_Loc); end Check_Fully_Conformant; --------------------------- -- Check_Mode_Conformant -- --------------------------- procedure Check_Mode_Conformant (New_Id : Entity_Id; Old_Id : Entity_Id; Err_Loc : Node_Id := Empty; Get_Inst : Boolean := False) is Result : Boolean; -- LLVM local pragma Warnings (Off, Result); begin Check_Conformance (New_Id, Old_Id, Mode_Conformant, True, Result, Err_Loc, Get_Inst); end Check_Mode_Conformant; -------------------------------- -- Check_Overriding_Indicator -- -------------------------------- procedure Check_Overriding_Indicator (Subp : Entity_Id; Does_Override : Boolean) is Decl : Node_Id; Spec : Node_Id; begin if Ekind (Subp) = E_Enumeration_Literal then -- No overriding indicator for literals return; else Decl := Unit_Declaration_Node (Subp); end if; if Nkind (Decl) = N_Subprogram_Declaration or else Nkind (Decl) = N_Subprogram_Body or else Nkind (Decl) = N_Subprogram_Renaming_Declaration or else Nkind (Decl) = N_Subprogram_Body_Stub then Spec := Specification (Decl); else return; end if; if not Does_Override then if Must_Override (Spec) then Error_Msg_NE ("subprogram& is not overriding", Spec, Subp); end if; else if Must_Not_Override (Spec) then Error_Msg_NE ("subprogram& overrides inherited operation", Spec, Subp); end if; end if; end Check_Overriding_Indicator; ------------------- -- Check_Returns -- ------------------- procedure Check_Returns (HSS : Node_Id; Mode : Character; Err : out Boolean; Proc : Entity_Id := Empty) is Handler : Node_Id; procedure Check_Statement_Sequence (L : List_Id); -- Internal recursive procedure to check a list of statements for proper -- termination by a return statement (or a transfer of control or a -- compound statement that is itself internally properly terminated). ------------------------------ -- Check_Statement_Sequence -- ------------------------------ procedure Check_Statement_Sequence (L : List_Id) is Last_Stm : Node_Id; Kind : Node_Kind; Raise_Exception_Call : Boolean; -- Set True if statement sequence terminated by Raise_Exception call -- or a Reraise_Occurrence call. begin Raise_Exception_Call := False; -- Get last real statement Last_Stm := Last (L); -- Don't count pragmas while Nkind (Last_Stm) = N_Pragma -- Don't count call to SS_Release (can happen after Raise_Exception) or else (Nkind (Last_Stm) = N_Procedure_Call_Statement and then Nkind (Name (Last_Stm)) = N_Identifier and then Is_RTE (Entity (Name (Last_Stm)), RE_SS_Release)) -- Don't count exception junk or else ((Nkind (Last_Stm) = N_Goto_Statement or else Nkind (Last_Stm) = N_Label or else Nkind (Last_Stm) = N_Object_Declaration) and then Exception_Junk (Last_Stm)) loop Prev (Last_Stm); end loop; -- Here we have the "real" last statement Kind := Nkind (Last_Stm); -- Transfer of control, OK. Note that in the No_Return procedure -- case, we already diagnosed any explicit return statements, so -- we can treat them as OK in this context. if Is_Transfer (Last_Stm) then return; -- Check cases of explicit non-indirect procedure calls elsif Kind = N_Procedure_Call_Statement and then Is_Entity_Name (Name (Last_Stm)) then -- Check call to Raise_Exception procedure which is treated -- specially, as is a call to Reraise_Occurrence. -- We suppress the warning in these cases since it is likely that -- the programmer really does not expect to deal with the case -- of Null_Occurrence, and thus would find a warning about a -- missing return curious, and raising Program_Error does not -- seem such a bad behavior if this does occur. -- Note that in the Ada 2005 case for Raise_Exception, the actual -- behavior will be to raise Constraint_Error (see AI-329). if Is_RTE (Entity (Name (Last_Stm)), RE_Raise_Exception) or else Is_RTE (Entity (Name (Last_Stm)), RE_Reraise_Occurrence) then Raise_Exception_Call := True; -- For Raise_Exception call, test first argument, if it is -- an attribute reference for a 'Identity call, then we know -- that the call cannot possibly return. declare Arg : constant Node_Id := Original_Node (First_Actual (Last_Stm)); begin if Nkind (Arg) = N_Attribute_Reference and then Attribute_Name (Arg) = Name_Identity then return; end if; end; end if; -- If statement, need to look inside if there is an else and check -- each constituent statement sequence for proper termination. elsif Kind = N_If_Statement and then Present (Else_Statements (Last_Stm)) then Check_Statement_Sequence (Then_Statements (Last_Stm)); Check_Statement_Sequence (Else_Statements (Last_Stm)); if Present (Elsif_Parts (Last_Stm)) then declare Elsif_Part : Node_Id := First (Elsif_Parts (Last_Stm)); begin while Present (Elsif_Part) loop Check_Statement_Sequence (Then_Statements (Elsif_Part)); Next (Elsif_Part); end loop; end; end if; return; -- Case statement, check each case for proper termination elsif Kind = N_Case_Statement then declare Case_Alt : Node_Id; begin Case_Alt := First_Non_Pragma (Alternatives (Last_Stm)); while Present (Case_Alt) loop Check_Statement_Sequence (Statements (Case_Alt)); Next_Non_Pragma (Case_Alt); end loop; end; return; -- Block statement, check its handled sequence of statements elsif Kind = N_Block_Statement then declare Err1 : Boolean; begin Check_Returns (Handled_Statement_Sequence (Last_Stm), Mode, Err1); if Err1 then Err := True; end if; return; end; -- Loop statement. If there is an iteration scheme, we can definitely -- fall out of the loop. Similarly if there is an exit statement, we -- can fall out. In either case we need a following return. elsif Kind = N_Loop_Statement then if Present (Iteration_Scheme (Last_Stm)) or else Has_Exit (Entity (Identifier (Last_Stm))) then null; -- A loop with no exit statement or iteration scheme if either -- an inifite loop, or it has some other exit (raise/return). -- In either case, no warning is required. else return; end if; -- Timed entry call, check entry call and delay alternatives -- Note: in expanded code, the timed entry call has been converted -- to a set of expanded statements on which the check will work -- correctly in any case. elsif Kind = N_Timed_Entry_Call then declare ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm); DCA : constant Node_Id := Delay_Alternative (Last_Stm); begin -- If statement sequence of entry call alternative is missing, -- then we can definitely fall through, and we post the error -- message on the entry call alternative itself. if No (Statements (ECA)) then Last_Stm := ECA; -- If statement sequence of delay alternative is missing, then -- we can definitely fall through, and we post the error -- message on the delay alternative itself. -- Note: if both ECA and DCA are missing the return, then we -- post only one message, should be enough to fix the bugs. -- If not we will get a message next time on the DCA when the -- ECA is fixed! elsif No (Statements (DCA)) then Last_Stm := DCA; -- Else check both statement sequences else Check_Statement_Sequence (Statements (ECA)); Check_Statement_Sequence (Statements (DCA)); return; end if; end; -- Conditional entry call, check entry call and else part -- Note: in expanded code, the conditional entry call has been -- converted to a set of expanded statements on which the check -- will work correctly in any case. elsif Kind = N_Conditional_Entry_Call then declare ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm); begin -- If statement sequence of entry call alternative is missing, -- then we can definitely fall through, and we post the error -- message on the entry call alternative itself. if No (Statements (ECA)) then Last_Stm := ECA; -- Else check statement sequence and else part else Check_Statement_Sequence (Statements (ECA)); Check_Statement_Sequence (Else_Statements (Last_Stm)); return; end if; end; end if; -- If we fall through, issue appropriate message if Mode = 'F' then if not Raise_Exception_Call then Error_Msg_N ("?RETURN statement missing following this statement", Last_Stm); Error_Msg_N ("\?Program_Error may be raised at run time", Last_Stm); end if; -- Note: we set Err even though we have not issued a warning -- because we still have a case of a missing return. This is -- an extremely marginal case, probably will never be noticed -- but we might as well get it right. Err := True; -- Otherwise we have the case of a procedure marked No_Return else Error_Msg_N ("?implied return after this statement will raise Program_Error", Last_Stm); Error_Msg_NE ("?procedure & is marked as No_Return", Last_Stm, Proc); declare RE : constant Node_Id := Make_Raise_Program_Error (Sloc (Last_Stm), Reason => PE_Implicit_Return); begin Insert_After (Last_Stm, RE); Analyze (RE); end; end if; end Check_Statement_Sequence; -- Start of processing for Check_Returns begin Err := False; Check_Statement_Sequence (Statements (HSS)); if Present (Exception_Handlers (HSS)) then Handler := First_Non_Pragma (Exception_Handlers (HSS)); while Present (Handler) loop Check_Statement_Sequence (Statements (Handler)); Next_Non_Pragma (Handler); end loop; end if; end Check_Returns; ---------------------------- -- Check_Subprogram_Order -- ---------------------------- procedure Check_Subprogram_Order (N : Node_Id) is function Subprogram_Name_Greater (S1, S2 : String) return Boolean; -- This is used to check if S1 > S2 in the sense required by this -- test, for example nameab < namec, but name2 < name10. ----------------------------- -- Subprogram_Name_Greater -- ----------------------------- function Subprogram_Name_Greater (S1, S2 : String) return Boolean is L1, L2 : Positive; N1, N2 : Natural; begin -- Remove trailing numeric parts L1 := S1'Last; while S1 (L1) in '0' .. '9' loop L1 := L1 - 1; end loop; L2 := S2'Last; while S2 (L2) in '0' .. '9' loop L2 := L2 - 1; end loop; -- If non-numeric parts non-equal, that's decisive if S1 (S1'First .. L1) < S2 (S2'First .. L2) then return False; elsif S1 (S1'First .. L1) > S2 (S2'First .. L2) then return True; -- If non-numeric parts equal, compare suffixed numeric parts. Note -- that a missing suffix is treated as numeric zero in this test. else N1 := 0; while L1 < S1'Last loop L1 := L1 + 1; N1 := N1 * 10 + Character'Pos (S1 (L1)) - Character'Pos ('0'); end loop; N2 := 0; while L2 < S2'Last loop L2 := L2 + 1; N2 := N2 * 10 + Character'Pos (S2 (L2)) - Character'Pos ('0'); end loop; return N1 > N2; end if; end Subprogram_Name_Greater; -- Start of processing for Check_Subprogram_Order begin -- Check body in alpha order if this is option if Style_Check and then Style_Check_Order_Subprograms and then Nkind (N) = N_Subprogram_Body and then Comes_From_Source (N) and then In_Extended_Main_Source_Unit (N) then declare LSN : String_Ptr renames Scope_Stack.Table (Scope_Stack.Last).Last_Subprogram_Name; Body_Id : constant Entity_Id := Defining_Entity (Specification (N)); begin Get_Decoded_Name_String (Chars (Body_Id)); if LSN /= null then if Subprogram_Name_Greater (LSN.all, Name_Buffer (1 .. Name_Len)) then Style.Subprogram_Not_In_Alpha_Order (Body_Id); end if; Free (LSN); end if; LSN := new String'(Name_Buffer (1 .. Name_Len)); end; end if; end Check_Subprogram_Order; ------------------------------ -- Check_Subtype_Conformant -- ------------------------------ procedure Check_Subtype_Conformant (New_Id : Entity_Id; Old_Id : Entity_Id; Err_Loc : Node_Id := Empty) is Result : Boolean; -- LLVM local pragma Warnings (Off, Result); begin Check_Conformance (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc); end Check_Subtype_Conformant; --------------------------- -- Check_Type_Conformant -- --------------------------- procedure Check_Type_Conformant (New_Id : Entity_Id; Old_Id : Entity_Id; Err_Loc : Node_Id := Empty) is Result : Boolean; -- LLVM local pragma Warnings (Off, Result); begin Check_Conformance (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc); end Check_Type_Conformant; ---------------------- -- Conforming_Types -- ---------------------- function Conforming_Types (T1 : Entity_Id; T2 : Entity_Id; Ctype : Conformance_Type; Get_Inst : Boolean := False) return Boolean is Type_1 : Entity_Id := T1; Type_2 : Entity_Id := T2; Are_Anonymous_Access_To_Subprogram_Types : Boolean := False; function Base_Types_Match (T1, T2 : Entity_Id) return Boolean; -- If neither T1 nor T2 are generic actual types, or if they are -- in different scopes (e.g. parent and child instances), then verify -- that the base types are equal. Otherwise T1 and T2 must be -- on the same subtype chain. The whole purpose of this procedure -- is to prevent spurious ambiguities in an instantiation that may -- arise if two distinct generic types are instantiated with the -- same actual. ---------------------- -- Base_Types_Match -- ---------------------- function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is begin if T1 = T2 then return True; elsif Base_Type (T1) = Base_Type (T2) then -- The following is too permissive. A more precise test must -- check that the generic actual is an ancestor subtype of the -- other ???. return not Is_Generic_Actual_Type (T1) or else not Is_Generic_Actual_Type (T2) or else Scope (T1) /= Scope (T2); -- In some cases a type imported through a limited_with clause, -- and its non-limited view are both visible, for example in an -- anonymous access_to_classwide type in a formal. Both entities -- designate the same type. elsif From_With_Type (T1) and then Ekind (T1) = E_Incomplete_Type and then T2 = Non_Limited_View (T1) then return True; elsif From_With_Type (T2) and then Ekind (T2) = E_Incomplete_Type and then T1 = Non_Limited_View (T2) then return True; else return False; end if; end Base_Types_Match; -- Start of processing for Conforming_Types begin -- The context is an instance association for a formal -- access-to-subprogram type; the formal parameter types require -- mapping because they may denote other formal parameters of the -- generic unit. if Get_Inst then Type_1 := Get_Instance_Of (T1); Type_2 := Get_Instance_Of (T2); end if; -- First see if base types match if Base_Types_Match (Type_1, Type_2) then return Ctype <= Mode_Conformant or else Subtypes_Statically_Match (Type_1, Type_2); elsif Is_Incomplete_Or_Private_Type (Type_1) and then Present (Full_View (Type_1)) and then Base_Types_Match (Full_View (Type_1), Type_2) then return Ctype <= Mode_Conformant or else Subtypes_Statically_Match (Full_View (Type_1), Type_2); elsif Ekind (Type_2) = E_Incomplete_Type and then Present (Full_View (Type_2)) and then Base_Types_Match (Type_1, Full_View (Type_2)) then return Ctype <= Mode_Conformant or else Subtypes_Statically_Match (Type_1, Full_View (Type_2)); elsif Is_Private_Type (Type_2) and then In_Instance and then Present (Full_View (Type_2)) and then Base_Types_Match (Type_1, Full_View (Type_2)) then return Ctype <= Mode_Conformant or else Subtypes_Statically_Match (Type_1, Full_View (Type_2)); end if; -- Ada 2005 (AI-254): Anonymous access to subprogram types must be -- treated recursively because they carry a signature. Are_Anonymous_Access_To_Subprogram_Types := -- Case 1: Anonymous access to subprogram types (Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type and then Ekind (Type_2) = E_Anonymous_Access_Subprogram_Type) -- Case 2: Anonymous access to PROTECTED subprogram types. In this -- case the anonymous type_declaration has been replaced by an -- occurrence of an internal access to subprogram type declaration -- available through the Original_Access_Type attribute or else (Ekind (Type_1) = E_Access_Protected_Subprogram_Type and then Ekind (Type_2) = E_Access_Protected_Subprogram_Type and then not Comes_From_Source (Type_1) and then not Comes_From_Source (Type_2) and then Present (Original_Access_Type (Type_1)) and then Present (Original_Access_Type (Type_2)) and then Ekind (Original_Access_Type (Type_1)) = E_Anonymous_Access_Protected_Subprogram_Type and then Ekind (Original_Access_Type (Type_2)) = E_Anonymous_Access_Protected_Subprogram_Type); -- Test anonymous access type case. For this case, static subtype -- matching is required for mode conformance (RM 6.3.1(15)) if (Ekind (Type_1) = E_Anonymous_Access_Type and then Ekind (Type_2) = E_Anonymous_Access_Type) or else Are_Anonymous_Access_To_Subprogram_Types -- Ada 2005 (AI-254) then declare Desig_1 : Entity_Id; Desig_2 : Entity_Id; begin Desig_1 := Directly_Designated_Type (Type_1); -- An access parameter can designate an incomplete type -- If the incomplete type is the limited view of a type -- from a limited_with_clause, check whether the non-limited -- view is available. if Ekind (Desig_1) = E_Incomplete_Type then if Present (Full_View (Desig_1)) then Desig_1 := Full_View (Desig_1); elsif Present (Non_Limited_View (Desig_1)) then Desig_1 := Non_Limited_View (Desig_1); end if; end if; Desig_2 := Directly_Designated_Type (Type_2); if Ekind (Desig_2) = E_Incomplete_Type then if Present (Full_View (Desig_2)) then Desig_2 := Full_View (Desig_2); elsif Present (Non_Limited_View (Desig_2)) then Desig_2 := Non_Limited_View (Desig_2); end if; end if; -- The context is an instance association for a formal -- access-to-subprogram type; formal access parameter designated -- types require mapping because they may denote other formal -- parameters of the generic unit. if Get_Inst then Desig_1 := Get_Instance_Of (Desig_1); Desig_2 := Get_Instance_Of (Desig_2); end if; -- It is possible for a Class_Wide_Type to be introduced for an -- incomplete type, in which case there is a separate class_ wide -- type for the full view. The types conform if their Etypes -- conform, i.e. one may be the full view of the other. This can -- only happen in the context of an access parameter, other uses -- of an incomplete Class_Wide_Type are illegal. if Is_Class_Wide_Type (Desig_1) and then Is_Class_Wide_Type (Desig_2) then return Conforming_Types (Etype (Base_Type (Desig_1)), Etype (Base_Type (Desig_2)), Ctype); elsif Are_Anonymous_Access_To_Subprogram_Types then if Ada_Version < Ada_05 then return Ctype = Type_Conformant or else Subtypes_Statically_Match (Desig_1, Desig_2); -- We must check the conformance of the signatures themselves else declare Conformant : Boolean; begin Check_Conformance (Desig_1, Desig_2, Ctype, False, Conformant); return Conformant; end; end if; else return Base_Type (Desig_1) = Base_Type (Desig_2) and then (Ctype = Type_Conformant or else Subtypes_Statically_Match (Desig_1, Desig_2)); end if; end; -- Otherwise definitely no match else if ((Ekind (Type_1) = E_Anonymous_Access_Type and then Is_Access_Type (Type_2)) or else (Ekind (Type_2) = E_Anonymous_Access_Type and then Is_Access_Type (Type_1))) and then Conforming_Types (Designated_Type (Type_1), Designated_Type (Type_2), Ctype) then May_Hide_Profile := True; end if; return False; end if; end Conforming_Types; -------------------------- -- Create_Extra_Formals -- -------------------------- procedure Create_Extra_Formals (E : Entity_Id) is Formal : Entity_Id; Last_Extra : Entity_Id; Formal_Type : Entity_Id; P_Formal : Entity_Id := Empty; function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id; -- Add an extra formal, associated with the current Formal. The extra -- formal is added to the list of extra formals, and also returned as -- the result. These formals are always of mode IN. ---------------------- -- Add_Extra_Formal -- ---------------------- function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id is EF : constant Entity_Id := Make_Defining_Identifier (Sloc (Formal), Chars => New_External_Name (Chars (Formal), 'F')); begin -- We never generate extra formals if expansion is not active -- because we don't need them unless we are generating code. if not Expander_Active then return Empty; end if; -- A little optimization. Never generate an extra formal for the -- _init operand of an initialization procedure, since it could -- never be used. if Chars (Formal) = Name_uInit then return Empty; end if; Set_Ekind (EF, E_In_Parameter); Set_Actual_Subtype (EF, Typ); Set_Etype (EF, Typ); Set_Scope (EF, Scope (Formal)); Set_Mechanism (EF, Default_Mechanism); Set_Formal_Validity (EF); Set_Extra_Formal (Last_Extra, EF); Last_Extra := EF; return EF; end Add_Extra_Formal; -- Start of processing for Create_Extra_Formals begin -- If this is a derived subprogram then the subtypes of the parent -- subprogram's formal parameters will be used to to determine the need -- for extra formals. if Is_Overloadable (E) and then Present (Alias (E)) then P_Formal := First_Formal (Alias (E)); end if; Last_Extra := Empty; Formal := First_Formal (E); while Present (Formal) loop Last_Extra := Formal; Next_Formal (Formal); end loop; -- If Extra_formals where already created, don't do it again. This -- situation may arise for subprogram types created as part of -- dispatching calls (see Expand_Dispatching_Call) if Present (Last_Extra) and then Present (Extra_Formal (Last_Extra)) then return; end if; Formal := First_Formal (E); while Present (Formal) loop -- Create extra formal for supporting the attribute 'Constrained. -- The case of a private type view without discriminants also -- requires the extra formal if the underlying type has defaulted -- discriminants. if Ekind (Formal) /= E_In_Parameter then if Present (P_Formal) then Formal_Type := Etype (P_Formal); else Formal_Type := Etype (Formal); end if; -- Do not produce extra formals for Unchecked_Union parameters. -- Jump directly to the end of the loop. if Is_Unchecked_Union (Base_Type (Formal_Type)) then goto Skip_Extra_Formal_Generation; end if; if not Has_Discriminants (Formal_Type) and then Ekind (Formal_Type) in Private_Kind and then Present (Underlying_Type (Formal_Type)) then Formal_Type := Underlying_Type (Formal_Type); end if; if Has_Discriminants (Formal_Type) and then ((not Is_Constrained (Formal_Type) and then not Is_Indefinite_Subtype (Formal_Type)) or else Present (Extra_Formal (Formal))) then Set_Extra_Constrained (Formal, Add_Extra_Formal (Standard_Boolean)); end if; end if; -- Create extra formal for supporting accessibility checking -- This is suppressed if we specifically suppress accessibility -- checks at the pacage level for either the subprogram, or the -- package in which it resides. However, we do not suppress it -- simply if the scope has accessibility checks suppressed, since -- this could cause trouble when clients are compiled with a -- different suppression setting. The explicit checks at the -- package level are safe from this point of view. if Ekind (Etype (Formal)) = E_Anonymous_Access_Type and then not (Explicit_Suppress (E, Accessibility_Check) or else Explicit_Suppress (Scope (E), Accessibility_Check)) and then (No (P_Formal) or else Present (Extra_Accessibility (P_Formal))) then -- Temporary kludge: for now we avoid creating the extra formal -- for access parameters of protected operations because of -- problem with the case of internal protected calls. ??? if Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Definition and then Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Body then Set_Extra_Accessibility (Formal, Add_Extra_Formal (Standard_Natural)); end if; end if; if Present (P_Formal) then Next_Formal (P_Formal); end if; -- This label is required when skipping extra formal generation for -- Unchecked_Union parameters. <<Skip_Extra_Formal_Generation>> Next_Formal (Formal); end loop; end Create_Extra_Formals; ----------------------------- -- Enter_Overloaded_Entity -- ----------------------------- procedure Enter_Overloaded_Entity (S : Entity_Id) is E : Entity_Id := Current_Entity_In_Scope (S); C_E : Entity_Id := Current_Entity (S); begin if Present (E) then Set_Has_Homonym (E); Set_Has_Homonym (S); end if; Set_Is_Immediately_Visible (S); Set_Scope (S, Current_Scope); -- Chain new entity if front of homonym in current scope, so that -- homonyms are contiguous. if Present (E) and then E /= C_E then while Homonym (C_E) /= E loop C_E := Homonym (C_E); end loop; Set_Homonym (C_E, S); else E := C_E; Set_Current_Entity (S); end if; Set_Homonym (S, E); Append_Entity (S, Current_Scope); Set_Public_Status (S); if Debug_Flag_E then Write_Str ("New overloaded entity chain: "); Write_Name (Chars (S)); E := S; while Present (E) loop Write_Str (" "); Write_Int (Int (E)); E := Homonym (E); end loop; Write_Eol; end if; -- Generate warning for hiding if Warn_On_Hiding and then Comes_From_Source (S) and then In_Extended_Main_Source_Unit (S) then E := S; loop E := Homonym (E); exit when No (E); -- Warn unless genuine overloading if (not Is_Overloadable (E)) or else Subtype_Conformant (E, S) then Error_Msg_Sloc := Sloc (E); Error_Msg_N ("declaration of & hides one#?", S); end if; end loop; end if; end Enter_Overloaded_Entity; ----------------------------- -- Find_Corresponding_Spec -- ----------------------------- function Find_Corresponding_Spec (N : Node_Id) return Entity_Id is Spec : constant Node_Id := Specification (N); Designator : constant Entity_Id := Defining_Entity (Spec); E : Entity_Id; begin E := Current_Entity (Designator); while Present (E) loop -- We are looking for a matching spec. It must have the same scope, -- and the same name, and either be type conformant, or be the case -- of a library procedure spec and its body (which belong to one -- another regardless of whether they are type conformant or not). if Scope (E) = Current_Scope then if Current_Scope = Standard_Standard or else (Ekind (E) = Ekind (Designator) and then Type_Conformant (E, Designator)) then -- Within an instantiation, we know that spec and body are -- subtype conformant, because they were subtype conformant -- in the generic. We choose the subtype-conformant entity -- here as well, to resolve spurious ambiguities in the -- instance that were not present in the generic (i.e. when -- two different types are given the same actual). If we are -- looking for a spec to match a body, full conformance is -- expected. if In_Instance then Set_Convention (Designator, Convention (E)); if Nkind (N) = N_Subprogram_Body and then Present (Homonym (E)) and then not Fully_Conformant (E, Designator) then goto Next_Entity; elsif not Subtype_Conformant (E, Designator) then goto Next_Entity; end if; end if; if not Has_Completion (E) then if Nkind (N) /= N_Subprogram_Body_Stub then Set_Corresponding_Spec (N, E); end if; Set_Has_Completion (E); return E; elsif Nkind (Parent (N)) = N_Subunit then -- If this is the proper body of a subunit, the completion -- flag is set when analyzing the stub. return E; -- If body already exists, this is an error unless the -- previous declaration is the implicit declaration of -- a derived subprogram, or this is a spurious overloading -- in an instance. elsif No (Alias (E)) and then not Is_Intrinsic_Subprogram (E) and then not In_Instance then Error_Msg_Sloc := Sloc (E); if Is_Imported (E) then Error_Msg_NE ("body not allowed for imported subprogram & declared#", N, E); else Error_Msg_NE ("duplicate body for & declared#", N, E); end if; end if; elsif Is_Child_Unit (E) and then Nkind (Unit_Declaration_Node (Designator)) = N_Subprogram_Body and then Nkind (Parent (Unit_Declaration_Node (Designator))) = N_Compilation_Unit then -- Child units cannot be overloaded, so a conformance mismatch -- between body and a previous spec is an error. Error_Msg_N ("body of child unit does not match previous declaration", N); end if; end if; <<Next_Entity>> E := Homonym (E); end loop; -- On exit, we know that no previous declaration of subprogram exists return Empty; end Find_Corresponding_Spec; ---------------------- -- Fully_Conformant -- ---------------------- function Fully_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is Result : Boolean; begin Check_Conformance (New_Id, Old_Id, Fully_Conformant, False, Result); return Result; end Fully_Conformant; ---------------------------------- -- Fully_Conformant_Expressions -- ---------------------------------- function Fully_Conformant_Expressions (Given_E1 : Node_Id; Given_E2 : Node_Id) return Boolean is E1 : constant Node_Id := Original_Node (Given_E1); E2 : constant Node_Id := Original_Node (Given_E2); -- We always test conformance on original nodes, since it is possible -- for analysis and/or expansion to make things look as though they -- conform when they do not, e.g. by converting 1+2 into 3. function FCE (Given_E1, Given_E2 : Node_Id) return Boolean renames Fully_Conformant_Expressions; function FCL (L1, L2 : List_Id) return Boolean; -- Compare elements of two lists for conformance. Elements have to -- be conformant, and actuals inserted as default parameters do not -- match explicit actuals with the same value. function FCO (Op_Node, Call_Node : Node_Id) return Boolean; -- Compare an operator node with a function call --------- -- FCL -- --------- function FCL (L1, L2 : List_Id) return Boolean is N1, N2 : Node_Id; begin if L1 = No_List then N1 := Empty; else N1 := First (L1); end if; if L2 = No_List then N2 := Empty; else N2 := First (L2); end if; -- Compare two lists, skipping rewrite insertions (we want to -- compare the original trees, not the expanded versions!) loop if Is_Rewrite_Insertion (N1) then Next (N1); elsif Is_Rewrite_Insertion (N2) then Next (N2); elsif No (N1) then return No (N2); elsif No (N2) then return False; elsif not FCE (N1, N2) then return False; else Next (N1); Next (N2); end if; end loop; end FCL; --------- -- FCO -- --------- function FCO (Op_Node, Call_Node : Node_Id) return Boolean is Actuals : constant List_Id := Parameter_Associations (Call_Node); Act : Node_Id; begin if No (Actuals) or else Entity (Op_Node) /= Entity (Name (Call_Node)) then return False; else Act := First (Actuals); if Nkind (Op_Node) in N_Binary_Op then if not FCE (Left_Opnd (Op_Node), Act) then return False; end if; Next (Act); end if; return Present (Act) and then FCE (Right_Opnd (Op_Node), Act) and then No (Next (Act)); end if; end FCO; -- Start of processing for Fully_Conformant_Expressions begin -- Non-conformant if paren count does not match. Note: if some idiot -- complains that we don't do this right for more than 3 levels of -- parentheses, they will be treated with the respect they deserve :-) if Paren_Count (E1) /= Paren_Count (E2) then return False; -- If same entities are referenced, then they are conformant even if -- they have different forms (RM 8.3.1(19-20)). elsif Is_Entity_Name (E1) and then Is_Entity_Name (E2) then if Present (Entity (E1)) then return Entity (E1) = Entity (E2) or else (Chars (Entity (E1)) = Chars (Entity (E2)) and then Ekind (Entity (E1)) = E_Discriminant and then Ekind (Entity (E2)) = E_In_Parameter); elsif Nkind (E1) = N_Expanded_Name and then Nkind (E2) = N_Expanded_Name and then Nkind (Selector_Name (E1)) = N_Character_Literal and then Nkind (Selector_Name (E2)) = N_Character_Literal then return Chars (Selector_Name (E1)) = Chars (Selector_Name (E2)); else -- Identifiers in component associations don't always have -- entities, but their names must conform. return Nkind (E1) = N_Identifier and then Nkind (E2) = N_Identifier and then Chars (E1) = Chars (E2); end if; elsif Nkind (E1) = N_Character_Literal and then Nkind (E2) = N_Expanded_Name then return Nkind (Selector_Name (E2)) = N_Character_Literal and then Chars (E1) = Chars (Selector_Name (E2)); elsif Nkind (E2) = N_Character_Literal and then Nkind (E1) = N_Expanded_Name then return Nkind (Selector_Name (E1)) = N_Character_Literal and then Chars (E2) = Chars (Selector_Name (E1)); elsif Nkind (E1) in N_Op and then Nkind (E2) = N_Function_Call then return FCO (E1, E2); elsif Nkind (E2) in N_Op and then Nkind (E1) = N_Function_Call then return FCO (E2, E1); -- Otherwise we must have the same syntactic entity elsif Nkind (E1) /= Nkind (E2) then return False; -- At this point, we specialize by node type else case Nkind (E1) is when N_Aggregate => return FCL (Expressions (E1), Expressions (E2)) and then FCL (Component_Associations (E1), Component_Associations (E2)); when N_Allocator => if Nkind (Expression (E1)) = N_Qualified_Expression or else Nkind (Expression (E2)) = N_Qualified_Expression then return FCE (Expression (E1), Expression (E2)); -- Check that the subtype marks and any constraints -- are conformant else declare Indic1 : constant Node_Id := Expression (E1); Indic2 : constant Node_Id := Expression (E2); Elt1 : Node_Id; Elt2 : Node_Id; begin if Nkind (Indic1) /= N_Subtype_Indication then return Nkind (Indic2) /= N_Subtype_Indication and then Entity (Indic1) = Entity (Indic2); elsif Nkind (Indic2) /= N_Subtype_Indication then return Nkind (Indic1) /= N_Subtype_Indication and then Entity (Indic1) = Entity (Indic2); else if Entity (Subtype_Mark (Indic1)) /= Entity (Subtype_Mark (Indic2)) then return False; end if; Elt1 := First (Constraints (Constraint (Indic1))); Elt2 := First (Constraints (Constraint (Indic2))); while Present (Elt1) and then Present (Elt2) loop if not FCE (Elt1, Elt2) then return False; end if; Next (Elt1); Next (Elt2); end loop; return True; end if; end; end if; when N_Attribute_Reference => return Attribute_Name (E1) = Attribute_Name (E2) and then FCL (Expressions (E1), Expressions (E2)); when N_Binary_Op => return Entity (E1) = Entity (E2) and then FCE (Left_Opnd (E1), Left_Opnd (E2)) and then FCE (Right_Opnd (E1), Right_Opnd (E2)); when N_And_Then | N_Or_Else | N_In | N_Not_In => return FCE (Left_Opnd (E1), Left_Opnd (E2)) and then FCE (Right_Opnd (E1), Right_Opnd (E2)); when N_Character_Literal => return Char_Literal_Value (E1) = Char_Literal_Value (E2); when N_Component_Association => return FCL (Choices (E1), Choices (E2)) and then FCE (Expression (E1), Expression (E2)); when N_Conditional_Expression => return FCL (Expressions (E1), Expressions (E2)); when N_Explicit_Dereference => return FCE (Prefix (E1), Prefix (E2)); when N_Extension_Aggregate => return FCL (Expressions (E1), Expressions (E2)) and then Null_Record_Present (E1) = Null_Record_Present (E2) and then FCL (Component_Associations (E1), Component_Associations (E2)); when N_Function_Call => return FCE (Name (E1), Name (E2)) and then FCL (Parameter_Associations (E1), Parameter_Associations (E2)); when N_Indexed_Component => return FCE (Prefix (E1), Prefix (E2)) and then FCL (Expressions (E1), Expressions (E2)); when N_Integer_Literal => return (Intval (E1) = Intval (E2)); when N_Null => return True; when N_Operator_Symbol => return Chars (E1) = Chars (E2); when N_Others_Choice => return True; when N_Parameter_Association => return Chars (Selector_Name (E1)) = Chars (Selector_Name (E2)) and then FCE (Explicit_Actual_Parameter (E1), Explicit_Actual_Parameter (E2)); when N_Qualified_Expression => return FCE (Subtype_Mark (E1), Subtype_Mark (E2)) and then FCE (Expression (E1), Expression (E2)); when N_Range => return FCE (Low_Bound (E1), Low_Bound (E2)) and then FCE (High_Bound (E1), High_Bound (E2)); when N_Real_Literal => return (Realval (E1) = Realval (E2)); when N_Selected_Component => return FCE (Prefix (E1), Prefix (E2)) and then FCE (Selector_Name (E1), Selector_Name (E2)); when N_Slice => return FCE (Prefix (E1), Prefix (E2)) and then FCE (Discrete_Range (E1), Discrete_Range (E2)); when N_String_Literal => declare S1 : constant String_Id := Strval (E1); S2 : constant String_Id := Strval (E2); L1 : constant Nat := String_Length (S1); L2 : constant Nat := String_Length (S2); begin if L1 /= L2 then return False; else for J in 1 .. L1 loop if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then return False; end if; end loop; return True; end if; end; when N_Type_Conversion => return FCE (Subtype_Mark (E1), Subtype_Mark (E2)) and then FCE (Expression (E1), Expression (E2)); when N_Unary_Op => return Entity (E1) = Entity (E2) and then FCE (Right_Opnd (E1), Right_Opnd (E2)); when N_Unchecked_Type_Conversion => return FCE (Subtype_Mark (E1), Subtype_Mark (E2)) and then FCE (Expression (E1), Expression (E2)); -- All other node types cannot appear in this context. Strictly -- we should raise a fatal internal error. Instead we just ignore -- the nodes. This means that if anyone makes a mistake in the -- expander and mucks an expression tree irretrievably, the -- result will be a failure to detect a (probably very obscure) -- case of non-conformance, which is better than bombing on some -- case where two expressions do in fact conform. when others => return True; end case; end if; end Fully_Conformant_Expressions; ---------------------------------------- -- Fully_Conformant_Discrete_Subtypes -- ---------------------------------------- function Fully_Conformant_Discrete_Subtypes (Given_S1 : Node_Id; Given_S2 : Node_Id) return Boolean is S1 : constant Node_Id := Original_Node (Given_S1); S2 : constant Node_Id := Original_Node (Given_S2); function Conforming_Bounds (B1, B2 : Node_Id) return Boolean; -- Special-case for a bound given by a discriminant, which in the body -- is replaced with the discriminal of the enclosing type. function Conforming_Ranges (R1, R2 : Node_Id) return Boolean; -- Check both bounds function Conforming_Bounds (B1, B2 : Node_Id) return Boolean is begin if Is_Entity_Name (B1) and then Is_Entity_Name (B2) and then Ekind (Entity (B1)) = E_Discriminant then return Chars (B1) = Chars (B2); else return Fully_Conformant_Expressions (B1, B2); end if; end Conforming_Bounds; function Conforming_Ranges (R1, R2 : Node_Id) return Boolean is begin return Conforming_Bounds (Low_Bound (R1), Low_Bound (R2)) and then Conforming_Bounds (High_Bound (R1), High_Bound (R2)); end Conforming_Ranges; -- Start of processing for Fully_Conformant_Discrete_Subtypes begin if Nkind (S1) /= Nkind (S2) then return False; elsif Is_Entity_Name (S1) then return Entity (S1) = Entity (S2); elsif Nkind (S1) = N_Range then return Conforming_Ranges (S1, S2); elsif Nkind (S1) = N_Subtype_Indication then return Entity (Subtype_Mark (S1)) = Entity (Subtype_Mark (S2)) and then Conforming_Ranges (Range_Expression (Constraint (S1)), Range_Expression (Constraint (S2))); else return True; end if; end Fully_Conformant_Discrete_Subtypes; -------------------- -- Install_Entity -- -------------------- procedure Install_Entity (E : Entity_Id) is Prev : constant Entity_Id := Current_Entity (E); begin Set_Is_Immediately_Visible (E); Set_Current_Entity (E); Set_Homonym (E, Prev); end Install_Entity; --------------------- -- Install_Formals -- --------------------- procedure Install_Formals (Id : Entity_Id) is F : Entity_Id; begin F := First_Formal (Id); while Present (F) loop Install_Entity (F); Next_Formal (F); end loop; end Install_Formals; --------------------------------- -- Is_Non_Overriding_Operation -- --------------------------------- function Is_Non_Overriding_Operation (Prev_E : Entity_Id; New_E : Entity_Id) return Boolean is Formal : Entity_Id; F_Typ : Entity_Id; G_Typ : Entity_Id := Empty; function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id; -- If F_Type is a derived type associated with a generic actual -- subtype, then return its Generic_Parent_Type attribute, else return -- Empty. function Types_Correspond (P_Type : Entity_Id; N_Type : Entity_Id) return Boolean; -- Returns true if and only if the types (or designated types in the -- case of anonymous access types) are the same or N_Type is derived -- directly or indirectly from P_Type. ----------------------------- -- Get_Generic_Parent_Type -- ----------------------------- function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id is G_Typ : Entity_Id; Indic : Node_Id; begin if Is_Derived_Type (F_Typ) and then Nkind (Parent (F_Typ)) = N_Full_Type_Declaration then -- The tree must be traversed to determine the parent subtype in -- the generic unit, which unfortunately isn't always available -- via semantic attributes. ??? (Note: The use of Original_Node -- is needed for cases where a full derived type has been -- rewritten.) Indic := Subtype_Indication (Type_Definition (Original_Node (Parent (F_Typ)))); if Nkind (Indic) = N_Subtype_Indication then G_Typ := Entity (Subtype_Mark (Indic)); else G_Typ := Entity (Indic); end if; if Nkind (Parent (G_Typ)) = N_Subtype_Declaration and then Present (Generic_Parent_Type (Parent (G_Typ))) then return Generic_Parent_Type (Parent (G_Typ)); end if; end if; return Empty; end Get_Generic_Parent_Type; ---------------------- -- Types_Correspond -- ---------------------- function Types_Correspond (P_Type : Entity_Id; N_Type : Entity_Id) return Boolean is Prev_Type : Entity_Id := Base_Type (P_Type); New_Type : Entity_Id := Base_Type (N_Type); begin if Ekind (Prev_Type) = E_Anonymous_Access_Type then Prev_Type := Designated_Type (Prev_Type); end if; if Ekind (New_Type) = E_Anonymous_Access_Type then New_Type := Designated_Type (New_Type); end if; if Prev_Type = New_Type then return True; elsif not Is_Class_Wide_Type (New_Type) then while Etype (New_Type) /= New_Type loop New_Type := Etype (New_Type); if New_Type = Prev_Type then return True; end if; end loop; end if; return False; end Types_Correspond; -- Start of processing for Is_Non_Overriding_Operation begin -- In the case where both operations are implicit derived subprograms -- then neither overrides the other. This can only occur in certain -- obscure cases (e.g., derivation from homographs created in a generic -- instantiation). if Present (Alias (Prev_E)) and then Present (Alias (New_E)) then return True; elsif Ekind (Current_Scope) = E_Package and then Is_Generic_Instance (Current_Scope) and then In_Private_Part (Current_Scope) and then Comes_From_Source (New_E) then -- We examine the formals and result subtype of the inherited -- operation, to determine whether their type is derived from (the -- instance of) a generic type. Formal := First_Formal (Prev_E); while Present (Formal) loop F_Typ := Base_Type (Etype (Formal)); if Ekind (F_Typ) = E_Anonymous_Access_Type then F_Typ := Designated_Type (F_Typ); end if; G_Typ := Get_Generic_Parent_Type (F_Typ); Next_Formal (Formal); end loop; if No (G_Typ) and then Ekind (Prev_E) = E_Function then G_Typ := Get_Generic_Parent_Type (Base_Type (Etype (Prev_E))); end if; if No (G_Typ) then return False; end if; -- If the generic type is a private type, then the original -- operation was not overriding in the generic, because there was -- no primitive operation to override. if Nkind (Parent (G_Typ)) = N_Formal_Type_Declaration and then Nkind (Formal_Type_Definition (Parent (G_Typ))) = N_Formal_Private_Type_Definition then return True; -- The generic parent type is the ancestor of a formal derived -- type declaration. We need to check whether it has a primitive -- operation that should be overridden by New_E in the generic. else declare P_Formal : Entity_Id; N_Formal : Entity_Id; P_Typ : Entity_Id; N_Typ : Entity_Id; P_Prim : Entity_Id; Prim_Elt : Elmt_Id := First_Elmt (Primitive_Operations (G_Typ)); begin while Present (Prim_Elt) loop P_Prim := Node (Prim_Elt); if Chars (P_Prim) = Chars (New_E) and then Ekind (P_Prim) = Ekind (New_E) then P_Formal := First_Formal (P_Prim); N_Formal := First_Formal (New_E); while Present (P_Formal) and then Present (N_Formal) loop P_Typ := Etype (P_Formal); N_Typ := Etype (N_Formal); if not Types_Correspond (P_Typ, N_Typ) then exit; end if; Next_Entity (P_Formal); Next_Entity (N_Formal); end loop; -- Found a matching primitive operation belonging to the -- formal ancestor type, so the new subprogram is -- overriding. if No (P_Formal) and then No (N_Formal) and then (Ekind (New_E) /= E_Function or else Types_Correspond (Etype (P_Prim), Etype (New_E))) then return False; end if; end if; Next_Elmt (Prim_Elt); end loop; -- If no match found, then the new subprogram does not -- override in the generic (nor in the instance). return True; end; end if; else return False; end if; end Is_Non_Overriding_Operation; ------------------------------ -- Make_Inequality_Operator -- ------------------------------ -- S is the defining identifier of an equality operator. We build a -- subprogram declaration with the right signature. This operation is -- intrinsic, because it is always expanded as the negation of the -- call to the equality function. procedure Make_Inequality_Operator (S : Entity_Id) is Loc : constant Source_Ptr := Sloc (S); Decl : Node_Id; Formals : List_Id; Op_Name : Entity_Id; FF : constant Entity_Id := First_Formal (S); NF : constant Entity_Id := Next_Formal (FF); begin -- Check that equality was properly defined, ignore call if not if No (NF) then return; end if; declare A : constant Entity_Id := Make_Defining_Identifier (Sloc (FF), Chars => Chars (FF)); B : constant Entity_Id := Make_Defining_Identifier (Sloc (NF), Chars => Chars (NF)); begin Op_Name := Make_Defining_Operator_Symbol (Loc, Name_Op_Ne); Formals := New_List ( Make_Parameter_Specification (Loc, Defining_Identifier => A, Parameter_Type => New_Reference_To (Etype (First_Formal (S)), Sloc (Etype (First_Formal (S))))), Make_Parameter_Specification (Loc, Defining_Identifier => B, Parameter_Type => New_Reference_To (Etype (Next_Formal (First_Formal (S))), Sloc (Etype (Next_Formal (First_Formal (S))))))); Decl := Make_Subprogram_Declaration (Loc, Specification => Make_Function_Specification (Loc, Defining_Unit_Name => Op_Name, Parameter_Specifications => Formals, Result_Definition => New_Reference_To (Standard_Boolean, Loc))); -- Insert inequality right after equality if it is explicit or after -- the derived type when implicit. These entities are created only -- for visibility purposes, and eventually replaced in the course of -- expansion, so they do not need to be attached to the tree and seen -- by the back-end. Keeping them internal also avoids spurious -- freezing problems. The declaration is inserted in the tree for -- analysis, and removed afterwards. If the equality operator comes -- from an explicit declaration, attach the inequality immediately -- after. Else the equality is inherited from a derived type -- declaration, so insert inequality after that declaration. if No (Alias (S)) then Insert_After (Unit_Declaration_Node (S), Decl); elsif Is_List_Member (Parent (S)) then Insert_After (Parent (S), Decl); else Insert_After (Parent (Etype (First_Formal (S))), Decl); end if; Mark_Rewrite_Insertion (Decl); Set_Is_Intrinsic_Subprogram (Op_Name); Analyze (Decl); Remove (Decl); Set_Has_Completion (Op_Name); Set_Corresponding_Equality (Op_Name, S); Set_Is_Abstract (Op_Name, Is_Abstract (S)); end; end Make_Inequality_Operator; ---------------------- -- May_Need_Actuals -- ---------------------- procedure May_Need_Actuals (Fun : Entity_Id) is F : Entity_Id; B : Boolean; begin F := First_Formal (Fun); B := True; while Present (F) loop if No (Default_Value (F)) then B := False; exit; end if; Next_Formal (F); end loop; Set_Needs_No_Actuals (Fun, B); end May_Need_Actuals; --------------------- -- Mode_Conformant -- --------------------- function Mode_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is Result : Boolean; begin Check_Conformance (New_Id, Old_Id, Mode_Conformant, False, Result); return Result; end Mode_Conformant; --------------------------- -- New_Overloaded_Entity -- --------------------------- procedure New_Overloaded_Entity (S : Entity_Id; Derived_Type : Entity_Id := Empty) is Does_Override : Boolean := False; -- Set if the current scope has an operation that is type-conformant -- with S, and becomes hidden by S. E : Entity_Id; -- Entity that S overrides Prev_Vis : Entity_Id := Empty; -- Needs comment ??? Is_Alias_Interface : Boolean := False; function Is_Private_Declaration (E : Entity_Id) return Boolean; -- Check that E is declared in the private part of the current package, -- or in the package body, where it may hide a previous declaration. -- We can't use In_Private_Part by itself because this flag is also -- set when freezing entities, so we must examine the place of the -- declaration in the tree, and recognize wrapper packages as well. procedure Maybe_Primitive_Operation (Is_Overriding : Boolean := False); -- If the subprogram being analyzed is a primitive operation of -- the type of one of its formals, set the corresponding flag. ---------------------------- -- Is_Private_Declaration -- ---------------------------- function Is_Private_Declaration (E : Entity_Id) return Boolean is Priv_Decls : List_Id; Decl : constant Node_Id := Unit_Declaration_Node (E); begin if Is_Package_Or_Generic_Package (Current_Scope) and then In_Private_Part (Current_Scope) then Priv_Decls := Private_Declarations ( Specification (Unit_Declaration_Node (Current_Scope))); return In_Package_Body (Current_Scope) or else (Is_List_Member (Decl) and then List_Containing (Decl) = Priv_Decls) or else (Nkind (Parent (Decl)) = N_Package_Specification and then not Is_Compilation_Unit ( Defining_Entity (Parent (Decl))) and then List_Containing (Parent (Parent (Decl))) = Priv_Decls); else return False; end if; end Is_Private_Declaration; ------------------------------- -- Maybe_Primitive_Operation -- ------------------------------- procedure Maybe_Primitive_Operation (Is_Overriding : Boolean := False) is Formal : Entity_Id; F_Typ : Entity_Id; B_Typ : Entity_Id; function Visible_Part_Type (T : Entity_Id) return Boolean; -- Returns true if T is declared in the visible part of -- the current package scope; otherwise returns false. -- Assumes that T is declared in a package. procedure Check_Private_Overriding (T : Entity_Id); -- Checks that if a primitive abstract subprogram of a visible -- abstract type is declared in a private part, then it must -- override an abstract subprogram declared in the visible part. -- Also checks that if a primitive function with a controlling -- result is declared in a private part, then it must override -- a function declared in the visible part. ------------------------------ -- Check_Private_Overriding -- ------------------------------ procedure Check_Private_Overriding (T : Entity_Id) is begin if Ekind (Current_Scope) = E_Package and then In_Private_Part (Current_Scope) and then Visible_Part_Type (T) and then not In_Instance then if Is_Abstract (T) and then Is_Abstract (S) and then (not Is_Overriding or else not Is_Abstract (E)) then if not Is_Interface (T) then Error_Msg_N ("abstract subprograms must be visible " & "('R'M 3.9.3(10))!", S); -- Ada 2005 (AI-251) else Error_Msg_N ("primitive subprograms of interface types " & "declared in a visible part, must be declared in " & "the visible part ('R'M 3.9.4)!", S); end if; elsif Ekind (S) = E_Function and then Is_Tagged_Type (T) and then T = Base_Type (Etype (S)) and then not Is_Overriding then Error_Msg_N ("private function with tagged result must" & " override visible-part function", S); Error_Msg_N ("\move subprogram to the visible part" & " ('R'M 3.9.3(10))", S); end if; end if; end Check_Private_Overriding; ----------------------- -- Visible_Part_Type -- ----------------------- function Visible_Part_Type (T : Entity_Id) return Boolean is P : constant Node_Id := Unit_Declaration_Node (Scope (T)); N : Node_Id; begin -- If the entity is a private type, then it must be -- declared in a visible part. if Ekind (T) in Private_Kind then return True; end if; -- Otherwise, we traverse the visible part looking for its -- corresponding declaration. We cannot use the declaration -- node directly because in the private part the entity of a -- private type is the one in the full view, which does not -- indicate that it is the completion of something visible. N := First (Visible_Declarations (Specification (P))); while Present (N) loop if Nkind (N) = N_Full_Type_Declaration and then Present (Defining_Identifier (N)) and then T = Defining_Identifier (N) then return True; elsif (Nkind (N) = N_Private_Type_Declaration or else Nkind (N) = N_Private_Extension_Declaration) and then Present (Defining_Identifier (N)) and then T = Full_View (Defining_Identifier (N)) then return True; end if; Next (N); end loop; return False; end Visible_Part_Type; -- Start of processing for Maybe_Primitive_Operation begin if not Comes_From_Source (S) then null; -- If the subprogram is at library level, it is not primitive -- operation. elsif Current_Scope = Standard_Standard then null; elsif (Ekind (Current_Scope) = E_Package and then not In_Package_Body (Current_Scope)) or else Is_Overriding then -- For function, check return type if Ekind (S) = E_Function then B_Typ := Base_Type (Etype (S)); if Scope (B_Typ) = Current_Scope then Set_Has_Primitive_Operations (B_Typ); Check_Private_Overriding (B_Typ); end if; end if; -- For all subprograms, check formals Formal := First_Formal (S); while Present (Formal) loop if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then F_Typ := Designated_Type (Etype (Formal)); else F_Typ := Etype (Formal); end if; B_Typ := Base_Type (F_Typ); if Scope (B_Typ) = Current_Scope then Set_Has_Primitive_Operations (B_Typ); Check_Private_Overriding (B_Typ); end if; Next_Formal (Formal); end loop; end if; end Maybe_Primitive_Operation; -- Start of processing for New_Overloaded_Entity begin -- We need to look for an entity that S may override. This must be a -- homonym in the current scope, so we look for the first homonym of -- S in the current scope as the starting point for the search. E := Current_Entity_In_Scope (S); -- If there is no homonym then this is definitely not overriding if No (E) then Enter_Overloaded_Entity (S); Check_Dispatching_Operation (S, Empty); Maybe_Primitive_Operation; -- Ada 2005 (AI-397): Subprograms in the context of protected -- types have their overriding indicators checked in Sem_Ch9. if Ekind (S) not in Subprogram_Kind or else Ekind (Scope (S)) /= E_Protected_Type then Check_Overriding_Indicator (S, False); end if; -- If there is a homonym that is not overloadable, then we have an -- error, except for the special cases checked explicitly below. elsif not Is_Overloadable (E) then -- Check for spurious conflict produced by a subprogram that has the -- same name as that of the enclosing generic package. The conflict -- occurs within an instance, between the subprogram and the renaming -- declaration for the package. After the subprogram, the package -- renaming declaration becomes hidden. if Ekind (E) = E_Package and then Present (Renamed_Object (E)) and then Renamed_Object (E) = Current_Scope and then Nkind (Parent (Renamed_Object (E))) = N_Package_Specification and then Present (Generic_Parent (Parent (Renamed_Object (E)))) then Set_Is_Hidden (E); Set_Is_Immediately_Visible (E, False); Enter_Overloaded_Entity (S); Set_Homonym (S, Homonym (E)); Check_Dispatching_Operation (S, Empty); Check_Overriding_Indicator (S, False); -- If the subprogram is implicit it is hidden by the previous -- declaration. However if it is dispatching, it must appear in the -- dispatch table anyway, because it can be dispatched to even if it -- cannot be called directly. elsif Present (Alias (S)) and then not Comes_From_Source (S) then Set_Scope (S, Current_Scope); if Is_Dispatching_Operation (Alias (S)) then Check_Dispatching_Operation (S, Empty); end if; return; else Error_Msg_Sloc := Sloc (E); Error_Msg_N ("& conflicts with declaration#", S); -- Useful additional warning if Is_Generic_Unit (E) then Error_Msg_N ("\previous generic unit cannot be overloaded", S); end if; return; end if; -- E exists and is overloadable else Is_Alias_Interface := Present (Alias (S)) and then Is_Dispatching_Operation (Alias (S)) and then Present (DTC_Entity (Alias (S))) and then Is_Interface (Scope (DTC_Entity (Alias (S)))); -- Loop through E and its homonyms to determine if any of them is -- the candidate for overriding by S. while Present (E) loop -- Definitely not interesting if not in the current scope if Scope (E) /= Current_Scope then null; -- Check if we have type conformance -- Ada 2005 (AI-251): In case of overriding an interface -- subprogram it is not an error that the old and new entities -- have the same profile, and hence we skip this code. elsif not Is_Alias_Interface and then Type_Conformant (E, S) -- Ada 2005 (AI-251): Do not consider here entities that cover -- abstract interface primitives. They will be handled after -- the overriden entity is found (see comments bellow inside -- this subprogram). and then not (Is_Subprogram (E) and then Present (Abstract_Interface_Alias (E))) then -- If the old and new entities have the same profile and one -- is not the body of the other, then this is an error, unless -- one of them is implicitly declared. -- There are some cases when both can be implicit, for example -- when both a literal and a function that overrides it are -- inherited in a derivation, or when an inhertited operation -- of a tagged full type overrides the ineherited operation of -- a private extension. Ada 83 had a special rule for the the -- literal case. In Ada95, the later implicit operation hides -- the former, and the literal is always the former. In the -- odd case where both are derived operations declared at the -- same point, both operations should be declared, and in that -- case we bypass the following test and proceed to the next -- part (this can only occur for certain obscure cases -- involving homographs in instances and can't occur for -- dispatching operations ???). Note that the following -- condition is less than clear. For example, it's not at all -- clear why there's a test for E_Entry here. ??? if Present (Alias (S)) and then (No (Alias (E)) or else Comes_From_Source (E) or else Is_Dispatching_Operation (E)) and then (Ekind (E) = E_Entry or else Ekind (E) /= E_Enumeration_Literal) then -- When an derived operation is overloaded it may be due to -- the fact that the full view of a private extension -- re-inherits. It has to be dealt with. if Is_Package_Or_Generic_Package (Current_Scope) and then In_Private_Part (Current_Scope) then Check_Operation_From_Private_View (S, E); end if; -- In any case the implicit operation remains hidden by -- the existing declaration, which is overriding. Set_Is_Overriding_Operation (E); if Comes_From_Source (E) then Check_Overriding_Indicator (E, True); -- Indicate that E overrides the operation from which -- S is inherited. if Present (Alias (S)) then Set_Overridden_Operation (E, Alias (S)); else Set_Overridden_Operation (E, S); end if; end if; return; -- Within an instance, the renaming declarations for -- actual subprograms may become ambiguous, but they do -- not hide each other. elsif Ekind (E) /= E_Entry and then not Comes_From_Source (E) and then not Is_Generic_Instance (E) and then (Present (Alias (E)) or else Is_Intrinsic_Subprogram (E)) and then (not In_Instance or else No (Parent (E)) or else Nkind (Unit_Declaration_Node (E)) /= N_Subprogram_Renaming_Declaration) then -- A subprogram child unit is not allowed to override -- an inherited subprogram (10.1.1(20)). if Is_Child_Unit (S) then Error_Msg_N ("child unit overrides inherited subprogram in parent", S); return; end if; if Is_Non_Overriding_Operation (E, S) then Enter_Overloaded_Entity (S); if No (Derived_Type) or else Is_Tagged_Type (Derived_Type) then Check_Dispatching_Operation (S, Empty); end if; return; end if; -- E is a derived operation or an internal operator which -- is being overridden. Remove E from further visibility. -- Furthermore, if E is a dispatching operation, it must be -- replaced in the list of primitive operations of its type -- (see Override_Dispatching_Operation). Does_Override := True; declare Prev : Entity_Id; begin Prev := First_Entity (Current_Scope); while Present (Prev) and then Next_Entity (Prev) /= E loop Next_Entity (Prev); end loop; -- It is possible for E to be in the current scope and -- yet not in the entity chain. This can only occur in a -- generic context where E is an implicit concatenation -- in the formal part, because in a generic body the -- entity chain starts with the formals. pragma Assert (Present (Prev) or else Chars (E) = Name_Op_Concat); -- E must be removed both from the entity_list of the -- current scope, and from the visibility chain if Debug_Flag_E then Write_Str ("Override implicit operation "); Write_Int (Int (E)); Write_Eol; end if; -- If E is a predefined concatenation, it stands for four -- different operations. As a result, a single explicit -- declaration does not hide it. In a possible ambiguous -- situation, Disambiguate chooses the user-defined op, -- so it is correct to retain the previous internal one. if Chars (E) /= Name_Op_Concat or else Ekind (E) /= E_Operator then -- For nondispatching derived operations that are -- overridden by a subprogram declared in the private -- part of a package, we retain the derived -- subprogram but mark it as not immediately visible. -- If the derived operation was declared in the -- visible part then this ensures that it will still -- be visible outside the package with the proper -- signature (calls from outside must also be -- directed to this version rather than the -- overriding one, unlike the dispatching case). -- Calls from inside the package will still resolve -- to the overriding subprogram since the derived one -- is marked as not visible within the package. -- If the private operation is dispatching, we achieve -- the overriding by keeping the implicit operation -- but setting its alias to be the overriding one. In -- this fashion the proper body is executed in all -- cases, but the original signature is used outside -- of the package. -- If the overriding is not in the private part, we -- remove the implicit operation altogether. if Is_Private_Declaration (S) then if not Is_Dispatching_Operation (E) then Set_Is_Immediately_Visible (E, False); else -- Work done in Override_Dispatching_Operation, -- so nothing else need to be done here. null; end if; else -- Find predecessor of E in Homonym chain if E = Current_Entity (E) then Prev_Vis := Empty; else Prev_Vis := Current_Entity (E); while Homonym (Prev_Vis) /= E loop Prev_Vis := Homonym (Prev_Vis); end loop; end if; if Prev_Vis /= Empty then -- Skip E in the visibility chain Set_Homonym (Prev_Vis, Homonym (E)); else Set_Name_Entity_Id (Chars (E), Homonym (E)); end if; Set_Next_Entity (Prev, Next_Entity (E)); if No (Next_Entity (Prev)) then Set_Last_Entity (Current_Scope, Prev); end if; end if; end if; Enter_Overloaded_Entity (S); Set_Is_Overriding_Operation (S); Check_Overriding_Indicator (S, True); -- Indicate that S overrides the operation from which -- E is inherited. if Comes_From_Source (S) then if Present (Alias (E)) then Set_Overridden_Operation (S, Alias (E)); else Set_Overridden_Operation (S, E); end if; end if; if Is_Dispatching_Operation (E) then -- An overriding dispatching subprogram inherits the -- convention of the overridden subprogram (by -- AI-117). Set_Convention (S, Convention (E)); -- AI-251: For an entity overriding an interface -- primitive check if the entity also covers other -- abstract subprograms in the same scope. This is -- required to handle the general case, that is, -- 1) overriding other interface primitives, and -- 2) overriding abstract subprograms inherited from -- some abstract ancestor type. if Has_Homonym (E) and then Present (Alias (E)) and then Ekind (Alias (E)) /= E_Operator and then Present (DTC_Entity (Alias (E))) and then Is_Interface (Scope (DTC_Entity (Alias (E)))) then declare E1 : Entity_Id; begin E1 := Homonym (E); while Present (E1) loop if (Is_Overloadable (E1) or else Ekind (E1) = E_Subprogram_Type) and then Present (Alias (E1)) and then Ekind (Alias (E1)) /= E_Operator and then Present (DTC_Entity (Alias (E1))) and then Is_Abstract (Scope (DTC_Entity (Alias (E1)))) and then Type_Conformant (E1, S) then Check_Dispatching_Operation (S, E1); end if; E1 := Homonym (E1); end loop; end; end if; Check_Dispatching_Operation (S, E); -- AI-251: Handle the case in which the entity -- overrides a primitive operation that covered -- several abstract interface primitives. declare E1 : Entity_Id; begin E1 := Current_Entity_In_Scope (S); while Present (E1) loop if Is_Subprogram (E1) and then Present (Abstract_Interface_Alias (E1)) and then Alias (E1) = E then Set_Alias (E1, S); end if; E1 := Homonym (E1); end loop; end; else Check_Dispatching_Operation (S, Empty); end if; Maybe_Primitive_Operation (Is_Overriding => True); goto Check_Inequality; end; -- Apparent redeclarations in instances can occur when two -- formal types get the same actual type. The subprograms in -- in the instance are legal, even if not callable from the -- outside. Calls from within are disambiguated elsewhere. -- For dispatching operations in the visible part, the usual -- rules apply, and operations with the same profile are not -- legal (B830001). elsif (In_Instance_Visible_Part and then not Is_Dispatching_Operation (E)) or else In_Instance_Not_Visible then null; -- Here we have a real error (identical profile) else Error_Msg_Sloc := Sloc (E); -- Avoid cascaded errors if the entity appears in -- subsequent calls. Set_Scope (S, Current_Scope); Error_Msg_N ("& conflicts with declaration#", S); if Is_Generic_Instance (S) and then not Has_Completion (E) then Error_Msg_N ("\instantiation cannot provide body for it", S); end if; return; end if; else -- If one subprogram has an access parameter and the other -- a parameter of an access type, calls to either might be -- ambiguous. Verify that parameters match except for the -- access parameter. if May_Hide_Profile then declare F1 : Entity_Id; F2 : Entity_Id; begin F1 := First_Formal (S); F2 := First_Formal (E); while Present (F1) and then Present (F2) loop if Is_Access_Type (Etype (F1)) then if not Is_Access_Type (Etype (F2)) or else not Conforming_Types (Designated_Type (Etype (F1)), Designated_Type (Etype (F2)), Type_Conformant) then May_Hide_Profile := False; end if; elsif not Conforming_Types (Etype (F1), Etype (F2), Type_Conformant) then May_Hide_Profile := False; end if; Next_Formal (F1); Next_Formal (F2); end loop; if May_Hide_Profile and then No (F1) and then No (F2) then Error_Msg_NE ("calls to& may be ambiguous?", S, S); end if; end; end if; end if; Prev_Vis := E; E := Homonym (E); end loop; -- On exit, we know that S is a new entity Enter_Overloaded_Entity (S); Maybe_Primitive_Operation; Check_Overriding_Indicator (S, Does_Override); -- If S is a derived operation for an untagged type then by -- definition it's not a dispatching operation (even if the parent -- operation was dispatching), so we don't call -- Check_Dispatching_Operation in that case. if No (Derived_Type) or else Is_Tagged_Type (Derived_Type) then Check_Dispatching_Operation (S, Empty); end if; end if; -- If this is a user-defined equality operator that is not a derived -- subprogram, create the corresponding inequality. If the operation is -- dispatching, the expansion is done elsewhere, and we do not create -- an explicit inequality operation. <<Check_Inequality>> if Chars (S) = Name_Op_Eq and then Etype (S) = Standard_Boolean and then Present (Parent (S)) and then not Is_Dispatching_Operation (S) then Make_Inequality_Operator (S); end if; end New_Overloaded_Entity; --------------------- -- Process_Formals -- --------------------- procedure Process_Formals (T : List_Id; Related_Nod : Node_Id) is Param_Spec : Node_Id; Formal : Entity_Id; Formal_Type : Entity_Id; Default : Node_Id; Ptype : Entity_Id; function Is_Class_Wide_Default (D : Node_Id) return Boolean; -- Check whether the default has a class-wide type. After analysis the -- default has the type of the formal, so we must also check explicitly -- for an access attribute. --------------------------- -- Is_Class_Wide_Default -- --------------------------- function Is_Class_Wide_Default (D : Node_Id) return Boolean is begin return Is_Class_Wide_Type (Designated_Type (Etype (D))) or else (Nkind (D) = N_Attribute_Reference and then Attribute_Name (D) = Name_Access and then Is_Class_Wide_Type (Etype (Prefix (D)))); end Is_Class_Wide_Default; -- Start of processing for Process_Formals begin -- In order to prevent premature use of the formals in the same formal -- part, the Ekind is left undefined until all default expressions are -- analyzed. The Ekind is established in a separate loop at the end. Param_Spec := First (T); while Present (Param_Spec) loop Formal := Defining_Identifier (Param_Spec); Enter_Name (Formal); -- Case of ordinary parameters if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then Find_Type (Parameter_Type (Param_Spec)); Ptype := Parameter_Type (Param_Spec); if Ptype = Error then goto Continue; end if; Formal_Type := Entity (Ptype); if Ekind (Formal_Type) = E_Incomplete_Type or else (Is_Class_Wide_Type (Formal_Type) and then Ekind (Root_Type (Formal_Type)) = E_Incomplete_Type) then -- Ada 2005 (AI-326): Tagged incomplete types allowed if Is_Tagged_Type (Formal_Type) then null; elsif Nkind (Parent (T)) /= N_Access_Function_Definition and then Nkind (Parent (T)) /= N_Access_Procedure_Definition then Error_Msg_N ("invalid use of incomplete type", Param_Spec); end if; elsif Ekind (Formal_Type) = E_Void then Error_Msg_NE ("premature use of&", Parameter_Type (Param_Spec), Formal_Type); end if; -- Ada 2005 (AI-231): Create and decorate an internal subtype -- declaration corresponding to the null-excluding type of the -- formal in the enclosing scope. Finally, replace the parameter -- type of the formal with the internal subtype. if Ada_Version >= Ada_05 and then Is_Access_Type (Formal_Type) and then Null_Exclusion_Present (Param_Spec) then if Can_Never_Be_Null (Formal_Type) and then Comes_From_Source (Related_Nod) then Error_Msg_N ("null exclusion must apply to a type that does not " & "exclude null ('R'M 3.10 (14)", Related_Nod); end if; Formal_Type := Create_Null_Excluding_Itype (T => Formal_Type, Related_Nod => Related_Nod, Scope_Id => Scope (Current_Scope)); end if; -- An access formal type else Formal_Type := Access_Definition (Related_Nod, Parameter_Type (Param_Spec)); -- Ada 2005 (AI-254) declare AD : constant Node_Id := Access_To_Subprogram_Definition (Parameter_Type (Param_Spec)); begin if Present (AD) and then Protected_Present (AD) then Formal_Type := Replace_Anonymous_Access_To_Protected_Subprogram (Param_Spec, Formal_Type); end if; end; end if; Set_Etype (Formal, Formal_Type); Default := Expression (Param_Spec); if Present (Default) then if Out_Present (Param_Spec) then Error_Msg_N ("default initialization only allowed for IN parameters", Param_Spec); end if; -- Do the special preanalysis of the expression (see section on -- "Handling of Default Expressions" in the spec of package Sem). Analyze_Per_Use_Expression (Default, Formal_Type); -- Check that the designated type of an access parameter's default -- is not a class-wide type unless the parameter's designated type -- is also class-wide. if Ekind (Formal_Type) = E_Anonymous_Access_Type and then not From_With_Type (Formal_Type) and then Is_Class_Wide_Default (Default) and then not Is_Class_Wide_Type (Designated_Type (Formal_Type)) then Error_Msg_N ("access to class-wide expression not allowed here", Default); end if; end if; -- Ada 2005 (AI-231): Static checks if Ada_Version >= Ada_05 and then Is_Access_Type (Etype (Formal)) and then Can_Never_Be_Null (Etype (Formal)) then Null_Exclusion_Static_Checks (Param_Spec); end if; <<Continue>> Next (Param_Spec); end loop; -- If this is the formal part of a function specification, analyze the -- subtype mark in the context where the formals are visible but not -- yet usable, and may hide outer homographs. if Nkind (Related_Nod) = N_Function_Specification then Analyze_Return_Type (Related_Nod); end if; -- Now set the kind (mode) of each formal Param_Spec := First (T); while Present (Param_Spec) loop Formal := Defining_Identifier (Param_Spec); Set_Formal_Mode (Formal); if Ekind (Formal) = E_In_Parameter then Set_Default_Value (Formal, Expression (Param_Spec)); if Present (Expression (Param_Spec)) then Default := Expression (Param_Spec); if Is_Scalar_Type (Etype (Default)) then if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then Formal_Type := Entity (Parameter_Type (Param_Spec)); else Formal_Type := Access_Definition (Related_Nod, Parameter_Type (Param_Spec)); end if; Apply_Scalar_Range_Check (Default, Formal_Type); end if; end if; end if; Next (Param_Spec); end loop; end Process_Formals; ---------------------------- -- Reference_Body_Formals -- ---------------------------- procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id) is Fs : Entity_Id; Fb : Entity_Id; begin if Error_Posted (Spec) then return; end if; Fs := First_Formal (Spec); Fb := First_Formal (Bod); while Present (Fs) loop Generate_Reference (Fs, Fb, 'b'); if Style_Check then Style.Check_Identifier (Fb, Fs); end if; Set_Spec_Entity (Fb, Fs); Set_Referenced (Fs, False); Next_Formal (Fs); Next_Formal (Fb); end loop; end Reference_Body_Formals; ------------------------- -- Set_Actual_Subtypes -- ------------------------- procedure Set_Actual_Subtypes (N : Node_Id; Subp : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); Decl : Node_Id; Formal : Entity_Id; T : Entity_Id; First_Stmt : Node_Id := Empty; AS_Needed : Boolean; begin -- If this is an emtpy initialization procedure, no need to create -- actual subtypes (small optimization). if Ekind (Subp) = E_Procedure and then Is_Null_Init_Proc (Subp) then return; end if; Formal := First_Formal (Subp); while Present (Formal) loop T := Etype (Formal); -- We never need an actual subtype for a constrained formal if Is_Constrained (T) then AS_Needed := False; -- If we have unknown discriminants, then we do not need an actual -- subtype, or more accurately we cannot figure it out! Note that -- all class-wide types have unknown discriminants. elsif Has_Unknown_Discriminants (T) then AS_Needed := False; -- At this stage we have an unconstrained type that may need an -- actual subtype. For sure the actual subtype is needed if we have -- an unconstrained array type. elsif Is_Array_Type (T) then AS_Needed := True; -- The only other case needing an actual subtype is an unconstrained -- record type which is an IN parameter (we cannot generate actual -- subtypes for the OUT or IN OUT case, since an assignment can -- change the discriminant values. However we exclude the case of -- initialization procedures, since discriminants are handled very -- specially in this context, see the section entitled "Handling of -- Discriminants" in Einfo. -- We also exclude the case of Discrim_SO_Functions (functions used -- in front end layout mode for size/offset values), since in such -- functions only discriminants are referenced, and not only are such -- subtypes not needed, but they cannot always be generated, because -- of order of elaboration issues. elsif Is_Record_Type (T) and then Ekind (Formal) = E_In_Parameter and then Chars (Formal) /= Name_uInit and then not Is_Unchecked_Union (T) and then not Is_Discrim_SO_Function (Subp) then AS_Needed := True; -- All other cases do not need an actual subtype else AS_Needed := False; end if; -- Generate actual subtypes for unconstrained arrays and -- unconstrained discriminated records. if AS_Needed then if Nkind (N) = N_Accept_Statement then -- If expansion is active, The formal is replaced by a local -- variable that renames the corresponding entry of the -- parameter block, and it is this local variable that may -- require an actual subtype. if Expander_Active then Decl := Build_Actual_Subtype (T, Renamed_Object (Formal)); else Decl := Build_Actual_Subtype (T, Formal); end if; if Present (Handled_Statement_Sequence (N)) then First_Stmt := First (Statements (Handled_Statement_Sequence (N))); Prepend (Decl, Statements (Handled_Statement_Sequence (N))); Mark_Rewrite_Insertion (Decl); else -- If the accept statement has no body, there will be no -- reference to the actuals, so no need to compute actual -- subtypes. return; end if; else Decl := Build_Actual_Subtype (T, Formal); Prepend (Decl, Declarations (N)); Mark_Rewrite_Insertion (Decl); end if; -- The declaration uses the bounds of an existing object, and -- therefore needs no constraint checks. Analyze (Decl, Suppress => All_Checks); -- We need to freeze manually the generated type when it is -- inserted anywhere else than in a declarative part. if Present (First_Stmt) then Insert_List_Before_And_Analyze (First_Stmt, Freeze_Entity (Defining_Identifier (Decl), Loc)); end if; if Nkind (N) = N_Accept_Statement and then Expander_Active then Set_Actual_Subtype (Renamed_Object (Formal), Defining_Identifier (Decl)); else Set_Actual_Subtype (Formal, Defining_Identifier (Decl)); end if; end if; Next_Formal (Formal); end loop; end Set_Actual_Subtypes; --------------------- -- Set_Formal_Mode -- --------------------- procedure Set_Formal_Mode (Formal_Id : Entity_Id) is Spec : constant Node_Id := Parent (Formal_Id); begin -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters -- since we ensure that corresponding actuals are always valid at the -- point of the call. if Out_Present (Spec) then if Ekind (Scope (Formal_Id)) = E_Function or else Ekind (Scope (Formal_Id)) = E_Generic_Function then Error_Msg_N ("functions can only have IN parameters", Spec); Set_Ekind (Formal_Id, E_In_Parameter); elsif In_Present (Spec) then Set_Ekind (Formal_Id, E_In_Out_Parameter); else Set_Ekind (Formal_Id, E_Out_Parameter); Set_Never_Set_In_Source (Formal_Id, True); Set_Is_True_Constant (Formal_Id, False); Set_Current_Value (Formal_Id, Empty); end if; else Set_Ekind (Formal_Id, E_In_Parameter); end if; -- Set Is_Known_Non_Null for access parameters since the language -- guarantees that access parameters are always non-null. We also set -- Can_Never_Be_Null, since there is no way to change the value. if Nkind (Parameter_Type (Spec)) = N_Access_Definition then -- Ada 2005 (AI-231): In Ada95, access parameters are always non- -- null; In Ada 2005, only if then null_exclusion is explicit. if Ada_Version < Ada_05 or else Can_Never_Be_Null (Etype (Formal_Id)) then Set_Is_Known_Non_Null (Formal_Id); Set_Can_Never_Be_Null (Formal_Id); end if; -- Ada 2005 (AI-231): Null-exclusion access subtype elsif Is_Access_Type (Etype (Formal_Id)) and then Can_Never_Be_Null (Etype (Formal_Id)) then Set_Is_Known_Non_Null (Formal_Id); end if; Set_Mechanism (Formal_Id, Default_Mechanism); Set_Formal_Validity (Formal_Id); end Set_Formal_Mode; ------------------------- -- Set_Formal_Validity -- ------------------------- procedure Set_Formal_Validity (Formal_Id : Entity_Id) is begin -- If no validity checking, then we cannot assume anything about the -- validity of parameters, since we do not know there is any checking -- of the validity on the call side. if not Validity_Checks_On then return; -- If validity checking for parameters is enabled, this means we are -- not supposed to make any assumptions about argument values. elsif Validity_Check_Parameters then return; -- If we are checking in parameters, we will assume that the caller is -- also checking parameters, so we can assume the parameter is valid. elsif Ekind (Formal_Id) = E_In_Parameter and then Validity_Check_In_Params then Set_Is_Known_Valid (Formal_Id, True); -- Similar treatment for IN OUT parameters elsif Ekind (Formal_Id) = E_In_Out_Parameter and then Validity_Check_In_Out_Params then Set_Is_Known_Valid (Formal_Id, True); end if; end Set_Formal_Validity; ------------------------ -- Subtype_Conformant -- ------------------------ function Subtype_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is Result : Boolean; begin Check_Conformance (New_Id, Old_Id, Subtype_Conformant, False, Result); return Result; end Subtype_Conformant; --------------------- -- Type_Conformant -- --------------------- function Type_Conformant (New_Id : Entity_Id; Old_Id : Entity_Id; Skip_Controlling_Formals : Boolean := False) return Boolean is Result : Boolean; begin May_Hide_Profile := False; Check_Conformance (New_Id, Old_Id, Type_Conformant, False, Result, Skip_Controlling_Formals => Skip_Controlling_Formals); return Result; end Type_Conformant; ------------------------------- -- Valid_Operator_Definition -- ------------------------------- procedure Valid_Operator_Definition (Designator : Entity_Id) is N : Integer := 0; F : Entity_Id; Id : constant Name_Id := Chars (Designator); N_OK : Boolean; begin F := First_Formal (Designator); while Present (F) loop N := N + 1; if Present (Default_Value (F)) then Error_Msg_N ("default values not allowed for operator parameters", Parent (F)); end if; Next_Formal (F); end loop; -- Verify that user-defined operators have proper number of arguments -- First case of operators which can only be unary if Id = Name_Op_Not or else Id = Name_Op_Abs then N_OK := (N = 1); -- Case of operators which can be unary or binary elsif Id = Name_Op_Add or Id = Name_Op_Subtract then N_OK := (N in 1 .. 2); -- All other operators can only be binary else N_OK := (N = 2); end if; if not N_OK then Error_Msg_N ("incorrect number of arguments for operator", Designator); end if; if Id = Name_Op_Ne and then Base_Type (Etype (Designator)) = Standard_Boolean and then not Is_Intrinsic_Subprogram (Designator) then Error_Msg_N ("explicit definition of inequality not allowed", Designator); end if; end Valid_Operator_Definition; end Sem_Ch6;
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding Samples -- -- -- -- ncurses2.trace_set -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 2000,2006 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Eugene V. Melaragno <aldomel@ix.netcom.com> 2000 -- Version Control -- $Revision: 1.2 $ -- $Date: 2006/06/25 14:24:40 $ -- Binding Version 01.00 ------------------------------------------------------------------------------ with ncurses2.util; use ncurses2.util; with Terminal_Interface.Curses; use Terminal_Interface.Curses; with Terminal_Interface.Curses.Trace; use Terminal_Interface.Curses.Trace; with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus; with Ada.Strings.Bounded; -- interactively set the trace level procedure ncurses2.trace_set is function menu_virtualize (c : Key_Code) return Menu_Request_Code; function subset (super, sub : Trace_Attribute_Set) return Boolean; function trace_or (a, b : Trace_Attribute_Set) return Trace_Attribute_Set; function trace_num (tlevel : Trace_Attribute_Set) return String; function tracetrace (tlevel : Trace_Attribute_Set) return String; function run_trace_menu (m : Menu) return Boolean; function menu_virtualize (c : Key_Code) return Menu_Request_Code is begin case c is when Character'Pos (newl) | Key_Exit => return Menu_Request_Code'Last + 1; -- MAX_COMMAND? TODO when Character'Pos ('u') => return M_ScrollUp_Line; when Character'Pos ('d') => return M_ScrollDown_Line; when Character'Pos ('b') | Key_Next_Page => return M_ScrollUp_Page; when Character'Pos ('f') | Key_Previous_Page => return M_ScrollDown_Page; when Character'Pos ('n') | Key_Cursor_Down => return M_Next_Item; when Character'Pos ('p') | Key_Cursor_Up => return M_Previous_Item; when Character'Pos (' ') => return M_Toggle_Item; when Key_Mouse => return c; when others => Beep; return c; end case; end menu_virtualize; type string_a is access String; type tbl_entry is record name : string_a; mask : Trace_Attribute_Set; end record; t_tbl : constant array (Positive range <>) of tbl_entry := ( (new String'("Disable"), Trace_Disable), (new String'("Times"), Trace_Attribute_Set'(Times => True, others => False)), (new String'("Tputs"), Trace_Attribute_Set'(Tputs => True, others => False)), (new String'("Update"), Trace_Attribute_Set'(Update => True, others => False)), (new String'("Cursor_Move"), Trace_Attribute_Set'(Cursor_Move => True, others => False)), (new String'("Character_Output"), Trace_Attribute_Set'(Character_Output => True, others => False)), (new String'("Ordinary"), Trace_Ordinary), (new String'("Calls"), Trace_Attribute_Set'(Calls => True, others => False)), (new String'("Virtual_Puts"), Trace_Attribute_Set'(Virtual_Puts => True, others => False)), (new String'("Input_Events"), Trace_Attribute_Set'(Input_Events => True, others => False)), (new String'("TTY_State"), Trace_Attribute_Set'(TTY_State => True, others => False)), (new String'("Internal_Calls"), Trace_Attribute_Set'(Internal_Calls => True, others => False)), (new String'("Character_Calls"), Trace_Attribute_Set'(Character_Calls => True, others => False)), (new String'("Termcap_TermInfo"), Trace_Attribute_Set'(Termcap_TermInfo => True, others => False)), (new String'("Maximium"), Trace_Maximum) ); package BS is new Ada.Strings.Bounded.Generic_Bounded_Length (300); function subset (super, sub : Trace_Attribute_Set) return Boolean is begin if (super.Times or not sub.Times) and (super.Tputs or not sub.Tputs) and (super.Update or not sub.Update) and (super.Cursor_Move or not sub.Cursor_Move) and (super.Character_Output or not sub.Character_Output) and (super.Calls or not sub.Calls) and (super.Virtual_Puts or not sub.Virtual_Puts) and (super.Input_Events or not sub.Input_Events) and (super.TTY_State or not sub.TTY_State) and (super.Internal_Calls or not sub.Internal_Calls) and (super.Character_Calls or not sub.Character_Calls) and (super.Termcap_TermInfo or not sub.Termcap_TermInfo) and True then return True; else return False; end if; end subset; function trace_or (a, b : Trace_Attribute_Set) return Trace_Attribute_Set is retval : Trace_Attribute_Set := Trace_Disable; begin retval.Times := (a.Times or b.Times); retval.Tputs := (a.Tputs or b.Tputs); retval.Update := (a.Update or b.Update); retval.Cursor_Move := (a.Cursor_Move or b.Cursor_Move); retval.Character_Output := (a.Character_Output or b.Character_Output); retval.Calls := (a.Calls or b.Calls); retval.Virtual_Puts := (a.Virtual_Puts or b.Virtual_Puts); retval.Input_Events := (a.Input_Events or b.Input_Events); retval.TTY_State := (a.TTY_State or b.TTY_State); retval.Internal_Calls := (a.Internal_Calls or b.Internal_Calls); retval.Character_Calls := (a.Character_Calls or b.Character_Calls); retval.Termcap_TermInfo := (a.Termcap_TermInfo or b.Termcap_TermInfo); return retval; end trace_or; -- Print the hexadecimal value of the mask so -- users can set it from the command line. function trace_num (tlevel : Trace_Attribute_Set) return String is result : Integer := 0; m : Integer := 1; begin if tlevel.Times then result := result + m; end if; m := m * 2; if tlevel.Tputs then result := result + m; end if; m := m * 2; if tlevel.Update then result := result + m; end if; m := m * 2; if tlevel.Cursor_Move then result := result + m; end if; m := m * 2; if tlevel.Character_Output then result := result + m; end if; m := m * 2; if tlevel.Calls then result := result + m; end if; m := m * 2; if tlevel.Virtual_Puts then result := result + m; end if; m := m * 2; if tlevel.Input_Events then result := result + m; end if; m := m * 2; if tlevel.TTY_State then result := result + m; end if; m := m * 2; if tlevel.Internal_Calls then result := result + m; end if; m := m * 2; if tlevel.Character_Calls then result := result + m; end if; m := m * 2; if tlevel.Termcap_TermInfo then result := result + m; end if; m := m * 2; return result'Img; end trace_num; function tracetrace (tlevel : Trace_Attribute_Set) return String is use BS; buf : Bounded_String := To_Bounded_String (""); begin -- The C version prints the hexadecimal value of the mask, we -- won't do that here because this is Ada. if tlevel = Trace_Disable then Append (buf, "Trace_Disable"); else if subset (tlevel, Trace_Attribute_Set'(Times => True, others => False)) then Append (buf, "Times"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(Tputs => True, others => False)) then Append (buf, "Tputs"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(Update => True, others => False)) then Append (buf, "Update"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(Cursor_Move => True, others => False)) then Append (buf, "Cursor_Move"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(Character_Output => True, others => False)) then Append (buf, "Character_Output"); Append (buf, ", "); end if; if subset (tlevel, Trace_Ordinary) then Append (buf, "Ordinary"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(Calls => True, others => False)) then Append (buf, "Calls"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(Virtual_Puts => True, others => False)) then Append (buf, "Virtual_Puts"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(Input_Events => True, others => False)) then Append (buf, "Input_Events"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(TTY_State => True, others => False)) then Append (buf, "TTY_State"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(Internal_Calls => True, others => False)) then Append (buf, "Internal_Calls"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(Character_Calls => True, others => False)) then Append (buf, "Character_Calls"); Append (buf, ", "); end if; if subset (tlevel, Trace_Attribute_Set'(Termcap_TermInfo => True, others => False)) then Append (buf, "Termcap_TermInfo"); Append (buf, ", "); end if; if subset (tlevel, Trace_Maximum) then Append (buf, "Maximium"); Append (buf, ", "); end if; end if; if To_String (buf) (Length (buf) - 1) = ',' then Delete (buf, Length (buf) - 1, Length (buf)); end if; return To_String (buf); end tracetrace; function run_trace_menu (m : Menu) return Boolean is i, p : Item; changed : Boolean; c, v : Key_Code; begin loop changed := False; c := Getchar (Get_Window (m)); v := menu_virtualize (c); case Driver (m, v) is when Unknown_Request => return False; when others => i := Current (m); if i = Menus.Items (m, 1) then -- the first item for n in t_tbl'First + 1 .. t_tbl'Last loop if Value (i) then Set_Value (i, False); changed := True; end if; end loop; else for n in t_tbl'First + 1 .. t_tbl'Last loop p := Menus.Items (m, n); if Value (p) then Set_Value (Menus.Items (m, 1), False); changed := True; exit; end if; end loop; end if; if not changed then return True; end if; end case; end loop; end run_trace_menu; nc_tracing, mask : Trace_Attribute_Set; pragma Import (C, nc_tracing, "_nc_tracing"); items_a : constant Item_Array_Access := new Item_Array (t_tbl'First .. t_tbl'Last + 1); mrows : Line_Count; mcols : Column_Count; menuwin : Window; menu_y : constant Line_Position := 8; menu_x : constant Column_Position := 8; ip : Item; m : Menu; newtrace : Trace_Attribute_Set; begin Add (Line => 0, Column => 0, Str => "Interactively set trace level:"); Add (Line => 2, Column => 0, Str => " Press space bar to toggle a selection."); Add (Line => 3, Column => 0, Str => " Use up and down arrow to move the select bar."); Add (Line => 4, Column => 0, Str => " Press return to set the trace level."); Add (Line => 6, Column => 0, Str => "(Current trace level is "); Add (Str => tracetrace (nc_tracing) & " numerically: " & trace_num (nc_tracing)); Add (Ch => ')'); Refresh; for n in t_tbl'Range loop items_a (n) := New_Item (t_tbl (n).name.all); end loop; items_a (t_tbl'Last + 1) := Null_Item; m := New_Menu (items_a); Set_Format (m, 16, 2); Scale (m, mrows, mcols); Switch_Options (m, (One_Valued => True, others => False), On => False); menuwin := New_Window (mrows + 2, mcols + 2, menu_y, menu_x); Set_Window (m, menuwin); Set_KeyPad_Mode (menuwin, SwitchOn => True); Box (menuwin); Set_Sub_Window (m, Derived_Window (menuwin, mrows, mcols, 1, 1)); Post (m); for n in t_tbl'Range loop ip := Items (m, n); mask := t_tbl (n).mask; if mask = Trace_Disable then Set_Value (ip, nc_tracing = Trace_Disable); elsif subset (sub => mask, super => nc_tracing) then Set_Value (ip, True); end if; end loop; while run_trace_menu (m) loop null; end loop; newtrace := Trace_Disable; for n in t_tbl'Range loop ip := Items (m, n); if Value (ip) then mask := t_tbl (n).mask; newtrace := trace_or (newtrace, mask); end if; end loop; Trace_On (newtrace); Trace_Put ("trace level interactively set to " & tracetrace (nc_tracing)); Move_Cursor (Line => Lines - 4, Column => 0); Add (Str => "Trace level is "); Add (Str => tracetrace (nc_tracing)); Add (Ch => newl); Pause; -- was just Add(); Getchar Post (m, False); -- menuwin has subwindows I think, which makes an error. declare begin Delete (menuwin); exception when Curses_Exception => null; end; -- free_menu(m); -- free_item() end ncurses2.trace_set;
-- SPDX-FileCopyrightText: 2021 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- with Ada.Iterator_Interfaces; package Program.Interpretations.Symbols is pragma Preelaborate; type Cursor is record Index : Natural; Symbol : Program.Symbols.Symbol; end record; function Has_Element (Self : Cursor) return Boolean is (Self.Index > 0); package Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element); type Iterator is new Iterators.Forward_Iterator with private; function Each (Set : Interpretation_Set) return Iterator; private type Iterator is new Iterators.Forward_Iterator with record Set : Interpretation_Set; end record; overriding function First (Self : Iterator) return Cursor; overriding function Next (Self : Iterator; Position : Cursor) return Cursor; end Program.Interpretations.Symbols;
------------------------------------------------------------------------- -- GL.Errors - GL error support -- -- Copyright (c) Rod Kay 2007 -- AUSTRALIA -- Permission granted to use this software, without any warranty, -- for any purpose, provided this copyright note remains attached -- and unmodified if sources are distributed further. ------------------------------------------------------------------------- with Ada.Text_IO; use Ada.Text_IO; with Ada.Unchecked_Conversion; with GLU; with Interfaces.C.Strings; use Interfaces.C.Strings; package body GL.Errors is function Current return String is function to_chars_ptr is new Ada.Unchecked_Conversion (GL.ubytePtr, chars_ptr); begin return Value (to_chars_ptr (GLU.Error_String (GL.Get_Error))); end Current; procedure log (Prefix : String := "") is Current_GL_Error : constant String := Current; begin if Current_GL_Error /= "no error" then case Prefix = "" is when True => Put_Line ("openGL error : '" & Current_GL_Error & "'"); when False => Put_Line (Prefix & " : '" & Current_GL_Error & "'"); end case; raise openGL_Error; -- tbd : use ada.exceptions to attach the openg error string to the exception. end if; end log; procedure log (Prefix : String := ""; error_Occurred : out Boolean) is Current_GL_Error : constant String := Current; begin error_Occurred := Current_GL_Error /= "no error"; if error_Occurred then case Prefix = "" is when True => Put_Line ("openGL error : '" & Current_GL_Error & "'"); when False => Put_Line (Prefix & " : '" & Current_GL_Error & "'"); end case; end if; end log; end GL.Errors;
with Ada.Wide_Text_IO; use Ada.Wide_Text_IO; with Ada.Characters.Handling; use Ada.Characters.Handling; with Asis; with Asis.Compilation_Units; with Asis.Elements; with Asis.Declarations; with Asis.Definitions; with Asis.Expressions; with Asis.Exceptions; package body FP_Detect is function Is_PP_Elem_Fn(Element : Asis.Element) return Boolean is Decl : Asis.Element := Asis.Expressions.Corresponding_Name_Declaration(Element); Unit : Asis.Compilation_Unit := Asis.Elements.Enclosing_Compilation_Unit(Decl); Unit_Name : Wide_String := Asis.Compilation_Units.Unit_Full_Name(Unit); begin Put("Unit_Name = "); Put(Unit_Name); New_Line; return Unit_Name = "PP_F_Elementary" or Unit_Name = "PP_LF_Elementary" or Unit_Name = "PP_SF_Elementary"; exception when others => return False; end Is_PP_Elem_Fn; function Is_ElemFn_Instance(Element : Asis.Element) return Boolean is Generic_Element : Asis.Element := Asis.Declarations.Corresponding_Generic_Element(Element); Generic_Unit : Asis.Compilation_Unit := Asis.Elements.Enclosing_Compilation_Unit(Generic_Element); Generic_Unit_Name : Wide_String := Asis.Compilation_Units.Unit_Full_Name(Generic_Unit); begin return Generic_Unit_Name = "Ada.Numerics.Generic_Elementary_Functions"; exception when others => return False; end Is_ElemFn_Instance; function Is_FP_Operator_Expression(Element : Asis.Element) return Maybe_FP_Operator is Root : Asis.Element; Type_Info : FP_Type; Result_Field_Op : Maybe_FP_Operator(Field_Op); Result_Elem_Fn : Maybe_FP_Operator(Elementary_Fn); begin -- try to obtain FP precision: Type_Info := FP_Type_Of(Element); -- store the precision in potential result records: Result_Field_Op.Type_Info := Type_Info; Result_Elem_Fn.Type_Info := Type_Info; -- try to extract the root of the expression tree: Root := Asis.Expressions.Prefix(Element); -- investigate the kind of the root expression: case Asis.Elements.Expression_Kind(Root) is when Asis.An_Operator_Symbol => -- check whether the operator is a rounded FP operator: Result_Field_Op.Op_Kind := Asis.Elements.Operator_Kind(Root); case Result_Field_Op.Op_Kind is when Asis.A_Divide_Operator | Asis.A_Multiply_Operator | Asis.A_Plus_Operator | Asis.A_Minus_Operator | Asis.An_Exponentiate_Operator => return Result_Field_Op; when others => return No_FP_Operator; end case; when Asis.A_Selected_Component => -- check whether the function refers to one of the functions from -- Ada.Numerics.Generic_Elementary_Functions: if Is_PP_Elem_Fn(Asis.Expressions.Selector(Root)) then Result_Elem_Fn.Fn_Name := Asis.Expressions.Selector(Root); return Result_Elem_Fn; else return No_FP_Operator; end if; when Asis.An_Identifier => if Is_PP_Elem_Fn(Root) then Result_Elem_Fn.Fn_Name := Root; return Result_Elem_Fn; else return No_FP_Operator; end if; when others => return No_FP_Operator; end case; exception when Ex : Asis.Exceptions.ASIS_Inappropriate_Element => return No_FP_Operator; end Is_FP_Operator_Expression; function FP_Type_Of(Expr : Asis.Element) return FP_Type is Expr_Type_Decl : Asis.Declaration := Asis.Expressions.Corresponding_Expression_Type(Expr); Expr_Type_Def : Asis.Definition := Asis.Declarations.Type_Declaration_View(Expr_Type_Decl); Expr_Root_Type_Decl : Asis.Declaration; Expr_Root_Type_Def : Asis.Definition; Result : FP_Type; begin -- determine the root type so that we can get its precision: begin Expr_Root_Type_Decl := Asis.Definitions.Corresponding_Root_Type(Expr_Type_Def); Expr_Root_Type_Def := Asis.Declarations.Type_Declaration_View(Expr_Root_Type_Decl); exception when Ex : others => -- failed to find a root, assume already got the root: Expr_Root_Type_Decl := Expr_Type_Decl; Expr_Root_Type_Def := Expr_Type_Def; end; -- extract precision from the root type: declare Digits_Expr : Asis.Expression := Asis.Definitions.Digits_Expression(Expr_Root_Type_Def); Digits_String : Wide_String := Asis.Expressions.Value_Image(Digits_Expr); begin Result.Precision := Integer'Value(To_String(Digits_String)); end; -- extract the type name: Result.Name := Asis.Declarations.Names(Expr_Type_Decl)(1); -- check if the name is standard: declare Name : Wide_String := Asis.Declarations.Defining_Name_Image(Result.Name); begin if Name = "Float" then Result.Is_Standard := True; Result.Code := F; elsif Name = "Long_Float" then Result.Is_Standard := True; Result.Code := LF; elsif Name = "Short_Float" then Result.Is_Standard := True; Result.Code := SF; else Result.Is_Standard := False; Result.Code := LF; end if; end; return Result; end FP_Type_Of; end FP_Detect;
pragma Ada_2005; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; with SDL_SDL_stdinc_h; package SDL_SDL_cpuinfo_h is function SDL_HasRDTSC return SDL_SDL_stdinc_h.SDL_bool; -- ../include/SDL/SDL_cpuinfo.h:40 pragma Import (C, SDL_HasRDTSC, "SDL_HasRDTSC"); function SDL_HasMMX return SDL_SDL_stdinc_h.SDL_bool; -- ../include/SDL/SDL_cpuinfo.h:43 pragma Import (C, SDL_HasMMX, "SDL_HasMMX"); function SDL_HasMMXExt return SDL_SDL_stdinc_h.SDL_bool; -- ../include/SDL/SDL_cpuinfo.h:46 pragma Import (C, SDL_HasMMXExt, "SDL_HasMMXExt"); function SDL_Has3DNow return SDL_SDL_stdinc_h.SDL_bool; -- ../include/SDL/SDL_cpuinfo.h:49 pragma Import (C, SDL_Has3DNow, "SDL_Has3DNow"); function SDL_Has3DNowExt return SDL_SDL_stdinc_h.SDL_bool; -- ../include/SDL/SDL_cpuinfo.h:52 pragma Import (C, SDL_Has3DNowExt, "SDL_Has3DNowExt"); function SDL_HasSSE return SDL_SDL_stdinc_h.SDL_bool; -- ../include/SDL/SDL_cpuinfo.h:55 pragma Import (C, SDL_HasSSE, "SDL_HasSSE"); function SDL_HasSSE2 return SDL_SDL_stdinc_h.SDL_bool; -- ../include/SDL/SDL_cpuinfo.h:58 pragma Import (C, SDL_HasSSE2, "SDL_HasSSE2"); function SDL_HasAltiVec return SDL_SDL_stdinc_h.SDL_bool; -- ../include/SDL/SDL_cpuinfo.h:61 pragma Import (C, SDL_HasAltiVec, "SDL_HasAltiVec"); end SDL_SDL_cpuinfo_h;
./menu2 1 Fee Fie 2 Huff & Puff 3 mirror mirror 4 tick tock chose (0 to exit) #:2 you chose #:Huff & Puff 1 Fee Fie 2 Huff & Puff 3 mirror mirror 4 tick tock chose (0 to exit) #:55 Menu selection out of range 1 Fee Fie 2 Huff & Puff 3 mirror mirror 4 tick tock chose (0 to exit) #:0 Menu selection out of range [2010-06-09 22:18:25] process terminated successfully (elapsed time: 15.27s)
------------------------------------------------------------------------------- -- LSE -- L-System Editor -- Author: Heziode -- -- License: -- MIT License -- -- Copyright (c) 2018 Quentin Dauprat (Heziode) <Heziode@protonmail.com> -- -- Permission is hereby granted, free of charge, to any person obtaining a -- copy of this software and associated documentation files (the "Software"), -- to deal in the Software without restriction, including without limitation -- the rights to use, copy, modify, merge, publish, distribute, sublicense, -- and/or sell copies of the Software, and to permit persons to whom the -- Software is furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -- DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- with Ada.Command_Line; with Ada.Text_IO; with GNAT.Command_Line; with GNAT.Directory_Operations; with GNAT.Strings; with LSE.Model.IO.Drawing_Area.Drawing_Area_Ptr; with LSE.Model.IO.Drawing_Area_Factory; with LSE.Model.IO.Text_File; with LSE.Model.IO.Turtle; with LSE.Model.IO.Turtle_Utils; with LSE.Model.L_System.Concrete_Builder; with LSE.Model.L_System.L_System; with LSE.Presenter.Presenter; with LSE.View.View; use Ada.Command_Line; use Ada.Text_IO; use GNAT.Command_Line; use GNAT.Directory_Operations; use GNAT.Strings; use LSE.Model.IO.Drawing_Area.Drawing_Area_Ptr; use LSE.Model.IO.Drawing_Area_Factory; use LSE.Model.IO.Text_File; use LSE.Model.IO.Turtle; use LSE.Model.IO.Turtle_Utils; use LSE.Model.L_System.Concrete_Builder; use LSE.Model.L_System.L_System; use LSE.Presenter.Presenter; use LSE.View.View; -- @description -- Entry point of the app -- procedure Main is Main_UI : constant String := "ressources/view.glade"; pragma Unreferenced (Main_UI); Exec_Dir : constant String := Dir_Name (Command_Name); pragma Unreferenced (Exec_Dir); No_Input_File : exception; No_Export_File : exception; No_Export : exception; No_Develop : exception; LS_Creation : exception; Config : Command_Line_Configuration; No_GUI : aliased Boolean := False; Input_File : aliased String_Access; Output_File : aliased String_Access; Export : aliased String_Access; Export_File : aliased String_Access; Develop : aliased Integer := 0; Width : aliased Integer := 0; Height : aliased Integer := 0; Background_Color : aliased String_Access; Foreground_Color : aliased String_Access; Margin_Top : aliased Integer := 0; Margin_Right : aliased Integer := 0; Margin_Bottom : aliased Integer := 0; Margin_Left : aliased Integer := 0; T : LSE.Model.IO.Turtle_Utils.Holder; B : LSE.Model.L_System.Concrete_Builder.Instance; L : LSE.Model.L_System.L_System.Instance; F : File_Type; Medium : LSE.Model.IO.Drawing_Area.Drawing_Area_Ptr.Holder; View : LSE.View.View.Instance; Presenter : LSE.Presenter.Presenter.Instance; begin Define_Switch (Config, No_GUI'Access, Long_Switch => "--no-gui", Help => "True for no-gui, False otherwise [default False]"); Define_Switch (Config, Input_File'Access, "-i:", Long_Switch => "--input=", Help => "Input file that contains a L-System"); Define_Switch (Config, Output_File'Access, "-o:", Long_Switch => "--output=", Help => "Output file that will contains a L-System"); Define_Switch (Config, Export'Access, "-e:", Long_Switch => "--export=", Help => "Export format"); Define_Switch (Config, Export_File'Access, "-p:", Long_Switch => "--export-file=", Help => "Output file that will contains the " & "representation of the L-System"); Define_Switch (Config, Develop'Access, "-d:", Long_Switch => "--develop=", Help => "number of step to develop"); Define_Switch (Config, Width'Access, "-w:", Long_Switch => "--width=", Help => "Width of the output representation " & "(must be greater than 0 else is ignored)"); Define_Switch (Config, Height'Access, "-h:", Long_Switch => "--height=", Help => "Height of the output representation " & "(must be greater than 0 else is ignored)"); Define_Switch (Config, Background_Color'Access, "-b:", Long_Switch => "--background-color=", Help => "background color of the output representation " & "(in Hex, like #AABBCC or AABBCC)"); Define_Switch (Config, Foreground_Color'Access, "-f:", Long_Switch => "--foreground-color=", Help => "foreground color of the output representation " & "(in Hex, like #AABBCC or AABBCC)"); Define_Switch (Config, Margin_Top'Access, "-mt:", Long_Switch => "--margin-top=", Help => "Enable margin top of the output representation " & "(must be greater than 0 else is ignored)"); Define_Switch (Config, Margin_Right'Access, "-mr:", Long_Switch => "--margin-right=", Help => "Enable margin right of the output representation " & "(must be greater than 0 else is ignored)"); Define_Switch (Config, Margin_Bottom'Access, "-mb:", Long_Switch => "--margin-bottom=", Help => "Enable margin bottom of the output representation" & " (must be greater than 0 else is ignored)"); Define_Switch (Config, Margin_Left'Access, "-ml:", Long_Switch => "--margin-left=", Help => "Enable margin left of the output representation " & "(must be greater than 0 else is ignored)"); Getopt (Config); if No_GUI then if Input_File.all = "" then raise No_Input_File; elsif Export.all = "" then raise No_Export; elsif Export_File.all = "" then raise No_Export_File; elsif Develop < 0 then raise No_Develop; end if; T := To_Holder (Initialize); Make (Medium, Export.all, Export_File.all); T.Reference.Set_Medium (Medium); if Width > 0 then Set_Width (T.Reference, Width); end if; if Height > 0 then Set_Height (T.Reference, Height); end if; if Background_Color.all /= "" then Set_Background_Color (T.Reference, Background_Color.all); end if; if Foreground_Color.all /= "" then Set_Foreground_Color (T.Reference, Foreground_Color.all); end if; if Margin_Top > 0 then Set_Margin_Top (T.Reference, Natural (Margin_Top)); end if; if Margin_Right > 0 then Set_Margin_Right (T.Reference, Margin_Right); end if; if Margin_Bottom > 0 then Set_Margin_Bottom (T.Reference, Margin_Bottom); end if; if Margin_Left > 0 then Set_Margin_Left (T.Reference, Margin_Left); end if; Initialize (B); Open_File (F, In_File, Input_File.all, False); if Read_LSystem (F, B, T, L) then Put_Line ("L-System:"); Put_Line (L.Get_LSystem); L.Set_State (Develop); L.Develop; L.Interpret (T); Close_File (F); Put_Line ("L-System rendered for level" & Integer'Image (Develop)); else Put_Line ("L-System creation error:"); Put_Line (B.Get_Error); Close_File (F); raise LS_Creation; end if; else -- GUI Mode Presenter.Initialize; View := Presenter.Get_View; View.Set_Presenter (Presenter); Presenter.Start; end if; exception when GNAT.Command_Line.Exit_From_Command_Line => return; end Main;
with AUnit; with AUnit.Test_Cases; package Day.Test is type Test is new AUnit.Test_Cases.Test_Case with null record; function Name (T : Test) return AUnit.Message_String; procedure Register_Tests (T : in out Test); -- Test routines procedure Test_Part1 (T : in out AUnit.Test_Cases.Test_Case'Class); procedure Test_Part2 (T : in out AUnit.Test_Cases.Test_Case'Class); end Day.Test;
package revisions -- Ada spec generator -- File: revisions.ads BUILD_TIME : constant String := "Thu Nov 7 2019 04:10:14" ; VERSION_MAJOR : constant := 0 ; VERSION_MINOR : constant := 0 ; VERSION_BUILD : constant := 999 ; REPO_URL : constant String := "git@gitlab.com:privatetutor/projectlets/go.git" ; SHORT_COMMIT_ID : constant String := "26d9420" ; LONG_COMMIT_ID : constant String := "26d9420a08b510d4f0dcd17437114246b60a09a4" ; end revisions ;
----------------------------------------------------------------------- -- Util.Concurrent.Fifos -- Concurrent Fifo Queues -- Copyright (C) 2012, 2014 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Unchecked_Deallocation; package body Util.Concurrent.Fifos is -- ------------------------------ -- Put the element in the queue. -- ------------------------------ procedure Enqueue (Into : in out Fifo; Item : in Element_Type; Wait : in Duration := FOREVER) is begin if Wait < 0.0 then Into.Buffer.Enqueue (Item); else select Into.Buffer.Enqueue (Item); or delay Wait; raise Timeout; end select; end if; end Enqueue; -- ------------------------------ -- Get an element from the queue. -- Wait until one element gets available. -- ------------------------------ procedure Dequeue (From : in out Fifo; Item : out Element_Type; Wait : in Duration := FOREVER) is begin if Wait < 0.0 then From.Buffer.Dequeue (Item); else select From.Buffer.Dequeue (Item); or delay Wait; raise Timeout; end select; end if; end Dequeue; -- ------------------------------ -- Get the number of elements in the queue. -- ------------------------------ function Get_Count (From : in Fifo) return Natural is begin return From.Buffer.Get_Count; end Get_Count; -- ------------------------------ -- Set the queue size. -- ------------------------------ procedure Set_Size (Into : in out Fifo; Capacity : in Positive) is begin Into.Buffer.Set_Size (Capacity); end Set_Size; -- ------------------------------ -- Initializes the queue. -- ------------------------------ overriding procedure Initialize (Object : in out Fifo) is begin Object.Buffer.Set_Size (Default_Size); end Initialize; -- ------------------------------ -- Release the queue elements. -- ------------------------------ overriding procedure Finalize (Object : in out Fifo) is begin if Clear_On_Dequeue then while Object.Get_Count > 0 loop declare Unused : Element_Type; begin Object.Dequeue (Unused); end; end loop; end if; Object.Buffer.Set_Size (0); end Finalize; -- Queue of objects. protected body Protected_Fifo is -- ------------------------------ -- Put the element in the queue. -- If the queue is full, wait until some room is available. -- ------------------------------ entry Enqueue (Item : in Element_Type) when Count < Elements'Length is begin Elements (Last) := Item; Last := Last + 1; if Last > Elements'Last then if Clear_On_Dequeue then Last := Elements'First + 1; else Last := Elements'First; end if; end if; Count := Count + 1; end Enqueue; -- ------------------------------ -- Get an element from the queue. -- Wait until one element gets available. -- ------------------------------ entry Dequeue (Item : out Element_Type) when Count > 0 is begin Count := Count - 1; Item := Elements (First); -- For the clear on dequeue mode, erase the queue element. -- If the element holds some storage or a reference, this gets cleared here. -- The element used to clear is at index 0 (which does not exist if Clear_On_Dequeue -- is false). There is no overhead when this is not used -- (ie, instantiation/compile time flag). if Clear_On_Dequeue then Elements (First) := Elements (0); end if; First := First + 1; if First > Elements'Last then if Clear_On_Dequeue then First := Elements'First + 1; else First := Elements'First; end if; end if; end Dequeue; -- ------------------------------ -- Get the number of elements in the queue. -- ------------------------------ function Get_Count return Natural is begin return Count; end Get_Count; -- ------------------------------ -- Set the queue size. -- ------------------------------ procedure Set_Size (Capacity : in Natural) is procedure Free is new Ada.Unchecked_Deallocation (Element_Array, Element_Array_Access); First_Pos : Natural := 1; begin if Clear_On_Dequeue then First_Pos := 0; end if; if Capacity = 0 then Free (Elements); elsif Elements = null then Elements := new Element_Array (First_Pos .. Capacity); else declare New_Array : constant Element_Array_Access := new Element_Array (First_Pos .. Capacity); begin if Capacity > Elements'Length then New_Array (First_Pos .. Elements'Last) := Elements (First_Pos .. Elements'Last); else New_Array (First_Pos .. Capacity) := Elements (First_Pos .. Capacity); end if; Free (Elements); Elements := New_Array; end; end if; end Set_Size; end Protected_Fifo; end Util.Concurrent.Fifos;
with Ada.Unchecked_Deallocation; package body kv.Ref_Counting_Mixin is procedure Free is new Ada.Unchecked_Deallocation(Data_Type, Data_Access); procedure Free is new Ada.Unchecked_Deallocation(Control_Type, Control_Access); ----------------------------------------------------------------------------- procedure Initialize(Self : in out Ref_Type) is begin Self.Control := new Control_Type; Self.Control.Data := new Data_Type; Self.Control.Count := 1; end Initialize; ----------------------------------------------------------------------------- procedure Adjust(Self : in out Ref_Type) is Control : Control_Access := Self.Control; begin if Control /= null then Control.Count := Control.Count + 1; end if; end Adjust; ----------------------------------------------------------------------------- procedure Finalize(Self : in out Ref_Type) is Control : Control_Access := Self.Control; begin Self.Control := null; if Control /= null then Control.Count := Control.Count - 1; if Control.Count = 0 then Free(Control.Data); Free(Control); end if; end if; end Finalize; ----------------------------------------------------------------------------- procedure Set(Self : in out Ref_Type; Data : in Data_Access) is begin Self.Control.Data := Data; end Set; ----------------------------------------------------------------------------- function Get(Self : Ref_Type) return Data_Access is begin return Self.Control.Data; end Get; end kv.Ref_Counting_Mixin;
----------------------------------------------------------------------- -- util-executors -- Execute work that is queued -- Copyright (C) 2019, 2020 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- package body Util.Executors is overriding procedure Initialize (Manager : in out Executor_Manager) is begin Manager.Self := Manager'Unchecked_Access; end Initialize; -- ------------------------------ -- Execute the work through the executor. -- ------------------------------ procedure Execute (Manager : in out Executor_Manager; Work : in Work_Type) is W : constant Work_Info := Work_Info '(Work => Work, Done => False); begin Manager.Queue.Enqueue (W); end Execute; -- ------------------------------ -- Start the executor tasks. -- ------------------------------ procedure Start (Manager : in out Executor_Manager; Autostop : in Boolean := False) is begin Manager.Autostop := Autostop; for Worker of Manager.Workers loop Worker.Start (Manager.Self); end loop; end Start; -- ------------------------------ -- Stop the tasks and wait for their completion. -- ------------------------------ procedure Stop (Manager : in out Executor_Manager) is W : Work_Info; begin W.Done := True; for Worker of Manager.Workers loop if not Worker'Terminated then Manager.Queue.Enqueue (W); end if; end loop; end Stop; -- ------------------------------ -- Set the work queue size. -- ------------------------------ procedure Set_Queue_Size (Manager : in out Executor_Manager; Capacity : in Positive) is begin Manager.Queue.Set_Size (Capacity); end Set_Queue_Size; -- ------------------------------ -- Wait for the pending work to be executed by the executor tasks. -- ------------------------------ procedure Wait (Manager : in out Executor_Manager) is begin Manager.Queue.Wait_Empty; end Wait; -- ------------------------------ -- Get the number of elements in the queue. -- ------------------------------ function Get_Count (Manager : in Executor_Manager) return Natural is begin return Manager.Queue.Get_Count; end Get_Count; -- ------------------------------ -- Stop and release the executor. -- ------------------------------ overriding procedure Finalize (Manager : in out Executor_Manager) is begin Manager.Stop; end Finalize; task body Worker_Task is M : access Executor_Manager; Autostop : Boolean := False; begin select accept Start (Manager : in Executor_Manager_Access) do M := Manager; end Start; or terminate; end select; while M /= null loop declare Work : Work_Info; begin if Autostop then M.Queue.Dequeue (Work, 0.0); else M.Queue.Dequeue (Work); end if; exit when Work.Done; begin Execute (Work.Work); exception when E : others => Error (Work.Work, E); end; Autostop := M.Autostop; exception when Work_Queue.Timeout => exit; end; end loop; end Worker_Task; end Util.Executors;
with fann_c.fann_Train_data; package Neural.Set -- -- models a set of neural patterns used for trainng or testing a net. -- is type Patterns_view is access all Patterns; type Set is record Patterns : Patterns_view; Fann : fann_c.fann_Train_data.pointer; end record; function to_Set (the_Patterns : in Patterns_view) return Set; end Neural.Set;
-- -- Utility package to convert IDs to enumarative values. -- private generic type Field_Enumerator is (<>); Prefix : String := ""; package Protypo.Api.Field_Names is function Is_Field (X : ID) return Boolean; function To_Field (X : ID) return Field_Enumerator; end Protypo.Api.Field_Names;
with Ada.Strings.Unbounded; package Word_Lists is package ASU renames Ada.Strings.Unbounded; type Cell; type Word_List_Type is access Cell; type Cell is record Word: ASU.Unbounded_String; Count: Natural := 0; Next: Word_List_Type; end record; Word_List_Error: exception; procedure Add_Word (List: in out Word_List_Type; Word: in ASU.Unbounded_String); procedure Delete_Word (List: in out Word_List_Type; Word: in ASU.Unbounded_String); procedure Search_Word (List: in Word_List_Type; Word: in ASU.Unbounded_String; Count: out Natural); procedure Max_Word (List: in Word_List_Type; Word: out ASU.Unbounded_String; Count: out Natural); procedure Print_All (List: in Word_List_Type); end Word_Lists;
with GNAT.Command_Line; use GNAT.Command_Line; with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Termbox_Package; use Termbox_Package; with Editor_Package; use Editor_Package; with Buffer_Package; use Buffer_Package; with Command_Package; use Command_Package; procedure Main is RunRC : Boolean := True; TopOrBot : Boolean := False; Reversed : Boolean := False; begin loop case Getopt ("n t r") is when 'n' => RunRC := False; when 't' => TopOrBot := True; when 'r' => Reversed := True; when others => exit; end case; end loop; declare Init : constant Integer := TB_Init; Mode : constant Output_Mode := TB_Select_Output_Mode (TB_OUTPUT_256); File_Name : constant Unbounded_String := To_Unbounded_String (Get_Argument); Editor_Main : Editor; begin if Init = 0 and Mode = TB_OUTPUT_256 then TB_Clear; Editor_Main := Open_Editor (File_Name, 0, 0); Load_File (File_Name, Editor_Main); if RunRC then Run_Startup_Files (File_Name); end if; Enable_Undo (Editor_Main.Doc_View.B); Editor_Main.Doc_View.B.Dirty := False; declare A : constant Arg := (T => ARG_STRING, S1 => File_Name); begin Run_File (Editor_Main, Editor_Main.Doc_View, A); Run (Editor_Main); end; Put (TopOrBot'Image); Put (Reversed'Image); TB_Shutdown; end if; end; end Main;
-- { dg-do compile } -- { dg-options "-gnatE" } package body Dynamic_Elab2 is function Get_Plot return Plot is procedure Fill (X : out Plot) is begin X.Data := Get_R; end; X : Plot; begin Fill(X); return X; end; end Dynamic_Elab2;
package body STM32GD.SPI.Peripheral is procedure Init is begin null; end Init; procedure Transfer (Data : in out SPI_Data_8b) is begin while SPI.SR.TXE = 0 loop null; end loop; SPI.DR.DR := UInt16 (Data (0)); while SPI.SR.RXNE = 0 loop null; end loop; Data (0) := Byte (SPI.DR.DR); end Transfer; end STM32GD.SPI.Peripheral;
with Units; use Units; package body Units.Navigation with SPARK_Mode is function foo return Heading_Type is result : Angle_Type; -- SPARK GPL 2016: everything okay. -- SPARK Pro 18.0w: error with DEGREE 360; remove "constant" and it works A : Angle_Type := DEGREE_360; begin return Heading_Type( result ); end foo; function bar return Length_Type is EPS : constant := 1.0E-12; pragma Assert (EPS > Float'Small); begin return 0.0*Meter; end bar; end Units.Navigation;
-- { dg-do compile } -- { dg-options "-O" } with Text_IO; use Text_IO; package body Concat2 is function Get_Param return String is begin return ""; end; procedure Browse is Mode : constant String := Get_Param; Mode_Param : constant String := "MODE=" & Mode; begin Put_Line (Mode_Param); end; end Concat2;
-------------------------------------------------------------------------------- -- Copyright (c) 2013, Felix Krause <contact@flyx.org> -- -- Permission to use, copy, modify, and/or distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------------- with CL.Memory.Images.GL_Base; with CL.Contexts.CL_GL; with GL.Objects.Renderbuffers; with GL.Objects.Textures.Targets; package CL.Memory.Images.CL_GL is package Image2D_Base is new GL_Base (Parent => Image2D); package Image3D_Base is new GL_Base (Parent => Image3D); subtype Image2D is Image2D_Base.Image; subtype Image3D is Image3D_Base.Image; package Constructors is package Targets renames GL.Objects.Textures.Targets; function Create_Image2D (Context : Contexts.CL_GL.Context'Class; Mode : Access_Kind; Texture_Target : Targets.Texture_2D_Target.Fillable_Target'Class; Mipmap_Level : GL.Objects.Textures.Mipmap_Level; Texture : GL.Objects.Textures.Texture'Class) return Image2D; function Create_Image2D (Context : Contexts.CL_GL.Context'Class; Mode : Access_Kind; Texture_Target : Targets.Cube_Map_Side_Target.Fillable_Target'Class; Mipmap_Level : GL.Objects.Textures.Mipmap_Level; Texture : GL.Objects.Textures.Texture'Class) return Image2D; function Create_Image2D (Context : Contexts.CL_GL.Context'Class; Mode : Access_Kind; Renderbuffer : GL.Objects.Renderbuffers.Renderbuffer_Target) return Image2D; function Create_Image3D (Context : Contexts.CL_GL.Context'Class; Mode : Access_Kind; Texture_Target : Targets.Texture_3D_Target.Fillable_Target'Class; Mipmap_Level : GL.Objects.Textures.Mipmap_Level; Texture : GL.Objects.Textures.Texture'Class) return Image3D; end Constructors; end CL.Memory.Images.CL_GL;
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding Samples -- -- -- -- ncurses -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- Copyright 2020 Thomas E. Dickey -- -- Copyright 2000-2014,2015 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Eugene V. Melaragno <aldomel@ix.netcom.com> 2000 -- Version Control -- $Revision: 1.8 $ -- $Date: 2020/02/02 23:34:34 $ -- Binding Version 01.00 ------------------------------------------------------------------------------ with ncurses2.util; use ncurses2.util; with Terminal_Interface.Curses; use Terminal_Interface.Curses; -- test effects of overlapping windows procedure ncurses2.overlap_test is procedure fillwin (win : Window; ch : Character); procedure crosswin (win : Window; ch : Character); procedure fillwin (win : Window; ch : Character) is y1 : Line_Position; x1 : Column_Position; begin Get_Size (win, y1, x1); for y in 0 .. y1 - 1 loop Move_Cursor (win, y, 0); for x in 0 .. x1 - 1 loop Add (win, Ch => ch); end loop; end loop; exception when Curses_Exception => null; -- write to lower right corner end fillwin; procedure crosswin (win : Window; ch : Character) is y1 : Line_Position; x1 : Column_Position; begin Get_Size (win, y1, x1); for y in 0 .. y1 - 1 loop for x in 0 .. x1 - 1 loop if ((x > (x1 - 1) / 3) and (x <= (2 * (x1 - 1)) / 3)) or (((y > (y1 - 1) / 3) and (y <= (2 * (y1 - 1)) / 3))) then Move_Cursor (win, y, x); Add (win, Ch => ch); end if; end loop; end loop; end crosswin; -- In a 24x80 screen like some xterms are, the instructions will -- be overwritten. ch : Character; win1 : Window := New_Window (9, 20, 3, 3); win2 : Window := New_Window (9, 20, 9, 16); begin Set_Raw_Mode (SwitchOn => True); Refresh; Move_Cursor (Line => 0, Column => 0); Add (Str => "This test shows the behavior of wnoutrefresh() with " & "respect to"); Add (Ch => newl); Add (Str => "the shared region of two overlapping windows A and B. " & "The cross"); Add (Ch => newl); Add (Str => "pattern in each window does not overlap the other."); Add (Ch => newl); Move_Cursor (Line => 18, Column => 0); Add (Str => "a = refresh A, then B, then doupdate. b = refresh B, " & "then A, then doupdate"); Add (Ch => newl); Add (Str => "c = fill window A with letter A. d = fill window B " & "with letter B."); Add (Ch => newl); Add (Str => "e = cross pattern in window A. f = cross pattern " & "in window B."); Add (Ch => newl); Add (Str => "g = clear window A. h = clear window B."); Add (Ch => newl); Add (Str => "i = overwrite A onto B. j = overwrite " & "B onto A."); Add (Ch => newl); Add (Str => "^Q/ESC = terminate test."); loop ch := Code_To_Char (Getchar); exit when ch = CTRL ('Q') or ch = CTRL ('['); -- QUIT or ESCAPE case ch is when 'a' => -- refresh window A first, then B Refresh_Without_Update (win1); Refresh_Without_Update (win2); Update_Screen; when 'b' => -- refresh window B first, then A Refresh_Without_Update (win2); Refresh_Without_Update (win1); Update_Screen; when 'c' => -- fill window A so it's visible fillwin (win1, 'A'); when 'd' => -- fill window B so it's visible fillwin (win2, 'B'); when 'e' => -- cross test pattern in window A crosswin (win1, 'A'); when 'f' => -- cross test pattern in window B crosswin (win2, 'B'); when 'g' => -- clear window A Clear (win1); Move_Cursor (win1, 0, 0); when 'h' => -- clear window B Clear (win2); Move_Cursor (win2, 0, 0); when 'i' => -- overwrite A onto B Overwrite (win1, win2); when 'j' => -- overwrite B onto A Overwrite (win2, win1); when others => null; end case; end loop; Delete (win2); Delete (win1); Erase; End_Windows; end ncurses2.overlap_test;
package Examples.Text_Rewrites is procedure Demo (File_Name : String); end Examples.Text_Rewrites;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2019, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ with HAL; with System; package SAM.DAC is function Enabled return Boolean; -- return True if the DAC is enabled type Reference_Volage is (VREFAU, -- Unbuffered external voltage reference VDDANA, -- Voltage supply VREFAB, -- Buffered external voltage reference INTREF); -- Internal bandgap reference type Mode_Kind is (Single_Mode, Differential_Mode); procedure Configure (Mode : Mode_Kind; Vref : Reference_Volage) with Pre => not Enabled; type Channel_ID is range 0 .. 1; type Oversampling_Ratio is (OSR_1, OSR_2, OSR_4, OSR_8, OSR_16, OSR_32); type Refresh_Period is new HAL.UInt4; type Current_Control is (CC100K, CC1M, CC12M); type Data_Adjustment is (Right_Adjusted, Left_Adjusted); procedure Configure_Channel (Chan : Channel_ID; Oversampling : Oversampling_Ratio; Refresh : Refresh_Period; Enable_Dithering : Boolean; Run_In_Standby : Boolean; Standalone_Filter : Boolean; Current : Current_Control; Adjustement : Data_Adjustment; Enable_Filter_Result_Ready_Evt : Boolean; Enable_Data_Buffer_Empty_Evt : Boolean; Enable_Convert_On_Input_Evt : Boolean; Invert_Input_Evt : Boolean; Enable_Overrun_Int : Boolean; Enable_Underrun_Int : Boolean; Enable_Result_Ready_Int : Boolean; Enable_Buffer_Empty_Int : Boolean) with Pre => not Enabled; procedure Enable (Chan_0 : Boolean; Chan_1 : Boolean) with Post => (if Chan_0 or else Chan_1 then Enabled); procedure Write (Chan : Channel_ID; Data : HAL.UInt16); procedure Write_Buffer (Chan : Channel_ID; Data : HAL.UInt16); function Result (Chan : Channel_ID) return HAL.UInt16; function Data_Address (Chan : Channel_ID) return System.Address; -- For DMA transfers procedure Debug_Stop_Mode (Enabled : Boolean := True); -- Stop the device when the CPU is halted by an external debugger. -- This mode is enabled by default. private for Reference_Volage use (VREFAU => 0, VDDANA => 1, VREFAB => 2, INTREF => 3); for Oversampling_Ratio use (OSR_1 => 0, OSR_2 => 1, OSR_4 => 2, OSR_8 => 3, OSR_16 => 4, OSR_32 => 5); for Current_Control use (CC100K => 0, CC1M => 1, CC12M => 2); end SAM.DAC;
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- package body Program.Nodes.Formal_Derived_Type_Definitions is function Create (Abstract_Token : Program.Lexical_Elements.Lexical_Element_Access; Limited_Token : Program.Lexical_Elements.Lexical_Element_Access; Synchronized_Token : Program.Lexical_Elements.Lexical_Element_Access; New_Token : not null Program.Lexical_Elements .Lexical_Element_Access; Subtype_Mark : not null Program.Elements.Expressions .Expression_Access; And_Token : Program.Lexical_Elements.Lexical_Element_Access; Progenitors : Program.Elements.Expressions .Expression_Vector_Access; With_Token : Program.Lexical_Elements.Lexical_Element_Access; Private_Token : Program.Lexical_Elements.Lexical_Element_Access) return Formal_Derived_Type_Definition is begin return Result : Formal_Derived_Type_Definition := (Abstract_Token => Abstract_Token, Limited_Token => Limited_Token, Synchronized_Token => Synchronized_Token, New_Token => New_Token, Subtype_Mark => Subtype_Mark, And_Token => And_Token, Progenitors => Progenitors, With_Token => With_Token, Private_Token => Private_Token, Enclosing_Element => null) do Initialize (Result); end return; end Create; function Create (Subtype_Mark : not null Program.Elements.Expressions .Expression_Access; Progenitors : Program.Elements.Expressions .Expression_Vector_Access; Is_Part_Of_Implicit : Boolean := False; Is_Part_Of_Inherited : Boolean := False; Is_Part_Of_Instance : Boolean := False; Has_Abstract : Boolean := False; Has_Limited : Boolean := False; Has_Synchronized : Boolean := False; Has_With_Private : Boolean := False) return Implicit_Formal_Derived_Type_Definition is begin return Result : Implicit_Formal_Derived_Type_Definition := (Subtype_Mark => Subtype_Mark, Progenitors => Progenitors, Is_Part_Of_Implicit => Is_Part_Of_Implicit, Is_Part_Of_Inherited => Is_Part_Of_Inherited, Is_Part_Of_Instance => Is_Part_Of_Instance, Has_Abstract => Has_Abstract, Has_Limited => Has_Limited, Has_Synchronized => Has_Synchronized, Has_With_Private => Has_With_Private, Enclosing_Element => null) do Initialize (Result); end return; end Create; overriding function Subtype_Mark (Self : Base_Formal_Derived_Type_Definition) return not null Program.Elements.Expressions.Expression_Access is begin return Self.Subtype_Mark; end Subtype_Mark; overriding function Progenitors (Self : Base_Formal_Derived_Type_Definition) return Program.Elements.Expressions.Expression_Vector_Access is begin return Self.Progenitors; end Progenitors; overriding function Abstract_Token (Self : Formal_Derived_Type_Definition) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Abstract_Token; end Abstract_Token; overriding function Limited_Token (Self : Formal_Derived_Type_Definition) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Limited_Token; end Limited_Token; overriding function Synchronized_Token (Self : Formal_Derived_Type_Definition) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Synchronized_Token; end Synchronized_Token; overriding function New_Token (Self : Formal_Derived_Type_Definition) return not null Program.Lexical_Elements.Lexical_Element_Access is begin return Self.New_Token; end New_Token; overriding function And_Token (Self : Formal_Derived_Type_Definition) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.And_Token; end And_Token; overriding function With_Token (Self : Formal_Derived_Type_Definition) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.With_Token; end With_Token; overriding function Private_Token (Self : Formal_Derived_Type_Definition) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Private_Token; end Private_Token; overriding function Has_Abstract (Self : Formal_Derived_Type_Definition) return Boolean is begin return Self.Abstract_Token.Assigned; end Has_Abstract; overriding function Has_Limited (Self : Formal_Derived_Type_Definition) return Boolean is begin return Self.Limited_Token.Assigned; end Has_Limited; overriding function Has_Synchronized (Self : Formal_Derived_Type_Definition) return Boolean is begin return Self.Synchronized_Token.Assigned; end Has_Synchronized; overriding function Has_With_Private (Self : Formal_Derived_Type_Definition) return Boolean is begin return Self.With_Token.Assigned; end Has_With_Private; overriding function Is_Part_Of_Implicit (Self : Implicit_Formal_Derived_Type_Definition) return Boolean is begin return Self.Is_Part_Of_Implicit; end Is_Part_Of_Implicit; overriding function Is_Part_Of_Inherited (Self : Implicit_Formal_Derived_Type_Definition) return Boolean is begin return Self.Is_Part_Of_Inherited; end Is_Part_Of_Inherited; overriding function Is_Part_Of_Instance (Self : Implicit_Formal_Derived_Type_Definition) return Boolean is begin return Self.Is_Part_Of_Instance; end Is_Part_Of_Instance; overriding function Has_Abstract (Self : Implicit_Formal_Derived_Type_Definition) return Boolean is begin return Self.Has_Abstract; end Has_Abstract; overriding function Has_Limited (Self : Implicit_Formal_Derived_Type_Definition) return Boolean is begin return Self.Has_Limited; end Has_Limited; overriding function Has_Synchronized (Self : Implicit_Formal_Derived_Type_Definition) return Boolean is begin return Self.Has_Synchronized; end Has_Synchronized; overriding function Has_With_Private (Self : Implicit_Formal_Derived_Type_Definition) return Boolean is begin return Self.Has_With_Private; end Has_With_Private; procedure Initialize (Self : aliased in out Base_Formal_Derived_Type_Definition'Class) is begin Set_Enclosing_Element (Self.Subtype_Mark, Self'Unchecked_Access); for Item in Self.Progenitors.Each_Element loop Set_Enclosing_Element (Item.Element, Self'Unchecked_Access); end loop; null; end Initialize; overriding function Is_Formal_Derived_Type_Definition_Element (Self : Base_Formal_Derived_Type_Definition) return Boolean is pragma Unreferenced (Self); begin return True; end Is_Formal_Derived_Type_Definition_Element; overriding function Is_Formal_Type_Definition_Element (Self : Base_Formal_Derived_Type_Definition) return Boolean is pragma Unreferenced (Self); begin return True; end Is_Formal_Type_Definition_Element; overriding function Is_Definition_Element (Self : Base_Formal_Derived_Type_Definition) return Boolean is pragma Unreferenced (Self); begin return True; end Is_Definition_Element; overriding procedure Visit (Self : not null access Base_Formal_Derived_Type_Definition; Visitor : in out Program.Element_Visitors.Element_Visitor'Class) is begin Visitor.Formal_Derived_Type_Definition (Self); end Visit; overriding function To_Formal_Derived_Type_Definition_Text (Self : aliased in out Formal_Derived_Type_Definition) return Program.Elements.Formal_Derived_Type_Definitions .Formal_Derived_Type_Definition_Text_Access is begin return Self'Unchecked_Access; end To_Formal_Derived_Type_Definition_Text; overriding function To_Formal_Derived_Type_Definition_Text (Self : aliased in out Implicit_Formal_Derived_Type_Definition) return Program.Elements.Formal_Derived_Type_Definitions .Formal_Derived_Type_Definition_Text_Access is pragma Unreferenced (Self); begin return null; end To_Formal_Derived_Type_Definition_Text; end Program.Nodes.Formal_Derived_Type_Definitions;
with Ada.Text_IO; with Ada.Strings.Fixed; with Ada.Characters.Handling; with Ada.Long_Integer_Text_IO; -- Copyright 2021 Melwyn Francis Carlo procedure A022 is use Ada.Text_IO; use Ada.Strings.Fixed; use Ada.Long_Integer_Text_IO; FT : File_Type; Ch : Character; Name_Val : String (1 .. 50) := 50 * ' '; Names_List : array (Integer range 1 .. 5500) of String (1 .. 50) := (others => 50 * ' '); File_Name : constant String := "problems/022/p022_names.txt"; Is_Incremented : Boolean := False; Count_Val : Integer := 1; Index_Val : Integer := 1; Alpha_Val, Str_Len : Integer; N : Long_Integer; begin Open (FT, In_File, File_Name); Get (FT, Ch); while not End_Of_File (FT) loop Get (FT, Ch); if Ada.Characters.Handling.Is_Letter (Ch) then Is_Incremented := False; Name_Val (Index_Val) := Ch; Index_Val := Index_Val + 1; else if not Is_Incremented then Index_Val := 1; Is_Incremented := True; Names_List (Count_Val) := Name_Val; Count_Val := Count_Val + 1; Name_Val := 50 * ' '; end if; end if; end loop; Close (FT); Count_Val := Count_Val - 1; for I in 1 .. (Count_Val - 1) loop for J in (I + 1) .. Count_Val loop if Names_List (I) > Names_List (J) then Name_Val := 50 * ' '; Name_Val := Names_List (I); Names_List (I) := Names_List (J); Names_List (J) := Name_Val; end if; end loop; end loop; N := 0; for I in 1 .. Count_Val loop Alpha_Val := 0; Str_Len := Index (Names_List (I), " ") - 1; for J in 1 .. Str_Len loop Alpha_Val := Alpha_Val + Character'Pos (Names_List (I) (J)) - 64; end loop; N := N + Long_Integer (I * Alpha_Val); end loop; Put (N, Width => 0); end A022;
with Ada.Text_IO; use Ada.Text_IO; with P_StructuralTypes; use P_StructuralTypes; package body P_stephandler is function Get_NextHandler (Self : in out T_StepHandler) return Ptr_Handler is begin return Self.NextHandler; end; procedure Set_NextHandler (Self : in out T_StepHandler; Ptr_StepHandler : Ptr_Handler) is begin Self.NextHandler := Ptr_StepHandler; end; procedure Set_BinaryContainer (Self : in out T_StepHandler; Ptr_BinaryContainer : BinaryContainer_Access) is begin Self.Ptr_BinaryContainer := Ptr_BinaryContainer; end; function Get_BinaryContainer (Self : in out T_StepHandler) return BinaryContainer_Access is begin return Self.Ptr_BinaryContainer; end; end P_stephandler;
-- The Village of Vampire by YT, このソースコードはNYSLです with Ada.Strings.Unbounded; with Tabula.Calendar.Time_IO; with Tabula.Casts.Cast_IO; with Tabula.Villages.Village_IO; package body Vampire.Villages.Village_IO is use People; use Person_Records; procedure IO ( Serializer : not null access Serialization.Serializer; Name : in String; People : in out Villages.People.Vector) is package People_IO is new Serialization.IO_List ( Cursor => Villages.People.Cursor, Element_Type => Person_Type, Container_Type => Villages.People.Vector, Reference_Type => Villages.People.Reference_Type, Default => Empty_Person, Has_Element => Villages.People.Has_Element, Next => Villages.People.Cursor'Succ); use Serialization; use Person_Role_IO; use Person_State_IO; use Requested_Role_IO; use People_IO; use Calendar.Time_IO; use Casts.Cast_IO; procedure People_Callback ( Serializer : not null access Serialization.Serializer; Item : in out Person_Type) is procedure Person_Records_Callback ( Serializer : not null access Serialization.Serializer; Item : in out Person_Record) is begin for P in IO (Serializer) loop IO (Serializer, "state", Item.State); IO (Serializer, "vote", Item.Vote, Default => Default_Person_Record.Vote); IO (Serializer, "provisional-vote", Item.Provisional_Vote, Default => Default_Person_Record.Provisional_Vote); IO (Serializer, "candidate", Item.Candidate, Default => Default_Person_Record.Candidate); IO (Serializer, "target", Item.Target, Default => Default_Person_Record.Target); IO (Serializer, "special", Item.Special, Default => Default_Person_Record.Special); IO (Serializer, "note", Item.Note, Default => Default_Person_Record.Note); end loop; end Person_Records_Callback; package Person_Records_IO is new Serialization.IO_List ( Cursor => Villages.Person_Records.Cursor, Element_Type => Person_Record, Container_Type => Villages.Person_Records.Vector, Reference_Type => Villages.Person_Records.Reference_Type, Default => Default_Person_Record, Has_Element => Villages.Person_Records.Has_Element, Next => Villages.Person_Records.Cursor'Succ); use Person_Records_IO; begin for P in IO (Serializer) loop IO (Serializer, "id", Item.Id); IO_Partial (Serializer, Item); IO (Serializer, "request", Item.Request); IO (Serializer, "role", Item.Role); IO (Serializer, "ignore-request", Item.Ignore_Request, Default => Empty_Person.Ignore_Request); IO (Serializer, "records", Item.Records, Person_Records_Callback'Access); IO (Serializer, "commited", Item.Commited); end loop; end People_Callback; begin IO (Serializer, Name, People, People_Callback'Access); end IO; procedure IO ( Serializer : not null access Serialization.Serializer; Name : in String; Messages : in out Villages.Messages.Vector) is use Serialization; use Message_Kind_IO; use Calendar.Time_IO; procedure Messages_Callback ( Serializer : not null access Serialization.Serializer; Item : in out Message) is begin for P in IO (Serializer) loop IO (Serializer, "day", Item.Day); IO (Serializer, "time", Item.Time); IO (Serializer, "kind", Item.Kind); IO (Serializer, "subject", Item.Subject, Default => Default_Message.Subject); IO (Serializer, "target", Item.Target, Default => Default_Message.Target); IO (Serializer, "text", Item.Text, Default => Default_Message.Text); end loop; end Messages_Callback; use Villages.Messages; package Messages_IO is new Serialization.IO_List ( Cursor => Villages.Messages.Cursor, Element_Type => Message, Container_Type => Villages.Messages.Vector, Reference_Type => Villages.Messages.Reference_Type, Default => Default_Message, Has_Element => Villages.Messages.Has_Element, Next => Villages.Messages.Cursor'Succ); use Messages_IO; begin IO (Serializer, Name, Messages, Messages_Callback'Access); end IO; procedure IO ( Serializer : not null access Serialization.Serializer; Village : in out Village_Type; Info_Only : in Boolean := False) is use Serialization; use Calendar.Time_IO; use Tabula.Villages.Village_IO.Village_State_IO; use Village_Time_IO; use Vote_IO; use Execution_IO; use Attack_IO; use Vampire_Action_Set_IO; use Servant_Knowing_IO; use Person_Role_IO; use Monster_Side_IO; use Role_Appearance_IO; use Hunter_Silver_Bullet_IO; use Unfortunate_IO; use Daytime_Preview_IO; use Doctor_Infected_IO; use Formation_IO; use Obsolete_Teaming_IO; procedure IO ( Serializer : not null access Serialization.Serializer; Name : in String; Item : in out Role_Appearances) is begin for P in IO (Serializer, Name) loop for I in Village.Appearance'Range loop IO (Serializer, Person_Role'Image (I), Item (I)); end loop; end loop; end IO; begin for P in IO (Serializer) loop -- inherited IO (Serializer, "name", Village.Name); IO (Serializer, "by", Village.By, Default => Ada.Strings.Unbounded.Null_Unbounded_String); IO (Serializer, "face-group", Village.Face_Group); IO (Serializer, "face-width", Village.Face_Width); IO (Serializer, "face-height", Village.Face_Height); -- additional IO (Serializer, "state", Village.State); IO (Serializer, "today", Village.Today); IO (Serializer, "time", Village.Time); IO (Serializer, "dawn", Village.Dawn); IO (Serializer, "day-duration", Village.Day_Duration); IO (Serializer, "night-duration", Village.Night_Duration); IO (Serializer, "vote", Village.Vote, Default => Unsigned); IO (Serializer, "execution", Village.Execution, Default => From_First); IO (Serializer, "formation", Village.Formation, Default => Public); IO (Serializer, "monster-side", Village.Monster_Side, Default => Fixed); IO (Serializer, "attack", Village.Attack, Default => Two); IO (Serializer, "vampire-action-set", Village.Vampire_Action_Set, Default => Gaze); IO (Serializer, "servant-knowing", Village.Servant_Knowing, Default => None); IO (Serializer, "daytime-preview", Village.Daytime_Preview, Default => Role_And_Message); IO (Serializer, "doctor-infected", Village.Doctor_Infected, Default => Cure); IO (Serializer, "hunter-silver-bullet", Village.Hunter_Silver_Bullet, Default => Target_And_Self); IO (Serializer, "unfortunate", Village.Unfortunate, Default => None); IO (Serializer, "teaming", Village.Obsolete_Teaming); -- 記録用 if Serializer.Direction = Reading or else Village.Appearance /= Role_Appearances'(others => Random) then IO (Serializer, "appearance", Village.Appearance); end if; if Serializer.Direction = Reading or else Village.Execution = Dummy_Killed_And_From_First then IO (Serializer, "dummy-role", Village.Dummy_Role); end if; IO (Serializer, "people", Village.People); if Serializer.Direction = Reading or else not Village.Escaped_People.Is_Empty then IO (Serializer, "escaped-people", Village.Escaped_People); end if; if not Info_Only then IO (Serializer, "messages", Village.Messages); end if; end loop; end IO; end Vampire.Villages.Village_IO;
with SDL; with SDL.CPUS; with SDL.Log; with SDL.Platform; with System; use type System.Bit_Order; procedure Platform is Endian : System.Bit_Order renames System.Default_Bit_Order; begin SDL.Log.Set (Category => SDL.Log.Application, Priority => SDL.Log.Debug); SDL.Log.Put_Debug ("This system is running : " & SDL.Platform.Platforms'Image (SDL.Platform.Get)); -- Endian-ness. SDL.Log.Put_Debug ("Bit Order : " & System.Bit_Order'Image (Endian)); SDL.Log.Put_Debug ("...in other words : " & (if Endian = System.High_Order_First then "Big-endian" else "Little-endian")); -- CPU Info. SDL.Log.Put_Debug ("CPU count : " & Positive'Image (SDL.CPUS.Count)); SDL.Log.Put_Debug ("CPU cache line size : " & Positive'Image (SDL.CPUS.Cache_Line_Size)); SDL.Log.Put_Debug ("RDTSC : " & Boolean'Image (SDL.CPUS.Has_RDTSC)); SDL.Log.Put_Debug ("AltiVec : " & Boolean'Image (SDL.CPUS.Has_AltiVec)); SDL.Log.Put_Debug ("3DNow! : " & Boolean'Image (SDL.CPUS.Has_3DNow)); SDL.Log.Put_Debug ("SSE : " & Boolean'Image (SDL.CPUS.Has_SSE)); SDL.Log.Put_Debug ("SSE2 : " & Boolean'Image (SDL.CPUS.Has_SSE_2)); SDL.Log.Put_Debug ("SSE3 : " & Boolean'Image (SDL.CPUS.Has_SSE_3)); SDL.Log.Put_Debug ("SSE4.1 : " & Boolean'Image (SDL.CPUS.Has_SSE_4_1)); SDL.Log.Put_Debug ("SSE4.2 : " & Boolean'Image (SDL.CPUS.Has_SSE_4_2)); SDL.Finalise; end Platform;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S Y S T E M . S O F T _ L I N K S -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2021, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it 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. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- 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/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This is a Ravenscar bare board version of this body. Tasking version of -- these functions are always used. with System.Tasking; with System.Task_Primitives.Operations; package body System.Soft_Links is use System.Task_Primitives.Operations; use type System.Tasking.Termination_Handler; ---------------- -- Local data -- ---------------- Caller_Priority : Any_Priority; -- Task's active priority when the global lock is seized. This priority is -- restored when the task releases the global lock. ---------------------------- -- Get_Current_Excep_Soft -- ---------------------------- function Get_Current_Excep_Soft return EOA is begin return Self.Common.Compiler_Data.Current_Excep'Access; end Get_Current_Excep_Soft; ------------------------ -- Get_GNAT_Exception -- ------------------------ function Get_GNAT_Exception return Ada.Exceptions.Exception_Id is begin return Ada.Exceptions.Exception_Identity (Get_Current_Excep.all.all); end Get_GNAT_Exception; ------------------- -- Adafinal_Soft -- ------------------- procedure Adafinal_Soft is begin -- Handle normal task termination by the environment task, but only for -- the normal task termination. Abnormal termination is not supported by -- this run time, and in the case of Unhandled_Exception the last chance -- handler is invoked (which does not return). Task_Termination_Handler.all (Ada.Exceptions.Null_Occurrence); -- Here we should typically finalize all library-level controlled -- objects. However, in Ravenscar tasks (including the environment task) -- are non-terminating, so we avoid finalization. -- We used to raise a Program_Error here to signal the task termination -- event in order to avoid silent task death. It has been removed -- because the Ada.Task_Termination functionality serves the same -- purpose in a more flexible (and standard) way. In addition, this -- exception triggered a second execution of the termination handler -- (if any was installed). end Adafinal_Soft; -------------------- -- Task_Lock_Soft -- -------------------- procedure Task_Lock_Soft is Self_Id : constant System.Tasking.Task_Id := Self; begin Self_Id.Common.Global_Task_Lock_Nesting := Self_Id.Common.Global_Task_Lock_Nesting + 1; if Self_Id.Common.Global_Task_Lock_Nesting = 1 then declare Prio : constant System.Any_Priority := Get_Priority (Self_Id); begin -- Increase priority Set_Priority (Self_Id, System.Any_Priority'Last); -- Store caller's active priority so that it can be later restored -- when releasing the global lock. Caller_Priority := Prio; end; end if; end Task_Lock_Soft; --------------------------- -- Task_Termination_Soft -- --------------------------- procedure Task_Termination_Soft (Except : EO) is pragma Unreferenced (Except); Self_Id : constant System.Tasking.Task_Id := Self; TH : System.Tasking.Termination_Handler := null; begin -- Raise the priority to prevent race conditions when using -- System.Tasking.Fall_Back_Handler. Set_Priority (Self_Id, Any_Priority'Last); TH := System.Tasking.Fall_Back_Handler; -- Restore original priority after retrieving shared data Set_Priority (Self_Id, Self_Id.Common.Base_Priority); -- Execute the task termination handler if we found it if TH /= null then TH.all (Self_Id); end if; end Task_Termination_Soft; ---------------------- -- Task_Unlock_Soft -- ---------------------- procedure Task_Unlock_Soft is Self_Id : constant System.Tasking.Task_Id := Self; begin pragma Assert (Self_Id.Common.Global_Task_Lock_Nesting > 0); Self_Id.Common.Global_Task_Lock_Nesting := Self_Id.Common.Global_Task_Lock_Nesting - 1; if Self_Id.Common.Global_Task_Lock_Nesting = 0 then -- Restore the task's active priority Set_Priority (Self_Id, Caller_Priority); end if; end Task_Unlock_Soft; end System.Soft_Links;
pragma License (Unrestricted); with Ada.Numerics.Generic_Complex_Types; package Ada.Numerics.Long_Complex_Types is new Generic_Complex_Types (Long_Float); pragma Pure (Ada.Numerics.Long_Complex_Types);
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- Copyright (C) 2012-2013, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it 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. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- 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/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This file provides register definitions for the STM32F4 (ARM Cortex M4F) -- microcontrollers from ST Microelectronics. pragma Restrictions (No_Elaboration_Code); with System.Storage_Elements; package System.STM32F4 is subtype Address is System.Address; type Word is mod 2**32; type Bits_1 is mod 2**1 with Size => 1; type Bits_2 is mod 2**2 with Size => 2; type Bits_4 is mod 2**4 with Size => 4; type Bits_12 is mod 2**12 with Size => 12; type Bits_16 is mod 2**16 with Size => 16; type Bits_32x1 is array (0 .. 31) of Bits_1 with Pack, Size => 32; type Bits_16x2 is array (0 .. 15) of Bits_2 with Pack, Size => 32; type Bits_8x4 is array (0 .. 7) of Bits_4 with Pack, Size => 32; -- Define address bases for the various system components Peripheral_Base : constant := 16#4000_0000#; APB1_Peripheral_Base : constant := Peripheral_Base; APB2_Peripheral_Base : constant := Peripheral_Base + 16#0001_0000#; AHB1_Peripheral_Base : constant := Peripheral_Base + 16#0002_0000#; AHB2_Peripheral_Base : constant := Peripheral_Base + 16#1000_0000#; GPIOB_Base : constant := AHB1_Peripheral_Base + 16#0400#; FLASH_Base : constant := AHB1_Peripheral_Base + 16#3C00#; USART1_Base : constant := APB2_Peripheral_Base + 16#1000#; RCC_Base : constant := AHB1_Peripheral_Base + 16#3800#; PWR_Base : constant := APB1_Peripheral_Base + 16#7000#; --------------------------------- -- RCC Reset and Clock Control -- --------------------------------- type RCC_Registers is record CR : Word; -- RCC clock control register at 16#00# PLLCFGR : Word; -- RCC PLL configuration register at 16#04# CFGR : Word; -- RCC clock configuration register at 16#08# CIR : Word; -- RCC clock interrupt register at 16#0C# AHB1RSTR : Word; -- RCC AHB1 peripheral reset register at 16#10# AHB2RSTR : Word; -- RCC AHB2 peripheral reset register at 16#14# AHB3RSTR : Word; -- RCC AHB3 peripheral reset register at 16#18# Reserved_0 : Word; -- Reserved at 16#1C# APB1RSTR : Word; -- RCC APB1 peripheral reset register at 16#20# APB2RSTR : Word; -- RCC APB2 peripheral reset register at 16#24# Reserved_1 : Word; -- Reserved at 16#28# Reserved_2 : Word; -- Reserved at 16#2c# AHB1ENR : Word; -- RCC AHB1 peripheral clock register at 16#30# AHB2ENR : Word; -- RCC AHB2 peripheral clock register at 16#34# AHB3ENR : Word; -- RCC AHB3 peripheral clock register at 16#38# Reserved_3 : Word; -- Reserved at 16#0C# APB1ENR : Word; -- RCC APB1 peripheral clock enable at 16#40# APB2ENR : Word; -- RCC APB2 peripheral clock enable at 16#44# Reserved_4 : Word; -- Reserved at 16#48# Reserved_5 : Word; -- Reserved at 16#4c# AHB1LPENR : Word; -- RCC AHB1 periph. low power clk en. at 16#50# AHB2LPENR : Word; -- RCC AHB2 periph. low power clk en. at 16#54# AHB3LPENR : Word; -- RCC AHB3 periph. low power clk en. at 16#58# Reserved_6 : Word; -- Reserved, 16#5C# APB1LPENR : Word; -- RCC APB1 periph. low power clk en. at 16#60# APB2LPENR : Word; -- RCC APB2 periph. low power clk en. at 16#64# Reserved_7 : Word; -- Reserved at 16#68# Reserved_8 : Word; -- Reserved at 16#6C# BDCR : Word; -- RCC Backup domain control register at 16#70# CSR : Word; -- RCC clock control/status register at 16#74# Reserved_9 : Word; -- Reserved at 16#78# Reserved_10 : Word; -- Reserved at 16#7C# SSCGR : Word; -- RCC spread spectrum clk gen. reg. at 16#80# PLLI2SCFGR : Word; -- RCC PLLI2S configuration register at 16#84# end record; RCC : RCC_Registers with Volatile, Address => System'To_Address (RCC_Base); package RCC_CR is -- Constants for RCC CR register HSION : constant Word := 2**0; -- Internal high-speed clock enable HSIRDY : constant Word := 2**1; -- Internal high-speed clock ready HSEON : constant Word := 2**16; -- External high-speed clock enable HSERDY : constant Word := 2**17; -- External high-speed clock ready HSEBYP : constant Word := 2**18; -- External HS clk. resonator bypass CSSON : constant Word := 2**19; -- Clock security system enable PLLON : constant Word := 2**24; -- Main PLL enable PLLRDY : constant Word := 2**25; -- Main PLL ready PLLI2SON : constant Word := 2**26; -- Main PLL enable PLLI2SRDY : constant Word := 2**27; -- Main PLL ready end RCC_CR; PLLSRC_HSE : constant := 2**22; -- PLL source clock is HSE package RCC_CFGR is -- Constants for RCC CFGR register -- AHB prescaler HPRE_DIV1 : constant Word := 16#00#; -- AHB is SYSCLK HPRE_DIV2 : constant Word := 16#80#; -- AHB is SYSCLK / 2 HPRE_DIV4 : constant Word := 16#90#; -- AHB is SYSCLK / 4 HPRE_DIV8 : constant Word := 16#A0#; -- AHB is SYSCLK / 8 HPRE_DIV16 : constant Word := 16#B0#; -- AHB is SYSCLK / 16 HPRE_DIV64 : constant Word := 16#C0#; -- AHB is SYSCLK / 64 HPRE_DIV128 : constant Word := 16#D0#; -- AHB is SYSCLK / 128 HPRE_DIV256 : constant Word := 16#E0#; -- AHB is SYSCLK / 256 HPRE_DIV512 : constant Word := 16#F0#; -- AHB is SYSCLK / 512 -- APB1 prescaler PPRE1_DIV1 : constant Word := 16#0000#; -- APB1 is HCLK / 1 PPRE1_DIV2 : constant Word := 16#1000#; -- APB1 is HCLK / 2 PPRE1_DIV4 : constant Word := 16#1400#; -- APB1 is HCLK / 4 PPRE1_DIV8 : constant Word := 16#1800#; -- APB1 is HCLK / 8 PPRE1_DIV16 : constant Word := 16#1C00#; -- APB1 is HCLK / 16 -- APB2 prescaler PPRE2_DIV1 : constant Word := 16#0000#; -- APB2 is HCLK / 1 PPRE2_DIV2 : constant Word := 16#8000#; -- APB2 is HCLK / 2 PPRE2_DIV4 : constant Word := 16#A000#; -- APB2 is HCLK / 4 PPRE2_DIV8 : constant Word := 16#C000#; -- APB2 is HCLK / 8 PPRE2_DIV16 : constant Word := 16#E000#; -- APB2 is HCLK / 16 -- MCO1 clock selector MCO1SEL_HSI : constant Word := 0 * 2**21; -- HSI clock on MC01 pin MCO1SEL_LSE : constant Word := 1 * 2**21; -- LSE clock on MC01 pin MCO1SEL_HSE : constant Word := 2 * 2**21; -- HSE clock on MC01 pin MCO1SEL_PLL : constant Word := 3 * 2**21; -- PLL clock on MC01 pin -- MCO1 prescaler MCO1PRE_DIV1 : constant Word := 0 * 2**24; -- MC01 divides by 1 MCO1PRE_DIV2 : constant Word := 4 * 2**24; -- MC01 divides by 2 MCO1PRE_DIV3 : constant Word := 5 * 2**24; -- MC01 divides by 3 MCO1PRE_DIV4 : constant Word := 6 * 2**24; -- MC01 divides by 4 MCO1PRE_DIV5 : constant Word := 7 * 2**24; -- MC01 divides by 5 -- MCO2 clock selector MCO2SEL_SYSCLK : constant Word := 0 * 2**30; -- SYSCLK clock on MCO2 pin MCO2SEL_PLLI2S : constant Word := 1 * 2**30; -- SYSCLK clock on MCO2 pin MCO2SEL_HSE : constant Word := 2 * 2**30; -- SYSCLK clock on MCO2 pin MCO2SEL_PLL : constant Word := 3 * 2**30; -- SYSCLK clock on MCO2 pin -- MCO2 prescaler MCO2PRE_DIV1 : constant Word := 0 * 2**27; -- MCO2 divides by 1 MCO2PRE_DIV2 : constant Word := 4 * 2**27; -- MCO2 divides by 4 MCO2PRE_DIV3 : constant Word := 5 * 2**27; -- MCO2 divides by 5 MCO2PRE_DIV4 : constant Word := 6 * 2**27; -- MCO2 divides by 6 MCO2PRE_DIV5 : constant Word := 7 * 2**27; -- MCO2 divides by 7 -- I2S clock source I2SSRC_PLLI2S : constant Word := 0 * 2**23; -- I2SSRC is PLLI2S I2SSRC_PCKIN : constant Word := 1 * 2**23; -- I2SSRC is I2S_CKIN -- System clock switch SW_HSI : constant Word := 16#0#; -- HSI selected as system clock SW_HSE : constant Word := 16#1#; -- HSI selected as system clock SW_PLL : constant Word := 16#2#; -- PLL selected as system clock -- System clock switch status SWS_HSI : constant Word := 16#0#; -- HSI used as system clock SWS_HSE : constant Word := 16#4#; -- HSI used as system clock SWS_PLL : constant Word := 16#8#; -- PLL used as system clock end RCC_CFGR; package RCC_CSR is -- Constants for RCC CR register LSION : constant Word := 2**0; -- Int. low-speed clock enable LSIRDY : constant Word := 2**1; -- Int. low-speed clock enable end RCC_CSR; -- Bit definitions for RCC APB1ENR register RCC_APB1ENR_PWR : constant Word := 16#1000_0000#; -- Bit definitions for RCC APB2ENR register RCC_APB2ENR_USART1 : constant Word := 16#10#; -- Bit definitions for RCC AHB1ENR register RCC_AHB1ENR_GPIOB : constant Word := 16#02#; --------- -- PWR -- --------- type PWR_Registers is record CR : Word; -- PWR power control register at 16#00# CSR : Word; -- PWR power control/status register at 16#04# end record; PWR : PWR_Registers with Volatile, Import, Address => System'To_Address (PWR_Base); PWR_CR_VOS_HIGH_407 : constant Word := 16#4000#; -- Core voltage set to high PWR_CR_VOS_HIGH_429 : constant Word := 16#C000#; -- Core voltage set to high PWR_CSR_VOSRDY : constant Word := 2**14; -- Regulator output ready --------------- -- FLASH_ACR -- --------------- package FLASH_ACR is -- Constants for FLASH ACR register -- Wait states LATENCY_0WS : constant Word := 16#0#; LATENCY_1WS : constant Word := 16#1#; LATENCY_2WS : constant Word := 16#2#; LATENCY_3WS : constant Word := 16#3#; LATENCY_4WS : constant Word := 16#4#; LATENCY_5WS : constant Word := 16#5#; LATENCY_6WS : constant Word := 16#6#; LATENCY_7WS : constant Word := 16#7#; PRFTEN : constant Word := 16#01_00#; -- Preftech enable ICEN : constant Word := 16#02_00#; -- Instruction cache enable DCEN : constant Word := 16#04_00#; -- Data cache enable ICRST : constant Word := 16#08_00#; -- Instruction cache reset DCRST : constant Word := 16#10_00#; -- Data cache reset end FLASH_ACR; type FLASH_Registers is record ACR : Word; KEYR : Word; OPTKEYR : Word; SR : Word; CR : Word; OPTCR : Word; end record; FLASH : FLASH_Registers with Volatile, Address => System'To_Address (FLASH_Base); pragma Import (Ada, FLASH); ---------- -- GPIO -- ---------- package GPIO is -- MODER constants Mode_IN : constant Bits_2 := 0; Mode_OUT : constant Bits_2 := 1; Mode_AF : constant Bits_2 := 2; Mode_AN : constant Bits_2 := 3; -- OTYPER constants Type_PP : constant Bits_1 := 0; -- Push/pull Type_OD : constant Bits_1 := 1; -- Open drain -- OSPEEDR constants Speed_2MHz : constant Bits_2 := 0; -- Low speed Speed_25MHz : constant Bits_2 := 1; -- Medium speed Speed_50MHz : constant Bits_2 := 2; -- Fast speed Speed_100MHz : constant Bits_2 := 3; -- High speed on 30pF, 80MHz on 15 -- PUPDR constants No_Pull : constant Bits_2 := 0; Pull_Up : constant Bits_2 := 1; Pull_Down : constant Bits_2 := 2; -- AFL constants AF_USART1 : constant Bits_4 := 7; end GPIO; type GPIO_Registers is record MODER : Bits_16x2; OTYPER : Bits_32x1; OSPEEDR : Bits_16x2; PUPDR : Bits_16x2; IDR : Word; ODR : Word; BSRR : Word; LCKR : Word; AFRL : Bits_8x4; AFRH : Bits_8x4; end record; GPIOB : GPIO_Registers with Volatile, Address => System'To_Address (GPIOB_Base); pragma Import (Ada, GPIOB); ----------- -- USART -- ----------- package USART is -- Bit definitions for USART CR1 register CR1_SBK : constant Bits_16 := 16#0001#; -- Send Break CR1_RWU : constant Bits_16 := 16#0002#; -- Receiver Wakeup CR1_RE : constant Bits_16 := 16#0004#; -- Receiver Enable CR1_TE : constant Bits_16 := 16#0008#; -- Transmitter Enable CR1_IDLEIE : constant Bits_16 := 16#0010#; -- IDLE Interrupt Enable CR1_RXNEIE : constant Bits_16 := 16#0020#; -- RXNE Interrupt Enable CR1_TCIE : constant Bits_16 := 16#0040#; -- Xfer Complete Int. Ena. CR1_TXEIE : constant Bits_16 := 16#0080#; -- PE Interrupt Enable CR1_PEIE : constant Bits_16 := 16#0100#; -- PE Interrupt Enable CR1_PS : constant Bits_16 := 16#0200#; -- Parity Selection CR1_PCE : constant Bits_16 := 16#0400#; -- Parity Control Enable CR1_WAKE : constant Bits_16 := 16#0800#; -- Wakeup Method CR1_M : constant Bits_16 := 16#1000#; -- Word Length CR1_UE : constant Bits_16 := 16#2000#; -- USART Enable CR1_OVER8 : constant Bits_16 := 16#8000#; -- Oversampling by 8 Enable -- Bit definitions for USART CR2 register CR2_ADD : constant Bits_16 := 16#000F#; -- Address of USART Node CR2_LBDL : constant Bits_16 := 16#0020#; -- LIN Brk Detection Length CR2_LBDIE : constant Bits_16 := 16#0040#; -- LIN Brk Det. Int. Enable CR2_LBCL : constant Bits_16 := 16#0100#; -- Last Bit Clock pulse CR2_CPHA : constant Bits_16 := 16#0200#; -- Clock Phase CR2_CPOL : constant Bits_16 := 16#0400#; -- Clock Polarity CR2_CLKEN : constant Bits_16 := 16#0800#; -- Clock Enable CR2_STOP : constant Bits_16 := 16#3000#; -- STOP bits CR2_STOP_0 : constant Bits_16 := 16#1000#; -- Bit 0 CR2_STOP_1 : constant Bits_16 := 16#2000#; -- Bit 1 CR2_LINEN : constant Bits_16 := 16#4000#; -- LIN mode enable -- Bit definitions for USART CR3 register CR3_EIE : constant Bits_16 := 16#0001#; -- Error Interrupt Enable CR3_IREN : constant Bits_16 := 16#0002#; -- IrDA mode Enable CR3_IRLP : constant Bits_16 := 16#0004#; -- IrDA Low-Power CR3_HDSEL : constant Bits_16 := 16#0008#; -- Half-Duplex Selection CR3_NACK : constant Bits_16 := 16#0010#; -- Smartcard NACK enable CR3_SCEN : constant Bits_16 := 16#0020#; -- Smartcard mode enable CR3_DMAR : constant Bits_16 := 16#0040#; -- DMA Enable Receiver CR3_DMAT : constant Bits_16 := 16#0080#; -- DMA Enable Transmitter CR3_RTSE : constant Bits_16 := 16#0100#; -- RTS Enable CR3_CTSE : constant Bits_16 := 16#0200#; -- CTS Enable CR3_CTSIE : constant Bits_16 := 16#0400#; -- CTS Interrupt Enable CR3_ONEBIT : constant Bits_16 := 16#0800#; -- One bit method enable end USART; type USART_Registers is record SR : Bits_16; -- USART Status register Reserved_0 : Bits_16; DR : Bits_16; -- USART Data register Reserved_1 : Bits_16; BRR : Bits_16; -- USART Baud rate register Reserved_2 : Bits_16; CR1 : Bits_16; -- USART Control register 1 Reserved_3 : Bits_16; CR2 : Bits_16; -- USART Control register 2 Reserved_4 : Bits_16; CR3 : Bits_16; -- USART Control register 3 Reserved_5 : Bits_16; GTPR : Bits_16; -- USART Guard time and prescaler register Reserved_6 : Bits_16; end record; USART1 : USART_Registers with Volatile, Address => System'To_Address (USART1_Base); type MCU_ID_Register is record DEV_ID : Bits_12; Reserved : Bits_4; REV_ID : Bits_16; end record with Pack, Size => 32; MCU_ID : MCU_ID_Register with Volatile, Address => System'To_Address (16#E004_2000#); -- Only 32-bits access supported (read-only) DEV_ID_STM32F405xx : constant := 16#413#; DEV_ID_STM32F407xx : constant := 16#413#; DEV_ID_STM32F42xxx : constant := 16#419#; DEV_ID_STM32F43xxx : constant := 16#419#; end System.STM32F4;
with Nanomsg.Socket; with Ada.Containers.Ordered_Maps; package Nanomsg.Socket_Pools is type Pool_T is tagged private; procedure Add_Socket (Self : in out Pool_T; Socket : in Nanomsg.Socket.Socket_T); procedure Remove_Socket (Self : in out Pool_T; Socket : in Nanomsg.Socket.Socket_T); function Has_Socket (Self : in Pool_T; Socket : in Nanomsg.Socket.Socket_T) return Boolean; function Has_Message (Self : in Pool_T) return Pool_T; function Ready_To_Receive (Self : in Pool_T) return Pool_T renames Has_Message; function Ready_To_Send (Self : in Pool_T) return Pool_T; function Ready_To_Send_Receive (Self : in Pool_T) return Pool_T; private package Pool_Container_P is new Ada.Containers.Ordered_Maps (Element_Type => Nanomsg.Socket.Socket_T, "=" => Nanomsg.Socket."=", Key_Type => Natural); subtype Pool_Container_T is Pool_Container_P.Map; type Pool_T is tagged record Pool : Pool_Container_T; end record; end Nanomsg.Socket_Pools;
pragma Ada_2012; with AWS.Resources.Streams.Memory; with GNAT.Semaphores; with System; with Ada.Finalization; package AWS.Resources.Streams.Pipes is use AWS.Resources.Streams.Memory; type Stream_Type is new Streams.Memory.Stream_Type with private; procedure Append (Resource : in out Stream_Type; Buffer : Stream_Element_Array; Trim : Boolean := False); -- Append Buffer into the memory stream procedure Append (Resource : in out Stream_Type; Buffer : Stream_Element_Access); -- Append static data pointed to Buffer into the memory stream as is. -- The stream will free the memory on close. procedure Append (Resource : in out Stream_Type; Buffer : Buffer_Access); -- Append static data pointed to Buffer into the memory stream as is. -- The stream would not try to free the memory on close. overriding procedure Read (Resource : in out Stream_Type; Buffer : out Stream_Element_Array; Last : out Stream_Element_Offset); -- Returns a chunck of data in Buffer, Last point to the last element -- returned in Buffer. overriding function End_Of_File (Resource : Stream_Type) return Boolean; -- Returns True if the end of the memory stream has been reached procedure Clear (Resource : in out Stream_Type); -- Delete all data from memory stream overriding procedure Reset (Resource : in out Stream_Type) is null; -- Reset the streaming data to the first position overriding procedure Set_Index (Resource : in out Stream_Type; To : Stream_Element_Offset) is null; -- Set the position in the stream, next Read will start at the position -- whose index is To. overriding function Size (Resource : Stream_Type) return Stream_Element_Offset is (0); -- Returns the number of bytes in the memory stream overriding procedure Close (Resource : in out Stream_Type); -- Close the memory stream. Release all memory associated with the stream private type Stream_Type is new Streams.Memory.Stream_Type with record Guard : aliased GNAT.Semaphores.Binary_Semaphore (True, System.Default_Priority); Is_Open : Boolean := True; Has_Write : Boolean := False with Atomic; Has_Read : Boolean := False with Atomic; end record; type Lock_Type (Guard : not null access GNAT.Semaphores.Binary_Semaphore) is new Ada.Finalization.Limited_Controlled with null record with Unreferenced_Objects => True; procedure Initialize (Object : in out Lock_Type); procedure Finalize (Object : in out Lock_Type); end AWS.Resources.Streams.Pipes;