content
stringlengths 23
1.05M
|
|---|
package body Construct_Conversion_Array with
SPARK_Mode
is
----------------------
-- Conversion_Array --
----------------------
function Conversion_Array return Conversion_Array_Type is
Conversion_Array : Conversion_Array_Type := (others => Zero);
begin
for J in Product_Index_Type loop
Conversion_Array (J) := Two_Power (Exposant (J));
pragma Loop_Invariant (for all K in 0 .. J => Conversion_Array (K) = Two_Power (Exposant (K)));
end loop;
Prove_Property (Conversion_Array);
return Conversion_Array;
end Conversion_Array;
--------------------
-- Prove_Property --
--------------------
procedure Prove_Property (Conversion_Array : Conversion_Array_Type) is
begin
for J in Index_Type loop
for K in Index_Type loop
Exposant_Lemma (J, K); -- The two lemmas will help solvers
Two_Power_Lemma (Exposant (J), Exposant (K)); -- to prove the following code.
pragma Assert (Two_Power (Exposant (J)) = Conversion_Array (J)
and then Two_Power (Exposant (K)) = Conversion_Array (K)
and then Two_Power (Exposant (J + K)) = Conversion_Array (J + K));
-- A reminder of the precondition
-- The following code will split the two different cases of
-- Property. In the statements, assertions are used to guide
-- provers to the goal.
if J mod 2 = 1 and then K mod 2 = 1 then
pragma Assert (Exposant (J + K) + 1 = Exposant (J) + Exposant (K));
pragma Assert (Two_Power (Exposant (J + K) + 1)
= Two_Power (Exposant (J)) * Two_Power (Exposant (K)));
pragma Assert (Two_Power (Exposant (J + K)) * (+2)
= Two_Power (Exposant (J)) * Two_Power (Exposant (K)));
pragma Assert (Property (Conversion_Array, J, K));
else
pragma Assert (Exposant (J + K) = Exposant (J) + Exposant (K));
pragma Assert (Two_Power (Exposant (J + K)) = Two_Power (Exposant (J)) * Two_Power (Exposant (K)));
pragma Assert (Property (Conversion_Array, J, K));
end if;
pragma Loop_Invariant (for all M in 0 .. K =>
Property (Conversion_Array, J, M));
end loop;
pragma Loop_Invariant (for all L in 0 .. J =>
(for all M in Index_Type =>
Property (Conversion_Array, L, M)));
end loop;
end Prove_Property;
end Construct_Conversion_Array;
|
pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with processor_hpp;
with memory_hpp;
with lcd_hpp;
with timer_handler_hpp;
with Interfaces.C.Extensions;
with word_operations_hpp;
package gameboy_hpp is
package Class_Gameboy is
type Gameboy is limited record
p : aliased processor_hpp.Class_Processor.Processor; -- gameboy.hpp:43
mem : aliased memory_hpp.Class_Memory.Memory; -- gameboy.hpp:44
the_lcd : aliased lcd_hpp.Class_LCD.LCD; -- gameboy.hpp:45
timers : aliased timer_handler_hpp.Class_TimerHandler.TimerHandler; -- gameboy.hpp:46
running : aliased Extensions.bool; -- gameboy.hpp:48
keys : aliased word_operations_hpp.uint8_t; -- gameboy.hpp:49
end record;
pragma Import (CPP, Gameboy);
function New_Gameboy return Gameboy; -- gameboy.hpp:18
pragma CPP_Constructor (New_Gameboy, "_ZN7GameboyC1Ev");
procedure step (this : access Gameboy; s : access unsigned_char); -- gameboy.hpp:21
pragma Import (CPP, step, "_ZN7Gameboy4stepEPh");
procedure changeGame (this : access Gameboy; game : access word_operations_hpp.uint8_t); -- gameboy.hpp:23
pragma Import (CPP, changeGame, "_ZN7Gameboy10changeGameEPh");
function isRunning (this : access Gameboy) return Extensions.bool; -- gameboy.hpp:25
pragma Import (CPP, isRunning, "_ZN7Gameboy9isRunningEv");
procedure stop (this : access Gameboy); -- gameboy.hpp:26
pragma Import (CPP, stop, "_ZN7Gameboy4stopEv");
function readyToLaunch (this : access Gameboy) return Extensions.bool; -- gameboy.hpp:30
pragma Import (CPP, readyToLaunch, "_ZN7Gameboy13readyToLaunchEv");
procedure setKeys (this : access Gameboy; value : word_operations_hpp.uint8_t); -- gameboy.hpp:34
pragma Import (CPP, setKeys, "_ZN7Gameboy7setKeysEh");
procedure setJoypadInterrupt (this : access Gameboy); -- gameboy.hpp:36
pragma Import (CPP, setJoypadInterrupt, "_ZN7Gameboy18setJoypadInterruptEv");
procedure wireComponents (this : access Gameboy); -- gameboy.hpp:38
pragma Import (CPP, wireComponents, "_ZN7Gameboy14wireComponentsEv");
procedure clockCycle (this : access Gameboy); -- gameboy.hpp:39
pragma Import (CPP, clockCycle, "_ZN7Gameboy10clockCycleEv");
procedure checkKeys (this : access Gameboy; atomic : word_operations_hpp.uint8_t); -- gameboy.hpp:40
pragma Import (CPP, checkKeys, "_ZN7Gameboy9checkKeysEh");
procedure interruptJOYPAD (this : access Gameboy); -- gameboy.hpp:41
pragma Import (CPP, interruptJOYPAD, "_ZN7Gameboy15interruptJOYPADEv");
end;
use Class_Gameboy;
end gameboy_hpp;
|
procedure @_Main_Name_@ is
begin
-- Insert code here.
null;
end @_Main_Name_@;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- ADA.STRINGS.TEXT_OUTPUT.FORMATTING --
-- --
-- S p e c --
-- --
-- Copyright (C) 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. --
-- --
------------------------------------------------------------------------------
package Ada.Strings.Text_Output.Formatting is
-- Template-based output, based loosely on C's printf family. Unlike
-- printf, it is type safe. We don't support myriad formatting options; the
-- caller is expected to call 'Image, or other functions that might have
-- various formatting capabilities.
--
-- Each of the following calls Flush
type Template is new UTF_8;
procedure Put
(S : in out Sink'Class; T : Template;
X1, X2, X3, X4, X5, X6, X7, X8, X9 : UTF_8_Lines := "");
-- Prints the template as is, except for the following escape sequences:
-- "\n" is end of line.
-- "\i" indents by the default amount, and "\o" outdents.
-- "\I" indents by one space, and "\O" outdents.
-- "\1" is replaced with X1, and similarly for 2, 3, ....
-- "\\" is "\".
-- Note that the template is not type String, to avoid this sort of thing:
--
-- https://xkcd.com/327/
procedure Put
(T : Template;
X1, X2, X3, X4, X5, X6, X7, X8, X9 : UTF_8_Lines := "");
-- Sends to standard output
procedure Err
(T : Template;
X1, X2, X3, X4, X5, X6, X7, X8, X9 : UTF_8_Lines := "");
-- Sends to standard error
function Format
(T : Template;
X1, X2, X3, X4, X5, X6, X7, X8, X9 : UTF_8_Lines := "")
return UTF_8_Lines;
-- Returns a UTF-8-encoded String
end Ada.Strings.Text_Output.Formatting;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- ADA.CONTAINERS.BOUNDED_MULTIWAY_TREES --
-- --
-- B o d y --
-- --
-- Copyright (C) 2011-2019, 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/>. --
-- --
-- This unit was originally developed by Matthew J Heaney. --
------------------------------------------------------------------------------
with Ada.Finalization;
with System; use type System.Address;
package body Ada.Containers.Bounded_Multiway_Trees is
pragma Warnings (Off, "variable ""Busy*"" is not referenced");
pragma Warnings (Off, "variable ""Lock*"" is not referenced");
-- See comment in Ada.Containers.Helpers
use Finalization;
--------------------
-- Root_Iterator --
--------------------
type Root_Iterator is abstract new Limited_Controlled and
Tree_Iterator_Interfaces.Forward_Iterator with
record
Container : Tree_Access;
Subtree : Count_Type;
end record;
overriding procedure Finalize (Object : in out Root_Iterator);
-----------------------
-- Subtree_Iterator --
-----------------------
type Subtree_Iterator is new Root_Iterator with null record;
overriding function First (Object : Subtree_Iterator) return Cursor;
overriding function Next
(Object : Subtree_Iterator;
Position : Cursor) return Cursor;
---------------------
-- Child_Iterator --
---------------------
type Child_Iterator is new Root_Iterator and
Tree_Iterator_Interfaces.Reversible_Iterator with null record;
overriding function First (Object : Child_Iterator) return Cursor;
overriding function Next
(Object : Child_Iterator;
Position : Cursor) return Cursor;
overriding function Last (Object : Child_Iterator) return Cursor;
overriding function Previous
(Object : Child_Iterator;
Position : Cursor) return Cursor;
-----------------------
-- Local Subprograms --
-----------------------
procedure Initialize_Node (Container : in out Tree; Index : Count_Type);
procedure Initialize_Root (Container : in out Tree);
procedure Allocate_Node
(Container : in out Tree;
Initialize_Element : not null access procedure (Index : Count_Type);
New_Node : out Count_Type);
procedure Allocate_Node
(Container : in out Tree;
New_Item : Element_Type;
New_Node : out Count_Type);
procedure Allocate_Node
(Container : in out Tree;
Stream : not null access Root_Stream_Type'Class;
New_Node : out Count_Type);
procedure Deallocate_Node
(Container : in out Tree;
X : Count_Type);
procedure Deallocate_Children
(Container : in out Tree;
Subtree : Count_Type;
Count : in out Count_Type);
procedure Deallocate_Subtree
(Container : in out Tree;
Subtree : Count_Type;
Count : in out Count_Type);
function Equal_Children
(Left_Tree : Tree;
Left_Subtree : Count_Type;
Right_Tree : Tree;
Right_Subtree : Count_Type) return Boolean;
function Equal_Subtree
(Left_Tree : Tree;
Left_Subtree : Count_Type;
Right_Tree : Tree;
Right_Subtree : Count_Type) return Boolean;
procedure Iterate_Children
(Container : Tree;
Subtree : Count_Type;
Process : not null access procedure (Position : Cursor));
procedure Iterate_Subtree
(Container : Tree;
Subtree : Count_Type;
Process : not null access procedure (Position : Cursor));
procedure Copy_Children
(Source : Tree;
Source_Parent : Count_Type;
Target : in out Tree;
Target_Parent : Count_Type;
Count : in out Count_Type);
procedure Copy_Subtree
(Source : Tree;
Source_Subtree : Count_Type;
Target : in out Tree;
Target_Parent : Count_Type;
Target_Subtree : out Count_Type;
Count : in out Count_Type);
function Find_In_Children
(Container : Tree;
Subtree : Count_Type;
Item : Element_Type) return Count_Type;
function Find_In_Subtree
(Container : Tree;
Subtree : Count_Type;
Item : Element_Type) return Count_Type;
function Child_Count
(Container : Tree;
Parent : Count_Type) return Count_Type;
function Subtree_Node_Count
(Container : Tree;
Subtree : Count_Type) return Count_Type;
function Is_Reachable
(Container : Tree;
From, To : Count_Type) return Boolean;
function Root_Node (Container : Tree) return Count_Type;
procedure Remove_Subtree
(Container : in out Tree;
Subtree : Count_Type);
procedure Insert_Subtree_Node
(Container : in out Tree;
Subtree : Count_Type'Base;
Parent : Count_Type;
Before : Count_Type'Base);
procedure Insert_Subtree_List
(Container : in out Tree;
First : Count_Type'Base;
Last : Count_Type'Base;
Parent : Count_Type;
Before : Count_Type'Base);
procedure Splice_Children
(Container : in out Tree;
Target_Parent : Count_Type;
Before : Count_Type'Base;
Source_Parent : Count_Type);
procedure Splice_Children
(Target : in out Tree;
Target_Parent : Count_Type;
Before : Count_Type'Base;
Source : in out Tree;
Source_Parent : Count_Type);
procedure Splice_Subtree
(Target : in out Tree;
Parent : Count_Type;
Before : Count_Type'Base;
Source : in out Tree;
Position : in out Count_Type); -- source on input, target on output
---------
-- "=" --
---------
function "=" (Left, Right : Tree) return Boolean is
begin
if Left.Count /= Right.Count then
return False;
end if;
if Left.Count = 0 then
return True;
end if;
return Equal_Children
(Left_Tree => Left,
Left_Subtree => Root_Node (Left),
Right_Tree => Right,
Right_Subtree => Root_Node (Right));
end "=";
-------------------
-- Allocate_Node --
-------------------
procedure Allocate_Node
(Container : in out Tree;
Initialize_Element : not null access procedure (Index : Count_Type);
New_Node : out Count_Type)
is
begin
if Container.Free >= 0 then
New_Node := Container.Free;
pragma Assert (New_Node in Container.Elements'Range);
-- We always perform the assignment first, before we change container
-- state, in order to defend against exceptions duration assignment.
Initialize_Element (New_Node);
Container.Free := Container.Nodes (New_Node).Next;
else
-- A negative free store value means that the links of the nodes in
-- the free store have not been initialized. In this case, the nodes
-- are physically contiguous in the array, starting at the index that
-- is the absolute value of the Container.Free, and continuing until
-- the end of the array (Nodes'Last).
New_Node := abs Container.Free;
pragma Assert (New_Node in Container.Elements'Range);
-- As above, we perform this assignment first, before modifying any
-- container state.
Initialize_Element (New_Node);
Container.Free := Container.Free - 1;
if abs Container.Free > Container.Capacity then
Container.Free := 0;
end if;
end if;
Initialize_Node (Container, New_Node);
end Allocate_Node;
procedure Allocate_Node
(Container : in out Tree;
New_Item : Element_Type;
New_Node : out Count_Type)
is
procedure Initialize_Element (Index : Count_Type);
procedure Initialize_Element (Index : Count_Type) is
begin
Container.Elements (Index) := New_Item;
end Initialize_Element;
begin
Allocate_Node (Container, Initialize_Element'Access, New_Node);
end Allocate_Node;
procedure Allocate_Node
(Container : in out Tree;
Stream : not null access Root_Stream_Type'Class;
New_Node : out Count_Type)
is
procedure Initialize_Element (Index : Count_Type);
procedure Initialize_Element (Index : Count_Type) is
begin
Element_Type'Read (Stream, Container.Elements (Index));
end Initialize_Element;
begin
Allocate_Node (Container, Initialize_Element'Access, New_Node);
end Allocate_Node;
-------------------
-- Ancestor_Find --
-------------------
function Ancestor_Find
(Position : Cursor;
Item : Element_Type) return Cursor
is
R, N : Count_Type;
begin
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
-- AI-0136 says to raise PE if Position equals the root node. This does
-- not seem correct, as this value is just the limiting condition of the
-- search. For now we omit this check, pending a ruling from the ARG.
-- ???
--
-- if Checks and then Is_Root (Position) then
-- raise Program_Error with "Position cursor designates root";
-- end if;
R := Root_Node (Position.Container.all);
N := Position.Node;
while N /= R loop
if Position.Container.Elements (N) = Item then
return Cursor'(Position.Container, N);
end if;
N := Position.Container.Nodes (N).Parent;
end loop;
return No_Element;
end Ancestor_Find;
------------------
-- Append_Child --
------------------
procedure Append_Child
(Container : in out Tree;
Parent : Cursor;
New_Item : Element_Type;
Count : Count_Type := 1)
is
Nodes : Tree_Node_Array renames Container.Nodes;
First, Last : Count_Type;
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Checks and then Parent.Container /= Container'Unrestricted_Access then
raise Program_Error with "Parent cursor not in container";
end if;
if Count = 0 then
return;
end if;
if Checks and then Container.Count > Container.Capacity - Count then
raise Capacity_Error
with "requested count exceeds available storage";
end if;
TC_Check (Container.TC);
if Container.Count = 0 then
Initialize_Root (Container);
end if;
Allocate_Node (Container, New_Item, First);
Nodes (First).Parent := Parent.Node;
Last := First;
for J in Count_Type'(2) .. Count loop
Allocate_Node (Container, New_Item, Nodes (Last).Next);
Nodes (Nodes (Last).Next).Parent := Parent.Node;
Nodes (Nodes (Last).Next).Prev := Last;
Last := Nodes (Last).Next;
end loop;
Insert_Subtree_List
(Container => Container,
First => First,
Last => Last,
Parent => Parent.Node,
Before => No_Node); -- means "insert at end of list"
Container.Count := Container.Count + Count;
end Append_Child;
------------
-- Assign --
------------
procedure Assign (Target : in out Tree; Source : Tree) is
Target_Count : Count_Type;
begin
if Target'Address = Source'Address then
return;
end if;
if Checks and then Target.Capacity < Source.Count then
raise Capacity_Error -- ???
with "Target capacity is less than Source count";
end if;
Target.Clear; -- Checks busy bit
if Source.Count = 0 then
return;
end if;
Initialize_Root (Target);
-- Copy_Children returns the number of nodes that it allocates, but it
-- does this by incrementing the count value passed in, so we must
-- initialize the count before calling Copy_Children.
Target_Count := 0;
Copy_Children
(Source => Source,
Source_Parent => Root_Node (Source),
Target => Target,
Target_Parent => Root_Node (Target),
Count => Target_Count);
pragma Assert (Target_Count = Source.Count);
Target.Count := Source.Count;
end Assign;
-----------------
-- Child_Count --
-----------------
function Child_Count (Parent : Cursor) return Count_Type is
begin
if Parent = No_Element then
return 0;
elsif Parent.Container.Count = 0 then
pragma Assert (Is_Root (Parent));
return 0;
else
return Child_Count (Parent.Container.all, Parent.Node);
end if;
end Child_Count;
function Child_Count
(Container : Tree;
Parent : Count_Type) return Count_Type
is
NN : Tree_Node_Array renames Container.Nodes;
CC : Children_Type renames NN (Parent).Children;
Result : Count_Type;
Node : Count_Type'Base;
begin
Result := 0;
Node := CC.First;
while Node > 0 loop
Result := Result + 1;
Node := NN (Node).Next;
end loop;
return Result;
end Child_Count;
-----------------
-- Child_Depth --
-----------------
function Child_Depth (Parent, Child : Cursor) return Count_Type is
Result : Count_Type;
N : Count_Type'Base;
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Checks and then Child = No_Element then
raise Constraint_Error with "Child cursor has no element";
end if;
if Checks and then Parent.Container /= Child.Container then
raise Program_Error with "Parent and Child in different containers";
end if;
if Parent.Container.Count = 0 then
pragma Assert (Is_Root (Parent));
pragma Assert (Child = Parent);
return 0;
end if;
Result := 0;
N := Child.Node;
while N /= Parent.Node loop
Result := Result + 1;
N := Parent.Container.Nodes (N).Parent;
if Checks and then N < 0 then
raise Program_Error with "Parent is not ancestor of Child";
end if;
end loop;
return Result;
end Child_Depth;
-----------
-- Clear --
-----------
procedure Clear (Container : in out Tree) is
Container_Count : constant Count_Type := Container.Count;
Count : Count_Type;
begin
TC_Check (Container.TC);
if Container_Count = 0 then
return;
end if;
Container.Count := 0;
-- Deallocate_Children returns the number of nodes that it deallocates,
-- but it does this by incrementing the count value that is passed in,
-- so we must first initialize the count return value before calling it.
Count := 0;
Deallocate_Children
(Container => Container,
Subtree => Root_Node (Container),
Count => Count);
pragma Assert (Count = Container_Count);
end Clear;
------------------------
-- Constant_Reference --
------------------------
function Constant_Reference
(Container : aliased Tree;
Position : Cursor) return Constant_Reference_Type
is
begin
if Checks and then Position.Container = null then
raise Constraint_Error with
"Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with
"Position cursor designates wrong container";
end if;
if Checks and then Position.Node = Root_Node (Container) then
raise Program_Error with "Position cursor designates root";
end if;
-- Implement Vet for multiway tree???
-- pragma Assert (Vet (Position),
-- "Position cursor in Constant_Reference is bad");
declare
TC : constant Tamper_Counts_Access :=
Container.TC'Unrestricted_Access;
begin
return R : constant Constant_Reference_Type :=
(Element => Container.Elements (Position.Node)'Access,
Control => (Controlled with TC))
do
Lock (TC.all);
end return;
end;
end Constant_Reference;
--------------
-- Contains --
--------------
function Contains
(Container : Tree;
Item : Element_Type) return Boolean
is
begin
return Find (Container, Item) /= No_Element;
end Contains;
----------
-- Copy --
----------
function Copy
(Source : Tree;
Capacity : Count_Type := 0) return Tree
is
C : Count_Type;
begin
if Capacity = 0 then
C := Source.Count;
elsif Capacity >= Source.Count then
C := Capacity;
elsif Checks then
raise Capacity_Error with "Capacity value too small";
end if;
return Target : Tree (Capacity => C) do
Initialize_Root (Target);
if Source.Count = 0 then
return;
end if;
Copy_Children
(Source => Source,
Source_Parent => Root_Node (Source),
Target => Target,
Target_Parent => Root_Node (Target),
Count => Target.Count);
pragma Assert (Target.Count = Source.Count);
end return;
end Copy;
-------------------
-- Copy_Children --
-------------------
procedure Copy_Children
(Source : Tree;
Source_Parent : Count_Type;
Target : in out Tree;
Target_Parent : Count_Type;
Count : in out Count_Type)
is
S_Nodes : Tree_Node_Array renames Source.Nodes;
S_Node : Tree_Node_Type renames S_Nodes (Source_Parent);
T_Nodes : Tree_Node_Array renames Target.Nodes;
T_Node : Tree_Node_Type renames T_Nodes (Target_Parent);
pragma Assert (T_Node.Children.First <= 0);
pragma Assert (T_Node.Children.Last <= 0);
T_CC : Children_Type;
C : Count_Type'Base;
begin
-- We special-case the first allocation, in order to establish the
-- representation invariants for type Children_Type.
C := S_Node.Children.First;
if C <= 0 then -- source parent has no children
return;
end if;
Copy_Subtree
(Source => Source,
Source_Subtree => C,
Target => Target,
Target_Parent => Target_Parent,
Target_Subtree => T_CC.First,
Count => Count);
T_CC.Last := T_CC.First;
-- The representation invariants for the Children_Type list have been
-- established, so we can now copy the remaining children of Source.
C := S_Nodes (C).Next;
while C > 0 loop
Copy_Subtree
(Source => Source,
Source_Subtree => C,
Target => Target,
Target_Parent => Target_Parent,
Target_Subtree => T_Nodes (T_CC.Last).Next,
Count => Count);
T_Nodes (T_Nodes (T_CC.Last).Next).Prev := T_CC.Last;
T_CC.Last := T_Nodes (T_CC.Last).Next;
C := S_Nodes (C).Next;
end loop;
-- We add the newly-allocated children to their parent list only after
-- the allocation has succeeded, in order to preserve invariants of the
-- parent.
T_Node.Children := T_CC;
end Copy_Children;
------------------
-- Copy_Subtree --
------------------
procedure Copy_Subtree
(Target : in out Tree;
Parent : Cursor;
Before : Cursor;
Source : Cursor)
is
Target_Subtree : Count_Type;
Target_Count : Count_Type;
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Checks and then Parent.Container /= Target'Unrestricted_Access then
raise Program_Error with "Parent cursor not in container";
end if;
if Before /= No_Element then
if Checks and then Before.Container /= Target'Unrestricted_Access then
raise Program_Error with "Before cursor not in container";
end if;
if Checks and then
Before.Container.Nodes (Before.Node).Parent /= Parent.Node
then
raise Constraint_Error with "Before cursor not child of Parent";
end if;
end if;
if Source = No_Element then
return;
end if;
if Checks and then Is_Root (Source) then
raise Constraint_Error with "Source cursor designates root";
end if;
if Target.Count = 0 then
Initialize_Root (Target);
end if;
-- Copy_Subtree returns a count of the number of nodes that it
-- allocates, but it works by incrementing the value that is passed
-- in. We must therefore initialize the count value before calling
-- Copy_Subtree.
Target_Count := 0;
Copy_Subtree
(Source => Source.Container.all,
Source_Subtree => Source.Node,
Target => Target,
Target_Parent => Parent.Node,
Target_Subtree => Target_Subtree,
Count => Target_Count);
Insert_Subtree_Node
(Container => Target,
Subtree => Target_Subtree,
Parent => Parent.Node,
Before => Before.Node);
Target.Count := Target.Count + Target_Count;
end Copy_Subtree;
procedure Copy_Subtree
(Source : Tree;
Source_Subtree : Count_Type;
Target : in out Tree;
Target_Parent : Count_Type;
Target_Subtree : out Count_Type;
Count : in out Count_Type)
is
T_Nodes : Tree_Node_Array renames Target.Nodes;
begin
-- First we allocate the root of the target subtree.
Allocate_Node
(Container => Target,
New_Item => Source.Elements (Source_Subtree),
New_Node => Target_Subtree);
T_Nodes (Target_Subtree).Parent := Target_Parent;
Count := Count + 1;
-- We now have a new subtree (for the Target tree), containing only a
-- copy of the corresponding element in the Source subtree. Next we copy
-- the children of the Source subtree as children of the new Target
-- subtree.
Copy_Children
(Source => Source,
Source_Parent => Source_Subtree,
Target => Target,
Target_Parent => Target_Subtree,
Count => Count);
end Copy_Subtree;
-------------------------
-- Deallocate_Children --
-------------------------
procedure Deallocate_Children
(Container : in out Tree;
Subtree : Count_Type;
Count : in out Count_Type)
is
Nodes : Tree_Node_Array renames Container.Nodes;
Node : Tree_Node_Type renames Nodes (Subtree); -- parent
CC : Children_Type renames Node.Children;
C : Count_Type'Base;
begin
while CC.First > 0 loop
C := CC.First;
CC.First := Nodes (C).Next;
Deallocate_Subtree (Container, C, Count);
end loop;
CC.Last := 0;
end Deallocate_Children;
---------------------
-- Deallocate_Node --
---------------------
procedure Deallocate_Node
(Container : in out Tree;
X : Count_Type)
is
NN : Tree_Node_Array renames Container.Nodes;
pragma Assert (X > 0);
pragma Assert (X <= NN'Last);
N : Tree_Node_Type renames NN (X);
pragma Assert (N.Parent /= X); -- node is active
begin
-- The tree container actually contains two lists: one for the "active"
-- nodes that contain elements that have been inserted onto the tree,
-- and another for the "inactive" nodes of the free store, from which
-- nodes are allocated when a new child is inserted in the tree.
-- We desire that merely declaring a tree object should have only
-- minimal cost; specially, we want to avoid having to initialize the
-- free store (to fill in the links), especially if the capacity of the
-- tree object is large.
-- The head of the free list is indicated by Container.Free. If its
-- value is non-negative, then the free store has been initialized in
-- the "normal" way: Container.Free points to the head of the list of
-- free (inactive) nodes, and the value 0 means the free list is
-- empty. Each node on the free list has been initialized to point to
-- the next free node (via its Next component), and the value 0 means
-- that this is the last node of the free list.
-- If Container.Free is negative, then the links on the free store have
-- not been initialized. In this case the link values are implied: the
-- free store comprises the components of the node array started with
-- the absolute value of Container.Free, and continuing until the end of
-- the array (Nodes'Last).
-- We prefer to lazy-init the free store (in fact, we would prefer to
-- not initialize it at all, because such initialization is an O(n)
-- operation). The time when we need to actually initialize the nodes in
-- the free store is when the node that becomes inactive is not at the
-- end of the active list. The free store would then be discontigous and
-- so its nodes would need to be linked in the traditional way.
-- It might be possible to perform an optimization here. Suppose that
-- the free store can be represented as having two parts: one comprising
-- the non-contiguous inactive nodes linked together in the normal way,
-- and the other comprising the contiguous inactive nodes (that are not
-- linked together, at the end of the nodes array). This would allow us
-- to never have to initialize the free store, except in a lazy way as
-- nodes become inactive. ???
-- When an element is deleted from the list container, its node becomes
-- inactive, and so we set its Parent and Prev components to an
-- impossible value (the index of the node itself), to indicate that it
-- is now inactive. This provides a useful way to detect a dangling
-- cursor reference.
N.Parent := X; -- Node is deallocated (not on active list)
N.Prev := X;
if Container.Free >= 0 then
-- The free store has previously been initialized. All we need to do
-- here is link the newly-free'd node onto the free list.
N.Next := Container.Free;
Container.Free := X;
elsif X + 1 = abs Container.Free then
-- The free store has not been initialized, and the node becoming
-- inactive immediately precedes the start of the free store. All
-- we need to do is move the start of the free store back by one.
N.Next := X; -- Not strictly necessary, but marginally safer
Container.Free := Container.Free + 1;
else
-- The free store has not been initialized, and the node becoming
-- inactive does not immediately precede the free store. Here we
-- first initialize the free store (meaning the links are given
-- values in the traditional way), and then link the newly-free'd
-- node onto the head of the free store.
-- See the comments above for an optimization opportunity. If the
-- next link for a node on the free store is negative, then this
-- means the remaining nodes on the free store are physically
-- contiguous, starting at the absolute value of that index value.
-- ???
Container.Free := abs Container.Free;
if Container.Free > Container.Capacity then
Container.Free := 0;
else
for J in Container.Free .. Container.Capacity - 1 loop
NN (J).Next := J + 1;
end loop;
NN (Container.Capacity).Next := 0;
end if;
NN (X).Next := Container.Free;
Container.Free := X;
end if;
end Deallocate_Node;
------------------------
-- Deallocate_Subtree --
------------------------
procedure Deallocate_Subtree
(Container : in out Tree;
Subtree : Count_Type;
Count : in out Count_Type)
is
begin
Deallocate_Children (Container, Subtree, Count);
Deallocate_Node (Container, Subtree);
Count := Count + 1;
end Deallocate_Subtree;
---------------------
-- Delete_Children --
---------------------
procedure Delete_Children
(Container : in out Tree;
Parent : Cursor)
is
Count : Count_Type;
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Checks and then Parent.Container /= Container'Unrestricted_Access then
raise Program_Error with "Parent cursor not in container";
end if;
TC_Check (Container.TC);
if Container.Count = 0 then
pragma Assert (Is_Root (Parent));
return;
end if;
-- Deallocate_Children returns a count of the number of nodes that it
-- deallocates, but it works by incrementing the value that is passed
-- in. We must therefore initialize the count value before calling
-- Deallocate_Children.
Count := 0;
Deallocate_Children (Container, Parent.Node, Count);
pragma Assert (Count <= Container.Count);
Container.Count := Container.Count - Count;
end Delete_Children;
-----------------
-- Delete_Leaf --
-----------------
procedure Delete_Leaf
(Container : in out Tree;
Position : in out Cursor)
is
X : Count_Type;
begin
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with "Position cursor not in container";
end if;
if Checks and then Is_Root (Position) then
raise Program_Error with "Position cursor designates root";
end if;
if Checks and then not Is_Leaf (Position) then
raise Constraint_Error with "Position cursor does not designate leaf";
end if;
TC_Check (Container.TC);
X := Position.Node;
Position := No_Element;
Remove_Subtree (Container, X);
Container.Count := Container.Count - 1;
Deallocate_Node (Container, X);
end Delete_Leaf;
--------------------
-- Delete_Subtree --
--------------------
procedure Delete_Subtree
(Container : in out Tree;
Position : in out Cursor)
is
X : Count_Type;
Count : Count_Type;
begin
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with "Position cursor not in container";
end if;
if Checks and then Is_Root (Position) then
raise Program_Error with "Position cursor designates root";
end if;
TC_Check (Container.TC);
X := Position.Node;
Position := No_Element;
Remove_Subtree (Container, X);
-- Deallocate_Subtree returns a count of the number of nodes that it
-- deallocates, but it works by incrementing the value that is passed
-- in. We must therefore initialize the count value before calling
-- Deallocate_Subtree.
Count := 0;
Deallocate_Subtree (Container, X, Count);
pragma Assert (Count <= Container.Count);
Container.Count := Container.Count - Count;
end Delete_Subtree;
-----------
-- Depth --
-----------
function Depth (Position : Cursor) return Count_Type is
Result : Count_Type;
N : Count_Type'Base;
begin
if Position = No_Element then
return 0;
end if;
if Is_Root (Position) then
return 1;
end if;
Result := 0;
N := Position.Node;
while N >= 0 loop
N := Position.Container.Nodes (N).Parent;
Result := Result + 1;
end loop;
return Result;
end Depth;
-------------
-- Element --
-------------
function Element (Position : Cursor) return Element_Type is
begin
if Checks and then Position.Container = null then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Node = Root_Node (Position.Container.all)
then
raise Program_Error with "Position cursor designates root";
end if;
return Position.Container.Elements (Position.Node);
end Element;
--------------------
-- Equal_Children --
--------------------
function Equal_Children
(Left_Tree : Tree;
Left_Subtree : Count_Type;
Right_Tree : Tree;
Right_Subtree : Count_Type) return Boolean
is
L_NN : Tree_Node_Array renames Left_Tree.Nodes;
R_NN : Tree_Node_Array renames Right_Tree.Nodes;
Left_Children : Children_Type renames L_NN (Left_Subtree).Children;
Right_Children : Children_Type renames R_NN (Right_Subtree).Children;
L, R : Count_Type'Base;
begin
if Child_Count (Left_Tree, Left_Subtree)
/= Child_Count (Right_Tree, Right_Subtree)
then
return False;
end if;
L := Left_Children.First;
R := Right_Children.First;
while L > 0 loop
if not Equal_Subtree (Left_Tree, L, Right_Tree, R) then
return False;
end if;
L := L_NN (L).Next;
R := R_NN (R).Next;
end loop;
return True;
end Equal_Children;
-------------------
-- Equal_Subtree --
-------------------
function Equal_Subtree
(Left_Position : Cursor;
Right_Position : Cursor) return Boolean
is
begin
if Checks and then Left_Position = No_Element then
raise Constraint_Error with "Left cursor has no element";
end if;
if Checks and then Right_Position = No_Element then
raise Constraint_Error with "Right cursor has no element";
end if;
if Left_Position = Right_Position then
return True;
end if;
if Is_Root (Left_Position) then
if not Is_Root (Right_Position) then
return False;
end if;
if Left_Position.Container.Count = 0 then
return Right_Position.Container.Count = 0;
end if;
if Right_Position.Container.Count = 0 then
return False;
end if;
return Equal_Children
(Left_Tree => Left_Position.Container.all,
Left_Subtree => Left_Position.Node,
Right_Tree => Right_Position.Container.all,
Right_Subtree => Right_Position.Node);
end if;
if Is_Root (Right_Position) then
return False;
end if;
return Equal_Subtree
(Left_Tree => Left_Position.Container.all,
Left_Subtree => Left_Position.Node,
Right_Tree => Right_Position.Container.all,
Right_Subtree => Right_Position.Node);
end Equal_Subtree;
function Equal_Subtree
(Left_Tree : Tree;
Left_Subtree : Count_Type;
Right_Tree : Tree;
Right_Subtree : Count_Type) return Boolean
is
begin
if Left_Tree.Elements (Left_Subtree) /=
Right_Tree.Elements (Right_Subtree)
then
return False;
end if;
return Equal_Children
(Left_Tree => Left_Tree,
Left_Subtree => Left_Subtree,
Right_Tree => Right_Tree,
Right_Subtree => Right_Subtree);
end Equal_Subtree;
--------------
-- Finalize --
--------------
procedure Finalize (Object : in out Root_Iterator) is
begin
Unbusy (Object.Container.TC);
end Finalize;
----------
-- Find --
----------
function Find
(Container : Tree;
Item : Element_Type) return Cursor
is
Node : Count_Type;
begin
if Container.Count = 0 then
return No_Element;
end if;
Node := Find_In_Children (Container, Root_Node (Container), Item);
if Node = 0 then
return No_Element;
end if;
return Cursor'(Container'Unrestricted_Access, Node);
end Find;
-----------
-- First --
-----------
overriding function First (Object : Subtree_Iterator) return Cursor is
begin
if Object.Subtree = Root_Node (Object.Container.all) then
return First_Child (Root (Object.Container.all));
else
return Cursor'(Object.Container, Object.Subtree);
end if;
end First;
overriding function First (Object : Child_Iterator) return Cursor is
begin
return First_Child (Cursor'(Object.Container, Object.Subtree));
end First;
-----------------
-- First_Child --
-----------------
function First_Child (Parent : Cursor) return Cursor is
Node : Count_Type'Base;
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Parent.Container.Count = 0 then
pragma Assert (Is_Root (Parent));
return No_Element;
end if;
Node := Parent.Container.Nodes (Parent.Node).Children.First;
if Node <= 0 then
return No_Element;
end if;
return Cursor'(Parent.Container, Node);
end First_Child;
-------------------------
-- First_Child_Element --
-------------------------
function First_Child_Element (Parent : Cursor) return Element_Type is
begin
return Element (First_Child (Parent));
end First_Child_Element;
----------------------
-- Find_In_Children --
----------------------
function Find_In_Children
(Container : Tree;
Subtree : Count_Type;
Item : Element_Type) return Count_Type
is
N : Count_Type'Base;
Result : Count_Type;
begin
N := Container.Nodes (Subtree).Children.First;
while N > 0 loop
Result := Find_In_Subtree (Container, N, Item);
if Result > 0 then
return Result;
end if;
N := Container.Nodes (N).Next;
end loop;
return 0;
end Find_In_Children;
---------------------
-- Find_In_Subtree --
---------------------
function Find_In_Subtree
(Position : Cursor;
Item : Element_Type) return Cursor
is
Result : Count_Type;
begin
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
-- Commented-out pending ruling by ARG. ???
-- if Checks and then
-- Position.Container /= Container'Unrestricted_Access
-- then
-- raise Program_Error with "Position cursor not in container";
-- end if;
if Position.Container.Count = 0 then
pragma Assert (Is_Root (Position));
return No_Element;
end if;
if Is_Root (Position) then
Result := Find_In_Children
(Container => Position.Container.all,
Subtree => Position.Node,
Item => Item);
else
Result := Find_In_Subtree
(Container => Position.Container.all,
Subtree => Position.Node,
Item => Item);
end if;
if Result = 0 then
return No_Element;
end if;
return Cursor'(Position.Container, Result);
end Find_In_Subtree;
function Find_In_Subtree
(Container : Tree;
Subtree : Count_Type;
Item : Element_Type) return Count_Type
is
begin
if Container.Elements (Subtree) = Item then
return Subtree;
end if;
return Find_In_Children (Container, Subtree, Item);
end Find_In_Subtree;
------------------------
-- Get_Element_Access --
------------------------
function Get_Element_Access
(Position : Cursor) return not null Element_Access is
begin
return Position.Container.Elements (Position.Node)'Access;
end Get_Element_Access;
-----------------
-- Has_Element --
-----------------
function Has_Element (Position : Cursor) return Boolean is
begin
if Position = No_Element then
return False;
end if;
return Position.Node /= Root_Node (Position.Container.all);
end Has_Element;
---------------------
-- Initialize_Node --
---------------------
procedure Initialize_Node
(Container : in out Tree;
Index : Count_Type)
is
begin
Container.Nodes (Index) :=
(Parent => No_Node,
Prev => 0,
Next => 0,
Children => (others => 0));
end Initialize_Node;
---------------------
-- Initialize_Root --
---------------------
procedure Initialize_Root (Container : in out Tree) is
begin
Initialize_Node (Container, Root_Node (Container));
end Initialize_Root;
------------------
-- Insert_Child --
------------------
procedure Insert_Child
(Container : in out Tree;
Parent : Cursor;
Before : Cursor;
New_Item : Element_Type;
Count : Count_Type := 1)
is
Position : Cursor;
pragma Unreferenced (Position);
begin
Insert_Child (Container, Parent, Before, New_Item, Position, Count);
end Insert_Child;
procedure Insert_Child
(Container : in out Tree;
Parent : Cursor;
Before : Cursor;
New_Item : Element_Type;
Position : out Cursor;
Count : Count_Type := 1)
is
Nodes : Tree_Node_Array renames Container.Nodes;
First : Count_Type;
Last : Count_Type;
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Checks and then Parent.Container /= Container'Unrestricted_Access then
raise Program_Error with "Parent cursor not in container";
end if;
if Before /= No_Element then
if Checks and then Before.Container /= Container'Unrestricted_Access
then
raise Program_Error with "Before cursor not in container";
end if;
if Checks and then
Before.Container.Nodes (Before.Node).Parent /= Parent.Node
then
raise Constraint_Error with "Parent cursor not parent of Before";
end if;
end if;
if Count = 0 then
Position := No_Element; -- Need ruling from ARG ???
return;
end if;
if Checks and then Container.Count > Container.Capacity - Count then
raise Capacity_Error
with "requested count exceeds available storage";
end if;
TC_Check (Container.TC);
if Container.Count = 0 then
Initialize_Root (Container);
end if;
Allocate_Node (Container, New_Item, First);
Nodes (First).Parent := Parent.Node;
Last := First;
for J in Count_Type'(2) .. Count loop
Allocate_Node (Container, New_Item, Nodes (Last).Next);
Nodes (Nodes (Last).Next).Parent := Parent.Node;
Nodes (Nodes (Last).Next).Prev := Last;
Last := Nodes (Last).Next;
end loop;
Insert_Subtree_List
(Container => Container,
First => First,
Last => Last,
Parent => Parent.Node,
Before => Before.Node);
Container.Count := Container.Count + Count;
Position := Cursor'(Parent.Container, First);
end Insert_Child;
procedure Insert_Child
(Container : in out Tree;
Parent : Cursor;
Before : Cursor;
Position : out Cursor;
Count : Count_Type := 1)
is
Nodes : Tree_Node_Array renames Container.Nodes;
First : Count_Type;
Last : Count_Type;
pragma Warnings (Off);
Default_Initialized_Item : Element_Type;
pragma Unmodified (Default_Initialized_Item);
-- OK to reference, see below
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Checks and then Parent.Container /= Container'Unrestricted_Access then
raise Program_Error with "Parent cursor not in container";
end if;
if Before /= No_Element then
if Checks and then Before.Container /= Container'Unrestricted_Access
then
raise Program_Error with "Before cursor not in container";
end if;
if Checks and then
Before.Container.Nodes (Before.Node).Parent /= Parent.Node
then
raise Constraint_Error with "Parent cursor not parent of Before";
end if;
end if;
if Count = 0 then
Position := No_Element; -- Need ruling from ARG ???
return;
end if;
if Checks and then Container.Count > Container.Capacity - Count then
raise Capacity_Error
with "requested count exceeds available storage";
end if;
TC_Check (Container.TC);
if Container.Count = 0 then
Initialize_Root (Container);
end if;
-- There is no explicit element provided, but in an instance the element
-- type may be a scalar with a Default_Value aspect, or a composite
-- type with such a scalar component, or components with default
-- initialization, so insert the specified number of possibly
-- initialized elements at the given position.
Allocate_Node (Container, Default_Initialized_Item, First);
Nodes (First).Parent := Parent.Node;
Last := First;
for J in Count_Type'(2) .. Count loop
Allocate_Node
(Container, Default_Initialized_Item, Nodes (Last).Next);
Nodes (Nodes (Last).Next).Parent := Parent.Node;
Nodes (Nodes (Last).Next).Prev := Last;
Last := Nodes (Last).Next;
end loop;
Insert_Subtree_List
(Container => Container,
First => First,
Last => Last,
Parent => Parent.Node,
Before => Before.Node);
Container.Count := Container.Count + Count;
Position := Cursor'(Parent.Container, First);
pragma Warnings (On);
end Insert_Child;
-------------------------
-- Insert_Subtree_List --
-------------------------
procedure Insert_Subtree_List
(Container : in out Tree;
First : Count_Type'Base;
Last : Count_Type'Base;
Parent : Count_Type;
Before : Count_Type'Base)
is
NN : Tree_Node_Array renames Container.Nodes;
N : Tree_Node_Type renames NN (Parent);
CC : Children_Type renames N.Children;
begin
-- This is a simple utility operation to insert a list of nodes
-- (First..Last) as children of Parent. The Before node specifies where
-- the new children should be inserted relative to existing children.
if First <= 0 then
pragma Assert (Last <= 0);
return;
end if;
pragma Assert (Last > 0);
pragma Assert (Before <= 0 or else NN (Before).Parent = Parent);
if CC.First <= 0 then -- no existing children
CC.First := First;
NN (CC.First).Prev := 0;
CC.Last := Last;
NN (CC.Last).Next := 0;
elsif Before <= 0 then -- means "insert after existing nodes"
NN (CC.Last).Next := First;
NN (First).Prev := CC.Last;
CC.Last := Last;
NN (CC.Last).Next := 0;
elsif Before = CC.First then
NN (Last).Next := CC.First;
NN (CC.First).Prev := Last;
CC.First := First;
NN (CC.First).Prev := 0;
else
NN (NN (Before).Prev).Next := First;
NN (First).Prev := NN (Before).Prev;
NN (Last).Next := Before;
NN (Before).Prev := Last;
end if;
end Insert_Subtree_List;
-------------------------
-- Insert_Subtree_Node --
-------------------------
procedure Insert_Subtree_Node
(Container : in out Tree;
Subtree : Count_Type'Base;
Parent : Count_Type;
Before : Count_Type'Base)
is
begin
-- This is a simple wrapper operation to insert a single child into the
-- Parent's children list.
Insert_Subtree_List
(Container => Container,
First => Subtree,
Last => Subtree,
Parent => Parent,
Before => Before);
end Insert_Subtree_Node;
--------------
-- Is_Empty --
--------------
function Is_Empty (Container : Tree) return Boolean is
begin
return Container.Count = 0;
end Is_Empty;
-------------
-- Is_Leaf --
-------------
function Is_Leaf (Position : Cursor) return Boolean is
begin
if Position = No_Element then
return False;
end if;
if Position.Container.Count = 0 then
pragma Assert (Is_Root (Position));
return True;
end if;
return Position.Container.Nodes (Position.Node).Children.First <= 0;
end Is_Leaf;
------------------
-- Is_Reachable --
------------------
function Is_Reachable
(Container : Tree;
From, To : Count_Type) return Boolean
is
Idx : Count_Type;
begin
Idx := From;
while Idx >= 0 loop
if Idx = To then
return True;
end if;
Idx := Container.Nodes (Idx).Parent;
end loop;
return False;
end Is_Reachable;
-------------
-- Is_Root --
-------------
function Is_Root (Position : Cursor) return Boolean is
begin
return
(if Position.Container = null then False
else Position.Node = Root_Node (Position.Container.all));
end Is_Root;
-------------
-- Iterate --
-------------
procedure Iterate
(Container : Tree;
Process : not null access procedure (Position : Cursor))
is
Busy : With_Busy (Container.TC'Unrestricted_Access);
begin
if Container.Count = 0 then
return;
end if;
Iterate_Children
(Container => Container,
Subtree => Root_Node (Container),
Process => Process);
end Iterate;
function Iterate (Container : Tree)
return Tree_Iterator_Interfaces.Forward_Iterator'Class
is
begin
return Iterate_Subtree (Root (Container));
end Iterate;
----------------------
-- Iterate_Children --
----------------------
procedure Iterate_Children
(Parent : Cursor;
Process : not null access procedure (Position : Cursor))
is
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Parent.Container.Count = 0 then
pragma Assert (Is_Root (Parent));
return;
end if;
declare
C : Count_Type;
NN : Tree_Node_Array renames Parent.Container.Nodes;
Busy : With_Busy (Parent.Container.TC'Unrestricted_Access);
begin
C := NN (Parent.Node).Children.First;
while C > 0 loop
Process (Cursor'(Parent.Container, Node => C));
C := NN (C).Next;
end loop;
end;
end Iterate_Children;
procedure Iterate_Children
(Container : Tree;
Subtree : Count_Type;
Process : not null access procedure (Position : Cursor))
is
NN : Tree_Node_Array renames Container.Nodes;
N : Tree_Node_Type renames NN (Subtree);
C : Count_Type;
begin
-- This is a helper function to recursively iterate over all the nodes
-- in a subtree, in depth-first fashion. This particular helper just
-- visits the children of this subtree, not the root of the subtree
-- itself. This is useful when starting from the ultimate root of the
-- entire tree (see Iterate), as that root does not have an element.
C := N.Children.First;
while C > 0 loop
Iterate_Subtree (Container, C, Process);
C := NN (C).Next;
end loop;
end Iterate_Children;
function Iterate_Children
(Container : Tree;
Parent : Cursor)
return Tree_Iterator_Interfaces.Reversible_Iterator'Class
is
C : constant Tree_Access := Container'Unrestricted_Access;
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Checks and then Parent.Container /= C then
raise Program_Error with "Parent cursor not in container";
end if;
return It : constant Child_Iterator :=
Child_Iterator'(Limited_Controlled with
Container => C,
Subtree => Parent.Node)
do
Busy (C.TC);
end return;
end Iterate_Children;
---------------------
-- Iterate_Subtree --
---------------------
function Iterate_Subtree
(Position : Cursor)
return Tree_Iterator_Interfaces.Forward_Iterator'Class
is
C : constant Tree_Access := Position.Container;
begin
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
-- Implement Vet for multiway trees???
-- pragma Assert (Vet (Position), "bad subtree cursor");
return It : constant Subtree_Iterator :=
(Limited_Controlled with
Container => C,
Subtree => Position.Node)
do
Busy (C.TC);
end return;
end Iterate_Subtree;
procedure Iterate_Subtree
(Position : Cursor;
Process : not null access procedure (Position : Cursor))
is
begin
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
if Position.Container.Count = 0 then
pragma Assert (Is_Root (Position));
return;
end if;
declare
T : Tree renames Position.Container.all;
Busy : With_Busy (T.TC'Unrestricted_Access);
begin
if Is_Root (Position) then
Iterate_Children (T, Position.Node, Process);
else
Iterate_Subtree (T, Position.Node, Process);
end if;
end;
end Iterate_Subtree;
procedure Iterate_Subtree
(Container : Tree;
Subtree : Count_Type;
Process : not null access procedure (Position : Cursor))
is
begin
-- This is a helper function to recursively iterate over all the nodes
-- in a subtree, in depth-first fashion. It first visits the root of the
-- subtree, then visits its children.
Process (Cursor'(Container'Unrestricted_Access, Subtree));
Iterate_Children (Container, Subtree, Process);
end Iterate_Subtree;
----------
-- Last --
----------
overriding function Last (Object : Child_Iterator) return Cursor is
begin
return Last_Child (Cursor'(Object.Container, Object.Subtree));
end Last;
----------------
-- Last_Child --
----------------
function Last_Child (Parent : Cursor) return Cursor is
Node : Count_Type'Base;
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Parent.Container.Count = 0 then
pragma Assert (Is_Root (Parent));
return No_Element;
end if;
Node := Parent.Container.Nodes (Parent.Node).Children.Last;
if Node <= 0 then
return No_Element;
end if;
return Cursor'(Parent.Container, Node);
end Last_Child;
------------------------
-- Last_Child_Element --
------------------------
function Last_Child_Element (Parent : Cursor) return Element_Type is
begin
return Element (Last_Child (Parent));
end Last_Child_Element;
----------
-- Move --
----------
procedure Move (Target : in out Tree; Source : in out Tree) is
begin
if Target'Address = Source'Address then
return;
end if;
TC_Check (Source.TC);
Target.Assign (Source);
Source.Clear;
end Move;
----------
-- Next --
----------
overriding function Next
(Object : Subtree_Iterator;
Position : Cursor) return Cursor
is
begin
if Position.Container = null then
return No_Element;
end if;
if Checks and then Position.Container /= Object.Container then
raise Program_Error with
"Position cursor of Next designates wrong tree";
end if;
pragma Assert (Object.Container.Count > 0);
pragma Assert (Position.Node /= Root_Node (Object.Container.all));
declare
Nodes : Tree_Node_Array renames Object.Container.Nodes;
Node : Count_Type;
begin
Node := Position.Node;
if Nodes (Node).Children.First > 0 then
return Cursor'(Object.Container, Nodes (Node).Children.First);
end if;
while Node /= Object.Subtree loop
if Nodes (Node).Next > 0 then
return Cursor'(Object.Container, Nodes (Node).Next);
end if;
Node := Nodes (Node).Parent;
end loop;
return No_Element;
end;
end Next;
overriding function Next
(Object : Child_Iterator;
Position : Cursor) return Cursor
is
begin
if Position.Container = null then
return No_Element;
end if;
if Checks and then Position.Container /= Object.Container then
raise Program_Error with
"Position cursor of Next designates wrong tree";
end if;
pragma Assert (Object.Container.Count > 0);
pragma Assert (Position.Node /= Root_Node (Object.Container.all));
return Next_Sibling (Position);
end Next;
------------------
-- Next_Sibling --
------------------
function Next_Sibling (Position : Cursor) return Cursor is
begin
if Position = No_Element then
return No_Element;
end if;
if Position.Container.Count = 0 then
pragma Assert (Is_Root (Position));
return No_Element;
end if;
declare
T : Tree renames Position.Container.all;
NN : Tree_Node_Array renames T.Nodes;
N : Tree_Node_Type renames NN (Position.Node);
begin
if N.Next <= 0 then
return No_Element;
end if;
return Cursor'(Position.Container, N.Next);
end;
end Next_Sibling;
procedure Next_Sibling (Position : in out Cursor) is
begin
Position := Next_Sibling (Position);
end Next_Sibling;
----------------
-- Node_Count --
----------------
function Node_Count (Container : Tree) return Count_Type is
begin
-- Container.Count is the number of nodes we have actually allocated. We
-- cache the value specifically so this Node_Count operation can execute
-- in O(1) time, which makes it behave similarly to how the Length
-- selector function behaves for other containers.
--
-- The cached node count value only describes the nodes we have
-- allocated; the root node itself is not included in that count. The
-- Node_Count operation returns a value that includes the root node
-- (because the RM says so), so we must add 1 to our cached value.
return 1 + Container.Count;
end Node_Count;
------------
-- Parent --
------------
function Parent (Position : Cursor) return Cursor is
begin
if Position = No_Element then
return No_Element;
end if;
if Position.Container.Count = 0 then
pragma Assert (Is_Root (Position));
return No_Element;
end if;
declare
T : Tree renames Position.Container.all;
NN : Tree_Node_Array renames T.Nodes;
N : Tree_Node_Type renames NN (Position.Node);
begin
if N.Parent < 0 then
pragma Assert (Position.Node = Root_Node (T));
return No_Element;
end if;
return Cursor'(Position.Container, N.Parent);
end;
end Parent;
-------------------
-- Prepend_Child --
-------------------
procedure Prepend_Child
(Container : in out Tree;
Parent : Cursor;
New_Item : Element_Type;
Count : Count_Type := 1)
is
Nodes : Tree_Node_Array renames Container.Nodes;
First, Last : Count_Type;
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Checks and then Parent.Container /= Container'Unrestricted_Access then
raise Program_Error with "Parent cursor not in container";
end if;
if Count = 0 then
return;
end if;
if Checks and then Container.Count > Container.Capacity - Count then
raise Capacity_Error
with "requested count exceeds available storage";
end if;
TC_Check (Container.TC);
if Container.Count = 0 then
Initialize_Root (Container);
end if;
Allocate_Node (Container, New_Item, First);
Nodes (First).Parent := Parent.Node;
Last := First;
for J in Count_Type'(2) .. Count loop
Allocate_Node (Container, New_Item, Nodes (Last).Next);
Nodes (Nodes (Last).Next).Parent := Parent.Node;
Nodes (Nodes (Last).Next).Prev := Last;
Last := Nodes (Last).Next;
end loop;
Insert_Subtree_List
(Container => Container,
First => First,
Last => Last,
Parent => Parent.Node,
Before => Nodes (Parent.Node).Children.First);
Container.Count := Container.Count + Count;
end Prepend_Child;
--------------
-- Previous --
--------------
overriding function Previous
(Object : Child_Iterator;
Position : Cursor) return Cursor
is
begin
if Position.Container = null then
return No_Element;
end if;
if Checks and then Position.Container /= Object.Container then
raise Program_Error with
"Position cursor of Previous designates wrong tree";
end if;
return Previous_Sibling (Position);
end Previous;
----------------------
-- Previous_Sibling --
----------------------
function Previous_Sibling (Position : Cursor) return Cursor is
begin
if Position = No_Element then
return No_Element;
end if;
if Position.Container.Count = 0 then
pragma Assert (Is_Root (Position));
return No_Element;
end if;
declare
T : Tree renames Position.Container.all;
NN : Tree_Node_Array renames T.Nodes;
N : Tree_Node_Type renames NN (Position.Node);
begin
if N.Prev <= 0 then
return No_Element;
end if;
return Cursor'(Position.Container, N.Prev);
end;
end Previous_Sibling;
procedure Previous_Sibling (Position : in out Cursor) is
begin
Position := Previous_Sibling (Position);
end Previous_Sibling;
----------------------
-- Pseudo_Reference --
----------------------
function Pseudo_Reference
(Container : aliased Tree'Class) return Reference_Control_Type
is
TC : constant Tamper_Counts_Access := Container.TC'Unrestricted_Access;
begin
return R : constant Reference_Control_Type := (Controlled with TC) do
Lock (TC.all);
end return;
end Pseudo_Reference;
-------------------
-- Query_Element --
-------------------
procedure Query_Element
(Position : Cursor;
Process : not null access procedure (Element : Element_Type))
is
begin
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Is_Root (Position) then
raise Program_Error with "Position cursor designates root";
end if;
declare
T : Tree renames Position.Container.all'Unrestricted_Access.all;
Lock : With_Lock (T.TC'Unrestricted_Access);
begin
Process (Element => T.Elements (Position.Node));
end;
end Query_Element;
----------
-- Read --
----------
procedure Read
(Stream : not null access Root_Stream_Type'Class;
Container : out Tree)
is
procedure Read_Children (Subtree : Count_Type);
function Read_Subtree
(Parent : Count_Type) return Count_Type;
NN : Tree_Node_Array renames Container.Nodes;
Total_Count : Count_Type'Base;
-- Value read from the stream that says how many elements follow
Read_Count : Count_Type'Base;
-- Actual number of elements read from the stream
-------------------
-- Read_Children --
-------------------
procedure Read_Children (Subtree : Count_Type) is
Count : Count_Type'Base;
-- number of child subtrees
CC : Children_Type;
begin
Count_Type'Read (Stream, Count);
if Checks and then Count < 0 then
raise Program_Error with "attempt to read from corrupt stream";
end if;
if Count = 0 then
return;
end if;
CC.First := Read_Subtree (Parent => Subtree);
CC.Last := CC.First;
for J in Count_Type'(2) .. Count loop
NN (CC.Last).Next := Read_Subtree (Parent => Subtree);
NN (NN (CC.Last).Next).Prev := CC.Last;
CC.Last := NN (CC.Last).Next;
end loop;
-- Now that the allocation and reads have completed successfully, it
-- is safe to link the children to their parent.
NN (Subtree).Children := CC;
end Read_Children;
------------------
-- Read_Subtree --
------------------
function Read_Subtree
(Parent : Count_Type) return Count_Type
is
Subtree : Count_Type;
begin
Allocate_Node (Container, Stream, Subtree);
Container.Nodes (Subtree).Parent := Parent;
Read_Count := Read_Count + 1;
Read_Children (Subtree);
return Subtree;
end Read_Subtree;
-- Start of processing for Read
begin
Container.Clear; -- checks busy bit
Count_Type'Read (Stream, Total_Count);
if Checks and then Total_Count < 0 then
raise Program_Error with "attempt to read from corrupt stream";
end if;
if Total_Count = 0 then
return;
end if;
if Checks and then Total_Count > Container.Capacity then
raise Capacity_Error -- ???
with "node count in stream exceeds container capacity";
end if;
Initialize_Root (Container);
Read_Count := 0;
Read_Children (Root_Node (Container));
if Checks and then Read_Count /= Total_Count then
raise Program_Error with "attempt to read from corrupt stream";
end if;
Container.Count := Total_Count;
end Read;
procedure Read
(Stream : not null access Root_Stream_Type'Class;
Position : out Cursor)
is
begin
raise Program_Error with "attempt to read tree cursor from stream";
end Read;
procedure Read
(Stream : not null access Root_Stream_Type'Class;
Item : out Reference_Type)
is
begin
raise Program_Error with "attempt to stream reference";
end Read;
procedure Read
(Stream : not null access Root_Stream_Type'Class;
Item : out Constant_Reference_Type)
is
begin
raise Program_Error with "attempt to stream reference";
end Read;
---------------
-- Reference --
---------------
function Reference
(Container : aliased in out Tree;
Position : Cursor) return Reference_Type
is
begin
if Checks and then Position.Container = null then
raise Constraint_Error with
"Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with
"Position cursor designates wrong container";
end if;
if Checks and then Position.Node = Root_Node (Container) then
raise Program_Error with "Position cursor designates root";
end if;
-- Implement Vet for multiway tree???
-- pragma Assert (Vet (Position),
-- "Position cursor in Constant_Reference is bad");
declare
TC : constant Tamper_Counts_Access :=
Container.TC'Unrestricted_Access;
begin
return R : constant Reference_Type :=
(Element => Container.Elements (Position.Node)'Access,
Control => (Controlled with TC))
do
Lock (TC.all);
end return;
end;
end Reference;
--------------------
-- Remove_Subtree --
--------------------
procedure Remove_Subtree
(Container : in out Tree;
Subtree : Count_Type)
is
NN : Tree_Node_Array renames Container.Nodes;
N : Tree_Node_Type renames NN (Subtree);
CC : Children_Type renames NN (N.Parent).Children;
begin
-- This is a utility operation to remove a subtree node from its
-- parent's list of children.
if CC.First = Subtree then
pragma Assert (N.Prev <= 0);
if CC.Last = Subtree then
pragma Assert (N.Next <= 0);
CC.First := 0;
CC.Last := 0;
else
CC.First := N.Next;
NN (CC.First).Prev := 0;
end if;
elsif CC.Last = Subtree then
pragma Assert (N.Next <= 0);
CC.Last := N.Prev;
NN (CC.Last).Next := 0;
else
NN (N.Prev).Next := N.Next;
NN (N.Next).Prev := N.Prev;
end if;
end Remove_Subtree;
----------------------
-- Replace_Element --
----------------------
procedure Replace_Element
(Container : in out Tree;
Position : Cursor;
New_Item : Element_Type)
is
begin
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with "Position cursor not in container";
end if;
if Checks and then Is_Root (Position) then
raise Program_Error with "Position cursor designates root";
end if;
TE_Check (Container.TC);
Container.Elements (Position.Node) := New_Item;
end Replace_Element;
------------------------------
-- Reverse_Iterate_Children --
------------------------------
procedure Reverse_Iterate_Children
(Parent : Cursor;
Process : not null access procedure (Position : Cursor))
is
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Parent.Container.Count = 0 then
pragma Assert (Is_Root (Parent));
return;
end if;
declare
NN : Tree_Node_Array renames Parent.Container.Nodes;
Busy : With_Busy (Parent.Container.TC'Unrestricted_Access);
C : Count_Type;
begin
C := NN (Parent.Node).Children.Last;
while C > 0 loop
Process (Cursor'(Parent.Container, Node => C));
C := NN (C).Prev;
end loop;
end;
end Reverse_Iterate_Children;
----------
-- Root --
----------
function Root (Container : Tree) return Cursor is
begin
return (Container'Unrestricted_Access, Root_Node (Container));
end Root;
---------------
-- Root_Node --
---------------
function Root_Node (Container : Tree) return Count_Type is
pragma Unreferenced (Container);
begin
return 0;
end Root_Node;
---------------------
-- Splice_Children --
---------------------
procedure Splice_Children
(Target : in out Tree;
Target_Parent : Cursor;
Before : Cursor;
Source : in out Tree;
Source_Parent : Cursor)
is
begin
if Checks and then Target_Parent = No_Element then
raise Constraint_Error with "Target_Parent cursor has no element";
end if;
if Checks and then Target_Parent.Container /= Target'Unrestricted_Access
then
raise Program_Error
with "Target_Parent cursor not in Target container";
end if;
if Before /= No_Element then
if Checks and then Before.Container /= Target'Unrestricted_Access then
raise Program_Error
with "Before cursor not in Target container";
end if;
if Checks and then
Target.Nodes (Before.Node).Parent /= Target_Parent.Node
then
raise Constraint_Error
with "Before cursor not child of Target_Parent";
end if;
end if;
if Checks and then Source_Parent = No_Element then
raise Constraint_Error with "Source_Parent cursor has no element";
end if;
if Checks and then Source_Parent.Container /= Source'Unrestricted_Access
then
raise Program_Error
with "Source_Parent cursor not in Source container";
end if;
if Source.Count = 0 then
pragma Assert (Is_Root (Source_Parent));
return;
end if;
if Target'Address = Source'Address then
if Target_Parent = Source_Parent then
return;
end if;
TC_Check (Target.TC);
if Checks and then Is_Reachable (Container => Target,
From => Target_Parent.Node,
To => Source_Parent.Node)
then
raise Constraint_Error
with "Source_Parent is ancestor of Target_Parent";
end if;
Splice_Children
(Container => Target,
Target_Parent => Target_Parent.Node,
Before => Before.Node,
Source_Parent => Source_Parent.Node);
return;
end if;
TC_Check (Target.TC);
TC_Check (Source.TC);
if Target.Count = 0 then
Initialize_Root (Target);
end if;
Splice_Children
(Target => Target,
Target_Parent => Target_Parent.Node,
Before => Before.Node,
Source => Source,
Source_Parent => Source_Parent.Node);
end Splice_Children;
procedure Splice_Children
(Container : in out Tree;
Target_Parent : Cursor;
Before : Cursor;
Source_Parent : Cursor)
is
begin
if Checks and then Target_Parent = No_Element then
raise Constraint_Error with "Target_Parent cursor has no element";
end if;
if Checks and then
Target_Parent.Container /= Container'Unrestricted_Access
then
raise Program_Error
with "Target_Parent cursor not in container";
end if;
if Before /= No_Element then
if Checks and then Before.Container /= Container'Unrestricted_Access
then
raise Program_Error
with "Before cursor not in container";
end if;
if Checks and then
Container.Nodes (Before.Node).Parent /= Target_Parent.Node
then
raise Constraint_Error
with "Before cursor not child of Target_Parent";
end if;
end if;
if Checks and then Source_Parent = No_Element then
raise Constraint_Error with "Source_Parent cursor has no element";
end if;
if Checks and then
Source_Parent.Container /= Container'Unrestricted_Access
then
raise Program_Error
with "Source_Parent cursor not in container";
end if;
if Target_Parent = Source_Parent then
return;
end if;
pragma Assert (Container.Count > 0);
TC_Check (Container.TC);
if Checks and then Is_Reachable (Container => Container,
From => Target_Parent.Node,
To => Source_Parent.Node)
then
raise Constraint_Error
with "Source_Parent is ancestor of Target_Parent";
end if;
Splice_Children
(Container => Container,
Target_Parent => Target_Parent.Node,
Before => Before.Node,
Source_Parent => Source_Parent.Node);
end Splice_Children;
procedure Splice_Children
(Container : in out Tree;
Target_Parent : Count_Type;
Before : Count_Type'Base;
Source_Parent : Count_Type)
is
NN : Tree_Node_Array renames Container.Nodes;
CC : constant Children_Type := NN (Source_Parent).Children;
C : Count_Type'Base;
begin
-- This is a utility operation to remove the children from Source parent
-- and insert them into Target parent.
NN (Source_Parent).Children := Children_Type'(others => 0);
-- Fix up the Parent pointers of each child to designate its new Target
-- parent.
C := CC.First;
while C > 0 loop
NN (C).Parent := Target_Parent;
C := NN (C).Next;
end loop;
Insert_Subtree_List
(Container => Container,
First => CC.First,
Last => CC.Last,
Parent => Target_Parent,
Before => Before);
end Splice_Children;
procedure Splice_Children
(Target : in out Tree;
Target_Parent : Count_Type;
Before : Count_Type'Base;
Source : in out Tree;
Source_Parent : Count_Type)
is
S_NN : Tree_Node_Array renames Source.Nodes;
S_CC : Children_Type renames S_NN (Source_Parent).Children;
Target_Count, Source_Count : Count_Type;
T, S : Count_Type'Base;
begin
-- This is a utility operation to copy the children from the Source
-- parent and insert them as children of the Target parent, and then
-- delete them from the Source. (This is not a true splice operation,
-- but it is the best we can do in a bounded form.) The Before position
-- specifies where among the Target parent's exising children the new
-- children are inserted.
-- Before we attempt the insertion, we must count the sources nodes in
-- order to determine whether the target have enough storage
-- available. Note that calculating this value is an O(n) operation.
-- Here is an optimization opportunity: iterate of each children the
-- source explicitly, and keep a running count of the total number of
-- nodes. Compare the running total to the capacity of the target each
-- pass through the loop. This is more efficient than summing the counts
-- of child subtree (which is what Subtree_Node_Count does) and then
-- comparing that total sum to the target's capacity. ???
-- Here is another possibility. We currently treat the splice as an
-- all-or-nothing proposition: either we can insert all of children of
-- the source, or we raise exception with modifying the target. The
-- price for not causing side-effect is an O(n) determination of the
-- source count. If we are willing to tolerate side-effect, then we
-- could loop over the children of the source, counting that subtree and
-- then immediately inserting it in the target. The issue here is that
-- the test for available storage could fail during some later pass,
-- after children have already been inserted into target. ???
Source_Count := Subtree_Node_Count (Source, Source_Parent) - 1;
if Source_Count = 0 then
return;
end if;
if Checks and then Target.Count > Target.Capacity - Source_Count then
raise Capacity_Error -- ???
with "Source count exceeds available storage on Target";
end if;
-- Copy_Subtree returns a count of the number of nodes it inserts, but
-- it does this by incrementing the value passed in. Therefore we must
-- initialize the count before calling Copy_Subtree.
Target_Count := 0;
S := S_CC.First;
while S > 0 loop
Copy_Subtree
(Source => Source,
Source_Subtree => S,
Target => Target,
Target_Parent => Target_Parent,
Target_Subtree => T,
Count => Target_Count);
Insert_Subtree_Node
(Container => Target,
Subtree => T,
Parent => Target_Parent,
Before => Before);
S := S_NN (S).Next;
end loop;
pragma Assert (Target_Count = Source_Count);
Target.Count := Target.Count + Target_Count;
-- As with Copy_Subtree, operation Deallocate_Children returns a count
-- of the number of nodes it deallocates, but it works by incrementing
-- the value passed in. We must therefore initialize the count before
-- calling it.
Source_Count := 0;
Deallocate_Children (Source, Source_Parent, Source_Count);
pragma Assert (Source_Count = Target_Count);
Source.Count := Source.Count - Source_Count;
end Splice_Children;
--------------------
-- Splice_Subtree --
--------------------
procedure Splice_Subtree
(Target : in out Tree;
Parent : Cursor;
Before : Cursor;
Source : in out Tree;
Position : in out Cursor)
is
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Checks and then Parent.Container /= Target'Unrestricted_Access then
raise Program_Error with "Parent cursor not in Target container";
end if;
if Before /= No_Element then
if Checks and then Before.Container /= Target'Unrestricted_Access then
raise Program_Error with "Before cursor not in Target container";
end if;
if Checks and then Target.Nodes (Before.Node).Parent /= Parent.Node
then
raise Constraint_Error with "Before cursor not child of Parent";
end if;
end if;
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Source'Unrestricted_Access then
raise Program_Error with "Position cursor not in Source container";
end if;
if Checks and then Is_Root (Position) then
raise Program_Error with "Position cursor designates root";
end if;
if Target'Address = Source'Address then
if Target.Nodes (Position.Node).Parent = Parent.Node then
if Before = No_Element then
if Target.Nodes (Position.Node).Next <= 0 then -- last child
return;
end if;
elsif Position.Node = Before.Node then
return;
elsif Target.Nodes (Position.Node).Next = Before.Node then
return;
end if;
end if;
TC_Check (Target.TC);
if Checks and then Is_Reachable (Container => Target,
From => Parent.Node,
To => Position.Node)
then
raise Constraint_Error with "Position is ancestor of Parent";
end if;
Remove_Subtree (Target, Position.Node);
Target.Nodes (Position.Node).Parent := Parent.Node;
Insert_Subtree_Node (Target, Position.Node, Parent.Node, Before.Node);
return;
end if;
TC_Check (Target.TC);
TC_Check (Source.TC);
if Target.Count = 0 then
Initialize_Root (Target);
end if;
Splice_Subtree
(Target => Target,
Parent => Parent.Node,
Before => Before.Node,
Source => Source,
Position => Position.Node); -- modified during call
Position.Container := Target'Unrestricted_Access;
end Splice_Subtree;
procedure Splice_Subtree
(Container : in out Tree;
Parent : Cursor;
Before : Cursor;
Position : Cursor)
is
begin
if Checks and then Parent = No_Element then
raise Constraint_Error with "Parent cursor has no element";
end if;
if Checks and then Parent.Container /= Container'Unrestricted_Access then
raise Program_Error with "Parent cursor not in container";
end if;
if Before /= No_Element then
if Checks and then Before.Container /= Container'Unrestricted_Access
then
raise Program_Error with "Before cursor not in container";
end if;
if Checks and then Container.Nodes (Before.Node).Parent /= Parent.Node
then
raise Constraint_Error with "Before cursor not child of Parent";
end if;
end if;
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with "Position cursor not in container";
end if;
if Checks and then Is_Root (Position) then
-- Should this be PE instead? Need ARG confirmation. ???
raise Constraint_Error with "Position cursor designates root";
end if;
if Container.Nodes (Position.Node).Parent = Parent.Node then
if Before = No_Element then
if Container.Nodes (Position.Node).Next <= 0 then -- last child
return;
end if;
elsif Position.Node = Before.Node then
return;
elsif Container.Nodes (Position.Node).Next = Before.Node then
return;
end if;
end if;
TC_Check (Container.TC);
if Checks and then Is_Reachable (Container => Container,
From => Parent.Node,
To => Position.Node)
then
raise Constraint_Error with "Position is ancestor of Parent";
end if;
Remove_Subtree (Container, Position.Node);
Container.Nodes (Position.Node).Parent := Parent.Node;
Insert_Subtree_Node (Container, Position.Node, Parent.Node, Before.Node);
end Splice_Subtree;
procedure Splice_Subtree
(Target : in out Tree;
Parent : Count_Type;
Before : Count_Type'Base;
Source : in out Tree;
Position : in out Count_Type) -- Source on input, Target on output
is
Source_Count : Count_Type := Subtree_Node_Count (Source, Position);
pragma Assert (Source_Count >= 1);
Target_Subtree : Count_Type;
Target_Count : Count_Type;
begin
-- This is a utility operation to do the heavy lifting associated with
-- splicing a subtree from one tree to another. Note that "splicing"
-- is a bit of a misnomer here in the case of a bounded tree, because
-- the elements must be copied from the source to the target.
if Checks and then Target.Count > Target.Capacity - Source_Count then
raise Capacity_Error -- ???
with "Source count exceeds available storage on Target";
end if;
-- Copy_Subtree returns a count of the number of nodes it inserts, but
-- it does this by incrementing the value passed in. Therefore we must
-- initialize the count before calling Copy_Subtree.
Target_Count := 0;
Copy_Subtree
(Source => Source,
Source_Subtree => Position,
Target => Target,
Target_Parent => Parent,
Target_Subtree => Target_Subtree,
Count => Target_Count);
pragma Assert (Target_Count = Source_Count);
-- Now link the newly-allocated subtree into the target.
Insert_Subtree_Node
(Container => Target,
Subtree => Target_Subtree,
Parent => Parent,
Before => Before);
Target.Count := Target.Count + Target_Count;
-- The manipulation of the Target container is complete. Now we remove
-- the subtree from the Source container.
Remove_Subtree (Source, Position); -- unlink the subtree
-- As with Copy_Subtree, operation Deallocate_Subtree returns a count of
-- the number of nodes it deallocates, but it works by incrementing the
-- value passed in. We must therefore initialize the count before
-- calling it.
Source_Count := 0;
Deallocate_Subtree (Source, Position, Source_Count);
pragma Assert (Source_Count = Target_Count);
Source.Count := Source.Count - Source_Count;
Position := Target_Subtree;
end Splice_Subtree;
------------------------
-- Subtree_Node_Count --
------------------------
function Subtree_Node_Count (Position : Cursor) return Count_Type is
begin
if Position = No_Element then
return 0;
end if;
if Position.Container.Count = 0 then
pragma Assert (Is_Root (Position));
return 1;
end if;
return Subtree_Node_Count (Position.Container.all, Position.Node);
end Subtree_Node_Count;
function Subtree_Node_Count
(Container : Tree;
Subtree : Count_Type) return Count_Type
is
Result : Count_Type;
Node : Count_Type'Base;
begin
Result := 1;
Node := Container.Nodes (Subtree).Children.First;
while Node > 0 loop
Result := Result + Subtree_Node_Count (Container, Node);
Node := Container.Nodes (Node).Next;
end loop;
return Result;
end Subtree_Node_Count;
----------
-- Swap --
----------
procedure Swap
(Container : in out Tree;
I, J : Cursor)
is
begin
if Checks and then I = No_Element then
raise Constraint_Error with "I cursor has no element";
end if;
if Checks and then I.Container /= Container'Unrestricted_Access then
raise Program_Error with "I cursor not in container";
end if;
if Checks and then Is_Root (I) then
raise Program_Error with "I cursor designates root";
end if;
if I = J then -- make this test sooner???
return;
end if;
if Checks and then J = No_Element then
raise Constraint_Error with "J cursor has no element";
end if;
if Checks and then J.Container /= Container'Unrestricted_Access then
raise Program_Error with "J cursor not in container";
end if;
if Checks and then Is_Root (J) then
raise Program_Error with "J cursor designates root";
end if;
TE_Check (Container.TC);
declare
EE : Element_Array renames Container.Elements;
EI : constant Element_Type := EE (I.Node);
begin
EE (I.Node) := EE (J.Node);
EE (J.Node) := EI;
end;
end Swap;
--------------------
-- Update_Element --
--------------------
procedure Update_Element
(Container : in out Tree;
Position : Cursor;
Process : not null access procedure (Element : in out Element_Type))
is
begin
if Checks and then Position = No_Element then
raise Constraint_Error with "Position cursor has no element";
end if;
if Checks and then Position.Container /= Container'Unrestricted_Access
then
raise Program_Error with "Position cursor not in container";
end if;
if Checks and then Is_Root (Position) then
raise Program_Error with "Position cursor designates root";
end if;
declare
T : Tree renames Position.Container.all'Unrestricted_Access.all;
Lock : With_Lock (T.TC'Unrestricted_Access);
begin
Process (Element => T.Elements (Position.Node));
end;
end Update_Element;
-----------
-- Write --
-----------
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Container : Tree)
is
procedure Write_Children (Subtree : Count_Type);
procedure Write_Subtree (Subtree : Count_Type);
--------------------
-- Write_Children --
--------------------
procedure Write_Children (Subtree : Count_Type) is
CC : Children_Type renames Container.Nodes (Subtree).Children;
C : Count_Type'Base;
begin
Count_Type'Write (Stream, Child_Count (Container, Subtree));
C := CC.First;
while C > 0 loop
Write_Subtree (C);
C := Container.Nodes (C).Next;
end loop;
end Write_Children;
-------------------
-- Write_Subtree --
-------------------
procedure Write_Subtree (Subtree : Count_Type) is
begin
Element_Type'Write (Stream, Container.Elements (Subtree));
Write_Children (Subtree);
end Write_Subtree;
-- Start of processing for Write
begin
Count_Type'Write (Stream, Container.Count);
if Container.Count = 0 then
return;
end if;
Write_Children (Root_Node (Container));
end Write;
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Position : Cursor)
is
begin
raise Program_Error with "attempt to write tree cursor to stream";
end Write;
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Item : Reference_Type)
is
begin
raise Program_Error with "attempt to stream reference";
end Write;
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Item : Constant_Reference_Type)
is
begin
raise Program_Error with "attempt to stream reference";
end Write;
end Ada.Containers.Bounded_Multiway_Trees;
|
-------------------------------------------------------------------------------
-- --
-- Coffee Clock --
-- --
-- Copyright (C) 2016-2017 Fabien Chouteau --
-- --
-- Coffee Clock 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. --
-- --
-- Coffee Clock 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 We Noise Maker. If not, see <http://www.gnu.org/licenses/>. --
-- --
-------------------------------------------------------------------------------
with Giza.Colors; use Giza.Colors;
with Dialog_Window; use Dialog_Window;
with ok_80x80;
with cancel_80x80;
with calandar_80x80;
with up_200x100;
with down_200x100;
with Date_Widget; use Date_Widget;
package body Date_Select_Window is
package Up_Bmp renames up_200x100;
package Down_Bmp renames down_200x100;
-------------
-- On_Init --
-------------
overriding procedure On_Init
(This : in out Instance)
is
Size : constant Size_T := This.Get_Size;
begin
On_Init (Parent (This));
This.Up_M.Disable_Frame;
This.Up_M.Disable_Background;
This.Up_M.Set_Image (Up_Bmp.Image);
This.Up_M.Set_Size ((Up_Bmp.Image.Size.W, Up_Bmp.Image.Size.H));
This.Add_Child (This.Up_M'Unchecked_Access, (50, 10));
This.Up_D.Disable_Frame;
This.Up_D.Disable_Background;
This.Up_D.Set_Image (Up_Bmp.Image);
This.Up_D.Set_Size ((Up_Bmp.Image.Size.W, Up_Bmp.Image.Size.H));
This.Add_Child (This.Up_D'Unchecked_Access, (250, 10));
This.Up_Y.Disable_Frame;
This.Up_Y.Disable_Background;
This.Up_Y.Set_Image (Up_Bmp.Image);
This.Up_Y.Set_Size ((Up_Bmp.Image.Size.W, Up_Bmp.Image.Size.H));
This.Add_Child (This.Up_Y'Unchecked_Access, (450, 10));
This.Down_M.Disable_Frame;
This.Down_M.Disable_Background;
This.Down_M.Set_Image (Down_Bmp.Image);
This.Down_M.Set_Size ((Up_Bmp.Image.Size.W, Up_Bmp.Image.Size.H));
This.Add_Child (This.Down_M'Unchecked_Access, (50, 370));
This.Down_D.Disable_Frame;
This.Down_D.Disable_Background;
This.Down_D.Set_Image (Down_Bmp.Image);
This.Down_D.Set_Size ((Up_Bmp.Image.Size.W, Up_Bmp.Image.Size.H));
This.Add_Child (This.Down_D'Unchecked_Access, (250, 370));
This.Down_Y.Disable_Frame;
This.Down_Y.Disable_Background;
This.Down_Y.Set_Image (Down_Bmp.Image);
This.Down_Y.Set_Size ((Up_Bmp.Image.Size.W, Up_Bmp.Image.Size.H));
This.Add_Child (This.Down_Y'Unchecked_Access, (450, 370));
This.Set_Top_Image (ok_80x80.Image);
This.Set_Icon_Image (calandar_80x80.Image);
This.Set_Bottom_Image (cancel_80x80.Image);
This.Set_Background (Black);
This.Date.Set_Size (This.Date.Required_Size);
This.Add_Child (This.Date'Unchecked_Access,
((Size.W - This.Date.Get_Size.W) / 2,
(Size.H - This.Date.Get_Size.H) / 2));
end On_Init;
------------------
-- On_Displayed --
------------------
overriding procedure On_Displayed
(This : in out Instance)
is
pragma Unreferenced (This);
begin
null;
end On_Displayed;
---------------
-- On_Hidden --
---------------
overriding procedure On_Hidden
(This : in out Instance)
is
pragma Unreferenced (This);
begin
null;
end On_Hidden;
-----------------------
-- On_Position_Event --
-----------------------
overriding function On_Position_Event
(This : in out Instance;
Evt : Position_Event_Ref;
Pos : Point_T)
return Boolean
is
Date : HAL.Real_Time_Clock.RTC_Date;
begin
if On_Position_Event (Parent (This), Evt, Pos) then
Date := This.Date.Get_Date;
if This.Up_M.Active then
This.Up_M.Set_Active (False);
Date.Month := Next (Date.Month);
elsif This.Down_M.Active then
This.Down_M.Set_Active (False);
Date.Month := Prev (Date.Month);
elsif This.Up_D.Active then
This.Up_D.Set_Active (False);
Date.Day := Next (Date.Day);
elsif This.Down_D.Active then
This.Down_D.Set_Active (False);
Date.Day := Prev (Date.Day);
elsif This.Up_Y.Active then
This.Up_Y.Set_Active (False);
Date.Year := Next (Date.Year);
elsif This.Down_Y.Active then
This.Down_Y.Set_Active (False);
Date.Year := Prev (Date.Year);
end if;
This.Date.Set_Date (Date);
return True;
else
return False;
end if;
end On_Position_Event;
--------------
-- Set_Date --
--------------
procedure Set_Date
(This : in out Instance;
Date : HAL.Real_Time_Clock.RTC_Date)
is
begin
This.Date.Set_Date (Date);
end Set_Date;
--------------
-- Get_Date --
--------------
function Get_Date (This : Instance) return HAL.Real_Time_Clock.RTC_Date
is (This.Date.Get_Date);
end Date_Select_Window;
|
with LMCP_Messages;
with AFRL.CMASI.AutomationRequest; use AFRL.CMASI.AutomationRequest;
with AFRL.CMASI.EntityState; use AFRL.CMASI.EntityState;
with AFRL.CMASI.KeyValuePair; use AFRL.CMASI.KeyValuePair;
with AFRL.CMASI.Location3D; use AFRL.CMASI.Location3D;
with AFRL.CMASI.VehicleAction; use AFRL.CMASI.VehicleAction;
with AFRL.CMASI.Waypoint; use AFRL.CMASI.Waypoint;
with AFRL.Impact.ImpactAutomationRequest; use AFRL.Impact.ImpactAutomationRequest;
with AVTAS.LMCP.Object;
with UxAS.Messages.lmcptask.AssignmentCostMatrix; use UxAS.Messages.lmcptask.AssignmentCostMatrix;
with UxAS.Messages.lmcptask.TaskAutomationRequest; use UxAS.Messages.lmcptask.TaskAutomationRequest;
with UxAS.Messages.lmcptask.TaskPlanOptions; use UxAS.Messages.lmcptask.TaskPlanOptions;
with UxAS.Messages.lmcptask.UniqueAutomationRequest; use UxAS.Messages.lmcptask.UniqueAutomationRequest;
with UxAS.Messages.lmcptask.UniqueAutomationResponse; use UxAS.Messages.lmcptask.UniqueAutomationResponse;
with UxAS.Messages.Route.RouteConstraints; use UxAS.Messages.Route.RouteConstraints;
with UxAS.Messages.Route.RoutePlan; use UxAS.Messages.Route.RoutePlan;
with UxAS.Messages.Route.RoutePlanRequest; use UxAS.Messages.Route.RoutePlanRequest;
with UxAS.Messages.Route.RoutePlanResponse; use UxAS.Messages.Route.RoutePlanResponse;
with UxAS.Messages.Route.RouteRequest; use UxAS.Messages.Route.RouteRequest;
package LMCP_Message_Conversions is
function As_AssignmentCostMatrix_Message (Msg : not null AssignmentCostMatrix_Any) return LMCP_Messages.AssignmentCostMatrix;
function As_RouteConstraints_Message (Msg : not null RouteConstraints_Any) return LMCP_Messages.RouteConstraints;
function As_Location3D_Message (Msg : not null Location3D_Any) return LMCP_Messages.Location3D;
function As_VehicleAction_Message (Msg : not null VehicleAction_Any) return LMCP_Messages.VehicleAction;
function As_KeyValuePair_Message (Msg : not null KeyValuePair_Acc) return LMCP_Messages.KeyValuePair;
function As_Waypoint_Message (Msg : not null Waypoint_Any) return LMCP_Messages.Waypoint;
function As_RoutePlan_Message (Msg : not null RoutePlan_Any) return LMCP_Messages.RoutePlan;
function As_RoutePlanResponse_Message (Msg : not null RoutePlanResponse_Any) return LMCP_Messages.RoutePlanResponse;
function As_RouteRequest_Message (Msg : not null RouteRequest_Any) return LMCP_Messages.RouteRequest;
function As_RoutePlanRequest_Message (Msg : not null RoutePlanRequest_Any) return LMCP_Messages.RoutePlanRequest;
function As_AutomationRequest_Message (Msg : not null AutomationRequest_Any) return LMCP_Messages.AutomationRequest;
function As_TaskAutomationRequest_Message (Msg : not null TaskAutomationRequest_Any) return LMCP_Messages.TaskAutomationRequest;
function As_ImpactAutomationRequest_Message (Msg : not null ImpactAutomationRequest_Any) return LMCP_Messages.ImpactAutomationRequest;
function As_UniqueAutomationRequest_Message (Msg : not null UniqueAutomationRequest_Any) return LMCP_Messages.UniqueAutomationRequest;
function As_UniqueAutomationResponse_Message (Msg : not null UniqueAutomationResponse_Any) return LMCP_Messages.UniqueAutomationResponse;
function As_TaskPlanOption_Message (Msg : not null TaskPlanOptions_Any) return LMCP_Messages.TaskPlanOptions;
function As_EntityState_Message (Msg : not null EntityState_Any) return LMCP_Messages.EntityState;
function As_Object_Any (Msg : LMCP_Messages.Message_Root'Class) return AVTAS.LMCP.Object.Object_Any;
end LMCP_Message_Conversions;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . B B . B O A R D _ S U P P O R T --
-- --
-- B o d y --
-- --
-- Copyright (C) 1999-2002 Universidad Politecnica de Madrid --
-- Copyright (C) 2003-2005 The European Space Agency --
-- Copyright (C) 2003-2021, AdaCore --
-- --
-- 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. --
-- --
-- The port of GNARL to bare board targets was initially developed by the --
-- Real-Time Systems Group at the Technical University of Madrid. --
-- --
------------------------------------------------------------------------------
with System.BB.CPU_Specific;
with System.BB.Parameters;
with System.Machine_Code;
with Interfaces; use Interfaces;
package body System.BB.Board_Support is
use System.BB.CPU_Specific;
use System.BB.Parameters;
use System.Machine_Code;
----------------------
-- Initialize_Board --
----------------------
procedure Initialize_Board is
begin
null;
end Initialize_Board;
package body Interrupts is
function Priority_From_Interrupt_ID
(Interrupt : BB.Interrupts.Interrupt_ID)
return Any_Priority;
-- On x86-64 the priority of an Interrupt is encoded in the upper 4-bits
-- of the 8-bit Interrupt ID.
--------------------------------
-- Priority_From_Interrupt_ID --
--------------------------------
function Priority_From_Interrupt_ID
(Interrupt : BB.Interrupts.Interrupt_ID)
return Any_Priority
is
function Shift_Right
(Value : Any_Priority;
Amount : Natural) return Any_Priority
with Import, Convention => Intrinsic;
-- Used to retrieve the interrupt priority that is encoded in the
-- top 4-bits of the Interrupt ID.
begin
return Shift_Right (System.Any_Priority (Interrupt), 4);
end Priority_From_Interrupt_ID;
-------------------------------
-- Install_Interrupt_Handler --
-------------------------------
procedure Install_Interrupt_Handler
(Interrupt : BB.Interrupts.Interrupt_ID;
Prio : Interrupt_Priority)
is
begin
-- On x86-64 there's is nothing for us to do to enable the interrupt
-- in the local APIC. However, we use this opportunity to check the
-- priority of the protected object corresponds with the priority of
-- the Interrupt Vector since the upper 4-bits of the 8-bit vector ID
-- encodes the priority of the protected object.
if Prio /= Priority_Of_Interrupt (Interrupt) then
raise Program_Error with
"protected object for interrupt " & Interrupt'Image & " " &
"requires aspect Interrupt_Priority => " &
Priority_Of_Interrupt (Interrupt)'Image;
end if;
end Install_Interrupt_Handler;
---------------------------
-- Priority_Of_Interrupt --
---------------------------
function Priority_Of_Interrupt
(Interrupt : System.BB.Interrupts.Interrupt_ID)
return System.Any_Priority
is
begin
-- Assert that it is a real interrupt
pragma Assert (Interrupt /= System.BB.Interrupts.No_Interrupt);
-- Convert the hardware priority to an Ada priority
return System.Interrupt_Priority'First - 1 +
Priority_From_Interrupt_ID (Interrupt);
end Priority_Of_Interrupt;
----------------
-- Power_Down --
----------------
procedure Power_Down is
begin
Asm ("hlt", Volatile => True);
end Power_Down;
--------------------------
-- Set_Current_Priority --
--------------------------
procedure Set_Current_Priority (Priority : Integer) is
Hardware_Priority : Unsigned_64;
begin
Hardware_Priority :=
(if Priority in Interrupt_Priority then
Unsigned_64 (Priority - Interrupt_Priority'First + 1)
else 0);
-- Move the hardware priority into the Task Priority Register, CR8
Asm
("movq %0, %%cr8",
Inputs =>
Unsigned_64'Asm_Input ("r", Hardware_Priority),
Volatile => True);
end Set_Current_Priority;
end Interrupts;
package body Time is
-- For x86-64 we can generally determine the clock speed from the
-- the information provided from processor. Consequently, we set the
-- granularity of Ada.Real_Time to nanoseconds and convert between
-- hardware and Ada.Real_Time time bases here in this package, similar
-- to what is done in other operating systems.
-- To facilitate the conversion between hardware and Ada.Real_Time time
-- bases we use clock frequencies in kilohertz so we do not unduly cap
-- the range of Ada.Real_Time.Time due to the overflow in the
-- conversion.
Ticks_Per_Millisecond : constant := Ticks_Per_Second / 1_000;
---------------------------
-- Clear_Alarm_Interrupt --
---------------------------
procedure Clear_Alarm_Interrupt is
begin
null;
end Clear_Alarm_Interrupt;
---------------------------
-- Install_Alarm_Handler --
---------------------------
procedure Install_Alarm_Handler
(Handler : BB.Interrupts.Interrupt_Handler) is
begin
BB.Interrupts.Attach_Handler
(Handler,
APIC_Timer_Interrupt_ID,
Interrupts.Priority_Of_Interrupt (APIC_Timer_Interrupt_ID));
end Install_Alarm_Handler;
----------------
-- Read_Clock --
----------------
function Read_Clock return BB.Time.Time is
begin
-- Read the raw clock and covert it to the Time time base
return
BB.Time.Time ((Read_Raw_Clock * Ticks_Per_Millisecond) /
TSC_Frequency_In_kHz);
end Read_Clock;
---------------
-- Set_Alarm --
---------------
procedure Set_Alarm (Ticks : BB.Time.Time)
is
-- Convert Ticks to the hardware time base to minimise the number
-- of conversions we need to do.
Raw_Alarm_Time : constant Unsigned_64 :=
(Unsigned_64 (Ticks) * TSC_Frequency_In_kHz) /
Ticks_Per_Millisecond;
Now : constant Unsigned_64 := Read_Raw_Clock;
Time_To_Alarm : constant Unsigned_64 :=
(if Raw_Alarm_Time > (Now + APIC_Timer_Divider)
then (Raw_Alarm_Time - Now) / APIC_Timer_Divider
else 1);
-- The Raw_Alarm_Time is compared against the current time plus the
-- APIC_Timer_Divider because we don't want Time_To_Alarm to be set
-- to zero after the divide.
Timer_Value : Unsigned_32;
-- Value of the timer that we will set
begin
Timer_Value :=
(if Time_To_Alarm > Unsigned_64 (Unsigned_32'Last)
then Unsigned_32'Last
else Unsigned_32 (Time_To_Alarm));
Local_APIC_Timer_Initial_Count := APIC_Time (Timer_Value);
end Set_Alarm;
end Time;
package body Multiprocessors is separate;
end System.BB.Board_Support;
|
WITH Text_Io; USE Text_Io;
PROCEDURE ShowBrd IS
--------------------------------------------------------------------
--| Program : ShowBrd
Version : Constant STRING := "0.2";
--------------------------------------------------------------------
--| Abstract : Read a Mah Jongg SAV file and display the first level.
--------------------------------------------------------------------
--| Library : (none)
--| Compiler/System : Meridian Ada
--| Author : John Dalbey Date : 3/95
--| References : Mah Jongg Requirements Document and Specification
--------------------------------------------------------------------
-- VERSION HISTORY:
-- Version 0.1: Prototype.
-- Version 0.2: Modularized.
-- Asks user for a level, but this version ignores it.
--------------------------------------------------------------------
PACKAGE My_Int_Io IS NEW Text_Io.Integer_Io (Integer);
RowBound : Constant INTEGER := 9;
ColBound : Constant CHARACTER := 'O';
LayerBound : Constant INTEGER := 5;
FileName : Constant STRING (1..7) := "mah.sav"; -- the OS filename
SUBTYPE Rows is INTEGER RANGE 1 .. RowBound; -- Row range
SUBTYPE Cols is CHARACTER RANGE 'A' .. ColBound; -- Column range
SUBTYPE Layers is INTEGER RANGE 1 .. LayerBound; -- Layers high (1 is bottom, 5 is top)
SUBTYPE TileValue is INTEGER RANGE -1 .. 42; -- Legal tile values
TYPE Boards IS ARRAY (Rows, Cols) OF TileValue;
PROCEDURE Load_Board
(TilesLeft: OUT Natural; -- tiles left to remove from board
BoardNum : OUT Natural; -- the board sequence number
TheBoard : OUT Boards -- the structure to store the tiles in
) IS
--
-- Load the array with tile values from the saved file.
--
Sav_File: Text_Io.File_Type; -- the file type for the saved file
TheSeed : Integer; -- an input seed (ignored)
Tile : TileValue; -- an input tile value
BEGIN
-- Open the .SAV file
Text_Io.Open (Sav_File, Text_Io.In_File, FileName);
-- The file has a header of four numbers which must be read first.
My_Int_IO.Get (Sav_File, TilesLeft);
My_Int_IO.Get (Sav_File, BoardNum);
My_Int_IO.Get (Sav_File, Tile); -- Read and ignore 2 unknown values
My_Int_IO.Get (Sav_File, TheSeed);
FOR dummy in Rows LOOP -- Read and ignore the first column
My_Int_IO.Get(Sav_File, Tile);
END LOOP;
-- Now read the first layer of tiles (9 rows by 17 columns) into
-- the array.
FOR Col IN Cols LOOP
FOR Row IN Rows LOOP
-- Read a tile value from the file into the board
My_Int_IO.Get (Sav_File, TheBoard (Row, Col));
END LOOP;
END LOOP;
Text_Io.Close (Sav_File);
END Load_Board;
PROCEDURE Show_Labels
(TilesLeft: IN Natural; -- tiles left to remove from board
BoardNum : IN Natural; -- the board sequence number
LayerNum : IN Layers -- The layer number
) IS
--
-- clear the screen, show header info and column labels
--
BEGIN
Put (Ascii.Esc);
Put ("[2J");
Put ("Board number: ");
My_Int_Io.Put (BoardNum);
New_Line;
Put ("Tiles left: ");
My_Int_Io.Put (TilesLeft);
New_Line;
Put ("Layer : ");
My_Int_Io.Put (LayerNum, 2);
New_Line;
Put (" col A B C D E F G H I J K L M "&
"N O");
New_Line;
Put (" - - - - - - - - - - - - - "&
"- -");
New_Line;
Put ("row");
New_Line;
END Show_Labels;
PROCEDURE Show_Layer (LayerNum: IN Layers; TheBoard: IN Boards) IS
--
-- Display the tiles from the specified layer
--
BEGIN
-- Consider each row in turn
FOR Row IN Rows LOOP
My_Int_Io.Put (Row, 2); -- display the row label
Put (" | ");
-- loop through columns, showing each tile value on this row
FOR Col IN Cols LOOP
My_Int_Io.Put (TheBoard (Row, Col), Width=>3);
Put (" ");
END LOOP;
New_Line;
END LOOP;
New_Line;
END Show_Layer;
PROCEDURE Do_Main IS
--
-- Control obtaining input and calling output routines
--
TilesLeft : Natural; -- tiles left to remove from board
BoardNum : Natural; -- the board sequence number
TheBoard : Boards; -- the structure to store the tiles in
Layer : INTEGER RANGE 0 .. LayerBound; -- which layer user wants to see
BEGIN -- main
Put ("Show Board V");
Put_Line (Version);
Load_Board (TilesLeft, BoardNum, TheBoard); -- go load the board
-- Ask user what layer they want to see
Put ("Layer? (1 - 5, 0 to quit) ");
My_Int_Io.Get (Layer);
-- repeat until user enters a zero or > 5
WHILE Layer > 0 LOOP
Show_Labels(TilesLeft, BoardNum, Layer); -- Show the label markers
Show_Layer (Layer, TheBoard); -- Go display the layer
Put ("Layer? (1 - 5, 0 to quit) "); -- Prompt for another display
My_Int_Io.Get (Layer); -- obtain user's choice
END LOOP;
EXCEPTION
WHEN Text_Io.Name_Error =>
Text_Io.Put (" Error - File 'mah.sav' doesn't exist in this directory!");
Text_Io.New_Line;
END Do_Main;
BEGIN
Do_Main;
END ShowBrd;
|
-- Práctica 4: César Borao Moratinos (Hash_Maps_G_Open, Test Program)
with Ada.Text_IO;
with Ada.Strings.Unbounded;
with Ada.Numerics.Discrete_Random;
with Hash_Maps_G;
procedure Hash_Maps_Test is
package ASU renames Ada.Strings.Unbounded;
package ATIO renames Ada.Text_IO;
HASH_SIZE: constant := 10;
type Hash_Range is mod HASH_SIZE;
function Natural_Hash (N: Natural) return Hash_Range is
begin
return Hash_Range'Mod(N);
end Natural_Hash;
package Maps is new Hash_Maps_G (Key_Type => Natural,
Value_Type => Natural,
"=" => "=",
Hash_Range => Hash_Range,
Hash => Natural_Hash,
Max => 15);
procedure Print_Map (M : Maps.Map) is
C: Maps.Cursor := Maps.First(M);
begin
Ada.Text_IO.Put_Line ("Map");
Ada.Text_IO.Put_Line ("===");
while Maps.Has_Element(C) loop
Ada.Text_IO.Put_Line (Natural'Image(Maps.Element(C).Key) & " " &
Natural'Image(Maps.Element(C).Value));
Maps.Next(C);
end loop;
end Print_Map;
procedure Do_Put (M: in out Maps.Map; K: Natural; V: Natural) is
begin
Ada.Text_IO.New_Line;
ATIO.Put_Line("Putting" & Natural'Image(K));
Maps.Put (M, K, V);
Print_Map(M);
exception
when Maps.Full_Map =>
Ada.Text_IO.Put_Line("Full_Map");
end Do_Put;
procedure Do_Get (M: in out Maps.Map; K: Natural) is
V: Natural;
Success: Boolean;
begin
Ada.Text_IO.New_Line;
ATIO.Put_Line("Getting" & Natural'Image(K));
Maps.Get (M, K, V, Success);
if Success then
Ada.Text_IO.Put_Line("Value:" & Natural'Image(V));
Print_Map(M);
else
Ada.Text_IO.Put_Line("Element not found!");
end if;
end Do_Get;
procedure Do_Delete (M: in out Maps.Map; K: Natural) is
Success: Boolean;
begin
Ada.Text_IO.New_Line;
ATIO.Put_Line("Deleting" & Natural'Image(K));
Maps.Delete (M, K, Success);
if Success then
Print_Map(M);
else
Ada.Text_IO.Put_Line("Element not found!");
end if;
end Do_Delete;
A_Map : Maps.Map;
begin
-- First puts
Do_Put (A_Map, 10, 10);
Do_Put (A_Map, 11, 20);
Do_Put (A_Map, 30, 30);
Do_Put (A_Map, 99, 20);
Do_Put (A_Map, 50, 50);
Do_Put (A_Map, 15, 15);
Do_Put (A_Map, 16, 16);
Do_Put (A_Map, 40, 40);
Do_Put (A_Map, 25, 25);
Do_Put (A_Map, 90, 50);
Do_Put (A_Map, 150, 50);
-- Now deletes
Do_Delete (A_Map, 50);
Do_Delete (A_Map, 99);
Do_Delete (A_Map, 30);
Do_Delete (A_Map, 40);
Do_Delete (A_Map, 50);
Do_Delete (A_Map, 40);
Do_Delete (A_Map, 25);
Do_Get (A_Map, 15);
-- Now gets
Do_Get (A_Map, 150);
Do_Get (A_Map, 30);
Do_Get (A_Map, 100);
end Hash_Maps_Test;
|
-- Standard Ada library specification
-- Copyright (c) 2004-2016 AXE Consultants
-- Copyright (c) 2004, 2005, 2006 Ada-Europe
-- Copyright (c) 2000 The MITRE Corporation, Inc.
-- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc.
-- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual
---------------------------------------------------------------------------
package Ada.Strings.UTF_Encoding is
pragma Pure (UTF_Encoding);
-- Declarations common to the string encoding packages
type Encoding_Scheme is (UTF_8, UTF_16BE, UTF_16LE);
subtype UTF_String is String;
subtype UTF_8_String is String;
subtype UTF_16_Wide_String is Wide_String;
Encoding_Error : exception;
BOM_8 : constant UTF_8_String :=
Character'Val(16#EF#) &
Character'Val(16#BB#) &
Character'Val(16#BF#);
BOM_16BE : constant UTF_String :=
Character'Val(16#FE#) &
Character'Val(16#FF#);
BOM_16LE : constant UTF_String :=
Character'Val(16#FF#) &
Character'Val(16#FE#);
BOM_16 : constant UTF_16_Wide_String :=
(1 => Wide_Character'Val(16#FEFF#));
function Encoding (Item : UTF_String;
Default : Encoding_Scheme := UTF_8)
return Encoding_Scheme;
end Ada.Strings.UTF_Encoding;
|
-- This spec has been automatically generated from msp430g2553.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with System;
-- Comparator A
package MSP430_SVD.COMPARATOR_A is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- Comp. A Internal Reference Select 0
type CACTL1_CAREF_Field is
(-- Comp. A Int. Ref. Select 0 : Off
Caref_0,
-- Comp. A Int. Ref. Select 1 : 0.25*Vcc
Caref_1,
-- Comp. A Int. Ref. Select 2 : 0.5*Vcc
Caref_2,
-- Comp. A Int. Ref. Select 3 : Vt
Caref_3)
with Size => 2;
for CACTL1_CAREF_Field use
(Caref_0 => 0,
Caref_1 => 1,
Caref_2 => 2,
Caref_3 => 3);
-- Comparator A Control 1
type CACTL1_Register is record
-- Comp. A Interrupt Flag
CAIFG : MSP430_SVD.Bit := 16#0#;
-- Comp. A Interrupt Enable
CAIE : MSP430_SVD.Bit := 16#0#;
-- Comp. A Int. Edge Select: 0:rising / 1:falling
CAIES : MSP430_SVD.Bit := 16#0#;
-- Comp. A enable
CAON : MSP430_SVD.Bit := 16#0#;
-- Comp. A Internal Reference Select 0
CAREF : CACTL1_CAREF_Field := MSP430_SVD.COMPARATOR_A.Caref_0;
-- Comp. A Internal Reference Enable
CARSEL : MSP430_SVD.Bit := 16#0#;
-- Comp. A Exchange Inputs
CAEX : MSP430_SVD.Bit := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for CACTL1_Register use record
CAIFG at 0 range 0 .. 0;
CAIE at 0 range 1 .. 1;
CAIES at 0 range 2 .. 2;
CAON at 0 range 3 .. 3;
CAREF at 0 range 4 .. 5;
CARSEL at 0 range 6 .. 6;
CAEX at 0 range 7 .. 7;
end record;
-- CACTL2_P2CA array
type CACTL2_P2CA_Field_Array is array (0 .. 4) of MSP430_SVD.Bit
with Component_Size => 1, Size => 5;
-- Type definition for CACTL2_P2CA
type CACTL2_P2CA_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- P2CA as a value
Val : MSP430_SVD.UInt5;
when True =>
-- P2CA as an array
Arr : CACTL2_P2CA_Field_Array;
end case;
end record
with Unchecked_Union, Size => 5;
for CACTL2_P2CA_Field use record
Val at 0 range 0 .. 4;
Arr at 0 range 0 .. 4;
end record;
-- Comparator A Control 2
type CACTL2_Register is record
-- Comp. A Output
CAOUT : MSP430_SVD.Bit := 16#0#;
-- Comp. A Enable Output Filter
CAF : MSP430_SVD.Bit := 16#0#;
-- Comp. A +Terminal Multiplexer
P2CA : CACTL2_P2CA_Field := (As_Array => False, Val => 16#0#);
-- Comp. A Short + and - Terminals
CASHORT : MSP430_SVD.Bit := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for CACTL2_Register use record
CAOUT at 0 range 0 .. 0;
CAF at 0 range 1 .. 1;
P2CA at 0 range 2 .. 6;
CASHORT at 0 range 7 .. 7;
end record;
-- CAPD array
type CAPD_Field_Array is array (0 .. 7) of MSP430_SVD.Bit
with Component_Size => 1, Size => 8;
-- Comparator A Port Disable
type CAPD_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- CAPD as a value
Val : MSP430_SVD.Byte;
when True =>
-- CAPD as an array
Arr : CAPD_Field_Array;
end case;
end record
with Unchecked_Union, Size => 8, Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for CAPD_Register use record
Val at 0 range 0 .. 7;
Arr at 0 range 0 .. 7;
end record;
-----------------
-- Peripherals --
-----------------
-- Comparator A
type COMPARATOR_A_Peripheral is record
-- Comparator A Control 1
CACTL1 : aliased CACTL1_Register;
-- Comparator A Control 2
CACTL2 : aliased CACTL2_Register;
-- Comparator A Port Disable
CAPD : aliased CAPD_Register;
end record
with Volatile;
for COMPARATOR_A_Peripheral use record
CACTL1 at 16#1# range 0 .. 7;
CACTL2 at 16#2# range 0 .. 7;
CAPD at 16#3# range 0 .. 7;
end record;
-- Comparator A
COMPARATOR_A_Periph : aliased COMPARATOR_A_Peripheral
with Import, Address => COMPARATOR_A_Base;
end MSP430_SVD.COMPARATOR_A;
|
--
-- Copyright 2018 The wookey project team <wookey@ssi.gouv.fr>
-- - Ryad Benadjila
-- - Arnauld Michelizza
-- - Mathieu Renard
-- - Philippe Thierry
-- - Philippe Trebuchet
--
-- 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 types.c;
package c.kernel is
procedure log (s : types.c.c_string)
with
convention => c,
import => true,
external_name => "dbg_log",
global => null;
procedure flush
with
convention => c,
import => true,
external_name => "dbg_flush",
global => null;
function get_random
(s : out types.c.c_string;
len : in unsigned_16)
return types.c.t_retval
with
convention => c,
import => true,
external_name => "get_random",
global => null;
function get_random_u32
(rng : out unsigned_32)
return types.c.t_retval
with
convention => c,
import => true,
external_name => "get_random_u32",
global => null;
end c.kernel;
|
package Other_Basic_Subprogram_Calls is
function Other_F1 return Integer;
procedure Other_P1;
end Other_Basic_Subprogram_Calls;
|
-- with STM32.SPI; use STM32.SPI;
-- with HAL.SPI;
with usb_handler; pragma Unreferenced (usb_handler);
with Ada.Interrupts.Names;
with Cortex_M.NVIC; use Cortex_M.NVIC;
with STM32_SVD.RCC; use STM32_SVD.RCC;
with Config;
with spi_accel;
with Ada.Real_Time; use Ada.Real_Time;
with sbus_commander; pragma Unreferenced (sbus_commander);
package body cc3df4revo.Board is
package IC renames Interfaces.C;
-- Doing receive (if any)
procedure usb_receive (message : out ASB32.Bounded_String) is
buffer : IC.char_array (IC.size_t (1) .. IC.size_t (ASB32.Max_Length));
size : IC.unsigned_short := ada_usbapi_rx (buffer) -- usb call!
with Unreferenced;
begin
message := ASB32.To_Bounded_String (IC.To_Ada (buffer, True));
end usb_receive;
-- Doing sending
procedure usb_transmit (message : in String) is
begin
ada_usbapi_tx (message'Address, message'Length);
end usb_transmit;
--
-- Initialization
--
procedure Initialize is
unused : Interfaces.C.int;
begin
----
-- UART pins
----
-- Enable_Clock (SBUS_RX & SBUS_TX);
-- Configure_IO (SBUS_RX,
-- Config => (Mode => Mode_AF,
-- AF => SBUS_AF,
-- AF_Output_Type => Open_Drain,
-- AF_Speed => Speed_25MHz,
-- Resistors => Pull_Up));
-- Configure_IO (SBUS_TX,
-- Config => (Mode => Mode_AF,
-- AF => SBUS_AF,
-- AF_Output_Type => Push_Pull,
-- AF_Speed => Speed_25MHz,
-- Resistors => Pull_Up));
-- Enable_Clock (SBUS1);
--
----
-- Configure USART for SBUS
----
-- Disable (SBUS1);
-- Set_Baud_Rate (SBUS1, 100_000);
-- Set_Mode (SBUS1, Tx_Rx_Mode);
-- Set_Stop_Bits (SBUS1, Stopbits_2);
-- Set_Word_Length (SBUS1, Word_Length_8);
-- Set_Parity (SBUS1, Even_Parity);
-- Set_Flow_Control (SBUS1, No_Flow_Control);
-- Enable (SBUS1);
--
-- -- Configuration of SBUS finished.
-- -- Now let's set up SPI
-- declare
-- IMU_SPI : SPI_Port renames SPI_1;
-- SPI_GPIO_Conf : GPIO_Port_Configuration;
-- SPI_Conf : SPI_Configuration;
-- SPI5_SCK : GPIO_Point renames PA5;
-- SPI5_MISO : GPIO_Point renames PA6;
-- SPI5_MOSI : GPIO_Point renames PA7;
-- SPI_Pins : constant GPIO_Points := (SPI5_SCK, SPI5_MISO, SPI5_MOSI);
-- begin
-- Enable_Clock (SPI_Pins);
-- Enable_Clock (IMU_SPI);
--
-- SPI_GPIO_Conf := (Mode => Mode_AF,
-- AF => GPIO_AF_SPI1_5,
-- AF_Speed => Speed_2MHz,
-- AF_Output_Type => Push_Pull,
-- Resistors => Floating);
-- Configure_IO (SPI_Pins, SPI_GPIO_Conf);
-- Reset (IMU_SPI);
--
-- if not Enabled (IMU_SPI) then
-- SPI_Conf :=
-- (Direction => D2Lines_FullDuplex,
-- Mode => Master,
-- Data_Size => HAL.SPI.Data_Size_8b,
-- Clock_Polarity => Low,
-- Clock_Phase => P1Edge,
-- Slave_Management => Software_Managed,
-- Baud_Rate_Prescaler => BRP_2,
-- First_Bit => MSB,
-- CRC_Poly => 7);
-- Configure (IMU_SPI, SPI_Conf);
-- -- TODO: delay 10ms
-- STM32.SPI.Enable (IMU_SPI);
-- end if;
-- end;
--
-- Configure_PWM_Timer (MOTOR_123_Timer'Access, 2_000_000); -- 2kHz
-- M1.Attach_PWM_Channel
-- (MOTOR_123_Timer'Access,
-- MOTOR_1_Channel,
-- MOTOR_1,
-- MOTOR_1_AF);
-- M1.Enable_Output;
-- M1.Set_Duty_Cycle (0);
--
-- USB
--
RCC_Periph.AHB2ENR.OTGFSEN := True;
Enable_Clock (PA11);
Enable_Clock (PA12);
Enable_Clock (PA9);
Configure_IO (PA9,
(Mode => Mode_In,
Resistors => Floating));
Configure_IO (PA11 & PA12,
(Mode => Mode_AF,
Resistors => Floating,
AF_Output_Type => Push_Pull,
AF_Speed => Speed_Very_High,
AF => GPIO_AF_OTG_FS_10));
unused := ada_usbapi_setup;
Enable_Clock (Config.SIGNAL_LED);
Configure_IO (Config.SIGNAL_LED,
Config => (Mode => Mode_Out,
Resistors => Floating,
Output_Type => Push_Pull,
Speed => Speed_100MHz));
Cortex_M.NVIC.Enable_Interrupt (Interrupt_ID (Ada.Interrupts.Names.OTG_FS_Interrupt));
delay until Clock + Seconds (2); -- wait for reconnect usb
--
-- SPI init
--
spi_accel.init;
end Initialize;
end cc3df4revo.Board;
|
pragma Ada_2012;
with Ada.Numerics.Elementary_Functions;
-- with Ada.Text_IO; use Ada.Text_IO;
package body Notch_Example.Filters is
----------------
-- New_Filter --
----------------
function New_Filter
(F0 : Normalized_Frequency;
R : Float;
Gain : Float := 1.0)
return Filter_Access
is
use Ada.Numerics;
use Ada.Numerics.Elementary_Functions;
C : constant Float := -2.0 * Cos (2.0 * Pi * Float (F0));
begin
return new Notch_Filter'(Num0 => 1.0,
Num1 => C,
Num2 => 1.0,
Den1 => C * R,
Den2 => R * R,
Gain => Gain,
Status => (others => 0.0));
end New_Filter;
------------------
-- Sample_Ready --
------------------
procedure Sample_Ready (X : in out Notch_Filter) is
use Fakedsp;
Input : Float;
Output : Float;
function Saturate (X : Float) return Sample_Type;
-- Convert a Float to Sample_Type protecting against overflow
-- by saturating if X is outside the representable range.
-- It should never happen, but even if just one sample overflows,
-- the code dies on an exception; therefore, it is worth to
-- protect against overflows. (Meglio aver paura che toccarne...)
function Saturate (X : Float) return Sample_Type
is (if X > Float (Sample_Type'Last) then
Sample_Type'Last
elsif X < Float (Sample_Type'First) then
Sample_Type'First
else
Sample_Type (X));
begin
Input := Float (Sample_Type'(Card.Read_ADC));
-- Do you recognize the form I used?
Output := X.Num0 * Input + X.Status (1);
-- Note the '-' sign in the following lines!!!
-- Den1 and Den2 are the denominator coefficients, we must
-- use them with the '-' sign! (Yes... I too fell in it...)
X.Status (1) := - Output * X.Den1 + Input * X.Num1 + X.Status (2);
X.Status (2) := - Output * X.Den2 + Input * X.Num2;
-- Put_Line (Input'Img & ".," & Output'Img);
Card.Write_Dac (Saturate (Output * X.Gain));
end Sample_Ready;
end Notch_Example.Filters;
|
with AdaBase.Results.Field;
with AdaBase.Results.Converters;
with Ada.Strings.Unbounded;
with Ada.Integer_Text_IO;
with Ada.Text_IO;
with Ada.Wide_Text_IO;
procedure Spawn_Fields is
package TIO renames Ada.Text_IO;
package WIO renames Ada.Wide_Text_IO;
package IIO renames Ada.Integer_Text_IO;
package SU renames Ada.Strings.Unbounded;
package AR renames AdaBase.Results;
package ARC renames AdaBase.Results.Converters;
SF : AR.Field.Std_Field :=
AR.Field.spawn_field (binob => (50, 15, 4, 8));
BR : AR.Field.Std_Field :=
AR.Field.spawn_field (data =>
(datatype => AdaBase.ft_textual,
v13 => SU.To_Unbounded_String ("Baltimore Ravens")));
myset : AR.Settype (1 .. 3) :=
((enumeration => SU.To_Unbounded_String ("hockey")),
(enumeration => SU.To_Unbounded_String ("baseball")),
(enumeration => SU.To_Unbounded_String ("tennis")));
ST : AR.Field.Std_Field :=
AR.Field.spawn_field (enumset => ARC.convert (myset));
chain_len : Natural := SF.as_chain'Length;
begin
TIO.Put_Line ("Chain #1 length:" & chain_len'Img);
TIO.Put_Line ("Chain #1 type: " & SF.native_type'Img);
for x in 1 .. chain_len loop
TIO.Put (" block" & x'Img & " value:" & SF.as_chain (x)'Img);
IIO.Put (Item => Natural (SF.as_chain (x)), Base => 16);
TIO.Put_Line ("");
end loop;
TIO.Put ("Chain #1 converted to 4-byte unsigned integer:" &
SF.as_nbyte4'Img & " ");
IIO.Put (Item => Natural (SF.as_nbyte4), Base => 16);
TIO.Put_Line ("");
TIO.Put_Line ("");
WIO.Put_Line ("Convert BR field to wide string: " & BR.as_wstring);
TIO.Put_Line ("Convert ST settype to string: " & ST.as_string);
TIO.Put_Line ("Length of ST set: " & myset'Length'Img);
end Spawn_Fields;
|
with Ada.Integer_Text_IO;
procedure Tokeletes is
S : Natural;
begin
for N in 1..10000 loop
S := 0;
for I in 1..N-1 loop
if N mod I = 0 then
S := S + I;
end if;
end loop;
if S = N then
Ada.Integer_Text_IO.Put( N );
end if;
end loop;
end Tokeletes;
|
with
openGL.Errors,
openGL.Buffer,
openGL.Tasks,
GL.Binding,
ada.unchecked_Deallocation;
package body openGL.Primitive.long_indexed
is
---------
--- Forge
--
procedure define (Self : in out Item; Kind : in facet_Kind;
Indices : in long_Indices)
is
use Buffer.long_indices.Forge;
buffer_Indices : aliased long_Indices := (Indices'Range => <>);
begin
for Each in buffer_Indices'Range
loop
buffer_Indices (Each) := Indices (Each) - 1; -- Adjust indices to zero-based-indexing for GL.
end loop;
Self.facet_Kind := Kind;
Self.Indices := new Buffer.long_indices.Object' (to_Buffer (buffer_Indices'Access,
usage => Buffer.static_Draw));
end define;
function new_Primitive (Kind : in facet_Kind;
Indices : in long_Indices) return Primitive.long_indexed.view
is
Self : constant View := new Item;
begin
define (Self.all, Kind, Indices);
return Self;
end new_Primitive;
overriding
procedure destroy (Self : in out Item)
is
procedure free is new ada.unchecked_Deallocation (Buffer.long_indices.Object'Class,
Buffer.long_indices.view);
begin
Buffer.destroy (Self.Indices.all);
free (Self.Indices);
end destroy;
--------------
-- Attributes
--
procedure Indices_are (Self : in out Item; Now : in long_Indices)
is
use Buffer.long_indices;
buffer_Indices : aliased long_Indices := (Now'Range => <>);
begin
for Each in buffer_Indices'Range
loop
buffer_Indices (Each) := Now (Each) - 1; -- Adjust indices to zero-based-indexing for GL.
end loop;
Self.Indices.set (to => buffer_Indices);
end Indices_are;
--------------
-- Operations
--
overriding
procedure render (Self : in out Item)
is
use GL,
GL.Binding;
begin
Tasks.check;
openGL.Primitive.item (Self).render; -- Do base class render.
Self.Indices.enable;
glDrawElements (Thin (Self.facet_Kind),
gl.GLint (Self.Indices.Length),
GL_UNSIGNED_INT,
null);
Errors.log;
end render;
end openGL.Primitive.long_indexed;
|
with AWS.Response;
with AWS.Status;
package Hello_World_CB is
function HW_CB (Request: AWS.Status.Data) return AWS.Response.Data;
end Hello_World_CB;
|
private
with
ada.Containers.Vectors,
ada.Containers.hashed_Maps,
ada.Containers.ordered_Sets;
generic
package any_Math.any_Geometry.any_d3.any_Modeller
is
type Item is tagged private;
type View is access all Item;
--------------
-- Attributes
--
procedure add_Triangle (Self : in out Item; Vertex_1,
Vertex_2,
Vertex_3 : in Site);
function Triangle_Count (Self : in Item) return Natural;
function Model (Self : in Item) return a_Model;
function bounding_Sphere_Radius (Self : in out Item) return Real;
--
-- Caches the radius on 1st call.
--------------
-- Operations
--
procedure clear (Self : in out Item);
private
subtype Vertex is Site;
type my_Vertex is new Vertex;
--------------
-- Containers
--
function Hash (Site : in my_Vertex) return ada.Containers.Hash_type;
package Vertex_Maps_of_Index is new ada.Containers.hashed_Maps (my_Vertex,
Natural,
Hash,
"=");
subtype Vertex_Map_of_Index is Vertex_Maps_of_Index.Map;
package Vertex_Vectors is new Ada.Containers.Vectors (Positive, Vertex);
subtype Vertex_Vector is Vertex_Vectors.Vector;
subtype Index_Triangle is any_Geometry.Triangle;
function "<" (Left, Right : in Index_Triangle) return Boolean;
package Index_Triangle_Sets is new ada.Containers.ordered_Sets (Element_Type => Index_Triangle,
"<" => "<",
"=" => "=");
subtype Index_Triangle_Set is Index_Triangle_Sets.Set;
------------
-- Modeller
--
type Item is tagged
record
Triangles : Index_Triangle_Set;
Vertices : Vertex_Vector;
Index_Map : Vertex_Map_of_Index;
bounding_Sphere_Radius : Real := Real'First;
end record;
end any_Math.any_Geometry.any_d3.any_Modeller;
|
with
lumen.Window,
openGL.Model,
openGL.Visual,
openGL.Renderer.lean,
openGL.Camera,
openGL.Dolly,
openGL.frame_Counter;
package openGL.Demo
--
-- Provides a convenient method of setting up a simple openGL demo.
--
is
Window : lumen.Window.Window_handle;
Renderer : aliased openGL.Renderer.lean.item;
Camera : aliased openGL.Camera.item;
Dolly : openGL.Dolly.item (camera => Camera'unchecked_Access);
FPS_Counter : openGL.frame_Counter.item;
Done : Boolean := False;
function Models return openGL.Model.views;
--
-- Creates a set of models with one model of each kind.
procedure layout (the_Visuals : in openGL.Visual.views);
--
-- Layout the visuals in a grid fashion for viewing all at once.
procedure print_Usage (append_Message : in String := "");
procedure define (Name : in String;
Width : in Positive := 1000;
Height : in Positive := 1000);
procedure destroy;
end openGL.Demo;
|
-----------------------------------------------------------------------
-- EL.Beans -- Bean utilities
-- Copyright (C) 2011 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.Containers.Indefinite_Vectors;
with Util.Beans.Basic;
with EL.Contexts;
with EL.Expressions;
package EL.Beans is
pragma Preelaborate;
-- ------------------------------
-- Bean Initialization
-- ------------------------------
-- The <b>Param_Value</b> describes a bean property that must be initialized by evaluating the
-- associated EL expression. A list of <b>Param_Value</b> can be used to initialize several
-- bean properties of an object. The bean object must implement the <b>Bean</b> interface
-- with the <b>Set_Value</b> operation.
type Param_Value (Length : Natural) is record
Name : String (1 .. Length);
Value : EL.Expressions.Expression;
end record;
package Param_Vectors is
new Ada.Containers.Indefinite_Vectors (Index_Type => Positive,
Element_Type => Param_Value,
"=" => "=");
-- Add a parameter to initialize the bean property identified by the name <b>Name</b>
-- to the value represented by <b>Value</b>. The value string is evaluated as a string or
-- as an EL expression.
procedure Add_Parameter (Container : in out Param_Vectors.Vector;
Name : in String;
Value : in String;
Context : in EL.Contexts.ELContext'Class);
-- Initialize the bean object by evaluation the parameters and set the bean property.
-- Each parameter expression is evaluated by using the EL context. The value is then
-- set on the bean object by using the bean <b>Set_Value</b> procedure.
procedure Initialize (Bean : in out Util.Beans.Basic.Bean'Class;
Params : in Param_Vectors.Vector;
Context : in EL.Contexts.ELContext'Class);
end EL.Beans;
|
-- { dg-do compile }
-- { dg-options "-O -fdump-rtl-final" }
package body Unchecked_Convert9 is
procedure Proc is
L : Unsigned_32 := 16#55557777#;
begin
Var := Conv (L);
end;
end Unchecked_Convert9;
-- { dg-final { scan-rtl-dump-times "set \\(mem/v" 1 "final" } }
|
-----------------------------------------------------------------------
-- mat-formats - Format various types for the console or GUI interface
-- Copyright (C) 2015, 2021 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;
package body MAT.Formats is
use type MAT.Types.Target_Tick_Ref;
Hex_Prefix : constant Boolean := True;
Hex_Length : Positive := 16;
Conversion : constant String (1 .. 10) := "0123456789";
function Location (File : in Ada.Strings.Unbounded.Unbounded_String) return String;
-- Format a short description of a malloc event.
function Event_Malloc (Item : in MAT.Events.Target_Event_Type;
Related : in MAT.Events.Tools.Target_Event_Vector;
Start_Time : in MAT.Types.Target_Tick_Ref) return String;
-- Format a short description of a realloc event.
function Event_Realloc (Item : in MAT.Events.Target_Event_Type;
Related : in MAT.Events.Tools.Target_Event_Vector;
Start_Time : in MAT.Types.Target_Tick_Ref) return String;
-- Format a short description of a free event.
function Event_Free (Item : in MAT.Events.Target_Event_Type;
Related : in MAT.Events.Tools.Target_Event_Vector;
Start_Time : in MAT.Types.Target_Tick_Ref) return String;
-- ------------------------------
-- Set the size of a target address to format them.
-- ------------------------------
procedure Set_Address_Size (Size : in Positive) is
begin
Hex_Length := Size;
end Set_Address_Size;
-- ------------------------------
-- Format the PID into a string.
-- ------------------------------
function Pid (Value : in MAT.Types.Target_Process_Ref) return String is
begin
return Util.Strings.Image (Natural (Value));
end Pid;
-- ------------------------------
-- Format the address into a string.
-- ------------------------------
function Addr (Value : in MAT.Types.Target_Addr) return String is
Hex : constant String := MAT.Types.Hex_Image (Value, Hex_Length);
begin
if Hex_Prefix then
return "0x" & Hex;
else
return Hex;
end if;
end Addr;
-- ------------------------------
-- Format the size into a string.
-- ------------------------------
function Size (Value : in MAT.Types.Target_Size) return String is
Result : constant String := MAT.Types.Target_Size'Image (Value);
begin
if Result (Result'First) = ' ' then
return Result (Result'First + 1 .. Result'Last);
else
return Result;
end if;
end Size;
-- ------------------------------
-- Format the memory growth size into a string.
-- ------------------------------
function Size (Alloced : in MAT.Types.Target_Size;
Freed : in MAT.Types.Target_Size) return String is
use type MAT.Types.Target_Size;
begin
if Alloced > Freed then
return "+" & Size (Alloced - Freed);
elsif Alloced < Freed then
return "-" & Size (Freed - Alloced);
else
return "=" & Size (Alloced);
end if;
end Size;
-- ------------------------------
-- Format the time relative to the start time.
-- ------------------------------
function Time (Value : in MAT.Types.Target_Tick_Ref;
Start : in MAT.Types.Target_Tick_Ref) return String is
T : constant MAT.Types.Target_Tick_Ref := Value - Start;
Sec : constant MAT.Types.Target_Tick_Ref := T / 1_000_000;
Usec : constant MAT.Types.Target_Tick_Ref := T mod 1_000_000;
Msec : Natural := Natural (Usec / 1_000);
Frac : String (1 .. 5);
begin
Frac (5) := 's';
Frac (4) := Conversion (Msec mod 10 + 1);
Msec := Msec / 10;
Frac (3) := Conversion (Msec mod 10 + 1);
Msec := Msec / 10;
Frac (2) := Conversion (Msec mod 10 + 1);
Frac (1) := '.';
return MAT.Types.Target_Tick_Ref'Image (Sec) & Frac;
end Time;
-- ------------------------------
-- Format the duration in seconds, milliseconds or microseconds.
-- ------------------------------
function Duration (Value : in MAT.Types.Target_Tick_Ref) return String is
Sec : constant MAT.Types.Target_Tick_Ref := Value / 1_000_000;
Usec : constant MAT.Types.Target_Tick_Ref := Value mod 1_000_000;
Msec : constant Natural := Natural (Usec / 1_000);
Val : Natural;
Frac : String (1 .. 5);
begin
if Sec = 0 and Msec = 0 then
return Util.Strings.Image (Integer (Usec)) & "us";
elsif Sec = 0 then
Val := Natural (Usec mod 1_000);
Frac (5) := 's';
Frac (4) := 'm';
Frac (3) := Conversion (Val mod 10 + 1);
Val := Val / 10;
Frac (3) := Conversion (Val mod 10 + 1);
Val := Val / 10;
Frac (2) := Conversion (Val mod 10 + 1);
Frac (1) := '.';
return Util.Strings.Image (Integer (Msec)) & Frac;
else
Val := Msec;
Frac (4) := 's';
Frac (3) := Conversion (Val mod 10 + 1);
Val := Val / 10;
Frac (3) := Conversion (Val mod 10 + 1);
Val := Val / 10;
Frac (2) := Conversion (Val mod 10 + 1);
Frac (1) := '.';
return Util.Strings.Image (Integer (Sec)) & Frac (1 .. 4);
end if;
end Duration;
function Location (File : in Ada.Strings.Unbounded.Unbounded_String) return String is
Pos : constant Natural := Ada.Strings.Unbounded.Index (File, "/", Ada.Strings.Backward);
Len : constant Natural := Ada.Strings.Unbounded.Length (File);
begin
if Pos /= 0 then
return Ada.Strings.Unbounded.Slice (File, Pos + 1, Len);
else
return Ada.Strings.Unbounded.To_String (File);
end if;
end Location;
-- ------------------------------
-- Format a file, line, function information into a string.
-- ------------------------------
function Location (File : in Ada.Strings.Unbounded.Unbounded_String;
Line : in Natural;
Func : in Ada.Strings.Unbounded.Unbounded_String) return String is
begin
if Ada.Strings.Unbounded.Length (File) = 0 then
return Ada.Strings.Unbounded.To_String (Func);
elsif Line > 0 then
declare
Num : constant String := Natural'Image (Line);
begin
return Ada.Strings.Unbounded.To_String (Func) & " ("
& Location (File) & ":" & Num (Num'First + 1 .. Num'Last) & ")";
end;
else
return Ada.Strings.Unbounded.To_String (Func) & " (" & Location (File) & ")";
end if;
end Location;
-- ------------------------------
-- Format an event range description.
-- ------------------------------
function Event (First : in MAT.Events.Target_Event_Type;
Last : in MAT.Events.Target_Event_Type) return String is
use type MAT.Events.Event_Id_Type;
Id1 : constant String := MAT.Events.Event_Id_Type'Image (First.Id);
Id2 : constant String := MAT.Events.Event_Id_Type'Image (Last.Id);
begin
if First.Id = Last.Id then
return Id1 (Id1'First + 1 .. Id1'Last);
else
return Id1 (Id1'First + 1 .. Id1'Last) & ".." & Id2 (Id2'First + 1 .. Id2'Last);
end if;
end Event;
-- ------------------------------
-- Format a short description of the event.
-- ------------------------------
function Event (Item : in MAT.Events.Target_Event_Type;
Mode : in Format_Type := NORMAL) return String is
use type MAT.Types.Target_Addr;
begin
case Item.Index is
when MAT.Events.MSG_MALLOC =>
if Mode = BRIEF then
return "malloc";
else
return "malloc(" & Size (Item.Size) & ") = " & Addr (Item.Addr);
end if;
when MAT.Events.MSG_REALLOC =>
if Mode = BRIEF then
if Item.Old_Addr = 0 then
return "realloc";
else
return "realloc";
end if;
else
if Item.Old_Addr = 0 then
return "realloc(0," & Size (Item.Size) & ") = "
& Addr (Item.Addr);
else
return "realloc(" & Addr (Item.Old_Addr) & "," & Size (Item.Size) & ") = "
& Addr (Item.Addr);
end if;
end if;
when MAT.Events.MSG_FREE =>
if Mode = BRIEF then
return "free";
else
return "free(" & Addr (Item.Addr) & "), " & Size (Item.Size);
end if;
when MAT.Events.MSG_BEGIN =>
return "begin";
when MAT.Events.MSG_END =>
return "end";
when MAT.Events.MSG_LIBRARY =>
return "library";
end case;
end Event;
-- ------------------------------
-- Format a short description of a malloc event.
-- ------------------------------
function Event_Malloc (Item : in MAT.Events.Target_Event_Type;
Related : in MAT.Events.Tools.Target_Event_Vector;
Start_Time : in MAT.Types.Target_Tick_Ref) return String is
Free_Event : MAT.Events.Target_Event_Type;
Slot_Addr : constant String := Addr (Item.Addr);
begin
Free_Event := MAT.Events.Tools.Find (Related, MAT.Events.MSG_FREE);
return Size (Item.Size) & " bytes allocated at "
& Slot_Addr
& " after " & Duration (Item.Time - Start_Time)
& ", freed " & Duration (Free_Event.Time - Item.Time)
& " after by event" & MAT.Events.Event_Id_Type'Image (Free_Event.Id)
;
exception
when MAT.Events.Tools.Not_Found =>
return Size (Item.Size) & " bytes allocated at " & Slot_Addr & " (never freed)";
end Event_Malloc;
-- ------------------------------
-- Format a short description of a realloc event.
-- ------------------------------
function Event_Realloc (Item : in MAT.Events.Target_Event_Type;
Related : in MAT.Events.Tools.Target_Event_Vector;
Start_Time : in MAT.Types.Target_Tick_Ref) return String is
use type MAT.Events.Event_Id_Type;
Free_Event : MAT.Events.Target_Event_Type;
Slot_Addr : constant String := Addr (Item.Addr);
begin
if Item.Next_Id = 0 and Item.Prev_Id = 0 then
return Size (Item.Size) & " bytes reallocated at " & Slot_Addr
& " after " & Duration (Item.Time - Start_Time)
& " (never freed)";
end if;
Free_Event := MAT.Events.Tools.Find (Related, MAT.Events.MSG_FREE);
return Size (Item.Size) & " bytes reallocated at " & Slot_Addr
& " after " & Duration (Item.Time - Start_Time)
& ", freed " & Duration (Free_Event.Time - Item.Time)
& " after by event" & MAT.Events.Event_Id_Type'Image (Free_Event.Id)
& " " & Size (Item.Size, Item.Old_Size) & " bytes";
exception
when MAT.Events.Tools.Not_Found =>
return Size (Item.Size) & " bytes reallocated at " & Slot_Addr
& " after " & Duration (Item.Time - Start_Time)
& " (never freed) " & Size (Item.Size, Item.Old_Size) & " bytes";
end Event_Realloc;
-- ------------------------------
-- Format a short description of a free event.
-- ------------------------------
function Event_Free (Item : in MAT.Events.Target_Event_Type;
Related : in MAT.Events.Tools.Target_Event_Vector;
Start_Time : in MAT.Types.Target_Tick_Ref) return String is
Alloc_Event : MAT.Events.Target_Event_Type;
Slot_Addr : constant String := Addr (Item.Addr);
begin
Alloc_Event := MAT.Events.Tools.Find (Related, MAT.Events.MSG_MALLOC);
return Size (Alloc_Event.Size) & " bytes freed at " & Slot_Addr
& " after " & Duration (Item.Time - Start_Time)
& ", alloc'ed for " & Duration (Item.Time - Alloc_Event.Time)
& " by event" & MAT.Events.Event_Id_Type'Image (Alloc_Event.Id);
exception
when MAT.Events.Tools.Not_Found =>
return Size (Item.Size) & " bytes freed at " & Slot_Addr;
end Event_Free;
-- ------------------------------
-- Format a short description of the event.
-- ------------------------------
function Event (Item : in MAT.Events.Target_Event_Type;
Related : in MAT.Events.Tools.Target_Event_Vector;
Start_Time : in MAT.Types.Target_Tick_Ref) return String is
begin
case Item.Index is
when MAT.Events.MSG_MALLOC =>
return Event_Malloc (Item, Related, Start_Time);
when MAT.Events.MSG_REALLOC =>
return Event_Realloc (Item, Related, Start_Time);
when MAT.Events.MSG_FREE =>
return Event_Free (Item, Related, Start_Time);
when MAT.Events.MSG_BEGIN =>
return "Begin event";
when MAT.Events.MSG_END =>
return "End event";
when MAT.Events.MSG_LIBRARY =>
return "Library information event";
end case;
end Event;
-- ------------------------------
-- Format the difference between two event IDs (offset).
-- ------------------------------
function Offset (First : in MAT.Events.Event_Id_Type;
Second : in MAT.Events.Event_Id_Type) return String is
use type MAT.Events.Event_Id_Type;
begin
if First = Second or First = 0 or Second = 0 then
return "";
elsif First > Second then
return "+" & Util.Strings.Image (Natural (First - Second));
else
return "-" & Util.Strings.Image (Natural (Second - First));
end if;
end Offset;
-- ------------------------------
-- Format a short description of the memory allocation slot.
-- ------------------------------
function Slot (Value : in MAT.Types.Target_Addr;
Item : in MAT.Memory.Allocation;
Start_Time : in MAT.Types.Target_Tick_Ref) return String is
begin
return Addr (Value) & " is " & Size (Item.Size)
& " bytes allocated after " & Duration (Item.Time - Start_Time)
& " by event" & MAT.Events.Event_Id_Type'Image (Item.Event);
end Slot;
end MAT.Formats;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Test is
procedure P is begin return 0; end;
begin P; end;
|
------------------------------------------------------------------------------
-- --
-- GNAT SYSTEM UTILITIES --
-- --
-- X N M A K E --
-- --
-- B o d y --
-- --
-- $Revision$
-- --
-- Copyright (C) 1992-2001 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. --
-- --
------------------------------------------------------------------------------
-- Program to construct the spec and body of the Nmake package
-- Input files:
-- sinfo.ads Spec of Sinfo package
-- nmake.adt Template for Nmake package
-- Output files:
-- nmake.ads Spec of Nmake package
-- nmake.adb Body of Nmake package
-- Note: this program assumes that sinfo.ads has passed the error checks that
-- are carried out by the csinfo utility, so it does not duplicate these
-- checks and assumes that sinfo.ads has the correct form.
-- In the absence of any switches, both the ads and adb files are output.
-- The switch -s or /s indicates that only the ads file is to be output.
-- The switch -b or /b indicates that only the adb file is to be output.
-- If a file name argument is given, then the output is written to this file
-- rather than to nmake.ads or nmake.adb. A file name can only be given if
-- exactly one of the -s or -b options is present.
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;
with Ada.Strings.Maps; use Ada.Strings.Maps;
with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Spitbol; use GNAT.Spitbol;
with GNAT.Spitbol.Patterns; use GNAT.Spitbol.Patterns;
procedure XNmake is
Err : exception;
-- Raised to terminate execution
A : VString := Nul;
Arg : VString := Nul;
Arg_List : VString := Nul;
Comment : VString := Nul;
Default : VString := Nul;
Field : VString := Nul;
Line : VString := Nul;
Node : VString := Nul;
Op_Name : VString := Nul;
Prevl : VString := Nul;
Sinfo_Rev : VString := Nul;
Synonym : VString := Nul;
Temp_Rev : VString := Nul;
X : VString := Nul;
XNmake_Rev : VString := Nul;
Lineno : Natural;
NWidth : Natural;
FileS : VString := V ("nmake.ads");
FileB : VString := V ("nmake.adb");
-- Set to null if corresponding file not to be generated
Given_File : VString := Nul;
-- File name given by command line argument
InS, InT : File_Type;
OutS, OutB : File_Type;
wsp : Pattern := Span (' ' & ASCII.HT);
-- Note: in following patterns, we break up the word revision to
-- avoid RCS getting enthusiastic about updating the reference!
Get_SRev : Pattern := BreakX ('$') & "$Rev" & "ision: " &
Break (' ') * Sinfo_Rev;
GetT_Rev : Pattern := BreakX ('$') & "$Rev" & "ision: " &
Break (' ') * Temp_Rev;
Body_Only : Pattern := BreakX (' ') * X & Span (' ') & "-- body only";
Spec_Only : Pattern := BreakX (' ') * X & Span (' ') & "-- spec only";
Node_Hdr : Pattern := wsp & "-- N_" & Rest * Node;
Punc : Pattern := BreakX (" .,");
Binop : Pattern := wsp & "-- plus fields for binary operator";
Unop : Pattern := wsp & "-- plus fields for unary operator";
Syn : Pattern := wsp & "-- " & Break (' ') * Synonym
& " (" & Break (')') * Field & Rest * Comment;
Templ : Pattern := BreakX ('T') * A & "T e m p l a t e";
Spec : Pattern := BreakX ('S') * A & "S p e c";
Sem_Field : Pattern := BreakX ('-') & "-Sem";
Lib_Field : Pattern := BreakX ('-') & "-Lib";
Get_Field : Pattern := BreakX (Decimal_Digit_Set) * Field;
Get_Dflt : Pattern := BreakX ('(') & "(set to "
& Break (" ") * Default & " if";
Next_Arg : Pattern := Break (',') * Arg & ',';
Op_Node : Pattern := "Op_" & Rest * Op_Name;
Shft_Rot : Pattern := "Shift_" or "Rotate_";
No_Ent : Pattern := "Or_Else" or "And_Then" or "In" or "Not_In";
M : Match_Result;
V_String_Id : constant VString := V ("String_Id");
V_Node_Id : constant VString := V ("Node_Id");
V_Name_Id : constant VString := V ("Name_Id");
V_List_Id : constant VString := V ("List_Id");
V_Elist_Id : constant VString := V ("Elist_Id");
V_Boolean : constant VString := V ("Boolean");
procedure WriteS (S : String);
procedure WriteB (S : String);
procedure WriteBS (S : String);
procedure WriteS (S : VString);
procedure WriteB (S : VString);
procedure WriteBS (S : VString);
-- Write given line to spec or body file or both if active
procedure WriteB (S : String) is
begin
if FileB /= Nul then
Put_Line (OutB, S);
end if;
end WriteB;
procedure WriteB (S : VString) is
begin
if FileB /= Nul then
Put_Line (OutB, S);
end if;
end WriteB;
procedure WriteBS (S : String) is
begin
if FileB /= Nul then
Put_Line (OutB, S);
end if;
if FileS /= Nul then
Put_Line (OutS, S);
end if;
end WriteBS;
procedure WriteBS (S : VString) is
begin
if FileB /= Nul then
Put_Line (OutB, S);
end if;
if FileS /= Nul then
Put_Line (OutS, S);
end if;
end WriteBS;
procedure WriteS (S : String) is
begin
if FileS /= Nul then
Put_Line (OutS, S);
end if;
end WriteS;
procedure WriteS (S : VString) is
begin
if FileS /= Nul then
Put_Line (OutS, S);
end if;
end WriteS;
-- Start of processing for XNmake
begin
-- Capture our revision (following line updated by RCS)
Match ("$Revision$",
"$Rev" & "ision: " & Break (' ') * XNmake_Rev);
Lineno := 0;
NWidth := 28;
Anchored_Mode := True;
for ArgN in 1 .. Argument_Count loop
declare
Arg : constant String := Argument (ArgN);
begin
if Arg (1) = '-' then
if Arg'Length = 2
and then (Arg (2) = 'b' or else Arg (2) = 'B')
then
FileS := Nul;
elsif Arg'Length = 2
and then (Arg (2) = 's' or else Arg (2) = 'S')
then
FileB := Nul;
else
raise Err;
end if;
else
if Given_File /= Nul then
raise Err;
else
Given_File := V (Arg);
end if;
end if;
end;
end loop;
if FileS = Nul and then FileB = Nul then
raise Err;
elsif Given_File /= Nul then
if FileB = Nul then
FileS := Given_File;
elsif FileS = Nul then
FileB := Given_File;
else
raise Err;
end if;
end if;
Open (InS, In_File, "sinfo.ads");
Open (InT, In_File, "nmake.adt");
if FileS /= Nul then
Create (OutS, Out_File, S (FileS));
end if;
if FileB /= Nul then
Create (OutB, Out_File, S (FileB));
end if;
Anchored_Mode := True;
-- Get Sinfo revision number
loop
Line := Get_Line (InS);
exit when Match (Line, Get_SRev);
end loop;
-- Copy initial part of template to spec and body
loop
Line := Get_Line (InT);
if Match (Line, GetT_Rev) then
WriteBS
("-- Generated by xnmake revision " &
XNmake_Rev & " using");
WriteBS
("-- sinfo.ads revision " &
Sinfo_Rev);
WriteBS
("-- nmake.adt revision " &
Temp_Rev);
else
-- Skip lines describing the template
if Match (Line, "-- This file is a template") then
loop
Line := Get_Line (InT);
exit when Line = "";
end loop;
end if;
exit when Match (Line, "package");
if Match (Line, Body_Only, M) then
Replace (M, X);
WriteB (Line);
elsif Match (Line, Spec_Only, M) then
Replace (M, X);
WriteS (Line);
else
if Match (Line, Templ, M) then
Replace (M, A & " S p e c ");
end if;
WriteS (Line);
if Match (Line, Spec, M) then
Replace (M, A & "B o d y");
end if;
WriteB (Line);
end if;
end if;
end loop;
-- Package line reached
WriteS ("package Nmake is");
WriteB ("package body Nmake is");
WriteB ("");
-- Copy rest of lines up to template insert point to spec only
loop
Line := Get_Line (InT);
exit when Match (Line, "!!TEMPLATE INSERTION POINT");
WriteS (Line);
end loop;
-- Here we are doing the actual insertions, loop through node types
loop
Line := Get_Line (InS);
if Match (Line, Node_Hdr)
and then not Match (Node, Punc)
and then Node /= "Unused"
then
exit when Node = "Empty";
Prevl := " function Make_" & Node & " (Sloc : Source_Ptr";
Arg_List := Nul;
-- Loop through fields of one node
loop
Line := Get_Line (InS);
exit when Line = "";
if Match (Line, Binop) then
WriteBS (Prevl & ';');
Append (Arg_List, "Left_Opnd,Right_Opnd,");
WriteBS (
" " & Rpad ("Left_Opnd", NWidth) & " : Node_Id;");
Prevl :=
" " & Rpad ("Right_Opnd", NWidth) & " : Node_Id";
elsif Match (Line, Unop) then
WriteBS (Prevl & ';');
Append (Arg_List, "Right_Opnd,");
Prevl := " " & Rpad ("Right_Opnd", NWidth) & " : Node_Id";
elsif Match (Line, Syn) then
if Synonym /= "Prev_Ids"
and then Synonym /= "More_Ids"
and then Synonym /= "Comes_From_Source"
and then Synonym /= "Paren_Count"
and then not Match (Field, Sem_Field)
and then not Match (Field, Lib_Field)
then
Match (Field, Get_Field);
if Field = "Str" then Field := V_String_Id;
elsif Field = "Node" then Field := V_Node_Id;
elsif Field = "Name" then Field := V_Name_Id;
elsif Field = "List" then Field := V_List_Id;
elsif Field = "Elist" then Field := V_Elist_Id;
elsif Field = "Flag" then Field := V_Boolean;
end if;
if Field = "Boolean" then
Default := V ("False");
else
Default := Nul;
end if;
Match (Comment, Get_Dflt);
WriteBS (Prevl & ';');
Append (Arg_List, Synonym & ',');
Rpad (Synonym, NWidth);
if Default = "" then
Prevl := " " & Synonym & " : " & Field;
else
Prevl :=
" " & Synonym & " : " & Field & " := " & Default;
end if;
end if;
end if;
end loop;
WriteBS (Prevl & ')');
WriteS (" return Node_Id;");
WriteS (" pragma Inline (Make_" & Node & ");");
WriteB (" return Node_Id");
WriteB (" is");
WriteB (" N : constant Node_Id :=");
if Match (Node, "Defining_Identifier") or else
Match (Node, "Defining_Character") or else
Match (Node, "Defining_Operator")
then
WriteB (" New_Entity (N_" & Node & ", Sloc);");
else
WriteB (" New_Node (N_" & Node & ", Sloc);");
end if;
WriteB (" begin");
while Match (Arg_List, Next_Arg, "") loop
if Length (Arg) < NWidth then
WriteB (" Set_" & Arg & " (N, " & Arg & ");");
else
WriteB (" Set_" & Arg);
WriteB (" (N, " & Arg & ");");
end if;
end loop;
if Match (Node, Op_Node) then
if Node = "Op_Plus" then
WriteB (" Set_Chars (N, Name_Op_Add);");
elsif Node = "Op_Minus" then
WriteB (" Set_Chars (N, Name_Op_Subtract);");
elsif Match (Op_Name, Shft_Rot) then
WriteB (" Set_Chars (N, Name_" & Op_Name & ");");
else
WriteB (" Set_Chars (N, Name_" & Node & ");");
end if;
if not Match (Op_Name, No_Ent) then
WriteB (" Set_Entity (N, Standard_" & Node & ");");
end if;
end if;
WriteB (" return N;");
WriteB (" end Make_" & Node & ';');
WriteBS ("");
end if;
end loop;
WriteBS ("end Nmake;");
exception
when Err =>
Put_Line (Standard_Error, "usage: xnmake [-b] [-s] [filename]");
Set_Exit_Status (1);
end XNmake;
|
with STM32_SVD.TIM;
with STM32_SVD; use STM32_SVD;
package STM32GD.Timer is
type Timer_Callback_Type is access procedure;
type Timer_Type is (
Timer_1, Timer2, Timer_3, Timer_6, Timer_7, Timer_8,
Timer_15, Timer_16, Timer_17, Timer_20);
end STM32GD.Timer;
|
-- An example of using low-level convertor API (fixed string procedures)
-- Program reads standard input, adds cr before lf, then writes to standard output
with Ada.Streams;
use Ada.Streams;
use type Ada.Streams.Stream_Element_Offset;
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Text_IO.Text_Streams;
use Ada.Text_IO.Text_Streams;
with Ada.Unchecked_Conversion;
with Encodings.Line_Endings.Add_CR;
with Encodings.Utility;
use Encodings.Utility;
procedure Add_CR is
-- String version of Stream.Read
--procedure Read_String(
-- Stream: in out Root_Stream_Type'Class;
-- Item: out String;
-- Last: out Natural
--) is
-- Character_Length: constant := Character'Stream_Size / Stream_Element'Size;
-- Buffer_Length: constant Stream_Element_Offset := Item'Length * Character_Length;
-- Buffer: Stream_Element_Array(1 .. Buffer_Length);
-- Buffer_I, Buffer_Last: Stream_Element_Offset;
-- Character_Count: Natural;
-- function Conversion is new Ada.Unchecked_Conversion(
-- Source => Stream_Element_Array,
-- Target => Character
-- );
--begin
-- Stream.Read(Buffer, Buffer_Last);
-- Character_Count := Integer(Buffer_Last) / Character_Length;
-- Last := Character_Count + (Item'First - 1);
-- Buffer_I := 1;
-- for I in Item'First..Last loop
-- Item(I) := Conversion(Buffer(Buffer_I .. Buffer_I + Character_Length - 1));
-- Buffer_I := Buffer_I + Character_Length;
-- end loop;
--end;
Input_Stream: Stream_Access := Stream(Standard_Input);
Output_Stream: Stream_Access := Stream(Standard_Output);
Input_Buffer: String(1 .. 100);
Output_Buffer: String(1 .. 100);
Input_Last, Input_Read_Last: Natural;
Output_Last: Natural;
Coder: Encodings.Line_Endings.Add_CR.Coder;
begin
while not End_Of_File(Standard_Input) loop
Read_String(Input_Stream.all, Input_Buffer, Input_Read_Last);
Input_Last := Input_Buffer'First - 1;
while Input_Last < Input_Read_Last loop
Coder.Convert(Input_Buffer(Input_Last + 1 .. Input_Read_Last), Input_Last, Output_Buffer, Output_Last);
String'Write(Output_Stream, Output_Buffer(Output_Buffer'First .. Output_Last));
end loop;
end loop;
end Add_CR;
|
with System;
package Vect6_Pkg is
type Index_Type is mod System.Memory_Size;
function K return Index_Type;
function N return Index_Type;
end Vect6_Pkg;
|
-----------------------------------------------------------------------
-- wiki-plugins -- Wiki plugins
-- Copyright (C) 2016, 2018, 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.
-----------------------------------------------------------------------
with Wiki.Attributes;
with Wiki.Documents;
with Wiki.Filters;
with Wiki.Strings;
-- == Plugins {#wiki-plugins} ==
-- The `Wiki.Plugins` package defines the plugin interface that is used by the wiki
-- engine to provide pluggable extensions in the Wiki. The plugins works by using
-- a factory that finds and gives access to a plugin given its name.
-- The plugin factory is represented by the `Wiki_Plugin` limited interface which
-- must only implement the `Find` function. A simple plugin factory can be created
-- by declaring a tagged record that implements the interface:
--
-- type Factory is new Wiki.Plugins.Plugin_Factory with null record;
-- overriding function
-- Find (Factory : in Factory;
-- Name : in String) return Wiki.Plugins.Wiki_Plugin_Access;
--
-- @include wiki-plugins-variables.ads
-- @include wiki-plugins-conditions.ads
-- @include wiki-plugins-templates.ads
package Wiki.Plugins is
pragma Preelaborate;
type Plugin_Context;
type Wiki_Plugin is limited interface;
type Wiki_Plugin_Access is access all Wiki_Plugin'Class;
type Plugin_Factory is limited interface;
type Plugin_Factory_Access is access all Plugin_Factory'Class;
-- Find a plugin knowing its name.
function Find (Factory : in Plugin_Factory;
Name : in String) return Wiki_Plugin_Access is abstract;
type Plugin_Context is limited record
Previous : access Plugin_Context;
Filters : Wiki.Filters.Filter_Chain;
Factory : Plugin_Factory_Access;
Variables : Wiki.Attributes.Attribute_List;
Syntax : Wiki.Wiki_Syntax;
Ident : Wiki.Strings.UString;
Is_Hidden : Boolean := False;
Is_Included : Boolean := False;
end record;
-- Expand the plugin configured with the parameters for the document.
procedure Expand (Plugin : in out Wiki_Plugin;
Document : in out Wiki.Documents.Document;
Params : in out Wiki.Attributes.Attribute_List;
Context : in out Plugin_Context) is abstract;
end Wiki.Plugins;
|
-- This file is generated by SWIG. Please do *not* modify by hand.
--
with speech_tools_c;
with speech_tools_c.Pointers;
with interfaces.C;
package festival.FT_ff_pref_func is
-- Item
--
type Item is access
function (arg_2_1 : in speech_tools_c.Pointers.EST_Item_Pointer;
arg_2_2 : in speech_tools_c.Pointers.EST_String_Pointer) return speech_tools_c.EST_Val;
pragma convention (C, Item);
-- Items
--
type Items is array (interfaces.C.Size_t range <>) of aliased festival.FT_ff_pref_func.Item;
-- Pointer
--
type Pointer is access all festival.FT_ff_pref_func.Item;
-- Pointers
--
type Pointers is array (interfaces.C.Size_t range <>) of aliased festival.FT_ff_pref_func.Pointer;
-- Pointer_Pointer
--
type Pointer_Pointer is access all festival.FT_ff_pref_func.Pointer;
end festival.FT_ff_pref_func;
|
with AUnit.Test_Fixtures;
with AUnit.Test_Suites;
package PBKDF2.Tests is
function Suite return AUnit.Test_Suites.Access_Test_Suite;
private
type Fixture is new AUnit.Test_Fixtures.Test_Fixture with null record;
procedure PBKDF2_HMAC_SHA_1_Test (Object : in out Fixture);
procedure PBKDF2_HMAC_SHA_256_Test (Object : in out Fixture);
procedure PBKDF2_HMAC_SHA_512_Test (Object : in out Fixture);
end PBKDF2.Tests;
|
-- generated parser support file.
-- command line: wisitoken-bnf-generate.exe --generate LR1 Ada_Emacs re2c PROCESS text_rep ada.wy
--
-- Copyright (C) 2013 - 2019 Free Software Foundation, Inc.
-- 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, 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
with Wisi; use Wisi;
with Wisi.Ada; use Wisi.Ada;
package body Ada_Process_Actions is
use WisiToken.Semantic_Checks;
use all type Motion_Param_Array;
procedure abstract_subprogram_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (6,
Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end abstract_subprogram_declaration_0;
procedure accept_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Motion), (9, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (5, Invalid_Token_ID) & (6, 72) &
(9, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, 3, 1), (8, 3, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (True, (Simple, (Label => None)), (Simple, (Int, Ada_Indent))), (True, (Simple, (Int,
Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label =>
None))), (False, (Simple, (Label => None)))));
end case;
end accept_statement_0;
function accept_statement_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 2, 8, End_Names_Optional);
end accept_statement_0_check;
procedure accept_statement_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end accept_statement_1;
procedure access_definition_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple,
(Anchored_1, 4, Ada_Indent_Broken)))));
end case;
end access_definition_0;
procedure access_definition_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple,
(Anchored_2, 4, Ada_Indent_Broken)))));
end case;
end access_definition_1;
procedure access_definition_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (4, 1, 2)));
when Indent =>
null;
end case;
end access_definition_2;
procedure actual_parameter_part_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple,
(Anchored_0, 1, 1)), (Simple, (Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end actual_parameter_part_0;
procedure actual_parameter_part_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple,
(Anchored_0, 1, 1)), (Simple, (Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end actual_parameter_part_1;
procedure aggregate_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 1))), (False, (Simple, (Label => None))), (False,
(Simple, (Label => None))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end aggregate_0;
procedure aggregate_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 1))), (True, (Simple, (Anchored_0, 1, 1)), (Simple,
(Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end aggregate_1;
procedure aggregate_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple,
(Anchored_0, 1, 1)), (Simple, (Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end aggregate_3;
procedure aggregate_4
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple,
(Anchored_0, 1, 1)), (Simple, (Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end aggregate_4;
procedure array_type_definition_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Anchored_0, 2, 1))), (False, (Simple, (Anchored_0, 2, 0))), (False,
(Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end array_type_definition_0;
procedure array_type_definition_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Anchored_0, 2, 1))), (False, (Simple, (Anchored_0, 2, 0))), (False,
(Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end array_type_definition_1;
procedure aspect_clause_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end aspect_clause_0;
procedure aspect_specification_opt_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken)))));
end case;
end aspect_specification_opt_0;
procedure assignment_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Hanging_0, (Anchored_1, 2, Ada_Indent_Broken), (Anchored_1, 3,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end assignment_statement_0;
procedure association_opt_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (True, (Simple, (Anchored_1, 2, Ada_Indent_Broken)), (Simple, (Anchored_1, 2,
Ada_Indent_Broken)))));
end case;
end association_opt_0;
procedure association_opt_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Hanging_0, (Label => None), (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (True, (Hanging_3, (Anchored_1, 2,
Ada_Indent_Broken), (Anchored_1, 2, 2 * Ada_Indent_Broken)), (Hanging_3, (Anchored_1, 2, Ada_Indent_Broken),
(Anchored_1, 2, 2 * Ada_Indent_Broken)))));
end case;
end association_opt_2;
procedure association_opt_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Hanging_0, (Label => None), (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end association_opt_3;
procedure association_opt_4
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, (1 => (True, (Hanging_0, (Label => None), (Int,
Ada_Indent_Broken)), (Hanging_0, (Label => None), (Int, Ada_Indent_Broken)))));
end case;
end association_opt_4;
procedure asynchronous_select_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Motion), (8, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (8,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent)), (Simple, (Int, Ada_Indent))), (True, (Simple, (Label => None)), (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (True, (Simple, (Int, Ada_Indent)),
(Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False,
(Simple, (Label => None)))));
end case;
end asynchronous_select_0;
procedure at_clause_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end at_clause_0;
procedure block_label_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Int, Ada_Indent_Label))), (False,
(Simple, (Label => None)))));
end case;
end block_label_0;
function block_label_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 1);
end block_label_0_check;
function block_label_opt_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 1);
end block_label_opt_0_check;
procedure block_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Motion), (4, Motion), (8,
Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, Invalid_Token_ID) & (4, Invalid_Token_ID) & (5, 72) &
(8, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label
=> None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label =>
None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end block_statement_0;
function block_statement_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 1, 7, End_Names_Optional);
end block_statement_0_check;
procedure block_statement_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Motion), (6, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, Invalid_Token_ID) & (3, 72) & (6, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label
=> None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end block_statement_1;
function block_statement_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 1, 5, End_Names_Optional);
end block_statement_1_check;
procedure case_expression_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Motion)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (4, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Int, Ada_Indent_When)))));
end case;
end case_expression_0;
procedure case_expression_alternative_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Motion)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Hanging_0, (Anchored_1, 1,
Ada_Indent), (Anchored_1, 1, Ada_Indent + Ada_Indent_Broken)))));
end case;
end case_expression_alternative_0;
procedure case_expression_alternative_list_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple,
(Label => None)), (Simple, (Int, Ada_Indent_When))), (False, (Simple, (Label => None)))));
end case;
end case_expression_alternative_list_0;
procedure case_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (4, Invalid_Token_ID) & (7,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (True, (Simple, (Int, Ada_Indent_When)),
(Simple, (Int, Ada_Indent_When))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))),
(False, (Simple, (Label => None)))));
end case;
end case_statement_0;
procedure case_statement_alternative_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Motion)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (True, (Simple, (Int, Ada_Indent)),
(Simple, (Int, Ada_Indent)))));
end case;
end case_statement_alternative_0;
procedure case_statement_alternative_list_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
null;
end case;
end case_statement_alternative_list_0;
procedure compilation_unit_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Int, 0))), (False, (Simple, (Int,
0)))));
end case;
end compilation_unit_2;
procedure compilation_unit_list_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Int, 0))), (True, (Simple, (Int, 0)),
(Simple, (Int, 0)))));
end case;
end compilation_unit_list_0;
procedure compilation_unit_list_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, (1 => (True, (Simple, (Int, 0)), (Simple, (Int, 0)))));
end case;
end compilation_unit_list_1;
function compilation_unit_list_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Tokens);
begin
return Terminate_Partial_Parse (Partial_Parse_Active, Partial_Parse_Byte_Goal, Recover_Active, Nonterm);
end compilation_unit_list_1_check;
procedure component_clause_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (8, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end component_clause_0;
procedure component_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 4, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end component_declaration_0;
procedure component_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end component_declaration_1;
procedure component_list_4
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end component_list_4;
procedure conditional_entry_call_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Motion), (7, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (7,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label =>
None))), (False, (Simple, (Label => None)))));
end case;
end conditional_entry_call_0;
procedure declaration_9
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Hanging_0, (Label => None), (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 4,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end declaration_9;
procedure delay_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end delay_statement_0;
procedure delay_statement_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end delay_statement_1;
procedure derived_type_definition_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 2)));
when Indent =>
null;
end case;
end derived_type_definition_0;
procedure derived_type_definition_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 2)));
when Indent =>
null;
end case;
end derived_type_definition_1;
procedure discriminant_part_opt_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end discriminant_part_opt_1;
procedure elsif_expression_item_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Motion), (3, Motion)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent)))));
end case;
end elsif_expression_item_0;
procedure elsif_expression_list_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
null;
end case;
end elsif_expression_list_0;
procedure elsif_statement_item_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Motion), (3, Motion)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (True, (Simple,
(Int, Ada_Indent)), (Simple, (Int, Ada_Indent)))));
end case;
end elsif_statement_item_0;
procedure elsif_statement_list_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
null;
end case;
end elsif_statement_list_0;
procedure entry_body_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Motion), (6, Motion), (8,
Motion), (12, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (4, Invalid_Token_ID) & (6,
Invalid_Token_ID) & (8, Invalid_Token_ID) & (9, 72) & (12, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, 3, 1), (11, 3, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 4, Ada_Indent_Broken))), (False, (Simple, (Label =>
None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))),
(True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (False,
(Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end entry_body_0;
function entry_body_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 2, 11, End_Names_Optional);
end entry_body_0_check;
procedure entry_body_formal_part_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 1))), (False,
(Simple, (Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 0))), (False, (Simple, (Int,
Ada_Indent_Broken)))));
end case;
end entry_body_formal_part_0;
procedure entry_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (8,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 3, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Anchored_0, 4, 1))), (False, (Simple, (Anchored_0, 4, 0))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end entry_declaration_0;
procedure entry_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (6,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 3, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end entry_declaration_1;
procedure enumeration_representation_clause_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 1, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end enumeration_representation_clause_0;
procedure enumeration_type_definition_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end enumeration_type_definition_0;
procedure exception_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end exception_declaration_0;
procedure exception_handler_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Motion)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (True, (Simple, (Int, Ada_Indent)),
(Simple, (Int, Ada_Indent)))));
end case;
end exception_handler_0;
procedure exception_handler_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Motion)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (True, (Simple, (Int, Ada_Indent)),
(Simple, (Int, Ada_Indent)))));
end case;
end exception_handler_1;
procedure exception_handler_list_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
null;
end case;
end exception_handler_list_0;
procedure exit_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False,
(Simple, (Label => None)))));
end case;
end exit_statement_0;
procedure exit_statement_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end exit_statement_1;
procedure expression_function_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (6,
Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end expression_function_declaration_0;
procedure extended_return_object_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Anchored_1, 6, Ada_Indent_Broken)))));
end case;
end extended_return_object_declaration_0;
procedure extended_return_object_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken)))));
end case;
end extended_return_object_declaration_1;
procedure extended_return_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Motion), (7, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (4, 72) &
(7, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((True, (Simple, (Label => None)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (True,
(Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (False,
(Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end extended_return_statement_0;
procedure extended_return_statement_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end extended_return_statement_1;
procedure formal_object_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (9, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (5, 1, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 6, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_object_declaration_0;
procedure formal_object_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (8, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 5,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_object_declaration_1;
procedure formal_object_declaration_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (5, 1, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_object_declaration_2;
procedure formal_object_declaration_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_object_declaration_3;
procedure formal_part_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Misc)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end formal_part_0;
procedure formal_subprogram_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Label => None)))));
end case;
end formal_subprogram_declaration_0;
procedure formal_subprogram_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_subprogram_declaration_1;
procedure formal_subprogram_declaration_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_subprogram_declaration_2;
procedure formal_subprogram_declaration_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_subprogram_declaration_3;
procedure formal_type_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_type_declaration_0;
procedure formal_type_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_type_declaration_1;
procedure formal_type_declaration_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_type_declaration_2;
procedure formal_derived_type_definition_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 2)));
when Indent =>
null;
end case;
end formal_derived_type_definition_0;
procedure formal_derived_type_definition_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 2)));
when Indent =>
null;
end case;
end formal_derived_type_definition_1;
procedure formal_package_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (9, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 1, 1), (6, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end formal_package_declaration_0;
procedure full_type_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False,
(Simple, (Label => None)))));
end case;
end full_type_declaration_0;
procedure function_specification_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Statement_Start)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken)))));
end case;
end function_specification_0;
function function_specification_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 2);
end function_specification_0_check;
procedure generic_formal_part_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Statement_Start)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent)))));
end case;
end generic_formal_part_0;
procedure generic_formal_part_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Statement_Start)));
when Face =>
null;
when Indent =>
null;
end case;
end generic_formal_part_1;
procedure generic_instantiation_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, 1, 1), (5, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Label => None)))));
end case;
end generic_instantiation_0;
procedure generic_instantiation_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (8,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 1, 1), (6, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end generic_instantiation_1;
procedure generic_instantiation_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (8,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 1, 1), (6, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False,
(Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end generic_instantiation_2;
procedure generic_package_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, Invalid_Token_ID) & (3,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((True, (Simple, (Label => None)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end generic_package_declaration_0;
procedure generic_renaming_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 1, 1), (5, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Label => None)))));
end case;
end generic_renaming_declaration_0;
procedure generic_renaming_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 1, 1), (5, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Language,
Ada_Indent_Renames_0'Access, +3))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end generic_renaming_declaration_1;
procedure generic_renaming_declaration_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 1, 1), (5, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Language,
Ada_Indent_Renames_0'Access, +3))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end generic_renaming_declaration_2;
procedure generic_subprogram_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (4,
Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, Invalid_Token_ID) & (4,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
null;
end case;
end generic_subprogram_declaration_0;
procedure goto_label_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 0)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Int, Ada_Indent_Label))), (False,
(Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end goto_label_0;
procedure handled_sequence_of_statements_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((True, (Simple, (Label => None)), (Simple, (Label =>
None))), (False, (Simple, (Int, -Ada_Indent))), (True, (Simple, (Int, Ada_Indent_When - Ada_Indent)), (Simple,
(Int, Ada_Indent_When - Ada_Indent)))));
end case;
end handled_sequence_of_statements_0;
procedure identifier_list_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken)))));
end case;
end identifier_list_0;
procedure identifier_list_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 1);
when Face =>
null;
when Indent =>
null;
end case;
end identifier_list_1;
function identifier_opt_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 1);
end identifier_opt_0_check;
procedure if_expression_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Motion), (3, Motion), (6, Motion)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (5,
Invalid_Token_ID) & (6, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent)))));
end case;
end if_expression_0;
procedure if_expression_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Motion), (3, Motion), (5, Motion)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (5,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Int, Ada_Indent)))));
end case;
end if_expression_1;
procedure if_expression_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Motion), (3, Motion)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (5,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent))), (False, (Simple, (Label => None)))));
end case;
end if_expression_2;
procedure if_expression_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Motion), (3, Motion)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent)))));
end case;
end if_expression_3;
procedure if_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Motion), (6, Motion), (10,
Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (5,
Invalid_Token_ID) & (6, Invalid_Token_ID) & (10, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Hanging_2,
(Int, Ada_Indent_Broken), (Int, 2 * Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label
=> None))), (False, (Simple, (Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Label
=> None)))));
end case;
end if_statement_0;
procedure if_statement_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Motion), (5, Motion), (9,
Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (5,
Invalid_Token_ID) & (9, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Hanging_2,
(Int, Ada_Indent_Broken), (Int, 2 * Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label
=> None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label =>
None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end if_statement_1;
procedure if_statement_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Motion), (8, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (5,
Invalid_Token_ID) & (8, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Hanging_2,
(Int, Ada_Indent_Broken), (Int, 2 * Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label
=> None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Label =>
None)))));
end case;
end if_statement_2;
procedure if_statement_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Motion), (7, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (7,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Hanging_2,
(Int, Ada_Indent_Broken), (Int, 2 * Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label
=> None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end if_statement_3;
procedure incomplete_type_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end incomplete_type_declaration_0;
procedure incomplete_type_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end incomplete_type_declaration_1;
procedure index_constraint_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Anchored_0, 1, 1))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end index_constraint_0;
procedure interface_list_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 2)));
when Indent =>
null;
end case;
end interface_list_0;
procedure interface_list_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, 1, 2)));
when Indent =>
null;
end case;
end interface_list_1;
procedure iteration_scheme_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken)))));
end case;
end iteration_scheme_0;
procedure iteration_scheme_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent_Broken)), (Simple, (Int, Ada_Indent_Broken)))));
end case;
end iteration_scheme_1;
procedure iterator_specification_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Remove_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => 4));
when Indent =>
null;
end case;
end iterator_specification_2;
procedure iterator_specification_5
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Remove_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => 3));
when Indent =>
null;
end case;
end iterator_specification_5;
procedure loop_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (3,
Motion), (8, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, Invalid_Token_ID) & (3, Invalid_Token_ID) & (8,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Label
=> None))), (False, (Simple, (Label => None)))));
end case;
end loop_statement_0;
function loop_statement_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 1, 7, End_Names_Optional);
end loop_statement_0_check;
procedure loop_statement_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (4,
Motion), (7, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, Invalid_Token_ID) & (4, Invalid_Token_ID) & (7,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label
=> None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Label =>
None)))));
end case;
end loop_statement_1;
function loop_statement_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 1, 6, End_Names_Optional);
end loop_statement_1_check;
procedure name_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Anchored_1, 1, Ada_Indent_Broken))), (False, (Hanging_0, (Anchored_0, 2, 1), (Anchored_0, 2, 1 +
Ada_Indent_Broken))), (False, (Simple, (Anchored_0, 2, 0)))));
end case;
end name_0;
procedure name_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple, (if
Ada_Indent_Hanging_Rel_Exp then (Anchored_0, 1, Ada_Indent_Broken) else (Anchored_1, 1,
Ada_Indent_Broken))))));
end case;
end name_1;
function name_2_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 1);
end name_2_check;
procedure name_5
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Mark_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Suffix)));
when Indent =>
null;
end case;
end name_5;
function name_5_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 1);
end name_5_check;
function name_7_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 1);
end name_7_check;
function name_opt_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 1);
end name_opt_0_check;
procedure null_exclusion_opt_name_type_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, 3, 2)));
when Indent =>
null;
end case;
end null_exclusion_opt_name_type_0;
procedure null_exclusion_opt_name_type_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, 1, 2)));
when Indent =>
null;
end case;
end null_exclusion_opt_name_type_1;
procedure null_exclusion_opt_name_type_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 3, 2)));
when Indent =>
null;
end case;
end null_exclusion_opt_name_type_2;
procedure null_exclusion_opt_name_type_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 2)));
when Indent =>
null;
end case;
end null_exclusion_opt_name_type_3;
procedure null_procedure_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (6,
Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end null_procedure_declaration_0;
procedure object_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (9, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Anchored_2, 6, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end object_declaration_0;
procedure object_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (9, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 6, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end object_declaration_1;
procedure object_declaration_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (9, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 6, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end object_declaration_2;
procedure object_declaration_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end object_declaration_3;
procedure object_declaration_4
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end object_declaration_4;
procedure object_declaration_5
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end object_declaration_5;
procedure object_renaming_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (8, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 1);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (4, 1, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end object_renaming_declaration_0;
procedure object_renaming_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 1);
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end object_renaming_declaration_1;
procedure object_renaming_declaration_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 1);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (5, 1, 3)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end object_renaming_declaration_2;
procedure overriding_indicator_opt_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override)));
when Face =>
null;
when Indent =>
null;
end case;
end overriding_indicator_opt_0;
procedure overriding_indicator_opt_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Statement_Start)));
when Face =>
null;
when Indent =>
null;
end case;
end overriding_indicator_opt_1;
procedure package_body_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Motion), (7, Motion), (11,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (5, Invalid_Token_ID) & (7,
Invalid_Token_ID) & (8, 72) & (11, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 1, 1), (10, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))),
(False, (Simple, (Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False,
(Simple, (Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end package_body_0;
function package_body_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 3, 10, End_Names_Optional);
end package_body_0_check;
procedure package_body_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Motion), (9, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (5, Invalid_Token_ID) & (9,
Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 1, 1), (8, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Label
=> None)))));
end case;
end package_body_1;
function package_body_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 3, 8, End_Names_Optional);
end package_body_1_check;
procedure package_body_stub_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Label => None)))));
end case;
end package_body_stub_0;
procedure package_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
null;
end case;
end package_declaration_0;
procedure package_renaming_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, 1, 1), (4, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end package_renaming_declaration_0;
procedure package_specification_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Motion), (6, Motion)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (4, Invalid_Token_ID) & (6,
Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, 1, 1), (9, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))),
(True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (True,
(Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (False,
(Simple, (Label => None)))));
end case;
end package_specification_0;
function package_specification_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 2, 9, End_Names_Optional);
end package_specification_0_check;
procedure package_specification_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Motion)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (4, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, 1, 1), (7, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))),
(True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (False,
(Simple, (Label => None)))));
end case;
end package_specification_1;
function package_specification_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 2, 7, End_Names_Optional);
end package_specification_1_check;
procedure parameter_and_result_profile_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Language, Ada_Indent_Return_0'Access, 1 & 0)))));
end case;
end parameter_and_result_profile_0;
procedure parameter_specification_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (6, 1, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 7,
Ada_Indent_Broken)))));
end case;
end parameter_specification_0;
procedure parameter_specification_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (6, 1, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken)))));
end case;
end parameter_specification_1;
procedure parameter_specification_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 5,
Ada_Indent_Broken)))));
end case;
end parameter_specification_2;
procedure parameter_specification_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken)))));
end case;
end parameter_specification_3;
procedure paren_expression_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Hanging_0,
(Anchored_0, 1, 1), (Anchored_0, 1, 1 + Ada_Indent_Broken))), (False, (Simple, (Anchored_0, 1, 0)))));
end case;
end paren_expression_0;
procedure pragma_g_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Anchored_0, 3,
1))), (False, (Simple, (Anchored_0, 3, 0))), (False, (Simple, (Label => None)))));
end case;
end pragma_g_0;
procedure pragma_g_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Anchored_0, 3,
1))), (False, (Simple, (Anchored_0, 3, 0))), (False, (Simple, (Label => None)))));
end case;
end pragma_g_1;
procedure pragma_g_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end pragma_g_2;
procedure primary_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, 3, 0)));
when Indent =>
null;
end case;
end primary_0;
procedure primary_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, (1 => (False, (Simple, (Language,
Ada_Indent_Aggregate'Access, Null_Args)))));
end case;
end primary_2;
procedure primary_4
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 1, 2)));
when Indent =>
null;
end case;
end primary_4;
procedure private_extension_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (12, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end private_extension_declaration_0;
procedure private_type_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (8, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))),
(False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple,
(Label => None))), (False, (Simple, (Label => None)))));
end case;
end private_type_declaration_0;
procedure procedure_call_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Hanging_0, (Label => None), (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end procedure_call_statement_0;
procedure procedure_specification_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Statement_Start)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken)))));
end case;
end procedure_specification_0;
function procedure_specification_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 2);
end procedure_specification_0_check;
procedure protected_body_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Motion), (9, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (5, Invalid_Token_ID) & (9,
Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 3, 2), (8, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))),
(False, (Simple, (Label => None))), (False, (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))),
(False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end protected_body_0;
function protected_body_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 3, 8, End_Names_Optional);
end protected_body_0_check;
procedure protected_body_stub_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end protected_body_stub_0;
procedure protected_definition_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, Motion)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (5, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((True, (Simple, (Int, Ada_Indent)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end protected_definition_0;
function protected_definition_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 5);
end protected_definition_0_check;
procedure protected_definition_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((True, (Simple, (Int, Ada_Indent)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end protected_definition_1;
function protected_definition_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 3);
end protected_definition_1_check;
procedure protected_type_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Motion), (11,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (6, Invalid_Token_ID) & (10, 49) &
(11, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end protected_type_declaration_0;
function protected_type_declaration_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 3, 10, End_Names_Optional);
end protected_type_declaration_0_check;
procedure protected_type_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Motion), (8, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (6, Invalid_Token_ID) & (7, 49) &
(8, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (True, (Simple, (Label => None)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end protected_type_declaration_1;
function protected_type_declaration_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 3, 7, End_Names_Optional);
end protected_type_declaration_1_check;
procedure qualified_expression_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, 1, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (if Ada_Indent_Hanging_Rel_Exp then (Anchored_0, 1, Ada_Indent_Broken)
else (Anchored_1, 1, Ada_Indent_Broken))))));
end case;
end qualified_expression_0;
procedure quantified_expression_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 4, Ada_Indent_Broken)))));
end case;
end quantified_expression_0;
procedure raise_expression_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 3,
Ada_Indent_Broken)))));
end case;
end raise_expression_0;
procedure raise_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Anchored_1, 3,
Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end raise_statement_0;
procedure raise_statement_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end raise_statement_1;
procedure raise_statement_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end raise_statement_2;
procedure range_g_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Anchored_0, 4, 1))), (False, (Simple, (Anchored_0, 4, 0)))));
end case;
end range_g_0;
procedure record_definition_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((True, (Simple, (Language, Ada_Indent_Record_1'Access, 69
& 1 & 0)), (Simple, (Language, Ada_Indent_Record_1'Access, 69 & 1 & Ada_Indent))), (True, (Simple, (Language,
Ada_Indent_Record_1'Access, 69 & 1 & Ada_Indent)), (Simple, (Language, Ada_Indent_Record_1'Access, 69 & 1 &
Ada_Indent))), (False, (Simple, (Language, Ada_Indent_Record_1'Access, 69 & 1 & 0))), (False, (Simple, (Label
=> None)))));
end case;
end record_definition_0;
procedure record_representation_clause_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 1, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Language,
Ada_Indent_Record_0'Access, 1 & 4 & 0))), (False, (Simple, (Language, Ada_Indent_Record_0'Access, 1 & 4 &
Ada_Indent))), (False, (Simple, (Language, Ada_Indent_Record_0'Access, 1 & 4 & Ada_Indent))), (False, (Simple,
(Language, Ada_Indent_Record_0'Access, 1 & 4 & 0))), (False, (Simple, (Label => None))), (False, (Simple,
(Label => None)))));
end case;
end record_representation_clause_0;
procedure requeue_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end requeue_statement_0;
procedure requeue_statement_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end requeue_statement_1;
procedure result_profile_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 2)));
when Indent =>
Indent_Action_1 (Parse_Data, Tree, Nonterm, Tokens, 1, ((False, (Simple, (Label => None))), (False, (Simple,
(Anchored_3, 1, Ada_Indent_Broken))), (False, (Simple, (Anchored_3, 1, Ada_Indent_Broken)))));
end case;
end result_profile_0;
procedure result_profile_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_1 (Parse_Data, Tree, Nonterm, Tokens, 1, ((False, (Simple, (Label => None))), (False, (Simple,
(Anchored_4, 1, Ada_Indent_Broken)))));
end case;
end result_profile_1;
procedure selected_component_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Mark_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Prefix), (3, Suffix)));
when Indent =>
null;
end case;
end selected_component_0;
function selected_component_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Merge_Names (Nonterm, Tokens, 1, 3);
end selected_component_0_check;
procedure selected_component_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Mark_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Prefix)));
when Indent =>
null;
end case;
end selected_component_1;
procedure selected_component_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Mark_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Prefix)));
when Indent =>
null;
end case;
end selected_component_2;
function selected_component_2_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Merge_Names (Nonterm, Tokens, 1, 3);
end selected_component_2_check;
procedure selected_component_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Mark_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Prefix)));
when Indent =>
null;
end case;
end selected_component_3;
procedure selective_accept_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Motion), (7, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, 43) & (3, Invalid_Token_ID) &
(7, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((True, (Simple, (Label => None)), (Simple, (Int,
Ada_Indent))), (True, (Simple, (Label => None)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label =>
None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))),
(False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end selective_accept_0;
procedure selective_accept_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, 43) & (5, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((True, (Simple, (Label => None)), (Simple, (Int,
Ada_Indent))), (True, (Simple, (Label => None)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label =>
None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end selective_accept_1;
procedure select_alternative_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Motion)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent))),
(False, (Simple, (Int, Ada_Indent)))));
end case;
end select_alternative_0;
procedure select_alternative_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Motion), (4, Statement_Start), (5, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent))),
(False, (Simple, (Label => None)))));
end case;
end select_alternative_1;
procedure select_alternative_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Motion)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent)))));
end case;
end select_alternative_2;
procedure select_alternative_4
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end select_alternative_4;
procedure select_alternative_list_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, Motion)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, 43) & (2, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent)))));
end case;
end select_alternative_list_0;
procedure select_alternative_list_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, (1 => (False, (Simple, (Int, Ada_Indent)))));
end case;
end select_alternative_list_1;
procedure simple_return_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end simple_return_statement_0;
procedure simple_statement_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end simple_statement_0;
procedure simple_statement_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 0)));
when Indent =>
null;
end case;
end simple_statement_3;
procedure simple_statement_8
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end simple_statement_8;
procedure single_protected_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Motion), (7, Motion), (9,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (4, Invalid_Token_ID) & (7,
Invalid_Token_ID) & (8, 49) & (9, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False,
(Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end single_protected_declaration_0;
function single_protected_declaration_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 2, 8, End_Names_Optional);
end single_protected_declaration_0_check;
procedure single_protected_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Motion), (6, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (4, Invalid_Token_ID) & (5, 49) &
(6, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (True, (Simple, (Label => None)), (Simple,
(Int, Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end single_protected_declaration_1;
function single_protected_declaration_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 2, 5, End_Names_Optional);
end single_protected_declaration_1_check;
procedure single_task_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Motion), (11,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (4, Invalid_Token_ID) & (8, 49) &
(11, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, 3, 2), (9, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False,
(Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Label => None)))));
end case;
end single_task_declaration_0;
function single_task_declaration_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 2, 10, End_Names_Optional);
end single_task_declaration_0_check;
procedure single_task_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Motion), (8, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (4, Invalid_Token_ID) & (5, 49) &
(8, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((2, 3, 2), (6, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (True, (Simple, (Label => None)), (Simple,
(Int, Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Label => None)))));
end case;
end single_task_declaration_1;
function single_task_declaration_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 2, 7, End_Names_Optional);
end single_task_declaration_1_check;
procedure single_task_declaration_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end single_task_declaration_2;
procedure subprogram_body_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (4,
Motion), (6, Motion), (10, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, Invalid_Token_ID) & (4,
Invalid_Token_ID) & (6, Invalid_Token_ID) & (7, 72) & (10, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (9, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple,
(Label => None)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label =>
None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))),
(True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (False,
(Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end subprogram_body_0;
function subprogram_body_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 2, 9, End_Names_Optional);
end subprogram_body_0_check;
procedure subprogram_body_stub_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (6,
Statement_End)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False,
(Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end subprogram_body_stub_0;
procedure subprogram_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (4,
Statement_End)));
when Face =>
null;
when Indent =>
null;
end case;
end subprogram_declaration_0;
procedure subprogram_default_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, 1, 1)));
when Indent =>
null;
end case;
end subprogram_default_0;
procedure subprogram_renaming_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (2, Statement_Override), (6,
Statement_End)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (4, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Language, Ada_Indent_Renames_0'Access, +2))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None)))));
end case;
end subprogram_renaming_declaration_0;
function subprogram_specification_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 1);
end subprogram_specification_0_check;
function subprogram_specification_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Lexer, Recover_Active);
begin
return Propagate_Name (Nonterm, Tokens, 1);
end subprogram_specification_1_check;
procedure subtype_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 2);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end subtype_declaration_0;
procedure subtype_indication_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 2)));
when Indent =>
null;
end case;
end subtype_indication_0;
procedure subtype_indication_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 2)));
when Indent =>
null;
end case;
end subtype_indication_1;
procedure subtype_indication_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, 1, 2)));
when Indent =>
null;
end case;
end subtype_indication_2;
procedure subtype_indication_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, 1, 2)));
when Indent =>
null;
end case;
end subtype_indication_3;
procedure subunit_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_Override)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Anchored_0, 2, 1))), (False, (Simple, (Anchored_0, 2, 0))),
(False, (Simple, (Label => None)))));
end case;
end subunit_0;
procedure task_body_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Motion), (7, Motion), (11,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (5, Invalid_Token_ID) & (7,
Invalid_Token_ID) & (8, 72) & (11, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 3, 2), (10, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False,
(Simple, (Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple,
(Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label
=> None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end task_body_0;
function task_body_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 3, 10, End_Names_Optional);
end task_body_0_check;
procedure task_body_stub_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False,
(Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Label =>
None)))));
end case;
end task_body_stub_0;
procedure task_definition_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, Motion)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((True, (Simple, (Int, Ada_Indent)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Label => None))), (True, (Simple, (Int, Ada_Indent)), (Simple, (Int,
Ada_Indent)))));
end case;
end task_definition_0;
procedure task_definition_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
null;
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, (1 => (True, (Simple, (Int, Ada_Indent)), (Simple, (Int,
Ada_Indent)))));
end case;
end task_definition_1;
procedure task_type_declaration_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Motion), (9, Motion), (13,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (6, Invalid_Token_ID) & (9,
Invalid_Token_ID) & (10, 49) & (13, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 3, 2), (12, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple,
(Label => None))), (False, (Simple, (Label => None)))));
end case;
end task_type_declaration_0;
function task_type_declaration_0_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 3, 12, End_Names_Optional);
end task_type_declaration_0_check;
procedure task_type_declaration_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Motion), (10,
Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (6, Invalid_Token_ID) & (7, 49) &
(10, Invalid_Token_ID)));
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, ((3, 3, 2), (9, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (True, (Simple, (Label => None)), (Simple, (Int,
Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Label
=> None))), (False, (Simple, (Label => None)))));
end case;
end task_type_declaration_1;
function task_type_declaration_1_check
(Lexer : access constant WisiToken.Lexer.Instance'Class;
Nonterm : in out WisiToken.Recover_Token;
Tokens : in WisiToken.Recover_Token_Array;
Recover_Active : in Boolean)
return WisiToken.Semantic_Checks.Check_Status
is
pragma Unreferenced (Nonterm, Recover_Active);
begin
return Match_Names (Lexer, Descriptor, Tokens, 3, 9, End_Names_Optional);
end task_type_declaration_1_check;
procedure task_type_declaration_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (6, Statement_End)));
Name_Action (Parse_Data, Tree, Nonterm, Tokens, 3);
when Face =>
Face_Apply_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 3, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end task_type_declaration_2;
procedure timed_entry_call_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Motion), (6, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (3, Invalid_Token_ID) & (6,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (True, (Simple, (Int,
Ada_Indent)), (Simple, (Int, Ada_Indent))), (False, (Simple, (Label => None))), (False, (Simple, (Label =>
None))), (False, (Simple, (Label => None)))));
end case;
end timed_entry_call_0;
procedure variant_part_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (7, Statement_End)));
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (4, Invalid_Token_ID) & (7,
Invalid_Token_ID)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Label => None))), (False, (Simple, (Int, Ada_Indent_When))),
(False, (Simple, (Label => None))), (False, (Simple, (Label => None))), (False, (Simple, (Label => None)))));
end case;
end variant_part_0;
procedure variant_list_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Motion_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Invalid_Token_ID) & (2, Invalid_Token_ID)));
when Face =>
null;
when Indent =>
null;
end case;
end variant_list_0;
procedure variant_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (1, Motion)));
when Face =>
null;
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Hanging_0,
(Label => None), (Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent))), (True, (Simple, (Int,
Ada_Indent)), (Simple, (Int, Ada_Indent)))));
end case;
end variant_0;
procedure use_clause_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
Face_Apply_List_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (4, 1, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_Use))), (False, (Simple, (Label => None)))));
end case;
end use_clause_0;
procedure use_clause_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Statement_End)));
when Face =>
Face_Apply_List_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 2)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Use))), (False, (Simple, (Label => None)))));
end case;
end use_clause_1;
procedure use_clause_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
Face_Apply_List_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Use))), (False, (Simple, (Label => None)))));
end case;
end use_clause_2;
procedure with_clause_0
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (5, Statement_End)));
when Face =>
Face_Apply_List_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (4, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_Broken))), (False, (Simple, (Int,
Ada_Indent_With))), (False, (Simple, (Label => None)))));
end case;
end with_clause_0;
procedure with_clause_1
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Statement_End)));
when Face =>
Face_Apply_List_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_With))), (False, (Simple, (Label => None)))));
end case;
end with_clause_1;
procedure with_clause_2
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (4, Statement_End)));
when Face =>
Face_Apply_List_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (3, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_Broken))), (False, (Simple, (Int, Ada_Indent_With))), (False, (Simple, (Label => None)))));
end case;
end with_clause_2;
procedure with_clause_3
(User_Data : in out WisiToken.Syntax_Trees.User_Data_Type'Class;
Tree : in out WisiToken.Syntax_Trees.Tree;
Nonterm : in WisiToken.Syntax_Trees.Valid_Node_Index;
Tokens : in WisiToken.Syntax_Trees.Valid_Node_Index_Array)
is
Parse_Data : Wisi.Parse_Data_Type renames Wisi.Parse_Data_Type (User_Data);
begin
case Parse_Data.Post_Parse_Action is
when Navigate =>
Statement_Action (Parse_Data, Tree, Nonterm, Tokens, ((1, Statement_Start), (3, Statement_End)));
when Face =>
Face_Apply_List_Action (Parse_Data, Tree, Nonterm, Tokens, (1 => (2, 1, 1)));
when Indent =>
Indent_Action_0 (Parse_Data, Tree, Nonterm, Tokens, ((False, (Simple, (Label => None))), (False, (Simple,
(Int, Ada_Indent_With))), (False, (Simple, (Label => None)))));
end case;
end with_clause_3;
end Ada_Process_Actions;
|
-------------------------------------------------------------------------------
-- 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.Characters.Latin_1;
with Ada.Float_Text_IO;
with Ada.Strings;
with Ada.Strings.Fixed;
with LSE.Model.IO.Text_File;
with LSE.Utils.Colors;
package body LSE.Model.IO.Drawing_Area.PostScript is
package L renames Ada.Characters.Latin_1;
function Initialize (File_Path : String)
return Instance
is
This : Instance;
begin
This.File_Path := To_Unbounded_String (File_Path);
return This;
end Initialize;
procedure Configure (This : in out Instance;
Turtle : LSE.Model.IO.Turtle.Instance)
is
use Ada.Strings;
use Ada.Strings.Fixed;
use LSE.Model.IO.Text_File;
use LSE.Utils.Colors;
R, G, B : Float := 0.0;
begin
Open_File (This.File.all, Out_File, To_String (This.File_Path));
Put_Line (This.File.all, "%%Creator: Lindenmayer system editor" & L.LF &
"%%BoundingBox: 0 0" & Positive'Image (Turtle.Get_Width) &
Positive'Image (Turtle.Get_Height) & L.LF &
"%%EndComments" & L.LF &
"%%Page: picture");
if Turtle.Get_Background_Color /= "" then
To_RGB (Turtle.Get_Background_Color, R, G, B);
Put_Line (This.File.all, RGB_To_String (R, G, B) & L.Space &
"setrgbcolor" & L.LF &
"newpath" & L.LF &
"0 0 moveto" & L.LF &
Trim (Positive'Image (Turtle.Get_Width), Left) &
" 0 lineto " & L.LF &
Trim (Positive'Image (Turtle.Get_Width), Left) &
Positive'Image (Turtle.Get_Height) & " lineto" & L.LF &
"0" & Positive'Image (Turtle.Get_Height) & " lineto" &
L.LF & "closepath" & L.LF &
"fill");
end if;
To_RGB (Turtle.Get_Foreground_Color, R, G, B);
Put_Line (This.File.all, RGB_To_String (R, G, B) & L.Space &
"setrgbcolor" & L.LF &
"newpath" & L.LF &
Trim (Fixed_Point'Image (Fixed_Point (Turtle.Get_Offset_X +
Turtle.Get_Margin_Left)), Left)
& L.Space &
Trim (Fixed_Point'Image (Fixed_Point (Turtle.Get_Offset_Y +
Turtle.Get_Margin_Bottom)), Left)
& L.Space & "moveto");
end Configure;
procedure Draw (This : in out Instance)
is
use LSE.Model.IO.Text_File;
begin
Put_Line (This.File.all, "closepath");
Put_Line (This.File.all, "stroke");
Put_Line (This.File.all, "showpage");
Close_File (This.File.all);
end Draw;
procedure Forward (This : in out Instance;
Coordinate : LSE.Utils.Coordinate_2D.Coordinate;
Trace : Boolean := False)
is
use Ada.Float_Text_IO;
begin
Put (File => This.File.all,
Item => Coordinate.Get_X,
Aft => 2,
Exp => 0);
Put (This.File.all, L.Space);
Put (File => This.File.all,
Item => Coordinate.Get_Y,
Aft => 2,
Exp => 0);
if Trace then
Put_Line (This.File.all, " rlineto");
else
Put_Line (This.File.all, " rmoveto");
end if;
end Forward;
procedure Rotate_Clockwise (This : in out Instance)
is
begin
null;
end Rotate_Clockwise;
procedure Rotate_Anticlockwise (This : in out Instance)
is
begin
null;
end Rotate_Anticlockwise;
procedure UTurn (This : in out Instance)
is
begin
null;
end UTurn;
procedure Position_Save (This : in out Instance)
is
begin
null;
end Position_Save;
procedure Position_Restore (This : in out Instance;
X, Y : Fixed_Point)
is
use Ada.Strings;
R : Unbounded_String;
begin
R := Trim (To_Unbounded_String (Fixed_Point'Image (X)), Both) &
L.Space & Trim (To_Unbounded_String (Fixed_Point'Image (Y)), Both) &
L.Space & "rmoveto";
Put_Line (This.File.all, To_String (R));
end Position_Restore;
end LSE.Model.IO.Drawing_Area.PostScript;
|
with Ada.Strings.Wide_Hash;
function Ada.Strings.Wide_Bounded.Wide_Hash (
Key : Bounded.Bounded_Wide_String)
return Containers.Hash_Type is
begin
return Strings.Wide_Hash (Key.Element (1 .. Key.Length));
end Ada.Strings.Wide_Bounded.Wide_Hash;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure String_Concatenation is
S1 : constant String := "Hello";
S2 : constant String := S1 & " literal";
begin
Put_Line (S1);
Put_Line (S2);
end String_Concatenation;
|
-- { dg-do compile }
procedure Unaligned_Rep_Clause is
type One_Bit_Record is
record
B : Boolean;
end record;
Pragma Pack(One_Bit_Record);
subtype Version_Number_Type is String (1 .. 3);
type Inter is
record
Version : Version_Number_Type;
end record;
type Msg_Type is
record
Status : One_Bit_Record;
Version : Inter;
end record;
for Msg_Type use
record
Status at 0 range 0 .. 0;
Version at 0 range 1 .. 24;
end record;
for Msg_Type'Size use 25;
Data : Msg_Type;
Pragma Warnings (Off, Data);
Version : Inter;
begin
Version := Data.Version;
end;
|
-----------------------------------------------------------------------
-- awa-wikis-previews -- Wiki preview management
-- Copyright (C) 2015 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 EL.Expressions;
with ASF.Applications;
with AWA.Modules;
with AWA.Jobs.Services;
with AWA.Jobs.Modules;
with AWA.Wikis.Modules;
with AWA.Wikis.Models;
-- == Wiki Preview Module ==
-- The <tt>AWA.Wikis.Previews</tt> package implements a preview image generation for a wiki page.
-- This module is optional, it is possible to use the wikis without preview support. When the
-- module is registered, it listens to wiki page lifecycle events. When a new wiki content is
-- changed, it triggers a job to make the preview. The preview job uses the
-- <tt>wkhtmotoimage</tt> external program to make the preview image.
package AWA.Wikis.Previews is
-- The name under which the module is registered.
NAME : constant String := "wiki_previews";
-- The configuration parameter that defines how to build the wiki preview template path.
PARAM_PREVIEW_TEMPLATE : constant String := "wiki_preview_template";
-- The configuration parameter to build the preview command to execute.
PARAM_PREVIEW_COMMAND : constant String := "wiki_preview_command";
-- The configuration parameter that defines how to build the HTML preview path.
PARAM_PREVIEW_HTML : constant String := "wiki_preview_html";
-- The configuration parameter that defines the path for the tmp directory.
PARAM_PREVIEW_TMPDIR : constant String := "wiki_preview_tmp";
-- The worker procedure that performs the preview job.
procedure Preview_Worker (Job : in out AWA.Jobs.Services.Abstract_Job_Type'Class);
-- Preview job definition.
package Preview_Job_Definition is new AWA.Jobs.Services.Work_Definition (Preview_Worker'Access);
-- ------------------------------
-- Preview wiki module
-- ------------------------------
type Preview_Module is new AWA.Modules.Module
and AWA.Wikis.Modules.Wiki_Lifecycle.Listener with private;
type Preview_Module_Access is access all Preview_Module'Class;
-- Initialize the preview wiki module.
overriding
procedure Initialize (Plugin : in out Preview_Module;
App : in AWA.Modules.Application_Access;
Props : in ASF.Applications.Config);
-- Configures the module after its initialization and after having read its XML configuration.
overriding
procedure Configure (Plugin : in out Preview_Module;
Props : in ASF.Applications.Config);
-- The `On_Create` procedure is called by `Notify_Create` to notify the creation of the page.
overriding
procedure On_Create (Instance : in Preview_Module;
Item : in AWA.Wikis.Models.Wiki_Page_Ref'Class);
-- The `On_Update` procedure is called by `Notify_Update` to notify the update of the page.
overriding
procedure On_Update (Instance : in Preview_Module;
Item : in AWA.Wikis.Models.Wiki_Page_Ref'Class);
-- The `On_Delete` procedure is called by `Notify_Delete` to notify the deletion of the page.
overriding
procedure On_Delete (Instance : in Preview_Module;
Item : in AWA.Wikis.Models.Wiki_Page_Ref'Class);
-- Create a preview job and schedule the job to generate a new thumbnail preview for the page.
procedure Make_Preview_Job (Plugin : in Preview_Module;
Page : in AWA.Wikis.Models.Wiki_Page_Ref'Class);
-- Execute the preview job and make the thumbnail preview. The page is first rendered in
-- an HTML text file and the preview is rendered by using an external command.
procedure Do_Preview_Job (Plugin : in Preview_Module;
Job : in out AWA.Jobs.Services.Abstract_Job_Type'Class);
-- Get the preview module instance associated with the current application.
function Get_Preview_Module return Preview_Module_Access;
private
type Preview_Module is new AWA.Modules.Module
and AWA.Wikis.Modules.Wiki_Lifecycle.Listener with record
Template : EL.Expressions.Expression;
Command : EL.Expressions.Expression;
Html : EL.Expressions.Expression;
Job_Module : AWA.Jobs.Modules.Job_Module_Access;
end record;
end AWA.Wikis.Previews;
|
with Asis.Elements;
with Asis.Exceptions;
with Asis.Expressions;
with Asis.Extensions;
with Asis.Set_Get; use Asis.Set_Get;
with A4G.Int_Knds; use A4G.Int_Knds;
package body Asis_Adapter.Element.Expressions is
-----------------------------
-- Do_Pre_Child_Processing --
-----------------------------
procedure Do_Pre_Child_Processing
(Element : in Asis.Element; State : in out Class)
is
Parent_Name : constant String := Module_Name;
Module_Name : constant String := Parent_Name & ".Do_Pre_Child_Processing";
Result : a_nodes_h.Expression_Struct :=
a_nodes_h.Support.Default_Expression_Struct;
Expression_Kind : Asis.Expression_Kinds :=
Asis.Elements.Expression_Kind (Element);
-- Supporting procedures are in alphabetical order:
--Designator Expressions only applies to certain kinds of attributes
procedure Add_Attribute_Designator_Expressions is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Element);
begin
case Arg_Kind is
when A_First_Attribute |
A_Last_Attribute |
A_Length_Attribute |
A_Range_Attribute |
An_Implementation_Defined_Attribute |
An_Unknown_Attribute =>
Add_Element_List
(This => State,
Elements_In => Asis.Expressions.Attribute_Designator_Expressions (Element),
Dot_Label_Name => "Attribute_Designator_Expressions",
List_Out => Result.Attribute_Designator_Expressions,
Add_Edges => True);
when others => null;
end case;
end;
procedure Add_Allocator_Qualified_Expression is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Allocator_Qualified_Expression (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Allocator_Qualified_Expression", ID);
Result.Allocator_Qualified_Expression := ID;
end;
procedure Add_Allocator_Subtype_Indication is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Allocator_Subtype_Indication (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Allocator_Subtype_Indication", ID);
Result.Allocator_Subtype_Indication := ID;
end;
procedure Add_Array_Component_Associations is
begin
Add_Element_List
(This => State,
Elements_In => Asis.Expressions.
Array_Component_Associations (Element),
Dot_Label_Name => "Array_Component_Associations",
List_Out => Result.Array_Component_Associations,
Add_Edges => True);
end;
procedure Add_Attribute_Kind is
begin
State.Add_To_Dot_Label ("Attribute_Kind",
Asis.Elements.Attribute_Kind (Element)'Image);
Result.Attribute_Kind := anhS.To_Attribute_Kinds (Asis.Elements.Attribute_Kind (Element));
end;
procedure Add_Attribute_Designator_Identifier is
ID : constant a_nodes_h.Element_ID := Get_Element_ID
(Asis.Expressions.Attribute_Designator_Identifier (Element));
begin
State.Add_To_Dot_Label_And_Edge
("Attribute_Designator_Identifier", ID);
Result.Attribute_Designator_Identifier :=
ID;
end;
procedure Add_Converted_Or_Qualified_Expression is
ID : constant a_nodes_h.Element_ID := Get_Element_ID
(Asis.Expressions.Converted_Or_Qualified_Expression (Element));
begin
State.Add_To_Dot_Label_And_Edge
("Converted_Or_Qualified_Expression", ID);
Result.Converted_Or_Qualified_Expression :=
ID;
end;
procedure Add_Converted_Or_Qualified_Subtype_Mark is
ID : constant a_nodes_h.Element_ID := Get_Element_ID
(Asis.Expressions.Converted_Or_Qualified_Subtype_Mark (Element));
begin
State.Add_To_Dot_Label_And_Edge
("Converted_Or_Qualified_Subtype_Mark", ID);
Result.Converted_Or_Qualified_Subtype_Mark :=
ID;
end;
procedure Add_Corresponding_Called_Function is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Corresponding_Called_Function
(Element));
begin
State.Add_To_Dot_Label
("Corresponding_Called_Function", To_String (ID));
Result.Corresponding_Called_Function := ID;
end;
procedure Add_Corresponding_Expression_Type is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Corresponding_Expression_Type
(Element));
begin
State.Add_To_Dot_Label
("Corresponding_Expression_Type", To_String (ID));
Result.Corresponding_Expression_Type := ID;
end;
procedure Add_Corresponding_Name_Declaration is
use Asis;
ID : a_nodes_h.Element_ID := anhS.Invalid_Element_ID;
begin
if Asis.Extensions.Is_Uniquely_Defined (Element) then
ID := Get_Element_ID
(Asis.Expressions.Corresponding_Name_Declaration (Element));
end if;
--May be Invalid/Nil This is so we know if this value is not set
State.Add_To_Dot_Label
("Corresponding_Name_Declaration", To_String (ID));
Result.Corresponding_Name_Declaration := ID;
end;
procedure Add_Corresponding_Name_Definition is
ID : a_nodes_h.Element_ID := anhS.Invalid_Element_ID;
begin
if Asis.Extensions.Is_Uniquely_Defined (Element) then
ID := Get_Element_ID
(Asis.Expressions.Corresponding_Name_Definition (Element));
end if;
--May be Invalid/Nil This is so we know if this value is not set
State.Add_To_Dot_Label
("Corresponding_Name_Definition", To_String (ID));
Result.Corresponding_Name_Definition := ID;
end;
procedure Add_Corresponding_Name_Definition_List is
use Asis;
Parent_Name : constant String := Module_Name;
Module_Name : constant String := Parent_Name &
".Add_Corresponding_Name_Definition_List";
package Logging is new Generic_Logging (Module_Name); use Logging;
procedure Add_List (Elements_In : in Asis.Element_List) is
begin
Add_Element_List
(This => State,
Elements_In => Elements_In,
Dot_Label_Name => "Corresponding_Name_Definition_List",
List_Out => Result.Corresponding_Name_Definition_List);
exception
when X : Asis.Exceptions.Asis_Inappropriate_Element =>
Log_Exception (X);
Log ("Continuing...");
end Add_List;
begin
if Asis.Extensions.Is_Uniquely_Defined (Element) then
Add_List (Asis.Expressions.Corresponding_Name_Definition_List (Element));
else
Add_List (Asis.Nil_Element_List);
end if;
end;
procedure Add_Expression_Paths is
begin
Add_Element_List
(This => State,
Elements_In => Asis.Expressions.
Expression_Paths (Element),
Dot_Label_Name => "Expression_Paths",
List_Out => Result.Expression_Paths,
Add_Edges => True);
end;
procedure Add_Extension_Aggregate_Expression is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Extension_Aggregate_Expression
(Element));
begin
State.Add_To_Dot_Label_And_Edge
("Extension_Aggregate_Expression", ID);
Result.Extension_Aggregate_Expression := ID;
end;
procedure Add_Function_Call_Parameters is
begin
Add_Element_List
(This => State,
Elements_In => Asis.Expressions.
Function_Call_Parameters (Element),
Dot_Label_Name => "Function_Call_Parameters",
List_Out => Result.Function_Call_Parameters,
Add_Edges => True);
end;
procedure Add_Index_Expressions is
begin
Add_Element_List
(This => State,
Elements_In => Asis.Expressions.
Index_Expressions (Element),
Dot_Label_Name => "Index_Expressions",
List_Out => Result.Index_Expressions,
Add_Edges => True);
end;
procedure Add_Membership_Test_Choices is
begin
Add_Element_List
(This => State,
Elements_In => Asis.Expressions.
Membership_Test_Choices (Element),
Dot_Label_Name => "Membership_Test_Choices",
List_Out => Result.Membership_Test_Choices,
Add_Edges => True);
end;
procedure Add_Membership_Test_Expression is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Membership_Test_Expression (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Membership_Test_Expression", ID);
Result.Membership_Test_Expression := ID;
end;
procedure Add_Name_Image is
function TQS (This : in Wide_String) return String
renames To_Quoted_String;
procedure Add_It_Quoted (It : in Wide_String) is
begin
State.Add_To_Dot_Label ("Name_Image", TQS (It));
end Add_It_Quoted;
WS : constant Wide_String := Asis.Expressions.Name_Image (Element);
S : constant String := To_String(WS);
-- If the name image contains < or >, graphviz will barf. Use the
-- correct special character identifier for those:
procedure Add_To_Dot_Label is
begin
-- Look for ">", "<", ">=", or "<=":
If S = TQS (">") then
Add_It_Quoted (">");
elsif S = TQS ("<") then
Add_It_Quoted ("<");
elsif S = TQS (">=") then
Add_It_Quoted (">=");
elsif S = TQS ("<=") then
Add_It_Quoted ("<=");
else
-- Not adding quotes in order to reduce changes to dot files
-- during RC-511. Created RC-524 to straighten this out.
State.Add_To_Dot_Label ("Name_Image", WS);
end if;
end Add_To_Dot_Label;
begin -- Add_Name_Image
Result.Name_Image := To_Chars_Ptr (WS);
Add_To_Dot_Label;
end;
procedure Add_Expression_Parenthesized is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Expression_Parenthesized (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Expression_Parenthesized", ID);
Result.Expression_Parenthesized := ID;
end;
procedure Add_Prefix is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Prefix (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Prefix", ID);
Result.Prefix := ID;
end;
procedure Add_Record_Component_Associations is
begin
Add_Element_List
(This => State,
Elements_In => Asis.Expressions.
Record_Component_Associations (Element),
Dot_Label_Name => "Record_Component_Associations",
List_Out => Result.Record_Component_Associations,
Add_Edges => True);
end;
procedure Add_Selector is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Selector (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Selector", ID);
Result.Selector := ID;
end;
procedure Add_Short_Circuit_Operation_Left_Expression is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Short_Circuit_Operation_Left_Expression (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Short_Circuit_Operation_Left_Expression", ID);
Result.Short_Circuit_Operation_Left_Expression := ID;
end;
procedure Add_Short_Circuit_Operation_Right_Expression is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Short_Circuit_Operation_Right_Expression (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Short_Circuit_Operation_Right_Expression", ID);
Result.Short_Circuit_Operation_Right_Expression := ID;
end;
procedure Add_Slice_Range is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Slice_Range (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Slice_Range", ID);
Result.Slice_Range := ID;
end;
procedure Add_Subpool_Name is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Expressions.Subpool_Name (Element));
begin
State.Add_To_Dot_Label_And_Edge ("Subpool_Name", ID);
Result.Subpool_Name := ID;
end;
procedure Add_Value_Image is
WS : constant Wide_String := Asis.Expressions.Value_Image (Element);
use all type Asis.Expression_Kinds;
begin
State.Add_To_Dot_Label
("Value_Image",
(if Expression_Kind = A_String_Literal then
To_Quoted_String (WS)
else
To_String (WS)));
Result.Value_Image := To_Chars_Ptr(WS);
end;
procedure Add_Common_Items is
begin
State.Add_To_Dot_Label ("Expression_Kind", Expression_Kind'Image);
Result.Expression_Kind := anhS.To_Expression_Kinds (Expression_Kind);
Add_Corresponding_Expression_Type;
end Add_Common_Items;
use all type Asis.Expression_Kinds;
begin
If Expression_Kind /= Not_An_Expression then
Add_Common_Items;
end if;
case Expression_Kind is
when Not_An_Expression =>
raise Program_Error with
Module_Name & " called with: " & Expression_Kind'Image;
when A_Box_Expression => -- A2005
-- No more info:
null;
when An_Integer_Literal =>
Add_Value_Image;
when A_Real_Literal =>
Add_Value_Image;
when A_String_Literal =>
Add_Value_Image;
when An_Identifier =>
Add_Name_Image;
Add_Corresponding_Name_Definition;
Add_Corresponding_Name_Definition_List;
Add_Corresponding_Name_Declaration;
when An_Operator_Symbol =>
Add_Name_Image;
Add_Corresponding_Name_Definition;
Add_Corresponding_Name_Definition_List;
Add_Corresponding_Name_Declaration;
Result.Operator_Kind := Add_Operator_Kind (State, Element);
when A_Character_Literal =>
Add_Name_Image;
Add_Corresponding_Name_Definition;
Add_Corresponding_Name_Definition_List;
Add_Corresponding_Name_Declaration;
when An_Enumeration_Literal =>
Add_Name_Image;
Add_Corresponding_Name_Definition;
Add_Corresponding_Name_Definition_List;
Add_Corresponding_Name_Declaration;
when An_Explicit_Dereference =>
Add_Prefix; --
when A_Function_Call =>
Add_Prefix;
Add_Corresponding_Called_Function;
Add_Function_Call_Parameters;
when An_Indexed_Component =>
Add_Index_Expressions;--
Add_Prefix;
--Corresponding_Called_Function; 2012 only
--Is_Generatized_Indexing 2012 only
when A_Slice =>
Add_Prefix;--
Add_Slice_Range;
when A_Selected_Component =>
Add_Prefix;--selected_component.ads
Add_Selector;
when An_Attribute_Reference =>
Add_Attribute_Kind;
Add_Prefix;
Add_Attribute_Designator_Identifier;
Add_Attribute_Designator_Expressions;
when A_Record_Aggregate =>
Add_Record_Component_Associations;
when An_Extension_Aggregate =>
Add_Record_Component_Associations;
Add_Extension_Aggregate_Expression;
when A_Positional_Array_Aggregate =>
Add_Array_Component_Associations;
when A_Named_Array_Aggregate =>
Add_Array_Component_Associations;
when An_And_Then_Short_Circuit =>
Add_Short_Circuit_Operation_Left_Expression;--short_circuit.adb
Add_Short_Circuit_Operation_Right_Expression;
when An_Or_Else_Short_Circuit =>
Add_Short_Circuit_Operation_Left_Expression;--short_circuit.adb
Add_Short_Circuit_Operation_Right_Expression;
when An_In_Membership_Test => -- A2012
Add_Membership_Test_Expression;
Add_Membership_Test_Choices;
State.Add_Not_Implemented (Ada_2012);
when A_Not_In_Membership_Test => -- A2012
Add_Membership_Test_Expression;
Add_Membership_Test_Choices;
State.Add_Not_Implemented (Ada_2012);
when A_Null_Literal =>
-- No more information:
null;
when A_Parenthesized_Expression =>
Add_Expression_Parenthesized; --
when A_Raise_Expression => -- A2012
-- No more information:
null;
State.Add_Not_Implemented (Ada_2012);
when A_Type_Conversion =>
Add_Converted_Or_Qualified_Subtype_Mark;
Add_Converted_Or_Qualified_Expression;
when A_Qualified_Expression =>
Add_Converted_Or_Qualified_Subtype_Mark;
Add_Converted_Or_Qualified_Expression;
when An_Allocation_From_Subtype =>
Add_Allocator_Subtype_Indication;
Add_Subpool_Name;
when An_Allocation_From_Qualified_Expression =>
Add_Allocator_Qualified_Expression;
Add_Subpool_Name;
State.Add_Not_Implemented;
when A_Case_Expression => -- A2012
Add_Expression_Paths;
State.Add_Not_Implemented (Ada_2012);
when An_If_Expression => -- A2012
Add_Expression_Paths;
State.Add_Not_Implemented (Ada_2012);
when A_For_All_Quantified_Expression => -- A2012
-- Iterator_Specification
-- Predicate
State.Add_Not_Implemented (Ada_2012);
when A_For_Some_Quantified_Expression => -- A2012
-- Iterator_Specification
-- Predicate
State.Add_Not_Implemented (Ada_2012);
end case;
State.A_Element.Element_Kind := a_nodes_h.An_Expression;
State.A_Element.The_Union.Expression := Result;
end Do_Pre_Child_Processing;
end Asis_Adapter.Element.Expressions;
|
with Ada.Unchecked_Conversion, Interfaces.C.Strings, Interfaces.C.Extensions;
with Libtcod.Color.Conversions;
with error_h, context_init_h, console_init_h, console_printing_h, console_drawing_h;
package body Libtcod.Console is
use Interfaces.C, Interfaces.C.Extensions, Libtcod.Color.Conversions;
use context_h, context_init_h, console_h, console_init_h, console_printing_h,
console_drawing_h;
function Background_Mode_To_Bgflag is new Ada.Unchecked_Conversion
(Source => Background_Mode, Target => TCOD_bkgnd_flag_t);
function Bgflag_to_Background_Mode is new Ada.Unchecked_Conversion
(Source => TCOD_bkgnd_flag_t, Target => Background_Mode);
function To_TCOD_Alignment is new Ada.Unchecked_Conversion
(Source => Alignment_Type, Target => TCOD_alignment_t);
function To_Alignment_Type is new Ada.Unchecked_Conversion
(Source => TCOD_alignment_t, Target => Alignment_Type);
subtype Limited_Controlled is Ada.Finalization.Limited_Controlled;
SDL_Window_Resizable : constant := 16#00000020#;
SDL_Window_Fullscreen : constant := 16#00000001#;
------------------
-- make_context --
------------------
function make_context(w : Width; h : Height; title : String;
resizable : Boolean := True; fullscreen : Boolean := False;
renderer : Renderer_Type := Renderer_SDL2) return Context is
c_title : aliased char_array := To_C(title);
err : error_h.TCOD_Error;
params : aliased TCOD_ContextParams := (columns => int(w), rows => int(h),
renderer_type => Renderer_Type'Pos(renderer),
window_title =>
Strings.To_Chars_Ptr(c_title'Unchecked_Access),
vsync => 1, pixel_width => 0,
pixel_height => 0, argc => 0,
others => <>);
sdl_flags : unsigned := 0;
begin
return result : Context do
if resizable then
sdl_flags := sdl_flags or SDL_Window_Resizable;
end if;
if fullscreen then
sdl_flags := sdl_flags or SDL_Window_Fullscreen;
end if;
params.sdl_window_flags := int(sdl_flags);
err := TCOD_context_new(params'Access, result.data'Address);
if err /= error_h.TCOD_E_OK then
raise Error with Strings.Value(error_h.TCOD_get_error);
end if;
end return;
end make_context;
-----------------
-- make_screen --
-----------------
function make_screen(w : Width; h : Height) return Screen is
begin
return result : Screen :=
Screen'(Limited_Controlled with TCOD_console_new(int(w), int(h))) do
if result.data = null then
raise Program_Error with "TCOD console allocation failed";
end if;
end return;
end make_screen;
--------------
-- Finalize --
--------------
overriding procedure Finalize(self : in out Context) is
begin
TCOD_context_delete(self.data);
end Finalize;
overriding procedure Finalize(self : in out Screen) is
begin
TCOD_console_delete(self.data);
end Finalize;
procedure set_title(title : String) is
c_title : aliased char_array := To_C(title);
begin
TCOD_console_set_window_title(Strings.To_Chars_Ptr(c_title'Unchecked_Access));
end;
procedure set_fullscreen(val : Boolean) is
begin
TCOD_console_set_fullscreen(bool(val));
end;
function is_fullscreen return Boolean is (Boolean(TCOD_console_is_fullscreen));
----------------------
-- is_window_closed --
----------------------
function is_window_closed return Boolean is (Boolean(TCOD_console_is_window_closed));
-------------
-- present --
-------------
procedure present(cxt : in out Context'Class; s : Screen) is
err : error_h.TCOD_Error := TCOD_context_present(cxt.data, s.data, null);
begin
if err /= error_h.TCOD_E_OK then
raise Error with Strings.Value(error_h.TCOD_get_error);
end if;
end;
---------------
-- get_width --
---------------
function get_width(s : Screen) return Width is
(Width(TCOD_console_get_width(s.data)));
----------------
-- get_height --
----------------
function get_height(s : Screen) return Height is
(Height(TCOD_console_get_height(s.data)));
-------------------
-- has_key_color --
-------------------
function has_key_color(s : Screen) return Boolean is
(Boolean(s.data.all.has_key_color));
-------------------
-- set_key_color --
-------------------
procedure set_key_color(s : in out Screen; key_color : RGB_Color) is
begin
TCOD_console_set_key_color(s.data, To_TCOD_ColorRGB(key_color));
end set_key_color;
-------------------
-- get_key_color --
-------------------
function get_key_color(s : Screen) return RGB_Color is
(To_RGB_Color(s.data.all.key_color));
--------------------
-- set_default_fg --
--------------------
procedure set_default_fg(s : in out Screen; fg : RGB_Color) is
begin
TCOD_console_set_default_foreground(s.data, To_TCOD_ColorRGB(fg));
end set_default_fg;
--------------------
-- get_default_fg --
--------------------
function get_default_fg(s : Screen) return RGB_Color is
(To_RGB_Color(TCOD_console_get_default_foreground(s.data)));
--------------------
-- set_default_bg --
--------------------
procedure set_default_bg(s : in out Screen; bg : RGB_Color) is
begin
TCOD_console_set_default_background(s.data, To_TCOD_ColorRGB(bg));
end set_default_bg;
--------------------
-- get_default_bg --
--------------------
function get_default_bg(s : Screen) return RGB_Color is
(To_RGB_Color(TCOD_console_get_default_background(s.data)));
-----------
-- clear --
-----------
procedure clear(s : in out Screen) is
begin
TCOD_console_clear(s.data);
end clear;
------------
-- resize --
------------
procedure resize(s : in out Screen; w : Width; h : Height) is
begin
TCOD_console_resize_u(s.data, int(w), int(h));
end resize;
----------
-- blit --
----------
procedure blit(s : Screen; src_x : X_Pos; src_y : Y_Pos;
w : Width; h : Height; dest : in out Screen;
dest_x : X_Pos; dest_y : Y_Pos) is
begin
TCOD_console_blit(s.data, int(src_x), int(src_y), int(w), int(h),
dest.data, int(dest_x), int(dest_y), 1.0, 1.0);
end blit;
--------------
-- put_char --
--------------
procedure put_char(s : in out Screen; x : X_Pos; y : Y_Pos; ch : Wide_Character) is
begin
TCOD_console_set_char(s.data, int(x), int(y), Wide_Character'Pos(ch));
end put_char;
procedure put_char(s : in out Screen; x : X_Pos; y : Y_Pos; ch : Wide_Character;
mode : Background_Mode) is
begin
TCOD_console_put_char(s.data, int(x), int(y), Wide_Character'Pos(ch),
Background_Mode_To_Bgflag(mode));
end put_char;
procedure put_char(s : in out Screen; x : X_Pos; y : Y_Pos; ch : Wide_Character;
fg_color, bg_color : RGB_Color) is
begin
TCOD_console_put_char_ex(s.data, int(x), int(y), Wide_Character'Pos(ch),
To_TCOD_ColorRGB(fg_color), To_TCOD_ColorRGB(bg_color));
end put_char;
-----------
-- print --
-----------
procedure print(s : in out Screen; x : X_Pos; y : Y_Pos; text : String) is
c_str : aliased char_array := To_C(text);
begin
TCOD_console_print(s.data, int(x), int(y), Strings.To_Chars_Ptr(c_str'Unchecked_Access));
end print;
--------------
-- get_char --
--------------
function get_char(s : Screen; x : X_Pos; y : Y_Pos) return Wide_Character is
(Wide_Character'Val(TCOD_console_get_char(s.data, int(x), int(y))));
-----------------
-- set_char_fg --
-----------------
procedure set_char_fg(s : in out Screen; x : X_Pos; y : Y_Pos; color : RGB_Color) is
begin
TCOD_console_set_char_foreground(s.data, int(x), int(y), To_TCOD_ColorRGB(color));
end set_char_fg;
-----------------
-- get_char_fg --
-----------------
function get_char_fg(s : Screen; x : X_Pos; y : Y_Pos) return RGB_Color is
(To_RGB_Color(TCOD_console_get_char_foreground(s.data, int(x), int(y))));
-----------------
-- set_char_bg --
-----------------
procedure set_char_bg(s : in out Screen; x : X_Pos; y : Y_Pos; color : RGB_Color;
mode : Background_Mode := Background_Set) is
begin
TCOD_console_set_char_background(s.data, int(x), int(y), To_TCOD_ColorRGB(color),
Background_Mode_To_Bgflag(mode));
end set_char_bg;
-----------------
-- get_char_bg --
-----------------
function get_char_bg(s : Screen; x : X_Pos; y : Y_Pos) return RGB_Color is
(To_RGB_Color(TCOD_console_get_char_background(s.data, int(x), int(y))));
-----------------
-- set_bg_mode --
-----------------
procedure set_bg_mode(s : in out Screen; mode : Background_Mode) is
begin
TCOD_console_set_background_flag(s.data, Background_Mode_To_Bgflag(mode));
end set_bg_mode;
-----------------
-- get_bg_mode --
-----------------
function get_bg_mode(s : Screen) return Background_Mode is
(Bgflag_to_Background_Mode(TCOD_console_get_background_flag(s.data)));
-------------------
-- set_alignment --
-------------------
procedure set_alignment(s : in out Screen; alignment : Alignment_Type) is
begin
TCOD_console_set_alignment(s.data, To_TCOD_Alignment(alignment));
end set_alignment;
-------------------
-- get_alignment --
-------------------
function get_alignment(s : Screen) return Alignment_Type is
(To_Alignment_Type(TCOD_console_get_alignment(s.data)));
----------
-- rect --
----------
procedure rect(s : in out Screen; x : X_Pos; y : Y_Pos; w : Width; h : Height;
clear : Boolean := False; bg_flag : Background_Mode := Background_Set) is
begin
TCOD_console_rect(s.data, int(x), int(y), int(w), int(h), bool(clear),
Background_Mode_To_Bgflag(bg_flag));
end rect;
end Libtcod.Console;
|
--
-- Copyright (C) 2015-2016 secunet Security Networks AG
--
-- 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 2 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.
--
with HW.GFX.GMA.Config;
private package HW.GFX.GMA.PCH is
type FDI_Port_Type is (FDI_A, FDI_B, FDI_C);
----------------------------------------------------------------------------
-- common to all PCH outputs
PCH_TRANSCODER_SELECT_SHIFT : constant :=
(case Config.CPU is
when Ironlake => 30,
when Sandybridge | Ivybridge => 29,
when others => 0);
PCH_TRANSCODER_SELECT_MASK : constant :=
(case Config.CPU is
when Ironlake => 1 * 2 ** 30,
when Sandybridge | Ivybridge => 3 * 2 ** 29,
when others => 0);
type PCH_TRANSCODER_SELECT_Array is array (FDI_Port_Type) of Word32;
PCH_TRANSCODER_SELECT : constant PCH_TRANSCODER_SELECT_Array :=
(FDI_A => 0 * 2 ** PCH_TRANSCODER_SELECT_SHIFT,
FDI_B => 1 * 2 ** PCH_TRANSCODER_SELECT_SHIFT,
FDI_C => 2 * 2 ** PCH_TRANSCODER_SELECT_SHIFT);
end HW.GFX.GMA.PCH;
|
with Ada.Streams; use Ada.Streams;
package body Opt41_Pkg is
type Wstream is new Root_Stream_Type with record
S : Unbounded_String;
end record;
procedure Read (Stream : in out Wstream;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset) is null;
procedure Write (Stream : in out Wstream; Item : Stream_Element_Array) is
begin
for J in Item'Range loop
Append (Stream.S, Character'Val (Item (J)));
end loop;
end Write;
function Rec_Write (R : Rec) return Unbounded_String is
S : aliased Wstream;
begin
Rec'Output (S'Access, R);
return S.S;
end Rec_Write;
type Rstream is new Root_Stream_Type with record
S : String_Access;
Idx : Integer := 1;
end record;
procedure Write (Stream : in out Rstream; Item : Stream_Element_Array) is null;
procedure Read (Stream : in out Rstream;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset) is
begin
Last := Stream_Element_Offset'Min
(Item'Last, Item'First + Stream_Element_Offset (Stream.S'Last - Stream.Idx));
for I in Item'First .. Last loop
Item (I) := Stream_Element (Character'Pos (Stream.S (Stream.Idx)));
Stream.Idx := Stream.Idx + 1;
end loop;
end Read;
function Rec_Read (Str : String_Access) return Rec is
S : aliased Rstream;
begin
S.S := Str;
return Rec'Input (S'Access);
end Rec_Read;
end Opt41_Pkg;
|
with STM32GD.GPIO; use STM32GD.GPIO;
with STM32GD.GPIO.Pin;
with STM32GD.CLOCKS;
with STM32GD.CLOCKS.Tree;
with STM32GD.USART;
with STM32GD.USART.Peripheral;
with Drivers.Text_IO;
package STM32GD.Board is
package GPIO renames STM32GD.GPIO;
package Clocks is new STM32GD.Clocks.Tree;
package BUTTON is new Pin (Pin => Pin_12,
Port => Port_D,
Mode => Mode_Out);
package LED is new Pin (Pin => Pin_12,
Port => Port_D,
Mode => Mode_Out);
package LED2 is new Pin (Pin => Pin_13,
Port => Port_D,
Mode => Mode_Out);
package LED3 is new Pin (Pin => Pin_14,
Port => Port_D,
Mode => Mode_Out);
package LED4 is new Pin (Pin => Pin_15,
Port => Port_D,
Mode => Mode_Out);
package TX is new Pin (Pin => Pin_2,
Port => Port_A,
Pull_Resistor => Pull_Up,
Mode => Mode_AF,
Alternate_Function => 7);
package RX is new Pin (Pin => Pin_3,
Port => Port_A,
Pull_Resistor => Pull_Up,
Mode => Mode_AF,
Alternate_Function => 7);
package USART is new STM32GD.USART.Peripheral (
USART => STM32GD.USART.USART_2,
Speed => 115200,
Clock => Clocks.PCLK1);
package Text_IO is new Drivers.Text_IO (USART => STM32GD.Board.USART);
procedure Init;
end STM32GD.Board;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . I M G _ E N U M _ N E W --
-- --
-- S p e c --
-- --
-- Copyright (C) 2000-2019, 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. --
-- --
------------------------------------------------------------------------------
-- Enumeration_Type'Image for all enumeration types except those in package
-- Standard (where we have no opportunity to build image tables), and in
-- package System (where it is too early to start building image tables).
-- Special routines exist for the enumeration types in these packages.
-- This is the new version of the package, for use by compilers built after
-- Nov 21st, 2007, which provides procedures that avoid using the secondary
-- stack. The original package System.Img_Enum is maintained in the sources
-- for bootstrapping with older versions of the compiler which expect to find
-- functions in this package.
pragma Compiler_Unit_Warning;
package System.Img_Enum_New is
pragma Pure;
procedure Image_Enumeration_8
(Pos : Natural;
S : in out String;
P : out Natural;
Names : String;
Indexes : System.Address);
-- Used to compute Enum'Image (Str) where Enum is some enumeration type
-- other than those defined in package Standard. Names is a string with
-- a lower bound of 1 containing the characters of all the enumeration
-- literals concatenated together in sequence. Indexes is the address of
-- an array of type array (0 .. N) of Natural_8, where N is the number of
-- enumeration literals in the type. The Indexes values are the starting
-- subscript of each enumeration literal, indexed by Pos values, with an
-- extra entry at the end containing Names'Length + 1. The reason that
-- Indexes is passed by address is that the actual type is created on the
-- fly by the expander. The desired 'Image value is stored in S (1 .. P)
-- and P is set on return. The caller guarantees that S is long enough to
-- hold the result and that the lower bound is 1.
procedure Image_Enumeration_16
(Pos : Natural;
S : in out String;
P : out Natural;
Names : String;
Indexes : System.Address);
-- Identical to Set_Image_Enumeration_8 except that it handles types using
-- array (0 .. Num) of Natural_16 for the Indexes table.
procedure Image_Enumeration_32
(Pos : Natural;
S : in out String;
P : out Natural;
Names : String;
Indexes : System.Address);
-- Identical to Set_Image_Enumeration_8 except that it handles types using
-- array (0 .. Num) of Natural_32 for the Indexes table.
end System.Img_Enum_New;
|
------------------------------------------------------------------------------
-- --
-- Ada User Repository Annex (AURA) --
-- Reference Implementation --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (ANNEXI-STRAYLINE) --
-- --
-- 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 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 --
-- OWNER 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 package handles the checkout specification files, as well as the
-- checkout action (copying from the cache)
with Progress;
with Registrar.Subsystems;
package Checkout is
-------------------
-- Checkout_Pass --
-------------------
procedure Checkout_Pass;
Checkout_Pass_Progress: aliased Progress.Progress_Tracker;
-- Should be called only after:
-- * The root directory has been entered to the Registrar,
-- * Repositories have been initialized.
--
-- This operation interates through all "Requested" AURA Subsystems and
-- dispatches to a work order per subsystem that one of the following
-- actions, entering all units of the subsystem's root if aquired:
--
-- * Checkout spec is available, relevent source directory exists:
--
-- The subsystem's Source_Repository is set to that specified by the
-- Checkout spec. If that index is not valid, the the process fails.
-- The source contents (exluding subdirectories) are then entered
-- into the Registrar, and the Subsystem's state is promoted to "Aquired"
--
-- * Checkout spec is available, relevent source directory does not exist:
--
-- This case is where a checkout operation is actually triggered
--
-- The subsystem's Source_Repository is set to that specified by the
-- Checkout spec. If that index is not valid, the the process fails.
--
-- == Source_Repository is not the "root repository":
--
-- If Cache_State of Available, the relevent subdirectory is copied
-- out of the cache (checked-out), and the copied directory is entered
-- with the Registrar (not including sub-directories).
--
-- If the cache does not contain the expected directory, checkout of
-- the subsystem fails.
--
-- If the relevant Repository is not Cached, it is marked as
-- Requested, and will be checked-out in the next cycle.
--
-- == Source_Repository is the "root repository":
--
-- All cached repositories starting from index 2 are scanned for the
-- subsystem, until it is found, the index is not cached, or the index
-- reaches the end of all repositories.
--
-- If the subsystem is found, the repository is set to the index of
-- the hit, and the checkout spec is written. If the subsystem is not
-- found, but there remain uncached repositories, then all remaining
-- uncached repositories are marked as requested.
--
-- If all repositories are cached, and the subsystem cannot be found,
-- the checkout of the subsystem fails
--
-- If the checkout was successful, the subsystem's state is promoted
-- to "Aquired"
--
-- * Checkout spec is not available, relevant source directory exists:
--
-- The subsystem's Source_Repository is set to the default "project
-- local" index of 1, a Checkout spec is generated. The source contents
-- (exluding subdirectories) are then entered into the Registrar, and the
-- Subsystem's state is promoted to "Aquired"
--
-- * Checkout spec is not available, relevant source directory does not
-- exist:
--
-- The subsystem's Source_Repository is set to the default "project
-- local" index of 1, and a Checkout spec is generated. The Subsystem's
-- state is not modified (remains "Requested"). This means that the
-- next checkout pass will search for an approprite repository
--
-- The Checkout_Pass_Progress tracker progress of each candidate checkout
-- (Requested Subsystem).
-------------------------
-- Write_Checkout_Spec --
-------------------------
procedure Write_Checkout_Spec (SS: in Registrar.Subsystems.Subsystem);
-- Writes (or regenerates) the checkout spec file for SS. This is a
-- sequential operation.
--
-- This procedure should be invoked if the Source_Repository value of
-- a subsystem is changed.
--
-- If the spec already exists (the unit is registered), then it is
-- re-written. If the spec has not been registered, it is entered
-- to the registrar after generation.
end Checkout;
|
-----------------------------------------------------------------------
-- asf-validators -- ASF Validators
-- Copyright (C) 2010 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 EL.Objects;
with ASF.Components.Base;
with ASF.Contexts.Faces;
-- The <b>ASF.Validators</b> defines an interface used by the validation model
-- to check during the validation phase that the submitted values are valid.
--
-- See JSR 314 - JavaServer Faces Specification 3.5 Validation Model
-- (To_String is the JSF getAsString method and To_Object is the JSF getAsObject method)
package ASF.Validators is
Invalid_Value : exception;
-- ------------------------------
-- Validator
-- ------------------------------
-- The <b>Validator</b> implements a procedure to verify the validity of
-- an input parameter. The <b>validate</b> procedure is called after the
-- converter. The validator instance must be registered in
-- the component factory (See <b>ASF.Factory.Component_Factory</b>).
-- Unlike the Java implementation, the instance will be shared by multiple
-- views and requests. The validator is also responsible for adding the necessary
-- error message in the faces context.
type Validator is limited interface;
type Validator_Access is access all Validator'Class;
-- Verify that the value matches the validation rules defined by the validator.
-- If some error are found, the procedure should create a <b>FacesMessage</b>
-- describing the problem and add that message to the current faces context.
-- The procedure can examine the state and modify the component tree.
-- It must raise the <b>Invalid_Value</b> exception if the value is not valid.
procedure Validate (Valid : in Validator;
Context : in out ASF.Contexts.Faces.Faces_Context'Class;
Component : in out ASF.Components.Base.UIComponent'Class;
Value : in EL.Objects.Object) is abstract;
end ASF.Validators;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- C H E C K S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-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. 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 COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- 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 Casing; use Casing;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Eval_Fat; use Eval_Fat;
with Exp_Ch11; use Exp_Ch11;
with Exp_Ch2; use Exp_Ch2;
with Exp_Ch4; use Exp_Ch4;
with Exp_Pakd; use Exp_Pakd;
with Exp_Util; use Exp_Util;
with Expander; use Expander;
with Freeze; use Freeze;
with Lib; use Lib;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Output; use Output;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch8; use Sem_Ch8;
with Sem_Disp; use Sem_Disp;
with Sem_Eval; use Sem_Eval;
with Sem_Mech; use Sem_Mech;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sem_Warn; use Sem_Warn;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Snames; use Snames;
with Sprint; use Sprint;
with Stand; use Stand;
with Stringt; use Stringt;
with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Validsw; use Validsw;
package body Checks is
-- General note: many of these routines are concerned with generating
-- checking code to make sure that constraint error is raised at runtime.
-- Clearly this code is only needed if the expander is active, since
-- otherwise we will not be generating code or going into the runtime
-- execution anyway.
-- We therefore disconnect most of these checks if the expander is
-- inactive. This has the additional benefit that we do not need to
-- worry about the tree being messed up by previous errors (since errors
-- turn off expansion anyway).
-- There are a few exceptions to the above rule. For instance routines
-- such as Apply_Scalar_Range_Check that do not insert any code can be
-- safely called even when the Expander is inactive (but Errors_Detected
-- is 0). The benefit of executing this code when expansion is off, is
-- the ability to emit constraint error warning for static expressions
-- even when we are not generating code.
-- The above is modified in gnatprove mode to ensure that proper check
-- flags are always placed, even if expansion is off.
-------------------------------------
-- Suppression of Redundant Checks --
-------------------------------------
-- This unit implements a limited circuit for removal of redundant
-- checks. The processing is based on a tracing of simple sequential
-- flow. For any sequence of statements, we save expressions that are
-- marked to be checked, and then if the same expression appears later
-- with the same check, then under certain circumstances, the second
-- check can be suppressed.
-- Basically, we can suppress the check if we know for certain that
-- the previous expression has been elaborated (together with its
-- check), and we know that the exception frame is the same, and that
-- nothing has happened to change the result of the exception.
-- Let us examine each of these three conditions in turn to describe
-- how we ensure that this condition is met.
-- First, we need to know for certain that the previous expression has
-- been executed. This is done principally by the mechanism of calling
-- Conditional_Statements_Begin at the start of any statement sequence
-- and Conditional_Statements_End at the end. The End call causes all
-- checks remembered since the Begin call to be discarded. This does
-- miss a few cases, notably the case of a nested BEGIN-END block with
-- no exception handlers. But the important thing is to be conservative.
-- The other protection is that all checks are discarded if a label
-- is encountered, since then the assumption of sequential execution
-- is violated, and we don't know enough about the flow.
-- Second, we need to know that the exception frame is the same. We
-- do this by killing all remembered checks when we enter a new frame.
-- Again, that's over-conservative, but generally the cases we can help
-- with are pretty local anyway (like the body of a loop for example).
-- Third, we must be sure to forget any checks which are no longer valid.
-- This is done by two mechanisms, first the Kill_Checks_Variable call is
-- used to note any changes to local variables. We only attempt to deal
-- with checks involving local variables, so we do not need to worry
-- about global variables. Second, a call to any non-global procedure
-- causes us to abandon all stored checks, since such a all may affect
-- the values of any local variables.
-- The following define the data structures used to deal with remembering
-- checks so that redundant checks can be eliminated as described above.
-- Right now, the only expressions that we deal with are of the form of
-- simple local objects (either declared locally, or IN parameters) or
-- such objects plus/minus a compile time known constant. We can do
-- more later on if it seems worthwhile, but this catches many simple
-- cases in practice.
-- The following record type reflects a single saved check. An entry
-- is made in the stack of saved checks if and only if the expression
-- has been elaborated with the indicated checks.
type Saved_Check is record
Killed : Boolean;
-- Set True if entry is killed by Kill_Checks
Entity : Entity_Id;
-- The entity involved in the expression that is checked
Offset : Uint;
-- A compile time value indicating the result of adding or
-- subtracting a compile time value. This value is to be
-- added to the value of the Entity. A value of zero is
-- used for the case of a simple entity reference.
Check_Type : Character;
-- This is set to 'R' for a range check (in which case Target_Type
-- is set to the target type for the range check) or to 'O' for an
-- overflow check (in which case Target_Type is set to Empty).
Target_Type : Entity_Id;
-- Used only if Do_Range_Check is set. Records the target type for
-- the check. We need this, because a check is a duplicate only if
-- it has the same target type (or more accurately one with a
-- range that is smaller or equal to the stored target type of a
-- saved check).
end record;
-- The following table keeps track of saved checks. Rather than use an
-- extensible table, we just use a table of fixed size, and we discard
-- any saved checks that do not fit. That's very unlikely to happen and
-- this is only an optimization in any case.
Saved_Checks : array (Int range 1 .. 200) of Saved_Check;
-- Array of saved checks
Num_Saved_Checks : Nat := 0;
-- Number of saved checks
-- The following stack keeps track of statement ranges. It is treated
-- as a stack. When Conditional_Statements_Begin is called, an entry
-- is pushed onto this stack containing the value of Num_Saved_Checks
-- at the time of the call. Then when Conditional_Statements_End is
-- called, this value is popped off and used to reset Num_Saved_Checks.
-- Note: again, this is a fixed length stack with a size that should
-- always be fine. If the value of the stack pointer goes above the
-- limit, then we just forget all saved checks.
Saved_Checks_Stack : array (Int range 1 .. 100) of Nat;
Saved_Checks_TOS : Nat := 0;
-----------------------
-- Local Subprograms --
-----------------------
procedure Apply_Arithmetic_Overflow_Strict (N : Node_Id);
-- Used to apply arithmetic overflow checks for all cases except operators
-- on signed arithmetic types in MINIMIZED/ELIMINATED case (for which we
-- call Apply_Arithmetic_Overflow_Minimized_Eliminated below). N can be a
-- signed integer arithmetic operator (but not an if or case expression).
-- It is also called for types other than signed integers.
procedure Apply_Arithmetic_Overflow_Minimized_Eliminated (Op : Node_Id);
-- Used to apply arithmetic overflow checks for the case where the overflow
-- checking mode is MINIMIZED or ELIMINATED and we have a signed integer
-- arithmetic op (which includes the case of if and case expressions). Note
-- that Do_Overflow_Check may or may not be set for node Op. In these modes
-- we have work to do even if overflow checking is suppressed.
procedure Apply_Division_Check
(N : Node_Id;
Rlo : Uint;
Rhi : Uint;
ROK : Boolean);
-- N is an N_Op_Div, N_Op_Rem, or N_Op_Mod node. This routine applies
-- division checks as required if the Do_Division_Check flag is set.
-- Rlo and Rhi give the possible range of the right operand, these values
-- can be referenced and trusted only if ROK is set True.
procedure Apply_Float_Conversion_Check
(Expr : Node_Id;
Target_Typ : Entity_Id);
-- The checks on a conversion from a floating-point type to an integer
-- type are delicate. They have to be performed before conversion, they
-- have to raise an exception when the operand is a NaN, and rounding must
-- be taken into account to determine the safe bounds of the operand.
procedure Apply_Selected_Length_Checks
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id;
Do_Static : Boolean);
-- This is the subprogram that does all the work for Apply_Length_Check
-- and Apply_Static_Length_Check. Expr, Target_Typ and Source_Typ are as
-- described for the above routines. The Do_Static flag indicates that
-- only a static check is to be done.
procedure Compute_Range_For_Arithmetic_Op
(Op : Node_Kind;
Lo_Left : Uint;
Hi_Left : Uint;
Lo_Right : Uint;
Hi_Right : Uint;
OK : out Boolean;
Lo : out Uint;
Hi : out Uint);
-- Given an integer arithmetical operation Op and the range of values of
-- its operand(s), try to compute a conservative estimate of the possible
-- range of values for the result of the operation. Thus if OK is True on
-- return, the result is known to lie in the range Lo .. Hi (inclusive).
-- If OK is false, both Lo and Hi are set to No_Uint.
type Check_Type is new Check_Id range Access_Check .. Division_Check;
function Check_Needed (Nod : Node_Id; Check : Check_Type) return Boolean;
-- This function is used to see if an access or division by zero check is
-- needed. The check is to be applied to a single variable appearing in the
-- source, and N is the node for the reference. If N is not of this form,
-- True is returned with no further processing. If N is of the right form,
-- then further processing determines if the given Check is needed.
--
-- The particular circuit is to see if we have the case of a check that is
-- not needed because it appears in the right operand of a short circuited
-- conditional where the left operand guards the check. For example:
--
-- if Var = 0 or else Q / Var > 12 then
-- ...
-- end if;
--
-- In this example, the division check is not required. At the same time
-- we can issue warnings for suspicious use of non-short-circuited forms,
-- such as:
--
-- if Var = 0 or Q / Var > 12 then
-- ...
-- end if;
procedure Find_Check
(Expr : Node_Id;
Check_Type : Character;
Target_Type : Entity_Id;
Entry_OK : out Boolean;
Check_Num : out Nat;
Ent : out Entity_Id;
Ofs : out Uint);
-- This routine is used by Enable_Range_Check and Enable_Overflow_Check
-- to see if a check is of the form for optimization, and if so, to see
-- if it has already been performed. Expr is the expression to check,
-- and Check_Type is 'R' for a range check, 'O' for an overflow check.
-- Target_Type is the target type for a range check, and Empty for an
-- overflow check. If the entry is not of the form for optimization,
-- then Entry_OK is set to False, and the remaining out parameters
-- are undefined. If the entry is OK, then Ent/Ofs are set to the
-- entity and offset from the expression. Check_Num is the number of
-- a matching saved entry in Saved_Checks, or zero if no such entry
-- is located.
function Get_Discriminal (E : Entity_Id; Bound : Node_Id) return Node_Id;
-- If a discriminal is used in constraining a prival, Return reference
-- to the discriminal of the protected body (which renames the parameter
-- of the enclosing protected operation). This clumsy transformation is
-- needed because privals are created too late and their actual subtypes
-- are not available when analysing the bodies of the protected operations.
-- This function is called whenever the bound is an entity and the scope
-- indicates a protected operation. If the bound is an in-parameter of
-- a protected operation that is not a prival, the function returns the
-- bound itself.
-- To be cleaned up???
function Guard_Access
(Cond : Node_Id;
Loc : Source_Ptr;
Expr : Node_Id) return Node_Id;
-- In the access type case, guard the test with a test to ensure
-- that the access value is non-null, since the checks do not
-- not apply to null access values.
procedure Install_Static_Check (R_Cno : Node_Id; Loc : Source_Ptr);
-- Called by Apply_{Length,Range}_Checks to rewrite the tree with the
-- Constraint_Error node.
function Is_Signed_Integer_Arithmetic_Op (N : Node_Id) return Boolean;
-- Returns True if node N is for an arithmetic operation with signed
-- integer operands. This includes unary and binary operators, and also
-- if and case expression nodes where the dependent expressions are of
-- a signed integer type. These are the kinds of nodes for which special
-- handling applies in MINIMIZED or ELIMINATED overflow checking mode.
function Range_Or_Validity_Checks_Suppressed
(Expr : Node_Id) return Boolean;
-- Returns True if either range or validity checks or both are suppressed
-- for the type of the given expression, or, if the expression is the name
-- of an entity, if these checks are suppressed for the entity.
function Selected_Length_Checks
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id;
Warn_Node : Node_Id) return Check_Result;
-- Like Apply_Selected_Length_Checks, except it doesn't modify
-- anything, just returns a list of nodes as described in the spec of
-- this package for the Range_Check function.
-- ??? In fact it does construct the test and insert it into the tree,
-- and insert actions in various ways (calling Insert_Action directly
-- in particular) so we do not call it in GNATprove mode, contrary to
-- Selected_Range_Checks.
function Selected_Range_Checks
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id;
Warn_Node : Node_Id) return Check_Result;
-- Like Apply_Range_Check, except it does not modify anything, just
-- returns a list of nodes as described in the spec of this package
-- for the Range_Check function.
------------------------------
-- Access_Checks_Suppressed --
------------------------------
function Access_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Access_Check);
else
return Scope_Suppress.Suppress (Access_Check);
end if;
end Access_Checks_Suppressed;
-------------------------------------
-- Accessibility_Checks_Suppressed --
-------------------------------------
function Accessibility_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Accessibility_Check);
else
return Scope_Suppress.Suppress (Accessibility_Check);
end if;
end Accessibility_Checks_Suppressed;
-----------------------------
-- Activate_Division_Check --
-----------------------------
procedure Activate_Division_Check (N : Node_Id) is
begin
Set_Do_Division_Check (N, True);
Possible_Local_Raise (N, Standard_Constraint_Error);
end Activate_Division_Check;
-----------------------------
-- Activate_Overflow_Check --
-----------------------------
procedure Activate_Overflow_Check (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
begin
-- Floating-point case. If Etype is not set (this can happen when we
-- activate a check on a node that has not yet been analyzed), then
-- we assume we do not have a floating-point type (as per our spec).
if Present (Typ) and then Is_Floating_Point_Type (Typ) then
-- Ignore call if we have no automatic overflow checks on the target
-- and Check_Float_Overflow mode is not set. These are the cases in
-- which we expect to generate infinities and NaN's with no check.
if not (Machine_Overflows_On_Target or Check_Float_Overflow) then
return;
-- Ignore for unary operations ("+", "-", abs) since these can never
-- result in overflow for floating-point cases.
elsif Nkind (N) in N_Unary_Op then
return;
-- Otherwise we will set the flag
else
null;
end if;
-- Discrete case
else
-- Nothing to do for Rem/Mod/Plus (overflow not possible, the check
-- for zero-divide is a divide check, not an overflow check).
if Nkind (N) in N_Op_Rem | N_Op_Mod | N_Op_Plus then
return;
end if;
end if;
-- Fall through for cases where we do set the flag
Set_Do_Overflow_Check (N);
Possible_Local_Raise (N, Standard_Constraint_Error);
end Activate_Overflow_Check;
--------------------------
-- Activate_Range_Check --
--------------------------
procedure Activate_Range_Check (N : Node_Id) is
begin
Set_Do_Range_Check (N);
Possible_Local_Raise (N, Standard_Constraint_Error);
end Activate_Range_Check;
---------------------------------
-- Alignment_Checks_Suppressed --
---------------------------------
function Alignment_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Alignment_Check);
else
return Scope_Suppress.Suppress (Alignment_Check);
end if;
end Alignment_Checks_Suppressed;
----------------------------------
-- Allocation_Checks_Suppressed --
----------------------------------
-- Note: at the current time there are no calls to this function, because
-- the relevant check is in the run-time, so it is not a check that the
-- compiler can suppress anyway, but we still have to recognize the check
-- name Allocation_Check since it is part of the standard.
function Allocation_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Allocation_Check);
else
return Scope_Suppress.Suppress (Allocation_Check);
end if;
end Allocation_Checks_Suppressed;
-------------------------
-- Append_Range_Checks --
-------------------------
procedure Append_Range_Checks
(Checks : Check_Result;
Stmts : List_Id;
Suppress_Typ : Entity_Id;
Static_Sloc : Source_Ptr)
is
Checks_On : constant Boolean :=
not Index_Checks_Suppressed (Suppress_Typ)
or else
not Range_Checks_Suppressed (Suppress_Typ);
begin
-- For now we just return if Checks_On is false, however this should be
-- enhanced to check for an always True value in the condition and to
-- generate a compilation warning???
if not Checks_On then
return;
end if;
for J in 1 .. 2 loop
exit when No (Checks (J));
if Nkind (Checks (J)) = N_Raise_Constraint_Error
and then Present (Condition (Checks (J)))
then
Append_To (Stmts, Checks (J));
else
Append_To
(Stmts,
Make_Raise_Constraint_Error (Static_Sloc,
Reason => CE_Range_Check_Failed));
end if;
end loop;
end Append_Range_Checks;
------------------------
-- Apply_Access_Check --
------------------------
procedure Apply_Access_Check (N : Node_Id) is
P : constant Node_Id := Prefix (N);
begin
-- We do not need checks if we are not generating code (i.e. the
-- expander is not active). This is not just an optimization, there
-- are cases (e.g. with pragma Debug) where generating the checks
-- can cause real trouble).
if not Expander_Active then
return;
end if;
-- No check if short circuiting makes check unnecessary
if not Check_Needed (P, Access_Check) then
return;
end if;
-- No check if accessing the Offset_To_Top component of a dispatch
-- table. They are safe by construction.
if Tagged_Type_Expansion
and then Present (Etype (P))
and then RTU_Loaded (Ada_Tags)
and then RTE_Available (RE_Offset_To_Top_Ptr)
and then Etype (P) = RTE (RE_Offset_To_Top_Ptr)
then
return;
end if;
-- Otherwise go ahead and install the check
Install_Null_Excluding_Check (P);
end Apply_Access_Check;
-------------------------------
-- Apply_Accessibility_Check --
-------------------------------
procedure Apply_Accessibility_Check
(N : Node_Id;
Typ : Entity_Id;
Insert_Node : Node_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Check_Cond : Node_Id;
Param_Ent : Entity_Id := Param_Entity (N);
Param_Level : Node_Id;
Type_Level : Node_Id;
begin
if Ada_Version >= Ada_2012
and then not Present (Param_Ent)
and then Is_Entity_Name (N)
and then Ekind (Entity (N)) in E_Constant | E_Variable
and then Present (Effective_Extra_Accessibility (Entity (N)))
then
Param_Ent := Entity (N);
while Present (Renamed_Object (Param_Ent)) loop
-- Renamed_Object must return an Entity_Name here
-- because of preceding "Present (E_E_A (...))" test.
Param_Ent := Entity (Renamed_Object (Param_Ent));
end loop;
end if;
if Inside_A_Generic then
return;
-- Only apply the run-time check if the access parameter has an
-- associated extra access level parameter and when the level of the
-- type is less deep than the level of the access parameter, and
-- accessibility checks are not suppressed.
elsif Present (Param_Ent)
and then Present (Extra_Accessibility (Param_Ent))
and then UI_Gt (Object_Access_Level (N),
Deepest_Type_Access_Level (Typ))
and then not Accessibility_Checks_Suppressed (Param_Ent)
and then not Accessibility_Checks_Suppressed (Typ)
then
Param_Level :=
New_Occurrence_Of (Extra_Accessibility (Param_Ent), Loc);
-- Use the dynamic accessibility parameter for the function's result
-- when one has been created instead of statically referring to the
-- deepest type level so as to appropriatly handle the rules for
-- RM 3.10.2 (10.1/3).
if Ekind (Scope (Param_Ent))
in E_Function | E_Operator | E_Subprogram_Type
and then Present (Extra_Accessibility_Of_Result (Scope (Param_Ent)))
then
Type_Level :=
New_Occurrence_Of
(Extra_Accessibility_Of_Result (Scope (Param_Ent)), Loc);
else
Type_Level :=
Make_Integer_Literal (Loc, Deepest_Type_Access_Level (Typ));
end if;
-- Raise Program_Error if the accessibility level of the access
-- parameter is deeper than the level of the target access type.
Check_Cond :=
Make_Op_Gt (Loc,
Left_Opnd => Param_Level,
Right_Opnd => Type_Level);
Insert_Action (Insert_Node,
Make_Raise_Program_Error (Loc,
Condition => Check_Cond,
Reason => PE_Accessibility_Check_Failed));
Analyze_And_Resolve (N);
-- If constant folding has happened on the condition for the
-- generated error, then warn about it being unconditional.
if Nkind (Check_Cond) = N_Identifier
and then Entity (Check_Cond) = Standard_True
then
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_N ("accessibility check fails<<", N);
Error_Msg_N ("\Program_Error [<<", N);
end if;
end if;
end Apply_Accessibility_Check;
--------------------------------
-- Apply_Address_Clause_Check --
--------------------------------
procedure Apply_Address_Clause_Check (E : Entity_Id; N : Node_Id) is
pragma Assert (Nkind (N) = N_Freeze_Entity);
AC : constant Node_Id := Address_Clause (E);
Loc : constant Source_Ptr := Sloc (AC);
Typ : constant Entity_Id := Etype (E);
Expr : Node_Id;
-- Address expression (not necessarily the same as Aexp, for example
-- when Aexp is a reference to a constant, in which case Expr gets
-- reset to reference the value expression of the constant).
begin
-- See if alignment check needed. Note that we never need a check if the
-- maximum alignment is one, since the check will always succeed.
-- Note: we do not check for checks suppressed here, since that check
-- was done in Sem_Ch13 when the address clause was processed. We are
-- only called if checks were not suppressed. The reason for this is
-- that we have to delay the call to Apply_Alignment_Check till freeze
-- time (so that all types etc are elaborated), but we have to check
-- the status of check suppressing at the point of the address clause.
if No (AC)
or else not Check_Address_Alignment (AC)
or else Maximum_Alignment = 1
then
return;
end if;
-- Obtain expression from address clause
Expr := Address_Value (Expression (AC));
-- See if we know that Expr has an acceptable value at compile time. If
-- it hasn't or we don't know, we defer issuing the warning until the
-- end of the compilation to take into account back end annotations.
if Compile_Time_Known_Value (Expr)
and then (Known_Alignment (E) or else Known_Alignment (Typ))
then
declare
AL : Uint := Alignment (Typ);
begin
-- The object alignment might be more restrictive than the type
-- alignment.
if Known_Alignment (E) then
AL := Alignment (E);
end if;
if Expr_Value (Expr) mod AL = 0 then
return;
end if;
end;
-- If the expression has the form X'Address, then we can find out if the
-- object X has an alignment that is compatible with the object E. If it
-- hasn't or we don't know, we defer issuing the warning until the end
-- of the compilation to take into account back end annotations.
elsif Nkind (Expr) = N_Attribute_Reference
and then Attribute_Name (Expr) = Name_Address
and then
Has_Compatible_Alignment (E, Prefix (Expr), False) = Known_Compatible
then
return;
end if;
-- Here we do not know if the value is acceptable. Strictly we don't
-- have to do anything, since if the alignment is bad, we have an
-- erroneous program. However we are allowed to check for erroneous
-- conditions and we decide to do this by default if the check is not
-- suppressed.
-- However, don't do the check if elaboration code is unwanted
if Restriction_Active (No_Elaboration_Code) then
return;
-- Generate a check to raise PE if alignment may be inappropriate
else
-- If the original expression is a nonstatic constant, use the name
-- of the constant itself rather than duplicating its initialization
-- expression, which was extracted above.
-- Note: Expr is empty if the address-clause is applied to in-mode
-- actuals (allowed by 13.1(22)).
if not Present (Expr)
or else
(Is_Entity_Name (Expression (AC))
and then Ekind (Entity (Expression (AC))) = E_Constant
and then Nkind (Parent (Entity (Expression (AC)))) =
N_Object_Declaration)
then
Expr := New_Copy_Tree (Expression (AC));
else
Remove_Side_Effects (Expr);
end if;
if No (Actions (N)) then
Set_Actions (N, New_List);
end if;
Prepend_To (Actions (N),
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd =>
Make_Op_Mod (Loc,
Left_Opnd =>
Unchecked_Convert_To
(RTE (RE_Integer_Address), Expr),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (E, Loc),
Attribute_Name => Name_Alignment)),
Right_Opnd => Make_Integer_Literal (Loc, Uint_0)),
Reason => PE_Misaligned_Address_Value));
Warning_Msg := No_Error_Msg;
Analyze (First (Actions (N)), Suppress => All_Checks);
-- If the above raise action generated a warning message (for example
-- from Warn_On_Non_Local_Exception mode with the active restriction
-- No_Exception_Propagation).
if Warning_Msg /= No_Error_Msg then
-- If the expression has a known at compile time value, then
-- once we know the alignment of the type, we can check if the
-- exception will be raised or not, and if not, we don't need
-- the warning so we will kill the warning later on.
if Compile_Time_Known_Value (Expr) then
Alignment_Warnings.Append
((E => E,
A => Expr_Value (Expr),
P => Empty,
W => Warning_Msg));
-- Likewise if the expression is of the form X'Address
elsif Nkind (Expr) = N_Attribute_Reference
and then Attribute_Name (Expr) = Name_Address
then
Alignment_Warnings.Append
((E => E,
A => No_Uint,
P => Prefix (Expr),
W => Warning_Msg));
-- Add explanation of the warning generated by the check
else
Error_Msg_N
("\address value may be incompatible with alignment of "
& "object?X?", AC);
end if;
end if;
return;
end if;
exception
-- If we have some missing run time component in configurable run time
-- mode then just skip the check (it is not required in any case).
when RE_Not_Available =>
return;
end Apply_Address_Clause_Check;
-------------------------------------
-- Apply_Arithmetic_Overflow_Check --
-------------------------------------
procedure Apply_Arithmetic_Overflow_Check (N : Node_Id) is
begin
-- Use old routine in almost all cases (the only case we are treating
-- specially is the case of a signed integer arithmetic op with the
-- overflow checking mode set to MINIMIZED or ELIMINATED).
if Overflow_Check_Mode = Strict
or else not Is_Signed_Integer_Arithmetic_Op (N)
then
Apply_Arithmetic_Overflow_Strict (N);
-- Otherwise use the new routine for the case of a signed integer
-- arithmetic op, with Do_Overflow_Check set to True, and the checking
-- mode is MINIMIZED or ELIMINATED.
else
Apply_Arithmetic_Overflow_Minimized_Eliminated (N);
end if;
end Apply_Arithmetic_Overflow_Check;
--------------------------------------
-- Apply_Arithmetic_Overflow_Strict --
--------------------------------------
-- This routine is called only if the type is an integer type and an
-- arithmetic overflow check may be needed for op (add, subtract, or
-- multiply). This check is performed if Backend_Overflow_Checks_On_Target
-- is not enabled and Do_Overflow_Check is set. In this case we expand the
-- operation into a more complex sequence of tests that ensures that
-- overflow is properly caught.
-- This is used in CHECKED modes. It is identical to the code for this
-- cases before the big overflow earthquake, thus ensuring that in this
-- modes we have compatible behavior (and reliability) to what was there
-- before. It is also called for types other than signed integers, and if
-- the Do_Overflow_Check flag is off.
-- Note: we also call this routine if we decide in the MINIMIZED case
-- to give up and just generate an overflow check without any fuss.
procedure Apply_Arithmetic_Overflow_Strict (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Rtyp : constant Entity_Id := Root_Type (Typ);
begin
-- Nothing to do if Do_Overflow_Check not set or overflow checks
-- suppressed.
if not Do_Overflow_Check (N) then
return;
end if;
-- An interesting special case. If the arithmetic operation appears as
-- the operand of a type conversion:
-- type1 (x op y)
-- and all the following conditions apply:
-- arithmetic operation is for a signed integer type
-- target type type1 is a static integer subtype
-- range of x and y are both included in the range of type1
-- range of x op y is included in the range of type1
-- size of type1 is at least twice the result size of op
-- then we don't do an overflow check in any case. Instead, we transform
-- the operation so that we end up with:
-- type1 (type1 (x) op type1 (y))
-- This avoids intermediate overflow before the conversion. It is
-- explicitly permitted by RM 3.5.4(24):
-- For the execution of a predefined operation of a signed integer
-- type, the implementation need not raise Constraint_Error if the
-- result is outside the base range of the type, so long as the
-- correct result is produced.
-- It's hard to imagine that any programmer counts on the exception
-- being raised in this case, and in any case it's wrong coding to
-- have this expectation, given the RM permission. Furthermore, other
-- Ada compilers do allow such out of range results.
-- Note that we do this transformation even if overflow checking is
-- off, since this is precisely about giving the "right" result and
-- avoiding the need for an overflow check.
-- Note: this circuit is partially redundant with respect to the similar
-- processing in Exp_Ch4.Expand_N_Type_Conversion, but the latter deals
-- with cases that do not come through here. We still need the following
-- processing even with the Exp_Ch4 code in place, since we want to be
-- sure not to generate the arithmetic overflow check in these cases
-- (Exp_Ch4 would have a hard time removing them once generated).
if Is_Signed_Integer_Type (Typ)
and then Nkind (Parent (N)) = N_Type_Conversion
then
Conversion_Optimization : declare
Target_Type : constant Entity_Id :=
Base_Type (Entity (Subtype_Mark (Parent (N))));
Llo, Lhi : Uint;
Rlo, Rhi : Uint;
LOK, ROK : Boolean;
Vlo : Uint;
Vhi : Uint;
VOK : Boolean;
Tlo : Uint;
Thi : Uint;
begin
if Is_Integer_Type (Target_Type)
and then RM_Size (Root_Type (Target_Type)) >= 2 * RM_Size (Rtyp)
then
Tlo := Expr_Value (Type_Low_Bound (Target_Type));
Thi := Expr_Value (Type_High_Bound (Target_Type));
Determine_Range
(Left_Opnd (N), LOK, Llo, Lhi, Assume_Valid => True);
Determine_Range
(Right_Opnd (N), ROK, Rlo, Rhi, Assume_Valid => True);
if (LOK and ROK)
and then Tlo <= Llo and then Lhi <= Thi
and then Tlo <= Rlo and then Rhi <= Thi
then
Determine_Range (N, VOK, Vlo, Vhi, Assume_Valid => True);
if VOK and then Tlo <= Vlo and then Vhi <= Thi then
Rewrite (Left_Opnd (N),
Make_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Target_Type, Loc),
Expression => Relocate_Node (Left_Opnd (N))));
Rewrite (Right_Opnd (N),
Make_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Target_Type, Loc),
Expression => Relocate_Node (Right_Opnd (N))));
-- Rewrite the conversion operand so that the original
-- node is retained, in order to avoid the warning for
-- redundant conversions in Resolve_Type_Conversion.
Rewrite (N, Relocate_Node (N));
Set_Etype (N, Target_Type);
Analyze_And_Resolve (Left_Opnd (N), Target_Type);
Analyze_And_Resolve (Right_Opnd (N), Target_Type);
-- Given that the target type is twice the size of the
-- source type, overflow is now impossible, so we can
-- safely kill the overflow check and return.
Set_Do_Overflow_Check (N, False);
return;
end if;
end if;
end if;
end Conversion_Optimization;
end if;
-- Now see if an overflow check is required
declare
Siz : constant Int := UI_To_Int (Esize (Rtyp));
Dsiz : constant Int := Siz * 2;
Opnod : Node_Id;
Ctyp : Entity_Id;
Opnd : Node_Id;
Cent : RE_Id;
begin
-- Skip check if back end does overflow checks, or the overflow flag
-- is not set anyway, or we are not doing code expansion, or the
-- parent node is a type conversion whose operand is an arithmetic
-- operation on signed integers on which the expander can promote
-- later the operands to type Integer (see Expand_N_Type_Conversion).
if Backend_Overflow_Checks_On_Target
or else not Do_Overflow_Check (N)
or else not Expander_Active
or else (Present (Parent (N))
and then Nkind (Parent (N)) = N_Type_Conversion
and then Integer_Promotion_Possible (Parent (N)))
then
return;
end if;
-- Otherwise, generate the full general code for front end overflow
-- detection, which works by doing arithmetic in a larger type:
-- x op y
-- is expanded into
-- Typ (Checktyp (x) op Checktyp (y));
-- where Typ is the type of the original expression, and Checktyp is
-- an integer type of sufficient length to hold the largest possible
-- result.
-- If the size of check type exceeds the size of Long_Long_Integer,
-- we use a different approach, expanding to:
-- typ (xxx_With_Ovflo_Check (Integer_64 (x), Integer (y)))
-- where xxx is Add, Multiply or Subtract as appropriate
-- Find check type if one exists
if Dsiz <= Standard_Integer_Size then
Ctyp := Standard_Integer;
elsif Dsiz <= Standard_Long_Long_Integer_Size then
Ctyp := Standard_Long_Long_Integer;
-- No check type exists, use runtime call
else
if Nkind (N) = N_Op_Add then
Cent := RE_Add_With_Ovflo_Check;
elsif Nkind (N) = N_Op_Multiply then
Cent := RE_Multiply_With_Ovflo_Check;
else
pragma Assert (Nkind (N) = N_Op_Subtract);
Cent := RE_Subtract_With_Ovflo_Check;
end if;
Rewrite (N,
OK_Convert_To (Typ,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (Cent), Loc),
Parameter_Associations => New_List (
OK_Convert_To (RTE (RE_Integer_64), Left_Opnd (N)),
OK_Convert_To (RTE (RE_Integer_64), Right_Opnd (N))))));
Analyze_And_Resolve (N, Typ);
return;
end if;
-- If we fall through, we have the case where we do the arithmetic
-- in the next higher type and get the check by conversion. In these
-- cases Ctyp is set to the type to be used as the check type.
Opnod := Relocate_Node (N);
Opnd := OK_Convert_To (Ctyp, Left_Opnd (Opnod));
Analyze (Opnd);
Set_Etype (Opnd, Ctyp);
Set_Analyzed (Opnd, True);
Set_Left_Opnd (Opnod, Opnd);
Opnd := OK_Convert_To (Ctyp, Right_Opnd (Opnod));
Analyze (Opnd);
Set_Etype (Opnd, Ctyp);
Set_Analyzed (Opnd, True);
Set_Right_Opnd (Opnod, Opnd);
-- The type of the operation changes to the base type of the check
-- type, and we reset the overflow check indication, since clearly no
-- overflow is possible now that we are using a double length type.
-- We also set the Analyzed flag to avoid a recursive attempt to
-- expand the node.
Set_Etype (Opnod, Base_Type (Ctyp));
Set_Do_Overflow_Check (Opnod, False);
Set_Analyzed (Opnod, True);
-- Now build the outer conversion
Opnd := OK_Convert_To (Typ, Opnod);
Analyze (Opnd);
Set_Etype (Opnd, Typ);
-- In the discrete type case, we directly generate the range check
-- for the outer operand. This range check will implement the
-- required overflow check.
if Is_Discrete_Type (Typ) then
Rewrite (N, Opnd);
Generate_Range_Check
(Expression (N), Typ, CE_Overflow_Check_Failed);
-- For other types, we enable overflow checking on the conversion,
-- after setting the node as analyzed to prevent recursive attempts
-- to expand the conversion node.
else
Set_Analyzed (Opnd, True);
Enable_Overflow_Check (Opnd);
Rewrite (N, Opnd);
end if;
exception
when RE_Not_Available =>
return;
end;
end Apply_Arithmetic_Overflow_Strict;
----------------------------------------------------
-- Apply_Arithmetic_Overflow_Minimized_Eliminated --
----------------------------------------------------
procedure Apply_Arithmetic_Overflow_Minimized_Eliminated (Op : Node_Id) is
pragma Assert (Is_Signed_Integer_Arithmetic_Op (Op));
Loc : constant Source_Ptr := Sloc (Op);
P : constant Node_Id := Parent (Op);
LLIB : constant Entity_Id := Base_Type (Standard_Long_Long_Integer);
-- Operands and results are of this type when we convert
Result_Type : constant Entity_Id := Etype (Op);
-- Original result type
Check_Mode : constant Overflow_Mode_Type := Overflow_Check_Mode;
pragma Assert (Check_Mode in Minimized_Or_Eliminated);
Lo, Hi : Uint;
-- Ranges of values for result
begin
-- Nothing to do if our parent is one of the following:
-- Another signed integer arithmetic op
-- A membership operation
-- A comparison operation
-- In all these cases, we will process at the higher level (and then
-- this node will be processed during the downwards recursion that
-- is part of the processing in Minimize_Eliminate_Overflows).
if Is_Signed_Integer_Arithmetic_Op (P)
or else Nkind (P) in N_Membership_Test
or else Nkind (P) in N_Op_Compare
-- This is also true for an alternative in a case expression
or else Nkind (P) = N_Case_Expression_Alternative
-- This is also true for a range operand in a membership test
or else (Nkind (P) = N_Range
and then Nkind (Parent (P)) in N_Membership_Test)
then
-- If_Expressions and Case_Expressions are treated as arithmetic
-- ops, but if they appear in an assignment or similar contexts
-- there is no overflow check that starts from that parent node,
-- so apply check now.
if Nkind (P) in N_If_Expression | N_Case_Expression
and then not Is_Signed_Integer_Arithmetic_Op (Parent (P))
then
null;
else
return;
end if;
end if;
-- Otherwise, we have a top level arithmetic operation node, and this
-- is where we commence the special processing for MINIMIZED/ELIMINATED
-- modes. This is the case where we tell the machinery not to move into
-- Bignum mode at this top level (of course the top level operation
-- will still be in Bignum mode if either of its operands are of type
-- Bignum).
Minimize_Eliminate_Overflows (Op, Lo, Hi, Top_Level => True);
-- That call may but does not necessarily change the result type of Op.
-- It is the job of this routine to undo such changes, so that at the
-- top level, we have the proper type. This "undoing" is a point at
-- which a final overflow check may be applied.
-- If the result type was not fiddled we are all set. We go to base
-- types here because things may have been rewritten to generate the
-- base type of the operand types.
if Base_Type (Etype (Op)) = Base_Type (Result_Type) then
return;
-- Bignum case
elsif Is_RTE (Etype (Op), RE_Bignum) then
-- We need a sequence that looks like:
-- Rnn : Result_Type;
-- declare
-- M : Mark_Id := SS_Mark;
-- begin
-- Rnn := Long_Long_Integer'Base (From_Bignum (Op));
-- SS_Release (M);
-- end;
-- This block is inserted (using Insert_Actions), and then the node
-- is replaced with a reference to Rnn.
-- If our parent is a conversion node then there is no point in
-- generating a conversion to Result_Type. Instead, we let the parent
-- handle this. Note that this special case is not just about
-- optimization. Consider
-- A,B,C : Integer;
-- ...
-- X := Long_Long_Integer'Base (A * (B ** C));
-- Now the product may fit in Long_Long_Integer but not in Integer.
-- In MINIMIZED/ELIMINATED mode, we don't want to introduce an
-- overflow exception for this intermediate value.
declare
Blk : constant Node_Id := Make_Bignum_Block (Loc);
Rnn : constant Entity_Id := Make_Temporary (Loc, 'R', Op);
RHS : Node_Id;
Rtype : Entity_Id;
begin
RHS := Convert_From_Bignum (Op);
if Nkind (P) /= N_Type_Conversion then
Convert_To_And_Rewrite (Result_Type, RHS);
Rtype := Result_Type;
-- Interesting question, do we need a check on that conversion
-- operation. Answer, not if we know the result is in range.
-- At the moment we are not taking advantage of this. To be
-- looked at later ???
else
Rtype := LLIB;
end if;
Insert_Before
(First (Statements (Handled_Statement_Sequence (Blk))),
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Rnn, Loc),
Expression => RHS));
Insert_Actions (Op, New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Rnn,
Object_Definition => New_Occurrence_Of (Rtype, Loc)),
Blk));
Rewrite (Op, New_Occurrence_Of (Rnn, Loc));
Analyze_And_Resolve (Op);
end;
-- Here we know the result is Long_Long_Integer'Base, or that it has
-- been rewritten because the parent operation is a conversion. See
-- Apply_Arithmetic_Overflow_Strict.Conversion_Optimization.
else
pragma Assert
(Etype (Op) = LLIB or else Nkind (Parent (Op)) = N_Type_Conversion);
-- All we need to do here is to convert the result to the proper
-- result type. As explained above for the Bignum case, we can
-- omit this if our parent is a type conversion.
if Nkind (P) /= N_Type_Conversion then
Convert_To_And_Rewrite (Result_Type, Op);
end if;
Analyze_And_Resolve (Op);
end if;
end Apply_Arithmetic_Overflow_Minimized_Eliminated;
----------------------------
-- Apply_Constraint_Check --
----------------------------
procedure Apply_Constraint_Check
(N : Node_Id;
Typ : Entity_Id;
No_Sliding : Boolean := False)
is
Desig_Typ : Entity_Id;
begin
-- No checks inside a generic (check the instantiations)
if Inside_A_Generic then
return;
end if;
-- Apply required constraint checks
if Is_Scalar_Type (Typ) then
Apply_Scalar_Range_Check (N, Typ);
elsif Is_Array_Type (Typ) then
-- A useful optimization: an aggregate with only an others clause
-- always has the right bounds.
if Nkind (N) = N_Aggregate
and then No (Expressions (N))
and then Nkind
(First (Choices (First (Component_Associations (N)))))
= N_Others_Choice
then
return;
end if;
if Is_Constrained (Typ) then
Apply_Length_Check (N, Typ);
if No_Sliding then
Apply_Range_Check (N, Typ);
end if;
else
Apply_Range_Check (N, Typ);
end if;
elsif (Is_Record_Type (Typ) or else Is_Private_Type (Typ))
and then Has_Discriminants (Base_Type (Typ))
and then Is_Constrained (Typ)
then
Apply_Discriminant_Check (N, Typ);
elsif Is_Access_Type (Typ) then
Desig_Typ := Designated_Type (Typ);
-- No checks necessary if expression statically null
if Known_Null (N) then
if Can_Never_Be_Null (Typ) then
Install_Null_Excluding_Check (N);
end if;
-- No sliding possible on access to arrays
elsif Is_Array_Type (Desig_Typ) then
if Is_Constrained (Desig_Typ) then
Apply_Length_Check (N, Typ);
end if;
Apply_Range_Check (N, Typ);
-- Do not install a discriminant check for a constrained subtype
-- created for an unconstrained nominal type because the subtype
-- has the correct constraints by construction.
elsif Has_Discriminants (Base_Type (Desig_Typ))
and then Is_Constrained (Desig_Typ)
and then not Is_Constr_Subt_For_U_Nominal (Desig_Typ)
then
Apply_Discriminant_Check (N, Typ);
end if;
-- Apply the 2005 Null_Excluding check. Note that we do not apply
-- this check if the constraint node is illegal, as shown by having
-- an error posted. This additional guard prevents cascaded errors
-- and compiler aborts on illegal programs involving Ada 2005 checks.
if Can_Never_Be_Null (Typ)
and then not Can_Never_Be_Null (Etype (N))
and then not Error_Posted (N)
then
Install_Null_Excluding_Check (N);
end if;
end if;
end Apply_Constraint_Check;
------------------------------
-- Apply_Discriminant_Check --
------------------------------
procedure Apply_Discriminant_Check
(N : Node_Id;
Typ : Entity_Id;
Lhs : Node_Id := Empty)
is
Loc : constant Source_Ptr := Sloc (N);
Do_Access : constant Boolean := Is_Access_Type (Typ);
S_Typ : Entity_Id := Etype (N);
Cond : Node_Id;
T_Typ : Entity_Id;
function Denotes_Explicit_Dereference (Obj : Node_Id) return Boolean;
-- A heap object with an indefinite subtype is constrained by its
-- initial value, and assigning to it requires a constraint_check.
-- The target may be an explicit dereference, or a renaming of one.
function Is_Aliased_Unconstrained_Component return Boolean;
-- It is possible for an aliased component to have a nominal
-- unconstrained subtype (through instantiation). If this is a
-- discriminated component assigned in the expansion of an aggregate
-- in an initialization, the check must be suppressed. This unusual
-- situation requires a predicate of its own.
----------------------------------
-- Denotes_Explicit_Dereference --
----------------------------------
function Denotes_Explicit_Dereference (Obj : Node_Id) return Boolean is
begin
return
Nkind (Obj) = N_Explicit_Dereference
or else
(Is_Entity_Name (Obj)
and then Present (Renamed_Object (Entity (Obj)))
and then Nkind (Renamed_Object (Entity (Obj))) =
N_Explicit_Dereference);
end Denotes_Explicit_Dereference;
----------------------------------------
-- Is_Aliased_Unconstrained_Component --
----------------------------------------
function Is_Aliased_Unconstrained_Component return Boolean is
Comp : Entity_Id;
Pref : Node_Id;
begin
if Nkind (Lhs) /= N_Selected_Component then
return False;
else
Comp := Entity (Selector_Name (Lhs));
Pref := Prefix (Lhs);
end if;
if Ekind (Comp) /= E_Component
or else not Is_Aliased (Comp)
then
return False;
end if;
return not Comes_From_Source (Pref)
and then In_Instance
and then not Is_Constrained (Etype (Comp));
end Is_Aliased_Unconstrained_Component;
-- Start of processing for Apply_Discriminant_Check
begin
if Do_Access then
T_Typ := Designated_Type (Typ);
else
T_Typ := Typ;
end if;
-- If the expression is a function call that returns a limited object
-- it cannot be copied. It is not clear how to perform the proper
-- discriminant check in this case because the discriminant value must
-- be retrieved from the constructed object itself.
if Nkind (N) = N_Function_Call
and then Is_Limited_Type (Typ)
and then Is_Entity_Name (Name (N))
and then Returns_By_Ref (Entity (Name (N)))
then
return;
end if;
-- Only apply checks when generating code and discriminant checks are
-- not suppressed. In GNATprove mode, we do not apply the checks, but we
-- still analyze the expression to possibly issue errors on SPARK code
-- when a run-time error can be detected at compile time.
if not GNATprove_Mode then
if not Expander_Active
or else Discriminant_Checks_Suppressed (T_Typ)
then
return;
end if;
end if;
-- No discriminant checks necessary for an access when expression is
-- statically Null. This is not only an optimization, it is fundamental
-- because otherwise discriminant checks may be generated in init procs
-- for types containing an access to a not-yet-frozen record, causing a
-- deadly forward reference.
-- Also, if the expression is of an access type whose designated type is
-- incomplete, then the access value must be null and we suppress the
-- check.
if Known_Null (N) then
return;
elsif Is_Access_Type (S_Typ) then
S_Typ := Designated_Type (S_Typ);
if Ekind (S_Typ) = E_Incomplete_Type then
return;
end if;
end if;
-- If an assignment target is present, then we need to generate the
-- actual subtype if the target is a parameter or aliased object with
-- an unconstrained nominal subtype.
-- Ada 2005 (AI-363): For Ada 2005, we limit the building of the actual
-- subtype to the parameter and dereference cases, since other aliased
-- objects are unconstrained (unless the nominal subtype is explicitly
-- constrained).
if Present (Lhs)
and then (Present (Param_Entity (Lhs))
or else (Ada_Version < Ada_2005
and then not Is_Constrained (T_Typ)
and then Is_Aliased_View (Lhs)
and then not Is_Aliased_Unconstrained_Component)
or else (Ada_Version >= Ada_2005
and then not Is_Constrained (T_Typ)
and then Denotes_Explicit_Dereference (Lhs)
and then Nkind (Original_Node (Lhs)) /=
N_Function_Call))
then
T_Typ := Get_Actual_Subtype (Lhs);
end if;
-- Nothing to do if the type is unconstrained (this is the case where
-- the actual subtype in the RM sense of N is unconstrained and no check
-- is required).
if not Is_Constrained (T_Typ) then
return;
-- Ada 2005: nothing to do if the type is one for which there is a
-- partial view that is constrained.
elsif Ada_Version >= Ada_2005
and then Object_Type_Has_Constrained_Partial_View
(Typ => Base_Type (T_Typ),
Scop => Current_Scope)
then
return;
end if;
-- Nothing to do if the type is an Unchecked_Union
if Is_Unchecked_Union (Base_Type (T_Typ)) then
return;
end if;
-- Suppress checks if the subtypes are the same. The check must be
-- preserved in an assignment to a formal, because the constraint is
-- given by the actual.
if Nkind (Original_Node (N)) /= N_Allocator
and then (No (Lhs)
or else not Is_Entity_Name (Lhs)
or else No (Param_Entity (Lhs)))
then
if (Etype (N) = Typ
or else (Do_Access and then Designated_Type (Typ) = S_Typ))
and then not Is_Aliased_View (Lhs)
then
return;
end if;
-- We can also eliminate checks on allocators with a subtype mark that
-- coincides with the context type. The context type may be a subtype
-- without a constraint (common case, a generic actual).
elsif Nkind (Original_Node (N)) = N_Allocator
and then Is_Entity_Name (Expression (Original_Node (N)))
then
declare
Alloc_Typ : constant Entity_Id :=
Entity (Expression (Original_Node (N)));
begin
if Alloc_Typ = T_Typ
or else (Nkind (Parent (T_Typ)) = N_Subtype_Declaration
and then Is_Entity_Name (
Subtype_Indication (Parent (T_Typ)))
and then Alloc_Typ = Base_Type (T_Typ))
then
return;
end if;
end;
end if;
-- See if we have a case where the types are both constrained, and all
-- the constraints are constants. In this case, we can do the check
-- successfully at compile time.
-- We skip this check for the case where the node is rewritten as
-- an allocator, because it already carries the context subtype,
-- and extracting the discriminants from the aggregate is messy.
if Is_Constrained (S_Typ)
and then Nkind (Original_Node (N)) /= N_Allocator
then
declare
DconT : Elmt_Id;
Discr : Entity_Id;
DconS : Elmt_Id;
ItemS : Node_Id;
ItemT : Node_Id;
begin
-- S_Typ may not have discriminants in the case where it is a
-- private type completed by a default discriminated type. In that
-- case, we need to get the constraints from the underlying type.
-- If the underlying type is unconstrained (i.e. has no default
-- discriminants) no check is needed.
if Has_Discriminants (S_Typ) then
Discr := First_Discriminant (S_Typ);
DconS := First_Elmt (Discriminant_Constraint (S_Typ));
else
Discr := First_Discriminant (Underlying_Type (S_Typ));
DconS :=
First_Elmt
(Discriminant_Constraint (Underlying_Type (S_Typ)));
if No (DconS) then
return;
end if;
-- A further optimization: if T_Typ is derived from S_Typ
-- without imposing a constraint, no check is needed.
if Nkind (Original_Node (Parent (T_Typ))) =
N_Full_Type_Declaration
then
declare
Type_Def : constant Node_Id :=
Type_Definition (Original_Node (Parent (T_Typ)));
begin
if Nkind (Type_Def) = N_Derived_Type_Definition
and then Is_Entity_Name (Subtype_Indication (Type_Def))
and then Entity (Subtype_Indication (Type_Def)) = S_Typ
then
return;
end if;
end;
end if;
end if;
-- Constraint may appear in full view of type
if Ekind (T_Typ) = E_Private_Subtype
and then Present (Full_View (T_Typ))
then
DconT :=
First_Elmt (Discriminant_Constraint (Full_View (T_Typ)));
else
DconT :=
First_Elmt (Discriminant_Constraint (T_Typ));
end if;
while Present (Discr) loop
ItemS := Node (DconS);
ItemT := Node (DconT);
-- For a discriminated component type constrained by the
-- current instance of an enclosing type, there is no
-- applicable discriminant check.
if Nkind (ItemT) = N_Attribute_Reference
and then Is_Access_Type (Etype (ItemT))
and then Is_Entity_Name (Prefix (ItemT))
and then Is_Type (Entity (Prefix (ItemT)))
then
return;
end if;
-- If the expressions for the discriminants are identical
-- and it is side-effect free (for now just an entity),
-- this may be a shared constraint, e.g. from a subtype
-- without a constraint introduced as a generic actual.
-- Examine other discriminants if any.
if ItemS = ItemT
and then Is_Entity_Name (ItemS)
then
null;
elsif not Is_OK_Static_Expression (ItemS)
or else not Is_OK_Static_Expression (ItemT)
then
exit;
elsif Expr_Value (ItemS) /= Expr_Value (ItemT) then
if Do_Access then -- needs run-time check.
exit;
else
Apply_Compile_Time_Constraint_Error
(N, "incorrect value for discriminant&??",
CE_Discriminant_Check_Failed, Ent => Discr);
return;
end if;
end if;
Next_Elmt (DconS);
Next_Elmt (DconT);
Next_Discriminant (Discr);
end loop;
if No (Discr) then
return;
end if;
end;
end if;
-- In GNATprove mode, we do not apply the checks
if GNATprove_Mode then
return;
end if;
-- Here we need a discriminant check. First build the expression
-- for the comparisons of the discriminants:
-- (n.disc1 /= typ.disc1) or else
-- (n.disc2 /= typ.disc2) or else
-- ...
-- (n.discn /= typ.discn)
Cond := Build_Discriminant_Checks (N, T_Typ);
-- If Lhs is set and is a parameter, then the condition is guarded by:
-- lhs'constrained and then (condition built above)
if Present (Param_Entity (Lhs)) then
Cond :=
Make_And_Then (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Param_Entity (Lhs), Loc),
Attribute_Name => Name_Constrained),
Right_Opnd => Cond);
end if;
if Do_Access then
Cond := Guard_Access (Cond, Loc, N);
end if;
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition => Cond,
Reason => CE_Discriminant_Check_Failed));
end Apply_Discriminant_Check;
-------------------------
-- Apply_Divide_Checks --
-------------------------
procedure Apply_Divide_Checks (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Left : constant Node_Id := Left_Opnd (N);
Right : constant Node_Id := Right_Opnd (N);
Mode : constant Overflow_Mode_Type := Overflow_Check_Mode;
-- Current overflow checking mode
LLB : Uint;
Llo : Uint;
Lhi : Uint;
LOK : Boolean;
Rlo : Uint;
Rhi : Uint;
ROK : Boolean;
pragma Warnings (Off, Lhi);
-- Don't actually use this value
begin
-- If we are operating in MINIMIZED or ELIMINATED mode, and we are
-- operating on signed integer types, then the only thing this routine
-- does is to call Apply_Arithmetic_Overflow_Minimized_Eliminated. That
-- procedure will (possibly later on during recursive downward calls),
-- ensure that any needed overflow/division checks are properly applied.
if Mode in Minimized_Or_Eliminated
and then Is_Signed_Integer_Type (Typ)
then
Apply_Arithmetic_Overflow_Minimized_Eliminated (N);
return;
end if;
-- Proceed here in SUPPRESSED or CHECKED modes
if Expander_Active
and then not Backend_Divide_Checks_On_Target
and then Check_Needed (Right, Division_Check)
then
Determine_Range (Right, ROK, Rlo, Rhi, Assume_Valid => True);
-- Deal with division check
if Do_Division_Check (N)
and then not Division_Checks_Suppressed (Typ)
then
Apply_Division_Check (N, Rlo, Rhi, ROK);
end if;
-- Deal with overflow check
if Do_Overflow_Check (N)
and then not Overflow_Checks_Suppressed (Etype (N))
then
Set_Do_Overflow_Check (N, False);
-- Test for extremely annoying case of xxx'First divided by -1
-- for division of signed integer types (only overflow case).
if Nkind (N) = N_Op_Divide
and then Is_Signed_Integer_Type (Typ)
then
Determine_Range (Left, LOK, Llo, Lhi, Assume_Valid => True);
LLB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
if ((not ROK) or else (Rlo <= (-1) and then (-1) <= Rhi))
and then
((not LOK) or else (Llo = LLB))
then
-- Ensure that expressions are not evaluated twice (once
-- for their runtime checks and once for their regular
-- computation).
Force_Evaluation (Left, Mode => Strict);
Force_Evaluation (Right, Mode => Strict);
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_And_Then (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd =>
Duplicate_Subexpr_Move_Checks (Left),
Right_Opnd => Make_Integer_Literal (Loc, LLB)),
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => Duplicate_Subexpr (Right),
Right_Opnd => Make_Integer_Literal (Loc, -1))),
Reason => CE_Overflow_Check_Failed));
end if;
end if;
end if;
end if;
end Apply_Divide_Checks;
--------------------------
-- Apply_Division_Check --
--------------------------
procedure Apply_Division_Check
(N : Node_Id;
Rlo : Uint;
Rhi : Uint;
ROK : Boolean)
is
pragma Assert (Do_Division_Check (N));
Loc : constant Source_Ptr := Sloc (N);
Right : constant Node_Id := Right_Opnd (N);
Opnd : Node_Id;
begin
if Expander_Active
and then not Backend_Divide_Checks_On_Target
and then Check_Needed (Right, Division_Check)
-- See if division by zero possible, and if so generate test. This
-- part of the test is not controlled by the -gnato switch, since it
-- is a Division_Check and not an Overflow_Check.
and then Do_Division_Check (N)
then
Set_Do_Division_Check (N, False);
if (not ROK) or else (Rlo <= 0 and then 0 <= Rhi) then
if Is_Floating_Point_Type (Etype (N)) then
Opnd := Make_Real_Literal (Loc, Ureal_0);
else
Opnd := Make_Integer_Literal (Loc, 0);
end if;
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd => Duplicate_Subexpr_Move_Checks (Right),
Right_Opnd => Opnd),
Reason => CE_Divide_By_Zero));
end if;
end if;
end Apply_Division_Check;
----------------------------------
-- Apply_Float_Conversion_Check --
----------------------------------
-- Let F and I be the source and target types of the conversion. The RM
-- specifies that a floating-point value X is rounded to the nearest
-- integer, with halfway cases being rounded away from zero. The rounded
-- value of X is checked against I'Range.
-- The catch in the above paragraph is that there is no good way to know
-- whether the round-to-integer operation resulted in overflow. A remedy is
-- to perform a range check in the floating-point domain instead, however:
-- (1) The bounds may not be known at compile time
-- (2) The check must take into account rounding or truncation.
-- (3) The range of type I may not be exactly representable in F.
-- (4) For the rounding case, the end-points I'First - 0.5 and
-- I'Last + 0.5 may or may not be in range, depending on the
-- sign of I'First and I'Last.
-- (5) X may be a NaN, which will fail any comparison
-- The following steps correctly convert X with rounding:
-- (1) If either I'First or I'Last is not known at compile time, use
-- I'Base instead of I in the next three steps and perform a
-- regular range check against I'Range after conversion.
-- (2) If I'First - 0.5 is representable in F then let Lo be that
-- value and define Lo_OK as (I'First > 0). Otherwise, let Lo be
-- F'Machine (I'First) and let Lo_OK be (Lo >= I'First).
-- In other words, take one of the closest floating-point numbers
-- (which is an integer value) to I'First, and see if it is in
-- range or not.
-- (3) If I'Last + 0.5 is representable in F then let Hi be that value
-- and define Hi_OK as (I'Last < 0). Otherwise, let Hi be
-- F'Machine (I'Last) and let Hi_OK be (Hi <= I'Last).
-- (4) Raise CE when (Lo_OK and X < Lo) or (not Lo_OK and X <= Lo)
-- or (Hi_OK and X > Hi) or (not Hi_OK and X >= Hi)
-- For the truncating case, replace steps (2) and (3) as follows:
-- (2) If I'First > 0, then let Lo be F'Pred (I'First) and let Lo_OK
-- be False. Otherwise, let Lo be F'Succ (I'First - 1) and let
-- Lo_OK be True.
-- (3) If I'Last < 0, then let Hi be F'Succ (I'Last) and let Hi_OK
-- be False. Otherwise let Hi be F'Pred (I'Last + 1) and let
-- Hi_OK be True.
procedure Apply_Float_Conversion_Check
(Expr : Node_Id;
Target_Typ : Entity_Id)
is
LB : constant Node_Id := Type_Low_Bound (Target_Typ);
HB : constant Node_Id := Type_High_Bound (Target_Typ);
Loc : constant Source_Ptr := Sloc (Expr);
Expr_Type : constant Entity_Id := Base_Type (Etype (Expr));
Target_Base : constant Entity_Id :=
Implementation_Base_Type (Target_Typ);
Par : constant Node_Id := Parent (Expr);
pragma Assert (Nkind (Par) = N_Type_Conversion);
-- Parent of check node, must be a type conversion
Truncate : constant Boolean := Float_Truncate (Par);
Max_Bound : constant Uint :=
UI_Expon
(Machine_Radix_Value (Expr_Type),
Machine_Mantissa_Value (Expr_Type) - 1) - 1;
-- Largest bound, so bound plus or minus half is a machine number of F
Ifirst, Ilast : Uint;
-- Bounds of integer type
Lo, Hi : Ureal;
-- Bounds to check in floating-point domain
Lo_OK, Hi_OK : Boolean;
-- True iff Lo resp. Hi belongs to I'Range
Lo_Chk, Hi_Chk : Node_Id;
-- Expressions that are False iff check fails
Reason : RT_Exception_Code;
begin
-- We do not need checks if we are not generating code (i.e. the full
-- expander is not active). In SPARK mode, we specifically don't want
-- the frontend to expand these checks, which are dealt with directly
-- in the formal verification backend.
if not Expander_Active then
return;
end if;
-- Here we will generate an explicit range check, so we don't want to
-- set the Do_Range check flag, since the range check is taken care of
-- by the code we will generate.
Set_Do_Range_Check (Expr, False);
if not Compile_Time_Known_Value (LB)
or not Compile_Time_Known_Value (HB)
then
declare
-- First check that the value falls in the range of the base type,
-- to prevent overflow during conversion and then perform a
-- regular range check against the (dynamic) bounds.
pragma Assert (Target_Base /= Target_Typ);
Temp : constant Entity_Id := Make_Temporary (Loc, 'T', Par);
begin
Apply_Float_Conversion_Check (Expr, Target_Base);
Set_Etype (Temp, Target_Base);
-- Note: Previously the declaration was inserted above the parent
-- of the conversion, apparently as a small optimization for the
-- subequent traversal in Insert_Actions. Unfortunately a similar
-- optimization takes place in Insert_Actions, assuming that the
-- insertion point must be above the expression that creates
-- actions. This is not correct in the presence of conditional
-- expressions, where the insertion must be in the list of actions
-- attached to the current alternative.
Insert_Action (Par,
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition => New_Occurrence_Of (Target_Typ, Loc),
Expression => New_Copy_Tree (Par)),
Suppress => All_Checks);
Insert_Action (Par,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Not_In (Loc,
Left_Opnd => New_Occurrence_Of (Temp, Loc),
Right_Opnd => New_Occurrence_Of (Target_Typ, Loc)),
Reason => CE_Range_Check_Failed));
Rewrite (Par, New_Occurrence_Of (Temp, Loc));
return;
end;
end if;
-- Get the (static) bounds of the target type
Ifirst := Expr_Value (LB);
Ilast := Expr_Value (HB);
-- A simple optimization: if the expression is a universal literal,
-- we can do the comparison with the bounds and the conversion to
-- an integer type statically. The range checks are unchanged.
if Nkind (Expr) = N_Real_Literal
and then Etype (Expr) = Universal_Real
and then Is_Integer_Type (Target_Typ)
then
declare
Int_Val : constant Uint := UR_To_Uint (Realval (Expr));
begin
if Int_Val <= Ilast and then Int_Val >= Ifirst then
-- Conversion is safe
Rewrite (Parent (Expr),
Make_Integer_Literal (Loc, UI_To_Int (Int_Val)));
Analyze_And_Resolve (Parent (Expr), Target_Typ);
return;
end if;
end;
end if;
-- Check against lower bound
if Truncate and then Ifirst > 0 then
Lo := Pred (Expr_Type, UR_From_Uint (Ifirst));
Lo_OK := False;
elsif Truncate then
Lo := Succ (Expr_Type, UR_From_Uint (Ifirst - 1));
Lo_OK := True;
elsif abs (Ifirst) < Max_Bound then
Lo := UR_From_Uint (Ifirst) - Ureal_Half;
Lo_OK := (Ifirst > 0);
else
Lo := Machine (Expr_Type, UR_From_Uint (Ifirst), Round_Even, Expr);
Lo_OK := (Lo >= UR_From_Uint (Ifirst));
end if;
if Lo_OK then
-- Lo_Chk := (X >= Lo)
Lo_Chk := Make_Op_Ge (Loc,
Left_Opnd => Duplicate_Subexpr_No_Checks (Expr),
Right_Opnd => Make_Real_Literal (Loc, Lo));
else
-- Lo_Chk := (X > Lo)
Lo_Chk := Make_Op_Gt (Loc,
Left_Opnd => Duplicate_Subexpr_No_Checks (Expr),
Right_Opnd => Make_Real_Literal (Loc, Lo));
end if;
-- Check against higher bound
if Truncate and then Ilast < 0 then
Hi := Succ (Expr_Type, UR_From_Uint (Ilast));
Hi_OK := False;
elsif Truncate then
Hi := Pred (Expr_Type, UR_From_Uint (Ilast + 1));
Hi_OK := True;
elsif abs (Ilast) < Max_Bound then
Hi := UR_From_Uint (Ilast) + Ureal_Half;
Hi_OK := (Ilast < 0);
else
Hi := Machine (Expr_Type, UR_From_Uint (Ilast), Round_Even, Expr);
Hi_OK := (Hi <= UR_From_Uint (Ilast));
end if;
if Hi_OK then
-- Hi_Chk := (X <= Hi)
Hi_Chk := Make_Op_Le (Loc,
Left_Opnd => Duplicate_Subexpr_No_Checks (Expr),
Right_Opnd => Make_Real_Literal (Loc, Hi));
else
-- Hi_Chk := (X < Hi)
Hi_Chk := Make_Op_Lt (Loc,
Left_Opnd => Duplicate_Subexpr_No_Checks (Expr),
Right_Opnd => Make_Real_Literal (Loc, Hi));
end if;
-- If the bounds of the target type are the same as those of the base
-- type, the check is an overflow check as a range check is not
-- performed in these cases.
if Expr_Value (Type_Low_Bound (Target_Base)) = Ifirst
and then Expr_Value (Type_High_Bound (Target_Base)) = Ilast
then
Reason := CE_Overflow_Check_Failed;
else
Reason := CE_Range_Check_Failed;
end if;
-- Raise CE if either conditions does not hold
Insert_Action (Expr,
Make_Raise_Constraint_Error (Loc,
Condition => Make_Op_Not (Loc, Make_And_Then (Loc, Lo_Chk, Hi_Chk)),
Reason => Reason));
end Apply_Float_Conversion_Check;
------------------------
-- Apply_Length_Check --
------------------------
procedure Apply_Length_Check
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id := Empty)
is
begin
Apply_Selected_Length_Checks
(Expr, Target_Typ, Source_Typ, Do_Static => False);
end Apply_Length_Check;
--------------------------------------
-- Apply_Length_Check_On_Assignment --
--------------------------------------
procedure Apply_Length_Check_On_Assignment
(Expr : Node_Id;
Target_Typ : Entity_Id;
Target : Node_Id;
Source_Typ : Entity_Id := Empty)
is
Assign : constant Node_Id := Parent (Target);
begin
-- No check is needed for the initialization of an object whose
-- nominal subtype is unconstrained.
if Is_Constr_Subt_For_U_Nominal (Target_Typ)
and then Nkind (Parent (Assign)) = N_Freeze_Entity
and then Is_Entity_Name (Target)
and then Entity (Target) = Entity (Parent (Assign))
then
return;
end if;
Apply_Selected_Length_Checks
(Expr, Target_Typ, Source_Typ, Do_Static => False);
end Apply_Length_Check_On_Assignment;
-------------------------------------
-- Apply_Parameter_Aliasing_Checks --
-------------------------------------
procedure Apply_Parameter_Aliasing_Checks
(Call : Node_Id;
Subp : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (Call);
function May_Cause_Aliasing
(Formal_1 : Entity_Id;
Formal_2 : Entity_Id) return Boolean;
-- Determine whether two formal parameters can alias each other
-- depending on their modes.
function Original_Actual (N : Node_Id) return Node_Id;
-- The expander may replace an actual with a temporary for the sake of
-- side effect removal. The temporary may hide a potential aliasing as
-- it does not share the address of the actual. This routine attempts
-- to retrieve the original actual.
procedure Overlap_Check
(Actual_1 : Node_Id;
Actual_2 : Node_Id;
Formal_1 : Entity_Id;
Formal_2 : Entity_Id;
Check : in out Node_Id);
-- Create a check to determine whether Actual_1 overlaps with Actual_2.
-- If detailed exception messages are enabled, the check is augmented to
-- provide information about the names of the corresponding formals. See
-- the body for details. Actual_1 and Actual_2 denote the two actuals to
-- be tested. Formal_1 and Formal_2 denote the corresponding formals.
-- Check contains all and-ed simple tests generated so far or remains
-- unchanged in the case of detailed exception messaged.
------------------------
-- May_Cause_Aliasing --
------------------------
function May_Cause_Aliasing
(Formal_1 : Entity_Id;
Formal_2 : Entity_Id) return Boolean
is
begin
-- The following combination cannot lead to aliasing
-- Formal 1 Formal 2
-- IN IN
if Ekind (Formal_1) = E_In_Parameter
and then
Ekind (Formal_2) = E_In_Parameter
then
return False;
-- The following combinations may lead to aliasing
-- Formal 1 Formal 2
-- IN OUT
-- IN IN OUT
-- OUT IN
-- OUT IN OUT
-- OUT OUT
else
return True;
end if;
end May_Cause_Aliasing;
---------------------
-- Original_Actual --
---------------------
function Original_Actual (N : Node_Id) return Node_Id is
begin
if Nkind (N) = N_Type_Conversion then
return Expression (N);
-- The expander created a temporary to capture the result of a type
-- conversion where the expression is the real actual.
elsif Nkind (N) = N_Identifier
and then Present (Original_Node (N))
and then Nkind (Original_Node (N)) = N_Type_Conversion
then
return Expression (Original_Node (N));
end if;
return N;
end Original_Actual;
-------------------
-- Overlap_Check --
-------------------
procedure Overlap_Check
(Actual_1 : Node_Id;
Actual_2 : Node_Id;
Formal_1 : Entity_Id;
Formal_2 : Entity_Id;
Check : in out Node_Id)
is
Cond : Node_Id;
ID_Casing : constant Casing_Type :=
Identifier_Casing (Source_Index (Current_Sem_Unit));
begin
-- Generate:
-- Actual_1'Overlaps_Storage (Actual_2)
Cond :=
Make_Attribute_Reference (Loc,
Prefix => New_Copy_Tree (Original_Actual (Actual_1)),
Attribute_Name => Name_Overlaps_Storage,
Expressions =>
New_List (New_Copy_Tree (Original_Actual (Actual_2))));
-- Generate the following check when detailed exception messages are
-- enabled:
-- if Actual_1'Overlaps_Storage (Actual_2) then
-- raise Program_Error with <detailed message>;
-- end if;
if Exception_Extra_Info then
Start_String;
-- Do not generate location information for internal calls
if Comes_From_Source (Call) then
Store_String_Chars (Build_Location_String (Loc));
Store_String_Char (' ');
end if;
Store_String_Chars ("aliased parameters, actuals for """);
Get_Name_String (Chars (Formal_1));
Set_Casing (ID_Casing);
Store_String_Chars (Name_Buffer (1 .. Name_Len));
Store_String_Chars (""" and """);
Get_Name_String (Chars (Formal_2));
Set_Casing (ID_Casing);
Store_String_Chars (Name_Buffer (1 .. Name_Len));
Store_String_Chars (""" overlap");
Insert_Action (Call,
Make_If_Statement (Loc,
Condition => Cond,
Then_Statements => New_List (
Make_Raise_Statement (Loc,
Name =>
New_Occurrence_Of (Standard_Program_Error, Loc),
Expression => Make_String_Literal (Loc, End_String)))));
-- Create a sequence of overlapping checks by and-ing them all
-- together.
else
if No (Check) then
Check := Cond;
else
Check :=
Make_And_Then (Loc,
Left_Opnd => Check,
Right_Opnd => Cond);
end if;
end if;
end Overlap_Check;
-- Local variables
Actual_1 : Node_Id;
Actual_2 : Node_Id;
Check : Node_Id;
Formal_1 : Entity_Id;
Formal_2 : Entity_Id;
Orig_Act_1 : Node_Id;
Orig_Act_2 : Node_Id;
-- Start of processing for Apply_Parameter_Aliasing_Checks
begin
Check := Empty;
Actual_1 := First_Actual (Call);
Formal_1 := First_Formal (Subp);
while Present (Actual_1) and then Present (Formal_1) loop
Orig_Act_1 := Original_Actual (Actual_1);
-- Ensure that the actual is an object that is not passed by value.
-- Elementary types are always passed by value, therefore actuals of
-- such types cannot lead to aliasing. An aggregate is an object in
-- Ada 2012, but an actual that is an aggregate cannot overlap with
-- another actual. A type that is By_Reference (such as an array of
-- controlled types) is not subject to the check because any update
-- will be done in place and a subsequent read will always see the
-- correct value, see RM 6.2 (12/3).
if Nkind (Orig_Act_1) = N_Aggregate
or else (Nkind (Orig_Act_1) = N_Qualified_Expression
and then Nkind (Expression (Orig_Act_1)) = N_Aggregate)
then
null;
elsif Is_Object_Reference (Orig_Act_1)
and then not Is_Elementary_Type (Etype (Orig_Act_1))
and then not Is_By_Reference_Type (Etype (Orig_Act_1))
then
Actual_2 := Next_Actual (Actual_1);
Formal_2 := Next_Formal (Formal_1);
while Present (Actual_2) and then Present (Formal_2) loop
Orig_Act_2 := Original_Actual (Actual_2);
-- The other actual we are testing against must also denote
-- a non pass-by-value object. Generate the check only when
-- the mode of the two formals may lead to aliasing.
if Is_Object_Reference (Orig_Act_2)
and then not Is_Elementary_Type (Etype (Orig_Act_2))
and then May_Cause_Aliasing (Formal_1, Formal_2)
then
Remove_Side_Effects (Actual_1);
Remove_Side_Effects (Actual_2);
Overlap_Check
(Actual_1 => Actual_1,
Actual_2 => Actual_2,
Formal_1 => Formal_1,
Formal_2 => Formal_2,
Check => Check);
end if;
Next_Actual (Actual_2);
Next_Formal (Formal_2);
end loop;
end if;
Next_Actual (Actual_1);
Next_Formal (Formal_1);
end loop;
-- Place a simple check right before the call
if Present (Check) and then not Exception_Extra_Info then
Insert_Action (Call,
Make_Raise_Program_Error (Loc,
Condition => Check,
Reason => PE_Aliased_Parameters));
end if;
end Apply_Parameter_Aliasing_Checks;
-------------------------------------
-- Apply_Parameter_Validity_Checks --
-------------------------------------
procedure Apply_Parameter_Validity_Checks (Subp : Entity_Id) is
Subp_Decl : Node_Id;
procedure Add_Validity_Check
(Formal : Entity_Id;
Prag_Nam : Name_Id;
For_Result : Boolean := False);
-- Add a single 'Valid[_Scalars] check which verifies the initialization
-- of Formal. Prag_Nam denotes the pre or post condition pragma name.
-- Set flag For_Result when to verify the result of a function.
------------------------
-- Add_Validity_Check --
------------------------
procedure Add_Validity_Check
(Formal : Entity_Id;
Prag_Nam : Name_Id;
For_Result : Boolean := False)
is
procedure Build_Pre_Post_Condition (Expr : Node_Id);
-- Create a pre/postcondition pragma that tests expression Expr
------------------------------
-- Build_Pre_Post_Condition --
------------------------------
procedure Build_Pre_Post_Condition (Expr : Node_Id) is
Loc : constant Source_Ptr := Sloc (Subp);
Decls : List_Id;
Prag : Node_Id;
begin
Prag :=
Make_Pragma (Loc,
Chars => Prag_Nam,
Pragma_Argument_Associations => New_List (
Make_Pragma_Argument_Association (Loc,
Chars => Name_Check,
Expression => Expr)));
-- Add a message unless exception messages are suppressed
if not Exception_Locations_Suppressed then
Append_To (Pragma_Argument_Associations (Prag),
Make_Pragma_Argument_Association (Loc,
Chars => Name_Message,
Expression =>
Make_String_Literal (Loc,
Strval => "failed "
& Get_Name_String (Prag_Nam)
& " from "
& Build_Location_String (Loc))));
end if;
-- Insert the pragma in the tree
if Nkind (Parent (Subp_Decl)) = N_Compilation_Unit then
Add_Global_Declaration (Prag);
Analyze (Prag);
-- PPC pragmas associated with subprogram bodies must be inserted
-- in the declarative part of the body.
elsif Nkind (Subp_Decl) = N_Subprogram_Body then
Decls := Declarations (Subp_Decl);
if No (Decls) then
Decls := New_List;
Set_Declarations (Subp_Decl, Decls);
end if;
Prepend_To (Decls, Prag);
Analyze (Prag);
-- For subprogram declarations insert the PPC pragma right after
-- the declarative node.
else
Insert_After_And_Analyze (Subp_Decl, Prag);
end if;
end Build_Pre_Post_Condition;
-- Local variables
Loc : constant Source_Ptr := Sloc (Subp);
Typ : constant Entity_Id := Etype (Formal);
Check : Node_Id;
Nam : Name_Id;
-- Start of processing for Add_Validity_Check
begin
-- For scalars, generate 'Valid test
if Is_Scalar_Type (Typ) then
Nam := Name_Valid;
-- For any non-scalar with scalar parts, generate 'Valid_Scalars test
elsif Scalar_Part_Present (Typ) then
Nam := Name_Valid_Scalars;
-- No test needed for other cases (no scalars to test)
else
return;
end if;
-- Step 1: Create the expression to verify the validity of the
-- context.
Check := New_Occurrence_Of (Formal, Loc);
-- When processing a function result, use 'Result. Generate
-- Context'Result
if For_Result then
Check :=
Make_Attribute_Reference (Loc,
Prefix => Check,
Attribute_Name => Name_Result);
end if;
-- Generate:
-- Context['Result]'Valid[_Scalars]
Check :=
Make_Attribute_Reference (Loc,
Prefix => Check,
Attribute_Name => Nam);
-- Step 2: Create a pre or post condition pragma
Build_Pre_Post_Condition (Check);
end Add_Validity_Check;
-- Local variables
Formal : Entity_Id;
Subp_Spec : Node_Id;
-- Start of processing for Apply_Parameter_Validity_Checks
begin
-- Extract the subprogram specification and declaration nodes
Subp_Spec := Parent (Subp);
if Nkind (Subp_Spec) = N_Defining_Program_Unit_Name then
Subp_Spec := Parent (Subp_Spec);
end if;
Subp_Decl := Parent (Subp_Spec);
if not Comes_From_Source (Subp)
-- Do not process formal subprograms because the corresponding actual
-- will receive the proper checks when the instance is analyzed.
or else Is_Formal_Subprogram (Subp)
-- Do not process imported subprograms since pre and postconditions
-- are never verified on routines coming from a different language.
or else Is_Imported (Subp)
or else Is_Intrinsic_Subprogram (Subp)
-- The PPC pragmas generated by this routine do not correspond to
-- source aspects, therefore they cannot be applied to abstract
-- subprograms.
or else Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration
-- Do not consider subprogram renaminds because the renamed entity
-- already has the proper PPC pragmas.
or else Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
-- Do not process null procedures because there is no benefit of
-- adding the checks to a no action routine.
or else (Nkind (Subp_Spec) = N_Procedure_Specification
and then Null_Present (Subp_Spec))
then
return;
end if;
-- Inspect all the formals applying aliasing and scalar initialization
-- checks where applicable.
Formal := First_Formal (Subp);
while Present (Formal) loop
-- Generate the following scalar initialization checks for each
-- formal parameter:
-- mode IN - Pre => Formal'Valid[_Scalars]
-- mode IN OUT - Pre, Post => Formal'Valid[_Scalars]
-- mode OUT - Post => Formal'Valid[_Scalars]
if Ekind (Formal) in E_In_Parameter | E_In_Out_Parameter then
Add_Validity_Check (Formal, Name_Precondition, False);
end if;
if Ekind (Formal) in E_In_Out_Parameter | E_Out_Parameter then
Add_Validity_Check (Formal, Name_Postcondition, False);
end if;
Next_Formal (Formal);
end loop;
-- Generate following scalar initialization check for function result:
-- Post => Subp'Result'Valid[_Scalars]
if Ekind (Subp) = E_Function then
Add_Validity_Check (Subp, Name_Postcondition, True);
end if;
end Apply_Parameter_Validity_Checks;
---------------------------
-- Apply_Predicate_Check --
---------------------------
procedure Apply_Predicate_Check
(N : Node_Id;
Typ : Entity_Id;
Fun : Entity_Id := Empty)
is
Par : Node_Id;
S : Entity_Id;
Check_Disabled : constant Boolean := (not Predicate_Enabled (Typ))
or else not Predicate_Check_In_Scope (N);
begin
S := Current_Scope;
while Present (S) and then not Is_Subprogram (S) loop
S := Scope (S);
end loop;
-- If the check appears within the predicate function itself, it means
-- that the user specified a check whose formal is the predicated
-- subtype itself, rather than some covering type. This is likely to be
-- a common error, and thus deserves a warning. We want to emit this
-- warning even if predicate checking is disabled (in which case the
-- warning is still useful even if it is not strictly accurate).
if Present (S) and then S = Predicate_Function (Typ) then
Error_Msg_NE
("predicate check includes a call to& that requires a "
& "predicate check??", Parent (N), Fun);
Error_Msg_N
("\this will result in infinite recursion??", Parent (N));
if Is_First_Subtype (Typ) then
Error_Msg_NE
("\use an explicit subtype of& to carry the predicate",
Parent (N), Typ);
end if;
if not Check_Disabled then
Insert_Action (N,
Make_Raise_Storage_Error (Sloc (N),
Reason => SE_Infinite_Recursion));
return;
end if;
end if;
if Check_Disabled then
return;
end if;
-- Normal case of predicate active
-- If the expression is an IN parameter, the predicate will have
-- been applied at the point of call. An additional check would
-- be redundant, or will lead to out-of-scope references if the
-- call appears within an aspect specification for a precondition.
-- However, if the reference is within the body of the subprogram
-- that declares the formal, the predicate can safely be applied,
-- which may be necessary for a nested call whose formal has a
-- different predicate.
if Is_Entity_Name (N)
and then Ekind (Entity (N)) = E_In_Parameter
then
declare
In_Body : Boolean := False;
P : Node_Id := Parent (N);
begin
while Present (P) loop
if Nkind (P) = N_Subprogram_Body
and then
((Present (Corresponding_Spec (P))
and then
Corresponding_Spec (P) = Scope (Entity (N)))
or else
Defining_Unit_Name (Specification (P)) =
Scope (Entity (N)))
then
In_Body := True;
exit;
end if;
P := Parent (P);
end loop;
if not In_Body then
return;
end if;
end;
end if;
-- If the type has a static predicate and the expression is known
-- at compile time, see if the expression satisfies the predicate.
Check_Expression_Against_Static_Predicate (N, Typ);
if not Expander_Active then
return;
end if;
Par := Parent (N);
if Nkind (Par) = N_Qualified_Expression then
Par := Parent (Par);
end if;
-- For an entity of the type, generate a call to the predicate
-- function, unless its type is an actual subtype, which is not
-- visible outside of the enclosing subprogram.
if Is_Entity_Name (N)
and then not Is_Actual_Subtype (Typ)
then
Insert_Action (N,
Make_Predicate_Check
(Typ, New_Occurrence_Of (Entity (N), Sloc (N))));
return;
elsif Nkind (N) in N_Aggregate | N_Extension_Aggregate then
-- If the expression is an aggregate in an assignment, apply the
-- check to the LHS after the assignment, rather than create a
-- redundant temporary. This is only necessary in rare cases
-- of array types (including strings) initialized with an
-- aggregate with an "others" clause, either coming from source
-- or generated by an Initialize_Scalars pragma.
if Nkind (Par) = N_Assignment_Statement then
Insert_Action_After (Par,
Make_Predicate_Check
(Typ, Duplicate_Subexpr (Name (Par))));
return;
-- Similarly, if the expression is an aggregate in an object
-- declaration, apply it to the object after the declaration.
-- This is only necessary in rare cases of tagged extensions
-- initialized with an aggregate with an "others => <>" clause.
elsif Nkind (Par) = N_Object_Declaration then
Insert_Action_After (Par,
Make_Predicate_Check (Typ,
New_Occurrence_Of (Defining_Identifier (Par), Sloc (N))));
return;
end if;
end if;
-- If the expression is not an entity it may have side effects,
-- and the following call will create an object declaration for
-- it. We disable checks during its analysis, to prevent an
-- infinite recursion.
Insert_Action (N,
Make_Predicate_Check
(Typ, Duplicate_Subexpr (N)), Suppress => All_Checks);
end Apply_Predicate_Check;
-----------------------
-- Apply_Range_Check --
-----------------------
procedure Apply_Range_Check
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id := Empty;
Insert_Node : Node_Id := Empty)
is
Checks_On : constant Boolean :=
not Index_Checks_Suppressed (Target_Typ)
or else
not Range_Checks_Suppressed (Target_Typ);
Loc : constant Source_Ptr := Sloc (Expr);
Cond : Node_Id;
R_Cno : Node_Id;
R_Result : Check_Result;
begin
-- Only apply checks when generating code. In GNATprove mode, we do not
-- apply the checks, but we still call Selected_Range_Checks to possibly
-- issue errors on SPARK code when a run-time error can be detected at
-- compile time.
if not GNATprove_Mode then
if not Expander_Active or not Checks_On then
return;
end if;
end if;
R_Result :=
Selected_Range_Checks (Expr, Target_Typ, Source_Typ, Insert_Node);
if GNATprove_Mode then
return;
end if;
for J in 1 .. 2 loop
R_Cno := R_Result (J);
exit when No (R_Cno);
-- The range check requires runtime evaluation. Depending on what its
-- triggering condition is, the check may be converted into a compile
-- time constraint check.
if Nkind (R_Cno) = N_Raise_Constraint_Error
and then Present (Condition (R_Cno))
then
Cond := Condition (R_Cno);
-- Insert the range check before the related context. Note that
-- this action analyses the triggering condition.
if Present (Insert_Node) then
Insert_Action (Insert_Node, R_Cno);
else
Insert_Action (Expr, R_Cno);
end if;
-- The triggering condition evaluates to True, the range check
-- can be converted into a compile time constraint check.
if Is_Entity_Name (Cond)
and then Entity (Cond) = Standard_True
then
-- Since an N_Range is technically not an expression, we have
-- to set one of the bounds to C_E and then just flag the
-- N_Range. The warning message will point to the lower bound
-- and complain about a range, which seems OK.
if Nkind (Expr) = N_Range then
Apply_Compile_Time_Constraint_Error
(Low_Bound (Expr),
"static range out of bounds of}??",
CE_Range_Check_Failed,
Ent => Target_Typ,
Typ => Target_Typ);
Set_Raises_Constraint_Error (Expr);
else
Apply_Compile_Time_Constraint_Error
(Expr,
"static value out of range of}??",
CE_Range_Check_Failed,
Ent => Target_Typ,
Typ => Target_Typ);
end if;
end if;
-- The range check raises Constraint_Error explicitly
elsif Present (Insert_Node) then
R_Cno :=
Make_Raise_Constraint_Error (Sloc (Insert_Node),
Reason => CE_Range_Check_Failed);
Insert_Action (Insert_Node, R_Cno);
else
Install_Static_Check (R_Cno, Loc);
end if;
end loop;
end Apply_Range_Check;
------------------------------
-- Apply_Scalar_Range_Check --
------------------------------
-- Note that Apply_Scalar_Range_Check never turns the Do_Range_Check flag
-- off if it is already set on.
procedure Apply_Scalar_Range_Check
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id := Empty;
Fixed_Int : Boolean := False)
is
Parnt : constant Node_Id := Parent (Expr);
S_Typ : Entity_Id;
Arr : Node_Id := Empty; -- initialize to prevent warning
Arr_Typ : Entity_Id := Empty; -- initialize to prevent warning
Is_Subscr_Ref : Boolean;
-- Set true if Expr is a subscript
Is_Unconstrained_Subscr_Ref : Boolean;
-- Set true if Expr is a subscript of an unconstrained array. In this
-- case we do not attempt to do an analysis of the value against the
-- range of the subscript, since we don't know the actual subtype.
Int_Real : Boolean;
-- Set to True if Expr should be regarded as a real value even though
-- the type of Expr might be discrete.
procedure Bad_Value (Warn : Boolean := False);
-- Procedure called if value is determined to be out of range. Warn is
-- True to force a warning instead of an error, even when SPARK_Mode is
-- On.
---------------
-- Bad_Value --
---------------
procedure Bad_Value (Warn : Boolean := False) is
begin
Apply_Compile_Time_Constraint_Error
(Expr, "value not in range of}??", CE_Range_Check_Failed,
Ent => Target_Typ,
Typ => Target_Typ,
Warn => Warn);
end Bad_Value;
-- Start of processing for Apply_Scalar_Range_Check
begin
-- Return if check obviously not needed
if
-- Not needed inside generic
Inside_A_Generic
-- Not needed if previous error
or else Target_Typ = Any_Type
or else Nkind (Expr) = N_Error
-- Not needed for non-scalar type
or else not Is_Scalar_Type (Target_Typ)
-- Not needed if we know node raises CE already
or else Raises_Constraint_Error (Expr)
then
return;
end if;
-- Now, see if checks are suppressed
Is_Subscr_Ref :=
Is_List_Member (Expr) and then Nkind (Parnt) = N_Indexed_Component;
if Is_Subscr_Ref then
Arr := Prefix (Parnt);
Arr_Typ := Get_Actual_Subtype_If_Available (Arr);
if Is_Access_Type (Arr_Typ) then
Arr_Typ := Designated_Type (Arr_Typ);
end if;
end if;
if not Do_Range_Check (Expr) then
-- Subscript reference. Check for Index_Checks suppressed
if Is_Subscr_Ref then
-- Check array type and its base type
if Index_Checks_Suppressed (Arr_Typ)
or else Index_Checks_Suppressed (Base_Type (Arr_Typ))
then
return;
-- Check array itself if it is an entity name
elsif Is_Entity_Name (Arr)
and then Index_Checks_Suppressed (Entity (Arr))
then
return;
-- Check expression itself if it is an entity name
elsif Is_Entity_Name (Expr)
and then Index_Checks_Suppressed (Entity (Expr))
then
return;
end if;
-- All other cases, check for Range_Checks suppressed
else
-- Check target type and its base type
if Range_Checks_Suppressed (Target_Typ)
or else Range_Checks_Suppressed (Base_Type (Target_Typ))
then
return;
-- Check expression itself if it is an entity name
elsif Is_Entity_Name (Expr)
and then Range_Checks_Suppressed (Entity (Expr))
then
return;
-- If Expr is part of an assignment statement, then check left
-- side of assignment if it is an entity name.
elsif Nkind (Parnt) = N_Assignment_Statement
and then Is_Entity_Name (Name (Parnt))
and then Range_Checks_Suppressed (Entity (Name (Parnt)))
then
return;
end if;
end if;
end if;
-- Do not set range checks if they are killed
if Nkind (Expr) = N_Unchecked_Type_Conversion
and then Kill_Range_Check (Expr)
then
return;
end if;
-- Do not set range checks for any values from System.Scalar_Values
-- since the whole idea of such values is to avoid checking them.
if Is_Entity_Name (Expr)
and then Is_RTU (Scope (Entity (Expr)), System_Scalar_Values)
then
return;
end if;
-- Now see if we need a check
if No (Source_Typ) then
S_Typ := Etype (Expr);
else
S_Typ := Source_Typ;
end if;
if not Is_Scalar_Type (S_Typ) or else S_Typ = Any_Type then
return;
end if;
Is_Unconstrained_Subscr_Ref :=
Is_Subscr_Ref and then not Is_Constrained (Arr_Typ);
-- Special checks for floating-point type
if Is_Floating_Point_Type (S_Typ) then
-- Always do a range check if the source type includes infinities and
-- the target type does not include infinities. We do not do this if
-- range checks are killed.
-- If the expression is a literal and the bounds of the type are
-- static constants it may be possible to optimize the check.
if Has_Infinities (S_Typ)
and then not Has_Infinities (Target_Typ)
then
-- If the expression is a literal and the bounds of the type are
-- static constants it may be possible to optimize the check.
if Nkind (Expr) = N_Real_Literal then
declare
Tlo : constant Node_Id := Type_Low_Bound (Target_Typ);
Thi : constant Node_Id := Type_High_Bound (Target_Typ);
begin
if Compile_Time_Known_Value (Tlo)
and then Compile_Time_Known_Value (Thi)
and then Expr_Value_R (Expr) >= Expr_Value_R (Tlo)
and then Expr_Value_R (Expr) <= Expr_Value_R (Thi)
then
return;
else
Enable_Range_Check (Expr);
end if;
end;
else
Enable_Range_Check (Expr);
end if;
end if;
end if;
-- Return if we know expression is definitely in the range of the target
-- type as determined by Determine_Range. Right now we only do this for
-- discrete types, and not fixed-point or floating-point types.
-- The additional less-precise tests below catch these cases
-- In GNATprove_Mode, also deal with the case of a conversion from
-- floating-point to integer. It is only possible because analysis
-- in GNATprove rules out the possibility of a NaN or infinite value.
-- Note: skip this if we are given a source_typ, since the point of
-- supplying a Source_Typ is to stop us looking at the expression.
-- We could sharpen this test to be out parameters only ???
if Is_Discrete_Type (Target_Typ)
and then (Is_Discrete_Type (Etype (Expr))
or else (GNATprove_Mode
and then Is_Floating_Point_Type (Etype (Expr))))
and then not Is_Unconstrained_Subscr_Ref
and then No (Source_Typ)
then
declare
Thi : constant Node_Id := Type_High_Bound (Target_Typ);
Tlo : constant Node_Id := Type_Low_Bound (Target_Typ);
begin
if Compile_Time_Known_Value (Tlo)
and then Compile_Time_Known_Value (Thi)
then
declare
OK : Boolean := False; -- initialize to prevent warning
Hiv : constant Uint := Expr_Value (Thi);
Lov : constant Uint := Expr_Value (Tlo);
Hi : Uint := No_Uint;
Lo : Uint := No_Uint;
begin
-- If range is null, we for sure have a constraint error (we
-- don't even need to look at the value involved, since all
-- possible values will raise CE).
if Lov > Hiv then
-- When SPARK_Mode is On, force a warning instead of
-- an error in that case, as this likely corresponds
-- to deactivated code.
Bad_Value (Warn => SPARK_Mode = On);
-- In GNATprove mode, we enable the range check so that
-- GNATprove will issue a message if it cannot be proved.
if GNATprove_Mode then
Enable_Range_Check (Expr);
end if;
return;
end if;
-- Otherwise determine range of value
if Is_Discrete_Type (Etype (Expr)) then
Determine_Range
(Expr, OK, Lo, Hi, Assume_Valid => True);
-- When converting a float to an integer type, determine the
-- range in real first, and then convert the bounds using
-- UR_To_Uint which correctly rounds away from zero when
-- half way between two integers, as required by normal
-- Ada 95 rounding semantics. It is only possible because
-- analysis in GNATprove rules out the possibility of a NaN
-- or infinite value.
elsif GNATprove_Mode
and then Is_Floating_Point_Type (Etype (Expr))
then
declare
Hir : Ureal;
Lor : Ureal;
begin
Determine_Range_R
(Expr, OK, Lor, Hir, Assume_Valid => True);
if OK then
Lo := UR_To_Uint (Lor);
Hi := UR_To_Uint (Hir);
end if;
end;
end if;
if OK then
-- If definitely in range, all OK
if Lo >= Lov and then Hi <= Hiv then
return;
-- If definitely not in range, warn
elsif Lov > Hi or else Hiv < Lo then
-- Ignore out of range values for System.Priority in
-- CodePeer mode since the actual target compiler may
-- provide a wider range.
if not CodePeer_Mode
or else not Is_RTE (Target_Typ, RE_Priority)
then
Bad_Value;
end if;
return;
-- Otherwise we don't know
else
null;
end if;
end if;
end;
end if;
end;
end if;
Int_Real :=
Is_Floating_Point_Type (S_Typ)
or else (Is_Fixed_Point_Type (S_Typ) and then not Fixed_Int);
-- Check if we can determine at compile time whether Expr is in the
-- range of the target type. Note that if S_Typ is within the bounds
-- of Target_Typ then this must be the case. This check is meaningful
-- only if this is not a conversion between integer and real types.
if not Is_Unconstrained_Subscr_Ref
and then Is_Discrete_Type (S_Typ) = Is_Discrete_Type (Target_Typ)
and then
(In_Subrange_Of (S_Typ, Target_Typ, Fixed_Int)
-- Also check if the expression itself is in the range of the
-- target type if it is a known at compile time value. We skip
-- this test if S_Typ is set since for OUT and IN OUT parameters
-- the Expr itself is not relevant to the checking.
or else
(No (Source_Typ)
and then Is_In_Range (Expr, Target_Typ,
Assume_Valid => True,
Fixed_Int => Fixed_Int,
Int_Real => Int_Real)))
then
return;
elsif Is_Out_Of_Range (Expr, Target_Typ,
Assume_Valid => True,
Fixed_Int => Fixed_Int,
Int_Real => Int_Real)
then
Bad_Value;
return;
-- Floating-point case
-- In the floating-point case, we only do range checks if the type is
-- constrained. We definitely do NOT want range checks for unconstrained
-- types, since we want to have infinities, except when
-- Check_Float_Overflow is set.
elsif Is_Floating_Point_Type (S_Typ) then
if Is_Constrained (S_Typ) or else Check_Float_Overflow then
Enable_Range_Check (Expr);
end if;
-- For all other cases we enable a range check unconditionally
else
Enable_Range_Check (Expr);
return;
end if;
end Apply_Scalar_Range_Check;
----------------------------------
-- Apply_Selected_Length_Checks --
----------------------------------
procedure Apply_Selected_Length_Checks
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id;
Do_Static : Boolean)
is
Checks_On : constant Boolean :=
not Index_Checks_Suppressed (Target_Typ)
or else
not Length_Checks_Suppressed (Target_Typ);
Loc : constant Source_Ptr := Sloc (Expr);
Cond : Node_Id;
R_Cno : Node_Id;
R_Result : Check_Result;
begin
-- Only apply checks when generating code
-- Note: this means that we lose some useful warnings if the expander
-- is not active.
if not Expander_Active then
return;
end if;
R_Result :=
Selected_Length_Checks (Expr, Target_Typ, Source_Typ, Empty);
for J in 1 .. 2 loop
R_Cno := R_Result (J);
exit when No (R_Cno);
-- A length check may mention an Itype which is attached to a
-- subsequent node. At the top level in a package this can cause
-- an order-of-elaboration problem, so we make sure that the itype
-- is referenced now.
if Ekind (Current_Scope) = E_Package
and then Is_Compilation_Unit (Current_Scope)
then
Ensure_Defined (Target_Typ, Expr);
if Present (Source_Typ) then
Ensure_Defined (Source_Typ, Expr);
elsif Is_Itype (Etype (Expr)) then
Ensure_Defined (Etype (Expr), Expr);
end if;
end if;
-- If the item is a conditional raise of constraint error, then have
-- a look at what check is being performed and ???
if Nkind (R_Cno) = N_Raise_Constraint_Error
and then Present (Condition (R_Cno))
then
Cond := Condition (R_Cno);
-- Case where node does not now have a dynamic check
if not Has_Dynamic_Length_Check (Expr) then
-- If checks are on, just insert the check
if Checks_On then
Insert_Action (Expr, R_Cno);
if not Do_Static then
Set_Has_Dynamic_Length_Check (Expr);
end if;
-- If checks are off, then analyze the length check after
-- temporarily attaching it to the tree in case the relevant
-- condition can be evaluated at compile time. We still want a
-- compile time warning in this case.
else
Set_Parent (R_Cno, Expr);
Analyze (R_Cno);
end if;
end if;
-- Output a warning if the condition is known to be True
if Is_Entity_Name (Cond)
and then Entity (Cond) = Standard_True
then
Apply_Compile_Time_Constraint_Error
(Expr, "wrong length for array of}??",
CE_Length_Check_Failed,
Ent => Target_Typ,
Typ => Target_Typ);
-- If we were only doing a static check, or if checks are not
-- on, then we want to delete the check, since it is not needed.
-- We do this by replacing the if statement by a null statement
elsif Do_Static or else not Checks_On then
Remove_Warning_Messages (R_Cno);
Rewrite (R_Cno, Make_Null_Statement (Loc));
end if;
else
Install_Static_Check (R_Cno, Loc);
end if;
end loop;
end Apply_Selected_Length_Checks;
-------------------------------
-- Apply_Static_Length_Check --
-------------------------------
procedure Apply_Static_Length_Check
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id := Empty)
is
begin
Apply_Selected_Length_Checks
(Expr, Target_Typ, Source_Typ, Do_Static => True);
end Apply_Static_Length_Check;
-------------------------------------
-- Apply_Subscript_Validity_Checks --
-------------------------------------
procedure Apply_Subscript_Validity_Checks (Expr : Node_Id) is
Sub : Node_Id;
begin
pragma Assert (Nkind (Expr) = N_Indexed_Component);
-- Loop through subscripts
Sub := First (Expressions (Expr));
while Present (Sub) loop
-- Check one subscript. Note that we do not worry about enumeration
-- type with holes, since we will convert the value to a Pos value
-- for the subscript, and that convert will do the necessary validity
-- check.
Ensure_Valid (Sub, Holes_OK => True);
-- Move to next subscript
Next (Sub);
end loop;
end Apply_Subscript_Validity_Checks;
----------------------------------
-- Apply_Type_Conversion_Checks --
----------------------------------
procedure Apply_Type_Conversion_Checks (N : Node_Id) is
Target_Type : constant Entity_Id := Etype (N);
Target_Base : constant Entity_Id := Base_Type (Target_Type);
Expr : constant Node_Id := Expression (N);
Expr_Type : constant Entity_Id := Underlying_Type (Etype (Expr));
-- Note: if Etype (Expr) is a private type without discriminants, its
-- full view might have discriminants with defaults, so we need the
-- full view here to retrieve the constraints.
begin
if Inside_A_Generic then
return;
-- Skip these checks if serious errors detected, there are some nasty
-- situations of incomplete trees that blow things up.
elsif Serious_Errors_Detected > 0 then
return;
-- Never generate discriminant checks for Unchecked_Union types
elsif Present (Expr_Type)
and then Is_Unchecked_Union (Expr_Type)
then
return;
-- Scalar type conversions of the form Target_Type (Expr) require a
-- range check if we cannot be sure that Expr is in the base type of
-- Target_Typ and also that Expr is in the range of Target_Typ. These
-- are not quite the same condition from an implementation point of
-- view, but clearly the second includes the first.
elsif Is_Scalar_Type (Target_Type) then
declare
Conv_OK : constant Boolean := Conversion_OK (N);
-- If the Conversion_OK flag on the type conversion is set and no
-- floating-point type is involved in the type conversion then
-- fixed-point values must be read as integral values.
Float_To_Int : constant Boolean :=
Is_Floating_Point_Type (Expr_Type)
and then Is_Integer_Type (Target_Type);
begin
if not Overflow_Checks_Suppressed (Target_Base)
and then not Overflow_Checks_Suppressed (Target_Type)
and then not
In_Subrange_Of (Expr_Type, Target_Base, Fixed_Int => Conv_OK)
and then not Float_To_Int
then
-- A small optimization: the attribute 'Pos applied to an
-- enumeration type has a known range, even though its type is
-- Universal_Integer. So in numeric conversions it is usually
-- within range of the target integer type. Use the static
-- bounds of the base types to check. Disable this optimization
-- in case of a generic formal discrete type, because we don't
-- necessarily know the upper bound yet.
if Nkind (Expr) = N_Attribute_Reference
and then Attribute_Name (Expr) = Name_Pos
and then Is_Enumeration_Type (Etype (Prefix (Expr)))
and then not Is_Generic_Type (Etype (Prefix (Expr)))
and then Is_Integer_Type (Target_Type)
then
declare
Enum_T : constant Entity_Id :=
Root_Type (Etype (Prefix (Expr)));
Int_T : constant Entity_Id := Base_Type (Target_Type);
Last_I : constant Uint :=
Intval (High_Bound (Scalar_Range (Int_T)));
Last_E : Uint;
begin
-- Character types have no explicit literals, so we use
-- the known number of characters in the type.
if Root_Type (Enum_T) = Standard_Character then
Last_E := UI_From_Int (255);
elsif Enum_T = Standard_Wide_Character
or else Enum_T = Standard_Wide_Wide_Character
then
Last_E := UI_From_Int (65535);
else
Last_E :=
Enumeration_Pos
(Entity (High_Bound (Scalar_Range (Enum_T))));
end if;
if Last_E > Last_I then
Activate_Overflow_Check (N);
end if;
end;
else
Activate_Overflow_Check (N);
end if;
end if;
if not Range_Checks_Suppressed (Target_Type)
and then not Range_Checks_Suppressed (Expr_Type)
then
if Float_To_Int
and then not GNATprove_Mode
then
Apply_Float_Conversion_Check (Expr, Target_Type);
else
-- Conversions involving fixed-point types are expanded
-- separately, and do not need a Range_Check flag, except
-- in GNATprove_Mode, where the explicit constraint check
-- will not be generated.
if GNATprove_Mode
or else (not Is_Fixed_Point_Type (Expr_Type)
and then not Is_Fixed_Point_Type (Target_Type))
then
Apply_Scalar_Range_Check
(Expr, Target_Type, Fixed_Int => Conv_OK);
else
Set_Do_Range_Check (Expr, False);
end if;
-- If the target type has predicates, we need to indicate
-- the need for a check, even if Determine_Range finds that
-- the value is within bounds. This may be the case e.g for
-- a division with a constant denominator.
if Has_Predicates (Target_Type) then
Enable_Range_Check (Expr);
end if;
end if;
end if;
end;
elsif Comes_From_Source (N)
and then not Discriminant_Checks_Suppressed (Target_Type)
and then Is_Record_Type (Target_Type)
and then Is_Derived_Type (Target_Type)
and then not Is_Tagged_Type (Target_Type)
and then not Is_Constrained (Target_Type)
and then Present (Stored_Constraint (Target_Type))
then
-- An unconstrained derived type may have inherited discriminant.
-- Build an actual discriminant constraint list using the stored
-- constraint, to verify that the expression of the parent type
-- satisfies the constraints imposed by the (unconstrained) derived
-- type. This applies to value conversions, not to view conversions
-- of tagged types.
declare
Loc : constant Source_Ptr := Sloc (N);
Cond : Node_Id;
Constraint : Elmt_Id;
Discr_Value : Node_Id;
Discr : Entity_Id;
New_Constraints : constant Elist_Id := New_Elmt_List;
Old_Constraints : constant Elist_Id :=
Discriminant_Constraint (Expr_Type);
begin
Constraint := First_Elmt (Stored_Constraint (Target_Type));
while Present (Constraint) loop
Discr_Value := Node (Constraint);
if Is_Entity_Name (Discr_Value)
and then Ekind (Entity (Discr_Value)) = E_Discriminant
then
Discr := Corresponding_Discriminant (Entity (Discr_Value));
if Present (Discr)
and then Scope (Discr) = Base_Type (Expr_Type)
then
-- Parent is constrained by new discriminant. Obtain
-- Value of original discriminant in expression. If the
-- new discriminant has been used to constrain more than
-- one of the stored discriminants, this will provide the
-- required consistency check.
Append_Elmt
(Make_Selected_Component (Loc,
Prefix =>
Duplicate_Subexpr_No_Checks
(Expr, Name_Req => True),
Selector_Name =>
Make_Identifier (Loc, Chars (Discr))),
New_Constraints);
else
-- Discriminant of more remote ancestor ???
return;
end if;
-- Derived type definition has an explicit value for this
-- stored discriminant.
else
Append_Elmt
(Duplicate_Subexpr_No_Checks (Discr_Value),
New_Constraints);
end if;
Next_Elmt (Constraint);
end loop;
-- Use the unconstrained expression type to retrieve the
-- discriminants of the parent, and apply momentarily the
-- discriminant constraint synthesized above.
Set_Discriminant_Constraint (Expr_Type, New_Constraints);
Cond := Build_Discriminant_Checks (Expr, Expr_Type);
Set_Discriminant_Constraint (Expr_Type, Old_Constraints);
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition => Cond,
Reason => CE_Discriminant_Check_Failed));
end;
-- For arrays, checks are set now, but conversions are applied during
-- expansion, to take into accounts changes of representation. The
-- checks become range checks on the base type or length checks on the
-- subtype, depending on whether the target type is unconstrained or
-- constrained. Note that the range check is put on the expression of a
-- type conversion, while the length check is put on the type conversion
-- itself.
elsif Is_Array_Type (Target_Type) then
if Is_Constrained (Target_Type) then
Set_Do_Length_Check (N);
else
Set_Do_Range_Check (Expr);
end if;
end if;
end Apply_Type_Conversion_Checks;
----------------------------------------------
-- Apply_Universal_Integer_Attribute_Checks --
----------------------------------------------
procedure Apply_Universal_Integer_Attribute_Checks (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
begin
if Inside_A_Generic then
return;
-- Nothing to do if the result type is universal integer
elsif Typ = Universal_Integer then
return;
-- Nothing to do if checks are suppressed
elsif Range_Checks_Suppressed (Typ)
and then Overflow_Checks_Suppressed (Typ)
then
return;
-- Nothing to do if the attribute does not come from source. The
-- internal attributes we generate of this type do not need checks,
-- and furthermore the attempt to check them causes some circular
-- elaboration orders when dealing with packed types.
elsif not Comes_From_Source (N) then
return;
-- If the prefix is a selected component that depends on a discriminant
-- the check may improperly expose a discriminant instead of using
-- the bounds of the object itself. Set the type of the attribute to
-- the base type of the context, so that a check will be imposed when
-- needed (e.g. if the node appears as an index).
elsif Nkind (Prefix (N)) = N_Selected_Component
and then Ekind (Typ) = E_Signed_Integer_Subtype
and then Depends_On_Discriminant (Scalar_Range (Typ))
then
Set_Etype (N, Base_Type (Typ));
-- Otherwise, replace the attribute node with a type conversion node
-- whose expression is the attribute, retyped to universal integer, and
-- whose subtype mark is the target type. The call to analyze this
-- conversion will set range and overflow checks as required for proper
-- detection of an out of range value.
else
Set_Etype (N, Universal_Integer);
Set_Analyzed (N, True);
Rewrite (N,
Make_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Typ, Loc),
Expression => Relocate_Node (N)));
Analyze_And_Resolve (N, Typ);
return;
end if;
end Apply_Universal_Integer_Attribute_Checks;
-------------------------------------
-- Atomic_Synchronization_Disabled --
-------------------------------------
-- Note: internally Disable/Enable_Atomic_Synchronization is implemented
-- using a bogus check called Atomic_Synchronization. This is to make it
-- more convenient to get exactly the same semantics as [Un]Suppress.
function Atomic_Synchronization_Disabled (E : Entity_Id) return Boolean is
begin
-- If debug flag d.e is set, always return False, i.e. all atomic sync
-- looks enabled, since it is never disabled.
if Debug_Flag_Dot_E then
return False;
-- If debug flag d.d is set then always return True, i.e. all atomic
-- sync looks disabled, since it always tests True.
elsif Debug_Flag_Dot_D then
return True;
-- If entity present, then check result for that entity
elsif Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Atomic_Synchronization);
-- Otherwise result depends on current scope setting
else
return Scope_Suppress.Suppress (Atomic_Synchronization);
end if;
end Atomic_Synchronization_Disabled;
-------------------------------
-- Build_Discriminant_Checks --
-------------------------------
function Build_Discriminant_Checks
(N : Node_Id;
T_Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (N);
Cond : Node_Id;
Disc : Elmt_Id;
Disc_Ent : Entity_Id;
Dref : Node_Id;
Dval : Node_Id;
function Aggregate_Discriminant_Val (Disc : Entity_Id) return Node_Id;
--------------------------------
-- Aggregate_Discriminant_Val --
--------------------------------
function Aggregate_Discriminant_Val (Disc : Entity_Id) return Node_Id is
Assoc : Node_Id;
begin
-- The aggregate has been normalized with named associations. We use
-- the Chars field to locate the discriminant to take into account
-- discriminants in derived types, which carry the same name as those
-- in the parent.
Assoc := First (Component_Associations (N));
while Present (Assoc) loop
if Chars (First (Choices (Assoc))) = Chars (Disc) then
return Expression (Assoc);
else
Next (Assoc);
end if;
end loop;
-- Discriminant must have been found in the loop above
raise Program_Error;
end Aggregate_Discriminant_Val;
-- Start of processing for Build_Discriminant_Checks
begin
-- Loop through discriminants evolving the condition
Cond := Empty;
Disc := First_Elmt (Discriminant_Constraint (T_Typ));
-- For a fully private type, use the discriminants of the parent type
if Is_Private_Type (T_Typ)
and then No (Full_View (T_Typ))
then
Disc_Ent := First_Discriminant (Etype (Base_Type (T_Typ)));
else
Disc_Ent := First_Discriminant (T_Typ);
end if;
while Present (Disc) loop
Dval := Node (Disc);
if Nkind (Dval) = N_Identifier
and then Ekind (Entity (Dval)) = E_Discriminant
then
Dval := New_Occurrence_Of (Discriminal (Entity (Dval)), Loc);
else
Dval := Duplicate_Subexpr_No_Checks (Dval);
end if;
-- If we have an Unchecked_Union node, we can infer the discriminants
-- of the node.
if Is_Unchecked_Union (Base_Type (T_Typ)) then
Dref := New_Copy (
Get_Discriminant_Value (
First_Discriminant (T_Typ),
T_Typ,
Stored_Constraint (T_Typ)));
elsif Nkind (N) = N_Aggregate then
Dref :=
Duplicate_Subexpr_No_Checks
(Aggregate_Discriminant_Val (Disc_Ent));
elsif Is_Access_Type (Etype (N)) then
Dref :=
Make_Selected_Component (Loc,
Prefix =>
Make_Explicit_Dereference (Loc,
Duplicate_Subexpr_No_Checks (N, Name_Req => True)),
Selector_Name => Make_Identifier (Loc, Chars (Disc_Ent)));
Set_Is_In_Discriminant_Check (Dref);
else
Dref :=
Make_Selected_Component (Loc,
Prefix =>
Duplicate_Subexpr_No_Checks (N, Name_Req => True),
Selector_Name => Make_Identifier (Loc, Chars (Disc_Ent)));
Set_Is_In_Discriminant_Check (Dref);
end if;
Evolve_Or_Else (Cond,
Make_Op_Ne (Loc,
Left_Opnd => Dref,
Right_Opnd => Dval));
Next_Elmt (Disc);
Next_Discriminant (Disc_Ent);
end loop;
return Cond;
end Build_Discriminant_Checks;
------------------
-- Check_Needed --
------------------
function Check_Needed (Nod : Node_Id; Check : Check_Type) return Boolean is
N : Node_Id;
P : Node_Id;
K : Node_Kind;
L : Node_Id;
R : Node_Id;
function Left_Expression (Op : Node_Id) return Node_Id;
-- Return the relevant expression from the left operand of the given
-- short circuit form: this is LO itself, except if LO is a qualified
-- expression, a type conversion, or an expression with actions, in
-- which case this is Left_Expression (Expression (LO)).
---------------------
-- Left_Expression --
---------------------
function Left_Expression (Op : Node_Id) return Node_Id is
LE : Node_Id := Left_Opnd (Op);
begin
while Nkind (LE) in N_Qualified_Expression
| N_Type_Conversion
| N_Expression_With_Actions
loop
LE := Expression (LE);
end loop;
return LE;
end Left_Expression;
-- Start of processing for Check_Needed
begin
-- Always check if not simple entity
if Nkind (Nod) not in N_Has_Entity
or else not Comes_From_Source (Nod)
then
return True;
end if;
-- Look up tree for short circuit
N := Nod;
loop
P := Parent (N);
K := Nkind (P);
-- Done if out of subexpression (note that we allow generated stuff
-- such as itype declarations in this context, to keep the loop going
-- since we may well have generated such stuff in complex situations.
-- Also done if no parent (probably an error condition, but no point
-- in behaving nasty if we find it).
if No (P)
or else (K not in N_Subexpr and then Comes_From_Source (P))
then
return True;
-- Or/Or Else case, where test is part of the right operand, or is
-- part of one of the actions associated with the right operand, and
-- the left operand is an equality test.
elsif K = N_Op_Or then
exit when N = Right_Opnd (P)
and then Nkind (Left_Expression (P)) = N_Op_Eq;
elsif K = N_Or_Else then
exit when (N = Right_Opnd (P)
or else
(Is_List_Member (N)
and then List_Containing (N) = Actions (P)))
and then Nkind (Left_Expression (P)) = N_Op_Eq;
-- Similar test for the And/And then case, where the left operand
-- is an inequality test.
elsif K = N_Op_And then
exit when N = Right_Opnd (P)
and then Nkind (Left_Expression (P)) = N_Op_Ne;
elsif K = N_And_Then then
exit when (N = Right_Opnd (P)
or else
(Is_List_Member (N)
and then List_Containing (N) = Actions (P)))
and then Nkind (Left_Expression (P)) = N_Op_Ne;
end if;
N := P;
end loop;
-- If we fall through the loop, then we have a conditional with an
-- appropriate test as its left operand, so look further.
L := Left_Expression (P);
-- L is an "=" or "/=" operator: extract its operands
R := Right_Opnd (L);
L := Left_Opnd (L);
-- Left operand of test must match original variable
if Nkind (L) not in N_Has_Entity or else Entity (L) /= Entity (Nod) then
return True;
end if;
-- Right operand of test must be key value (zero or null)
case Check is
when Access_Check =>
if not Known_Null (R) then
return True;
end if;
when Division_Check =>
if not Compile_Time_Known_Value (R)
or else Expr_Value (R) /= Uint_0
then
return True;
end if;
when others =>
raise Program_Error;
end case;
-- Here we have the optimizable case, warn if not short-circuited
if K = N_Op_And or else K = N_Op_Or then
Error_Msg_Warn := SPARK_Mode /= On;
case Check is
when Access_Check =>
if GNATprove_Mode then
Error_Msg_N
("Constraint_Error might have been raised (access check)",
Parent (Nod));
else
Error_Msg_N
("Constraint_Error may be raised (access check)??",
Parent (Nod));
end if;
when Division_Check =>
if GNATprove_Mode then
Error_Msg_N
("Constraint_Error might have been raised (zero divide)",
Parent (Nod));
else
Error_Msg_N
("Constraint_Error may be raised (zero divide)??",
Parent (Nod));
end if;
when others =>
raise Program_Error;
end case;
if K = N_Op_And then
Error_Msg_N -- CODEFIX
("use `AND THEN` instead of AND??", P);
else
Error_Msg_N -- CODEFIX
("use `OR ELSE` instead of OR??", P);
end if;
-- If not short-circuited, we need the check
return True;
-- If short-circuited, we can omit the check
else
return False;
end if;
end Check_Needed;
-----------------------------------
-- Check_Valid_Lvalue_Subscripts --
-----------------------------------
procedure Check_Valid_Lvalue_Subscripts (Expr : Node_Id) is
begin
-- Skip this if range checks are suppressed
if Range_Checks_Suppressed (Etype (Expr)) then
return;
-- Only do this check for expressions that come from source. We assume
-- that expander generated assignments explicitly include any necessary
-- checks. Note that this is not just an optimization, it avoids
-- infinite recursions.
elsif not Comes_From_Source (Expr) then
return;
-- For a selected component, check the prefix
elsif Nkind (Expr) = N_Selected_Component then
Check_Valid_Lvalue_Subscripts (Prefix (Expr));
return;
-- Case of indexed component
elsif Nkind (Expr) = N_Indexed_Component then
Apply_Subscript_Validity_Checks (Expr);
-- Prefix may itself be or contain an indexed component, and these
-- subscripts need checking as well.
Check_Valid_Lvalue_Subscripts (Prefix (Expr));
end if;
end Check_Valid_Lvalue_Subscripts;
----------------------------------
-- Null_Exclusion_Static_Checks --
----------------------------------
procedure Null_Exclusion_Static_Checks
(N : Node_Id;
Comp : Node_Id := Empty;
Array_Comp : Boolean := False)
is
Has_Null : constant Boolean := Has_Null_Exclusion (N);
Kind : constant Node_Kind := Nkind (N);
Error_Nod : Node_Id;
Expr : Node_Id;
Typ : Entity_Id;
begin
pragma Assert
(Kind in N_Component_Declaration
| N_Discriminant_Specification
| N_Function_Specification
| N_Object_Declaration
| N_Parameter_Specification);
if Kind = N_Function_Specification then
Typ := Etype (Defining_Entity (N));
else
Typ := Etype (Defining_Identifier (N));
end if;
case Kind is
when N_Component_Declaration =>
if Present (Access_Definition (Component_Definition (N))) then
Error_Nod := Component_Definition (N);
else
Error_Nod := Subtype_Indication (Component_Definition (N));
end if;
when N_Discriminant_Specification =>
Error_Nod := Discriminant_Type (N);
when N_Function_Specification =>
Error_Nod := Result_Definition (N);
when N_Object_Declaration =>
Error_Nod := Object_Definition (N);
when N_Parameter_Specification =>
Error_Nod := Parameter_Type (N);
when others =>
raise Program_Error;
end case;
if Has_Null then
-- Enforce legality rule 3.10 (13): A null exclusion can only be
-- applied to an access [sub]type.
if not Is_Access_Type (Typ) then
Error_Msg_N
("`NOT NULL` allowed only for an access type", Error_Nod);
-- Enforce legality rule RM 3.10(14/1): A null exclusion can only
-- be applied to a [sub]type that does not exclude null already.
elsif Can_Never_Be_Null (Typ) and then Comes_From_Source (Typ) then
Error_Msg_NE
("`NOT NULL` not allowed (& already excludes null)",
Error_Nod, Typ);
end if;
end if;
-- Check that null-excluding objects are always initialized, except for
-- deferred constants, for which the expression will appear in the full
-- declaration.
if Kind = N_Object_Declaration
and then No (Expression (N))
and then not Constant_Present (N)
and then not No_Initialization (N)
then
if Present (Comp) then
-- Specialize the warning message to indicate that we are dealing
-- with an uninitialized composite object that has a defaulted
-- null-excluding component.
Error_Msg_Name_1 := Chars (Defining_Identifier (Comp));
Error_Msg_Name_2 := Chars (Defining_Identifier (N));
Discard_Node
(Compile_Time_Constraint_Error
(N => N,
Msg =>
"(Ada 2005) null-excluding component % of object % must "
& "be initialized??",
Ent => Defining_Identifier (Comp)));
-- This is a case of an array with null-excluding components, so
-- indicate that in the warning.
elsif Array_Comp then
Discard_Node
(Compile_Time_Constraint_Error
(N => N,
Msg =>
"(Ada 2005) null-excluding array components must "
& "be initialized??",
Ent => Defining_Identifier (N)));
-- Normal case of object of a null-excluding access type
else
-- Add an expression that assigns null. This node is needed by
-- Apply_Compile_Time_Constraint_Error, which will replace this
-- with a Constraint_Error node.
Set_Expression (N, Make_Null (Sloc (N)));
Set_Etype (Expression (N), Etype (Defining_Identifier (N)));
Apply_Compile_Time_Constraint_Error
(N => Expression (N),
Msg =>
"(Ada 2005) null-excluding objects must be initialized??",
Reason => CE_Null_Not_Allowed);
end if;
end if;
-- Check that a null-excluding component, formal or object is not being
-- assigned a null value. Otherwise generate a warning message and
-- replace Expression (N) by an N_Constraint_Error node.
if Kind /= N_Function_Specification then
Expr := Expression (N);
if Present (Expr) and then Known_Null (Expr) then
case Kind is
when N_Component_Declaration
| N_Discriminant_Specification
=>
Apply_Compile_Time_Constraint_Error
(N => Expr,
Msg =>
"(Ada 2005) null not allowed in null-excluding "
& "components??",
Reason => CE_Null_Not_Allowed);
when N_Object_Declaration =>
Apply_Compile_Time_Constraint_Error
(N => Expr,
Msg =>
"(Ada 2005) null not allowed in null-excluding "
& "objects??",
Reason => CE_Null_Not_Allowed);
when N_Parameter_Specification =>
Apply_Compile_Time_Constraint_Error
(N => Expr,
Msg =>
"(Ada 2005) null not allowed in null-excluding "
& "formals??",
Reason => CE_Null_Not_Allowed);
when others =>
null;
end case;
end if;
end if;
end Null_Exclusion_Static_Checks;
-------------------------------------
-- Compute_Range_For_Arithmetic_Op --
-------------------------------------
procedure Compute_Range_For_Arithmetic_Op
(Op : Node_Kind;
Lo_Left : Uint;
Hi_Left : Uint;
Lo_Right : Uint;
Hi_Right : Uint;
OK : out Boolean;
Lo : out Uint;
Hi : out Uint)
is
-- Use local variables for possible adjustments
Llo : Uint renames Lo_Left;
Lhi : Uint renames Hi_Left;
Rlo : Uint := Lo_Right;
Rhi : Uint := Hi_Right;
begin
-- We will compute a range for the result in almost all cases
OK := True;
case Op is
-- Absolute value
when N_Op_Abs =>
Lo := Uint_0;
Hi := UI_Max (abs Rlo, abs Rhi);
-- Addition
when N_Op_Add =>
Lo := Llo + Rlo;
Hi := Lhi + Rhi;
-- Division
when N_Op_Divide =>
-- If the right operand can only be zero, set 0..0
if Rlo = 0 and then Rhi = 0 then
Lo := Uint_0;
Hi := Uint_0;
-- Possible bounds of division must come from dividing end
-- values of the input ranges (four possibilities), provided
-- zero is not included in the possible values of the right
-- operand.
-- Otherwise, we just consider two intervals of values for
-- the right operand: the interval of negative values (up to
-- -1) and the interval of positive values (starting at 1).
-- Since division by 1 is the identity, and division by -1
-- is negation, we get all possible bounds of division in that
-- case by considering:
-- - all values from the division of end values of input
-- ranges;
-- - the end values of the left operand;
-- - the negation of the end values of the left operand.
else
declare
Mrk : constant Uintp.Save_Mark := Mark;
-- Mark so we can release the RR and Ev values
Ev1 : Uint;
Ev2 : Uint;
Ev3 : Uint;
Ev4 : Uint;
begin
-- Discard extreme values of zero for the divisor, since
-- they will simply result in an exception in any case.
if Rlo = 0 then
Rlo := Uint_1;
elsif Rhi = 0 then
Rhi := -Uint_1;
end if;
-- Compute possible bounds coming from dividing end
-- values of the input ranges.
Ev1 := Llo / Rlo;
Ev2 := Llo / Rhi;
Ev3 := Lhi / Rlo;
Ev4 := Lhi / Rhi;
Lo := UI_Min (UI_Min (Ev1, Ev2), UI_Min (Ev3, Ev4));
Hi := UI_Max (UI_Max (Ev1, Ev2), UI_Max (Ev3, Ev4));
-- If the right operand can be both negative or positive,
-- include the end values of the left operand in the
-- extreme values, as well as their negation.
if Rlo < 0 and then Rhi > 0 then
Ev1 := Llo;
Ev2 := -Llo;
Ev3 := Lhi;
Ev4 := -Lhi;
Lo := UI_Min (Lo,
UI_Min (UI_Min (Ev1, Ev2), UI_Min (Ev3, Ev4)));
Hi := UI_Max (Hi,
UI_Max (UI_Max (Ev1, Ev2), UI_Max (Ev3, Ev4)));
end if;
-- Release the RR and Ev values
Release_And_Save (Mrk, Lo, Hi);
end;
end if;
-- Exponentiation
when N_Op_Expon =>
-- Discard negative values for the exponent, since they will
-- simply result in an exception in any case.
if Rhi < 0 then
Rhi := Uint_0;
elsif Rlo < 0 then
Rlo := Uint_0;
end if;
-- Estimate number of bits in result before we go computing
-- giant useless bounds. Basically the number of bits in the
-- result is the number of bits in the base multiplied by the
-- value of the exponent. If this is big enough that the result
-- definitely won't fit in Long_Long_Integer, return immediately
-- and avoid computing giant bounds.
-- The comparison here is approximate, but conservative, it
-- only clicks on cases that are sure to exceed the bounds.
if Num_Bits (UI_Max (abs Llo, abs Lhi)) * Rhi + 1 > 100 then
Lo := No_Uint;
Hi := No_Uint;
OK := False;
return;
-- If right operand is zero then result is 1
elsif Rhi = 0 then
Lo := Uint_1;
Hi := Uint_1;
else
-- High bound comes either from exponentiation of largest
-- positive value to largest exponent value, or from
-- the exponentiation of most negative value to an
-- even exponent.
declare
Hi1, Hi2 : Uint;
begin
if Lhi > 0 then
Hi1 := Lhi ** Rhi;
else
Hi1 := Uint_0;
end if;
if Llo < 0 then
if Rhi mod 2 = 0 then
Hi2 := Llo ** Rhi;
else
Hi2 := Llo ** (Rhi - 1);
end if;
else
Hi2 := Uint_0;
end if;
Hi := UI_Max (Hi1, Hi2);
end;
-- Result can only be negative if base can be negative
if Llo < 0 then
if Rhi mod 2 = 0 then
Lo := Llo ** (Rhi - 1);
else
Lo := Llo ** Rhi;
end if;
-- Otherwise low bound is minimum ** minimum
else
Lo := Llo ** Rlo;
end if;
end if;
-- Negation
when N_Op_Minus =>
Lo := -Rhi;
Hi := -Rlo;
-- Mod
when N_Op_Mod =>
declare
Maxabs : constant Uint := UI_Max (abs Rlo, abs Rhi) - 1;
-- This is the maximum absolute value of the result
begin
Lo := Uint_0;
Hi := Uint_0;
-- The result depends only on the sign and magnitude of
-- the right operand, it does not depend on the sign or
-- magnitude of the left operand.
if Rlo < 0 then
Lo := -Maxabs;
end if;
if Rhi > 0 then
Hi := Maxabs;
end if;
end;
-- Multiplication
when N_Op_Multiply =>
-- Possible bounds of multiplication must come from multiplying
-- end values of the input ranges (four possibilities).
declare
Mrk : constant Uintp.Save_Mark := Mark;
-- Mark so we can release the Ev values
Ev1 : constant Uint := Llo * Rlo;
Ev2 : constant Uint := Llo * Rhi;
Ev3 : constant Uint := Lhi * Rlo;
Ev4 : constant Uint := Lhi * Rhi;
begin
Lo := UI_Min (UI_Min (Ev1, Ev2), UI_Min (Ev3, Ev4));
Hi := UI_Max (UI_Max (Ev1, Ev2), UI_Max (Ev3, Ev4));
-- Release the Ev values
Release_And_Save (Mrk, Lo, Hi);
end;
-- Plus operator (affirmation)
when N_Op_Plus =>
Lo := Rlo;
Hi := Rhi;
-- Remainder
when N_Op_Rem =>
declare
Maxabs : constant Uint := UI_Max (abs Rlo, abs Rhi) - 1;
-- This is the maximum absolute value of the result. Note
-- that the result range does not depend on the sign of the
-- right operand.
begin
Lo := Uint_0;
Hi := Uint_0;
-- Case of left operand negative, which results in a range
-- of -Maxabs .. 0 for those negative values. If there are
-- no negative values then Lo value of result is always 0.
if Llo < 0 then
Lo := -Maxabs;
end if;
-- Case of left operand positive
if Lhi > 0 then
Hi := Maxabs;
end if;
end;
-- Subtract
when N_Op_Subtract =>
Lo := Llo - Rhi;
Hi := Lhi - Rlo;
-- Nothing else should be possible
when others =>
raise Program_Error;
end case;
end Compute_Range_For_Arithmetic_Op;
----------------------------------
-- Conditional_Statements_Begin --
----------------------------------
procedure Conditional_Statements_Begin is
begin
Saved_Checks_TOS := Saved_Checks_TOS + 1;
-- If stack overflows, kill all checks, that way we know to simply reset
-- the number of saved checks to zero on return. This should never occur
-- in practice.
if Saved_Checks_TOS > Saved_Checks_Stack'Last then
Kill_All_Checks;
-- In the normal case, we just make a new stack entry saving the current
-- number of saved checks for a later restore.
else
Saved_Checks_Stack (Saved_Checks_TOS) := Num_Saved_Checks;
if Debug_Flag_CC then
w ("Conditional_Statements_Begin: Num_Saved_Checks = ",
Num_Saved_Checks);
end if;
end if;
end Conditional_Statements_Begin;
--------------------------------
-- Conditional_Statements_End --
--------------------------------
procedure Conditional_Statements_End is
begin
pragma Assert (Saved_Checks_TOS > 0);
-- If the saved checks stack overflowed, then we killed all checks, so
-- setting the number of saved checks back to zero is correct. This
-- should never occur in practice.
if Saved_Checks_TOS > Saved_Checks_Stack'Last then
Num_Saved_Checks := 0;
-- In the normal case, restore the number of saved checks from the top
-- stack entry.
else
Num_Saved_Checks := Saved_Checks_Stack (Saved_Checks_TOS);
if Debug_Flag_CC then
w ("Conditional_Statements_End: Num_Saved_Checks = ",
Num_Saved_Checks);
end if;
end if;
Saved_Checks_TOS := Saved_Checks_TOS - 1;
end Conditional_Statements_End;
-------------------------
-- Convert_From_Bignum --
-------------------------
function Convert_From_Bignum (N : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (N);
begin
pragma Assert (Is_RTE (Etype (N), RE_Bignum));
-- Construct call From Bignum
return
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_From_Bignum), Loc),
Parameter_Associations => New_List (Relocate_Node (N)));
end Convert_From_Bignum;
-----------------------
-- Convert_To_Bignum --
-----------------------
function Convert_To_Bignum (N : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (N);
begin
-- Nothing to do if Bignum already except call Relocate_Node
if Is_RTE (Etype (N), RE_Bignum) then
return Relocate_Node (N);
-- Otherwise construct call to To_Bignum, converting the operand to the
-- required Long_Long_Integer form.
else
pragma Assert (Is_Signed_Integer_Type (Etype (N)));
return
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_To_Bignum), Loc),
Parameter_Associations => New_List (
Convert_To (Standard_Long_Long_Integer, Relocate_Node (N))));
end if;
end Convert_To_Bignum;
---------------------
-- Determine_Range --
---------------------
Cache_Size : constant := 2 ** 10;
type Cache_Index is range 0 .. Cache_Size - 1;
-- Determine size of below cache (power of 2 is more efficient)
Determine_Range_Cache_N : array (Cache_Index) of Node_Id;
Determine_Range_Cache_O : array (Cache_Index) of Node_Id;
Determine_Range_Cache_V : array (Cache_Index) of Boolean;
Determine_Range_Cache_Lo : array (Cache_Index) of Uint;
Determine_Range_Cache_Hi : array (Cache_Index) of Uint;
Determine_Range_Cache_Lo_R : array (Cache_Index) of Ureal;
Determine_Range_Cache_Hi_R : array (Cache_Index) of Ureal;
-- The above arrays are used to implement a small direct cache for
-- Determine_Range and Determine_Range_R calls. Because of the way these
-- subprograms recursively traces subexpressions, and because overflow
-- checking calls the routine on the way up the tree, a quadratic behavior
-- can otherwise be encountered in large expressions. The cache entry for
-- node N is stored in the (N mod Cache_Size) entry, and can be validated
-- by checking the actual node value stored there. The Range_Cache_O array
-- records the setting of Original_Node (N) so that the cache entry does
-- not become stale when the node N is rewritten. The Range_Cache_V array
-- records the setting of Assume_Valid for the cache entry.
procedure Determine_Range
(N : Node_Id;
OK : out Boolean;
Lo : out Uint;
Hi : out Uint;
Assume_Valid : Boolean := False)
is
Kind : constant Node_Kind := Nkind (N);
-- Kind of node
function Half_Address_Space return Uint;
-- The size of half the total addressable memory space in storage units
-- (minus one, so that the size fits in a signed integer whose size is
-- System_Address_Size, which helps in various cases).
------------------------
-- Half_Address_Space --
------------------------
function Half_Address_Space return Uint is
begin
return Uint_2 ** (System_Address_Size - 1) - 1;
end Half_Address_Space;
-- Local variables
Typ : Entity_Id := Etype (N);
-- Type to use, may get reset to base type for possibly invalid entity
Lo_Left : Uint := No_Uint;
Hi_Left : Uint := No_Uint;
-- Lo and Hi bounds of left operand
Lo_Right : Uint := No_Uint;
Hi_Right : Uint := No_Uint;
-- Lo and Hi bounds of right (or only) operand
Bound : Node_Id;
-- Temp variable used to hold a bound node
Hbound : Uint;
-- High bound of base type of expression
Lor : Uint;
Hir : Uint;
-- Refined values for low and high bounds, after tightening
OK1 : Boolean;
-- Used in lower level calls to indicate if call succeeded
Cindex : Cache_Index;
-- Used to search cache
Btyp : Entity_Id;
-- Base type
-- Start of processing for Determine_Range
begin
-- Prevent junk warnings by initializing range variables
Lo := No_Uint;
Hi := No_Uint;
Lor := No_Uint;
Hir := No_Uint;
-- For temporary constants internally generated to remove side effects
-- we must use the corresponding expression to determine the range of
-- the expression. But note that the expander can also generate
-- constants in other cases, including deferred constants.
if Is_Entity_Name (N)
and then Nkind (Parent (Entity (N))) = N_Object_Declaration
and then Ekind (Entity (N)) = E_Constant
and then Is_Internal_Name (Chars (Entity (N)))
then
if Present (Expression (Parent (Entity (N)))) then
Determine_Range
(Expression (Parent (Entity (N))), OK, Lo, Hi, Assume_Valid);
elsif Present (Full_View (Entity (N))) then
Determine_Range
(Expression (Parent (Full_View (Entity (N)))),
OK, Lo, Hi, Assume_Valid);
else
OK := False;
end if;
return;
end if;
-- If type is not defined, we can't determine its range
if No (Typ)
-- We don't deal with anything except discrete types
or else not Is_Discrete_Type (Typ)
-- Don't deal with enumerated types with non-standard representation
or else (Is_Enumeration_Type (Typ)
and then Present (Enum_Pos_To_Rep (Base_Type (Typ))))
-- Ignore type for which an error has been posted, since range in
-- this case may well be a bogosity deriving from the error. Also
-- ignore if error posted on the reference node.
or else Error_Posted (N) or else Error_Posted (Typ)
then
OK := False;
return;
end if;
-- For all other cases, we can determine the range
OK := True;
-- If value is compile time known, then the possible range is the one
-- value that we know this expression definitely has.
if Compile_Time_Known_Value (N) then
Lo := Expr_Value (N);
Hi := Lo;
return;
end if;
-- Return if already in the cache
Cindex := Cache_Index (N mod Cache_Size);
if Determine_Range_Cache_N (Cindex) = N
and then
Determine_Range_Cache_O (Cindex) = Original_Node (N)
and then
Determine_Range_Cache_V (Cindex) = Assume_Valid
then
Lo := Determine_Range_Cache_Lo (Cindex);
Hi := Determine_Range_Cache_Hi (Cindex);
return;
end if;
-- Otherwise, start by finding the bounds of the type of the expression,
-- the value cannot be outside this range (if it is, then we have an
-- overflow situation, which is a separate check, we are talking here
-- only about the expression value).
-- First a check, never try to find the bounds of a generic type, since
-- these bounds are always junk values, and it is only valid to look at
-- the bounds in an instance.
if Is_Generic_Type (Typ) then
OK := False;
return;
end if;
-- First step, change to use base type unless we know the value is valid
if (Is_Entity_Name (N) and then Is_Known_Valid (Entity (N)))
or else Assume_No_Invalid_Values
or else Assume_Valid
then
-- If this is a known valid constant with a nonstatic value, it may
-- have inherited a narrower subtype from its initial value; use this
-- saved subtype (see sem_ch3.adb).
if Is_Entity_Name (N)
and then Ekind (Entity (N)) = E_Constant
and then Present (Actual_Subtype (Entity (N)))
then
Typ := Actual_Subtype (Entity (N));
end if;
else
Typ := Underlying_Type (Base_Type (Typ));
end if;
-- Retrieve the base type. Handle the case where the base type is a
-- private enumeration type.
Btyp := Base_Type (Typ);
if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
Btyp := Full_View (Btyp);
end if;
-- We use the actual bound unless it is dynamic, in which case use the
-- corresponding base type bound if possible. If we can't get a bound
-- then we figure we can't determine the range (a peculiar case, that
-- perhaps cannot happen, but there is no point in bombing in this
-- optimization circuit).
-- First the low bound
Bound := Type_Low_Bound (Typ);
if Compile_Time_Known_Value (Bound) then
Lo := Expr_Value (Bound);
elsif Compile_Time_Known_Value (Type_Low_Bound (Btyp)) then
Lo := Expr_Value (Type_Low_Bound (Btyp));
else
OK := False;
return;
end if;
-- Now the high bound
Bound := Type_High_Bound (Typ);
-- We need the high bound of the base type later on, and this should
-- always be compile time known. Again, it is not clear that this
-- can ever be false, but no point in bombing.
if Compile_Time_Known_Value (Type_High_Bound (Btyp)) then
Hbound := Expr_Value (Type_High_Bound (Btyp));
Hi := Hbound;
else
OK := False;
return;
end if;
-- If we have a static subtype, then that may have a tighter bound so
-- use the upper bound of the subtype instead in this case.
if Compile_Time_Known_Value (Bound) then
Hi := Expr_Value (Bound);
end if;
-- We may be able to refine this value in certain situations. If any
-- refinement is possible, then Lor and Hir are set to possibly tighter
-- bounds, and OK1 is set to True.
case Kind is
-- Unary operation case
when N_Op_Abs
| N_Op_Minus
| N_Op_Plus
=>
Determine_Range
(Right_Opnd (N), OK1, Lo_Right, Hi_Right, Assume_Valid);
if OK1 then
Compute_Range_For_Arithmetic_Op
(Kind, Lo_Left, Hi_Left, Lo_Right, Hi_Right, OK1, Lor, Hir);
end if;
-- Binary operation case
when N_Op_Add
| N_Op_Divide
| N_Op_Expon
| N_Op_Mod
| N_Op_Multiply
| N_Op_Rem
| N_Op_Subtract
=>
Determine_Range
(Left_Opnd (N), OK1, Lo_Left, Hi_Left, Assume_Valid);
if OK1 then
Determine_Range
(Right_Opnd (N), OK1, Lo_Right, Hi_Right, Assume_Valid);
end if;
if OK1 then
Compute_Range_For_Arithmetic_Op
(Kind, Lo_Left, Hi_Left, Lo_Right, Hi_Right, OK1, Lor, Hir);
end if;
-- Attribute reference cases
when N_Attribute_Reference =>
case Get_Attribute_Id (Attribute_Name (N)) is
-- For Min/Max attributes, we can refine the range using the
-- possible range of values of the attribute expressions.
when Attribute_Min
| Attribute_Max
=>
Determine_Range
(First (Expressions (N)),
OK1, Lo_Left, Hi_Left, Assume_Valid);
if OK1 then
Determine_Range
(Next (First (Expressions (N))),
OK1, Lo_Right, Hi_Right, Assume_Valid);
end if;
if OK1 then
Lor := UI_Min (Lo_Left, Lo_Right);
Hir := UI_Max (Hi_Left, Hi_Right);
end if;
-- For Pos/Val attributes, we can refine the range using the
-- possible range of values of the attribute expression.
when Attribute_Pos
| Attribute_Val
=>
Determine_Range
(First (Expressions (N)), OK1, Lor, Hir, Assume_Valid);
-- For Length and Range_Length attributes, use the bounds of
-- the (corresponding index) type to refine the range.
when Attribute_Length
| Attribute_Range_Length
=>
declare
Ptyp : Entity_Id;
Ityp : Entity_Id;
LL, LU : Uint;
UL, UU : Uint;
begin
Ptyp := Etype (Prefix (N));
if Is_Access_Type (Ptyp) then
Ptyp := Designated_Type (Ptyp);
end if;
-- For string literal, we know exact value
if Ekind (Ptyp) = E_String_Literal_Subtype then
OK := True;
Lo := String_Literal_Length (Ptyp);
Hi := String_Literal_Length (Ptyp);
return;
end if;
if Is_Array_Type (Ptyp) then
Ityp := Get_Index_Subtype (N);
else
Ityp := Ptyp;
end if;
-- If the (index) type is a formal type or derived from
-- one, the bounds are not static.
if Is_Generic_Type (Root_Type (Ityp)) then
OK := False;
return;
end if;
Determine_Range
(Type_Low_Bound (Ityp), OK1, LL, LU, Assume_Valid);
if OK1 then
Determine_Range
(Type_High_Bound (Ityp), OK1, UL, UU, Assume_Valid);
if OK1 then
-- The maximum value for Length is the biggest
-- possible gap between the values of the bounds.
-- But of course, this value cannot be negative.
Hir := UI_Max (Uint_0, UU - LL + 1);
-- For a constrained array, the minimum value for
-- Length is taken from the actual value of the
-- bounds, since the index will be exactly of this
-- subtype.
if Is_Constrained (Ptyp) then
Lor := UI_Max (Uint_0, UL - LU + 1);
-- For an unconstrained array, the minimum value
-- for length is always zero.
else
Lor := Uint_0;
end if;
end if;
end if;
-- Small optimization: the maximum size in storage units
-- an object can have with GNAT is half of the address
-- space, so we can bound the length of an array declared
-- in Interfaces (or its children) because its component
-- size is at least the storage unit and it is meant to
-- be used to interface actual array objects.
if Is_Array_Type (Ptyp) then
declare
S : constant Entity_Id := Scope (Base_Type (Ptyp));
begin
if Is_RTU (S, Interfaces)
or else (S /= Standard_Standard
and then Is_RTU (Scope (S), Interfaces))
then
Hir := UI_Min (Hir, Half_Address_Space);
end if;
end;
end if;
end;
-- The maximum default alignment is quite low, but GNAT accepts
-- alignment clauses that are fairly large, but not as large as
-- the maximum size of objects, see below.
when Attribute_Alignment =>
Lor := Uint_0;
Hir := Half_Address_Space;
OK1 := True;
-- The attribute should have been folded if a component clause
-- was specified, so we assume there is none.
when Attribute_Bit
| Attribute_First_Bit
=>
Lor := Uint_0;
Hir := UI_From_Int (System_Storage_Unit - 1);
OK1 := True;
-- Likewise about the component clause. Note that Last_Bit
-- yields -1 for a field of size 0 if First_Bit is 0.
when Attribute_Last_Bit =>
Lor := Uint_Minus_1;
Hir := Hi;
OK1 := True;
-- Likewise about the component clause for Position. The
-- maximum size in storage units that an object can have
-- with GNAT is half of the address space.
when Attribute_Max_Size_In_Storage_Elements
| Attribute_Position
=>
Lor := Uint_0;
Hir := Half_Address_Space;
OK1 := True;
-- These attributes yield a nonnegative value (we do not set
-- the maximum value because it is too large to be useful).
when Attribute_Bit_Position
| Attribute_Component_Size
| Attribute_Object_Size
| Attribute_Size
| Attribute_Value_Size
=>
Lor := Uint_0;
Hir := Hi;
OK1 := True;
-- The maximum size is the sum of twice the size of the largest
-- integer for every dimension, rounded up to the next multiple
-- of the maximum alignment, but we add instead of rounding.
when Attribute_Descriptor_Size =>
declare
Max_Align : constant Pos :=
Maximum_Alignment * System_Storage_Unit;
Max_Size : constant Uint :=
2 * Esize (Universal_Integer);
Ndims : constant Pos :=
Number_Dimensions (Etype (Prefix (N)));
begin
Lor := Uint_0;
Hir := Max_Size * Ndims + Max_Align;
OK1 := True;
end;
-- No special handling for other attributes
-- Probably more opportunities exist here???
when others =>
OK1 := False;
end case;
when N_Type_Conversion =>
-- For type conversion from one discrete type to another, we can
-- refine the range using the converted value.
if Is_Discrete_Type (Etype (Expression (N))) then
Determine_Range (Expression (N), OK1, Lor, Hir, Assume_Valid);
-- When converting a float to an integer type, determine the range
-- in real first, and then convert the bounds using UR_To_Uint
-- which correctly rounds away from zero when half way between two
-- integers, as required by normal Ada 95 rounding semantics. It
-- is only possible because analysis in GNATprove rules out the
-- possibility of a NaN or infinite value.
elsif GNATprove_Mode
and then Is_Floating_Point_Type (Etype (Expression (N)))
then
declare
Lor_Real, Hir_Real : Ureal;
begin
Determine_Range_R (Expression (N), OK1, Lor_Real, Hir_Real,
Assume_Valid);
if OK1 then
Lor := UR_To_Uint (Lor_Real);
Hir := UR_To_Uint (Hir_Real);
end if;
end;
else
OK1 := False;
end if;
-- Nothing special to do for all other expression kinds
when others =>
OK1 := False;
Lor := No_Uint;
Hir := No_Uint;
end case;
-- At this stage, if OK1 is true, then we know that the actual result of
-- the computed expression is in the range Lor .. Hir. We can use this
-- to restrict the possible range of results.
if OK1 then
-- If the refined value of the low bound is greater than the type
-- low bound, then reset it to the more restrictive value. However,
-- we do NOT do this for the case of a modular type where the
-- possible upper bound on the value is above the base type high
-- bound, because that means the result could wrap.
if Lor > Lo
and then not (Is_Modular_Integer_Type (Typ) and then Hir > Hbound)
then
Lo := Lor;
end if;
-- Similarly, if the refined value of the high bound is less than the
-- value so far, then reset it to the more restrictive value. Again,
-- we do not do this if the refined low bound is negative for a
-- modular type, since this would wrap.
if Hir < Hi
and then not (Is_Modular_Integer_Type (Typ) and then Lor < Uint_0)
then
Hi := Hir;
end if;
end if;
-- Set cache entry for future call and we are all done
Determine_Range_Cache_N (Cindex) := N;
Determine_Range_Cache_O (Cindex) := Original_Node (N);
Determine_Range_Cache_V (Cindex) := Assume_Valid;
Determine_Range_Cache_Lo (Cindex) := Lo;
Determine_Range_Cache_Hi (Cindex) := Hi;
return;
-- If any exception occurs, it means that we have some bug in the compiler,
-- possibly triggered by a previous error, or by some unforeseen peculiar
-- occurrence. However, this is only an optimization attempt, so there is
-- really no point in crashing the compiler. Instead we just decide, too
-- bad, we can't figure out a range in this case after all.
exception
when others =>
-- Debug flag K disables this behavior (useful for debugging)
if Debug_Flag_K then
raise;
else
OK := False;
Lo := No_Uint;
Hi := No_Uint;
return;
end if;
end Determine_Range;
-----------------------
-- Determine_Range_R --
-----------------------
procedure Determine_Range_R
(N : Node_Id;
OK : out Boolean;
Lo : out Ureal;
Hi : out Ureal;
Assume_Valid : Boolean := False)
is
Typ : Entity_Id := Etype (N);
-- Type to use, may get reset to base type for possibly invalid entity
Lo_Left : Ureal;
Hi_Left : Ureal;
-- Lo and Hi bounds of left operand
Lo_Right : Ureal := No_Ureal;
Hi_Right : Ureal := No_Ureal;
-- Lo and Hi bounds of right (or only) operand
Bound : Node_Id;
-- Temp variable used to hold a bound node
Hbound : Ureal;
-- High bound of base type of expression
Lor : Ureal;
Hir : Ureal;
-- Refined values for low and high bounds, after tightening
OK1 : Boolean;
-- Used in lower level calls to indicate if call succeeded
Cindex : Cache_Index;
-- Used to search cache
Btyp : Entity_Id;
-- Base type
function OK_Operands return Boolean;
-- Used for binary operators. Determines the ranges of the left and
-- right operands, and if they are both OK, returns True, and puts
-- the results in Lo_Right, Hi_Right, Lo_Left, Hi_Left.
function Round_Machine (B : Ureal) return Ureal;
-- B is a real bound. Round it using mode Round_Even.
-----------------
-- OK_Operands --
-----------------
function OK_Operands return Boolean is
begin
Determine_Range_R
(Left_Opnd (N), OK1, Lo_Left, Hi_Left, Assume_Valid);
if not OK1 then
return False;
end if;
Determine_Range_R
(Right_Opnd (N), OK1, Lo_Right, Hi_Right, Assume_Valid);
return OK1;
end OK_Operands;
-------------------
-- Round_Machine --
-------------------
function Round_Machine (B : Ureal) return Ureal is
begin
return Machine (Typ, B, Round_Even, N);
end Round_Machine;
-- Start of processing for Determine_Range_R
begin
-- Prevent junk warnings by initializing range variables
Lo := No_Ureal;
Hi := No_Ureal;
Lor := No_Ureal;
Hir := No_Ureal;
-- For temporary constants internally generated to remove side effects
-- we must use the corresponding expression to determine the range of
-- the expression. But note that the expander can also generate
-- constants in other cases, including deferred constants.
if Is_Entity_Name (N)
and then Nkind (Parent (Entity (N))) = N_Object_Declaration
and then Ekind (Entity (N)) = E_Constant
and then Is_Internal_Name (Chars (Entity (N)))
then
if Present (Expression (Parent (Entity (N)))) then
Determine_Range_R
(Expression (Parent (Entity (N))), OK, Lo, Hi, Assume_Valid);
elsif Present (Full_View (Entity (N))) then
Determine_Range_R
(Expression (Parent (Full_View (Entity (N)))),
OK, Lo, Hi, Assume_Valid);
else
OK := False;
end if;
return;
end if;
-- If type is not defined, we can't determine its range
if No (Typ)
-- We don't deal with anything except IEEE floating-point types
or else not Is_Floating_Point_Type (Typ)
or else Float_Rep (Typ) /= IEEE_Binary
-- Ignore type for which an error has been posted, since range in
-- this case may well be a bogosity deriving from the error. Also
-- ignore if error posted on the reference node.
or else Error_Posted (N) or else Error_Posted (Typ)
then
OK := False;
return;
end if;
-- For all other cases, we can determine the range
OK := True;
-- If value is compile time known, then the possible range is the one
-- value that we know this expression definitely has.
if Compile_Time_Known_Value (N) then
Lo := Expr_Value_R (N);
Hi := Lo;
return;
end if;
-- Return if already in the cache
Cindex := Cache_Index (N mod Cache_Size);
if Determine_Range_Cache_N (Cindex) = N
and then
Determine_Range_Cache_O (Cindex) = Original_Node (N)
and then
Determine_Range_Cache_V (Cindex) = Assume_Valid
then
Lo := Determine_Range_Cache_Lo_R (Cindex);
Hi := Determine_Range_Cache_Hi_R (Cindex);
return;
end if;
-- Otherwise, start by finding the bounds of the type of the expression,
-- the value cannot be outside this range (if it is, then we have an
-- overflow situation, which is a separate check, we are talking here
-- only about the expression value).
-- First a check, never try to find the bounds of a generic type, since
-- these bounds are always junk values, and it is only valid to look at
-- the bounds in an instance.
if Is_Generic_Type (Typ) then
OK := False;
return;
end if;
-- First step, change to use base type unless we know the value is valid
if (Is_Entity_Name (N) and then Is_Known_Valid (Entity (N)))
or else Assume_No_Invalid_Values
or else Assume_Valid
then
null;
else
Typ := Underlying_Type (Base_Type (Typ));
end if;
-- Retrieve the base type. Handle the case where the base type is a
-- private type.
Btyp := Base_Type (Typ);
if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
Btyp := Full_View (Btyp);
end if;
-- We use the actual bound unless it is dynamic, in which case use the
-- corresponding base type bound if possible. If we can't get a bound
-- then we figure we can't determine the range (a peculiar case, that
-- perhaps cannot happen, but there is no point in bombing in this
-- optimization circuit).
-- First the low bound
Bound := Type_Low_Bound (Typ);
if Compile_Time_Known_Value (Bound) then
Lo := Expr_Value_R (Bound);
elsif Compile_Time_Known_Value (Type_Low_Bound (Btyp)) then
Lo := Expr_Value_R (Type_Low_Bound (Btyp));
else
OK := False;
return;
end if;
-- Now the high bound
Bound := Type_High_Bound (Typ);
-- We need the high bound of the base type later on, and this should
-- always be compile time known. Again, it is not clear that this
-- can ever be false, but no point in bombing.
if Compile_Time_Known_Value (Type_High_Bound (Btyp)) then
Hbound := Expr_Value_R (Type_High_Bound (Btyp));
Hi := Hbound;
else
OK := False;
return;
end if;
-- If we have a static subtype, then that may have a tighter bound so
-- use the upper bound of the subtype instead in this case.
if Compile_Time_Known_Value (Bound) then
Hi := Expr_Value_R (Bound);
end if;
-- We may be able to refine this value in certain situations. If any
-- refinement is possible, then Lor and Hir are set to possibly tighter
-- bounds, and OK1 is set to True.
case Nkind (N) is
-- For unary plus, result is limited by range of operand
when N_Op_Plus =>
Determine_Range_R
(Right_Opnd (N), OK1, Lor, Hir, Assume_Valid);
-- For unary minus, determine range of operand, and negate it
when N_Op_Minus =>
Determine_Range_R
(Right_Opnd (N), OK1, Lo_Right, Hi_Right, Assume_Valid);
if OK1 then
Lor := -Hi_Right;
Hir := -Lo_Right;
end if;
-- For binary addition, get range of each operand and do the
-- addition to get the result range.
when N_Op_Add =>
if OK_Operands then
Lor := Round_Machine (Lo_Left + Lo_Right);
Hir := Round_Machine (Hi_Left + Hi_Right);
end if;
-- For binary subtraction, get range of each operand and do the worst
-- case subtraction to get the result range.
when N_Op_Subtract =>
if OK_Operands then
Lor := Round_Machine (Lo_Left - Hi_Right);
Hir := Round_Machine (Hi_Left - Lo_Right);
end if;
-- For multiplication, get range of each operand and do the
-- four multiplications to get the result range.
when N_Op_Multiply =>
if OK_Operands then
declare
M1 : constant Ureal := Round_Machine (Lo_Left * Lo_Right);
M2 : constant Ureal := Round_Machine (Lo_Left * Hi_Right);
M3 : constant Ureal := Round_Machine (Hi_Left * Lo_Right);
M4 : constant Ureal := Round_Machine (Hi_Left * Hi_Right);
begin
Lor := UR_Min (UR_Min (M1, M2), UR_Min (M3, M4));
Hir := UR_Max (UR_Max (M1, M2), UR_Max (M3, M4));
end;
end if;
-- For division, consider separately the cases where the right
-- operand is positive or negative. Otherwise, the right operand
-- can be arbitrarily close to zero, so the result is likely to
-- be unbounded in one direction, do not attempt to compute it.
when N_Op_Divide =>
if OK_Operands then
-- Right operand is positive
if Lo_Right > Ureal_0 then
-- If the low bound of the left operand is negative, obtain
-- the overall low bound by dividing it by the smallest
-- value of the right operand, and otherwise by the largest
-- value of the right operand.
if Lo_Left < Ureal_0 then
Lor := Round_Machine (Lo_Left / Lo_Right);
else
Lor := Round_Machine (Lo_Left / Hi_Right);
end if;
-- If the high bound of the left operand is negative, obtain
-- the overall high bound by dividing it by the largest
-- value of the right operand, and otherwise by the
-- smallest value of the right operand.
if Hi_Left < Ureal_0 then
Hir := Round_Machine (Hi_Left / Hi_Right);
else
Hir := Round_Machine (Hi_Left / Lo_Right);
end if;
-- Right operand is negative
elsif Hi_Right < Ureal_0 then
-- If the low bound of the left operand is negative, obtain
-- the overall low bound by dividing it by the largest
-- value of the right operand, and otherwise by the smallest
-- value of the right operand.
if Lo_Left < Ureal_0 then
Lor := Round_Machine (Lo_Left / Hi_Right);
else
Lor := Round_Machine (Lo_Left / Lo_Right);
end if;
-- If the high bound of the left operand is negative, obtain
-- the overall high bound by dividing it by the smallest
-- value of the right operand, and otherwise by the
-- largest value of the right operand.
if Hi_Left < Ureal_0 then
Hir := Round_Machine (Hi_Left / Lo_Right);
else
Hir := Round_Machine (Hi_Left / Hi_Right);
end if;
else
OK1 := False;
end if;
end if;
when N_Type_Conversion =>
-- For type conversion from one floating-point type to another, we
-- can refine the range using the converted value.
if Is_Floating_Point_Type (Etype (Expression (N))) then
Determine_Range_R (Expression (N), OK1, Lor, Hir, Assume_Valid);
-- When converting an integer to a floating-point type, determine
-- the range in integer first, and then convert the bounds.
elsif Is_Discrete_Type (Etype (Expression (N))) then
declare
Hir_Int : Uint;
Lor_Int : Uint;
begin
Determine_Range
(Expression (N), OK1, Lor_Int, Hir_Int, Assume_Valid);
if OK1 then
Lor := Round_Machine (UR_From_Uint (Lor_Int));
Hir := Round_Machine (UR_From_Uint (Hir_Int));
end if;
end;
else
OK1 := False;
end if;
-- Nothing special to do for all other expression kinds
when others =>
OK1 := False;
Lor := No_Ureal;
Hir := No_Ureal;
end case;
-- At this stage, if OK1 is true, then we know that the actual result of
-- the computed expression is in the range Lor .. Hir. We can use this
-- to restrict the possible range of results.
if OK1 then
-- If the refined value of the low bound is greater than the type
-- low bound, then reset it to the more restrictive value.
if Lor > Lo then
Lo := Lor;
end if;
-- Similarly, if the refined value of the high bound is less than the
-- value so far, then reset it to the more restrictive value.
if Hir < Hi then
Hi := Hir;
end if;
end if;
-- Set cache entry for future call and we are all done
Determine_Range_Cache_N (Cindex) := N;
Determine_Range_Cache_O (Cindex) := Original_Node (N);
Determine_Range_Cache_V (Cindex) := Assume_Valid;
Determine_Range_Cache_Lo_R (Cindex) := Lo;
Determine_Range_Cache_Hi_R (Cindex) := Hi;
return;
-- If any exception occurs, it means that we have some bug in the compiler,
-- possibly triggered by a previous error, or by some unforeseen peculiar
-- occurrence. However, this is only an optimization attempt, so there is
-- really no point in crashing the compiler. Instead we just decide, too
-- bad, we can't figure out a range in this case after all.
exception
when others =>
-- Debug flag K disables this behavior (useful for debugging)
if Debug_Flag_K then
raise;
else
OK := False;
Lo := No_Ureal;
Hi := No_Ureal;
return;
end if;
end Determine_Range_R;
------------------------------------
-- Discriminant_Checks_Suppressed --
------------------------------------
function Discriminant_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) then
if Is_Unchecked_Union (E) then
return True;
elsif Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Discriminant_Check);
end if;
end if;
return Scope_Suppress.Suppress (Discriminant_Check);
end Discriminant_Checks_Suppressed;
--------------------------------
-- Division_Checks_Suppressed --
--------------------------------
function Division_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Division_Check);
else
return Scope_Suppress.Suppress (Division_Check);
end if;
end Division_Checks_Suppressed;
--------------------------------------
-- Duplicated_Tag_Checks_Suppressed --
--------------------------------------
function Duplicated_Tag_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Duplicated_Tag_Check);
else
return Scope_Suppress.Suppress (Duplicated_Tag_Check);
end if;
end Duplicated_Tag_Checks_Suppressed;
-----------------------------------
-- Elaboration_Checks_Suppressed --
-----------------------------------
function Elaboration_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
-- The complication in this routine is that if we are in the dynamic
-- model of elaboration, we also check All_Checks, since All_Checks
-- does not set Elaboration_Check explicitly.
if Present (E) then
if Kill_Elaboration_Checks (E) then
return True;
elsif Checks_May_Be_Suppressed (E) then
if Is_Check_Suppressed (E, Elaboration_Check) then
return True;
elsif Dynamic_Elaboration_Checks then
return Is_Check_Suppressed (E, All_Checks);
else
return False;
end if;
end if;
end if;
if Scope_Suppress.Suppress (Elaboration_Check) then
return True;
elsif Dynamic_Elaboration_Checks then
return Scope_Suppress.Suppress (All_Checks);
else
return False;
end if;
end Elaboration_Checks_Suppressed;
---------------------------
-- Enable_Overflow_Check --
---------------------------
procedure Enable_Overflow_Check (N : Node_Id) is
Typ : constant Entity_Id := Base_Type (Etype (N));
Mode : constant Overflow_Mode_Type := Overflow_Check_Mode;
Chk : Nat;
OK : Boolean;
Ent : Entity_Id;
Ofs : Uint;
Lo : Uint;
Hi : Uint;
Do_Ovflow_Check : Boolean;
begin
if Debug_Flag_CC then
w ("Enable_Overflow_Check for node ", Int (N));
Write_Str (" Source location = ");
wl (Sloc (N));
pg (Union_Id (N));
end if;
-- No check if overflow checks suppressed for type of node
if Overflow_Checks_Suppressed (Etype (N)) then
return;
-- Nothing to do for unsigned integer types, which do not overflow
elsif Is_Modular_Integer_Type (Typ) then
return;
end if;
-- This is the point at which processing for STRICT mode diverges
-- from processing for MINIMIZED/ELIMINATED modes. This divergence is
-- probably more extreme that it needs to be, but what is going on here
-- is that when we introduced MINIMIZED/ELIMINATED modes, we wanted
-- to leave the processing for STRICT mode untouched. There were
-- two reasons for this. First it avoided any incompatible change of
-- behavior. Second, it guaranteed that STRICT mode continued to be
-- legacy reliable.
-- The big difference is that in STRICT mode there is a fair amount of
-- circuitry to try to avoid setting the Do_Overflow_Check flag if we
-- know that no check is needed. We skip all that in the two new modes,
-- since really overflow checking happens over a whole subtree, and we
-- do the corresponding optimizations later on when applying the checks.
if Mode in Minimized_Or_Eliminated then
if not (Overflow_Checks_Suppressed (Etype (N)))
and then not (Is_Entity_Name (N)
and then Overflow_Checks_Suppressed (Entity (N)))
then
Activate_Overflow_Check (N);
end if;
if Debug_Flag_CC then
w ("Minimized/Eliminated mode");
end if;
return;
end if;
-- Remainder of processing is for STRICT case, and is unchanged from
-- earlier versions preceding the addition of MINIMIZED/ELIMINATED.
-- Nothing to do if the range of the result is known OK. We skip this
-- for conversions, since the caller already did the check, and in any
-- case the condition for deleting the check for a type conversion is
-- different.
if Nkind (N) /= N_Type_Conversion then
Determine_Range (N, OK, Lo, Hi, Assume_Valid => True);
-- Note in the test below that we assume that the range is not OK
-- if a bound of the range is equal to that of the type. That's not
-- quite accurate but we do this for the following reasons:
-- a) The way that Determine_Range works, it will typically report
-- the bounds of the value as being equal to the bounds of the
-- type, because it either can't tell anything more precise, or
-- does not think it is worth the effort to be more precise.
-- b) It is very unusual to have a situation in which this would
-- generate an unnecessary overflow check (an example would be
-- a subtype with a range 0 .. Integer'Last - 1 to which the
-- literal value one is added).
-- c) The alternative is a lot of special casing in this routine
-- which would partially duplicate Determine_Range processing.
if OK then
Do_Ovflow_Check := True;
-- Note that the following checks are quite deliberately > and <
-- rather than >= and <= as explained above.
if Lo > Expr_Value (Type_Low_Bound (Typ))
and then
Hi < Expr_Value (Type_High_Bound (Typ))
then
Do_Ovflow_Check := False;
-- Despite the comments above, it is worth dealing specially with
-- division. The only case where integer division can overflow is
-- (largest negative number) / (-1). So we will do an extra range
-- analysis to see if this is possible.
elsif Nkind (N) = N_Op_Divide then
Determine_Range
(Left_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
if OK and then Lo > Expr_Value (Type_Low_Bound (Typ)) then
Do_Ovflow_Check := False;
else
Determine_Range
(Right_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
if OK and then (Lo > Uint_Minus_1
or else
Hi < Uint_Minus_1)
then
Do_Ovflow_Check := False;
end if;
end if;
-- Likewise for Abs/Minus, the only case where the operation can
-- overflow is when the operand is the largest negative number.
elsif Nkind (N) in N_Op_Abs | N_Op_Minus then
Determine_Range
(Right_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
if OK and then Lo > Expr_Value (Type_Low_Bound (Typ)) then
Do_Ovflow_Check := False;
end if;
end if;
-- If no overflow check required, we are done
if not Do_Ovflow_Check then
if Debug_Flag_CC then
w ("No overflow check required");
end if;
return;
end if;
end if;
end if;
-- If not in optimizing mode, set flag and we are done. We are also done
-- (and just set the flag) if the type is not a discrete type, since it
-- is not worth the effort to eliminate checks for other than discrete
-- types. In addition, we take this same path if we have stored the
-- maximum number of checks possible already (a very unlikely situation,
-- but we do not want to blow up).
if Optimization_Level = 0
or else not Is_Discrete_Type (Etype (N))
or else Num_Saved_Checks = Saved_Checks'Last
then
Activate_Overflow_Check (N);
if Debug_Flag_CC then
w ("Optimization off");
end if;
return;
end if;
-- Otherwise evaluate and check the expression
Find_Check
(Expr => N,
Check_Type => 'O',
Target_Type => Empty,
Entry_OK => OK,
Check_Num => Chk,
Ent => Ent,
Ofs => Ofs);
if Debug_Flag_CC then
w ("Called Find_Check");
w (" OK = ", OK);
if OK then
w (" Check_Num = ", Chk);
w (" Ent = ", Int (Ent));
Write_Str (" Ofs = ");
pid (Ofs);
end if;
end if;
-- If check is not of form to optimize, then set flag and we are done
if not OK then
Activate_Overflow_Check (N);
return;
end if;
-- If check is already performed, then return without setting flag
if Chk /= 0 then
if Debug_Flag_CC then
w ("Check suppressed!");
end if;
return;
end if;
-- Here we will make a new entry for the new check
Activate_Overflow_Check (N);
Num_Saved_Checks := Num_Saved_Checks + 1;
Saved_Checks (Num_Saved_Checks) :=
(Killed => False,
Entity => Ent,
Offset => Ofs,
Check_Type => 'O',
Target_Type => Empty);
if Debug_Flag_CC then
w ("Make new entry, check number = ", Num_Saved_Checks);
w (" Entity = ", Int (Ent));
Write_Str (" Offset = ");
pid (Ofs);
w (" Check_Type = O");
w (" Target_Type = Empty");
end if;
-- If we get an exception, then something went wrong, probably because of
-- an error in the structure of the tree due to an incorrect program. Or
-- it may be a bug in the optimization circuit. In either case the safest
-- thing is simply to set the check flag unconditionally.
exception
when others =>
Activate_Overflow_Check (N);
if Debug_Flag_CC then
w (" exception occurred, overflow flag set");
end if;
return;
end Enable_Overflow_Check;
------------------------
-- Enable_Range_Check --
------------------------
procedure Enable_Range_Check (N : Node_Id) is
Chk : Nat;
OK : Boolean;
Ent : Entity_Id;
Ofs : Uint;
Ttyp : Entity_Id;
P : Node_Id;
begin
-- Return if unchecked type conversion with range check killed. In this
-- case we never set the flag (that's what Kill_Range_Check is about).
if Nkind (N) = N_Unchecked_Type_Conversion
and then Kill_Range_Check (N)
then
return;
end if;
-- Do not set range check flag if parent is assignment statement or
-- object declaration with Suppress_Assignment_Checks flag set
if Nkind (Parent (N)) in N_Assignment_Statement | N_Object_Declaration
and then Suppress_Assignment_Checks (Parent (N))
then
return;
end if;
-- Check for various cases where we should suppress the range check
-- No check if range checks suppressed for type of node
if Present (Etype (N)) and then Range_Checks_Suppressed (Etype (N)) then
return;
-- No check if node is an entity name, and range checks are suppressed
-- for this entity, or for the type of this entity.
elsif Is_Entity_Name (N)
and then (Range_Checks_Suppressed (Entity (N))
or else Range_Checks_Suppressed (Etype (Entity (N))))
then
return;
-- No checks if index of array, and index checks are suppressed for
-- the array object or the type of the array.
elsif Nkind (Parent (N)) = N_Indexed_Component then
declare
Pref : constant Node_Id := Prefix (Parent (N));
begin
if Is_Entity_Name (Pref)
and then Index_Checks_Suppressed (Entity (Pref))
then
return;
elsif Index_Checks_Suppressed (Etype (Pref)) then
return;
end if;
end;
end if;
-- Debug trace output
if Debug_Flag_CC then
w ("Enable_Range_Check for node ", Int (N));
Write_Str (" Source location = ");
wl (Sloc (N));
pg (Union_Id (N));
end if;
-- If not in optimizing mode, set flag and we are done. We are also done
-- (and just set the flag) if the type is not a discrete type, since it
-- is not worth the effort to eliminate checks for other than discrete
-- types. In addition, we take this same path if we have stored the
-- maximum number of checks possible already (a very unlikely situation,
-- but we do not want to blow up).
if Optimization_Level = 0
or else No (Etype (N))
or else not Is_Discrete_Type (Etype (N))
or else Num_Saved_Checks = Saved_Checks'Last
then
Activate_Range_Check (N);
if Debug_Flag_CC then
w ("Optimization off");
end if;
return;
end if;
-- Otherwise find out the target type
P := Parent (N);
-- For assignment, use left side subtype
if Nkind (P) = N_Assignment_Statement
and then Expression (P) = N
then
Ttyp := Etype (Name (P));
-- For indexed component, use subscript subtype
elsif Nkind (P) = N_Indexed_Component then
declare
Atyp : Entity_Id;
Indx : Node_Id;
Subs : Node_Id;
begin
Atyp := Etype (Prefix (P));
if Is_Access_Type (Atyp) then
Atyp := Designated_Type (Atyp);
-- If the prefix is an access to an unconstrained array,
-- perform check unconditionally: it depends on the bounds of
-- an object and we cannot currently recognize whether the test
-- may be redundant.
if not Is_Constrained (Atyp) then
Activate_Range_Check (N);
return;
end if;
-- Ditto if prefix is simply an unconstrained array. We used
-- to think this case was OK, if the prefix was not an explicit
-- dereference, but we have now seen a case where this is not
-- true, so it is safer to just suppress the optimization in this
-- case. The back end is getting better at eliminating redundant
-- checks in any case, so the loss won't be important.
elsif Is_Array_Type (Atyp)
and then not Is_Constrained (Atyp)
then
Activate_Range_Check (N);
return;
end if;
Indx := First_Index (Atyp);
Subs := First (Expressions (P));
loop
if Subs = N then
Ttyp := Etype (Indx);
exit;
end if;
Next_Index (Indx);
Next (Subs);
end loop;
end;
-- For now, ignore all other cases, they are not so interesting
else
if Debug_Flag_CC then
w (" target type not found, flag set");
end if;
Activate_Range_Check (N);
return;
end if;
-- Evaluate and check the expression
Find_Check
(Expr => N,
Check_Type => 'R',
Target_Type => Ttyp,
Entry_OK => OK,
Check_Num => Chk,
Ent => Ent,
Ofs => Ofs);
if Debug_Flag_CC then
w ("Called Find_Check");
w ("Target_Typ = ", Int (Ttyp));
w (" OK = ", OK);
if OK then
w (" Check_Num = ", Chk);
w (" Ent = ", Int (Ent));
Write_Str (" Ofs = ");
pid (Ofs);
end if;
end if;
-- If check is not of form to optimize, then set flag and we are done
if not OK then
if Debug_Flag_CC then
w (" expression not of optimizable type, flag set");
end if;
Activate_Range_Check (N);
return;
end if;
-- If check is already performed, then return without setting flag
if Chk /= 0 then
if Debug_Flag_CC then
w ("Check suppressed!");
end if;
return;
end if;
-- Here we will make a new entry for the new check
Activate_Range_Check (N);
Num_Saved_Checks := Num_Saved_Checks + 1;
Saved_Checks (Num_Saved_Checks) :=
(Killed => False,
Entity => Ent,
Offset => Ofs,
Check_Type => 'R',
Target_Type => Ttyp);
if Debug_Flag_CC then
w ("Make new entry, check number = ", Num_Saved_Checks);
w (" Entity = ", Int (Ent));
Write_Str (" Offset = ");
pid (Ofs);
w (" Check_Type = R");
w (" Target_Type = ", Int (Ttyp));
pg (Union_Id (Ttyp));
end if;
-- If we get an exception, then something went wrong, probably because of
-- an error in the structure of the tree due to an incorrect program. Or
-- it may be a bug in the optimization circuit. In either case the safest
-- thing is simply to set the check flag unconditionally.
exception
when others =>
Activate_Range_Check (N);
if Debug_Flag_CC then
w (" exception occurred, range flag set");
end if;
return;
end Enable_Range_Check;
------------------
-- Ensure_Valid --
------------------
procedure Ensure_Valid
(Expr : Node_Id;
Holes_OK : Boolean := False;
Related_Id : Entity_Id := Empty;
Is_Low_Bound : Boolean := False;
Is_High_Bound : Boolean := False)
is
Typ : constant Entity_Id := Etype (Expr);
begin
-- Ignore call if we are not doing any validity checking
if not Validity_Checks_On then
return;
-- Ignore call if range or validity checks suppressed on entity or type
elsif Range_Or_Validity_Checks_Suppressed (Expr) then
return;
-- No check required if expression is from the expander, we assume the
-- expander will generate whatever checks are needed. Note that this is
-- not just an optimization, it avoids infinite recursions.
-- Unchecked conversions must be checked, unless they are initialized
-- scalar values, as in a component assignment in an init proc.
-- In addition, we force a check if Force_Validity_Checks is set
elsif not Comes_From_Source (Expr)
and then not
(Nkind (Expr) = N_Identifier
and then Present (Renamed_Object (Entity (Expr)))
and then Comes_From_Source (Renamed_Object (Entity (Expr))))
and then not Force_Validity_Checks
and then (Nkind (Expr) /= N_Unchecked_Type_Conversion
or else Kill_Range_Check (Expr))
then
return;
-- No check required if expression is known to have valid value
elsif Expr_Known_Valid (Expr) then
return;
-- No check needed within a generated predicate function. Validity
-- of input value will have been checked earlier.
elsif Ekind (Current_Scope) = E_Function
and then Is_Predicate_Function (Current_Scope)
then
return;
-- Ignore case of enumeration with holes where the flag is set not to
-- worry about holes, since no special validity check is needed
elsif Is_Enumeration_Type (Typ)
and then Has_Non_Standard_Rep (Typ)
and then Holes_OK
then
return;
-- No check required on the left-hand side of an assignment
elsif Nkind (Parent (Expr)) = N_Assignment_Statement
and then Expr = Name (Parent (Expr))
then
return;
-- No check on a universal real constant. The context will eventually
-- convert it to a machine number for some target type, or report an
-- illegality.
elsif Nkind (Expr) = N_Real_Literal
and then Etype (Expr) = Universal_Real
then
return;
-- If the expression denotes a component of a packed boolean array,
-- no possible check applies. We ignore the old ACATS chestnuts that
-- involve Boolean range True..True.
-- Note: validity checks are generated for expressions that yield a
-- scalar type, when it is possible to create a value that is outside of
-- the type. If this is a one-bit boolean no such value exists. This is
-- an optimization, and it also prevents compiler blowing up during the
-- elaboration of improperly expanded packed array references.
elsif Nkind (Expr) = N_Indexed_Component
and then Is_Bit_Packed_Array (Etype (Prefix (Expr)))
and then Root_Type (Etype (Expr)) = Standard_Boolean
then
return;
-- For an expression with actions, we want to insert the validity check
-- on the final Expression.
elsif Nkind (Expr) = N_Expression_With_Actions then
Ensure_Valid (Expression (Expr));
return;
-- An annoying special case. If this is an out parameter of a scalar
-- type, then the value is not going to be accessed, therefore it is
-- inappropriate to do any validity check at the call site. Likewise
-- if the parameter is passed by reference.
else
-- Only need to worry about scalar types
if Is_Scalar_Type (Typ) then
declare
P : Node_Id;
N : Node_Id;
E : Entity_Id;
F : Entity_Id;
A : Node_Id;
L : List_Id;
begin
-- Find actual argument (which may be a parameter association)
-- and the parent of the actual argument (the call statement)
N := Expr;
P := Parent (Expr);
if Nkind (P) = N_Parameter_Association then
N := P;
P := Parent (N);
end if;
-- If this is an indirect or dispatching call, get signature
-- from the subprogram type.
if Nkind (P) in N_Entry_Call_Statement
| N_Function_Call
| N_Procedure_Call_Statement
then
E := Get_Called_Entity (P);
L := Parameter_Associations (P);
-- Only need to worry if there are indeed actuals, and if
-- this could be a subprogram call, otherwise we cannot get
-- a match (either we are not an argument, or the mode of
-- the formal is not OUT). This test also filters out the
-- generic case.
if Is_Non_Empty_List (L) and then Is_Subprogram (E) then
-- This is the loop through parameters, looking for an
-- OUT parameter for which we are the argument.
F := First_Formal (E);
A := First (L);
while Present (F) loop
if A = N
and then (Ekind (F) = E_Out_Parameter
or else Mechanism (F) = By_Reference)
then
return;
end if;
Next_Formal (F);
Next (A);
end loop;
end if;
end if;
end;
end if;
end if;
-- If this is a boolean expression, only its elementary operands need
-- checking: if they are valid, a boolean or short-circuit operation
-- with them will be valid as well.
if Base_Type (Typ) = Standard_Boolean
and then
(Nkind (Expr) in N_Op or else Nkind (Expr) in N_Short_Circuit)
then
return;
end if;
-- If we fall through, a validity check is required
Insert_Valid_Check (Expr, Related_Id, Is_Low_Bound, Is_High_Bound);
if Is_Entity_Name (Expr)
and then Safe_To_Capture_Value (Expr, Entity (Expr))
then
Set_Is_Known_Valid (Entity (Expr));
end if;
end Ensure_Valid;
----------------------
-- Expr_Known_Valid --
----------------------
function Expr_Known_Valid (Expr : Node_Id) return Boolean is
Typ : constant Entity_Id := Etype (Expr);
begin
-- Non-scalar types are always considered valid, since they never give
-- rise to the issues of erroneous or bounded error behavior that are
-- the concern. In formal reference manual terms the notion of validity
-- only applies to scalar types. Note that even when packed arrays are
-- represented using modular types, they are still arrays semantically,
-- so they are also always valid (in particular, the unused bits can be
-- random rubbish without affecting the validity of the array value).
if not Is_Scalar_Type (Typ) or else Is_Packed_Array_Impl_Type (Typ) then
return True;
-- If no validity checking, then everything is considered valid
elsif not Validity_Checks_On then
return True;
-- Floating-point types are considered valid unless floating-point
-- validity checks have been specifically turned on.
elsif Is_Floating_Point_Type (Typ)
and then not Validity_Check_Floating_Point
then
return True;
-- If the expression is the value of an object that is known to be
-- valid, then clearly the expression value itself is valid.
elsif Is_Entity_Name (Expr)
and then Is_Known_Valid (Entity (Expr))
-- Exclude volatile variables
and then not Treat_As_Volatile (Entity (Expr))
then
return True;
-- References to discriminants are always considered valid. The value
-- of a discriminant gets checked when the object is built. Within the
-- record, we consider it valid, and it is important to do so, since
-- otherwise we can try to generate bogus validity checks which
-- reference discriminants out of scope. Discriminants of concurrent
-- types are excluded for the same reason.
elsif Is_Entity_Name (Expr)
and then Denotes_Discriminant (Expr, Check_Concurrent => True)
then
return True;
-- If the type is one for which all values are known valid, then we are
-- sure that the value is valid except in the slightly odd case where
-- the expression is a reference to a variable whose size has been
-- explicitly set to a value greater than the object size.
elsif Is_Known_Valid (Typ) then
if Is_Entity_Name (Expr)
and then Ekind (Entity (Expr)) = E_Variable
and then Esize (Entity (Expr)) > Esize (Typ)
then
return False;
else
return True;
end if;
-- Integer and character literals always have valid values, where
-- appropriate these will be range checked in any case.
elsif Nkind (Expr) in N_Integer_Literal | N_Character_Literal then
return True;
-- If we have a type conversion or a qualification of a known valid
-- value, then the result will always be valid.
elsif Nkind (Expr) in N_Type_Conversion | N_Qualified_Expression then
return Expr_Known_Valid (Expression (Expr));
-- Case of expression is a non-floating-point operator. In this case we
-- can assume the result is valid the generated code for the operator
-- will include whatever checks are needed (e.g. range checks) to ensure
-- validity. This assumption does not hold for the floating-point case,
-- since floating-point operators can generate Infinite or NaN results
-- which are considered invalid.
-- Historical note: in older versions, the exemption of floating-point
-- types from this assumption was done only in cases where the parent
-- was an assignment, function call or parameter association. Presumably
-- the idea was that in other contexts, the result would be checked
-- elsewhere, but this list of cases was missing tests (at least the
-- N_Object_Declaration case, as shown by a reported missing validity
-- check), and it is not clear why function calls but not procedure
-- calls were tested for. It really seems more accurate and much
-- safer to recognize that expressions which are the result of a
-- floating-point operator can never be assumed to be valid.
elsif Nkind (Expr) in N_Op and then not Is_Floating_Point_Type (Typ) then
return True;
-- The result of a membership test is always valid, since it is true or
-- false, there are no other possibilities.
elsif Nkind (Expr) in N_Membership_Test then
return True;
-- For all other cases, we do not know the expression is valid
else
return False;
end if;
end Expr_Known_Valid;
----------------
-- Find_Check --
----------------
procedure Find_Check
(Expr : Node_Id;
Check_Type : Character;
Target_Type : Entity_Id;
Entry_OK : out Boolean;
Check_Num : out Nat;
Ent : out Entity_Id;
Ofs : out Uint)
is
function Within_Range_Of
(Target_Type : Entity_Id;
Check_Type : Entity_Id) return Boolean;
-- Given a requirement for checking a range against Target_Type, and
-- and a range Check_Type against which a check has already been made,
-- determines if the check against check type is sufficient to ensure
-- that no check against Target_Type is required.
---------------------
-- Within_Range_Of --
---------------------
function Within_Range_Of
(Target_Type : Entity_Id;
Check_Type : Entity_Id) return Boolean
is
begin
if Target_Type = Check_Type then
return True;
else
declare
Tlo : constant Node_Id := Type_Low_Bound (Target_Type);
Thi : constant Node_Id := Type_High_Bound (Target_Type);
Clo : constant Node_Id := Type_Low_Bound (Check_Type);
Chi : constant Node_Id := Type_High_Bound (Check_Type);
begin
if (Tlo = Clo
or else (Compile_Time_Known_Value (Tlo)
and then
Compile_Time_Known_Value (Clo)
and then
Expr_Value (Clo) >= Expr_Value (Tlo)))
and then
(Thi = Chi
or else (Compile_Time_Known_Value (Thi)
and then
Compile_Time_Known_Value (Chi)
and then
Expr_Value (Chi) <= Expr_Value (Clo)))
then
return True;
else
return False;
end if;
end;
end if;
end Within_Range_Of;
-- Start of processing for Find_Check
begin
-- Establish default, in case no entry is found
Check_Num := 0;
-- Case of expression is simple entity reference
if Is_Entity_Name (Expr) then
Ent := Entity (Expr);
Ofs := Uint_0;
-- Case of expression is entity + known constant
elsif Nkind (Expr) = N_Op_Add
and then Compile_Time_Known_Value (Right_Opnd (Expr))
and then Is_Entity_Name (Left_Opnd (Expr))
then
Ent := Entity (Left_Opnd (Expr));
Ofs := Expr_Value (Right_Opnd (Expr));
-- Case of expression is entity - known constant
elsif Nkind (Expr) = N_Op_Subtract
and then Compile_Time_Known_Value (Right_Opnd (Expr))
and then Is_Entity_Name (Left_Opnd (Expr))
then
Ent := Entity (Left_Opnd (Expr));
Ofs := UI_Negate (Expr_Value (Right_Opnd (Expr)));
-- Any other expression is not of the right form
else
Ent := Empty;
Ofs := Uint_0;
Entry_OK := False;
return;
end if;
-- Come here with expression of appropriate form, check if entity is an
-- appropriate one for our purposes.
if (Ekind (Ent) = E_Variable
or else Is_Constant_Object (Ent))
and then not Is_Library_Level_Entity (Ent)
then
Entry_OK := True;
else
Entry_OK := False;
return;
end if;
-- See if there is matching check already
for J in reverse 1 .. Num_Saved_Checks loop
declare
SC : Saved_Check renames Saved_Checks (J);
begin
if SC.Killed = False
and then SC.Entity = Ent
and then SC.Offset = Ofs
and then SC.Check_Type = Check_Type
and then Within_Range_Of (Target_Type, SC.Target_Type)
then
Check_Num := J;
return;
end if;
end;
end loop;
-- If we fall through entry was not found
return;
end Find_Check;
---------------------------------
-- Generate_Discriminant_Check --
---------------------------------
procedure Generate_Discriminant_Check (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Pref : constant Node_Id := Prefix (N);
Sel : constant Node_Id := Selector_Name (N);
Orig_Comp : constant Entity_Id :=
Original_Record_Component (Entity (Sel));
-- The original component to be checked
Discr_Fct : constant Entity_Id :=
Discriminant_Checking_Func (Orig_Comp);
-- The discriminant checking function
Discr : Entity_Id;
-- One discriminant to be checked in the type
Real_Discr : Entity_Id;
-- Actual discriminant in the call
Pref_Type : Entity_Id;
-- Type of relevant prefix (ignoring private/access stuff)
Args : List_Id;
-- List of arguments for function call
Formal : Entity_Id;
-- Keep track of the formal corresponding to the actual we build for
-- each discriminant, in order to be able to perform the necessary type
-- conversions.
Scomp : Node_Id;
-- Selected component reference for checking function argument
begin
Pref_Type := Etype (Pref);
-- Force evaluation of the prefix, so that it does not get evaluated
-- twice (once for the check, once for the actual reference). Such a
-- double evaluation is always a potential source of inefficiency, and
-- is functionally incorrect in the volatile case, or when the prefix
-- may have side effects. A nonvolatile entity or a component of a
-- nonvolatile entity requires no evaluation.
if Is_Entity_Name (Pref) then
if Treat_As_Volatile (Entity (Pref)) then
Force_Evaluation (Pref, Name_Req => True);
end if;
elsif Treat_As_Volatile (Etype (Pref)) then
Force_Evaluation (Pref, Name_Req => True);
elsif Nkind (Pref) = N_Selected_Component
and then Is_Entity_Name (Prefix (Pref))
then
null;
else
Force_Evaluation (Pref, Name_Req => True);
end if;
-- For a tagged type, use the scope of the original component to
-- obtain the type, because ???
if Is_Tagged_Type (Scope (Orig_Comp)) then
Pref_Type := Scope (Orig_Comp);
-- For an untagged derived type, use the discriminants of the parent
-- which have been renamed in the derivation, possibly by a one-to-many
-- discriminant constraint. For untagged type, initially get the Etype
-- of the prefix
else
if Is_Derived_Type (Pref_Type)
and then Number_Discriminants (Pref_Type) /=
Number_Discriminants (Etype (Base_Type (Pref_Type)))
then
Pref_Type := Etype (Base_Type (Pref_Type));
end if;
end if;
-- We definitely should have a checking function, This routine should
-- not be called if no discriminant checking function is present.
pragma Assert (Present (Discr_Fct));
-- Create the list of the actual parameters for the call. This list
-- is the list of the discriminant fields of the record expression to
-- be discriminant checked.
Args := New_List;
Formal := First_Formal (Discr_Fct);
Discr := First_Discriminant (Pref_Type);
while Present (Discr) loop
-- If we have a corresponding discriminant field, and a parent
-- subtype is present, then we want to use the corresponding
-- discriminant since this is the one with the useful value.
if Present (Corresponding_Discriminant (Discr))
and then Ekind (Pref_Type) = E_Record_Type
and then Present (Parent_Subtype (Pref_Type))
then
Real_Discr := Corresponding_Discriminant (Discr);
else
Real_Discr := Discr;
end if;
-- Construct the reference to the discriminant
Scomp :=
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (Pref_Type,
Duplicate_Subexpr (Pref)),
Selector_Name => New_Occurrence_Of (Real_Discr, Loc));
-- Manually analyze and resolve this selected component. We really
-- want it just as it appears above, and do not want the expander
-- playing discriminal games etc with this reference. Then we append
-- the argument to the list we are gathering.
Set_Etype (Scomp, Etype (Real_Discr));
Set_Analyzed (Scomp, True);
Append_To (Args, Convert_To (Etype (Formal), Scomp));
Next_Formal_With_Extras (Formal);
Next_Discriminant (Discr);
end loop;
-- Now build and insert the call
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Discr_Fct, Loc),
Parameter_Associations => Args),
Reason => CE_Discriminant_Check_Failed));
end Generate_Discriminant_Check;
---------------------------
-- Generate_Index_Checks --
---------------------------
procedure Generate_Index_Checks (N : Node_Id) is
function Entity_Of_Prefix return Entity_Id;
-- Returns the entity of the prefix of N (or Empty if not found)
----------------------
-- Entity_Of_Prefix --
----------------------
function Entity_Of_Prefix return Entity_Id is
P : Node_Id;
begin
P := Prefix (N);
while not Is_Entity_Name (P) loop
if Nkind (P) not in N_Selected_Component | N_Indexed_Component then
return Empty;
end if;
P := Prefix (P);
end loop;
return Entity (P);
end Entity_Of_Prefix;
-- Local variables
Loc : constant Source_Ptr := Sloc (N);
A : constant Node_Id := Prefix (N);
A_Ent : constant Entity_Id := Entity_Of_Prefix;
Sub : Node_Id;
-- Start of processing for Generate_Index_Checks
begin
-- Ignore call if the prefix is not an array since we have a serious
-- error in the sources. Ignore it also if index checks are suppressed
-- for array object or type.
if not Is_Array_Type (Etype (A))
or else (Present (A_Ent) and then Index_Checks_Suppressed (A_Ent))
or else Index_Checks_Suppressed (Etype (A))
then
return;
-- The indexed component we are dealing with contains 'Loop_Entry in its
-- prefix. This case arises when analysis has determined that constructs
-- such as
-- Prefix'Loop_Entry (Expr)
-- Prefix'Loop_Entry (Expr1, Expr2, ... ExprN)
-- require rewriting for error detection purposes. A side effect of this
-- action is the generation of index checks that mention 'Loop_Entry.
-- Delay the generation of the check until 'Loop_Entry has been properly
-- expanded. This is done in Expand_Loop_Entry_Attributes.
elsif Nkind (Prefix (N)) = N_Attribute_Reference
and then Attribute_Name (Prefix (N)) = Name_Loop_Entry
then
return;
end if;
-- Generate a raise of constraint error with the appropriate reason and
-- a condition of the form:
-- Base_Type (Sub) not in Array'Range (Subscript)
-- Note that the reason we generate the conversion to the base type here
-- is that we definitely want the range check to take place, even if it
-- looks like the subtype is OK. Optimization considerations that allow
-- us to omit the check have already been taken into account in the
-- setting of the Do_Range_Check flag earlier on.
Sub := First (Expressions (N));
-- Handle string literals
if Ekind (Etype (A)) = E_String_Literal_Subtype then
if Do_Range_Check (Sub) then
Set_Do_Range_Check (Sub, False);
-- For string literals we obtain the bounds of the string from the
-- associated subtype.
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Not_In (Loc,
Left_Opnd =>
Convert_To (Base_Type (Etype (Sub)),
Duplicate_Subexpr_Move_Checks (Sub)),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Etype (A), Loc),
Attribute_Name => Name_Range)),
Reason => CE_Index_Check_Failed));
end if;
-- General case
else
declare
A_Idx : Node_Id;
A_Range : Node_Id;
Ind : Pos;
Num : List_Id;
Range_N : Node_Id;
begin
A_Idx := First_Index (Etype (A));
Ind := 1;
while Present (Sub) loop
if Do_Range_Check (Sub) then
Set_Do_Range_Check (Sub, False);
-- Force evaluation except for the case of a simple name of
-- a nonvolatile entity.
if not Is_Entity_Name (Sub)
or else Treat_As_Volatile (Entity (Sub))
then
Force_Evaluation (Sub);
end if;
if Nkind (A_Idx) = N_Range then
A_Range := A_Idx;
elsif Nkind (A_Idx) in N_Identifier | N_Expanded_Name then
A_Range := Scalar_Range (Entity (A_Idx));
if Nkind (A_Range) = N_Subtype_Indication then
A_Range := Range_Expression (Constraint (A_Range));
end if;
else pragma Assert (Nkind (A_Idx) = N_Subtype_Indication);
A_Range := Range_Expression (Constraint (A_Idx));
end if;
-- For array objects with constant bounds we can generate
-- the index check using the bounds of the type of the index
if Present (A_Ent)
and then Ekind (A_Ent) = E_Variable
and then Is_Constant_Bound (Low_Bound (A_Range))
and then Is_Constant_Bound (High_Bound (A_Range))
then
Range_N :=
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Etype (A_Idx), Loc),
Attribute_Name => Name_Range);
-- For arrays with non-constant bounds we cannot generate
-- the index check using the bounds of the type of the index
-- since it may reference discriminants of some enclosing
-- type. We obtain the bounds directly from the prefix
-- object.
else
if Ind = 1 then
Num := No_List;
else
Num := New_List (Make_Integer_Literal (Loc, Ind));
end if;
Range_N :=
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr_Move_Checks (A, Name_Req => True),
Attribute_Name => Name_Range,
Expressions => Num);
end if;
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Not_In (Loc,
Left_Opnd =>
Convert_To (Base_Type (Etype (Sub)),
Duplicate_Subexpr_Move_Checks (Sub)),
Right_Opnd => Range_N),
Reason => CE_Index_Check_Failed));
end if;
Next_Index (A_Idx);
Ind := Ind + 1;
Next (Sub);
end loop;
end;
end if;
end Generate_Index_Checks;
--------------------------
-- Generate_Range_Check --
--------------------------
procedure Generate_Range_Check
(N : Node_Id;
Target_Type : Entity_Id;
Reason : RT_Exception_Code)
is
Loc : constant Source_Ptr := Sloc (N);
Source_Type : constant Entity_Id := Etype (N);
Source_Base_Type : constant Entity_Id := Base_Type (Source_Type);
Target_Base_Type : constant Entity_Id := Base_Type (Target_Type);
procedure Convert_And_Check_Range (Suppress : Check_Id);
-- Convert N to the target base type and save the result in a temporary.
-- The action is analyzed using the default checks as modified by the
-- given Suppress argument. Then check the converted value against the
-- range of the target subtype.
function Is_Single_Attribute_Reference (N : Node_Id) return Boolean;
-- Return True if N is an expression that contains a single attribute
-- reference, possibly as operand among only integer literal operands.
-----------------------------
-- Convert_And_Check_Range --
-----------------------------
procedure Convert_And_Check_Range (Suppress : Check_Id) is
Tnn : constant Entity_Id := Make_Temporary (Loc, 'T', N);
Conv_N : Node_Id;
begin
-- For enumeration types with non-standard representation this is a
-- direct conversion from the enumeration type to the target integer
-- type, which is treated by the back end as a normal integer type
-- conversion, treating the enumeration type as an integer, which is
-- exactly what we want. We set Conversion_OK to make sure that the
-- analyzer does not complain about what otherwise might be an
-- illegal conversion.
if Is_Enumeration_Type (Source_Base_Type)
and then Present (Enum_Pos_To_Rep (Source_Base_Type))
and then Is_Integer_Type (Target_Base_Type)
then
Conv_N := OK_Convert_To (Target_Base_Type, Duplicate_Subexpr (N));
else
Conv_N := Convert_To (Target_Base_Type, Duplicate_Subexpr (N));
end if;
-- We make a temporary to hold the value of the conversion to the
-- target base type, and then do the test against this temporary.
-- N itself is replaced by an occurrence of Tnn and followed by
-- the explicit range check.
-- Tnn : constant Target_Base_Type := Target_Base_Type (N);
-- [constraint_error when Tnn not in Target_Type]
-- Tnn
Insert_Actions (N, New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Tnn,
Object_Definition => New_Occurrence_Of (Target_Base_Type, Loc),
Constant_Present => True,
Expression => Conv_N),
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Not_In (Loc,
Left_Opnd => New_Occurrence_Of (Tnn, Loc),
Right_Opnd => New_Occurrence_Of (Target_Type, Loc)),
Reason => Reason)),
Suppress => Suppress);
Rewrite (N, New_Occurrence_Of (Tnn, Loc));
-- Set the type of N, because the declaration for Tnn might not
-- be analyzed yet, as is the case if N appears within a record
-- declaration, as a discriminant constraint or expression.
Set_Etype (N, Target_Base_Type);
end Convert_And_Check_Range;
-------------------------------------
-- Is_Single_Attribute_Reference --
-------------------------------------
function Is_Single_Attribute_Reference (N : Node_Id) return Boolean is
begin
if Nkind (N) = N_Attribute_Reference then
return True;
elsif Nkind (N) in N_Binary_Op then
if Nkind (Right_Opnd (N)) = N_Integer_Literal then
return Is_Single_Attribute_Reference (Left_Opnd (N));
elsif Nkind (Left_Opnd (N)) = N_Integer_Literal then
return Is_Single_Attribute_Reference (Right_Opnd (N));
else
return False;
end if;
else
return False;
end if;
end Is_Single_Attribute_Reference;
-- Start of processing for Generate_Range_Check
begin
-- First special case, if the source type is already within the range
-- of the target type, then no check is needed (probably we should have
-- stopped Do_Range_Check from being set in the first place, but better
-- late than never in preventing junk code and junk flag settings).
if In_Subrange_Of (Source_Type, Target_Type)
-- We do NOT apply this if the source node is a literal, since in this
-- case the literal has already been labeled as having the subtype of
-- the target.
and then not
(Nkind (N) in
N_Integer_Literal | N_Real_Literal | N_Character_Literal
or else
(Is_Entity_Name (N)
and then Ekind (Entity (N)) = E_Enumeration_Literal))
then
Set_Do_Range_Check (N, False);
return;
end if;
-- Here a check is needed. If the expander is not active (which is also
-- the case in GNATprove mode), then simply set the Do_Range_Check flag
-- and we are done. We just want to see the range check flag set, we do
-- not want to generate the explicit range check code.
if not Expander_Active then
Set_Do_Range_Check (N);
return;
end if;
-- Here we will generate an explicit range check, so we don't want to
-- set the Do_Range check flag, since the range check is taken care of
-- by the code we will generate.
Set_Do_Range_Check (N, False);
-- Force evaluation of the node, so that it does not get evaluated twice
-- (once for the check, once for the actual reference). Such a double
-- evaluation is always a potential source of inefficiency, and is
-- functionally incorrect in the volatile case.
-- We skip the evaluation of attribute references because, after these
-- runtime checks are generated, the expander may need to rewrite this
-- node (for example, see Attribute_Max_Size_In_Storage_Elements in
-- Expand_N_Attribute_Reference) and, in many cases, their return type
-- is universal integer, which is a very large type for a temporary.
if not Is_Single_Attribute_Reference (N)
and then (not Is_Entity_Name (N)
or else Treat_As_Volatile (Entity (N)))
then
Force_Evaluation (N, Mode => Strict);
end if;
-- The easiest case is when Source_Base_Type and Target_Base_Type are
-- the same since in this case we can simply do a direct check of the
-- value of N against the bounds of Target_Type.
-- [constraint_error when N not in Target_Type]
-- Note: this is by far the most common case, for example all cases of
-- checks on the RHS of assignments are in this category, but not all
-- cases are like this. Notably conversions can involve two types.
if Source_Base_Type = Target_Base_Type then
-- Insert the explicit range check. Note that we suppress checks for
-- this code, since we don't want a recursive range check popping up.
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Not_In (Loc,
Left_Opnd => Duplicate_Subexpr (N),
Right_Opnd => New_Occurrence_Of (Target_Type, Loc)),
Reason => Reason),
Suppress => All_Checks);
-- Next test for the case where the target type is within the bounds
-- of the base type of the source type, since in this case we can
-- simply convert the bounds of the target type to this base type
-- to do the test.
-- [constraint_error when N not in
-- Source_Base_Type (Target_Type'First)
-- ..
-- Source_Base_Type(Target_Type'Last))]
-- The conversions will always work and need no check
-- Unchecked_Convert_To is used instead of Convert_To to handle the case
-- of converting from an enumeration value to an integer type, such as
-- occurs for the case of generating a range check on Enum'Val(Exp)
-- (which used to be handled by gigi). This is OK, since the conversion
-- itself does not require a check.
elsif In_Subrange_Of (Target_Type, Source_Base_Type) then
-- Insert the explicit range check. Note that we suppress checks for
-- this code, since we don't want a recursive range check popping up.
if Is_Discrete_Type (Source_Base_Type)
and then
Is_Discrete_Type (Target_Base_Type)
then
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Not_In (Loc,
Left_Opnd => Duplicate_Subexpr (N),
Right_Opnd =>
Make_Range (Loc,
Low_Bound =>
Unchecked_Convert_To (Source_Base_Type,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Target_Type, Loc),
Attribute_Name => Name_First)),
High_Bound =>
Unchecked_Convert_To (Source_Base_Type,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Target_Type, Loc),
Attribute_Name => Name_Last)))),
Reason => Reason),
Suppress => All_Checks);
-- For conversions involving at least one type that is not discrete,
-- first convert to the target base type and then generate the range
-- check. This avoids problems with values that are close to a bound
-- of the target type that would fail a range check when done in a
-- larger source type before converting but pass if converted with
-- rounding and then checked (such as in float-to-float conversions).
-- Note that overflow checks are not suppressed for this code because
-- we do not know whether the source type is in range of the target
-- base type (unlike in the next case below).
else
Convert_And_Check_Range (Suppress => Range_Check);
end if;
-- Note that at this stage we know that the Target_Base_Type is not in
-- the range of the Source_Base_Type (since even the Target_Type itself
-- is not in this range). It could still be the case that Source_Type is
-- in range of the target base type since we have not checked that case.
-- If that is the case, we can freely convert the source to the target,
-- and then test the target result against the bounds. Note that checks
-- are suppressed for this code, since we don't want a recursive range
-- check popping up.
elsif In_Subrange_Of (Source_Type, Target_Base_Type) then
Convert_And_Check_Range (Suppress => All_Checks);
-- At this stage, we know that we have two scalar types, which are
-- directly convertible, and where neither scalar type has a base
-- range that is in the range of the other scalar type.
-- The only way this can happen is with a signed and unsigned type.
-- So test for these two cases:
else
-- Case of the source is unsigned and the target is signed
if Is_Unsigned_Type (Source_Base_Type)
and then not Is_Unsigned_Type (Target_Base_Type)
then
-- If the source is unsigned and the target is signed, then we
-- know that the source is not shorter than the target (otherwise
-- the source base type would be in the target base type range).
-- In other words, the unsigned type is either the same size as
-- the target, or it is larger. It cannot be smaller.
pragma Assert
(Esize (Source_Base_Type) >= Esize (Target_Base_Type));
-- We only need to check the low bound if the low bound of the
-- target type is non-negative. If the low bound of the target
-- type is negative, then we know that we will fit fine.
-- If the high bound of the target type is negative, then we
-- know we have a constraint error, since we can't possibly
-- have a negative source.
-- With these two checks out of the way, we can do the check
-- using the source type safely
-- This is definitely the most annoying case.
-- [constraint_error
-- when (Target_Type'First >= 0
-- and then
-- N < Source_Base_Type (Target_Type'First))
-- or else Target_Type'Last < 0
-- or else N > Source_Base_Type (Target_Type'Last)];
-- We turn off all checks since we know that the conversions
-- will work fine, given the guards for negative values.
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Or_Else (Loc,
Make_Or_Else (Loc,
Left_Opnd =>
Make_And_Then (Loc,
Left_Opnd => Make_Op_Ge (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Target_Type, Loc),
Attribute_Name => Name_First),
Right_Opnd => Make_Integer_Literal (Loc, Uint_0)),
Right_Opnd =>
Make_Op_Lt (Loc,
Left_Opnd => Duplicate_Subexpr (N),
Right_Opnd =>
Convert_To (Source_Base_Type,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Target_Type, Loc),
Attribute_Name => Name_First)))),
Right_Opnd =>
Make_Op_Lt (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Target_Type, Loc),
Attribute_Name => Name_Last),
Right_Opnd => Make_Integer_Literal (Loc, Uint_0))),
Right_Opnd =>
Make_Op_Gt (Loc,
Left_Opnd => Duplicate_Subexpr (N),
Right_Opnd =>
Convert_To (Source_Base_Type,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Target_Type, Loc),
Attribute_Name => Name_Last)))),
Reason => Reason),
Suppress => All_Checks);
-- Only remaining possibility is that the source is signed and
-- the target is unsigned.
else
pragma Assert (not Is_Unsigned_Type (Source_Base_Type)
and then Is_Unsigned_Type (Target_Base_Type));
-- If the source is signed and the target is unsigned, then we
-- know that the target is not shorter than the source (otherwise
-- the target base type would be in the source base type range).
-- In other words, the unsigned type is either the same size as
-- the target, or it is larger. It cannot be smaller.
-- Clearly we have an error if the source value is negative since
-- no unsigned type can have negative values. If the source type
-- is non-negative, then the check can be done using the target
-- type.
-- Tnn : constant Target_Base_Type (N) := Target_Type;
-- [constraint_error
-- when N < 0 or else Tnn not in Target_Type];
-- We turn off all checks for the conversion of N to the target
-- base type, since we generate the explicit check to ensure that
-- the value is non-negative
declare
Tnn : constant Entity_Id := Make_Temporary (Loc, 'T', N);
begin
Insert_Actions (N, New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Tnn,
Object_Definition =>
New_Occurrence_Of (Target_Base_Type, Loc),
Constant_Present => True,
Expression =>
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark =>
New_Occurrence_Of (Target_Base_Type, Loc),
Expression => Duplicate_Subexpr (N))),
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Lt (Loc,
Left_Opnd => Duplicate_Subexpr (N),
Right_Opnd => Make_Integer_Literal (Loc, Uint_0)),
Right_Opnd =>
Make_Not_In (Loc,
Left_Opnd => New_Occurrence_Of (Tnn, Loc),
Right_Opnd =>
New_Occurrence_Of (Target_Type, Loc))),
Reason => Reason)),
Suppress => All_Checks);
-- Set the Etype explicitly, because Insert_Actions may have
-- placed the declaration in the freeze list for an enclosing
-- construct, and thus it is not analyzed yet.
Set_Etype (Tnn, Target_Base_Type);
Rewrite (N, New_Occurrence_Of (Tnn, Loc));
end;
end if;
end if;
end Generate_Range_Check;
------------------
-- Get_Check_Id --
------------------
function Get_Check_Id (N : Name_Id) return Check_Id is
begin
-- For standard check name, we can do a direct computation
if N in First_Check_Name .. Last_Check_Name then
return Check_Id (N - (First_Check_Name - 1));
-- For non-standard names added by pragma Check_Name, search table
else
for J in All_Checks + 1 .. Check_Names.Last loop
if Check_Names.Table (J) = N then
return J;
end if;
end loop;
end if;
-- No matching name found
return No_Check_Id;
end Get_Check_Id;
---------------------
-- Get_Discriminal --
---------------------
function Get_Discriminal (E : Entity_Id; Bound : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (E);
D : Entity_Id;
Sc : Entity_Id;
begin
-- The bound can be a bona fide parameter of a protected operation,
-- rather than a prival encoded as an in-parameter.
if No (Discriminal_Link (Entity (Bound))) then
return Bound;
end if;
-- Climb the scope stack looking for an enclosing protected type. If
-- we run out of scopes, return the bound itself.
Sc := Scope (E);
while Present (Sc) loop
if Sc = Standard_Standard then
return Bound;
elsif Ekind (Sc) = E_Protected_Type then
exit;
end if;
Sc := Scope (Sc);
end loop;
D := First_Discriminant (Sc);
while Present (D) loop
if Chars (D) = Chars (Bound) then
return New_Occurrence_Of (Discriminal (D), Loc);
end if;
Next_Discriminant (D);
end loop;
return Bound;
end Get_Discriminal;
----------------------
-- Get_Range_Checks --
----------------------
function Get_Range_Checks
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id := Empty;
Warn_Node : Node_Id := Empty) return Check_Result
is
begin
return
Selected_Range_Checks (Expr, Target_Typ, Source_Typ, Warn_Node);
end Get_Range_Checks;
------------------
-- Guard_Access --
------------------
function Guard_Access
(Cond : Node_Id;
Loc : Source_Ptr;
Expr : Node_Id) return Node_Id
is
begin
if Nkind (Cond) = N_Or_Else then
Set_Paren_Count (Cond, 1);
end if;
if Nkind (Expr) = N_Allocator then
return Cond;
else
return
Make_And_Then (Loc,
Left_Opnd =>
Make_Op_Ne (Loc,
Left_Opnd => Duplicate_Subexpr_No_Checks (Expr),
Right_Opnd => Make_Null (Loc)),
Right_Opnd => Cond);
end if;
end Guard_Access;
-----------------------------
-- Index_Checks_Suppressed --
-----------------------------
function Index_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Index_Check);
else
return Scope_Suppress.Suppress (Index_Check);
end if;
end Index_Checks_Suppressed;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
for J in Determine_Range_Cache_N'Range loop
Determine_Range_Cache_N (J) := Empty;
end loop;
Check_Names.Init;
for J in Int range 1 .. All_Checks loop
Check_Names.Append (Name_Id (Int (First_Check_Name) + J - 1));
end loop;
end Initialize;
-------------------------
-- Insert_Range_Checks --
-------------------------
procedure Insert_Range_Checks
(Checks : Check_Result;
Node : Node_Id;
Suppress_Typ : Entity_Id;
Static_Sloc : Source_Ptr;
Do_Before : Boolean := False)
is
Checks_On : constant Boolean :=
not Index_Checks_Suppressed (Suppress_Typ)
or else
not Range_Checks_Suppressed (Suppress_Typ);
Check_Node : Node_Id;
begin
-- For now we just return if Checks_On is false, however this should be
-- enhanced to check for an always True value in the condition and to
-- generate a compilation warning???
if not Expander_Active or not Checks_On then
return;
end if;
for J in 1 .. 2 loop
exit when No (Checks (J));
if Nkind (Checks (J)) = N_Raise_Constraint_Error
and then Present (Condition (Checks (J)))
then
Check_Node := Checks (J);
else
Check_Node :=
Make_Raise_Constraint_Error (Static_Sloc,
Reason => CE_Range_Check_Failed);
end if;
Mark_Rewrite_Insertion (Check_Node);
if Do_Before then
Insert_Before_And_Analyze (Node, Check_Node);
else
Insert_After_And_Analyze (Node, Check_Node);
end if;
end loop;
end Insert_Range_Checks;
------------------------
-- Insert_Valid_Check --
------------------------
procedure Insert_Valid_Check
(Expr : Node_Id;
Related_Id : Entity_Id := Empty;
Is_Low_Bound : Boolean := False;
Is_High_Bound : Boolean := False)
is
Loc : constant Source_Ptr := Sloc (Expr);
Typ : constant Entity_Id := Etype (Expr);
Exp : Node_Id;
begin
-- Do not insert if checks off, or if not checking validity or if
-- expression is known to be valid.
if not Validity_Checks_On
or else Range_Or_Validity_Checks_Suppressed (Expr)
or else Expr_Known_Valid (Expr)
then
return;
-- Do not insert checks within a predicate function. This will arise
-- if the current unit and the predicate function are being compiled
-- with validity checks enabled.
elsif Present (Predicate_Function (Typ))
and then Current_Scope = Predicate_Function (Typ)
then
return;
-- If the expression is a packed component of a modular type of the
-- right size, the data is always valid.
elsif Nkind (Expr) = N_Selected_Component
and then Present (Component_Clause (Entity (Selector_Name (Expr))))
and then Is_Modular_Integer_Type (Typ)
and then Modulus (Typ) = 2 ** Esize (Entity (Selector_Name (Expr)))
then
return;
-- Do not generate a validity check when inside a generic unit as this
-- is an expansion activity.
elsif Inside_A_Generic then
return;
end if;
-- Entities declared in Lock_free protected types must be treated as
-- volatile, and we must inhibit validity checks to prevent improper
-- constant folding.
if Is_Entity_Name (Expr)
and then Is_Subprogram (Scope (Entity (Expr)))
and then Present (Protected_Subprogram (Scope (Entity (Expr))))
and then Uses_Lock_Free
(Scope (Protected_Subprogram (Scope (Entity (Expr)))))
then
return;
end if;
-- If we have a checked conversion, then validity check applies to
-- the expression inside the conversion, not the result, since if
-- the expression inside is valid, then so is the conversion result.
Exp := Expr;
while Nkind (Exp) = N_Type_Conversion loop
Exp := Expression (Exp);
end loop;
-- Do not generate a check for a variable which already validates the
-- value of an assignable object.
if Is_Validation_Variable_Reference (Exp) then
return;
end if;
declare
CE : Node_Id;
PV : Node_Id;
Var_Id : Entity_Id;
begin
-- If the expression denotes an assignable object, capture its value
-- in a variable and replace the original expression by the variable.
-- This approach has several effects:
-- 1) The evaluation of the object results in only one read in the
-- case where the object is atomic or volatile.
-- Var ... := Object; -- read
-- 2) The captured value is the one verified by attribute 'Valid.
-- As a result the object is not evaluated again, which would
-- result in an unwanted read in the case where the object is
-- atomic or volatile.
-- if not Var'Valid then -- OK, no read of Object
-- if not Object'Valid then -- Wrong, extra read of Object
-- 3) The captured value replaces the original object reference.
-- As a result the object is not evaluated again, in the same
-- vein as 2).
-- ... Var ... -- OK, no read of Object
-- ... Object ... -- Wrong, extra read of Object
-- 4) The use of a variable to capture the value of the object
-- allows the propagation of any changes back to the original
-- object.
-- procedure Call (Val : in out ...);
-- Var : ... := Object; -- read Object
-- if not Var'Valid then -- validity check
-- Call (Var); -- modify Var
-- Object := Var; -- update Object
if Is_Variable (Exp) then
Var_Id := Make_Temporary (Loc, 'T', Exp);
-- Because we could be dealing with a transient scope which would
-- cause our object declaration to remain unanalyzed we must do
-- some manual decoration.
Set_Ekind (Var_Id, E_Variable);
Set_Etype (Var_Id, Typ);
Insert_Action (Exp,
Make_Object_Declaration (Loc,
Defining_Identifier => Var_Id,
Object_Definition => New_Occurrence_Of (Typ, Loc),
Expression => New_Copy_Tree (Exp)),
Suppress => Validity_Check);
Set_Validated_Object (Var_Id, New_Copy_Tree (Exp));
Rewrite (Exp, New_Occurrence_Of (Var_Id, Loc));
-- Move the Do_Range_Check flag over to the new Exp so it doesn't
-- get lost and doesn't leak elsewhere.
if Do_Range_Check (Validated_Object (Var_Id)) then
Set_Do_Range_Check (Exp);
Set_Do_Range_Check (Validated_Object (Var_Id), False);
end if;
PV := New_Occurrence_Of (Var_Id, Loc);
-- Otherwise the expression does not denote a variable. Force its
-- evaluation by capturing its value in a constant. Generate:
-- Temp : constant ... := Exp;
else
Force_Evaluation
(Exp => Exp,
Related_Id => Related_Id,
Is_Low_Bound => Is_Low_Bound,
Is_High_Bound => Is_High_Bound);
PV := New_Copy_Tree (Exp);
end if;
-- A rather specialized test. If PV is an analyzed expression which
-- is an indexed component of a packed array that has not been
-- properly expanded, turn off its Analyzed flag to make sure it
-- gets properly reexpanded. If the prefix is an access value,
-- the dereference will be added later.
-- The reason this arises is that Duplicate_Subexpr_No_Checks did
-- an analyze with the old parent pointer. This may point e.g. to
-- a subprogram call, which deactivates this expansion.
if Analyzed (PV)
and then Nkind (PV) = N_Indexed_Component
and then Is_Array_Type (Etype (Prefix (PV)))
and then Present (Packed_Array_Impl_Type (Etype (Prefix (PV))))
then
Set_Analyzed (PV, False);
end if;
-- Build the raise CE node to check for validity. We build a type
-- qualification for the prefix, since it may not be of the form of
-- a name, and we don't care in this context!
CE :=
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Op_Not (Loc,
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => PV,
Attribute_Name => Name_Valid)),
Reason => CE_Invalid_Data);
-- Insert the validity check. Note that we do this with validity
-- checks turned off, to avoid recursion, we do not want validity
-- checks on the validity checking code itself.
Insert_Action (Expr, CE, Suppress => Validity_Check);
-- If the expression is a reference to an element of a bit-packed
-- array, then it is rewritten as a renaming declaration. If the
-- expression is an actual in a call, it has not been expanded,
-- waiting for the proper point at which to do it. The same happens
-- with renamings, so that we have to force the expansion now. This
-- non-local complication is due to code in exp_ch2,adb, exp_ch4.adb
-- and exp_ch6.adb.
if Is_Entity_Name (Exp)
and then Nkind (Parent (Entity (Exp))) =
N_Object_Renaming_Declaration
then
declare
Old_Exp : constant Node_Id := Name (Parent (Entity (Exp)));
begin
if Nkind (Old_Exp) = N_Indexed_Component
and then Is_Bit_Packed_Array (Etype (Prefix (Old_Exp)))
then
Expand_Packed_Element_Reference (Old_Exp);
end if;
end;
end if;
end;
end Insert_Valid_Check;
-------------------------------------
-- Is_Signed_Integer_Arithmetic_Op --
-------------------------------------
function Is_Signed_Integer_Arithmetic_Op (N : Node_Id) return Boolean is
begin
case Nkind (N) is
when N_Op_Abs
| N_Op_Add
| N_Op_Divide
| N_Op_Expon
| N_Op_Minus
| N_Op_Mod
| N_Op_Multiply
| N_Op_Plus
| N_Op_Rem
| N_Op_Subtract
=>
return Is_Signed_Integer_Type (Etype (N));
when N_Case_Expression
| N_If_Expression
=>
return Is_Signed_Integer_Type (Etype (N));
when others =>
return False;
end case;
end Is_Signed_Integer_Arithmetic_Op;
----------------------------------
-- Install_Null_Excluding_Check --
----------------------------------
procedure Install_Null_Excluding_Check (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (Parent (N));
Typ : constant Entity_Id := Etype (N);
function Safe_To_Capture_In_Parameter_Value return Boolean;
-- Determines if it is safe to capture Known_Non_Null status for an
-- the entity referenced by node N. The caller ensures that N is indeed
-- an entity name. It is safe to capture the non-null status for an IN
-- parameter when the reference occurs within a declaration that is sure
-- to be executed as part of the declarative region.
procedure Mark_Non_Null;
-- After installation of check, if the node in question is an entity
-- name, then mark this entity as non-null if possible.
function Safe_To_Capture_In_Parameter_Value return Boolean is
E : constant Entity_Id := Entity (N);
S : constant Entity_Id := Current_Scope;
S_Par : Node_Id;
begin
if Ekind (E) /= E_In_Parameter then
return False;
end if;
-- Two initial context checks. We must be inside a subprogram body
-- with declarations and reference must not appear in nested scopes.
if (Ekind (S) /= E_Function and then Ekind (S) /= E_Procedure)
or else Scope (E) /= S
then
return False;
end if;
S_Par := Parent (Parent (S));
if Nkind (S_Par) /= N_Subprogram_Body
or else No (Declarations (S_Par))
then
return False;
end if;
declare
N_Decl : Node_Id;
P : Node_Id;
begin
-- Retrieve the declaration node of N (if any). Note that N
-- may be a part of a complex initialization expression.
P := Parent (N);
N_Decl := Empty;
while Present (P) loop
-- If we have a short circuit form, and we are within the right
-- hand expression, we return false, since the right hand side
-- is not guaranteed to be elaborated.
if Nkind (P) in N_Short_Circuit
and then N = Right_Opnd (P)
then
return False;
end if;
-- Similarly, if we are in an if expression and not part of the
-- condition, then we return False, since neither the THEN or
-- ELSE dependent expressions will always be elaborated.
if Nkind (P) = N_If_Expression
and then N /= First (Expressions (P))
then
return False;
end if;
-- If within a case expression, and not part of the expression,
-- then return False, since a particular dependent expression
-- may not always be elaborated
if Nkind (P) = N_Case_Expression
and then N /= Expression (P)
then
return False;
end if;
-- While traversing the parent chain, if node N belongs to a
-- statement, then it may never appear in a declarative region.
if Nkind (P) in N_Statement_Other_Than_Procedure_Call
or else Nkind (P) = N_Procedure_Call_Statement
then
return False;
end if;
-- If we are at a declaration, record it and exit
if Nkind (P) in N_Declaration
and then Nkind (P) not in N_Subprogram_Specification
then
N_Decl := P;
exit;
end if;
P := Parent (P);
end loop;
if No (N_Decl) then
return False;
end if;
return List_Containing (N_Decl) = Declarations (S_Par);
end;
end Safe_To_Capture_In_Parameter_Value;
-------------------
-- Mark_Non_Null --
-------------------
procedure Mark_Non_Null is
begin
-- Only case of interest is if node N is an entity name
if Is_Entity_Name (N) then
-- For sure, we want to clear an indication that this is known to
-- be null, since if we get past this check, it definitely is not.
Set_Is_Known_Null (Entity (N), False);
-- We can mark the entity as known to be non-null if either it is
-- safe to capture the value, or in the case of an IN parameter,
-- which is a constant, if the check we just installed is in the
-- declarative region of the subprogram body. In this latter case,
-- a check is decisive for the rest of the body if the expression
-- is sure to be elaborated, since we know we have to elaborate
-- all declarations before executing the body.
-- Couldn't this always be part of Safe_To_Capture_Value ???
if Safe_To_Capture_Value (N, Entity (N))
or else Safe_To_Capture_In_Parameter_Value
then
Set_Is_Known_Non_Null (Entity (N));
end if;
end if;
end Mark_Non_Null;
-- Start of processing for Install_Null_Excluding_Check
begin
-- No need to add null-excluding checks when the tree may not be fully
-- decorated.
if Serious_Errors_Detected > 0 then
return;
end if;
pragma Assert (Is_Access_Type (Typ));
-- No check inside a generic, check will be emitted in instance
if Inside_A_Generic then
return;
end if;
-- No check needed if known to be non-null
if Known_Non_Null (N) then
return;
end if;
-- If known to be null, here is where we generate a compile time check
if Known_Null (N) then
-- Avoid generating warning message inside init procs. In SPARK mode
-- we can go ahead and call Apply_Compile_Time_Constraint_Error
-- since it will be turned into an error in any case.
if (not Inside_Init_Proc or else SPARK_Mode = On)
-- Do not emit the warning within a conditional expression,
-- where the expression might not be evaluated, and the warning
-- appear as extraneous noise.
and then not Within_Case_Or_If_Expression (N)
then
Apply_Compile_Time_Constraint_Error
(N, "null value not allowed here??", CE_Access_Check_Failed);
-- Remaining cases, where we silently insert the raise
else
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Reason => CE_Access_Check_Failed));
end if;
Mark_Non_Null;
return;
end if;
-- If entity is never assigned, for sure a warning is appropriate
if Is_Entity_Name (N) then
Check_Unset_Reference (N);
end if;
-- No check needed if checks are suppressed on the range. Note that we
-- don't set Is_Known_Non_Null in this case (we could legitimately do
-- so, since the program is erroneous, but we don't like to casually
-- propagate such conclusions from erroneosity).
if Access_Checks_Suppressed (Typ) then
return;
end if;
-- No check needed for access to concurrent record types generated by
-- the expander. This is not just an optimization (though it does indeed
-- remove junk checks). It also avoids generation of junk warnings.
if Nkind (N) in N_Has_Chars
and then Chars (N) = Name_uObject
and then Is_Concurrent_Record_Type
(Directly_Designated_Type (Etype (N)))
then
return;
end if;
-- No check needed in interface thunks since the runtime check is
-- already performed at the caller side.
if Is_Thunk (Current_Scope) then
return;
end if;
-- No check needed for the Get_Current_Excep.all.all idiom generated by
-- the expander within exception handlers, since we know that the value
-- can never be null.
-- Is this really the right way to do this? Normally we generate such
-- code in the expander with checks off, and that's how we suppress this
-- kind of junk check ???
if Nkind (N) = N_Function_Call
and then Nkind (Name (N)) = N_Explicit_Dereference
and then Nkind (Prefix (Name (N))) = N_Identifier
and then Is_RTE (Entity (Prefix (Name (N))), RE_Get_Current_Excep)
then
return;
end if;
-- In GNATprove mode, we do not apply the check
if GNATprove_Mode then
return;
end if;
-- Otherwise install access check
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd => Duplicate_Subexpr_Move_Checks (N),
Right_Opnd => Make_Null (Loc)),
Reason => CE_Access_Check_Failed));
Mark_Non_Null;
end Install_Null_Excluding_Check;
-----------------------------------------
-- Install_Primitive_Elaboration_Check --
-----------------------------------------
procedure Install_Primitive_Elaboration_Check (Subp_Body : Node_Id) is
function Within_Compilation_Unit_Instance
(Subp_Id : Entity_Id) return Boolean;
-- Determine whether subprogram Subp_Id appears within an instance which
-- acts as a compilation unit.
--------------------------------------
-- Within_Compilation_Unit_Instance --
--------------------------------------
function Within_Compilation_Unit_Instance
(Subp_Id : Entity_Id) return Boolean
is
Pack : Entity_Id;
begin
-- Examine the scope chain looking for a compilation-unit-level
-- instance.
Pack := Scope (Subp_Id);
while Present (Pack) and then Pack /= Standard_Standard loop
if Ekind (Pack) = E_Package
and then Is_Generic_Instance (Pack)
and then Nkind (Parent (Unit_Declaration_Node (Pack))) =
N_Compilation_Unit
then
return True;
end if;
Pack := Scope (Pack);
end loop;
return False;
end Within_Compilation_Unit_Instance;
-- Local declarations
Context : constant Node_Id := Parent (Subp_Body);
Loc : constant Source_Ptr := Sloc (Subp_Body);
Subp_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Body);
Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
Decls : List_Id;
Flag_Id : Entity_Id;
Set_Ins : Node_Id;
Set_Stmt : Node_Id;
Tag_Typ : Entity_Id;
-- Start of processing for Install_Primitive_Elaboration_Check
begin
-- Do not generate an elaboration check in compilation modes where
-- expansion is not desirable.
if GNATprove_Mode then
return;
-- Do not generate an elaboration check if all checks have been
-- suppressed.
elsif Suppress_Checks then
return;
-- Do not generate an elaboration check if the related subprogram is
-- not subjected to accessibility checks.
elsif Elaboration_Checks_Suppressed (Subp_Id) then
return;
-- Do not generate an elaboration check if such code is not desirable
elsif Restriction_Active (No_Elaboration_Code) then
return;
-- Do not generate an elaboration check if exceptions cannot be used,
-- caught, or propagated.
elsif not Exceptions_OK then
return;
-- Do not consider subprograms which act as compilation units, because
-- they cannot be the target of a dispatching call.
elsif Nkind (Context) = N_Compilation_Unit then
return;
-- Do not consider anything other than nonabstract library-level source
-- primitives.
elsif not
(Comes_From_Source (Subp_Id)
and then Is_Library_Level_Entity (Subp_Id)
and then Is_Primitive (Subp_Id)
and then not Is_Abstract_Subprogram (Subp_Id))
then
return;
-- Do not consider inlined primitives, because once the body is inlined
-- the reference to the elaboration flag will be out of place and will
-- result in an undefined symbol.
elsif Is_Inlined (Subp_Id) or else Has_Pragma_Inline (Subp_Id) then
return;
-- Do not generate a duplicate elaboration check. This happens only in
-- the case of primitives completed by an expression function, as the
-- corresponding body is apparently analyzed and expanded twice.
elsif Analyzed (Subp_Body) then
return;
-- Do not consider primitives which occur within an instance that acts
-- as a compilation unit. Such an instance defines its spec and body out
-- of order (body is first) within the tree, which causes the reference
-- to the elaboration flag to appear as an undefined symbol.
elsif Within_Compilation_Unit_Instance (Subp_Id) then
return;
end if;
Tag_Typ := Find_Dispatching_Type (Subp_Id);
-- Only tagged primitives may be the target of a dispatching call
if No (Tag_Typ) then
return;
-- Do not consider finalization-related primitives, because they may
-- need to be called while elaboration is taking place.
elsif Is_Controlled (Tag_Typ)
and then
Chars (Subp_Id) in Name_Adjust | Name_Finalize | Name_Initialize
then
return;
end if;
-- Create the declaration of the elaboration flag. The name carries a
-- unique counter in case of name overloading.
Flag_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Subp_Id), 'E', -1));
Set_Is_Frozen (Flag_Id);
-- Insert the declaration of the elaboration flag in front of the
-- primitive spec and analyze it in the proper context.
Push_Scope (Scope (Subp_Id));
-- Generate:
-- E : Boolean := False;
Insert_Action (Subp_Decl,
Make_Object_Declaration (Loc,
Defining_Identifier => Flag_Id,
Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
Expression => New_Occurrence_Of (Standard_False, Loc)));
Pop_Scope;
-- Prevent the compiler from optimizing the elaboration check by killing
-- the current value of the flag and the associated assignment.
Set_Current_Value (Flag_Id, Empty);
Set_Last_Assignment (Flag_Id, Empty);
-- Add a check at the top of the body declarations to ensure that the
-- elaboration flag has been set.
Decls := Declarations (Subp_Body);
if No (Decls) then
Decls := New_List;
Set_Declarations (Subp_Body, Decls);
end if;
-- Generate:
-- if not F then
-- raise Program_Error with "access before elaboration";
-- end if;
Prepend_To (Decls,
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Not (Loc,
Right_Opnd => New_Occurrence_Of (Flag_Id, Loc)),
Reason => PE_Access_Before_Elaboration));
Analyze (First (Decls));
-- Set the elaboration flag once the body has been elaborated. Insert
-- the statement after the subprogram stub when the primitive body is
-- a subunit.
if Nkind (Context) = N_Subunit then
Set_Ins := Corresponding_Stub (Context);
else
Set_Ins := Subp_Body;
end if;
-- Generate:
-- E := True;
Set_Stmt :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Flag_Id, Loc),
Expression => New_Occurrence_Of (Standard_True, Loc));
-- Mark the assignment statement as elaboration code. This allows the
-- early call region mechanism (see Sem_Elab) to properly ignore such
-- assignments even though they are non-preelaborable code.
Set_Is_Elaboration_Code (Set_Stmt);
Insert_After_And_Analyze (Set_Ins, Set_Stmt);
end Install_Primitive_Elaboration_Check;
--------------------------
-- Install_Static_Check --
--------------------------
procedure Install_Static_Check (R_Cno : Node_Id; Loc : Source_Ptr) is
Stat : constant Boolean := Is_OK_Static_Expression (R_Cno);
Typ : constant Entity_Id := Etype (R_Cno);
begin
Rewrite (R_Cno,
Make_Raise_Constraint_Error (Loc,
Reason => CE_Range_Check_Failed));
Set_Analyzed (R_Cno);
Set_Etype (R_Cno, Typ);
Set_Raises_Constraint_Error (R_Cno);
Set_Is_Static_Expression (R_Cno, Stat);
-- Now deal with possible local raise handling
Possible_Local_Raise (R_Cno, Standard_Constraint_Error);
end Install_Static_Check;
-------------------------
-- Is_Check_Suppressed --
-------------------------
function Is_Check_Suppressed (E : Entity_Id; C : Check_Id) return Boolean is
Ptr : Suppress_Stack_Entry_Ptr;
begin
-- First search the local entity suppress stack. We search this from the
-- top of the stack down so that we get the innermost entry that applies
-- to this case if there are nested entries.
Ptr := Local_Suppress_Stack_Top;
while Ptr /= null loop
if (Ptr.Entity = Empty or else Ptr.Entity = E)
and then (Ptr.Check = All_Checks or else Ptr.Check = C)
then
return Ptr.Suppress;
end if;
Ptr := Ptr.Prev;
end loop;
-- Now search the global entity suppress table for a matching entry.
-- We also search this from the top down so that if there are multiple
-- pragmas for the same entity, the last one applies (not clear what
-- or whether the RM specifies this handling, but it seems reasonable).
Ptr := Global_Suppress_Stack_Top;
while Ptr /= null loop
if (Ptr.Entity = Empty or else Ptr.Entity = E)
and then (Ptr.Check = All_Checks or else Ptr.Check = C)
then
return Ptr.Suppress;
end if;
Ptr := Ptr.Prev;
end loop;
-- If we did not find a matching entry, then use the normal scope
-- suppress value after all (actually this will be the global setting
-- since it clearly was not overridden at any point). For a predefined
-- check, we test the specific flag. For a user defined check, we check
-- the All_Checks flag. The Overflow flag requires special handling to
-- deal with the General vs Assertion case.
if C = Overflow_Check then
return Overflow_Checks_Suppressed (Empty);
elsif C in Predefined_Check_Id then
return Scope_Suppress.Suppress (C);
else
return Scope_Suppress.Suppress (All_Checks);
end if;
end Is_Check_Suppressed;
---------------------
-- Kill_All_Checks --
---------------------
procedure Kill_All_Checks is
begin
if Debug_Flag_CC then
w ("Kill_All_Checks");
end if;
-- We reset the number of saved checks to zero, and also modify all
-- stack entries for statement ranges to indicate that the number of
-- checks at each level is now zero.
Num_Saved_Checks := 0;
-- Note: the Int'Min here avoids any possibility of J being out of
-- range when called from e.g. Conditional_Statements_Begin.
for J in 1 .. Int'Min (Saved_Checks_TOS, Saved_Checks_Stack'Last) loop
Saved_Checks_Stack (J) := 0;
end loop;
end Kill_All_Checks;
-----------------
-- Kill_Checks --
-----------------
procedure Kill_Checks (V : Entity_Id) is
begin
if Debug_Flag_CC then
w ("Kill_Checks for entity", Int (V));
end if;
for J in 1 .. Num_Saved_Checks loop
if Saved_Checks (J).Entity = V then
if Debug_Flag_CC then
w (" Checks killed for saved check ", J);
end if;
Saved_Checks (J).Killed := True;
end if;
end loop;
end Kill_Checks;
------------------------------
-- Length_Checks_Suppressed --
------------------------------
function Length_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Length_Check);
else
return Scope_Suppress.Suppress (Length_Check);
end if;
end Length_Checks_Suppressed;
-----------------------
-- Make_Bignum_Block --
-----------------------
function Make_Bignum_Block (Loc : Source_Ptr) return Node_Id is
M : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uM);
begin
return
Make_Block_Statement (Loc,
Declarations =>
New_List (Build_SS_Mark_Call (Loc, M)),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Build_SS_Release_Call (Loc, M))));
end Make_Bignum_Block;
----------------------------------
-- Minimize_Eliminate_Overflows --
----------------------------------
-- This is a recursive routine that is called at the top of an expression
-- tree to properly process overflow checking for a whole subtree by making
-- recursive calls to process operands. This processing may involve the use
-- of bignum or long long integer arithmetic, which will change the types
-- of operands and results. That's why we can't do this bottom up (since
-- it would interfere with semantic analysis).
-- What happens is that if MINIMIZED/ELIMINATED mode is in effect then
-- the operator expansion routines, as well as the expansion routines for
-- if/case expression, do nothing (for the moment) except call the routine
-- to apply the overflow check (Apply_Arithmetic_Overflow_Check). That
-- routine does nothing for non top-level nodes, so at the point where the
-- call is made for the top level node, the entire expression subtree has
-- not been expanded, or processed for overflow. All that has to happen as
-- a result of the top level call to this routine.
-- As noted above, the overflow processing works by making recursive calls
-- for the operands, and figuring out what to do, based on the processing
-- of these operands (e.g. if a bignum operand appears, the parent op has
-- to be done in bignum mode), and the determined ranges of the operands.
-- After possible rewriting of a constituent subexpression node, a call is
-- made to either reexpand the node (if nothing has changed) or reanalyze
-- the node (if it has been modified by the overflow check processing). The
-- Analyzed_Flag is set to False before the reexpand/reanalyze. To avoid
-- a recursive call into the whole overflow apparatus, an important rule
-- for this call is that the overflow handling mode must be temporarily set
-- to STRICT.
procedure Minimize_Eliminate_Overflows
(N : Node_Id;
Lo : out Uint;
Hi : out Uint;
Top_Level : Boolean)
is
Rtyp : constant Entity_Id := Etype (N);
pragma Assert (Is_Signed_Integer_Type (Rtyp));
-- Result type, must be a signed integer type
Check_Mode : constant Overflow_Mode_Type := Overflow_Check_Mode;
pragma Assert (Check_Mode in Minimized_Or_Eliminated);
Loc : constant Source_Ptr := Sloc (N);
Rlo, Rhi : Uint;
-- Ranges of values for right operand (operator case)
Llo : Uint := No_Uint; -- initialize to prevent warning
Lhi : Uint := No_Uint; -- initialize to prevent warning
-- Ranges of values for left operand (operator case)
LLIB : constant Entity_Id := Base_Type (Standard_Long_Long_Integer);
-- Operands and results are of this type when we convert
LLLo : constant Uint := Intval (Type_Low_Bound (LLIB));
LLHi : constant Uint := Intval (Type_High_Bound (LLIB));
-- Bounds of Long_Long_Integer
Binary : constant Boolean := Nkind (N) in N_Binary_Op;
-- Indicates binary operator case
OK : Boolean;
-- Used in call to Determine_Range
Bignum_Operands : Boolean;
-- Set True if one or more operands is already of type Bignum, meaning
-- that for sure (regardless of Top_Level setting) we are committed to
-- doing the operation in Bignum mode (or in the case of a case or if
-- expression, converting all the dependent expressions to Bignum).
Long_Long_Integer_Operands : Boolean;
-- Set True if one or more operands is already of type Long_Long_Integer
-- which means that if the result is known to be in the result type
-- range, then we must convert such operands back to the result type.
procedure Reanalyze (Typ : Entity_Id; Suppress : Boolean := False);
-- This is called when we have modified the node and we therefore need
-- to reanalyze it. It is important that we reset the mode to STRICT for
-- this reanalysis, since if we leave it in MINIMIZED or ELIMINATED mode
-- we would reenter this routine recursively which would not be good.
-- The argument Suppress is set True if we also want to suppress
-- overflow checking for the reexpansion (this is set when we know
-- overflow is not possible). Typ is the type for the reanalysis.
procedure Reexpand (Suppress : Boolean := False);
-- This is like Reanalyze, but does not do the Analyze step, it only
-- does a reexpansion. We do this reexpansion in STRICT mode, so that
-- instead of reentering the MINIMIZED/ELIMINATED mode processing, we
-- follow the normal expansion path (e.g. converting A**4 to A**2**2).
-- Note that skipping reanalysis is not just an optimization, testing
-- has showed up several complex cases in which reanalyzing an already
-- analyzed node causes incorrect behavior.
function In_Result_Range return Boolean;
-- Returns True iff Lo .. Hi are within range of the result type
procedure Max (A : in out Uint; B : Uint);
-- If A is No_Uint, sets A to B, else to UI_Max (A, B)
procedure Min (A : in out Uint; B : Uint);
-- If A is No_Uint, sets A to B, else to UI_Min (A, B)
---------------------
-- In_Result_Range --
---------------------
function In_Result_Range return Boolean is
begin
if Lo = No_Uint or else Hi = No_Uint then
return False;
elsif Is_OK_Static_Subtype (Etype (N)) then
return Lo >= Expr_Value (Type_Low_Bound (Rtyp))
and then
Hi <= Expr_Value (Type_High_Bound (Rtyp));
else
return Lo >= Expr_Value (Type_Low_Bound (Base_Type (Rtyp)))
and then
Hi <= Expr_Value (Type_High_Bound (Base_Type (Rtyp)));
end if;
end In_Result_Range;
---------
-- Max --
---------
procedure Max (A : in out Uint; B : Uint) is
begin
if A = No_Uint or else B > A then
A := B;
end if;
end Max;
---------
-- Min --
---------
procedure Min (A : in out Uint; B : Uint) is
begin
if A = No_Uint or else B < A then
A := B;
end if;
end Min;
---------------
-- Reanalyze --
---------------
procedure Reanalyze (Typ : Entity_Id; Suppress : Boolean := False) is
Svg : constant Overflow_Mode_Type :=
Scope_Suppress.Overflow_Mode_General;
Sva : constant Overflow_Mode_Type :=
Scope_Suppress.Overflow_Mode_Assertions;
Svo : constant Boolean :=
Scope_Suppress.Suppress (Overflow_Check);
begin
Scope_Suppress.Overflow_Mode_General := Strict;
Scope_Suppress.Overflow_Mode_Assertions := Strict;
if Suppress then
Scope_Suppress.Suppress (Overflow_Check) := True;
end if;
Analyze_And_Resolve (N, Typ);
Scope_Suppress.Suppress (Overflow_Check) := Svo;
Scope_Suppress.Overflow_Mode_General := Svg;
Scope_Suppress.Overflow_Mode_Assertions := Sva;
end Reanalyze;
--------------
-- Reexpand --
--------------
procedure Reexpand (Suppress : Boolean := False) is
Svg : constant Overflow_Mode_Type :=
Scope_Suppress.Overflow_Mode_General;
Sva : constant Overflow_Mode_Type :=
Scope_Suppress.Overflow_Mode_Assertions;
Svo : constant Boolean :=
Scope_Suppress.Suppress (Overflow_Check);
begin
Scope_Suppress.Overflow_Mode_General := Strict;
Scope_Suppress.Overflow_Mode_Assertions := Strict;
Set_Analyzed (N, False);
if Suppress then
Scope_Suppress.Suppress (Overflow_Check) := True;
end if;
Expand (N);
Scope_Suppress.Suppress (Overflow_Check) := Svo;
Scope_Suppress.Overflow_Mode_General := Svg;
Scope_Suppress.Overflow_Mode_Assertions := Sva;
end Reexpand;
-- Start of processing for Minimize_Eliminate_Overflows
begin
-- Default initialize Lo and Hi since these are not guaranteed to be
-- set otherwise.
Lo := No_Uint;
Hi := No_Uint;
-- Case where we do not have a signed integer arithmetic operation
if not Is_Signed_Integer_Arithmetic_Op (N) then
-- Use the normal Determine_Range routine to get the range. We
-- don't require operands to be valid, invalid values may result in
-- rubbish results where the result has not been properly checked for
-- overflow, that's fine.
Determine_Range (N, OK, Lo, Hi, Assume_Valid => False);
-- If Determine_Range did not work (can this in fact happen? Not
-- clear but might as well protect), use type bounds.
if not OK then
Lo := Intval (Type_Low_Bound (Base_Type (Etype (N))));
Hi := Intval (Type_High_Bound (Base_Type (Etype (N))));
end if;
-- If we don't have a binary operator, all we have to do is to set
-- the Hi/Lo range, so we are done.
return;
-- Processing for if expression
elsif Nkind (N) = N_If_Expression then
declare
Then_DE : constant Node_Id := Next (First (Expressions (N)));
Else_DE : constant Node_Id := Next (Then_DE);
begin
Bignum_Operands := False;
Minimize_Eliminate_Overflows
(Then_DE, Lo, Hi, Top_Level => False);
if Lo = No_Uint then
Bignum_Operands := True;
end if;
Minimize_Eliminate_Overflows
(Else_DE, Rlo, Rhi, Top_Level => False);
if Rlo = No_Uint then
Bignum_Operands := True;
else
Long_Long_Integer_Operands :=
Etype (Then_DE) = LLIB or else Etype (Else_DE) = LLIB;
Min (Lo, Rlo);
Max (Hi, Rhi);
end if;
-- If at least one of our operands is now Bignum, we must rebuild
-- the if expression to use Bignum operands. We will analyze the
-- rebuilt if expression with overflow checks off, since once we
-- are in bignum mode, we are all done with overflow checks.
if Bignum_Operands then
Rewrite (N,
Make_If_Expression (Loc,
Expressions => New_List (
Remove_Head (Expressions (N)),
Convert_To_Bignum (Then_DE),
Convert_To_Bignum (Else_DE)),
Is_Elsif => Is_Elsif (N)));
Reanalyze (RTE (RE_Bignum), Suppress => True);
-- If we have no Long_Long_Integer operands, then we are in result
-- range, since it means that none of our operands felt the need
-- to worry about overflow (otherwise it would have already been
-- converted to long long integer or bignum). We reexpand to
-- complete the expansion of the if expression (but we do not
-- need to reanalyze).
elsif not Long_Long_Integer_Operands then
Set_Do_Overflow_Check (N, False);
Reexpand;
-- Otherwise convert us to long long integer mode. Note that we
-- don't need any further overflow checking at this level.
else
Convert_To_And_Rewrite (LLIB, Then_DE);
Convert_To_And_Rewrite (LLIB, Else_DE);
Set_Etype (N, LLIB);
-- Now reanalyze with overflow checks off
Set_Do_Overflow_Check (N, False);
Reanalyze (LLIB, Suppress => True);
end if;
end;
return;
-- Here for case expression
elsif Nkind (N) = N_Case_Expression then
Bignum_Operands := False;
Long_Long_Integer_Operands := False;
declare
Alt : Node_Id;
begin
-- Loop through expressions applying recursive call
Alt := First (Alternatives (N));
while Present (Alt) loop
declare
Aexp : constant Node_Id := Expression (Alt);
begin
Minimize_Eliminate_Overflows
(Aexp, Lo, Hi, Top_Level => False);
if Lo = No_Uint then
Bignum_Operands := True;
elsif Etype (Aexp) = LLIB then
Long_Long_Integer_Operands := True;
end if;
end;
Next (Alt);
end loop;
-- If we have no bignum or long long integer operands, it means
-- that none of our dependent expressions could raise overflow.
-- In this case, we simply return with no changes except for
-- resetting the overflow flag, since we are done with overflow
-- checks for this node. We will reexpand to get the needed
-- expansion for the case expression, but we do not need to
-- reanalyze, since nothing has changed.
if not (Bignum_Operands or Long_Long_Integer_Operands) then
Set_Do_Overflow_Check (N, False);
Reexpand (Suppress => True);
-- Otherwise we are going to rebuild the case expression using
-- either bignum or long long integer operands throughout.
else
declare
Rtype : Entity_Id := Empty;
New_Alts : List_Id;
New_Exp : Node_Id;
begin
New_Alts := New_List;
Alt := First (Alternatives (N));
while Present (Alt) loop
if Bignum_Operands then
New_Exp := Convert_To_Bignum (Expression (Alt));
Rtype := RTE (RE_Bignum);
else
New_Exp := Convert_To (LLIB, Expression (Alt));
Rtype := LLIB;
end if;
Append_To (New_Alts,
Make_Case_Expression_Alternative (Sloc (Alt),
Actions => No_List,
Discrete_Choices => Discrete_Choices (Alt),
Expression => New_Exp));
Next (Alt);
end loop;
Rewrite (N,
Make_Case_Expression (Loc,
Expression => Expression (N),
Alternatives => New_Alts));
pragma Assert (Present (Rtype));
Reanalyze (Rtype, Suppress => True);
end;
end if;
end;
return;
end if;
-- If we have an arithmetic operator we make recursive calls on the
-- operands to get the ranges (and to properly process the subtree
-- that lies below us).
Minimize_Eliminate_Overflows
(Right_Opnd (N), Rlo, Rhi, Top_Level => False);
if Binary then
Minimize_Eliminate_Overflows
(Left_Opnd (N), Llo, Lhi, Top_Level => False);
end if;
-- Record if we have Long_Long_Integer operands
Long_Long_Integer_Operands :=
Etype (Right_Opnd (N)) = LLIB
or else (Binary and then Etype (Left_Opnd (N)) = LLIB);
-- If either operand is a bignum, then result will be a bignum and we
-- don't need to do any range analysis. As previously discussed we could
-- do range analysis in such cases, but it could mean working with giant
-- numbers at compile time for very little gain (the number of cases
-- in which we could slip back from bignum mode is small).
if Rlo = No_Uint or else (Binary and then Llo = No_Uint) then
Lo := No_Uint;
Hi := No_Uint;
Bignum_Operands := True;
-- Otherwise compute result range
else
Compute_Range_For_Arithmetic_Op
(Nkind (N), Llo, Lhi, Rlo, Rhi, OK, Lo, Hi);
Bignum_Operands := False;
end if;
-- Here for the case where we have not rewritten anything (no bignum
-- operands or long long integer operands), and we know the result.
-- If we know we are in the result range, and we do not have Bignum
-- operands or Long_Long_Integer operands, we can just reexpand with
-- overflow checks turned off (since we know we cannot have overflow).
-- As always the reexpansion is required to complete expansion of the
-- operator, but we do not need to reanalyze, and we prevent recursion
-- by suppressing the check.
if not (Bignum_Operands or Long_Long_Integer_Operands)
and then In_Result_Range
then
Set_Do_Overflow_Check (N, False);
Reexpand (Suppress => True);
return;
-- Here we know that we are not in the result range, and in the general
-- case we will move into either the Bignum or Long_Long_Integer domain
-- to compute the result. However, there is one exception. If we are
-- at the top level, and we do not have Bignum or Long_Long_Integer
-- operands, we will have to immediately convert the result back to
-- the result type, so there is no point in Bignum/Long_Long_Integer
-- fiddling.
elsif Top_Level
and then not (Bignum_Operands or Long_Long_Integer_Operands)
-- One further refinement. If we are at the top level, but our parent
-- is a type conversion, then go into bignum or long long integer node
-- since the result will be converted to that type directly without
-- going through the result type, and we may avoid an overflow. This
-- is the case for example of Long_Long_Integer (A ** 4), where A is
-- of type Integer, and the result A ** 4 fits in Long_Long_Integer
-- but does not fit in Integer.
and then Nkind (Parent (N)) /= N_Type_Conversion
then
-- Here keep original types, but we need to complete analysis
-- One subtlety. We can't just go ahead and do an analyze operation
-- here because it will cause recursion into the whole MINIMIZED/
-- ELIMINATED overflow processing which is not what we want. Here
-- we are at the top level, and we need a check against the result
-- mode (i.e. we want to use STRICT mode). So do exactly that.
-- Also, we have not modified the node, so this is a case where
-- we need to reexpand, but not reanalyze.
Reexpand;
return;
-- Cases where we do the operation in Bignum mode. This happens either
-- because one of our operands is in Bignum mode already, or because
-- the computed bounds are outside the bounds of Long_Long_Integer,
-- which in some cases can be indicated by Hi and Lo being No_Uint.
-- Note: we could do better here and in some cases switch back from
-- Bignum mode to normal mode, e.g. big mod 2 must be in the range
-- 0 .. 1, but the cases are rare and it is not worth the effort.
-- Failing to do this switching back is only an efficiency issue.
elsif Lo = No_Uint or else Lo < LLLo or else Hi > LLHi then
-- OK, we are definitely outside the range of Long_Long_Integer. The
-- question is whether to move to Bignum mode, or stay in the domain
-- of Long_Long_Integer, signalling that an overflow check is needed.
-- Obviously in MINIMIZED mode we stay with LLI, since we are not in
-- the Bignum business. In ELIMINATED mode, we will normally move
-- into Bignum mode, but there is an exception if neither of our
-- operands is Bignum now, and we are at the top level (Top_Level
-- set True). In this case, there is no point in moving into Bignum
-- mode to prevent overflow if the caller will immediately convert
-- the Bignum value back to LLI with an overflow check. It's more
-- efficient to stay in LLI mode with an overflow check (if needed)
if Check_Mode = Minimized
or else (Top_Level and not Bignum_Operands)
then
if Do_Overflow_Check (N) then
Enable_Overflow_Check (N);
end if;
-- The result now has to be in Long_Long_Integer mode, so adjust
-- the possible range to reflect this. Note these calls also
-- change No_Uint values from the top level case to LLI bounds.
Max (Lo, LLLo);
Min (Hi, LLHi);
-- Otherwise we are in ELIMINATED mode and we switch to Bignum mode
else
pragma Assert (Check_Mode = Eliminated);
declare
Fent : Entity_Id;
Args : List_Id;
begin
case Nkind (N) is
when N_Op_Abs =>
Fent := RTE (RE_Big_Abs);
when N_Op_Add =>
Fent := RTE (RE_Big_Add);
when N_Op_Divide =>
Fent := RTE (RE_Big_Div);
when N_Op_Expon =>
Fent := RTE (RE_Big_Exp);
when N_Op_Minus =>
Fent := RTE (RE_Big_Neg);
when N_Op_Mod =>
Fent := RTE (RE_Big_Mod);
when N_Op_Multiply =>
Fent := RTE (RE_Big_Mul);
when N_Op_Rem =>
Fent := RTE (RE_Big_Rem);
when N_Op_Subtract =>
Fent := RTE (RE_Big_Sub);
-- Anything else is an internal error, this includes the
-- N_Op_Plus case, since how can plus cause the result
-- to be out of range if the operand is in range?
when others =>
raise Program_Error;
end case;
-- Construct argument list for Bignum call, converting our
-- operands to Bignum form if they are not already there.
Args := New_List;
if Binary then
Append_To (Args, Convert_To_Bignum (Left_Opnd (N)));
end if;
Append_To (Args, Convert_To_Bignum (Right_Opnd (N)));
-- Now rewrite the arithmetic operator with a call to the
-- corresponding bignum function.
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Fent, Loc),
Parameter_Associations => Args));
Reanalyze (RTE (RE_Bignum), Suppress => True);
-- Indicate result is Bignum mode
Lo := No_Uint;
Hi := No_Uint;
return;
end;
end if;
-- Otherwise we are in range of Long_Long_Integer, so no overflow
-- check is required, at least not yet.
else
Set_Do_Overflow_Check (N, False);
end if;
-- Here we are not in Bignum territory, but we may have long long
-- integer operands that need special handling. First a special check:
-- If an exponentiation operator exponent is of type Long_Long_Integer,
-- it means we converted it to prevent overflow, but exponentiation
-- requires a Natural right operand, so convert it back to Natural.
-- This conversion may raise an exception which is fine.
if Nkind (N) = N_Op_Expon and then Etype (Right_Opnd (N)) = LLIB then
Convert_To_And_Rewrite (Standard_Natural, Right_Opnd (N));
end if;
-- Here we will do the operation in Long_Long_Integer. We do this even
-- if we know an overflow check is required, better to do this in long
-- long integer mode, since we are less likely to overflow.
-- Convert right or only operand to Long_Long_Integer, except that
-- we do not touch the exponentiation right operand.
if Nkind (N) /= N_Op_Expon then
Convert_To_And_Rewrite (LLIB, Right_Opnd (N));
end if;
-- Convert left operand to Long_Long_Integer for binary case
if Binary then
Convert_To_And_Rewrite (LLIB, Left_Opnd (N));
end if;
-- Reset node to unanalyzed
Set_Analyzed (N, False);
Set_Etype (N, Empty);
Set_Entity (N, Empty);
-- Now analyze this new node. This reanalysis will complete processing
-- for the node. In particular we will complete the expansion of an
-- exponentiation operator (e.g. changing A ** 2 to A * A), and also
-- we will complete any division checks (since we have not changed the
-- setting of the Do_Division_Check flag).
-- We do this reanalysis in STRICT mode to avoid recursion into the
-- MINIMIZED/ELIMINATED handling, since we are now done with that.
declare
SG : constant Overflow_Mode_Type :=
Scope_Suppress.Overflow_Mode_General;
SA : constant Overflow_Mode_Type :=
Scope_Suppress.Overflow_Mode_Assertions;
begin
Scope_Suppress.Overflow_Mode_General := Strict;
Scope_Suppress.Overflow_Mode_Assertions := Strict;
if not Do_Overflow_Check (N) then
Reanalyze (LLIB, Suppress => True);
else
Reanalyze (LLIB);
end if;
Scope_Suppress.Overflow_Mode_General := SG;
Scope_Suppress.Overflow_Mode_Assertions := SA;
end;
end Minimize_Eliminate_Overflows;
-------------------------
-- Overflow_Check_Mode --
-------------------------
function Overflow_Check_Mode return Overflow_Mode_Type is
begin
if In_Assertion_Expr = 0 then
return Scope_Suppress.Overflow_Mode_General;
else
return Scope_Suppress.Overflow_Mode_Assertions;
end if;
end Overflow_Check_Mode;
--------------------------------
-- Overflow_Checks_Suppressed --
--------------------------------
function Overflow_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Overflow_Check);
else
return Scope_Suppress.Suppress (Overflow_Check);
end if;
end Overflow_Checks_Suppressed;
---------------------------------
-- Predicate_Checks_Suppressed --
---------------------------------
function Predicate_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Predicate_Check);
else
return Scope_Suppress.Suppress (Predicate_Check);
end if;
end Predicate_Checks_Suppressed;
-----------------------------
-- Range_Checks_Suppressed --
-----------------------------
function Range_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) then
if Kill_Range_Checks (E) then
return True;
elsif Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Range_Check);
end if;
end if;
return Scope_Suppress.Suppress (Range_Check);
end Range_Checks_Suppressed;
-----------------------------------------
-- Range_Or_Validity_Checks_Suppressed --
-----------------------------------------
-- Note: the coding would be simpler here if we simply made appropriate
-- calls to Range/Validity_Checks_Suppressed, but that would result in
-- duplicated checks which we prefer to avoid.
function Range_Or_Validity_Checks_Suppressed
(Expr : Node_Id) return Boolean
is
begin
-- Immediate return if scope checks suppressed for either check
if Scope_Suppress.Suppress (Range_Check)
or
Scope_Suppress.Suppress (Validity_Check)
then
return True;
end if;
-- If no expression, that's odd, decide that checks are suppressed,
-- since we don't want anyone trying to do checks in this case, which
-- is most likely the result of some other error.
if No (Expr) then
return True;
end if;
-- Expression is present, so perform suppress checks on type
declare
Typ : constant Entity_Id := Etype (Expr);
begin
if Checks_May_Be_Suppressed (Typ)
and then (Is_Check_Suppressed (Typ, Range_Check)
or else
Is_Check_Suppressed (Typ, Validity_Check))
then
return True;
end if;
end;
-- If expression is an entity name, perform checks on this entity
if Is_Entity_Name (Expr) then
declare
Ent : constant Entity_Id := Entity (Expr);
begin
if Checks_May_Be_Suppressed (Ent) then
return Is_Check_Suppressed (Ent, Range_Check)
or else Is_Check_Suppressed (Ent, Validity_Check);
end if;
end;
end if;
-- If we fall through, no checks suppressed
return False;
end Range_Or_Validity_Checks_Suppressed;
-------------------
-- Remove_Checks --
-------------------
procedure Remove_Checks (Expr : Node_Id) is
function Process (N : Node_Id) return Traverse_Result;
-- Process a single node during the traversal
procedure Traverse is new Traverse_Proc (Process);
-- The traversal procedure itself
-------------
-- Process --
-------------
function Process (N : Node_Id) return Traverse_Result is
begin
if Nkind (N) not in N_Subexpr then
return Skip;
end if;
Set_Do_Range_Check (N, False);
case Nkind (N) is
when N_And_Then =>
Traverse (Left_Opnd (N));
return Skip;
when N_Attribute_Reference =>
Set_Do_Overflow_Check (N, False);
when N_Function_Call =>
Set_Do_Tag_Check (N, False);
when N_Op =>
Set_Do_Overflow_Check (N, False);
case Nkind (N) is
when N_Op_Divide =>
Set_Do_Division_Check (N, False);
when N_Op_And =>
Set_Do_Length_Check (N, False);
when N_Op_Mod =>
Set_Do_Division_Check (N, False);
when N_Op_Or =>
Set_Do_Length_Check (N, False);
when N_Op_Rem =>
Set_Do_Division_Check (N, False);
when N_Op_Xor =>
Set_Do_Length_Check (N, False);
when others =>
null;
end case;
when N_Or_Else =>
Traverse (Left_Opnd (N));
return Skip;
when N_Selected_Component =>
Set_Do_Discriminant_Check (N, False);
when N_Type_Conversion =>
Set_Do_Length_Check (N, False);
Set_Do_Tag_Check (N, False);
Set_Do_Overflow_Check (N, False);
when others =>
null;
end case;
return OK;
end Process;
-- Start of processing for Remove_Checks
begin
Traverse (Expr);
end Remove_Checks;
----------------------------
-- Selected_Length_Checks --
----------------------------
function Selected_Length_Checks
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id;
Warn_Node : Node_Id) return Check_Result
is
Loc : constant Source_Ptr := Sloc (Expr);
S_Typ : Entity_Id;
T_Typ : Entity_Id;
Expr_Actual : Node_Id;
Exptyp : Entity_Id;
Cond : Node_Id := Empty;
Do_Access : Boolean := False;
Wnode : Node_Id := Warn_Node;
Ret_Result : Check_Result := (Empty, Empty);
Num_Checks : Natural := 0;
procedure Add_Check (N : Node_Id);
-- Adds the action given to Ret_Result if N is non-Empty
function Get_E_Length (E : Entity_Id; Indx : Nat) return Node_Id;
function Get_N_Length (N : Node_Id; Indx : Nat) return Node_Id;
-- Comments required ???
function Same_Bounds (L : Node_Id; R : Node_Id) return Boolean;
-- True for equal literals and for nodes that denote the same constant
-- entity, even if its value is not a static constant. This includes the
-- case of a discriminal reference within an init proc. Removes some
-- obviously superfluous checks.
function Length_E_Cond
(Exptyp : Entity_Id;
Typ : Entity_Id;
Indx : Nat) return Node_Id;
-- Returns expression to compute:
-- Typ'Length /= Exptyp'Length
function Length_N_Cond
(Exp : Node_Id;
Typ : Entity_Id;
Indx : Nat) return Node_Id;
-- Returns expression to compute:
-- Typ'Length /= Exp'Length
function Length_Mismatch_Info_Message
(Left_Element_Count : Uint;
Right_Element_Count : Uint) return String;
-- Returns a message indicating how many elements were expected
-- (Left_Element_Count) and how many were found (Right_Element_Count).
---------------
-- Add_Check --
---------------
procedure Add_Check (N : Node_Id) is
begin
if Present (N) then
-- For now, ignore attempt to place more than two checks ???
-- This is really worrisome, are we really discarding checks ???
if Num_Checks = 2 then
return;
end if;
pragma Assert (Num_Checks <= 1);
Num_Checks := Num_Checks + 1;
Ret_Result (Num_Checks) := N;
end if;
end Add_Check;
------------------
-- Get_E_Length --
------------------
function Get_E_Length (E : Entity_Id; Indx : Nat) return Node_Id is
SE : constant Entity_Id := Scope (E);
N : Node_Id;
E1 : Entity_Id := E;
begin
if Ekind (Scope (E)) = E_Record_Type
and then Has_Discriminants (Scope (E))
then
N := Build_Discriminal_Subtype_Of_Component (E);
if Present (N) then
Insert_Action (Expr, N);
E1 := Defining_Identifier (N);
end if;
end if;
if Ekind (E1) = E_String_Literal_Subtype then
return
Make_Integer_Literal (Loc,
Intval => String_Literal_Length (E1));
elsif SE /= Standard_Standard
and then Ekind (Scope (SE)) = E_Protected_Type
and then Has_Discriminants (Scope (SE))
and then Has_Completion (Scope (SE))
and then not Inside_Init_Proc
then
-- If the type whose length is needed is a private component
-- constrained by a discriminant, we must expand the 'Length
-- attribute into an explicit computation, using the discriminal
-- of the current protected operation. This is because the actual
-- type of the prival is constructed after the protected opera-
-- tion has been fully expanded.
declare
Indx_Type : Node_Id;
Lo : Node_Id;
Hi : Node_Id;
Do_Expand : Boolean := False;
begin
Indx_Type := First_Index (E);
for J in 1 .. Indx - 1 loop
Next_Index (Indx_Type);
end loop;
Get_Index_Bounds (Indx_Type, Lo, Hi);
if Nkind (Lo) = N_Identifier
and then Ekind (Entity (Lo)) = E_In_Parameter
then
Lo := Get_Discriminal (E, Lo);
Do_Expand := True;
end if;
if Nkind (Hi) = N_Identifier
and then Ekind (Entity (Hi)) = E_In_Parameter
then
Hi := Get_Discriminal (E, Hi);
Do_Expand := True;
end if;
if Do_Expand then
if not Is_Entity_Name (Lo) then
Lo := Duplicate_Subexpr_No_Checks (Lo);
end if;
if not Is_Entity_Name (Hi) then
Lo := Duplicate_Subexpr_No_Checks (Hi);
end if;
N :=
Make_Op_Add (Loc,
Left_Opnd =>
Make_Op_Subtract (Loc,
Left_Opnd => Hi,
Right_Opnd => Lo),
Right_Opnd => Make_Integer_Literal (Loc, 1));
return N;
else
N :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix =>
New_Occurrence_Of (E1, Loc));
if Indx > 1 then
Set_Expressions (N, New_List (
Make_Integer_Literal (Loc, Indx)));
end if;
return N;
end if;
end;
else
N :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix =>
New_Occurrence_Of (E1, Loc));
if Indx > 1 then
Set_Expressions (N, New_List (
Make_Integer_Literal (Loc, Indx)));
end if;
return N;
end if;
end Get_E_Length;
------------------
-- Get_N_Length --
------------------
function Get_N_Length (N : Node_Id; Indx : Nat) return Node_Id is
begin
return
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix =>
Duplicate_Subexpr_No_Checks (N, Name_Req => True),
Expressions => New_List (
Make_Integer_Literal (Loc, Indx)));
end Get_N_Length;
-------------------
-- Length_E_Cond --
-------------------
function Length_E_Cond
(Exptyp : Entity_Id;
Typ : Entity_Id;
Indx : Nat) return Node_Id
is
begin
return
Make_Op_Ne (Loc,
Left_Opnd => Get_E_Length (Typ, Indx),
Right_Opnd => Get_E_Length (Exptyp, Indx));
end Length_E_Cond;
-------------------
-- Length_N_Cond --
-------------------
function Length_N_Cond
(Exp : Node_Id;
Typ : Entity_Id;
Indx : Nat) return Node_Id
is
begin
return
Make_Op_Ne (Loc,
Left_Opnd => Get_E_Length (Typ, Indx),
Right_Opnd => Get_N_Length (Exp, Indx));
end Length_N_Cond;
----------------------------------
-- Length_Mismatch_Info_Message --
----------------------------------
function Length_Mismatch_Info_Message
(Left_Element_Count : Uint;
Right_Element_Count : Uint) return String
is
function Plural_Vs_Singular_Ending (Count : Uint) return String;
-- Returns an empty string if Count is 1; otherwise returns "s"
function Plural_Vs_Singular_Ending (Count : Uint) return String is
begin
if Count = 1 then
return "";
else
return "s";
end if;
end Plural_Vs_Singular_Ending;
begin
return "expected " & UI_Image (Left_Element_Count)
& " element"
& Plural_Vs_Singular_Ending (Left_Element_Count)
& "; found " & UI_Image (Right_Element_Count)
& " element"
& Plural_Vs_Singular_Ending (Right_Element_Count);
end Length_Mismatch_Info_Message;
-----------------
-- Same_Bounds --
-----------------
function Same_Bounds (L : Node_Id; R : Node_Id) return Boolean is
begin
return
(Nkind (L) = N_Integer_Literal
and then Nkind (R) = N_Integer_Literal
and then Intval (L) = Intval (R))
or else
(Is_Entity_Name (L)
and then Ekind (Entity (L)) = E_Constant
and then ((Is_Entity_Name (R)
and then Entity (L) = Entity (R))
or else
(Nkind (R) = N_Type_Conversion
and then Is_Entity_Name (Expression (R))
and then Entity (L) = Entity (Expression (R)))))
or else
(Is_Entity_Name (R)
and then Ekind (Entity (R)) = E_Constant
and then Nkind (L) = N_Type_Conversion
and then Is_Entity_Name (Expression (L))
and then Entity (R) = Entity (Expression (L)))
or else
(Is_Entity_Name (L)
and then Is_Entity_Name (R)
and then Entity (L) = Entity (R)
and then Ekind (Entity (L)) = E_In_Parameter
and then Inside_Init_Proc);
end Same_Bounds;
-- Start of processing for Selected_Length_Checks
begin
-- Checks will be applied only when generating code
if not Expander_Active then
return Ret_Result;
end if;
if Target_Typ = Any_Type
or else Target_Typ = Any_Composite
or else Raises_Constraint_Error (Expr)
then
return Ret_Result;
end if;
if No (Wnode) then
Wnode := Expr;
end if;
T_Typ := Target_Typ;
if No (Source_Typ) then
S_Typ := Etype (Expr);
else
S_Typ := Source_Typ;
end if;
if S_Typ = Any_Type or else S_Typ = Any_Composite then
return Ret_Result;
end if;
if Is_Access_Type (T_Typ) and then Is_Access_Type (S_Typ) then
S_Typ := Designated_Type (S_Typ);
T_Typ := Designated_Type (T_Typ);
Do_Access := True;
-- A simple optimization for the null case
if Known_Null (Expr) then
return Ret_Result;
end if;
end if;
if Is_Array_Type (T_Typ) and then Is_Array_Type (S_Typ) then
if Is_Constrained (T_Typ) then
-- The checking code to be generated will freeze the corresponding
-- array type. However, we must freeze the type now, so that the
-- freeze node does not appear within the generated if expression,
-- but ahead of it.
Freeze_Before (Expr, T_Typ);
Expr_Actual := Get_Referenced_Object (Expr);
Exptyp := Get_Actual_Subtype (Expr);
if Is_Access_Type (Exptyp) then
Exptyp := Designated_Type (Exptyp);
end if;
-- String_Literal case. This needs to be handled specially be-
-- cause no index types are available for string literals. The
-- condition is simply:
-- T_Typ'Length = string-literal-length
if Nkind (Expr_Actual) = N_String_Literal
and then Ekind (Etype (Expr_Actual)) = E_String_Literal_Subtype
then
Cond :=
Make_Op_Ne (Loc,
Left_Opnd => Get_E_Length (T_Typ, 1),
Right_Opnd =>
Make_Integer_Literal (Loc,
Intval =>
String_Literal_Length (Etype (Expr_Actual))));
-- General array case. Here we have a usable actual subtype for
-- the expression, and the condition is built from the two types
-- (Do_Length):
-- T_Typ'Length /= Exptyp'Length or else
-- T_Typ'Length (2) /= Exptyp'Length (2) or else
-- T_Typ'Length (3) /= Exptyp'Length (3) or else
-- ...
elsif Is_Constrained (Exptyp) then
declare
Ndims : constant Nat := Number_Dimensions (T_Typ);
L_Index : Node_Id;
R_Index : Node_Id;
L_Low : Node_Id;
L_High : Node_Id;
R_Low : Node_Id;
R_High : Node_Id;
L_Length : Uint;
R_Length : Uint;
Ref_Node : Node_Id;
begin
-- At the library level, we need to ensure that the type of
-- the object is elaborated before the check itself is
-- emitted. This is only done if the object is in the
-- current compilation unit, otherwise the type is frozen
-- and elaborated in its unit.
if Is_Itype (Exptyp)
and then
Ekind (Cunit_Entity (Current_Sem_Unit)) = E_Package
and then
not In_Package_Body (Cunit_Entity (Current_Sem_Unit))
and then In_Open_Scopes (Scope (Exptyp))
then
Ref_Node := Make_Itype_Reference (Sloc (Expr));
Set_Itype (Ref_Node, Exptyp);
Insert_Action (Expr, Ref_Node);
end if;
L_Index := First_Index (T_Typ);
R_Index := First_Index (Exptyp);
for Indx in 1 .. Ndims loop
if not (Nkind (L_Index) = N_Raise_Constraint_Error
or else
Nkind (R_Index) = N_Raise_Constraint_Error)
then
Get_Index_Bounds (L_Index, L_Low, L_High);
Get_Index_Bounds (R_Index, R_Low, R_High);
-- Deal with compile time length check. Note that we
-- skip this in the access case, because the access
-- value may be null, so we cannot know statically.
if not Do_Access
and then Compile_Time_Known_Value (L_Low)
and then Compile_Time_Known_Value (L_High)
and then Compile_Time_Known_Value (R_Low)
and then Compile_Time_Known_Value (R_High)
then
if Expr_Value (L_High) >= Expr_Value (L_Low) then
L_Length := Expr_Value (L_High) -
Expr_Value (L_Low) + 1;
else
L_Length := UI_From_Int (0);
end if;
if Expr_Value (R_High) >= Expr_Value (R_Low) then
R_Length := Expr_Value (R_High) -
Expr_Value (R_Low) + 1;
else
R_Length := UI_From_Int (0);
end if;
if L_Length > R_Length then
Add_Check
(Compile_Time_Constraint_Error
(Wnode, "too few elements for}??", T_Typ,
Extra_Msg => Length_Mismatch_Info_Message
(L_Length, R_Length)));
elsif L_Length < R_Length then
Add_Check
(Compile_Time_Constraint_Error
(Wnode, "too many elements for}??", T_Typ,
Extra_Msg => Length_Mismatch_Info_Message
(L_Length, R_Length)));
end if;
-- The comparison for an individual index subtype
-- is omitted if the corresponding index subtypes
-- statically match, since the result is known to
-- be true. Note that this test is worth while even
-- though we do static evaluation, because non-static
-- subtypes can statically match.
elsif not
Subtypes_Statically_Match
(Etype (L_Index), Etype (R_Index))
and then not
(Same_Bounds (L_Low, R_Low)
and then Same_Bounds (L_High, R_High))
then
Evolve_Or_Else
(Cond, Length_E_Cond (Exptyp, T_Typ, Indx));
end if;
Next (L_Index);
Next (R_Index);
end if;
end loop;
end;
-- Handle cases where we do not get a usable actual subtype that
-- is constrained. This happens for example in the function call
-- and explicit dereference cases. In these cases, we have to get
-- the length or range from the expression itself, making sure we
-- do not evaluate it more than once.
-- Here Expr is the original expression, or more properly the
-- result of applying Duplicate_Expr to the original tree, forcing
-- the result to be a name.
else
declare
Ndims : constant Pos := Number_Dimensions (T_Typ);
begin
-- Build the condition for the explicit dereference case
for Indx in 1 .. Ndims loop
Evolve_Or_Else
(Cond, Length_N_Cond (Expr, T_Typ, Indx));
end loop;
end;
end if;
end if;
end if;
-- Construct the test and insert into the tree
if Present (Cond) then
if Do_Access then
Cond := Guard_Access (Cond, Loc, Expr);
end if;
Add_Check
(Make_Raise_Constraint_Error (Loc,
Condition => Cond,
Reason => CE_Length_Check_Failed));
end if;
return Ret_Result;
end Selected_Length_Checks;
---------------------------
-- Selected_Range_Checks --
---------------------------
function Selected_Range_Checks
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id;
Warn_Node : Node_Id) return Check_Result
is
Loc : constant Source_Ptr := Sloc (Expr);
S_Typ : Entity_Id;
T_Typ : Entity_Id;
Expr_Actual : Node_Id;
Exptyp : Entity_Id;
Cond : Node_Id := Empty;
Do_Access : Boolean := False;
Wnode : Node_Id := Warn_Node;
Ret_Result : Check_Result := (Empty, Empty);
Num_Checks : Natural := 0;
procedure Add_Check (N : Node_Id);
-- Adds the action given to Ret_Result if N is non-Empty
function Discrete_Range_Cond
(Exp : Node_Id;
Typ : Entity_Id) return Node_Id;
-- Returns expression to compute:
-- Low_Bound (Exp) < Typ'First
-- or else
-- High_Bound (Exp) > Typ'Last
function Discrete_Expr_Cond
(Exp : Node_Id;
Typ : Entity_Id) return Node_Id;
-- Returns expression to compute:
-- Exp < Typ'First
-- or else
-- Exp > Typ'Last
function Get_E_First_Or_Last
(Loc : Source_Ptr;
E : Entity_Id;
Indx : Nat;
Nam : Name_Id) return Node_Id;
-- Returns an attribute reference
-- E'First or E'Last
-- with a source location of Loc.
--
-- Nam is Name_First or Name_Last, according to which attribute is
-- desired. If Indx is non-zero, it is passed as a literal in the
-- Expressions of the attribute reference (identifying the desired
-- array dimension).
function Get_N_First (N : Node_Id; Indx : Nat) return Node_Id;
function Get_N_Last (N : Node_Id; Indx : Nat) return Node_Id;
-- Returns expression to compute:
-- N'First or N'Last using Duplicate_Subexpr_No_Checks
function Range_E_Cond
(Exptyp : Entity_Id;
Typ : Entity_Id;
Indx : Nat)
return Node_Id;
-- Returns expression to compute:
-- Exptyp'First < Typ'First or else Exptyp'Last > Typ'Last
function Range_Equal_E_Cond
(Exptyp : Entity_Id;
Typ : Entity_Id;
Indx : Nat) return Node_Id;
-- Returns expression to compute:
-- Exptyp'First /= Typ'First or else Exptyp'Last /= Typ'Last
function Range_N_Cond
(Exp : Node_Id;
Typ : Entity_Id;
Indx : Nat) return Node_Id;
-- Return expression to compute:
-- Exp'First < Typ'First or else Exp'Last > Typ'Last
---------------
-- Add_Check --
---------------
procedure Add_Check (N : Node_Id) is
begin
if Present (N) then
-- For now, ignore attempt to place more than 2 checks ???
if Num_Checks = 2 then
return;
end if;
pragma Assert (Num_Checks <= 1);
Num_Checks := Num_Checks + 1;
Ret_Result (Num_Checks) := N;
end if;
end Add_Check;
-------------------------
-- Discrete_Expr_Cond --
-------------------------
function Discrete_Expr_Cond
(Exp : Node_Id;
Typ : Entity_Id) return Node_Id
is
begin
return
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Lt (Loc,
Left_Opnd =>
Convert_To (Base_Type (Typ),
Duplicate_Subexpr_No_Checks (Exp)),
Right_Opnd =>
Convert_To (Base_Type (Typ),
Get_E_First_Or_Last (Loc, Typ, 0, Name_First))),
Right_Opnd =>
Make_Op_Gt (Loc,
Left_Opnd =>
Convert_To (Base_Type (Typ),
Duplicate_Subexpr_No_Checks (Exp)),
Right_Opnd =>
Convert_To
(Base_Type (Typ),
Get_E_First_Or_Last (Loc, Typ, 0, Name_Last))));
end Discrete_Expr_Cond;
-------------------------
-- Discrete_Range_Cond --
-------------------------
function Discrete_Range_Cond
(Exp : Node_Id;
Typ : Entity_Id) return Node_Id
is
LB : Node_Id := Low_Bound (Exp);
HB : Node_Id := High_Bound (Exp);
Left_Opnd : Node_Id;
Right_Opnd : Node_Id;
begin
if Nkind (LB) = N_Identifier
and then Ekind (Entity (LB)) = E_Discriminant
then
LB := New_Occurrence_Of (Discriminal (Entity (LB)), Loc);
end if;
Left_Opnd :=
Make_Op_Lt (Loc,
Left_Opnd =>
Convert_To
(Base_Type (Typ), Duplicate_Subexpr_No_Checks (LB)),
Right_Opnd =>
Convert_To
(Base_Type (Typ),
Get_E_First_Or_Last (Loc, Typ, 0, Name_First)));
if Nkind (HB) = N_Identifier
and then Ekind (Entity (HB)) = E_Discriminant
then
HB := New_Occurrence_Of (Discriminal (Entity (HB)), Loc);
end if;
Right_Opnd :=
Make_Op_Gt (Loc,
Left_Opnd =>
Convert_To
(Base_Type (Typ), Duplicate_Subexpr_No_Checks (HB)),
Right_Opnd =>
Convert_To
(Base_Type (Typ),
Get_E_First_Or_Last (Loc, Typ, 0, Name_Last)));
return Make_Or_Else (Loc, Left_Opnd, Right_Opnd);
end Discrete_Range_Cond;
-------------------------
-- Get_E_First_Or_Last --
-------------------------
function Get_E_First_Or_Last
(Loc : Source_Ptr;
E : Entity_Id;
Indx : Nat;
Nam : Name_Id) return Node_Id
is
Exprs : List_Id;
begin
if Indx > 0 then
Exprs := New_List (Make_Integer_Literal (Loc, UI_From_Int (Indx)));
else
Exprs := No_List;
end if;
return Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (E, Loc),
Attribute_Name => Nam,
Expressions => Exprs);
end Get_E_First_Or_Last;
-----------------
-- Get_N_First --
-----------------
function Get_N_First (N : Node_Id; Indx : Nat) return Node_Id is
begin
return
Make_Attribute_Reference (Loc,
Attribute_Name => Name_First,
Prefix =>
Duplicate_Subexpr_No_Checks (N, Name_Req => True),
Expressions => New_List (
Make_Integer_Literal (Loc, Indx)));
end Get_N_First;
----------------
-- Get_N_Last --
----------------
function Get_N_Last (N : Node_Id; Indx : Nat) return Node_Id is
begin
return
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Last,
Prefix =>
Duplicate_Subexpr_No_Checks (N, Name_Req => True),
Expressions => New_List (
Make_Integer_Literal (Loc, Indx)));
end Get_N_Last;
------------------
-- Range_E_Cond --
------------------
function Range_E_Cond
(Exptyp : Entity_Id;
Typ : Entity_Id;
Indx : Nat) return Node_Id
is
begin
return
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Lt (Loc,
Left_Opnd =>
Get_E_First_Or_Last (Loc, Exptyp, Indx, Name_First),
Right_Opnd =>
Get_E_First_Or_Last (Loc, Typ, Indx, Name_First)),
Right_Opnd =>
Make_Op_Gt (Loc,
Left_Opnd =>
Get_E_First_Or_Last (Loc, Exptyp, Indx, Name_Last),
Right_Opnd =>
Get_E_First_Or_Last (Loc, Typ, Indx, Name_Last)));
end Range_E_Cond;
------------------------
-- Range_Equal_E_Cond --
------------------------
function Range_Equal_E_Cond
(Exptyp : Entity_Id;
Typ : Entity_Id;
Indx : Nat) return Node_Id
is
begin
return
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Ne (Loc,
Left_Opnd =>
Get_E_First_Or_Last (Loc, Exptyp, Indx, Name_First),
Right_Opnd =>
Get_E_First_Or_Last (Loc, Typ, Indx, Name_First)),
Right_Opnd =>
Make_Op_Ne (Loc,
Left_Opnd =>
Get_E_First_Or_Last (Loc, Exptyp, Indx, Name_Last),
Right_Opnd =>
Get_E_First_Or_Last (Loc, Typ, Indx, Name_Last)));
end Range_Equal_E_Cond;
------------------
-- Range_N_Cond --
------------------
function Range_N_Cond
(Exp : Node_Id;
Typ : Entity_Id;
Indx : Nat) return Node_Id
is
begin
return
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Lt (Loc,
Left_Opnd =>
Get_N_First (Exp, Indx),
Right_Opnd =>
Get_E_First_Or_Last (Loc, Typ, Indx, Name_First)),
Right_Opnd =>
Make_Op_Gt (Loc,
Left_Opnd =>
Get_N_Last (Exp, Indx),
Right_Opnd =>
Get_E_First_Or_Last (Loc, Typ, Indx, Name_Last)));
end Range_N_Cond;
-- Start of processing for Selected_Range_Checks
begin
-- Checks will be applied only when generating code. In GNATprove mode,
-- we do not apply the checks, but we still call Selected_Range_Checks
-- to possibly issue errors on SPARK code when a run-time error can be
-- detected at compile time.
if not Expander_Active and not GNATprove_Mode then
return Ret_Result;
end if;
if Target_Typ = Any_Type
or else Target_Typ = Any_Composite
or else Raises_Constraint_Error (Expr)
then
return Ret_Result;
end if;
if No (Wnode) then
Wnode := Expr;
end if;
T_Typ := Target_Typ;
if No (Source_Typ) then
S_Typ := Etype (Expr);
else
S_Typ := Source_Typ;
end if;
if S_Typ = Any_Type or else S_Typ = Any_Composite then
return Ret_Result;
end if;
-- The order of evaluating T_Typ before S_Typ seems to be critical
-- because S_Typ can be derived from Etype (Expr), if it's not passed
-- in, and since Node can be an N_Range node, it might be invalid.
-- Should there be an assert check somewhere for taking the Etype of
-- an N_Range node ???
if Is_Access_Type (T_Typ) and then Is_Access_Type (S_Typ) then
S_Typ := Designated_Type (S_Typ);
T_Typ := Designated_Type (T_Typ);
Do_Access := True;
-- A simple optimization for the null case
if Known_Null (Expr) then
return Ret_Result;
end if;
end if;
-- For an N_Range Node, check for a null range and then if not
-- null generate a range check action.
if Nkind (Expr) = N_Range then
-- There's no point in checking a range against itself
if Expr = Scalar_Range (T_Typ) then
return Ret_Result;
end if;
declare
T_LB : constant Node_Id := Type_Low_Bound (T_Typ);
T_HB : constant Node_Id := Type_High_Bound (T_Typ);
Known_T_LB : constant Boolean := Compile_Time_Known_Value (T_LB);
Known_T_HB : constant Boolean := Compile_Time_Known_Value (T_HB);
LB : Node_Id := Low_Bound (Expr);
HB : Node_Id := High_Bound (Expr);
Known_LB : Boolean := False;
Known_HB : Boolean := False;
Null_Range : Boolean;
Out_Of_Range_L : Boolean;
Out_Of_Range_H : Boolean;
begin
-- Compute what is known at compile time
if Known_T_LB and Known_T_HB then
if Compile_Time_Known_Value (LB) then
Known_LB := True;
-- There's no point in checking that a bound is within its
-- own range so pretend that it is known in this case. First
-- deal with low bound.
elsif Ekind (Etype (LB)) = E_Signed_Integer_Subtype
and then Scalar_Range (Etype (LB)) = Scalar_Range (T_Typ)
then
LB := T_LB;
Known_LB := True;
end if;
-- Likewise for the high bound
if Compile_Time_Known_Value (HB) then
Known_HB := True;
elsif Ekind (Etype (HB)) = E_Signed_Integer_Subtype
and then Scalar_Range (Etype (HB)) = Scalar_Range (T_Typ)
then
HB := T_HB;
Known_HB := True;
end if;
end if;
-- Check for case where everything is static and we can do the
-- check at compile time. This is skipped if we have an access
-- type, since the access value may be null.
-- ??? This code can be improved since you only need to know that
-- the two respective bounds (LB & T_LB or HB & T_HB) are known at
-- compile time to emit pertinent messages.
if Known_T_LB and Known_T_HB and Known_LB and Known_HB
and not Do_Access
then
-- Floating-point case
if Is_Floating_Point_Type (S_Typ) then
Null_Range := Expr_Value_R (HB) < Expr_Value_R (LB);
Out_Of_Range_L :=
(Expr_Value_R (LB) < Expr_Value_R (T_LB))
or else
(Expr_Value_R (LB) > Expr_Value_R (T_HB));
Out_Of_Range_H :=
(Expr_Value_R (HB) > Expr_Value_R (T_HB))
or else
(Expr_Value_R (HB) < Expr_Value_R (T_LB));
-- Fixed or discrete type case
else
Null_Range := Expr_Value (HB) < Expr_Value (LB);
Out_Of_Range_L :=
(Expr_Value (LB) < Expr_Value (T_LB))
or else
(Expr_Value (LB) > Expr_Value (T_HB));
Out_Of_Range_H :=
(Expr_Value (HB) > Expr_Value (T_HB))
or else
(Expr_Value (HB) < Expr_Value (T_LB));
end if;
if not Null_Range then
if Out_Of_Range_L then
if No (Warn_Node) then
Add_Check
(Compile_Time_Constraint_Error
(Low_Bound (Expr),
"static value out of range of}??", T_Typ));
else
Add_Check
(Compile_Time_Constraint_Error
(Wnode,
"static range out of bounds of}??", T_Typ));
end if;
end if;
if Out_Of_Range_H then
if No (Warn_Node) then
Add_Check
(Compile_Time_Constraint_Error
(High_Bound (Expr),
"static value out of range of}??", T_Typ));
else
Add_Check
(Compile_Time_Constraint_Error
(Wnode,
"static range out of bounds of}??", T_Typ));
end if;
end if;
end if;
else
declare
LB : Node_Id := Low_Bound (Expr);
HB : Node_Id := High_Bound (Expr);
begin
-- If either bound is a discriminant and we are within the
-- record declaration, it is a use of the discriminant in a
-- constraint of a component, and nothing can be checked
-- here. The check will be emitted within the init proc.
-- Before then, the discriminal has no real meaning.
-- Similarly, if the entity is a discriminal, there is no
-- check to perform yet.
-- The same holds within a discriminated synchronized type,
-- where the discriminant may constrain a component or an
-- entry family.
if Nkind (LB) = N_Identifier
and then Denotes_Discriminant (LB, True)
then
if Current_Scope = Scope (Entity (LB))
or else Is_Concurrent_Type (Current_Scope)
or else Ekind (Entity (LB)) /= E_Discriminant
then
return Ret_Result;
else
LB :=
New_Occurrence_Of (Discriminal (Entity (LB)), Loc);
end if;
end if;
if Nkind (HB) = N_Identifier
and then Denotes_Discriminant (HB, True)
then
if Current_Scope = Scope (Entity (HB))
or else Is_Concurrent_Type (Current_Scope)
or else Ekind (Entity (HB)) /= E_Discriminant
then
return Ret_Result;
else
HB :=
New_Occurrence_Of (Discriminal (Entity (HB)), Loc);
end if;
end if;
Cond := Discrete_Range_Cond (Expr, T_Typ);
Set_Paren_Count (Cond, 1);
Cond :=
Make_And_Then (Loc,
Left_Opnd =>
Make_Op_Ge (Loc,
Left_Opnd =>
Convert_To (Base_Type (Etype (HB)),
Duplicate_Subexpr_No_Checks (HB)),
Right_Opnd =>
Convert_To (Base_Type (Etype (LB)),
Duplicate_Subexpr_No_Checks (LB))),
Right_Opnd => Cond);
end;
end if;
end;
elsif Is_Scalar_Type (S_Typ) then
-- This somewhat duplicates what Apply_Scalar_Range_Check does,
-- except the above simply sets a flag in the node and lets
-- gigi generate the check base on the Etype of the expression.
-- Sometimes, however we want to do a dynamic check against an
-- arbitrary target type, so we do that here.
if Ekind (Base_Type (S_Typ)) /= Ekind (Base_Type (T_Typ)) then
Cond := Discrete_Expr_Cond (Expr, T_Typ);
-- For literals, we can tell if the constraint error will be
-- raised at compile time, so we never need a dynamic check, but
-- if the exception will be raised, then post the usual warning,
-- and replace the literal with a raise constraint error
-- expression. As usual, skip this for access types
elsif Compile_Time_Known_Value (Expr) and then not Do_Access then
declare
LB : constant Node_Id := Type_Low_Bound (T_Typ);
UB : constant Node_Id := Type_High_Bound (T_Typ);
Out_Of_Range : Boolean;
Static_Bounds : constant Boolean :=
Compile_Time_Known_Value (LB)
and Compile_Time_Known_Value (UB);
begin
-- Following range tests should use Sem_Eval routine ???
if Static_Bounds then
if Is_Floating_Point_Type (S_Typ) then
Out_Of_Range :=
(Expr_Value_R (Expr) < Expr_Value_R (LB))
or else
(Expr_Value_R (Expr) > Expr_Value_R (UB));
-- Fixed or discrete type
else
Out_Of_Range :=
Expr_Value (Expr) < Expr_Value (LB)
or else
Expr_Value (Expr) > Expr_Value (UB);
end if;
-- Bounds of the type are static and the literal is out of
-- range so output a warning message.
if Out_Of_Range then
if No (Warn_Node) then
Add_Check
(Compile_Time_Constraint_Error
(Expr,
"static value out of range of}??", T_Typ));
else
Add_Check
(Compile_Time_Constraint_Error
(Wnode,
"static value out of range of}??", T_Typ));
end if;
end if;
else
Cond := Discrete_Expr_Cond (Expr, T_Typ);
end if;
end;
-- Here for the case of a non-static expression, we need a runtime
-- check unless the source type range is guaranteed to be in the
-- range of the target type.
else
if not In_Subrange_Of (S_Typ, T_Typ) then
Cond := Discrete_Expr_Cond (Expr, T_Typ);
end if;
end if;
end if;
if Is_Array_Type (T_Typ) and then Is_Array_Type (S_Typ) then
if Is_Constrained (T_Typ) then
Expr_Actual := Get_Referenced_Object (Expr);
Exptyp := Get_Actual_Subtype (Expr_Actual);
if Is_Access_Type (Exptyp) then
Exptyp := Designated_Type (Exptyp);
end if;
-- String_Literal case. This needs to be handled specially be-
-- cause no index types are available for string literals. The
-- condition is simply:
-- T_Typ'Length = string-literal-length
if Nkind (Expr_Actual) = N_String_Literal then
null;
-- General array case. Here we have a usable actual subtype for
-- the expression, and the condition is built from the two types
-- T_Typ'First < Exptyp'First or else
-- T_Typ'Last > Exptyp'Last or else
-- T_Typ'First(1) < Exptyp'First(1) or else
-- T_Typ'Last(1) > Exptyp'Last(1) or else
-- ...
elsif Is_Constrained (Exptyp) then
declare
Ndims : constant Pos := Number_Dimensions (T_Typ);
L_Index : Node_Id;
R_Index : Node_Id;
begin
L_Index := First_Index (T_Typ);
R_Index := First_Index (Exptyp);
for Indx in 1 .. Ndims loop
if not (Nkind (L_Index) = N_Raise_Constraint_Error
or else
Nkind (R_Index) = N_Raise_Constraint_Error)
then
-- Deal with compile time length check. Note that we
-- skip this in the access case, because the access
-- value may be null, so we cannot know statically.
if not
Subtypes_Statically_Match
(Etype (L_Index), Etype (R_Index))
then
-- If the target type is constrained then we
-- have to check for exact equality of bounds
-- (required for qualified expressions).
if Is_Constrained (T_Typ) then
Evolve_Or_Else
(Cond,
Range_Equal_E_Cond (Exptyp, T_Typ, Indx));
else
Evolve_Or_Else
(Cond, Range_E_Cond (Exptyp, T_Typ, Indx));
end if;
end if;
Next (L_Index);
Next (R_Index);
end if;
end loop;
end;
-- Handle cases where we do not get a usable actual subtype that
-- is constrained. This happens for example in the function call
-- and explicit dereference cases. In these cases, we have to get
-- the length or range from the expression itself, making sure we
-- do not evaluate it more than once.
-- Here Expr is the original expression, or more properly the
-- result of applying Duplicate_Expr to the original tree,
-- forcing the result to be a name.
else
declare
Ndims : constant Pos := Number_Dimensions (T_Typ);
begin
-- Build the condition for the explicit dereference case
for Indx in 1 .. Ndims loop
Evolve_Or_Else
(Cond, Range_N_Cond (Expr, T_Typ, Indx));
end loop;
end;
end if;
else
-- For a conversion to an unconstrained array type, generate an
-- Action to check that the bounds of the source value are within
-- the constraints imposed by the target type (RM 4.6(38)). No
-- check is needed for a conversion to an access to unconstrained
-- array type, as 4.6(24.15/2) requires the designated subtypes
-- of the two access types to statically match.
if Nkind (Parent (Expr)) = N_Type_Conversion
and then not Do_Access
then
declare
Opnd_Index : Node_Id;
Targ_Index : Node_Id;
Opnd_Range : Node_Id;
begin
Opnd_Index := First_Index (Get_Actual_Subtype (Expr));
Targ_Index := First_Index (T_Typ);
while Present (Opnd_Index) loop
-- If the index is a range, use its bounds. If it is an
-- entity (as will be the case if it is a named subtype
-- or an itype created for a slice) retrieve its range.
if Is_Entity_Name (Opnd_Index)
and then Is_Type (Entity (Opnd_Index))
then
Opnd_Range := Scalar_Range (Entity (Opnd_Index));
else
Opnd_Range := Opnd_Index;
end if;
if Nkind (Opnd_Range) = N_Range then
if Is_In_Range
(Low_Bound (Opnd_Range), Etype (Targ_Index),
Assume_Valid => True)
and then
Is_In_Range
(High_Bound (Opnd_Range), Etype (Targ_Index),
Assume_Valid => True)
then
null;
-- If null range, no check needed
elsif
Compile_Time_Known_Value (High_Bound (Opnd_Range))
and then
Compile_Time_Known_Value (Low_Bound (Opnd_Range))
and then
Expr_Value (High_Bound (Opnd_Range)) <
Expr_Value (Low_Bound (Opnd_Range))
then
null;
elsif Is_Out_Of_Range
(Low_Bound (Opnd_Range), Etype (Targ_Index),
Assume_Valid => True)
or else
Is_Out_Of_Range
(High_Bound (Opnd_Range), Etype (Targ_Index),
Assume_Valid => True)
then
Add_Check
(Compile_Time_Constraint_Error
(Wnode, "value out of range of}??", T_Typ));
else
Evolve_Or_Else
(Cond,
Discrete_Range_Cond
(Opnd_Range, Etype (Targ_Index)));
end if;
end if;
Next_Index (Opnd_Index);
Next_Index (Targ_Index);
end loop;
end;
end if;
end if;
end if;
-- Construct the test and insert into the tree
if Present (Cond) then
if Do_Access then
Cond := Guard_Access (Cond, Loc, Expr);
end if;
Add_Check
(Make_Raise_Constraint_Error (Loc,
Condition => Cond,
Reason => CE_Range_Check_Failed));
end if;
return Ret_Result;
end Selected_Range_Checks;
-------------------------------
-- Storage_Checks_Suppressed --
-------------------------------
function Storage_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Storage_Check);
else
return Scope_Suppress.Suppress (Storage_Check);
end if;
end Storage_Checks_Suppressed;
---------------------------
-- Tag_Checks_Suppressed --
---------------------------
function Tag_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E)
and then Checks_May_Be_Suppressed (E)
then
return Is_Check_Suppressed (E, Tag_Check);
else
return Scope_Suppress.Suppress (Tag_Check);
end if;
end Tag_Checks_Suppressed;
---------------------------------------
-- Validate_Alignment_Check_Warnings --
---------------------------------------
procedure Validate_Alignment_Check_Warnings is
begin
for J in Alignment_Warnings.First .. Alignment_Warnings.Last loop
declare
AWR : Alignment_Warnings_Record
renames Alignment_Warnings.Table (J);
begin
if Known_Alignment (AWR.E)
and then ((AWR.A /= No_Uint
and then AWR.A mod Alignment (AWR.E) = 0)
or else (Present (AWR.P)
and then Has_Compatible_Alignment
(AWR.E, AWR.P, True) =
Known_Compatible))
then
Delete_Warning_And_Continuations (AWR.W);
end if;
end;
end loop;
end Validate_Alignment_Check_Warnings;
--------------------------
-- Validity_Check_Range --
--------------------------
procedure Validity_Check_Range
(N : Node_Id;
Related_Id : Entity_Id := Empty)
is
begin
if Validity_Checks_On and Validity_Check_Operands then
if Nkind (N) = N_Range then
Ensure_Valid
(Expr => Low_Bound (N),
Related_Id => Related_Id,
Is_Low_Bound => True);
Ensure_Valid
(Expr => High_Bound (N),
Related_Id => Related_Id,
Is_High_Bound => True);
end if;
end if;
end Validity_Check_Range;
--------------------------------
-- Validity_Checks_Suppressed --
--------------------------------
function Validity_Checks_Suppressed (E : Entity_Id) return Boolean is
begin
if Present (E) and then Checks_May_Be_Suppressed (E) then
return Is_Check_Suppressed (E, Validity_Check);
else
return Scope_Suppress.Suppress (Validity_Check);
end if;
end Validity_Checks_Suppressed;
end Checks;
|
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Extensions;
package stdint_h is
subtype uint8_t is unsigned_char; -- /usr/include/stdint.h:48
end stdint_h;
|
with Numerics, Ada.Text_IO;
use Numerics;
package body Numerics.Dense_Matrices is
function Outer (X, Y : in Real_Vector) return Real_Matrix is
Result : Real_Matrix (1 .. X'Length, 1 .. Y'Length);
begin
for I in Result'Range (1) loop
for J in Result'Range (2) loop
Result (I, J) := X (I) * Y (J);
end loop;
end loop;
return Result;
end Outer;
function "-" (A : in Real_Matrix) return Real_Matrix is
Result : Real_Matrix := A;
begin
for X of Result loop X := -X; end loop;
return Result;
end "-";
function "*" (X : in Real;
A : in Real_Matrix) return Real_Matrix is
Result : Real_Matrix := A;
begin
for Y of Result loop Y := X * Y; end loop;
return Result;
end "*";
function "+" (A : in Real_Matrix;
B : in Real_Matrix) return Real_Matrix is
C : Real_Matrix (1 .. A'Length (1), 1 .. A'Length (2))
:= (others => (others => 0.0));
Coff_1 : constant Integer := 1 - A'First (1);
Coff_2 : constant Integer := 1 - A'First (2);
Boff_1 : constant Integer := B'First (1) - A'First (1);
Boff_2 : constant Integer := B'First (2) - A'First (2);
begin
for I in A'Range (1) loop
for J in A'Range (2) loop
C (I + Coff_1, J + Coff_2) := A (I, J) + B (I + Boff_1, J + Boff_2);
end loop;
end loop;
return C;
end "+";
function "-" (A : in Real_Matrix;
B : in Real_Matrix) return Real_Matrix is
C : Real_Matrix (1 .. A'Length (1), 1 .. A'Length (2))
:= (others => (others => 0.0));
Coff_1 : constant Integer := 1 - A'First (1);
Coff_2 : constant Integer := 1 - A'First (2);
Boff_1 : constant Integer := B'First (1) - A'First (1);
Boff_2 : constant Integer := B'First (2) - A'First (2);
begin
for I in A'Range (1) loop
for J in A'Range (2) loop
C (I + Coff_1, J + Coff_2) := A (I, J) - B (I + Boff_1, J + Boff_2);
end loop;
end loop;
return C;
end "-";
function "*" (A : in Real_Matrix;
B : in Real_Matrix) return Real_Matrix is
C : Real_Matrix (1 .. A'Length (1), 1 .. B'Length (2))
:= (others => (others => 0.0));
Coff_1 : constant Integer := 1 - A'First (1);
Coff_2 : constant Integer := 1 - B'First (2);
Boff_1 : constant Integer := B'First (1) - A'First (2);
Tmp : Real;
begin
for I in A'Range (1) loop
for J in B'Range (2) loop
Tmp := 0.0;
for K in A'Range (2) loop
Tmp := Tmp + A (I, K) * B (K + Boff_1, J);
end loop;
C (I + Coff_1, J + Coff_2) := Tmp;
end loop;
end loop;
return C;
end "*";
function Transpose (A : in Real_Matrix) return Real_Matrix is
B : Real_Matrix (A'Range (2), A'Range (1));
begin
for I in A'Range (1) loop
for J in A'Range (2) loop
B (J, I) := A (I, J);
end loop;
end loop;
return B;
end Transpose;
function Eye (N : in Pos) return Real_Matrix is
A : Real_Matrix (1 .. N, 1 .. N) := (others => (others => 0.0));
begin
for I in 1 .. N loop
A (I, I) := 1.0;
end loop;
return A;
end Eye;
function Eye (N : in Pos) return Int_Matrix is
A : Int_Matrix (1 .. N, 1 .. N) := (others => (others => 0));
begin
for I in 1 .. N loop
A (I, I) := 1;
end loop;
return A;
end Eye;
function Pivoting_Array (A : in Real_Matrix) return Int_Array is
N : constant Nat := A'Length (1);
P : Int_Array (1 .. N);
Max : Real;
Row : Pos;
Tmp : Nat;
begin
for I in P'Range loop
P (I) := I;
end loop;
for J in 1 .. N loop
Max := abs (A (J + A'First (1) - 1, J + A'First (2) - 1));
Row := J;
for I in J + 1 .. N loop
if abs (A (I + A'First (1) - 1, J + A'First (2) - 1)) > Max then
Max := A (I + A'First (1) - 1, J + A'First (2) - 1);
Row := I;
end if;
end loop;
if J /= Row then
Tmp := P (J);
P (J) := P (Row);
P (Row) := Tmp;
end if;
end loop;
return P;
end Pivoting_Array;
function Permute_Row (A : in Real_Matrix;
P : in Int_Array) return Real_Matrix is
PA : Real_Matrix (1 .. A'Length (1), 1 .. A'Length (2));
begin
for Row in P'Range loop
for J in 1 .. A'Length (1) loop
PA (Row, J) := A (P (Row), J + A'First (1) - 1);
end loop;
end loop;
return PA;
end Permute_Row;
procedure LU_Decomposition (A : in Real_Matrix;
P : out Int_Array;
L : out Real_Matrix;
U : out Real_Matrix) is
N : constant Nat := A'Length (1);
PA : Real_Matrix (A'Range (1), A'Range (2));
S : Real;
begin
L := (others => (others => 0.0));
U := (others => (others => 0.0));
P := Pivoting_Array (A);
PA := Permute_Row (A => A, P => P);
for J in 0 .. N - 1 loop
L (L'First (1) + J, L'First (2) + J) := 1.0;
for I in 0 .. J loop
S := 0.0;
for K in 0 .. I - 1 loop
S := S + U (U'First (1) + K, U'First (2) + J) *
L (L'First (1) + I, L'First (2) + K);
end loop;
U (U'First (1) + I, U'First (2) + J) :=
PA (PA'First (1) + I, PA'First (2) + J) - S;
end loop;
for I in J + 1 .. N - 1 loop
S := 0.0;
for K in 0 .. J loop
S := S + U (U'First (1) + K, U'First (2) + J) *
L (L'First (1) + I, L'First (2) + K);
end loop;
L (L'First (1) + I, L'First (2) + J) :=
(PA (PA'First (1) + I, PA'First (2) + J) - S) /
U (U'First (1) + J, U'First (2) + J);
end loop;
end loop;
end LU_Decomposition;
procedure Print (X : in Real_Vector) is
use Real_IO, Ada.Text_IO;
begin
for Item of X loop
Put (Item, Aft => 3, Exp => 0); New_Line;
end loop;
end Print;
procedure Print (A : in Real_Matrix) is
use Real_IO, Ada.Text_IO;
begin
for I in A'Range (1) loop
for J in A'Range (2) loop
Put (A (I, J), Aft => 3, Exp => 0); Put (", ");
end loop;
New_Line;
end loop;
end Print;
procedure Print (A : in Int_Matrix) is
use Int_IO, Ada.Text_IO;
begin
for I in A'Range (1) loop
for J in A'Range (2) loop
Put (A (I, J), 3); Put (", ");
end loop;
New_Line;
end loop;
end Print;
function Number_Of_Swaps (P : in Int_Array) return Pos is
Y : array (P'Range) of Boolean := (others => False);
Ind : Pos := 0;
Cycles : Pos := 0;
begin
for I in P'Range loop
if Y (I) = False then
Cycles := Cycles + 1;
Y (I) := True;
Ind := P (I);
while Y (Ind) = False loop
Y (Ind) := True;
Ind := P (Ind);
end loop;
end if;
end loop;
return P'Length - Cycles;
end Number_Of_Swaps;
function Diag (A : in Real_Matrix) return Real_Vector is
X : Real_Vector (1 .. A'Length (1));
begin
for I in X'Range loop
X (I) := A (I + A'First (1) - 1, I + A'First (2) - 1);
end loop;
return X;
end Diag;
function Diag (X : in Real_Vector) return Real_Matrix is
A : Real_Matrix (1 .. X'Length, 1 .. X'Length)
:= (others => (others => 0.0));
begin
for I in X'Range loop
A (I + 1 - X'First, I + 1 - X'First) := X (I);
end loop;
return A;
end Diag;
function Determinant (P : in Int_Array;
L : in Real_Matrix;
U : in Real_Matrix) return Real is
Num : Pos := Number_Of_Swaps (P);
Vec_L : Real_Vector := Diag (L);
Vec_U : Real_Vector := Diag (U);
Det : Real := 1.0;
begin
for X of Vec_L loop
Det := Det * X;
end loop;
for X of Vec_U loop
Det := Det * X;
end loop;
if Num mod 2 = 1 then Det := -Det; end if;
return Det;
end Determinant;
function Determinant (A : in Real_Matrix) return Real is
P : Int_Array (1 .. A'Length (1));
L : Real_Matrix (1 .. A'Length (1), 1 .. A'Length (2));
U : Real_Matrix (1 .. A'Length (1), 1 .. A'Length (2));
begin
LU_Decomposition (A, P, L, U);
return Determinant (P, L, U);
end Determinant;
function Solve_Upper (U : in Real_Matrix;
B : in Real_Vector) return Real_Vector is
N : constant Nat := U'Length (1);
X : Real_Vector (1 .. N) := (others => 0.0);
Tmp : Real;
begin
for I in reverse 1 .. N loop
Tmp := 0.0;
for J in I + 1 .. N loop
Tmp := Tmp + U (I, J) * X (J);
end loop;
X (I) := (B (I) - Tmp) / U (I, I);
end loop;
return X;
end Solve_Upper;
function Solve_Lower (L : in Real_Matrix;
B : in Real_Vector) return Real_Vector is
N : constant Nat := L'Length (1);
X : Real_Vector (1 .. N) := (others => 0.0);
Tmp : Real;
begin
for I in 1 .. N loop
Tmp := 0.0;
for J in 1 .. I - 1 loop
Tmp := Tmp + L (I, J) * X (J);
end loop;
X (I) := B (I) - Tmp;
end loop;
return X;
end Solve_Lower;
function Permute_Row (X : in Real_Vector;
P : in Int_Array) return Real_Vector is
Y : Real_Vector (X'Range);
begin
for I in P'Range loop
Y (I) := X (P (I));
end loop;
return Y;
end Permute_Row;
function Solve (P : in Int_Array;
L : in Real_Matrix;
U : in Real_Matrix;
B : in Real_Vector) return Real_Vector is
Pb : Real_Vector := Permute_Row (B, P);
Y : Real_Vector (1 .. B'Length);
begin
Y := Solve_Lower (L, Pb);
return Solve_Upper (U, Y);
end Solve;
function Solve (A : in Real_Matrix;
B : in Real_Vector) return Real_Vector is
P : Int_Array (1 .. A'Length (1));
L : Real_Matrix (1 .. A'Length (1), 1 .. A'Length (2));
U : Real_Matrix (1 .. A'Length (1), 1 .. A'Length (2));
begin
LU_Decomposition (A, P, L, U);
return Solve (P, L, U, B);
end Solve;
function Inverse (A : in Real_Matrix) return Real_Matrix is
P : Int_Array (1 .. A'Length (1));
X : Real_Vector (1 .. A'Length (1));
L : Real_Matrix (1 .. A'Length (1), 1 .. A'Length (2));
U : Real_Matrix (1 .. A'Length (1), 1 .. A'Length (2));
Inv : Real_Matrix (1 .. A'Length (1), 1 .. A'Length (2));
begin
LU_Decomposition (A, P, L, U);
pragma Assert (Determinant (P, L, U) /= 0.0, "Error: matrix is singular");
for I in X'Range loop
for Item of X loop Item := 0.0; end loop;
X (I) := 1.0;
X := Solve (P, L, U, X);
for J in X'Range loop
Inv (J, I) := X (J);
end loop;
end loop;
return Inv;
end Inverse;
function "and" (A, B : in Real_Matrix) return Real_Matrix is
Offset_1 : constant Integer := 1 - A'First (1) - B'First (1);
Offset_2 : constant Integer := 1 - A'First (2) - B'First (2);
Al_1 : constant Nat := A'Length (1);
Al_2 : constant Nat := A'Length (2);
Bl_1 : constant Nat := B'Length (1);
Bl_2 : constant Nat := B'Length (2);
C : Real_Matrix (1 .. Al_1 * Bl_1, 1 .. Al_2 * Bl_2);
begin
for Ai in A'Range (1) loop
for Bi in B'Range (1) loop
for Aj in A'Range (2) loop
for Bj in B'Range (2) loop
C (Bl_1 * (Ai - A'First (1)) + Bi,
Bl_2 * (Aj - A'First (2)) + Bj)
:= A (Ai, Aj) * B (Bi, Bj);
end loop;
end loop;
end loop;
end loop;
return C;
end "and";
function "or" (A, B : in Real_Matrix) return Real_Matrix is
Al_1 : constant Nat := A'Length (1);
Al_2 : constant Nat := A'Length (2);
Bl_1 : constant Nat := B'Length (1);
Bl_2 : constant Nat := B'Length (2);
C : Real_Matrix (1 .. Al_1 + Bl_1, 1 .. Al_2 + Bl_2)
:= (others => (others => 0.0));
begin
for I in A'Range (1) loop
for J in A'Range (2) loop
C (I + 1 - A'First (1), J + 1 - A'First (2)) := A (I, J);
end loop;
end loop;
for I in B'Range (1) loop
for J in B'Range (2) loop
C (Al_1 + I + 1 - B'First (1),
Al_2 + J + 1 - B'First (2))
:= B (I, J);
end loop;
end loop;
return C;
end "or";
function Remove_1st_N (X : in Real_Vector;
N : in Pos) return Real_Vector is
Y : Real_Vector (1 .. X'Length - N);
begin
for I in Y'Range loop
Y (I) := X (X'First - 1 + I + N);
end loop;
return Y;
end Remove_1st_N;
function Remove_1st_N (A : in Real_Matrix;
N : in Pos) return Real_Matrix is
B : Real_Matrix (1 .. A'Length (1) - N,
1 .. A'Length (2) - N);
begin
for I in B'Range (1) loop
for J in B'Range (2) loop
B (I, J) := A (A'First (1) - 1 + I + N,
A'First (2) - 1 + J + N);
end loop;
end loop;
return B;
end Remove_1st_N;
procedure Copy (From : in Real_Vector;
To : in out Real_Vector;
Start : in Pos) is
begin
for I in From'Range loop
To (I + Start - From'First) := From (I);
end loop;
end Copy;
procedure Copy (From : in Real_Matrix;
To : in out Real_Matrix;
Start_I : in Pos;
Start_J : in Pos) is
begin
for I in From'Range (1) loop
for J in From'Range (2) loop
To (I + Start_I - From'First (1), J + Start_J - From'First (2))
:= From (I, J);
end loop;
end loop;
end Copy;
end Numerics.Dense_Matrices;
|
-- REST API Validation
-- API to validate
--
-- The version of the OpenAPI document: 1.0.0
-- Contact: Stephane.Carrez@gmail.com
--
-- NOTE: This package is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
-- https://openapi-generator.tech
-- Do not edit the class manually.
pragma Warnings (Off, "*is not referenced");
with Swagger.Streams;
package body TestAPI.Clients is
pragma Style_Checks ("-mr");
--
-- Query an orchestrated service instance
procedure Orch_Store
(Client : in out Client_Type;
Inline_Object_3Type : in TestAPI.Models.InlineObject3_Type) is
URI : Swagger.Clients.URI_Type;
Req : Swagger.Clients.Request_Type;
begin
Client.Initialize (Req, (1 => Swagger.Clients.APPLICATION_JSON));
TestAPI.Models.Serialize (Req.Stream, "", Inline_Object_3Type);
URI.Set_Path ("/orchestration");
Client.Call (Swagger.Clients.POST, URI, Req);
end Orch_Store;
--
procedure Test_Text_Response
(Client : in out Client_Type;
Options : in Swagger.Nullable_UString;
Result : out Swagger.UString) is
URI : Swagger.Clients.URI_Type;
Reply : Swagger.Value_Type;
begin
Client.Set_Accept ((1 => Swagger.Clients.TEXT_PLAIN));
URI.Add_Param ("options", Options);
URI.Set_Path ("/testTextResponse");
Client.Call (Swagger.Clients.GET, URI, Reply);
Swagger.Streams.Deserialize (Reply, "", Result);
end Test_Text_Response;
-- Create a ticket
procedure Do_Create_Ticket
(Client : in out Client_Type;
Title : in Swagger.UString;
Owner : in Swagger.Nullable_UString;
Status : in Swagger.Nullable_UString;
Description : in Swagger.Nullable_UString) is
URI : Swagger.Clients.URI_Type;
Req : Swagger.Clients.Request_Type;
begin
Client.Initialize (Req, (1 => Swagger.Clients.APPLICATION_FORM));
Req.Stream.Write_Entity ("owner", Owner);
Req.Stream.Write_Entity ("status", Status);
Req.Stream.Write_Entity ("title", Title);
Req.Stream.Write_Entity ("description", Description);
URI.Set_Path ("/tickets");
Client.Call (Swagger.Clients.POST, URI, Req);
end Do_Create_Ticket;
-- Delete a ticket
procedure Do_Delete_Ticket
(Client : in out Client_Type;
Tid : in Swagger.Long) is
URI : Swagger.Clients.URI_Type;
begin
URI.Set_Path ("/tickets/{tid}");
URI.Set_Path_Param ("tid", Swagger.To_String (Tid));
Client.Call (Swagger.Clients.DELETE, URI);
end Do_Delete_Ticket;
-- List the tickets
procedure Do_Head_Ticket
(Client : in out Client_Type) is
URI : Swagger.Clients.URI_Type;
begin
URI.Set_Path ("/tickets");
Client.Call (Swagger.Clients.HEAD, URI);
end Do_Head_Ticket;
-- Patch a ticket
procedure Do_Patch_Ticket
(Client : in out Client_Type;
Tid : in Swagger.Long;
Owner : in Swagger.Nullable_UString;
Status : in Swagger.Nullable_UString;
Title : in Swagger.Nullable_UString;
Description : in Swagger.Nullable_UString;
Result : out TestAPI.Models.Ticket_Type) is
URI : Swagger.Clients.URI_Type;
Req : Swagger.Clients.Request_Type;
Reply : Swagger.Value_Type;
begin
Client.Set_Accept ((1 => Swagger.Clients.APPLICATION_JSON));
Client.Initialize (Req, (1 => Swagger.Clients.APPLICATION_FORM));
Req.Stream.Write_Entity ("owner", Owner);
Req.Stream.Write_Entity ("status", Status);
Req.Stream.Write_Entity ("title", Title);
Req.Stream.Write_Entity ("description", Description);
URI.Set_Path ("/tickets/{tid}");
URI.Set_Path_Param ("tid", Swagger.To_String (Tid));
Client.Call (Swagger.Clients.PATCH, URI, Req, Reply);
TestAPI.Models.Deserialize (Reply, "", Result);
end Do_Patch_Ticket;
-- Update a ticket
procedure Do_Update_Ticket
(Client : in out Client_Type;
Tid : in Swagger.Long;
Owner : in Swagger.Nullable_UString;
Status : in Swagger.Nullable_UString;
Title : in Swagger.Nullable_UString;
Description : in Swagger.Nullable_UString;
Result : out TestAPI.Models.Ticket_Type) is
URI : Swagger.Clients.URI_Type;
Req : Swagger.Clients.Request_Type;
Reply : Swagger.Value_Type;
begin
Client.Set_Accept ((1 => Swagger.Clients.APPLICATION_JSON));
Client.Initialize (Req, (1 => Swagger.Clients.APPLICATION_FORM));
Req.Stream.Write_Entity ("owner", Owner);
Req.Stream.Write_Entity ("status", Status);
Req.Stream.Write_Entity ("title", Title);
Req.Stream.Write_Entity ("description", Description);
URI.Set_Path ("/tickets/{tid}");
URI.Set_Path_Param ("tid", Swagger.To_String (Tid));
Client.Call (Swagger.Clients.PUT, URI, Req, Reply);
TestAPI.Models.Deserialize (Reply, "", Result);
end Do_Update_Ticket;
-- Get a ticket
-- Get a ticket
procedure Do_Get_Ticket
(Client : in out Client_Type;
Tid : in Swagger.Long;
Result : out TestAPI.Models.Ticket_Type) is
URI : Swagger.Clients.URI_Type;
Reply : Swagger.Value_Type;
begin
Client.Set_Accept ((1 => Swagger.Clients.APPLICATION_JSON));
URI.Set_Path ("/tickets/{tid}");
URI.Set_Path_Param ("tid", Swagger.To_String (Tid));
Client.Call (Swagger.Clients.GET, URI, Reply);
TestAPI.Models.Deserialize (Reply, "", Result);
end Do_Get_Ticket;
-- List the tickets
-- List the tickets created for the project.
procedure Do_List_Tickets
(Client : in out Client_Type;
Status : in Swagger.Nullable_UString;
Owner : in Swagger.Nullable_UString;
Result : out TestAPI.Models.Ticket_Type_Vectors.Vector) is
URI : Swagger.Clients.URI_Type;
Reply : Swagger.Value_Type;
begin
Client.Set_Accept ((1 => Swagger.Clients.APPLICATION_JSON));
URI.Add_Param ("status", Status);
URI.Add_Param ("owner", Owner);
URI.Set_Path ("/tickets");
Client.Call (Swagger.Clients.GET, URI, Reply);
TestAPI.Models.Deserialize (Reply, "", Result);
end Do_List_Tickets;
-- Get a ticket
-- Get a ticket
procedure Do_Options_Ticket
(Client : in out Client_Type;
Tid : in Swagger.Long;
Result : out TestAPI.Models.Ticket_Type) is
URI : Swagger.Clients.URI_Type;
Reply : Swagger.Value_Type;
begin
Client.Set_Accept ((1 => Swagger.Clients.APPLICATION_JSON));
URI.Set_Path ("/tickets/{tid}");
URI.Set_Path_Param ("tid", Swagger.To_String (Tid));
Client.Call (Swagger.Clients.OPTIONS, URI, Reply);
TestAPI.Models.Deserialize (Reply, "", Result);
end Do_Options_Ticket;
end TestAPI.Clients;
|
------------------------------------------------------------------------------
-- G E L A A S I S --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of this file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $:
with Asis.Elements;
with Asis.Statements;
with Asis.Extensions;
with Asis.Expressions;
with Asis.Gela.Debug;
with Asis.Gela.Errors;
with Asis.Definitions;
with Asis.Declarations;
with Asis.Gela.Classes;
with Asis.Gela.Replace;
with Asis.Gela.Resolver;
with Asis.Gela.Overloads.Walk;
with Asis.Gela.Overloads.Iters;
with Asis.Gela.Overloads.Types;
with Asis.Gela.Elements.Assoc;
with Asis.Gela.Element_Utils;
with XASIS.Utils;
with XASIS.Types;
with XASIS.Static;
package body Asis.Gela.Overloads is
use Asis.Elements;
use Asis.Declarations;
use Asis.Gela.Classes;
use Asis.Gela.Overloads.Types;
type Expected_Kinds is (Some_Type, Some_Range, Any_Discrete_Range,
Any_Numeric_Type, Any_Integer_Type, Any_Real_Type, Any_Boolean_Type,
Any_Discrete_Type, Any_Type, A_Call_Statement, A_Callable_Name,
A_Requeue, Any_Nonlimited);
procedure Resolve_To
(Element : in out Asis.Element;
Expect : in Expected_Kinds;
Tipe : in Type_Info := Not_A_Type;
Profile : in Asis.Declaration := Asis.Nil_Element);
procedure Resolve_In_Declaration
(Element : in out Asis.Element;
Parent : in Asis.Declaration);
procedure Resolve_In_Definition
(Element : in out Asis.Element;
Parent : in Asis.Definition);
procedure Resolve_In_Statement
(Element : in out Asis.Element;
Parent : in Asis.Statement);
procedure Resolve_Definition
(Element : in out Asis.Definition);
procedure Resolve_In_Enum_Rep_Clause
(Element : in out Asis.Element;
Parent : in Asis.Clause);
procedure Resolve_In_Component_Clause
(Element : in out Asis.Element;
Parent : in Asis.Clause);
function Find_Subtype_Of_Constraint (Element : Asis.Definition)
return Asis.Subtype_Indication;
function Is_Part_Of_Signed_Type (Element : Asis.Constraint) return Boolean;
function Is_Part_Of_Float_Type (Element : Asis.Constraint) return Boolean;
function Is_Part_Of_Fixed_Type (Element : Asis.Constraint) return Boolean;
function Resolve_Discriminant_Names
(Info : Type_Info;
Names : Asis.Expression_List;
Index : Asis.List_Index) return Type_Info;
function Find_Variant_Discriminant (Item : Asis.Variant)
return Asis.Declaration;
function Find_Part_Discriminant (Part : Asis.Definition)
return Asis.Declaration;
function Find_Discriminant
(List : Asis.Discriminant_Specification_List;
Image : Asis.Program_Text) return Asis.Declaration;
function Find_Case_Type (Element : Asis.Path) return Type_Info;
function Is_Resolved
(Info : Type_Info;
Item : Asis.Element) return Boolean;
function Is_Timed_Entry_Call (Element : Asis.Element) return Boolean;
function Is_Conditional_Entry_Call
(Element : Asis.Element) return Boolean;
function First_Statement_Kind (Path : Asis.Element) return Statement_Kinds;
procedure Check_No_Guards
(Path : Asis.Element;
Item : Wide_String);
function Parent_Of_Requeue (Element : Asis.Statement) return Asis.Element;
procedure Set_Representation_Value (Element : Asis.Representation_Clause);
---------------------
-- Check_No_Guards --
---------------------
procedure Check_No_Guards
(Path : Asis.Element;
Item : Wide_String)
is
The_Guard : Asis.Element := Guard (Path.all);
begin
if Assigned (The_Guard) then
Errors.Report (Item => Path, -- The_Guard,
What => Errors.Error_Syntax_Guard_Exists,
Argument1 => Item);
end if;
end Check_No_Guards;
--------------------
-- Find_Case_Type --
--------------------
function Find_Case_Type (Element : Asis.Path) return Type_Info is
Parent : Asis.Element := Enclosing_Element (Element);
Expr : Asis.Expression :=
Asis.Statements.Case_Expression (Parent);
Decl : Asis.Declaration :=
Asis.Expressions.Corresponding_Expression_Type (Expr);
begin
return Type_From_Declaration (Decl, Element);
end Find_Case_Type;
-----------------------
-- Find_Discriminant --
-----------------------
function Find_Discriminant
(List : Asis.Discriminant_Specification_List;
Image : Asis.Program_Text) return Asis.Declaration
is
begin
for K in List'Range loop
if XASIS.Utils.Has_Defining_Name (List (K), Image) then
return List (K);
end if;
end loop;
return Asis.Nil_Element;
end Find_Discriminant;
--------------------------------
-- Find_Subtype_Of_Constraint --
--------------------------------
function Find_Subtype_Of_Constraint (Element : Asis.Definition)
return Asis.Subtype_Indication
is
Parent : Asis.Element := Enclosing_Element (Element);
begin
if Definition_Kind (Parent) = A_Constraint then
Parent := Enclosing_Element (Parent);
end if;
if Element_Kind (Parent) = An_Expression then
return Asis.Nil_Element;
end if;
case Definition_Kind (Parent) is
when A_Subtype_Indication | A_Discrete_Subtype_Definition |
A_Discrete_Range =>
return Parent;
when A_Type_Definition =>
return Asis.Nil_Element;
when others =>
raise Internal_Error;
end case;
end Find_Subtype_Of_Constraint;
----------------------------
-- Find_Part_Discriminant --
----------------------------
function Find_Part_Discriminant (Part : Asis.Definition)
return Asis.Declaration
is
use Asis.Definitions;
Ident : Asis.Identifier := Discriminant_Direct_Name (Part);
Decl : Asis.Declaration := XASIS.Utils.Parent_Declaration (Part);
Discr : Asis.Definition := Discriminant_Part (Decl);
begin
if Definition_Kind (Discr) /= A_Known_Discriminant_Part then
return Asis.Nil_Element;
end if;
declare
List : Asis.Declaration_List :=
Asis.Definitions.Discriminants (Discr);
begin
return Find_Discriminant (List, XASIS.Utils.Name_Image (Ident));
end;
end Find_Part_Discriminant;
-------------------------------
-- Find_Variant_Discriminant --
-------------------------------
function Find_Variant_Discriminant (Item : Asis.Variant)
return Asis.Declaration
is
Part : Asis.Definition := Enclosing_Element (Item);
begin
return Find_Part_Discriminant (Part);
end Find_Variant_Discriminant;
--------------------------
-- First_Statement_Kind --
--------------------------
function First_Statement_Kind (Path : Asis.Element) return Statement_Kinds
is
List : Asis.Element_List := Sequence_Of_Statements (Path.all, False);
begin
return Statement_Kind (List (1).all);
end First_Statement_Kind;
----------------------------
-- Is_Part_Of_Signed_Type --
----------------------------
function Is_Part_Of_Signed_Type (Element : Asis.Constraint) return Boolean
is
Parent : constant Asis.Element := Enclosing_Element (Element);
begin
return Type_Kind (Parent) = A_Signed_Integer_Type_Definition;
end Is_Part_Of_Signed_Type;
---------------------------
-- Is_Part_Of_Float_Type --
---------------------------
function Is_Part_Of_Float_Type (Element : Asis.Constraint) return Boolean
is
Parent : constant Asis.Element := Enclosing_Element (Element);
begin
return Type_Kind (Parent) = A_Floating_Point_Definition;
end Is_Part_Of_Float_Type;
---------------------------
-- Is_Part_Of_Fixed_Type --
---------------------------
function Is_Part_Of_Fixed_Type (Element : Asis.Constraint) return Boolean
is
Parent : constant Asis.Element := Enclosing_Element (Element);
Kind : constant Asis.Type_Kinds := Type_Kind (Parent);
begin
return Kind = An_Ordinary_Fixed_Point_Definition
or Kind = A_Decimal_Fixed_Point_Definition;
end Is_Part_Of_Fixed_Type;
-------------------------------
-- Is_Conditional_Entry_Call --
-------------------------------
function Is_Conditional_Entry_Call
(Element : Asis.Element) return Boolean
is
Path : constant Asis.Element_List := Statement_Paths (Element.all);
begin
if Path'Length = 2
and then Path_Kind (Path (1).all) = A_Select_Path
and then Path_Kind (Path (2).all) = An_Else_Path
and then First_Statement_Kind (Path (1)) = An_Entry_Call_Statement
then
Check_No_Guards (Path (1), "Conditional_Entry_Call");
return True;
end if;
return False;
end Is_Conditional_Entry_Call;
-------------------------
-- Is_Timed_Entry_Call --
-------------------------
function Is_Timed_Entry_Call (Element : Asis.Element) return Boolean is
Path : constant Asis.Element_List := Statement_Paths (Element.all);
begin
if Path'Length = 2
and then Path_Kind (Path (1).all) = A_Select_Path
and then Path_Kind (Path (2).all) = An_Or_Path
and then First_Statement_Kind (Path (1)) = An_Entry_Call_Statement
and then First_Statement_Kind (Path (2)) in
A_Delay_Until_Statement .. A_Delay_Relative_Statement
then
Check_No_Guards (Path (1), "Timed_Entry_Call");
Check_No_Guards (Path (2), "Timed_Entry_Call");
return True;
end if;
return False;
end Is_Timed_Entry_Call;
-----------------
-- Is_Resolved --
-----------------
function Is_Resolved
(Info : Type_Info;
Item : Asis.Element) return Boolean is
begin
if Is_Not_Type (Info) then
Errors.Report (Item, Errors.Error_Unknown_Type);
return False;
end if;
return True;
end Is_Resolved;
-----------------------
-- Parent_Of_Requeue --
-----------------------
function Parent_Of_Requeue (Element : Asis.Statement) return Asis.Element is
Parent : Asis.Element := Element;
begin
while not Is_Nil (Parent)
and then Statement_Kind (Parent) /= An_Accept_Statement
and then Declaration_Kind (Parent) /= An_Entry_Body_Declaration
loop
Parent := Enclosing_Element (Parent);
end loop;
return Parent;
end Parent_Of_Requeue;
-------------
-- Resolve --
-------------
procedure Resolve (Item : in out Asis.Element) is
begin
if Is_Part_Of_Implicit (Item) then
return;
end if;
case Element_Kind (Item) is
when An_Association =>
declare
Parent_2 : Asis.Element :=
Enclosing_Element (Enclosing_Element (Item));
Kind : Asis.Representation_Clause_Kinds
:= Representation_Clause_Kind (Parent_2);
begin
case Kind is
when An_Enumeration_Representation_Clause =>
Resolve_In_Enum_Rep_Clause (Item, Parent_2);
when others =>
null;
end case;
end;
when A_Declaration =>
case Declaration_Kind (Item) is
when An_Integer_Number_Declaration =>
declare
use Asis.Expressions;
Expr : Asis.Expression :=
Initialization_Expression (Item);
Tipe : Asis.Declaration;
Info : Type_Info;
begin
Tipe := Corresponding_Expression_Type (Expr);
Info := Type_From_Declaration (Tipe, Expr);
if Is_Real (Info) then
Replace.Integer_Real_Number (Item);
end if;
end;
when A_Real_Number_Declaration =>
raise Internal_Error; -- go to An_Integer_Number_Declaration
when others =>
null;
end case;
when An_Expression =>
declare
Parent : Asis.Element := Enclosing_Element (Item);
Kind : Asis.Element_Kinds := Element_Kind (Parent);
begin
case Kind is
when An_Association =>
declare
Parent_2 : Asis.Element :=
Enclosing_Element (Enclosing_Element (Parent));
Kind : Asis.Representation_Clause_Kinds
:= Representation_Clause_Kind (Parent_2);
begin
case Kind is
when An_Enumeration_Representation_Clause =>
Resolve_In_Enum_Rep_Clause (Item, Parent_2);
when others =>
null;
end case;
end;
when A_Declaration =>
Resolve_In_Declaration (Item, Parent);
when A_Definition =>
Resolve_In_Definition (Item, Parent);
when A_Path =>
case Path_Kind (Parent) is
when An_If_Path | An_Elsif_Path =>
Resolve_To (Item, Any_Boolean_Type);
when A_Case_Path =>
Resolve_To (Item, Some_Type,
Find_Case_Type (Parent));
when others =>
null;
end case;
when A_Statement =>
Resolve_In_Statement (Item, Parent);
when A_Clause =>
case Clause_Kind (Parent) is
when A_Component_Clause =>
Resolve_In_Component_Clause (Item, Parent);
when others =>
null;
end case;
when others =>
null;
end case;
end;
when A_Definition =>
Resolve_Definition (Item);
when A_Statement =>
case Statement_Kind (Item) is
when An_Assignment_Statement =>
Resolve_To (Item, Any_Type);
when A_Procedure_Call_Statement =>
Resolve_To (Item, A_Call_Statement);
when A_Selective_Accept_Statement =>
if Is_Timed_Entry_Call (Item) then
Replace.To_Timed_Entry_Call (Item);
elsif Is_Conditional_Entry_Call(Item) then
Replace.To_Conditional_Entry_Call (Item);
end if;
when others =>
null;
end case;
when A_Clause =>
case Clause_Kind (Item) is
when A_Representation_Clause =>
case Representation_Clause_Kind (Item) is
when An_Enumeration_Representation_Clause =>
Set_Representation_Value (Item);
when others =>
null;
end case;
when others =>
null;
end case;
when others =>
null;
end case;
end Resolve;
------------------------
-- Resolve_Definition --
------------------------
procedure Resolve_Definition
(Element : in out Asis.Definition)
is
Kind : Asis.Definition_Kinds := Definition_Kind (Element);
Constr : Asis.Constraint;
Parent : Asis.Element;
begin
case Kind is
when A_Discrete_Subtype_Definition =>
case Discrete_Range_Kind (Element) is
when A_Discrete_Range_Attribute_Reference |
A_Discrete_Simple_Expression_Range =>
-- Parent := Definition_Kind (Enclosing_Element (Element));
Resolve_To (Element, Any_Discrete_Range);
when others =>
null;
end case;
when A_Subtype_Indication =>
Constr := Asis.Definitions.Subtype_Constraint (Element);
case Constraint_Kind (Constr) is
when An_Index_Constraint =>
declare
Info : Type_Info :=
Type_From_Indication (Element, Element);
List : Asis.Discrete_Range_List :=
Asis.Definitions.Discrete_Ranges (Constr);
begin
if Is_Resolved (Info, Element) then
for I in List'Range loop
if Discrete_Range_Kind (List (I)) in
A_Discrete_Range_Attribute_Reference ..
A_Discrete_Simple_Expression_Range
then
Resolve_To (List (I), Some_Range,
Get_Array_Index_Type (Info, I));
end if;
end loop;
end if;
end;
when A_Discriminant_Constraint =>
declare
Info : Type_Info :=
Type_From_Indication (Element, Element);
List : Asis.Discriminant_Association_List :=
Asis.Definitions.Discriminant_Associations (Constr);
begin
if Is_Resolved (Info, Element) then
for I in List'Range loop
declare
use Asis.Expressions;
use Asis.Gela.Elements.Assoc;
Expr : Asis.Expression :=
Discriminant_Expression (List (I));
Saved : Asis.Expression := Expr;
Names : Asis.Expression_List :=
Discriminant_Selector_Names (List (I));
Tipe : Type_Info :=
Resolve_Discriminant_Names (Info, Names, I);
begin
if Is_Not_Type (Tipe) then
return;
end if;
Resolve_To (Expr, Some_Type, Tipe);
if not Is_Equal (Expr, Saved) then
Set_Discriminant_Expression
(Discriminant_Association_Node
(List (I).all),
Expr);
end if;
end;
end loop;
end if;
end;
when others =>
null;
end case;
when A_Discrete_Range =>
Parent := Enclosing_Element (Element);
if Definition_Kind (Parent) = A_Variant then
declare
Discr : Asis.Declaration :=
Find_Variant_Discriminant (Parent);
Info : Type_Info;
begin
if Assigned (Discr) then
Info := Type_Of_Declaration (Discr, Element);
if Is_Resolved (Info, Discr) then
Resolve_To (Element, Some_Range, Info);
end if;
end if;
end;
elsif Path_Kind (Parent) = A_Case_Path then
declare
Info : Type_Info := Find_Case_Type (Parent);
begin
if Is_Resolved (Info, Parent) then
Resolve_To (Element, Some_Range, Info);
end if;
end;
end if;
when others =>
null;
end case;
end Resolve_Definition;
--------------------------------
-- Resolve_Discriminant_Names --
--------------------------------
function Resolve_Discriminant_Names
(Info : Type_Info;
Names : Asis.Expression_List;
Index : Asis.List_Index) return Type_Info
is
Result : Type_Info;
Found : Boolean := False;
Decl : Asis.Declaration := Get_Declaration (Info);
Place : Asis.Element := Get_Place (Info);
Part : Asis.Definition := Discriminant_Part (Decl);
begin
if Definition_Kind (Part) /= A_Known_Discriminant_Part then
return Result;
end if;
declare
List : Asis.Declaration_List :=
Asis.Definitions.Discriminants (Part);
begin
for J in Names'Range loop
declare
Image : Asis.Program_Text := XASIS.Utils.Name_Image (Names (J));
Discr : Asis.Declaration := Find_Discriminant (List, Image);
Name : Asis.Expression := Names (J);
begin
if Assigned (Discr) then
if not Found then
Result := Type_Of_Declaration (Discr, Place);
Found := True;
end if;
Walk.Set_Declaration (Name, Discr);
end if;
end;
end loop;
if Names'Length = 0 and Index in List'Range then
Result := Type_Of_Declaration (List (Index), Place);
end if;
end;
return Result;
end Resolve_Discriminant_Names;
---------------------------------
-- Resolve_In_Component_Clause --
---------------------------------
procedure Resolve_In_Component_Clause
(Element : in out Asis.Element;
Parent : in Asis.Clause)
is
Name : Asis.Name := Representation_Clause_Name (Parent.all);
begin
if not Is_Equal (Element, Name) then
Resolve_To (Element, Any_Integer_Type);
end if;
end Resolve_In_Component_Clause;
----------------------------
-- Resolve_In_Declaration --
----------------------------
procedure Resolve_In_Declaration
(Element : in out Asis.Element;
Parent : in Asis.Declaration)
is
Kind : Asis.Declaration_Kinds := Declaration_Kind (Parent);
begin
case Kind is
when An_Integer_Number_Declaration =>
Resolve_To (Element, Any_Numeric_Type);
when A_Variable_Declaration |
A_Constant_Declaration |
A_Component_Declaration =>
declare
Info : Type_Info := Type_Of_Declaration (Parent, Element);
begin
if Is_Resolved (Info, Parent) then
Resolve_To (Element, Some_Type, Info);
end if;
end;
when A_Discriminant_Specification |
A_Parameter_Specification |
A_Formal_Object_Declaration |
A_Return_Object_Specification =>
if Is_Equal (Initialization_Expression (Parent), Element) then
declare
Info : Type_Info := Type_Of_Declaration (Parent, Element);
begin
if Is_Resolved (Info, Parent) then
Resolve_To (Element, Some_Type, Info);
end if;
end;
end if;
when An_Object_Renaming_Declaration =>
if Is_Equal (Renamed_Entity (Parent), Element) then
declare
Info : Type_Info := Type_Of_Declaration (Parent, Element);
begin
if Is_Resolved (Info, Parent) then
Resolve_To (Element, Some_Type, Info);
end if;
end;
end if;
when A_Procedure_Renaming_Declaration |
A_Function_Renaming_Declaration =>
if Is_Equal (Renamed_Entity (Parent), Element) then
Resolve_To (Element, A_Callable_Name, Profile => Parent);
end if;
when A_Formal_Function_Declaration |
A_Formal_Procedure_Declaration =>
declare
Default : constant Asis.Expression :=
Formal_Subprogram_Default (Parent);
begin
if Is_Equal (Element, Default) and then
Expression_Kind (Element) /= Asis.A_Null_Literal
then
Resolve_To (Element, A_Callable_Name, Profile => Parent);
end if;
end;
when An_Entry_Body_Declaration =>
Resolve_To (Element, Any_Boolean_Type);
when others =>
null;
end case;
end Resolve_In_Declaration;
---------------------------
-- Resolve_In_Definition --
---------------------------
procedure Resolve_In_Definition
(Element : in out Asis.Element;
Parent : in Asis.Definition)
is
use Asis.Definitions;
Kind : Asis.Definition_Kinds := Definition_Kind (Parent);
begin
case Kind is
when A_Constraint =>
case Constraint_Kind (Parent) is
when A_Range_Attribute_Reference =>
declare
Ind : Asis.Subtype_Indication :=
Find_Subtype_Of_Constraint (Parent);
Info : Type_Info;
begin
if Assigned (Ind) then
Info := Type_From_Indication (Ind, Element);
if Is_Resolved (Info, Ind) then
Resolve_To (Element, Some_Range, Info);
end if;
end if;
end;
when A_Simple_Expression_Range =>
if Clause_Kind (Enclosing_Element (Parent))
= A_Component_Clause
then
Resolve_To (Element, Any_Integer_Type);
return;
end if;
declare
Ind : Asis.Subtype_Indication :=
Find_Subtype_Of_Constraint (Parent);
Info : Type_Info;
begin
if Assigned (Ind) then
Info := Type_From_Indication (Ind, Element);
if Is_Resolved (Info, Ind) then
Resolve_To (Element, Some_Type, Info);
end if;
elsif Is_Part_Of_Signed_Type (Parent) then
Resolve_To (Element, Any_Integer_Type);
elsif Is_Part_Of_Float_Type (Parent)
or Is_Part_Of_Fixed_Type (Parent)
then
Resolve_To (Element, Any_Real_Type);
end if;
end;
when A_Digits_Constraint =>
Resolve_To (Element, Any_Integer_Type);
when A_Delta_Constraint =>
Resolve_To (Element, Any_Real_Type);
when others =>
null;
end case;
when A_Type_Definition =>
case Type_Kind (Parent) is
when A_Modular_Type_Definition |
A_Floating_Point_Definition =>
Resolve_To (Element, Any_Integer_Type);
when An_Ordinary_Fixed_Point_Definition =>
Resolve_To (Element, Any_Real_Type);
when A_Decimal_Fixed_Point_Definition =>
if Is_Equal (Element, Delta_Expression (Parent)) then
Resolve_To (Element, Any_Real_Type);
else
Resolve_To (Element, Any_Integer_Type);
end if;
when others =>
null;
end case;
when A_Variant =>
declare
Discr : Asis.Declaration := Find_Variant_Discriminant (Parent);
Info : Type_Info;
begin
if Assigned (Discr) then
Info := Type_Of_Declaration (Discr, Element);
if Is_Resolved (Info, Discr) then
Resolve_To (Element, Some_Type, Info);
end if;
end if;
end;
when A_Variant_Part =>
declare
Discr : Asis.Declaration := Find_Part_Discriminant (Parent);
begin
if Assigned (Discr) then
Walk.Set_Declaration (Element, Discr);
end if;
end;
when others =>
null;
end case;
end Resolve_In_Definition;
--------------------------------
-- Resolve_In_Enum_Rep_Clause --
--------------------------------
procedure Resolve_In_Enum_Rep_Clause
(Element : in out Asis.Element;
Parent : in Asis.Clause)
is
Name : Asis.Element;
Info : Type_Info;
Assc : Asis.Element;
begin
if Element_Kind (Element.all) = An_Association then
Walk.Check_Association (Element);
return;
end if;
Assc := Enclosing_Element (Element.all);
if Is_Equal (Element, Component_Expression (Assc.all)) then
Resolve_To (Element, Any_Integer_Type);
Gela.Resolver.Polish_Subexpression (Element);
return;
end if;
Name := Representation_Clause_Name (Parent.all);
Info := Type_From_Subtype_Mark (Name, Element);
if Is_Resolved (Info, Name) then
Resolve_To (Element, Some_Type, Info);
end if;
end Resolve_In_Enum_Rep_Clause;
--------------------------
-- Resolve_In_Statement --
--------------------------
procedure Resolve_In_Statement
(Element : in out Asis.Element;
Parent : in Asis.Statement)
is
use Asis.Statements;
use Asis.Expressions;
begin
case Statement_Kind (Parent) is
when A_Case_Statement =>
Resolve_To (Element, Any_Discrete_Type);
when A_While_Loop_Statement =>
Resolve_To (Element, Any_Boolean_Type);
when An_Exit_Statement =>
if Is_Equal (Element, Exit_Condition (Parent)) then
Resolve_To (Element, Any_Boolean_Type);
end if;
when A_Return_Statement =>
declare
Decl : Asis.Declaration :=
XASIS.Utils.Parent_Declaration (Parent);
Mark : Asis.Definition :=
XASIS.Utils.Get_Result_Subtype (Decl);
Info : Type_Info :=
Type_From_Indication (Mark, Element);
begin
if Is_Resolved (Info, Mark) then
Resolve_To (Element, Some_Type, Info);
end if;
end;
when An_Accept_Statement =>
if Is_Equal (Element, Accept_Entry_Direct_Name (Parent)) then
Resolve_To (Element, A_Callable_Name, Profile => Parent);
elsif Is_Equal (Element, Accept_Entry_Index (Parent)) then
declare
Ident : Asis.Identifier := Accept_Entry_Direct_Name (Parent);
Decl : Asis.Declaration;
Def : Asis.Discrete_Subtype_Definition;
Info : Type_Info;
begin
if not Assigned (Ident) then
return;
end if;
Decl := Corresponding_Name_Declaration (Ident);
if not Assigned (Decl) then
return;
end if;
Def := Entry_Family_Definition (Decl);
Info := Type_From_Discrete_Def (Def, Element);
if Is_Resolved (Info, Def) then
Resolve_To (Element, Some_Type, Info);
end if;
end;
end if;
when A_Delay_Until_Statement =>
Resolve_To (Element, Any_Nonlimited);
when A_Delay_Relative_Statement =>
declare
Info : Type_Info :=
Type_From_Declaration (XASIS.Types.Duration, Element);
begin
if Is_Resolved (Info, XASIS.Types.Duration) then
Resolve_To (Element, Some_Type, Info);
end if;
end;
when A_Code_Statement =>
Resolve_To (Element, Any_Type);
when A_Requeue_Statement | A_Requeue_Statement_With_Abort =>
declare
Decl : Asis.Element := Parent_Of_Requeue (Parent);
begin
Resolve_To (Element, A_Requeue, Profile => Decl);
end;
when A_Raise_Statement =>
if Is_Equal (Element, Raise_Statement_Message (Parent)) then
declare
Info : Type_Info :=
Type_From_Declaration (XASIS.Types.String, Element);
begin
Resolve_To (Element, Some_Type, Info);
end;
end if;
when others =>
null;
end case;
end Resolve_In_Statement;
----------------
-- Resolve_To --
----------------
procedure Resolve_To
(Element : in out Asis.Element;
Expect : in Expected_Kinds;
Tipe : in Type_Info := Not_A_Type;
Profile : in Asis.Declaration := Asis.Nil_Element)
is
use Asis.Gela.Overloads.Walk;
use Asis.Gela.Overloads.Iters;
Up : Up_Resolver;
Down : Down_Resolver;
Control : Traverse_Control := Continue;
Set : Up_Interpretation_Set;
Result : Up_Interpretation;
Impl : Implicit_Set;
begin
Up_Iterator.Walk_Element (Element, Control, Up);
Set := Get_Interpretations (Up);
Impl := Get_Implicits (Up);
case Expect is
when Any_Numeric_Type =>
Constrain_To_Numeric_Types (Set, Impl, Element);
when Any_Integer_Type =>
Constrain_To_Integer_Types (Set, Impl, Element);
when Any_Real_Type =>
Constrain_To_Real_Types (Set, Impl, Element);
when Some_Type =>
Constrain_To_Type (Set, Impl, Element, Tipe);
when Some_Range =>
Constrain_To_Range (Set, Impl, Element, Tipe);
when Any_Discrete_Range =>
Constrain_To_Discrete_Range (Set, Impl, Element);
when Any_Boolean_Type =>
Constrain_To_Boolean_Types (Set, Impl, Element);
when Any_Discrete_Type =>
Constrain_To_Discrete_Types (Set, Impl, Element);
when Any_Type =>
null;
when A_Call_Statement =>
Constrain_To_Calls (Set);
when A_Callable_Name =>
Constrain_To_Expected_Profile (Set, Profile, Element);
when Any_Nonlimited =>
Constrain_To_Non_Limited_Types (Set, Impl, Element);
when A_Requeue =>
Constrain_To_Expected_Profile (Set, Profile, Element, True);
end case;
Select_Prefered (Set);
pragma Assert (Debug.Run (Element, Debug.Overload) or else
Debug.Dump (Types.Image (Set)));
if Has_Interpretation (Set, Element) then
if Expect = Some_Type then
Result := Up_Expression (Tipe);
else
Get (Set, 1, Result);
end if;
Set_Interpretation (Down, To_Down_Interpretation (Result));
Copy_Store_Set (Up, Down);
Down_Iterator.Walk_Element (Element, Control, Down, False);
end if;
Destroy_Store_Set (Up);
Destroy (Set);
Destroy (Impl);
end Resolve_To;
------------------------------
-- Set_Representation_Value --
------------------------------
procedure Set_Representation_Value (Element : Asis.Representation_Clause) is
Name : Asis.Name := Representation_Clause_Name (Element.all);
Info : Type_Info := Type_From_Subtype_Mark (Name, Element);
View : Asis.Definition;
Aggr : Asis.Expression := Representation_Clause_Expression (Element.all);
Assc : Asis.Association_List := Array_Component_Associations (Aggr.all);
begin
if not Is_Enumeration (Info) then
return;
end if;
View := Get_Type_Def (Top_Parent_Type (Info));
declare
List : Asis.Declaration_List :=
Enumeration_Literal_Declarations (View.all);
Index : Asis.List_Index := 1;
begin
for J in Assc'Range loop
declare
use XASIS;
Enum : Asis.Declaration;
Expr : Asis.Expression := Component_Expression (Assc (J).all);
Val : Static.Value;
Choice : Asis.Expression_List :=
Array_Component_Choices (Assc (J).all);
begin
if Asis.Extensions.Is_Static_Expression (Expr) then
Val := Static.Evaluate (Expr);
if Choice'Length = 0 then
-- Enum := XASIS.Utils.Declaration_Name (List (Index));
Enum := List (Index);
Index := Index + 1;
else
Enum := Corresponding_Name_Declaration (Choice (1).all);
end if;
Element_Utils.Set_Representation_Value
(Enum, Static.Image (Val));
end if;
end;
end loop;
end;
end Set_Representation_Value;
end Asis.Gela.Overloads;
------------------------------------------------------------------------------
-- Copyright (c) 2006-2013, Maxim Reznik
-- 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 Maxim Reznik, 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 OWNER 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 generated by SWIG. Do *not* modify by hand.
--
with llvm;
with Interfaces.C.Strings;
package LLVM_Analysis.Binding is
function LLVMVerifyModule
(M : in llvm.LLVMModuleRef;
Action : in LLVM_Analysis.LLVMVerifierFailureAction;
OutMessage : access Interfaces.C.Strings.chars_ptr)
return Interfaces.C.int;
function LLVMVerifyFunction
(Fn : in llvm.LLVMValueRef;
Action : in LLVM_Analysis.LLVMVerifierFailureAction)
return Interfaces.C.int;
procedure LLVMViewFunctionCFG (Fn : in llvm.LLVMValueRef);
procedure LLVMViewFunctionCFGOnly (Fn : in llvm.LLVMValueRef);
private
pragma Import (C, LLVMVerifyModule, "Ada_LLVMVerifyModule");
pragma Import (C, LLVMVerifyFunction, "Ada_LLVMVerifyFunction");
pragma Import (C, LLVMViewFunctionCFG, "Ada_LLVMViewFunctionCFG");
pragma Import (C, LLVMViewFunctionCFGOnly, "Ada_LLVMViewFunctionCFGOnly");
end LLVM_Analysis.Binding;
|
-- ___ _ ___ _ _ --
-- / __| |/ (_) | | Common SKilL implementation --
-- \__ \ ' <| | | |__ type handling in skill --
-- |___/_|\_\_|_|____| by: Timm Felden --
-- --
pragma Ada_2012;
with Ada.Containers.Vectors;
with Ada.Unchecked_Conversion;
with Skill.Field_Types;
with Skill.Internal.Parts;
with Ada.Unchecked_Deallocation;
with Skill.Field_Declarations;
with Skill.Streams.Reader;
with Skill.Iterators.Dynamic_New_Instances;
with Skill.Iterators.Static_Data;
with Skill.Iterators.Type_Hierarchy_Iterator;
with Skill.Iterators.Type_Order;
-- pool realizations are moved to the pools.adb, because this way we can work
-- around several restrictions of the (generic) ada type system.
package body Skill.Types.Pools is
function Dynamic (This : access Pool_T) return Pool_Dyn is
type P is access all Pool_T;
function Convert is new Ada.Unchecked_Conversion (P, Pool_Dyn);
begin
return Convert (P (This));
end Dynamic;
function To_Pool (This : access Pool_T'Class) return Pool is
type T is access all Pool_T;
function Convert is new Ada.Unchecked_Conversion (T, Pool);
begin
return Convert (T (This));
end To_Pool;
-- pool properties
function To_String (This : Pool_T) return String is (This.Name.all);
function Skill_Name
(This : access Pool_T) return String_Access is
(This.Name);
function ID (This : access Pool_T) return Natural is (This.Type_Id);
function Base (This : access Pool_T'Class) return Base_Pool is (This.Base);
function Super (This : access Pool_T) return Pool is (This.Super);
function Next (This : access Pool_T'Class) return Pool is (This.Next);
procedure Establish_Next (This : access Base_Pool_T'Class) is
procedure Set_Next_Pool (This : access Pool_T'Class; Nx : Pool) is
begin
if This.Sub_Pools.Is_Empty then
This.Next := Nx;
else
This.Next := This.Sub_Pools.First_Element.To_Pool;
for I in 0 .. This.Sub_Pools.Length - 2 loop
Set_Next_Pool
(This.Sub_Pools.Element (I).To_Pool,
This.Sub_Pools.Element (I + 1).To_Pool);
end loop;
Set_Next_Pool (This.Sub_Pools.Last_Element, Nx);
end if;
end Set_Next_Pool;
begin
Set_Next_Pool (This, null);
end Establish_Next;
function Type_Hierarchy_Height
(This : access Pool_T'Class) return Natural is
(This.Super_Type_Count);
function Size (This : access Pool_T'Class) return Natural is
begin
if This.Fixed then
return This.Cached_Size;
end if;
declare
Size : Natural := 0;
Iter : aliased Skill.Iterators.Type_Hierarchy_Iterator.Iterator;
begin
Iter.Init (This.To_Pool);
while Iter.Has_Next loop
Size := Size + Iter.Next.Static_Size;
end loop;
return Size;
end;
end Size;
function Static_Size (This : access Pool_T'Class) return Natural is
begin
return This.Static_Data_Instances + Natural (This.New_Objects.Length);
end Static_Size;
function Static_Size_With_Deleted
(This : access Pool_T'Class) return Natural
is
begin
return This.Static_Data_Instances +
Natural (This.New_Objects.Length) -
This.Deleted_Count;
end Static_Size_With_Deleted;
function New_Objects_Size
(This : access Pool_T'Class) return Natural is
(This.New_Objects.Length);
function New_Objects_Element
(This : access Pool_T'Class;
Idx : Natural) return Annotation is
(This.New_Objects.Element (Idx));
procedure Fixed (This : access Pool_T'Class; Fix : Boolean) is
procedure Set (P : Sub_Pool) is
begin
Fixed (P, True);
This.Cached_Size := This.Cached_Size + P.Cached_Size;
end Set;
begin
if This.Fixed = Fix then
return;
end if;
This.Fixed := Fix;
if Fix then
This.Cached_Size := This.Static_Size_With_Deleted;
This.Sub_Pools.Foreach (Set'Access);
elsif This.Super /= null then
Fixed (This.Super, False);
end if;
end Fixed;
procedure Do_In_Type_Order
(This : access Pool_T'Class;
F : not null access procedure (I : Annotation))
is
Iter : aliased Skill.Iterators.Type_Order.Iterator;
begin
Iter.Init (This.To_Pool);
while Iter.Has_Next loop
F (Iter.Next);
end loop;
end Do_In_Type_Order;
procedure Do_For_Static_Instances
(This : access Pool_T'Class;
F : not null access procedure (I : Annotation))
is
Iter : aliased Skill.Iterators.Static_Data.Iterator :=
Skill.Iterators.Static_Data.Make (This.To_Pool);
begin
while Iter.Has_Next loop
F (Iter.Next);
end loop;
end Do_For_Static_Instances;
function First_Dynamic_New_Instance
(This : access Pool_T'Class) return Annotation
is
P : Pool := This.To_Pool;
begin
while P /= null loop
if P.New_Objects.Length > 0 then
return P.New_Objects.First_Element;
end if;
P := P.Next;
end loop;
return null;
end First_Dynamic_New_Instance;
function Blocks
(This : access Pool_T) return Skill.Internal.Parts.Blocks is
(This.Blocks);
function Data_Fields
(This : access Pool_T) return Skill.Field_Declarations.Field_Vector is
(This.Data_Fields_F);
-- internal use only
function Add_Field
(This : access Pool_T;
ID : Natural;
T : Field_Types.Field_Type;
Name : String_Access;
Restrictions : Field_Restrictions.Vector)
return Skill.Field_Declarations.Field_Declaration
is
function Convert is new Ada.Unchecked_Conversion
(Field_Declarations.Lazy_Field,
Field_Declarations.Field_Declaration);
type P is access all Pool_T;
function Convert is new Ada.Unchecked_Conversion
(P,
Field_Declarations.Owner_T);
F : Field_Declarations.Field_Declaration :=
Convert
(Skill.Field_Declarations.Make_Lazy_Field
(Convert (P (This)),
ID,
T,
Name,
Restrictions));
begin
F.Restrictions := Restrictions;
This.Data_Fields.Append (F);
return F;
end Add_Field;
function Add_Field
(This : access Base_Pool_T;
ID : Natural;
T : Field_Types.Field_Type;
Name : String_Access;
Restrictions : Field_Restrictions.Vector)
return Skill.Field_Declarations.Field_Declaration
is
type P is access all Pool_T;
function Convert is new Ada.Unchecked_Conversion (P, Pool);
begin
return Convert (P (This)).Add_Field (ID, T, Name, Restrictions);
end Add_Field;
function Add_Field
(This : access Sub_Pool_T;
ID : Natural;
T : Field_Types.Field_Type;
Name : String_Access;
Restrictions : Field_Restrictions.Vector)
return Skill.Field_Declarations.Field_Declaration
is
type P is access all Pool_T;
function Convert is new Ada.Unchecked_Conversion (P, Pool);
begin
return Convert (P (This)).Add_Field (ID, T, Name, Restrictions);
end Add_Field;
function Pool_Offset (This : access Pool_T'Class) return Integer is
begin
return This.Type_Id - 32;
end Pool_Offset;
function Sub_Pools
(This : access Pool_T'Class) return Sub_Pool_Vector is
(This.Sub_Pools);
function Known_Fields
(This : access Pool_T'Class) return String_Access_Array_Access is
(This.Known_Fields);
-- base pool properties
-- internal use only
function Data
(This : access Base_Pool_T) return Skill.Types.Annotation_Array is
(This.Data);
procedure Compress
(This : access Base_Pool_T'Class;
Lbpo_Map : Skill.Internal.Lbpo_Map_T)
is
D : Annotation_Array := new Annotation_Array_T (1 .. This.Size);
P : Skill_ID_T := 1;
procedure Update (I : Annotation) is
begin
if 0 /= I.Skill_ID then
D (P) := I;
I.Skill_ID := P;
P := P + 1;
end if;
end Update;
begin
This.Do_In_Type_Order (Update'Access);
This.Data := D;
This.Update_After_Compress (Lbpo_Map);
end Compress;
procedure Update_After_Compress
(This : access Pool_T'Class;
Lbpo_Map : Skill.Internal.Lbpo_Map_T)
is
procedure Reset (D : Field_Declarations.Field_Declaration) is
use type Interfaces.Integer_64;
begin
D.Data_Chunks.Clear;
D.Add_Chunk
(new Internal.Parts.Bulk_Chunk'(-1, -1, This.Cached_Size, 1));
end Reset;
begin
This.Static_Data_Instances :=
This.Static_Data_Instances +
This.New_Objects.Length -
This.Deleted_Count;
This.New_Objects.Clear;
This.Deleted_Count := 0;
This.Blocks.Clear;
This.Blocks.Append
(Skill.Internal.Parts.Block'
(Lbpo_Map (This.Pool_Offset), This.Static_Data_Instances, This.Size));
-- reset Data chunks
This.Data_Fields_F.Foreach (Reset'Access);
for I in 0 .. This.Sub_Pools.Length - 1 loop
This.Sub_Pools.Element (I).Dynamic.Update_After_Compress (Lbpo_Map);
end loop;
end Update_After_Compress;
-- invoked by resize pool (from base pool implementation)
procedure Resize_Data (This : access Base_Pool_T'Class) is
Count : Types.Skill_ID_T := This.Blocks.Last_Element.Dynamic_Count;
D : Annotation_Array :=
new Annotation_Array_T (This.Data'First .. (This.Data'Last + Count));
procedure Free is new Ada.Unchecked_Deallocation
(Object => Annotation_Array_T,
Name => Annotation_Array);
begin
D (This.Data'First .. This.Data'Last) := This.Data.all;
if This.Data /= Empty_Data then
Free (This.Data);
end if;
This.Data := D;
end Resize_Data;
-- Called after a prepare append operation to write empty the new objects
-- buffer and to set blocks correctly
procedure Update_After_Prepare_Append
(This : access Pool_T'Class;
Chunk_Map : Skill.Field_Declarations.Chunk_Map)
is
New_Instances : constant Boolean :=
null /= This.Dynamic.First_Dynamic_New_Instance;
New_Pool : constant Boolean := This.Blocks.Is_Empty;
New_Field : Boolean := False;
procedure Find_New_Field (F : Field_Declarations.Field_Declaration) is
begin
if not New_Field and then F.Data_Chunks.Is_Empty then
New_Field := True;
end if;
end Find_New_Field;
begin
This.Data_Fields_F.Foreach (Find_New_Field'Access);
if New_Pool or else New_Instances or else New_Field then
declare
-- build block chunk
Lcount : Natural := This.New_Objects_Size;
procedure Dynamic_Lcount (P : Sub_Pool) is
begin
Lcount := Lcount + P.To_Pool.Dynamic.New_Objects_Size;
P.Sub_Pools.Foreach (Dynamic_Lcount'Access);
end Dynamic_Lcount;
Lbpo : Natural;
begin
This.Sub_Pools.Foreach (Dynamic_Lcount'Access);
if 0 = Lcount then
Lbpo := 0;
else
Lbpo := This.Dynamic.First_Dynamic_New_Instance.Skill_ID - 1;
end if;
This.Blocks.Append
(Skill.Internal.Parts.Block'
(BPO => Lbpo, Static_Count => Lcount, Dynamic_Count => Lcount));
-- @note: if this does not hold for p; then it will not hold for
-- p.subPools either!
if New_Instances or else not New_Pool then
-- build field chunks
for I in 1 .. This.Data_Fields_F.Length loop
declare
F : Field_Declarations.Field_Declaration :=
This.Data_Fields_F.Element (I);
CE : Skill.Field_Declarations.Chunk_Entry;
begin
if F.Data_Chunks.Is_Empty then
CE :=
new Skill.Field_Declarations.Chunk_Entry_T'
(C =>
new Skill.Internal.Parts.Bulk_Chunk'
(First => Types.v64 (-1),
Last => Types.v64 (-1),
Count => This.Size,
Block_Count => This.Blocks.Length),
Input => Skill.Streams.Reader.Empty_Sub_Stream);
F.Data_Chunks.Append (CE);
Chunk_Map.Include (F, CE.C);
elsif New_Instances then
CE :=
new Skill.Field_Declarations.Chunk_Entry_T'
(C =>
new Skill.Internal.Parts.Simple_Chunk'
(First => Types.v64 (-1),
Last => Types.v64 (-1),
Count => Lcount,
BPO => Lbpo),
Input => Skill.Streams.Reader.Empty_Sub_Stream);
F.Data_Chunks.Append (CE);
Chunk_Map.Include (F, CE.C);
end if;
end;
end loop;
end if;
end;
end if;
-- notify sub pools
declare
procedure Update (P : Sub_Pool) is
begin
Update_After_Prepare_Append (P, Chunk_Map);
end Update;
begin
This.Sub_Pools.Foreach (Update'Access);
end;
-- remove new objects, because they are regular objects by now
-- TODO if we ever want to get rid of Destroyed mode
-- staticData.addAll(newObjects);
-- newObjects.clear();
-- newObjects.trimToSize();
end Update_After_Prepare_Append;
procedure Prepare_Append
(This : access Base_Pool_T'Class;
Chunk_Map : Skill.Field_Declarations.Chunk_Map)
is
New_Instances : constant Boolean :=
null /= This.Dynamic.First_Dynamic_New_Instance;
begin
-- check if we have to append at all
if not New_Instances
and then not This.Blocks.Is_Empty
and then not This.Data_Fields.Is_Empty
then
declare
Done : Boolean := True;
procedure Check (F : Field_Declarations.Field_Declaration) is
begin
if F.Data_Chunks.Is_Empty then
Done := False;
end if;
end Check;
begin
This.Data_Fields_F.Foreach (Check'Access);
if Done then
return;
end if;
end;
end if;
if New_Instances then
-- we have to resize
declare
Count : Natural := This.Size;
D : Annotation_Array :=
new Annotation_Array_T (This.Data'First .. Count);
procedure Free is new Ada.Unchecked_Deallocation
(Object => Annotation_Array_T,
Name => Annotation_Array);
I : Natural := This.Data'Last + 1;
Iter : aliased Skill.Iterators.Dynamic_New_Instances.Iterator;
Inst : Annotation;
begin
Iter.Init (This.To_Pool);
D (This.Data'First .. This.Data'Last) := This.Data.all;
while Iter.Has_Next loop
Inst := Iter.Next;
D (I) := Inst;
Inst.Skill_ID := I;
I := I + 1;
end loop;
if This.Data /= Empty_Data then
Free (This.Data);
end if;
This.Data := D;
end;
end if;
Update_After_Prepare_Append (This, Chunk_Map);
end Prepare_Append;
procedure Set_Owner
(This : access Base_Pool_T'Class;
Owner : access Skill.Files.File_T'Class)
is
type P is access all Skill.Files.File_T'Class;
function Convert is new Ada.Unchecked_Conversion (P, Owner_T);
begin
This.Owner := Convert (P (Owner));
end Set_Owner;
procedure Delete
(This : access Pool_T'Class;
Target : access Skill_Object'Class)
is
begin
Target.Skill_ID := 0;
This.Deleted_Count := This.Deleted_Count + 1;
end Delete;
end Skill.Types.Pools;
|
with System;
with Startup;
with MSP430_SVD; use MSP430_SVD;
with MSP430_SVD.SYSTEM_CLOCK; use MSP430_SVD.SYSTEM_CLOCK;
package body MSPGD.Board is
CALDCO_1MHz : DCOCTL_Register with Import, Address => System'To_Address (16#10FE#);
CALBC1_1MHz : BCSCTL1_Register with Import, Address => System'To_Address (16#10FF#);
CALDCO_8MHz : DCOCTL_Register with Import, Address => System'To_Address (16#10FC#);
CALBC1_8MHz : BCSCTL1_Register with Import, Address => System'To_Address (16#10FD#);
CALDCO_12MHz : DCOCTL_Register with Import, Address => System'To_Address (16#10FA#);
CALBC1_12MHz : BCSCTL1_Register with Import, Address => System'To_Address (16#10FB#);
CALDCO_16MHz : DCOCTL_Register with Import, Address => System'To_Address (16#10F8#);
CALBC1_16MHz : BCSCTL1_Register with Import, Address => System'To_Address (16#10F9#);
procedure Init is
begin
SYSTEM_CLOCK_Periph.DCOCTL.MOD_k.Val := 0;
SYSTEM_CLOCK_Periph.DCOCTL.DCO.Val := 0;
SYSTEM_CLOCK_Periph.BCSCTL1 := CALBC1_8MHz;
SYSTEM_CLOCK_Periph.DCOCTL := CALDCO_8MHz;
LED_RED.Init;
LED_GREEN.Init;
RX.Init;
TX.Init;
BUTTON.Init;
UART.Init;
end Init;
end MSPGD.Board;
|
with Ada.Numerics.Generic_Elementary_Functions;
package body Generic_Quaternions is
package Elementary_Functions is
new Ada.Numerics.Generic_Elementary_Functions (Real);
use Elementary_Functions;
function "abs" (Left : Quaternion) return Real is
begin
return Sqrt (Left.A**2 + Left.B**2 + Left.C**2 + Left.D**2);
end "abs";
function Conj (Left : Quaternion) return Quaternion is
begin
return (A => Left.A, B => -Left.B, C => -Left.C, D => -Left.D);
end Conj;
function "-" (Left : Quaternion) return Quaternion is
begin
return (A => -Left.A, B => -Left.B, C => -Left.C, D => -Left.D);
end "-";
function "+" (Left, Right : Quaternion) return Quaternion is
begin
return
( A => Left.A + Right.A, B => Left.B + Right.B,
C => Left.C + Right.C, D => Left.D + Right.D
);
end "+";
function "-" (Left, Right : Quaternion) return Quaternion is
begin
return
( A => Left.A - Right.A, B => Left.B - Right.B,
C => Left.C - Right.C, D => Left.D - Right.D
);
end "-";
function "*" (Left : Quaternion; Right : Real) return Quaternion is
begin
return
( A => Left.A * Right, B => Left.B * Right,
C => Left.C * Right, D => Left.D * Right
);
end "*";
function "*" (Left : Real; Right : Quaternion) return Quaternion is
begin
return Right * Left;
end "*";
function "*" (Left, Right : Quaternion) return Quaternion is
begin
return
( A => Left.A * Right.A - Left.B * Right.B - Left.C * Right.C - Left.D * Right.D,
B => Left.A * Right.B + Left.B * Right.A + Left.C * Right.D - Left.D * Right.C,
C => Left.A * Right.C - Left.B * Right.D + Left.C * Right.A + Left.D * Right.B,
D => Left.A * Right.D + Left.B * Right.C - Left.C * Right.B + Left.D * Right.A
);
end "*";
function Image (Left : Quaternion) return String is
begin
return Real'Image (Left.A) & " +" &
Real'Image (Left.B) & "i +" &
Real'Image (Left.C) & "j +" &
Real'Image (Left.D) & "k";
end Image;
end Generic_Quaternions;
|
with C.string;
package body MPFR is
function Version return String is
S : constant C.char_const_ptr := C.mpfr.mpfr_get_version;
Length : constant Natural := Natural (C.string.strlen (S));
Result : String (1 .. Length);
for Result'Address use S.all'Address;
begin
return Result;
end Version;
function Default_Precision return Precision is
begin
return Precision (C.mpfr.mpfr_get_default_prec);
end Default_Precision;
function Default_Rounding return Rounding is
Repr : constant Integer :=
C.mpfr.mpfr_rnd_t'Enum_Rep (C.mpfr.mpfr_get_default_rounding_mode);
begin
return Rounding'Enum_Val (Repr);
end Default_Rounding;
end MPFR;
|
package FLTK.Images.RGB is
type RGB_Image is new Image with private;
type RGB_Image_Reference (Data : not null access RGB_Image'Class) is limited null record
with Implicit_Dereference => Data;
function Copy
(This : in RGB_Image;
Width, Height : in Natural)
return RGB_Image'Class;
function Copy
(This : in RGB_Image)
return RGB_Image'Class;
procedure Color_Average
(This : in out RGB_Image;
Col : in Color;
Amount : in Blend);
procedure Desaturate
(This : in out RGB_Image);
procedure Draw
(This : in RGB_Image;
X, Y : in Integer);
procedure Draw
(This : in RGB_Image;
X, Y, W, H : in Integer;
CX, CY : in Integer := 0);
private
type RGB_Image is new Image with null record;
overriding procedure Finalize
(This : in out RGB_Image);
pragma Inline (Copy);
pragma Inline (Color_Average);
pragma Inline (Desaturate);
pragma Inline (Draw);
end FLTK.Images.RGB;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../../License.txt
with Ada.Exceptions;
with Ada.Calendar.Time_Zones;
with Ada.Unchecked_Conversion;
package body AdaBase.Statement.Base.MySQL is
package EX renames Ada.Exceptions;
package CTZ renames Ada.Calendar.Time_Zones;
--------------------
-- discard_rest --
--------------------
overriding
procedure discard_rest (Stmt : out MySQL_statement)
is
use type ABM.MYSQL_RES_Access;
use type ABM.MYSQL_STMT_Access;
begin
case Stmt.type_of_statement is
when direct_statement =>
if Stmt.result_handle /= null then
Stmt.rows_leftover := True;
Stmt.mysql_conn.free_result (Stmt.result_handle);
Stmt.clear_column_information;
end if;
when prepared_statement =>
if Stmt.stmt_handle /= null then
Stmt.rows_leftover := True;
Stmt.mysql_conn.prep_free_result (Stmt.stmt_handle);
end if;
end case;
Stmt.delivery := completed;
end discard_rest;
--------------------
-- column_count --
--------------------
overriding
function column_count (Stmt : MySQL_statement) return Natural is
begin
return Stmt.num_columns;
end column_count;
---------------------------
-- last_driver_message --
---------------------------
overriding
function last_driver_message (Stmt : MySQL_statement) return String is
begin
case Stmt.type_of_statement is
when direct_statement =>
return Stmt.mysql_conn.driverMessage;
when prepared_statement =>
return Stmt.mysql_conn.prep_DriverMessage
(Stmt.stmt_handle);
end case;
end last_driver_message;
----------------------
-- last_insert_id --
----------------------
overriding
function last_insert_id (Stmt : MySQL_statement) return Trax_ID is
begin
case Stmt.type_of_statement is
when direct_statement =>
return Stmt.mysql_conn.lastInsertID;
when prepared_statement =>
return Stmt.mysql_conn.prep_LastInsertID
(Stmt.stmt_handle);
end case;
end last_insert_id;
----------------------
-- last_sql_state --
----------------------
overriding
function last_sql_state (Stmt : MySQL_statement) return SQL_State is
begin
case Stmt.type_of_statement is
when direct_statement =>
return Stmt.mysql_conn.SqlState;
when prepared_statement =>
return Stmt.mysql_conn.prep_SqlState
(Stmt.stmt_handle);
end case;
end last_sql_state;
------------------------
-- last_driver_code --
------------------------
overriding
function last_driver_code (Stmt : MySQL_statement) return Driver_Codes is
begin
case Stmt.type_of_statement is
when direct_statement =>
return Stmt.mysql_conn.driverCode;
when prepared_statement =>
return Stmt.mysql_conn.prep_DriverCode
(Stmt.stmt_handle);
end case;
end last_driver_code;
----------------------------
-- execute (version 1) --
----------------------------
overriding
function execute (Stmt : out MySQL_statement) return Boolean
is
num_markers : constant Natural := Natural (Stmt.realmccoy.Length);
status_successful : Boolean := True;
begin
if Stmt.type_of_statement = direct_statement then
raise INVALID_FOR_DIRECT_QUERY
with "The execute command is for prepared statements only";
end if;
Stmt.successful_execution := False;
Stmt.rows_leftover := False;
if num_markers > 0 then
-- Check to make sure all prepared markers are bound
for sx in Natural range 1 .. num_markers loop
if not Stmt.realmccoy.Element (sx).bound then
raise STMT_PREPARATION
with "Prep Stmt column" & sx'Img & " unbound";
end if;
end loop;
declare
slots : ABM.MYSQL_BIND_Array (1 .. num_markers);
vault : mysql_canvases (1 .. num_markers);
begin
for sx in slots'Range loop
Stmt.construct_bind_slot (struct => slots (sx),
canvas => vault (sx),
marker => sx);
end loop;
if not Stmt.mysql_conn.prep_bind_parameters
(Stmt.stmt_handle, slots)
then
Stmt.log_problem (category => statement_preparation,
message => "failed to bind parameters",
pull_codes => True);
status_successful := False;
end if;
if status_successful then
Stmt.log_nominal (category => statement_execution,
message => "Exec with" & num_markers'Img &
" bound parameters");
if Stmt.mysql_conn.prep_execute (Stmt.stmt_handle) then
Stmt.successful_execution := True;
else
Stmt.log_problem (category => statement_execution,
message => "failed to exec prep stmt",
pull_codes => True);
status_successful := False;
end if;
end if;
-- Recover dynamically allocated data
for sx in slots'Range loop
free_binary (vault (sx).buffer_binary);
end loop;
end;
else
-- No binding required, just execute the prepared statement
Stmt.log_nominal (category => statement_execution,
message => "Exec without bound parameters");
if Stmt.mysql_conn.prep_execute (Stmt.stmt_handle) then
Stmt.successful_execution := True;
else
Stmt.log_problem (category => statement_execution,
message => "failed to exec prep stmt",
pull_codes => True);
status_successful := False;
end if;
end if;
Stmt.internal_post_prep_stmt;
return status_successful;
end execute;
----------------------------
-- execute (version 2) --
----------------------------
overriding
function execute (Stmt : out MySQL_statement; parameters : String;
delimiter : Character := '|') return Boolean
is
function parameters_given return Natural;
num_markers : constant Natural := Natural (Stmt.realmccoy.Length);
function parameters_given return Natural
is
result : Natural := 1;
begin
for x in parameters'Range loop
if parameters (x) = delimiter then
result := result + 1;
end if;
end loop;
return result;
end parameters_given;
begin
if Stmt.type_of_statement = direct_statement then
raise INVALID_FOR_DIRECT_QUERY
with "The execute command is for prepared statements only";
end if;
if num_markers /= parameters_given then
raise STMT_PREPARATION
with "Parameter number mismatch, " & num_markers'Img &
" expected, but" & parameters_given'Img & " provided.";
end if;
declare
index : Natural := 1;
arrow : Natural := parameters'First;
scans : Boolean := False;
start : Natural := 1;
stop : Natural := 0;
begin
for x in parameters'Range loop
if parameters (x) = delimiter then
if not scans then
Stmt.auto_assign (index, "");
else
Stmt.auto_assign (index, parameters (start .. stop));
scans := False;
end if;
index := index + 1;
else
stop := x;
if not scans then
start := x;
scans := True;
end if;
end if;
end loop;
if not scans then
Stmt.auto_assign (index, "");
else
Stmt.auto_assign (index, parameters (start .. stop));
end if;
end;
return Stmt.execute;
end execute;
------------------
-- initialize --
------------------
overriding
procedure initialize (Object : in out MySQL_statement)
is
use type ACM.MySQL_Connection_Access;
begin
if Object.mysql_conn = null then
return;
end if;
logger_access := Object.log_handler;
Object.dialect := driver_mysql;
Object.connection := ACB.Base_Connection_Access (Object.mysql_conn);
case Object.type_of_statement is
when direct_statement =>
Object.sql_final := new String'(CT.trim_sql
(Object.initial_sql.all));
Object.internal_direct_post_exec;
when prepared_statement =>
declare
use type ABM.MYSQL_RES_Access;
begin
Object.sql_final := new String'(Object.transform_sql
(Object.initial_sql.all));
Object.mysql_conn.initialize_and_prepare_statement
(stmt => Object.stmt_handle, sql => Object.sql_final.all);
declare
params : Natural := Object.mysql_conn.prep_markers_found
(stmt => Object.stmt_handle);
errmsg : String := "marker mismatch," &
Object.realmccoy.Length'Img & " expected but" &
params'Img & " found by MySQL";
begin
if params /= Natural (Object.realmccoy.Length) then
raise ILLEGAL_BIND_SQL with errmsg;
end if;
Object.log_nominal (category => statement_preparation,
message => Object.sql_final.all);
end;
Object.result_handle := Object.mysql_conn.prep_result_metadata
(Object.stmt_handle);
-- Direct statements always produce result sets, but prepared
-- statements very well may not. The next procedure ends early
-- after clearing column data if there is results.
Object.scan_column_information;
if Object.result_handle /= null then
Object.mysql_conn.free_result (Object.result_handle);
end if;
exception
when HELL : others =>
Object.log_problem (category => statement_preparation,
message => EX.Exception_Message (HELL));
raise;
end;
end case;
end initialize;
--------------
-- Adjust --
--------------
overriding
procedure Adjust (Object : in out MySQL_statement) is
begin
-- The stmt object goes through this evolution:
-- A) created in private_prepare()
-- B) copied to new object in prepare(), A) destroyed
-- C) copied to new object in program, B) destroyed
-- We don't want to take any action until C) is destroyed, so add a
-- reference counter upon each assignment. When finalize sees a
-- value of "2", it knows it is the program-level statement and then
-- it can release memory releases, but not before!
Object.assign_counter := Object.assign_counter + 1;
-- Since the finalization is looking for a specific reference
-- counter, any further assignments would fail finalization, so
-- just prohibit them outright.
if Object.assign_counter > 2 then
raise STMT_PREPARATION
with "Statement objects cannot be re-assigned.";
end if;
end Adjust;
----------------
-- finalize --
----------------
overriding
procedure finalize (Object : in out MySQL_statement) is
begin
if Object.assign_counter /= 2 then
return;
end if;
if Object.type_of_statement = prepared_statement then
if not Object.mysql_conn.prep_close_statement (Object.stmt_handle)
then
Object.log_problem (category => statement_preparation,
message => "Deallocating statement memory",
pull_codes => True);
end if;
end if;
free_sql (Object.sql_final);
Object.reclaim_canvas;
end finalize;
---------------------
-- direct_result --
---------------------
procedure process_direct_result (Stmt : out MySQL_statement)
is
use type ABM.MYSQL_RES_Access;
begin
case Stmt.con_buffered is
when True => Stmt.mysql_conn.store_result
(result_handle => Stmt.result_handle);
when False => Stmt.mysql_conn.use_result
(result_handle => Stmt.result_handle);
end case;
Stmt.result_present := (Stmt.result_handle /= null);
end process_direct_result;
---------------------
-- rows_returned --
---------------------
overriding
function rows_returned (Stmt : MySQL_statement) return Affected_Rows is
begin
if not Stmt.successful_execution then
raise PRIOR_EXECUTION_FAILED
with "Has query been executed yet?";
end if;
if Stmt.result_present then
if Stmt.con_buffered then
return Stmt.size_of_rowset;
else
raise INVALID_FOR_RESULT_SET
with "Row set size is not known (Use query buffers to fix)";
end if;
else
raise INVALID_FOR_RESULT_SET
with "Result set not found; use rows_affected";
end if;
end rows_returned;
----------------------
-- reclaim_canvas --
----------------------
procedure reclaim_canvas (Stmt : out MySQL_statement)
is
use type ABM.ICS.char_array_access;
begin
if Stmt.bind_canvas /= null then
for sx in Stmt.bind_canvas.all'Range loop
if Stmt.bind_canvas (sx).buffer_binary /= null then
free_binary (Stmt.bind_canvas (sx).buffer_binary);
end if;
end loop;
free_canvas (Stmt.bind_canvas);
end if;
end reclaim_canvas;
--------------------------------
-- clear_column_information --
--------------------------------
procedure clear_column_information (Stmt : out MySQL_statement) is
begin
Stmt.num_columns := 0;
Stmt.column_info.Clear;
Stmt.crate.Clear;
Stmt.headings_map.Clear;
Stmt.reclaim_canvas;
end clear_column_information;
-------------------------------
-- scan_column_information --
-------------------------------
procedure scan_column_information (Stmt : out MySQL_statement)
is
use type ABM.MYSQL_FIELD_Access;
use type ABM.MYSQL_RES_Access;
field : ABM.MYSQL_FIELD_Access;
function fn (raw : String) return CT.Text;
function sn (raw : String) return String;
function fn (raw : String) return CT.Text is
begin
case Stmt.con_case_mode is
when upper_case =>
return CT.SUS (ACH.To_Upper (raw));
when lower_case =>
return CT.SUS (ACH.To_Lower (raw));
when natural_case =>
return CT.SUS (raw);
end case;
end fn;
function sn (raw : String) return String is
begin
case Stmt.con_case_mode is
when upper_case =>
return ACH.To_Upper (raw);
when lower_case =>
return ACH.To_Lower (raw);
when natural_case =>
return raw;
end case;
end sn;
begin
Stmt.clear_column_information;
if Stmt.result_handle = null then
return;
end if;
Stmt.num_columns := Stmt.mysql_conn.fields_in_result
(Stmt.result_handle);
loop
field := Stmt.mysql_conn.fetch_field
(result_handle => Stmt.result_handle);
exit when field = null;
declare
info : column_info;
brec : bindrec;
begin
brec.v00 := False; -- placeholder
info.field_name := fn (Stmt.mysql_conn.field_name_field (field));
info.table := fn (Stmt.mysql_conn.field_name_table (field));
info.mysql_type := field.field_type;
info.null_possible := Stmt.mysql_conn.field_allows_null (field);
Stmt.mysql_conn.field_data_type (field => field,
std_type => info.field_type,
size => info.field_size);
if info.field_size > Stmt.con_max_blob then
info.field_size := Stmt.con_max_blob;
end if;
Stmt.column_info.Append (New_Item => info);
-- The following pre-populates for bind support
Stmt.crate.Append (New_Item => brec);
Stmt.headings_map.Insert
(Key => sn (Stmt.mysql_conn.field_name_field (field)),
New_Item => Stmt.crate.Last_Index);
end;
end loop;
end scan_column_information;
-------------------
-- column_name --
-------------------
overriding
function column_name (Stmt : MySQL_statement; index : Positive)
return String
is
maxlen : constant Natural := Natural (Stmt.column_info.Length);
begin
if index > maxlen then
raise INVALID_COLUMN_INDEX with "Max index is" & maxlen'Img &
" but" & index'Img & " attempted";
end if;
return CT.USS (Stmt.column_info.Element (Index => index).field_name);
end column_name;
--------------------
-- column_table --
--------------------
overriding
function column_table (Stmt : MySQL_statement; index : Positive)
return String
is
maxlen : constant Natural := Natural (Stmt.column_info.Length);
begin
if index > maxlen then
raise INVALID_COLUMN_INDEX with "Max index is" & maxlen'Img &
" but" & index'Img & " attempted";
end if;
return CT.USS (Stmt.column_info.Element (Index => index).table);
end column_table;
--------------------------
-- column_native_type --
--------------------------
overriding
function column_native_type (Stmt : MySQL_statement; index : Positive)
return field_types
is
maxlen : constant Natural := Natural (Stmt.column_info.Length);
begin
if index > maxlen then
raise INVALID_COLUMN_INDEX with "Max index is" & maxlen'Img &
" but" & index'Img & " attempted";
end if;
return Stmt.column_info.Element (Index => index).field_type;
end column_native_type;
------------------
-- fetch_next --
------------------
overriding
function fetch_next (Stmt : out MySQL_statement) return ARS.Datarow is
begin
if Stmt.delivery = completed then
return ARS.Empty_Datarow;
end if;
case Stmt.type_of_statement is
when prepared_statement =>
return Stmt.internal_ps_fetch_row;
when direct_statement =>
return Stmt.internal_fetch_row;
end case;
end fetch_next;
-------------------
-- fetch_bound --
-------------------
overriding
function fetch_bound (Stmt : out MySQL_statement) return Boolean is
begin
if Stmt.delivery = completed then
return False;
end if;
case Stmt.type_of_statement is
when prepared_statement =>
return Stmt.internal_ps_fetch_bound;
when direct_statement =>
return Stmt.internal_fetch_bound;
end case;
end fetch_bound;
-----------------
-- fetch_all --
-----------------
overriding
function fetch_all (Stmt : out MySQL_statement) return ARS.Datarow_Set
is
maxrows : Natural := Natural (Stmt.rows_returned);
tmpset : ARS.Datarow_Set (1 .. maxrows + 1);
nullset : ARS.Datarow_Set (1 .. 0);
index : Natural := 1;
row : ARS.Datarow;
begin
if (Stmt.delivery = completed) or else (maxrows = 0) then
return nullset;
end if;
-- It is possible that one or more rows was individually fetched
-- before the entire set was fetched. Let's consider this legal so
-- use a repeat loop to check each row and return a partial set
-- if necessary.
loop
tmpset (index) := Stmt.fetch_next;
exit when tmpset (index).data_exhausted;
index := index + 1;
exit when index > maxrows + 1; -- should never happen
end loop;
if index = 1 then
return nullset; -- nothing was fetched
end if;
return tmpset (1 .. index - 1);
end fetch_all;
----------------------
-- fetch_next_set --
----------------------
overriding
procedure fetch_next_set (Stmt : out MySQL_statement;
data_present : out Boolean;
data_fetched : out Boolean)
is
use type ABM.MYSQL_RES_Access;
begin
data_fetched := False;
if Stmt.result_handle /= null then
Stmt.mysql_conn.free_result (Stmt.result_handle);
end if;
data_present := Stmt.mysql_conn.fetch_next_set;
if not data_present then
return;
end if;
declare
begin
Stmt.process_direct_result;
exception
when others =>
Stmt.log_nominal (category => statement_execution,
message => "Result set missing from: "
& Stmt.sql_final.all);
return;
end;
Stmt.internal_direct_post_exec (newset => True);
data_fetched := True;
end fetch_next_set;
--------------------------
-- internal_fetch_row --
--------------------------
function internal_fetch_row (Stmt : out MySQL_statement)
return ARS.Datarow
is
use type ABM.ICS.chars_ptr;
use type ABM.MYSQL_ROW_access;
rptr : ABM.MYSQL_ROW_access :=
Stmt.mysql_conn.fetch_row (Stmt.result_handle);
begin
if rptr = null then
Stmt.delivery := completed;
Stmt.mysql_conn.free_result (Stmt.result_handle);
Stmt.clear_column_information;
return ARS.Empty_Datarow;
end if;
Stmt.delivery := progressing;
declare
maxlen : constant Natural := Natural (Stmt.column_info.Length);
bufmax : constant ABM.IC.size_t := ABM.IC.size_t (Stmt.con_max_blob);
subtype data_buffer is ABM.IC.char_array (1 .. bufmax);
type db_access is access all data_buffer;
type rowtype is array (1 .. maxlen) of db_access;
type rowtype_access is access all rowtype;
row : rowtype_access;
result : ARS.Datarow;
field_lengths : constant ACM.fldlen := Stmt.mysql_conn.fetch_lengths
(result_handle => Stmt.result_handle,
num_columns => maxlen);
function convert is new Ada.Unchecked_Conversion
(Source => ABM.MYSQL_ROW_access, Target => rowtype_access);
function db_convert (dba : db_access; size : Natural) return String;
function db_convert (dba : db_access; size : Natural) return String
is
max : Natural := size;
begin
if max > Stmt.con_max_blob then
max := Stmt.con_max_blob;
end if;
declare
result : String (1 .. max);
begin
for x in result'Range loop
result (x) := Character (dba.all (ABM.IC.size_t (x)));
end loop;
return result;
end;
end db_convert;
begin
row := convert (rptr);
for F in 1 .. maxlen loop
declare
colinfo : column_info renames Stmt.column_info.Element (F);
field : ARF.Std_Field;
last_one : constant Boolean := (F = maxlen);
heading : constant String := CT.USS (colinfo.field_name);
isnull : constant Boolean := (row (F) = null);
sz : constant Natural := field_lengths (F);
ST : constant String := db_convert (row (F), sz);
dvariant : ARF.Variant;
begin
if isnull then
field := ARF.spawn_null_field (colinfo.field_type);
else
case colinfo.field_type is
when ft_nbyte0 =>
dvariant := (datatype => ft_nbyte0, v00 => ST = "1");
when ft_nbyte1 =>
dvariant := (datatype => ft_nbyte1, v01 => convert (ST));
when ft_nbyte2 =>
dvariant := (datatype => ft_nbyte2, v02 => convert (ST));
when ft_nbyte3 =>
dvariant := (datatype => ft_nbyte3, v03 => convert (ST));
when ft_nbyte4 =>
dvariant := (datatype => ft_nbyte4, v04 => convert (ST));
when ft_nbyte8 =>
dvariant := (datatype => ft_nbyte8, v05 => convert (ST));
when ft_byte1 =>
dvariant := (datatype => ft_byte1, v06 => convert (ST));
when ft_byte2 =>
dvariant := (datatype => ft_byte2, v07 => convert (ST));
when ft_byte3 =>
dvariant := (datatype => ft_byte3, v08 => convert (ST));
when ft_byte4 =>
dvariant := (datatype => ft_byte4, v09 => convert (ST));
when ft_byte8 =>
dvariant := (datatype => ft_byte8, v10 => convert (ST));
when ft_real9 =>
dvariant := (datatype => ft_real9, v11 => convert (ST));
when ft_real18 =>
dvariant := (datatype => ft_real18, v12 => convert (ST));
when ft_textual =>
dvariant := (datatype => ft_textual, v13 => CT.SUS (ST));
when ft_widetext =>
dvariant := (datatype => ft_widetext,
v14 => convert (ST));
when ft_supertext =>
dvariant := (datatype => ft_supertext,
v15 => convert (ST));
when ft_utf8 =>
dvariant := (datatype => ft_utf8, v21 => CT.SUS (ST));
when ft_geometry =>
-- MySQL internal geometry format is SRID + WKB
-- Remove the first 4 bytes and save only the WKB
dvariant :=
(datatype => ft_geometry,
v22 => CT.SUS (ST (ST'First + 4 .. ST'Last)));
when ft_timestamp =>
begin
dvariant := (datatype => ft_timestamp,
v16 => ARC.convert (ST));
exception
when AR.CONVERSION_FAILED =>
dvariant := (datatype => ft_textual,
v13 => CT.SUS (ST));
end;
when ft_enumtype =>
dvariant := (datatype => ft_enumtype,
v18 => ARC.convert (CT.SUS (ST)));
when ft_chain => null;
when ft_settype => null;
when ft_bits => null;
end case;
case colinfo.field_type is
when ft_chain =>
field := ARF.spawn_field (binob => ARC.convert (ST));
when ft_bits =>
field := ARF.spawn_bits_field
(convert_to_bitstring (ST, colinfo.field_size * 8));
when ft_settype =>
field := ARF.spawn_field (enumset => ST);
when others =>
field := ARF.spawn_field (data => dvariant,
null_data => isnull);
end case;
end if;
result.push (heading => heading,
field => field,
last_field => last_one);
end;
end loop;
return result;
end;
end internal_fetch_row;
------------------
-- bincopy #1 --
------------------
function bincopy (data : ABM.ICS.char_array_access;
datalen, max_size : Natural) return String
is
reslen : Natural := datalen;
begin
if reslen > max_size then
reslen := max_size;
end if;
declare
result : String (1 .. reslen) := (others => '_');
begin
for x in result'Range loop
result (x) := Character (data.all (ABM.IC.size_t (x)));
end loop;
return result;
end;
end bincopy;
------------------
-- bincopy #2 --
------------------
function bincopy (data : ABM.ICS.char_array_access;
datalen, max_size : Natural;
hard_limit : Natural := 0) return AR.Chain
is
reslen : Natural := datalen;
chainlen : Natural := data.all'Length;
begin
if reslen > max_size then
reslen := max_size;
end if;
if hard_limit > 0 then
chainlen := hard_limit;
else
chainlen := reslen;
end if;
declare
result : AR.Chain (1 .. chainlen) := (others => 0);
jimmy : Character;
begin
for x in Natural range 1 .. reslen loop
jimmy := Character (data.all (ABM.IC.size_t (x)));
result (x) := AR.NByte1 (Character'Pos (jimmy));
end loop;
return result;
end;
end bincopy;
-----------------------------
-- internal_ps_fetch_row --
-----------------------------
function internal_ps_fetch_row (Stmt : out MySQL_statement)
return ARS.Datarow
is
use type ABM.ICS.chars_ptr;
use type ABM.MYSQL_ROW_access;
use type ACM.fetch_status;
status : ACM.fetch_status;
begin
status := Stmt.mysql_conn.prep_fetch_bound (Stmt.stmt_handle);
if status = ACM.spent then
Stmt.delivery := completed;
Stmt.clear_column_information;
elsif status = ACM.truncated then
Stmt.log_nominal (category => statement_execution,
message => "data truncated");
Stmt.delivery := progressing;
elsif status = ACM.error then
Stmt.log_problem (category => statement_execution,
message => "prep statement fetch error",
pull_codes => True);
Stmt.delivery := completed;
else
Stmt.delivery := progressing;
end if;
if Stmt.delivery = completed then
return ARS.Empty_Datarow;
end if;
declare
maxlen : constant Natural := Stmt.num_columns;
result : ARS.Datarow;
begin
for F in 1 .. maxlen loop
declare
use type ABM.enum_field_types;
function binary_string return String;
cv : mysql_canvas renames Stmt.bind_canvas (F);
colinfo : column_info renames Stmt.column_info.Element (F);
dvariant : ARF.Variant;
field : ARF.Std_Field;
last_one : constant Boolean := (F = maxlen);
datalen : constant Natural := Natural (cv.length);
heading : constant String := CT.USS (colinfo.field_name);
isnull : constant Boolean := (Natural (cv.is_null) = 1);
mtype : ABM.enum_field_types := colinfo.mysql_type;
function binary_string return String is
begin
return bincopy (data => cv.buffer_binary,
datalen => datalen,
max_size => Stmt.con_max_blob);
end binary_string;
begin
if isnull then
field := ARF.spawn_null_field (colinfo.field_type);
else
case colinfo.field_type is
when ft_nbyte0 =>
dvariant := (datatype => ft_nbyte0,
v00 => Natural (cv.buffer_uint8) = 1);
when ft_nbyte1 =>
dvariant := (datatype => ft_nbyte1,
v01 => AR.NByte1 (cv.buffer_uint8));
when ft_nbyte2 =>
dvariant := (datatype => ft_nbyte2,
v02 => AR.NByte2 (cv.buffer_uint16));
when ft_nbyte3 =>
dvariant := (datatype => ft_nbyte3,
v03 => AR.NByte3 (cv.buffer_uint32));
when ft_nbyte4 =>
dvariant := (datatype => ft_nbyte4,
v04 => AR.NByte4 (cv.buffer_uint32));
when ft_nbyte8 =>
dvariant := (datatype => ft_nbyte8,
v05 => AR.NByte8 (cv.buffer_uint64));
when ft_byte1 =>
dvariant := (datatype => ft_byte1,
v06 => AR.Byte1 (cv.buffer_int8));
when ft_byte2 =>
dvariant := (datatype => ft_byte2,
v07 => AR.Byte2 (cv.buffer_int16));
when ft_byte3 =>
dvariant := (datatype => ft_byte3,
v08 => AR.Byte3 (cv.buffer_int32));
when ft_byte4 =>
dvariant := (datatype => ft_byte4,
v09 => AR.Byte4 (cv.buffer_int32));
when ft_byte8 =>
dvariant := (datatype => ft_byte8,
v10 => AR.Byte8 (cv.buffer_int64));
when ft_real9 =>
if mtype = ABM.MYSQL_TYPE_NEWDECIMAL or else
mtype = ABM.MYSQL_TYPE_DECIMAL
then
dvariant := (datatype => ft_real9,
v11 => convert (binary_string));
else
dvariant := (datatype => ft_real9,
v11 => AR.Real9 (cv.buffer_float));
end if;
when ft_real18 =>
if mtype = ABM.MYSQL_TYPE_NEWDECIMAL or else
mtype = ABM.MYSQL_TYPE_DECIMAL
then
dvariant := (datatype => ft_real18,
v12 => convert (binary_string));
else
dvariant := (datatype => ft_real18,
v12 => AR.Real18 (cv.buffer_double));
end if;
when ft_textual =>
dvariant := (datatype => ft_textual,
v13 => CT.SUS (binary_string));
when ft_widetext =>
dvariant := (datatype => ft_widetext,
v14 => convert (binary_string));
when ft_supertext =>
dvariant := (datatype => ft_supertext,
v15 => convert (binary_string));
when ft_utf8 =>
dvariant := (datatype => ft_utf8,
v21 => CT.SUS (binary_string));
when ft_geometry =>
-- MySQL internal geometry format is SRID + WKB
-- Remove the first 4 bytes and save only the WKB
declare
ST : String := binary_string;
wkbstring : String := ST (ST'First + 4 .. ST'Last);
begin
dvariant := (datatype => ft_geometry,
v22 => CT.SUS (wkbstring));
end;
when ft_timestamp =>
declare
year : Natural := Natural (cv.buffer_time.year);
month : Natural := Natural (cv.buffer_time.month);
day : Natural := Natural (cv.buffer_time.day);
begin
if year < CAL.Year_Number'First or else
year > CAL.Year_Number'Last
then
year := CAL.Year_Number'First;
end if;
if month < CAL.Month_Number'First or else
month > CAL.Month_Number'Last
then
month := CAL.Month_Number'First;
end if;
if day < CAL.Day_Number'First or else
day > CAL.Day_Number'Last
then
day := CAL.Day_Number'First;
end if;
dvariant :=
(datatype => ft_timestamp,
v16 => CFM.Time_Of
(Year => year,
Month => month,
Day => day,
Hour => Natural (cv.buffer_time.hour),
Minute => Natural (cv.buffer_time.minute),
Second => Natural (cv.buffer_time.second),
Sub_Second => CFM.Second_Duration (Natural
(cv.buffer_time.second_part) / 1000000))
);
end;
when ft_enumtype =>
dvariant := (datatype => ft_enumtype,
v18 => ARC.convert (binary_string));
when ft_settype => null;
when ft_chain => null;
when ft_bits => null;
end case;
case colinfo.field_type is
when ft_chain =>
field := ARF.spawn_field
(binob => bincopy (cv.buffer_binary, datalen,
Stmt.con_max_blob));
when ft_bits =>
field := ARF.spawn_bits_field
(convert_to_bitstring
(binary_string, datalen * 8));
when ft_settype =>
field := ARF.spawn_field
(enumset => binary_string);
when others =>
field := ARF.spawn_field
(data => dvariant, null_data => isnull);
end case;
end if;
result.push (heading => heading,
field => field,
last_field => last_one);
end;
end loop;
return result;
end;
end internal_ps_fetch_row;
-------------------------------
-- internal_ps_fetch_bound --
-------------------------------
function internal_ps_fetch_bound (Stmt : out MySQL_statement)
return Boolean
is
use type ABM.ICS.chars_ptr;
use type ACM.fetch_status;
status : ACM.fetch_status;
begin
status := Stmt.mysql_conn.prep_fetch_bound (Stmt.stmt_handle);
if status = ACM.spent then
Stmt.delivery := completed;
Stmt.clear_column_information;
elsif status = ACM.truncated then
Stmt.log_nominal (category => statement_execution,
message => "data truncated");
Stmt.delivery := progressing;
elsif status = ACM.error then
Stmt.log_problem (category => statement_execution,
message => "prep statement fetch error",
pull_codes => True);
Stmt.delivery := completed;
else
Stmt.delivery := progressing;
end if;
if Stmt.delivery = completed then
return False;
end if;
declare
maxlen : constant Natural := Stmt.num_columns;
begin
for F in 1 .. maxlen loop
if not Stmt.crate.Element (Index => F).bound then
goto continue;
end if;
declare
use type ABM.enum_field_types;
function binary_string return String;
cv : mysql_canvas renames Stmt.bind_canvas (F);
colinfo : column_info renames Stmt.column_info.Element (F);
param : bindrec renames Stmt.crate.Element (F);
datalen : constant Natural := Natural (cv.length);
Tout : constant field_types := param.output_type;
Tnative : constant field_types := colinfo.field_type;
mtype : ABM.enum_field_types := colinfo.mysql_type;
errmsg : constant String := "native type : " &
field_types'Image (Tnative) & " binding type : " &
field_types'Image (Tout);
function binary_string return String is
begin
return bincopy (data => cv.buffer_binary,
datalen => datalen,
max_size => Stmt.con_max_blob);
end binary_string;
begin
-- Derivation of implementation taken from PostgreSQL
-- Only guaranteed successful converstions allowed though
case Tout is
when ft_nbyte2 =>
case Tnative is
when ft_nbyte1 | ft_nbyte2 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_nbyte3 =>
case Tnative is
when ft_nbyte1 | ft_nbyte2 | ft_nbyte3 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_nbyte4 =>
case Tnative is
when ft_nbyte1 | ft_nbyte2 | ft_nbyte3 | ft_nbyte4 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_nbyte8 =>
case Tnative is
when ft_nbyte1 | ft_nbyte2 | ft_nbyte3 | ft_nbyte4 |
ft_nbyte8 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_byte2 =>
case Tnative is
when ft_byte1 | ft_byte2 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_byte3 =>
case Tnative is
when ft_byte1 | ft_byte2 | ft_byte3 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_byte4 =>
case Tnative is
when ft_byte1 | ft_byte2 | ft_byte3 | ft_byte4 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_byte8 =>
case Tnative is
when ft_byte1 | ft_byte2 | ft_byte3 | ft_byte4 |
ft_byte8 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_real18 =>
case Tnative is
when ft_real9 | ft_real18 =>
null; -- guaranteed to convert without loss
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_textual =>
case Tnative is
when ft_textual | ft_utf8 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when others =>
if Tnative /= Tout then
raise BINDING_TYPE_MISMATCH with errmsg;
end if;
end case;
case Tout is
when ft_nbyte0 => param.a00.all := (Natural (cv.buffer_uint8) = 1);
when ft_nbyte1 => param.a01.all := AR.NByte1 (cv.buffer_uint8);
when ft_nbyte2 => param.a02.all := AR.NByte2 (cv.buffer_uint16);
when ft_nbyte3 => param.a03.all := AR.NByte3 (cv.buffer_uint32);
when ft_nbyte4 => param.a04.all := AR.NByte4 (cv.buffer_uint32);
when ft_nbyte8 => param.a05.all := AR.NByte8 (cv.buffer_uint64);
when ft_byte1 => param.a06.all := AR.Byte1 (cv.buffer_int8);
when ft_byte2 => param.a07.all := AR.Byte2 (cv.buffer_int16);
when ft_byte3 => param.a08.all := AR.Byte3 (cv.buffer_int32);
when ft_byte4 => param.a09.all := AR.Byte4 (cv.buffer_int32);
when ft_byte8 => param.a10.all := AR.Byte8 (cv.buffer_int64);
when ft_real9 =>
if mtype = ABM.MYSQL_TYPE_NEWDECIMAL or else
mtype = ABM.MYSQL_TYPE_DECIMAL
then
param.a11.all := convert (binary_string);
else
param.a11.all := AR.Real9 (cv.buffer_float);
end if;
when ft_real18 =>
if mtype = ABM.MYSQL_TYPE_NEWDECIMAL or else
mtype = ABM.MYSQL_TYPE_DECIMAL
then
param.a12.all := convert (binary_string);
else
param.a12.all := AR.Real18 (cv.buffer_double);
end if;
when ft_textual => param.a13.all := CT.SUS (binary_string);
when ft_widetext => param.a14.all := convert (binary_string);
when ft_supertext => param.a15.all :=
convert (binary_string);
when ft_utf8 => param.a21.all := binary_string;
when ft_geometry =>
-- MySQL internal geometry format is SRID + WKB
-- Remove the first 4 bytes and translate WKB
declare
ST : String := binary_string;
wkbstring : String := ST (ST'First + 4 .. ST'Last);
begin
param.a22.all := WKB.Translate_WKB (wkbstring);
end;
when ft_timestamp =>
declare
year : Natural := Natural (cv.buffer_time.year);
month : Natural := Natural (cv.buffer_time.month);
day : Natural := Natural (cv.buffer_time.day);
begin
if year < CAL.Year_Number'First or else
year > CAL.Year_Number'Last
then
year := CAL.Year_Number'First;
end if;
if month < CAL.Month_Number'First or else
month > CAL.Month_Number'Last
then
month := CAL.Month_Number'First;
end if;
if day < CAL.Day_Number'First or else
day > CAL.Day_Number'Last
then
day := CAL.Day_Number'First;
end if;
param.a16.all := CFM.Time_Of
(Year => year,
Month => month,
Day => day,
Hour => Natural (cv.buffer_time.hour),
Minute => Natural (cv.buffer_time.minute),
Second => Natural (cv.buffer_time.second),
Sub_Second => CFM.Second_Duration (Natural
(cv.buffer_time.second_part) / 1000000));
end;
when ft_chain =>
if param.a17.all'Length < datalen then
raise BINDING_SIZE_MISMATCH with "native size : " &
param.a17.all'Length'Img &
" less than binding size : " & datalen'Img;
end if;
param.a17.all := bincopy
(cv.buffer_binary, datalen, Stmt.con_max_blob,
param.a17.all'Length);
when ft_bits =>
declare
strval : String := bincopy (cv.buffer_binary, datalen,
Stmt.con_max_blob);
FL : Natural := param.a20.all'Length;
DVLEN : Natural := strval'Length * 8;
begin
if FL < DVLEN then
raise BINDING_SIZE_MISMATCH with "native size : " &
FL'Img & " less than binding size : " & DVLEN'Img;
end if;
param.a20.all :=
ARC.convert (convert_to_bitstring (strval, FL));
end;
when ft_enumtype =>
param.a18.all :=
ARC.convert (CT.SUS (binary_string));
when ft_settype =>
declare
setstr : constant String := binary_string;
num_items : constant Natural := num_set_items (setstr);
begin
if param.a19.all'Length < num_items
then
raise BINDING_SIZE_MISMATCH with "native size : " &
param.a19.all'Length'Img &
" less than binding size : " & num_items'Img;
end if;
param.a19.all := ARC.convert (setstr,
param.a19.all'Length);
end;
end case;
end;
<<continue>>
null;
end loop;
return True;
end;
end internal_ps_fetch_bound;
-----------------------------------
-- internal_fetch_bound_direct --
-----------------------------------
function internal_fetch_bound (Stmt : out MySQL_statement) return Boolean
is
use type ABM.ICS.chars_ptr;
use type ABM.MYSQL_ROW_access;
rptr : ABM.MYSQL_ROW_access :=
Stmt.mysql_conn.fetch_row (Stmt.result_handle);
begin
if rptr = null then
Stmt.delivery := completed;
Stmt.mysql_conn.free_result (Stmt.result_handle);
Stmt.clear_column_information;
return False;
end if;
Stmt.delivery := progressing;
declare
maxlen : constant Natural := Natural (Stmt.column_info.Length);
bufmax : constant ABM.IC.size_t := ABM.IC.size_t (Stmt.con_max_blob);
subtype data_buffer is ABM.IC.char_array (1 .. bufmax);
type db_access is access all data_buffer;
type rowtype is array (1 .. maxlen) of db_access;
type rowtype_access is access all rowtype;
row : rowtype_access;
field_lengths : constant ACM.fldlen := Stmt.mysql_conn.fetch_lengths
(result_handle => Stmt.result_handle,
num_columns => maxlen);
function Convert is new Ada.Unchecked_Conversion
(Source => ABM.MYSQL_ROW_access, Target => rowtype_access);
function db_convert (dba : db_access; size : Natural) return String;
function db_convert (dba : db_access; size : Natural) return String
is
max : Natural := size;
begin
if max > Stmt.con_max_blob then
max := Stmt.con_max_blob;
end if;
declare
result : String (1 .. max);
begin
for x in result'Range loop
result (x) := Character (dba.all (ABM.IC.size_t (x)));
end loop;
return result;
end;
end db_convert;
begin
row := Convert (rptr);
for F in 1 .. maxlen loop
declare
use type ABM.enum_field_types;
dossier : bindrec renames Stmt.crate.Element (F);
colinfo : column_info renames Stmt.column_info.Element (F);
mtype : ABM.enum_field_types := colinfo.mysql_type;
isnull : constant Boolean := (row (F) = null);
sz : constant Natural := field_lengths (F);
ST : constant String := db_convert (row (F), sz);
Tout : constant field_types := dossier.output_type;
Tnative : constant field_types := colinfo.field_type;
errmsg : constant String := "native type : " &
field_types'Image (Tnative) & " binding type : " &
field_types'Image (Tout);
begin
if not dossier.bound then
goto continue;
end if;
if isnull or else CT.IsBlank (ST) then
set_as_null (dossier);
goto continue;
end if;
-- Derivation of implementation taken from PostgreSQL
-- Only guaranteed successful converstions allowed though
case Tout is
when ft_nbyte2 =>
case Tnative is
when ft_nbyte1 | ft_nbyte2 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_nbyte3 =>
case Tnative is
when ft_nbyte1 | ft_nbyte2 | ft_nbyte3 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_nbyte4 =>
case Tnative is
when ft_nbyte1 | ft_nbyte2 | ft_nbyte3 | ft_nbyte4 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_nbyte8 =>
case Tnative is
when ft_nbyte1 | ft_nbyte2 | ft_nbyte3 | ft_nbyte4 |
ft_nbyte8 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_byte2 =>
case Tnative is
when ft_byte1 | ft_byte2 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_byte3 =>
case Tnative is
when ft_byte1 | ft_byte2 | ft_byte3 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_byte4 =>
case Tnative is
when ft_byte1 | ft_byte2 | ft_byte3 | ft_byte4 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_byte8 =>
case Tnative is
when ft_byte1 | ft_byte2 | ft_byte3 | ft_byte4 |
ft_byte8 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_real18 =>
case Tnative is
when ft_real9 | ft_real18 =>
null; -- guaranteed to convert without loss
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when ft_textual =>
case Tnative is
when ft_textual | ft_utf8 =>
null;
when others =>
raise BINDING_TYPE_MISMATCH with errmsg;
end case;
when others =>
if Tnative /= Tout then
raise BINDING_TYPE_MISMATCH with errmsg;
end if;
end case;
case Tout is
when ft_nbyte0 => dossier.a00.all := (ST = "1");
when ft_nbyte1 => dossier.a01.all := convert (ST);
when ft_nbyte2 => dossier.a02.all := convert (ST);
when ft_nbyte3 => dossier.a03.all := convert (ST);
when ft_nbyte4 => dossier.a04.all := convert (ST);
when ft_nbyte8 => dossier.a05.all := convert (ST);
when ft_byte1 => dossier.a06.all := convert (ST);
when ft_byte2 => dossier.a07.all := convert (ST);
when ft_byte3 => dossier.a08.all := convert (ST);
when ft_byte4 => dossier.a09.all := convert (ST);
when ft_byte8 => dossier.a10.all := convert (ST);
when ft_real9 => dossier.a11.all := convert (ST);
when ft_real18 => dossier.a12.all := convert (ST);
when ft_widetext => dossier.a14.all := convert (ST);
when ft_supertext => dossier.a15.all := convert (ST);
when ft_enumtype => dossier.a18.all := ARC.convert (ST);
when ft_textual => dossier.a13.all := CT.SUS (ST);
when ft_utf8 => dossier.a21.all := ST;
when ft_geometry =>
-- MySQL internal geometry format is SRID + WKB
-- Remove the first 4 bytes and translate WKB
declare
wkbstring : String := ST (ST'First + 4 .. ST'Last);
begin
dossier.a22.all := WKB.Translate_WKB (wkbstring);
end;
when ft_timestamp =>
begin
dossier.a16.all := ARC.convert (ST);
exception
when AR.CONVERSION_FAILED =>
dossier.a16.all := AR.PARAM_IS_TIMESTAMP;
end;
when ft_chain =>
declare
FL : Natural := dossier.a17.all'Length;
DVLEN : Natural := ST'Length;
begin
if DVLEN > FL then
raise BINDING_SIZE_MISMATCH with "native size : " &
DVLEN'Img & " greater than binding size : " &
FL'Img;
end if;
dossier.a17.all := ARC.convert (ST, FL);
end;
when ft_bits =>
declare
FL : Natural := dossier.a20.all'Length;
DVLEN : Natural := ST'Length * 8;
begin
if DVLEN > FL then
raise BINDING_SIZE_MISMATCH with "native size : " &
DVLEN'Img & " greater than binding size : " &
FL'Img;
end if;
dossier.a20.all :=
ARC.convert (convert_to_bitstring (ST, FL));
end;
when ft_settype =>
declare
FL : Natural := dossier.a19.all'Length;
items : constant Natural := CT.num_set_items (ST);
begin
if items > FL then
raise BINDING_SIZE_MISMATCH with
"native size : " & items'Img &
" greater than binding size : " & FL'Img;
end if;
dossier.a19.all := ARC.convert (ST, FL);
end;
end case;
end;
<<continue>>
end loop;
return True;
end;
end internal_fetch_bound;
----------------------------------
-- internal_direct_post_exec --
----------------------------------
procedure internal_direct_post_exec (Stmt : out MySQL_statement;
newset : Boolean := False) is
begin
Stmt.successful_execution := False;
Stmt.size_of_rowset := 0;
if newset then
Stmt.log_nominal (category => statement_execution,
message => "Fetch next rowset from: "
& Stmt.sql_final.all);
else
Stmt.connection.execute (sql => Stmt.sql_final.all);
Stmt.log_nominal (category => statement_execution,
message => Stmt.sql_final.all);
Stmt.process_direct_result;
end if;
Stmt.successful_execution := True;
if Stmt.result_present then
Stmt.scan_column_information;
if Stmt.con_buffered then
Stmt.size_of_rowset := Stmt.mysql_conn.rows_in_result
(Stmt.result_handle);
end if;
Stmt.delivery := pending;
else
declare
returned_cols : Natural;
begin
returned_cols := Stmt.mysql_conn.field_count;
if returned_cols = 0 then
Stmt.impacted := Stmt.mysql_conn.rows_affected_by_execution;
else
raise ACM.RESULT_FAIL with "Columns returned without result";
end if;
end;
Stmt.delivery := completed;
end if;
exception
when ACM.QUERY_FAIL =>
Stmt.log_problem (category => statement_execution,
message => Stmt.sql_final.all,
pull_codes => True);
when RES : ACM.RESULT_FAIL =>
Stmt.log_problem (category => statement_execution,
message => EX.Exception_Message (X => RES),
pull_codes => True);
end internal_direct_post_exec;
-------------------------------
-- internal_post_prep_stmt --
-------------------------------
procedure internal_post_prep_stmt (Stmt : out MySQL_statement)
is
use type mysql_canvases_Access;
begin
Stmt.delivery := completed; -- default for early returns
if Stmt.num_columns = 0 then
Stmt.result_present := False;
Stmt.impacted := Stmt.mysql_conn.prep_rows_affected_by_execution
(Stmt.stmt_handle);
return;
end if;
Stmt.result_present := True;
if Stmt.bind_canvas /= null then
raise STMT_PREPARATION with
"Previous bind canvas present (expected to be null)";
end if;
Stmt.bind_canvas := new mysql_canvases (1 .. Stmt.num_columns);
declare
slots : ABM.MYSQL_BIND_Array (1 .. Stmt.num_columns);
ft : field_types;
fsize : Natural;
begin
for sx in slots'Range loop
slots (sx).is_null := Stmt.bind_canvas (sx).is_null'Access;
slots (sx).length := Stmt.bind_canvas (sx).length'Access;
slots (sx).error := Stmt.bind_canvas (sx).error'Access;
slots (sx).buffer_type := Stmt.column_info.Element (sx).mysql_type;
ft := Stmt.column_info.Element (sx).field_type;
case slots (sx).buffer_type is
when ABM.MYSQL_TYPE_DOUBLE =>
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_double'Address;
when ABM.MYSQL_TYPE_FLOAT =>
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_float'Address;
when ABM.MYSQL_TYPE_NEWDECIMAL | ABM.MYSQL_TYPE_DECIMAL =>
-- Don't set buffer_type to FLOAT or DOUBLE. MySQL will
-- automatically convert it, but precision will be lost.
-- Ask for a string and let's convert that ourselves.
slots (sx).buffer_type := ABM.MYSQL_TYPE_NEWDECIMAL;
fsize := Stmt.column_info.Element (sx).field_size;
slots (sx).buffer_length := ABM.IC.unsigned_long (fsize);
Stmt.bind_canvas (sx).buffer_binary := new ABM.IC.char_array
(1 .. ABM.IC.size_t (fsize));
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_binary.all'Address;
when ABM.MYSQL_TYPE_TINY =>
if ft = ft_nbyte0 or else ft = ft_nbyte1 then
slots (sx).is_unsigned := 1;
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_uint8'Address;
else
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_int8'Address;
end if;
when ABM.MYSQL_TYPE_SHORT | ABM.MYSQL_TYPE_YEAR =>
if ft = ft_nbyte2 then
slots (sx).is_unsigned := 1;
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_uint16'Address;
else
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_int16'Address;
end if;
when ABM.MYSQL_TYPE_INT24 | ABM.MYSQL_TYPE_LONG =>
if ft = ft_nbyte3 or else ft = ft_nbyte4 then
slots (sx).is_unsigned := 1;
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_uint32'Address;
else
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_int32'Address;
end if;
when ABM.MYSQL_TYPE_LONGLONG =>
if ft = ft_nbyte8 then
slots (sx).is_unsigned := 1;
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_uint64'Address;
else
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_int64'Address;
end if;
when ABM.MYSQL_TYPE_DATE | ABM.MYSQL_TYPE_TIMESTAMP |
ABM.MYSQL_TYPE_TIME | ABM.MYSQL_TYPE_DATETIME =>
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_time'Address;
when ABM.MYSQL_TYPE_BIT | ABM.MYSQL_TYPE_TINY_BLOB |
ABM.MYSQL_TYPE_MEDIUM_BLOB | ABM.MYSQL_TYPE_LONG_BLOB |
ABM.MYSQL_TYPE_BLOB | ABM.MYSQL_TYPE_STRING |
ABM.MYSQL_TYPE_VAR_STRING =>
fsize := Stmt.column_info.Element (sx).field_size;
slots (sx).buffer_length := ABM.IC.unsigned_long (fsize);
Stmt.bind_canvas (sx).buffer_binary := new ABM.IC.char_array
(1 .. ABM.IC.size_t (fsize));
slots (sx).buffer :=
Stmt.bind_canvas (sx).buffer_binary.all'Address;
when ABM.MYSQL_TYPE_NULL | ABM.MYSQL_TYPE_NEWDATE |
ABM.MYSQL_TYPE_VARCHAR | ABM.MYSQL_TYPE_GEOMETRY |
ABM.MYSQL_TYPE_ENUM | ABM.MYSQL_TYPE_SET =>
raise STMT_PREPARATION with
"Unsupported MySQL type for result binding attempted";
end case;
end loop;
if not Stmt.mysql_conn.prep_bind_result (Stmt.stmt_handle, slots)
then
Stmt.log_problem (category => statement_preparation,
message => "failed to bind result structures",
pull_codes => True);
return;
end if;
end;
if Stmt.con_buffered then
Stmt.mysql_conn.prep_store_result (Stmt.stmt_handle);
Stmt.size_of_rowset := Stmt.mysql_conn.prep_rows_in_result
(Stmt.stmt_handle);
end if;
Stmt.delivery := pending;
end internal_post_prep_stmt;
---------------------------
-- construct_bind_slot --
---------------------------
procedure construct_bind_slot (Stmt : MySQL_statement;
struct : out ABM.MYSQL_BIND;
canvas : out mysql_canvas;
marker : Positive)
is
procedure set_binary_buffer (Str : String);
zone : bindrec renames Stmt.realmccoy.Element (marker);
vartype : constant field_types := zone.output_type;
use type AR.NByte0_Access;
use type AR.NByte1_Access;
use type AR.NByte2_Access;
use type AR.NByte3_Access;
use type AR.NByte4_Access;
use type AR.NByte8_Access;
use type AR.Byte1_Access;
use type AR.Byte2_Access;
use type AR.Byte3_Access;
use type AR.Byte4_Access;
use type AR.Byte8_Access;
use type AR.Real9_Access;
use type AR.Real18_Access;
use type AR.Str1_Access;
use type AR.Str2_Access;
use type AR.Str4_Access;
use type AR.Time_Access;
use type AR.Enum_Access;
use type AR.Chain_Access;
use type AR.Settype_Access;
use type AR.Bits_Access;
use type AR.S_UTF8_Access;
use type AR.Geometry_Access;
procedure set_binary_buffer (Str : String)
is
len : constant ABM.IC.size_t := ABM.IC.size_t (Str'Length);
begin
canvas.buffer_binary := new ABM.IC.char_array (1 .. len);
canvas.buffer_binary.all := ABM.IC.To_C (Str, False);
canvas.length := ABM.IC.unsigned_long (len);
struct.buffer := canvas.buffer_binary.all'Address;
struct.buffer_length := ABM.IC.unsigned_long (len);
struct.length := canvas.length'Unchecked_Access;
struct.is_null := canvas.is_null'Unchecked_Access;
end set_binary_buffer;
begin
case vartype is
when ft_nbyte0 | ft_nbyte1 | ft_nbyte2 | ft_nbyte3 | ft_nbyte4 |
ft_nbyte8 => struct.is_unsigned := 1;
when others => null;
end case;
case vartype is
when ft_nbyte0 => struct.buffer_type := ABM.MYSQL_TYPE_TINY;
when ft_nbyte1 => struct.buffer_type := ABM.MYSQL_TYPE_TINY;
when ft_nbyte2 => struct.buffer_type := ABM.MYSQL_TYPE_SHORT;
when ft_nbyte3 => struct.buffer_type := ABM.MYSQL_TYPE_LONG;
when ft_nbyte4 => struct.buffer_type := ABM.MYSQL_TYPE_LONG;
when ft_nbyte8 => struct.buffer_type := ABM.MYSQL_TYPE_LONGLONG;
when ft_byte1 => struct.buffer_type := ABM.MYSQL_TYPE_TINY;
when ft_byte2 => struct.buffer_type := ABM.MYSQL_TYPE_SHORT;
when ft_byte3 => struct.buffer_type := ABM.MYSQL_TYPE_LONG;
when ft_byte4 => struct.buffer_type := ABM.MYSQL_TYPE_LONG;
when ft_byte8 => struct.buffer_type := ABM.MYSQL_TYPE_LONGLONG;
when ft_real9 => struct.buffer_type := ABM.MYSQL_TYPE_FLOAT;
when ft_real18 => struct.buffer_type := ABM.MYSQL_TYPE_DOUBLE;
when ft_textual => struct.buffer_type := ABM.MYSQL_TYPE_STRING;
when ft_widetext => struct.buffer_type := ABM.MYSQL_TYPE_STRING;
when ft_supertext => struct.buffer_type := ABM.MYSQL_TYPE_STRING;
when ft_timestamp => struct.buffer_type := ABM.MYSQL_TYPE_DATETIME;
when ft_chain => struct.buffer_type := ABM.MYSQL_TYPE_BLOB;
when ft_enumtype => struct.buffer_type := ABM.MYSQL_TYPE_STRING;
when ft_settype => struct.buffer_type := ABM.MYSQL_TYPE_STRING;
when ft_bits => struct.buffer_type := ABM.MYSQL_TYPE_STRING;
when ft_utf8 => struct.buffer_type := ABM.MYSQL_TYPE_STRING;
when ft_geometry => struct.buffer_type := ABM.MYSQL_TYPE_STRING;
end case;
if zone.null_data then
canvas.is_null := 1;
struct.buffer_type := ABM.MYSQL_TYPE_NULL;
else
case vartype is
when ft_nbyte0 =>
struct.buffer := canvas.buffer_uint8'Address;
if zone.a00 = null then
if zone.v00 then
canvas.buffer_uint8 := 1;
end if;
else
if zone.a00.all then
canvas.buffer_uint8 := 1;
end if;
end if;
when ft_nbyte1 =>
struct.buffer := canvas.buffer_uint8'Address;
if zone.a01 = null then
canvas.buffer_uint8 := ABM.IC.unsigned_char (zone.v01);
else
canvas.buffer_uint8 := ABM.IC.unsigned_char (zone.a01.all);
end if;
when ft_nbyte2 =>
struct.buffer := canvas.buffer_uint16'Address;
if zone.a02 = null then
canvas.buffer_uint16 := ABM.IC.unsigned_short (zone.v02);
else
canvas.buffer_uint16 := ABM.IC.unsigned_short (zone.a02.all);
end if;
when ft_nbyte3 =>
struct.buffer := canvas.buffer_uint32'Address;
-- ABM.MYSQL_TYPE_INT24 not for input, use next biggest
if zone.a03 = null then
canvas.buffer_uint32 := ABM.IC.unsigned (zone.v03);
else
canvas.buffer_uint32 := ABM.IC.unsigned (zone.a03.all);
end if;
when ft_nbyte4 =>
struct.buffer := canvas.buffer_uint32'Address;
if zone.a04 = null then
canvas.buffer_uint32 := ABM.IC.unsigned (zone.v04);
else
canvas.buffer_uint32 := ABM.IC.unsigned (zone.a04.all);
end if;
when ft_nbyte8 =>
struct.buffer := canvas.buffer_uint64'Address;
if zone.a05 = null then
canvas.buffer_uint64 := ABM.IC.unsigned_long (zone.v05);
else
canvas.buffer_uint64 := ABM.IC.unsigned_long (zone.a05.all);
end if;
when ft_byte1 =>
struct.buffer := canvas.buffer_int8'Address;
if zone.a06 = null then
canvas.buffer_int8 := ABM.IC.signed_char (zone.v06);
else
canvas.buffer_int8 := ABM.IC.signed_char (zone.a06.all);
end if;
when ft_byte2 =>
struct.buffer := canvas.buffer_int16'Address;
if zone.a07 = null then
canvas.buffer_int16 := ABM.IC.short (zone.v07);
else
canvas.buffer_int16 := ABM.IC.short (zone.a07.all);
end if;
when ft_byte3 =>
struct.buffer := canvas.buffer_int32'Address;
-- ABM.MYSQL_TYPE_INT24 not for input, use next biggest
if zone.a08 = null then
canvas.buffer_int32 := ABM.IC.int (zone.v08);
else
canvas.buffer_int32 := ABM.IC.int (zone.a08.all);
end if;
when ft_byte4 =>
struct.buffer := canvas.buffer_int32'Address;
if zone.a09 = null then
canvas.buffer_int32 := ABM.IC.int (zone.v09);
else
canvas.buffer_int32 := ABM.IC.int (zone.a09.all);
end if;
when ft_byte8 =>
struct.buffer := canvas.buffer_int64'Address;
if zone.a10 = null then
canvas.buffer_int64 := ABM.IC.long (zone.v10);
else
canvas.buffer_int64 := ABM.IC.long (zone.a10.all);
end if;
when ft_real9 =>
struct.buffer := canvas.buffer_float'Address;
if zone.a11 = null then
canvas.buffer_float := ABM.IC.C_float (zone.v11);
else
canvas.buffer_float := ABM.IC.C_float (zone.a11.all);
end if;
when ft_real18 =>
struct.buffer := canvas.buffer_double'Address;
if zone.a12 = null then
canvas.buffer_double := ABM.IC.double (zone.v12);
else
canvas.buffer_double := ABM.IC.double (zone.a12.all);
end if;
when ft_textual =>
if zone.a13 = null then
set_binary_buffer (ARC.convert (zone.v13));
else
set_binary_buffer (ARC.convert (zone.a13.all));
end if;
when ft_widetext =>
if zone.a14 = null then
set_binary_buffer (ARC.convert (zone.v14));
else
set_binary_buffer (ARC.convert (zone.a14.all));
end if;
when ft_supertext =>
if zone.a15 = null then
set_binary_buffer (ARC.convert (zone.v15));
else
set_binary_buffer (ARC.convert (zone.a15.all));
end if;
when ft_utf8 =>
if zone.a21 = null then
set_binary_buffer (ARC.convert (zone.v21));
else
set_binary_buffer (zone.a21.all);
end if;
when ft_geometry =>
if zone.a22 = null then
set_binary_buffer (WKB.produce_WKT (zone.v22));
else
set_binary_buffer (Spatial_Data.Well_Known_Text (zone.a22.all));
end if;
when ft_timestamp =>
struct.buffer := canvas.buffer_time'Address;
declare
hack : CAL.Time;
begin
if zone.a16 = null then
hack := zone.v16;
else
hack := zone.a16.all;
end if;
-- Negative time not supported
canvas.buffer_time.year := ABM.IC.unsigned (CFM.Year (hack));
canvas.buffer_time.month := ABM.IC.unsigned (CFM.Month (hack));
canvas.buffer_time.day := ABM.IC.unsigned (CFM.Day (hack));
canvas.buffer_time.hour := ABM.IC.unsigned (CFM.Hour (hack));
canvas.buffer_time.minute := ABM.IC.unsigned
(CFM.Minute (hack));
canvas.buffer_time.second := ABM.IC.unsigned
(CFM.Second (hack));
canvas.buffer_time.second_part :=
ABM.IC.unsigned_long (CFM.Sub_Second (hack) * 1000000);
end;
when ft_chain =>
if zone.a17 = null then
set_binary_buffer (CT.USS (zone.v17));
else
set_binary_buffer (ARC.convert (zone.a17.all));
end if;
when ft_enumtype =>
if zone.a18 = null then
set_binary_buffer (ARC.convert (zone.v18.enumeration));
else
set_binary_buffer (ARC.convert (zone.a18.all.enumeration));
end if;
when ft_settype =>
if zone.a19 = null then
set_binary_buffer (CT.USS (zone.v19));
else
set_binary_buffer (ARC.convert (zone.a19.all));
end if;
when ft_bits =>
if zone.a20 = null then
set_binary_buffer (CT.USS (zone.v20));
else
set_binary_buffer (ARC.convert (zone.a20.all));
end if;
end case;
end if;
end construct_bind_slot;
-------------------
-- log_problem --
-------------------
procedure log_problem
(statement : MySQL_statement;
category : Log_Category;
message : String;
pull_codes : Boolean := False;
break : Boolean := False)
is
error_msg : CT.Text := CT.blank;
error_code : Driver_Codes := 0;
sqlstate : SQL_State := stateless;
begin
if pull_codes then
error_msg := CT.SUS (statement.last_driver_message);
error_code := statement.last_driver_code;
sqlstate := statement.last_sql_state;
end if;
logger_access.all.log_problem
(driver => statement.dialect,
category => category,
message => CT.SUS (message),
error_msg => error_msg,
error_code => error_code,
sqlstate => sqlstate,
break => break);
end log_problem;
---------------------
-- num_set_items --
---------------------
function num_set_items (nv : String) return Natural
is
result : Natural := 0;
begin
if not CT.IsBlank (nv) then
result := 1;
for x in nv'Range loop
if nv (x) = ',' then
result := result + 1;
end if;
end loop;
end if;
return result;
end num_set_items;
----------------------------
-- convert_to_bitstring --
----------------------------
function convert_to_bitstring (nv : String; width : Natural) return String
is
use type AR.NByte1;
result : String (1 .. width) := (others => '0');
marker : Natural;
lode : AR.NByte1;
mask : constant array (0 .. 7) of AR.NByte1 := (2 ** 0, 2 ** 1,
2 ** 2, 2 ** 3,
2 ** 4, 2 ** 5,
2 ** 6, 2 ** 7);
begin
-- We can't seem to get the true size, e.g 12 bits shows as 2,
-- for two bytes, which could represent up to 16 bits. Thus, we
-- return a variable width in multiples of 8. MySQL doesn't mind
-- leading zeros.
marker := result'Last;
for x in reverse nv'Range loop
lode := AR.NByte1 (Character'Pos (nv (x)));
for position in mask'Range loop
if (lode and mask (position)) > 0 then
result (marker) := '1';
end if;
exit when marker = result'First;
marker := marker - 1;
end loop;
end loop;
return result;
end convert_to_bitstring;
end AdaBase.Statement.Base.MySQL;
|
with
lace.Subject.local;
package gel.Mouse.local
--
-- Provides a concrete mouse.
--
is
type Item is limited new lace.Subject.local.item
and gel.Mouse .item with private;
type View is access all Item'Class;
package Forge
is
function to_Mouse (of_Name : in String) return Item;
function new_Mouse (of_Name : in String) return View;
end Forge;
procedure free (Self : in out View);
private
type Item is limited new lace.Subject.local.item
and gel.Mouse .item with null record;
end gel.Mouse.local;
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from ATSAMD51G19A.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package SAM_SVD.MCLK is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- Interrupt Enable Clear
type MCLK_INTENCLR_Register is record
-- Clock Ready Interrupt Enable
CKRDY : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for MCLK_INTENCLR_Register use record
CKRDY at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Interrupt Enable Set
type MCLK_INTENSET_Register is record
-- Clock Ready Interrupt Enable
CKRDY : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for MCLK_INTENSET_Register use record
CKRDY at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Interrupt Flag Status and Clear
type MCLK_INTFLAG_Register is record
-- Clock Ready
CKRDY : Boolean := True;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for MCLK_INTFLAG_Register use record
CKRDY at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- AHB Mask
type MCLK_AHBMASK_Register is record
-- HPB0 AHB Clock Mask
HPB0 : Boolean := True;
-- HPB1 AHB Clock Mask
HPB1 : Boolean := True;
-- HPB2 AHB Clock Mask
HPB2 : Boolean := True;
-- HPB3 AHB Clock Mask
HPB3 : Boolean := True;
-- DSU AHB Clock Mask
DSU : Boolean := True;
-- HMATRIX AHB Clock Mask
HMATRIX : Boolean := True;
-- NVMCTRL AHB Clock Mask
NVMCTRL : Boolean := True;
-- HSRAM AHB Clock Mask
HSRAM : Boolean := True;
-- CMCC AHB Clock Mask
CMCC : Boolean := True;
-- DMAC AHB Clock Mask
DMAC : Boolean := True;
-- USB AHB Clock Mask
USB : Boolean := True;
-- BKUPRAM AHB Clock Mask
BKUPRAM : Boolean := True;
-- PAC AHB Clock Mask
PAC : Boolean := True;
-- QSPI AHB Clock Mask
QSPI : Boolean := True;
-- unspecified
Reserved_14_14 : HAL.Bit := 16#1#;
-- SDHC0 AHB Clock Mask
SDHC0 : Boolean := True;
-- unspecified
Reserved_16_18 : HAL.UInt3 := 16#7#;
-- ICM AHB Clock Mask
ICM : Boolean := True;
-- PUKCC AHB Clock Mask
PUKCC : Boolean := True;
-- QSPI_2X AHB Clock Mask
QSPI_2X : Boolean := True;
-- NVMCTRL_SMEEPROM AHB Clock Mask
NVMCTRL_SMEEPROM : Boolean := True;
-- NVMCTRL_CACHE AHB Clock Mask
NVMCTRL_CACHE : Boolean := True;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MCLK_AHBMASK_Register use record
HPB0 at 0 range 0 .. 0;
HPB1 at 0 range 1 .. 1;
HPB2 at 0 range 2 .. 2;
HPB3 at 0 range 3 .. 3;
DSU at 0 range 4 .. 4;
HMATRIX at 0 range 5 .. 5;
NVMCTRL at 0 range 6 .. 6;
HSRAM at 0 range 7 .. 7;
CMCC at 0 range 8 .. 8;
DMAC at 0 range 9 .. 9;
USB at 0 range 10 .. 10;
BKUPRAM at 0 range 11 .. 11;
PAC at 0 range 12 .. 12;
QSPI at 0 range 13 .. 13;
Reserved_14_14 at 0 range 14 .. 14;
SDHC0 at 0 range 15 .. 15;
Reserved_16_18 at 0 range 16 .. 18;
ICM at 0 range 19 .. 19;
PUKCC at 0 range 20 .. 20;
QSPI_2X at 0 range 21 .. 21;
NVMCTRL_SMEEPROM at 0 range 22 .. 22;
NVMCTRL_CACHE at 0 range 23 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-- APBA Mask
type MCLK_APBAMASK_Register is record
-- PAC APB Clock Enable
PAC : Boolean := True;
-- PM APB Clock Enable
PM : Boolean := True;
-- MCLK APB Clock Enable
MCLK : Boolean := True;
-- RSTC APB Clock Enable
RSTC : Boolean := True;
-- OSCCTRL APB Clock Enable
OSCCTRL : Boolean := True;
-- OSC32KCTRL APB Clock Enable
OSC32KCTRL : Boolean := True;
-- SUPC APB Clock Enable
SUPC : Boolean := True;
-- GCLK APB Clock Enable
GCLK : Boolean := True;
-- WDT APB Clock Enable
WDT : Boolean := True;
-- RTC APB Clock Enable
RTC : Boolean := True;
-- EIC APB Clock Enable
EIC : Boolean := True;
-- FREQM APB Clock Enable
FREQM : Boolean := False;
-- SERCOM0 APB Clock Enable
SERCOM0 : Boolean := False;
-- SERCOM1 APB Clock Enable
SERCOM1 : Boolean := False;
-- TC0 APB Clock Enable
TC0 : Boolean := False;
-- TC1 APB Clock Enable
TC1 : Boolean := False;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MCLK_APBAMASK_Register use record
PAC at 0 range 0 .. 0;
PM at 0 range 1 .. 1;
MCLK at 0 range 2 .. 2;
RSTC at 0 range 3 .. 3;
OSCCTRL at 0 range 4 .. 4;
OSC32KCTRL at 0 range 5 .. 5;
SUPC at 0 range 6 .. 6;
GCLK at 0 range 7 .. 7;
WDT at 0 range 8 .. 8;
RTC at 0 range 9 .. 9;
EIC at 0 range 10 .. 10;
FREQM at 0 range 11 .. 11;
SERCOM0 at 0 range 12 .. 12;
SERCOM1 at 0 range 13 .. 13;
TC0 at 0 range 14 .. 14;
TC1 at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- APBB Mask
type MCLK_APBBMASK_Register is record
-- USB APB Clock Enable
USB : Boolean := False;
-- DSU APB Clock Enable
DSU : Boolean := True;
-- NVMCTRL APB Clock Enable
NVMCTRL : Boolean := True;
-- unspecified
Reserved_3_3 : HAL.Bit := 16#0#;
-- PORT APB Clock Enable
PORT : Boolean := True;
-- unspecified
Reserved_5_5 : HAL.Bit := 16#0#;
-- HMATRIX APB Clock Enable
HMATRIX : Boolean := True;
-- EVSYS APB Clock Enable
EVSYS : Boolean := False;
-- unspecified
Reserved_8_8 : HAL.Bit := 16#0#;
-- SERCOM2 APB Clock Enable
SERCOM2 : Boolean := False;
-- SERCOM3 APB Clock Enable
SERCOM3 : Boolean := False;
-- TCC0 APB Clock Enable
TCC0 : Boolean := False;
-- TCC1 APB Clock Enable
TCC1 : Boolean := False;
-- TC2 APB Clock Enable
TC2 : Boolean := False;
-- TC3 APB Clock Enable
TC3 : Boolean := False;
-- unspecified
Reserved_15_15 : HAL.Bit := 16#1#;
-- RAMECC APB Clock Enable
RAMECC : Boolean := True;
-- unspecified
Reserved_17_31 : HAL.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MCLK_APBBMASK_Register use record
USB at 0 range 0 .. 0;
DSU at 0 range 1 .. 1;
NVMCTRL at 0 range 2 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
PORT at 0 range 4 .. 4;
Reserved_5_5 at 0 range 5 .. 5;
HMATRIX at 0 range 6 .. 6;
EVSYS at 0 range 7 .. 7;
Reserved_8_8 at 0 range 8 .. 8;
SERCOM2 at 0 range 9 .. 9;
SERCOM3 at 0 range 10 .. 10;
TCC0 at 0 range 11 .. 11;
TCC1 at 0 range 12 .. 12;
TC2 at 0 range 13 .. 13;
TC3 at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
RAMECC at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
-- APBC Mask
type MCLK_APBCMASK_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- TCC2 APB Clock Enable
TCC2 : Boolean := False;
-- unspecified
Reserved_4_6 : HAL.UInt3 := 16#0#;
-- PDEC APB Clock Enable
PDEC : Boolean := False;
-- AC APB Clock Enable
AC : Boolean := False;
-- AES APB Clock Enable
AES : Boolean := False;
-- TRNG APB Clock Enable
TRNG : Boolean := False;
-- ICM APB Clock Enable
ICM : Boolean := False;
-- unspecified
Reserved_12_12 : HAL.Bit := 16#0#;
-- QSPI APB Clock Enable
QSPI : Boolean := True;
-- CCL APB Clock Enable
CCL : Boolean := False;
-- unspecified
Reserved_15_31 : HAL.UInt17 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MCLK_APBCMASK_Register use record
Reserved_0_2 at 0 range 0 .. 2;
TCC2 at 0 range 3 .. 3;
Reserved_4_6 at 0 range 4 .. 6;
PDEC at 0 range 7 .. 7;
AC at 0 range 8 .. 8;
AES at 0 range 9 .. 9;
TRNG at 0 range 10 .. 10;
ICM at 0 range 11 .. 11;
Reserved_12_12 at 0 range 12 .. 12;
QSPI at 0 range 13 .. 13;
CCL at 0 range 14 .. 14;
Reserved_15_31 at 0 range 15 .. 31;
end record;
-- APBD Mask
type MCLK_APBDMASK_Register is record
-- SERCOM4 APB Clock Enable
SERCOM4 : Boolean := False;
-- SERCOM5 APB Clock Enable
SERCOM5 : Boolean := False;
-- unspecified
Reserved_2_6 : HAL.UInt5 := 16#0#;
-- ADC0 APB Clock Enable
ADC0 : Boolean := False;
-- ADC1 APB Clock Enable
ADC1 : Boolean := False;
-- DAC APB Clock Enable
DAC : Boolean := False;
-- unspecified
Reserved_10_10 : HAL.Bit := 16#0#;
-- PCC APB Clock Enable
PCC : Boolean := False;
-- unspecified
Reserved_12_31 : HAL.UInt20 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MCLK_APBDMASK_Register use record
SERCOM4 at 0 range 0 .. 0;
SERCOM5 at 0 range 1 .. 1;
Reserved_2_6 at 0 range 2 .. 6;
ADC0 at 0 range 7 .. 7;
ADC1 at 0 range 8 .. 8;
DAC at 0 range 9 .. 9;
Reserved_10_10 at 0 range 10 .. 10;
PCC at 0 range 11 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Main Clock
type MCLK_Peripheral is record
-- Interrupt Enable Clear
INTENCLR : aliased MCLK_INTENCLR_Register;
-- Interrupt Enable Set
INTENSET : aliased MCLK_INTENSET_Register;
-- Interrupt Flag Status and Clear
INTFLAG : aliased MCLK_INTFLAG_Register;
-- HS Clock Division
HSDIV : aliased HAL.UInt8;
-- CPU Clock Division
CPUDIV : aliased HAL.UInt8;
-- AHB Mask
AHBMASK : aliased MCLK_AHBMASK_Register;
-- APBA Mask
APBAMASK : aliased MCLK_APBAMASK_Register;
-- APBB Mask
APBBMASK : aliased MCLK_APBBMASK_Register;
-- APBC Mask
APBCMASK : aliased MCLK_APBCMASK_Register;
-- APBD Mask
APBDMASK : aliased MCLK_APBDMASK_Register;
end record
with Volatile;
for MCLK_Peripheral use record
INTENCLR at 16#1# range 0 .. 7;
INTENSET at 16#2# range 0 .. 7;
INTFLAG at 16#3# range 0 .. 7;
HSDIV at 16#4# range 0 .. 7;
CPUDIV at 16#5# range 0 .. 7;
AHBMASK at 16#10# range 0 .. 31;
APBAMASK at 16#14# range 0 .. 31;
APBBMASK at 16#18# range 0 .. 31;
APBCMASK at 16#1C# range 0 .. 31;
APBDMASK at 16#20# range 0 .. 31;
end record;
-- Main Clock
MCLK_Periph : aliased MCLK_Peripheral
with Import, Address => MCLK_Base;
end SAM_SVD.MCLK;
|
with GA_Maths;
package Multivector_Type_Base is
-- Object_Type mvtypebase.h lines 8 - 13 and 36
-- A versor is also a multivetor
-- A blade is also a versor and, therfore, also a multivector
type Object_Type is (Unspecified_Object_Type, Blade_MV, Versor_MV, MV_Object);
type Parity is (No_Parity, Even_Parity, Odd_Parity); -- line 43
-- mvtypebase.h lines 33 - 43
type MV_Typebase is record
M_Zero : boolean := False; -- True if multivector is zero
M_Type : Object_Type := Unspecified_Object_Type;
M_Grade : integer := -1; -- Top grade occupied by the multivector
M_Grade_Use : GA_Maths.Grade_Usage := 0; -- Bit map indicating which grades are present
M_Parity : Parity := No_Parity;
end record;
-- procedure Set_Grade_Usage (Base : in out Type_Base; GU : GA_Maths.Grade_Usage);
-- procedure Set_M_Type (Base : in out Type_Base; theType : Object_Type);
-- procedure Set_Parity (Base : in out Type_Base; Par : Parity);
-- procedure Set_Top_Grade (Base : in out Type_Base; Grade : Integer);
procedure Set_Type_Base (Base : in out MV_Typebase; Zero : boolean;
Object : Object_Type; Grade : integer;
GU : GA_Maths.Grade_Usage; Par : Parity := No_Parity);
private
type Flag is (Valid);
end Multivector_Type_Base;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- P R J . D E C T --
-- --
-- B o d y --
-- --
-- Copyright (C) 2001-2016, 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. 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 COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Err_Vars; use Err_Vars;
with Opt; use Opt;
with Prj.Attr; use Prj.Attr;
with Prj.Attr.PM; use Prj.Attr.PM;
with Prj.Err; use Prj.Err;
with Prj.Strt; use Prj.Strt;
with Prj.Tree; use Prj.Tree;
with Snames;
with Uintp; use Uintp;
with GNAT; use GNAT;
with GNAT.Case_Util; use GNAT.Case_Util;
with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
with GNAT.Strings;
package body Prj.Dect is
type Zone is (In_Project, In_Package, In_Case_Construction);
-- Used to indicate if we are parsing a package (In_Package), a case
-- construction (In_Case_Construction) or none of those two (In_Project).
procedure Rename_Obsolescent_Attributes
(In_Tree : Project_Node_Tree_Ref;
Attribute : Project_Node_Id;
Current_Package : Project_Node_Id);
-- Rename obsolescent attributes in the tree. When the attribute has been
-- renamed since its initial introduction in the design of projects, we
-- replace the old name in the tree with the new name, so that the code
-- does not have to check both names forever.
procedure Check_Attribute_Allowed
(In_Tree : Project_Node_Tree_Ref;
Project : Project_Node_Id;
Attribute : Project_Node_Id;
Flags : Processing_Flags);
-- Check whether the attribute is valid in this project. In particular,
-- depending on the type of project (qualifier), some attributes might
-- be disabled.
procedure Check_Package_Allowed
(In_Tree : Project_Node_Tree_Ref;
Project : Project_Node_Id;
Current_Package : Project_Node_Id;
Flags : Processing_Flags);
-- Check whether the package is valid in this project
procedure Parse_Attribute_Declaration
(In_Tree : Project_Node_Tree_Ref;
Attribute : out Project_Node_Id;
First_Attribute : Attribute_Node_Id;
Current_Project : Project_Node_Id;
Current_Package : Project_Node_Id;
Packages_To_Check : String_List_Access;
Flags : Processing_Flags);
-- Parse an attribute declaration
procedure Parse_Case_Construction
(In_Tree : Project_Node_Tree_Ref;
Case_Construction : out Project_Node_Id;
First_Attribute : Attribute_Node_Id;
Current_Project : Project_Node_Id;
Current_Package : Project_Node_Id;
Packages_To_Check : String_List_Access;
Is_Config_File : Boolean;
Flags : Processing_Flags);
-- Parse a case construction
procedure Parse_Declarative_Items
(In_Tree : Project_Node_Tree_Ref;
Declarations : out Project_Node_Id;
In_Zone : Zone;
First_Attribute : Attribute_Node_Id;
Current_Project : Project_Node_Id;
Current_Package : Project_Node_Id;
Packages_To_Check : String_List_Access;
Is_Config_File : Boolean;
Flags : Processing_Flags);
-- Parse declarative items. Depending on In_Zone, some declarative items
-- may be forbidden. Is_Config_File should be set to True if the project
-- represents a config file (.cgpr) since some specific checks apply.
procedure Parse_Package_Declaration
(In_Tree : Project_Node_Tree_Ref;
Package_Declaration : out Project_Node_Id;
Current_Project : Project_Node_Id;
Packages_To_Check : String_List_Access;
Is_Config_File : Boolean;
Flags : Processing_Flags);
-- Parse a package declaration.
-- Is_Config_File should be set to True if the project represents a config
-- file (.cgpr) since some specific checks apply.
procedure Parse_String_Type_Declaration
(In_Tree : Project_Node_Tree_Ref;
String_Type : out Project_Node_Id;
Current_Project : Project_Node_Id;
Flags : Processing_Flags);
-- type <name> is ( <literal_string> { , <literal_string> } ) ;
procedure Parse_Variable_Declaration
(In_Tree : Project_Node_Tree_Ref;
Variable : out Project_Node_Id;
Current_Project : Project_Node_Id;
Current_Package : Project_Node_Id;
Flags : Processing_Flags);
-- Parse a variable assignment
-- <variable_Name> := <expression>; OR
-- <variable_Name> : <string_type_Name> := <string_expression>;
-----------
-- Parse --
-----------
procedure Parse
(In_Tree : Project_Node_Tree_Ref;
Declarations : out Project_Node_Id;
Current_Project : Project_Node_Id;
Extends : Project_Node_Id;
Packages_To_Check : String_List_Access;
Is_Config_File : Boolean;
Flags : Processing_Flags)
is
First_Declarative_Item : Project_Node_Id := Empty_Node;
begin
Declarations :=
Default_Project_Node
(Of_Kind => N_Project_Declaration, In_Tree => In_Tree);
Set_Location_Of (Declarations, In_Tree, To => Token_Ptr);
Set_Extended_Project_Of (Declarations, In_Tree, To => Extends);
Set_Project_Declaration_Of (Current_Project, In_Tree, Declarations);
Parse_Declarative_Items
(Declarations => First_Declarative_Item,
In_Tree => In_Tree,
In_Zone => In_Project,
First_Attribute => Prj.Attr.Attribute_First,
Current_Project => Current_Project,
Current_Package => Empty_Node,
Packages_To_Check => Packages_To_Check,
Is_Config_File => Is_Config_File,
Flags => Flags);
Set_First_Declarative_Item_Of
(Declarations, In_Tree, To => First_Declarative_Item);
end Parse;
-----------------------------------
-- Rename_Obsolescent_Attributes --
-----------------------------------
procedure Rename_Obsolescent_Attributes
(In_Tree : Project_Node_Tree_Ref;
Attribute : Project_Node_Id;
Current_Package : Project_Node_Id)
is
begin
if Present (Current_Package)
and then Expression_Kind_Of (Current_Package, In_Tree) /= Ignored
then
case Name_Of (Attribute, In_Tree) is
when Snames.Name_Specification =>
Set_Name_Of (Attribute, In_Tree, To => Snames.Name_Spec);
when Snames.Name_Specification_Suffix =>
Set_Name_Of (Attribute, In_Tree, To => Snames.Name_Spec_Suffix);
when Snames.Name_Implementation =>
Set_Name_Of (Attribute, In_Tree, To => Snames.Name_Body);
when Snames.Name_Implementation_Suffix =>
Set_Name_Of (Attribute, In_Tree, To => Snames.Name_Body_Suffix);
when others =>
null;
end case;
end if;
end Rename_Obsolescent_Attributes;
---------------------------
-- Check_Package_Allowed --
---------------------------
procedure Check_Package_Allowed
(In_Tree : Project_Node_Tree_Ref;
Project : Project_Node_Id;
Current_Package : Project_Node_Id;
Flags : Processing_Flags)
is
Qualif : constant Project_Qualifier :=
Project_Qualifier_Of (Project, In_Tree);
Name : constant Name_Id := Name_Of (Current_Package, In_Tree);
begin
if Name /= Snames.Name_Ide
and then
((Qualif = Aggregate and then Name /= Snames.Name_Builder)
or else
(Qualif = Aggregate_Library and then Name /= Snames.Name_Builder
and then Name /= Snames.Name_Install))
then
Error_Msg_Name_1 := Name;
Error_Msg
(Flags,
"package %% is forbidden in aggregate projects",
Location_Of (Current_Package, In_Tree));
end if;
end Check_Package_Allowed;
-----------------------------
-- Check_Attribute_Allowed --
-----------------------------
procedure Check_Attribute_Allowed
(In_Tree : Project_Node_Tree_Ref;
Project : Project_Node_Id;
Attribute : Project_Node_Id;
Flags : Processing_Flags)
is
Qualif : constant Project_Qualifier :=
Project_Qualifier_Of (Project, In_Tree);
Name : constant Name_Id := Name_Of (Attribute, In_Tree);
begin
case Qualif is
when Aggregate
| Aggregate_Library
=>
if Name = Snames.Name_Languages
or else Name = Snames.Name_Source_Files
or else Name = Snames.Name_Source_List_File
or else Name = Snames.Name_Locally_Removed_Files
or else Name = Snames.Name_Excluded_Source_Files
or else Name = Snames.Name_Excluded_Source_List_File
or else Name = Snames.Name_Interfaces
or else Name = Snames.Name_Object_Dir
or else Name = Snames.Name_Exec_Dir
or else Name = Snames.Name_Source_Dirs
or else Name = Snames.Name_Inherit_Source_Path
or else
(Qualif = Aggregate and then Name = Snames.Name_Library_Dir)
or else
(Qualif = Aggregate and then Name = Snames.Name_Library_Name)
or else Name = Snames.Name_Main
or else Name = Snames.Name_Roots
or else Name = Snames.Name_Externally_Built
or else Name = Snames.Name_Executable
or else Name = Snames.Name_Executable_Suffix
or else Name = Snames.Name_Default_Switches
then
Error_Msg_Name_1 := Name;
Error_Msg
(Flags,
"%% is not valid in aggregate projects",
Location_Of (Attribute, In_Tree));
end if;
when others =>
if Name = Snames.Name_Project_Files
or else Name = Snames.Name_Project_Path
or else Name = Snames.Name_External
then
Error_Msg_Name_1 := Name;
Error_Msg
(Flags,
"%% is only valid in aggregate projects",
Location_Of (Attribute, In_Tree));
end if;
end case;
end Check_Attribute_Allowed;
---------------------------------
-- Parse_Attribute_Declaration --
---------------------------------
procedure Parse_Attribute_Declaration
(In_Tree : Project_Node_Tree_Ref;
Attribute : out Project_Node_Id;
First_Attribute : Attribute_Node_Id;
Current_Project : Project_Node_Id;
Current_Package : Project_Node_Id;
Packages_To_Check : String_List_Access;
Flags : Processing_Flags)
is
Current_Attribute : Attribute_Node_Id := First_Attribute;
Full_Associative_Array : Boolean := False;
Attribute_Name : Name_Id := No_Name;
Optional_Index : Boolean := False;
Pkg_Id : Package_Node_Id := Empty_Package;
procedure Process_Attribute_Name;
-- Read the name of the attribute, and check its type
procedure Process_Associative_Array_Index;
-- Read the index of the associative array and check its validity
----------------------------
-- Process_Attribute_Name --
----------------------------
procedure Process_Attribute_Name is
Ignore : Boolean;
begin
Attribute_Name := Token_Name;
Set_Name_Of (Attribute, In_Tree, To => Attribute_Name);
Set_Location_Of (Attribute, In_Tree, To => Token_Ptr);
-- Find the attribute
Current_Attribute :=
Attribute_Node_Id_Of (Attribute_Name, First_Attribute);
-- If the attribute cannot be found, create the attribute if inside
-- an unknown package.
if Current_Attribute = Empty_Attribute then
if Present (Current_Package)
and then Expression_Kind_Of (Current_Package, In_Tree) = Ignored
then
Pkg_Id := Package_Id_Of (Current_Package, In_Tree);
Add_Attribute (Pkg_Id, Token_Name, Current_Attribute);
else
-- If not a valid attribute name, issue an error if inside
-- a package that need to be checked.
Ignore := Present (Current_Package) and then
Packages_To_Check /= All_Packages;
if Ignore then
-- Check that we are not in a package to check
Get_Name_String (Name_Of (Current_Package, In_Tree));
for Index in Packages_To_Check'Range loop
if Name_Buffer (1 .. Name_Len) =
Packages_To_Check (Index).all
then
Ignore := False;
exit;
end if;
end loop;
end if;
if not Ignore then
Error_Msg_Name_1 := Token_Name;
Error_Msg (Flags, "undefined attribute %%", Token_Ptr);
end if;
end if;
-- Set, if appropriate the index case insensitivity flag
else
if Is_Read_Only (Current_Attribute) then
Error_Msg_Name_1 := Token_Name;
Error_Msg
(Flags, "read-only attribute %% cannot be given a value",
Token_Ptr);
end if;
if Attribute_Kind_Of (Current_Attribute) in
All_Case_Insensitive_Associative_Array
then
Set_Case_Insensitive (Attribute, In_Tree, To => True);
end if;
end if;
Scan (In_Tree); -- past the attribute name
-- Set the expression kind of the attribute
if Current_Attribute /= Empty_Attribute then
Set_Expression_Kind_Of
(Attribute, In_Tree, To => Variable_Kind_Of (Current_Attribute));
Optional_Index := Optional_Index_Of (Current_Attribute);
end if;
end Process_Attribute_Name;
-------------------------------------
-- Process_Associative_Array_Index --
-------------------------------------
procedure Process_Associative_Array_Index is
begin
-- If the attribute is not an associative array attribute, report
-- an error. If this information is still unknown, set the kind
-- to Associative_Array.
if Current_Attribute /= Empty_Attribute
and then Attribute_Kind_Of (Current_Attribute) = Single
then
Error_Msg (Flags,
"the attribute """ &
Get_Name_String (Attribute_Name_Of (Current_Attribute))
& """ cannot be an associative array",
Location_Of (Attribute, In_Tree));
elsif Attribute_Kind_Of (Current_Attribute) = Unknown then
Set_Attribute_Kind_Of (Current_Attribute, To => Associative_Array);
end if;
Scan (In_Tree); -- past the left parenthesis
if Others_Allowed_For (Current_Attribute)
and then Token = Tok_Others
then
Set_Associative_Array_Index_Of
(Attribute, In_Tree, All_Other_Names);
Scan (In_Tree); -- past others
else
if Others_Allowed_For (Current_Attribute) then
Expect (Tok_String_Literal, "literal string or others");
else
Expect (Tok_String_Literal, "literal string");
end if;
if Token = Tok_String_Literal then
Get_Name_String (Token_Name);
if Case_Insensitive (Attribute, In_Tree) then
To_Lower (Name_Buffer (1 .. Name_Len));
end if;
Set_Associative_Array_Index_Of (Attribute, In_Tree, Name_Find);
Scan (In_Tree); -- past the literal string index
if Token = Tok_At then
case Attribute_Kind_Of (Current_Attribute) is
when Optional_Index_Associative_Array
| Optional_Index_Case_Insensitive_Associative_Array
=>
Scan (In_Tree);
Expect (Tok_Integer_Literal, "integer literal");
if Token = Tok_Integer_Literal then
-- Set the source index value from given literal
declare
Index : constant Int :=
UI_To_Int (Int_Literal_Value);
begin
if Index = 0 then
Error_Msg
(Flags, "index cannot be zero", Token_Ptr);
else
Set_Source_Index_Of
(Attribute, In_Tree, To => Index);
end if;
end;
Scan (In_Tree);
end if;
when others =>
Error_Msg (Flags, "index not allowed here", Token_Ptr);
Scan (In_Tree);
if Token = Tok_Integer_Literal then
Scan (In_Tree);
end if;
end case;
end if;
end if;
end if;
Expect (Tok_Right_Paren, "`)`");
if Token = Tok_Right_Paren then
Scan (In_Tree); -- past the right parenthesis
end if;
end Process_Associative_Array_Index;
begin
Attribute :=
Default_Project_Node
(Of_Kind => N_Attribute_Declaration, In_Tree => In_Tree);
Set_Location_Of (Attribute, In_Tree, To => Token_Ptr);
Set_Previous_Line_Node (Attribute);
-- Scan past "for"
Scan (In_Tree);
-- Body or External may be an attribute name
if Token = Tok_Body then
Token := Tok_Identifier;
Token_Name := Snames.Name_Body;
end if;
if Token = Tok_External then
Token := Tok_Identifier;
Token_Name := Snames.Name_External;
end if;
Expect (Tok_Identifier, "identifier");
Process_Attribute_Name;
Rename_Obsolescent_Attributes (In_Tree, Attribute, Current_Package);
Check_Attribute_Allowed (In_Tree, Current_Project, Attribute, Flags);
-- Associative array attributes
if Token = Tok_Left_Paren then
Process_Associative_Array_Index;
else
-- If it is an associative array attribute and there are no left
-- parenthesis, then this is a full associative array declaration.
-- Flag it as such for later processing of its value.
if Current_Attribute /= Empty_Attribute
and then
Attribute_Kind_Of (Current_Attribute) /= Single
then
if Attribute_Kind_Of (Current_Attribute) = Unknown then
Set_Attribute_Kind_Of (Current_Attribute, To => Single);
else
Full_Associative_Array := True;
end if;
end if;
end if;
Expect (Tok_Use, "USE");
if Token = Tok_Use then
Scan (In_Tree);
if Full_Associative_Array then
-- Expect <project>'<same_attribute_name>, or
-- <project>.<same_package_name>'<same_attribute_name>
declare
The_Project : Project_Node_Id := Empty_Node;
-- The node of the project where the associative array is
-- declared.
The_Package : Project_Node_Id := Empty_Node;
-- The node of the package where the associative array is
-- declared, if any.
Project_Name : Name_Id := No_Name;
-- The name of the project where the associative array is
-- declared.
Location : Source_Ptr := No_Location;
-- The location of the project name
begin
Expect (Tok_Identifier, "identifier");
if Token = Tok_Identifier then
Location := Token_Ptr;
-- Find the project node in the imported project or
-- in the project being extended.
The_Project := Imported_Or_Extended_Project_Of
(Current_Project, In_Tree, Token_Name);
if No (The_Project) and then not In_Tree.Incomplete_With then
Error_Msg (Flags, "unknown project", Location);
Scan (In_Tree); -- past the project name
else
Project_Name := Token_Name;
Scan (In_Tree); -- past the project name
-- If this is inside a package, a dot followed by the
-- name of the package must followed the project name.
if Present (Current_Package) then
Expect (Tok_Dot, "`.`");
if Token /= Tok_Dot then
The_Project := Empty_Node;
else
Scan (In_Tree); -- past the dot
Expect (Tok_Identifier, "identifier");
if Token /= Tok_Identifier then
The_Project := Empty_Node;
-- If it is not the same package name, issue error
elsif
Token_Name /= Name_Of (Current_Package, In_Tree)
then
The_Project := Empty_Node;
Error_Msg
(Flags, "not the same package as " &
Get_Name_String
(Name_Of (Current_Package, In_Tree)),
Token_Ptr);
Scan (In_Tree); -- past the package name
else
if Present (The_Project) then
The_Package :=
First_Package_Of (The_Project, In_Tree);
-- Look for the package node
while Present (The_Package)
and then Name_Of (The_Package, In_Tree) /=
Token_Name
loop
The_Package :=
Next_Package_In_Project
(The_Package, In_Tree);
end loop;
-- If the package cannot be found in the
-- project, issue an error.
if No (The_Package) then
The_Project := Empty_Node;
Error_Msg_Name_2 := Project_Name;
Error_Msg_Name_1 := Token_Name;
Error_Msg
(Flags,
"package % not declared in project %",
Token_Ptr);
end if;
end if;
Scan (In_Tree); -- past the package name
end if;
end if;
end if;
end if;
end if;
if Present (The_Project) or else In_Tree.Incomplete_With then
-- Looking for '<same attribute name>
Expect (Tok_Apostrophe, "`''`");
if Token /= Tok_Apostrophe then
The_Project := Empty_Node;
else
Scan (In_Tree); -- past the apostrophe
Expect (Tok_Identifier, "identifier");
if Token /= Tok_Identifier then
The_Project := Empty_Node;
else
-- If it is not the same attribute name, issue error
if Token_Name /= Attribute_Name then
The_Project := Empty_Node;
Error_Msg_Name_1 := Attribute_Name;
Error_Msg
(Flags, "invalid name, should be %", Token_Ptr);
end if;
Scan (In_Tree); -- past the attribute name
end if;
end if;
end if;
if No (The_Project) then
-- If there were any problem, set the attribute id to null,
-- so that the node will not be recorded.
Current_Attribute := Empty_Attribute;
else
-- Set the appropriate field in the node.
-- Note that the index and the expression are nil. This
-- characterizes full associative array attribute
-- declarations.
Set_Associative_Project_Of (Attribute, In_Tree, The_Project);
Set_Associative_Package_Of (Attribute, In_Tree, The_Package);
end if;
end;
-- Other attribute declarations (not full associative array)
else
declare
Expression_Location : constant Source_Ptr := Token_Ptr;
-- The location of the first token of the expression
Expression : Project_Node_Id := Empty_Node;
-- The expression, value for the attribute declaration
begin
-- Get the expression value and set it in the attribute node
Parse_Expression
(In_Tree => In_Tree,
Expression => Expression,
Flags => Flags,
Current_Project => Current_Project,
Current_Package => Current_Package,
Optional_Index => Optional_Index);
Set_Expression_Of (Attribute, In_Tree, To => Expression);
-- If the expression is legal, but not of the right kind
-- for the attribute, issue an error.
if Current_Attribute /= Empty_Attribute
and then Present (Expression)
and then Variable_Kind_Of (Current_Attribute) /=
Expression_Kind_Of (Expression, In_Tree)
then
if Variable_Kind_Of (Current_Attribute) = Undefined then
Set_Variable_Kind_Of
(Current_Attribute,
To => Expression_Kind_Of (Expression, In_Tree));
else
Error_Msg
(Flags, "wrong expression kind for attribute """ &
Get_Name_String
(Attribute_Name_Of (Current_Attribute)) &
"""",
Expression_Location);
end if;
end if;
end;
end if;
end if;
-- If the attribute was not recognized, return an empty node.
-- It may be that it is not in a package to check, and the node will
-- not be added to the tree.
if Current_Attribute = Empty_Attribute then
Attribute := Empty_Node;
end if;
Set_End_Of_Line (Attribute);
Set_Previous_Line_Node (Attribute);
end Parse_Attribute_Declaration;
-----------------------------
-- Parse_Case_Construction --
-----------------------------
procedure Parse_Case_Construction
(In_Tree : Project_Node_Tree_Ref;
Case_Construction : out Project_Node_Id;
First_Attribute : Attribute_Node_Id;
Current_Project : Project_Node_Id;
Current_Package : Project_Node_Id;
Packages_To_Check : String_List_Access;
Is_Config_File : Boolean;
Flags : Processing_Flags)
is
Current_Item : Project_Node_Id := Empty_Node;
Next_Item : Project_Node_Id := Empty_Node;
First_Case_Item : Boolean := True;
Variable_Location : Source_Ptr := No_Location;
String_Type : Project_Node_Id := Empty_Node;
Case_Variable : Project_Node_Id := Empty_Node;
First_Declarative_Item : Project_Node_Id := Empty_Node;
First_Choice : Project_Node_Id := Empty_Node;
When_Others : Boolean := False;
-- Set to True when there is a "when others =>" clause
begin
Case_Construction :=
Default_Project_Node
(Of_Kind => N_Case_Construction, In_Tree => In_Tree);
Set_Location_Of (Case_Construction, In_Tree, To => Token_Ptr);
-- Scan past "case"
Scan (In_Tree);
-- Get the switch variable
Expect (Tok_Identifier, "identifier");
if Token = Tok_Identifier then
Variable_Location := Token_Ptr;
Parse_Variable_Reference
(In_Tree => In_Tree,
Variable => Case_Variable,
Flags => Flags,
Current_Project => Current_Project,
Current_Package => Current_Package);
Set_Case_Variable_Reference_Of
(Case_Construction, In_Tree, To => Case_Variable);
else
if Token /= Tok_Is then
Scan (In_Tree);
end if;
end if;
if Present (Case_Variable) then
String_Type := String_Type_Of (Case_Variable, In_Tree);
if Expression_Kind_Of (Case_Variable, In_Tree) /= Single then
Error_Msg (Flags,
"variable """ &
Get_Name_String (Name_Of (Case_Variable, In_Tree)) &
""" is not a single string",
Variable_Location);
end if;
end if;
Expect (Tok_Is, "IS");
if Token = Tok_Is then
Set_End_Of_Line (Case_Construction);
Set_Previous_Line_Node (Case_Construction);
Set_Next_End_Node (Case_Construction);
-- Scan past "is"
Scan (In_Tree);
end if;
Start_New_Case_Construction (In_Tree, String_Type);
When_Loop :
while Token = Tok_When loop
if First_Case_Item then
Current_Item :=
Default_Project_Node
(Of_Kind => N_Case_Item, In_Tree => In_Tree);
Set_First_Case_Item_Of
(Case_Construction, In_Tree, To => Current_Item);
First_Case_Item := False;
else
Next_Item :=
Default_Project_Node
(Of_Kind => N_Case_Item, In_Tree => In_Tree);
Set_Next_Case_Item (Current_Item, In_Tree, To => Next_Item);
Current_Item := Next_Item;
end if;
Set_Location_Of (Current_Item, In_Tree, To => Token_Ptr);
-- Scan past "when"
Scan (In_Tree);
if Token = Tok_Others then
When_Others := True;
-- Scan past "others"
Scan (In_Tree);
Expect (Tok_Arrow, "`=>`");
Set_End_Of_Line (Current_Item);
Set_Previous_Line_Node (Current_Item);
-- Empty_Node in Field1 of a Case_Item indicates
-- the "when others =>" branch.
Set_First_Choice_Of (Current_Item, In_Tree, To => Empty_Node);
Parse_Declarative_Items
(In_Tree => In_Tree,
Declarations => First_Declarative_Item,
In_Zone => In_Case_Construction,
First_Attribute => First_Attribute,
Current_Project => Current_Project,
Current_Package => Current_Package,
Packages_To_Check => Packages_To_Check,
Is_Config_File => Is_Config_File,
Flags => Flags);
-- "when others =>" must be the last branch, so save the
-- Case_Item and exit
Set_First_Declarative_Item_Of
(Current_Item, In_Tree, To => First_Declarative_Item);
exit When_Loop;
else
Parse_Choice_List
(In_Tree => In_Tree,
First_Choice => First_Choice,
Flags => Flags,
String_Type => Present (String_Type));
Set_First_Choice_Of (Current_Item, In_Tree, To => First_Choice);
Expect (Tok_Arrow, "`=>`");
Set_End_Of_Line (Current_Item);
Set_Previous_Line_Node (Current_Item);
Parse_Declarative_Items
(In_Tree => In_Tree,
Declarations => First_Declarative_Item,
In_Zone => In_Case_Construction,
First_Attribute => First_Attribute,
Current_Project => Current_Project,
Current_Package => Current_Package,
Packages_To_Check => Packages_To_Check,
Is_Config_File => Is_Config_File,
Flags => Flags);
Set_First_Declarative_Item_Of
(Current_Item, In_Tree, To => First_Declarative_Item);
end if;
end loop When_Loop;
End_Case_Construction
(Check_All_Labels => not When_Others and not Quiet_Output,
Case_Location => Location_Of (Case_Construction, In_Tree),
Flags => Flags,
String_Type => Present (String_Type));
Expect (Tok_End, "`END CASE`");
Remove_Next_End_Node;
if Token = Tok_End then
-- Scan past "end"
Scan (In_Tree);
Expect (Tok_Case, "CASE");
end if;
-- Scan past "case"
Scan (In_Tree);
Expect (Tok_Semicolon, "`;`");
Set_Previous_End_Node (Case_Construction);
end Parse_Case_Construction;
-----------------------------
-- Parse_Declarative_Items --
-----------------------------
procedure Parse_Declarative_Items
(In_Tree : Project_Node_Tree_Ref;
Declarations : out Project_Node_Id;
In_Zone : Zone;
First_Attribute : Attribute_Node_Id;
Current_Project : Project_Node_Id;
Current_Package : Project_Node_Id;
Packages_To_Check : String_List_Access;
Is_Config_File : Boolean;
Flags : Processing_Flags)
is
Current_Declarative_Item : Project_Node_Id := Empty_Node;
Next_Declarative_Item : Project_Node_Id := Empty_Node;
Current_Declaration : Project_Node_Id := Empty_Node;
Item_Location : Source_Ptr := No_Location;
begin
Declarations := Empty_Node;
loop
-- We are always positioned at the token that precedes the first
-- token of the declarative element. Scan past it.
Scan (In_Tree);
Item_Location := Token_Ptr;
case Token is
when Tok_Identifier =>
if In_Zone = In_Case_Construction then
-- Check if the variable has already been declared
declare
The_Variable : Project_Node_Id := Empty_Node;
begin
if Present (Current_Package) then
The_Variable :=
First_Variable_Of (Current_Package, In_Tree);
elsif Present (Current_Project) then
The_Variable :=
First_Variable_Of (Current_Project, In_Tree);
end if;
while Present (The_Variable)
and then Name_Of (The_Variable, In_Tree) /=
Token_Name
loop
The_Variable := Next_Variable (The_Variable, In_Tree);
end loop;
-- It is an error to declare a variable in a case
-- construction for the first time.
if No (The_Variable) then
Error_Msg
(Flags, "a variable cannot be declared for the "
& "first time here", Token_Ptr);
end if;
end;
end if;
Parse_Variable_Declaration
(In_Tree,
Current_Declaration,
Current_Project => Current_Project,
Current_Package => Current_Package,
Flags => Flags);
Set_End_Of_Line (Current_Declaration);
Set_Previous_Line_Node (Current_Declaration);
when Tok_For =>
Parse_Attribute_Declaration
(In_Tree => In_Tree,
Attribute => Current_Declaration,
First_Attribute => First_Attribute,
Current_Project => Current_Project,
Current_Package => Current_Package,
Packages_To_Check => Packages_To_Check,
Flags => Flags);
Set_End_Of_Line (Current_Declaration);
Set_Previous_Line_Node (Current_Declaration);
when Tok_Null =>
Scan (In_Tree); -- past "null"
when Tok_Package =>
-- Package declaration
if In_Zone /= In_Project then
Error_Msg
(Flags, "a package cannot be declared here", Token_Ptr);
end if;
Parse_Package_Declaration
(In_Tree => In_Tree,
Package_Declaration => Current_Declaration,
Current_Project => Current_Project,
Packages_To_Check => Packages_To_Check,
Is_Config_File => Is_Config_File,
Flags => Flags);
Set_Previous_End_Node (Current_Declaration);
when Tok_Type =>
-- Type String Declaration
if In_Zone /= In_Project then
Error_Msg (Flags,
"a string type cannot be declared here",
Token_Ptr);
end if;
Parse_String_Type_Declaration
(In_Tree => In_Tree,
String_Type => Current_Declaration,
Current_Project => Current_Project,
Flags => Flags);
Set_End_Of_Line (Current_Declaration);
Set_Previous_Line_Node (Current_Declaration);
when Tok_Case =>
-- Case construction
Parse_Case_Construction
(In_Tree => In_Tree,
Case_Construction => Current_Declaration,
First_Attribute => First_Attribute,
Current_Project => Current_Project,
Current_Package => Current_Package,
Packages_To_Check => Packages_To_Check,
Is_Config_File => Is_Config_File,
Flags => Flags);
Set_Previous_End_Node (Current_Declaration);
when others =>
exit;
-- We are leaving Parse_Declarative_Items positioned
-- at the first token after the list of declarative items.
-- It could be "end" (for a project, a package declaration or
-- a case construction) or "when" (for a case construction)
end case;
Expect (Tok_Semicolon, "`;` after declarative items");
-- Insert an N_Declarative_Item in the tree, but only if
-- Current_Declaration is not an empty node.
if Present (Current_Declaration) then
if No (Current_Declarative_Item) then
Current_Declarative_Item :=
Default_Project_Node
(Of_Kind => N_Declarative_Item, In_Tree => In_Tree);
Declarations := Current_Declarative_Item;
else
Next_Declarative_Item :=
Default_Project_Node
(Of_Kind => N_Declarative_Item, In_Tree => In_Tree);
Set_Next_Declarative_Item
(Current_Declarative_Item, In_Tree,
To => Next_Declarative_Item);
Current_Declarative_Item := Next_Declarative_Item;
end if;
Set_Current_Item_Node
(Current_Declarative_Item, In_Tree,
To => Current_Declaration);
Set_Location_Of
(Current_Declarative_Item, In_Tree, To => Item_Location);
end if;
end loop;
end Parse_Declarative_Items;
-------------------------------
-- Parse_Package_Declaration --
-------------------------------
procedure Parse_Package_Declaration
(In_Tree : Project_Node_Tree_Ref;
Package_Declaration : out Project_Node_Id;
Current_Project : Project_Node_Id;
Packages_To_Check : String_List_Access;
Is_Config_File : Boolean;
Flags : Processing_Flags)
is
First_Attribute : Attribute_Node_Id := Empty_Attribute;
Current_Package : Package_Node_Id := Empty_Package;
First_Declarative_Item : Project_Node_Id := Empty_Node;
Package_Location : constant Source_Ptr := Token_Ptr;
Renaming : Boolean := False;
Extending : Boolean := False;
begin
Package_Declaration :=
Default_Project_Node
(Of_Kind => N_Package_Declaration, In_Tree => In_Tree);
Set_Location_Of (Package_Declaration, In_Tree, To => Package_Location);
-- Scan past "package"
Scan (In_Tree);
Expect (Tok_Identifier, "identifier");
if Token = Tok_Identifier then
Set_Name_Of (Package_Declaration, In_Tree, To => Token_Name);
Current_Package := Package_Node_Id_Of (Token_Name);
if Current_Package = Empty_Package then
if not Quiet_Output then
declare
List : constant Strings.String_List := Package_Name_List;
Index : Natural;
Name : constant String := Get_Name_String (Token_Name);
begin
-- Check for possible misspelling of a known package name
Index := 0;
loop
if Index >= List'Last then
Index := 0;
exit;
end if;
Index := Index + 1;
exit when
GNAT.Spelling_Checker.Is_Bad_Spelling_Of
(Name, List (Index).all);
end loop;
-- Issue warning(s) in verbose mode or when a possible
-- misspelling has been found.
if Verbose_Mode or else Index /= 0 then
Error_Msg (Flags,
"?""" &
Get_Name_String
(Name_Of (Package_Declaration, In_Tree)) &
""" is not a known package name",
Token_Ptr);
end if;
if Index /= 0 then
Error_Msg -- CODEFIX
(Flags,
"\?possible misspelling of """ &
List (Index).all & """", Token_Ptr);
end if;
end;
end if;
-- Set the package declaration to "ignored" so that it is not
-- processed by Prj.Proc.Process.
Set_Expression_Kind_Of (Package_Declaration, In_Tree, Ignored);
-- Add the unknown package in the list of packages
Add_Unknown_Package (Token_Name, Current_Package);
elsif Current_Package = Unknown_Package then
-- Set the package declaration to "ignored" so that it is not
-- processed by Prj.Proc.Process.
Set_Expression_Kind_Of (Package_Declaration, In_Tree, Ignored);
else
First_Attribute := First_Attribute_Of (Current_Package);
end if;
Set_Package_Id_Of
(Package_Declaration, In_Tree, To => Current_Package);
declare
Current : Project_Node_Id :=
First_Package_Of (Current_Project, In_Tree);
begin
while Present (Current)
and then Name_Of (Current, In_Tree) /= Token_Name
loop
Current := Next_Package_In_Project (Current, In_Tree);
end loop;
if Present (Current) then
Error_Msg
(Flags,
"package """ &
Get_Name_String (Name_Of (Package_Declaration, In_Tree)) &
""" is declared twice in the same project",
Token_Ptr);
else
-- Add the package to the project list
Set_Next_Package_In_Project
(Package_Declaration, In_Tree,
To => First_Package_Of (Current_Project, In_Tree));
Set_First_Package_Of
(Current_Project, In_Tree, To => Package_Declaration);
end if;
end;
-- Scan past the package name
Scan (In_Tree);
end if;
Check_Package_Allowed
(In_Tree, Current_Project, Package_Declaration, Flags);
if Token = Tok_Renames then
Renaming := True;
elsif Token = Tok_Extends then
Extending := True;
end if;
if Renaming or else Extending then
if Is_Config_File then
Error_Msg
(Flags,
"no package rename or extension in configuration projects",
Token_Ptr);
end if;
-- Scan past "renames" or "extends"
Scan (In_Tree);
Expect (Tok_Identifier, "identifier");
if Token = Tok_Identifier then
declare
Project_Name : constant Name_Id := Token_Name;
Clause : Project_Node_Id :=
First_With_Clause_Of (Current_Project, In_Tree);
The_Project : Project_Node_Id := Empty_Node;
Extended : constant Project_Node_Id :=
Extended_Project_Of
(Project_Declaration_Of
(Current_Project, In_Tree),
In_Tree);
begin
while Present (Clause) loop
-- Only non limited imported projects may be used in a
-- renames declaration.
The_Project :=
Non_Limited_Project_Node_Of (Clause, In_Tree);
exit when Present (The_Project)
and then Name_Of (The_Project, In_Tree) = Project_Name;
Clause := Next_With_Clause_Of (Clause, In_Tree);
end loop;
if No (Clause) then
-- As we have not found the project in the imports, we check
-- if it's the name of an eventual extended project.
if Present (Extended)
and then Name_Of (Extended, In_Tree) = Project_Name
then
Set_Project_Of_Renamed_Package_Of
(Package_Declaration, In_Tree, To => Extended);
else
Error_Msg_Name_1 := Project_Name;
Error_Msg
(Flags,
"% is not an imported or extended project", Token_Ptr);
end if;
else
Set_Project_Of_Renamed_Package_Of
(Package_Declaration, In_Tree, To => The_Project);
end if;
end;
Scan (In_Tree);
Expect (Tok_Dot, "`.`");
if Token = Tok_Dot then
Scan (In_Tree);
Expect (Tok_Identifier, "identifier");
if Token = Tok_Identifier then
if Name_Of (Package_Declaration, In_Tree) /= Token_Name then
Error_Msg (Flags, "not the same package name", Token_Ptr);
elsif
Present (Project_Of_Renamed_Package_Of
(Package_Declaration, In_Tree))
then
declare
Current : Project_Node_Id :=
First_Package_Of
(Project_Of_Renamed_Package_Of
(Package_Declaration, In_Tree),
In_Tree);
begin
while Present (Current)
and then Name_Of (Current, In_Tree) /= Token_Name
loop
Current :=
Next_Package_In_Project (Current, In_Tree);
end loop;
if No (Current) then
Error_Msg
(Flags, """" &
Get_Name_String (Token_Name) &
""" is not a package declared by the project",
Token_Ptr);
end if;
end;
end if;
Scan (In_Tree);
end if;
end if;
end if;
end if;
if Renaming then
Expect (Tok_Semicolon, "`;`");
Set_End_Of_Line (Package_Declaration);
Set_Previous_Line_Node (Package_Declaration);
elsif Token = Tok_Is then
Set_End_Of_Line (Package_Declaration);
Set_Previous_Line_Node (Package_Declaration);
Set_Next_End_Node (Package_Declaration);
Parse_Declarative_Items
(In_Tree => In_Tree,
Declarations => First_Declarative_Item,
In_Zone => In_Package,
First_Attribute => First_Attribute,
Current_Project => Current_Project,
Current_Package => Package_Declaration,
Packages_To_Check => Packages_To_Check,
Is_Config_File => Is_Config_File,
Flags => Flags);
Set_First_Declarative_Item_Of
(Package_Declaration, In_Tree, To => First_Declarative_Item);
Expect (Tok_End, "END");
if Token = Tok_End then
-- Scan past "end"
Scan (In_Tree);
end if;
-- We should have the name of the package after "end"
Expect (Tok_Identifier, "identifier");
if Token = Tok_Identifier
and then Name_Of (Package_Declaration, In_Tree) /= No_Name
and then Token_Name /= Name_Of (Package_Declaration, In_Tree)
then
Error_Msg_Name_1 := Name_Of (Package_Declaration, In_Tree);
Error_Msg (Flags, "expected %%", Token_Ptr);
end if;
if Token /= Tok_Semicolon then
-- Scan past the package name
Scan (In_Tree);
end if;
Expect (Tok_Semicolon, "`;`");
Remove_Next_End_Node;
else
Error_Msg (Flags, "expected IS", Token_Ptr);
end if;
end Parse_Package_Declaration;
-----------------------------------
-- Parse_String_Type_Declaration --
-----------------------------------
procedure Parse_String_Type_Declaration
(In_Tree : Project_Node_Tree_Ref;
String_Type : out Project_Node_Id;
Current_Project : Project_Node_Id;
Flags : Processing_Flags)
is
Current : Project_Node_Id := Empty_Node;
First_String : Project_Node_Id := Empty_Node;
begin
String_Type :=
Default_Project_Node
(Of_Kind => N_String_Type_Declaration, In_Tree => In_Tree);
Set_Location_Of (String_Type, In_Tree, To => Token_Ptr);
-- Scan past "type"
Scan (In_Tree);
Expect (Tok_Identifier, "identifier");
if Token = Tok_Identifier then
Set_Name_Of (String_Type, In_Tree, To => Token_Name);
Current := First_String_Type_Of (Current_Project, In_Tree);
while Present (Current)
and then
Name_Of (Current, In_Tree) /= Token_Name
loop
Current := Next_String_Type (Current, In_Tree);
end loop;
if Present (Current) then
Error_Msg (Flags,
"duplicate string type name """ &
Get_Name_String (Token_Name) &
"""",
Token_Ptr);
else
Current := First_Variable_Of (Current_Project, In_Tree);
while Present (Current)
and then Name_Of (Current, In_Tree) /= Token_Name
loop
Current := Next_Variable (Current, In_Tree);
end loop;
if Present (Current) then
Error_Msg (Flags,
"""" &
Get_Name_String (Token_Name) &
""" is already a variable name", Token_Ptr);
else
Set_Next_String_Type
(String_Type, In_Tree,
To => First_String_Type_Of (Current_Project, In_Tree));
Set_First_String_Type_Of
(Current_Project, In_Tree, To => String_Type);
end if;
end if;
-- Scan past the name
Scan (In_Tree);
end if;
Expect (Tok_Is, "IS");
if Token = Tok_Is then
Scan (In_Tree);
end if;
Expect (Tok_Left_Paren, "`(`");
if Token = Tok_Left_Paren then
Scan (In_Tree);
end if;
Parse_String_Type_List
(In_Tree => In_Tree, First_String => First_String, Flags => Flags);
Set_First_Literal_String (String_Type, In_Tree, To => First_String);
Expect (Tok_Right_Paren, "`)`");
if Token = Tok_Right_Paren then
Scan (In_Tree);
end if;
end Parse_String_Type_Declaration;
--------------------------------
-- Parse_Variable_Declaration --
--------------------------------
procedure Parse_Variable_Declaration
(In_Tree : Project_Node_Tree_Ref;
Variable : out Project_Node_Id;
Current_Project : Project_Node_Id;
Current_Package : Project_Node_Id;
Flags : Processing_Flags)
is
Expression_Location : Source_Ptr;
String_Type_Name : Name_Id := No_Name;
Project_String_Type_Name : Name_Id := No_Name;
Type_Location : Source_Ptr := No_Location;
Project_Location : Source_Ptr := No_Location;
Expression : Project_Node_Id := Empty_Node;
Variable_Name : constant Name_Id := Token_Name;
OK : Boolean := True;
begin
Variable :=
Default_Project_Node
(Of_Kind => N_Variable_Declaration, In_Tree => In_Tree);
Set_Name_Of (Variable, In_Tree, To => Variable_Name);
Set_Location_Of (Variable, In_Tree, To => Token_Ptr);
-- Scan past the variable name
Scan (In_Tree);
if Token = Tok_Colon then
-- Typed string variable declaration
Scan (In_Tree);
Set_Kind_Of (Variable, In_Tree, N_Typed_Variable_Declaration);
Expect (Tok_Identifier, "identifier");
OK := Token = Tok_Identifier;
if OK then
String_Type_Name := Token_Name;
Type_Location := Token_Ptr;
Scan (In_Tree);
if Token = Tok_Dot then
Project_String_Type_Name := String_Type_Name;
Project_Location := Type_Location;
-- Scan past the dot
Scan (In_Tree);
Expect (Tok_Identifier, "identifier");
if Token = Tok_Identifier then
String_Type_Name := Token_Name;
Type_Location := Token_Ptr;
Scan (In_Tree);
else
OK := False;
end if;
end if;
if OK then
declare
Proj : Project_Node_Id := Current_Project;
Current : Project_Node_Id := Empty_Node;
begin
if Project_String_Type_Name /= No_Name then
declare
The_Project_Name_And_Node : constant
Tree_Private_Part.Project_Name_And_Node :=
Tree_Private_Part.Projects_Htable.Get
(In_Tree.Projects_HT, Project_String_Type_Name);
use Tree_Private_Part;
begin
if The_Project_Name_And_Node =
Tree_Private_Part.No_Project_Name_And_Node
then
Error_Msg (Flags,
"unknown project """ &
Get_Name_String
(Project_String_Type_Name) &
"""",
Project_Location);
Current := Empty_Node;
else
Current :=
First_String_Type_Of
(The_Project_Name_And_Node.Node, In_Tree);
while
Present (Current)
and then
Name_Of (Current, In_Tree) /= String_Type_Name
loop
Current := Next_String_Type (Current, In_Tree);
end loop;
end if;
end;
else
-- Look for a string type with the correct name in this
-- project or in any of its ancestors.
loop
Current :=
First_String_Type_Of (Proj, In_Tree);
while
Present (Current)
and then
Name_Of (Current, In_Tree) /= String_Type_Name
loop
Current := Next_String_Type (Current, In_Tree);
end loop;
exit when Present (Current);
Proj := Parent_Project_Of (Proj, In_Tree);
exit when No (Proj);
end loop;
end if;
if No (Current) then
Error_Msg (Flags,
"unknown string type """ &
Get_Name_String (String_Type_Name) &
"""",
Type_Location);
OK := False;
else
Set_String_Type_Of
(Variable, In_Tree, To => Current);
end if;
end;
end if;
end if;
end if;
Expect (Tok_Colon_Equal, "`:=`");
OK := OK and then Token = Tok_Colon_Equal;
if Token = Tok_Colon_Equal then
Scan (In_Tree);
end if;
-- Get the single string or string list value
Expression_Location := Token_Ptr;
Parse_Expression
(In_Tree => In_Tree,
Expression => Expression,
Flags => Flags,
Current_Project => Current_Project,
Current_Package => Current_Package,
Optional_Index => False);
Set_Expression_Of (Variable, In_Tree, To => Expression);
if Present (Expression) then
-- A typed string must have a single string value, not a list
if Kind_Of (Variable, In_Tree) = N_Typed_Variable_Declaration
and then Expression_Kind_Of (Expression, In_Tree) = List
then
Error_Msg
(Flags,
"expression must be a single string", Expression_Location);
end if;
Set_Expression_Kind_Of
(Variable, In_Tree,
To => Expression_Kind_Of (Expression, In_Tree));
end if;
if OK then
declare
The_Variable : Project_Node_Id := Empty_Node;
begin
if Present (Current_Package) then
The_Variable := First_Variable_Of (Current_Package, In_Tree);
elsif Present (Current_Project) then
The_Variable := First_Variable_Of (Current_Project, In_Tree);
end if;
while Present (The_Variable)
and then Name_Of (The_Variable, In_Tree) /= Variable_Name
loop
The_Variable := Next_Variable (The_Variable, In_Tree);
end loop;
if No (The_Variable) then
if Present (Current_Package) then
Set_Next_Variable
(Variable, In_Tree,
To => First_Variable_Of (Current_Package, In_Tree));
Set_First_Variable_Of
(Current_Package, In_Tree, To => Variable);
elsif Present (Current_Project) then
Set_Next_Variable
(Variable, In_Tree,
To => First_Variable_Of (Current_Project, In_Tree));
Set_First_Variable_Of
(Current_Project, In_Tree, To => Variable);
end if;
else
if Expression_Kind_Of (Variable, In_Tree) /= Undefined then
if Expression_Kind_Of (The_Variable, In_Tree) =
Undefined
then
Set_Expression_Kind_Of
(The_Variable, In_Tree,
To => Expression_Kind_Of (Variable, In_Tree));
else
if Expression_Kind_Of (The_Variable, In_Tree) /=
Expression_Kind_Of (Variable, In_Tree)
then
Error_Msg (Flags,
"wrong expression kind for variable """ &
Get_Name_String
(Name_Of (The_Variable, In_Tree)) &
"""",
Expression_Location);
end if;
end if;
end if;
end if;
end;
end if;
end Parse_Variable_Declaration;
end Prj.Dect;
|
-----------------------------------------------------------------------
-- Util.Beans.Objects.Hash -- Hash on an object
-- Copyright (C) 2010, 2011 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.Hash;
with Ada.Strings.Wide_Wide_Hash;
with Ada.Unchecked_Conversion;
with Interfaces;
with Util.Beans.Basic;
function Util.Beans.Objects.Hash (Key : in Object) return Ada.Containers.Hash_Type is
use Ada.Containers;
use Ada.Strings;
use Interfaces;
use Util.Beans.Basic;
type Unsigned_32_Array is array (Natural range <>) of Unsigned_32;
subtype U32_For_Float is Unsigned_32_Array (1 .. Long_Long_Float'Size / 32);
subtype U32_For_Duration is Unsigned_32_Array (1 .. Duration'Size / 32);
subtype U32_For_Long is Unsigned_32_Array (1 .. Long_Long_Integer'Size / 32);
subtype U32_For_Access is Unsigned_32_Array (1 .. Readonly_Bean_Access'Size / 32);
-- Hash the integer and floats using 32-bit values.
function To_U32_For_Long is new Ada.Unchecked_Conversion (Source => Long_Long_Integer,
Target => U32_For_Long);
-- Likewise for floats.
function To_U32_For_Float is new Ada.Unchecked_Conversion (Source => Long_Long_Float,
Target => U32_For_Float);
-- Likewise for duration.
function To_U32_For_Duration is new Ada.Unchecked_Conversion (Source => Duration,
Target => U32_For_Duration);
-- Likewise for the bean pointer
function To_U32_For_Access is new Ada.Unchecked_Conversion (Source => Readonly_Bean_Access,
Target => U32_For_Access);
begin
case Key.V.Of_Type is
when TYPE_NULL =>
return 0;
when TYPE_BOOLEAN =>
if Key.V.Bool_Value then
return 1;
else
return 2;
end if;
when TYPE_INTEGER =>
declare
U32 : constant U32_For_Long := To_U32_For_Long (Key.V.Int_Value);
Val : Unsigned_32 := U32 (U32'First);
begin
for I in U32'First + 1 .. U32'Last loop
Val := Val xor U32 (I);
end loop;
return Hash_Type (Val);
end;
when TYPE_FLOAT =>
declare
U32 : constant U32_For_Float := To_U32_For_Float (Key.V.Float_Value);
Val : Unsigned_32 := U32 (U32'First);
begin
for I in U32'First + 1 .. U32'Last loop
Val := Val xor U32 (I);
end loop;
return Hash_Type (Val);
end;
when TYPE_STRING =>
if Key.V.String_Proxy = null then
return 0;
else
return Hash (Key.V.String_Proxy.Value);
end if;
when TYPE_TIME =>
declare
U32 : constant U32_For_Duration := To_U32_For_Duration (Key.V.Time_Value);
Val : Unsigned_32 := U32 (U32'First);
begin
for I in U32'First + 1 .. U32'Last loop
Val := Val xor U32 (I);
end loop;
return Hash_Type (Val);
end;
when TYPE_WIDE_STRING =>
if Key.V.Wide_Proxy = null then
return 0;
else
return Wide_Wide_Hash (Key.V.Wide_Proxy.Value);
end if;
when TYPE_BEAN =>
if Key.V.Proxy = null or else Bean_Proxy (Key.V.Proxy.all).Bean = null then
return 0;
end if;
declare
U32 : constant U32_For_Access
:= To_U32_For_Access (Bean_Proxy (Key.V.Proxy.all).Bean.all'Access);
Val : Unsigned_32 := U32 (U32'First);
-- The loop is not executed if pointers are 32-bit wide.
pragma Warnings (Off);
begin
for I in U32'First + 1 .. U32'Last loop
Val := Val xor U32 (I);
end loop;
return Hash_Type (Val);
end;
end case;
end Util.Beans.Objects.Hash;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 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$
------------------------------------------------------------------------------
-- This package provides sets of Unicode characters (code points).
------------------------------------------------------------------------------
with League.Strings;
with League.Characters;
private with Ada.Streams;
private with Ada.Finalization;
private with Matreshka.Internals.Code_Point_Sets;
package League.Character_Sets is
pragma Preelaborate;
pragma Remote_Types;
type Universal_Character_Set is tagged private;
Empty_Universal_Character_Set : constant Universal_Character_Set;
function To_Set
(Sequence : Wide_Wide_String)
return Universal_Character_Set;
-- Return set containing all characters from Sequence
function To_Set
(Sequence : League.Strings.Universal_String)
return Universal_Character_Set;
-- Return set containing all characters from Sequence
function To_Set
(Low, High : Wide_Wide_Character)
return Universal_Character_Set;
-- Return set containing all characters between Low and High
function "=" (Left, Right : Universal_Character_Set) return Boolean;
function "not"
(Right : Universal_Character_Set)
return Universal_Character_Set;
-- Return complementing set of character
function "and"
(Left, Right : Universal_Character_Set)
return Universal_Character_Set;
-- Return intersection of Left and Right
function "or"
(Left, Right : Universal_Character_Set)
return Universal_Character_Set;
-- Return union of Left and Right
function "xor"
(Left, Right : Universal_Character_Set)
return Universal_Character_Set;
function "-"
(Left, Right : Universal_Character_Set)
return Universal_Character_Set;
-- Return difference
function Has
(Set : Universal_Character_Set;
Element : Wide_Wide_Character)
return Boolean;
function Has
(Set : Universal_Character_Set;
Element : League.Characters.Universal_Character)
return Boolean;
function Is_Subset
(Elements : Universal_Character_Set;
Set : Universal_Character_Set)
return Boolean;
function "<="
(Left : Universal_Character_Set;
Right : Universal_Character_Set)
return Boolean renames Is_Subset;
function Is_Empty (Set : Universal_Character_Set) return Boolean;
private
procedure Read
(Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Item : out Universal_Character_Set);
procedure Write
(Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Item : Universal_Character_Set);
type Universal_Character_Set is new Ada.Finalization.Controlled with record
Data : Matreshka.Internals.Code_Point_Sets.Shared_Code_Point_Set_Access
:= Matreshka.Internals.Code_Point_Sets.Shared_Empty'Access;
end record;
for Universal_Character_Set'Read use Read;
for Universal_Character_Set'Write use Write;
overriding procedure Adjust (Self : in out Universal_Character_Set);
overriding procedure Finalize (Self : in out Universal_Character_Set);
Empty_Universal_Character_Set : constant Universal_Character_Set :=
(Ada.Finalization.Controlled with
Data => Matreshka.Internals.Code_Point_Sets.Shared_Empty'Access);
end League.Character_Sets;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012-2014, 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 Ada.Tags;
with League.Text_Codecs;
with XML.SAX.Input_Sources.Streams.Element_Arrays;
with XML.SAX.Simple_Readers;
with Web_Services.SOAP.Constants;
with Web_Services.SOAP.Handler_Registry;
with Web_Services.SOAP.Handlers;
with Web_Services.SOAP.Message_Decoders;
with Web_Services.SOAP.Messages;
with Web_Services.SOAP.Modules.Registry;
with Web_Services.SOAP.Payloads.Faults.Simple;
package body Web_Services.SOAP.Dispatcher is
--------------
-- Dispatch --
--------------
procedure Dispatch
(Input_Data : Ada.Streams.Stream_Element_Array;
SOAP_Action : League.Strings.Universal_String;
Stream : Web_Services.SOAP.Reply_Streams.Reply_Stream_Access)
is
use type League.Strings.Universal_String;
use type Web_Services.SOAP.Handlers.SOAP_Message_Handler;
use type Web_Services.SOAP.Messages.SOAP_Message_Access;
use type Web_Services.SOAP.Payloads.SOAP_Payload_Access;
Source : aliased
XML.SAX.Input_Sources.Streams.Element_Arrays.
Stream_Element_Array_Input_Source;
Decoder : aliased
Web_Services.SOAP.Message_Decoders.SOAP_Message_Decoder;
Reader : aliased XML.SAX.Simple_Readers.Simple_Reader;
Input : Web_Services.SOAP.Messages.SOAP_Message_Access;
Output : Web_Services.SOAP.Messages.SOAP_Message_Access;
Handler : Web_Services.SOAP.Handlers.SOAP_Message_Handler;
Handled : Boolean;
Detail : League.Strings.Universal_String;
begin
-- Parse request data.
Source.Set_Stream_Element_Array (Input_Data);
Reader.Set_Content_Handler (Decoder'Unchecked_Access);
Reader.Set_Error_Handler (Decoder'Unchecked_Access);
Reader.Set_Lexical_Handler (Decoder'Unchecked_Access);
Reader.Parse (Source'Access);
if Decoder.Success then
-- Request was decoded successfully, lookup for handler.
Input := Decoder.Message;
Input.Action := SOAP_Action;
Input.Output := Stream;
-- Execute SOAP Modules.
Web_Services.SOAP.Modules.Registry.Execute_Receive_Request
(Input.all, Output);
if Output /= null then
-- Return error when SOAP Module returns fault.
Stream.Send_Message (Output);
return;
end if;
-- Handle message using message-style handlers.
if Input.Payload = null then
Handler :=
Web_Services.SOAP.Handler_Registry.Resolve (Ada.Tags.No_Tag);
else
Handler :=
Web_Services.SOAP.Handler_Registry.Resolve (Input.Payload'Tag);
end if;
if Handler /= null then
-- Execute handler.
Handler (Input, Output);
Web_Services.SOAP.Messages.Free (Input);
Stream.Send_Message (Output);
return;
end if;
-- Process request using RCI-style handlers.
Handled := False;
for Handler of Web_Services.SOAP.Handler_Registry.RPC_Registry loop
Handler (Input.all, Output, Handled);
exit when Handled;
end loop;
if Handled then
-- Return when request has been handled.
Stream.Send_Message (Output);
return;
end if;
-- SOAP Message was not handled, return SOAP Fault.
Detail :=
League.Strings.To_Universal_String
("SOAP message handler was not found for");
if not Input.Namespace_URI.Is_Empty then
Detail.Append
(" {"
& Input.Namespace_URI
& "}"
& Input.Local_Name
& " payload element");
else
Detail.Append (" empty payload element");
end if;
if not Input.Action.Is_Empty then
Detail.Append (" with '" & Input.Action & "' SOAP Action");
else
Detail.Append (" without SOAP Action");
end if;
-- Use of rpc:ProcedureNotPresent subcode not required, but looks
-- helpful.
Output :=
new Web_Services.SOAP.Messages.SOAP_Message'
(Action => <>,
Namespace_URI => <>,
Local_Name => <>,
Output => null,
Headers => <>,
Payload =>
Web_Services.SOAP.Payloads.Faults.Simple.Create_Sender_Fault
(Web_Services.SOAP.Constants.SOAP_RPC_URI,
Web_Services.SOAP.Constants
.SOAP_Procedure_Not_Present_Subcode,
Web_Services.SOAP.Constants.SOAP_RPC_Prefix,
Web_Services.SOAP.Constants.XML_EN_US_Code,
League.Strings.To_Universal_String
("Procedure Not Present"),
Detail));
Stream.Send_Message (Output);
return;
else
Output := Decoder.Message;
if Output = null then
-- SOAP message handler detects error, but unable to generate
-- SOAP fault.
declare
Ignore : Boolean;
Codec : constant League.Text_Codecs.Text_Codec
:= League.Text_Codecs.Codec
(League.Strings.To_Universal_String ("utf-8"));
begin
Stream.Send_Reply
(Status => Reply_Streams.S_400,
Success => Ignore,
Content_Type => Web_Services.SOAP.Constants.MIME_Text_Plain,
Output_Data => Codec.Encode (Decoder.Error_String));
return;
end;
end if;
Stream.Send_Message (Output);
end if;
end Dispatch;
end Web_Services.SOAP.Dispatcher;
|
with Terminal_Interface.Curses; use Terminal_Interface.Curses;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
package Extools is
procedure Refrosh (Win : Window := Standard_Window);
end Extools;
|
pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
package mm3dnow_h is
-- Copyright (C) 2004-2017 Free Software Foundation, Inc.
-- This file is part of GCC.
-- GCC 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, or (at your option)
-- any later version.
-- GCC 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.
-- 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/>.
-- Implemented from the mm3dnow.h (of supposedly AMD origin) included with
-- MSVC 7.1.
-- skipped func _m_femms
-- skipped func _m_pavgusb
-- skipped func _m_pf2id
-- skipped func _m_pfacc
-- skipped func _m_pfadd
-- skipped func _m_pfcmpeq
-- skipped func _m_pfcmpge
-- skipped func _m_pfcmpgt
-- skipped func _m_pfmax
-- skipped func _m_pfmin
-- skipped func _m_pfmul
-- skipped func _m_pfrcp
-- skipped func _m_pfrcpit1
-- skipped func _m_pfrcpit2
-- skipped func _m_pfrsqrt
-- skipped func _m_pfrsqit1
-- skipped func _m_pfsub
-- skipped func _m_pfsubr
-- skipped func _m_pi2fd
-- skipped func _m_pmulhrw
-- skipped func _m_prefetch
-- _MM_HINT_T0
-- skipped func _m_from_float
-- skipped func _m_to_float
-- skipped func _m_pf2iw
-- skipped func _m_pfnacc
-- skipped func _m_pfpnacc
-- skipped func _m_pi2fw
-- skipped func _m_pswapd
end mm3dnow_h;
|
-- CC3017B.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 AN INSTANCE OF A GENERIC PROCEDURE MUST DECLARE A
-- PROCEDURE AND THAT AN INSTANCE OF A GENERIC FUNCTION MUST
-- DECLARE A FUNCTION. CHECK THAT CONSTRAINT_ERROR IS NOT RAISED
-- IF THE DEFAULT VALUE FOR A FORMAL PARAMETER DOES NOT SATISFY
-- THE CONSTRAINTS OF THE SUBTYPE_INDICATION WHEN THE
-- DECLARATION IS ELABORATED, ONLY WHEN THE DEFAULT IS USED.
-- SUBTESTS ARE:
-- (A) ARRAY PARAMETERS CONSTRAINED WITH NONSTATIC BOUNDS AND
-- INITIALIZED WITH A STATIC AGGREGATE.
-- (B) A SCALAR PARAMETER WITH NON-STATIC RANGE CONSTRAINTS
-- INITIALIZED WITH A STATIC VALUE.
-- (C) A RECORD PARAMETER WHOSE COMPONENTS HAVE NON-STATIC
-- CONSTRAINTS INITIALIZED WITH A STATIC AGGREGATE.
-- (D) AN ARRAY PARAMETER CONSTRAINED WITH STATIC BOUNDS ON SUB-
-- SCRIPTS AND NON-STATIC BOUNDS ON COMPONENTS, INITIALIZED
-- WITH A STATIC AGGREGATE.
-- (E) A RECORD PARAMETER WITH A NON-STATIC CONSTRAINT
-- INITIALIZED WITH A STATIC AGGREGATE.
-- EDWARD V. BERARD, 7 AUGUST 1990
WITH REPORT;
PROCEDURE CC3017B IS
BEGIN
REPORT.TEST ("CC3017B", "CHECK THAT AN INSTANCE OF A GENERIC " &
"PROCEDURE MUST DECLARE A PROCEDURE AND THAT AN " &
"INSTANCE OF A GENERIC FUNCTION MUST DECLARE A " &
"FUNCTION. CHECK THAT CONSTRAINT_ERROR IS NOT " &
"RAISED IF AN INITIALIZATION VALUE DOES NOT SATISFY " &
"CONSTRAINTS ON A FORMAL PARAMETER");
--------------------------------------------------
NONSTAT_ARRAY_PARMS:
DECLARE
-- (A) ARRAY PARAMETERS CONSTRAINED WITH NONSTATIC BOUNDS AND
-- INITIALIZED WITH A STATIC AGGREGATE.
TYPE NUMBER IS RANGE 1 .. 100 ;
GENERIC
TYPE INTEGER_TYPE IS RANGE <> ;
LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE ;
PROCEDURE PA (FIRST : IN INTEGER_TYPE ;
SECOND : IN INTEGER_TYPE) ;
PROCEDURE PA (FIRST : IN INTEGER_TYPE ;
SECOND : IN INTEGER_TYPE) IS
TYPE A1 IS ARRAY (INTEGER_TYPE RANGE LOWER .. FIRST,
INTEGER_TYPE RANGE LOWER .. SECOND)
OF INTEGER_TYPE;
PROCEDURE PA1 (A : A1 := ((LOWER,UPPER),(UPPER,UPPER)))
IS
BEGIN
REPORT.FAILED ("BODY OF PA1 EXECUTED");
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN PA1");
END PA1;
BEGIN -- PA
PA1;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
REPORT.FAILED ("WRONG EXCEPTION RAISED - PA1");
END PA;
PROCEDURE NEW_PA IS NEW PA (INTEGER_TYPE => NUMBER,
LOWER => 1,
UPPER => 50) ;
BEGIN -- NONSTAT_ARRAY_PARMS
NEW_PA (FIRST => NUMBER (25),
SECOND => NUMBER (75));
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN CALL TO NEW_PA");
END NONSTAT_ARRAY_PARMS ;
--------------------------------------------------
SCALAR_NON_STATIC:
DECLARE
-- (B) A SCALAR PARAMETER WITH NON-STATIC RANGE CONSTRAINTS
-- INITIALIZED WITH A STATIC VALUE.
TYPE NUMBER IS RANGE 1 .. 100 ;
GENERIC
TYPE INTEGER_TYPE IS RANGE <> ;
STATIC_VALUE : IN INTEGER_TYPE ;
PROCEDURE PB (LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE) ;
PROCEDURE PB (LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE) IS
SUBTYPE INT IS INTEGER_TYPE RANGE LOWER .. UPPER ;
PROCEDURE PB1 (I : INT := STATIC_VALUE) IS
BEGIN -- PB1
REPORT.FAILED ("BODY OF PB1 EXECUTED");
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN PB1");
END PB1;
BEGIN -- PB
PB1;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
REPORT.FAILED ("WRONG EXCEPTION RAISED - PB1");
END PB;
PROCEDURE NEW_PB IS NEW PB (INTEGER_TYPE => NUMBER,
STATIC_VALUE => 20) ;
BEGIN -- SCALAR_NON_STATIC
NEW_PB (LOWER => NUMBER (25),
UPPER => NUMBER (75));
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN CALL TO NEW_PB");
END SCALAR_NON_STATIC ;
--------------------------------------------------
REC_NON_STAT_COMPS:
DECLARE
-- (C) A RECORD PARAMETER WHOSE COMPONENTS HAVE NON-STATIC
-- CONSTRAINTS INITIALIZED WITH A STATIC AGGREGATE.
TYPE NUMBER IS RANGE 1 .. 100 ;
GENERIC
TYPE INTEGER_TYPE IS RANGE <> ;
F_STATIC_VALUE : IN INTEGER_TYPE ;
S_STATIC_VALUE : IN INTEGER_TYPE ;
T_STATIC_VALUE : IN INTEGER_TYPE ;
L_STATIC_VALUE : IN INTEGER_TYPE ;
PROCEDURE PC (LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE) ;
PROCEDURE PC (LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE) IS
SUBTYPE SUBINTEGER_TYPE IS INTEGER_TYPE
RANGE LOWER .. UPPER ;
TYPE AR1 IS ARRAY (INTEGER RANGE 1..3) OF
SUBINTEGER_TYPE ;
TYPE REC IS
RECORD
FIRST : SUBINTEGER_TYPE ;
SECOND : AR1 ;
END RECORD;
PROCEDURE PC1 (R : REC := (F_STATIC_VALUE,
(S_STATIC_VALUE,
T_STATIC_VALUE,
L_STATIC_VALUE))) IS
BEGIN -- PC1
REPORT.FAILED ("BODY OF PC1 EXECUTED");
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN PC1");
END PC1;
BEGIN -- PC
PC1;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
REPORT.FAILED ("WRONG EXCEPTION RAISED - PC1");
END PC;
PROCEDURE NEW_PC IS NEW PC (INTEGER_TYPE => NUMBER,
F_STATIC_VALUE => 15,
S_STATIC_VALUE => 19,
T_STATIC_VALUE => 85,
L_STATIC_VALUE => 99) ;
BEGIN -- REC_NON_STAT_COMPS
NEW_PC (LOWER => 20,
UPPER => 80);
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN CALL TO NEW_PC");
END REC_NON_STAT_COMPS ;
--------------------------------------------------
FIRST_STATIC_ARRAY:
DECLARE
-- (D) AN ARRAY PARAMETER CONSTRAINED WITH STATIC BOUNDS ON SUB-
-- SCRIPTS AND NON-STATIC BOUNDS ON COMPONENTS, INITIALIZED
-- WITH A STATIC AGGREGATE.
TYPE NUMBER IS RANGE 1 .. 100 ;
GENERIC
TYPE INTEGER_TYPE IS RANGE <> ;
F_STATIC_VALUE : IN INTEGER_TYPE ;
S_STATIC_VALUE : IN INTEGER_TYPE ;
T_STATIC_VALUE : IN INTEGER_TYPE ;
L_STATIC_VALUE : IN INTEGER_TYPE ;
A_STATIC_VALUE : IN INTEGER_TYPE ;
B_STATIC_VALUE : IN INTEGER_TYPE ;
C_STATIC_VALUE : IN INTEGER_TYPE ;
D_STATIC_VALUE : IN INTEGER_TYPE ;
PROCEDURE P1D (LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE) ;
PROCEDURE P1D (LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE) IS
SUBTYPE SUBINTEGER_TYPE IS INTEGER_TYPE
RANGE LOWER .. UPPER ;
TYPE A1 IS ARRAY (INTEGER_TYPE RANGE
F_STATIC_VALUE .. S_STATIC_VALUE,
INTEGER_TYPE RANGE
T_STATIC_VALUE .. L_STATIC_VALUE)
OF SUBINTEGER_TYPE ;
PROCEDURE P1D1 (A : A1 :=
((A_STATIC_VALUE, B_STATIC_VALUE),
(C_STATIC_VALUE, D_STATIC_VALUE))) IS
BEGIN -- P1D1
REPORT.FAILED ("BODY OF P1D1 EXECUTED");
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN P1D1");
END P1D1;
BEGIN -- P1D
P1D1 ;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
REPORT.FAILED ("WRONG EXCEPTION RAISED - P1D1");
END P1D;
PROCEDURE NEW_P1D IS NEW P1D (INTEGER_TYPE => NUMBER,
F_STATIC_VALUE => 21,
S_STATIC_VALUE => 37,
T_STATIC_VALUE => 67,
L_STATIC_VALUE => 79,
A_STATIC_VALUE => 11,
B_STATIC_VALUE => 88,
C_STATIC_VALUE => 87,
D_STATIC_VALUE => 13) ;
BEGIN -- FIRST_STATIC_ARRAY
NEW_P1D (LOWER => 10,
UPPER => 90);
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN CALL TO NEW_P1D");
END FIRST_STATIC_ARRAY ;
--------------------------------------------------
SECOND_STATIC_ARRAY:
DECLARE
-- (D) AN ARRAY PARAMETER CONSTRAINED WITH STATIC BOUNDS ON SUB-
-- SCRIPTS AND NON-STATIC BOUNDS ON COMPONENTS, INITIALIZED
-- WITH A STATIC AGGREGATE.
TYPE NUMBER IS RANGE 1 .. 100 ;
GENERIC
TYPE INTEGER_TYPE IS RANGE <> ;
F_STATIC_VALUE : IN INTEGER_TYPE ;
S_STATIC_VALUE : IN INTEGER_TYPE ;
T_STATIC_VALUE : IN INTEGER_TYPE ;
L_STATIC_VALUE : IN INTEGER_TYPE ;
A_STATIC_VALUE : IN INTEGER_TYPE ;
B_STATIC_VALUE : IN INTEGER_TYPE ;
PROCEDURE P2D (LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE) ;
PROCEDURE P2D (LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE) IS
SUBTYPE SUBINTEGER_TYPE IS INTEGER_TYPE
RANGE LOWER .. UPPER ;
TYPE A1 IS ARRAY (INTEGER_TYPE RANGE
F_STATIC_VALUE .. S_STATIC_VALUE,
INTEGER_TYPE RANGE
T_STATIC_VALUE .. L_STATIC_VALUE)
OF SUBINTEGER_TYPE ;
PROCEDURE P2D1 (A : A1 :=
(F_STATIC_VALUE .. S_STATIC_VALUE =>
(A_STATIC_VALUE, B_STATIC_VALUE))) IS
BEGIN -- P2D1
REPORT.FAILED ("BODY OF P2D1 EXECUTED");
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN P2D1");
END P2D1;
BEGIN -- P2D
P2D1;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
REPORT.FAILED ("WRONG EXCEPTION RAISED - P2D1");
END P2D;
PROCEDURE NEW_P2D IS NEW P2D (INTEGER_TYPE => NUMBER,
F_STATIC_VALUE => 21,
S_STATIC_VALUE => 37,
T_STATIC_VALUE => 67,
L_STATIC_VALUE => 79,
A_STATIC_VALUE => 7,
B_STATIC_VALUE => 93) ;
BEGIN -- SECOND_STATIC_ARRAY
NEW_P2D (LOWER => 5,
UPPER => 95);
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN CALL TO NEW_P2D");
END SECOND_STATIC_ARRAY ;
--------------------------------------------------
REC_NON_STATIC_CONS:
DECLARE
-- (E) A RECORD PARAMETER WITH A NON-STATIC CONSTRAINT
-- INITIALIZED WITH A STATIC AGGREGATE.
TYPE NUMBER IS RANGE 1 .. 100 ;
GENERIC
TYPE INTEGER_TYPE IS RANGE <> ;
F_STATIC_VALUE : IN INTEGER_TYPE ;
S_STATIC_VALUE : IN INTEGER_TYPE ;
T_STATIC_VALUE : IN INTEGER_TYPE ;
L_STATIC_VALUE : IN INTEGER_TYPE ;
D_STATIC_VALUE : IN INTEGER_TYPE ;
PROCEDURE PE (LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE) ;
PROCEDURE PE (LOWER : IN INTEGER_TYPE ;
UPPER : IN INTEGER_TYPE) IS
SUBTYPE SUBINTEGER_TYPE IS INTEGER_TYPE
RANGE LOWER .. UPPER ;
TYPE AR1 IS ARRAY (INTEGER RANGE 1..3) OF
SUBINTEGER_TYPE ;
TYPE REC (DISCRIM : SUBINTEGER_TYPE) IS
RECORD
FIRST : SUBINTEGER_TYPE ;
SECOND : AR1 ;
END RECORD ;
SUBTYPE REC4 IS REC (LOWER) ;
PROCEDURE PE1 (R : REC4 := (D_STATIC_VALUE,
F_STATIC_VALUE,
(S_STATIC_VALUE,
T_STATIC_VALUE,
L_STATIC_VALUE))) IS
BEGIN -- PE1
REPORT.FAILED ("BODY OF PE1 EXECUTED");
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN PE1");
END PE1;
BEGIN -- PE
PE1;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
REPORT.FAILED ("WRONG EXCEPTION RAISED - PE1");
END PE;
PROCEDURE NEW_PE IS NEW PE (INTEGER_TYPE => NUMBER,
F_STATIC_VALUE => 37,
S_STATIC_VALUE => 21,
T_STATIC_VALUE => 67,
L_STATIC_VALUE => 79,
D_STATIC_VALUE => 44) ;
BEGIN -- REC_NON_STATIC_CONS
NEW_PE (LOWER => 2,
UPPER => 99);
EXCEPTION
WHEN OTHERS =>
REPORT.FAILED ("EXCEPTION RAISED IN CALL TO NEW_PE");
END REC_NON_STATIC_CONS ;
--------------------------------------------------
REPORT.RESULT;
END CC3017B;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Definitions; use Definitions;
package Actions is
menu_error : exception;
-- output of "synth version"
procedure print_version;
-- output of "synth help"
procedure print_help;
-- Interactive configuration menu
procedure launch_configure_menu (num_cores : cpu_range);
private
function generic_execute (command : String) return Boolean;
procedure clear_screen;
end Actions;
|
-- This spec has been automatically generated from STM32L5x2.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.DMAMUX is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype C0CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C0CR_SPOL_Field is HAL.UInt2;
subtype C0CR_NBREQ_Field is HAL.UInt5;
subtype C0CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 0 Control register
type C0CR_Register is record
-- DMA Request ID
DMAREQ_ID : C0CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C0CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C0CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C0CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C0CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C1CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C1CR_SPOL_Field is HAL.UInt2;
subtype C1CR_NBREQ_Field is HAL.UInt5;
subtype C1CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 1 Control register
type C1CR_Register is record
-- DMA Request ID
DMAREQ_ID : C1CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C1CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C1CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C1CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C1CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C2CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C2CR_SPOL_Field is HAL.UInt2;
subtype C2CR_NBREQ_Field is HAL.UInt5;
subtype C2CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 2 Control register
type C2CR_Register is record
-- DMA Request ID
DMAREQ_ID : C2CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C2CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C2CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C2CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C2CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C3CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C3CR_SPOL_Field is HAL.UInt2;
subtype C3CR_NBREQ_Field is HAL.UInt5;
subtype C3CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 3 Control register
type C3CR_Register is record
-- DMA Request ID
DMAREQ_ID : C3CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C3CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C3CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C3CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C3CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C4CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C4CR_SPOL_Field is HAL.UInt2;
subtype C4CR_NBREQ_Field is HAL.UInt5;
subtype C4CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 4 Control register
type C4CR_Register is record
-- DMA Request ID
DMAREQ_ID : C4CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C4CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C4CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C4CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C4CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C5CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C5CR_SPOL_Field is HAL.UInt2;
subtype C5CR_NBREQ_Field is HAL.UInt5;
subtype C5CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 5 Control register
type C5CR_Register is record
-- DMA Request ID
DMAREQ_ID : C5CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
OIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C5CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C5CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C5CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C5CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
OIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C6CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C6CR_SPOL_Field is HAL.UInt2;
subtype C6CR_NBREQ_Field is HAL.UInt5;
subtype C6CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 6 Control register
type C6CR_Register is record
-- DMA Request ID
DMAREQ_ID : C6CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C6CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C6CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C6CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C6CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C7CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C7CR_SPOL_Field is HAL.UInt2;
subtype C7CR_NBREQ_Field is HAL.UInt5;
subtype C7CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 7 Control register
type C7CR_Register is record
-- DMA Request ID
DMAREQ_ID : C7CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C7CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C7CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C7CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C7CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C8CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C8CR_SPOL_Field is HAL.UInt2;
subtype C8CR_NBREQ_Field is HAL.UInt5;
subtype C8CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 8 Control register
type C8CR_Register is record
-- DMA Request ID
DMAREQ_ID : C8CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C8CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C8CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C8CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C8CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C9CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C9CR_SPOL_Field is HAL.UInt2;
subtype C9CR_NBREQ_Field is HAL.UInt5;
subtype C9CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 9 Control register
type C9CR_Register is record
-- DMA Request ID
DMAREQ_ID : C9CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C9CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C9CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C9CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C9CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C10CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C10CR_SPOL_Field is HAL.UInt2;
subtype C10CR_NBREQ_Field is HAL.UInt5;
subtype C10CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 10 Control register
type C10CR_Register is record
-- DMA Request ID
DMAREQ_ID : C10CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C10CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C10CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C10CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C10CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C11CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C11CR_SPOL_Field is HAL.UInt2;
subtype C11CR_NBREQ_Field is HAL.UInt5;
subtype C11CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 11 Control register
type C11CR_Register is record
-- DMA Request ID
DMAREQ_ID : C11CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C11CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C11CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C11CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C11CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C12CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C12CR_SPOL_Field is HAL.UInt2;
subtype C12CR_NBREQ_Field is HAL.UInt5;
subtype C12CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 12 Control register
type C12CR_Register is record
-- DMA Request ID
DMAREQ_ID : C12CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C12CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C12CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C12CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C12CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C13CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C13CR_SPOL_Field is HAL.UInt2;
subtype C13CR_NBREQ_Field is HAL.UInt5;
subtype C13CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 13 Control register
type C13CR_Register is record
-- DMA Request ID
DMAREQ_ID : C13CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization Overrun Interrupt Enable
SOIE : Boolean := False;
-- Event Generation Enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Sync polarity
SPOL : C13CR_SPOL_Field := 16#0#;
-- Nb request
NBREQ : C13CR_NBREQ_Field := 16#0#;
-- SYNC_ID
SYNC_ID : C13CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C13CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
-- CSR_SOF array
type CSR_SOF_Field_Array is array (0 .. 15) of Boolean
with Component_Size => 1, Size => 16;
-- Type definition for CSR_SOF
type CSR_SOF_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- SOF as a value
Val : HAL.UInt16;
when True =>
-- SOF as an array
Arr : CSR_SOF_Field_Array;
end case;
end record
with Unchecked_Union, Size => 16;
for CSR_SOF_Field use record
Val at 0 range 0 .. 15;
Arr at 0 range 0 .. 15;
end record;
-- DMA Multiplexer Channel Status register
type CSR_Register is record
-- Synchronization Overrun Flag 0
SOF : CSR_SOF_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CSR_Register use record
SOF at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- CCFR_CSOF array
type CCFR_CSOF_Field_Array is array (0 .. 15) of Boolean
with Component_Size => 1, Size => 16;
-- Type definition for CCFR_CSOF
type CCFR_CSOF_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- CSOF as a value
Val : HAL.UInt16;
when True =>
-- CSOF as an array
Arr : CCFR_CSOF_Field_Array;
end case;
end record
with Unchecked_Union, Size => 16;
for CCFR_CSOF_Field use record
Val at 0 range 0 .. 15;
Arr at 0 range 0 .. 15;
end record;
-- DMA Channel Clear Flag Register
type CCFR_Register is record
-- Synchronization Clear Overrun Flag 0
CSOF : CCFR_CSOF_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CCFR_Register use record
CSOF at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype RG0CR_SIG_ID_Field is HAL.UInt5;
subtype RG0CR_GPOL_Field is HAL.UInt2;
subtype RG0CR_GNBREQ_Field is HAL.UInt5;
-- DMA Request Generator 0 Control Register
type RG0CR_Register is record
-- Signal ID
SIG_ID : RG0CR_SIG_ID_Field := 16#0#;
-- unspecified
Reserved_5_7 : HAL.UInt3 := 16#0#;
-- Overrun Interrupt Enable
OIE : Boolean := False;
-- unspecified
Reserved_9_15 : HAL.UInt7 := 16#0#;
-- Generation Enable
GE : Boolean := False;
-- Generation Polarity
GPOL : RG0CR_GPOL_Field := 16#0#;
-- Number of Request
GNBREQ : RG0CR_GNBREQ_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RG0CR_Register use record
SIG_ID at 0 range 0 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
OIE at 0 range 8 .. 8;
Reserved_9_15 at 0 range 9 .. 15;
GE at 0 range 16 .. 16;
GPOL at 0 range 17 .. 18;
GNBREQ at 0 range 19 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype RG1CR_SIG_ID_Field is HAL.UInt5;
subtype RG1CR_GPOL_Field is HAL.UInt2;
subtype RG1CR_GNBREQ_Field is HAL.UInt5;
-- DMA Request Generator 1 Control Register
type RG1CR_Register is record
-- Signal ID
SIG_ID : RG1CR_SIG_ID_Field := 16#0#;
-- unspecified
Reserved_5_7 : HAL.UInt3 := 16#0#;
-- Overrun Interrupt Enable
OIE : Boolean := False;
-- unspecified
Reserved_9_15 : HAL.UInt7 := 16#0#;
-- Generation Enable
GE : Boolean := False;
-- Generation Polarity
GPOL : RG1CR_GPOL_Field := 16#0#;
-- Number of Request
GNBREQ : RG1CR_GNBREQ_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RG1CR_Register use record
SIG_ID at 0 range 0 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
OIE at 0 range 8 .. 8;
Reserved_9_15 at 0 range 9 .. 15;
GE at 0 range 16 .. 16;
GPOL at 0 range 17 .. 18;
GNBREQ at 0 range 19 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype RG2CR_SIG_ID_Field is HAL.UInt5;
subtype RG2CR_GPOL_Field is HAL.UInt2;
subtype RG2CR_GNBREQ_Field is HAL.UInt5;
-- DMA Request Generator 2 Control Register
type RG2CR_Register is record
-- Signal ID
SIG_ID : RG2CR_SIG_ID_Field := 16#0#;
-- unspecified
Reserved_5_7 : HAL.UInt3 := 16#0#;
-- Overrun Interrupt Enable
OIE : Boolean := False;
-- unspecified
Reserved_9_15 : HAL.UInt7 := 16#0#;
-- Generation Enable
GE : Boolean := False;
-- Generation Polarity
GPOL : RG2CR_GPOL_Field := 16#0#;
-- Number of Request
GNBREQ : RG2CR_GNBREQ_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RG2CR_Register use record
SIG_ID at 0 range 0 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
OIE at 0 range 8 .. 8;
Reserved_9_15 at 0 range 9 .. 15;
GE at 0 range 16 .. 16;
GPOL at 0 range 17 .. 18;
GNBREQ at 0 range 19 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype RG3CR_SIG_ID_Field is HAL.UInt5;
subtype RG3CR_GPOL_Field is HAL.UInt2;
subtype RG3CR_GNBREQ_Field is HAL.UInt5;
-- DMA Request Generator 3 Control Register
type RG3CR_Register is record
-- Signal ID
SIG_ID : RG3CR_SIG_ID_Field := 16#0#;
-- unspecified
Reserved_5_7 : HAL.UInt3 := 16#0#;
-- Overrun Interrupt Enable
OIE : Boolean := False;
-- unspecified
Reserved_9_15 : HAL.UInt7 := 16#0#;
-- Generation Enable
GE : Boolean := False;
-- Generation Polarity
GPOL : RG3CR_GPOL_Field := 16#0#;
-- Number of Request
GNBREQ : RG3CR_GNBREQ_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RG3CR_Register use record
SIG_ID at 0 range 0 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
OIE at 0 range 8 .. 8;
Reserved_9_15 at 0 range 9 .. 15;
GE at 0 range 16 .. 16;
GPOL at 0 range 17 .. 18;
GNBREQ at 0 range 19 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype C14CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C14CR_SPOL_Field is HAL.UInt2;
subtype C14CR_NBREQ_Field is HAL.UInt5;
subtype C14CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 10 Control register
type C14CR_Register is record
-- DMA request identification
DMAREQ_ID : C14CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization overrun interrupt enable
SOIE : Boolean := False;
-- Event generation enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Synchronization polarity
SPOL : C14CR_SPOL_Field := 16#0#;
-- Number of DMA requests minus 1 to forward
NBREQ : C14CR_NBREQ_Field := 16#0#;
-- Synchronization identification
SYNC_ID : C14CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C14CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype C15CR_DMAREQ_ID_Field is HAL.UInt7;
subtype C15CR_SPOL_Field is HAL.UInt2;
subtype C15CR_NBREQ_Field is HAL.UInt5;
subtype C15CR_SYNC_ID_Field is HAL.UInt5;
-- DMA Multiplexer Channel 10 Control register
type C15CR_Register is record
-- DMA request identification
DMAREQ_ID : C15CR_DMAREQ_ID_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Synchronization overrun interrupt enable
SOIE : Boolean := False;
-- Event generation enable
EGE : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Synchronization enable
SE : Boolean := False;
-- Synchronization polarity
SPOL : C15CR_SPOL_Field := 16#0#;
-- Number of DMA requests minus 1 to forward
NBREQ : C15CR_NBREQ_Field := 16#0#;
-- Synchronization identification
SYNC_ID : C15CR_SYNC_ID_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for C15CR_Register use record
DMAREQ_ID at 0 range 0 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SOIE at 0 range 8 .. 8;
EGE at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
SE at 0 range 16 .. 16;
SPOL at 0 range 17 .. 18;
NBREQ at 0 range 19 .. 23;
SYNC_ID at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
-- RGSR_OF array
type RGSR_OF_Field_Array is array (0 .. 3) of Boolean
with Component_Size => 1, Size => 4;
-- Type definition for RGSR_OF
type RGSR_OF_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- OF as a value
Val : HAL.UInt4;
when True =>
-- OF as an array
Arr : RGSR_OF_Field_Array;
end case;
end record
with Unchecked_Union, Size => 4;
for RGSR_OF_Field use record
Val at 0 range 0 .. 3;
Arr at 0 range 0 .. 3;
end record;
-- DMA Request Generator Status Register
type RGSR_Register is record
-- Read-only. Generator Overrun Flag 0
OF_k : RGSR_OF_Field;
-- unspecified
Reserved_4_31 : HAL.UInt28;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RGSR_Register use record
OF_k at 0 range 0 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- RGCFR_CSOF array
type RGCFR_CSOF_Field_Array is array (0 .. 3) of Boolean
with Component_Size => 1, Size => 4;
-- Type definition for RGCFR_CSOF
type RGCFR_CSOF_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- CSOF as a value
Val : HAL.UInt4;
when True =>
-- CSOF as an array
Arr : RGCFR_CSOF_Field_Array;
end case;
end record
with Unchecked_Union, Size => 4;
for RGCFR_CSOF_Field use record
Val at 0 range 0 .. 3;
Arr at 0 range 0 .. 3;
end record;
-- DMA Request Generator Clear Flag Register
type RGCFR_Register is record
-- Generator Clear Overrun Flag 0
CSOF : RGCFR_CSOF_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RGCFR_Register use record
CSOF at 0 range 0 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Direct memory access Multiplexer
type DMAMUX_Peripheral is record
-- DMA Multiplexer Channel 0 Control register
C0CR : aliased C0CR_Register;
-- DMA Multiplexer Channel 1 Control register
C1CR : aliased C1CR_Register;
-- DMA Multiplexer Channel 2 Control register
C2CR : aliased C2CR_Register;
-- DMA Multiplexer Channel 3 Control register
C3CR : aliased C3CR_Register;
-- DMA Multiplexer Channel 4 Control register
C4CR : aliased C4CR_Register;
-- DMA Multiplexer Channel 5 Control register
C5CR : aliased C5CR_Register;
-- DMA Multiplexer Channel 6 Control register
C6CR : aliased C6CR_Register;
-- DMA Multiplexer Channel 7 Control register
C7CR : aliased C7CR_Register;
-- DMA Multiplexer Channel 8 Control register
C8CR : aliased C8CR_Register;
-- DMA Multiplexer Channel 9 Control register
C9CR : aliased C9CR_Register;
-- DMA Multiplexer Channel 10 Control register
C10CR : aliased C10CR_Register;
-- DMA Multiplexer Channel 11 Control register
C11CR : aliased C11CR_Register;
-- DMA Multiplexer Channel 12 Control register
C12CR : aliased C12CR_Register;
-- DMA Multiplexer Channel 13 Control register
C13CR : aliased C13CR_Register;
-- DMA Multiplexer Channel Status register
CSR : aliased CSR_Register;
-- DMA Channel Clear Flag Register
CCFR : aliased CCFR_Register;
-- DMA Request Generator 0 Control Register
RG0CR : aliased RG0CR_Register;
-- DMA Request Generator 1 Control Register
RG1CR : aliased RG1CR_Register;
-- DMA Request Generator 2 Control Register
RG2CR : aliased RG2CR_Register;
-- DMA Request Generator 3 Control Register
RG3CR : aliased RG3CR_Register;
-- DMA Multiplexer Channel 10 Control register
C14CR : aliased C14CR_Register;
-- DMA Multiplexer Channel 10 Control register
C15CR : aliased C15CR_Register;
-- DMA Request Generator Status Register
RGSR : aliased RGSR_Register;
-- DMA Request Generator Clear Flag Register
RGCFR : aliased RGCFR_Register;
end record
with Volatile;
for DMAMUX_Peripheral use record
C0CR at 16#0# range 0 .. 31;
C1CR at 16#4# range 0 .. 31;
C2CR at 16#8# range 0 .. 31;
C3CR at 16#C# range 0 .. 31;
C4CR at 16#10# range 0 .. 31;
C5CR at 16#14# range 0 .. 31;
C6CR at 16#18# range 0 .. 31;
C7CR at 16#1C# range 0 .. 31;
C8CR at 16#20# range 0 .. 31;
C9CR at 16#24# range 0 .. 31;
C10CR at 16#28# range 0 .. 31;
C11CR at 16#2C# range 0 .. 31;
C12CR at 16#30# range 0 .. 31;
C13CR at 16#34# range 0 .. 31;
CSR at 16#80# range 0 .. 31;
CCFR at 16#84# range 0 .. 31;
RG0CR at 16#100# range 0 .. 31;
RG1CR at 16#104# range 0 .. 31;
RG2CR at 16#108# range 0 .. 31;
RG3CR at 16#10C# range 0 .. 31;
C14CR at 16#138# range 0 .. 31;
C15CR at 16#13C# range 0 .. 31;
RGSR at 16#140# range 0 .. 31;
RGCFR at 16#144# range 0 .. 31;
end record;
-- Direct memory access Multiplexer
DMAMUX1_Periph : aliased DMAMUX_Peripheral
with Import, Address => System'To_Address (16#40020800#);
-- Direct memory access Multiplexer
SEC_DMAMUX1_Periph : aliased DMAMUX_Peripheral
with Import, Address => System'To_Address (16#50020800#);
end STM32_SVD.DMAMUX;
|
with Blueprint; use Blueprint;
package Init_Project is
procedure Init (Path : String; Blueprint : String; ToDo : Action);
private
end Init_Project;
|
-- Institution: Technische Universität München
-- Department: Realtime Computer Systems (RCS)
-- Project: StratoX
-- Module: CRC-8
--
-- Authors: Emanuel Regnath (emanuel.regnath@tum.de)
--
-- Description: Checksum according to fletcher's algorithm
generic
type Index_Type is (<>);
type Element_Type is private;
package Generic_Unit with
SPARK_Mode is
type Byte is mod 2**8;
--type Array_Type is array (Integer range <>) of Element_Type;
type Checksum_Type is record
ck_a : Byte;
ck_b : Byte;
end record;
-- init
--function Checksum(Data : Array_Type) return Checksum_Type;
function Add (i1 : Index_Type; i2 : Index_Type) return Index_Type;
end Generic_Unit;
|
-- { dg-do run }
procedure interface3 is
--
package Pkg is
type Foo is interface;
subtype Element_Type is Foo'Class;
--
type Element_Access is access Element_Type;
type Elements_Type is array (1 .. 1) of Element_Access;
type Elements_Access is access Elements_Type;
--
type Vector is tagged record
Elements : Elements_Access;
end record;
--
procedure Test (Obj : Vector);
end;
--
package body Pkg is
procedure Test (Obj : Vector) is
Elements : Elements_Access := new Elements_Type;
--
begin
Elements (1) := new Element_Type'(Obj.Elements (1).all);
end;
end;
--
begin
null;
end;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- B I N D G E N --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-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. 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 COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Casing; use Casing;
with Fname; use Fname;
with Gnatvsn; use Gnatvsn;
with Hostparm;
with Namet; use Namet;
with Opt; use Opt;
with Osint; use Osint;
with Osint.B; use Osint.B;
with Output; use Output;
with Rident; use Rident;
with Table;
with Targparm; use Targparm;
with Types; use Types;
with System.OS_Lib;
with System.WCh_Con; use System.WCh_Con;
with GNAT.Heap_Sort_A; use GNAT.Heap_Sort_A;
with GNAT.HTable;
package body Bindgen is
Statement_Buffer : String (1 .. 1000);
-- Buffer used for constructing output statements
Stm_Last : Natural := 0;
-- Stm_Last location in Statement_Buffer currently set
With_GNARL : Boolean := False;
-- Flag which indicates whether the program uses the GNARL library
-- (presence of the unit System.OS_Interface)
Num_Elab_Calls : Nat := 0;
-- Number of generated calls to elaboration routines
Num_Primary_Stacks : Int := 0;
-- Number of default-sized primary stacks the binder needs to allocate for
-- task objects declared in the program.
Num_Sec_Stacks : Int := 0;
-- Number of default-sized primary stacks the binder needs to allocate for
-- task objects declared in the program.
System_Restrictions_Used : Boolean := False;
-- Flag indicating whether the unit System.Restrictions is in the closure
-- of the partition. This is set by Resolve_Binder_Options, and is used
-- to determine whether or not to initialize the restrictions information
-- in the body of the binder generated file (we do not want to do this
-- unconditionally, since it drags in the System.Restrictions unit
-- unconditionally, which is unpleasand, especially for ZFP etc.)
Dispatching_Domains_Used : Boolean := False;
-- Flag indicating whether multiprocessor dispatching domains are used in
-- the closure of the partition. This is set by Resolve_Binder_Options, and
-- is used to call the routine to disallow the creation of new dispatching
-- domains just before calling the main procedure from the environment
-- task.
System_Secondary_Stack_Package_In_Closure : Boolean := False;
-- Flag indicating whether the unit System.Secondary_Stack is in the
-- closure of the partition. This is set by Resolve_Binder_Options, and
-- is used to initialize the package in cases where the run-time brings
-- in package but the secondary stack is not used.
System_Tasking_Restricted_Stages_Used : Boolean := False;
-- Flag indicating whether the unit System.Tasking.Restricted.Stages is in
-- the closure of the partition. This is set by Resolve_Binder_Options,
-- and it used to call a routine to active all the tasks at the end of
-- the elaboration when partition elaboration policy is sequential.
System_Interrupts_Used : Boolean := False;
-- Flag indicating whether the unit System.Interrups is in the closure of
-- the partition. This is set by Resolve_Binder_Options, and it used to
-- attach interrupt handlers at the end of the elaboration when partition
-- elaboration policy is sequential.
System_BB_CPU_Primitives_Multiprocessors_Used : Boolean := False;
-- Flag indicating whether unit System.BB.CPU_Primitives.Multiprocessors
-- is in the closure of the partition. This is set by procedure
-- Resolve_Binder_Options, and it is used to call a procedure that starts
-- slave processors.
System_Version_Control_Used : Boolean := False;
-- Flag indicating whether unit System.Version_Control is in the closure.
-- This unit is implicitly withed by the compiler when Version or
-- Body_Version attributes are used. If the package is not in the closure,
-- the version definitions can be removed.
Lib_Final_Built : Boolean := False;
-- Flag indicating whether the finalize_library rountine has been built
Bind_Env_String_Built : Boolean := False;
-- Flag indicating whether a bind environment string has been built
CodePeer_Wrapper_Name : constant String := "call_main_subprogram";
-- For CodePeer, introduce a wrapper subprogram which calls the
-- user-defined main subprogram.
----------------------------------
-- Interface_State Pragma Table --
----------------------------------
-- This table assembles the interface state pragma information from
-- all the units in the partition. Note that Bcheck has already checked
-- that the information is consistent across units. The entries
-- in this table are n/u/r/s for not set/user/runtime/system.
package IS_Pragma_Settings is new Table.Table
(Table_Component_Type => Character,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => 100,
Table_Increment => 200,
Table_Name => "IS_Pragma_Settings");
-- This table assembles the Priority_Specific_Dispatching pragma
-- information from all the units in the partition. Note that Bcheck has
-- already checked that the information is consistent across units.
-- The entries in this table are the upper case first character of the
-- policy name, e.g. 'F' for FIFO_Within_Priorities.
package PSD_Pragma_Settings is new Table.Table
(Table_Component_Type => Character,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => 100,
Table_Increment => 200,
Table_Name => "PSD_Pragma_Settings");
----------------------------
-- Bind_Environment Table --
----------------------------
subtype Header_Num is Int range 0 .. 36;
function Hash (Nam : Name_Id) return Header_Num;
package Bind_Environment is new GNAT.HTable.Simple_HTable
(Header_Num => Header_Num,
Element => Name_Id,
No_Element => No_Name,
Key => Name_Id,
Hash => Hash,
Equal => "=");
----------------------
-- Run-Time Globals --
----------------------
-- This section documents the global variables that are set from the
-- generated binder file.
-- Main_Priority : Integer;
-- Time_Slice_Value : Integer;
-- Heap_Size : Natural;
-- WC_Encoding : Character;
-- Locking_Policy : Character;
-- Queuing_Policy : Character;
-- Task_Dispatching_Policy : Character;
-- Priority_Specific_Dispatching : System.Address;
-- Num_Specific_Dispatching : Integer;
-- Restrictions : System.Address;
-- Interrupt_States : System.Address;
-- Num_Interrupt_States : Integer;
-- Unreserve_All_Interrupts : Integer;
-- Exception_Tracebacks : Integer;
-- Exception_Tracebacks_Symbolic : Integer;
-- Detect_Blocking : Integer;
-- Default_Stack_Size : Integer;
-- Default_Secondary_Stack_Size : System.Parameters.Size_Type;
-- Leap_Seconds_Support : Integer;
-- Main_CPU : Integer;
-- Default_Sized_SS_Pool : System.Address;
-- Binder_Sec_Stacks_Count : Natural;
-- XDR_Stream : Integer;
-- Main_Priority is the priority value set by pragma Priority in the main
-- program. If no such pragma is present, the value is -1.
-- Time_Slice_Value is the time slice value set by pragma Time_Slice in the
-- main program, or by the use of a -Tnnn parameter for the binder (if both
-- are present, the binder value overrides). The value is in milliseconds.
-- A value of zero indicates that time slicing should be suppressed. If no
-- pragma is present, and no -T switch was used, the value is -1.
-- WC_Encoding shows the wide character encoding method used for the main
-- program. This is one of the encoding letters defined in
-- System.WCh_Con.WC_Encoding_Letters.
-- Locking_Policy is a space if no locking policy was specified for the
-- partition. If a locking policy was specified, the value is the upper
-- case first character of the locking policy name, for example, 'C' for
-- Ceiling_Locking.
-- Queuing_Policy is a space if no queuing policy was specified for the
-- partition. If a queuing policy was specified, the value is the upper
-- case first character of the queuing policy name for example, 'F' for
-- FIFO_Queuing.
-- Task_Dispatching_Policy is a space if no task dispatching policy was
-- specified for the partition. If a task dispatching policy was specified,
-- the value is the upper case first character of the policy name, e.g. 'F'
-- for FIFO_Within_Priorities.
-- Priority_Specific_Dispatching is the address of a string used to store
-- the task dispatching policy specified for the different priorities in
-- the partition. The length of this string is determined by the last
-- priority for which such a pragma applies (the string will be a null
-- string if no specific dispatching policies were used). If pragma were
-- present, the entries apply to the priorities in sequence from the first
-- priority. The value stored is the upper case first character of the
-- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
-- for those priority ranges not specified.
-- Num_Specific_Dispatching is length of the Priority_Specific_Dispatching
-- string. It will be set to zero if no Priority_Specific_Dispatching
-- pragmas are present.
-- Restrictions is the address of a null-terminated string specifying the
-- restrictions information for the partition. The format is identical to
-- that of the parameter string found on R lines in ali files (see Lib.Writ
-- spec in lib-writ.ads for full details). The difference is that in this
-- context the values are the cumulative ones for the entire partition.
-- Interrupt_States is the address of a string used to specify the
-- cumulative results of Interrupt_State pragmas used in the partition.
-- The length of this string is determined by the last interrupt for which
-- such a pragma is given (the string will be a null string if no pragmas
-- were used). If pragma were present the entries apply to the interrupts
-- in sequence from the first interrupt, and are set to one of four
-- possible settings: 'n' for not specified, 'u' for user, 'r' for run
-- time, 's' for system, see description of Interrupt_State pragma for
-- further details.
-- Num_Interrupt_States is the length of the Interrupt_States string. It
-- will be set to zero if no Interrupt_State pragmas are present.
-- Unreserve_All_Interrupts is set to one if at least one unit in the
-- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
-- Exception_Tracebacks is set to one if the -Ea or -E parameter was
-- present in the bind and to zero otherwise. Note that on some targets
-- exception tracebacks are provided by default, so a value of zero for
-- this parameter does not necessarily mean no trace backs are available.
-- Exception_Tracebacks_Symbolic is set to one if the -Es parameter was
-- present in the bind and to zero otherwise.
-- Detect_Blocking indicates whether pragma Detect_Blocking is active or
-- not. A value of zero indicates that the pragma is not present, while a
-- value of 1 signals its presence in the partition.
-- Default_Stack_Size is the default stack size used when creating an Ada
-- task with no explicit Storage_Size clause.
-- Default_Secondary_Stack_Size is the default secondary stack size used
-- when creating an Ada task with no explicit Secondary_Stack_Size clause.
-- Leap_Seconds_Support denotes whether leap seconds have been enabled or
-- disabled. A value of zero indicates that leap seconds are turned "off",
-- while a value of one signifies "on" status.
-- Main_CPU is the processor set by pragma CPU in the main program. If no
-- such pragma is present, the value is -1.
-- Default_Sized_SS_Pool is set to the address of the default-sized
-- secondary stacks array generated by the binder. This pool of stacks is
-- generated when either the restriction No_Implicit_Heap_Allocations
-- or No_Implicit_Task_Allocations is active.
-- Binder_Sec_Stacks_Count is the number of generated secondary stacks in
-- the Default_Sized_SS_Pool.
-- XDR_Stream indicates whether streaming should be performed using the
-- XDR protocol. A value of one indicates that XDR streaming is enabled.
procedure WBI (Info : String) renames Osint.B.Write_Binder_Info;
-- Convenient shorthand used throughout
-----------------------
-- Local Subprograms --
-----------------------
procedure Gen_Adainit (Elab_Order : Unit_Id_Array);
-- Generates the Adainit procedure
procedure Gen_Adafinal;
-- Generate the Adafinal procedure
procedure Gen_Bind_Env_String;
-- Generate the bind environment buffer
procedure Gen_CodePeer_Wrapper;
-- For CodePeer, generate wrapper which calls user-defined main subprogram
procedure Gen_Elab_Calls (Elab_Order : Unit_Id_Array);
-- Generate sequence of elaboration calls
procedure Gen_Elab_Externals (Elab_Order : Unit_Id_Array);
-- Generate sequence of external declarations for elaboration
procedure Gen_Elab_Order (Elab_Order : Unit_Id_Array);
-- Generate comments showing elaboration order chosen
procedure Gen_Finalize_Library (Elab_Order : Unit_Id_Array);
-- Generate a sequence of finalization calls to elaborated packages
procedure Gen_Main;
-- Generate procedure main
procedure Gen_Object_Files_Options (Elab_Order : Unit_Id_Array);
-- Output comments containing a list of the full names of the object
-- files to be linked and the list of linker options supplied by
-- Linker_Options pragmas in the source.
procedure Gen_Output_File_Ada
(Filename : String;
Elab_Order : Unit_Id_Array);
-- Generate Ada output file
procedure Gen_Restrictions;
-- Generate initialization of restrictions variable
procedure Gen_Versions;
-- Output series of definitions for unit versions
function Get_Ada_Main_Name return String;
-- This function is used for the Ada main output to compute a usable name
-- for the generated main program. The normal main program name is
-- Ada_Main, but this won't work if the user has a unit with this name.
-- This function tries Ada_Main first, and if there is such a clash, then
-- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
function Get_Main_Unit_Name (S : String) return String;
-- Return the main unit name corresponding to S by replacing '.' with '_'
function Get_Main_Name return String;
-- This function is used in the main output case to compute the correct
-- external main program. It is "main" by default, unless the flag
-- Use_Ada_Main_Program_Name_On_Target is set, in which case it is the name
-- of the Ada main name without the "_ada". This default can be overridden
-- explicitly using the -Mname binder switch.
function Get_WC_Encoding return Character;
-- Return wide character encoding method to set as WC_Encoding in output.
-- If -W has been used, returns the specified encoding, otherwise returns
-- the encoding method used for the main program source. If there is no
-- main program source (-z switch used), returns brackets ('b').
function Has_Finalizer (Elab_Order : Unit_Id_Array) return Boolean;
-- Determine whether the current unit has at least one library-level
-- finalizer.
function Lt_Linker_Option (Op1 : Natural; Op2 : Natural) return Boolean;
-- Compare linker options, when sorting, first according to
-- Is_Internal_File (internal files come later) and then by
-- elaboration order position (latest to earliest).
procedure Move_Linker_Option (From : Natural; To : Natural);
-- Move routine for sorting linker options
procedure Resolve_Binder_Options (Elab_Order : Unit_Id_Array);
-- Set the value of With_GNARL
procedure Set_Char (C : Character);
-- Set given character in Statement_Buffer at the Stm_Last + 1 position
-- and increment Stm_Last by one to reflect the stored character.
procedure Set_Int (N : Int);
-- Set given value in decimal in Statement_Buffer with no spaces starting
-- at the Stm_Last + 1 position, and updating Stm_Last past the value. A
-- minus sign is output for a negative value.
procedure Set_Boolean (B : Boolean);
-- Set given boolean value in Statement_Buffer at the Stm_Last + 1 position
-- and update Stm_Last past the value.
procedure Set_IS_Pragma_Table;
-- Initializes contents of IS_Pragma_Settings table from ALI table
procedure Set_Main_Program_Name;
-- Given the main program name in Name_Buffer (length in Name_Len) generate
-- the name of the routine to be used in the call. The name is generated
-- starting at Stm_Last + 1, and Stm_Last is updated past it.
procedure Set_Name_Buffer;
-- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
procedure Set_PSD_Pragma_Table;
-- Initializes contents of PSD_Pragma_Settings table from ALI table
procedure Set_String (S : String);
-- Sets characters of given string in Statement_Buffer, starting at the
-- Stm_Last + 1 position, and updating last past the string value.
procedure Set_String_Replace (S : String);
-- Replaces the last S'Length characters in the Statement_Buffer with the
-- characters of S. The caller must ensure that these characters do in fact
-- exist in the Statement_Buffer.
procedure Set_Unit_Name;
-- Given a unit name in the Name_Buffer, copy it into Statement_Buffer,
-- starting at the Stm_Last + 1 position and update Stm_Last past the
-- value. Each dot (.) will be qualified into double underscores (__).
procedure Set_Unit_Number (U : Unit_Id);
-- Sets unit number (first unit is 1, leading zeroes output to line up all
-- output unit numbers nicely as required by the value, and by the total
-- number of units.
procedure Write_Statement_Buffer;
-- Write out contents of statement buffer up to Stm_Last, and reset
-- Stm_Last to 0.
procedure Write_Statement_Buffer (S : String);
-- First writes its argument (using Set_String (S)), then writes out the
-- contents of statement buffer up to Stm_Last, and resets Stm_Last to 0.
procedure Write_Bind_Line (S : String);
-- Write S (an LF-terminated string) to the binder file (for use with
-- Set_Special_Output).
------------------
-- Gen_Adafinal --
------------------
procedure Gen_Adafinal is
begin
WBI (" procedure " & Ada_Final_Name.all & " is");
-- Call s_stalib_adafinal to await termination of tasks and so on. We
-- want to do this if there is a main program, either in Ada or in some
-- other language. (Note that Bind_Main_Program is True for Ada mains,
-- but False for mains in other languages.) We do not want to do this if
-- we're binding a library.
if not Bind_For_Library and not CodePeer_Mode then
WBI (" procedure s_stalib_adafinal;");
Set_String (" pragma Import (Ada, s_stalib_adafinal, ");
Set_String ("""system__standard_library__adafinal"");");
Write_Statement_Buffer;
end if;
WBI ("");
WBI (" procedure Runtime_Finalize;");
WBI (" pragma Import (C, Runtime_Finalize, " &
"""__gnat_runtime_finalize"");");
WBI ("");
WBI (" begin");
if not CodePeer_Mode then
WBI (" if not Is_Elaborated then");
WBI (" return;");
WBI (" end if;");
WBI (" Is_Elaborated := False;");
end if;
WBI (" Runtime_Finalize;");
-- By default (real targets), finalization is done differently depending
-- on whether this is the main program or a library.
if not CodePeer_Mode then
if not Bind_For_Library then
WBI (" s_stalib_adafinal;");
elsif Lib_Final_Built then
WBI (" finalize_library;");
else
WBI (" null;");
end if;
-- Pragma Import C cannot be used on virtual targets, therefore call the
-- runtime finalization routine directly in CodePeer mode, where
-- imported functions are ignored.
else
WBI (" System.Standard_Library.Adafinal;");
end if;
WBI (" end " & Ada_Final_Name.all & ";");
WBI ("");
end Gen_Adafinal;
-----------------
-- Gen_Adainit --
-----------------
procedure Gen_Adainit (Elab_Order : Unit_Id_Array) is
Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
Main_CPU : Int renames ALIs.Table (ALIs.First).Main_CPU;
begin
-- Declare the access-to-subprogram type used for initialization of
-- of __gnat_finalize_library_objects. This is declared at library
-- level for compatibility with the type used in System.Soft_Links.
-- The import of the soft link which performs library-level object
-- finalization does not work for CodePeer, so regular Ada is used in
-- that case. For restricted run-time libraries (ZFP and Ravenscar)
-- tasks are non-terminating, so we do not want finalization.
if not Suppress_Standard_Library_On_Target
and then not CodePeer_Mode
and then not Configurable_Run_Time_On_Target
then
WBI (" type No_Param_Proc is access procedure;");
WBI (" pragma Favor_Top_Level (No_Param_Proc);");
WBI ("");
end if;
WBI (" procedure " & Ada_Init_Name.all & " is");
-- In CodePeer mode, simplify adainit procedure by only calling
-- elaboration procedures.
if CodePeer_Mode then
WBI (" begin");
-- If the standard library is suppressed, then the only global variables
-- that might be needed (by the Ravenscar profile) are the priority and
-- the processor for the environment task.
elsif Suppress_Standard_Library_On_Target then
if Main_Priority /= No_Main_Priority then
WBI (" Main_Priority : Integer;");
WBI (" pragma Import (C, Main_Priority," &
" ""__gl_main_priority"");");
WBI ("");
end if;
if Main_CPU /= No_Main_CPU then
WBI (" Main_CPU : Integer;");
WBI (" pragma Import (C, Main_CPU," &
" ""__gl_main_cpu"");");
WBI ("");
end if;
if System_Interrupts_Used
and then Partition_Elaboration_Policy_Specified = 'S'
then
WBI (" procedure Install_Restricted_Handlers_Sequential;");
WBI (" pragma Import (C," &
"Install_Restricted_Handlers_Sequential," &
" ""__gnat_attach_all_handlers"");");
WBI ("");
end if;
if System_Tasking_Restricted_Stages_Used
and then Partition_Elaboration_Policy_Specified = 'S'
then
WBI (" Partition_Elaboration_Policy : Character;");
WBI (" pragma Import (C, Partition_Elaboration_Policy," &
" ""__gnat_partition_elaboration_policy"");");
WBI ("");
WBI (" procedure Activate_All_Tasks_Sequential;");
WBI (" pragma Import (C, Activate_All_Tasks_Sequential," &
" ""__gnat_activate_all_tasks"");");
WBI ("");
end if;
if System_BB_CPU_Primitives_Multiprocessors_Used then
WBI (" procedure Start_Slave_CPUs;");
WBI (" pragma Import (C, Start_Slave_CPUs," &
" ""__gnat_start_slave_cpus"");");
WBI ("");
end if;
if System_Secondary_Stack_Package_In_Closure then
-- System.Secondary_Stack is in the closure of the program
-- because the program uses the secondary stack or the restricted
-- run-time is unconditionally calling SS_Init. In both cases,
-- SS_Init needs to know the number of secondary stacks created by
-- the binder.
WBI (" Binder_Sec_Stacks_Count : Natural;");
WBI (" pragma Import (Ada, Binder_Sec_Stacks_Count, " &
"""__gnat_binder_ss_count"");");
WBI ("");
-- Import secondary stack pool variables if the secondary stack
-- used. They are not referenced otherwise.
if Sec_Stack_Used then
WBI (" Default_Secondary_Stack_Size : " &
"System.Parameters.Size_Type;");
WBI (" pragma Import (C, Default_Secondary_Stack_Size, " &
"""__gnat_default_ss_size"");");
WBI (" Default_Sized_SS_Pool : System.Address;");
WBI (" pragma Import (Ada, Default_Sized_SS_Pool, " &
"""__gnat_default_ss_pool"");");
WBI ("");
end if;
end if;
WBI (" begin");
if Main_Priority /= No_Main_Priority then
Set_String (" Main_Priority := ");
Set_Int (Main_Priority);
Set_Char (';');
Write_Statement_Buffer;
end if;
if Main_CPU /= No_Main_CPU then
Set_String (" Main_CPU := ");
Set_Int (Main_CPU);
Set_Char (';');
Write_Statement_Buffer;
end if;
if System_Tasking_Restricted_Stages_Used
and then Partition_Elaboration_Policy_Specified = 'S'
then
Set_String (" Partition_Elaboration_Policy := '");
Set_Char (Partition_Elaboration_Policy_Specified);
Set_String ("';");
Write_Statement_Buffer;
end if;
if Main_Priority = No_Main_Priority
and then Main_CPU = No_Main_CPU
and then not System_Tasking_Restricted_Stages_Used
then
WBI (" null;");
end if;
-- Generate the default-sized secondary stack pool if the secondary
-- stack is used by the program.
if System_Secondary_Stack_Package_In_Closure then
if Sec_Stack_Used then
-- Elaborate the body of the binder to initialize the default-
-- sized secondary stack pool.
WBI ("");
WBI (" " & Get_Ada_Main_Name & "'Elab_Body;");
-- Generate the default-sized secondary stack pool and set the
-- related secondary stack globals.
Set_String (" Default_Secondary_Stack_Size := ");
if Opt.Default_Sec_Stack_Size /= Opt.No_Stack_Size then
Set_Int (Opt.Default_Sec_Stack_Size);
else
Set_String
("System.Parameters.Runtime_Default_Sec_Stack_Size");
end if;
Set_Char (';');
Write_Statement_Buffer;
Set_String (" Binder_Sec_Stacks_Count := ");
Set_Int (Num_Sec_Stacks);
Set_Char (';');
Write_Statement_Buffer;
WBI (" Default_Sized_SS_Pool := " &
"Sec_Default_Sized_Stacks'Address;");
WBI ("");
else
-- The presence of System.Secondary_Stack in the closure of the
-- program implies the restricted run-time is unconditionally
-- calling SS_Init. Let SS_Init know that no stacks were
-- created.
WBI (" Binder_Sec_Stacks_Count := 0;");
end if;
end if;
-- Normal case (standard library not suppressed). Set all global values
-- used by the run time.
else
WBI (" Main_Priority : Integer;");
WBI (" pragma Import (C, Main_Priority, " &
"""__gl_main_priority"");");
WBI (" Time_Slice_Value : Integer;");
WBI (" pragma Import (C, Time_Slice_Value, " &
"""__gl_time_slice_val"");");
WBI (" WC_Encoding : Character;");
WBI (" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
WBI (" Locking_Policy : Character;");
WBI (" pragma Import (C, Locking_Policy, " &
"""__gl_locking_policy"");");
WBI (" Queuing_Policy : Character;");
WBI (" pragma Import (C, Queuing_Policy, " &
"""__gl_queuing_policy"");");
WBI (" Task_Dispatching_Policy : Character;");
WBI (" pragma Import (C, Task_Dispatching_Policy, " &
"""__gl_task_dispatching_policy"");");
WBI (" Priority_Specific_Dispatching : System.Address;");
WBI (" pragma Import (C, Priority_Specific_Dispatching, " &
"""__gl_priority_specific_dispatching"");");
WBI (" Num_Specific_Dispatching : Integer;");
WBI (" pragma Import (C, Num_Specific_Dispatching, " &
"""__gl_num_specific_dispatching"");");
WBI (" Main_CPU : Integer;");
WBI (" pragma Import (C, Main_CPU, " &
"""__gl_main_cpu"");");
WBI (" Interrupt_States : System.Address;");
WBI (" pragma Import (C, Interrupt_States, " &
"""__gl_interrupt_states"");");
WBI (" Num_Interrupt_States : Integer;");
WBI (" pragma Import (C, Num_Interrupt_States, " &
"""__gl_num_interrupt_states"");");
WBI (" Unreserve_All_Interrupts : Integer;");
WBI (" pragma Import (C, Unreserve_All_Interrupts, " &
"""__gl_unreserve_all_interrupts"");");
if Exception_Tracebacks or Exception_Tracebacks_Symbolic then
WBI (" Exception_Tracebacks : Integer;");
WBI (" pragma Import (C, Exception_Tracebacks, " &
"""__gl_exception_tracebacks"");");
if Exception_Tracebacks_Symbolic then
WBI (" Exception_Tracebacks_Symbolic : Integer;");
WBI (" pragma Import (C, Exception_Tracebacks_Symbolic, " &
"""__gl_exception_tracebacks_symbolic"");");
end if;
end if;
WBI (" Detect_Blocking : Integer;");
WBI (" pragma Import (C, Detect_Blocking, " &
"""__gl_detect_blocking"");");
WBI (" Default_Stack_Size : Integer;");
WBI (" pragma Import (C, Default_Stack_Size, " &
"""__gl_default_stack_size"");");
if Sec_Stack_Used then
WBI (" Default_Secondary_Stack_Size : " &
"System.Parameters.Size_Type;");
WBI (" pragma Import (C, Default_Secondary_Stack_Size, " &
"""__gnat_default_ss_size"");");
end if;
if Leap_Seconds_Support then
WBI (" Leap_Seconds_Support : Integer;");
WBI (" pragma Import (C, Leap_Seconds_Support, " &
"""__gl_leap_seconds_support"");");
end if;
WBI (" Bind_Env_Addr : System.Address;");
WBI (" pragma Import (C, Bind_Env_Addr, " &
"""__gl_bind_env_addr"");");
if XDR_Stream then
WBI (" XDR_Stream : Integer;");
WBI (" pragma Import (C, XDR_Stream, ""__gl_xdr_stream"");");
end if;
-- Import entry point for elaboration time signal handler
-- installation, and indication of if it's been called previously.
WBI ("");
WBI (" procedure Runtime_Initialize " &
"(Install_Handler : Integer);");
WBI (" pragma Import (C, Runtime_Initialize, " &
"""__gnat_runtime_initialize"");");
-- Import handlers attach procedure for sequential elaboration policy
if System_Interrupts_Used
and then Partition_Elaboration_Policy_Specified = 'S'
then
WBI (" procedure Install_Restricted_Handlers_Sequential;");
WBI (" pragma Import (C," &
"Install_Restricted_Handlers_Sequential," &
" ""__gnat_attach_all_handlers"");");
WBI ("");
end if;
-- Import task activation procedure for sequential elaboration
-- policy.
if System_Tasking_Restricted_Stages_Used
and then Partition_Elaboration_Policy_Specified = 'S'
then
WBI (" Partition_Elaboration_Policy : Character;");
WBI (" pragma Import (C, Partition_Elaboration_Policy," &
" ""__gnat_partition_elaboration_policy"");");
WBI ("");
WBI (" procedure Activate_All_Tasks_Sequential;");
WBI (" pragma Import (C, Activate_All_Tasks_Sequential," &
" ""__gnat_activate_all_tasks"");");
end if;
-- Import procedure to start slave cpus for bareboard runtime
if System_BB_CPU_Primitives_Multiprocessors_Used then
WBI (" procedure Start_Slave_CPUs;");
WBI (" pragma Import (C, Start_Slave_CPUs," &
" ""__gnat_start_slave_cpus"");");
end if;
-- For restricted run-time libraries (ZFP and Ravenscar)
-- tasks are non-terminating, so we do not want finalization.
if not Configurable_Run_Time_On_Target then
WBI ("");
WBI (" Finalize_Library_Objects : No_Param_Proc;");
WBI (" pragma Import (C, Finalize_Library_Objects, " &
"""__gnat_finalize_library_objects"");");
end if;
-- Initialize stack limit variable of the environment task if the
-- stack check method is stack limit and stack check is enabled.
if Stack_Check_Limits_On_Target
and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
then
WBI ("");
WBI (" procedure Initialize_Stack_Limit;");
WBI (" pragma Import (C, Initialize_Stack_Limit, " &
"""__gnat_initialize_stack_limit"");");
end if;
-- When dispatching domains are used then we need to signal it
-- before calling the main procedure.
if Dispatching_Domains_Used then
WBI (" procedure Freeze_Dispatching_Domains;");
WBI (" pragma Import");
WBI (" (Ada, Freeze_Dispatching_Domains, "
& """__gnat_freeze_dispatching_domains"");");
end if;
-- Secondary stack global variables
WBI (" Binder_Sec_Stacks_Count : Natural;");
WBI (" pragma Import (Ada, Binder_Sec_Stacks_Count, " &
"""__gnat_binder_ss_count"");");
WBI (" Default_Sized_SS_Pool : System.Address;");
WBI (" pragma Import (Ada, Default_Sized_SS_Pool, " &
"""__gnat_default_ss_pool"");");
WBI ("");
-- Start of processing for Adainit
WBI (" begin");
WBI (" if Is_Elaborated then");
WBI (" return;");
WBI (" end if;");
WBI (" Is_Elaborated := True;");
-- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
-- restriction No_Standard_Allocators_After_Elaboration is active.
if Cumulative_Restrictions.Set
(No_Standard_Allocators_After_Elaboration)
then
WBI (" System.Elaboration_Allocators."
& "Mark_Start_Of_Elaboration;");
end if;
-- Generate assignments to initialize globals
Set_String (" Main_Priority := ");
Set_Int (Main_Priority);
Set_Char (';');
Write_Statement_Buffer;
Set_String (" Time_Slice_Value := ");
if Task_Dispatching_Policy_Specified = 'F'
and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
then
Set_Int (0);
else
Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
end if;
Set_Char (';');
Write_Statement_Buffer;
Set_String (" WC_Encoding := '");
Set_Char (Get_WC_Encoding);
Set_String ("';");
Write_Statement_Buffer;
Set_String (" Locking_Policy := '");
Set_Char (Locking_Policy_Specified);
Set_String ("';");
Write_Statement_Buffer;
Set_String (" Queuing_Policy := '");
Set_Char (Queuing_Policy_Specified);
Set_String ("';");
Write_Statement_Buffer;
Set_String (" Task_Dispatching_Policy := '");
Set_Char (Task_Dispatching_Policy_Specified);
Set_String ("';");
Write_Statement_Buffer;
if System_Tasking_Restricted_Stages_Used
and then Partition_Elaboration_Policy_Specified = 'S'
then
Set_String (" Partition_Elaboration_Policy := '");
Set_Char (Partition_Elaboration_Policy_Specified);
Set_String ("';");
Write_Statement_Buffer;
end if;
Gen_Restrictions;
WBI (" Priority_Specific_Dispatching :=");
WBI (" Local_Priority_Specific_Dispatching'Address;");
Set_String (" Num_Specific_Dispatching := ");
Set_Int (PSD_Pragma_Settings.Last + 1);
Set_Char (';');
Write_Statement_Buffer;
Set_String (" Main_CPU := ");
Set_Int (Main_CPU);
Set_Char (';');
Write_Statement_Buffer;
WBI (" Interrupt_States := Local_Interrupt_States'Address;");
Set_String (" Num_Interrupt_States := ");
Set_Int (IS_Pragma_Settings.Last + 1);
Set_Char (';');
Write_Statement_Buffer;
Set_String (" Unreserve_All_Interrupts := ");
if Unreserve_All_Interrupts_Specified then
Set_String ("1");
else
Set_String ("0");
end if;
Set_Char (';');
Write_Statement_Buffer;
if Exception_Tracebacks or Exception_Tracebacks_Symbolic then
WBI (" Exception_Tracebacks := 1;");
if Exception_Tracebacks_Symbolic then
WBI (" Exception_Tracebacks_Symbolic := 1;");
end if;
end if;
Set_String (" Detect_Blocking := ");
if Detect_Blocking then
Set_Int (1);
else
Set_Int (0);
end if;
Set_String (";");
Write_Statement_Buffer;
Set_String (" Default_Stack_Size := ");
Set_Int (Default_Stack_Size);
Set_String (";");
Write_Statement_Buffer;
if Leap_Seconds_Support then
WBI (" Leap_Seconds_Support := 1;");
end if;
if XDR_Stream then
WBI (" XDR_Stream := 1;");
end if;
if Bind_Env_String_Built then
WBI (" Bind_Env_Addr := Bind_Env'Address;");
end if;
WBI ("");
-- Generate default-sized secondary stack pool and set secondary
-- stack globals.
if Sec_Stack_Used then
-- Elaborate the body of the binder to initialize the default-
-- sized secondary stack pool.
WBI (" " & Get_Ada_Main_Name & "'Elab_Body;");
-- Generate the default-sized secondary stack pool and set the
-- related secondary stack globals.
Set_String (" Default_Secondary_Stack_Size := ");
if Opt.Default_Sec_Stack_Size /= Opt.No_Stack_Size then
Set_Int (Opt.Default_Sec_Stack_Size);
else
Set_String ("System.Parameters.Runtime_Default_Sec_Stack_Size");
end if;
Set_Char (';');
Write_Statement_Buffer;
Set_String (" Binder_Sec_Stacks_Count := ");
Set_Int (Num_Sec_Stacks);
Set_Char (';');
Write_Statement_Buffer;
Set_String (" Default_Sized_SS_Pool := ");
if Num_Sec_Stacks > 0 then
Set_String ("Sec_Default_Sized_Stacks'Address;");
else
Set_String ("System.Null_Address;");
end if;
Write_Statement_Buffer;
WBI ("");
end if;
-- Generate call to Runtime_Initialize
WBI (" Runtime_Initialize (1);");
end if;
-- Generate call to set Initialize_Scalar values if active
if Initialize_Scalars_Used then
WBI ("");
Set_String (" System.Scalar_Values.Initialize ('");
Set_Char (Initialize_Scalars_Mode1);
Set_String ("', '");
Set_Char (Initialize_Scalars_Mode2);
Set_String ("');");
Write_Statement_Buffer;
end if;
-- Initialize stack limit variable of the environment task if the stack
-- check method is stack limit and stack check is enabled.
if Stack_Check_Limits_On_Target
and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
then
WBI ("");
WBI (" Initialize_Stack_Limit;");
end if;
-- On CodePeer, the finalization of library objects is not relevant
if CodePeer_Mode then
null;
-- If this is the main program case, attach finalize_library to the soft
-- link. Do it only when not using a restricted run time, in which case
-- tasks are non-terminating, so we do not want library-level
-- finalization.
elsif not Bind_For_Library
and then not Configurable_Run_Time_On_Target
and then not Suppress_Standard_Library_On_Target
then
WBI ("");
if Lib_Final_Built then
Set_String (" Finalize_Library_Objects := ");
Set_String ("finalize_library'access;");
else
Set_String (" Finalize_Library_Objects := null;");
end if;
Write_Statement_Buffer;
end if;
-- Generate elaboration calls
if not CodePeer_Mode then
WBI ("");
end if;
Gen_Elab_Calls (Elab_Order);
if not CodePeer_Mode then
-- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
-- restriction No_Standard_Allocators_After_Elaboration is active.
if Cumulative_Restrictions.Set
(No_Standard_Allocators_After_Elaboration)
then
WBI
(" System.Elaboration_Allocators.Mark_End_Of_Elaboration;");
end if;
-- From this point, no new dispatching domain can be created
if Dispatching_Domains_Used then
WBI (" Freeze_Dispatching_Domains;");
end if;
-- Sequential partition elaboration policy
if Partition_Elaboration_Policy_Specified = 'S' then
if System_Interrupts_Used then
WBI (" Install_Restricted_Handlers_Sequential;");
end if;
if System_Tasking_Restricted_Stages_Used then
WBI (" Activate_All_Tasks_Sequential;");
end if;
end if;
if System_BB_CPU_Primitives_Multiprocessors_Used then
WBI (" Start_Slave_CPUs;");
end if;
end if;
WBI (" end " & Ada_Init_Name.all & ";");
WBI ("");
end Gen_Adainit;
-------------------------
-- Gen_Bind_Env_String --
-------------------------
procedure Gen_Bind_Env_String is
procedure Write_Name_With_Len (Nam : Name_Id);
-- Write Nam as a string literal, prefixed with one
-- character encoding Nam's length.
-------------------------
-- Write_Name_With_Len --
-------------------------
procedure Write_Name_With_Len (Nam : Name_Id) is
begin
Get_Name_String (Nam);
Write_Str ("Character'Val (");
Write_Int (Int (Name_Len));
Write_Str (") & """);
Write_Str (Name_Buffer (1 .. Name_Len));
Write_Char ('"');
end Write_Name_With_Len;
-- Local variables
First : Boolean := True;
KN : Name_Id := No_Name;
VN : Name_Id := No_Name;
-- Start of processing for Gen_Bind_Env_String
begin
Bind_Environment.Get_First (KN, VN);
if VN = No_Name then
return;
end if;
Set_Special_Output (Write_Bind_Line'Access);
WBI (" Bind_Env : aliased constant String :=");
while VN /= No_Name loop
if First then
Write_Str (" ");
else
Write_Str (" & ");
end if;
Write_Name_With_Len (KN);
Write_Str (" & ");
Write_Name_With_Len (VN);
Write_Eol;
Bind_Environment.Get_Next (KN, VN);
First := False;
end loop;
WBI (" & ASCII.NUL;");
Cancel_Special_Output;
Bind_Env_String_Built := True;
end Gen_Bind_Env_String;
--------------------------
-- Gen_CodePeer_Wrapper --
--------------------------
procedure Gen_CodePeer_Wrapper is
Callee_Name : constant String := "Ada_Main_Program";
begin
if ALIs.Table (ALIs.First).Main_Program = Proc then
WBI (" procedure " & CodePeer_Wrapper_Name & " is ");
WBI (" begin");
WBI (" " & Callee_Name & ";");
else
WBI (" function " & CodePeer_Wrapper_Name & " return Integer is");
WBI (" begin");
WBI (" return " & Callee_Name & ";");
end if;
WBI (" end " & CodePeer_Wrapper_Name & ";");
WBI ("");
end Gen_CodePeer_Wrapper;
--------------------
-- Gen_Elab_Calls --
--------------------
procedure Gen_Elab_Calls (Elab_Order : Unit_Id_Array) is
Check_Elab_Flag : Boolean;
begin
-- Loop through elaboration order entries
for E in Elab_Order'Range loop
declare
Unum : constant Unit_Id := Elab_Order (E);
U : Unit_Record renames Units.Table (Unum);
Unum_Spec : Unit_Id;
-- This is the unit number of the spec that corresponds to
-- this entry. It is the same as Unum except when the body
-- and spec are different and we are currently processing
-- the body, in which case it is the spec (Unum + 1).
begin
if U.Utype = Is_Body then
Unum_Spec := Unum + 1;
else
Unum_Spec := Unum;
end if;
-- Nothing to do if predefined unit in no run time mode
if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
null;
-- Likewise if this is an interface to a stand alone library
elsif U.SAL_Interface then
null;
-- Case of no elaboration code
elsif U.No_Elab
-- In CodePeer mode, we special case subprogram bodies which
-- are handled in the 'else' part below, and lead to a call
-- to <subp>'Elab_Subp_Body.
and then (not CodePeer_Mode
-- Test for spec
or else U.Utype = Is_Spec
or else U.Utype = Is_Spec_Only
or else U.Unit_Kind /= 's')
then
-- In the case of a body with a separate spec, where the
-- separate spec has an elaboration entity defined, this is
-- where we increment the elaboration entity if one exists.
-- Likewise for lone specs with an elaboration entity defined
-- despite No_Elaboration_Code, e.g. when requested to preserve
-- control flow.
if (U.Utype = Is_Body or else U.Utype = Is_Spec_Only)
and then Units.Table (Unum_Spec).Set_Elab_Entity
and then not CodePeer_Mode
then
Set_String (" E");
Set_Unit_Number (Unum_Spec);
Set_String (" := E");
Set_Unit_Number (Unum_Spec);
Set_String (" + 1;");
Write_Statement_Buffer;
end if;
-- Here if elaboration code is present. If binding a library
-- or if there is a non-Ada main subprogram then we generate:
-- if uname_E = 0 then
-- uname'elab_[spec|body];
-- end if;
-- uname_E := uname_E + 1;
-- Otherwise, elaboration routines are called unconditionally:
-- uname'elab_[spec|body];
-- uname_E := uname_E + 1;
-- The uname_E increment is skipped if this is a separate spec,
-- since it will be done when we process the body.
-- In CodePeer mode, we do not generate any reference to xxx_E
-- variables, only calls to 'Elab* subprograms.
else
-- Check incompatibilities with No_Multiple_Elaboration
if not CodePeer_Mode
and then Cumulative_Restrictions.Set (No_Multiple_Elaboration)
then
-- Force_Checking_Of_Elaboration_Flags (-F) not allowed
if Force_Checking_Of_Elaboration_Flags then
Osint.Fail
("-F (force elaboration checks) switch not allowed "
& "with restriction No_Multiple_Elaboration active");
-- Interfacing of libraries not allowed
elsif Interface_Library_Unit then
Osint.Fail
("binding of interfaced libraries not allowed "
& "with restriction No_Multiple_Elaboration active");
-- Non-Ada main program not allowed
elsif not Bind_Main_Program then
Osint.Fail
("non-Ada main program not allowed "
& "with restriction No_Multiple_Elaboration active");
end if;
end if;
-- OK, see if we need to test elaboration flag
Check_Elab_Flag :=
Units.Table (Unum_Spec).Set_Elab_Entity
and then not CodePeer_Mode
and then (Force_Checking_Of_Elaboration_Flags
or Interface_Library_Unit
or not Bind_Main_Program);
if Check_Elab_Flag then
Set_String (" if E");
Set_Unit_Number (Unum_Spec);
Set_String (" = 0 then");
Write_Statement_Buffer;
Set_String (" ");
end if;
Set_String (" ");
Get_Decoded_Name_String_With_Brackets (U.Uname);
if Name_Buffer (Name_Len) = 's' then
Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
"'elab_spec";
Name_Len := Name_Len + 8;
-- Special case in CodePeer mode for subprogram bodies
-- which correspond to CodePeer 'Elab_Subp_Body special
-- init procedure.
elsif U.Unit_Kind = 's' and CodePeer_Mode then
Name_Buffer (Name_Len - 1 .. Name_Len + 13) :=
"'elab_subp_body";
Name_Len := Name_Len + 13;
else
Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
"'elab_body";
Name_Len := Name_Len + 8;
end if;
Set_Casing (U.Icasing);
Set_Name_Buffer;
Set_Char (';');
Write_Statement_Buffer;
if Check_Elab_Flag then
WBI (" end if;");
end if;
if U.Utype /= Is_Spec
and then not CodePeer_Mode
and then Units.Table (Unum_Spec).Set_Elab_Entity
then
Set_String (" E");
Set_Unit_Number (Unum_Spec);
Set_String (" := E");
Set_Unit_Number (Unum_Spec);
Set_String (" + 1;");
Write_Statement_Buffer;
end if;
end if;
end;
end loop;
end Gen_Elab_Calls;
------------------------
-- Gen_Elab_Externals --
------------------------
procedure Gen_Elab_Externals (Elab_Order : Unit_Id_Array) is
begin
if CodePeer_Mode then
return;
end if;
for E in Elab_Order'Range loop
declare
Unum : constant Unit_Id := Elab_Order (E);
U : Unit_Record renames Units.Table (Unum);
begin
-- Check for Elab_Entity to be set for this unit
if U.Set_Elab_Entity
-- Don't generate reference for stand alone library
and then not U.SAL_Interface
-- Don't generate reference for predefined file in No_Run_Time
-- mode, since we don't include the object files in this case
and then not
(No_Run_Time_Mode
and then Is_Predefined_File_Name (U.Sfile))
then
Get_Name_String (U.Sfile);
Set_String (" ");
Set_String ("E");
Set_Unit_Number (Unum);
Set_String (" : Short_Integer; pragma Import (Ada, E");
Set_Unit_Number (Unum);
Set_String (", """);
Get_Name_String (U.Uname);
Set_Unit_Name;
Set_String ("_E"");");
Write_Statement_Buffer;
end if;
end;
end loop;
WBI ("");
end Gen_Elab_Externals;
--------------------
-- Gen_Elab_Order --
--------------------
procedure Gen_Elab_Order (Elab_Order : Unit_Id_Array) is
begin
WBI ("");
WBI (" -- BEGIN ELABORATION ORDER");
for J in Elab_Order'Range loop
Set_String (" -- ");
Get_Name_String (Units.Table (Elab_Order (J)).Uname);
Set_Name_Buffer;
Write_Statement_Buffer;
end loop;
WBI (" -- END ELABORATION ORDER");
end Gen_Elab_Order;
--------------------------
-- Gen_Finalize_Library --
--------------------------
procedure Gen_Finalize_Library (Elab_Order : Unit_Id_Array) is
procedure Gen_Header;
-- Generate the header of the finalization routine
----------------
-- Gen_Header --
----------------
procedure Gen_Header is
begin
WBI (" procedure finalize_library is");
WBI (" begin");
end Gen_Header;
-- Local variables
Count : Int := 1;
U : Unit_Record;
Uspec : Unit_Record;
Unum : Unit_Id;
-- Start of processing for Gen_Finalize_Library
begin
if CodePeer_Mode then
return;
end if;
for E in reverse Elab_Order'Range loop
Unum := Elab_Order (E);
U := Units.Table (Unum);
-- Dealing with package bodies is a little complicated. In such
-- cases we must retrieve the package spec since it contains the
-- spec of the body finalizer.
if U.Utype = Is_Body then
Unum := Unum + 1;
Uspec := Units.Table (Unum);
else
Uspec := U;
end if;
Get_Name_String (Uspec.Uname);
-- We are only interested in non-generic packages
if U.Unit_Kind /= 'p' or else U.Is_Generic then
null;
-- That aren't an interface to a stand alone library
elsif U.SAL_Interface then
null;
-- Case of no finalization
elsif not U.Has_Finalizer then
-- The only case in which we have to do something is if this
-- is a body, with a separate spec, where the separate spec
-- has a finalizer. In that case, this is where we decrement
-- the elaboration entity.
if U.Utype = Is_Body and then Uspec.Has_Finalizer then
if not Lib_Final_Built then
Gen_Header;
Lib_Final_Built := True;
end if;
Set_String (" E");
Set_Unit_Number (Unum);
Set_String (" := E");
Set_Unit_Number (Unum);
Set_String (" - 1;");
Write_Statement_Buffer;
end if;
else
if not Lib_Final_Built then
Gen_Header;
Lib_Final_Built := True;
end if;
-- Generate:
-- declare
-- procedure F<Count>;
Set_String (" declare");
Write_Statement_Buffer;
Set_String (" procedure F");
Set_Int (Count);
Set_Char (';');
Write_Statement_Buffer;
-- Generate:
-- pragma Import (Ada, F<Count>,
-- "xx__yy__finalize_[body|spec]");
Set_String (" pragma Import (Ada, F");
Set_Int (Count);
Set_String (", """);
-- Perform name construction
Set_Unit_Name;
Set_String ("__finalize_");
-- Package spec processing
if U.Utype = Is_Spec
or else U.Utype = Is_Spec_Only
then
Set_String ("spec");
-- Package body processing
else
Set_String ("body");
end if;
Set_String (""");");
Write_Statement_Buffer;
-- If binding a library or if there is a non-Ada main subprogram
-- then we generate:
-- begin
-- uname_E := uname_E - 1;
-- if uname_E = 0 then
-- F<Count>;
-- end if;
-- end;
-- Otherwise, finalization routines are called unconditionally:
-- begin
-- uname_E := uname_E - 1;
-- F<Count>;
-- end;
-- The uname_E decrement is skipped if this is a separate spec,
-- since it will be done when we process the body.
WBI (" begin");
if U.Utype /= Is_Spec then
Set_String (" E");
Set_Unit_Number (Unum);
Set_String (" := E");
Set_Unit_Number (Unum);
Set_String (" - 1;");
Write_Statement_Buffer;
end if;
if Interface_Library_Unit or not Bind_Main_Program then
Set_String (" if E");
Set_Unit_Number (Unum);
Set_String (" = 0 then");
Write_Statement_Buffer;
Set_String (" ");
end if;
Set_String (" F");
Set_Int (Count);
Set_Char (';');
Write_Statement_Buffer;
if Interface_Library_Unit or not Bind_Main_Program then
WBI (" end if;");
end if;
WBI (" end;");
Count := Count + 1;
end if;
end loop;
if Lib_Final_Built then
-- It is possible that the finalization of a library-level object
-- raised an exception. In that case import the actual exception
-- and the routine necessary to raise it.
WBI (" declare");
WBI (" procedure Reraise_Library_Exception_If_Any;");
Set_String (" pragma Import (Ada, ");
Set_String ("Reraise_Library_Exception_If_Any, ");
Set_String ("""__gnat_reraise_library_exception_if_any"");");
Write_Statement_Buffer;
WBI (" begin");
WBI (" Reraise_Library_Exception_If_Any;");
WBI (" end;");
WBI (" end finalize_library;");
WBI ("");
end if;
end Gen_Finalize_Library;
--------------
-- Gen_Main --
--------------
procedure Gen_Main is
begin
if not No_Main_Subprogram then
-- To call the main program, we declare it using a pragma Import
-- Ada with the right link name.
-- It might seem more obvious to "with" the main program, and call
-- it in the normal Ada manner. We do not do this for three
-- reasons:
-- 1. It is more efficient not to recompile the main program
-- 2. We are not entitled to assume the source is accessible
-- 3. We don't know what options to use to compile it
-- It is really reason 3 that is most critical (indeed we used
-- to generate the "with", but several regression tests failed).
if ALIs.Table (ALIs.First).Main_Program = Func then
WBI (" function Ada_Main_Program return Integer;");
else
WBI (" procedure Ada_Main_Program;");
end if;
Set_String (" pragma Import (Ada, Ada_Main_Program, """);
Get_Name_String (Units.Table (First_Unit_Entry).Uname);
Set_Main_Program_Name;
Set_String (""");");
Write_Statement_Buffer;
WBI ("");
-- For CodePeer, declare a wrapper for the user-defined main program
if CodePeer_Mode then
Gen_CodePeer_Wrapper;
end if;
end if;
if Exit_Status_Supported_On_Target then
Set_String (" function ");
else
Set_String (" procedure ");
end if;
Set_String (Get_Main_Name);
if Command_Line_Args_On_Target then
Write_Statement_Buffer;
WBI (" (argc : Integer;");
WBI (" argv : System.Address;");
WBI (" envp : System.Address)");
if Exit_Status_Supported_On_Target then
WBI (" return Integer");
end if;
WBI (" is");
else
if Exit_Status_Supported_On_Target then
Set_String (" return Integer is");
else
Set_String (" is");
end if;
Write_Statement_Buffer;
end if;
if Opt.Default_Exit_Status /= 0
and then Bind_Main_Program
and then not Configurable_Run_Time_Mode
then
WBI (" procedure Set_Exit_Status (Status : Integer);");
WBI (" pragma Import (C, Set_Exit_Status, " &
"""__gnat_set_exit_status"");");
WBI ("");
end if;
-- Initialize and Finalize
if not CodePeer_Mode
and then not Cumulative_Restrictions.Set (No_Finalization)
then
WBI (" procedure Initialize (Addr : System.Address);");
WBI (" pragma Import (C, Initialize, ""__gnat_initialize"");");
WBI ("");
WBI (" procedure Finalize;");
WBI (" pragma Import (C, Finalize, ""__gnat_finalize"");");
end if;
-- If we want to analyze the stack, we must import corresponding symbols
if Dynamic_Stack_Measurement then
WBI ("");
WBI (" procedure Output_Results;");
WBI (" pragma Import (C, Output_Results, " &
"""__gnat_stack_usage_output_results"");");
WBI ("");
WBI (" " &
"procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
WBI (" pragma Import (C, Initialize_Stack_Analysis, " &
"""__gnat_stack_usage_initialize"");");
end if;
-- Deal with declarations for main program case
if not No_Main_Subprogram then
if ALIs.Table (ALIs.First).Main_Program = Func then
WBI (" Result : Integer;");
WBI ("");
end if;
if Bind_Main_Program
and not Suppress_Standard_Library_On_Target
and not CodePeer_Mode
then
WBI (" SEH : aliased array (1 .. 2) of Integer;");
WBI ("");
end if;
end if;
-- Generate a reference to Ada_Main_Program_Name. This symbol is not
-- referenced elsewhere in the generated program, but is needed by
-- the debugger (that's why it is generated in the first place). The
-- reference stops Ada_Main_Program_Name from being optimized away by
-- smart linkers.
-- Because this variable is unused, we make this variable "aliased"
-- with a pragma Volatile in order to tell the compiler to preserve
-- this variable at any level of optimization.
-- CodePeer and CCG do not need this extra code. The code is also not
-- needed if the binder is in "Minimal Binder" mode.
if Bind_Main_Program
and then not Minimal_Binder
and then not CodePeer_Mode
and then not Generate_C_Code
then
WBI (" Ensure_Reference : aliased System.Address := " &
"Ada_Main_Program_Name'Address;");
WBI (" pragma Volatile (Ensure_Reference);");
WBI ("");
end if;
WBI (" begin");
-- Acquire command-line arguments if present on target
if CodePeer_Mode then
null;
elsif Command_Line_Args_On_Target then
-- Initialize gnat_argc/gnat_argv only if not already initialized,
-- to avoid losing the result of any command-line processing done by
-- earlier GNAT run-time initialization.
WBI (" if gnat_argc = 0 then");
WBI (" gnat_argc := argc;");
WBI (" gnat_argv := argv;");
WBI (" end if;");
WBI (" gnat_envp := envp;");
WBI ("");
-- If configurable run-time and no command-line args, then nothing needs
-- to be done since the gnat_argc/argv/envp variables are suppressed in
-- this case.
elsif Configurable_Run_Time_On_Target then
null;
-- Otherwise set dummy values (to be filled in by some other unit?)
else
WBI (" gnat_argc := 0;");
WBI (" gnat_argv := System.Null_Address;");
WBI (" gnat_envp := System.Null_Address;");
end if;
if Opt.Default_Exit_Status /= 0
and then Bind_Main_Program
and then not Configurable_Run_Time_Mode
then
Set_String (" Set_Exit_Status (");
Set_Int (Opt.Default_Exit_Status);
Set_String (");");
Write_Statement_Buffer;
end if;
if Dynamic_Stack_Measurement then
Set_String (" Initialize_Stack_Analysis (");
Set_Int (Dynamic_Stack_Measurement_Array_Size);
Set_String (");");
Write_Statement_Buffer;
end if;
if not Cumulative_Restrictions.Set (No_Finalization)
and then not CodePeer_Mode
then
if not No_Main_Subprogram
and then Bind_Main_Program
and then not Suppress_Standard_Library_On_Target
then
WBI (" Initialize (SEH'Address);");
else
WBI (" Initialize (System.Null_Address);");
end if;
end if;
WBI (" " & Ada_Init_Name.all & ";");
if not No_Main_Subprogram then
if CodePeer_Mode then
if ALIs.Table (ALIs.First).Main_Program = Proc then
WBI (" " & CodePeer_Wrapper_Name & ";");
else
WBI (" Result := " & CodePeer_Wrapper_Name & ";");
end if;
elsif ALIs.Table (ALIs.First).Main_Program = Proc then
WBI (" Ada_Main_Program;");
else
WBI (" Result := Ada_Main_Program;");
end if;
end if;
-- Adafinal call is skipped if no finalization
if not Cumulative_Restrictions.Set (No_Finalization) then
WBI (" adafinal;");
end if;
-- Prints the result of static stack analysis
if Dynamic_Stack_Measurement then
WBI (" Output_Results;");
end if;
-- Finalize is only called if we have a run time
if not Cumulative_Restrictions.Set (No_Finalization)
and then not CodePeer_Mode
then
WBI (" Finalize;");
end if;
-- Return result
if Exit_Status_Supported_On_Target then
if No_Main_Subprogram
or else ALIs.Table (ALIs.First).Main_Program = Proc
then
WBI (" return (gnat_exit_status);");
else
WBI (" return (Result);");
end if;
end if;
WBI (" end;");
WBI ("");
end Gen_Main;
------------------------------
-- Gen_Object_Files_Options --
------------------------------
procedure Gen_Object_Files_Options (Elab_Order : Unit_Id_Array) is
Lgnat : Natural;
-- This keeps track of the position in the sorted set of entries in the
-- Linker_Options table of where the first entry from an internal file
-- appears.
Linker_Option_List_Started : Boolean := False;
-- Set to True when "LINKER OPTION LIST" is displayed
procedure Write_Linker_Option;
-- Write binder info linker option
-------------------------
-- Write_Linker_Option --
-------------------------
procedure Write_Linker_Option is
Start : Natural;
Stop : Natural;
begin
-- Loop through string, breaking at null's
Start := 1;
while Start < Name_Len loop
-- Find null ending this section
Stop := Start + 1;
while Name_Buffer (Stop) /= ASCII.NUL
and then Stop <= Name_Len loop
Stop := Stop + 1;
end loop;
-- Process section if non-null
if Stop > Start then
if Output_Linker_Option_List then
if not Zero_Formatting then
if not Linker_Option_List_Started then
Linker_Option_List_Started := True;
Write_Eol;
Write_Str (" LINKER OPTION LIST");
Write_Eol;
Write_Eol;
end if;
Write_Str (" ");
end if;
Write_Str (Name_Buffer (Start .. Stop - 1));
Write_Eol;
end if;
WBI (" -- " & Name_Buffer (Start .. Stop - 1));
end if;
Start := Stop + 1;
end loop;
end Write_Linker_Option;
-- Start of processing for Gen_Object_Files_Options
begin
WBI ("-- BEGIN Object file/option list");
if Object_List_Filename /= null then
Set_List_File (Object_List_Filename.all);
end if;
for E in Elab_Order'Range loop
-- If not spec that has an associated body, then generate a comment
-- giving the name of the corresponding object file.
if not Units.Table (Elab_Order (E)).SAL_Interface
and then Units.Table (Elab_Order (E)).Utype /= Is_Spec
then
Get_Name_String
(ALIs.Table
(Units.Table (Elab_Order (E)).My_ALI).Ofile_Full_Name);
-- If the presence of an object file is necessary or if it exists,
-- then use it.
if not Hostparm.Exclude_Missing_Objects
or else
System.OS_Lib.Is_Regular_File (Name_Buffer (1 .. Name_Len))
then
WBI (" -- " & Name_Buffer (1 .. Name_Len));
if Output_Object_List then
Write_Str (Name_Buffer (1 .. Name_Len));
Write_Eol;
end if;
end if;
end if;
end loop;
if Object_List_Filename /= null then
Close_List_File;
end if;
-- Add a "-Ldir" for each directory in the object path
for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
declare
Dir : constant String_Ptr := Dir_In_Obj_Search_Path (J);
begin
Name_Len := 0;
Add_Str_To_Name_Buffer ("-L");
Add_Str_To_Name_Buffer (Dir.all);
Write_Linker_Option;
end;
end loop;
if not (Opt.No_Run_Time_Mode or Opt.No_Stdlib) then
Name_Len := 0;
if Opt.Shared_Libgnat then
Add_Str_To_Name_Buffer ("-shared");
else
Add_Str_To_Name_Buffer ("-static");
end if;
-- Write directly to avoid inclusion in -K output as -static and
-- -shared are not usually specified linker options.
WBI (" -- " & Name_Buffer (1 .. Name_Len));
end if;
-- Sort linker options
-- This sort accomplishes two important purposes:
-- a) All application files are sorted to the front, and all GNAT
-- internal files are sorted to the end. This results in a well
-- defined dividing line between the two sets of files, for the
-- purpose of inserting certain standard library references into
-- the linker arguments list.
-- b) Given two different units, we sort the linker options so that
-- those from a unit earlier in the elaboration order comes later
-- in the list. This is a heuristic designed to create a more
-- friendly order of linker options when the operations appear in
-- separate units. The idea is that if unit A must be elaborated
-- before unit B, then it is more likely that B references
-- libraries included by A, than vice versa, so we want libraries
-- included by A to come after libraries included by B.
-- These two criteria are implemented by function Lt_Linker_Option. Note
-- that a special case of b) is that specs are elaborated before bodies,
-- so linker options from specs come after linker options for bodies,
-- and again, the assumption is that libraries used by the body are more
-- likely to reference libraries used by the spec, than vice versa.
Sort
(Linker_Options.Last,
Move_Linker_Option'Access,
Lt_Linker_Option'Access);
-- Write user linker options, i.e. the set of linker options that come
-- from all files other than GNAT internal files, Lgnat is left set to
-- point to the first entry from a GNAT internal file, or past the end
-- of the entries if there are no internal files.
Lgnat := Linker_Options.Last + 1;
for J in 1 .. Linker_Options.Last loop
if not Linker_Options.Table (J).Internal_File then
Get_Name_String (Linker_Options.Table (J).Name);
Write_Linker_Option;
else
Lgnat := J;
exit;
end if;
end loop;
-- Now we insert standard linker options that must appear after the
-- entries from user files, and before the entries from GNAT run-time
-- files. The reason for this decision is that libraries referenced
-- by internal routines may reference these standard library entries.
-- Note that we do not insert anything when pragma No_Run_Time has
-- been specified or when the standard libraries are not to be used,
-- otherwise on some platforms, we may get duplicate symbols when
-- linking (not clear if this is still the case, but it is harmless).
if not (Opt.No_Run_Time_Mode or else Opt.No_Stdlib) then
if With_GNARL then
Name_Len := 0;
if Opt.Shared_Libgnat then
Add_Str_To_Name_Buffer (Shared_Lib ("gnarl"));
else
Add_Str_To_Name_Buffer ("-lgnarl");
end if;
Write_Linker_Option;
end if;
Name_Len := 0;
if Opt.Shared_Libgnat then
Add_Str_To_Name_Buffer (Shared_Lib ("gnat"));
else
Add_Str_To_Name_Buffer ("-lgnat");
end if;
Write_Linker_Option;
end if;
-- Write linker options from all internal files
for J in Lgnat .. Linker_Options.Last loop
Get_Name_String (Linker_Options.Table (J).Name);
Write_Linker_Option;
end loop;
if Output_Linker_Option_List and then not Zero_Formatting then
Write_Eol;
end if;
WBI ("-- END Object file/option list ");
end Gen_Object_Files_Options;
---------------------
-- Gen_Output_File --
---------------------
procedure Gen_Output_File
(Filename : String;
Elab_Order : Unit_Id_Array)
is
begin
-- Acquire settings for Interrupt_State pragmas
Set_IS_Pragma_Table;
-- Acquire settings for Priority_Specific_Dispatching pragma
Set_PSD_Pragma_Table;
-- Override time slice value if -T switch is set
if Time_Slice_Set then
ALIs.Table (ALIs.First).Time_Slice_Value := Opt.Time_Slice_Value;
end if;
-- Count number of elaboration calls
for E in Elab_Order'Range loop
if Units.Table (Elab_Order (E)).No_Elab then
null;
else
Num_Elab_Calls := Num_Elab_Calls + 1;
end if;
end loop;
-- Count the number of statically allocated stacks to be generated by
-- the binder. If the user has specified the number of default-sized
-- secondary stacks, use that number. Otherwise start the count at one
-- as the binder is responsible for creating a secondary stack for the
-- main task.
if Opt.Quantity_Of_Default_Size_Sec_Stacks /= -1 then
Num_Sec_Stacks := Quantity_Of_Default_Size_Sec_Stacks;
elsif Sec_Stack_Used then
Num_Sec_Stacks := 1;
end if;
for J in Units.First .. Units.Last loop
Num_Primary_Stacks :=
Num_Primary_Stacks + Units.Table (J).Primary_Stack_Count;
Num_Sec_Stacks :=
Num_Sec_Stacks + Units.Table (J).Sec_Stack_Count;
end loop;
-- Generate output file in appropriate language
Gen_Output_File_Ada (Filename, Elab_Order);
end Gen_Output_File;
-------------------------
-- Gen_Output_File_Ada --
-------------------------
procedure Gen_Output_File_Ada
(Filename : String; Elab_Order : Unit_Id_Array)
is
Ada_Main : constant String := Get_Ada_Main_Name;
-- Name to be used for generated Ada main program. See the body of
-- function Get_Ada_Main_Name for details on the form of the name.
Needs_Library_Finalization : constant Boolean :=
not Configurable_Run_Time_On_Target
and then Has_Finalizer (Elab_Order);
-- For restricted run-time libraries (ZFP and Ravenscar) tasks are
-- non-terminating, so we do not want finalization.
Bfiles : Name_Id;
-- Name of generated bind file (spec)
Bfileb : Name_Id;
-- Name of generated bind file (body)
begin
-- Create spec first
Create_Binder_Output (Filename, 's', Bfiles);
-- We always compile the binder file in Ada 95 mode so that we properly
-- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
-- of the Ada 2005 or Ada 2012 constructs are needed by the binder file.
WBI ("pragma Warnings (Off);");
WBI ("pragma Ada_95;");
-- If we are operating in Restrictions (No_Exception_Handlers) mode,
-- then we need to make sure that the binder program is compiled with
-- the same restriction, so that no exception tables are generated.
if Cumulative_Restrictions.Set (No_Exception_Handlers) then
WBI ("pragma Restrictions (No_Exception_Handlers);");
end if;
-- Same processing for Restrictions (No_Exception_Propagation)
if Cumulative_Restrictions.Set (No_Exception_Propagation) then
WBI ("pragma Restrictions (No_Exception_Propagation);");
end if;
-- Same processing for pragma No_Run_Time
if No_Run_Time_Mode then
WBI ("pragma No_Run_Time;");
end if;
-- Generate with of System so we can reference System.Address
WBI ("with System;");
-- Generate with of System.Initialize_Scalars if active
if Initialize_Scalars_Used then
WBI ("with System.Scalar_Values;");
end if;
-- Generate withs of System.Secondary_Stack and System.Parameters to
-- allow the generation of the default-sized secondary stack pool.
if Sec_Stack_Used then
WBI ("with System.Parameters;");
WBI ("with System.Secondary_Stack;");
end if;
Resolve_Binder_Options (Elab_Order);
-- Generate standard with's
if not Suppress_Standard_Library_On_Target then
if CodePeer_Mode then
WBI ("with System.Standard_Library;");
end if;
end if;
WBI ("package " & Ada_Main & " is");
-- Main program case
if Bind_Main_Program then
-- Generate argc/argv stuff unless suppressed
if Command_Line_Args_On_Target
or not Configurable_Run_Time_On_Target
then
WBI ("");
WBI (" gnat_argc : Integer;");
WBI (" gnat_argv : System.Address;");
WBI (" gnat_envp : System.Address;");
-- If the standard library is not suppressed, these variables
-- are in the run-time data area for easy run time access.
if not Suppress_Standard_Library_On_Target then
WBI ("");
WBI (" pragma Import (C, gnat_argc);");
WBI (" pragma Import (C, gnat_argv);");
WBI (" pragma Import (C, gnat_envp);");
end if;
end if;
-- Define exit status. Again in normal mode, this is in the run-time
-- library, and is initialized there, but in the configurable
-- run-time case, the variable is declared and initialized in this
-- file.
WBI ("");
if Configurable_Run_Time_Mode then
if Exit_Status_Supported_On_Target then
WBI (" gnat_exit_status : Integer := 0;");
end if;
else
WBI (" gnat_exit_status : Integer;");
WBI (" pragma Import (C, gnat_exit_status);");
end if;
-- Generate the GNAT_Version and Ada_Main_Program_Name info only for
-- the main program. Otherwise, it can lead under some circumstances
-- to a symbol duplication during the link (for instance when a C
-- program uses two Ada libraries). Also zero terminate the string
-- so that its end can be found reliably at run time.
if not Minimal_Binder then
WBI ("");
WBI (" GNAT_Version : constant String :=");
WBI (" """ & Ver_Prefix &
Gnat_Version_String &
""" & ASCII.NUL;");
WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");");
WBI ("");
Set_String (" Ada_Main_Program_Name : constant String := """);
Get_Name_String (Units.Table (First_Unit_Entry).Uname);
Set_Main_Program_Name;
Set_String (""" & ASCII.NUL;");
Write_Statement_Buffer;
WBI
(" pragma Export (C, Ada_Main_Program_Name, " &
"""__gnat_ada_main_program_name"");");
end if;
end if;
WBI ("");
WBI (" procedure " & Ada_Init_Name.all & ";");
WBI (" pragma Export (C, " & Ada_Init_Name.all & ", """ &
Ada_Init_Name.all & """);");
-- If -a has been specified use pragma Linker_Constructor for the init
-- procedure and pragma Linker_Destructor for the final procedure.
if Use_Pragma_Linker_Constructor then
WBI (" pragma Linker_Constructor (" & Ada_Init_Name.all & ");");
end if;
if not Cumulative_Restrictions.Set (No_Finalization) then
WBI ("");
WBI (" procedure " & Ada_Final_Name.all & ";");
WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ &
Ada_Final_Name.all & """);");
if Use_Pragma_Linker_Constructor then
WBI (" pragma Linker_Destructor (" & Ada_Final_Name.all & ");");
end if;
end if;
if Bind_Main_Program then
WBI ("");
if Exit_Status_Supported_On_Target then
Set_String (" function ");
else
Set_String (" procedure ");
end if;
Set_String (Get_Main_Name);
-- Generate argument list if present
if Command_Line_Args_On_Target then
Write_Statement_Buffer;
WBI (" (argc : Integer;");
WBI (" argv : System.Address;");
Set_String
(" envp : System.Address)");
if Exit_Status_Supported_On_Target then
Write_Statement_Buffer;
WBI (" return Integer;");
else
Write_Statement_Buffer (";");
end if;
else
if Exit_Status_Supported_On_Target then
Write_Statement_Buffer (" return Integer;");
else
Write_Statement_Buffer (";");
end if;
end if;
WBI (" pragma Export (C, " & Get_Main_Name & ", """ &
Get_Main_Name & """);");
end if;
-- Generate version numbers for units, only if needed. Be very safe on
-- the condition.
if not Configurable_Run_Time_On_Target
or else System_Version_Control_Used
or else not Bind_Main_Program
then
Gen_Versions;
end if;
Gen_Elab_Order (Elab_Order);
-- Spec is complete
WBI ("");
WBI ("end " & Ada_Main & ";");
Close_Binder_Output;
-- Prepare to write body
Create_Binder_Output (Filename, 'b', Bfileb);
-- We always compile the binder file in Ada 95 mode so that we properly
-- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
-- of the Ada 2005/2012 constructs are needed by the binder file.
WBI ("pragma Warnings (Off);");
WBI ("pragma Ada_95;");
-- Output Source_File_Name pragmas which look like
-- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
-- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
-- where sss/bbb are the spec/body file names respectively
Get_Name_String (Bfiles);
Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
WBI ("pragma Source_File_Name (" &
Ada_Main &
", Spec_File_Name => """ &
Name_Buffer (1 .. Name_Len + 3));
Get_Name_String (Bfileb);
Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
WBI ("pragma Source_File_Name (" &
Ada_Main &
", Body_File_Name => """ &
Name_Buffer (1 .. Name_Len + 3));
-- Generate pragma Suppress (Overflow_Check). This is needed for recent
-- versions of the compiler which have overflow checks on by default.
-- We do not want overflow checking enabled for the increments of the
-- elaboration variables (since this can cause an unwanted reference to
-- the last chance exception handler for limited run-times).
WBI ("pragma Suppress (Overflow_Check);");
-- Generate with of System.Restrictions to initialize
-- Run_Time_Restrictions.
if System_Restrictions_Used
and not Suppress_Standard_Library_On_Target
then
WBI ("");
WBI ("with System.Restrictions;");
end if;
-- Generate with of Ada.Exceptions if needs library finalization
if Needs_Library_Finalization then
WBI ("with Ada.Exceptions;");
end if;
-- Generate with of System.Elaboration_Allocators if the restriction
-- No_Standard_Allocators_After_Elaboration was present.
if Cumulative_Restrictions.Set
(No_Standard_Allocators_After_Elaboration)
then
WBI ("with System.Elaboration_Allocators;");
end if;
-- Generate start of package body
WBI ("");
WBI ("package body " & Ada_Main & " is");
WBI ("");
-- Generate externals for elaboration entities
Gen_Elab_Externals (Elab_Order);
-- Generate default-sized secondary stacks pool. At least one stack is
-- created and assigned to the environment task if secondary stacks are
-- used by the program.
if Sec_Stack_Used then
Set_String (" Sec_Default_Sized_Stacks");
Set_String (" : array (1 .. ");
Set_Int (Num_Sec_Stacks);
Set_String (") of aliased System.Secondary_Stack.SS_Stack (");
if Opt.Default_Sec_Stack_Size /= No_Stack_Size then
Set_Int (Opt.Default_Sec_Stack_Size);
else
Set_String ("System.Parameters.Runtime_Default_Sec_Stack_Size");
end if;
Set_String (");");
Write_Statement_Buffer;
WBI ("");
end if;
-- Generate reference
if not CodePeer_Mode then
if not Suppress_Standard_Library_On_Target then
-- Generate Priority_Specific_Dispatching pragma string
Set_String
(" Local_Priority_Specific_Dispatching : " &
"constant String := """);
for J in 0 .. PSD_Pragma_Settings.Last loop
Set_Char (PSD_Pragma_Settings.Table (J));
end loop;
Set_String (""";");
Write_Statement_Buffer;
-- Generate Interrupt_State pragma string
Set_String (" Local_Interrupt_States : constant String := """);
for J in 0 .. IS_Pragma_Settings.Last loop
Set_Char (IS_Pragma_Settings.Table (J));
end loop;
Set_String (""";");
Write_Statement_Buffer;
WBI ("");
end if;
if not Suppress_Standard_Library_On_Target then
-- The B.1(39) implementation advice says that the adainit and
-- adafinal routines should be idempotent. Generate a flag to
-- ensure that. This is not needed if we are suppressing the
-- standard library since it would never be referenced.
WBI (" Is_Elaborated : Boolean := False;");
-- Generate bind environment string
Gen_Bind_Env_String;
end if;
WBI ("");
end if;
-- Generate the adafinal routine unless there is no finalization to do
if not Cumulative_Restrictions.Set (No_Finalization) then
if Needs_Library_Finalization then
Gen_Finalize_Library (Elab_Order);
end if;
Gen_Adafinal;
end if;
Gen_Adainit (Elab_Order);
if Bind_Main_Program then
Gen_Main;
end if;
-- Output object file list and the Ada body is complete
Gen_Object_Files_Options (Elab_Order);
WBI ("");
WBI ("end " & Ada_Main & ";");
Close_Binder_Output;
end Gen_Output_File_Ada;
----------------------
-- Gen_Restrictions --
----------------------
procedure Gen_Restrictions is
Count : Integer;
begin
if Suppress_Standard_Library_On_Target
or not System_Restrictions_Used
then
return;
end if;
WBI (" System.Restrictions.Run_Time_Restrictions :=");
WBI (" (Set =>");
Set_String (" (");
Count := 0;
for J in Cumulative_Restrictions.Set'Range loop
Set_Boolean (Cumulative_Restrictions.Set (J));
Set_String (", ");
Count := Count + 1;
if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
Write_Statement_Buffer;
Set_String (" ");
Count := 0;
end if;
end loop;
Set_String_Replace ("),");
Write_Statement_Buffer;
Set_String (" Value => (");
for J in Cumulative_Restrictions.Value'Range loop
Set_Int (Int (Cumulative_Restrictions.Value (J)));
Set_String (", ");
end loop;
Set_String_Replace ("),");
Write_Statement_Buffer;
WBI (" Violated =>");
Set_String (" (");
Count := 0;
for J in Cumulative_Restrictions.Violated'Range loop
Set_Boolean (Cumulative_Restrictions.Violated (J));
Set_String (", ");
Count := Count + 1;
if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
Write_Statement_Buffer;
Set_String (" ");
Count := 0;
end if;
end loop;
Set_String_Replace ("),");
Write_Statement_Buffer;
Set_String (" Count => (");
for J in Cumulative_Restrictions.Count'Range loop
Set_Int (Int (Cumulative_Restrictions.Count (J)));
Set_String (", ");
end loop;
Set_String_Replace ("),");
Write_Statement_Buffer;
Set_String (" Unknown => (");
for J in Cumulative_Restrictions.Unknown'Range loop
Set_Boolean (Cumulative_Restrictions.Unknown (J));
Set_String (", ");
end loop;
Set_String_Replace ("))");
Set_String (";");
Write_Statement_Buffer;
end Gen_Restrictions;
------------------
-- Gen_Versions --
------------------
-- This routine generates lines such as:
-- unnnnn : constant Integer := 16#hhhhhhhh#;
-- pragma Export (C, unnnnn, unam);
-- for each unit, where unam is the unit name suffixed by either B or S for
-- body or spec, with dots replaced by double underscores, and hhhhhhhh is
-- the version number, and nnnnn is a 5-digits serial number.
procedure Gen_Versions is
Ubuf : String (1 .. 6) := "u00000";
procedure Increment_Ubuf;
-- Little procedure to increment the serial number
--------------------
-- Increment_Ubuf --
--------------------
procedure Increment_Ubuf is
begin
for J in reverse Ubuf'Range loop
Ubuf (J) := Character'Succ (Ubuf (J));
exit when Ubuf (J) <= '9';
Ubuf (J) := '0';
end loop;
end Increment_Ubuf;
-- Start of processing for Gen_Versions
begin
WBI ("");
WBI (" type Version_32 is mod 2 ** 32;");
for U in Units.First .. Units.Last loop
if not Units.Table (U).SAL_Interface
and then (not Bind_For_Library
or else Units.Table (U).Directly_Scanned)
then
Increment_Ubuf;
WBI (" " & Ubuf & " : constant Version_32 := 16#" &
Units.Table (U).Version & "#;");
Set_String (" pragma Export (C, ");
Set_String (Ubuf);
Set_String (", """);
Get_Name_String (Units.Table (U).Uname);
for K in 1 .. Name_Len loop
if Name_Buffer (K) = '.' then
Set_Char ('_');
Set_Char ('_');
elsif Name_Buffer (K) = '%' then
exit;
else
Set_Char (Name_Buffer (K));
end if;
end loop;
if Name_Buffer (Name_Len) = 's' then
Set_Char ('S');
else
Set_Char ('B');
end if;
Set_String (""");");
Write_Statement_Buffer;
end if;
end loop;
end Gen_Versions;
------------------------
-- Get_Main_Unit_Name --
------------------------
function Get_Main_Unit_Name (S : String) return String is
Result : String := S;
begin
for J in S'Range loop
if Result (J) = '.' then
Result (J) := '_';
end if;
end loop;
return Result;
end Get_Main_Unit_Name;
-----------------------
-- Get_Ada_Main_Name --
-----------------------
function Get_Ada_Main_Name return String is
Suffix : constant String := "_00";
Name : String (1 .. Opt.Ada_Main_Name.all'Length + Suffix'Length) :=
Opt.Ada_Main_Name.all & Suffix;
Nlen : Natural;
begin
-- For CodePeer, we want reproducible names (independent of other mains
-- that may or may not be present) that don't collide when analyzing
-- multiple mains and which are easily recognizable as "ada_main" names.
if CodePeer_Mode then
Get_Name_String (Units.Table (First_Unit_Entry).Uname);
return
"ada_main_for_" &
Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len - 2));
end if;
-- This loop tries the following possibilities in order
-- <Ada_Main>
-- <Ada_Main>_01
-- <Ada_Main>_02
-- ..
-- <Ada_Main>_99
-- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
-- it is set to 'ada_main'.
for J in 0 .. 99 loop
if J = 0 then
Nlen := Name'Length - Suffix'Length;
else
Nlen := Name'Length;
Name (Name'Last) := Character'Val (J mod 10 + Character'Pos ('0'));
Name (Name'Last - 1) :=
Character'Val (J / 10 + Character'Pos ('0'));
end if;
for K in ALIs.First .. ALIs.Last loop
for L in ALIs.Table (K).First_Unit .. ALIs.Table (K).Last_Unit loop
-- Get unit name, removing %b or %e at end
Get_Name_String (Units.Table (L).Uname);
Name_Len := Name_Len - 2;
if Name_Buffer (1 .. Name_Len) = Name (1 .. Nlen) then
goto Continue;
end if;
end loop;
end loop;
return Name (1 .. Nlen);
<<Continue>>
null;
end loop;
-- If we fall through, just use a peculiar unlikely name
return ("Qwertyuiop");
end Get_Ada_Main_Name;
-------------------
-- Get_Main_Name --
-------------------
function Get_Main_Name return String is
begin
-- Explicit name given with -M switch
if Bind_Alternate_Main_Name then
return Alternate_Main_Name.all;
-- Case of main program name to be used directly
elsif Use_Ada_Main_Program_Name_On_Target then
-- Get main program name
Get_Name_String (Units.Table (First_Unit_Entry).Uname);
-- If this is a child name, return only the name of the child, since
-- we can't have dots in a nested program name. Note that we do not
-- include the %b at the end of the unit name.
for J in reverse 1 .. Name_Len - 2 loop
if J = 1 or else Name_Buffer (J - 1) = '.' then
return Name_Buffer (J .. Name_Len - 2);
end if;
end loop;
raise Program_Error; -- impossible exit
-- Case where "main" is to be used as default
else
return "main";
end if;
end Get_Main_Name;
---------------------
-- Get_WC_Encoding --
---------------------
function Get_WC_Encoding return Character is
begin
-- If encoding method specified by -W switch, then return it
if Wide_Character_Encoding_Method_Specified then
return WC_Encoding_Letters (Wide_Character_Encoding_Method);
-- If no main program, and not specified, set brackets, we really have
-- no better choice. If some other encoding is required when there is
-- no main, it must be set explicitly using -Wx.
-- Note: if the ALI file always passed the wide character encoding of
-- every file, then we could use the encoding of the initial specified
-- file, but this information is passed only for potential main
-- programs. We could fix this sometime, but it is a very minor point
-- (wide character default encoding for [Wide_[Wide_]]Text_IO when there
-- is no main program).
elsif No_Main_Subprogram then
return 'b';
-- Otherwise if there is a main program, take encoding from it
else
return ALIs.Table (ALIs.First).WC_Encoding;
end if;
end Get_WC_Encoding;
-------------------
-- Has_Finalizer --
-------------------
function Has_Finalizer (Elab_Order : Unit_Id_Array) return Boolean is
U : Unit_Record;
Unum : Unit_Id;
begin
for E in reverse Elab_Order'Range loop
Unum := Elab_Order (E);
U := Units.Table (Unum);
-- We are only interested in non-generic packages
if U.Unit_Kind = 'p'
and then U.Has_Finalizer
and then not U.Is_Generic
and then not U.No_Elab
then
return True;
end if;
end loop;
return False;
end Has_Finalizer;
----------
-- Hash --
----------
function Hash (Nam : Name_Id) return Header_Num is
begin
return Int (Nam - Names_Low_Bound) rem Header_Num'Last;
end Hash;
----------------------
-- Lt_Linker_Option --
----------------------
function Lt_Linker_Option (Op1 : Natural; Op2 : Natural) return Boolean is
begin
-- Sort internal files last
if Linker_Options.Table (Op1).Internal_File
/=
Linker_Options.Table (Op2).Internal_File
then
-- Note: following test uses False < True
return Linker_Options.Table (Op1).Internal_File
<
Linker_Options.Table (Op2).Internal_File;
-- If both internal or both non-internal, sort according to the
-- elaboration position. A unit that is elaborated later should come
-- earlier in the linker options list.
else
return Units.Table (Linker_Options.Table (Op1).Unit).Elab_Position
>
Units.Table (Linker_Options.Table (Op2).Unit).Elab_Position;
end if;
end Lt_Linker_Option;
------------------------
-- Move_Linker_Option --
------------------------
procedure Move_Linker_Option (From : Natural; To : Natural) is
begin
Linker_Options.Table (To) := Linker_Options.Table (From);
end Move_Linker_Option;
----------------------------
-- Resolve_Binder_Options --
----------------------------
procedure Resolve_Binder_Options (Elab_Order : Unit_Id_Array) is
procedure Check_Package (Var : in out Boolean; Name : String);
-- Set Var to true iff the current identifier in Namet is Name. Do
-- nothing if it doesn't match. This procedure is just a helper to
-- avoid explicitly dealing with length.
-------------------
-- Check_Package --
-------------------
procedure Check_Package (Var : in out Boolean; Name : String) is
begin
if Name_Len = Name'Length
and then Name_Buffer (1 .. Name_Len) = Name
then
Var := True;
end if;
end Check_Package;
-- Start of processing for Resolve_Binder_Options
begin
for E in Elab_Order'Range loop
Get_Name_String (Units.Table (Elab_Order (E)).Uname);
-- This is not a perfect approach, but is the current protocol
-- between the run-time and the binder to indicate that tasking is
-- used: System.OS_Interface should always be used by any tasking
-- application.
Check_Package (With_GNARL, "system.os_interface%s");
-- Ditto for the use of restricted tasking
Check_Package
(System_Tasking_Restricted_Stages_Used,
"system.tasking.restricted.stages%s");
-- Ditto for the use of interrupts
Check_Package (System_Interrupts_Used, "system.interrupts%s");
-- Ditto for the use of dispatching domains
Check_Package
(Dispatching_Domains_Used,
"system.multiprocessors.dispatching_domains%s");
-- Ditto for the use of restrictions
Check_Package (System_Restrictions_Used, "system.restrictions%s");
-- Ditto for the use of System.Secondary_Stack
Check_Package
(System_Secondary_Stack_Package_In_Closure,
"system.secondary_stack%s");
-- Ditto for use of an SMP bareboard runtime
Check_Package (System_BB_CPU_Primitives_Multiprocessors_Used,
"system.bb.cpu_primitives.multiprocessors%s");
-- Ditto for System.Version_Control, which is used for Version and
-- Body_Version attributes.
Check_Package (System_Version_Control_Used,
"system.version_control%s");
end loop;
end Resolve_Binder_Options;
------------------
-- Set_Bind_Env --
------------------
procedure Set_Bind_Env (Key, Value : String) is
begin
-- The lengths of Key and Value are stored as single bytes
if Key'Length > 255 then
Osint.Fail ("bind environment key """ & Key & """ too long");
end if;
if Value'Length > 255 then
Osint.Fail ("bind environment value """ & Value & """ too long");
end if;
Bind_Environment.Set (Name_Find (Key), Name_Find (Value));
end Set_Bind_Env;
-----------------
-- Set_Boolean --
-----------------
procedure Set_Boolean (B : Boolean) is
False_Str : constant String := "False";
True_Str : constant String := "True";
begin
if B then
Statement_Buffer (Stm_Last + 1 .. Stm_Last + True_Str'Length) :=
True_Str;
Stm_Last := Stm_Last + True_Str'Length;
else
Statement_Buffer (Stm_Last + 1 .. Stm_Last + False_Str'Length) :=
False_Str;
Stm_Last := Stm_Last + False_Str'Length;
end if;
end Set_Boolean;
--------------
-- Set_Char --
--------------
procedure Set_Char (C : Character) is
begin
Stm_Last := Stm_Last + 1;
Statement_Buffer (Stm_Last) := C;
end Set_Char;
-------------
-- Set_Int --
-------------
procedure Set_Int (N : Int) is
begin
if N < 0 then
Set_String ("-");
Set_Int (-N);
else
if N > 9 then
Set_Int (N / 10);
end if;
Stm_Last := Stm_Last + 1;
Statement_Buffer (Stm_Last) :=
Character'Val (N mod 10 + Character'Pos ('0'));
end if;
end Set_Int;
-------------------------
-- Set_IS_Pragma_Table --
-------------------------
procedure Set_IS_Pragma_Table is
begin
for F in ALIs.First .. ALIs.Last loop
for K in ALIs.Table (F).First_Interrupt_State ..
ALIs.Table (F).Last_Interrupt_State
loop
declare
Inum : constant Int :=
Interrupt_States.Table (K).Interrupt_Id;
Stat : constant Character :=
Interrupt_States.Table (K).Interrupt_State;
begin
while IS_Pragma_Settings.Last < Inum loop
IS_Pragma_Settings.Append ('n');
end loop;
IS_Pragma_Settings.Table (Inum) := Stat;
end;
end loop;
end loop;
end Set_IS_Pragma_Table;
---------------------------
-- Set_Main_Program_Name --
---------------------------
procedure Set_Main_Program_Name is
begin
-- Note that name has %b on the end which we ignore
-- First we output the initial _ada_ since we know that the main program
-- is a library level subprogram.
Set_String ("_ada_");
-- Copy name, changing dots to double underscores
for J in 1 .. Name_Len - 2 loop
if Name_Buffer (J) = '.' then
Set_String ("__");
else
Set_Char (Name_Buffer (J));
end if;
end loop;
end Set_Main_Program_Name;
---------------------
-- Set_Name_Buffer --
---------------------
procedure Set_Name_Buffer is
begin
for J in 1 .. Name_Len loop
Set_Char (Name_Buffer (J));
end loop;
end Set_Name_Buffer;
-------------------------
-- Set_PSD_Pragma_Table --
-------------------------
procedure Set_PSD_Pragma_Table is
begin
for F in ALIs.First .. ALIs.Last loop
for K in ALIs.Table (F).First_Specific_Dispatching ..
ALIs.Table (F).Last_Specific_Dispatching
loop
declare
DTK : Specific_Dispatching_Record
renames Specific_Dispatching.Table (K);
begin
while PSD_Pragma_Settings.Last < DTK.Last_Priority loop
PSD_Pragma_Settings.Append ('F');
end loop;
for Prio in DTK.First_Priority .. DTK.Last_Priority loop
PSD_Pragma_Settings.Table (Prio) := DTK.Dispatching_Policy;
end loop;
end;
end loop;
end loop;
end Set_PSD_Pragma_Table;
----------------
-- Set_String --
----------------
procedure Set_String (S : String) is
begin
Statement_Buffer (Stm_Last + 1 .. Stm_Last + S'Length) := S;
Stm_Last := Stm_Last + S'Length;
end Set_String;
------------------------
-- Set_String_Replace --
------------------------
procedure Set_String_Replace (S : String) is
begin
Statement_Buffer (Stm_Last - S'Length + 1 .. Stm_Last) := S;
end Set_String_Replace;
-------------------
-- Set_Unit_Name --
-------------------
procedure Set_Unit_Name is
begin
for J in 1 .. Name_Len - 2 loop
if Name_Buffer (J) = '.' then
Set_String ("__");
else
Set_Char (Name_Buffer (J));
end if;
end loop;
end Set_Unit_Name;
---------------------
-- Set_Unit_Number --
---------------------
procedure Set_Unit_Number (U : Unit_Id) is
Num_Units : constant Nat := Nat (Units.Last) - Nat (Unit_Id'First);
Unum : constant Nat := Nat (U) - Nat (Unit_Id'First);
begin
if Num_Units >= 10 and then Unum < 10 then
Set_Char ('0');
end if;
if Num_Units >= 100 and then Unum < 100 then
Set_Char ('0');
end if;
Set_Int (Unum);
end Set_Unit_Number;
---------------------
-- Write_Bind_Line --
---------------------
procedure Write_Bind_Line (S : String) is
begin
-- Need to strip trailing LF from S
WBI (S (S'First .. S'Last - 1));
end Write_Bind_Line;
----------------------------
-- Write_Statement_Buffer --
----------------------------
procedure Write_Statement_Buffer is
begin
WBI (Statement_Buffer (1 .. Stm_Last));
Stm_Last := 0;
end Write_Statement_Buffer;
procedure Write_Statement_Buffer (S : String) is
begin
Set_String (S);
Write_Statement_Buffer;
end Write_Statement_Buffer;
end Bindgen;
|
package Regression_Library is
function LibraryFun (Input : Boolean) return Boolean;
end Regression_Library;
|
--
-- The author disclaims copyright to this source code. In place of
-- a legal notice, here is a blessing:
--
-- May you do good and not evil.
-- May you find forgiveness for yourself and forgive others.
-- May you share freely, not taking more than you give.
--
package Report_Parsers is
type Context_Access is private;
-- (Global : in Lime.Lemon_Record) XXX
function Get_Context return Context_Access;
-- Get access to the parser part of then Lemon_Record
--
function Get_ARG (Parser : in Context_Access) return String;
function Get_CTX (Parser : in Context_Access) return String;
procedure Trim_Right_Symbol (Item : in String;
Pos : out Natural);
-- Split Item at Pos
private
type Context_Record;
type Context_Access is access all Context_Record;
end Report_Parsers;
|
--------------------------------------------------------------------------------
-- MIT License
--
-- Copyright (c) 2020 Zane Myers
--
-- 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.Unchecked_Conversion;
with Interfaces;
use Interfaces;
package body Vulkan.Math.Integers is
-- 32-bit LSB mask.
LSB32_MASK : constant := 16#00000000FFFFFFFF#;
-- A 64-bit unsigned integer type.
type Vkm_Uint64 is new Interfaces.Unsigned_64;
-- A 64-bit signed integer type.
type Vkm_Int64 is new Interfaces.Integer_64;
-- A representation of a 32-bit integer as an array of 32 booleans.
type Vkm_Bits32 is array (0 .. 31) of Boolean;
for Vkm_Bits32'Component_Size use 1;
for Vkm_Bits32'Size use 32;
----------------------------------------------------------------------------
-- Local Operations
----------------------------------------------------------------------------
-- Unchecked conversion from a 64-bit signed integer to a 64-bit unsigned
-- integer.
function To_Vkm_Uint64 is new
Ada.Unchecked_Conversion(
Source => Vkm_Int64,
Target => Vkm_Uint64);
function To_Vkm_Bits32 is new
Ada.Unchecked_Conversion(
Source => Vkm_Uint,
Target => Vkm_Bits32);
function To_Vkm_Bits32 is new
Ada.Unchecked_Conversion(
Source => Vkm_Int,
Target => Vkm_Bits32);
function To_Vkm_Uint is new
Ada.Unchecked_Conversion(
Source => Vkm_Bits32,
Target => Vkm_Uint);
function To_Vkm_Int is new
Ada.Unchecked_Conversion(
Source => Vkm_Bits32,
Target => Vkm_Int);
----------------------------------------------------------------------------
-- Operations
----------------------------------------------------------------------------
function Unsigned_Add_Carry(x, y : in Vkm_Uint;
carry : out Vkm_Uint) return Vkm_Uint is
begin
if (Vkm_Uint64(x) + Vkm_Uint64(y)) > Vkm_Uint64(Vkm_Uint'Last) then
carry := 1;
else
carry := 0;
end if;
return x + y;
end Unsigned_Add_Carry;
----------------------------------------------------------------------------
function Unsigned_Sub_Borrow(x, y : in Vkm_Uint;
borrow : out Vkm_Uint) return Vkm_Uint is
begin
borrow := (if x >= y then 0 else 1);
return x - y;
end Unsigned_Sub_Borrow;
----------------------------------------------------------------------------
procedure Unsigned_Mul_Extended(x, y : in Vkm_Uint;
msb, lsb : out Vkm_Uint) is
result : constant Vkm_Uint64 := Vkm_Uint64(x) * Vkm_Uint64(y);
begin
lsb := Vkm_Uint(LSB32_MASK and result);
msb := Vkm_Uint(LSB32_MASK and Shift_Right(result, 32));
end Unsigned_Mul_Extended;
----------------------------------------------------------------------------
procedure Signed_Mul_Extended(x, y : in Vkm_Int;
msb, lsb : out Vkm_Int) is
result : constant Vkm_Int64 := Vkm_Int64(x) * Vkm_Int64(y);
begin
lsb := To_Vkm_Int(Vkm_Uint(LSB32_MASK and To_Vkm_Uint64(result)));
msb := To_Vkm_Int(Vkm_Uint(LSB32_MASK and Shift_Right(To_Vkm_Uint64(result), 32)));
end Signed_Mul_Extended;
----------------------------------------------------------------------------
function Bitfield_Extract(value, offset, bits : in Vkm_Int) return Vkm_Int is
value_bits : constant Vkm_Bits32 := To_Vkm_Bits32(value);
result_bits : Vkm_Bits32 := (others => value_bits(Integer(offset + bits -1)));
begin
for bit_index in 0 .. bits - 1 loop
result_bits(Integer(bit_index)) := value_bits(Integer(offset + bit_index));
end loop;
return To_Vkm_Int(result_bits);
end Bitfield_Extract;
----------------------------------------------------------------------------
function Bitfield_Extract(value : in Vkm_Uint;
offset, bits : in Vkm_Int) return Vkm_Uint is
value_bits : constant Vkm_Bits32 := To_Vkm_Bits32(value);
result_bits : Vkm_Bits32 := (others => False);
begin
for bit_index in 0 .. bits - 1 loop
result_bits(Integer(bit_index)) := value_bits(Integer(offset + bit_index));
end loop;
return To_Vkm_Uint(result_bits);
end Bitfield_Extract;
----------------------------------------------------------------------------
function Bitfield_Insert(base, insert, offset, bits : in Vkm_Int) return Vkm_Int is
base_bits : Vkm_Bits32 := To_Vkm_Bits32(base);
insert_bits : constant Vkm_Bits32 := To_Vkm_Bits32(insert);
begin
for bit_index in 0 .. bits - 1 loop
base_bits(Integer(offset + bit_index)) := insert_bits(Integer(bit_index));
end loop;
return To_Vkm_Int(base_bits);
end Bitfield_Insert;
----------------------------------------------------------------------------
function Bitfield_Insert(base, insert : in Vkm_Uint;
offset, bits : in Vkm_Int) return Vkm_Uint is
base_bits : Vkm_Bits32 := To_Vkm_Bits32(base);
insert_bits : constant Vkm_Bits32 := To_Vkm_Bits32(insert);
begin
for bit_index in 0 .. bits - 1 loop
base_bits(Integer(offset + bit_index)) := insert_bits(Integer(bit_index));
end loop;
return To_Vkm_Uint(base_bits);
end Bitfield_Insert;
----------------------------------------------------------------------------
function Bitfield_Reverse(value : in Vkm_Int) return Vkm_Int is
value_bits : constant Vkm_Bits32 := To_Vkm_Bits32(value);
result_bits : Vkm_Bits32 := (others => False);
begin
for bit_index in 0 .. 31 loop
result_bits(bit_index) := value_bits(31 - bit_index);
end loop;
return To_Vkm_Int(result_bits);
end Bitfield_Reverse;
----------------------------------------------------------------------------
function Bitfield_Reverse(value : in Vkm_Uint) return Vkm_Uint is
value_bits : constant Vkm_Bits32 := To_Vkm_Bits32(value);
result_bits : Vkm_Bits32 := (others => False);
begin
for bit_index in 0 .. 31 loop
result_bits(bit_index) := value_bits(31 - bit_index);
end loop;
return To_Vkm_Uint(result_bits);
end Bitfield_Reverse;
----------------------------------------------------------------------------
function Bit_Count(value : in Vkm_Int) return Vkm_Int is
value_bits : constant Vkm_Bits32 := To_Vkm_Bits32(value);
result : Vkm_Int := 0;
begin
for bit_index in 0 .. 31 loop
result := result + (if value_bits(bit_index) then 1 else 0);
end loop;
return result;
end Bit_Count;
----------------------------------------------------------------------------
function Bit_Count(value : in Vkm_Uint) return Vkm_Int is
value_bits : constant Vkm_Bits32 := To_Vkm_Bits32(value);
result : Vkm_Int := 0;
begin
for bit_index in 0 .. 31 loop
result := result + (if value_bits(bit_index) then 1 else 0);
end loop;
return result;
end Bit_Count;
----------------------------------------------------------------------------
function Find_Lsb(value : in Vkm_Int) return Vkm_Int is
value_bits : constant Vkm_Bits32 := To_Vkm_Bits32(value);
result : Vkm_Int := -1;
begin
for bit_index in 0 .. 31 loop
if value_bits(bit_index) then
result := Vkm_Int(bit_index);
end if;
exit when result /= -1;
end loop;
return result;
end Find_Lsb;
----------------------------------------------------------------------------
function Find_Lsb(value : in Vkm_Uint) return Vkm_Int is
value_bits : constant Vkm_Bits32 := To_Vkm_Bits32(value);
result : Vkm_Int := -1;
begin
for bit_index in 0 .. 31 loop
if value_bits(bit_index) then
result := Vkm_Int(bit_index);
end if;
exit when result /= -1;
end loop;
return result;
end Find_Lsb;
----------------------------------------------------------------------------
function Find_Msb(value : in Vkm_Int) return Vkm_Int is
value_bits : constant Vkm_Bits32 := To_Vkm_Bits32(value);
result : Vkm_Int := -1;
begin
for bit_index in reverse 0 .. 31 loop
if not value_bits(bit_index) then
result := Vkm_Int(bit_index);
end if;
exit when result /= -1;
end loop;
return result;
end Find_Msb;
----------------------------------------------------------------------------
function Find_Msb(value : in Vkm_Uint) return Vkm_Int is
value_bits : constant Vkm_Bits32 := To_Vkm_Bits32(value);
result : Vkm_Int := -1;
begin
for bit_index in reverse 0 .. 31 loop
if value_bits(bit_index) then
result := Vkm_Int(bit_index);
end if;
exit when result /= -1;
end loop;
return result;
end Find_Msb;
end Vulkan.Math.Integers;
|
with
Interfaces.C,
System;
use type
Interfaces.C.int,
System.Address;
package body FLTK.Devices.Surfaces.Paged is
function new_fl_paged_device
return System.Address;
pragma Import (C, new_fl_paged_device, "new_fl_paged_device");
pragma Inline (new_fl_paged_device);
procedure free_fl_paged_device
(D : in System.Address);
pragma Import (C, free_fl_paged_device, "free_fl_paged_device");
pragma Inline (free_fl_paged_device);
function fl_paged_device_start_job
(D : in System.Address;
C : in Interfaces.C.int)
return Interfaces.C.int;
pragma Import (C, fl_paged_device_start_job, "fl_paged_device_start_job");
pragma Inline (fl_paged_device_start_job);
function fl_paged_device_start_job2
(D : in System.Address;
C, F, T : in Interfaces.C.int)
return Interfaces.C.int;
pragma Import (C, fl_paged_device_start_job2, "fl_paged_device_start_job2");
pragma Inline (fl_paged_device_start_job2);
procedure fl_paged_device_end_job
(D : in System.Address);
pragma Import (C, fl_paged_device_end_job, "fl_paged_device_end_job");
pragma Inline (fl_paged_device_end_job);
function fl_paged_device_start_page
(D : in System.Address)
return Interfaces.C.int;
pragma Import (C, fl_paged_device_start_page, "fl_paged_device_start_page");
pragma Inline (fl_paged_device_start_page);
function fl_paged_device_end_page
(D : in System.Address)
return Interfaces.C.int;
pragma Import (C, fl_paged_device_end_page, "fl_paged_device_end_page");
pragma Inline (fl_paged_device_end_page);
procedure fl_paged_device_margins
(D : in System.Address;
L, T, R, B : out Interfaces.C.int);
pragma Import (C, fl_paged_device_margins, "fl_paged_device_margins");
pragma Inline (fl_paged_device_margins);
function fl_paged_device_printable_rect
(D : in System.Address;
W, H : out Interfaces.C.int)
return Interfaces.C.int;
pragma Import (C, fl_paged_device_printable_rect, "fl_paged_device_printable_rect");
pragma Inline (fl_paged_device_printable_rect);
procedure fl_paged_device_get_origin
(D : in System.Address;
X, Y : out Interfaces.C.int);
pragma Import (C, fl_paged_device_get_origin, "fl_paged_device_get_origin");
pragma Inline (fl_paged_device_get_origin);
procedure fl_paged_device_set_origin
(D : in System.Address;
X, Y : in Interfaces.C.int);
pragma Import (C, fl_paged_device_set_origin, "fl_paged_device_set_origin");
pragma Inline (fl_paged_device_set_origin);
procedure fl_paged_device_rotate
(D : in System.Address;
R : in Interfaces.C.C_float);
pragma Import (C, fl_paged_device_rotate, "fl_paged_device_rotate");
pragma Inline (fl_paged_device_rotate);
procedure fl_paged_device_scale
(D : in System.Address;
X, Y : in Interfaces.C.C_float);
pragma Import (C, fl_paged_device_scale, "fl_paged_device_scale");
pragma Inline (fl_paged_device_scale);
procedure fl_paged_device_translate
(D : in System.Address;
X, Y : in Interfaces.C.int);
pragma Import (C, fl_paged_device_translate, "fl_paged_device_translate");
pragma Inline (fl_paged_device_translate);
procedure fl_paged_device_untranslate
(D : in System.Address);
pragma Import (C, fl_paged_device_untranslate, "fl_paged_device_untranslate");
pragma Inline (fl_paged_device_untranslate);
procedure fl_paged_device_print_widget
(D, I : in System.Address;
DX, DY : in Interfaces.C.int);
pragma Import (C, fl_paged_device_print_widget, "fl_paged_device_print_widget");
pragma Inline (fl_paged_device_print_widget);
procedure fl_paged_device_print_window
(D, I : in System.Address;
DX, DY : in Interfaces.C.int);
pragma Import (C, fl_paged_device_print_window, "fl_paged_device_print_window");
pragma Inline (fl_paged_device_print_window);
procedure fl_paged_device_print_window_part
(D, I : in System.Address;
X, Y, W, H, DX, DY : in Interfaces.C.int);
pragma Import (C, fl_paged_device_print_window_part, "fl_paged_device_print_window_part");
pragma Inline (fl_paged_device_print_window_part);
procedure Finalize
(This : in out Paged_Surface) is
begin
if This.Void_Ptr /= System.Null_Address and then
This in Paged_Surface'Class
then
free_fl_paged_device (This.Void_Ptr);
This.Void_Ptr := System.Null_Address;
end if;
Finalize (Surface_Device (This));
end Finalize;
package body Forge is
function Create
return Paged_Surface is
begin
return This : Paged_Surface do
This.Void_Ptr := new_fl_paged_device;
end return;
end Create;
pragma Inline (Create);
end Forge;
procedure Start_Job
(This : in out Paged_Surface;
Count : in Natural) is
begin
if fl_paged_device_start_job
(This.Void_Ptr, Interfaces.C.int (Count)) /= 0
then
raise Page_Error;
end if;
end Start_Job;
procedure Start_Job
(This : in out Paged_Surface;
Count : in Natural;
From, To : in Positive) is
begin
if fl_paged_device_start_job2
(This.Void_Ptr,
Interfaces.C.int (Count),
Interfaces.C.int (From),
Interfaces.C.int (To)) /= 0
then
raise Page_Error;
end if;
end Start_Job;
procedure End_Job
(This : in out Paged_Surface) is
begin
fl_paged_device_end_job (This.Void_Ptr);
end End_Job;
procedure Start_Page
(This : in out Paged_Surface) is
begin
if fl_paged_device_start_page (This.Void_Ptr) /= 0 then
raise Page_Error;
end if;
end Start_Page;
procedure End_Page
(This : in out Paged_Surface) is
begin
if fl_paged_device_end_page (This.Void_Ptr) /= 0 then
raise Page_Error;
end if;
end End_Page;
procedure Get_Margins
(This : in Paged_Surface;
Left, Top, Right, Bottom : out Integer) is
begin
fl_paged_device_margins
(This.Void_Ptr,
Interfaces.C.int (Left),
Interfaces.C.int (Top),
Interfaces.C.int (Right),
Interfaces.C.int (Bottom));
end Get_Margins;
procedure Get_Printable_Rect
(This : in Paged_Surface;
W, H : out Integer) is
begin
if fl_paged_device_printable_rect
(This.Void_Ptr, Interfaces.C.int (W), Interfaces.C.int (H)) /= 0
then
raise Page_Error;
end if;
end Get_Printable_Rect;
procedure Get_Origin
(This : in Paged_Surface;
X, Y : out Integer) is
begin
fl_paged_device_get_origin (This.Void_Ptr, Interfaces.C.int (X), Interfaces.C.int (Y));
end Get_Origin;
procedure Set_Origin
(This : in out Paged_Surface;
X, Y : in Integer) is
begin
fl_paged_device_set_origin
(This.Void_Ptr,
Interfaces.C.int (X),
Interfaces.C.int (Y));
end Set_Origin;
procedure Rotate
(This : in out Paged_Surface;
Degrees : in Float) is
begin
fl_paged_device_rotate (This.Void_Ptr, Interfaces.C.C_float (Degrees));
end Rotate;
procedure Scale
(This : in out Paged_Surface;
Factor : in Float) is
begin
fl_paged_device_scale (This.Void_Ptr, Interfaces.C.C_float (Factor), 0.0);
end Scale;
procedure Scale
(This : in out Paged_Surface;
Factor_X, Factor_Y : in Float) is
begin
fl_paged_device_scale
(This.Void_Ptr,
Interfaces.C.C_float (Factor_X),
Interfaces.C.C_float (Factor_Y));
end Scale;
procedure Translate
(This : in out Paged_Surface;
Delta_X, Delta_Y : in Integer) is
begin
fl_paged_device_translate
(This.Void_Ptr,
Interfaces.C.int (Delta_X),
Interfaces.C.int (Delta_Y));
end Translate;
procedure Untranslate
(This : in out Paged_Surface) is
begin
fl_paged_device_untranslate (This.Void_Ptr);
end Untranslate;
procedure Print_Widget
(This : in out Paged_Surface;
Item : in FLTK.Widgets.Widget'Class;
Offset_X, Offset_Y : in Integer := 0) is
begin
fl_paged_device_print_widget
(This.Void_Ptr,
Wrapper (Item).Void_Ptr,
Interfaces.C.int (Offset_X),
Interfaces.C.int (Offset_Y));
end Print_Widget;
procedure Print_Window
(This : in out Paged_Surface;
Item : in FLTK.Widgets.Groups.Windows.Window'Class;
Offset_X, Offset_Y : in Integer := 0) is
begin
fl_paged_device_print_window
(This.Void_Ptr,
Wrapper (Item).Void_Ptr,
Interfaces.C.int (Offset_X),
Interfaces.C.int (Offset_Y));
end Print_Window;
procedure Print_Window_Part
(This : in out Paged_Surface;
Item : in FLTK.Widgets.Groups.Windows.Window'Class;
X, Y, W, H : in Integer;
Offset_X, Offset_Y : in Integer := 0) is
begin
fl_paged_device_print_window_part
(This.Void_Ptr,
Wrapper (Item).Void_Ptr,
Interfaces.C.int (X),
Interfaces.C.int (Y),
Interfaces.C.int (W),
Interfaces.C.int (H),
Interfaces.C.int (Offset_X),
Interfaces.C.int (Offset_Y));
end Print_Window_Part;
end FLTK.Devices.Surfaces.Paged;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- T A R G P A R M --
-- --
-- B o d y --
-- --
-- $Revision$
-- --
-- Copyright (C) 1999-2001 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 Namet; use Namet;
with Output; use Output;
with Sinput; use Sinput;
with Sinput.L; use Sinput.L;
with Fname.UF; use Fname.UF;
with Types; use Types;
package body Targparm is
type Targparm_Tags is
(AAM, CLA, DEN, DSP, FEL, HIM, LSI, MOV,
MRN, SCD, SCP, SNZ, UAM, VMS, ZCD, ZCG, ZCF);
Targparm_Flags : array (Targparm_Tags) of Boolean := (others => False);
-- Flag is set True if corresponding parameter is scanned
AAM_Str : aliased constant Source_Buffer := "AAMP";
CLA_Str : aliased constant Source_Buffer := "Command_Line_Args";
DEN_Str : aliased constant Source_Buffer := "Denorm";
DSP_Str : aliased constant Source_Buffer := "Functions_Return_By_DSP";
FEL_Str : aliased constant Source_Buffer := "Frontend_Layout";
HIM_Str : aliased constant Source_Buffer := "High_Integrity_Mode";
LSI_Str : aliased constant Source_Buffer := "Long_Shifts_Inlined";
MOV_Str : aliased constant Source_Buffer := "Machine_Overflows";
MRN_Str : aliased constant Source_Buffer := "Machine_Rounds";
SCD_Str : aliased constant Source_Buffer := "Stack_Check_Default";
SCP_Str : aliased constant Source_Buffer := "Stack_Check_Probes";
SNZ_Str : aliased constant Source_Buffer := "Signed_Zeros";
UAM_Str : aliased constant Source_Buffer := "Use_Ada_Main_Program_Name";
VMS_Str : aliased constant Source_Buffer := "OpenVMS";
ZCD_Str : aliased constant Source_Buffer := "ZCX_By_Default";
ZCG_Str : aliased constant Source_Buffer := "GCC_ZCX_Support";
ZCF_Str : aliased constant Source_Buffer := "Front_End_ZCX_Support";
type Buffer_Ptr is access constant Source_Buffer;
Targparm_Str : array (Targparm_Tags) of Buffer_Ptr :=
(AAM_Str'Access,
CLA_Str'Access,
DEN_Str'Access,
DSP_Str'Access,
FEL_Str'Access,
HIM_Str'Access,
LSI_Str'Access,
MOV_Str'Access,
MRN_Str'Access,
SCD_Str'Access,
SCP_Str'Access,
SNZ_Str'Access,
UAM_Str'Access,
VMS_Str'Access,
ZCD_Str'Access,
ZCG_Str'Access,
ZCF_Str'Access);
---------------------------
-- Get_Target_Parameters --
---------------------------
procedure Get_Target_Parameters is
use ASCII;
S : Source_File_Index;
N : Name_Id;
T : Source_Buffer_Ptr;
P : Source_Ptr;
Z : Source_Ptr;
Fatal : Boolean := False;
-- Set True if a fatal error is detected
Result : Boolean;
-- Records boolean from system line
begin
Name_Buffer (1 .. 6) := "system";
Name_Len := 6;
N := File_Name_Of_Spec (Name_Find);
S := Load_Source_File (N);
if S = No_Source_File then
Write_Line ("fatal error, run-time library not installed correctly");
Write_Str ("cannot locate file ");
Write_Line (Name_Buffer (1 .. Name_Len));
raise Unrecoverable_Error;
-- This must always be the first source file read, and we have defined
-- a constant Types.System_Source_File_Index as 1 to reflect this.
else
pragma Assert (S = System_Source_File_Index);
null;
end if;
P := Source_First (S);
Z := Source_Last (S);
T := Source_Text (S);
while T (P .. P + 10) /= "end System;" loop
for K in Targparm_Tags loop
if T (P + 3 .. P + 2 + Targparm_Str (K)'Length) =
Targparm_Str (K).all
then
P := P + 3 + Targparm_Str (K)'Length;
if Targparm_Flags (K) then
Set_Standard_Error;
Write_Line
("fatal error: system.ads is incorrectly formatted");
Write_Str ("duplicate line for parameter: ");
for J in Targparm_Str (K)'Range loop
Write_Char (Targparm_Str (K).all (J));
end loop;
Write_Eol;
Set_Standard_Output;
Fatal := True;
else
Targparm_Flags (K) := True;
end if;
while T (P) /= ':' or else T (P + 1) /= '=' loop
P := P + 1;
end loop;
P := P + 2;
while T (P) = ' ' loop
P := P + 1;
end loop;
Result := (T (P) = 'T');
case K is
when AAM => AAMP_On_Target := Result;
when CLA => Command_Line_Args_On_Target := Result;
when DEN => Denorm_On_Target := Result;
when DSP => Functions_Return_By_DSP_On_Target := Result;
when FEL => Frontend_Layout_On_Target := Result;
when HIM => High_Integrity_Mode_On_Target := Result;
when LSI => Long_Shifts_Inlined_On_Target := Result;
when MOV => Machine_Overflows_On_Target := Result;
when MRN => Machine_Rounds_On_Target := Result;
when SCD => Stack_Check_Default_On_Target := Result;
when SCP => Stack_Check_Probes_On_Target := Result;
when SNZ => Signed_Zeros_On_Target := Result;
when UAM => Use_Ada_Main_Program_Name_On_Target := Result;
when VMS => OpenVMS_On_Target := Result;
when ZCD => ZCX_By_Default_On_Target := Result;
when ZCG => GCC_ZCX_Support_On_Target := Result;
when ZCF => Front_End_ZCX_Support_On_Target := Result;
end case;
exit;
end if;
end loop;
while T (P) /= CR and then T (P) /= LF loop
P := P + 1;
exit when P >= Z;
end loop;
while T (P) = CR or else T (P) = LF loop
P := P + 1;
exit when P >= Z;
end loop;
if P >= Z then
Set_Standard_Error;
Write_Line ("fatal error, system.ads not formatted correctly");
Set_Standard_Output;
raise Unrecoverable_Error;
end if;
end loop;
for K in Targparm_Tags loop
if not Targparm_Flags (K) then
Set_Standard_Error;
Write_Line
("fatal error: system.ads is incorrectly formatted");
Write_Str ("missing line for parameter: ");
for J in Targparm_Str (K)'Range loop
Write_Char (Targparm_Str (K).all (J));
end loop;
Write_Eol;
Set_Standard_Output;
Fatal := True;
end if;
end loop;
if Fatal then
raise Unrecoverable_Error;
end if;
end Get_Target_Parameters;
end Targparm;
|
-------------------------------------------------------------------------------
-- Copyright (c) 2019, Daniel King
-- 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.
-- * The name of the copyright holder may not 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 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 body Keccak.Generic_KeccakF.Byte_Lanes.Twisted is
Twist : constant array (Y_Coord, X_Coord) of X_Coord :=
(0 => (0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4),
1 => (0 => 3,
1 => 4,
2 => 0,
3 => 1,
4 => 2),
2 => (0 => 1,
1 => 2,
2 => 3,
3 => 4,
4 => 0),
3 => (0 => 4,
1 => 0,
2 => 1,
3 => 2,
4 => 3),
4 => (0 => 2,
1 => 3,
2 => 4,
3 => 0,
4 => 1));
-- Twist mapping for the X coordinate.
--
-- The twisted Y coordinate is equal to the un-twisted X coordinate.
-----------------------------------
-- XOR_Bits_Into_State_Twisted --
-----------------------------------
procedure XOR_Bits_Into_State_Twisted (A : in out State;
Data : in Keccak.Types.Byte_Array;
Bit_Len : in Natural)
is
use type Keccak.Types.Byte;
Remaining_Bits : Natural := Bit_Len;
Offset : Natural := 0;
XT : X_Coord;
YT : Y_Coord;
begin
-- Process whole lanes (64 bits).
Outer_Loop :
for Y in Y_Coord loop
pragma Loop_Invariant ((Offset * 8) + Remaining_Bits = Bit_Len);
pragma Loop_Invariant (Offset mod (Lane_Size_Bits / 8) = 0);
pragma Loop_Invariant (Offset = Natural (Y) * (Lane_Size_Bits / 8) * 5);
for X in X_Coord loop
pragma Loop_Invariant ((Offset * 8) + Remaining_Bits = Bit_Len);
pragma Loop_Invariant (Offset mod (Lane_Size_Bits / 8) = 0);
pragma Loop_Invariant (Offset = (Natural (Y) * (Lane_Size_Bits / 8) * 5) +
(Natural (X) * (Lane_Size_Bits / 8)));
exit Outer_Loop when Remaining_Bits < Lane_Size_Bits;
declare
Lane : Lane_Type := 0;
begin
for I in Natural range 0 .. (Lane_Size_Bits / 8) - 1 loop
Lane := Lane or Shift_Left (Lane_Type (Data (Data'First + Offset + I)),
I * 8);
end loop;
XT := Twist (Y, X);
YT := Y_Coord (X);
A (XT, YT) := A (XT, YT) xor Lane;
end;
Offset := Offset + Lane_Size_Bits / 8;
Remaining_Bits := Remaining_Bits - Lane_Size_Bits;
end loop;
end loop Outer_Loop;
-- Process any remaining data (smaller than 1 lane - 64 bits)
if Remaining_Bits > 0 then
declare
X : constant X_Coord := X_Coord ((Bit_Len / Lane_Size_Bits) mod 5);
Y : constant Y_Coord := Y_Coord ((Bit_Len / Lane_Size_Bits) / 5);
Word : Lane_Type := 0;
Remaining_Bytes : constant Natural := (Remaining_Bits + 7) / 8;
begin
XT := Twist (Y, X);
YT := Y_Coord (X);
for I in Natural range 0 .. Remaining_Bytes - 1 loop
Word := Word or Shift_Left (Lane_Type (Data (Data'First + Offset + I)), I * 8);
end loop;
A (XT, YT) := A (XT, YT) xor (Word and (2**Remaining_Bits) - 1);
end;
end if;
end XOR_Bits_Into_State_Twisted;
-----------------------------------
-- XOR_Bits_Into_State_Twisted --
-----------------------------------
procedure XOR_Bits_Into_State_Twisted (A : in out Lane_Complemented_State;
Data : in Keccak.Types.Byte_Array;
Bit_Len : in Natural)
is
begin
XOR_Bits_Into_State_Twisted
(A => State (A),
Data => Data,
Bit_Len => Bit_Len);
end XOR_Bits_Into_State_Twisted;
-----------------------------------
-- XOR_Byte_Into_State_Twisted --
-----------------------------------
procedure XOR_Byte_Into_State_Twisted (A : in out State;
Offset : in Natural;
Value : in Keccak.Types.Byte)
is
Lane_Size_Bytes : constant Positive := Lane_Size_Bits / 8;
X : constant X_Coord := X_Coord ((Offset / Lane_Size_Bytes) mod 5);
Y : constant Y_Coord := Y_Coord (Offset / (Lane_Size_Bytes * 5));
XT : constant X_Coord := Twist (Y, X);
YT : constant Y_Coord := Y_Coord (X);
begin
A (XT, YT) := A (XT, YT) xor Shift_Left (Lane_Type (Value),
(Offset mod (Lane_Size_Bits / 8)) * 8);
end XOR_Byte_Into_State_Twisted;
---------------------------
-- XOR_Byte_Into_State_Twisted --
---------------------------
procedure XOR_Byte_Into_State_Twisted (A : in out Lane_Complemented_State;
Offset : in Natural;
Value : in Keccak.Types.Byte)
is
begin
XOR_Byte_Into_State_Twisted (State (A), Offset, Value);
end XOR_Byte_Into_State_Twisted;
-----------------------------
-- Extract_Bytes_Twisted --
-----------------------------
procedure Extract_Bytes_Twisted (A : in State;
Data : out Keccak.Types.Byte_Array)
is
use type Keccak.Types.Byte;
X : X_Coord := 0;
Y : Y_Coord := 0;
XT : X_Coord;
YT : Y_Coord;
Remaining_Bytes : Natural := Data'Length;
Offset : Natural := 0;
Lane : Lane_Type;
begin
-- Case when each lane is at least 1 byte (i.e. 8, 16, 32, or 64 bits)
-- Process whole lanes
Outer_Loop :
for Y2 in Y_Coord loop
pragma Loop_Invariant (Offset mod (Lane_Size_Bits / 8) = 0
and Offset + Remaining_Bytes = Data'Length);
for X2 in X_Coord loop
pragma Loop_Variant (Increases => Offset,
Decreases => Remaining_Bytes);
pragma Loop_Invariant (Offset mod (Lane_Size_Bits / 8) = 0
and Offset + Remaining_Bytes = Data'Length);
XT := Twist (Y2, X2);
YT := Y_Coord (X2);
if Remaining_Bytes < Lane_Size_Bits / 8 then
X := XT;
Y := YT;
exit Outer_Loop;
end if;
Lane := A (XT, YT);
for I in Natural range 0 .. (Lane_Size_Bits / 8) - 1 loop
Data (Data'First + Offset + I)
:= Keccak.Types.Byte (Shift_Right (Lane, I * 8) and 16#FF#);
pragma Annotate (GNATprove, False_Positive,
"""Data"" might not be initialized",
"Data is initialized at end of procedure");
end loop;
Remaining_Bytes := Remaining_Bytes - Lane_Size_Bits / 8;
Offset := Offset + Lane_Size_Bits / 8;
end loop;
end loop Outer_Loop;
-- Process any remaining data (smaller than 1 lane)
if Remaining_Bytes > 0 then
Lane := A (X, Y);
declare
Initial_Offset : constant Natural := Offset with Ghost;
Shift : Natural := 0;
begin
while Remaining_Bytes > 0 loop
pragma Loop_Variant (Increases => Offset,
Increases => Shift,
Decreases => Remaining_Bytes);
pragma Loop_Invariant (Offset + Remaining_Bytes = Data'Length
and Shift mod 8 = 0
and Shift = (Offset - Initial_Offset) * 8);
Data (Data'First + Offset)
:= Keccak.Types.Byte (Shift_Right (Lane, Shift) and 16#FF#);
pragma Annotate (GNATprove, False_Positive,
"""Data"" might not be initialized",
"Data is initialized at end of procedure");
Shift := Shift + 8;
Offset := Offset + 1;
Remaining_Bytes := Remaining_Bytes - 1;
end loop;
end;
end if;
end Extract_Bytes_Twisted;
-----------------------------
-- Extract_Bytes_Twisted --
-----------------------------
procedure Extract_Bytes_Twisted (A : in Lane_Complemented_State;
Data : out Keccak.Types.Byte_Array)
is
use type Keccak.Types.Byte;
Complement_Mask : constant Lane_Complemented_State :=
(0 => (4 => Lane_Type'Last,
others => 0),
1 => (0 => Lane_Type'Last,
others => 0),
2 => (0 | 2 | 3 => Lane_Type'Last,
others => 0),
3 => (1 => Lane_Type'Last,
others => 0),
4 => (others => 0));
-- Some lanes need to be complemented (bitwise NOT) when reading them
-- from the Keccak-f state. We do this by storing a mask of all 1's
-- for those lanes that need to be complemented (and all 0's for the
-- other lanes). We then XOR against the corresponding entry in this
-- Complement_Mask to complement only the required lanes (as XOR'ing
-- against all 1's has the same effect as bitwise NOT).
X : X_Coord := 0;
Y : Y_Coord := 0;
XT : X_Coord;
YT : Y_Coord;
Remaining_Bytes : Natural := Data'Length;
Offset : Natural := 0;
Lane : Lane_Type;
begin
-- Case when each lane is at least 1 byte (i.e. 8, 16, 32, or 64 bits)
-- Process whole lanes
Outer_Loop :
for Y2 in Y_Coord loop
pragma Loop_Invariant (Offset mod (Lane_Size_Bits / 8) = 0
and Offset + Remaining_Bytes = Data'Length);
for X2 in X_Coord loop
pragma Loop_Variant (Increases => Offset,
Decreases => Remaining_Bytes);
pragma Loop_Invariant (Offset mod (Lane_Size_Bits / 8) = 0
and Offset + Remaining_Bytes = Data'Length);
XT := Twist (Y2, X2);
YT := Y_Coord (X2);
if Remaining_Bytes < Lane_Size_Bits / 8 then
X := XT;
Y := YT;
exit Outer_Loop;
end if;
Lane := A (XT, YT) xor Complement_Mask (XT, YT);
for I in Natural range 0 .. (Lane_Size_Bits / 8) - 1 loop
Data (Data'First + Offset + I)
:= Keccak.Types.Byte (Shift_Right (Lane, I * 8) and 16#FF#);
pragma Annotate (GNATprove, False_Positive,
"""Data"" might not be initialized",
"Data is initialized at end of procedure");
end loop;
Remaining_Bytes := Remaining_Bytes - Lane_Size_Bits / 8;
Offset := Offset + Lane_Size_Bits / 8;
end loop;
end loop Outer_Loop;
-- Process any remaining data (smaller than 1 lane)
if Remaining_Bytes > 0 then
Lane := A (X, Y) xor Complement_Mask (X, Y);
declare
Initial_Offset : constant Natural := Offset with Ghost;
Shift : Natural := 0;
begin
while Remaining_Bytes > 0 loop
pragma Loop_Variant (Increases => Offset,
Increases => Shift,
Decreases => Remaining_Bytes);
pragma Loop_Invariant (Offset + Remaining_Bytes = Data'Length
and Shift mod 8 = 0
and Shift = (Offset - Initial_Offset) * 8);
Data (Data'First + Offset)
:= Keccak.Types.Byte (Shift_Right (Lane, Shift) and 16#FF#);
pragma Annotate (GNATprove, False_Positive,
"""Data"" might not be initialized",
"Data is initialized at end of procedure");
Shift := Shift + 8;
Offset := Offset + 1;
Remaining_Bytes := Remaining_Bytes - 1;
end loop;
end;
end if;
end Extract_Bytes_Twisted;
--------------------
-- Extract_Bits --
--------------------
procedure Extract_Bits_Twisted (A : in State;
Data : out Keccak.Types.Byte_Array;
Bit_Len : in Natural)
is
use type Keccak.Types.Byte;
begin
Extract_Bytes_Twisted (A, Data);
-- Avoid exposing more bits than requested by masking away higher bits
-- in the last byte.
if Bit_Len > 0 and Bit_Len mod 8 /= 0 then
Data (Data'Last) := Data (Data'Last) and (2**(Bit_Len mod 8) - 1);
end if;
end Extract_Bits_Twisted;
--------------------
-- Extract_Bits --
--------------------
procedure Extract_Bits_Twisted (A : in Lane_Complemented_State;
Data : out Keccak.Types.Byte_Array;
Bit_Len : in Natural)
is
use type Keccak.Types.Byte;
begin
Extract_Bytes_Twisted (A, Data);
-- Avoid exposing more bits than requested by masking away higher bits
-- in the last byte.
if Bit_Len > 0 and Bit_Len mod 8 /= 0 then
Data (Data'Last) := Data (Data'Last) and (2**(Bit_Len mod 8) - 1);
end if;
end Extract_Bits_Twisted;
end Keccak.Generic_KeccakF.Byte_Lanes.Twisted;
|
with Gdk.Event; use Gdk.Event;
with Gtk.Box; use Gtk.Box;
with Gtk.Label; use Gtk.Label;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Main;
with Gtk.Window; use Gtk.Window;
with Ant_Handler;
procedure Main is
Win : Gtk_Window;
Label : Gtk_Label;
Box : Gtk_Vbox;
function Delete_Event_Cb
(Self : access Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean;
---------------------
-- Delete_Event_Cb --
---------------------
function Delete_Event_Cb
(Self : access Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean
is
pragma Unreferenced (Self, Event);
begin
Gtk.Main.Main_Quit;
return True;
end Delete_Event_Cb;
begin
-- Initialize GtkAda.
Gtk.Main.Init;
-- Create a window with a size of 400x400
Gtk_New (Win);
Win.Set_Default_Size (400, 400);
-- Create a box to organize vertically the contents of the window
Gtk_New_Vbox (Box);
Win.Add (Box);
-- Add a label
Gtk_New (Label, Ant_Handler.Do_Something("Hello, World!"));
Box.Add (Label);
-- Stop the Gtk process when closing the window
Win.On_Delete_Event (Delete_Event_Cb'Unrestricted_Access);
-- Show the window and present it
Win.Show_All;
Win.Present;
-- Start the Gtk+ main loop
Gtk.Main.Main;
end Main;
|
----------------------------csc410/prog6/as6.adb----------------------------
-- Author: Matthew Bennett
-- Class: CSC410 Burgess
-- Date: 11-20-04 Modified: 11-30-04
-- Due: 12-01-04
-- Desc: Assignment 6: KERRY RAYMOND'S SPANNING TREE ALGORITHM
-- FOR VIRTUAL TOPOLOGY NETWORKS
--
-- a nonproduction implementation of
-- RAYMOND's algorithm which utilizes a logical hierarchy for process priority
-- (holder values) as well as a virtual network topology for the process
-- "nodes".
-- Algorithm is O(log N) where N is number of nodes, dependent on net topology.
-- Each node communicates only with its neighbor in the spanning tree,
-- and hold information only about those neighbors
--
-- RAYMOND implemented as described in
-- "A Tree-Based Algorithm for Mutual Exclusion", K. Raymond
-- University of Queensland
-- with additional revisions due to message passing across a virtual topology
----------------------------------------------------------------------------
-- Refactorings 11-20-04: (deNOTed @FIX@)
--done(1) use linked lists --DONE 11-28-04
-- (2) fix integer overflow possibility
-- (3) graceful termination (not implemented)
----------------------------------------------------------------
-- dependencies
WITH ADA.TEXT_IO; USE ADA.TEXT_IO;
WITH ADA.INTEGER_TEXT_IO; USE ADA.INTEGER_TEXT_IO;
WITH ADA.NUMERICS.FLOAT_RANDOM; USE ADA.NUMERICS.FLOAT_RANDOM;
WITH ADA.CALENDAR; -- (provides cast: natural -> time FOR input into delay)
WITH ADA.STRINGS; USE ADA.STRINGS;
WITH ADA.STRINGS.UNBOUNDED; USE ADA.STRINGS.UNBOUNDED;
PROCEDURE as6 IS
-- globals: randomPool, taskArray
randomPool : ADA.NUMERICS.FLOAT_RANDOM.Generator; --generate our random #s
MAX_NEIGHBORS : CONSTANT := 50; --for conserving in arrays
DELAY_FACTOR : CONSTANT := 10.0; --invariant longer delays
TYPE RX; --recieve task
TYPE RX_Ptr IS ACCESS RX; --for spinning off receive
TASKarray : ARRAY (0..MAX_NEIGHBORS) of RX_Ptr; --keep up w tasks thrown off
TYPE passableArray IS ARRAY (0..MAX_NEIGHBORS) of Integer;
--this is needed bc anonymous types are not allowed in declarations
TYPE MESG IS (REQ, PRV);
PACKAGE MESG_IO IS NEW Enumeration_IO(MESG); USE MESG_IO;
--so that we can natively output enumerated type
--linked list portion----------------------------------------------------------
TYPE Node; --fwd declaration needed for self referential structures
TYPE Node_Ptr IS ACCESS Node; --for linking
TYPE Node IS RECORD --list building
myValue : Integer; --node's value
nextNode : Node_Ptr := NULL; --forward chaining
PrevNode : Node_Ptr := NULL; --backward chaining
END RECORD;
----------------------------------
PROCEDURE Enqueue ( --enqueue in linked list
Head : IN OUT Node_Ptr;
in_Value : IN Integer
) IS
tempNode : Node_Ptr;
BEGIN
tempNode := new Node;
tempNode.myValue := in_Value;
IF (Head = NULL) THEN Head := tempNode; --if empty, build list
ELSE --else insert at beginning
tempNode.NextNode := Head;
Head.PrevNode := tempNode;
Head := tempNode;
END IF;
END Enqueue;
----------------------------------
PROCEDURE Dequeue(
Head : IN OUT Node_Ptr;
Value : OUT Integer
) IS
Curr : Node_Ptr; --node iterator
BEGIN
Curr := Head;
IF (Head /= NULL) THEN -- nonempty queue
WHILE (Curr.NextNode /= NULL) --iterate to end of list
LOOP
Curr := Curr.NextNode;
END LOOP;
IF (Curr.PrevNode = NULL) THEN Head := NULL;
ELSE Curr.PrevNode.NextNode := NULL;
END IF;
Value := Curr.myValue;
END IF;
END Dequeue;
----------------------------------
FUNCTION IsEmpty (Head : Node_Ptr)
RETURN Boolean IS
BEGIN
IF (Head = NULL) THEN RETURN TRUE;
ELSE RETURN FALSE; END IF;
END IsEmpty;
--end linked list portion------------------------------------------------------
TASK TYPE RX IS
ENTRY init( myid : Integer; hold : Integer; Neighbor : passableArray);
ENTRY Send (mesgTYPE : MESG; FromId : Integer; ToId : Integer);
END RX;
-- BEGIN Receive TASK Definition --
TASK BODY RX IS
NeighborArray : passableArray; --array of possible holders
HOLDER : Integer; --which node is "higher" in the tree
USING : Boolean := FALSE; --is this node using CS?
REQUEST_Q : Node_Ptr := NULL; --queue of
ASKED : Boolean := FALSE; --am i expceted to provide PRIV?
SELF : Integer; --own ID, for comparison
-- (variable names agree with those given in RAYMOND)
outp : Unbounded_String := Null_Unbounded_String;
--temporary string variable for buffered output
TYPE Message; --fwd declaration, access type
TYPE Message_Ptr IS ACCESS Message; --for self reference
TYPE Message IS RECORD
m_mesgTYPE : MESG; --type of message received
m_fromId : Integer; --from process number
m_toId : Integer; --going to process number (NA)
NextNode,PrevNode : Message_Ptr := NULL; --back,fwd chaining
END RECORD;
MESG_Q : Message_Ptr := NULL; --messages stored in a linked list
-- procedures for Enqueuing and Dequeuing messages
PROCEDURE Message_Enqueue(
Head : IN OUT Message_Ptr;
mesgTYPE : MESG;
fromId : Integer;
toId : Integer
) IS
Item : Message_Ptr;
BEGIN
Item := new Message;
Item.m_mesgTYPE := mesgTYPE;
Item.m_fromId := fromId;
Item.m_toId := toId;
IF (Head = NULL) THEN -- We have an empty queue
Head := Item;
ELSE -- Insert at the beginning
Item.NextNode := Head;
Head.PrevNode := Item;
Head := Item;
END IF;
END Message_Enqueue;
----------------------------------
PROCEDURE Message_Dequeue(
Head : IN out Message_Ptr;
tempMesg : out Message)
IS Curr : Message_Ptr;
BEGIN
Curr := Head;
IF (Head /= NULL) THEN -- non-empty queue
WHILE (Curr.NextNode /= NULL) LOOP Curr := Curr.NextNode; END LOOP;
-- Curr should now point to the last element IN the list --
IF (Curr.PrevNode = NULL)
THEN Head := NULL;
ELSE Curr.PrevNode.NextNode := NULL;
END IF;
tempMesg.m_mesgTYPE := Curr.m_mesgTYPE;
tempMesg.m_fromId := Curr.m_fromId;
tempMesg.m_toId := Curr.m_toId;
END IF;
END Message_Dequeue;
----------------------------------
FUNCTION Message_IsEmpty (Head : Message_Ptr) RETURN Boolean IS
BEGIN
IF (Head = NULL) THEN RETURN TRUE;
ELSE RETURN FALSE;
END IF;
END Message_IsEmpty;
-------------------------------------------------------------------------------
-- Raymond's algorithm routines
-------------------------------------------------------------------------------
-- because ada procedures provide serialization, no extra serialization needed
PROCEDURE ASSIGN_PRIVILEGE IS
BEGIN
IF (HOLDER = SELF) AND (NOT USING) AND (NOT IsEmpty(REQUEST_Q)) THEN
Dequeue(REQUEST_Q, HOLDER);
ASKED := FALSE;
IF HOLDER = SELF THEN
USING := TRUE;
-- Critical Section
outp := (((80/6)*SELF) * " ") & Integer'Image(SELF) & " in CS.";
Put(To_String(outp)); New_line;
delay (Standard.Duration(Random(randomPool) * DELAY_FACTOR));
outp := (((80/6)*SELF) * " ") & Integer'Image(SELF) & " out CS.";
Put(To_String(outp)); New_line;
ELSE TASKarray(HOLDER).Send(PRV, SELF, HOLDER);
END IF;
END IF;
END ASSIGN_PRIVILEGE;
-------------------------------------------------------------------------------
PROCEDURE MAKE_REQUEST IS
BEGIN
IF (HOLDER /= SELF) AND (NOT IsEmpty(REQUEST_Q)) AND (NOT ASKED) THEN
taskArray(HOLDER).Send(REQ, SELF, HOLDER);
ASKED := TRUE;
END IF;
END MAKE_REQUEST;
-------------------------------------------------------------------------------
--ALGORITHM TASK---------------------------------------------------------------
TASK TYPE AL IS END AL;
TASK BODY AL IS
currMessage : Message;
BEGIN
LOOP
--50% chance of waiting, to let someone else try to get in CS
--I'm still having trouble getting it right at 50%
--simulate not entering by simply putting that process on the backburner
IF ((Random(randomPool) * 10.0) > 4.0) THEN--normalize and compare. 50% chance
Delay (Standard.Duration(Random(randomPool) * DELAY_FACTOR));
--spare us the busy waits, save processor time
-- Node now wishes to enter CS
Enqueue(REQUEST_Q, SELF);
ASSIGN_PRIVILEGE;
MAKE_REQUEST;
--!NOTE! peterson's or semaphores NOT needed because procedures are SERIAL calls
--node done CS
USING := FALSE;
ASSIGN_PRIVILEGE;
MAKE_REQUEST;
END IF;
-- Process any messages in the message queue
IF (NOT Message_IsEmpty(MESG_Q)) THEN
Message_Dequeue(MESG_Q, currMessage);
case currMessage.m_mesgTYPE IS
WHEN PRV =>
BEGIN
--outp := (((80/6)*SELF) * " ") &Integer'Image(SELF) & " Holder to self";
--put(To_String(outp)); New_line;
HOLDER := SELF;
ASSIGN_PRIVILEGE;
MAKE_REQUEST;
END;
WHEN REQ =>
BEGIN
Enqueue(REQUEST_Q, currMessage.m_FromId);
ASSIGN_PRIVILEGE;
MAKE_REQUEST;
END;
WHEN Others => NULL; --required by ada standards -- not called
END Case;
ELSE Delay (Standard.Duration(Random(randomPool) * DELAY_FACTOR ));
-- delay to let others in/finish
END IF;
END LOOP;
END AL;
TYPE AL_Ptr IS ACCESS AL;
aPtr : AL_Ptr; --spin off single ALgorithm task for each eexternal RX task
-------------------------------------------------------------------------------
-- BEGIN RX
BEGIN
ACCEPT Init( --simple initializations
myid : Integer;
hold : Integer;
Neighbor : passableArray
) DO
NeighborArray := Neighbor;
HOLDER := hold;
SELF := myid;
END Init;
aPtr := new AL; -- spin off algorithm task
-------------------------------------------------------------------------------
--start receiving messages
LOOP
SELECT
--just plain easier this way, for enqueing and dequeing w/o translation
ACCEPT Send (mesgTYPE : MESG; FromId : Integer; ToId : Integer)
DO
Message_Enqueue (MESG_Q, mesgTYPE, fromId, ToId);
outp := (((80/6)*SELF) * " ") &Integer'Image(SELF) & " " & MESG'Image(MESGTYPE)
& Integer'Image(FromId) & "," & Integer'Image(ToID);
Put(To_String(outp)); New_line;
END Send;
END SELECT;
END LOOP; -- RX LOOP
END RX;
-------------------------------------------------------------------------------
PROCEDURE Driver IS
infile : FILE_TYPE; --ada.standard.textIO type for reading ascii and iso-8XXX
taskId : Integer; --temporary, for task intialization
holder : Integer; --temporary, for task intialization
neighborArray : passableArray; --temporary, for task intialization
neighborCount : Integer := 0; --temp, for filling NeighborArray
seedUser : Integer; --user input random seed FOR random number generator
filename : string(1..5); --what file should we read from?
BEGIN
put_line("Raymond's Tree-based Algorithm");
put("# random seed: ");
get(seedUser); --to ensure a significantly random series, a seed is needed
-- to generate pseudo-random numbers
Ada.Numerics.Float_Random.Reset(randomPool,seedUser);
--seed the random number pool
put("Filename: ");
get(filename);
--first lets read in the
Open (File=> inFile, Mode => IN_FILE, Name => filename);
--open as read only ascii and use reference infile
--file format is: nodeID <initial holder> neighbor ...neighbor [MAX_NEIGHBORS]
WHILE NOT END_OF_FILE(infile)
LOOP
Get(infile, TASKId);
Get(infile, Holder);
WHILE NOT END_OF_LINE(infile)
LOOP
Get( infile, neighborArray(neighborCount) );
neighborCount := neighborCount + 1;
END LOOP;
TASKarray(TASKId) := new RX; --spin task, initialize
TASKarray(TASKId).init( taskId, holder, neighborArray);
END LOOP;
Close(infile);
EXCEPTION
WHEN Name_Error =>
Put(Item => "File not found.");
WHEN Status_Error =>
Put(Item => "File already open.");
WHEN Use_Error =>
Put(Item => "You lack permission to open file");
WHEN constraint_Error =>
Put(Item => "problem IN code! constraint error thrown");
END Driver;
BEGIN Driver; END as6; --seperation of globals
|
-------------------------------------------------------------------------------
-- Copyright (c) 2016 Daniel King
--
-- 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 AUnit.Assertions; use AUnit.Assertions;
with Verhoeff; use Verhoeff;
package body Verhoeff_Tests
is
----------------------------------------------------------------------------
-- Test the example from Wikipedia: https://en.wikipedia.org/wiki/Verhoeff_algorithm
-- (accessed 10th February 2016 at 13:23:00)
--
-- Checks that the string 236 has the check digit 3, and that Is_Valid
-- accepts the check digit.
procedure Test_Case_1(T : in out Test)
is
Test_String : constant String := "236";
Computed_Check_Digit : Digit_Character;
begin
Computed_Check_Digit := Check_Digit(Test_String);
Assert(Computed_Check_Digit = '3',
"wrong check digit returned: " & Computed_Check_Digit);
Assert(Is_Valid(Test_String & Computed_Check_Digit),
"Is_Valid failed");
end Test_Case_1;
----------------------------------------------------------------------------
-- Test the example http://www.augustana.ab.ca/~mohrj/algorithms/checkdigit.html
-- (accessed 10th February 2016 at 13:23:00)
--
-- Checks that the string 12345 has the check digit 1, and that Is_Valid
-- accepts the check digit.
procedure Test_Case_2(T : in out Test)
is
Test_String : constant String := "12345";
Computed_Check_Digit : Digit_Character;
begin
Computed_Check_Digit := Check_Digit(Test_String);
Assert(Computed_Check_Digit = '1',
"wrong check digit returned: " & Computed_Check_Digit);
Assert(Is_Valid(Test_String & Computed_Check_Digit),
"Is_Valid failed");
end Test_Case_2;
----------------------------------------------------------------------------
-- Test that for every possible 6-digit string
-- the resulting check digit is accepted as valid by Is_Valid, and that
-- Is_Valid rejects any other (invalid) check digits.
--
-- This test basically checks the library against itself; that it accepts
-- the check digits it computes and rejects any others.
procedure Test_Symmetry(T : in out Test)
is
Test_String : String(1 .. 6);
Computed_Check_Digit : Digit_Character;
begin
for A in Digit_Character loop
for B in Digit_Character loop
for C in Digit_Character loop
for D in Digit_Character loop
for E in Digit_Character loop
for F in Digit_Character loop
Test_String := String'(A,B,C,D,E,F);
Computed_Check_Digit := Check_Digit(Test_String);
-- Check that the check digit is valid
Assert(Is_Valid(Test_String & Computed_Check_Digit),
"computed check digit is invalid:" &
Test_String & ' ' & Character(Computed_Check_Digit));
-- Check that all other check digits are invalid
Assert((for all Invalid_Check_Digit in Digit_Character'Range =>
(if Invalid_Check_Digit /= Computed_Check_Digit
then not Is_Valid(Test_String & Invalid_Check_Digit)
)
),
"Is_Valid does not reject invalid check digits for: " & Test_String);
end loop;
end loop;
end loop;
end loop;
end loop;
end loop;
end Test_Symmetry;
----------------------------------------------------------------------------
-- Test the check digit of the empty string.
--
-- The check digit of an empty string should be 0.
procedure Test_Empty(T : in out Test)
is
begin
Assert(Check_Digit("") = '0',
"check digit of an empty string is not 0");
Assert(Is_Valid("0"),
"Is_Valid failed");
end Test_Empty;
end Verhoeff_Tests;
|
-- Copyright (c) 1990 Regents of the University of California.
-- All rights reserved.
--
-- This software was developed by John Self of the Arcadia project
-- at the University of California, Irvine.
--
-- Redistribution and use in source and binary forms are permitted
-- provided that the above copyright notice and this paragraph are
-- duplicated in all such forms and that any documentation,
-- advertising materials, and other materials related to such
-- distribution and use acknowledge that the software was developed
-- by the University of California, Irvine. The name of the
-- University may not be used to endorse or promote products derived
-- from this software without specific prior written permission.
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
-- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-- WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-- TITLE symbol table routines
-- AUTHOR: John Self (UCI)
-- DESCRIPTION implements only a simple symbol table using open hashing
-- NOTES could be faster, but it isn't used much
-- $Header: /co/ua/self/arcadia/aflex/ada/src/RCS/symS.a,v 1.4 90/01/12 15:20:42 self Exp Locker: self $
with Ada.Strings.Wide_Wide_Unbounded;
with MISC_DEFS;
package SYM is
use MISC_DEFS;
procedure ADDSYM
(SYM, STR_DEF : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
INT_DEF : in INTEGER;
TABLE : in out HASH_TABLE;
TABLE_SIZE : in INTEGER;
RESULT : out BOOLEAN);
-- result indicates success
procedure CCLINSTAL
(CCLTXT : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
CCLNUM : INTEGER);
function CCLLOOKUP
(CCLTXT : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String)
return INTEGER;
function FINDSYM
(SYMBOL : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
TABLE : HASH_TABLE;
TABLE_SIZE : INTEGER) return HASH_LINK;
function HASHFUNCT
(STR : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
HASH_SIZE : INTEGER) return INTEGER;
procedure NDINSTAL
(ND, DEF : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String);
function NDLOOKUP
(ND : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String)
return Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
procedure SCINSTAL
(STR : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
XCLUFLG : Boolean);
function SCLOOKUP
(STR : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String)
return Integer;
end SYM;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Test is
X: Integer;
procedure P is
type X is record A: Integer; end record;
V: X;
begin
New_Line;
end;
begin
P;
end;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . T A S K _ L O C K --
-- --
-- S p e c --
-- --
-- Copyright (C) 1998-2020, AdaCore --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
-- Simple task lock and unlock routines
-- A small package containing a task lock and unlock routines for creating
-- a critical region. The lock involved is a global lock, shared by all
-- tasks, and by all calls to these routines, so these routines should be
-- used with care to avoid unnecessary reduction of concurrency.
-- These routines may be used in a non-tasking program, and in that case
-- they have no effect (they do NOT cause the tasking runtime to be loaded).
-- Note: this package is in the System hierarchy so that it can be directly
-- be used by other predefined packages. User access to this package is via
-- a renaming of this package in GNAT.Task_Lock (file g-tasloc.ads).
package System.Task_Lock is
pragma Preelaborate;
procedure Lock;
pragma Inline (Lock);
-- Acquires the global lock, starts the execution of a critical region
-- which no other task can enter until the locking task calls Unlock
procedure Unlock;
pragma Inline (Unlock);
-- Releases the global lock, allowing another task to successfully
-- complete a Lock operation. Terminates the critical region.
--
-- The recommended protocol for using these two procedures is as
-- follows:
--
-- Locked_Processing : begin
-- Lock;
-- ...
-- TSL.Unlock;
--
-- exception
-- when others =>
-- Unlock;
-- raise;
-- end Locked_Processing;
--
-- This ensures that the lock is not left set if an exception is raised
-- explicitly or implicitly during the critical locked region.
--
-- Note on multiple calls to Lock: It is permissible to call Lock
-- more than once with no intervening Unlock from a single task,
-- and the lock will not be released until the corresponding number
-- of Unlock operations has been performed. For example:
--
-- System.Task_Lock.Lock; -- acquires lock
-- System.Task_Lock.Lock; -- no effect
-- System.Task_Lock.Lock; -- no effect
-- System.Task_Lock.Unlock; -- no effect
-- System.Task_Lock.Unlock; -- no effect
-- System.Task_Lock.Unlock; -- releases lock
--
-- However, as previously noted, the Task_Lock facility should only
-- be used for very local locks where the probability of conflict is
-- low, so usually this kind of nesting is not a good idea in any case.
-- In more complex locking situations, it is more appropriate to define
-- an appropriate protected type to provide the required locking.
--
-- It is an error to call Unlock when there has been no prior call to
-- Lock. The effect of such an erroneous call is undefined, and may
-- result in deadlock, or other malfunction of the run-time system.
end System.Task_Lock;
|
--===========================================================================
--
-- This package implements the slave configuration for the Pico
--
--===========================================================================
--
-- Copyright 2022 (C) Holger Rodriguez
--
-- SPDX-License-Identifier: BSD-3-Clause
--
package body SPI_Slave_Pico is
-----------------------------------------------------------------------
-- see .ads
procedure Initialize is
begin
SCK.Configure (RP.GPIO.Input, RP.GPIO.Floating, RP.GPIO.SPI);
NSS.Configure (RP.GPIO.Input, RP.GPIO.Floating, RP.GPIO.SPI);
MOSI.Configure (RP.GPIO.Input, RP.GPIO.Floating, RP.GPIO.SPI);
MISO.Configure (RP.GPIO.Output, RP.GPIO.Floating, RP.GPIO.SPI);
SPI.Configure (Config);
end Initialize;
end SPI_Slave_Pico;
|
package body Ada12 is
function Max (X, Y : Integer) return Integer is
(if X > Y then X else Y);
end Ada12;
|
-----------------------------------------------------------------------
-- util-processes-tests - Test for processes
-- Copyright (C) 2011, 2016, 2018, 2019, 2021 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.Tests;
package Util.Processes.Tests is
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite);
type Test is new Util.Tests.Test with null record;
-- Tests when the process is not launched
procedure Test_No_Process (T : in out Test);
-- Test executing a process
procedure Test_Spawn (T : in out Test);
-- Test output pipe redirection: read the process standard output
procedure Test_Output_Pipe (T : in out Test);
-- Test input pipe redirection: write the process standard input
procedure Test_Input_Pipe (T : in out Test);
-- Test error pipe redirection: read the process standard error
procedure Test_Error_Pipe (T : in out Test);
-- Test shell splitting.
procedure Test_Shell_Splitting_Pipe (T : in out Test);
-- Test launching several processes through pipes in several threads.
procedure Test_Multi_Spawn (T : in out Test);
-- Test output file redirection.
procedure Test_Output_Redirect (T : in out Test);
-- Test input file redirection.
procedure Test_Input_Redirect (T : in out Test);
-- Test changing working directory.
procedure Test_Set_Working_Directory (T : in out Test);
-- Test various errors.
procedure Test_Errors (T : in out Test);
-- Test launching and stopping a process.
procedure Test_Stop (T : in out Test);
-- Test various errors (pipe streams).
procedure Test_Pipe_Errors (T : in out Test);
-- Test launching and stopping a process (pipe streams).
procedure Test_Pipe_Stop (T : in out Test);
-- Test the Tools.Execute operation.
procedure Test_Tools_Execute (T : in out Test);
end Util.Processes.Tests;
|
with Ada.Real_Time;
with ACO.Drivers.Stm32f40x;
with STM32.Device;
with ACO.Nodes;
with ACO.OD.Example;
with ACO.CANopen;
with ACO.Nodes.Remotes;
with ACO.OD_Types;
with ACO.OD_Types.Entries;
with ACO.SDO_Sessions;
package body App is
D : aliased ACO.Drivers.Stm32f40x.CAN_Driver (STM32.Device.CAN_1'Access);
H : aliased ACO.CANopen.Handler (Driver => D'Access);
T : ACO.CANopen.Periodic_Task (H'Access, 10);
O : aliased ACO.OD.Example.Dictionary;
procedure Run
is
use Ada.Real_Time;
N : aliased ACO.Nodes.Remotes.Remote (Id => 1, Handler => H'Access, Od => O'Access);
Next_Release : Time := Clock;
begin
D.Initialize;
N.Start;
loop
-- H.Periodic_Actions (T_Now => Next_Release);
declare
use ACO.OD_Types.Entries;
An_Entry : constant Entry_U8 :=
Create (Accessability => ACO.OD_Types.RW,
Data => 0);
Req : ACO.Nodes.Remotes.SDO_Write_Request (N'Access);
Result : ACO.Nodes.Remotes.SDO_Result;
begin
N.Write (Request => Req,
Index => 16#1000#,
Subindex => 1,
An_Entry => An_Entry);
Req.Suspend_Until_Result (Result);
case Req.Status is
when ACO.SDO_Sessions.Complete =>
null;
when ACO.SDO_Sessions.Error =>
null;
when ACO.SDO_Sessions.Pending =>
null;
end case;
end;
Next_Release := Next_Release + Milliseconds (10);
delay until Next_Release;
end loop;
end Run;
end App;
|
-- ////////////////////////////////////////////////////////////
-- //
-- // SFML - Simple and Fast Multimedia Library
-- // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
-- //
-- // This software is provided 'as-is', without any express or implied warranty.
-- // In no event will the authors be held liable for any damages arising from the use of this software.
-- //
-- // Permission is granted to anyone to use this software for any purpose,
-- // including commercial applications, and to alter it and redistribute it freely,
-- // subject to the following restrictions:
-- //
-- // 1. The origin of this software must not be misrepresented;
-- // you must not claim that you wrote the original software.
-- // If you use this software in a product, an acknowledgment
-- // in the product documentation would be appreciated but is not required.
-- //
-- // 2. Altered source versions must be plainly marked as such,
-- // and must not be misrepresented as being the original software.
-- //
-- // 3. This notice may not be removed or altered from any source distribution.
-- //
-- ////////////////////////////////////////////////////////////
-- ////////////////////////////////////////////////////////////
-- // Headers
-- ////////////////////////////////////////////////////////////
with Sf.Config;
package Sf.Graphics.Color is
use Sf.Config;
-- ////////////////////////////////////////////////////////////
-- /// sfColor is an utility class for manipulating colors
-- ////////////////////////////////////////////////////////////
type sfColor is record
r : aliased sfUint8;
g : aliased sfUint8;
b : aliased sfUint8;
a : aliased sfUint8;
end record;
pragma Convention (C_Pass_By_Copy, sfColor);
-- ////////////////////////////////////////////////////////////
-- /// Define some common colors
-- ////////////////////////////////////////////////////////////
sfBlack : constant sfColor := (0, 0, 0, 255);
sfWhite : constant sfColor := (255, 255, 255, 255);
sfRed : constant sfColor := (255, 0, 0, 255);
sfGreen : constant sfColor := (0, 255, 0, 255);
sfBlue : constant sfColor := (0, 0, 255, 255);
sfYellow : constant sfColor := (255, 255, 0, 255);
sfMagenta : constant sfColor := (255, 0, 255, 255);
sfCyan : constant sfColor := (0, 255, 255, 255);
-- ////////////////////////////////////////////////////////////
-- /// Construct a color from its 3 RGB components
-- ///
-- /// \param R : Red component (0 .. 255)
-- /// \param G : Green component (0 .. 255)
-- /// \param B : Blue component (0 .. 255)
-- ///
-- /// \return sfColor constructed from the components
-- ///
-- ////////////////////////////////////////////////////////////
function sfColor_FromRGB (R, G, B : sfUint8) return sfColor;
-- ////////////////////////////////////////////////////////////
-- /// Construct a color from its 4 RGBA components
-- ///
-- /// \param R : Red component (0 .. 255)
-- /// \param G : Green component (0 .. 255)
-- /// \param B : Blue component (0 .. 255)
-- /// \param A : Alpha component (0 .. 255)
-- ///
-- /// \return sfColor constructed from the components
-- ///
-- ////////////////////////////////////////////////////////////
function sfColor_FromRGBA (R, G, B, A : sfUint8) return sfColor;
-- ////////////////////////////////////////////////////////////
-- /// Add two colors
-- ///
-- /// \param Color1 : First color
-- /// \param Color2 : Second color
-- ///
-- /// \return Component-wise saturated addition of the two colors
-- ///
-- ////////////////////////////////////////////////////////////
function sfColor_Add (Color1, Color2 : sfColor) return sfColor;
-- ////////////////////////////////////////////////////////////
-- /// Modulate two colors
-- ///
-- /// \param Color1 : First color
-- /// \param Color2 : Second color
-- ///
-- /// \return Component-wise multiplication of the two colors
-- ///
-- ////////////////////////////////////////////////////////////
function sfColor_Modulate (Color1, Color2 : sfColor) return sfColor;
private
pragma Import (C, sfColor_FromRGB, "sfColor_FromRGB");
pragma Import (C, sfColor_FromRGBA, "sfColor_FromRGBA");
pragma Import (C, sfColor_Add, "sfColor_Add");
pragma Import (C, sfColor_Modulate, "sfColor_Modulate");
end Sf.Graphics.Color;
|
-----------------------------------------------------------------------
-- demos -- Utility package for the demos
-- Copyright (C) 2016, 2017 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;
with BMP_Fonts;
with STM32.Board;
with HAL.Bitmap;
with Net;
with Net.Buffers;
with Net.Interfaces;
with Net.Interfaces.STM32;
with Net.DHCP;
package Demos is
use type Interfaces.Unsigned_32;
-- Reserve 256 network buffers.
NET_BUFFER_SIZE : constant Net.Uint32 := Net.Buffers.NET_ALLOC_SIZE * 256;
-- The Ethernet interface driver.
Ifnet : aliased Net.Interfaces.STM32.STM32_Ifnet;
-- The DHCP client used by the demos.
Dhcp : aliased Net.DHCP.Client;
Current_Font : BMP_Fonts.BMP_Font := BMP_Fonts.Font12x12;
Foreground : HAL.Bitmap.Bitmap_Color := HAL.Bitmap.White;
Background : HAL.Bitmap.Bitmap_Color := HAL.Bitmap.Black;
-- Write a message on the display.
procedure Put (X : in Natural;
Y : in Natural;
Msg : in String);
-- Write the 64-bit integer value on the display.
procedure Put (X : in Natural;
Y : in Natural;
Value : in Net.Uint64);
-- Refresh the ifnet statistics on the display.
procedure Refresh_Ifnet_Stats;
-- Initialize the board and the interface.
generic
with procedure Header;
procedure Initialize (Title : in String);
pragma Warnings (Off);
-- Get the default font size according to the display size.
function Default_Font return BMP_Fonts.BMP_Font is
(if STM32.Board.LCD_Natural_Width > 480 then BMP_Fonts.Font12x12 else BMP_Fonts.Font8x8);
end Demos;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ C H 3 --
-- --
-- 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 Elists; use Elists;
with Einfo; use Einfo;
with Errout; use Errout;
with Eval_Fat; use Eval_Fat;
with Exp_Ch3; use Exp_Ch3;
with Exp_Dist; use Exp_Dist;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Freeze; use Freeze;
with Itypes; use Itypes;
with Layout; use Layout;
with Lib; use Lib;
with Lib.Xref; use Lib.Xref;
with Namet; use Namet;
with Nmake; use Nmake;
with Opt; use Opt;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Case; use Sem_Case;
with Sem_Cat; use Sem_Cat;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch7; use Sem_Ch7;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch13; use Sem_Ch13;
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_Res; use Sem_Res;
with Sem_Smem; use Sem_Smem;
with Sem_Type; use Sem_Type;
with Sem_Util; use Sem_Util;
with Sem_Warn; use Sem_Warn;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uintp; use Uintp;
with Urealp; use Urealp;
package body Sem_Ch3 is
-----------------------
-- Local Subprograms --
-----------------------
procedure Add_Interface_Tag_Components
(N : Node_Id; Typ : Entity_Id);
-- Ada 2005 (AI-251): Add the tag components corresponding to all the
-- abstract interface types implemented by a record type or a derived
-- record type.
procedure Build_Derived_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id;
Is_Completion : Boolean;
Derive_Subps : Boolean := True);
-- Create and decorate a Derived_Type given the Parent_Type entity. N is
-- the N_Full_Type_Declaration node containing the derived type definition.
-- Parent_Type is the entity for the parent type in the derived type
-- definition and Derived_Type the actual derived type. Is_Completion must
-- be set to False if Derived_Type is the N_Defining_Identifier node in N
-- (ie Derived_Type = Defining_Identifier (N)). In this case N is not the
-- completion of a private type declaration. If Is_Completion is set to
-- True, N is the completion of a private type declaration and Derived_Type
-- is different from the defining identifier inside N (i.e. Derived_Type /=
-- Defining_Identifier (N)). Derive_Subps indicates whether the parent
-- subprograms should be derived. The only case where this parameter is
-- False is when Build_Derived_Type is recursively called to process an
-- implicit derived full type for a type derived from a private type (in
-- that case the subprograms must only be derived for the private view of
-- the type).
-- ??? These flags need a bit of re-examination and re-documentation:
-- ??? are they both necessary (both seem related to the recursion)?
procedure Build_Derived_Access_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id);
-- Subsidiary procedure to Build_Derived_Type. For a derived access type,
-- create an implicit base if the parent type is constrained or if the
-- subtype indication has a constraint.
procedure Build_Derived_Array_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id);
-- Subsidiary procedure to Build_Derived_Type. For a derived array type,
-- create an implicit base if the parent type is constrained or if the
-- subtype indication has a constraint.
procedure Build_Derived_Concurrent_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id);
-- Subsidiary procedure to Build_Derived_Type. For a derived task or pro-
-- tected type, inherit entries and protected subprograms, check legality
-- of discriminant constraints if any.
procedure Build_Derived_Enumeration_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id);
-- Subsidiary procedure to Build_Derived_Type. For a derived enumeration
-- type, we must create a new list of literals. Types derived from
-- Character and Wide_Character are special-cased.
procedure Build_Derived_Numeric_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id);
-- Subsidiary procedure to Build_Derived_Type. For numeric types, create
-- an anonymous base type, and propagate constraint to subtype if needed.
procedure Build_Derived_Private_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id;
Is_Completion : Boolean;
Derive_Subps : Boolean := True);
-- Subsidiary procedure to Build_Derived_Type. This procedure is complex
-- because the parent may or may not have a completion, and the derivation
-- may itself be a completion.
procedure Build_Derived_Record_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id;
Derive_Subps : Boolean := True);
-- Subsidiary procedure for Build_Derived_Type and
-- Analyze_Private_Extension_Declaration used for tagged and untagged
-- record types. All parameters are as in Build_Derived_Type except that
-- N, in addition to being an N_Full_Type_Declaration node, can also be an
-- N_Private_Extension_Declaration node. See the definition of this routine
-- for much more info. Derive_Subps indicates whether subprograms should
-- be derived from the parent type. The only case where Derive_Subps is
-- False is for an implicit derived full type for a type derived from a
-- private type (see Build_Derived_Type).
procedure Complete_Subprograms_Derivation
(Partial_View : Entity_Id;
Derived_Type : Entity_Id);
-- Ada 2005 (AI-251): Used to complete type derivation of private tagged
-- types implementing interfaces. In this case some interface primitives
-- may have been overriden with the partial-view and, instead of
-- re-calculating them, they are included in the list of primitive
-- operations of the full-view.
function Inherit_Components
(N : Node_Id;
Parent_Base : Entity_Id;
Derived_Base : Entity_Id;
Is_Tagged : Boolean;
Inherit_Discr : Boolean;
Discs : Elist_Id) return Elist_Id;
-- Called from Build_Derived_Record_Type to inherit the components of
-- Parent_Base (a base type) into the Derived_Base (the derived base type).
-- For more information on derived types and component inheritance please
-- consult the comment above the body of Build_Derived_Record_Type.
--
-- N is the original derived type declaration
--
-- Is_Tagged is set if we are dealing with tagged types
--
-- If Inherit_Discr is set, Derived_Base inherits its discriminants
-- from Parent_Base, otherwise no discriminants are inherited.
--
-- Discs gives the list of constraints that apply to Parent_Base in the
-- derived type declaration. If Discs is set to No_Elist, then we have
-- the following situation:
--
-- type Parent (D1..Dn : ..) is [tagged] record ...;
-- type Derived is new Parent [with ...];
--
-- which gets treated as
--
-- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
--
-- For untagged types the returned value is an association list. The list
-- starts from the association (Parent_Base => Derived_Base), and then it
-- contains a sequence of the associations of the form
--
-- (Old_Component => New_Component),
--
-- where Old_Component is the Entity_Id of a component in Parent_Base
-- and New_Component is the Entity_Id of the corresponding component
-- in Derived_Base. For untagged records, this association list is
-- needed when copying the record declaration for the derived base.
-- In the tagged case the value returned is irrelevant.
procedure Build_Discriminal (Discrim : Entity_Id);
-- Create the discriminal corresponding to discriminant Discrim, that is
-- the parameter corresponding to Discrim to be used in initialization
-- procedures for the type where Discrim is a discriminant. Discriminals
-- are not used during semantic analysis, and are not fully defined
-- entities until expansion. Thus they are not given a scope until
-- initialization procedures are built.
function Build_Discriminant_Constraints
(T : Entity_Id;
Def : Node_Id;
Derived_Def : Boolean := False) return Elist_Id;
-- Validate discriminant constraints, and return the list of the
-- constraints in order of discriminant declarations. T is the
-- discriminated unconstrained type. Def is the N_Subtype_Indication node
-- where the discriminants constraints for T are specified. Derived_Def is
-- True if we are building the discriminant constraints in a derived type
-- definition of the form "type D (...) is new T (xxx)". In this case T is
-- the parent type and Def is the constraint "(xxx)" on T and this routine
-- sets the Corresponding_Discriminant field of the discriminants in the
-- derived type D to point to the corresponding discriminants in the parent
-- type T.
procedure Build_Discriminated_Subtype
(T : Entity_Id;
Def_Id : Entity_Id;
Elist : Elist_Id;
Related_Nod : Node_Id;
For_Access : Boolean := False);
-- Subsidiary procedure to Constrain_Discriminated_Type and to
-- Process_Incomplete_Dependents. Given
--
-- T (a possibly discriminated base type)
-- Def_Id (a very partially built subtype for T),
--
-- the call completes Def_Id to be the appropriate E_*_Subtype.
--
-- The Elist is the list of discriminant constraints if any (it is set to
-- No_Elist if T is not a discriminated type, and to an empty list if
-- T has discriminants but there are no discriminant constraints). The
-- Related_Nod is the same as Decl_Node in Create_Constrained_Components.
-- The For_Access says whether or not this subtype is really constraining
-- an access type. That is its sole purpose is the designated type of an
-- access type -- in which case a Private_Subtype Is_For_Access_Subtype
-- is built to avoid freezing T when the access subtype is frozen.
function Build_Scalar_Bound
(Bound : Node_Id;
Par_T : Entity_Id;
Der_T : Entity_Id) return Node_Id;
-- The bounds of a derived scalar type are conversions of the bounds of
-- the parent type. Optimize the representation if the bounds are literals.
-- Needs a more complete spec--what are the parameters exactly, and what
-- exactly is the returned value, and how is Bound affected???
procedure Build_Underlying_Full_View
(N : Node_Id;
Typ : Entity_Id;
Par : Entity_Id);
-- If the completion of a private type is itself derived from a private
-- type, or if the full view of a private subtype is itself private, the
-- back-end has no way to compute the actual size of this type. We build
-- an internal subtype declaration of the proper parent type to convey
-- this information. This extra mechanism is needed because a full
-- view cannot itself have a full view (it would get clobbered during
-- view exchanges).
procedure Check_Access_Discriminant_Requires_Limited
(D : Node_Id;
Loc : Node_Id);
-- Check the restriction that the type to which an access discriminant
-- belongs must be a concurrent type or a descendant of a type with
-- the reserved word 'limited' in its declaration.
procedure Check_Delta_Expression (E : Node_Id);
-- Check that the expression represented by E is suitable for use
-- as a delta expression, i.e. it is of real type and is static.
procedure Check_Digits_Expression (E : Node_Id);
-- Check that the expression represented by E is suitable for use as
-- a digits expression, i.e. it is of integer type, positive and static.
procedure Check_Initialization (T : Entity_Id; Exp : Node_Id);
-- Validate the initialization of an object declaration. T is the
-- required type, and Exp is the initialization expression.
procedure Check_Or_Process_Discriminants
(N : Node_Id;
T : Entity_Id;
Prev : Entity_Id := Empty);
-- If T is the full declaration of an incomplete or private type, check
-- the conformance of the discriminants, otherwise process them. Prev
-- is the entity of the partial declaration, if any.
procedure Check_Real_Bound (Bound : Node_Id);
-- Check given bound for being of real type and static. If not, post an
-- appropriate message, and rewrite the bound with the real literal zero.
procedure Constant_Redeclaration
(Id : Entity_Id;
N : Node_Id;
T : out Entity_Id);
-- Various checks on legality of full declaration of deferred constant.
-- Id is the entity for the redeclaration, N is the N_Object_Declaration,
-- node. The caller has not yet set any attributes of this entity.
procedure Convert_Scalar_Bounds
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id;
Loc : Source_Ptr);
-- For derived scalar types, convert the bounds in the type definition
-- to the derived type, and complete their analysis. Given a constraint
-- of the form:
-- .. new T range Lo .. Hi;
-- Lo and Hi are analyzed and resolved with T'Base, the parent_type.
-- The bounds of the derived type (the anonymous base) are copies of
-- Lo and Hi. Finally, the bounds of the derived subtype are conversions
-- of those bounds to the derived_type, so that their typing is
-- consistent.
procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id);
-- Copies attributes from array base type T2 to array base type T1.
-- Copies only attributes that apply to base types, but not subtypes.
procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id);
-- Copies attributes from array subtype T2 to array subtype T1. Copies
-- attributes that apply to both subtypes and base types.
procedure Create_Constrained_Components
(Subt : Entity_Id;
Decl_Node : Node_Id;
Typ : Entity_Id;
Constraints : Elist_Id);
-- Build the list of entities for a constrained discriminated record
-- subtype. If a component depends on a discriminant, replace its subtype
-- using the discriminant values in the discriminant constraint.
-- Subt is the defining identifier for the subtype whose list of
-- constrained entities we will create. Decl_Node is the type declaration
-- node where we will attach all the itypes created. Typ is the base
-- discriminated type for the subtype Subt. Constraints is the list of
-- discriminant constraints for Typ.
function Constrain_Component_Type
(Comp : Entity_Id;
Constrained_Typ : Entity_Id;
Related_Node : Node_Id;
Typ : Entity_Id;
Constraints : Elist_Id) return Entity_Id;
-- Given a discriminated base type Typ, a list of discriminant constraint
-- Constraints for Typ and a component of Typ, with type Compon_Type,
-- create and return the type corresponding to Compon_type where all
-- discriminant references are replaced with the corresponding
-- constraint. If no discriminant references occur in Compon_Typ then
-- return it as is. Constrained_Typ is the final constrained subtype to
-- which the constrained Compon_Type belongs. Related_Node is the node
-- where we will attach all the itypes created.
procedure Constrain_Access
(Def_Id : in out Entity_Id;
S : Node_Id;
Related_Nod : Node_Id);
-- Apply a list of constraints to an access type. If Def_Id is empty, it is
-- an anonymous type created for a subtype indication. In that case it is
-- created in the procedure and attached to Related_Nod.
procedure Constrain_Array
(Def_Id : in out Entity_Id;
SI : Node_Id;
Related_Nod : Node_Id;
Related_Id : Entity_Id;
Suffix : Character);
-- Apply a list of index constraints to an unconstrained array type. The
-- first parameter is the entity for the resulting subtype. A value of
-- Empty for Def_Id indicates that an implicit type must be created, but
-- creation is delayed (and must be done by this procedure) because other
-- subsidiary implicit types must be created first (which is why Def_Id
-- is an in/out parameter). The second parameter is a subtype indication
-- node for the constrained array to be created (e.g. something of the
-- form string (1 .. 10)). Related_Nod gives the place where this type
-- has to be inserted in the tree. The Related_Id and Suffix parameters
-- are used to build the associated Implicit type name.
procedure Constrain_Concurrent
(Def_Id : in out Entity_Id;
SI : Node_Id;
Related_Nod : Node_Id;
Related_Id : Entity_Id;
Suffix : Character);
-- Apply list of discriminant constraints to an unconstrained concurrent
-- type.
--
-- SI is the N_Subtype_Indication node containing the constraint and
-- the unconstrained type to constrain.
--
-- Def_Id is the entity for the resulting constrained subtype. A value
-- of Empty for Def_Id indicates that an implicit type must be created,
-- but creation is delayed (and must be done by this procedure) because
-- other subsidiary implicit types must be created first (which is why
-- Def_Id is an in/out parameter).
--
-- Related_Nod gives the place where this type has to be inserted
-- in the tree
--
-- The last two arguments are used to create its external name if needed.
function Constrain_Corresponding_Record
(Prot_Subt : Entity_Id;
Corr_Rec : Entity_Id;
Related_Nod : Node_Id;
Related_Id : Entity_Id) return Entity_Id;
-- When constraining a protected type or task type with discriminants,
-- constrain the corresponding record with the same discriminant values.
procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id);
-- Constrain a decimal fixed point type with a digits constraint and/or a
-- range constraint, and build E_Decimal_Fixed_Point_Subtype entity.
procedure Constrain_Discriminated_Type
(Def_Id : Entity_Id;
S : Node_Id;
Related_Nod : Node_Id;
For_Access : Boolean := False);
-- Process discriminant constraints of composite type. Verify that values
-- have been provided for all discriminants, that the original type is
-- unconstrained, and that the types of the supplied expressions match
-- the discriminant types. The first three parameters are like in routine
-- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation
-- of For_Access.
procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id);
-- Constrain an enumeration type with a range constraint. This is identical
-- to Constrain_Integer, but for the Ekind of the resulting subtype.
procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id);
-- Constrain a floating point type with either a digits constraint
-- and/or a range constraint, building a E_Floating_Point_Subtype.
procedure Constrain_Index
(Index : Node_Id;
S : Node_Id;
Related_Nod : Node_Id;
Related_Id : Entity_Id;
Suffix : Character;
Suffix_Index : Nat);
-- Process an index constraint in a constrained array declaration. The
-- constraint can be a subtype name, or a range with or without an
-- explicit subtype mark. The index is the corresponding index of the
-- unconstrained array. The Related_Id and Suffix parameters are used to
-- build the associated Implicit type name.
procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id);
-- Build subtype of a signed or modular integer type
procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id);
-- Constrain an ordinary fixed point type with a range constraint, and
-- build an E_Ordinary_Fixed_Point_Subtype entity.
procedure Copy_And_Swap (Priv, Full : Entity_Id);
-- Copy the Priv entity into the entity of its full declaration
-- then swap the two entities in such a manner that the former private
-- type is now seen as a full type.
procedure Decimal_Fixed_Point_Type_Declaration
(T : Entity_Id;
Def : Node_Id);
-- Create a new decimal fixed point type, and apply the constraint to
-- obtain a subtype of this new type.
procedure Complete_Private_Subtype
(Priv : Entity_Id;
Full : Entity_Id;
Full_Base : Entity_Id;
Related_Nod : Node_Id);
-- Complete the implicit full view of a private subtype by setting the
-- appropriate semantic fields. If the full view of the parent is a record
-- type, build constrained components of subtype.
procedure Derive_Interface_Subprograms
(Derived_Type : Entity_Id);
-- Ada 2005 (AI-251): Subsidiary procedure to Build_Derived_Record_Type.
-- Traverse the list of implemented interfaces and derive all their
-- subprograms.
procedure Derived_Standard_Character
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id);
-- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
-- derivations from types Standard.Character and Standard.Wide_Character.
procedure Derived_Type_Declaration
(T : Entity_Id;
N : Node_Id;
Is_Completion : Boolean);
-- Process a derived type declaration. This routine will invoke
-- Build_Derived_Type to process the actual derived type definition.
-- Parameters N and Is_Completion have the same meaning as in
-- Build_Derived_Type. T is the N_Defining_Identifier for the entity
-- defined in the N_Full_Type_Declaration node N, that is T is the derived
-- type.
procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id);
-- Insert each literal in symbol table, as an overloadable identifier. Each
-- enumeration type is mapped into a sequence of integers, and each literal
-- is defined as a constant with integer value. If any of the literals are
-- character literals, the type is a character type, which means that
-- strings are legal aggregates for arrays of components of the type.
function Expand_To_Stored_Constraint
(Typ : Entity_Id;
Constraint : Elist_Id) return Elist_Id;
-- Given a Constraint (i.e. a list of expressions) on the discriminants of
-- Typ, expand it into a constraint on the stored discriminants and return
-- the new list of expressions constraining the stored discriminants.
function Find_Type_Of_Object
(Obj_Def : Node_Id;
Related_Nod : Node_Id) return Entity_Id;
-- Get type entity for object referenced by Obj_Def, attaching the
-- implicit types generated to Related_Nod
procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id);
-- Create a new float, and apply the constraint to obtain subtype of it
function Has_Range_Constraint (N : Node_Id) return Boolean;
-- Given an N_Subtype_Indication node N, return True if a range constraint
-- is present, either directly, or as part of a digits or delta constraint.
-- In addition, a digits constraint in the decimal case returns True, since
-- it establishes a default range if no explicit range is present.
function Is_Valid_Constraint_Kind
(T_Kind : Type_Kind;
Constraint_Kind : Node_Kind) return Boolean;
-- Returns True if it is legal to apply the given kind of constraint to the
-- given kind of type (index constraint to an array type, for example).
procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id);
-- Create new modular type. Verify that modulus is in bounds and is
-- a power of two (implementation restriction).
procedure New_Concatenation_Op (Typ : Entity_Id);
-- Create an abbreviated declaration for an operator in order to
-- materialize concatenation on array types.
procedure Ordinary_Fixed_Point_Type_Declaration
(T : Entity_Id;
Def : Node_Id);
-- Create a new ordinary fixed point type, and apply the constraint to
-- obtain subtype of it.
procedure Prepare_Private_Subtype_Completion
(Id : Entity_Id;
Related_Nod : Node_Id);
-- Id is a subtype of some private type. Creates the full declaration
-- associated with Id whenever possible, i.e. when the full declaration
-- of the base type is already known. Records each subtype into
-- Private_Dependents of the base type.
procedure Process_Incomplete_Dependents
(N : Node_Id;
Full_T : Entity_Id;
Inc_T : Entity_Id);
-- Process all entities that depend on an incomplete type. There include
-- subtypes, subprogram types that mention the incomplete type in their
-- profiles, and subprogram with access parameters that designate the
-- incomplete type.
-- Inc_T is the defining identifier of an incomplete type declaration, its
-- Ekind is E_Incomplete_Type.
--
-- N is the corresponding N_Full_Type_Declaration for Inc_T.
--
-- Full_T is N's defining identifier.
--
-- Subtypes of incomplete types with discriminants are completed when the
-- parent type is. This is simpler than private subtypes, because they can
-- only appear in the same scope, and there is no need to exchange views.
-- Similarly, access_to_subprogram types may have a parameter or a return
-- type that is an incomplete type, and that must be replaced with the
-- full type.
-- If the full type is tagged, subprogram with access parameters that
-- designated the incomplete may be primitive operations of the full type,
-- and have to be processed accordingly.
procedure Process_Real_Range_Specification (Def : Node_Id);
-- Given the type definition for a real type, this procedure processes
-- and checks the real range specification of this type definition if
-- one is present. If errors are found, error messages are posted, and
-- the Real_Range_Specification of Def is reset to Empty.
procedure Record_Type_Declaration
(T : Entity_Id;
N : Node_Id;
Prev : Entity_Id);
-- Process a record type declaration (for both untagged and tagged
-- records). Parameters T and N are exactly like in procedure
-- Derived_Type_Declaration, except that no flag Is_Completion is needed
-- for this routine. If this is the completion of an incomplete type
-- declaration, Prev is the entity of the incomplete declaration, used for
-- cross-referencing. Otherwise Prev = T.
procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id);
-- This routine is used to process the actual record type definition
-- (both for untagged and tagged records). Def is a record type
-- definition node. This procedure analyzes the components in this
-- record type definition. Prev_T is the entity for the enclosing record
-- type. It is provided so that its Has_Task flag can be set if any of
-- the component have Has_Task set. If the declaration is the completion
-- of an incomplete type declaration, Prev_T is the original incomplete
-- type, whose full view is the record type.
procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id);
-- Subsidiary to Build_Derived_Record_Type. For untagged records, we
-- build a copy of the declaration tree of the parent, and we create
-- independently the list of components for the derived type. Semantic
-- information uses the component entities, but record representation
-- clauses are validated on the declaration tree. This procedure replaces
-- discriminants and components in the declaration with those that have
-- been created by Inherit_Components.
procedure Set_Fixed_Range
(E : Entity_Id;
Loc : Source_Ptr;
Lo : Ureal;
Hi : Ureal);
-- Build a range node with the given bounds and set it as the Scalar_Range
-- of the given fixed-point type entity. Loc is the source location used
-- for the constructed range. See body for further details.
procedure Set_Scalar_Range_For_Subtype
(Def_Id : Entity_Id;
R : Node_Id;
Subt : Entity_Id);
-- This routine is used to set the scalar range field for a subtype given
-- Def_Id, the entity for the subtype, and R, the range expression for the
-- scalar range. Subt provides the parent subtype to be used to analyze,
-- resolve, and check the given range.
procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id);
-- Create a new signed integer entity, and apply the constraint to obtain
-- the required first named subtype of this type.
procedure Set_Stored_Constraint_From_Discriminant_Constraint
(E : Entity_Id);
-- E is some record type. This routine computes E's Stored_Constraint
-- from its Discriminant_Constraint.
-----------------------
-- Access_Definition --
-----------------------
function Access_Definition
(Related_Nod : Node_Id;
N : Node_Id) return Entity_Id
is
Anon_Type : Entity_Id;
Desig_Type : Entity_Id;
begin
if Is_Entry (Current_Scope)
and then Is_Task_Type (Etype (Scope (Current_Scope)))
then
Error_Msg_N ("task entries cannot have access parameters", N);
end if;
-- Ada 2005: for an object declaration the corresponding anonymous
-- type is declared in the current scope.
if Nkind (Related_Nod) = N_Object_Declaration then
Anon_Type :=
Create_Itype
(E_Anonymous_Access_Type, Related_Nod,
Scope_Id => Current_Scope);
-- For the anonymous function result case, retrieve the scope of
-- the function specification's associated entity rather than using
-- the current scope. The current scope will be the function itself
-- if the formal part is currently being analyzed, but will be the
-- parent scope in the case of a parameterless function, and we
-- always want to use the function's parent scope.
elsif Nkind (Related_Nod) = N_Function_Specification
and then Nkind (Parent (N)) /= N_Parameter_Specification
then
Anon_Type :=
Create_Itype
(E_Anonymous_Access_Type, Related_Nod,
Scope_Id => Scope (Defining_Unit_Name (Related_Nod)));
else
-- For access formals, access components, and access
-- discriminants, the scope is that of the enclosing declaration,
Anon_Type :=
Create_Itype
(E_Anonymous_Access_Type, Related_Nod,
Scope_Id => Scope (Current_Scope));
end if;
if All_Present (N)
and then Ada_Version >= Ada_05
then
Error_Msg_N ("ALL is not permitted for anonymous access types", N);
end if;
-- Ada 2005 (AI-254): In case of anonymous access to subprograms
-- call the corresponding semantic routine
if Present (Access_To_Subprogram_Definition (N)) then
Access_Subprogram_Declaration
(T_Name => Anon_Type,
T_Def => Access_To_Subprogram_Definition (N));
if Ekind (Anon_Type) = E_Access_Protected_Subprogram_Type then
Set_Ekind
(Anon_Type, E_Anonymous_Access_Protected_Subprogram_Type);
else
Set_Ekind
(Anon_Type, E_Anonymous_Access_Subprogram_Type);
end if;
return Anon_Type;
end if;
Find_Type (Subtype_Mark (N));
Desig_Type := Entity (Subtype_Mark (N));
Set_Directly_Designated_Type
(Anon_Type, Desig_Type);
Set_Etype (Anon_Type, Anon_Type);
Init_Size_Align (Anon_Type);
Set_Depends_On_Private (Anon_Type, Has_Private_Component (Anon_Type));
-- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
-- from Ada 95 semantics. In Ada 2005, anonymous access must specify
-- if the null value is allowed. In Ada 95 the null value is never
-- allowed.
if Ada_Version >= Ada_05 then
Set_Can_Never_Be_Null (Anon_Type, Null_Exclusion_Present (N));
else
Set_Can_Never_Be_Null (Anon_Type, True);
end if;
-- The anonymous access type is as public as the discriminated type or
-- subprogram that defines it. It is imported (for back-end purposes)
-- if the designated type is.
Set_Is_Public (Anon_Type, Is_Public (Scope (Anon_Type)));
-- Ada 2005 (AI-50217): Propagate the attribute that indicates that the
-- designated type comes from the limited view (for back-end purposes).
Set_From_With_Type (Anon_Type, From_With_Type (Desig_Type));
-- Ada 2005 (AI-231): Propagate the access-constant attribute
Set_Is_Access_Constant (Anon_Type, Constant_Present (N));
-- The context is either a subprogram declaration, object declaration,
-- or an access discriminant, in a private or a full type declaration.
-- In the case of a subprogram, if the designated type is incomplete,
-- the operation will be a primitive operation of the full type, to be
-- updated subsequently. If the type is imported through a limited_with
-- clause, the subprogram is not a primitive operation of the type
-- (which is declared elsewhere in some other scope).
if Ekind (Desig_Type) = E_Incomplete_Type
and then not From_With_Type (Desig_Type)
and then Is_Overloadable (Current_Scope)
then
Append_Elmt (Current_Scope, Private_Dependents (Desig_Type));
Set_Has_Delayed_Freeze (Current_Scope);
end if;
-- Ada 2005: if the designated type is an interface that may contain
-- tasks, create a Master entity for the declaration. This must be done
-- before expansion of the full declaration, because the declaration
-- may include an expression that is an allocator, whose expansion needs
-- the proper Master for the created tasks.
if Nkind (Related_Nod) = N_Object_Declaration
and then Expander_Active
and then Is_Interface (Desig_Type)
and then Is_Limited_Record (Desig_Type)
then
Build_Class_Wide_Master (Anon_Type);
end if;
return Anon_Type;
end Access_Definition;
-----------------------------------
-- Access_Subprogram_Declaration --
-----------------------------------
procedure Access_Subprogram_Declaration
(T_Name : Entity_Id;
T_Def : Node_Id)
is
Formals : constant List_Id := Parameter_Specifications (T_Def);
Formal : Entity_Id;
D_Ityp : Node_Id;
Desig_Type : constant Entity_Id :=
Create_Itype (E_Subprogram_Type, Parent (T_Def));
begin
-- Associate the Itype node with the inner full-type declaration
-- or subprogram spec. This is required to handle nested anonymous
-- declarations. For example:
-- procedure P
-- (X : access procedure
-- (Y : access procedure
-- (Z : access T)))
D_Ityp := Associated_Node_For_Itype (Desig_Type);
while Nkind (D_Ityp) /= N_Full_Type_Declaration
and then Nkind (D_Ityp) /= N_Procedure_Specification
and then Nkind (D_Ityp) /= N_Function_Specification
and then Nkind (D_Ityp) /= N_Object_Declaration
and then Nkind (D_Ityp) /= N_Object_Renaming_Declaration
and then Nkind (D_Ityp) /= N_Formal_Type_Declaration
loop
D_Ityp := Parent (D_Ityp);
pragma Assert (D_Ityp /= Empty);
end loop;
Set_Associated_Node_For_Itype (Desig_Type, D_Ityp);
if Nkind (D_Ityp) = N_Procedure_Specification
or else Nkind (D_Ityp) = N_Function_Specification
then
Set_Scope (Desig_Type, Scope (Defining_Unit_Name (D_Ityp)));
elsif Nkind (D_Ityp) = N_Full_Type_Declaration
or else Nkind (D_Ityp) = N_Object_Declaration
or else Nkind (D_Ityp) = N_Object_Renaming_Declaration
or else Nkind (D_Ityp) = N_Formal_Type_Declaration
then
Set_Scope (Desig_Type, Scope (Defining_Identifier (D_Ityp)));
end if;
if Nkind (T_Def) = N_Access_Function_Definition then
if Nkind (Result_Definition (T_Def)) = N_Access_Definition then
Set_Etype
(Desig_Type,
Access_Definition (T_Def, Result_Definition (T_Def)));
else
Analyze (Result_Definition (T_Def));
Set_Etype (Desig_Type, Entity (Result_Definition (T_Def)));
end if;
if not (Is_Type (Etype (Desig_Type))) then
Error_Msg_N
("expect type in function specification",
Result_Definition (T_Def));
end if;
else
Set_Etype (Desig_Type, Standard_Void_Type);
end if;
if Present (Formals) then
New_Scope (Desig_Type);
Process_Formals (Formals, Parent (T_Def));
-- A bit of a kludge here, End_Scope requires that the parent
-- pointer be set to something reasonable, but Itypes don't have
-- parent pointers. So we set it and then unset it ??? If and when
-- Itypes have proper parent pointers to their declarations, this
-- kludge can be removed.
Set_Parent (Desig_Type, T_Name);
End_Scope;
Set_Parent (Desig_Type, Empty);
end if;
-- The return type and/or any parameter type may be incomplete. Mark
-- the subprogram_type as depending on the incomplete type, so that
-- it can be updated when the full type declaration is seen.
if Present (Formals) then
Formal := First_Formal (Desig_Type);
while Present (Formal) loop
if Ekind (Formal) /= E_In_Parameter
and then Nkind (T_Def) = N_Access_Function_Definition
then
Error_Msg_N ("functions can only have IN parameters", Formal);
end if;
if Ekind (Etype (Formal)) = E_Incomplete_Type then
Append_Elmt (Desig_Type, Private_Dependents (Etype (Formal)));
Set_Has_Delayed_Freeze (Desig_Type);
end if;
Next_Formal (Formal);
end loop;
end if;
if Ekind (Etype (Desig_Type)) = E_Incomplete_Type
and then not Has_Delayed_Freeze (Desig_Type)
then
Append_Elmt (Desig_Type, Private_Dependents (Etype (Desig_Type)));
Set_Has_Delayed_Freeze (Desig_Type);
end if;
Check_Delayed_Subprogram (Desig_Type);
if Protected_Present (T_Def) then
Set_Ekind (T_Name, E_Access_Protected_Subprogram_Type);
Set_Convention (Desig_Type, Convention_Protected);
else
Set_Ekind (T_Name, E_Access_Subprogram_Type);
end if;
Set_Etype (T_Name, T_Name);
Init_Size_Align (T_Name);
Set_Directly_Designated_Type (T_Name, Desig_Type);
-- Ada 2005 (AI-231): Propagate the null-excluding attribute
Set_Can_Never_Be_Null (T_Name, Null_Exclusion_Present (T_Def));
Check_Restriction (No_Access_Subprograms, T_Def);
end Access_Subprogram_Declaration;
----------------------------
-- Access_Type_Declaration --
----------------------------
procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id) is
S : constant Node_Id := Subtype_Indication (Def);
P : constant Node_Id := Parent (Def);
Desig : Entity_Id;
-- Designated type
begin
-- Check for permissible use of incomplete type
if Nkind (S) /= N_Subtype_Indication then
Analyze (S);
if Ekind (Root_Type (Entity (S))) = E_Incomplete_Type then
Set_Directly_Designated_Type (T, Entity (S));
else
Set_Directly_Designated_Type (T,
Process_Subtype (S, P, T, 'P'));
end if;
else
Set_Directly_Designated_Type (T,
Process_Subtype (S, P, T, 'P'));
end if;
if All_Present (Def) or Constant_Present (Def) then
Set_Ekind (T, E_General_Access_Type);
else
Set_Ekind (T, E_Access_Type);
end if;
if Base_Type (Designated_Type (T)) = T then
Error_Msg_N ("access type cannot designate itself", S);
-- In Ada 2005, the type may have a limited view through some unit
-- in its own context, allowing the following circularity that cannot
-- be detected earlier
elsif Is_Class_Wide_Type (Designated_Type (T))
and then Etype (Designated_Type (T)) = T
then
Error_Msg_N
("access type cannot designate its own classwide type", S);
-- Clean up indication of tagged status to prevent cascaded errors
Set_Is_Tagged_Type (T, False);
end if;
Set_Etype (T, T);
-- If the type has appeared already in a with_type clause, it is
-- frozen and the pointer size is already set. Else, initialize.
if not From_With_Type (T) then
Init_Size_Align (T);
end if;
Set_Is_Access_Constant (T, Constant_Present (Def));
Desig := Designated_Type (T);
-- If designated type is an imported tagged type, indicate that the
-- access type is also imported, and therefore restricted in its use.
-- The access type may already be imported, so keep setting otherwise.
-- Ada 2005 (AI-50217): If the non-limited view of the designated type
-- is available, use it as the designated type of the access type, so
-- that the back-end gets a usable entity.
declare
N_Desig : Entity_Id;
begin
if From_With_Type (Desig)
and then Ekind (Desig) /= E_Access_Type
then
Set_From_With_Type (T);
if Ekind (Desig) = E_Incomplete_Type then
N_Desig := Non_Limited_View (Desig);
else pragma Assert (Ekind (Desig) = E_Class_Wide_Type);
if From_With_Type (Etype (Desig)) then
N_Desig := Non_Limited_View (Etype (Desig));
else
N_Desig := Etype (Desig);
end if;
end if;
pragma Assert (Present (N_Desig));
Set_Directly_Designated_Type (T, N_Desig);
end if;
end;
-- Note that Has_Task is always false, since the access type itself
-- is not a task type. See Einfo for more description on this point.
-- Exactly the same consideration applies to Has_Controlled_Component.
Set_Has_Task (T, False);
Set_Has_Controlled_Component (T, False);
-- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
-- attributes
Set_Can_Never_Be_Null (T, Null_Exclusion_Present (Def));
Set_Is_Access_Constant (T, Constant_Present (Def));
end Access_Type_Declaration;
----------------------------------
-- Add_Interface_Tag_Components --
----------------------------------
procedure Add_Interface_Tag_Components
(N : Node_Id;
Typ : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Elmt : Elmt_Id;
Ext : Node_Id;
L : List_Id;
Last_Tag : Node_Id;
Comp : Node_Id;
procedure Add_Tag (Iface : Entity_Id);
-- Comment required ???
-------------
-- Add_Tag --
-------------
procedure Add_Tag (Iface : Entity_Id) is
Decl : Node_Id;
Def : Node_Id;
Tag : Entity_Id;
Offset : Entity_Id;
begin
pragma Assert (Is_Tagged_Type (Iface)
and then Is_Interface (Iface));
Def :=
Make_Component_Definition (Loc,
Aliased_Present => True,
Subtype_Indication =>
New_Occurrence_Of (RTE (RE_Interface_Tag), Loc));
Tag := Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
Decl :=
Make_Component_Declaration (Loc,
Defining_Identifier => Tag,
Component_Definition => Def);
Analyze_Component_Declaration (Decl);
Set_Analyzed (Decl);
Set_Ekind (Tag, E_Component);
Set_Is_Limited_Record (Tag);
Set_Is_Tag (Tag);
Init_Component_Location (Tag);
pragma Assert (Is_Frozen (Iface));
Set_DT_Entry_Count (Tag,
DT_Entry_Count (First_Entity (Iface)));
if No (Last_Tag) then
Prepend (Decl, L);
else
Insert_After (Last_Tag, Decl);
end if;
Last_Tag := Decl;
-- If the ancestor has discriminants we need to give special support
-- to store the offset_to_top value of the secondary dispatch tables.
-- For this purpose we add a supplementary component just after the
-- field that contains the tag associated with each secondary DT.
if Typ /= Etype (Typ)
and then Has_Discriminants (Etype (Typ))
then
Def :=
Make_Component_Definition (Loc,
Subtype_Indication =>
New_Occurrence_Of (RTE (RE_Storage_Offset), Loc));
Offset :=
Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
Decl :=
Make_Component_Declaration (Loc,
Defining_Identifier => Offset,
Component_Definition => Def);
Analyze_Component_Declaration (Decl);
Set_Analyzed (Decl);
Set_Ekind (Offset, E_Component);
Init_Component_Location (Offset);
Insert_After (Last_Tag, Decl);
Last_Tag := Decl;
end if;
end Add_Tag;
-- Start of processing for Add_Interface_Tag_Components
begin
if Ekind (Typ) /= E_Record_Type
or else No (Abstract_Interfaces (Typ))
or else Is_Empty_Elmt_List (Abstract_Interfaces (Typ))
or else not RTE_Available (RE_Interface_Tag)
then
return;
end if;
if Present (Abstract_Interfaces (Typ)) then
-- Find the current last tag
if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
Ext := Record_Extension_Part (Type_Definition (N));
else
pragma Assert (Nkind (Type_Definition (N)) = N_Record_Definition);
Ext := Type_Definition (N);
end if;
Last_Tag := Empty;
if not (Present (Component_List (Ext))) then
Set_Null_Present (Ext, False);
L := New_List;
Set_Component_List (Ext,
Make_Component_List (Loc,
Component_Items => L,
Null_Present => False));
else
if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
L := Component_Items
(Component_List
(Record_Extension_Part
(Type_Definition (N))));
else
L := Component_Items
(Component_List
(Type_Definition (N)));
end if;
-- Find the last tag component
Comp := First (L);
while Present (Comp) loop
if Is_Tag (Defining_Identifier (Comp)) then
Last_Tag := Comp;
end if;
Next (Comp);
end loop;
end if;
-- At this point L references the list of components and Last_Tag
-- references the current last tag (if any). Now we add the tag
-- corresponding with all the interfaces that are not implemented
-- by the parent.
pragma Assert (Present
(First_Elmt (Abstract_Interfaces (Typ))));
Elmt := First_Elmt (Abstract_Interfaces (Typ));
while Present (Elmt) loop
Add_Tag (Node (Elmt));
Next_Elmt (Elmt);
end loop;
end if;
end Add_Interface_Tag_Components;
-----------------------------------
-- Analyze_Component_Declaration --
-----------------------------------
procedure Analyze_Component_Declaration (N : Node_Id) is
Id : constant Entity_Id := Defining_Identifier (N);
T : Entity_Id;
P : Entity_Id;
function Contains_POC (Constr : Node_Id) return Boolean;
-- Determines whether a constraint uses the discriminant of a record
-- type thus becoming a per-object constraint (POC).
function Is_Known_Limited (Typ : Entity_Id) return Boolean;
-- Check whether enclosing record is limited, to validate declaration
-- of components with limited types.
-- This seems a wrong description to me???
-- What is Typ? For sure it can return a result without checking
-- the enclosing record (enclosing what???)
------------------
-- Contains_POC --
------------------
function Contains_POC (Constr : Node_Id) return Boolean is
begin
case Nkind (Constr) is
when N_Attribute_Reference =>
return Attribute_Name (Constr) = Name_Access
and
Prefix (Constr) = Scope (Entity (Prefix (Constr)));
when N_Discriminant_Association =>
return Denotes_Discriminant (Expression (Constr));
when N_Identifier =>
return Denotes_Discriminant (Constr);
when N_Index_Or_Discriminant_Constraint =>
declare
IDC : Node_Id;
begin
IDC := First (Constraints (Constr));
while Present (IDC) loop
-- One per-object constraint is sufficient
if Contains_POC (IDC) then
return True;
end if;
Next (IDC);
end loop;
return False;
end;
when N_Range =>
return Denotes_Discriminant (Low_Bound (Constr))
or else
Denotes_Discriminant (High_Bound (Constr));
when N_Range_Constraint =>
return Denotes_Discriminant (Range_Expression (Constr));
when others =>
return False;
end case;
end Contains_POC;
----------------------
-- Is_Known_Limited --
----------------------
function Is_Known_Limited (Typ : Entity_Id) return Boolean is
P : constant Entity_Id := Etype (Typ);
R : constant Entity_Id := Root_Type (Typ);
begin
if Is_Limited_Record (Typ) then
return True;
-- If the root type is limited (and not a limited interface)
-- so is the current type
elsif Is_Limited_Record (R)
and then
(not Is_Interface (R)
or else not Is_Limited_Interface (R))
then
return True;
-- Else the type may have a limited interface progenitor, but a
-- limited record parent.
elsif R /= P
and then Is_Limited_Record (P)
then
return True;
else
return False;
end if;
end Is_Known_Limited;
-- Start of processing for Analyze_Component_Declaration
begin
Generate_Definition (Id);
Enter_Name (Id);
if Present (Subtype_Indication (Component_Definition (N))) then
T := Find_Type_Of_Object
(Subtype_Indication (Component_Definition (N)), N);
-- Ada 2005 (AI-230): Access Definition case
else
pragma Assert (Present
(Access_Definition (Component_Definition (N))));
T := Access_Definition
(Related_Nod => N,
N => Access_Definition (Component_Definition (N)));
Set_Is_Local_Anonymous_Access (T);
-- Ada 2005 (AI-254)
if Present (Access_To_Subprogram_Definition
(Access_Definition (Component_Definition (N))))
and then Protected_Present (Access_To_Subprogram_Definition
(Access_Definition
(Component_Definition (N))))
then
T := Replace_Anonymous_Access_To_Protected_Subprogram (N, T);
end if;
end if;
-- If the subtype is a constrained subtype of the enclosing record,
-- (which must have a partial view) the back-end does not properly
-- handle the recursion. Rewrite the component declaration with an
-- explicit subtype indication, which is acceptable to Gigi. We can copy
-- the tree directly because side effects have already been removed from
-- discriminant constraints.
if Ekind (T) = E_Access_Subtype
and then Is_Entity_Name (Subtype_Indication (Component_Definition (N)))
and then Comes_From_Source (T)
and then Nkind (Parent (T)) = N_Subtype_Declaration
and then Etype (Directly_Designated_Type (T)) = Current_Scope
then
Rewrite
(Subtype_Indication (Component_Definition (N)),
New_Copy_Tree (Subtype_Indication (Parent (T))));
T := Find_Type_Of_Object
(Subtype_Indication (Component_Definition (N)), N);
end if;
-- If the component declaration includes a default expression, then we
-- check that the component is not of a limited type (RM 3.7(5)),
-- and do the special preanalysis of the expression (see section on
-- "Handling of Default and Per-Object Expressions" in the spec of
-- package Sem).
if Present (Expression (N)) then
Analyze_Per_Use_Expression (Expression (N), T);
Check_Initialization (T, Expression (N));
if Ada_Version >= Ada_05
and then Is_Access_Type (T)
and then Ekind (T) = E_Anonymous_Access_Type
then
-- Check RM 3.9.2(9): "if the expected type for an expression is
-- an anonymous access-to-specific tagged type, then the object
-- designated by the expression shall not be dynamically tagged
-- unless it is a controlling operand in a call on a dispatching
-- operation"
if Is_Tagged_Type (Directly_Designated_Type (T))
and then
Ekind (Directly_Designated_Type (T)) /= E_Class_Wide_Type
and then
Ekind (Directly_Designated_Type (Etype (Expression (N)))) =
E_Class_Wide_Type
then
Error_Msg_N
("access to specific tagged type required ('R'M 3.9.2(9))",
Expression (N));
end if;
-- (Ada 2005: AI-230): Accessibility check for anonymous
-- components
if Type_Access_Level (Etype (Expression (N))) >
Type_Access_Level (T)
then
Error_Msg_N
("expression has deeper access level than component " &
"('R'M 3.10.2 (12.2))", Expression (N));
end if;
end if;
end if;
-- The parent type may be a private view with unknown discriminants,
-- and thus unconstrained. Regular components must be constrained.
if Is_Indefinite_Subtype (T) and then Chars (Id) /= Name_uParent then
if Is_Class_Wide_Type (T) then
Error_Msg_N
("class-wide subtype with unknown discriminants" &
" in component declaration",
Subtype_Indication (Component_Definition (N)));
else
Error_Msg_N
("unconstrained subtype in component declaration",
Subtype_Indication (Component_Definition (N)));
end if;
-- Components cannot be abstract, except for the special case of
-- the _Parent field (case of extending an abstract tagged type)
elsif Is_Abstract (T) and then Chars (Id) /= Name_uParent then
Error_Msg_N ("type of a component cannot be abstract", N);
end if;
Set_Etype (Id, T);
Set_Is_Aliased (Id, Aliased_Present (Component_Definition (N)));
-- The component declaration may have a per-object constraint, set
-- the appropriate flag in the defining identifier of the subtype.
if Present (Subtype_Indication (Component_Definition (N))) then
declare
Sindic : constant Node_Id :=
Subtype_Indication (Component_Definition (N));
begin
if Nkind (Sindic) = N_Subtype_Indication
and then Present (Constraint (Sindic))
and then Contains_POC (Constraint (Sindic))
then
Set_Has_Per_Object_Constraint (Id);
end if;
end;
end if;
-- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
-- out some static checks.
if Ada_Version >= Ada_05
and then Can_Never_Be_Null (T)
then
Null_Exclusion_Static_Checks (N);
end if;
-- If this component is private (or depends on a private type), flag the
-- record type to indicate that some operations are not available.
P := Private_Component (T);
if Present (P) then
-- Check for circular definitions
if P = Any_Type then
Set_Etype (Id, Any_Type);
-- There is a gap in the visibility of operations only if the
-- component type is not defined in the scope of the record type.
elsif Scope (P) = Scope (Current_Scope) then
null;
elsif Is_Limited_Type (P) then
Set_Is_Limited_Composite (Current_Scope);
else
Set_Is_Private_Composite (Current_Scope);
end if;
end if;
if P /= Any_Type
and then Is_Limited_Type (T)
and then Chars (Id) /= Name_uParent
and then Is_Tagged_Type (Current_Scope)
then
if Is_Derived_Type (Current_Scope)
and then not Is_Known_Limited (Current_Scope)
then
Error_Msg_N
("extension of nonlimited type cannot have limited components",
N);
if Is_Interface (Root_Type (Current_Scope)) then
Error_Msg_N
("\limitedness is not inherited from limited interface", N);
Error_Msg_N
("\add LIMITED to type indication", N);
end if;
Explain_Limited_Type (T, N);
Set_Etype (Id, Any_Type);
Set_Is_Limited_Composite (Current_Scope, False);
elsif not Is_Derived_Type (Current_Scope)
and then not Is_Limited_Record (Current_Scope)
and then not Is_Concurrent_Type (Current_Scope)
then
Error_Msg_N
("nonlimited tagged type cannot have limited components", N);
Explain_Limited_Type (T, N);
Set_Etype (Id, Any_Type);
Set_Is_Limited_Composite (Current_Scope, False);
end if;
end if;
Set_Original_Record_Component (Id, Id);
end Analyze_Component_Declaration;
--------------------------
-- Analyze_Declarations --
--------------------------
procedure Analyze_Declarations (L : List_Id) is
D : Node_Id;
Next_Node : Node_Id;
Freeze_From : Entity_Id := Empty;
procedure Adjust_D;
-- Adjust D not to include implicit label declarations, since these
-- have strange Sloc values that result in elaboration check problems.
-- (They have the sloc of the label as found in the source, and that
-- is ahead of the current declarative part).
--------------
-- Adjust_D --
--------------
procedure Adjust_D is
begin
while Present (Prev (D))
and then Nkind (D) = N_Implicit_Label_Declaration
loop
Prev (D);
end loop;
end Adjust_D;
-- Start of processing for Analyze_Declarations
begin
D := First (L);
while Present (D) loop
-- Complete analysis of declaration
Analyze (D);
Next_Node := Next (D);
if No (Freeze_From) then
Freeze_From := First_Entity (Current_Scope);
end if;
-- At the end of a declarative part, freeze remaining entities
-- declared in it. The end of the visible declarations of package
-- specification is not the end of a declarative part if private
-- declarations are present. The end of a package declaration is a
-- freezing point only if it a library package. A task definition or
-- protected type definition is not a freeze point either. Finally,
-- we do not freeze entities in generic scopes, because there is no
-- code generated for them and freeze nodes will be generated for
-- the instance.
-- The end of a package instantiation is not a freeze point, but
-- for now we make it one, because the generic body is inserted
-- (currently) immediately after. Generic instantiations will not
-- be a freeze point once delayed freezing of bodies is implemented.
-- (This is needed in any case for early instantiations ???).
if No (Next_Node) then
if Nkind (Parent (L)) = N_Component_List
or else Nkind (Parent (L)) = N_Task_Definition
or else Nkind (Parent (L)) = N_Protected_Definition
then
null;
elsif Nkind (Parent (L)) /= N_Package_Specification then
if Nkind (Parent (L)) = N_Package_Body then
Freeze_From := First_Entity (Current_Scope);
end if;
Adjust_D;
Freeze_All (Freeze_From, D);
Freeze_From := Last_Entity (Current_Scope);
elsif Scope (Current_Scope) /= Standard_Standard
and then not Is_Child_Unit (Current_Scope)
and then No (Generic_Parent (Parent (L)))
then
null;
elsif L /= Visible_Declarations (Parent (L))
or else No (Private_Declarations (Parent (L)))
or else Is_Empty_List (Private_Declarations (Parent (L)))
then
Adjust_D;
Freeze_All (Freeze_From, D);
Freeze_From := Last_Entity (Current_Scope);
end if;
-- If next node is a body then freeze all types before the body.
-- An exception occurs for expander generated bodies, which can
-- be recognized by their already being analyzed. The expander
-- ensures that all types needed by these bodies have been frozen
-- but it is not necessary to freeze all types (and would be wrong
-- since it would not correspond to an RM defined freeze point).
elsif not Analyzed (Next_Node)
and then (Nkind (Next_Node) = N_Subprogram_Body
or else Nkind (Next_Node) = N_Entry_Body
or else Nkind (Next_Node) = N_Package_Body
or else Nkind (Next_Node) = N_Protected_Body
or else Nkind (Next_Node) = N_Task_Body
or else Nkind (Next_Node) in N_Body_Stub)
then
Adjust_D;
Freeze_All (Freeze_From, D);
Freeze_From := Last_Entity (Current_Scope);
end if;
D := Next_Node;
end loop;
end Analyze_Declarations;
----------------------------------
-- Analyze_Incomplete_Type_Decl --
----------------------------------
procedure Analyze_Incomplete_Type_Decl (N : Node_Id) is
F : constant Boolean := Is_Pure (Current_Scope);
T : Entity_Id;
begin
Generate_Definition (Defining_Identifier (N));
-- Process an incomplete declaration. The identifier must not have been
-- declared already in the scope. However, an incomplete declaration may
-- appear in the private part of a package, for a private type that has
-- already been declared.
-- In this case, the discriminants (if any) must match
T := Find_Type_Name (N);
Set_Ekind (T, E_Incomplete_Type);
Init_Size_Align (T);
Set_Is_First_Subtype (T, True);
Set_Etype (T, T);
-- Ada 2005 (AI-326): Minimum decoration to give support to tagged
-- incomplete types.
if Tagged_Present (N) then
Set_Is_Tagged_Type (T);
Make_Class_Wide_Type (T);
Set_Primitive_Operations (T, New_Elmt_List);
end if;
New_Scope (T);
Set_Stored_Constraint (T, No_Elist);
if Present (Discriminant_Specifications (N)) then
Process_Discriminants (N);
end if;
End_Scope;
-- If the type has discriminants, non-trivial subtypes may be be
-- declared before the full view of the type. The full views of those
-- subtypes will be built after the full view of the type.
Set_Private_Dependents (T, New_Elmt_List);
Set_Is_Pure (T, F);
end Analyze_Incomplete_Type_Decl;
-----------------------------------
-- Analyze_Interface_Declaration --
-----------------------------------
procedure Analyze_Interface_Declaration (T : Entity_Id; Def : Node_Id) is
begin
Set_Is_Tagged_Type (T);
Set_Is_Limited_Record (T, Limited_Present (Def)
or else Task_Present (Def)
or else Protected_Present (Def)
or else Synchronized_Present (Def));
-- Type is abstract if full declaration carries keyword, or if
-- previous partial view did.
Set_Is_Abstract (T);
Set_Is_Interface (T);
Set_Is_Limited_Interface (T, Limited_Present (Def));
Set_Is_Protected_Interface (T, Protected_Present (Def));
Set_Is_Synchronized_Interface (T, Synchronized_Present (Def));
Set_Is_Task_Interface (T, Task_Present (Def));
Set_Abstract_Interfaces (T, New_Elmt_List);
Set_Primitive_Operations (T, New_Elmt_List);
end Analyze_Interface_Declaration;
-----------------------------
-- Analyze_Itype_Reference --
-----------------------------
-- Nothing to do. This node is placed in the tree only for the benefit of
-- back end processing, and has no effect on the semantic processing.
procedure Analyze_Itype_Reference (N : Node_Id) is
begin
pragma Assert (Is_Itype (Itype (N)));
null;
end Analyze_Itype_Reference;
--------------------------------
-- Analyze_Number_Declaration --
--------------------------------
procedure Analyze_Number_Declaration (N : Node_Id) is
Id : constant Entity_Id := Defining_Identifier (N);
E : constant Node_Id := Expression (N);
T : Entity_Id;
Index : Interp_Index;
It : Interp;
begin
Generate_Definition (Id);
Enter_Name (Id);
-- This is an optimization of a common case of an integer literal
if Nkind (E) = N_Integer_Literal then
Set_Is_Static_Expression (E, True);
Set_Etype (E, Universal_Integer);
Set_Etype (Id, Universal_Integer);
Set_Ekind (Id, E_Named_Integer);
Set_Is_Frozen (Id, True);
return;
end if;
Set_Is_Pure (Id, Is_Pure (Current_Scope));
-- Process expression, replacing error by integer zero, to avoid
-- cascaded errors or aborts further along in the processing
-- Replace Error by integer zero, which seems least likely to
-- cause cascaded errors.
if E = Error then
Rewrite (E, Make_Integer_Literal (Sloc (E), Uint_0));
Set_Error_Posted (E);
end if;
Analyze (E);
-- Verify that the expression is static and numeric. If
-- the expression is overloaded, we apply the preference
-- rule that favors root numeric types.
if not Is_Overloaded (E) then
T := Etype (E);
else
T := Any_Type;
Get_First_Interp (E, Index, It);
while Present (It.Typ) loop
if (Is_Integer_Type (It.Typ)
or else Is_Real_Type (It.Typ))
and then (Scope (Base_Type (It.Typ))) = Standard_Standard
then
if T = Any_Type then
T := It.Typ;
elsif It.Typ = Universal_Real
or else It.Typ = Universal_Integer
then
-- Choose universal interpretation over any other
T := It.Typ;
exit;
end if;
end if;
Get_Next_Interp (Index, It);
end loop;
end if;
if Is_Integer_Type (T) then
Resolve (E, T);
Set_Etype (Id, Universal_Integer);
Set_Ekind (Id, E_Named_Integer);
elsif Is_Real_Type (T) then
-- Because the real value is converted to universal_real, this is a
-- legal context for a universal fixed expression.
if T = Universal_Fixed then
declare
Loc : constant Source_Ptr := Sloc (N);
Conv : constant Node_Id := Make_Type_Conversion (Loc,
Subtype_Mark =>
New_Occurrence_Of (Universal_Real, Loc),
Expression => Relocate_Node (E));
begin
Rewrite (E, Conv);
Analyze (E);
end;
elsif T = Any_Fixed then
Error_Msg_N ("illegal context for mixed mode operation", E);
-- Expression is of the form : universal_fixed * integer. Try to
-- resolve as universal_real.
T := Universal_Real;
Set_Etype (E, T);
end if;
Resolve (E, T);
Set_Etype (Id, Universal_Real);
Set_Ekind (Id, E_Named_Real);
else
Wrong_Type (E, Any_Numeric);
Resolve (E, T);
Set_Etype (Id, T);
Set_Ekind (Id, E_Constant);
Set_Never_Set_In_Source (Id, True);
Set_Is_True_Constant (Id, True);
return;
end if;
if Nkind (E) = N_Integer_Literal
or else Nkind (E) = N_Real_Literal
then
Set_Etype (E, Etype (Id));
end if;
if not Is_OK_Static_Expression (E) then
Flag_Non_Static_Expr
("non-static expression used in number declaration!", E);
Rewrite (E, Make_Integer_Literal (Sloc (N), 1));
Set_Etype (E, Any_Type);
end if;
end Analyze_Number_Declaration;
--------------------------------
-- Analyze_Object_Declaration --
--------------------------------
procedure Analyze_Object_Declaration (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Id : constant Entity_Id := Defining_Identifier (N);
T : Entity_Id;
Act_T : Entity_Id;
E : Node_Id := Expression (N);
-- E is set to Expression (N) throughout this routine. When
-- Expression (N) is modified, E is changed accordingly.
Prev_Entity : Entity_Id := Empty;
function Build_Default_Subtype return Entity_Id;
-- If the object is limited or aliased, and if the type is unconstrained
-- and there is no expression, the discriminants cannot be modified and
-- the subtype of the object is constrained by the defaults, so it is
-- worthwhile building the corresponding subtype.
function Count_Tasks (T : Entity_Id) return Uint;
-- This function is called when a library level object of type is
-- declared. It's function is to count the static number of tasks
-- declared within the type (it is only called if Has_Tasks is set for
-- T). As a side effect, if an array of tasks with non-static bounds or
-- a variant record type is encountered, Check_Restrictions is called
-- indicating the count is unknown.
---------------------------
-- Build_Default_Subtype --
---------------------------
function Build_Default_Subtype return Entity_Id is
Constraints : constant List_Id := New_List;
Act : Entity_Id;
Decl : Node_Id;
Disc : Entity_Id;
begin
Disc := First_Discriminant (T);
if No (Discriminant_Default_Value (Disc)) then
return T; -- previous error.
end if;
Act := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
while Present (Disc) loop
Append (
New_Copy_Tree (
Discriminant_Default_Value (Disc)), Constraints);
Next_Discriminant (Disc);
end loop;
Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Act,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (T, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint
(Loc, Constraints)));
Insert_Before (N, Decl);
Analyze (Decl);
return Act;
end Build_Default_Subtype;
-----------------
-- Count_Tasks --
-----------------
function Count_Tasks (T : Entity_Id) return Uint is
C : Entity_Id;
X : Node_Id;
V : Uint;
begin
if Is_Task_Type (T) then
return Uint_1;
elsif Is_Record_Type (T) then
if Has_Discriminants (T) then
Check_Restriction (Max_Tasks, N);
return Uint_0;
else
V := Uint_0;
C := First_Component (T);
while Present (C) loop
V := V + Count_Tasks (Etype (C));
Next_Component (C);
end loop;
return V;
end if;
elsif Is_Array_Type (T) then
X := First_Index (T);
V := Count_Tasks (Component_Type (T));
while Present (X) loop
C := Etype (X);
if not Is_Static_Subtype (C) then
Check_Restriction (Max_Tasks, N);
return Uint_0;
else
V := V * (UI_Max (Uint_0,
Expr_Value (Type_High_Bound (C)) -
Expr_Value (Type_Low_Bound (C)) + Uint_1));
end if;
Next_Index (X);
end loop;
return V;
else
return Uint_0;
end if;
end Count_Tasks;
-- Start of processing for Analyze_Object_Declaration
begin
-- There are three kinds of implicit types generated by an
-- object declaration:
-- 1. Those for generated by the original Object Definition
-- 2. Those generated by the Expression
-- 3. Those used to constrained the Object Definition with the
-- expression constraints when it is unconstrained
-- They must be generated in this order to avoid order of elaboration
-- issues. Thus the first step (after entering the name) is to analyze
-- the object definition.
if Constant_Present (N) then
Prev_Entity := Current_Entity_In_Scope (Id);
-- If homograph is an implicit subprogram, it is overridden by the
-- current declaration.
if Present (Prev_Entity)
and then Is_Overloadable (Prev_Entity)
and then Is_Inherited_Operation (Prev_Entity)
then
Prev_Entity := Empty;
end if;
end if;
if Present (Prev_Entity) then
Constant_Redeclaration (Id, N, T);
Generate_Reference (Prev_Entity, Id, 'c');
Set_Completion_Referenced (Id);
if Error_Posted (N) then
-- Type mismatch or illegal redeclaration, Do not analyze
-- expression to avoid cascaded errors.
T := Find_Type_Of_Object (Object_Definition (N), N);
Set_Etype (Id, T);
Set_Ekind (Id, E_Variable);
return;
end if;
-- In the normal case, enter identifier at the start to catch premature
-- usage in the initialization expression.
else
Generate_Definition (Id);
Enter_Name (Id);
T := Find_Type_Of_Object (Object_Definition (N), N);
if Error_Posted (Id) then
Set_Etype (Id, T);
Set_Ekind (Id, E_Variable);
return;
end if;
end if;
-- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
-- out some static checks
if Ada_Version >= Ada_05
and then Can_Never_Be_Null (T)
then
-- In case of aggregates we must also take care of the correct
-- initialization of nested aggregates bug this is done at the
-- point of the analysis of the aggregate (see sem_aggr.adb)
if Present (Expression (N))
and then Nkind (Expression (N)) = N_Aggregate
then
null;
else
declare
Save_Typ : constant Entity_Id := Etype (Id);
begin
Set_Etype (Id, T); -- Temp. decoration for static checks
Null_Exclusion_Static_Checks (N);
Set_Etype (Id, Save_Typ);
end;
end if;
end if;
Set_Is_Pure (Id, Is_Pure (Current_Scope));
-- If deferred constant, make sure context is appropriate. We detect
-- a deferred constant as a constant declaration with no expression.
-- A deferred constant can appear in a package body if its completion
-- is by means of an interface pragma.
if Constant_Present (N)
and then No (E)
then
if not Is_Package_Or_Generic_Package (Current_Scope) then
Error_Msg_N
("invalid context for deferred constant declaration ('R'M 7.4)",
N);
Error_Msg_N
("\declaration requires an initialization expression",
N);
Set_Constant_Present (N, False);
-- In Ada 83, deferred constant must be of private type
elsif not Is_Private_Type (T) then
if Ada_Version = Ada_83 and then Comes_From_Source (N) then
Error_Msg_N
("(Ada 83) deferred constant must be private type", N);
end if;
end if;
-- If not a deferred constant, then object declaration freezes its type
else
Check_Fully_Declared (T, N);
Freeze_Before (N, T);
end if;
-- If the object was created by a constrained array definition, then
-- set the link in both the anonymous base type and anonymous subtype
-- that are built to represent the array type to point to the object.
if Nkind (Object_Definition (Declaration_Node (Id))) =
N_Constrained_Array_Definition
then
Set_Related_Array_Object (T, Id);
Set_Related_Array_Object (Base_Type (T), Id);
end if;
-- Special checks for protected objects not at library level
if Is_Protected_Type (T)
and then not Is_Library_Level_Entity (Id)
then
Check_Restriction (No_Local_Protected_Objects, Id);
-- Protected objects with interrupt handlers must be at library level
-- Ada 2005: this test is not needed (and the corresponding clause
-- in the RM is removed) because accessibility checks are sufficient
-- to make handlers not at the library level illegal.
if Has_Interrupt_Handler (T)
and then Ada_Version < Ada_05
then
Error_Msg_N
("interrupt object can only be declared at library level", Id);
end if;
end if;
-- The actual subtype of the object is the nominal subtype, unless
-- the nominal one is unconstrained and obtained from the expression.
Act_T := T;
-- Process initialization expression if present and not in error
if Present (E) and then E /= Error then
Analyze (E);
-- In case of errors detected in the analysis of the expression,
-- decorate it with the expected type to avoid cascade errors
if No (Etype (E)) then
Set_Etype (E, T);
end if;
-- If an initialization expression is present, then we set the
-- Is_True_Constant flag. It will be reset if this is a variable
-- and it is indeed modified.
Set_Is_True_Constant (Id, True);
-- If we are analyzing a constant declaration, set its completion
-- flag after analyzing the expression.
if Constant_Present (N) then
Set_Has_Completion (Id);
end if;
if not Assignment_OK (N) then
Check_Initialization (T, E);
end if;
Set_Etype (Id, T); -- may be overridden later on
Resolve (E, T);
Check_Unset_Reference (E);
if Compile_Time_Known_Value (E) then
Set_Current_Value (Id, E);
end if;
-- Check incorrect use of dynamically tagged expressions. Note
-- the use of Is_Tagged_Type (T) which seems redundant but is in
-- fact important to avoid spurious errors due to expanded code
-- for dispatching functions over an anonymous access type
if (Is_Class_Wide_Type (Etype (E)) or else Is_Dynamically_Tagged (E))
and then Is_Tagged_Type (T)
and then not Is_Class_Wide_Type (T)
then
Error_Msg_N ("dynamically tagged expression not allowed!", E);
end if;
Apply_Scalar_Range_Check (E, T);
Apply_Static_Length_Check (E, T);
end if;
-- If the No_Streams restriction is set, check that the type of the
-- object is not, and does not contain, any subtype derived from
-- Ada.Streams.Root_Stream_Type. Note that we guard the call to
-- Has_Stream just for efficiency reasons. There is no point in
-- spending time on a Has_Stream check if the restriction is not set.
if Restrictions.Set (No_Streams) then
if Has_Stream (T) then
Check_Restriction (No_Streams, N);
end if;
end if;
-- Abstract type is never permitted for a variable or constant.
-- Note: we inhibit this check for objects that do not come from
-- source because there is at least one case (the expansion of
-- x'class'input where x is abstract) where we legitimately
-- generate an abstract object.
if Is_Abstract (T) and then Comes_From_Source (N) then
Error_Msg_N ("type of object cannot be abstract",
Object_Definition (N));
if Is_CPP_Class (T) then
Error_Msg_NE ("\} may need a cpp_constructor",
Object_Definition (N), T);
end if;
-- Case of unconstrained type
elsif Is_Indefinite_Subtype (T) then
-- Nothing to do in deferred constant case
if Constant_Present (N) and then No (E) then
null;
-- Case of no initialization present
elsif No (E) then
if No_Initialization (N) then
null;
elsif Is_Class_Wide_Type (T) then
Error_Msg_N
("initialization required in class-wide declaration ", N);
else
Error_Msg_N
("unconstrained subtype not allowed (need initialization)",
Object_Definition (N));
end if;
-- Case of initialization present but in error. Set initial
-- expression as absent (but do not make above complaints)
elsif E = Error then
Set_Expression (N, Empty);
E := Empty;
-- Case of initialization present
else
-- Not allowed in Ada 83
if not Constant_Present (N) then
if Ada_Version = Ada_83
and then Comes_From_Source (Object_Definition (N))
then
Error_Msg_N
("(Ada 83) unconstrained variable not allowed",
Object_Definition (N));
end if;
end if;
-- Now we constrain the variable from the initializing expression
-- If the expression is an aggregate, it has been expanded into
-- individual assignments. Retrieve the actual type from the
-- expanded construct.
if Is_Array_Type (T)
and then No_Initialization (N)
and then Nkind (Original_Node (E)) = N_Aggregate
then
Act_T := Etype (E);
else
Expand_Subtype_From_Expr (N, T, Object_Definition (N), E);
Act_T := Find_Type_Of_Object (Object_Definition (N), N);
end if;
Set_Is_Constr_Subt_For_U_Nominal (Act_T);
if Aliased_Present (N) then
Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
end if;
Freeze_Before (N, Act_T);
Freeze_Before (N, T);
end if;
elsif Is_Array_Type (T)
and then No_Initialization (N)
and then Nkind (Original_Node (E)) = N_Aggregate
then
if not Is_Entity_Name (Object_Definition (N)) then
Act_T := Etype (E);
Check_Compile_Time_Size (Act_T);
if Aliased_Present (N) then
Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
end if;
end if;
-- When the given object definition and the aggregate are specified
-- independently, and their lengths might differ do a length check.
-- This cannot happen if the aggregate is of the form (others =>...)
if not Is_Constrained (T) then
null;
elsif Nkind (E) = N_Raise_Constraint_Error then
-- Aggregate is statically illegal. Place back in declaration
Set_Expression (N, E);
Set_No_Initialization (N, False);
elsif T = Etype (E) then
null;
elsif Nkind (E) = N_Aggregate
and then Present (Component_Associations (E))
and then Present (Choices (First (Component_Associations (E))))
and then Nkind (First
(Choices (First (Component_Associations (E))))) = N_Others_Choice
then
null;
else
Apply_Length_Check (E, T);
end if;
elsif (Is_Limited_Record (T)
or else Is_Concurrent_Type (T))
and then not Is_Constrained (T)
and then Has_Discriminants (T)
then
if No (E) then
Act_T := Build_Default_Subtype;
else
-- Ada 2005: a limited object may be initialized by means of an
-- aggregate. If the type has default discriminants it has an
-- unconstrained nominal type, Its actual subtype will be obtained
-- from the aggregate, and not from the default discriminants.
Act_T := Etype (E);
end if;
Rewrite (Object_Definition (N), New_Occurrence_Of (Act_T, Loc));
elsif Present (Underlying_Type (T))
and then not Is_Constrained (Underlying_Type (T))
and then Has_Discriminants (Underlying_Type (T))
and then Nkind (E) = N_Function_Call
and then Constant_Present (N)
then
-- The back-end has problems with constants of a discriminated type
-- with defaults, if the initial value is a function call. We
-- generate an intermediate temporary for the result of the call.
-- It is unclear why this should make it acceptable to gcc. ???
Remove_Side_Effects (E);
end if;
if T = Standard_Wide_Character or else T = Standard_Wide_Wide_Character
or else Root_Type (T) = Standard_Wide_String
or else Root_Type (T) = Standard_Wide_Wide_String
then
Check_Restriction (No_Wide_Characters, Object_Definition (N));
end if;
-- Now establish the proper kind and type of the object
if Constant_Present (N) then
Set_Ekind (Id, E_Constant);
Set_Never_Set_In_Source (Id, True);
Set_Is_True_Constant (Id, True);
else
Set_Ekind (Id, E_Variable);
-- A variable is set as shared passive if it appears in a shared
-- passive package, and is at the outer level. This is not done
-- for entities generated during expansion, because those are
-- always manipulated locally.
if Is_Shared_Passive (Current_Scope)
and then Is_Library_Level_Entity (Id)
and then Comes_From_Source (Id)
then
Set_Is_Shared_Passive (Id);
Check_Shared_Var (Id, T, N);
end if;
-- Case of no initializing expression present. If the type is not
-- fully initialized, then we set Never_Set_In_Source, since this
-- is a case of a potentially uninitialized object. Note that we
-- do not consider access variables to be fully initialized for
-- this purpose, since it still seems dubious if someone declares
-- Note that we only do this for source declarations. If the object
-- is declared by a generated declaration, we assume that it is not
-- appropriate to generate warnings in that case.
if No (E) then
if (Is_Access_Type (T)
or else not Is_Fully_Initialized_Type (T))
and then Comes_From_Source (N)
then
Set_Never_Set_In_Source (Id);
end if;
end if;
end if;
Init_Alignment (Id);
Init_Esize (Id);
if Aliased_Present (N) then
Set_Is_Aliased (Id);
if No (E)
and then Is_Record_Type (T)
and then not Is_Constrained (T)
and then Has_Discriminants (T)
then
Set_Actual_Subtype (Id, Build_Default_Subtype);
end if;
end if;
Set_Etype (Id, Act_T);
if Has_Controlled_Component (Etype (Id))
or else Is_Controlled (Etype (Id))
then
if not Is_Library_Level_Entity (Id) then
Check_Restriction (No_Nested_Finalization, N);
else
Validate_Controlled_Object (Id);
end if;
-- Generate a warning when an initialization causes an obvious ABE
-- violation. If the init expression is a simple aggregate there
-- shouldn't be any initialize/adjust call generated. This will be
-- true as soon as aggregates are built in place when possible.
-- ??? at the moment we do not generate warnings for temporaries
-- created for those aggregates although Program_Error might be
-- generated if compiled with -gnato.
if Is_Controlled (Etype (Id))
and then Comes_From_Source (Id)
then
declare
BT : constant Entity_Id := Base_Type (Etype (Id));
Implicit_Call : Entity_Id;
pragma Warnings (Off, Implicit_Call);
-- ??? what is this for (never referenced!)
function Is_Aggr (N : Node_Id) return Boolean;
-- Check that N is an aggregate
-------------
-- Is_Aggr --
-------------
function Is_Aggr (N : Node_Id) return Boolean is
begin
case Nkind (Original_Node (N)) is
when N_Aggregate | N_Extension_Aggregate =>
return True;
when N_Qualified_Expression |
N_Type_Conversion |
N_Unchecked_Type_Conversion =>
return Is_Aggr (Expression (Original_Node (N)));
when others =>
return False;
end case;
end Is_Aggr;
begin
-- If no underlying type, we already are in an error situation.
-- Do not try to add a warning since we do not have access to
-- prim-op list.
if No (Underlying_Type (BT)) then
Implicit_Call := Empty;
-- A generic type does not have usable primitive operators.
-- Initialization calls are built for instances.
elsif Is_Generic_Type (BT) then
Implicit_Call := Empty;
-- If the init expression is not an aggregate, an adjust call
-- will be generated
elsif Present (E) and then not Is_Aggr (E) then
Implicit_Call := Find_Prim_Op (BT, Name_Adjust);
-- If no init expression and we are not in the deferred
-- constant case, an Initialize call will be generated
elsif No (E) and then not Constant_Present (N) then
Implicit_Call := Find_Prim_Op (BT, Name_Initialize);
else
Implicit_Call := Empty;
end if;
end;
end if;
end if;
if Has_Task (Etype (Id)) then
Check_Restriction (No_Tasking, N);
if Is_Library_Level_Entity (Id) then
Check_Restriction (Max_Tasks, N, Count_Tasks (Etype (Id)));
else
Check_Restriction (Max_Tasks, N);
Check_Restriction (No_Task_Hierarchy, N);
Check_Potentially_Blocking_Operation (N);
end if;
-- A rather specialized test. If we see two tasks being declared
-- of the same type in the same object declaration, and the task
-- has an entry with an address clause, we know that program error
-- will be raised at run-time since we can't have two tasks with
-- entries at the same address.
if Is_Task_Type (Etype (Id)) and then More_Ids (N) then
declare
E : Entity_Id;
begin
E := First_Entity (Etype (Id));
while Present (E) loop
if Ekind (E) = E_Entry
and then Present (Get_Attribute_Definition_Clause
(E, Attribute_Address))
then
Error_Msg_N
("?more than one task with same entry address", N);
Error_Msg_N
("\?Program_Error will be raised at run time", N);
Insert_Action (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Duplicated_Entry_Address));
exit;
end if;
Next_Entity (E);
end loop;
end;
end if;
end if;
-- Some simple constant-propagation: if the expression is a constant
-- string initialized with a literal, share the literal. This avoids
-- a run-time copy.
if Present (E)
and then Is_Entity_Name (E)
and then Ekind (Entity (E)) = E_Constant
and then Base_Type (Etype (E)) = Standard_String
then
declare
Val : constant Node_Id := Constant_Value (Entity (E));
begin
if Present (Val)
and then Nkind (Val) = N_String_Literal
then
Rewrite (E, New_Copy (Val));
end if;
end;
end if;
-- Another optimization: if the nominal subtype is unconstrained and
-- the expression is a function call that returns an unconstrained
-- type, rewrite the declaration as a renaming of the result of the
-- call. The exceptions below are cases where the copy is expected,
-- either by the back end (Aliased case) or by the semantics, as for
-- initializing controlled types or copying tags for classwide types.
if Present (E)
and then Nkind (E) = N_Explicit_Dereference
and then Nkind (Original_Node (E)) = N_Function_Call
and then not Is_Library_Level_Entity (Id)
and then not Is_Constrained (Underlying_Type (T))
and then not Is_Aliased (Id)
and then not Is_Class_Wide_Type (T)
and then not Is_Controlled (T)
and then not Has_Controlled_Component (Base_Type (T))
and then Expander_Active
then
Rewrite (N,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Id,
Access_Definition => Empty,
Subtype_Mark => New_Occurrence_Of
(Base_Type (Etype (Id)), Loc),
Name => E));
Set_Renamed_Object (Id, E);
-- Force generation of debugging information for the constant and for
-- the renamed function call.
Set_Needs_Debug_Info (Id);
Set_Needs_Debug_Info (Entity (Prefix (E)));
end if;
if Present (Prev_Entity)
and then Is_Frozen (Prev_Entity)
and then not Error_Posted (Id)
then
Error_Msg_N ("full constant declaration appears too late", N);
end if;
Check_Eliminated (Id);
end Analyze_Object_Declaration;
---------------------------
-- Analyze_Others_Choice --
---------------------------
-- Nothing to do for the others choice node itself, the semantic analysis
-- of the others choice will occur as part of the processing of the parent
procedure Analyze_Others_Choice (N : Node_Id) is
pragma Warnings (Off, N);
begin
null;
end Analyze_Others_Choice;
--------------------------------
-- Analyze_Per_Use_Expression --
--------------------------------
procedure Analyze_Per_Use_Expression (N : Node_Id; T : Entity_Id) is
Save_In_Default_Expression : constant Boolean := In_Default_Expression;
begin
In_Default_Expression := True;
Pre_Analyze_And_Resolve (N, T);
In_Default_Expression := Save_In_Default_Expression;
end Analyze_Per_Use_Expression;
-------------------------------------------
-- Analyze_Private_Extension_Declaration --
-------------------------------------------
procedure Analyze_Private_Extension_Declaration (N : Node_Id) is
T : constant Entity_Id := Defining_Identifier (N);
Indic : constant Node_Id := Subtype_Indication (N);
Parent_Type : Entity_Id;
Parent_Base : Entity_Id;
begin
-- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
if Is_Non_Empty_List (Interface_List (N)) then
declare
Intf : Node_Id;
T : Entity_Id;
begin
Intf := First (Interface_List (N));
while Present (Intf) loop
T := Find_Type_Of_Subtype_Indic (Intf);
if not Is_Interface (T) then
Error_Msg_NE ("(Ada 2005) & must be an interface", Intf, T);
end if;
Next (Intf);
end loop;
end;
end if;
Generate_Definition (T);
Enter_Name (T);
Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
Parent_Base := Base_Type (Parent_Type);
if Parent_Type = Any_Type
or else Etype (Parent_Type) = Any_Type
then
Set_Ekind (T, Ekind (Parent_Type));
Set_Etype (T, Any_Type);
return;
elsif not Is_Tagged_Type (Parent_Type) then
Error_Msg_N
("parent of type extension must be a tagged type ", Indic);
return;
elsif Ekind (Parent_Type) = E_Void
or else Ekind (Parent_Type) = E_Incomplete_Type
then
Error_Msg_N ("premature derivation of incomplete type", Indic);
return;
end if;
-- Perhaps the parent type should be changed to the class-wide type's
-- specific type in this case to prevent cascading errors ???
if Is_Class_Wide_Type (Parent_Type) then
Error_Msg_N
("parent of type extension must not be a class-wide type", Indic);
return;
end if;
if (not Is_Package_Or_Generic_Package (Current_Scope)
and then Nkind (Parent (N)) /= N_Generic_Subprogram_Declaration)
or else In_Private_Part (Current_Scope)
then
Error_Msg_N ("invalid context for private extension", N);
end if;
-- Set common attributes
Set_Is_Pure (T, Is_Pure (Current_Scope));
Set_Scope (T, Current_Scope);
Set_Ekind (T, E_Record_Type_With_Private);
Init_Size_Align (T);
Set_Etype (T, Parent_Base);
Set_Has_Task (T, Has_Task (Parent_Base));
Set_Convention (T, Convention (Parent_Type));
Set_First_Rep_Item (T, First_Rep_Item (Parent_Type));
Set_Is_First_Subtype (T);
Make_Class_Wide_Type (T);
if Unknown_Discriminants_Present (N) then
Set_Discriminant_Constraint (T, No_Elist);
end if;
Build_Derived_Record_Type (N, Parent_Type, T);
if Limited_Present (N) then
Set_Is_Limited_Record (T);
if not Is_Limited_Type (Parent_Type)
and then
(not Is_Interface (Parent_Type)
or else not Is_Limited_Interface (Parent_Type))
then
Error_Msg_NE ("parent type& of limited extension must be limited",
N, Parent_Type);
end if;
end if;
end Analyze_Private_Extension_Declaration;
---------------------------------
-- Analyze_Subtype_Declaration --
---------------------------------
procedure Analyze_Subtype_Declaration (N : Node_Id) is
Id : constant Entity_Id := Defining_Identifier (N);
T : Entity_Id;
R_Checks : Check_Result;
begin
Generate_Definition (Id);
Set_Is_Pure (Id, Is_Pure (Current_Scope));
Init_Size_Align (Id);
-- The following guard condition on Enter_Name is to handle cases where
-- the defining identifier has already been entered into the scope but
-- the declaration as a whole needs to be analyzed.
-- This case in particular happens for derived enumeration types. The
-- derived enumeration type is processed as an inserted enumeration type
-- declaration followed by a rewritten subtype declaration. The defining
-- identifier, however, is entered into the name scope very early in the
-- processing of the original type declaration and therefore needs to be
-- avoided here, when the created subtype declaration is analyzed. (See
-- Build_Derived_Types)
-- This also happens when the full view of a private type is derived
-- type with constraints. In this case the entity has been introduced
-- in the private declaration.
if Present (Etype (Id))
and then (Is_Private_Type (Etype (Id))
or else Is_Task_Type (Etype (Id))
or else Is_Rewrite_Substitution (N))
then
null;
else
Enter_Name (Id);
end if;
T := Process_Subtype (Subtype_Indication (N), N, Id, 'P');
-- Inherit common attributes
Set_Is_Generic_Type (Id, Is_Generic_Type (Base_Type (T)));
Set_Is_Volatile (Id, Is_Volatile (T));
Set_Treat_As_Volatile (Id, Treat_As_Volatile (T));
Set_Is_Atomic (Id, Is_Atomic (T));
Set_Is_Ada_2005 (Id, Is_Ada_2005 (T));
-- In the case where there is no constraint given in the subtype
-- indication, Process_Subtype just returns the Subtype_Mark, so its
-- semantic attributes must be established here.
if Nkind (Subtype_Indication (N)) /= N_Subtype_Indication then
Set_Etype (Id, Base_Type (T));
case Ekind (T) is
when Array_Kind =>
Set_Ekind (Id, E_Array_Subtype);
Copy_Array_Subtype_Attributes (Id, T);
when Decimal_Fixed_Point_Kind =>
Set_Ekind (Id, E_Decimal_Fixed_Point_Subtype);
Set_Digits_Value (Id, Digits_Value (T));
Set_Delta_Value (Id, Delta_Value (T));
Set_Scale_Value (Id, Scale_Value (T));
Set_Small_Value (Id, Small_Value (T));
Set_Scalar_Range (Id, Scalar_Range (T));
Set_Machine_Radix_10 (Id, Machine_Radix_10 (T));
Set_Is_Constrained (Id, Is_Constrained (T));
Set_RM_Size (Id, RM_Size (T));
when Enumeration_Kind =>
Set_Ekind (Id, E_Enumeration_Subtype);
Set_First_Literal (Id, First_Literal (Base_Type (T)));
Set_Scalar_Range (Id, Scalar_Range (T));
Set_Is_Character_Type (Id, Is_Character_Type (T));
Set_Is_Constrained (Id, Is_Constrained (T));
Set_RM_Size (Id, RM_Size (T));
when Ordinary_Fixed_Point_Kind =>
Set_Ekind (Id, E_Ordinary_Fixed_Point_Subtype);
Set_Scalar_Range (Id, Scalar_Range (T));
Set_Small_Value (Id, Small_Value (T));
Set_Delta_Value (Id, Delta_Value (T));
Set_Is_Constrained (Id, Is_Constrained (T));
Set_RM_Size (Id, RM_Size (T));
when Float_Kind =>
Set_Ekind (Id, E_Floating_Point_Subtype);
Set_Scalar_Range (Id, Scalar_Range (T));
Set_Digits_Value (Id, Digits_Value (T));
Set_Is_Constrained (Id, Is_Constrained (T));
when Signed_Integer_Kind =>
Set_Ekind (Id, E_Signed_Integer_Subtype);
Set_Scalar_Range (Id, Scalar_Range (T));
Set_Is_Constrained (Id, Is_Constrained (T));
Set_RM_Size (Id, RM_Size (T));
when Modular_Integer_Kind =>
Set_Ekind (Id, E_Modular_Integer_Subtype);
Set_Scalar_Range (Id, Scalar_Range (T));
Set_Is_Constrained (Id, Is_Constrained (T));
Set_RM_Size (Id, RM_Size (T));
when Class_Wide_Kind =>
Set_Ekind (Id, E_Class_Wide_Subtype);
Set_First_Entity (Id, First_Entity (T));
Set_Last_Entity (Id, Last_Entity (T));
Set_Class_Wide_Type (Id, Class_Wide_Type (T));
Set_Cloned_Subtype (Id, T);
Set_Is_Tagged_Type (Id, True);
Set_Has_Unknown_Discriminants
(Id, True);
if Ekind (T) = E_Class_Wide_Subtype then
Set_Equivalent_Type (Id, Equivalent_Type (T));
end if;
when E_Record_Type | E_Record_Subtype =>
Set_Ekind (Id, E_Record_Subtype);
if Ekind (T) = E_Record_Subtype
and then Present (Cloned_Subtype (T))
then
Set_Cloned_Subtype (Id, Cloned_Subtype (T));
else
Set_Cloned_Subtype (Id, T);
end if;
Set_First_Entity (Id, First_Entity (T));
Set_Last_Entity (Id, Last_Entity (T));
Set_Has_Discriminants (Id, Has_Discriminants (T));
Set_Is_Constrained (Id, Is_Constrained (T));
Set_Is_Limited_Record (Id, Is_Limited_Record (T));
Set_Has_Unknown_Discriminants
(Id, Has_Unknown_Discriminants (T));
if Has_Discriminants (T) then
Set_Discriminant_Constraint
(Id, Discriminant_Constraint (T));
Set_Stored_Constraint_From_Discriminant_Constraint (Id);
elsif Has_Unknown_Discriminants (Id) then
Set_Discriminant_Constraint (Id, No_Elist);
end if;
if Is_Tagged_Type (T) then
Set_Is_Tagged_Type (Id);
Set_Is_Abstract (Id, Is_Abstract (T));
Set_Primitive_Operations
(Id, Primitive_Operations (T));
Set_Class_Wide_Type (Id, Class_Wide_Type (T));
end if;
when Private_Kind =>
Set_Ekind (Id, Subtype_Kind (Ekind (T)));
Set_Has_Discriminants (Id, Has_Discriminants (T));
Set_Is_Constrained (Id, Is_Constrained (T));
Set_First_Entity (Id, First_Entity (T));
Set_Last_Entity (Id, Last_Entity (T));
Set_Private_Dependents (Id, New_Elmt_List);
Set_Is_Limited_Record (Id, Is_Limited_Record (T));
Set_Has_Unknown_Discriminants
(Id, Has_Unknown_Discriminants (T));
if Is_Tagged_Type (T) then
Set_Is_Tagged_Type (Id);
Set_Is_Abstract (Id, Is_Abstract (T));
Set_Primitive_Operations
(Id, Primitive_Operations (T));
Set_Class_Wide_Type (Id, Class_Wide_Type (T));
end if;
-- In general the attributes of the subtype of a private type
-- are the attributes of the partial view of parent. However,
-- the full view may be a discriminated type, and the subtype
-- must share the discriminant constraint to generate correct
-- calls to initialization procedures.
if Has_Discriminants (T) then
Set_Discriminant_Constraint
(Id, Discriminant_Constraint (T));
Set_Stored_Constraint_From_Discriminant_Constraint (Id);
elsif Present (Full_View (T))
and then Has_Discriminants (Full_View (T))
then
Set_Discriminant_Constraint
(Id, Discriminant_Constraint (Full_View (T)));
Set_Stored_Constraint_From_Discriminant_Constraint (Id);
-- This would seem semantically correct, but apparently
-- confuses the back-end (4412-009). To be explained ???
-- Set_Has_Discriminants (Id);
end if;
Prepare_Private_Subtype_Completion (Id, N);
when Access_Kind =>
Set_Ekind (Id, E_Access_Subtype);
Set_Is_Constrained (Id, Is_Constrained (T));
Set_Is_Access_Constant
(Id, Is_Access_Constant (T));
Set_Directly_Designated_Type
(Id, Designated_Type (T));
Set_Can_Never_Be_Null (Id, Can_Never_Be_Null (T));
-- A Pure library_item must not contain the declaration of a
-- named access type, except within a subprogram, generic
-- subprogram, task unit, or protected unit (RM 10.2.1(16)).
if Comes_From_Source (Id)
and then In_Pure_Unit
and then not In_Subprogram_Task_Protected_Unit
then
Error_Msg_N
("named access types not allowed in pure unit", N);
end if;
when Concurrent_Kind =>
Set_Ekind (Id, Subtype_Kind (Ekind (T)));
Set_Corresponding_Record_Type (Id,
Corresponding_Record_Type (T));
Set_First_Entity (Id, First_Entity (T));
Set_First_Private_Entity (Id, First_Private_Entity (T));
Set_Has_Discriminants (Id, Has_Discriminants (T));
Set_Is_Constrained (Id, Is_Constrained (T));
Set_Last_Entity (Id, Last_Entity (T));
if Has_Discriminants (T) then
Set_Discriminant_Constraint (Id,
Discriminant_Constraint (T));
Set_Stored_Constraint_From_Discriminant_Constraint (Id);
end if;
-- If the subtype name denotes an incomplete type an error was
-- already reported by Process_Subtype.
when E_Incomplete_Type =>
Set_Etype (Id, Any_Type);
when others =>
raise Program_Error;
end case;
end if;
if Etype (Id) = Any_Type then
return;
end if;
-- Some common processing on all types
Set_Size_Info (Id, T);
Set_First_Rep_Item (Id, First_Rep_Item (T));
T := Etype (Id);
Set_Is_Immediately_Visible (Id, True);
Set_Depends_On_Private (Id, Has_Private_Component (T));
if Present (Generic_Parent_Type (N))
and then
(Nkind
(Parent (Generic_Parent_Type (N))) /= N_Formal_Type_Declaration
or else Nkind
(Formal_Type_Definition (Parent (Generic_Parent_Type (N))))
/= N_Formal_Private_Type_Definition)
then
if Is_Tagged_Type (Id) then
if Is_Class_Wide_Type (Id) then
Derive_Subprograms (Generic_Parent_Type (N), Id, Etype (T));
else
Derive_Subprograms (Generic_Parent_Type (N), Id, T);
end if;
elsif Scope (Etype (Id)) /= Standard_Standard then
Derive_Subprograms (Generic_Parent_Type (N), Id);
end if;
end if;
if Is_Private_Type (T)
and then Present (Full_View (T))
then
Conditional_Delay (Id, Full_View (T));
-- The subtypes of components or subcomponents of protected types
-- do not need freeze nodes, which would otherwise appear in the
-- wrong scope (before the freeze node for the protected type). The
-- proper subtypes are those of the subcomponents of the corresponding
-- record.
elsif Ekind (Scope (Id)) /= E_Protected_Type
and then Present (Scope (Scope (Id))) -- error defense!
and then Ekind (Scope (Scope (Id))) /= E_Protected_Type
then
Conditional_Delay (Id, T);
end if;
-- Check that constraint_error is raised for a scalar subtype
-- indication when the lower or upper bound of a non-null range
-- lies outside the range of the type mark.
if Nkind (Subtype_Indication (N)) = N_Subtype_Indication then
if Is_Scalar_Type (Etype (Id))
and then Scalar_Range (Id) /=
Scalar_Range (Etype (Subtype_Mark
(Subtype_Indication (N))))
then
Apply_Range_Check
(Scalar_Range (Id),
Etype (Subtype_Mark (Subtype_Indication (N))));
elsif Is_Array_Type (Etype (Id))
and then Present (First_Index (Id))
then
-- This really should be a subprogram that finds the indications
-- to check???
if ((Nkind (First_Index (Id)) = N_Identifier
and then Ekind (Entity (First_Index (Id))) in Scalar_Kind)
or else Nkind (First_Index (Id)) = N_Subtype_Indication)
and then
Nkind (Scalar_Range (Etype (First_Index (Id)))) = N_Range
then
declare
Target_Typ : constant Entity_Id :=
Etype
(First_Index (Etype
(Subtype_Mark (Subtype_Indication (N)))));
begin
R_Checks :=
Range_Check
(Scalar_Range (Etype (First_Index (Id))),
Target_Typ,
Etype (First_Index (Id)),
Defining_Identifier (N));
Insert_Range_Checks
(R_Checks,
N,
Target_Typ,
Sloc (Defining_Identifier (N)));
end;
end if;
end if;
end if;
Check_Eliminated (Id);
end Analyze_Subtype_Declaration;
--------------------------------
-- Analyze_Subtype_Indication --
--------------------------------
procedure Analyze_Subtype_Indication (N : Node_Id) is
T : constant Entity_Id := Subtype_Mark (N);
R : constant Node_Id := Range_Expression (Constraint (N));
begin
Analyze (T);
if R /= Error then
Analyze (R);
Set_Etype (N, Etype (R));
else
Set_Error_Posted (R);
Set_Error_Posted (T);
end if;
end Analyze_Subtype_Indication;
------------------------------
-- Analyze_Type_Declaration --
------------------------------
procedure Analyze_Type_Declaration (N : Node_Id) is
Def : constant Node_Id := Type_Definition (N);
Def_Id : constant Entity_Id := Defining_Identifier (N);
T : Entity_Id;
Prev : Entity_Id;
Is_Remote : constant Boolean :=
(Is_Remote_Types (Current_Scope)
or else Is_Remote_Call_Interface (Current_Scope))
and then not (In_Private_Part (Current_Scope)
or else
In_Package_Body (Current_Scope));
procedure Check_Ops_From_Incomplete_Type;
-- If there is a tagged incomplete partial view of the type, transfer
-- its operations to the full view, and indicate that the type of the
-- controlling parameter (s) is this full view.
------------------------------------
-- Check_Ops_From_Incomplete_Type --
------------------------------------
procedure Check_Ops_From_Incomplete_Type is
Elmt : Elmt_Id;
Formal : Entity_Id;
Op : Entity_Id;
begin
if Prev /= T
and then Ekind (Prev) = E_Incomplete_Type
and then Is_Tagged_Type (Prev)
and then Is_Tagged_Type (T)
then
Elmt := First_Elmt (Primitive_Operations (Prev));
while Present (Elmt) loop
Op := Node (Elmt);
Prepend_Elmt (Op, Primitive_Operations (T));
Formal := First_Formal (Op);
while Present (Formal) loop
if Etype (Formal) = Prev then
Set_Etype (Formal, T);
end if;
Next_Formal (Formal);
end loop;
if Etype (Op) = Prev then
Set_Etype (Op, T);
end if;
Next_Elmt (Elmt);
end loop;
end if;
end Check_Ops_From_Incomplete_Type;
-- Start of processing for Analyze_Type_Declaration
begin
Prev := Find_Type_Name (N);
-- The full view, if present, now points to the current type
-- Ada 2005 (AI-50217): If the type was previously decorated when
-- imported through a LIMITED WITH clause, it appears as incomplete
-- but has no full view.
if Ekind (Prev) = E_Incomplete_Type
and then Present (Full_View (Prev))
then
T := Full_View (Prev);
else
T := Prev;
end if;
Set_Is_Pure (T, Is_Pure (Current_Scope));
-- We set the flag Is_First_Subtype here. It is needed to set the
-- corresponding flag for the Implicit class-wide-type created
-- during tagged types processing.
Set_Is_First_Subtype (T, True);
-- Only composite types other than array types are allowed to have
-- discriminants.
case Nkind (Def) is
-- For derived types, the rule will be checked once we've figured
-- out the parent type.
when N_Derived_Type_Definition =>
null;
-- For record types, discriminants are allowed
when N_Record_Definition =>
null;
when others =>
if Present (Discriminant_Specifications (N)) then
Error_Msg_N
("elementary or array type cannot have discriminants",
Defining_Identifier
(First (Discriminant_Specifications (N))));
end if;
end case;
-- Elaborate the type definition according to kind, and generate
-- subsidiary (implicit) subtypes where needed. We skip this if
-- it was already done (this happens during the reanalysis that
-- follows a call to the high level optimizer).
if not Analyzed (T) then
Set_Analyzed (T);
case Nkind (Def) is
when N_Access_To_Subprogram_Definition =>
Access_Subprogram_Declaration (T, Def);
-- If this is a remote access to subprogram, we must create
-- the equivalent fat pointer type, and related subprograms.
if Is_Remote then
Process_Remote_AST_Declaration (N);
end if;
-- Validate categorization rule against access type declaration
-- usually a violation in Pure unit, Shared_Passive unit.
Validate_Access_Type_Declaration (T, N);
when N_Access_To_Object_Definition =>
Access_Type_Declaration (T, Def);
-- Validate categorization rule against access type declaration
-- usually a violation in Pure unit, Shared_Passive unit.
Validate_Access_Type_Declaration (T, N);
-- If we are in a Remote_Call_Interface package and define
-- a RACW, Read and Write attribute must be added.
if Is_Remote
and then Is_Remote_Access_To_Class_Wide_Type (Def_Id)
then
Add_RACW_Features (Def_Id);
end if;
-- Set no strict aliasing flag if config pragma seen
if Opt.No_Strict_Aliasing then
Set_No_Strict_Aliasing (Base_Type (Def_Id));
end if;
when N_Array_Type_Definition =>
Array_Type_Declaration (T, Def);
when N_Derived_Type_Definition =>
Derived_Type_Declaration (T, N, T /= Def_Id);
when N_Enumeration_Type_Definition =>
Enumeration_Type_Declaration (T, Def);
when N_Floating_Point_Definition =>
Floating_Point_Type_Declaration (T, Def);
when N_Decimal_Fixed_Point_Definition =>
Decimal_Fixed_Point_Type_Declaration (T, Def);
when N_Ordinary_Fixed_Point_Definition =>
Ordinary_Fixed_Point_Type_Declaration (T, Def);
when N_Signed_Integer_Type_Definition =>
Signed_Integer_Type_Declaration (T, Def);
when N_Modular_Type_Definition =>
Modular_Type_Declaration (T, Def);
when N_Record_Definition =>
Record_Type_Declaration (T, N, Prev);
when others =>
raise Program_Error;
end case;
end if;
if Etype (T) = Any_Type then
return;
end if;
-- Some common processing for all types
Set_Depends_On_Private (T, Has_Private_Component (T));
Check_Ops_From_Incomplete_Type;
-- Both the declared entity, and its anonymous base type if one
-- was created, need freeze nodes allocated.
declare
B : constant Entity_Id := Base_Type (T);
begin
-- In the case where the base type is different from the first
-- subtype, we pre-allocate a freeze node, and set the proper link
-- to the first subtype. Freeze_Entity will use this preallocated
-- freeze node when it freezes the entity.
if B /= T then
Ensure_Freeze_Node (B);
Set_First_Subtype_Link (Freeze_Node (B), T);
end if;
if not From_With_Type (T) then
Set_Has_Delayed_Freeze (T);
end if;
end;
-- Case of T is the full declaration of some private type which has
-- been swapped in Defining_Identifier (N).
if T /= Def_Id and then Is_Private_Type (Def_Id) then
Process_Full_View (N, T, Def_Id);
-- Record the reference. The form of this is a little strange,
-- since the full declaration has been swapped in. So the first
-- parameter here represents the entity to which a reference is
-- made which is the "real" entity, i.e. the one swapped in,
-- and the second parameter provides the reference location.
Generate_Reference (T, T, 'c');
Set_Completion_Referenced (Def_Id);
-- For completion of incomplete type, process incomplete dependents
-- and always mark the full type as referenced (it is the incomplete
-- type that we get for any real reference).
elsif Ekind (Prev) = E_Incomplete_Type then
Process_Incomplete_Dependents (N, T, Prev);
Generate_Reference (Prev, Def_Id, 'c');
Set_Completion_Referenced (Def_Id);
-- If not private type or incomplete type completion, this is a real
-- definition of a new entity, so record it.
else
Generate_Definition (Def_Id);
end if;
Check_Eliminated (Def_Id);
end Analyze_Type_Declaration;
--------------------------
-- Analyze_Variant_Part --
--------------------------
procedure Analyze_Variant_Part (N : Node_Id) is
procedure Non_Static_Choice_Error (Choice : Node_Id);
-- Error routine invoked by the generic instantiation below when
-- the variant part has a non static choice.
procedure Process_Declarations (Variant : Node_Id);
-- Analyzes all the declarations associated with a Variant.
-- Needed by the generic instantiation below.
package Variant_Choices_Processing is new
Generic_Choices_Processing
(Get_Alternatives => Variants,
Get_Choices => Discrete_Choices,
Process_Empty_Choice => No_OP,
Process_Non_Static_Choice => Non_Static_Choice_Error,
Process_Associated_Node => Process_Declarations);
use Variant_Choices_Processing;
-- Instantiation of the generic choice processing package
-----------------------------
-- Non_Static_Choice_Error --
-----------------------------
procedure Non_Static_Choice_Error (Choice : Node_Id) is
begin
Flag_Non_Static_Expr
("choice given in variant part is not static!", Choice);
end Non_Static_Choice_Error;
--------------------------
-- Process_Declarations --
--------------------------
procedure Process_Declarations (Variant : Node_Id) is
begin
if not Null_Present (Component_List (Variant)) then
Analyze_Declarations (Component_Items (Component_List (Variant)));
if Present (Variant_Part (Component_List (Variant))) then
Analyze (Variant_Part (Component_List (Variant)));
end if;
end if;
end Process_Declarations;
-- Variables local to Analyze_Case_Statement
Discr_Name : Node_Id;
Discr_Type : Entity_Id;
Case_Table : Choice_Table_Type (1 .. Number_Of_Choices (N));
Last_Choice : Nat;
Dont_Care : Boolean;
Others_Present : Boolean := False;
-- Start of processing for Analyze_Variant_Part
begin
Discr_Name := Name (N);
Analyze (Discr_Name);
if Ekind (Entity (Discr_Name)) /= E_Discriminant then
Error_Msg_N ("invalid discriminant name in variant part", Discr_Name);
end if;
Discr_Type := Etype (Entity (Discr_Name));
if not Is_Discrete_Type (Discr_Type) then
Error_Msg_N
("discriminant in a variant part must be of a discrete type",
Name (N));
return;
end if;
-- Call the instantiated Analyze_Choices which does the rest of the work
Analyze_Choices
(N, Discr_Type, Case_Table, Last_Choice, Dont_Care, Others_Present);
end Analyze_Variant_Part;
----------------------------
-- Array_Type_Declaration --
----------------------------
procedure Array_Type_Declaration (T : in out Entity_Id; Def : Node_Id) is
Component_Def : constant Node_Id := Component_Definition (Def);
Element_Type : Entity_Id;
Implicit_Base : Entity_Id;
Index : Node_Id;
Related_Id : Entity_Id := Empty;
Nb_Index : Nat;
P : constant Node_Id := Parent (Def);
Priv : Entity_Id;
begin
if Nkind (Def) = N_Constrained_Array_Definition then
Index := First (Discrete_Subtype_Definitions (Def));
else
Index := First (Subtype_Marks (Def));
end if;
-- Find proper names for the implicit types which may be public.
-- in case of anonymous arrays we use the name of the first object
-- of that type as prefix.
if No (T) then
Related_Id := Defining_Identifier (P);
else
Related_Id := T;
end if;
Nb_Index := 1;
while Present (Index) loop
Analyze (Index);
Make_Index (Index, P, Related_Id, Nb_Index);
Next_Index (Index);
Nb_Index := Nb_Index + 1;
end loop;
if Present (Subtype_Indication (Component_Def)) then
Element_Type := Process_Subtype (Subtype_Indication (Component_Def),
P, Related_Id, 'C');
-- Ada 2005 (AI-230): Access Definition case
else pragma Assert (Present (Access_Definition (Component_Def)));
Element_Type := Access_Definition
(Related_Nod => Related_Id,
N => Access_Definition (Component_Def));
Set_Is_Local_Anonymous_Access (Element_Type);
-- Ada 2005 (AI-230): In case of components that are anonymous
-- access types the level of accessibility depends on the enclosing
-- type declaration
Set_Scope (Element_Type, Current_Scope); -- Ada 2005 (AI-230)
-- Ada 2005 (AI-254)
declare
CD : constant Node_Id :=
Access_To_Subprogram_Definition
(Access_Definition (Component_Def));
begin
if Present (CD) and then Protected_Present (CD) then
Element_Type :=
Replace_Anonymous_Access_To_Protected_Subprogram
(Def, Element_Type);
end if;
end;
end if;
-- Constrained array case
if No (T) then
T := Create_Itype (E_Void, P, Related_Id, 'T');
end if;
if Nkind (Def) = N_Constrained_Array_Definition then
-- Establish Implicit_Base as unconstrained base type
Implicit_Base := Create_Itype (E_Array_Type, P, Related_Id, 'B');
Init_Size_Align (Implicit_Base);
Set_Etype (Implicit_Base, Implicit_Base);
Set_Scope (Implicit_Base, Current_Scope);
Set_Has_Delayed_Freeze (Implicit_Base);
-- The constrained array type is a subtype of the unconstrained one
Set_Ekind (T, E_Array_Subtype);
Init_Size_Align (T);
Set_Etype (T, Implicit_Base);
Set_Scope (T, Current_Scope);
Set_Is_Constrained (T, True);
Set_First_Index (T, First (Discrete_Subtype_Definitions (Def)));
Set_Has_Delayed_Freeze (T);
-- Complete setup of implicit base type
Set_First_Index (Implicit_Base, First_Index (T));
Set_Component_Type (Implicit_Base, Element_Type);
Set_Has_Task (Implicit_Base, Has_Task (Element_Type));
Set_Component_Size (Implicit_Base, Uint_0);
Set_Has_Controlled_Component
(Implicit_Base, Has_Controlled_Component
(Element_Type)
or else
Is_Controlled (Element_Type));
Set_Finalize_Storage_Only
(Implicit_Base, Finalize_Storage_Only
(Element_Type));
-- Unconstrained array case
else
Set_Ekind (T, E_Array_Type);
Init_Size_Align (T);
Set_Etype (T, T);
Set_Scope (T, Current_Scope);
Set_Component_Size (T, Uint_0);
Set_Is_Constrained (T, False);
Set_First_Index (T, First (Subtype_Marks (Def)));
Set_Has_Delayed_Freeze (T, True);
Set_Has_Task (T, Has_Task (Element_Type));
Set_Has_Controlled_Component (T, Has_Controlled_Component
(Element_Type)
or else
Is_Controlled (Element_Type));
Set_Finalize_Storage_Only (T, Finalize_Storage_Only
(Element_Type));
end if;
Set_Component_Type (Base_Type (T), Element_Type);
if Aliased_Present (Component_Definition (Def)) then
Set_Has_Aliased_Components (Etype (T));
end if;
-- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
-- array type to ensure that objects of this type are initialized.
if Ada_Version >= Ada_05
and then Can_Never_Be_Null (Element_Type)
then
Set_Can_Never_Be_Null (T);
if Null_Exclusion_Present (Component_Definition (Def))
and then Can_Never_Be_Null (Element_Type)
-- No need to check itypes because in their case this check
-- was done at their point of creation
and then not Is_Itype (Element_Type)
then
Error_Msg_N
("(Ada 2005) already a null-excluding type",
Subtype_Indication (Component_Definition (Def)));
end if;
end if;
Priv := Private_Component (Element_Type);
if Present (Priv) then
-- Check for circular definitions
if Priv = Any_Type then
Set_Component_Type (Etype (T), Any_Type);
-- There is a gap in the visibility of operations on the composite
-- type only if the component type is defined in a different scope.
elsif Scope (Priv) = Current_Scope then
null;
elsif Is_Limited_Type (Priv) then
Set_Is_Limited_Composite (Etype (T));
Set_Is_Limited_Composite (T);
else
Set_Is_Private_Composite (Etype (T));
Set_Is_Private_Composite (T);
end if;
end if;
-- Create a concatenation operator for the new type. Internal
-- array types created for packed entities do not need such, they
-- are compatible with the user-defined type.
if Number_Dimensions (T) = 1
and then not Is_Packed_Array_Type (T)
then
New_Concatenation_Op (T);
end if;
-- In the case of an unconstrained array the parser has already
-- verified that all the indices are unconstrained but we still
-- need to make sure that the element type is constrained.
if Is_Indefinite_Subtype (Element_Type) then
Error_Msg_N
("unconstrained element type in array declaration",
Subtype_Indication (Component_Def));
elsif Is_Abstract (Element_Type) then
Error_Msg_N
("the type of a component cannot be abstract",
Subtype_Indication (Component_Def));
end if;
end Array_Type_Declaration;
------------------------------------------------------
-- Replace_Anonymous_Access_To_Protected_Subprogram --
------------------------------------------------------
function Replace_Anonymous_Access_To_Protected_Subprogram
(N : Node_Id;
Prev_E : Entity_Id) return Entity_Id
is
Loc : constant Source_Ptr := Sloc (N);
Curr_Scope : constant Scope_Stack_Entry :=
Scope_Stack.Table (Scope_Stack.Last);
Anon : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('S'));
Acc : Node_Id;
Comp : Node_Id;
Decl : Node_Id;
P : Node_Id;
begin
Set_Is_Internal (Anon);
case Nkind (N) is
when N_Component_Declaration |
N_Unconstrained_Array_Definition |
N_Constrained_Array_Definition =>
Comp := Component_Definition (N);
Acc := Access_Definition (Component_Definition (N));
when N_Discriminant_Specification =>
Comp := Discriminant_Type (N);
Acc := Discriminant_Type (N);
when N_Parameter_Specification =>
Comp := Parameter_Type (N);
Acc := Parameter_Type (N);
when others =>
raise Program_Error;
end case;
Decl := Make_Full_Type_Declaration (Loc,
Defining_Identifier => Anon,
Type_Definition =>
Copy_Separate_Tree (Access_To_Subprogram_Definition (Acc)));
Mark_Rewrite_Insertion (Decl);
-- Insert the new declaration in the nearest enclosing scope
P := Parent (N);
while Present (P) and then not Has_Declarations (P) loop
P := Parent (P);
end loop;
pragma Assert (Present (P));
if Nkind (P) = N_Package_Specification then
Prepend (Decl, Visible_Declarations (P));
else
Prepend (Decl, Declarations (P));
end if;
-- Replace the anonymous type with an occurrence of the new declaration.
-- In all cases the rewritten node does not have the null-exclusion
-- attribute because (if present) it was already inherited by the
-- anonymous entity (Anon). Thus, in case of components we do not
-- inherit this attribute.
if Nkind (N) = N_Parameter_Specification then
Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
Set_Etype (Defining_Identifier (N), Anon);
Set_Null_Exclusion_Present (N, False);
else
Rewrite (Comp,
Make_Component_Definition (Loc,
Subtype_Indication => New_Occurrence_Of (Anon, Loc)));
end if;
Mark_Rewrite_Insertion (Comp);
-- Temporarily remove the current scope from the stack to add the new
-- declarations to the enclosing scope
Scope_Stack.Decrement_Last;
Analyze (Decl);
Scope_Stack.Append (Curr_Scope);
Set_Original_Access_Type (Anon, Prev_E);
return Anon;
end Replace_Anonymous_Access_To_Protected_Subprogram;
-------------------------------
-- Build_Derived_Access_Type --
-------------------------------
procedure Build_Derived_Access_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id)
is
S : constant Node_Id := Subtype_Indication (Type_Definition (N));
Desig_Type : Entity_Id;
Discr : Entity_Id;
Discr_Con_Elist : Elist_Id;
Discr_Con_El : Elmt_Id;
Subt : Entity_Id;
begin
-- Set the designated type so it is available in case this is
-- an access to a self-referential type, e.g. a standard list
-- type with a next pointer. Will be reset after subtype is built.
Set_Directly_Designated_Type
(Derived_Type, Designated_Type (Parent_Type));
Subt := Process_Subtype (S, N);
if Nkind (S) /= N_Subtype_Indication
and then Subt /= Base_Type (Subt)
then
Set_Ekind (Derived_Type, E_Access_Subtype);
end if;
if Ekind (Derived_Type) = E_Access_Subtype then
declare
Pbase : constant Entity_Id := Base_Type (Parent_Type);
Ibase : constant Entity_Id :=
Create_Itype (Ekind (Pbase), N, Derived_Type, 'B');
Svg_Chars : constant Name_Id := Chars (Ibase);
Svg_Next_E : constant Entity_Id := Next_Entity (Ibase);
begin
Copy_Node (Pbase, Ibase);
Set_Chars (Ibase, Svg_Chars);
Set_Next_Entity (Ibase, Svg_Next_E);
Set_Sloc (Ibase, Sloc (Derived_Type));
Set_Scope (Ibase, Scope (Derived_Type));
Set_Freeze_Node (Ibase, Empty);
Set_Is_Frozen (Ibase, False);
Set_Comes_From_Source (Ibase, False);
Set_Is_First_Subtype (Ibase, False);
Set_Etype (Ibase, Pbase);
Set_Etype (Derived_Type, Ibase);
end;
end if;
Set_Directly_Designated_Type
(Derived_Type, Designated_Type (Subt));
Set_Is_Constrained (Derived_Type, Is_Constrained (Subt));
Set_Is_Access_Constant (Derived_Type, Is_Access_Constant (Parent_Type));
Set_Size_Info (Derived_Type, Parent_Type);
Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
Set_Depends_On_Private (Derived_Type,
Has_Private_Component (Derived_Type));
Conditional_Delay (Derived_Type, Subt);
-- Ada 2005 (AI-231). Set the null-exclusion attribute
if Null_Exclusion_Present (Type_Definition (N))
or else Can_Never_Be_Null (Parent_Type)
then
Set_Can_Never_Be_Null (Derived_Type);
end if;
-- Note: we do not copy the Storage_Size_Variable, since
-- we always go to the root type for this information.
-- Apply range checks to discriminants for derived record case
-- ??? THIS CODE SHOULD NOT BE HERE REALLY.
Desig_Type := Designated_Type (Derived_Type);
if Is_Composite_Type (Desig_Type)
and then (not Is_Array_Type (Desig_Type))
and then Has_Discriminants (Desig_Type)
and then Base_Type (Desig_Type) /= Desig_Type
then
Discr_Con_Elist := Discriminant_Constraint (Desig_Type);
Discr_Con_El := First_Elmt (Discr_Con_Elist);
Discr := First_Discriminant (Base_Type (Desig_Type));
while Present (Discr_Con_El) loop
Apply_Range_Check (Node (Discr_Con_El), Etype (Discr));
Next_Elmt (Discr_Con_El);
Next_Discriminant (Discr);
end loop;
end if;
end Build_Derived_Access_Type;
------------------------------
-- Build_Derived_Array_Type --
------------------------------
procedure Build_Derived_Array_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Tdef : constant Node_Id := Type_Definition (N);
Indic : constant Node_Id := Subtype_Indication (Tdef);
Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
Implicit_Base : Entity_Id;
New_Indic : Node_Id;
procedure Make_Implicit_Base;
-- If the parent subtype is constrained, the derived type is a
-- subtype of an implicit base type derived from the parent base.
------------------------
-- Make_Implicit_Base --
------------------------
procedure Make_Implicit_Base is
begin
Implicit_Base :=
Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
Set_Ekind (Implicit_Base, Ekind (Parent_Base));
Set_Etype (Implicit_Base, Parent_Base);
Copy_Array_Subtype_Attributes (Implicit_Base, Parent_Base);
Copy_Array_Base_Type_Attributes (Implicit_Base, Parent_Base);
Set_Has_Delayed_Freeze (Implicit_Base, True);
end Make_Implicit_Base;
-- Start of processing for Build_Derived_Array_Type
begin
if not Is_Constrained (Parent_Type) then
if Nkind (Indic) /= N_Subtype_Indication then
Set_Ekind (Derived_Type, E_Array_Type);
Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
Copy_Array_Base_Type_Attributes (Derived_Type, Parent_Type);
Set_Has_Delayed_Freeze (Derived_Type, True);
else
Make_Implicit_Base;
Set_Etype (Derived_Type, Implicit_Base);
New_Indic :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Derived_Type,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Reference_To (Implicit_Base, Loc),
Constraint => Constraint (Indic)));
Rewrite (N, New_Indic);
Analyze (N);
end if;
else
if Nkind (Indic) /= N_Subtype_Indication then
Make_Implicit_Base;
Set_Ekind (Derived_Type, Ekind (Parent_Type));
Set_Etype (Derived_Type, Implicit_Base);
Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
else
Error_Msg_N ("illegal constraint on constrained type", Indic);
end if;
end if;
-- If parent type is not a derived type itself, and is declared in
-- closed scope (e.g. a subprogram), then we must explicitly introduce
-- the new type's concatenation operator since Derive_Subprograms
-- will not inherit the parent's operator. If the parent type is
-- unconstrained, the operator is of the unconstrained base type.
if Number_Dimensions (Parent_Type) = 1
and then not Is_Limited_Type (Parent_Type)
and then not Is_Derived_Type (Parent_Type)
and then not Is_Package_Or_Generic_Package
(Scope (Base_Type (Parent_Type)))
then
if not Is_Constrained (Parent_Type)
and then Is_Constrained (Derived_Type)
then
New_Concatenation_Op (Implicit_Base);
else
New_Concatenation_Op (Derived_Type);
end if;
end if;
end Build_Derived_Array_Type;
-----------------------------------
-- Build_Derived_Concurrent_Type --
-----------------------------------
procedure Build_Derived_Concurrent_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id)
is
D_Constraint : Node_Id;
Disc_Spec : Node_Id;
Old_Disc : Entity_Id;
New_Disc : Entity_Id;
Constraint_Present : constant Boolean :=
Nkind (Subtype_Indication (Type_Definition (N)))
= N_Subtype_Indication;
begin
Set_Stored_Constraint (Derived_Type, No_Elist);
if Is_Task_Type (Parent_Type) then
Set_Storage_Size_Variable (Derived_Type,
Storage_Size_Variable (Parent_Type));
end if;
if Present (Discriminant_Specifications (N)) then
New_Scope (Derived_Type);
Check_Or_Process_Discriminants (N, Derived_Type);
End_Scope;
elsif Constraint_Present then
-- Build constrained subtype and derive from it
declare
Loc : constant Source_Ptr := Sloc (N);
Anon : constant Entity_Id :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (Derived_Type), 'T'));
Decl : Node_Id;
begin
Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Anon,
Subtype_Indication =>
New_Copy_Tree (Subtype_Indication (Type_Definition (N))));
Insert_Before (N, Decl);
Rewrite (Subtype_Indication (Type_Definition (N)),
New_Occurrence_Of (Anon, Loc));
Analyze (Decl);
Set_Analyzed (Derived_Type, False);
Analyze (N);
return;
end;
end if;
-- All attributes are inherited from parent. In particular,
-- entries and the corresponding record type are the same.
-- Discriminants may be renamed, and must be treated separately.
Set_Has_Discriminants
(Derived_Type, Has_Discriminants (Parent_Type));
Set_Corresponding_Record_Type
(Derived_Type, Corresponding_Record_Type (Parent_Type));
if Constraint_Present then
if not Has_Discriminants (Parent_Type) then
Error_Msg_N ("untagged parent must have discriminants", N);
elsif Present (Discriminant_Specifications (N)) then
-- Verify that new discriminants are used to constrain old ones
D_Constraint :=
First
(Constraints
(Constraint (Subtype_Indication (Type_Definition (N)))));
Old_Disc := First_Discriminant (Parent_Type);
New_Disc := First_Discriminant (Derived_Type);
Disc_Spec := First (Discriminant_Specifications (N));
while Present (Old_Disc) and then Present (Disc_Spec) loop
if Nkind (Discriminant_Type (Disc_Spec)) /=
N_Access_Definition
then
Analyze (Discriminant_Type (Disc_Spec));
if not Subtypes_Statically_Compatible (
Etype (Discriminant_Type (Disc_Spec)),
Etype (Old_Disc))
then
Error_Msg_N
("not statically compatible with parent discriminant",
Discriminant_Type (Disc_Spec));
end if;
end if;
if Nkind (D_Constraint) = N_Identifier
and then Chars (D_Constraint) /=
Chars (Defining_Identifier (Disc_Spec))
then
Error_Msg_N ("new discriminants must constrain old ones",
D_Constraint);
else
Set_Corresponding_Discriminant (New_Disc, Old_Disc);
end if;
Next_Discriminant (Old_Disc);
Next_Discriminant (New_Disc);
Next (Disc_Spec);
end loop;
if Present (Old_Disc) or else Present (Disc_Spec) then
Error_Msg_N ("discriminant mismatch in derivation", N);
end if;
end if;
elsif Present (Discriminant_Specifications (N)) then
Error_Msg_N
("missing discriminant constraint in untagged derivation",
N);
end if;
if Present (Discriminant_Specifications (N)) then
Old_Disc := First_Discriminant (Parent_Type);
while Present (Old_Disc) loop
if No (Next_Entity (Old_Disc))
or else Ekind (Next_Entity (Old_Disc)) /= E_Discriminant
then
Set_Next_Entity (Last_Entity (Derived_Type),
Next_Entity (Old_Disc));
exit;
end if;
Next_Discriminant (Old_Disc);
end loop;
else
Set_First_Entity (Derived_Type, First_Entity (Parent_Type));
if Has_Discriminants (Parent_Type) then
Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
Set_Discriminant_Constraint (
Derived_Type, Discriminant_Constraint (Parent_Type));
end if;
end if;
Set_Last_Entity (Derived_Type, Last_Entity (Parent_Type));
Set_Has_Completion (Derived_Type);
end Build_Derived_Concurrent_Type;
------------------------------------
-- Build_Derived_Enumeration_Type --
------------------------------------
procedure Build_Derived_Enumeration_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Def : constant Node_Id := Type_Definition (N);
Indic : constant Node_Id := Subtype_Indication (Def);
Implicit_Base : Entity_Id;
Literal : Entity_Id;
New_Lit : Entity_Id;
Literals_List : List_Id;
Type_Decl : Node_Id;
Hi, Lo : Node_Id;
Rang_Expr : Node_Id;
begin
-- Since types Standard.Character and Standard.Wide_Character do
-- not have explicit literals lists we need to process types derived
-- from them specially. This is handled by Derived_Standard_Character.
-- If the parent type is a generic type, there are no literals either,
-- and we construct the same skeletal representation as for the generic
-- parent type.
if Root_Type (Parent_Type) = Standard_Character
or else Root_Type (Parent_Type) = Standard_Wide_Character
or else Root_Type (Parent_Type) = Standard_Wide_Wide_Character
then
Derived_Standard_Character (N, Parent_Type, Derived_Type);
elsif Is_Generic_Type (Root_Type (Parent_Type)) then
declare
Lo : Node_Id;
Hi : Node_Id;
begin
Lo :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_First,
Prefix => New_Reference_To (Derived_Type, Loc));
Set_Etype (Lo, Derived_Type);
Hi :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Last,
Prefix => New_Reference_To (Derived_Type, Loc));
Set_Etype (Hi, Derived_Type);
Set_Scalar_Range (Derived_Type,
Make_Range (Loc,
Low_Bound => Lo,
High_Bound => Hi));
end;
else
-- If a constraint is present, analyze the bounds to catch
-- premature usage of the derived literals.
if Nkind (Indic) = N_Subtype_Indication
and then Nkind (Range_Expression (Constraint (Indic))) = N_Range
then
Analyze (Low_Bound (Range_Expression (Constraint (Indic))));
Analyze (High_Bound (Range_Expression (Constraint (Indic))));
end if;
-- Introduce an implicit base type for the derived type even
-- if there is no constraint attached to it, since this seems
-- closer to the Ada semantics. Build a full type declaration
-- tree for the derived type using the implicit base type as
-- the defining identifier. The build a subtype declaration
-- tree which applies the constraint (if any) have it replace
-- the derived type declaration.
Literal := First_Literal (Parent_Type);
Literals_List := New_List;
while Present (Literal)
and then Ekind (Literal) = E_Enumeration_Literal
loop
-- Literals of the derived type have the same representation as
-- those of the parent type, but this representation can be
-- overridden by an explicit representation clause. Indicate
-- that there is no explicit representation given yet. These
-- derived literals are implicit operations of the new type,
-- and can be overridden by explicit ones.
if Nkind (Literal) = N_Defining_Character_Literal then
New_Lit :=
Make_Defining_Character_Literal (Loc, Chars (Literal));
else
New_Lit := Make_Defining_Identifier (Loc, Chars (Literal));
end if;
Set_Ekind (New_Lit, E_Enumeration_Literal);
Set_Enumeration_Pos (New_Lit, Enumeration_Pos (Literal));
Set_Enumeration_Rep (New_Lit, Enumeration_Rep (Literal));
Set_Enumeration_Rep_Expr (New_Lit, Empty);
Set_Alias (New_Lit, Literal);
Set_Is_Known_Valid (New_Lit, True);
Append (New_Lit, Literals_List);
Next_Literal (Literal);
end loop;
Implicit_Base :=
Make_Defining_Identifier (Sloc (Derived_Type),
New_External_Name (Chars (Derived_Type), 'B'));
-- Indicate the proper nature of the derived type. This must
-- be done before analysis of the literals, to recognize cases
-- when a literal may be hidden by a previous explicit function
-- definition (cf. c83031a).
Set_Ekind (Derived_Type, E_Enumeration_Subtype);
Set_Etype (Derived_Type, Implicit_Base);
Type_Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Implicit_Base,
Discriminant_Specifications => No_List,
Type_Definition =>
Make_Enumeration_Type_Definition (Loc, Literals_List));
Mark_Rewrite_Insertion (Type_Decl);
Insert_Before (N, Type_Decl);
Analyze (Type_Decl);
-- After the implicit base is analyzed its Etype needs to be changed
-- to reflect the fact that it is derived from the parent type which
-- was ignored during analysis. We also set the size at this point.
Set_Etype (Implicit_Base, Parent_Type);
Set_Size_Info (Implicit_Base, Parent_Type);
Set_RM_Size (Implicit_Base, RM_Size (Parent_Type));
Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Type));
Set_Has_Non_Standard_Rep
(Implicit_Base, Has_Non_Standard_Rep
(Parent_Type));
Set_Has_Delayed_Freeze (Implicit_Base);
-- Process the subtype indication including a validation check
-- on the constraint, if any. If a constraint is given, its bounds
-- must be implicitly converted to the new type.
if Nkind (Indic) = N_Subtype_Indication then
declare
R : constant Node_Id :=
Range_Expression (Constraint (Indic));
begin
if Nkind (R) = N_Range then
Hi := Build_Scalar_Bound
(High_Bound (R), Parent_Type, Implicit_Base);
Lo := Build_Scalar_Bound
(Low_Bound (R), Parent_Type, Implicit_Base);
else
-- Constraint is a Range attribute. Replace with the
-- explicit mention of the bounds of the prefix, which must
-- be a subtype.
Analyze (Prefix (R));
Hi :=
Convert_To (Implicit_Base,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Last,
Prefix =>
New_Occurrence_Of (Entity (Prefix (R)), Loc)));
Lo :=
Convert_To (Implicit_Base,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_First,
Prefix =>
New_Occurrence_Of (Entity (Prefix (R)), Loc)));
end if;
end;
else
Hi :=
Build_Scalar_Bound
(Type_High_Bound (Parent_Type),
Parent_Type, Implicit_Base);
Lo :=
Build_Scalar_Bound
(Type_Low_Bound (Parent_Type),
Parent_Type, Implicit_Base);
end if;
Rang_Expr :=
Make_Range (Loc,
Low_Bound => Lo,
High_Bound => Hi);
-- If we constructed a default range for the case where no range
-- was given, then the expressions in the range must not freeze
-- since they do not correspond to expressions in the source.
if Nkind (Indic) /= N_Subtype_Indication then
Set_Must_Not_Freeze (Lo);
Set_Must_Not_Freeze (Hi);
Set_Must_Not_Freeze (Rang_Expr);
end if;
Rewrite (N,
Make_Subtype_Declaration (Loc,
Defining_Identifier => Derived_Type,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (Implicit_Base, Loc),
Constraint =>
Make_Range_Constraint (Loc,
Range_Expression => Rang_Expr))));
Analyze (N);
-- If pragma Discard_Names applies on the first subtype of the
-- parent type, then it must be applied on this subtype as well.
if Einfo.Discard_Names (First_Subtype (Parent_Type)) then
Set_Discard_Names (Derived_Type);
end if;
-- Apply a range check. Since this range expression doesn't have an
-- Etype, we have to specifically pass the Source_Typ parameter. Is
-- this right???
if Nkind (Indic) = N_Subtype_Indication then
Apply_Range_Check (Range_Expression (Constraint (Indic)),
Parent_Type,
Source_Typ => Entity (Subtype_Mark (Indic)));
end if;
end if;
end Build_Derived_Enumeration_Type;
--------------------------------
-- Build_Derived_Numeric_Type --
--------------------------------
procedure Build_Derived_Numeric_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Tdef : constant Node_Id := Type_Definition (N);
Indic : constant Node_Id := Subtype_Indication (Tdef);
Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
No_Constraint : constant Boolean := Nkind (Indic) /=
N_Subtype_Indication;
Implicit_Base : Entity_Id;
Lo : Node_Id;
Hi : Node_Id;
begin
-- Process the subtype indication including a validation check on
-- the constraint if any.
Discard_Node (Process_Subtype (Indic, N));
-- Introduce an implicit base type for the derived type even if there
-- is no constraint attached to it, since this seems closer to the Ada
-- semantics.
Implicit_Base :=
Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
Set_Etype (Implicit_Base, Parent_Base);
Set_Ekind (Implicit_Base, Ekind (Parent_Base));
Set_Size_Info (Implicit_Base, Parent_Base);
Set_RM_Size (Implicit_Base, RM_Size (Parent_Base));
Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Base));
Set_Parent (Implicit_Base, Parent (Derived_Type));
if Is_Discrete_Or_Fixed_Point_Type (Parent_Base) then
Set_RM_Size (Implicit_Base, RM_Size (Parent_Base));
end if;
Set_Has_Delayed_Freeze (Implicit_Base);
Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
Set_Scalar_Range (Implicit_Base,
Make_Range (Loc,
Low_Bound => Lo,
High_Bound => Hi));
if Has_Infinities (Parent_Base) then
Set_Includes_Infinities (Scalar_Range (Implicit_Base));
end if;
-- The Derived_Type, which is the entity of the declaration, is a
-- subtype of the implicit base. Its Ekind is a subtype, even in the
-- absence of an explicit constraint.
Set_Etype (Derived_Type, Implicit_Base);
-- If we did not have a constraint, then the Ekind is set from the
-- parent type (otherwise Process_Subtype has set the bounds)
if No_Constraint then
Set_Ekind (Derived_Type, Subtype_Kind (Ekind (Parent_Type)));
end if;
-- If we did not have a range constraint, then set the range from the
-- parent type. Otherwise, the call to Process_Subtype has set the
-- bounds.
if No_Constraint
or else not Has_Range_Constraint (Indic)
then
Set_Scalar_Range (Derived_Type,
Make_Range (Loc,
Low_Bound => New_Copy_Tree (Type_Low_Bound (Parent_Type)),
High_Bound => New_Copy_Tree (Type_High_Bound (Parent_Type))));
Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
if Has_Infinities (Parent_Type) then
Set_Includes_Infinities (Scalar_Range (Derived_Type));
end if;
end if;
-- Set remaining type-specific fields, depending on numeric type
if Is_Modular_Integer_Type (Parent_Type) then
Set_Modulus (Implicit_Base, Modulus (Parent_Base));
Set_Non_Binary_Modulus
(Implicit_Base, Non_Binary_Modulus (Parent_Base));
elsif Is_Floating_Point_Type (Parent_Type) then
-- Digits of base type is always copied from the digits value of
-- the parent base type, but the digits of the derived type will
-- already have been set if there was a constraint present.
Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
Set_Vax_Float (Implicit_Base, Vax_Float (Parent_Base));
if No_Constraint then
Set_Digits_Value (Derived_Type, Digits_Value (Parent_Type));
end if;
elsif Is_Fixed_Point_Type (Parent_Type) then
-- Small of base type and derived type are always copied from the
-- parent base type, since smalls never change. The delta of the
-- base type is also copied from the parent base type. However the
-- delta of the derived type will have been set already if a
-- constraint was present.
Set_Small_Value (Derived_Type, Small_Value (Parent_Base));
Set_Small_Value (Implicit_Base, Small_Value (Parent_Base));
Set_Delta_Value (Implicit_Base, Delta_Value (Parent_Base));
if No_Constraint then
Set_Delta_Value (Derived_Type, Delta_Value (Parent_Type));
end if;
-- The scale and machine radix in the decimal case are always
-- copied from the parent base type.
if Is_Decimal_Fixed_Point_Type (Parent_Type) then
Set_Scale_Value (Derived_Type, Scale_Value (Parent_Base));
Set_Scale_Value (Implicit_Base, Scale_Value (Parent_Base));
Set_Machine_Radix_10
(Derived_Type, Machine_Radix_10 (Parent_Base));
Set_Machine_Radix_10
(Implicit_Base, Machine_Radix_10 (Parent_Base));
Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
if No_Constraint then
Set_Digits_Value (Derived_Type, Digits_Value (Parent_Base));
else
-- the analysis of the subtype_indication sets the
-- digits value of the derived type.
null;
end if;
end if;
end if;
-- The type of the bounds is that of the parent type, and they
-- must be converted to the derived type.
Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
-- The implicit_base should be frozen when the derived type is frozen,
-- but note that it is used in the conversions of the bounds. For fixed
-- types we delay the determination of the bounds until the proper
-- freezing point. For other numeric types this is rejected by GCC, for
-- reasons that are currently unclear (???), so we choose to freeze the
-- implicit base now. In the case of integers and floating point types
-- this is harmless because subsequent representation clauses cannot
-- affect anything, but it is still baffling that we cannot use the
-- same mechanism for all derived numeric types.
if Is_Fixed_Point_Type (Parent_Type) then
Conditional_Delay (Implicit_Base, Parent_Type);
else
Freeze_Before (N, Implicit_Base);
end if;
end Build_Derived_Numeric_Type;
--------------------------------
-- Build_Derived_Private_Type --
--------------------------------
procedure Build_Derived_Private_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id;
Is_Completion : Boolean;
Derive_Subps : Boolean := True)
is
Der_Base : Entity_Id;
Discr : Entity_Id;
Full_Decl : Node_Id := Empty;
Full_Der : Entity_Id;
Full_P : Entity_Id;
Last_Discr : Entity_Id;
Par_Scope : constant Entity_Id := Scope (Base_Type (Parent_Type));
Swapped : Boolean := False;
procedure Copy_And_Build;
-- Copy derived type declaration, replace parent with its full view,
-- and analyze new declaration.
--------------------
-- Copy_And_Build --
--------------------
procedure Copy_And_Build is
Full_N : Node_Id;
begin
if Ekind (Parent_Type) in Record_Kind
or else
(Ekind (Parent_Type) in Enumeration_Kind
and then Root_Type (Parent_Type) /= Standard_Character
and then Root_Type (Parent_Type) /= Standard_Wide_Character
and then Root_Type (Parent_Type) /= Standard_Wide_Wide_Character
and then not Is_Generic_Type (Root_Type (Parent_Type)))
then
Full_N := New_Copy_Tree (N);
Insert_After (N, Full_N);
Build_Derived_Type (
Full_N, Parent_Type, Full_Der, True, Derive_Subps => False);
else
Build_Derived_Type (
N, Parent_Type, Full_Der, True, Derive_Subps => False);
end if;
end Copy_And_Build;
-- Start of processing for Build_Derived_Private_Type
begin
if Is_Tagged_Type (Parent_Type) then
Build_Derived_Record_Type
(N, Parent_Type, Derived_Type, Derive_Subps);
return;
elsif Has_Discriminants (Parent_Type) then
if Present (Full_View (Parent_Type)) then
if not Is_Completion then
-- Copy declaration for subsequent analysis, to provide a
-- completion for what is a private declaration. Indicate that
-- the full type is internally generated.
Full_Decl := New_Copy_Tree (N);
Full_Der := New_Copy (Derived_Type);
Set_Comes_From_Source (Full_Decl, False);
Set_Comes_From_Source (Full_Der, False);
Insert_After (N, Full_Decl);
else
-- If this is a completion, the full view being built is
-- itself private. We build a subtype of the parent with
-- the same constraints as this full view, to convey to the
-- back end the constrained components and the size of this
-- subtype. If the parent is constrained, its full view can
-- serve as the underlying full view of the derived type.
if No (Discriminant_Specifications (N)) then
if Nkind (Subtype_Indication (Type_Definition (N))) =
N_Subtype_Indication
then
Build_Underlying_Full_View (N, Derived_Type, Parent_Type);
elsif Is_Constrained (Full_View (Parent_Type)) then
Set_Underlying_Full_View (Derived_Type,
Full_View (Parent_Type));
end if;
else
-- If there are new discriminants, the parent subtype is
-- constrained by them, but it is not clear how to build
-- the underlying_full_view in this case ???
null;
end if;
end if;
end if;
-- Build partial view of derived type from partial view of parent
Build_Derived_Record_Type
(N, Parent_Type, Derived_Type, Derive_Subps);
if Present (Full_View (Parent_Type))
and then not Is_Completion
then
if not In_Open_Scopes (Par_Scope)
or else not In_Same_Source_Unit (N, Parent_Type)
then
-- Swap partial and full views temporarily
Install_Private_Declarations (Par_Scope);
Install_Visible_Declarations (Par_Scope);
Swapped := True;
end if;
-- Build full view of derived type from full view of parent which
-- is now installed. Subprograms have been derived on the partial
-- view, the completion does not derive them anew.
if not Is_Tagged_Type (Parent_Type) then
-- If the parent is itself derived from another private type,
-- installing the private declarations has not affected its
-- privacy status, so use its own full view explicitly.
if Is_Private_Type (Parent_Type) then
Build_Derived_Record_Type
(Full_Decl, Full_View (Parent_Type), Full_Der, False);
else
Build_Derived_Record_Type
(Full_Decl, Parent_Type, Full_Der, False);
end if;
else
-- If full view of parent is tagged, the completion
-- inherits the proper primitive operations.
Set_Defining_Identifier (Full_Decl, Full_Der);
Build_Derived_Record_Type
(Full_Decl, Parent_Type, Full_Der, Derive_Subps);
Set_Analyzed (Full_Decl);
end if;
if Swapped then
Uninstall_Declarations (Par_Scope);
if In_Open_Scopes (Par_Scope) then
Install_Visible_Declarations (Par_Scope);
end if;
end if;
Der_Base := Base_Type (Derived_Type);
Set_Full_View (Derived_Type, Full_Der);
Set_Full_View (Der_Base, Base_Type (Full_Der));
-- Copy the discriminant list from full view to the partial views
-- (base type and its subtype). Gigi requires that the partial
-- and full views have the same discriminants.
-- Note that since the partial view is pointing to discriminants
-- in the full view, their scope will be that of the full view.
-- This might cause some front end problems and need
-- adjustment???
Discr := First_Discriminant (Base_Type (Full_Der));
Set_First_Entity (Der_Base, Discr);
loop
Last_Discr := Discr;
Next_Discriminant (Discr);
exit when No (Discr);
end loop;
Set_Last_Entity (Der_Base, Last_Discr);
Set_First_Entity (Derived_Type, First_Entity (Der_Base));
Set_Last_Entity (Derived_Type, Last_Entity (Der_Base));
Set_Stored_Constraint (Full_Der, Stored_Constraint (Derived_Type));
else
-- If this is a completion, the derived type stays private
-- and there is no need to create a further full view, except
-- in the unusual case when the derivation is nested within a
-- child unit, see below.
null;
end if;
elsif Present (Full_View (Parent_Type))
and then Has_Discriminants (Full_View (Parent_Type))
then
if Has_Unknown_Discriminants (Parent_Type)
and then Nkind (Subtype_Indication (Type_Definition (N)))
= N_Subtype_Indication
then
Error_Msg_N
("cannot constrain type with unknown discriminants",
Subtype_Indication (Type_Definition (N)));
return;
end if;
-- If full view of parent is a record type, Build full view as
-- a derivation from the parent's full view. Partial view remains
-- private. For code generation and linking, the full view must
-- have the same public status as the partial one. This full view
-- is only needed if the parent type is in an enclosing scope, so
-- that the full view may actually become visible, e.g. in a child
-- unit. This is both more efficient, and avoids order of freezing
-- problems with the added entities.
if not Is_Private_Type (Full_View (Parent_Type))
and then (In_Open_Scopes (Scope (Parent_Type)))
then
Full_Der := Make_Defining_Identifier (Sloc (Derived_Type),
Chars (Derived_Type));
Set_Is_Itype (Full_Der);
Set_Has_Private_Declaration (Full_Der);
Set_Has_Private_Declaration (Derived_Type);
Set_Associated_Node_For_Itype (Full_Der, N);
Set_Parent (Full_Der, Parent (Derived_Type));
Set_Full_View (Derived_Type, Full_Der);
Set_Is_Public (Full_Der, Is_Public (Derived_Type));
Full_P := Full_View (Parent_Type);
Exchange_Declarations (Parent_Type);
Copy_And_Build;
Exchange_Declarations (Full_P);
else
Build_Derived_Record_Type
(N, Full_View (Parent_Type), Derived_Type,
Derive_Subps => False);
end if;
-- In any case, the primitive operations are inherited from
-- the parent type, not from the internal full view.
Set_Etype (Base_Type (Derived_Type), Base_Type (Parent_Type));
if Derive_Subps then
Derive_Subprograms (Parent_Type, Derived_Type);
end if;
else
-- Untagged type, No discriminants on either view
if Nkind (Subtype_Indication (Type_Definition (N))) =
N_Subtype_Indication
then
Error_Msg_N
("illegal constraint on type without discriminants", N);
end if;
if Present (Discriminant_Specifications (N))
and then Present (Full_View (Parent_Type))
and then not Is_Tagged_Type (Full_View (Parent_Type))
then
Error_Msg_N
("cannot add discriminants to untagged type", N);
end if;
Set_Stored_Constraint (Derived_Type, No_Elist);
Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
Set_Has_Controlled_Component
(Derived_Type, Has_Controlled_Component
(Parent_Type));
-- Direct controlled types do not inherit Finalize_Storage_Only flag
if not Is_Controlled (Parent_Type) then
Set_Finalize_Storage_Only
(Base_Type (Derived_Type), Finalize_Storage_Only (Parent_Type));
end if;
-- Construct the implicit full view by deriving from full view of
-- the parent type. In order to get proper visibility, we install
-- the parent scope and its declarations.
-- ??? if the parent is untagged private and its completion is
-- tagged, this mechanism will not work because we cannot derive
-- from the tagged full view unless we have an extension
if Present (Full_View (Parent_Type))
and then not Is_Tagged_Type (Full_View (Parent_Type))
and then not Is_Completion
then
Full_Der :=
Make_Defining_Identifier (Sloc (Derived_Type),
Chars => Chars (Derived_Type));
Set_Is_Itype (Full_Der);
Set_Has_Private_Declaration (Full_Der);
Set_Has_Private_Declaration (Derived_Type);
Set_Associated_Node_For_Itype (Full_Der, N);
Set_Parent (Full_Der, Parent (Derived_Type));
Set_Full_View (Derived_Type, Full_Der);
if not In_Open_Scopes (Par_Scope) then
Install_Private_Declarations (Par_Scope);
Install_Visible_Declarations (Par_Scope);
Copy_And_Build;
Uninstall_Declarations (Par_Scope);
-- If parent scope is open and in another unit, and parent has a
-- completion, then the derivation is taking place in the visible
-- part of a child unit. In that case retrieve the full view of
-- the parent momentarily.
elsif not In_Same_Source_Unit (N, Parent_Type) then
Full_P := Full_View (Parent_Type);
Exchange_Declarations (Parent_Type);
Copy_And_Build;
Exchange_Declarations (Full_P);
-- Otherwise it is a local derivation
else
Copy_And_Build;
end if;
Set_Scope (Full_Der, Current_Scope);
Set_Is_First_Subtype (Full_Der,
Is_First_Subtype (Derived_Type));
Set_Has_Size_Clause (Full_Der, False);
Set_Has_Alignment_Clause (Full_Der, False);
Set_Next_Entity (Full_Der, Empty);
Set_Has_Delayed_Freeze (Full_Der);
Set_Is_Frozen (Full_Der, False);
Set_Freeze_Node (Full_Der, Empty);
Set_Depends_On_Private (Full_Der,
Has_Private_Component (Full_Der));
Set_Public_Status (Full_Der);
end if;
end if;
Set_Has_Unknown_Discriminants (Derived_Type,
Has_Unknown_Discriminants (Parent_Type));
if Is_Private_Type (Derived_Type) then
Set_Private_Dependents (Derived_Type, New_Elmt_List);
end if;
if Is_Private_Type (Parent_Type)
and then Base_Type (Parent_Type) = Parent_Type
and then In_Open_Scopes (Scope (Parent_Type))
then
Append_Elmt (Derived_Type, Private_Dependents (Parent_Type));
if Is_Child_Unit (Scope (Current_Scope))
and then Is_Completion
and then In_Private_Part (Current_Scope)
and then Scope (Parent_Type) /= Current_Scope
then
-- This is the unusual case where a type completed by a private
-- derivation occurs within a package nested in a child unit,
-- and the parent is declared in an ancestor. In this case, the
-- full view of the parent type will become visible in the body
-- of the enclosing child, and only then will the current type
-- be possibly non-private. We build a underlying full view that
-- will be installed when the enclosing child body is compiled.
declare
IR : constant Node_Id := Make_Itype_Reference (Sloc (N));
begin
Full_Der :=
Make_Defining_Identifier (Sloc (Derived_Type),
Chars (Derived_Type));
Set_Is_Itype (Full_Der);
Set_Itype (IR, Full_Der);
Insert_After (N, IR);
-- The full view will be used to swap entities on entry/exit
-- to the body, and must appear in the entity list for the
-- package.
Append_Entity (Full_Der, Scope (Derived_Type));
Set_Has_Private_Declaration (Full_Der);
Set_Has_Private_Declaration (Derived_Type);
Set_Associated_Node_For_Itype (Full_Der, N);
Set_Parent (Full_Der, Parent (Derived_Type));
Full_P := Full_View (Parent_Type);
Exchange_Declarations (Parent_Type);
Copy_And_Build;
Exchange_Declarations (Full_P);
Set_Underlying_Full_View (Derived_Type, Full_Der);
end;
end if;
end if;
end Build_Derived_Private_Type;
-------------------------------
-- Build_Derived_Record_Type --
-------------------------------
-- 1. INTRODUCTION
-- Ideally we would like to use the same model of type derivation for
-- tagged and untagged record types. Unfortunately this is not quite
-- possible because the semantics of representation clauses is different
-- for tagged and untagged records under inheritance. Consider the
-- following:
-- type R (...) is [tagged] record ... end record;
-- type T (...) is new R (...) [with ...];
-- The representation clauses of T can specify a completely different
-- record layout from R's. Hence the same component can be placed in
-- two very different positions in objects of type T and R. If R and T
-- are tagged types, representation clauses for T can only specify the
-- layout of non inherited components, thus components that are common
-- in R and T have the same position in objects of type R and T.
-- This has two implications. The first is that the entire tree for R's
-- declaration needs to be copied for T in the untagged case, so that T
-- can be viewed as a record type of its own with its own representation
-- clauses. The second implication is the way we handle discriminants.
-- Specifically, in the untagged case we need a way to communicate to Gigi
-- what are the real discriminants in the record, while for the semantics
-- we need to consider those introduced by the user to rename the
-- discriminants in the parent type. This is handled by introducing the
-- notion of stored discriminants. See below for more.
-- Fortunately the way regular components are inherited can be handled in
-- the same way in tagged and untagged types.
-- To complicate things a bit more the private view of a private extension
-- cannot be handled in the same way as the full view (for one thing the
-- semantic rules are somewhat different). We will explain what differs
-- below.
-- 2. DISCRIMINANTS UNDER INHERITANCE
-- The semantic rules governing the discriminants of derived types are
-- quite subtle.
-- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
-- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
-- If parent type has discriminants, then the discriminants that are
-- declared in the derived type are [3.4 (11)]:
-- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
-- there is one;
-- o Otherwise, each discriminant of the parent type (implicitly declared
-- in the same order with the same specifications). In this case, the
-- discriminants are said to be "inherited", or if unknown in the parent
-- are also unknown in the derived type.
-- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
-- o The parent subtype shall be constrained;
-- o If the parent type is not a tagged type, then each discriminant of
-- the derived type shall be used in the constraint defining a parent
-- subtype [Implementation note: this ensures that the new discriminant
-- can share storage with an existing discriminant.].
-- For the derived type each discriminant of the parent type is either
-- inherited, constrained to equal some new discriminant of the derived
-- type, or constrained to the value of an expression.
-- When inherited or constrained to equal some new discriminant, the
-- parent discriminant and the discriminant of the derived type are said
-- to "correspond".
-- If a discriminant of the parent type is constrained to a specific value
-- in the derived type definition, then the discriminant is said to be
-- "specified" by that derived type definition.
-- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
-- We have spoken about stored discriminants in point 1 (introduction)
-- above. There are two sort of stored discriminants: implicit and
-- explicit. As long as the derived type inherits the same discriminants as
-- the root record type, stored discriminants are the same as regular
-- discriminants, and are said to be implicit. However, if any discriminant
-- in the root type was renamed in the derived type, then the derived
-- type will contain explicit stored discriminants. Explicit stored
-- discriminants are discriminants in addition to the semantically visible
-- discriminants defined for the derived type. Stored discriminants are
-- used by Gigi to figure out what are the physical discriminants in
-- objects of the derived type (see precise definition in einfo.ads).
-- As an example, consider the following:
-- type R (D1, D2, D3 : Int) is record ... end record;
-- type T1 is new R;
-- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
-- type T3 is new T2;
-- type T4 (Y : Int) is new T3 (Y, 99);
-- The following table summarizes the discriminants and stored
-- discriminants in R and T1 through T4.
-- Type Discrim Stored Discrim Comment
-- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R
-- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1
-- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2
-- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3
-- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4
-- Field Corresponding_Discriminant (abbreviated CD below) allows us to
-- find the corresponding discriminant in the parent type, while
-- Original_Record_Component (abbreviated ORC below), the actual physical
-- component that is renamed. Finally the field Is_Completely_Hidden
-- (abbreviated ICH below) is set for all explicit stored discriminants
-- (see einfo.ads for more info). For the above example this gives:
-- Discrim CD ORC ICH
-- ^^^^^^^ ^^ ^^^ ^^^
-- D1 in R empty itself no
-- D2 in R empty itself no
-- D3 in R empty itself no
-- D1 in T1 D1 in R itself no
-- D2 in T1 D2 in R itself no
-- D3 in T1 D3 in R itself no
-- X1 in T2 D3 in T1 D3 in T2 no
-- X2 in T2 D1 in T1 D1 in T2 no
-- D1 in T2 empty itself yes
-- D2 in T2 empty itself yes
-- D3 in T2 empty itself yes
-- X1 in T3 X1 in T2 D3 in T3 no
-- X2 in T3 X2 in T2 D1 in T3 no
-- D1 in T3 empty itself yes
-- D2 in T3 empty itself yes
-- D3 in T3 empty itself yes
-- Y in T4 X1 in T3 D3 in T3 no
-- D1 in T3 empty itself yes
-- D2 in T3 empty itself yes
-- D3 in T3 empty itself yes
-- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
-- Type derivation for tagged types is fairly straightforward. if no
-- discriminants are specified by the derived type, these are inherited
-- from the parent. No explicit stored discriminants are ever necessary.
-- The only manipulation that is done to the tree is that of adding a
-- _parent field with parent type and constrained to the same constraint
-- specified for the parent in the derived type definition. For instance:
-- type R (D1, D2, D3 : Int) is tagged record ... end record;
-- type T1 is new R with null record;
-- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
-- are changed into:
-- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
-- _parent : R (D1, D2, D3);
-- end record;
-- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
-- _parent : T1 (X2, 88, X1);
-- end record;
-- The discriminants actually present in R, T1 and T2 as well as their CD,
-- ORC and ICH fields are:
-- Discrim CD ORC ICH
-- ^^^^^^^ ^^ ^^^ ^^^
-- D1 in R empty itself no
-- D2 in R empty itself no
-- D3 in R empty itself no
-- D1 in T1 D1 in R D1 in R no
-- D2 in T1 D2 in R D2 in R no
-- D3 in T1 D3 in R D3 in R no
-- X1 in T2 D3 in T1 D3 in R no
-- X2 in T2 D1 in T1 D1 in R no
-- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
--
-- Regardless of whether we dealing with a tagged or untagged type
-- we will transform all derived type declarations of the form
--
-- type T is new R (...) [with ...];
-- or
-- subtype S is R (...);
-- type T is new S [with ...];
-- into
-- type BT is new R [with ...];
-- subtype T is BT (...);
--
-- That is, the base derived type is constrained only if it has no
-- discriminants. The reason for doing this is that GNAT's semantic model
-- assumes that a base type with discriminants is unconstrained.
--
-- Note that, strictly speaking, the above transformation is not always
-- correct. Consider for instance the following excerpt from ACVC b34011a:
--
-- procedure B34011A is
-- type REC (D : integer := 0) is record
-- I : Integer;
-- end record;
-- package P is
-- type T6 is new Rec;
-- function F return T6;
-- end P;
-- use P;
-- package Q6 is
-- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
-- end Q6;
--
-- The definition of Q6.U is illegal. However transforming Q6.U into
-- type BaseU is new T6;
-- subtype U is BaseU (Q6.F.I)
-- turns U into a legal subtype, which is incorrect. To avoid this problem
-- we always analyze the constraint (in this case (Q6.F.I)) before applying
-- the transformation described above.
-- There is another instance where the above transformation is incorrect.
-- Consider:
-- package Pack is
-- type Base (D : Integer) is tagged null record;
-- procedure P (X : Base);
-- type Der is new Base (2) with null record;
-- procedure P (X : Der);
-- end Pack;
-- Then the above transformation turns this into
-- type Der_Base is new Base with null record;
-- -- procedure P (X : Base) is implicitly inherited here
-- -- as procedure P (X : Der_Base).
-- subtype Der is Der_Base (2);
-- procedure P (X : Der);
-- -- The overriding of P (X : Der_Base) is illegal since we
-- -- have a parameter conformance problem.
-- To get around this problem, after having semantically processed Der_Base
-- and the rewritten subtype declaration for Der, we copy Der_Base field
-- Discriminant_Constraint from Der so that when parameter conformance is
-- checked when P is overridden, no semantic errors are flagged.
-- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
-- Regardless of whether we are dealing with a tagged or untagged type
-- we will transform all derived type declarations of the form
-- type R (D1, .., Dn : ...) is [tagged] record ...;
-- type T is new R [with ...];
-- into
-- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
-- The reason for such transformation is that it allows us to implement a
-- very clean form of component inheritance as explained below.
-- Note that this transformation is not achieved by direct tree rewriting
-- and manipulation, but rather by redoing the semantic actions that the
-- above transformation will entail. This is done directly in routine
-- Inherit_Components.
-- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
-- In both tagged and untagged derived types, regular non discriminant
-- components are inherited in the derived type from the parent type. In
-- the absence of discriminants component, inheritance is straightforward
-- as components can simply be copied from the parent.
-- If the parent has discriminants, inheriting components constrained with
-- these discriminants requires caution. Consider the following example:
-- type R (D1, D2 : Positive) is [tagged] record
-- S : String (D1 .. D2);
-- end record;
-- type T1 is new R [with null record];
-- type T2 (X : positive) is new R (1, X) [with null record];
-- As explained in 6. above, T1 is rewritten as
-- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
-- which makes the treatment for T1 and T2 identical.
-- What we want when inheriting S, is that references to D1 and D2 in R are
-- replaced with references to their correct constraints, ie D1 and D2 in
-- T1 and 1 and X in T2. So all R's discriminant references are replaced
-- with either discriminant references in the derived type or expressions.
-- This replacement is achieved as follows: before inheriting R's
-- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
-- created in the scope of T1 (resp. scope of T2) so that discriminants D1
-- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
-- For T2, for instance, this has the effect of replacing String (D1 .. D2)
-- by String (1 .. X).
-- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
-- We explain here the rules governing private type extensions relevant to
-- type derivation. These rules are explained on the following example:
-- type D [(...)] is new A [(...)] with private; <-- partial view
-- type D [(...)] is new P [(...)] with null record; <-- full view
-- Type A is called the ancestor subtype of the private extension.
-- Type P is the parent type of the full view of the private extension. It
-- must be A or a type derived from A.
-- The rules concerning the discriminants of private type extensions are
-- [7.3(10-13)]:
-- o If a private extension inherits known discriminants from the ancestor
-- subtype, then the full view shall also inherit its discriminants from
-- the ancestor subtype and the parent subtype of the full view shall be
-- constrained if and only if the ancestor subtype is constrained.
-- o If a partial view has unknown discriminants, then the full view may
-- define a definite or an indefinite subtype, with or without
-- discriminants.
-- o If a partial view has neither known nor unknown discriminants, then
-- the full view shall define a definite subtype.
-- o If the ancestor subtype of a private extension has constrained
-- discriminants, then the parent subtype of the full view shall impose a
-- statically matching constraint on those discriminants.
-- This means that only the following forms of private extensions are
-- allowed:
-- type D is new A with private; <-- partial view
-- type D is new P with null record; <-- full view
-- If A has no discriminants than P has no discriminants, otherwise P must
-- inherit A's discriminants.
-- type D is new A (...) with private; <-- partial view
-- type D is new P (:::) with null record; <-- full view
-- P must inherit A's discriminants and (...) and (:::) must statically
-- match.
-- subtype A is R (...);
-- type D is new A with private; <-- partial view
-- type D is new P with null record; <-- full view
-- P must have inherited R's discriminants and must be derived from A or
-- any of its subtypes.
-- type D (..) is new A with private; <-- partial view
-- type D (..) is new P [(:::)] with null record; <-- full view
-- No specific constraints on P's discriminants or constraint (:::).
-- Note that A can be unconstrained, but the parent subtype P must either
-- be constrained or (:::) must be present.
-- type D (..) is new A [(...)] with private; <-- partial view
-- type D (..) is new P [(:::)] with null record; <-- full view
-- P's constraints on A's discriminants must statically match those
-- imposed by (...).
-- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
-- The full view of a private extension is handled exactly as described
-- above. The model chose for the private view of a private extension is
-- the same for what concerns discriminants (ie they receive the same
-- treatment as in the tagged case). However, the private view of the
-- private extension always inherits the components of the parent base,
-- without replacing any discriminant reference. Strictly speaking this is
-- incorrect. However, Gigi never uses this view to generate code so this
-- is a purely semantic issue. In theory, a set of transformations similar
-- to those given in 5. and 6. above could be applied to private views of
-- private extensions to have the same model of component inheritance as
-- for non private extensions. However, this is not done because it would
-- further complicate private type processing. Semantically speaking, this
-- leaves us in an uncomfortable situation. As an example consider:
-- package Pack is
-- type R (D : integer) is tagged record
-- S : String (1 .. D);
-- end record;
-- procedure P (X : R);
-- type T is new R (1) with private;
-- private
-- type T is new R (1) with null record;
-- end;
-- This is transformed into:
-- package Pack is
-- type R (D : integer) is tagged record
-- S : String (1 .. D);
-- end record;
-- procedure P (X : R);
-- type T is new R (1) with private;
-- private
-- type BaseT is new R with null record;
-- subtype T is BaseT (1);
-- end;
-- (strictly speaking the above is incorrect Ada)
-- From the semantic standpoint the private view of private extension T
-- should be flagged as constrained since one can clearly have
--
-- Obj : T;
--
-- in a unit withing Pack. However, when deriving subprograms for the
-- private view of private extension T, T must be seen as unconstrained
-- since T has discriminants (this is a constraint of the current
-- subprogram derivation model). Thus, when processing the private view of
-- a private extension such as T, we first mark T as unconstrained, we
-- process it, we perform program derivation and just before returning from
-- Build_Derived_Record_Type we mark T as constrained.
-- ??? Are there are other uncomfortable cases that we will have to
-- deal with.
-- 10. RECORD_TYPE_WITH_PRIVATE complications
-- Types that are derived from a visible record type and have a private
-- extension present other peculiarities. They behave mostly like private
-- types, but if they have primitive operations defined, these will not
-- have the proper signatures for further inheritance, because other
-- primitive operations will use the implicit base that we define for
-- private derivations below. This affect subprogram inheritance (see
-- Derive_Subprograms for details). We also derive the implicit base from
-- the base type of the full view, so that the implicit base is a record
-- type and not another private type, This avoids infinite loops.
procedure Build_Derived_Record_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id;
Derive_Subps : Boolean := True)
is
Loc : constant Source_Ptr := Sloc (N);
Parent_Base : Entity_Id;
Type_Def : Node_Id;
Indic : Node_Id;
Discrim : Entity_Id;
Last_Discrim : Entity_Id;
Constrs : Elist_Id;
Discs : Elist_Id := New_Elmt_List;
-- An empty Discs list means that there were no constraints in the
-- subtype indication or that there was an error processing it.
Assoc_List : Elist_Id;
New_Discrs : Elist_Id;
New_Base : Entity_Id;
New_Decl : Node_Id;
New_Indic : Node_Id;
Is_Tagged : constant Boolean := Is_Tagged_Type (Parent_Type);
Discriminant_Specs : constant Boolean :=
Present (Discriminant_Specifications (N));
Private_Extension : constant Boolean :=
(Nkind (N) = N_Private_Extension_Declaration);
Constraint_Present : Boolean;
Has_Interfaces : Boolean := False;
Inherit_Discrims : Boolean := False;
Tagged_Partial_View : Entity_Id;
Save_Etype : Entity_Id;
Save_Discr_Constr : Elist_Id;
Save_Next_Entity : Entity_Id;
begin
if Ekind (Parent_Type) = E_Record_Type_With_Private
and then Present (Full_View (Parent_Type))
and then Has_Discriminants (Parent_Type)
then
Parent_Base := Base_Type (Full_View (Parent_Type));
else
Parent_Base := Base_Type (Parent_Type);
end if;
-- Before we start the previously documented transformations, here is
-- a little fix for size and alignment of tagged types. Normally when
-- we derive type D from type P, we copy the size and alignment of P
-- as the default for D, and in the absence of explicit representation
-- clauses for D, the size and alignment are indeed the same as the
-- parent.
-- But this is wrong for tagged types, since fields may be added,
-- and the default size may need to be larger, and the default
-- alignment may need to be larger.
-- We therefore reset the size and alignment fields in the tagged
-- case. Note that the size and alignment will in any case be at
-- least as large as the parent type (since the derived type has
-- a copy of the parent type in the _parent field)
if Is_Tagged then
Init_Size_Align (Derived_Type);
end if;
-- STEP 0a: figure out what kind of derived type declaration we have
if Private_Extension then
Type_Def := N;
Set_Ekind (Derived_Type, E_Record_Type_With_Private);
else
Type_Def := Type_Definition (N);
-- Ekind (Parent_Base) in not necessarily E_Record_Type since
-- Parent_Base can be a private type or private extension. However,
-- for tagged types with an extension the newly added fields are
-- visible and hence the Derived_Type is always an E_Record_Type.
-- (except that the parent may have its own private fields).
-- For untagged types we preserve the Ekind of the Parent_Base.
if Present (Record_Extension_Part (Type_Def)) then
Set_Ekind (Derived_Type, E_Record_Type);
else
Set_Ekind (Derived_Type, Ekind (Parent_Base));
end if;
end if;
-- Indic can either be an N_Identifier if the subtype indication
-- contains no constraint or an N_Subtype_Indication if the subtype
-- indication has a constraint.
Indic := Subtype_Indication (Type_Def);
Constraint_Present := (Nkind (Indic) = N_Subtype_Indication);
-- Check that the type has visible discriminants. The type may be
-- a private type with unknown discriminants whose full view has
-- discriminants which are invisible.
if Constraint_Present then
if not Has_Discriminants (Parent_Base)
or else
(Has_Unknown_Discriminants (Parent_Base)
and then Is_Private_Type (Parent_Base))
then
Error_Msg_N
("invalid constraint: type has no discriminant",
Constraint (Indic));
Constraint_Present := False;
Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
elsif Is_Constrained (Parent_Type) then
Error_Msg_N
("invalid constraint: parent type is already constrained",
Constraint (Indic));
Constraint_Present := False;
Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
end if;
end if;
-- STEP 0b: If needed, apply transformation given in point 5. above
if not Private_Extension
and then Has_Discriminants (Parent_Type)
and then not Discriminant_Specs
and then (Is_Constrained (Parent_Type) or else Constraint_Present)
then
-- First, we must analyze the constraint (see comment in point 5.)
if Constraint_Present then
New_Discrs := Build_Discriminant_Constraints (Parent_Type, Indic);
if Has_Discriminants (Derived_Type)
and then Has_Private_Declaration (Derived_Type)
and then Present (Discriminant_Constraint (Derived_Type))
then
-- Verify that constraints of the full view conform to those
-- given in partial view.
declare
C1, C2 : Elmt_Id;
begin
C1 := First_Elmt (New_Discrs);
C2 := First_Elmt (Discriminant_Constraint (Derived_Type));
while Present (C1) and then Present (C2) loop
if not
Fully_Conformant_Expressions (Node (C1), Node (C2))
then
Error_Msg_N (
"constraint not conformant to previous declaration",
Node (C1));
end if;
Next_Elmt (C1);
Next_Elmt (C2);
end loop;
end;
end if;
end if;
-- Insert and analyze the declaration for the unconstrained base type
New_Base := Create_Itype (Ekind (Derived_Type), N, Derived_Type, 'B');
New_Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => New_Base,
Type_Definition =>
Make_Derived_Type_Definition (Loc,
Abstract_Present => Abstract_Present (Type_Def),
Subtype_Indication =>
New_Occurrence_Of (Parent_Base, Loc),
Record_Extension_Part =>
Relocate_Node (Record_Extension_Part (Type_Def))));
Set_Parent (New_Decl, Parent (N));
Mark_Rewrite_Insertion (New_Decl);
Insert_Before (N, New_Decl);
-- Note that this call passes False for the Derive_Subps parameter
-- because subprogram derivation is deferred until after creating
-- the subtype (see below).
Build_Derived_Type
(New_Decl, Parent_Base, New_Base,
Is_Completion => True, Derive_Subps => False);
-- ??? This needs re-examination to determine whether the
-- above call can simply be replaced by a call to Analyze.
Set_Analyzed (New_Decl);
-- Insert and analyze the declaration for the constrained subtype
if Constraint_Present then
New_Indic :=
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
Constraint => Relocate_Node (Constraint (Indic)));
else
declare
Constr_List : constant List_Id := New_List;
C : Elmt_Id;
Expr : Node_Id;
begin
C := First_Elmt (Discriminant_Constraint (Parent_Type));
while Present (C) loop
Expr := Node (C);
-- It is safe here to call New_Copy_Tree since
-- Force_Evaluation was called on each constraint in
-- Build_Discriminant_Constraints.
Append (New_Copy_Tree (Expr), To => Constr_List);
Next_Elmt (C);
end loop;
New_Indic :=
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc, Constr_List));
end;
end if;
Rewrite (N,
Make_Subtype_Declaration (Loc,
Defining_Identifier => Derived_Type,
Subtype_Indication => New_Indic));
Analyze (N);
-- Derivation of subprograms must be delayed until the full subtype
-- has been established to ensure proper overriding of subprograms
-- inherited by full types. If the derivations occurred as part of
-- the call to Build_Derived_Type above, then the check for type
-- conformance would fail because earlier primitive subprograms
-- could still refer to the full type prior the change to the new
-- subtype and hence would not match the new base type created here.
Derive_Subprograms (Parent_Type, Derived_Type);
-- For tagged types the Discriminant_Constraint of the new base itype
-- is inherited from the first subtype so that no subtype conformance
-- problem arise when the first subtype overrides primitive
-- operations inherited by the implicit base type.
if Is_Tagged then
Set_Discriminant_Constraint
(New_Base, Discriminant_Constraint (Derived_Type));
end if;
return;
end if;
-- If we get here Derived_Type will have no discriminants or it will be
-- a discriminated unconstrained base type.
-- STEP 1a: perform preliminary actions/checks for derived tagged types
if Is_Tagged then
-- The parent type is frozen for non-private extensions (RM 13.14(7))
if not Private_Extension then
Freeze_Before (N, Parent_Type);
end if;
-- In Ada 2005 (AI-344), the restriction that a derived tagged type
-- cannot be declared at a deeper level than its parent type is
-- removed. The check on derivation within a generic body is also
-- relaxed, but there's a restriction that a derived tagged type
-- cannot be declared in a generic body if it's derived directly
-- or indirectly from a formal type of that generic.
if Ada_Version >= Ada_05 then
if Present (Enclosing_Generic_Body (Derived_Type)) then
declare
Ancestor_Type : Entity_Id;
begin
-- Check to see if any ancestor of the derived type is a
-- formal type.
Ancestor_Type := Parent_Type;
while not Is_Generic_Type (Ancestor_Type)
and then Etype (Ancestor_Type) /= Ancestor_Type
loop
Ancestor_Type := Etype (Ancestor_Type);
end loop;
-- If the derived type does have a formal type as an
-- ancestor, then it's an error if the derived type is
-- declared within the body of the generic unit that
-- declares the formal type in its generic formal part. It's
-- sufficient to check whether the ancestor type is declared
-- inside the same generic body as the derived type (such as
-- within a nested generic spec), in which case the
-- derivation is legal. If the formal type is declared
-- outside of that generic body, then it's guaranteed that
-- the derived type is declared within the generic body of
-- the generic unit declaring the formal type.
if Is_Generic_Type (Ancestor_Type)
and then Enclosing_Generic_Body (Ancestor_Type) /=
Enclosing_Generic_Body (Derived_Type)
then
Error_Msg_NE
("parent type of& must not be descendant of formal type"
& " of an enclosing generic body",
Indic, Derived_Type);
end if;
end;
end if;
elsif Type_Access_Level (Derived_Type) /=
Type_Access_Level (Parent_Type)
and then not Is_Generic_Type (Derived_Type)
then
if Is_Controlled (Parent_Type) then
Error_Msg_N
("controlled type must be declared at the library level",
Indic);
else
Error_Msg_N
("type extension at deeper accessibility level than parent",
Indic);
end if;
else
declare
GB : constant Node_Id := Enclosing_Generic_Body (Derived_Type);
begin
if Present (GB)
and then GB /= Enclosing_Generic_Body (Parent_Base)
then
Error_Msg_NE
("parent type of& must not be outside generic body"
& " ('R'M 3.9.1(4))",
Indic, Derived_Type);
end if;
end;
end if;
end if;
-- Ada 2005 (AI-251)
if Ada_Version = Ada_05
and then Is_Tagged
then
-- "The declaration of a specific descendant of an interface type
-- freezes the interface type" (RM 13.14).
declare
Iface : Node_Id;
begin
if Is_Non_Empty_List (Interface_List (Type_Def)) then
Iface := First (Interface_List (Type_Def));
while Present (Iface) loop
Freeze_Before (N, Etype (Iface));
Next (Iface);
end loop;
end if;
end;
end if;
-- STEP 1b : preliminary cleanup of the full view of private types
-- If the type is already marked as having discriminants, then it's the
-- completion of a private type or private extension and we need to
-- retain the discriminants from the partial view if the current
-- declaration has Discriminant_Specifications so that we can verify
-- conformance. However, we must remove any existing components that
-- were inherited from the parent (and attached in Copy_And_Swap)
-- because the full type inherits all appropriate components anyway, and
-- we do not want the partial view's components interfering.
if Has_Discriminants (Derived_Type) and then Discriminant_Specs then
Discrim := First_Discriminant (Derived_Type);
loop
Last_Discrim := Discrim;
Next_Discriminant (Discrim);
exit when No (Discrim);
end loop;
Set_Last_Entity (Derived_Type, Last_Discrim);
-- In all other cases wipe out the list of inherited components (even
-- inherited discriminants), it will be properly rebuilt here.
else
Set_First_Entity (Derived_Type, Empty);
Set_Last_Entity (Derived_Type, Empty);
end if;
-- STEP 1c: Initialize some flags for the Derived_Type
-- The following flags must be initialized here so that
-- Process_Discriminants can check that discriminants of tagged types
-- do not have a default initial value and that access discriminants
-- are only specified for limited records. For completeness, these
-- flags are also initialized along with all the other flags below.
-- AI-419: limitedness is not inherited from an interface parent
Set_Is_Tagged_Type (Derived_Type, Is_Tagged);
Set_Is_Limited_Record (Derived_Type,
Is_Limited_Record (Parent_Type)
and then not Is_Interface (Parent_Type));
-- STEP 2a: process discriminants of derived type if any
New_Scope (Derived_Type);
if Discriminant_Specs then
Set_Has_Unknown_Discriminants (Derived_Type, False);
-- The following call initializes fields Has_Discriminants and
-- Discriminant_Constraint, unless we are processing the completion
-- of a private type declaration.
Check_Or_Process_Discriminants (N, Derived_Type);
-- For non-tagged types the constraint on the Parent_Type must be
-- present and is used to rename the discriminants.
if not Is_Tagged and then not Has_Discriminants (Parent_Type) then
Error_Msg_N ("untagged parent must have discriminants", Indic);
elsif not Is_Tagged and then not Constraint_Present then
Error_Msg_N
("discriminant constraint needed for derived untagged records",
Indic);
-- Otherwise the parent subtype must be constrained unless we have a
-- private extension.
elsif not Constraint_Present
and then not Private_Extension
and then not Is_Constrained (Parent_Type)
then
Error_Msg_N
("unconstrained type not allowed in this context", Indic);
elsif Constraint_Present then
-- The following call sets the field Corresponding_Discriminant
-- for the discriminants in the Derived_Type.
Discs := Build_Discriminant_Constraints (Parent_Type, Indic, True);
-- For untagged types all new discriminants must rename
-- discriminants in the parent. For private extensions new
-- discriminants cannot rename old ones (implied by [7.3(13)]).
Discrim := First_Discriminant (Derived_Type);
while Present (Discrim) loop
if not Is_Tagged
and then No (Corresponding_Discriminant (Discrim))
then
Error_Msg_N
("new discriminants must constrain old ones", Discrim);
elsif Private_Extension
and then Present (Corresponding_Discriminant (Discrim))
then
Error_Msg_N
("only static constraints allowed for parent"
& " discriminants in the partial view", Indic);
exit;
end if;
-- If a new discriminant is used in the constraint, then its
-- subtype must be statically compatible with the parent
-- discriminant's subtype (3.7(15)).
if Present (Corresponding_Discriminant (Discrim))
and then
not Subtypes_Statically_Compatible
(Etype (Discrim),
Etype (Corresponding_Discriminant (Discrim)))
then
Error_Msg_N
("subtype must be compatible with parent discriminant",
Discrim);
end if;
Next_Discriminant (Discrim);
end loop;
-- Check whether the constraints of the full view statically
-- match those imposed by the parent subtype [7.3(13)].
if Present (Stored_Constraint (Derived_Type)) then
declare
C1, C2 : Elmt_Id;
begin
C1 := First_Elmt (Discs);
C2 := First_Elmt (Stored_Constraint (Derived_Type));
while Present (C1) and then Present (C2) loop
if not
Fully_Conformant_Expressions (Node (C1), Node (C2))
then
Error_Msg_N (
"not conformant with previous declaration",
Node (C1));
end if;
Next_Elmt (C1);
Next_Elmt (C2);
end loop;
end;
end if;
end if;
-- STEP 2b: No new discriminants, inherit discriminants if any
else
if Private_Extension then
Set_Has_Unknown_Discriminants
(Derived_Type,
Has_Unknown_Discriminants (Parent_Type)
or else Unknown_Discriminants_Present (N));
-- The partial view of the parent may have unknown discriminants,
-- but if the full view has discriminants and the parent type is
-- in scope they must be inherited.
elsif Has_Unknown_Discriminants (Parent_Type)
and then
(not Has_Discriminants (Parent_Type)
or else not In_Open_Scopes (Scope (Parent_Type)))
then
Set_Has_Unknown_Discriminants (Derived_Type);
end if;
if not Has_Unknown_Discriminants (Derived_Type)
and then not Has_Unknown_Discriminants (Parent_Base)
and then Has_Discriminants (Parent_Type)
then
Inherit_Discrims := True;
Set_Has_Discriminants
(Derived_Type, True);
Set_Discriminant_Constraint
(Derived_Type, Discriminant_Constraint (Parent_Base));
end if;
-- The following test is true for private types (remember
-- transformation 5. is not applied to those) and in an error
-- situation.
if Constraint_Present then
Discs := Build_Discriminant_Constraints (Parent_Type, Indic);
end if;
-- For now mark a new derived type as constrained only if it has no
-- discriminants. At the end of Build_Derived_Record_Type we properly
-- set this flag in the case of private extensions. See comments in
-- point 9. just before body of Build_Derived_Record_Type.
Set_Is_Constrained
(Derived_Type,
not (Inherit_Discrims
or else Has_Unknown_Discriminants (Derived_Type)));
end if;
-- STEP 3: initialize fields of derived type
Set_Is_Tagged_Type (Derived_Type, Is_Tagged);
Set_Stored_Constraint (Derived_Type, No_Elist);
-- Ada 2005 (AI-251): Private type-declarations can implement interfaces
-- but cannot be interfaces
if not Private_Extension
and then Ekind (Derived_Type) /= E_Private_Type
and then Ekind (Derived_Type) /= E_Limited_Private_Type
then
Set_Is_Interface (Derived_Type, Interface_Present (Type_Def));
Set_Abstract_Interfaces (Derived_Type, No_Elist);
end if;
-- Fields inherited from the Parent_Type
Set_Discard_Names
(Derived_Type, Einfo.Discard_Names (Parent_Type));
Set_Has_Specified_Layout
(Derived_Type, Has_Specified_Layout (Parent_Type));
Set_Is_Limited_Composite
(Derived_Type, Is_Limited_Composite (Parent_Type));
Set_Is_Limited_Record
(Derived_Type,
Is_Limited_Record (Parent_Type)
and then not Is_Interface (Parent_Type));
Set_Is_Private_Composite
(Derived_Type, Is_Private_Composite (Parent_Type));
-- Fields inherited from the Parent_Base
Set_Has_Controlled_Component
(Derived_Type, Has_Controlled_Component (Parent_Base));
Set_Has_Non_Standard_Rep
(Derived_Type, Has_Non_Standard_Rep (Parent_Base));
Set_Has_Primitive_Operations
(Derived_Type, Has_Primitive_Operations (Parent_Base));
-- Direct controlled types do not inherit Finalize_Storage_Only flag
if not Is_Controlled (Parent_Type) then
Set_Finalize_Storage_Only
(Derived_Type, Finalize_Storage_Only (Parent_Type));
end if;
-- Set fields for private derived types
if Is_Private_Type (Derived_Type) then
Set_Depends_On_Private (Derived_Type, True);
Set_Private_Dependents (Derived_Type, New_Elmt_List);
-- Inherit fields from non private record types. If this is the
-- completion of a derivation from a private type, the parent itself
-- is private, and the attributes come from its full view, which must
-- be present.
else
if Is_Private_Type (Parent_Base)
and then not Is_Record_Type (Parent_Base)
then
Set_Component_Alignment
(Derived_Type, Component_Alignment (Full_View (Parent_Base)));
Set_C_Pass_By_Copy
(Derived_Type, C_Pass_By_Copy (Full_View (Parent_Base)));
else
Set_Component_Alignment
(Derived_Type, Component_Alignment (Parent_Base));
Set_C_Pass_By_Copy
(Derived_Type, C_Pass_By_Copy (Parent_Base));
end if;
end if;
-- Set fields for tagged types
if Is_Tagged then
Set_Primitive_Operations (Derived_Type, New_Elmt_List);
-- All tagged types defined in Ada.Finalization are controlled
if Chars (Scope (Derived_Type)) = Name_Finalization
and then Chars (Scope (Scope (Derived_Type))) = Name_Ada
and then Scope (Scope (Scope (Derived_Type))) = Standard_Standard
then
Set_Is_Controlled (Derived_Type);
else
Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Base));
end if;
Make_Class_Wide_Type (Derived_Type);
Set_Is_Abstract (Derived_Type, Abstract_Present (Type_Def));
if Has_Discriminants (Derived_Type)
and then Constraint_Present
then
Set_Stored_Constraint
(Derived_Type, Expand_To_Stored_Constraint (Parent_Base, Discs));
end if;
-- Ada 2005 (AI-251): Look for the partial view of tagged types
-- declared in the private part. This will be used 1) to check that
-- the set of interfaces in both views is equal, and 2) to complete
-- the derivation of subprograms covering interfaces.
Tagged_Partial_View := Empty;
if Has_Private_Declaration (Derived_Type) then
Tagged_Partial_View := Next_Entity (Derived_Type);
loop
exit when Has_Private_Declaration (Tagged_Partial_View)
and then Full_View (Tagged_Partial_View) = Derived_Type;
Next_Entity (Tagged_Partial_View);
end loop;
end if;
-- Ada 2005 (AI-251): Collect the whole list of implemented
-- interfaces.
if Ada_Version >= Ada_05 then
Set_Abstract_Interfaces (Derived_Type, New_Elmt_List);
if Nkind (N) = N_Private_Extension_Declaration then
Collect_Interfaces (N, Derived_Type);
else
Collect_Interfaces (Type_Definition (N), Derived_Type);
end if;
end if;
else
Set_Is_Packed (Derived_Type, Is_Packed (Parent_Base));
Set_Has_Non_Standard_Rep
(Derived_Type, Has_Non_Standard_Rep (Parent_Base));
end if;
-- STEP 4: Inherit components from the parent base and constrain them.
-- Apply the second transformation described in point 6. above.
if (not Is_Empty_Elmt_List (Discs) or else Inherit_Discrims)
or else not Has_Discriminants (Parent_Type)
or else not Is_Constrained (Parent_Type)
then
Constrs := Discs;
else
Constrs := Discriminant_Constraint (Parent_Type);
end if;
Assoc_List :=
Inherit_Components
(N, Parent_Base, Derived_Type, Is_Tagged, Inherit_Discrims, Constrs);
-- STEP 5a: Copy the parent record declaration for untagged types
if not Is_Tagged then
-- Discriminant_Constraint (Derived_Type) has been properly
-- constructed. Save it and temporarily set it to Empty because we
-- do not want the call to New_Copy_Tree below to mess this list.
if Has_Discriminants (Derived_Type) then
Save_Discr_Constr := Discriminant_Constraint (Derived_Type);
Set_Discriminant_Constraint (Derived_Type, No_Elist);
else
Save_Discr_Constr := No_Elist;
end if;
-- Save the Etype field of Derived_Type. It is correctly set now,
-- but the call to New_Copy tree may remap it to point to itself,
-- which is not what we want. Ditto for the Next_Entity field.
Save_Etype := Etype (Derived_Type);
Save_Next_Entity := Next_Entity (Derived_Type);
-- Assoc_List maps all stored discriminants in the Parent_Base to
-- stored discriminants in the Derived_Type. It is fundamental that
-- no types or itypes with discriminants other than the stored
-- discriminants appear in the entities declared inside
-- Derived_Type, since the back end cannot deal with it.
New_Decl :=
New_Copy_Tree
(Parent (Parent_Base), Map => Assoc_List, New_Sloc => Loc);
-- Restore the fields saved prior to the New_Copy_Tree call
-- and compute the stored constraint.
Set_Etype (Derived_Type, Save_Etype);
Set_Next_Entity (Derived_Type, Save_Next_Entity);
if Has_Discriminants (Derived_Type) then
Set_Discriminant_Constraint
(Derived_Type, Save_Discr_Constr);
Set_Stored_Constraint
(Derived_Type, Expand_To_Stored_Constraint (Parent_Type, Discs));
Replace_Components (Derived_Type, New_Decl);
end if;
-- Insert the new derived type declaration
Rewrite (N, New_Decl);
-- STEP 5b: Complete the processing for record extensions in generics
-- There is no completion for record extensions declared in the
-- parameter part of a generic, so we need to complete processing for
-- these generic record extensions here. The Record_Type_Definition call
-- will change the Ekind of the components from E_Void to E_Component.
elsif Private_Extension and then Is_Generic_Type (Derived_Type) then
Record_Type_Definition (Empty, Derived_Type);
-- STEP 5c: Process the record extension for non private tagged types
elsif not Private_Extension then
-- Add the _parent field in the derived type
Expand_Record_Extension (Derived_Type, Type_Def);
-- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
-- implemented interfaces if we are in expansion mode
if Expander_Active then
Add_Interface_Tag_Components (N, Derived_Type);
end if;
-- Analyze the record extension
Record_Type_Definition
(Record_Extension_Part (Type_Def), Derived_Type);
end if;
End_Scope;
if Etype (Derived_Type) = Any_Type then
return;
end if;
-- Set delayed freeze and then derive subprograms, we need to do
-- this in this order so that derived subprograms inherit the
-- derived freeze if necessary.
Set_Has_Delayed_Freeze (Derived_Type);
if Derive_Subps then
-- Ada 2005 (AI-251): Check if this tagged type implements abstract
-- interfaces
Has_Interfaces := False;
if Is_Tagged_Type (Derived_Type) then
declare
E : Entity_Id;
begin
-- Handle private types
if Present (Full_View (Derived_Type)) then
E := Full_View (Derived_Type);
else
E := Derived_Type;
end if;
loop
if Is_Interface (E)
or else (Present (Abstract_Interfaces (E))
and then
not Is_Empty_Elmt_List (Abstract_Interfaces (E)))
then
Has_Interfaces := True;
exit;
end if;
exit when Etype (E) = E
-- Handle private types
or else (Present (Full_View (Etype (E)))
and then Full_View (Etype (E)) = E)
-- Protect the frontend against wrong source
or else Etype (E) = Derived_Type;
-- Climb to the ancestor type handling private types
if Present (Full_View (Etype (E))) then
E := Full_View (Etype (E));
else
E := Etype (E);
end if;
end loop;
end;
end if;
Derive_Subprograms (Parent_Type, Derived_Type);
-- Ada 2005 (AI-251): Handle tagged types implementing interfaces
if Is_Tagged_Type (Derived_Type)
and then Has_Interfaces
then
-- Ada 2005 (AI-251): If we are analyzing a full view that has
-- no partial view we derive the abstract interface Subprograms
if No (Tagged_Partial_View) then
Derive_Interface_Subprograms (Derived_Type);
-- Ada 2005 (AI-251): if we are analyzing a full view that has
-- a partial view we complete the derivation of the subprograms
else
Complete_Subprograms_Derivation
(Partial_View => Tagged_Partial_View,
Derived_Type => Derived_Type);
end if;
-- Ada 2005 (AI-251): In both cases we check if some of the
-- inherited subprograms cover interface primitives.
declare
Iface_Subp : Entity_Id;
Iface_Subp_Elmt : Elmt_Id;
Prev_Alias : Entity_Id;
Subp : Entity_Id;
Subp_Elmt : Elmt_Id;
begin
Iface_Subp_Elmt :=
First_Elmt (Primitive_Operations (Derived_Type));
while Present (Iface_Subp_Elmt) loop
Iface_Subp := Node (Iface_Subp_Elmt);
-- Look for an abstract interface subprogram
if Is_Abstract (Iface_Subp)
and then Present (Alias (Iface_Subp))
and then Present (DTC_Entity (Alias (Iface_Subp)))
and then Is_Interface
(Scope (DTC_Entity (Alias (Iface_Subp))))
then
-- Look for candidate primitive subprograms of the tagged
-- type that can cover this interface subprogram.
Subp_Elmt :=
First_Elmt (Primitive_Operations (Derived_Type));
while Present (Subp_Elmt) loop
Subp := Node (Subp_Elmt);
if not Is_Abstract (Subp)
and then Chars (Subp) = Chars (Iface_Subp)
and then Type_Conformant (Iface_Subp, Subp)
then
Prev_Alias := Alias (Iface_Subp);
Check_Dispatching_Operation
(Subp => Subp,
Old_Subp => Iface_Subp);
pragma Assert
(Alias (Iface_Subp) = Subp);
pragma Assert
(Abstract_Interface_Alias (Iface_Subp)
= Prev_Alias);
-- Traverse the list of aliased subprograms to link
-- subp with its ultimate aliased subprogram. This
-- avoids problems with the backend.
declare
E : Entity_Id;
begin
E := Alias (Subp);
while Present (Alias (E)) loop
E := Alias (E);
end loop;
Set_Alias (Subp, E);
end;
Set_Has_Delayed_Freeze (Subp);
exit;
end if;
Next_Elmt (Subp_Elmt);
end loop;
end if;
Next_Elmt (Iface_Subp_Elmt);
end loop;
end;
end if;
end if;
-- If we have a private extension which defines a constrained derived
-- type mark as constrained here after we have derived subprograms. See
-- comment on point 9. just above the body of Build_Derived_Record_Type.
if Private_Extension and then Inherit_Discrims then
if Constraint_Present and then not Is_Empty_Elmt_List (Discs) then
Set_Is_Constrained (Derived_Type, True);
Set_Discriminant_Constraint (Derived_Type, Discs);
elsif Is_Constrained (Parent_Type) then
Set_Is_Constrained
(Derived_Type, True);
Set_Discriminant_Constraint
(Derived_Type, Discriminant_Constraint (Parent_Type));
end if;
end if;
-- Update the class_wide type, which shares the now-completed
-- entity list with its specific type.
if Is_Tagged then
Set_First_Entity
(Class_Wide_Type (Derived_Type), First_Entity (Derived_Type));
Set_Last_Entity
(Class_Wide_Type (Derived_Type), Last_Entity (Derived_Type));
end if;
end Build_Derived_Record_Type;
------------------------
-- Build_Derived_Type --
------------------------
procedure Build_Derived_Type
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id;
Is_Completion : Boolean;
Derive_Subps : Boolean := True)
is
Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
begin
-- Set common attributes
Set_Scope (Derived_Type, Current_Scope);
Set_Ekind (Derived_Type, Ekind (Parent_Base));
Set_Etype (Derived_Type, Parent_Base);
Set_Has_Task (Derived_Type, Has_Task (Parent_Base));
Set_Size_Info (Derived_Type, Parent_Type);
Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
Set_Convention (Derived_Type, Convention (Parent_Type));
Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
-- The derived type inherits the representation clauses of the parent.
-- However, for a private type that is completed by a derivation, there
-- may be operation attributes that have been specified already (stream
-- attributes and External_Tag) and those must be provided. Finally,
-- if the partial view is a private extension, the representation items
-- of the parent have been inherited already, and should not be chained
-- twice to the derived type.
if Is_Tagged_Type (Parent_Type)
and then Present (First_Rep_Item (Derived_Type))
then
-- The existing items are either operational items or items inherited
-- from a private extension declaration.
declare
Rep : Node_Id;
Found : Boolean := False;
begin
Rep := First_Rep_Item (Derived_Type);
while Present (Rep) loop
if Rep = First_Rep_Item (Parent_Type) then
Found := True;
exit;
else
Rep := Next_Rep_Item (Rep);
end if;
end loop;
if not Found then
Set_Next_Rep_Item
(First_Rep_Item (Derived_Type), First_Rep_Item (Parent_Type));
end if;
end;
else
Set_First_Rep_Item (Derived_Type, First_Rep_Item (Parent_Type));
end if;
case Ekind (Parent_Type) is
when Numeric_Kind =>
Build_Derived_Numeric_Type (N, Parent_Type, Derived_Type);
when Array_Kind =>
Build_Derived_Array_Type (N, Parent_Type, Derived_Type);
when E_Record_Type
| E_Record_Subtype
| Class_Wide_Kind =>
Build_Derived_Record_Type
(N, Parent_Type, Derived_Type, Derive_Subps);
return;
when Enumeration_Kind =>
Build_Derived_Enumeration_Type (N, Parent_Type, Derived_Type);
when Access_Kind =>
Build_Derived_Access_Type (N, Parent_Type, Derived_Type);
when Incomplete_Or_Private_Kind =>
Build_Derived_Private_Type
(N, Parent_Type, Derived_Type, Is_Completion, Derive_Subps);
-- For discriminated types, the derivation includes deriving
-- primitive operations. For others it is done below.
if Is_Tagged_Type (Parent_Type)
or else Has_Discriminants (Parent_Type)
or else (Present (Full_View (Parent_Type))
and then Has_Discriminants (Full_View (Parent_Type)))
then
return;
end if;
when Concurrent_Kind =>
Build_Derived_Concurrent_Type (N, Parent_Type, Derived_Type);
when others =>
raise Program_Error;
end case;
if Etype (Derived_Type) = Any_Type then
return;
end if;
-- Set delayed freeze and then derive subprograms, we need to do this
-- in this order so that derived subprograms inherit the derived freeze
-- if necessary.
Set_Has_Delayed_Freeze (Derived_Type);
if Derive_Subps then
Derive_Subprograms (Parent_Type, Derived_Type);
end if;
Set_Has_Primitive_Operations
(Base_Type (Derived_Type), Has_Primitive_Operations (Parent_Type));
end Build_Derived_Type;
-----------------------
-- Build_Discriminal --
-----------------------
procedure Build_Discriminal (Discrim : Entity_Id) is
D_Minal : Entity_Id;
CR_Disc : Entity_Id;
begin
-- A discriminal has the same name as the discriminant
D_Minal :=
Make_Defining_Identifier (Sloc (Discrim),
Chars => Chars (Discrim));
Set_Ekind (D_Minal, E_In_Parameter);
Set_Mechanism (D_Minal, Default_Mechanism);
Set_Etype (D_Minal, Etype (Discrim));
Set_Discriminal (Discrim, D_Minal);
Set_Discriminal_Link (D_Minal, Discrim);
-- For task types, build at once the discriminants of the corresponding
-- record, which are needed if discriminants are used in entry defaults
-- and in family bounds.
if Is_Concurrent_Type (Current_Scope)
or else Is_Limited_Type (Current_Scope)
then
CR_Disc := Make_Defining_Identifier (Sloc (Discrim), Chars (Discrim));
Set_Ekind (CR_Disc, E_In_Parameter);
Set_Mechanism (CR_Disc, Default_Mechanism);
Set_Etype (CR_Disc, Etype (Discrim));
Set_Discriminal_Link (CR_Disc, Discrim);
Set_CR_Discriminant (Discrim, CR_Disc);
end if;
end Build_Discriminal;
------------------------------------
-- Build_Discriminant_Constraints --
------------------------------------
function Build_Discriminant_Constraints
(T : Entity_Id;
Def : Node_Id;
Derived_Def : Boolean := False) return Elist_Id
is
C : constant Node_Id := Constraint (Def);
Nb_Discr : constant Nat := Number_Discriminants (T);
Discr_Expr : array (1 .. Nb_Discr) of Node_Id := (others => Empty);
-- Saves the expression corresponding to a given discriminant in T
function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat;
-- Return the Position number within array Discr_Expr of a discriminant
-- D within the discriminant list of the discriminated type T.
------------------
-- Pos_Of_Discr --
------------------
function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat is
Disc : Entity_Id;
begin
Disc := First_Discriminant (T);
for J in Discr_Expr'Range loop
if Disc = D then
return J;
end if;
Next_Discriminant (Disc);
end loop;
-- Note: Since this function is called on discriminants that are
-- known to belong to the discriminated type, falling through the
-- loop with no match signals an internal compiler error.
raise Program_Error;
end Pos_Of_Discr;
-- Declarations local to Build_Discriminant_Constraints
Discr : Entity_Id;
E : Entity_Id;
Elist : constant Elist_Id := New_Elmt_List;
Constr : Node_Id;
Expr : Node_Id;
Id : Node_Id;
Position : Nat;
Found : Boolean;
Discrim_Present : Boolean := False;
-- Start of processing for Build_Discriminant_Constraints
begin
-- The following loop will process positional associations only.
-- For a positional association, the (single) discriminant is
-- implicitly specified by position, in textual order (RM 3.7.2).
Discr := First_Discriminant (T);
Constr := First (Constraints (C));
for D in Discr_Expr'Range loop
exit when Nkind (Constr) = N_Discriminant_Association;
if No (Constr) then
Error_Msg_N ("too few discriminants given in constraint", C);
return New_Elmt_List;
elsif Nkind (Constr) = N_Range
or else (Nkind (Constr) = N_Attribute_Reference
and then
Attribute_Name (Constr) = Name_Range)
then
Error_Msg_N
("a range is not a valid discriminant constraint", Constr);
Discr_Expr (D) := Error;
else
Analyze_And_Resolve (Constr, Base_Type (Etype (Discr)));
Discr_Expr (D) := Constr;
end if;
Next_Discriminant (Discr);
Next (Constr);
end loop;
if No (Discr) and then Present (Constr) then
Error_Msg_N ("too many discriminants given in constraint", Constr);
return New_Elmt_List;
end if;
-- Named associations can be given in any order, but if both positional
-- and named associations are used in the same discriminant constraint,
-- then positional associations must occur first, at their normal
-- position. Hence once a named association is used, the rest of the
-- discriminant constraint must use only named associations.
while Present (Constr) loop
-- Positional association forbidden after a named association
if Nkind (Constr) /= N_Discriminant_Association then
Error_Msg_N ("positional association follows named one", Constr);
return New_Elmt_List;
-- Otherwise it is a named association
else
-- E records the type of the discriminants in the named
-- association. All the discriminants specified in the same name
-- association must have the same type.
E := Empty;
-- Search the list of discriminants in T to see if the simple name
-- given in the constraint matches any of them.
Id := First (Selector_Names (Constr));
while Present (Id) loop
Found := False;
-- If Original_Discriminant is present, we are processing a
-- generic instantiation and this is an instance node. We need
-- to find the name of the corresponding discriminant in the
-- actual record type T and not the name of the discriminant in
-- the generic formal. Example:
--
-- generic
-- type G (D : int) is private;
-- package P is
-- subtype W is G (D => 1);
-- end package;
-- type Rec (X : int) is record ... end record;
-- package Q is new P (G => Rec);
--
-- At the point of the instantiation, formal type G is Rec
-- and therefore when reanalyzing "subtype W is G (D => 1);"
-- which really looks like "subtype W is Rec (D => 1);" at
-- the point of instantiation, we want to find the discriminant
-- that corresponds to D in Rec, ie X.
if Present (Original_Discriminant (Id)) then
Discr := Find_Corresponding_Discriminant (Id, T);
Found := True;
else
Discr := First_Discriminant (T);
while Present (Discr) loop
if Chars (Discr) = Chars (Id) then
Found := True;
exit;
end if;
Next_Discriminant (Discr);
end loop;
if not Found then
Error_Msg_N ("& does not match any discriminant", Id);
return New_Elmt_List;
-- The following is only useful for the benefit of generic
-- instances but it does not interfere with other
-- processing for the non-generic case so we do it in all
-- cases (for generics this statement is executed when
-- processing the generic definition, see comment at the
-- beginning of this if statement).
else
Set_Original_Discriminant (Id, Discr);
end if;
end if;
Position := Pos_Of_Discr (T, Discr);
if Present (Discr_Expr (Position)) then
Error_Msg_N ("duplicate constraint for discriminant&", Id);
else
-- Each discriminant specified in the same named association
-- must be associated with a separate copy of the
-- corresponding expression.
if Present (Next (Id)) then
Expr := New_Copy_Tree (Expression (Constr));
Set_Parent (Expr, Parent (Expression (Constr)));
else
Expr := Expression (Constr);
end if;
Discr_Expr (Position) := Expr;
Analyze_And_Resolve (Expr, Base_Type (Etype (Discr)));
end if;
-- A discriminant association with more than one discriminant
-- name is only allowed if the named discriminants are all of
-- the same type (RM 3.7.1(8)).
if E = Empty then
E := Base_Type (Etype (Discr));
elsif Base_Type (Etype (Discr)) /= E then
Error_Msg_N
("all discriminants in an association " &
"must have the same type", Id);
end if;
Next (Id);
end loop;
end if;
Next (Constr);
end loop;
-- A discriminant constraint must provide exactly one value for each
-- discriminant of the type (RM 3.7.1(8)).
for J in Discr_Expr'Range loop
if No (Discr_Expr (J)) then
Error_Msg_N ("too few discriminants given in constraint", C);
return New_Elmt_List;
end if;
end loop;
-- Determine if there are discriminant expressions in the constraint
for J in Discr_Expr'Range loop
if Denotes_Discriminant (Discr_Expr (J), Check_Protected => True) then
Discrim_Present := True;
end if;
end loop;
-- Build an element list consisting of the expressions given in the
-- discriminant constraint and apply the appropriate checks. The list
-- is constructed after resolving any named discriminant associations
-- and therefore the expressions appear in the textual order of the
-- discriminants.
Discr := First_Discriminant (T);
for J in Discr_Expr'Range loop
if Discr_Expr (J) /= Error then
Append_Elmt (Discr_Expr (J), Elist);
-- If any of the discriminant constraints is given by a
-- discriminant and we are in a derived type declaration we
-- have a discriminant renaming. Establish link between new
-- and old discriminant.
if Denotes_Discriminant (Discr_Expr (J)) then
if Derived_Def then
Set_Corresponding_Discriminant
(Entity (Discr_Expr (J)), Discr);
end if;
-- Force the evaluation of non-discriminant expressions.
-- If we have found a discriminant in the constraint 3.4(26)
-- and 3.8(18) demand that no range checks are performed are
-- after evaluation. If the constraint is for a component
-- definition that has a per-object constraint, expressions are
-- evaluated but not checked either. In all other cases perform
-- a range check.
else
if Discrim_Present then
null;
elsif Nkind (Parent (Parent (Def))) = N_Component_Declaration
and then
Has_Per_Object_Constraint
(Defining_Identifier (Parent (Parent (Def))))
then
null;
elsif Is_Access_Type (Etype (Discr)) then
Apply_Constraint_Check (Discr_Expr (J), Etype (Discr));
else
Apply_Range_Check (Discr_Expr (J), Etype (Discr));
end if;
Force_Evaluation (Discr_Expr (J));
end if;
-- Check that the designated type of an access discriminant's
-- expression is not a class-wide type unless the discriminant's
-- designated type is also class-wide.
if Ekind (Etype (Discr)) = E_Anonymous_Access_Type
and then not Is_Class_Wide_Type
(Designated_Type (Etype (Discr)))
and then Etype (Discr_Expr (J)) /= Any_Type
and then Is_Class_Wide_Type
(Designated_Type (Etype (Discr_Expr (J))))
then
Wrong_Type (Discr_Expr (J), Etype (Discr));
end if;
end if;
Next_Discriminant (Discr);
end loop;
return Elist;
end Build_Discriminant_Constraints;
---------------------------------
-- Build_Discriminated_Subtype --
---------------------------------
procedure Build_Discriminated_Subtype
(T : Entity_Id;
Def_Id : Entity_Id;
Elist : Elist_Id;
Related_Nod : Node_Id;
For_Access : Boolean := False)
is
Has_Discrs : constant Boolean := Has_Discriminants (T);
Constrained : constant Boolean
:= (Has_Discrs
and then not Is_Empty_Elmt_List (Elist)
and then not Is_Class_Wide_Type (T))
or else Is_Constrained (T);
begin
if Ekind (T) = E_Record_Type then
if For_Access then
Set_Ekind (Def_Id, E_Private_Subtype);
Set_Is_For_Access_Subtype (Def_Id, True);
else
Set_Ekind (Def_Id, E_Record_Subtype);
end if;
elsif Ekind (T) = E_Task_Type then
Set_Ekind (Def_Id, E_Task_Subtype);
elsif Ekind (T) = E_Protected_Type then
Set_Ekind (Def_Id, E_Protected_Subtype);
elsif Is_Private_Type (T) then
Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
elsif Is_Class_Wide_Type (T) then
Set_Ekind (Def_Id, E_Class_Wide_Subtype);
else
-- Incomplete type. attach subtype to list of dependents, to be
-- completed with full view of parent type, unless is it the
-- designated subtype of a record component within an init_proc.
-- This last case arises for a component of an access type whose
-- designated type is incomplete (e.g. a Taft Amendment type).
-- The designated subtype is within an inner scope, and needs no
-- elaboration, because only the access type is needed in the
-- initialization procedure.
Set_Ekind (Def_Id, Ekind (T));
if For_Access and then Within_Init_Proc then
null;
else
Append_Elmt (Def_Id, Private_Dependents (T));
end if;
end if;
Set_Etype (Def_Id, T);
Init_Size_Align (Def_Id);
Set_Has_Discriminants (Def_Id, Has_Discrs);
Set_Is_Constrained (Def_Id, Constrained);
Set_First_Entity (Def_Id, First_Entity (T));
Set_Last_Entity (Def_Id, Last_Entity (T));
Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
if Is_Tagged_Type (T) then
Set_Is_Tagged_Type (Def_Id);
Make_Class_Wide_Type (Def_Id);
end if;
Set_Stored_Constraint (Def_Id, No_Elist);
if Has_Discrs then
Set_Discriminant_Constraint (Def_Id, Elist);
Set_Stored_Constraint_From_Discriminant_Constraint (Def_Id);
end if;
if Is_Tagged_Type (T) then
-- Ada 2005 (AI-251): In case of concurrent types we inherit the
-- concurrent record type (which has the list of primitive
-- operations).
if Ada_Version >= Ada_05
and then Is_Concurrent_Type (T)
then
Set_Corresponding_Record_Type (Def_Id,
Corresponding_Record_Type (T));
else
Set_Primitive_Operations (Def_Id, Primitive_Operations (T));
end if;
Set_Is_Abstract (Def_Id, Is_Abstract (T));
end if;
-- Subtypes introduced by component declarations do not need to be
-- marked as delayed, and do not get freeze nodes, because the semantics
-- verifies that the parents of the subtypes are frozen before the
-- enclosing record is frozen.
if not Is_Type (Scope (Def_Id)) then
Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
if Is_Private_Type (T)
and then Present (Full_View (T))
then
Conditional_Delay (Def_Id, Full_View (T));
else
Conditional_Delay (Def_Id, T);
end if;
end if;
if Is_Record_Type (T) then
Set_Is_Limited_Record (Def_Id, Is_Limited_Record (T));
if Has_Discrs
and then not Is_Empty_Elmt_List (Elist)
and then not For_Access
then
Create_Constrained_Components (Def_Id, Related_Nod, T, Elist);
elsif not For_Access then
Set_Cloned_Subtype (Def_Id, T);
end if;
end if;
end Build_Discriminated_Subtype;
------------------------
-- Build_Scalar_Bound --
------------------------
function Build_Scalar_Bound
(Bound : Node_Id;
Par_T : Entity_Id;
Der_T : Entity_Id) return Node_Id
is
New_Bound : Entity_Id;
begin
-- Note: not clear why this is needed, how can the original bound
-- be unanalyzed at this point? and if it is, what business do we
-- have messing around with it? and why is the base type of the
-- parent type the right type for the resolution. It probably is
-- not! It is OK for the new bound we are creating, but not for
-- the old one??? Still if it never happens, no problem!
Analyze_And_Resolve (Bound, Base_Type (Par_T));
if Nkind (Bound) = N_Integer_Literal
or else Nkind (Bound) = N_Real_Literal
then
New_Bound := New_Copy (Bound);
Set_Etype (New_Bound, Der_T);
Set_Analyzed (New_Bound);
elsif Is_Entity_Name (Bound) then
New_Bound := OK_Convert_To (Der_T, New_Copy (Bound));
-- The following is almost certainly wrong. What business do we have
-- relocating a node (Bound) that is presumably still attached to
-- the tree elsewhere???
else
New_Bound := OK_Convert_To (Der_T, Relocate_Node (Bound));
end if;
Set_Etype (New_Bound, Der_T);
return New_Bound;
end Build_Scalar_Bound;
--------------------------------
-- Build_Underlying_Full_View --
--------------------------------
procedure Build_Underlying_Full_View
(N : Node_Id;
Typ : Entity_Id;
Par : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Subt : constant Entity_Id :=
Make_Defining_Identifier
(Loc, New_External_Name (Chars (Typ), 'S'));
Constr : Node_Id;
Indic : Node_Id;
C : Node_Id;
Id : Node_Id;
procedure Set_Discriminant_Name (Id : Node_Id);
-- If the derived type has discriminants, they may rename discriminants
-- of the parent. When building the full view of the parent, we need to
-- recover the names of the original discriminants if the constraint is
-- given by named associations.
---------------------------
-- Set_Discriminant_Name --
---------------------------
procedure Set_Discriminant_Name (Id : Node_Id) is
Disc : Entity_Id;
begin
Set_Original_Discriminant (Id, Empty);
if Has_Discriminants (Typ) then
Disc := First_Discriminant (Typ);
while Present (Disc) loop
if Chars (Disc) = Chars (Id)
and then Present (Corresponding_Discriminant (Disc))
then
Set_Chars (Id, Chars (Corresponding_Discriminant (Disc)));
end if;
Next_Discriminant (Disc);
end loop;
end if;
end Set_Discriminant_Name;
-- Start of processing for Build_Underlying_Full_View
begin
if Nkind (N) = N_Full_Type_Declaration then
Constr := Constraint (Subtype_Indication (Type_Definition (N)));
elsif Nkind (N) = N_Subtype_Declaration then
Constr := New_Copy_Tree (Constraint (Subtype_Indication (N)));
elsif Nkind (N) = N_Component_Declaration then
Constr :=
New_Copy_Tree
(Constraint (Subtype_Indication (Component_Definition (N))));
else
raise Program_Error;
end if;
C := First (Constraints (Constr));
while Present (C) loop
if Nkind (C) = N_Discriminant_Association then
Id := First (Selector_Names (C));
while Present (Id) loop
Set_Discriminant_Name (Id);
Next (Id);
end loop;
end if;
Next (C);
end loop;
Indic :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Subt,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Reference_To (Par, Loc),
Constraint => New_Copy_Tree (Constr)));
-- If this is a component subtype for an outer itype, it is not
-- a list member, so simply set the parent link for analysis: if
-- the enclosing type does not need to be in a declarative list,
-- neither do the components.
if Is_List_Member (N)
and then Nkind (N) /= N_Component_Declaration
then
Insert_Before (N, Indic);
else
Set_Parent (Indic, Parent (N));
end if;
Analyze (Indic);
Set_Underlying_Full_View (Typ, Full_View (Subt));
end Build_Underlying_Full_View;
-------------------------------
-- Check_Abstract_Overriding --
-------------------------------
procedure Check_Abstract_Overriding (T : Entity_Id) is
Op_List : Elist_Id;
Elmt : Elmt_Id;
Subp : Entity_Id;
Alias_Subp : Entity_Id;
Type_Def : Node_Id;
begin
Op_List := Primitive_Operations (T);
-- Loop to check primitive operations
Elmt := First_Elmt (Op_List);
while Present (Elmt) loop
Subp := Node (Elmt);
Alias_Subp := Alias (Subp);
-- Inherited subprograms are identified by the fact that they do not
-- come from source, and the associated source location is the
-- location of the first subtype of the derived type.
-- Special exception, do not complain about failure to override the
-- stream routines _Input and _Output, as well as the primitive
-- operations used in dispatching selects since we always provide
-- automatic overridings for these subprograms.
if (Is_Abstract (Subp)
or else (Has_Controlling_Result (Subp)
and then Present (Alias_Subp)
and then not Comes_From_Source (Subp)
and then Sloc (Subp) = Sloc (First_Subtype (T))))
and then not Is_TSS (Subp, TSS_Stream_Input)
and then not Is_TSS (Subp, TSS_Stream_Output)
and then not Is_Abstract (T)
and then Chars (Subp) /= Name_uDisp_Asynchronous_Select
and then Chars (Subp) /= Name_uDisp_Conditional_Select
and then Chars (Subp) /= Name_uDisp_Get_Prim_Op_Kind
and then Chars (Subp) /= Name_uDisp_Timed_Select
then
if Present (Alias_Subp) then
-- Only perform the check for a derived subprogram when the
-- type has an explicit record extension. This avoids
-- incorrectly flagging abstract subprograms for the case of a
-- type without an extension derived from a formal type with a
-- tagged actual (can occur within a private part).
-- Ada 2005 (AI-391): In the case of an inherited function with
-- a controlling result of the type, the rule does not apply if
-- the type is a null extension (unless the parent function
-- itself is abstract, in which case the function must still be
-- be overridden). The expander will generate an overriding
-- wrapper function calling the parent subprogram (see
-- Exp_Ch3.Make_Controlling_Wrapper_Functions).
Type_Def := Type_Definition (Parent (T));
if Nkind (Type_Def) = N_Derived_Type_Definition
and then Present (Record_Extension_Part (Type_Def))
and then
(Ada_Version < Ada_05
or else not Is_Null_Extension (T)
or else Ekind (Subp) = E_Procedure
or else not Has_Controlling_Result (Subp)
or else Is_Abstract (Alias_Subp)
or else Is_Access_Type (Etype (Subp)))
then
Error_Msg_NE
("type must be declared abstract or & overridden",
T, Subp);
-- Traverse the whole chain of aliased subprograms to
-- complete the error notification. This is especially
-- useful for traceability of the chain of entities when the
-- subprogram corresponds with an interface subprogram
-- (which might be defined in another package)
if Present (Alias_Subp) then
declare
E : Entity_Id;
begin
E := Subp;
while Present (Alias (E)) loop
Error_Msg_Sloc := Sloc (E);
Error_Msg_NE ("\& has been inherited #", T, Subp);
E := Alias (E);
end loop;
Error_Msg_Sloc := Sloc (E);
Error_Msg_NE
("\& has been inherited from subprogram #", T, Subp);
end;
end if;
-- Ada 2005 (AI-345): Protected or task type implementing
-- abstract interfaces.
elsif Is_Concurrent_Record_Type (T)
and then Present (Abstract_Interfaces (T))
then
Error_Msg_NE
("interface subprogram & must be overridden",
T, Subp);
end if;
else
Error_Msg_NE
("abstract subprogram not allowed for type&",
Subp, T);
Error_Msg_NE
("nonabstract type has abstract subprogram&",
T, Subp);
end if;
end if;
Next_Elmt (Elmt);
end loop;
end Check_Abstract_Overriding;
------------------------------------------------
-- Check_Access_Discriminant_Requires_Limited --
------------------------------------------------
procedure Check_Access_Discriminant_Requires_Limited
(D : Node_Id;
Loc : Node_Id)
is
begin
-- A discriminant_specification for an access discriminant shall appear
-- only in the declaration for a task or protected type, or for a type
-- with the reserved word 'limited' in its definition or in one of its
-- ancestors. (RM 3.7(10))
if Nkind (Discriminant_Type (D)) = N_Access_Definition
and then not Is_Concurrent_Type (Current_Scope)
and then not Is_Concurrent_Record_Type (Current_Scope)
and then not Is_Limited_Record (Current_Scope)
and then Ekind (Current_Scope) /= E_Limited_Private_Type
then
Error_Msg_N
("access discriminants allowed only for limited types", Loc);
end if;
end Check_Access_Discriminant_Requires_Limited;
-----------------------------------
-- Check_Aliased_Component_Types --
-----------------------------------
procedure Check_Aliased_Component_Types (T : Entity_Id) is
C : Entity_Id;
begin
-- ??? Also need to check components of record extensions, but not
-- components of protected types (which are always limited).
-- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
-- types to be unconstrained. This is safe because it is illegal to
-- create access subtypes to such types with explicit discriminant
-- constraints.
if not Is_Limited_Type (T) then
if Ekind (T) = E_Record_Type then
C := First_Component (T);
while Present (C) loop
if Is_Aliased (C)
and then Has_Discriminants (Etype (C))
and then not Is_Constrained (Etype (C))
and then not In_Instance_Body
and then Ada_Version < Ada_05
then
Error_Msg_N
("aliased component must be constrained ('R'M 3.6(11))",
C);
end if;
Next_Component (C);
end loop;
elsif Ekind (T) = E_Array_Type then
if Has_Aliased_Components (T)
and then Has_Discriminants (Component_Type (T))
and then not Is_Constrained (Component_Type (T))
and then not In_Instance_Body
and then Ada_Version < Ada_05
then
Error_Msg_N
("aliased component type must be constrained ('R'M 3.6(11))",
T);
end if;
end if;
end if;
end Check_Aliased_Component_Types;
----------------------
-- Check_Completion --
----------------------
procedure Check_Completion (Body_Id : Node_Id := Empty) is
E : Entity_Id;
procedure Post_Error;
-- Post error message for lack of completion for entity E
----------------
-- Post_Error --
----------------
procedure Post_Error is
begin
if not Comes_From_Source (E) then
if Ekind (E) = E_Task_Type
or else Ekind (E) = E_Protected_Type
then
-- It may be an anonymous protected type created for a
-- single variable. Post error on variable, if present.
declare
Var : Entity_Id;
begin
Var := First_Entity (Current_Scope);
while Present (Var) loop
exit when Etype (Var) = E
and then Comes_From_Source (Var);
Next_Entity (Var);
end loop;
if Present (Var) then
E := Var;
end if;
end;
end if;
end if;
-- If a generated entity has no completion, then either previous
-- semantic errors have disabled the expansion phase, or else we had
-- missing subunits, or else we are compiling without expan- sion,
-- or else something is very wrong.
if not Comes_From_Source (E) then
pragma Assert
(Serious_Errors_Detected > 0
or else Configurable_Run_Time_Violations > 0
or else Subunits_Missing
or else not Expander_Active);
return;
-- Here for source entity
else
-- Here if no body to post the error message, so we post the error
-- on the declaration that has no completion. This is not really
-- the right place to post it, think about this later ???
if No (Body_Id) then
if Is_Type (E) then
Error_Msg_NE
("missing full declaration for }", Parent (E), E);
else
Error_Msg_NE
("missing body for &", Parent (E), E);
end if;
-- Package body has no completion for a declaration that appears
-- in the corresponding spec. Post error on the body, with a
-- reference to the non-completed declaration.
else
Error_Msg_Sloc := Sloc (E);
if Is_Type (E) then
Error_Msg_NE
("missing full declaration for }!", Body_Id, E);
elsif Is_Overloadable (E)
and then Current_Entity_In_Scope (E) /= E
then
-- It may be that the completion is mistyped and appears
-- as a distinct overloading of the entity.
declare
Candidate : constant Entity_Id :=
Current_Entity_In_Scope (E);
Decl : constant Node_Id :=
Unit_Declaration_Node (Candidate);
begin
if Is_Overloadable (Candidate)
and then Ekind (Candidate) = Ekind (E)
and then Nkind (Decl) = N_Subprogram_Body
and then Acts_As_Spec (Decl)
then
Check_Type_Conformant (Candidate, E);
else
Error_Msg_NE ("missing body for & declared#!",
Body_Id, E);
end if;
end;
else
Error_Msg_NE ("missing body for & declared#!",
Body_Id, E);
end if;
end if;
end if;
end Post_Error;
-- Start processing for Check_Completion
begin
E := First_Entity (Current_Scope);
while Present (E) loop
if Is_Intrinsic_Subprogram (E) then
null;
-- The following situation requires special handling: a child
-- unit that appears in the context clause of the body of its
-- parent:
-- procedure Parent.Child (...);
-- with Parent.Child;
-- package body Parent is
-- Here Parent.Child appears as a local entity, but should not
-- be flagged as requiring completion, because it is a
-- compilation unit.
elsif Ekind (E) = E_Function
or else Ekind (E) = E_Procedure
or else Ekind (E) = E_Generic_Function
or else Ekind (E) = E_Generic_Procedure
then
if not Has_Completion (E)
and then not Is_Abstract (E)
and then Nkind (Parent (Unit_Declaration_Node (E))) /=
N_Compilation_Unit
and then Chars (E) /= Name_uSize
then
Post_Error;
end if;
elsif Is_Entry (E) then
if not Has_Completion (E) and then
(Ekind (Scope (E)) = E_Protected_Object
or else Ekind (Scope (E)) = E_Protected_Type)
then
Post_Error;
end if;
elsif Is_Package_Or_Generic_Package (E) then
if Unit_Requires_Body (E) then
if not Has_Completion (E)
and then Nkind (Parent (Unit_Declaration_Node (E))) /=
N_Compilation_Unit
then
Post_Error;
end if;
elsif not Is_Child_Unit (E) then
May_Need_Implicit_Body (E);
end if;
elsif Ekind (E) = E_Incomplete_Type
and then No (Underlying_Type (E))
then
Post_Error;
elsif (Ekind (E) = E_Task_Type or else
Ekind (E) = E_Protected_Type)
and then not Has_Completion (E)
then
Post_Error;
-- A single task declared in the current scope is a constant, verify
-- that the body of its anonymous type is in the same scope. If the
-- task is defined elsewhere, this may be a renaming declaration for
-- which no completion is needed.
elsif Ekind (E) = E_Constant
and then Ekind (Etype (E)) = E_Task_Type
and then not Has_Completion (Etype (E))
and then Scope (Etype (E)) = Current_Scope
then
Post_Error;
elsif Ekind (E) = E_Protected_Object
and then not Has_Completion (Etype (E))
then
Post_Error;
elsif Ekind (E) = E_Record_Type then
if Is_Tagged_Type (E) then
Check_Abstract_Overriding (E);
end if;
Check_Aliased_Component_Types (E);
elsif Ekind (E) = E_Array_Type then
Check_Aliased_Component_Types (E);
end if;
Next_Entity (E);
end loop;
end Check_Completion;
----------------------------
-- Check_Delta_Expression --
----------------------------
procedure Check_Delta_Expression (E : Node_Id) is
begin
if not (Is_Real_Type (Etype (E))) then
Wrong_Type (E, Any_Real);
elsif not Is_OK_Static_Expression (E) then
Flag_Non_Static_Expr
("non-static expression used for delta value!", E);
elsif not UR_Is_Positive (Expr_Value_R (E)) then
Error_Msg_N ("delta expression must be positive", E);
else
return;
end if;
-- If any of above errors occurred, then replace the incorrect
-- expression by the real 0.1, which should prevent further errors.
Rewrite (E,
Make_Real_Literal (Sloc (E), Ureal_Tenth));
Analyze_And_Resolve (E, Standard_Float);
end Check_Delta_Expression;
-----------------------------
-- Check_Digits_Expression --
-----------------------------
procedure Check_Digits_Expression (E : Node_Id) is
begin
if not (Is_Integer_Type (Etype (E))) then
Wrong_Type (E, Any_Integer);
elsif not Is_OK_Static_Expression (E) then
Flag_Non_Static_Expr
("non-static expression used for digits value!", E);
elsif Expr_Value (E) <= 0 then
Error_Msg_N ("digits value must be greater than zero", E);
else
return;
end if;
-- If any of above errors occurred, then replace the incorrect
-- expression by the integer 1, which should prevent further errors.
Rewrite (E, Make_Integer_Literal (Sloc (E), 1));
Analyze_And_Resolve (E, Standard_Integer);
end Check_Digits_Expression;
--------------------------
-- Check_Initialization --
--------------------------
procedure Check_Initialization (T : Entity_Id; Exp : Node_Id) is
begin
if (Is_Limited_Type (T)
or else Is_Limited_Composite (T))
and then not In_Instance
and then not In_Inlined_Body
then
-- Ada 2005 (AI-287): Relax the strictness of the front-end in
-- case of limited aggregates and extension aggregates.
if Ada_Version >= Ada_05
and then (Nkind (Exp) = N_Aggregate
or else Nkind (Exp) = N_Extension_Aggregate)
then
null;
else
Error_Msg_N
("cannot initialize entities of limited type", Exp);
Explain_Limited_Type (T, Exp);
end if;
end if;
end Check_Initialization;
------------------------------------
-- Check_Or_Process_Discriminants --
------------------------------------
-- If an incomplete or private type declaration was already given for the
-- type, the discriminants may have already been processed if they were
-- present on the incomplete declaration. In this case a full conformance
-- check is performed otherwise just process them.
procedure Check_Or_Process_Discriminants
(N : Node_Id;
T : Entity_Id;
Prev : Entity_Id := Empty)
is
begin
if Has_Discriminants (T) then
-- Make the discriminants visible to component declarations
declare
D : Entity_Id;
Prev : Entity_Id;
begin
D := First_Discriminant (T);
while Present (D) loop
Prev := Current_Entity (D);
Set_Current_Entity (D);
Set_Is_Immediately_Visible (D);
Set_Homonym (D, Prev);
-- Ada 2005 (AI-230): Access discriminant allowed in
-- non-limited record types.
if Ada_Version < Ada_05 then
-- This restriction gets applied to the full type here. It
-- has already been applied earlier to the partial view.
Check_Access_Discriminant_Requires_Limited (Parent (D), N);
end if;
Next_Discriminant (D);
end loop;
end;
elsif Present (Discriminant_Specifications (N)) then
Process_Discriminants (N, Prev);
end if;
end Check_Or_Process_Discriminants;
----------------------
-- Check_Real_Bound --
----------------------
procedure Check_Real_Bound (Bound : Node_Id) is
begin
if not Is_Real_Type (Etype (Bound)) then
Error_Msg_N
("bound in real type definition must be of real type", Bound);
elsif not Is_OK_Static_Expression (Bound) then
Flag_Non_Static_Expr
("non-static expression used for real type bound!", Bound);
else
return;
end if;
Rewrite
(Bound, Make_Real_Literal (Sloc (Bound), Ureal_0));
Analyze (Bound);
Resolve (Bound, Standard_Float);
end Check_Real_Bound;
------------------------
-- Collect_Interfaces --
------------------------
procedure Collect_Interfaces (N : Node_Id; Derived_Type : Entity_Id) is
Intf : Node_Id;
procedure Add_Interface (Iface : Entity_Id);
-- Add one interface
-------------------
-- Add_Interface --
-------------------
procedure Add_Interface (Iface : Entity_Id) is
Elmt : Elmt_Id;
begin
Elmt := First_Elmt (Abstract_Interfaces (Derived_Type));
while Present (Elmt) and then Node (Elmt) /= Iface loop
Next_Elmt (Elmt);
end loop;
if No (Elmt) then
Append_Elmt (Node => Iface,
To => Abstract_Interfaces (Derived_Type));
end if;
end Add_Interface;
-- Start of processing for Collect_Interfaces
begin
pragma Assert (False
or else Nkind (N) = N_Derived_Type_Definition
or else Nkind (N) = N_Record_Definition
or else Nkind (N) = N_Private_Extension_Declaration);
-- Traverse the graph of ancestor interfaces
if Is_Non_Empty_List (Interface_List (N)) then
Intf := First (Interface_List (N));
while Present (Intf) loop
-- Protect against wrong uses. For example:
-- type I is interface;
-- type O is tagged null record;
-- type Wrong is new I and O with null record; -- ERROR
if Is_Interface (Etype (Intf)) then
-- Do not add the interface when the derived type already
-- implements this interface
if not Interface_Present_In_Ancestor (Derived_Type,
Etype (Intf))
then
Collect_Interfaces
(Type_Definition (Parent (Etype (Intf))),
Derived_Type);
Add_Interface (Etype (Intf));
end if;
end if;
Next (Intf);
end loop;
end if;
end Collect_Interfaces;
------------------------------
-- Complete_Private_Subtype --
------------------------------
procedure Complete_Private_Subtype
(Priv : Entity_Id;
Full : Entity_Id;
Full_Base : Entity_Id;
Related_Nod : Node_Id)
is
Save_Next_Entity : Entity_Id;
Save_Homonym : Entity_Id;
begin
-- Set semantic attributes for (implicit) private subtype completion.
-- If the full type has no discriminants, then it is a copy of the full
-- view of the base. Otherwise, it is a subtype of the base with a
-- possible discriminant constraint. Save and restore the original
-- Next_Entity field of full to ensure that the calls to Copy_Node
-- do not corrupt the entity chain.
-- Note that the type of the full view is the same entity as the type of
-- the partial view. In this fashion, the subtype has access to the
-- correct view of the parent.
Save_Next_Entity := Next_Entity (Full);
Save_Homonym := Homonym (Priv);
case Ekind (Full_Base) is
when E_Record_Type |
E_Record_Subtype |
Class_Wide_Kind |
Private_Kind |
Task_Kind |
Protected_Kind =>
Copy_Node (Priv, Full);
Set_Has_Discriminants (Full, Has_Discriminants (Full_Base));
Set_First_Entity (Full, First_Entity (Full_Base));
Set_Last_Entity (Full, Last_Entity (Full_Base));
when others =>
Copy_Node (Full_Base, Full);
Set_Chars (Full, Chars (Priv));
Conditional_Delay (Full, Priv);
Set_Sloc (Full, Sloc (Priv));
end case;
Set_Next_Entity (Full, Save_Next_Entity);
Set_Homonym (Full, Save_Homonym);
Set_Associated_Node_For_Itype (Full, Related_Nod);
-- Set common attributes for all subtypes
Set_Ekind (Full, Subtype_Kind (Ekind (Full_Base)));
-- The Etype of the full view is inconsistent. Gigi needs to see the
-- structural full view, which is what the current scheme gives:
-- the Etype of the full view is the etype of the full base. However,
-- if the full base is a derived type, the full view then looks like
-- a subtype of the parent, not a subtype of the full base. If instead
-- we write:
-- Set_Etype (Full, Full_Base);
-- then we get inconsistencies in the front-end (confusion between
-- views). Several outstanding bugs are related to this ???
Set_Is_First_Subtype (Full, False);
Set_Scope (Full, Scope (Priv));
Set_Size_Info (Full, Full_Base);
Set_RM_Size (Full, RM_Size (Full_Base));
Set_Is_Itype (Full);
-- A subtype of a private-type-without-discriminants, whose full-view
-- has discriminants with default expressions, is not constrained!
if not Has_Discriminants (Priv) then
Set_Is_Constrained (Full, Is_Constrained (Full_Base));
if Has_Discriminants (Full_Base) then
Set_Discriminant_Constraint
(Full, Discriminant_Constraint (Full_Base));
-- The partial view may have been indefinite, the full view
-- might not be.
Set_Has_Unknown_Discriminants
(Full, Has_Unknown_Discriminants (Full_Base));
end if;
end if;
Set_First_Rep_Item (Full, First_Rep_Item (Full_Base));
Set_Depends_On_Private (Full, Has_Private_Component (Full));
-- Freeze the private subtype entity if its parent is delayed, and not
-- already frozen. We skip this processing if the type is an anonymous
-- subtype of a record component, or is the corresponding record of a
-- protected type, since ???
if not Is_Type (Scope (Full)) then
Set_Has_Delayed_Freeze (Full,
Has_Delayed_Freeze (Full_Base)
and then (not Is_Frozen (Full_Base)));
end if;
Set_Freeze_Node (Full, Empty);
Set_Is_Frozen (Full, False);
Set_Full_View (Priv, Full);
if Has_Discriminants (Full) then
Set_Stored_Constraint_From_Discriminant_Constraint (Full);
Set_Stored_Constraint (Priv, Stored_Constraint (Full));
if Has_Unknown_Discriminants (Full) then
Set_Discriminant_Constraint (Full, No_Elist);
end if;
end if;
if Ekind (Full_Base) = E_Record_Type
and then Has_Discriminants (Full_Base)
and then Has_Discriminants (Priv) -- might not, if errors
and then not Has_Unknown_Discriminants (Priv)
and then not Is_Empty_Elmt_List (Discriminant_Constraint (Priv))
then
Create_Constrained_Components
(Full, Related_Nod, Full_Base, Discriminant_Constraint (Priv));
-- If the full base is itself derived from private, build a congruent
-- subtype of its underlying type, for use by the back end. For a
-- constrained record component, the declaration cannot be placed on
-- the component list, but it must nevertheless be built an analyzed, to
-- supply enough information for Gigi to compute the size of component.
elsif Ekind (Full_Base) in Private_Kind
and then Is_Derived_Type (Full_Base)
and then Has_Discriminants (Full_Base)
and then (Ekind (Current_Scope) /= E_Record_Subtype)
then
if not Is_Itype (Priv)
and then
Nkind (Subtype_Indication (Parent (Priv))) = N_Subtype_Indication
then
Build_Underlying_Full_View
(Parent (Priv), Full, Etype (Full_Base));
elsif Nkind (Related_Nod) = N_Component_Declaration then
Build_Underlying_Full_View (Related_Nod, Full, Etype (Full_Base));
end if;
elsif Is_Record_Type (Full_Base) then
-- Show Full is simply a renaming of Full_Base
Set_Cloned_Subtype (Full, Full_Base);
end if;
-- It is unsafe to share to bounds of a scalar type, because the Itype
-- is elaborated on demand, and if a bound is non-static then different
-- orders of elaboration in different units will lead to different
-- external symbols.
if Is_Scalar_Type (Full_Base) then
Set_Scalar_Range (Full,
Make_Range (Sloc (Related_Nod),
Low_Bound =>
Duplicate_Subexpr_No_Checks (Type_Low_Bound (Full_Base)),
High_Bound =>
Duplicate_Subexpr_No_Checks (Type_High_Bound (Full_Base))));
-- This completion inherits the bounds of the full parent, but if
-- the parent is an unconstrained floating point type, so is the
-- completion.
if Is_Floating_Point_Type (Full_Base) then
Set_Includes_Infinities
(Scalar_Range (Full), Has_Infinities (Full_Base));
end if;
end if;
-- ??? It seems that a lot of fields are missing that should be copied
-- from Full_Base to Full. Here are some that are introduced in a
-- non-disruptive way but a cleanup is necessary.
if Is_Tagged_Type (Full_Base) then
Set_Is_Tagged_Type (Full);
Set_Primitive_Operations (Full, Primitive_Operations (Full_Base));
Set_Class_Wide_Type (Full, Class_Wide_Type (Full_Base));
-- If this is a subtype of a protected or task type, constrain its
-- corresponding record, unless this is a subtype without constraints,
-- i.e. a simple renaming as with an actual subtype in an instance.
elsif Is_Concurrent_Type (Full_Base) then
if Has_Discriminants (Full)
and then Present (Corresponding_Record_Type (Full_Base))
and then
not Is_Empty_Elmt_List (Discriminant_Constraint (Full))
then
Set_Corresponding_Record_Type (Full,
Constrain_Corresponding_Record
(Full, Corresponding_Record_Type (Full_Base),
Related_Nod, Full_Base));
else
Set_Corresponding_Record_Type (Full,
Corresponding_Record_Type (Full_Base));
end if;
end if;
end Complete_Private_Subtype;
-------------------------------------
-- Complete_Subprograms_Derivation --
-------------------------------------
procedure Complete_Subprograms_Derivation
(Partial_View : Entity_Id;
Derived_Type : Entity_Id)
is
Result : constant Elist_Id := New_Elmt_List;
Elmt_P : Elmt_Id;
Elmt_D : Elmt_Id;
Found : Boolean;
Prim_Op : Entity_Id;
E : Entity_Id;
begin
-- Handle the case in which the full-view is a transitive
-- derivation of the ancestor of the partial view.
-- type I is interface;
-- type T is new I with ...
-- package H is
-- type DT is new I with private;
-- private
-- type DT is new T with ...
-- end;
if Etype (Partial_View) /= Etype (Derived_Type)
and then Is_Interface (Etype (Partial_View))
and then Is_Ancestor (Etype (Partial_View), Etype (Derived_Type))
then
return;
end if;
if Is_Tagged_Type (Partial_View) then
Elmt_P := First_Elmt (Primitive_Operations (Partial_View));
else
Elmt_P := No_Elmt;
end if;
-- Inherit primitives declared with the partial-view
while Present (Elmt_P) loop
Prim_Op := Node (Elmt_P);
Found := False;
Elmt_D := First_Elmt (Primitive_Operations (Derived_Type));
while Present (Elmt_D) loop
if Node (Elmt_D) = Prim_Op then
Found := True;
exit;
end if;
Next_Elmt (Elmt_D);
end loop;
if not Found then
Append_Elmt (Prim_Op, Result);
-- Search for entries associated with abstract interfaces that
-- have been covered by this primitive
Elmt_D := First_Elmt (Primitive_Operations (Derived_Type));
while Present (Elmt_D) loop
E := Node (Elmt_D);
if Chars (E) = Chars (Prim_Op)
and then Is_Abstract (E)
and then Present (Alias (E))
and then Present (DTC_Entity (Alias (E)))
and then Is_Interface (Scope (DTC_Entity (Alias (E))))
then
Remove_Elmt (Primitive_Operations (Derived_Type), Elmt_D);
end if;
Next_Elmt (Elmt_D);
end loop;
end if;
Next_Elmt (Elmt_P);
end loop;
-- Append the entities of the full-view to the list of primitives
-- of derived_type.
Elmt_D := First_Elmt (Result);
while Present (Elmt_D) loop
Append_Elmt (Node (Elmt_D), Primitive_Operations (Derived_Type));
Next_Elmt (Elmt_D);
end loop;
end Complete_Subprograms_Derivation;
----------------------------
-- Constant_Redeclaration --
----------------------------
procedure Constant_Redeclaration
(Id : Entity_Id;
N : Node_Id;
T : out Entity_Id)
is
Prev : constant Entity_Id := Current_Entity_In_Scope (Id);
Obj_Def : constant Node_Id := Object_Definition (N);
New_T : Entity_Id;
procedure Check_Possible_Deferred_Completion
(Prev_Id : Entity_Id;
Prev_Obj_Def : Node_Id;
Curr_Obj_Def : Node_Id);
-- Determine whether the two object definitions describe the partial
-- and the full view of a constrained deferred constant. Generate
-- a subtype for the full view and verify that it statically matches
-- the subtype of the partial view.
procedure Check_Recursive_Declaration (Typ : Entity_Id);
-- If deferred constant is an access type initialized with an allocator,
-- check whether there is an illegal recursion in the definition,
-- through a default value of some record subcomponent. This is normally
-- detected when generating init procs, but requires this additional
-- mechanism when expansion is disabled.
----------------------------------------
-- Check_Possible_Deferred_Completion --
----------------------------------------
procedure Check_Possible_Deferred_Completion
(Prev_Id : Entity_Id;
Prev_Obj_Def : Node_Id;
Curr_Obj_Def : Node_Id)
is
begin
if Nkind (Prev_Obj_Def) = N_Subtype_Indication
and then Present (Constraint (Prev_Obj_Def))
and then Nkind (Curr_Obj_Def) = N_Subtype_Indication
and then Present (Constraint (Curr_Obj_Def))
then
declare
Loc : constant Source_Ptr := Sloc (N);
Def_Id : constant Entity_Id :=
Make_Defining_Identifier (Loc,
New_Internal_Name ('S'));
Decl : constant Node_Id :=
Make_Subtype_Declaration (Loc,
Defining_Identifier =>
Def_Id,
Subtype_Indication =>
Relocate_Node (Curr_Obj_Def));
begin
Insert_Before_And_Analyze (N, Decl);
Set_Etype (Id, Def_Id);
if not Subtypes_Statically_Match (Etype (Prev_Id), Def_Id) then
Error_Msg_Sloc := Sloc (Prev_Id);
Error_Msg_N ("subtype does not statically match deferred " &
"declaration#", N);
end if;
end;
end if;
end Check_Possible_Deferred_Completion;
---------------------------------
-- Check_Recursive_Declaration --
---------------------------------
procedure Check_Recursive_Declaration (Typ : Entity_Id) is
Comp : Entity_Id;
begin
if Is_Record_Type (Typ) then
Comp := First_Component (Typ);
while Present (Comp) loop
if Comes_From_Source (Comp) then
if Present (Expression (Parent (Comp)))
and then Is_Entity_Name (Expression (Parent (Comp)))
and then Entity (Expression (Parent (Comp))) = Prev
then
Error_Msg_Sloc := Sloc (Parent (Comp));
Error_Msg_NE
("illegal circularity with declaration for&#",
N, Comp);
return;
elsif Is_Record_Type (Etype (Comp)) then
Check_Recursive_Declaration (Etype (Comp));
end if;
end if;
Next_Component (Comp);
end loop;
end if;
end Check_Recursive_Declaration;
-- Start of processing for Constant_Redeclaration
begin
if Nkind (Parent (Prev)) = N_Object_Declaration then
if Nkind (Object_Definition
(Parent (Prev))) = N_Subtype_Indication
then
-- Find type of new declaration. The constraints of the two
-- views must match statically, but there is no point in
-- creating an itype for the full view.
if Nkind (Obj_Def) = N_Subtype_Indication then
Find_Type (Subtype_Mark (Obj_Def));
New_T := Entity (Subtype_Mark (Obj_Def));
else
Find_Type (Obj_Def);
New_T := Entity (Obj_Def);
end if;
T := Etype (Prev);
else
-- The full view may impose a constraint, even if the partial
-- view does not, so construct the subtype.
New_T := Find_Type_Of_Object (Obj_Def, N);
T := New_T;
end if;
else
-- Current declaration is illegal, diagnosed below in Enter_Name
T := Empty;
New_T := Any_Type;
end if;
-- If previous full declaration exists, or if a homograph is present,
-- let Enter_Name handle it, either with an error, or with the removal
-- of an overridden implicit subprogram.
if Ekind (Prev) /= E_Constant
or else Present (Expression (Parent (Prev)))
or else Present (Full_View (Prev))
then
Enter_Name (Id);
-- Verify that types of both declarations match, or else that both types
-- are anonymous access types whose designated subtypes statically match
-- (as allowed in Ada 2005 by AI-385).
elsif Base_Type (Etype (Prev)) /= Base_Type (New_T)
and then
(Ekind (Etype (Prev)) /= E_Anonymous_Access_Type
or else Ekind (Etype (New_T)) /= E_Anonymous_Access_Type
or else not Subtypes_Statically_Match
(Designated_Type (Etype (Prev)),
Designated_Type (Etype (New_T))))
then
Error_Msg_Sloc := Sloc (Prev);
Error_Msg_N ("type does not match declaration#", N);
Set_Full_View (Prev, Id);
Set_Etype (Id, Any_Type);
-- If so, process the full constant declaration
else
-- RM 7.4 (6): If the subtype defined by the subtype_indication in
-- the deferred declaration is constrained, then the subtype defined
-- by the subtype_indication in the full declaration shall match it
-- statically.
Check_Possible_Deferred_Completion
(Prev_Id => Prev,
Prev_Obj_Def => Object_Definition (Parent (Prev)),
Curr_Obj_Def => Obj_Def);
Set_Full_View (Prev, Id);
Set_Is_Public (Id, Is_Public (Prev));
Set_Is_Internal (Id);
Append_Entity (Id, Current_Scope);
-- Check ALIASED present if present before (RM 7.4(7))
if Is_Aliased (Prev)
and then not Aliased_Present (N)
then
Error_Msg_Sloc := Sloc (Prev);
Error_Msg_N ("ALIASED required (see declaration#)", N);
end if;
-- Check that placement is in private part and that the incomplete
-- declaration appeared in the visible part.
if Ekind (Current_Scope) = E_Package
and then not In_Private_Part (Current_Scope)
then
Error_Msg_Sloc := Sloc (Prev);
Error_Msg_N ("full constant for declaration#"
& " must be in private part", N);
elsif Ekind (Current_Scope) = E_Package
and then List_Containing (Parent (Prev))
/= Visible_Declarations
(Specification (Unit_Declaration_Node (Current_Scope)))
then
Error_Msg_N
("deferred constant must be declared in visible part",
Parent (Prev));
end if;
if Is_Access_Type (T)
and then Nkind (Expression (N)) = N_Allocator
then
Check_Recursive_Declaration (Designated_Type (T));
end if;
end if;
end Constant_Redeclaration;
----------------------
-- Constrain_Access --
----------------------
procedure Constrain_Access
(Def_Id : in out Entity_Id;
S : Node_Id;
Related_Nod : Node_Id)
is
T : constant Entity_Id := Entity (Subtype_Mark (S));
Desig_Type : constant Entity_Id := Designated_Type (T);
Desig_Subtype : Entity_Id := Create_Itype (E_Void, Related_Nod);
Constraint_OK : Boolean := True;
function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean;
-- Simple predicate to test for defaulted discriminants
-- Shouldn't this be in sem_util???
---------------------------------
-- Has_Defaulted_Discriminants --
---------------------------------
function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
begin
return Has_Discriminants (Typ)
and then Present (First_Discriminant (Typ))
and then Present
(Discriminant_Default_Value (First_Discriminant (Typ)));
end Has_Defaulted_Discriminants;
-- Start of processing for Constrain_Access
begin
if Is_Array_Type (Desig_Type) then
Constrain_Array (Desig_Subtype, S, Related_Nod, Def_Id, 'P');
elsif (Is_Record_Type (Desig_Type)
or else Is_Incomplete_Or_Private_Type (Desig_Type))
and then not Is_Constrained (Desig_Type)
then
-- ??? The following code is a temporary kludge to ignore a
-- discriminant constraint on access type if it is constraining
-- the current record. Avoid creating the implicit subtype of the
-- record we are currently compiling since right now, we cannot
-- handle these. For now, just return the access type itself.
if Desig_Type = Current_Scope
and then No (Def_Id)
then
Set_Ekind (Desig_Subtype, E_Record_Subtype);
Def_Id := Entity (Subtype_Mark (S));
-- This call added to ensure that the constraint is analyzed
-- (needed for a B test). Note that we still return early from
-- this procedure to avoid recursive processing. ???
Constrain_Discriminated_Type
(Desig_Subtype, S, Related_Nod, For_Access => True);
return;
end if;
if Ekind (T) = E_General_Access_Type
and then Has_Private_Declaration (Desig_Type)
and then In_Open_Scopes (Scope (Desig_Type))
then
-- Enforce rule that the constraint is illegal if there is
-- an unconstrained view of the designated type. This means
-- that the partial view (either a private type declaration or
-- a derivation from a private type) has no discriminants.
-- (Defect Report 8652/0008, Technical Corrigendum 1, checked
-- by ACATS B371001).
-- Rule updated for Ada 2005: the private type is said to have
-- a constrained partial view, given that objects of the type
-- can be declared.
declare
Pack : constant Node_Id :=
Unit_Declaration_Node (Scope (Desig_Type));
Decls : List_Id;
Decl : Node_Id;
begin
if Nkind (Pack) = N_Package_Declaration then
Decls := Visible_Declarations (Specification (Pack));
Decl := First (Decls);
while Present (Decl) loop
if (Nkind (Decl) = N_Private_Type_Declaration
and then
Chars (Defining_Identifier (Decl)) =
Chars (Desig_Type))
or else
(Nkind (Decl) = N_Full_Type_Declaration
and then
Chars (Defining_Identifier (Decl)) =
Chars (Desig_Type)
and then Is_Derived_Type (Desig_Type)
and then
Has_Private_Declaration (Etype (Desig_Type)))
then
if No (Discriminant_Specifications (Decl)) then
Error_Msg_N
("cannot constrain general access type if " &
"designated type has constrained partial view",
S);
end if;
exit;
end if;
Next (Decl);
end loop;
end if;
end;
end if;
Constrain_Discriminated_Type (Desig_Subtype, S, Related_Nod,
For_Access => True);
elsif (Is_Task_Type (Desig_Type)
or else Is_Protected_Type (Desig_Type))
and then not Is_Constrained (Desig_Type)
then
Constrain_Concurrent
(Desig_Subtype, S, Related_Nod, Desig_Type, ' ');
else
Error_Msg_N ("invalid constraint on access type", S);
Desig_Subtype := Desig_Type; -- Ignore invalid constraint.
Constraint_OK := False;
end if;
if No (Def_Id) then
Def_Id := Create_Itype (E_Access_Subtype, Related_Nod);
else
Set_Ekind (Def_Id, E_Access_Subtype);
end if;
if Constraint_OK then
Set_Etype (Def_Id, Base_Type (T));
if Is_Private_Type (Desig_Type) then
Prepare_Private_Subtype_Completion (Desig_Subtype, Related_Nod);
end if;
else
Set_Etype (Def_Id, Any_Type);
end if;
Set_Size_Info (Def_Id, T);
Set_Is_Constrained (Def_Id, Constraint_OK);
Set_Directly_Designated_Type (Def_Id, Desig_Subtype);
Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
Set_Is_Access_Constant (Def_Id, Is_Access_Constant (T));
Conditional_Delay (Def_Id, T);
-- AI-363 : Subtypes of general access types whose designated types have
-- default discriminants are disallowed. In instances, the rule has to
-- be checked against the actual, of which T is the subtype. In a
-- generic body, the rule is checked assuming that the actual type has
-- defaulted discriminants.
if Ada_Version >= Ada_05 then
if Ekind (Base_Type (T)) = E_General_Access_Type
and then Has_Defaulted_Discriminants (Desig_Type)
then
Error_Msg_N
("access subype of general access type not allowed", S);
Error_Msg_N ("\ when discriminants have defaults", S);
elsif Is_Access_Type (T)
and then Is_Generic_Type (Desig_Type)
and then Has_Discriminants (Desig_Type)
and then In_Package_Body (Current_Scope)
then
Error_Msg_N ("access subtype not allowed in generic body", S);
Error_Msg_N
("\ wben designated type is a discriminated formal", S);
end if;
end if;
end Constrain_Access;
---------------------
-- Constrain_Array --
---------------------
procedure Constrain_Array
(Def_Id : in out Entity_Id;
SI : Node_Id;
Related_Nod : Node_Id;
Related_Id : Entity_Id;
Suffix : Character)
is
C : constant Node_Id := Constraint (SI);
Number_Of_Constraints : Nat := 0;
Index : Node_Id;
S, T : Entity_Id;
Constraint_OK : Boolean := True;
begin
T := Entity (Subtype_Mark (SI));
if Ekind (T) in Access_Kind then
T := Designated_Type (T);
end if;
-- If an index constraint follows a subtype mark in a subtype indication
-- then the type or subtype denoted by the subtype mark must not already
-- impose an index constraint. The subtype mark must denote either an
-- unconstrained array type or an access type whose designated type
-- is such an array type... (RM 3.6.1)
if Is_Constrained (T) then
Error_Msg_N
("array type is already constrained", Subtype_Mark (SI));
Constraint_OK := False;
else
S := First (Constraints (C));
while Present (S) loop
Number_Of_Constraints := Number_Of_Constraints + 1;
Next (S);
end loop;
-- In either case, the index constraint must provide a discrete
-- range for each index of the array type and the type of each
-- discrete range must be the same as that of the corresponding
-- index. (RM 3.6.1)
if Number_Of_Constraints /= Number_Dimensions (T) then
Error_Msg_NE ("incorrect number of index constraints for }", C, T);
Constraint_OK := False;
else
S := First (Constraints (C));
Index := First_Index (T);
Analyze (Index);
-- Apply constraints to each index type
for J in 1 .. Number_Of_Constraints loop
Constrain_Index (Index, S, Related_Nod, Related_Id, Suffix, J);
Next (Index);
Next (S);
end loop;
end if;
end if;
if No (Def_Id) then
Def_Id :=
Create_Itype (E_Array_Subtype, Related_Nod, Related_Id, Suffix);
Set_Parent (Def_Id, Related_Nod);
else
Set_Ekind (Def_Id, E_Array_Subtype);
end if;
Set_Size_Info (Def_Id, (T));
Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
Set_Etype (Def_Id, Base_Type (T));
if Constraint_OK then
Set_First_Index (Def_Id, First (Constraints (C)));
else
Set_First_Index (Def_Id, First_Index (T));
end if;
Set_Is_Constrained (Def_Id, True);
Set_Is_Aliased (Def_Id, Is_Aliased (T));
Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
Set_Is_Private_Composite (Def_Id, Is_Private_Composite (T));
Set_Is_Limited_Composite (Def_Id, Is_Limited_Composite (T));
-- Build a freeze node if parent still needs one. Also, make sure
-- that the Depends_On_Private status is set (explanation ???)
-- and also that a conditional delay is set.
Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
Conditional_Delay (Def_Id, T);
end Constrain_Array;
------------------------------
-- Constrain_Component_Type --
------------------------------
function Constrain_Component_Type
(Comp : Entity_Id;
Constrained_Typ : Entity_Id;
Related_Node : Node_Id;
Typ : Entity_Id;
Constraints : Elist_Id) return Entity_Id
is
Loc : constant Source_Ptr := Sloc (Constrained_Typ);
Compon_Type : constant Entity_Id := Etype (Comp);
function Build_Constrained_Array_Type
(Old_Type : Entity_Id) return Entity_Id;
-- If Old_Type is an array type, one of whose indices is constrained
-- by a discriminant, build an Itype whose constraint replaces the
-- discriminant with its value in the constraint.
function Build_Constrained_Discriminated_Type
(Old_Type : Entity_Id) return Entity_Id;
-- Ditto for record components
function Build_Constrained_Access_Type
(Old_Type : Entity_Id) return Entity_Id;
-- Ditto for access types. Makes use of previous two functions, to
-- constrain designated type.
function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id;
-- T is an array or discriminated type, C is a list of constraints
-- that apply to T. This routine builds the constrained subtype.
function Is_Discriminant (Expr : Node_Id) return Boolean;
-- Returns True if Expr is a discriminant
function Get_Discr_Value (Discrim : Entity_Id) return Node_Id;
-- Find the value of discriminant Discrim in Constraint
-----------------------------------
-- Build_Constrained_Access_Type --
-----------------------------------
function Build_Constrained_Access_Type
(Old_Type : Entity_Id) return Entity_Id
is
Desig_Type : constant Entity_Id := Designated_Type (Old_Type);
Itype : Entity_Id;
Desig_Subtype : Entity_Id;
Scop : Entity_Id;
begin
-- if the original access type was not embedded in the enclosing
-- type definition, there is no need to produce a new access
-- subtype. In fact every access type with an explicit constraint
-- generates an itype whose scope is the enclosing record.
if not Is_Type (Scope (Old_Type)) then
return Old_Type;
elsif Is_Array_Type (Desig_Type) then
Desig_Subtype := Build_Constrained_Array_Type (Desig_Type);
elsif Has_Discriminants (Desig_Type) then
-- This may be an access type to an enclosing record type for
-- which we are constructing the constrained components. Return
-- the enclosing record subtype. This is not always correct,
-- but avoids infinite recursion. ???
Desig_Subtype := Any_Type;
for J in reverse 0 .. Scope_Stack.Last loop
Scop := Scope_Stack.Table (J).Entity;
if Is_Type (Scop)
and then Base_Type (Scop) = Base_Type (Desig_Type)
then
Desig_Subtype := Scop;
end if;
exit when not Is_Type (Scop);
end loop;
if Desig_Subtype = Any_Type then
Desig_Subtype :=
Build_Constrained_Discriminated_Type (Desig_Type);
end if;
else
return Old_Type;
end if;
if Desig_Subtype /= Desig_Type then
-- The Related_Node better be here or else we won't be able
-- to attach new itypes to a node in the tree.
pragma Assert (Present (Related_Node));
Itype := Create_Itype (E_Access_Subtype, Related_Node);
Set_Etype (Itype, Base_Type (Old_Type));
Set_Size_Info (Itype, (Old_Type));
Set_Directly_Designated_Type (Itype, Desig_Subtype);
Set_Depends_On_Private (Itype, Has_Private_Component
(Old_Type));
Set_Is_Access_Constant (Itype, Is_Access_Constant
(Old_Type));
-- The new itype needs freezing when it depends on a not frozen
-- type and the enclosing subtype needs freezing.
if Has_Delayed_Freeze (Constrained_Typ)
and then not Is_Frozen (Constrained_Typ)
then
Conditional_Delay (Itype, Base_Type (Old_Type));
end if;
return Itype;
else
return Old_Type;
end if;
end Build_Constrained_Access_Type;
----------------------------------
-- Build_Constrained_Array_Type --
----------------------------------
function Build_Constrained_Array_Type
(Old_Type : Entity_Id) return Entity_Id
is
Lo_Expr : Node_Id;
Hi_Expr : Node_Id;
Old_Index : Node_Id;
Range_Node : Node_Id;
Constr_List : List_Id;
Need_To_Create_Itype : Boolean := False;
begin
Old_Index := First_Index (Old_Type);
while Present (Old_Index) loop
Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
if Is_Discriminant (Lo_Expr)
or else Is_Discriminant (Hi_Expr)
then
Need_To_Create_Itype := True;
end if;
Next_Index (Old_Index);
end loop;
if Need_To_Create_Itype then
Constr_List := New_List;
Old_Index := First_Index (Old_Type);
while Present (Old_Index) loop
Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
if Is_Discriminant (Lo_Expr) then
Lo_Expr := Get_Discr_Value (Lo_Expr);
end if;
if Is_Discriminant (Hi_Expr) then
Hi_Expr := Get_Discr_Value (Hi_Expr);
end if;
Range_Node :=
Make_Range
(Loc, New_Copy_Tree (Lo_Expr), New_Copy_Tree (Hi_Expr));
Append (Range_Node, To => Constr_List);
Next_Index (Old_Index);
end loop;
return Build_Subtype (Old_Type, Constr_List);
else
return Old_Type;
end if;
end Build_Constrained_Array_Type;
------------------------------------------
-- Build_Constrained_Discriminated_Type --
------------------------------------------
function Build_Constrained_Discriminated_Type
(Old_Type : Entity_Id) return Entity_Id
is
Expr : Node_Id;
Constr_List : List_Id;
Old_Constraint : Elmt_Id;
Need_To_Create_Itype : Boolean := False;
begin
Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
while Present (Old_Constraint) loop
Expr := Node (Old_Constraint);
if Is_Discriminant (Expr) then
Need_To_Create_Itype := True;
end if;
Next_Elmt (Old_Constraint);
end loop;
if Need_To_Create_Itype then
Constr_List := New_List;
Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
while Present (Old_Constraint) loop
Expr := Node (Old_Constraint);
if Is_Discriminant (Expr) then
Expr := Get_Discr_Value (Expr);
end if;
Append (New_Copy_Tree (Expr), To => Constr_List);
Next_Elmt (Old_Constraint);
end loop;
return Build_Subtype (Old_Type, Constr_List);
else
return Old_Type;
end if;
end Build_Constrained_Discriminated_Type;
-------------------
-- Build_Subtype --
-------------------
function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id is
Indic : Node_Id;
Subtyp_Decl : Node_Id;
Def_Id : Entity_Id;
Btyp : Entity_Id := Base_Type (T);
begin
-- The Related_Node better be here or else we won't be able to
-- attach new itypes to a node in the tree.
pragma Assert (Present (Related_Node));
-- If the view of the component's type is incomplete or private
-- with unknown discriminants, then the constraint must be applied
-- to the full type.
if Has_Unknown_Discriminants (Btyp)
and then Present (Underlying_Type (Btyp))
then
Btyp := Underlying_Type (Btyp);
end if;
Indic :=
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
Constraint => Make_Index_Or_Discriminant_Constraint (Loc, C));
Def_Id := Create_Itype (Ekind (T), Related_Node);
Subtyp_Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Def_Id,
Subtype_Indication => Indic);
Set_Parent (Subtyp_Decl, Parent (Related_Node));
-- Itypes must be analyzed with checks off (see package Itypes)
Analyze (Subtyp_Decl, Suppress => All_Checks);
return Def_Id;
end Build_Subtype;
---------------------
-- Get_Discr_Value --
---------------------
function Get_Discr_Value (Discrim : Entity_Id) return Node_Id is
D : Entity_Id;
E : Elmt_Id;
G : Elmt_Id;
begin
-- The discriminant may be declared for the type, in which case we
-- find it by iterating over the list of discriminants. If the
-- discriminant is inherited from a parent type, it appears as the
-- corresponding discriminant of the current type. This will be the
-- case when constraining an inherited component whose constraint is
-- given by a discriminant of the parent.
D := First_Discriminant (Typ);
E := First_Elmt (Constraints);
while Present (D) loop
if D = Entity (Discrim)
or else Corresponding_Discriminant (D) = Entity (Discrim)
then
return Node (E);
end if;
Next_Discriminant (D);
Next_Elmt (E);
end loop;
-- The corresponding_Discriminant mechanism is incomplete, because
-- the correspondence between new and old discriminants is not one
-- to one: one new discriminant can constrain several old ones. In
-- that case, scan sequentially the stored_constraint, the list of
-- discriminants of the parents, and the constraints.
if Is_Derived_Type (Typ)
and then Present (Stored_Constraint (Typ))
and then Scope (Entity (Discrim)) = Etype (Typ)
then
D := First_Discriminant (Etype (Typ));
E := First_Elmt (Constraints);
G := First_Elmt (Stored_Constraint (Typ));
while Present (D) loop
if D = Entity (Discrim) then
return Node (E);
end if;
Next_Discriminant (D);
Next_Elmt (E);
Next_Elmt (G);
end loop;
end if;
-- Something is wrong if we did not find the value
raise Program_Error;
end Get_Discr_Value;
---------------------
-- Is_Discriminant --
---------------------
function Is_Discriminant (Expr : Node_Id) return Boolean is
Discrim_Scope : Entity_Id;
begin
if Denotes_Discriminant (Expr) then
Discrim_Scope := Scope (Entity (Expr));
-- Either we have a reference to one of Typ's discriminants,
pragma Assert (Discrim_Scope = Typ
-- or to the discriminants of the parent type, in the case
-- of a derivation of a tagged type with variants.
or else Discrim_Scope = Etype (Typ)
or else Full_View (Discrim_Scope) = Etype (Typ)
-- or same as above for the case where the discriminants
-- were declared in Typ's private view.
or else (Is_Private_Type (Discrim_Scope)
and then Chars (Discrim_Scope) = Chars (Typ))
-- or else we are deriving from the full view and the
-- discriminant is declared in the private entity.
or else (Is_Private_Type (Typ)
and then Chars (Discrim_Scope) = Chars (Typ))
-- or we have a class-wide type, in which case make sure the
-- discriminant found belongs to the root type.
or else (Is_Class_Wide_Type (Typ)
and then Etype (Typ) = Discrim_Scope));
return True;
end if;
-- In all other cases we have something wrong
return False;
end Is_Discriminant;
-- Start of processing for Constrain_Component_Type
begin
if Nkind (Parent (Comp)) = N_Component_Declaration
and then Comes_From_Source (Parent (Comp))
and then Comes_From_Source
(Subtype_Indication (Component_Definition (Parent (Comp))))
and then
Is_Entity_Name
(Subtype_Indication (Component_Definition (Parent (Comp))))
then
return Compon_Type;
elsif Is_Array_Type (Compon_Type) then
return Build_Constrained_Array_Type (Compon_Type);
elsif Has_Discriminants (Compon_Type) then
return Build_Constrained_Discriminated_Type (Compon_Type);
elsif Is_Access_Type (Compon_Type) then
return Build_Constrained_Access_Type (Compon_Type);
else
return Compon_Type;
end if;
end Constrain_Component_Type;
--------------------------
-- Constrain_Concurrent --
--------------------------
-- For concurrent types, the associated record value type carries the same
-- discriminants, so when we constrain a concurrent type, we must constrain
-- the corresponding record type as well.
procedure Constrain_Concurrent
(Def_Id : in out Entity_Id;
SI : Node_Id;
Related_Nod : Node_Id;
Related_Id : Entity_Id;
Suffix : Character)
is
T_Ent : Entity_Id := Entity (Subtype_Mark (SI));
T_Val : Entity_Id;
begin
if Ekind (T_Ent) in Access_Kind then
T_Ent := Designated_Type (T_Ent);
end if;
T_Val := Corresponding_Record_Type (T_Ent);
if Present (T_Val) then
if No (Def_Id) then
Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
end if;
Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
Set_Corresponding_Record_Type (Def_Id,
Constrain_Corresponding_Record
(Def_Id, T_Val, Related_Nod, Related_Id));
else
-- If there is no associated record, expansion is disabled and this
-- is a generic context. Create a subtype in any case, so that
-- semantic analysis can proceed.
if No (Def_Id) then
Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
end if;
Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
end if;
end Constrain_Concurrent;
------------------------------------
-- Constrain_Corresponding_Record --
------------------------------------
function Constrain_Corresponding_Record
(Prot_Subt : Entity_Id;
Corr_Rec : Entity_Id;
Related_Nod : Node_Id;
Related_Id : Entity_Id) return Entity_Id
is
T_Sub : constant Entity_Id :=
Create_Itype (E_Record_Subtype, Related_Nod, Related_Id, 'V');
begin
Set_Etype (T_Sub, Corr_Rec);
Init_Size_Align (T_Sub);
Set_Has_Discriminants (T_Sub, Has_Discriminants (Prot_Subt));
Set_Is_Constrained (T_Sub, True);
Set_First_Entity (T_Sub, First_Entity (Corr_Rec));
Set_Last_Entity (T_Sub, Last_Entity (Corr_Rec));
Conditional_Delay (T_Sub, Corr_Rec);
if Has_Discriminants (Prot_Subt) then -- False only if errors.
Set_Discriminant_Constraint
(T_Sub, Discriminant_Constraint (Prot_Subt));
Set_Stored_Constraint_From_Discriminant_Constraint (T_Sub);
Create_Constrained_Components
(T_Sub, Related_Nod, Corr_Rec, Discriminant_Constraint (T_Sub));
end if;
Set_Depends_On_Private (T_Sub, Has_Private_Component (T_Sub));
return T_Sub;
end Constrain_Corresponding_Record;
-----------------------
-- Constrain_Decimal --
-----------------------
procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id) is
T : constant Entity_Id := Entity (Subtype_Mark (S));
C : constant Node_Id := Constraint (S);
Loc : constant Source_Ptr := Sloc (C);
Range_Expr : Node_Id;
Digits_Expr : Node_Id;
Digits_Val : Uint;
Bound_Val : Ureal;
begin
Set_Ekind (Def_Id, E_Decimal_Fixed_Point_Subtype);
if Nkind (C) = N_Range_Constraint then
Range_Expr := Range_Expression (C);
Digits_Val := Digits_Value (T);
else
pragma Assert (Nkind (C) = N_Digits_Constraint);
Digits_Expr := Digits_Expression (C);
Analyze_And_Resolve (Digits_Expr, Any_Integer);
Check_Digits_Expression (Digits_Expr);
Digits_Val := Expr_Value (Digits_Expr);
if Digits_Val > Digits_Value (T) then
Error_Msg_N
("digits expression is incompatible with subtype", C);
Digits_Val := Digits_Value (T);
end if;
if Present (Range_Constraint (C)) then
Range_Expr := Range_Expression (Range_Constraint (C));
else
Range_Expr := Empty;
end if;
end if;
Set_Etype (Def_Id, Base_Type (T));
Set_Size_Info (Def_Id, (T));
Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
Set_Delta_Value (Def_Id, Delta_Value (T));
Set_Scale_Value (Def_Id, Scale_Value (T));
Set_Small_Value (Def_Id, Small_Value (T));
Set_Machine_Radix_10 (Def_Id, Machine_Radix_10 (T));
Set_Digits_Value (Def_Id, Digits_Val);
-- Manufacture range from given digits value if no range present
if No (Range_Expr) then
Bound_Val := (Ureal_10 ** Digits_Val - Ureal_1) * Small_Value (T);
Range_Expr :=
Make_Range (Loc,
Low_Bound =>
Convert_To (T, Make_Real_Literal (Loc, (-Bound_Val))),
High_Bound =>
Convert_To (T, Make_Real_Literal (Loc, Bound_Val)));
end if;
Set_Scalar_Range_For_Subtype (Def_Id, Range_Expr, T);
Set_Discrete_RM_Size (Def_Id);
-- Unconditionally delay the freeze, since we cannot set size
-- information in all cases correctly until the freeze point.
Set_Has_Delayed_Freeze (Def_Id);
end Constrain_Decimal;
----------------------------------
-- Constrain_Discriminated_Type --
----------------------------------
procedure Constrain_Discriminated_Type
(Def_Id : Entity_Id;
S : Node_Id;
Related_Nod : Node_Id;
For_Access : Boolean := False)
is
E : constant Entity_Id := Entity (Subtype_Mark (S));
T : Entity_Id;
C : Node_Id;
Elist : Elist_Id := New_Elmt_List;
procedure Fixup_Bad_Constraint;
-- This is called after finding a bad constraint, and after having
-- posted an appropriate error message. The mission is to leave the
-- entity T in as reasonable state as possible!
--------------------------
-- Fixup_Bad_Constraint --
--------------------------
procedure Fixup_Bad_Constraint is
begin
-- Set a reasonable Ekind for the entity. For an incomplete type,
-- we can't do much, but for other types, we can set the proper
-- corresponding subtype kind.
if Ekind (T) = E_Incomplete_Type then
Set_Ekind (Def_Id, Ekind (T));
else
Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
end if;
Set_Etype (Def_Id, Any_Type);
Set_Error_Posted (Def_Id);
end Fixup_Bad_Constraint;
-- Start of processing for Constrain_Discriminated_Type
begin
C := Constraint (S);
-- A discriminant constraint is only allowed in a subtype indication,
-- after a subtype mark. This subtype mark must denote either a type
-- with discriminants, or an access type whose designated type is a
-- type with discriminants. A discriminant constraint specifies the
-- values of these discriminants (RM 3.7.2(5)).
T := Base_Type (Entity (Subtype_Mark (S)));
if Ekind (T) in Access_Kind then
T := Designated_Type (T);
end if;
-- Check that the type has visible discriminants. The type may be
-- a private type with unknown discriminants whose full view has
-- discriminants which are invisible.
if not Has_Discriminants (T)
or else
(Has_Unknown_Discriminants (T)
and then Is_Private_Type (T))
then
Error_Msg_N ("invalid constraint: type has no discriminant", C);
Fixup_Bad_Constraint;
return;
elsif Is_Constrained (E)
or else (Ekind (E) = E_Class_Wide_Subtype
and then Present (Discriminant_Constraint (E)))
then
Error_Msg_N ("type is already constrained", Subtype_Mark (S));
Fixup_Bad_Constraint;
return;
end if;
-- T may be an unconstrained subtype (e.g. a generic actual).
-- Constraint applies to the base type.
T := Base_Type (T);
Elist := Build_Discriminant_Constraints (T, S);
-- If the list returned was empty we had an error in building the
-- discriminant constraint. We have also already signalled an error
-- in the incomplete type case
if Is_Empty_Elmt_List (Elist) then
Fixup_Bad_Constraint;
return;
end if;
Build_Discriminated_Subtype (T, Def_Id, Elist, Related_Nod, For_Access);
end Constrain_Discriminated_Type;
---------------------------
-- Constrain_Enumeration --
---------------------------
procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id) is
T : constant Entity_Id := Entity (Subtype_Mark (S));
C : constant Node_Id := Constraint (S);
begin
Set_Ekind (Def_Id, E_Enumeration_Subtype);
Set_First_Literal (Def_Id, First_Literal (Base_Type (T)));
Set_Etype (Def_Id, Base_Type (T));
Set_Size_Info (Def_Id, (T));
Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
Set_Discrete_RM_Size (Def_Id);
end Constrain_Enumeration;
----------------------
-- Constrain_Float --
----------------------
procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id) is
T : constant Entity_Id := Entity (Subtype_Mark (S));
C : Node_Id;
D : Node_Id;
Rais : Node_Id;
begin
Set_Ekind (Def_Id, E_Floating_Point_Subtype);
Set_Etype (Def_Id, Base_Type (T));
Set_Size_Info (Def_Id, (T));
Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
-- Process the constraint
C := Constraint (S);
-- Digits constraint present
if Nkind (C) = N_Digits_Constraint then
Check_Restriction (No_Obsolescent_Features, C);
if Warn_On_Obsolescent_Feature then
Error_Msg_N
("subtype digits constraint is an " &
"obsolescent feature ('R'M 'J.3(8))?", C);
end if;
D := Digits_Expression (C);
Analyze_And_Resolve (D, Any_Integer);
Check_Digits_Expression (D);
Set_Digits_Value (Def_Id, Expr_Value (D));
-- Check that digits value is in range. Obviously we can do this
-- at compile time, but it is strictly a runtime check, and of
-- course there is an ACVC test that checks this!
if Digits_Value (Def_Id) > Digits_Value (T) then
Error_Msg_Uint_1 := Digits_Value (T);
Error_Msg_N ("?digits value is too large, maximum is ^", D);
Rais :=
Make_Raise_Constraint_Error (Sloc (D),
Reason => CE_Range_Check_Failed);
Insert_Action (Declaration_Node (Def_Id), Rais);
end if;
C := Range_Constraint (C);
-- No digits constraint present
else
Set_Digits_Value (Def_Id, Digits_Value (T));
end if;
-- Range constraint present
if Nkind (C) = N_Range_Constraint then
Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
-- No range constraint present
else
pragma Assert (No (C));
Set_Scalar_Range (Def_Id, Scalar_Range (T));
end if;
Set_Is_Constrained (Def_Id);
end Constrain_Float;
---------------------
-- Constrain_Index --
---------------------
procedure Constrain_Index
(Index : Node_Id;
S : Node_Id;
Related_Nod : Node_Id;
Related_Id : Entity_Id;
Suffix : Character;
Suffix_Index : Nat)
is
Def_Id : Entity_Id;
R : Node_Id := Empty;
T : constant Entity_Id := Etype (Index);
begin
if Nkind (S) = N_Range
or else
(Nkind (S) = N_Attribute_Reference
and then Attribute_Name (S) = Name_Range)
then
-- A Range attribute will transformed into N_Range by Resolve
Analyze (S);
Set_Etype (S, T);
R := S;
Process_Range_Expr_In_Decl (R, T, Empty_List);
if not Error_Posted (S)
and then
(Nkind (S) /= N_Range
or else not Covers (T, (Etype (Low_Bound (S))))
or else not Covers (T, (Etype (High_Bound (S)))))
then
if Base_Type (T) /= Any_Type
and then Etype (Low_Bound (S)) /= Any_Type
and then Etype (High_Bound (S)) /= Any_Type
then
Error_Msg_N ("range expected", S);
end if;
end if;
elsif Nkind (S) = N_Subtype_Indication then
-- The parser has verified that this is a discrete indication
Resolve_Discrete_Subtype_Indication (S, T);
R := Range_Expression (Constraint (S));
elsif Nkind (S) = N_Discriminant_Association then
-- Syntactically valid in subtype indication
Error_Msg_N ("invalid index constraint", S);
Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
return;
-- Subtype_Mark case, no anonymous subtypes to construct
else
Analyze (S);
if Is_Entity_Name (S) then
if not Is_Type (Entity (S)) then
Error_Msg_N ("expect subtype mark for index constraint", S);
elsif Base_Type (Entity (S)) /= Base_Type (T) then
Wrong_Type (S, Base_Type (T));
end if;
return;
else
Error_Msg_N ("invalid index constraint", S);
Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
return;
end if;
end if;
Def_Id :=
Create_Itype (E_Void, Related_Nod, Related_Id, Suffix, Suffix_Index);
Set_Etype (Def_Id, Base_Type (T));
if Is_Modular_Integer_Type (T) then
Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
elsif Is_Integer_Type (T) then
Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
else
Set_Ekind (Def_Id, E_Enumeration_Subtype);
Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
end if;
Set_Size_Info (Def_Id, (T));
Set_RM_Size (Def_Id, RM_Size (T));
Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
Set_Scalar_Range (Def_Id, R);
Set_Etype (S, Def_Id);
Set_Discrete_RM_Size (Def_Id);
end Constrain_Index;
-----------------------
-- Constrain_Integer --
-----------------------
procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id) is
T : constant Entity_Id := Entity (Subtype_Mark (S));
C : constant Node_Id := Constraint (S);
begin
Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
if Is_Modular_Integer_Type (T) then
Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
else
Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
end if;
Set_Etype (Def_Id, Base_Type (T));
Set_Size_Info (Def_Id, (T));
Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
Set_Discrete_RM_Size (Def_Id);
end Constrain_Integer;
------------------------------
-- Constrain_Ordinary_Fixed --
------------------------------
procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id) is
T : constant Entity_Id := Entity (Subtype_Mark (S));
C : Node_Id;
D : Node_Id;
Rais : Node_Id;
begin
Set_Ekind (Def_Id, E_Ordinary_Fixed_Point_Subtype);
Set_Etype (Def_Id, Base_Type (T));
Set_Size_Info (Def_Id, (T));
Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
Set_Small_Value (Def_Id, Small_Value (T));
-- Process the constraint
C := Constraint (S);
-- Delta constraint present
if Nkind (C) = N_Delta_Constraint then
Check_Restriction (No_Obsolescent_Features, C);
if Warn_On_Obsolescent_Feature then
Error_Msg_S
("subtype delta constraint is an " &
"obsolescent feature ('R'M 'J.3(7))?");
end if;
D := Delta_Expression (C);
Analyze_And_Resolve (D, Any_Real);
Check_Delta_Expression (D);
Set_Delta_Value (Def_Id, Expr_Value_R (D));
-- Check that delta value is in range. Obviously we can do this
-- at compile time, but it is strictly a runtime check, and of
-- course there is an ACVC test that checks this!
if Delta_Value (Def_Id) < Delta_Value (T) then
Error_Msg_N ("?delta value is too small", D);
Rais :=
Make_Raise_Constraint_Error (Sloc (D),
Reason => CE_Range_Check_Failed);
Insert_Action (Declaration_Node (Def_Id), Rais);
end if;
C := Range_Constraint (C);
-- No delta constraint present
else
Set_Delta_Value (Def_Id, Delta_Value (T));
end if;
-- Range constraint present
if Nkind (C) = N_Range_Constraint then
Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
-- No range constraint present
else
pragma Assert (No (C));
Set_Scalar_Range (Def_Id, Scalar_Range (T));
end if;
Set_Discrete_RM_Size (Def_Id);
-- Unconditionally delay the freeze, since we cannot set size
-- information in all cases correctly until the freeze point.
Set_Has_Delayed_Freeze (Def_Id);
end Constrain_Ordinary_Fixed;
---------------------------
-- Convert_Scalar_Bounds --
---------------------------
procedure Convert_Scalar_Bounds
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id;
Loc : Source_Ptr)
is
Implicit_Base : constant Entity_Id := Base_Type (Derived_Type);
Lo : Node_Id;
Hi : Node_Id;
Rng : Node_Id;
begin
Lo := Build_Scalar_Bound
(Type_Low_Bound (Derived_Type),
Parent_Type, Implicit_Base);
Hi := Build_Scalar_Bound
(Type_High_Bound (Derived_Type),
Parent_Type, Implicit_Base);
Rng :=
Make_Range (Loc,
Low_Bound => Lo,
High_Bound => Hi);
Set_Includes_Infinities (Rng, Has_Infinities (Derived_Type));
Set_Parent (Rng, N);
Set_Scalar_Range (Derived_Type, Rng);
-- Analyze the bounds
Analyze_And_Resolve (Lo, Implicit_Base);
Analyze_And_Resolve (Hi, Implicit_Base);
-- Analyze the range itself, except that we do not analyze it if
-- the bounds are real literals, and we have a fixed-point type.
-- The reason for this is that we delay setting the bounds in this
-- case till we know the final Small and Size values (see circuit
-- in Freeze.Freeze_Fixed_Point_Type for further details).
if Is_Fixed_Point_Type (Parent_Type)
and then Nkind (Lo) = N_Real_Literal
and then Nkind (Hi) = N_Real_Literal
then
return;
-- Here we do the analysis of the range
-- Note: we do this manually, since if we do a normal Analyze and
-- Resolve call, there are problems with the conversions used for
-- the derived type range.
else
Set_Etype (Rng, Implicit_Base);
Set_Analyzed (Rng, True);
end if;
end Convert_Scalar_Bounds;
-------------------
-- Copy_And_Swap --
-------------------
procedure Copy_And_Swap (Priv, Full : Entity_Id) is
begin
-- Initialize new full declaration entity by copying the pertinent
-- fields of the corresponding private declaration entity.
-- We temporarily set Ekind to a value appropriate for a type to
-- avoid assert failures in Einfo from checking for setting type
-- attributes on something that is not a type. Ekind (Priv) is an
-- appropriate choice, since it allowed the attributes to be set
-- in the first place. This Ekind value will be modified later.
Set_Ekind (Full, Ekind (Priv));
-- Also set Etype temporarily to Any_Type, again, in the absence
-- of errors, it will be properly reset, and if there are errors,
-- then we want a value of Any_Type to remain.
Set_Etype (Full, Any_Type);
-- Now start copying attributes
Set_Has_Discriminants (Full, Has_Discriminants (Priv));
if Has_Discriminants (Full) then
Set_Discriminant_Constraint (Full, Discriminant_Constraint (Priv));
Set_Stored_Constraint (Full, Stored_Constraint (Priv));
end if;
Set_First_Rep_Item (Full, First_Rep_Item (Priv));
Set_Homonym (Full, Homonym (Priv));
Set_Is_Immediately_Visible (Full, Is_Immediately_Visible (Priv));
Set_Is_Public (Full, Is_Public (Priv));
Set_Is_Pure (Full, Is_Pure (Priv));
Set_Is_Tagged_Type (Full, Is_Tagged_Type (Priv));
Conditional_Delay (Full, Priv);
if Is_Tagged_Type (Full) then
Set_Primitive_Operations (Full, Primitive_Operations (Priv));
if Priv = Base_Type (Priv) then
Set_Class_Wide_Type (Full, Class_Wide_Type (Priv));
end if;
end if;
Set_Is_Volatile (Full, Is_Volatile (Priv));
Set_Treat_As_Volatile (Full, Treat_As_Volatile (Priv));
Set_Scope (Full, Scope (Priv));
Set_Next_Entity (Full, Next_Entity (Priv));
Set_First_Entity (Full, First_Entity (Priv));
Set_Last_Entity (Full, Last_Entity (Priv));
-- If access types have been recorded for later handling, keep them in
-- the full view so that they get handled when the full view freeze
-- node is expanded.
if Present (Freeze_Node (Priv))
and then Present (Access_Types_To_Process (Freeze_Node (Priv)))
then
Ensure_Freeze_Node (Full);
Set_Access_Types_To_Process
(Freeze_Node (Full),
Access_Types_To_Process (Freeze_Node (Priv)));
end if;
-- Swap the two entities. Now Privat is the full type entity and
-- Full is the private one. They will be swapped back at the end
-- of the private part. This swapping ensures that the entity that
-- is visible in the private part is the full declaration.
Exchange_Entities (Priv, Full);
Append_Entity (Full, Scope (Full));
end Copy_And_Swap;
-------------------------------------
-- Copy_Array_Base_Type_Attributes --
-------------------------------------
procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id) is
begin
Set_Component_Alignment (T1, Component_Alignment (T2));
Set_Component_Type (T1, Component_Type (T2));
Set_Component_Size (T1, Component_Size (T2));
Set_Has_Controlled_Component (T1, Has_Controlled_Component (T2));
Set_Finalize_Storage_Only (T1, Finalize_Storage_Only (T2));
Set_Has_Non_Standard_Rep (T1, Has_Non_Standard_Rep (T2));
Set_Has_Task (T1, Has_Task (T2));
Set_Is_Packed (T1, Is_Packed (T2));
Set_Has_Aliased_Components (T1, Has_Aliased_Components (T2));
Set_Has_Atomic_Components (T1, Has_Atomic_Components (T2));
Set_Has_Volatile_Components (T1, Has_Volatile_Components (T2));
end Copy_Array_Base_Type_Attributes;
-----------------------------------
-- Copy_Array_Subtype_Attributes --
-----------------------------------
procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id) is
begin
Set_Size_Info (T1, T2);
Set_First_Index (T1, First_Index (T2));
Set_Is_Aliased (T1, Is_Aliased (T2));
Set_Is_Atomic (T1, Is_Atomic (T2));
Set_Is_Volatile (T1, Is_Volatile (T2));
Set_Treat_As_Volatile (T1, Treat_As_Volatile (T2));
Set_Is_Constrained (T1, Is_Constrained (T2));
Set_Depends_On_Private (T1, Has_Private_Component (T2));
Set_First_Rep_Item (T1, First_Rep_Item (T2));
Set_Convention (T1, Convention (T2));
Set_Is_Limited_Composite (T1, Is_Limited_Composite (T2));
Set_Is_Private_Composite (T1, Is_Private_Composite (T2));
end Copy_Array_Subtype_Attributes;
-----------------------------------
-- Create_Constrained_Components --
-----------------------------------
procedure Create_Constrained_Components
(Subt : Entity_Id;
Decl_Node : Node_Id;
Typ : Entity_Id;
Constraints : Elist_Id)
is
Loc : constant Source_Ptr := Sloc (Subt);
Comp_List : constant Elist_Id := New_Elmt_List;
Parent_Type : constant Entity_Id := Etype (Typ);
Assoc_List : constant List_Id := New_List;
Discr_Val : Elmt_Id;
Errors : Boolean;
New_C : Entity_Id;
Old_C : Entity_Id;
Is_Static : Boolean := True;
procedure Collect_Fixed_Components (Typ : Entity_Id);
-- Collect parent type components that do not appear in a variant part
procedure Create_All_Components;
-- Iterate over Comp_List to create the components of the subtype
function Create_Component (Old_Compon : Entity_Id) return Entity_Id;
-- Creates a new component from Old_Compon, copying all the fields from
-- it, including its Etype, inserts the new component in the Subt entity
-- chain and returns the new component.
function Is_Variant_Record (T : Entity_Id) return Boolean;
-- If true, and discriminants are static, collect only components from
-- variants selected by discriminant values.
------------------------------
-- Collect_Fixed_Components --
------------------------------
procedure Collect_Fixed_Components (Typ : Entity_Id) is
begin
-- Build association list for discriminants, and find components of the
-- variant part selected by the values of the discriminants.
Old_C := First_Discriminant (Typ);
Discr_Val := First_Elmt (Constraints);
while Present (Old_C) loop
Append_To (Assoc_List,
Make_Component_Association (Loc,
Choices => New_List (New_Occurrence_Of (Old_C, Loc)),
Expression => New_Copy (Node (Discr_Val))));
Next_Elmt (Discr_Val);
Next_Discriminant (Old_C);
end loop;
-- The tag, and the possible parent and controller components
-- are unconditionally in the subtype.
if Is_Tagged_Type (Typ)
or else Has_Controlled_Component (Typ)
then
Old_C := First_Component (Typ);
while Present (Old_C) loop
if Chars ((Old_C)) = Name_uTag
or else Chars ((Old_C)) = Name_uParent
or else Chars ((Old_C)) = Name_uController
then
Append_Elmt (Old_C, Comp_List);
end if;
Next_Component (Old_C);
end loop;
end if;
end Collect_Fixed_Components;
---------------------------
-- Create_All_Components --
---------------------------
procedure Create_All_Components is
Comp : Elmt_Id;
begin
Comp := First_Elmt (Comp_List);
while Present (Comp) loop
Old_C := Node (Comp);
New_C := Create_Component (Old_C);
Set_Etype
(New_C,
Constrain_Component_Type
(Old_C, Subt, Decl_Node, Typ, Constraints));
Set_Is_Public (New_C, Is_Public (Subt));
Next_Elmt (Comp);
end loop;
end Create_All_Components;
----------------------
-- Create_Component --
----------------------
function Create_Component (Old_Compon : Entity_Id) return Entity_Id is
New_Compon : constant Entity_Id := New_Copy (Old_Compon);
begin
if Ekind (Old_Compon) = E_Discriminant
and then Is_Completely_Hidden (Old_Compon)
then
-- This is a shadow discriminant created for a discriminant of
-- the parent type that is one of several renamed by the same
-- new discriminant. Give the shadow discriminant an internal
-- name that cannot conflict with that of visible components.
Set_Chars (New_Compon, New_Internal_Name ('C'));
end if;
-- Set the parent so we have a proper link for freezing etc. This is
-- not a real parent pointer, since of course our parent does not own
-- up to us and reference us, we are an illegitimate child of the
-- original parent!
Set_Parent (New_Compon, Parent (Old_Compon));
-- If the old component's Esize was already determined and is a
-- static value, then the new component simply inherits it. Otherwise
-- the old component's size may require run-time determination, but
-- the new component's size still might be statically determinable
-- (if, for example it has a static constraint). In that case we want
-- Layout_Type to recompute the component's size, so we reset its
-- size and positional fields.
if Frontend_Layout_On_Target
and then not Known_Static_Esize (Old_Compon)
then
Set_Esize (New_Compon, Uint_0);
Init_Normalized_First_Bit (New_Compon);
Init_Normalized_Position (New_Compon);
Init_Normalized_Position_Max (New_Compon);
end if;
-- We do not want this node marked as Comes_From_Source, since
-- otherwise it would get first class status and a separate cross-
-- reference line would be generated. Illegitimate children do not
-- rate such recognition.
Set_Comes_From_Source (New_Compon, False);
-- But it is a real entity, and a birth certificate must be properly
-- registered by entering it into the entity list.
Enter_Name (New_Compon);
return New_Compon;
end Create_Component;
-----------------------
-- Is_Variant_Record --
-----------------------
function Is_Variant_Record (T : Entity_Id) return Boolean is
begin
return Nkind (Parent (T)) = N_Full_Type_Declaration
and then Nkind (Type_Definition (Parent (T))) = N_Record_Definition
and then Present (Component_List (Type_Definition (Parent (T))))
and then Present (
Variant_Part (Component_List (Type_Definition (Parent (T)))));
end Is_Variant_Record;
-- Start of processing for Create_Constrained_Components
begin
pragma Assert (Subt /= Base_Type (Subt));
pragma Assert (Typ = Base_Type (Typ));
Set_First_Entity (Subt, Empty);
Set_Last_Entity (Subt, Empty);
-- Check whether constraint is fully static, in which case we can
-- optimize the list of components.
Discr_Val := First_Elmt (Constraints);
while Present (Discr_Val) loop
if not Is_OK_Static_Expression (Node (Discr_Val)) then
Is_Static := False;
exit;
end if;
Next_Elmt (Discr_Val);
end loop;
New_Scope (Subt);
-- Inherit the discriminants of the parent type
Add_Discriminants : declare
Num_Disc : Int;
Num_Gird : Int;
begin
Num_Disc := 0;
Old_C := First_Discriminant (Typ);
while Present (Old_C) loop
Num_Disc := Num_Disc + 1;
New_C := Create_Component (Old_C);
Set_Is_Public (New_C, Is_Public (Subt));
Next_Discriminant (Old_C);
end loop;
-- For an untagged derived subtype, the number of discriminants may
-- be smaller than the number of inherited discriminants, because
-- several of them may be renamed by a single new discriminant.
-- In this case, add the hidden discriminants back into the subtype,
-- because otherwise the size of the subtype is computed incorrectly
-- in GCC 4.1.
Num_Gird := 0;
if Is_Derived_Type (Typ)
and then not Is_Tagged_Type (Typ)
then
Old_C := First_Stored_Discriminant (Typ);
while Present (Old_C) loop
Num_Gird := Num_Gird + 1;
Next_Stored_Discriminant (Old_C);
end loop;
end if;
if Num_Gird > Num_Disc then
-- Find out multiple uses of new discriminants, and add hidden
-- components for the extra renamed discriminants. We recognize
-- multiple uses through the Corresponding_Discriminant of a
-- new discriminant: if it constrains several old discriminants,
-- this field points to the last one in the parent type. The
-- stored discriminants of the derived type have the same name
-- as those of the parent.
declare
Constr : Elmt_Id;
New_Discr : Entity_Id;
Old_Discr : Entity_Id;
begin
Constr := First_Elmt (Stored_Constraint (Typ));
Old_Discr := First_Stored_Discriminant (Typ);
while Present (Constr) loop
if Is_Entity_Name (Node (Constr))
and then Ekind (Entity (Node (Constr))) = E_Discriminant
then
New_Discr := Entity (Node (Constr));
if Chars (Corresponding_Discriminant (New_Discr))
/= Chars (Old_Discr)
then
-- The new discriminant has been used to rename
-- a subsequent old discriminant. Introduce a shadow
-- component for the current old discriminant.
New_C := Create_Component (Old_Discr);
Set_Original_Record_Component (New_C, Old_Discr);
end if;
end if;
Next_Elmt (Constr);
Next_Stored_Discriminant (Old_Discr);
end loop;
end;
end if;
end Add_Discriminants;
if Is_Static
and then Is_Variant_Record (Typ)
then
Collect_Fixed_Components (Typ);
Gather_Components (
Typ,
Component_List (Type_Definition (Parent (Typ))),
Governed_By => Assoc_List,
Into => Comp_List,
Report_Errors => Errors);
pragma Assert (not Errors);
Create_All_Components;
-- If the subtype declaration is created for a tagged type derivation
-- with constraints, we retrieve the record definition of the parent
-- type to select the components of the proper variant.
elsif Is_Static
and then Is_Tagged_Type (Typ)
and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
and then
Nkind (Type_Definition (Parent (Typ))) = N_Derived_Type_Definition
and then Is_Variant_Record (Parent_Type)
then
Collect_Fixed_Components (Typ);
Gather_Components (
Typ,
Component_List (Type_Definition (Parent (Parent_Type))),
Governed_By => Assoc_List,
Into => Comp_List,
Report_Errors => Errors);
pragma Assert (not Errors);
-- If the tagged derivation has a type extension, collect all the
-- new components therein.
if Present
(Record_Extension_Part (Type_Definition (Parent (Typ))))
then
Old_C := First_Component (Typ);
while Present (Old_C) loop
if Original_Record_Component (Old_C) = Old_C
and then Chars (Old_C) /= Name_uTag
and then Chars (Old_C) /= Name_uParent
and then Chars (Old_C) /= Name_uController
then
Append_Elmt (Old_C, Comp_List);
end if;
Next_Component (Old_C);
end loop;
end if;
Create_All_Components;
else
-- If discriminants are not static, or if this is a multi-level type
-- extension, we have to include all components of the parent type.
Old_C := First_Component (Typ);
while Present (Old_C) loop
New_C := Create_Component (Old_C);
Set_Etype
(New_C,
Constrain_Component_Type
(Old_C, Subt, Decl_Node, Typ, Constraints));
Set_Is_Public (New_C, Is_Public (Subt));
Next_Component (Old_C);
end loop;
end if;
End_Scope;
end Create_Constrained_Components;
------------------------------------------
-- Decimal_Fixed_Point_Type_Declaration --
------------------------------------------
procedure Decimal_Fixed_Point_Type_Declaration
(T : Entity_Id;
Def : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Def);
Digs_Expr : constant Node_Id := Digits_Expression (Def);
Delta_Expr : constant Node_Id := Delta_Expression (Def);
Implicit_Base : Entity_Id;
Digs_Val : Uint;
Delta_Val : Ureal;
Scale_Val : Uint;
Bound_Val : Ureal;
-- Start of processing for Decimal_Fixed_Point_Type_Declaration
begin
Check_Restriction (No_Fixed_Point, Def);
-- Create implicit base type
Implicit_Base :=
Create_Itype (E_Decimal_Fixed_Point_Type, Parent (Def), T, 'B');
Set_Etype (Implicit_Base, Implicit_Base);
-- Analyze and process delta expression
Analyze_And_Resolve (Delta_Expr, Universal_Real);
Check_Delta_Expression (Delta_Expr);
Delta_Val := Expr_Value_R (Delta_Expr);
-- Check delta is power of 10, and determine scale value from it
declare
Val : Ureal;
begin
Scale_Val := Uint_0;
Val := Delta_Val;
if Val < Ureal_1 then
while Val < Ureal_1 loop
Val := Val * Ureal_10;
Scale_Val := Scale_Val + 1;
end loop;
if Scale_Val > 18 then
Error_Msg_N ("scale exceeds maximum value of 18", Def);
Scale_Val := UI_From_Int (+18);
end if;
else
while Val > Ureal_1 loop
Val := Val / Ureal_10;
Scale_Val := Scale_Val - 1;
end loop;
if Scale_Val < -18 then
Error_Msg_N ("scale is less than minimum value of -18", Def);
Scale_Val := UI_From_Int (-18);
end if;
end if;
if Val /= Ureal_1 then
Error_Msg_N ("delta expression must be a power of 10", Def);
Delta_Val := Ureal_10 ** (-Scale_Val);
end if;
end;
-- Set delta, scale and small (small = delta for decimal type)
Set_Delta_Value (Implicit_Base, Delta_Val);
Set_Scale_Value (Implicit_Base, Scale_Val);
Set_Small_Value (Implicit_Base, Delta_Val);
-- Analyze and process digits expression
Analyze_And_Resolve (Digs_Expr, Any_Integer);
Check_Digits_Expression (Digs_Expr);
Digs_Val := Expr_Value (Digs_Expr);
if Digs_Val > 18 then
Digs_Val := UI_From_Int (+18);
Error_Msg_N ("digits value out of range, maximum is 18", Digs_Expr);
end if;
Set_Digits_Value (Implicit_Base, Digs_Val);
Bound_Val := UR_From_Uint (10 ** Digs_Val - 1) * Delta_Val;
-- Set range of base type from digits value for now. This will be
-- expanded to represent the true underlying base range by Freeze.
Set_Fixed_Range (Implicit_Base, Loc, -Bound_Val, Bound_Val);
-- Set size to zero for now, size will be set at freeze time. We have
-- to do this for ordinary fixed-point, because the size depends on
-- the specified small, and we might as well do the same for decimal
-- fixed-point.
Init_Size_Align (Implicit_Base);
-- If there are bounds given in the declaration use them as the
-- bounds of the first named subtype.
if Present (Real_Range_Specification (Def)) then
declare
RRS : constant Node_Id := Real_Range_Specification (Def);
Low : constant Node_Id := Low_Bound (RRS);
High : constant Node_Id := High_Bound (RRS);
Low_Val : Ureal;
High_Val : Ureal;
begin
Analyze_And_Resolve (Low, Any_Real);
Analyze_And_Resolve (High, Any_Real);
Check_Real_Bound (Low);
Check_Real_Bound (High);
Low_Val := Expr_Value_R (Low);
High_Val := Expr_Value_R (High);
if Low_Val < (-Bound_Val) then
Error_Msg_N
("range low bound too small for digits value", Low);
Low_Val := -Bound_Val;
end if;
if High_Val > Bound_Val then
Error_Msg_N
("range high bound too large for digits value", High);
High_Val := Bound_Val;
end if;
Set_Fixed_Range (T, Loc, Low_Val, High_Val);
end;
-- If no explicit range, use range that corresponds to given
-- digits value. This will end up as the final range for the
-- first subtype.
else
Set_Fixed_Range (T, Loc, -Bound_Val, Bound_Val);
end if;
-- Complete entity for first subtype
Set_Ekind (T, E_Decimal_Fixed_Point_Subtype);
Set_Etype (T, Implicit_Base);
Set_Size_Info (T, Implicit_Base);
Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
Set_Digits_Value (T, Digs_Val);
Set_Delta_Value (T, Delta_Val);
Set_Small_Value (T, Delta_Val);
Set_Scale_Value (T, Scale_Val);
Set_Is_Constrained (T);
end Decimal_Fixed_Point_Type_Declaration;
---------------------------------
-- Derive_Interface_Subprogram --
---------------------------------
procedure Derive_Interface_Subprograms (Derived_Type : Entity_Id) is
procedure Do_Derivation (T : Entity_Id);
-- This inner subprograms is used to climb to the ancestors.
-- It is needed to add the derivations to the Derived_Type.
procedure Do_Derivation (T : Entity_Id) is
Etyp : constant Entity_Id := Etype (T);
AI : Elmt_Id;
begin
if Etyp /= T
and then Is_Interface (Etyp)
then
Do_Derivation (Etyp);
end if;
if Present (Abstract_Interfaces (T))
and then not Is_Empty_Elmt_List (Abstract_Interfaces (T))
then
AI := First_Elmt (Abstract_Interfaces (T));
while Present (AI) loop
if not Is_Ancestor (Node (AI), Derived_Type) then
Derive_Subprograms
(Parent_Type => Node (AI),
Derived_Type => Derived_Type,
No_Predefined_Prims => True);
end if;
Next_Elmt (AI);
end loop;
end if;
end Do_Derivation;
begin
Do_Derivation (Derived_Type);
-- At this point the list of primitive operations of Derived_Type
-- contains the entities corresponding to all the subprograms of all the
-- implemented interfaces. If N interfaces have subprograms with the
-- same profile we have N entities in this list because each one must be
-- allocated in its corresponding virtual table.
-- Its alias attribute references its original interface subprogram.
-- When overridden, the alias attribute is later saved in the
-- Abstract_Interface_Alias attribute.
end Derive_Interface_Subprograms;
-----------------------
-- Derive_Subprogram --
-----------------------
procedure Derive_Subprogram
(New_Subp : in out Entity_Id;
Parent_Subp : Entity_Id;
Derived_Type : Entity_Id;
Parent_Type : Entity_Id;
Actual_Subp : Entity_Id := Empty)
is
Formal : Entity_Id;
New_Formal : Entity_Id;
Visible_Subp : Entity_Id := Parent_Subp;
function Is_Private_Overriding return Boolean;
-- If Subp is a private overriding of a visible operation, the in-
-- herited operation derives from the overridden op (even though
-- its body is the overriding one) and the inherited operation is
-- visible now. See sem_disp to see the details of the handling of
-- the overridden subprogram, which is removed from the list of
-- primitive operations of the type. The overridden subprogram is
-- saved locally in Visible_Subp, and used to diagnose abstract
-- operations that need overriding in the derived type.
procedure Replace_Type (Id, New_Id : Entity_Id);
-- When the type is an anonymous access type, create a new access type
-- designating the derived type.
procedure Set_Derived_Name;
-- This procedure sets the appropriate Chars name for New_Subp. This
-- is normally just a copy of the parent name. An exception arises for
-- type support subprograms, where the name is changed to reflect the
-- name of the derived type, e.g. if type foo is derived from type bar,
-- then a procedure barDA is derived with a name fooDA.
---------------------------
-- Is_Private_Overriding --
---------------------------
function Is_Private_Overriding return Boolean is
Prev : Entity_Id;
begin
-- The visible operation that is overridden is a homonym of the
-- parent subprogram. We scan the homonym chain to find the one
-- whose alias is the subprogram we are deriving.
Prev := Current_Entity (Parent_Subp);
while Present (Prev) loop
if Is_Dispatching_Operation (Parent_Subp)
and then Present (Prev)
and then Ekind (Prev) = Ekind (Parent_Subp)
and then Alias (Prev) = Parent_Subp
and then Scope (Parent_Subp) = Scope (Prev)
and then
(not Is_Hidden (Prev)
or else
-- Ada 2005 (AI-251): Entities associated with overridden
-- interface subprograms are always marked as hidden; in
-- this case the field abstract_interface_alias references
-- the original entity (cf. override_dispatching_operation).
(Atree.Present (Abstract_Interface_Alias (Prev))
and then not Is_Hidden (Abstract_Interface_Alias (Prev))))
then
Visible_Subp := Prev;
return True;
end if;
Prev := Homonym (Prev);
end loop;
return False;
end Is_Private_Overriding;
------------------
-- Replace_Type --
------------------
procedure Replace_Type (Id, New_Id : Entity_Id) is
Acc_Type : Entity_Id;
IR : Node_Id;
Par : constant Node_Id := Parent (Derived_Type);
begin
-- When the type is an anonymous access type, create a new access
-- type designating the derived type. This itype must be elaborated
-- at the point of the derivation, not on subsequent calls that may
-- be out of the proper scope for Gigi, so we insert a reference to
-- it after the derivation.
if Ekind (Etype (Id)) = E_Anonymous_Access_Type then
declare
Desig_Typ : Entity_Id := Designated_Type (Etype (Id));
begin
if Ekind (Desig_Typ) = E_Record_Type_With_Private
and then Present (Full_View (Desig_Typ))
and then not Is_Private_Type (Parent_Type)
then
Desig_Typ := Full_View (Desig_Typ);
end if;
if Base_Type (Desig_Typ) = Base_Type (Parent_Type) then
Acc_Type := New_Copy (Etype (Id));
Set_Etype (Acc_Type, Acc_Type);
Set_Scope (Acc_Type, New_Subp);
-- Compute size of anonymous access type
if Is_Array_Type (Desig_Typ)
and then not Is_Constrained (Desig_Typ)
then
Init_Size (Acc_Type, 2 * System_Address_Size);
else
Init_Size (Acc_Type, System_Address_Size);
end if;
Init_Alignment (Acc_Type);
Set_Directly_Designated_Type (Acc_Type, Derived_Type);
Set_Etype (New_Id, Acc_Type);
Set_Scope (New_Id, New_Subp);
-- Create a reference to it
IR := Make_Itype_Reference (Sloc (Parent (Derived_Type)));
Set_Itype (IR, Acc_Type);
Insert_After (Parent (Derived_Type), IR);
else
Set_Etype (New_Id, Etype (Id));
end if;
end;
elsif Base_Type (Etype (Id)) = Base_Type (Parent_Type)
or else
(Ekind (Etype (Id)) = E_Record_Type_With_Private
and then Present (Full_View (Etype (Id)))
and then
Base_Type (Full_View (Etype (Id))) = Base_Type (Parent_Type))
then
-- Constraint checks on formals are generated during expansion,
-- based on the signature of the original subprogram. The bounds
-- of the derived type are not relevant, and thus we can use
-- the base type for the formals. However, the return type may be
-- used in a context that requires that the proper static bounds
-- be used (a case statement, for example) and for those cases
-- we must use the derived type (first subtype), not its base.
-- If the derived_type_definition has no constraints, we know that
-- the derived type has the same constraints as the first subtype
-- of the parent, and we can also use it rather than its base,
-- which can lead to more efficient code.
if Etype (Id) = Parent_Type then
if Is_Scalar_Type (Parent_Type)
and then
Subtypes_Statically_Compatible (Parent_Type, Derived_Type)
then
Set_Etype (New_Id, Derived_Type);
elsif Nkind (Par) = N_Full_Type_Declaration
and then
Nkind (Type_Definition (Par)) = N_Derived_Type_Definition
and then
Is_Entity_Name
(Subtype_Indication (Type_Definition (Par)))
then
Set_Etype (New_Id, Derived_Type);
else
Set_Etype (New_Id, Base_Type (Derived_Type));
end if;
else
Set_Etype (New_Id, Base_Type (Derived_Type));
end if;
else
Set_Etype (New_Id, Etype (Id));
end if;
end Replace_Type;
----------------------
-- Set_Derived_Name --
----------------------
procedure Set_Derived_Name is
Nm : constant TSS_Name_Type := Get_TSS_Name (Parent_Subp);
begin
if Nm = TSS_Null then
Set_Chars (New_Subp, Chars (Parent_Subp));
else
Set_Chars (New_Subp, Make_TSS_Name (Base_Type (Derived_Type), Nm));
end if;
end Set_Derived_Name;
-- Start of processing for Derive_Subprogram
begin
New_Subp :=
New_Entity (Nkind (Parent_Subp), Sloc (Derived_Type));
Set_Ekind (New_Subp, Ekind (Parent_Subp));
-- Check whether the inherited subprogram is a private operation that
-- should be inherited but not yet made visible. Such subprograms can
-- become visible at a later point (e.g., the private part of a public
-- child unit) via Declare_Inherited_Private_Subprograms. If the
-- following predicate is true, then this is not such a private
-- operation and the subprogram simply inherits the name of the parent
-- subprogram. Note the special check for the names of controlled
-- operations, which are currently exempted from being inherited with
-- a hidden name because they must be findable for generation of
-- implicit run-time calls.
if not Is_Hidden (Parent_Subp)
or else Is_Internal (Parent_Subp)
or else Is_Private_Overriding
or else Is_Internal_Name (Chars (Parent_Subp))
or else Chars (Parent_Subp) = Name_Initialize
or else Chars (Parent_Subp) = Name_Adjust
or else Chars (Parent_Subp) = Name_Finalize
then
Set_Derived_Name;
-- If parent is hidden, this can be a regular derivation if the
-- parent is immediately visible in a non-instantiating context,
-- or if we are in the private part of an instance. This test
-- should still be refined ???
-- The test for In_Instance_Not_Visible avoids inheriting the derived
-- operation as a non-visible operation in cases where the parent
-- subprogram might not be visible now, but was visible within the
-- original generic, so it would be wrong to make the inherited
-- subprogram non-visible now. (Not clear if this test is fully
-- correct; are there any cases where we should declare the inherited
-- operation as not visible to avoid it being overridden, e.g., when
-- the parent type is a generic actual with private primitives ???)
-- (they should be treated the same as other private inherited
-- subprograms, but it's not clear how to do this cleanly). ???
elsif (In_Open_Scopes (Scope (Base_Type (Parent_Type)))
and then Is_Immediately_Visible (Parent_Subp)
and then not In_Instance)
or else In_Instance_Not_Visible
then
Set_Derived_Name;
-- The type is inheriting a private operation, so enter
-- it with a special name so it can't be overridden.
else
Set_Chars (New_Subp, New_External_Name (Chars (Parent_Subp), 'P'));
end if;
Set_Parent (New_Subp, Parent (Derived_Type));
Replace_Type (Parent_Subp, New_Subp);
Conditional_Delay (New_Subp, Parent_Subp);
Formal := First_Formal (Parent_Subp);
while Present (Formal) loop
New_Formal := New_Copy (Formal);
-- Normally we do not go copying parents, but in the case of
-- formals, we need to link up to the declaration (which is the
-- parameter specification), and it is fine to link up to the
-- original formal's parameter specification in this case.
Set_Parent (New_Formal, Parent (Formal));
Append_Entity (New_Formal, New_Subp);
Replace_Type (Formal, New_Formal);
Next_Formal (Formal);
end loop;
-- If this derivation corresponds to a tagged generic actual, then
-- primitive operations rename those of the actual. Otherwise the
-- primitive operations rename those of the parent type, If the
-- parent renames an intrinsic operator, so does the new subprogram.
-- We except concatenation, which is always properly typed, and does
-- not get expanded as other intrinsic operations.
if No (Actual_Subp) then
if Is_Intrinsic_Subprogram (Parent_Subp) then
Set_Is_Intrinsic_Subprogram (New_Subp);
if Present (Alias (Parent_Subp))
and then Chars (Parent_Subp) /= Name_Op_Concat
then
Set_Alias (New_Subp, Alias (Parent_Subp));
else
Set_Alias (New_Subp, Parent_Subp);
end if;
else
Set_Alias (New_Subp, Parent_Subp);
end if;
else
Set_Alias (New_Subp, Actual_Subp);
end if;
-- Derived subprograms of a tagged type must inherit the convention
-- of the parent subprogram (a requirement of AI-117). Derived
-- subprograms of untagged types simply get convention Ada by default.
if Is_Tagged_Type (Derived_Type) then
Set_Convention (New_Subp, Convention (Parent_Subp));
end if;
Set_Is_Imported (New_Subp, Is_Imported (Parent_Subp));
Set_Is_Exported (New_Subp, Is_Exported (Parent_Subp));
if Ekind (Parent_Subp) = E_Procedure then
Set_Is_Valued_Procedure
(New_Subp, Is_Valued_Procedure (Parent_Subp));
end if;
-- No_Return must be inherited properly. If this is overridden in the
-- case of a dispatching operation, then a check is made in Sem_Disp
-- that the overriding operation is also No_Return (no such check is
-- required for the case of non-dispatching operation.
Set_No_Return (New_Subp, No_Return (Parent_Subp));
-- A derived function with a controlling result is abstract. If the
-- Derived_Type is a nonabstract formal generic derived type, then
-- inherited operations are not abstract: the required check is done at
-- instantiation time. If the derivation is for a generic actual, the
-- function is not abstract unless the actual is.
if Is_Generic_Type (Derived_Type)
and then not Is_Abstract (Derived_Type)
then
null;
elsif Is_Abstract (Alias (New_Subp))
or else (Is_Tagged_Type (Derived_Type)
and then Etype (New_Subp) = Derived_Type
and then No (Actual_Subp))
then
Set_Is_Abstract (New_Subp);
-- Finally, if the parent type is abstract we must verify that all
-- inherited operations are either non-abstract or overridden, or
-- that the derived type itself is abstract (this check is performed
-- at the end of a package declaration, in Check_Abstract_Overriding).
-- A private overriding in the parent type will not be visible in the
-- derivation if we are not in an inner package or in a child unit of
-- the parent type, in which case the abstractness of the inherited
-- operation is carried to the new subprogram.
elsif Is_Abstract (Parent_Type)
and then not In_Open_Scopes (Scope (Parent_Type))
and then Is_Private_Overriding
and then Is_Abstract (Visible_Subp)
then
Set_Alias (New_Subp, Visible_Subp);
Set_Is_Abstract (New_Subp);
end if;
New_Overloaded_Entity (New_Subp, Derived_Type);
-- Check for case of a derived subprogram for the instantiation of a
-- formal derived tagged type, if so mark the subprogram as dispatching
-- and inherit the dispatching attributes of the parent subprogram. The
-- derived subprogram is effectively renaming of the actual subprogram,
-- so it needs to have the same attributes as the actual.
if Present (Actual_Subp)
and then Is_Dispatching_Operation (Parent_Subp)
then
Set_Is_Dispatching_Operation (New_Subp);
if Present (DTC_Entity (Parent_Subp)) then
Set_DTC_Entity (New_Subp, DTC_Entity (Parent_Subp));
Set_DT_Position (New_Subp, DT_Position (Parent_Subp));
end if;
end if;
-- Indicate that a derived subprogram does not require a body and that
-- it does not require processing of default expressions.
Set_Has_Completion (New_Subp);
Set_Default_Expressions_Processed (New_Subp);
if Ekind (New_Subp) = E_Function then
Set_Mechanism (New_Subp, Mechanism (Parent_Subp));
end if;
end Derive_Subprogram;
------------------------
-- Derive_Subprograms --
------------------------
procedure Derive_Subprograms
(Parent_Type : Entity_Id;
Derived_Type : Entity_Id;
Generic_Actual : Entity_Id := Empty;
No_Predefined_Prims : Boolean := False)
is
Op_List : constant Elist_Id :=
Collect_Primitive_Operations (Parent_Type);
Act_List : Elist_Id;
Act_Elmt : Elmt_Id;
Elmt : Elmt_Id;
Is_Predef : Boolean;
Subp : Entity_Id;
New_Subp : Entity_Id := Empty;
Parent_Base : Entity_Id;
begin
if Ekind (Parent_Type) = E_Record_Type_With_Private
and then Has_Discriminants (Parent_Type)
and then Present (Full_View (Parent_Type))
then
Parent_Base := Full_View (Parent_Type);
else
Parent_Base := Parent_Type;
end if;
if Present (Generic_Actual) then
Act_List := Collect_Primitive_Operations (Generic_Actual);
Act_Elmt := First_Elmt (Act_List);
else
Act_Elmt := No_Elmt;
end if;
-- Literals are derived earlier in the process of building the derived
-- type, and are skipped here.
Elmt := First_Elmt (Op_List);
while Present (Elmt) loop
Subp := Node (Elmt);
if Ekind (Subp) /= E_Enumeration_Literal then
Is_Predef :=
Is_Dispatching_Operation (Subp)
and then Is_Predefined_Dispatching_Operation (Subp);
if No_Predefined_Prims and then Is_Predef then
null;
-- We don't need to derive alias entities associated with
-- abstract interfaces
elsif Is_Dispatching_Operation (Subp)
and then Present (Alias (Subp))
and then Present (Abstract_Interface_Alias (Subp))
then
null;
elsif No (Generic_Actual) then
Derive_Subprogram
(New_Subp, Subp, Derived_Type, Parent_Base);
else
Derive_Subprogram (New_Subp, Subp,
Derived_Type, Parent_Base, Node (Act_Elmt));
Next_Elmt (Act_Elmt);
end if;
end if;
Next_Elmt (Elmt);
end loop;
end Derive_Subprograms;
--------------------------------
-- Derived_Standard_Character --
--------------------------------
procedure Derived_Standard_Character
(N : Node_Id;
Parent_Type : Entity_Id;
Derived_Type : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Def : constant Node_Id := Type_Definition (N);
Indic : constant Node_Id := Subtype_Indication (Def);
Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
Implicit_Base : constant Entity_Id :=
Create_Itype
(E_Enumeration_Type, N, Derived_Type, 'B');
Lo : Node_Id;
Hi : Node_Id;
begin
Discard_Node (Process_Subtype (Indic, N));
Set_Etype (Implicit_Base, Parent_Base);
Set_Size_Info (Implicit_Base, Root_Type (Parent_Type));
Set_RM_Size (Implicit_Base, RM_Size (Root_Type (Parent_Type)));
Set_Is_Character_Type (Implicit_Base, True);
Set_Has_Delayed_Freeze (Implicit_Base);
-- The bounds of the implicit base are the bounds of the parent base.
-- Note that their type is the parent base.
Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
Set_Scalar_Range (Implicit_Base,
Make_Range (Loc,
Low_Bound => Lo,
High_Bound => Hi));
Conditional_Delay (Derived_Type, Parent_Type);
Set_Ekind (Derived_Type, E_Enumeration_Subtype);
Set_Etype (Derived_Type, Implicit_Base);
Set_Size_Info (Derived_Type, Parent_Type);
if Unknown_RM_Size (Derived_Type) then
Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
end if;
Set_Is_Character_Type (Derived_Type, True);
if Nkind (Indic) /= N_Subtype_Indication then
-- If no explicit constraint, the bounds are those
-- of the parent type.
Lo := New_Copy_Tree (Type_Low_Bound (Parent_Type));
Hi := New_Copy_Tree (Type_High_Bound (Parent_Type));
Set_Scalar_Range (Derived_Type, Make_Range (Loc, Lo, Hi));
end if;
Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
-- Because the implicit base is used in the conversion of the bounds,
-- we have to freeze it now. This is similar to what is done for
-- numeric types, and it equally suspicious, but otherwise a non-
-- static bound will have a reference to an unfrozen type, which is
-- rejected by Gigi (???).
Freeze_Before (N, Implicit_Base);
end Derived_Standard_Character;
------------------------------
-- Derived_Type_Declaration --
------------------------------
procedure Derived_Type_Declaration
(T : Entity_Id;
N : Node_Id;
Is_Completion : Boolean)
is
Def : constant Node_Id := Type_Definition (N);
Iface_Def : Node_Id;
Indic : constant Node_Id := Subtype_Indication (Def);
Extension : constant Node_Id := Record_Extension_Part (Def);
Parent_Type : Entity_Id;
Parent_Scope : Entity_Id;
Taggd : Boolean;
function Comes_From_Generic (Typ : Entity_Id) return Boolean;
-- Check whether the parent type is a generic formal, or derives
-- directly or indirectly from one.
------------------------
-- Comes_From_Generic --
------------------------
function Comes_From_Generic (Typ : Entity_Id) return Boolean is
begin
if Is_Generic_Type (Typ) then
return True;
elsif Is_Generic_Type (Root_Type (Parent_Type)) then
return True;
elsif Is_Private_Type (Typ)
and then Present (Full_View (Typ))
and then Is_Generic_Type (Root_Type (Full_View (Typ)))
then
return True;
elsif Is_Generic_Actual_Type (Typ) then
return True;
else
return False;
end if;
end Comes_From_Generic;
-- Start of processing for Derived_Type_Declaration
begin
Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
-- Ada 2005 (AI-251): In case of interface derivation check that the
-- parent is also an interface.
if Interface_Present (Def) then
if not Is_Interface (Parent_Type) then
Error_Msg_NE ("(Ada 2005) & must be an interface",
Indic, Parent_Type);
else
Iface_Def := Type_Definition (Parent (Parent_Type));
-- Ada 2005 (AI-251): Limited interfaces can only inherit from
-- other limited interfaces.
if Limited_Present (Def) then
if Limited_Present (Iface_Def) then
null;
elsif Protected_Present (Iface_Def) then
Error_Msg_N ("(Ada 2005) limited interface cannot" &
" inherit from protected interface", Indic);
elsif Synchronized_Present (Iface_Def) then
Error_Msg_N ("(Ada 2005) limited interface cannot" &
" inherit from synchronized interface", Indic);
elsif Task_Present (Iface_Def) then
Error_Msg_N ("(Ada 2005) limited interface cannot" &
" inherit from task interface", Indic);
else
Error_Msg_N ("(Ada 2005) limited interface cannot" &
" inherit from non-limited interface", Indic);
end if;
-- Ada 2005 (AI-345): Non-limited interfaces can only inherit
-- from non-limited or limited interfaces.
elsif not Protected_Present (Def)
and then not Synchronized_Present (Def)
and then not Task_Present (Def)
then
if Limited_Present (Iface_Def) then
null;
elsif Protected_Present (Iface_Def) then
Error_Msg_N ("(Ada 2005) non-limited interface cannot" &
" inherit from protected interface", Indic);
elsif Synchronized_Present (Iface_Def) then
Error_Msg_N ("(Ada 2005) non-limited interface cannot" &
" inherit from synchronized interface", Indic);
elsif Task_Present (Iface_Def) then
Error_Msg_N ("(Ada 2005) non-limited interface cannot" &
" inherit from task interface", Indic);
else
null;
end if;
end if;
end if;
end if;
-- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
-- interfaces
if Is_Tagged_Type (Parent_Type)
and then Is_Non_Empty_List (Interface_List (Def))
then
declare
Intf : Node_Id;
T : Entity_Id;
begin
Intf := First (Interface_List (Def));
while Present (Intf) loop
T := Find_Type_Of_Subtype_Indic (Intf);
if not Is_Interface (T) then
Error_Msg_NE ("(Ada 2005) & must be an interface", Intf, T);
elsif Limited_Present (Def)
and then not Is_Limited_Interface (T)
then
Error_Msg_NE
("progenitor interface& of limited type must be limited",
N, T);
end if;
Next (Intf);
end loop;
end;
end if;
if Parent_Type = Any_Type
or else Etype (Parent_Type) = Any_Type
or else (Is_Class_Wide_Type (Parent_Type)
and then Etype (Parent_Type) = T)
then
-- If Parent_Type is undefined or illegal, make new type into a
-- subtype of Any_Type, and set a few attributes to prevent cascaded
-- errors. If this is a self-definition, emit error now.
if T = Parent_Type
or else T = Etype (Parent_Type)
then
Error_Msg_N ("type cannot be used in its own definition", Indic);
end if;
Set_Ekind (T, Ekind (Parent_Type));
Set_Etype (T, Any_Type);
Set_Scalar_Range (T, Scalar_Range (Any_Type));
if Is_Tagged_Type (T) then
Set_Primitive_Operations (T, New_Elmt_List);
end if;
return;
end if;
-- Ada 2005 (AI-251): The case in which the parent of the full-view is
-- an interface is special because the list of interfaces in the full
-- view can be given in any order. For example:
-- type A is interface;
-- type B is interface and A;
-- type D is new B with private;
-- private
-- type D is new A and B with null record; -- 1 --
-- In this case we perform the following transformation of -1-:
-- type D is new B and A with null record;
-- If the parent of the full-view covers the parent of the partial-view
-- we have two possible cases:
-- 1) They have the same parent
-- 2) The parent of the full-view implements some further interfaces
-- In both cases we do not need to perform the transformation. In the
-- first case the source program is correct and the transformation is
-- not needed; in the second case the source program does not fulfill
-- the no-hidden interfaces rule (AI-396) and the error will be reported
-- later.
-- This transformation not only simplifies the rest of the analysis of
-- this type declaration but also simplifies the correct generation of
-- the object layout to the expander.
if In_Private_Part (Current_Scope)
and then Is_Interface (Parent_Type)
then
declare
Iface : Node_Id;
Partial_View : Entity_Id;
Partial_View_Parent : Entity_Id;
New_Iface : Node_Id;
begin
-- Look for the associated private type declaration
Partial_View := First_Entity (Current_Scope);
loop
exit when No (Partial_View)
or else (Has_Private_Declaration (Partial_View)
and then Full_View (Partial_View) = T);
Next_Entity (Partial_View);
end loop;
-- If the partial view was not found then the source code has
-- errors and the transformation is not needed.
if Present (Partial_View) then
Partial_View_Parent := Etype (Partial_View);
-- If the parent of the full-view covers the parent of the
-- partial-view we have nothing else to do.
if Interface_Present_In_Ancestor
(Parent_Type, Partial_View_Parent)
then
null;
-- Traverse the list of interfaces of the full-view to look
-- for the parent of the partial-view and perform the tree
-- transformation.
else
Iface := First (Interface_List (Def));
while Present (Iface) loop
if Etype (Iface) = Etype (Partial_View) then
Rewrite (Subtype_Indication (Def),
New_Copy (Subtype_Indication
(Parent (Partial_View))));
New_Iface := Make_Identifier (Sloc (N),
Chars (Parent_Type));
Append (New_Iface, Interface_List (Def));
-- Analyze the transformed code
Derived_Type_Declaration (T, N, Is_Completion);
return;
end if;
Next (Iface);
end loop;
end if;
end if;
end;
end if;
-- Only composite types other than array types are allowed to have
-- discriminants.
if Present (Discriminant_Specifications (N))
and then (Is_Elementary_Type (Parent_Type)
or else Is_Array_Type (Parent_Type))
and then not Error_Posted (N)
then
Error_Msg_N
("elementary or array type cannot have discriminants",
Defining_Identifier (First (Discriminant_Specifications (N))));
Set_Has_Discriminants (T, False);
end if;
-- In Ada 83, a derived type defined in a package specification cannot
-- be used for further derivation until the end of its visible part.
-- Note that derivation in the private part of the package is allowed.
if Ada_Version = Ada_83
and then Is_Derived_Type (Parent_Type)
and then In_Visible_Part (Scope (Parent_Type))
then
if Ada_Version = Ada_83 and then Comes_From_Source (Indic) then
Error_Msg_N
("(Ada 83): premature use of type for derivation", Indic);
end if;
end if;
-- Check for early use of incomplete or private type
if Ekind (Parent_Type) = E_Void
or else Ekind (Parent_Type) = E_Incomplete_Type
then
Error_Msg_N ("premature derivation of incomplete type", Indic);
return;
elsif (Is_Incomplete_Or_Private_Type (Parent_Type)
and then not Comes_From_Generic (Parent_Type))
or else Has_Private_Component (Parent_Type)
then
-- The ancestor type of a formal type can be incomplete, in which
-- case only the operations of the partial view are available in
-- the generic. Subsequent checks may be required when the full
-- view is analyzed, to verify that derivation from a tagged type
-- has an extension.
if Nkind (Original_Node (N)) = N_Formal_Type_Declaration then
null;
elsif No (Underlying_Type (Parent_Type))
or else Has_Private_Component (Parent_Type)
then
Error_Msg_N
("premature derivation of derived or private type", Indic);
-- Flag the type itself as being in error, this prevents some
-- nasty problems with subsequent uses of the malformed type.
Set_Error_Posted (T);
-- Check that within the immediate scope of an untagged partial
-- view it's illegal to derive from the partial view if the
-- full view is tagged. (7.3(7))
-- We verify that the Parent_Type is a partial view by checking
-- that it is not a Full_Type_Declaration (i.e. a private type or
-- private extension declaration), to distinguish a partial view
-- from a derivation from a private type which also appears as
-- E_Private_Type.
elsif Present (Full_View (Parent_Type))
and then Nkind (Parent (Parent_Type)) /= N_Full_Type_Declaration
and then not Is_Tagged_Type (Parent_Type)
and then Is_Tagged_Type (Full_View (Parent_Type))
then
Parent_Scope := Scope (T);
while Present (Parent_Scope)
and then Parent_Scope /= Standard_Standard
loop
if Parent_Scope = Scope (Parent_Type) then
Error_Msg_N
("premature derivation from type with tagged full view",
Indic);
end if;
Parent_Scope := Scope (Parent_Scope);
end loop;
end if;
end if;
-- Check that form of derivation is appropriate
Taggd := Is_Tagged_Type (Parent_Type);
-- Perhaps the parent type should be changed to the class-wide type's
-- specific type in this case to prevent cascading errors ???
if Present (Extension) and then Is_Class_Wide_Type (Parent_Type) then
Error_Msg_N ("parent type must not be a class-wide type", Indic);
return;
end if;
if Present (Extension) and then not Taggd then
Error_Msg_N
("type derived from untagged type cannot have extension", Indic);
elsif No (Extension) and then Taggd then
-- If this declaration is within a private part (or body) of a
-- generic instantiation then the derivation is allowed (the parent
-- type can only appear tagged in this case if it's a generic actual
-- type, since it would otherwise have been rejected in the analysis
-- of the generic template).
if not Is_Generic_Actual_Type (Parent_Type)
or else In_Visible_Part (Scope (Parent_Type))
then
Error_Msg_N
("type derived from tagged type must have extension", Indic);
end if;
end if;
Build_Derived_Type (N, Parent_Type, T, Is_Completion);
-- AI-419: the parent type of an explicitly limited derived type must
-- be a limited type or a limited interface.
if Limited_Present (Def) then
Set_Is_Limited_Record (T);
if Is_Interface (T) then
Set_Is_Limited_Interface (T);
end if;
if not Is_Limited_Type (Parent_Type)
and then
(not Is_Interface (Parent_Type)
or else not Is_Limited_Interface (Parent_Type))
then
Error_Msg_NE ("parent type& of limited type must be limited",
N, Parent_Type);
end if;
end if;
end Derived_Type_Declaration;
----------------------------------
-- Enumeration_Type_Declaration --
----------------------------------
procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id) is
Ev : Uint;
L : Node_Id;
R_Node : Node_Id;
B_Node : Node_Id;
begin
-- Create identifier node representing lower bound
B_Node := New_Node (N_Identifier, Sloc (Def));
L := First (Literals (Def));
Set_Chars (B_Node, Chars (L));
Set_Entity (B_Node, L);
Set_Etype (B_Node, T);
Set_Is_Static_Expression (B_Node, True);
R_Node := New_Node (N_Range, Sloc (Def));
Set_Low_Bound (R_Node, B_Node);
Set_Ekind (T, E_Enumeration_Type);
Set_First_Literal (T, L);
Set_Etype (T, T);
Set_Is_Constrained (T);
Ev := Uint_0;
-- Loop through literals of enumeration type setting pos and rep values
-- except that if the Ekind is already set, then it means that the
-- literal was already constructed (case of a derived type declaration
-- and we should not disturb the Pos and Rep values.
while Present (L) loop
if Ekind (L) /= E_Enumeration_Literal then
Set_Ekind (L, E_Enumeration_Literal);
Set_Enumeration_Pos (L, Ev);
Set_Enumeration_Rep (L, Ev);
Set_Is_Known_Valid (L, True);
end if;
Set_Etype (L, T);
New_Overloaded_Entity (L);
Generate_Definition (L);
Set_Convention (L, Convention_Intrinsic);
if Nkind (L) = N_Defining_Character_Literal then
Set_Is_Character_Type (T, True);
end if;
Ev := Ev + 1;
Next (L);
end loop;
-- Now create a node representing upper bound
B_Node := New_Node (N_Identifier, Sloc (Def));
Set_Chars (B_Node, Chars (Last (Literals (Def))));
Set_Entity (B_Node, Last (Literals (Def)));
Set_Etype (B_Node, T);
Set_Is_Static_Expression (B_Node, True);
Set_High_Bound (R_Node, B_Node);
Set_Scalar_Range (T, R_Node);
Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
Set_Enum_Esize (T);
-- Set Discard_Names if configuration pragma set, or if there is
-- a parameterless pragma in the current declarative region
if Global_Discard_Names
or else Discard_Names (Scope (T))
then
Set_Discard_Names (T);
end if;
-- Process end label if there is one
if Present (Def) then
Process_End_Label (Def, 'e', T);
end if;
end Enumeration_Type_Declaration;
---------------------------------
-- Expand_To_Stored_Constraint --
---------------------------------
function Expand_To_Stored_Constraint
(Typ : Entity_Id;
Constraint : Elist_Id) return Elist_Id
is
Explicitly_Discriminated_Type : Entity_Id;
Expansion : Elist_Id;
Discriminant : Entity_Id;
function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id;
-- Find the nearest type that actually specifies discriminants
---------------------------------
-- Type_With_Explicit_Discrims --
---------------------------------
function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id is
Typ : constant E := Base_Type (Id);
begin
if Ekind (Typ) in Incomplete_Or_Private_Kind then
if Present (Full_View (Typ)) then
return Type_With_Explicit_Discrims (Full_View (Typ));
end if;
else
if Has_Discriminants (Typ) then
return Typ;
end if;
end if;
if Etype (Typ) = Typ then
return Empty;
elsif Has_Discriminants (Typ) then
return Typ;
else
return Type_With_Explicit_Discrims (Etype (Typ));
end if;
end Type_With_Explicit_Discrims;
-- Start of processing for Expand_To_Stored_Constraint
begin
if No (Constraint)
or else Is_Empty_Elmt_List (Constraint)
then
return No_Elist;
end if;
Explicitly_Discriminated_Type := Type_With_Explicit_Discrims (Typ);
if No (Explicitly_Discriminated_Type) then
return No_Elist;
end if;
Expansion := New_Elmt_List;
Discriminant :=
First_Stored_Discriminant (Explicitly_Discriminated_Type);
while Present (Discriminant) loop
Append_Elmt (
Get_Discriminant_Value (
Discriminant, Explicitly_Discriminated_Type, Constraint),
Expansion);
Next_Stored_Discriminant (Discriminant);
end loop;
return Expansion;
end Expand_To_Stored_Constraint;
--------------------
-- Find_Type_Name --
--------------------
function Find_Type_Name (N : Node_Id) return Entity_Id is
Id : constant Entity_Id := Defining_Identifier (N);
Prev : Entity_Id;
New_Id : Entity_Id;
Prev_Par : Node_Id;
begin
-- Find incomplete declaration, if one was given
Prev := Current_Entity_In_Scope (Id);
if Present (Prev) then
-- Previous declaration exists. Error if not incomplete/private case
-- except if previous declaration is implicit, etc. Enter_Name will
-- emit error if appropriate.
Prev_Par := Parent (Prev);
if not Is_Incomplete_Or_Private_Type (Prev) then
Enter_Name (Id);
New_Id := Id;
elsif Nkind (N) /= N_Full_Type_Declaration
and then Nkind (N) /= N_Task_Type_Declaration
and then Nkind (N) /= N_Protected_Type_Declaration
then
-- Completion must be a full type declarations (RM 7.3(4))
Error_Msg_Sloc := Sloc (Prev);
Error_Msg_NE ("invalid completion of }", Id, Prev);
-- Set scope of Id to avoid cascaded errors. Entity is never
-- examined again, except when saving globals in generics.
Set_Scope (Id, Current_Scope);
New_Id := Id;
-- Case of full declaration of incomplete type
elsif Ekind (Prev) = E_Incomplete_Type then
-- Indicate that the incomplete declaration has a matching full
-- declaration. The defining occurrence of the incomplete
-- declaration remains the visible one, and the procedure
-- Get_Full_View dereferences it whenever the type is used.
if Present (Full_View (Prev)) then
Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
end if;
Set_Full_View (Prev, Id);
Append_Entity (Id, Current_Scope);
Set_Is_Public (Id, Is_Public (Prev));
Set_Is_Internal (Id);
New_Id := Prev;
-- Case of full declaration of private type
else
if Nkind (Parent (Prev)) /= N_Private_Extension_Declaration then
if Etype (Prev) /= Prev then
-- Prev is a private subtype or a derived type, and needs
-- no completion.
Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
New_Id := Id;
elsif Ekind (Prev) = E_Private_Type
and then
(Nkind (N) = N_Task_Type_Declaration
or else Nkind (N) = N_Protected_Type_Declaration)
then
Error_Msg_N
("completion of nonlimited type cannot be limited", N);
elsif Ekind (Prev) = E_Record_Type_With_Private
and then
(Nkind (N) = N_Task_Type_Declaration
or else Nkind (N) = N_Protected_Type_Declaration)
then
if not Is_Limited_Record (Prev) then
Error_Msg_N
("completion of nonlimited type cannot be limited", N);
elsif No (Interface_List (N)) then
Error_Msg_N
("completion of tagged private type must be tagged",
N);
end if;
end if;
-- Ada 2005 (AI-251): Private extension declaration of a
-- task type. This case arises with tasks implementing interfaces
elsif Nkind (N) = N_Task_Type_Declaration
or else Nkind (N) = N_Protected_Type_Declaration
then
null;
elsif Nkind (N) /= N_Full_Type_Declaration
or else Nkind (Type_Definition (N)) /= N_Derived_Type_Definition
then
Error_Msg_N
("full view of private extension must be an extension", N);
elsif not (Abstract_Present (Parent (Prev)))
and then Abstract_Present (Type_Definition (N))
then
Error_Msg_N
("full view of non-abstract extension cannot be abstract", N);
end if;
if not In_Private_Part (Current_Scope) then
Error_Msg_N
("declaration of full view must appear in private part", N);
end if;
Copy_And_Swap (Prev, Id);
Set_Has_Private_Declaration (Prev);
Set_Has_Private_Declaration (Id);
-- If no error, propagate freeze_node from private to full view.
-- It may have been generated for an early operational item.
if Present (Freeze_Node (Id))
and then Serious_Errors_Detected = 0
and then No (Full_View (Id))
then
Set_Freeze_Node (Prev, Freeze_Node (Id));
Set_Freeze_Node (Id, Empty);
Set_First_Rep_Item (Prev, First_Rep_Item (Id));
end if;
Set_Full_View (Id, Prev);
New_Id := Prev;
end if;
-- Verify that full declaration conforms to incomplete one
if Is_Incomplete_Or_Private_Type (Prev)
and then Present (Discriminant_Specifications (Prev_Par))
then
if Present (Discriminant_Specifications (N)) then
if Ekind (Prev) = E_Incomplete_Type then
Check_Discriminant_Conformance (N, Prev, Prev);
else
Check_Discriminant_Conformance (N, Prev, Id);
end if;
else
Error_Msg_N
("missing discriminants in full type declaration", N);
-- To avoid cascaded errors on subsequent use, share the
-- discriminants of the partial view.
Set_Discriminant_Specifications (N,
Discriminant_Specifications (Prev_Par));
end if;
end if;
-- A prior untagged private type can have an associated class-wide
-- type due to use of the class attribute, and in this case also the
-- full type is required to be tagged.
if Is_Type (Prev)
and then (Is_Tagged_Type (Prev)
or else Present (Class_Wide_Type (Prev)))
and then (Nkind (N) /= N_Task_Type_Declaration
and then Nkind (N) /= N_Protected_Type_Declaration)
then
-- The full declaration is either a tagged record or an
-- extension otherwise this is an error
if Nkind (Type_Definition (N)) = N_Record_Definition then
if not Tagged_Present (Type_Definition (N)) then
Error_Msg_NE
("full declaration of } must be tagged", Prev, Id);
Set_Is_Tagged_Type (Id);
Set_Primitive_Operations (Id, New_Elmt_List);
end if;
elsif Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
if No (Record_Extension_Part (Type_Definition (N))) then
Error_Msg_NE (
"full declaration of } must be a record extension",
Prev, Id);
Set_Is_Tagged_Type (Id);
Set_Primitive_Operations (Id, New_Elmt_List);
end if;
else
Error_Msg_NE
("full declaration of } must be a tagged type", Prev, Id);
end if;
end if;
return New_Id;
else
-- New type declaration
Enter_Name (Id);
return Id;
end if;
end Find_Type_Name;
-------------------------
-- Find_Type_Of_Object --
-------------------------
function Find_Type_Of_Object
(Obj_Def : Node_Id;
Related_Nod : Node_Id) return Entity_Id
is
Def_Kind : constant Node_Kind := Nkind (Obj_Def);
P : Node_Id := Parent (Obj_Def);
T : Entity_Id;
Nam : Name_Id;
begin
-- If the parent is a component_definition node we climb to the
-- component_declaration node
if Nkind (P) = N_Component_Definition then
P := Parent (P);
end if;
-- Case of an anonymous array subtype
if Def_Kind = N_Constrained_Array_Definition
or else Def_Kind = N_Unconstrained_Array_Definition
then
T := Empty;
Array_Type_Declaration (T, Obj_Def);
-- Create an explicit subtype whenever possible
elsif Nkind (P) /= N_Component_Declaration
and then Def_Kind = N_Subtype_Indication
then
-- Base name of subtype on object name, which will be unique in
-- the current scope.
-- If this is a duplicate declaration, return base type, to avoid
-- generating duplicate anonymous types.
if Error_Posted (P) then
Analyze (Subtype_Mark (Obj_Def));
return Entity (Subtype_Mark (Obj_Def));
end if;
Nam :=
New_External_Name
(Chars (Defining_Identifier (Related_Nod)), 'S', 0, 'T');
T := Make_Defining_Identifier (Sloc (P), Nam);
Insert_Action (Obj_Def,
Make_Subtype_Declaration (Sloc (P),
Defining_Identifier => T,
Subtype_Indication => Relocate_Node (Obj_Def)));
-- This subtype may need freezing, and this will not be done
-- automatically if the object declaration is not in declarative
-- part. Since this is an object declaration, the type cannot always
-- be frozen here. Deferred constants do not freeze their type
-- (which often enough will be private).
if Nkind (P) = N_Object_Declaration
and then Constant_Present (P)
and then No (Expression (P))
then
null;
else
Insert_Actions (Obj_Def, Freeze_Entity (T, Sloc (P)));
end if;
-- Ada 2005 AI-406: the object definition in an object declaration
-- can be an access definition.
elsif Def_Kind = N_Access_Definition then
T := Access_Definition (Related_Nod, Obj_Def);
Set_Is_Local_Anonymous_Access (T);
-- comment here, what cases ???
else
T := Process_Subtype (Obj_Def, Related_Nod);
end if;
return T;
end Find_Type_Of_Object;
--------------------------------
-- Find_Type_Of_Subtype_Indic --
--------------------------------
function Find_Type_Of_Subtype_Indic (S : Node_Id) return Entity_Id is
Typ : Entity_Id;
begin
-- Case of subtype mark with a constraint
if Nkind (S) = N_Subtype_Indication then
Find_Type (Subtype_Mark (S));
Typ := Entity (Subtype_Mark (S));
if not
Is_Valid_Constraint_Kind (Ekind (Typ), Nkind (Constraint (S)))
then
Error_Msg_N
("incorrect constraint for this kind of type", Constraint (S));
Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
end if;
-- Otherwise we have a subtype mark without a constraint
elsif Error_Posted (S) then
Rewrite (S, New_Occurrence_Of (Any_Id, Sloc (S)));
return Any_Type;
else
Find_Type (S);
Typ := Entity (S);
end if;
if Typ = Standard_Wide_Character
or else Typ = Standard_Wide_Wide_Character
or else Typ = Standard_Wide_String
or else Typ = Standard_Wide_Wide_String
then
Check_Restriction (No_Wide_Characters, S);
end if;
return Typ;
end Find_Type_Of_Subtype_Indic;
-------------------------------------
-- Floating_Point_Type_Declaration --
-------------------------------------
procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id) is
Digs : constant Node_Id := Digits_Expression (Def);
Digs_Val : Uint;
Base_Typ : Entity_Id;
Implicit_Base : Entity_Id;
Bound : Node_Id;
function Can_Derive_From (E : Entity_Id) return Boolean;
-- Find if given digits value allows derivation from specified type
---------------------
-- Can_Derive_From --
---------------------
function Can_Derive_From (E : Entity_Id) return Boolean is
Spec : constant Entity_Id := Real_Range_Specification (Def);
begin
if Digs_Val > Digits_Value (E) then
return False;
end if;
if Present (Spec) then
if Expr_Value_R (Type_Low_Bound (E)) >
Expr_Value_R (Low_Bound (Spec))
then
return False;
end if;
if Expr_Value_R (Type_High_Bound (E)) <
Expr_Value_R (High_Bound (Spec))
then
return False;
end if;
end if;
return True;
end Can_Derive_From;
-- Start of processing for Floating_Point_Type_Declaration
begin
Check_Restriction (No_Floating_Point, Def);
-- Create an implicit base type
Implicit_Base :=
Create_Itype (E_Floating_Point_Type, Parent (Def), T, 'B');
-- Analyze and verify digits value
Analyze_And_Resolve (Digs, Any_Integer);
Check_Digits_Expression (Digs);
Digs_Val := Expr_Value (Digs);
-- Process possible range spec and find correct type to derive from
Process_Real_Range_Specification (Def);
if Can_Derive_From (Standard_Short_Float) then
Base_Typ := Standard_Short_Float;
elsif Can_Derive_From (Standard_Float) then
Base_Typ := Standard_Float;
elsif Can_Derive_From (Standard_Long_Float) then
Base_Typ := Standard_Long_Float;
elsif Can_Derive_From (Standard_Long_Long_Float) then
Base_Typ := Standard_Long_Long_Float;
-- If we can't derive from any existing type, use long_long_float
-- and give appropriate message explaining the problem.
else
Base_Typ := Standard_Long_Long_Float;
if Digs_Val >= Digits_Value (Standard_Long_Long_Float) then
Error_Msg_Uint_1 := Digits_Value (Standard_Long_Long_Float);
Error_Msg_N ("digits value out of range, maximum is ^", Digs);
else
Error_Msg_N
("range too large for any predefined type",
Real_Range_Specification (Def));
end if;
end if;
-- If there are bounds given in the declaration use them as the bounds
-- of the type, otherwise use the bounds of the predefined base type
-- that was chosen based on the Digits value.
if Present (Real_Range_Specification (Def)) then
Set_Scalar_Range (T, Real_Range_Specification (Def));
Set_Is_Constrained (T);
-- The bounds of this range must be converted to machine numbers
-- in accordance with RM 4.9(38).
Bound := Type_Low_Bound (T);
if Nkind (Bound) = N_Real_Literal then
Set_Realval
(Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
Set_Is_Machine_Number (Bound);
end if;
Bound := Type_High_Bound (T);
if Nkind (Bound) = N_Real_Literal then
Set_Realval
(Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
Set_Is_Machine_Number (Bound);
end if;
else
Set_Scalar_Range (T, Scalar_Range (Base_Typ));
end if;
-- Complete definition of implicit base and declared first subtype
Set_Etype (Implicit_Base, Base_Typ);
Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
Set_Size_Info (Implicit_Base, (Base_Typ));
Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
Set_Digits_Value (Implicit_Base, Digits_Value (Base_Typ));
Set_Vax_Float (Implicit_Base, Vax_Float (Base_Typ));
Set_Ekind (T, E_Floating_Point_Subtype);
Set_Etype (T, Implicit_Base);
Set_Size_Info (T, (Implicit_Base));
Set_RM_Size (T, RM_Size (Implicit_Base));
Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
Set_Digits_Value (T, Digs_Val);
end Floating_Point_Type_Declaration;
----------------------------
-- Get_Discriminant_Value --
----------------------------
-- This is the situation:
-- There is a non-derived type
-- type T0 (Dx, Dy, Dz...)
-- There are zero or more levels of derivation, with each derivation
-- either purely inheriting the discriminants, or defining its own.
-- type Ti is new Ti-1
-- or
-- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
-- or
-- subtype Ti is ...
-- The subtype issue is avoided by the use of Original_Record_Component,
-- and the fact that derived subtypes also derive the constraints.
-- This chain leads back from
-- Typ_For_Constraint
-- Typ_For_Constraint has discriminants, and the value for each
-- discriminant is given by its corresponding Elmt of Constraints.
-- Discriminant is some discriminant in this hierarchy
-- We need to return its value
-- We do this by recursively searching each level, and looking for
-- Discriminant. Once we get to the bottom, we start backing up
-- returning the value for it which may in turn be a discriminant
-- further up, so on the backup we continue the substitution.
function Get_Discriminant_Value
(Discriminant : Entity_Id;
Typ_For_Constraint : Entity_Id;
Constraint : Elist_Id) return Node_Id
is
function Search_Derivation_Levels
(Ti : Entity_Id;
Discrim_Values : Elist_Id;
Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id;
-- This is the routine that performs the recursive search of levels
-- as described above.
------------------------------
-- Search_Derivation_Levels --
------------------------------
function Search_Derivation_Levels
(Ti : Entity_Id;
Discrim_Values : Elist_Id;
Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id
is
Assoc : Elmt_Id;
Disc : Entity_Id;
Result : Node_Or_Entity_Id;
Result_Entity : Node_Id;
begin
-- If inappropriate type, return Error, this happens only in
-- cascaded error situations, and we want to avoid a blow up.
if not Is_Composite_Type (Ti) or else Is_Array_Type (Ti) then
return Error;
end if;
-- Look deeper if possible. Use Stored_Constraints only for
-- untagged types. For tagged types use the given constraint.
-- This asymmetry needs explanation???
if not Stored_Discrim_Values
and then Present (Stored_Constraint (Ti))
and then not Is_Tagged_Type (Ti)
then
Result :=
Search_Derivation_Levels (Ti, Stored_Constraint (Ti), True);
else
declare
Td : constant Entity_Id := Etype (Ti);
begin
if Td = Ti then
Result := Discriminant;
else
if Present (Stored_Constraint (Ti)) then
Result :=
Search_Derivation_Levels
(Td, Stored_Constraint (Ti), True);
else
Result :=
Search_Derivation_Levels
(Td, Discrim_Values, Stored_Discrim_Values);
end if;
end if;
end;
end if;
-- Extra underlying places to search, if not found above. For
-- concurrent types, the relevant discriminant appears in the
-- corresponding record. For a type derived from a private type
-- without discriminant, the full view inherits the discriminants
-- of the full view of the parent.
if Result = Discriminant then
if Is_Concurrent_Type (Ti)
and then Present (Corresponding_Record_Type (Ti))
then
Result :=
Search_Derivation_Levels (
Corresponding_Record_Type (Ti),
Discrim_Values,
Stored_Discrim_Values);
elsif Is_Private_Type (Ti)
and then not Has_Discriminants (Ti)
and then Present (Full_View (Ti))
and then Etype (Full_View (Ti)) /= Ti
then
Result :=
Search_Derivation_Levels (
Full_View (Ti),
Discrim_Values,
Stored_Discrim_Values);
end if;
end if;
-- If Result is not a (reference to a) discriminant, return it,
-- otherwise set Result_Entity to the discriminant.
if Nkind (Result) = N_Defining_Identifier then
pragma Assert (Result = Discriminant);
Result_Entity := Result;
else
if not Denotes_Discriminant (Result) then
return Result;
end if;
Result_Entity := Entity (Result);
end if;
-- See if this level of derivation actually has discriminants
-- because tagged derivations can add them, hence the lower
-- levels need not have any.
if not Has_Discriminants (Ti) then
return Result;
end if;
-- Scan Ti's discriminants for Result_Entity,
-- and return its corresponding value, if any.
Result_Entity := Original_Record_Component (Result_Entity);
Assoc := First_Elmt (Discrim_Values);
if Stored_Discrim_Values then
Disc := First_Stored_Discriminant (Ti);
else
Disc := First_Discriminant (Ti);
end if;
while Present (Disc) loop
pragma Assert (Present (Assoc));
if Original_Record_Component (Disc) = Result_Entity then
return Node (Assoc);
end if;
Next_Elmt (Assoc);
if Stored_Discrim_Values then
Next_Stored_Discriminant (Disc);
else
Next_Discriminant (Disc);
end if;
end loop;
-- Could not find it
--
return Result;
end Search_Derivation_Levels;
Result : Node_Or_Entity_Id;
-- Start of processing for Get_Discriminant_Value
begin
-- ??? This routine is a gigantic mess and will be deleted. For the
-- time being just test for the trivial case before calling recurse.
if Base_Type (Scope (Discriminant)) = Base_Type (Typ_For_Constraint) then
declare
D : Entity_Id;
E : Elmt_Id;
begin
D := First_Discriminant (Typ_For_Constraint);
E := First_Elmt (Constraint);
while Present (D) loop
if Chars (D) = Chars (Discriminant) then
return Node (E);
end if;
Next_Discriminant (D);
Next_Elmt (E);
end loop;
end;
end if;
Result := Search_Derivation_Levels
(Typ_For_Constraint, Constraint, False);
-- ??? hack to disappear when this routine is gone
if Nkind (Result) = N_Defining_Identifier then
declare
D : Entity_Id;
E : Elmt_Id;
begin
D := First_Discriminant (Typ_For_Constraint);
E := First_Elmt (Constraint);
while Present (D) loop
if Corresponding_Discriminant (D) = Discriminant then
return Node (E);
end if;
Next_Discriminant (D);
Next_Elmt (E);
end loop;
end;
end if;
pragma Assert (Nkind (Result) /= N_Defining_Identifier);
return Result;
end Get_Discriminant_Value;
--------------------------
-- Has_Range_Constraint --
--------------------------
function Has_Range_Constraint (N : Node_Id) return Boolean is
C : constant Node_Id := Constraint (N);
begin
if Nkind (C) = N_Range_Constraint then
return True;
elsif Nkind (C) = N_Digits_Constraint then
return
Is_Decimal_Fixed_Point_Type (Entity (Subtype_Mark (N)))
or else
Present (Range_Constraint (C));
elsif Nkind (C) = N_Delta_Constraint then
return Present (Range_Constraint (C));
else
return False;
end if;
end Has_Range_Constraint;
------------------------
-- Inherit_Components --
------------------------
function Inherit_Components
(N : Node_Id;
Parent_Base : Entity_Id;
Derived_Base : Entity_Id;
Is_Tagged : Boolean;
Inherit_Discr : Boolean;
Discs : Elist_Id) return Elist_Id
is
Assoc_List : constant Elist_Id := New_Elmt_List;
procedure Inherit_Component
(Old_C : Entity_Id;
Plain_Discrim : Boolean := False;
Stored_Discrim : Boolean := False);
-- Inherits component Old_C from Parent_Base to the Derived_Base. If
-- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
-- True, Old_C is a stored discriminant. If they are both false then
-- Old_C is a regular component.
-----------------------
-- Inherit_Component --
-----------------------
procedure Inherit_Component
(Old_C : Entity_Id;
Plain_Discrim : Boolean := False;
Stored_Discrim : Boolean := False)
is
New_C : constant Entity_Id := New_Copy (Old_C);
Discrim : Entity_Id;
Corr_Discrim : Entity_Id;
begin
pragma Assert (not Is_Tagged or else not Stored_Discrim);
Set_Parent (New_C, Parent (Old_C));
-- Regular discriminants and components must be inserted
-- in the scope of the Derived_Base. Do it here.
if not Stored_Discrim then
Enter_Name (New_C);
end if;
-- For tagged types the Original_Record_Component must point to
-- whatever this field was pointing to in the parent type. This has
-- already been achieved by the call to New_Copy above.
if not Is_Tagged then
Set_Original_Record_Component (New_C, New_C);
end if;
-- If we have inherited a component then see if its Etype contains
-- references to Parent_Base discriminants. In this case, replace
-- these references with the constraints given in Discs. We do not
-- do this for the partial view of private types because this is
-- not needed (only the components of the full view will be used
-- for code generation) and cause problem. We also avoid this
-- transformation in some error situations.
if Ekind (New_C) = E_Component then
if (Is_Private_Type (Derived_Base)
and then not Is_Generic_Type (Derived_Base))
or else (Is_Empty_Elmt_List (Discs)
and then not Expander_Active)
then
Set_Etype (New_C, Etype (Old_C));
else
Set_Etype
(New_C,
Constrain_Component_Type
(Old_C, Derived_Base, N, Parent_Base, Discs));
end if;
end if;
-- In derived tagged types it is illegal to reference a non
-- discriminant component in the parent type. To catch this, mark
-- these components with an Ekind of E_Void. This will be reset in
-- Record_Type_Definition after processing the record extension of
-- the derived type.
if Is_Tagged and then Ekind (New_C) = E_Component then
Set_Ekind (New_C, E_Void);
end if;
if Plain_Discrim then
Set_Corresponding_Discriminant (New_C, Old_C);
Build_Discriminal (New_C);
-- If we are explicitly inheriting a stored discriminant it will be
-- completely hidden.
elsif Stored_Discrim then
Set_Corresponding_Discriminant (New_C, Empty);
Set_Discriminal (New_C, Empty);
Set_Is_Completely_Hidden (New_C);
-- Set the Original_Record_Component of each discriminant in the
-- derived base to point to the corresponding stored that we just
-- created.
Discrim := First_Discriminant (Derived_Base);
while Present (Discrim) loop
Corr_Discrim := Corresponding_Discriminant (Discrim);
-- Corr_Discrim could be missing in an error situation
if Present (Corr_Discrim)
and then Original_Record_Component (Corr_Discrim) = Old_C
then
Set_Original_Record_Component (Discrim, New_C);
end if;
Next_Discriminant (Discrim);
end loop;
Append_Entity (New_C, Derived_Base);
end if;
if not Is_Tagged then
Append_Elmt (Old_C, Assoc_List);
Append_Elmt (New_C, Assoc_List);
end if;
end Inherit_Component;
-- Variables local to Inherit_Component
Loc : constant Source_Ptr := Sloc (N);
Parent_Discrim : Entity_Id;
Stored_Discrim : Entity_Id;
D : Entity_Id;
Component : Entity_Id;
-- Start of processing for Inherit_Components
begin
if not Is_Tagged then
Append_Elmt (Parent_Base, Assoc_List);
Append_Elmt (Derived_Base, Assoc_List);
end if;
-- Inherit parent discriminants if needed
if Inherit_Discr then
Parent_Discrim := First_Discriminant (Parent_Base);
while Present (Parent_Discrim) loop
Inherit_Component (Parent_Discrim, Plain_Discrim => True);
Next_Discriminant (Parent_Discrim);
end loop;
end if;
-- Create explicit stored discrims for untagged types when necessary
if not Has_Unknown_Discriminants (Derived_Base)
and then Has_Discriminants (Parent_Base)
and then not Is_Tagged
and then
(not Inherit_Discr
or else First_Discriminant (Parent_Base) /=
First_Stored_Discriminant (Parent_Base))
then
Stored_Discrim := First_Stored_Discriminant (Parent_Base);
while Present (Stored_Discrim) loop
Inherit_Component (Stored_Discrim, Stored_Discrim => True);
Next_Stored_Discriminant (Stored_Discrim);
end loop;
end if;
-- See if we can apply the second transformation for derived types, as
-- explained in point 6. in the comments above Build_Derived_Record_Type
-- This is achieved by appending Derived_Base discriminants into Discs,
-- which has the side effect of returning a non empty Discs list to the
-- caller of Inherit_Components, which is what we want. This must be
-- done for private derived types if there are explicit stored
-- discriminants, to ensure that we can retrieve the values of the
-- constraints provided in the ancestors.
if Inherit_Discr
and then Is_Empty_Elmt_List (Discs)
and then Present (First_Discriminant (Derived_Base))
and then
(not Is_Private_Type (Derived_Base)
or else Is_Completely_Hidden
(First_Stored_Discriminant (Derived_Base))
or else Is_Generic_Type (Derived_Base))
then
D := First_Discriminant (Derived_Base);
while Present (D) loop
Append_Elmt (New_Reference_To (D, Loc), Discs);
Next_Discriminant (D);
end loop;
end if;
-- Finally, inherit non-discriminant components unless they are not
-- visible because defined or inherited from the full view of the
-- parent. Don't inherit the _parent field of the parent type.
Component := First_Entity (Parent_Base);
while Present (Component) loop
-- Ada 2005 (AI-251): Do not inherit tags corresponding with the
-- interfaces of the parent
if Ekind (Component) = E_Component
and then Is_Tag (Component)
and then RTE_Available (RE_Interface_Tag)
and then Etype (Component) = RTE (RE_Interface_Tag)
then
null;
elsif Ekind (Component) /= E_Component
or else Chars (Component) = Name_uParent
then
null;
-- If the derived type is within the parent type's declarative
-- region, then the components can still be inherited even though
-- they aren't visible at this point. This can occur for cases
-- such as within public child units where the components must
-- become visible upon entering the child unit's private part.
elsif not Is_Visible_Component (Component)
and then not In_Open_Scopes (Scope (Parent_Base))
then
null;
elsif Ekind (Derived_Base) = E_Private_Type
or else Ekind (Derived_Base) = E_Limited_Private_Type
then
null;
else
Inherit_Component (Component);
end if;
Next_Entity (Component);
end loop;
-- For tagged derived types, inherited discriminants cannot be used in
-- component declarations of the record extension part. To achieve this
-- we mark the inherited discriminants as not visible.
if Is_Tagged and then Inherit_Discr then
D := First_Discriminant (Derived_Base);
while Present (D) loop
Set_Is_Immediately_Visible (D, False);
Next_Discriminant (D);
end loop;
end if;
return Assoc_List;
end Inherit_Components;
-----------------------
-- Is_Null_Extension --
-----------------------
function Is_Null_Extension (T : Entity_Id) return Boolean is
Full_Type_Decl : constant Node_Id := Parent (T);
Full_Type_Defn : constant Node_Id := Type_Definition (Full_Type_Decl);
Comp_List : Node_Id;
First_Comp : Node_Id;
begin
if not Is_Tagged_Type (T)
or else Nkind (Full_Type_Defn) /= N_Derived_Type_Definition
then
return False;
end if;
Comp_List := Component_List (Record_Extension_Part (Full_Type_Defn));
if Present (Discriminant_Specifications (Full_Type_Decl)) then
return False;
elsif Present (Comp_List)
and then Is_Non_Empty_List (Component_Items (Comp_List))
then
First_Comp := First (Component_Items (Comp_List));
return Chars (Defining_Identifier (First_Comp)) = Name_uParent
and then No (Next (First_Comp));
else
return True;
end if;
end Is_Null_Extension;
------------------------------
-- Is_Valid_Constraint_Kind --
------------------------------
function Is_Valid_Constraint_Kind
(T_Kind : Type_Kind;
Constraint_Kind : Node_Kind) return Boolean
is
begin
case T_Kind is
when Enumeration_Kind |
Integer_Kind =>
return Constraint_Kind = N_Range_Constraint;
when Decimal_Fixed_Point_Kind =>
return
Constraint_Kind = N_Digits_Constraint
or else
Constraint_Kind = N_Range_Constraint;
when Ordinary_Fixed_Point_Kind =>
return
Constraint_Kind = N_Delta_Constraint
or else
Constraint_Kind = N_Range_Constraint;
when Float_Kind =>
return
Constraint_Kind = N_Digits_Constraint
or else
Constraint_Kind = N_Range_Constraint;
when Access_Kind |
Array_Kind |
E_Record_Type |
E_Record_Subtype |
Class_Wide_Kind |
E_Incomplete_Type |
Private_Kind |
Concurrent_Kind =>
return Constraint_Kind = N_Index_Or_Discriminant_Constraint;
when others =>
return True; -- Error will be detected later
end case;
end Is_Valid_Constraint_Kind;
--------------------------
-- Is_Visible_Component --
--------------------------
function Is_Visible_Component (C : Entity_Id) return Boolean is
Original_Comp : Entity_Id := Empty;
Original_Scope : Entity_Id;
Type_Scope : Entity_Id;
function Is_Local_Type (Typ : Entity_Id) return Boolean;
-- Check whether parent type of inherited component is declared locally,
-- possibly within a nested package or instance. The current scope is
-- the derived record itself.
-------------------
-- Is_Local_Type --
-------------------
function Is_Local_Type (Typ : Entity_Id) return Boolean is
Scop : Entity_Id;
begin
Scop := Scope (Typ);
while Present (Scop)
and then Scop /= Standard_Standard
loop
if Scop = Scope (Current_Scope) then
return True;
end if;
Scop := Scope (Scop);
end loop;
return False;
end Is_Local_Type;
-- Start of processing for Is_Visible_Component
begin
if Ekind (C) = E_Component
or else Ekind (C) = E_Discriminant
then
Original_Comp := Original_Record_Component (C);
end if;
if No (Original_Comp) then
-- Premature usage, or previous error
return False;
else
Original_Scope := Scope (Original_Comp);
Type_Scope := Scope (Base_Type (Scope (C)));
end if;
-- This test only concerns tagged types
if not Is_Tagged_Type (Original_Scope) then
return True;
-- If it is _Parent or _Tag, there is no visibility issue
elsif not Comes_From_Source (Original_Comp) then
return True;
-- If we are in the body of an instantiation, the component is visible
-- even when the parent type (possibly defined in an enclosing unit or
-- in a parent unit) might not.
elsif In_Instance_Body then
return True;
-- Discriminants are always visible
elsif Ekind (Original_Comp) = E_Discriminant
and then not Has_Unknown_Discriminants (Original_Scope)
then
return True;
-- If the component has been declared in an ancestor which is currently
-- a private type, then it is not visible. The same applies if the
-- component's containing type is not in an open scope and the original
-- component's enclosing type is a visible full type of a private type
-- (which can occur in cases where an attempt is being made to reference
-- a component in a sibling package that is inherited from a visible
-- component of a type in an ancestor package; the component in the
-- sibling package should not be visible even though the component it
-- inherited from is visible). This does not apply however in the case
-- where the scope of the type is a private child unit, or when the
-- parent comes from a local package in which the ancestor is currently
-- visible. The latter suppression of visibility is needed for cases
-- that are tested in B730006.
elsif Is_Private_Type (Original_Scope)
or else
(not Is_Private_Descendant (Type_Scope)
and then not In_Open_Scopes (Type_Scope)
and then Has_Private_Declaration (Original_Scope))
then
-- If the type derives from an entity in a formal package, there
-- are no additional visible components.
if Nkind (Original_Node (Unit_Declaration_Node (Type_Scope))) =
N_Formal_Package_Declaration
then
return False;
-- if we are not in the private part of the current package, there
-- are no additional visible components.
elsif Ekind (Scope (Current_Scope)) = E_Package
and then not In_Private_Part (Scope (Current_Scope))
then
return False;
else
return
Is_Child_Unit (Cunit_Entity (Current_Sem_Unit))
and then Is_Local_Type (Type_Scope);
end if;
-- There is another weird way in which a component may be invisible
-- when the private and the full view are not derived from the same
-- ancestor. Here is an example :
-- type A1 is tagged record F1 : integer; end record;
-- type A2 is new A1 with record F2 : integer; end record;
-- type T is new A1 with private;
-- private
-- type T is new A2 with null record;
-- In this case, the full view of T inherits F1 and F2 but the private
-- view inherits only F1
else
declare
Ancestor : Entity_Id := Scope (C);
begin
loop
if Ancestor = Original_Scope then
return True;
elsif Ancestor = Etype (Ancestor) then
return False;
end if;
Ancestor := Etype (Ancestor);
end loop;
-- LLVM local deleted unreachable line
end;
end if;
end Is_Visible_Component;
--------------------------
-- Make_Class_Wide_Type --
--------------------------
procedure Make_Class_Wide_Type (T : Entity_Id) is
CW_Type : Entity_Id;
CW_Name : Name_Id;
Next_E : Entity_Id;
begin
-- The class wide type can have been defined by the partial view in
-- which case everything is already done
if Present (Class_Wide_Type (T)) then
return;
end if;
CW_Type :=
New_External_Entity (E_Void, Scope (T), Sloc (T), T, 'C', 0, 'T');
-- Inherit root type characteristics
CW_Name := Chars (CW_Type);
Next_E := Next_Entity (CW_Type);
Copy_Node (T, CW_Type);
Set_Comes_From_Source (CW_Type, False);
Set_Chars (CW_Type, CW_Name);
Set_Parent (CW_Type, Parent (T));
Set_Next_Entity (CW_Type, Next_E);
Set_Has_Delayed_Freeze (CW_Type);
-- Customize the class-wide type: It has no prim. op., it cannot be
-- abstract and its Etype points back to the specific root type.
Set_Ekind (CW_Type, E_Class_Wide_Type);
Set_Is_Tagged_Type (CW_Type, True);
Set_Primitive_Operations (CW_Type, New_Elmt_List);
Set_Is_Abstract (CW_Type, False);
Set_Is_Constrained (CW_Type, False);
Set_Is_First_Subtype (CW_Type, Is_First_Subtype (T));
Init_Size_Align (CW_Type);
if Ekind (T) = E_Class_Wide_Subtype then
Set_Etype (CW_Type, Etype (Base_Type (T)));
else
Set_Etype (CW_Type, T);
end if;
-- If this is the class_wide type of a constrained subtype, it does
-- not have discriminants.
Set_Has_Discriminants (CW_Type,
Has_Discriminants (T) and then not Is_Constrained (T));
Set_Has_Unknown_Discriminants (CW_Type, True);
Set_Class_Wide_Type (T, CW_Type);
Set_Equivalent_Type (CW_Type, Empty);
-- The class-wide type of a class-wide type is itself (RM 3.9(14))
Set_Class_Wide_Type (CW_Type, CW_Type);
end Make_Class_Wide_Type;
----------------
-- Make_Index --
----------------
procedure Make_Index
(I : Node_Id;
Related_Nod : Node_Id;
Related_Id : Entity_Id := Empty;
Suffix_Index : Nat := 1)
is
R : Node_Id;
T : Entity_Id;
Def_Id : Entity_Id := Empty;
Found : Boolean := False;
begin
-- For a discrete range used in a constrained array definition and
-- defined by a range, an implicit conversion to the predefined type
-- INTEGER is assumed if each bound is either a numeric literal, a named
-- number, or an attribute, and the type of both bounds (prior to the
-- implicit conversion) is the type universal_integer. Otherwise, both
-- bounds must be of the same discrete type, other than universal
-- integer; this type must be determinable independently of the
-- context, but using the fact that the type must be discrete and that
-- both bounds must have the same type.
-- Character literals also have a universal type in the absence of
-- of additional context, and are resolved to Standard_Character.
if Nkind (I) = N_Range then
-- The index is given by a range constraint. The bounds are known
-- to be of a consistent type.
if not Is_Overloaded (I) then
T := Etype (I);
-- If the bounds are universal, choose the specific predefined
-- type.
if T = Universal_Integer then
T := Standard_Integer;
elsif T = Any_Character then
if Ada_Version >= Ada_95 then
Error_Msg_N
("ambiguous character literals (could be Wide_Character)",
I);
end if;
T := Standard_Character;
end if;
else
T := Any_Type;
declare
Ind : Interp_Index;
It : Interp;
begin
Get_First_Interp (I, Ind, It);
while Present (It.Typ) loop
if Is_Discrete_Type (It.Typ) then
if Found
and then not Covers (It.Typ, T)
and then not Covers (T, It.Typ)
then
Error_Msg_N ("ambiguous bounds in discrete range", I);
exit;
else
T := It.Typ;
Found := True;
end if;
end if;
Get_Next_Interp (Ind, It);
end loop;
if T = Any_Type then
Error_Msg_N ("discrete type required for range", I);
Set_Etype (I, Any_Type);
return;
elsif T = Universal_Integer then
T := Standard_Integer;
end if;
end;
end if;
if not Is_Discrete_Type (T) then
Error_Msg_N ("discrete type required for range", I);
Set_Etype (I, Any_Type);
return;
end if;
if Nkind (Low_Bound (I)) = N_Attribute_Reference
and then Attribute_Name (Low_Bound (I)) = Name_First
and then Is_Entity_Name (Prefix (Low_Bound (I)))
and then Is_Type (Entity (Prefix (Low_Bound (I))))
and then Is_Discrete_Type (Entity (Prefix (Low_Bound (I))))
then
-- The type of the index will be the type of the prefix, as long
-- as the upper bound is 'Last of the same type.
Def_Id := Entity (Prefix (Low_Bound (I)));
if Nkind (High_Bound (I)) /= N_Attribute_Reference
or else Attribute_Name (High_Bound (I)) /= Name_Last
or else not Is_Entity_Name (Prefix (High_Bound (I)))
or else Entity (Prefix (High_Bound (I))) /= Def_Id
then
Def_Id := Empty;
end if;
end if;
R := I;
Process_Range_Expr_In_Decl (R, T);
elsif Nkind (I) = N_Subtype_Indication then
-- The index is given by a subtype with a range constraint
T := Base_Type (Entity (Subtype_Mark (I)));
if not Is_Discrete_Type (T) then
Error_Msg_N ("discrete type required for range", I);
Set_Etype (I, Any_Type);
return;
end if;
R := Range_Expression (Constraint (I));
Resolve (R, T);
Process_Range_Expr_In_Decl (R, Entity (Subtype_Mark (I)));
elsif Nkind (I) = N_Attribute_Reference then
-- The parser guarantees that the attribute is a RANGE attribute
-- If the node denotes the range of a type mark, that is also the
-- resulting type, and we do no need to create an Itype for it.
if Is_Entity_Name (Prefix (I))
and then Comes_From_Source (I)
and then Is_Type (Entity (Prefix (I)))
and then Is_Discrete_Type (Entity (Prefix (I)))
then
Def_Id := Entity (Prefix (I));
end if;
Analyze_And_Resolve (I);
T := Etype (I);
R := I;
-- If none of the above, must be a subtype. We convert this to a
-- range attribute reference because in the case of declared first
-- named subtypes, the types in the range reference can be different
-- from the type of the entity. A range attribute normalizes the
-- reference and obtains the correct types for the bounds.
-- This transformation is in the nature of an expansion, is only
-- done if expansion is active. In particular, it is not done on
-- formal generic types, because we need to retain the name of the
-- original index for instantiation purposes.
else
if not Is_Entity_Name (I) or else not Is_Type (Entity (I)) then
Error_Msg_N ("invalid subtype mark in discrete range ", I);
Set_Etype (I, Any_Integer);
return;
else
-- The type mark may be that of an incomplete type. It is only
-- now that we can get the full view, previous analysis does
-- not look specifically for a type mark.
Set_Entity (I, Get_Full_View (Entity (I)));
Set_Etype (I, Entity (I));
Def_Id := Entity (I);
if not Is_Discrete_Type (Def_Id) then
Error_Msg_N ("discrete type required for index", I);
Set_Etype (I, Any_Type);
return;
end if;
end if;
if Expander_Active then
Rewrite (I,
Make_Attribute_Reference (Sloc (I),
Attribute_Name => Name_Range,
Prefix => Relocate_Node (I)));
-- The original was a subtype mark that does not freeze. This
-- means that the rewritten version must not freeze either.
Set_Must_Not_Freeze (I);
Set_Must_Not_Freeze (Prefix (I));
-- Is order critical??? if so, document why, if not
-- use Analyze_And_Resolve
Analyze (I);
T := Etype (I);
Resolve (I);
R := I;
-- If expander is inactive, type is legal, nothing else to construct
else
return;
end if;
end if;
if not Is_Discrete_Type (T) then
Error_Msg_N ("discrete type required for range", I);
Set_Etype (I, Any_Type);
return;
elsif T = Any_Type then
Set_Etype (I, Any_Type);
return;
end if;
-- We will now create the appropriate Itype to describe the range, but
-- first a check. If we originally had a subtype, then we just label
-- the range with this subtype. Not only is there no need to construct
-- a new subtype, but it is wrong to do so for two reasons:
-- 1. A legality concern, if we have a subtype, it must not freeze,
-- and the Itype would cause freezing incorrectly
-- 2. An efficiency concern, if we created an Itype, it would not be
-- recognized as the same type for the purposes of eliminating
-- checks in some circumstances.
-- We signal this case by setting the subtype entity in Def_Id
if No (Def_Id) then
Def_Id :=
Create_Itype (E_Void, Related_Nod, Related_Id, 'D', Suffix_Index);
Set_Etype (Def_Id, Base_Type (T));
if Is_Signed_Integer_Type (T) then
Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
elsif Is_Modular_Integer_Type (T) then
Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
else
Set_Ekind (Def_Id, E_Enumeration_Subtype);
Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
Set_First_Literal (Def_Id, First_Literal (T));
end if;
Set_Size_Info (Def_Id, (T));
Set_RM_Size (Def_Id, RM_Size (T));
Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
Set_Scalar_Range (Def_Id, R);
Conditional_Delay (Def_Id, T);
-- In the subtype indication case, if the immediate parent of the
-- new subtype is non-static, then the subtype we create is non-
-- static, even if its bounds are static.
if Nkind (I) = N_Subtype_Indication
and then not Is_Static_Subtype (Entity (Subtype_Mark (I)))
then
Set_Is_Non_Static_Subtype (Def_Id);
end if;
end if;
-- Final step is to label the index with this constructed type
Set_Etype (I, Def_Id);
end Make_Index;
------------------------------
-- Modular_Type_Declaration --
------------------------------
procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id) is
Mod_Expr : constant Node_Id := Expression (Def);
M_Val : Uint;
procedure Set_Modular_Size (Bits : Int);
-- Sets RM_Size to Bits, and Esize to normal word size above this
----------------------
-- Set_Modular_Size --
----------------------
procedure Set_Modular_Size (Bits : Int) is
begin
Set_RM_Size (T, UI_From_Int (Bits));
if Bits <= 8 then
Init_Esize (T, 8);
elsif Bits <= 16 then
Init_Esize (T, 16);
elsif Bits <= 32 then
Init_Esize (T, 32);
else
Init_Esize (T, System_Max_Binary_Modulus_Power);
end if;
end Set_Modular_Size;
-- Start of processing for Modular_Type_Declaration
begin
Analyze_And_Resolve (Mod_Expr, Any_Integer);
Set_Etype (T, T);
Set_Ekind (T, E_Modular_Integer_Type);
Init_Alignment (T);
Set_Is_Constrained (T);
if not Is_OK_Static_Expression (Mod_Expr) then
Flag_Non_Static_Expr
("non-static expression used for modular type bound!", Mod_Expr);
M_Val := 2 ** System_Max_Binary_Modulus_Power;
else
M_Val := Expr_Value (Mod_Expr);
end if;
if M_Val < 1 then
Error_Msg_N ("modulus value must be positive", Mod_Expr);
M_Val := 2 ** System_Max_Binary_Modulus_Power;
end if;
Set_Modulus (T, M_Val);
-- Create bounds for the modular type based on the modulus given in
-- the type declaration and then analyze and resolve those bounds.
Set_Scalar_Range (T,
Make_Range (Sloc (Mod_Expr),
Low_Bound =>
Make_Integer_Literal (Sloc (Mod_Expr), 0),
High_Bound =>
Make_Integer_Literal (Sloc (Mod_Expr), M_Val - 1)));
-- Properly analyze the literals for the range. We do this manually
-- because we can't go calling Resolve, since we are resolving these
-- bounds with the type, and this type is certainly not complete yet!
Set_Etype (Low_Bound (Scalar_Range (T)), T);
Set_Etype (High_Bound (Scalar_Range (T)), T);
Set_Is_Static_Expression (Low_Bound (Scalar_Range (T)));
Set_Is_Static_Expression (High_Bound (Scalar_Range (T)));
-- Loop through powers of two to find number of bits required
for Bits in Int range 0 .. System_Max_Binary_Modulus_Power loop
-- Binary case
if M_Val = 2 ** Bits then
Set_Modular_Size (Bits);
return;
-- Non-binary case
elsif M_Val < 2 ** Bits then
Set_Non_Binary_Modulus (T);
if Bits > System_Max_Nonbinary_Modulus_Power then
Error_Msg_Uint_1 :=
UI_From_Int (System_Max_Nonbinary_Modulus_Power);
Error_Msg_N
("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr);
Set_Modular_Size (System_Max_Binary_Modulus_Power);
return;
else
-- In the non-binary case, set size as per RM 13.3(55)
Set_Modular_Size (Bits);
return;
end if;
end if;
end loop;
-- If we fall through, then the size exceed System.Max_Binary_Modulus
-- so we just signal an error and set the maximum size.
Error_Msg_Uint_1 := UI_From_Int (System_Max_Binary_Modulus_Power);
Error_Msg_N ("modulus exceeds limit (2 '*'*^)", Mod_Expr);
Set_Modular_Size (System_Max_Binary_Modulus_Power);
Init_Alignment (T);
end Modular_Type_Declaration;
--------------------------
-- New_Concatenation_Op --
--------------------------
procedure New_Concatenation_Op (Typ : Entity_Id) is
Loc : constant Source_Ptr := Sloc (Typ);
Op : Entity_Id;
function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id;
-- Create abbreviated declaration for the formal of a predefined
-- Operator 'Op' of type 'Typ'
--------------------
-- Make_Op_Formal --
--------------------
function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id is
Formal : Entity_Id;
begin
Formal := New_Internal_Entity (E_In_Parameter, Op, Loc, 'P');
Set_Etype (Formal, Typ);
Set_Mechanism (Formal, Default_Mechanism);
return Formal;
end Make_Op_Formal;
-- Start of processing for New_Concatenation_Op
begin
Op := Make_Defining_Operator_Symbol (Loc, Name_Op_Concat);
Set_Ekind (Op, E_Operator);
Set_Scope (Op, Current_Scope);
Set_Etype (Op, Typ);
Set_Homonym (Op, Get_Name_Entity_Id (Name_Op_Concat));
Set_Is_Immediately_Visible (Op);
Set_Is_Intrinsic_Subprogram (Op);
Set_Has_Completion (Op);
Append_Entity (Op, Current_Scope);
Set_Name_Entity_Id (Name_Op_Concat, Op);
Append_Entity (Make_Op_Formal (Typ, Op), Op);
Append_Entity (Make_Op_Formal (Typ, Op), Op);
end New_Concatenation_Op;
-------------------------------------------
-- Ordinary_Fixed_Point_Type_Declaration --
-------------------------------------------
procedure Ordinary_Fixed_Point_Type_Declaration
(T : Entity_Id;
Def : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Def);
Delta_Expr : constant Node_Id := Delta_Expression (Def);
RRS : constant Node_Id := Real_Range_Specification (Def);
Implicit_Base : Entity_Id;
Delta_Val : Ureal;
Small_Val : Ureal;
Low_Val : Ureal;
High_Val : Ureal;
begin
Check_Restriction (No_Fixed_Point, Def);
-- Create implicit base type
Implicit_Base :=
Create_Itype (E_Ordinary_Fixed_Point_Type, Parent (Def), T, 'B');
Set_Etype (Implicit_Base, Implicit_Base);
-- Analyze and process delta expression
Analyze_And_Resolve (Delta_Expr, Any_Real);
Check_Delta_Expression (Delta_Expr);
Delta_Val := Expr_Value_R (Delta_Expr);
Set_Delta_Value (Implicit_Base, Delta_Val);
-- Compute default small from given delta, which is the largest power
-- of two that does not exceed the given delta value.
declare
Tmp : Ureal;
Scale : Int;
begin
Tmp := Ureal_1;
Scale := 0;
if Delta_Val < Ureal_1 then
while Delta_Val < Tmp loop
Tmp := Tmp / Ureal_2;
Scale := Scale + 1;
end loop;
else
loop
Tmp := Tmp * Ureal_2;
exit when Tmp > Delta_Val;
Scale := Scale - 1;
end loop;
end if;
Small_Val := UR_From_Components (Uint_1, UI_From_Int (Scale), 2);
end;
Set_Small_Value (Implicit_Base, Small_Val);
-- If no range was given, set a dummy range
if RRS <= Empty_Or_Error then
Low_Val := -Small_Val;
High_Val := Small_Val;
-- Otherwise analyze and process given range
else
declare
Low : constant Node_Id := Low_Bound (RRS);
High : constant Node_Id := High_Bound (RRS);
begin
Analyze_And_Resolve (Low, Any_Real);
Analyze_And_Resolve (High, Any_Real);
Check_Real_Bound (Low);
Check_Real_Bound (High);
-- Obtain and set the range
Low_Val := Expr_Value_R (Low);
High_Val := Expr_Value_R (High);
if Low_Val > High_Val then
Error_Msg_NE ("?fixed point type& has null range", Def, T);
end if;
end;
end if;
-- The range for both the implicit base and the declared first subtype
-- cannot be set yet, so we use the special routine Set_Fixed_Range to
-- set a temporary range in place. Note that the bounds of the base
-- type will be widened to be symmetrical and to fill the available
-- bits when the type is frozen.
-- We could do this with all discrete types, and probably should, but
-- we absolutely have to do it for fixed-point, since the end-points
-- of the range and the size are determined by the small value, which
-- could be reset before the freeze point.
Set_Fixed_Range (Implicit_Base, Loc, Low_Val, High_Val);
Set_Fixed_Range (T, Loc, Low_Val, High_Val);
Init_Size_Align (Implicit_Base);
-- Complete definition of first subtype
Set_Ekind (T, E_Ordinary_Fixed_Point_Subtype);
Set_Etype (T, Implicit_Base);
Init_Size_Align (T);
Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
Set_Small_Value (T, Small_Val);
Set_Delta_Value (T, Delta_Val);
Set_Is_Constrained (T);
end Ordinary_Fixed_Point_Type_Declaration;
----------------------------------------
-- Prepare_Private_Subtype_Completion --
----------------------------------------
procedure Prepare_Private_Subtype_Completion
(Id : Entity_Id;
Related_Nod : Node_Id)
is
Id_B : constant Entity_Id := Base_Type (Id);
Full_B : constant Entity_Id := Full_View (Id_B);
Full : Entity_Id;
begin
if Present (Full_B) then
-- The Base_Type is already completed, we can complete the subtype
-- now. We have to create a new entity with the same name, Thus we
-- can't use Create_Itype.
-- This is messy, should be fixed ???
Full := Make_Defining_Identifier (Sloc (Id), Chars (Id));
Set_Is_Itype (Full);
Set_Associated_Node_For_Itype (Full, Related_Nod);
Complete_Private_Subtype (Id, Full, Full_B, Related_Nod);
end if;
-- The parent subtype may be private, but the base might not, in some
-- nested instances. In that case, the subtype does not need to be
-- exchanged. It would still be nice to make private subtypes and their
-- bases consistent at all times ???
if Is_Private_Type (Id_B) then
Append_Elmt (Id, Private_Dependents (Id_B));
end if;
end Prepare_Private_Subtype_Completion;
---------------------------
-- Process_Discriminants --
---------------------------
procedure Process_Discriminants
(N : Node_Id;
Prev : Entity_Id := Empty)
is
Elist : constant Elist_Id := New_Elmt_List;
Id : Node_Id;
Discr : Node_Id;
Discr_Number : Uint;
Discr_Type : Entity_Id;
Default_Present : Boolean := False;
Default_Not_Present : Boolean := False;
begin
-- A composite type other than an array type can have discriminants.
-- Discriminants of non-limited types must have a discrete type.
-- On entry, the current scope is the composite type.
-- The discriminants are initially entered into the scope of the type
-- via Enter_Name with the default Ekind of E_Void to prevent premature
-- use, as explained at the end of this procedure.
Discr := First (Discriminant_Specifications (N));
while Present (Discr) loop
Enter_Name (Defining_Identifier (Discr));
-- For navigation purposes we add a reference to the discriminant
-- in the entity for the type. If the current declaration is a
-- completion, place references on the partial view. Otherwise the
-- type is the current scope.
if Present (Prev) then
-- The references go on the partial view, if present. If the
-- partial view has discriminants, the references have been
-- generated already.
if not Has_Discriminants (Prev) then
Generate_Reference (Prev, Defining_Identifier (Discr), 'd');
end if;
else
Generate_Reference
(Current_Scope, Defining_Identifier (Discr), 'd');
end if;
if Nkind (Discriminant_Type (Discr)) = N_Access_Definition then
Discr_Type := Access_Definition (Discr, Discriminant_Type (Discr));
-- Ada 2005 (AI-230): Access discriminants are now allowed for
-- nonlimited types, and are treated like other components of
-- anonymous access types in terms of accessibility.
if not Is_Concurrent_Type (Current_Scope)
and then not Is_Concurrent_Record_Type (Current_Scope)
and then not Is_Limited_Record (Current_Scope)
and then Ekind (Current_Scope) /= E_Limited_Private_Type
then
Set_Is_Local_Anonymous_Access (Discr_Type);
end if;
-- Ada 2005 (AI-254)
if Present (Access_To_Subprogram_Definition
(Discriminant_Type (Discr)))
and then Protected_Present (Access_To_Subprogram_Definition
(Discriminant_Type (Discr)))
then
Discr_Type :=
Replace_Anonymous_Access_To_Protected_Subprogram
(Discr, Discr_Type);
end if;
else
Find_Type (Discriminant_Type (Discr));
Discr_Type := Etype (Discriminant_Type (Discr));
if Error_Posted (Discriminant_Type (Discr)) then
Discr_Type := Any_Type;
end if;
end if;
if Is_Access_Type (Discr_Type) then
-- Ada 2005 (AI-230): Access discriminant allowed in non-limited
-- record types
if Ada_Version < Ada_05 then
Check_Access_Discriminant_Requires_Limited
(Discr, Discriminant_Type (Discr));
end if;
if Ada_Version = Ada_83 and then Comes_From_Source (Discr) then
Error_Msg_N
("(Ada 83) access discriminant not allowed", Discr);
end if;
elsif not Is_Discrete_Type (Discr_Type) then
Error_Msg_N ("discriminants must have a discrete or access type",
Discriminant_Type (Discr));
end if;
Set_Etype (Defining_Identifier (Discr), Discr_Type);
-- If a discriminant specification includes the assignment compound
-- delimiter followed by an expression, the expression is the default
-- expression of the discriminant; the default expression must be of
-- the type of the discriminant. (RM 3.7.1) Since this expression is
-- a default expression, we do the special preanalysis, since this
-- expression does not freeze (see "Handling of Default and Per-
-- Object Expressions" in spec of package Sem).
if Present (Expression (Discr)) then
Analyze_Per_Use_Expression (Expression (Discr), Discr_Type);
if Nkind (N) = N_Formal_Type_Declaration then
Error_Msg_N
("discriminant defaults not allowed for formal type",
Expression (Discr));
-- Tagged types cannot have defaulted discriminants, but a
-- non-tagged private type with defaulted discriminants
-- can have a tagged completion.
elsif Is_Tagged_Type (Current_Scope)
and then Comes_From_Source (N)
then
Error_Msg_N
("discriminants of tagged type cannot have defaults",
Expression (Discr));
else
Default_Present := True;
Append_Elmt (Expression (Discr), Elist);
-- Tag the defining identifiers for the discriminants with
-- their corresponding default expressions from the tree.
Set_Discriminant_Default_Value
(Defining_Identifier (Discr), Expression (Discr));
end if;
else
Default_Not_Present := True;
end if;
-- Ada 2005 (AI-231): Create an Itype that is a duplicate of
-- Discr_Type but with the null-exclusion attribute
if Ada_Version >= Ada_05 then
-- Ada 2005 (AI-231): Static checks
if Can_Never_Be_Null (Discr_Type) then
Null_Exclusion_Static_Checks (Discr);
elsif Is_Access_Type (Discr_Type)
and then Null_Exclusion_Present (Discr)
-- No need to check itypes because in their case this check
-- was done at their point of creation
and then not Is_Itype (Discr_Type)
then
if Can_Never_Be_Null (Discr_Type) then
Error_Msg_N
("(Ada 2005) already a null-excluding type", Discr);
end if;
Set_Etype (Defining_Identifier (Discr),
Create_Null_Excluding_Itype
(T => Discr_Type,
Related_Nod => Discr));
end if;
end if;
Next (Discr);
end loop;
-- An element list consisting of the default expressions of the
-- discriminants is constructed in the above loop and used to set
-- the Discriminant_Constraint attribute for the type. If an object
-- is declared of this (record or task) type without any explicit
-- discriminant constraint given, this element list will form the
-- actual parameters for the corresponding initialization procedure
-- for the type.
Set_Discriminant_Constraint (Current_Scope, Elist);
Set_Stored_Constraint (Current_Scope, No_Elist);
-- Default expressions must be provided either for all or for none
-- of the discriminants of a discriminant part. (RM 3.7.1)
if Default_Present and then Default_Not_Present then
Error_Msg_N
("incomplete specification of defaults for discriminants", N);
end if;
-- The use of the name of a discriminant is not allowed in default
-- expressions of a discriminant part if the specification of the
-- discriminant is itself given in the discriminant part. (RM 3.7.1)
-- To detect this, the discriminant names are entered initially with an
-- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
-- attempt to use a void entity (for example in an expression that is
-- type-checked) produces the error message: premature usage. Now after
-- completing the semantic analysis of the discriminant part, we can set
-- the Ekind of all the discriminants appropriately.
Discr := First (Discriminant_Specifications (N));
Discr_Number := Uint_1;
while Present (Discr) loop
Id := Defining_Identifier (Discr);
Set_Ekind (Id, E_Discriminant);
Init_Component_Location (Id);
Init_Esize (Id);
Set_Discriminant_Number (Id, Discr_Number);
-- Make sure this is always set, even in illegal programs
Set_Corresponding_Discriminant (Id, Empty);
-- Initialize the Original_Record_Component to the entity itself.
-- Inherit_Components will propagate the right value to
-- discriminants in derived record types.
Set_Original_Record_Component (Id, Id);
-- Create the discriminal for the discriminant
Build_Discriminal (Id);
Next (Discr);
Discr_Number := Discr_Number + 1;
end loop;
Set_Has_Discriminants (Current_Scope);
end Process_Discriminants;
-----------------------
-- Process_Full_View --
-----------------------
procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id) is
Priv_Parent : Entity_Id;
Full_Parent : Entity_Id;
Full_Indic : Node_Id;
procedure Collect_Implemented_Interfaces
(Typ : Entity_Id;
Ifaces : Elist_Id);
-- Ada 2005: Gather all the interfaces that Typ directly or
-- inherently implements. Duplicate entries are not added to
-- the list Ifaces.
function Contain_Interface
(Iface : Entity_Id;
Ifaces : Elist_Id) return Boolean;
-- Ada 2005: Determine whether Iface is present in the list Ifaces
function Find_Hidden_Interface
(Src : Elist_Id;
Dest : Elist_Id) return Entity_Id;
-- Ada 2005: Determine whether the interfaces in list Src are all
-- present in the list Dest. Return the first differing interface,
-- or Empty otherwise.
------------------------------------
-- Collect_Implemented_Interfaces --
------------------------------------
procedure Collect_Implemented_Interfaces
(Typ : Entity_Id;
Ifaces : Elist_Id)
is
Iface : Entity_Id;
Iface_Elmt : Elmt_Id;
begin
-- Abstract interfaces are only associated with tagged record types
if not Is_Tagged_Type (Typ)
or else not Is_Record_Type (Typ)
then
return;
end if;
-- Implementations of the form:
-- type Typ is new Iface ...
if Is_Interface (Etype (Typ))
and then not Contain_Interface (Etype (Typ), Ifaces)
then
Append_Elmt (Etype (Typ), Ifaces);
end if;
-- Implementations of the form:
-- type Typ is ... and Iface ...
if Present (Abstract_Interfaces (Typ)) then
Iface_Elmt := First_Elmt (Abstract_Interfaces (Typ));
while Present (Iface_Elmt) loop
Iface := Node (Iface_Elmt);
pragma Assert (Is_Interface (Iface));
if not Contain_Interface (Iface, Ifaces) then
Append_Elmt (Iface, Ifaces);
Collect_Implemented_Interfaces (Iface, Ifaces);
end if;
Next_Elmt (Iface_Elmt);
end loop;
end if;
-- Implementations of the form:
-- type Typ is new Parent_Typ and ...
if Ekind (Typ) = E_Record_Type
and then Present (Parent_Subtype (Typ))
then
Collect_Implemented_Interfaces (Parent_Subtype (Typ), Ifaces);
-- Implementations of the form:
-- type Typ is ... with private;
elsif Ekind (Typ) = E_Record_Type_With_Private
and then Present (Full_View (Typ))
and then Etype (Typ) /= Full_View (Typ)
and then Etype (Typ) /= Typ
then
Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
end if;
end Collect_Implemented_Interfaces;
-----------------------
-- Contain_Interface --
-----------------------
function Contain_Interface
(Iface : Entity_Id;
Ifaces : Elist_Id) return Boolean
is
Iface_Elmt : Elmt_Id;
begin
if Present (Ifaces) then
Iface_Elmt := First_Elmt (Ifaces);
while Present (Iface_Elmt) loop
if Node (Iface_Elmt) = Iface then
return True;
end if;
Next_Elmt (Iface_Elmt);
end loop;
end if;
return False;
end Contain_Interface;
---------------------------
-- Find_Hidden_Interface --
---------------------------
function Find_Hidden_Interface
(Src : Elist_Id;
Dest : Elist_Id) return Entity_Id
is
Iface : Entity_Id;
Iface_Elmt : Elmt_Id;
begin
if Present (Src) and then Present (Dest) then
Iface_Elmt := First_Elmt (Src);
while Present (Iface_Elmt) loop
Iface := Node (Iface_Elmt);
if not Contain_Interface (Iface, Dest) then
return Iface;
end if;
Next_Elmt (Iface_Elmt);
end loop;
end if;
return Empty;
end Find_Hidden_Interface;
-- Start of processing for Process_Full_View
begin
-- First some sanity checks that must be done after semantic
-- decoration of the full view and thus cannot be placed with other
-- similar checks in Find_Type_Name
if not Is_Limited_Type (Priv_T)
and then (Is_Limited_Type (Full_T)
or else Is_Limited_Composite (Full_T))
then
Error_Msg_N
("completion of nonlimited type cannot be limited", Full_T);
Explain_Limited_Type (Full_T, Full_T);
elsif Is_Abstract (Full_T) and then not Is_Abstract (Priv_T) then
Error_Msg_N
("completion of nonabstract type cannot be abstract", Full_T);
elsif Is_Tagged_Type (Priv_T)
and then Is_Limited_Type (Priv_T)
and then not Is_Limited_Type (Full_T)
then
-- GNAT allow its own definition of Limited_Controlled to disobey
-- this rule in order in ease the implementation. The next test is
-- safe because Root_Controlled is defined in a private system child
if Etype (Full_T) = Full_View (RTE (RE_Root_Controlled)) then
Set_Is_Limited_Composite (Full_T);
else
Error_Msg_N
("completion of limited tagged type must be limited", Full_T);
end if;
elsif Is_Generic_Type (Priv_T) then
Error_Msg_N ("generic type cannot have a completion", Full_T);
end if;
if Ada_Version >= Ada_05
and then Is_Tagged_Type (Priv_T)
and then Is_Tagged_Type (Full_T)
then
declare
Iface : Entity_Id;
Priv_T_Ifaces : constant Elist_Id := New_Elmt_List;
Full_T_Ifaces : constant Elist_Id := New_Elmt_List;
begin
Collect_Implemented_Interfaces (Priv_T, Priv_T_Ifaces);
Collect_Implemented_Interfaces (Full_T, Full_T_Ifaces);
-- Ada 2005 (AI-251): The partial view shall be a descendant of
-- an interface type if and only if the full type is descendant
-- of the interface type (AARM 7.3 (7.3/2).
Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
if Present (Iface) then
Error_Msg_NE ("interface & not implemented by full type " &
"('R'M'-2005 7.3 (7.3/2))", Priv_T, Iface);
end if;
Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
if Present (Iface) then
Error_Msg_NE ("interface & not implemented by partial view " &
"('R'M'-2005 7.3 (7.3/2))", Full_T, Iface);
end if;
end;
end if;
if Is_Tagged_Type (Priv_T)
and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
and then Is_Derived_Type (Full_T)
then
Priv_Parent := Etype (Priv_T);
-- The full view of a private extension may have been transformed
-- into an unconstrained derived type declaration and a subtype
-- declaration (see build_derived_record_type for details).
if Nkind (N) = N_Subtype_Declaration then
Full_Indic := Subtype_Indication (N);
Full_Parent := Etype (Base_Type (Full_T));
else
Full_Indic := Subtype_Indication (Type_Definition (N));
Full_Parent := Etype (Full_T);
end if;
-- Check that the parent type of the full type is a descendant of
-- the ancestor subtype given in the private extension. If either
-- entity has an Etype equal to Any_Type then we had some previous
-- error situation [7.3(8)].
if Priv_Parent = Any_Type or else Full_Parent = Any_Type then
return;
-- Ada 2005 (AI-251): Interfaces in the full-typ can be given in
-- any order. Therefore we don't have to check that its parent must
-- be a descendant of the parent of the private type declaration.
elsif Is_Interface (Priv_Parent)
and then Is_Interface (Full_Parent)
then
null;
-- Ada 2005 (AI-251): If the parent of the private type declaration
-- is an interface there is no need to check that it is an ancestor
-- of the associated full type declaration. The required tests for
-- this case case are performed by Build_Derived_Record_Type.
elsif not Is_Interface (Base_Type (Priv_Parent))
and then not Is_Ancestor (Base_Type (Priv_Parent), Full_Parent)
then
Error_Msg_N
("parent of full type must descend from parent"
& " of private extension", Full_Indic);
-- Check the rules of 7.3(10): if the private extension inherits
-- known discriminants, then the full type must also inherit those
-- discriminants from the same (ancestor) type, and the parent
-- subtype of the full type must be constrained if and only if
-- the ancestor subtype of the private extension is constrained.
elsif No (Discriminant_Specifications (Parent (Priv_T)))
and then not Has_Unknown_Discriminants (Priv_T)
and then Has_Discriminants (Base_Type (Priv_Parent))
then
declare
Priv_Indic : constant Node_Id :=
Subtype_Indication (Parent (Priv_T));
Priv_Constr : constant Boolean :=
Is_Constrained (Priv_Parent)
or else
Nkind (Priv_Indic) = N_Subtype_Indication
or else Is_Constrained (Entity (Priv_Indic));
Full_Constr : constant Boolean :=
Is_Constrained (Full_Parent)
or else
Nkind (Full_Indic) = N_Subtype_Indication
or else Is_Constrained (Entity (Full_Indic));
Priv_Discr : Entity_Id;
Full_Discr : Entity_Id;
begin
Priv_Discr := First_Discriminant (Priv_Parent);
Full_Discr := First_Discriminant (Full_Parent);
while Present (Priv_Discr) and then Present (Full_Discr) loop
if Original_Record_Component (Priv_Discr) =
Original_Record_Component (Full_Discr)
or else
Corresponding_Discriminant (Priv_Discr) =
Corresponding_Discriminant (Full_Discr)
then
null;
else
exit;
end if;
Next_Discriminant (Priv_Discr);
Next_Discriminant (Full_Discr);
end loop;
if Present (Priv_Discr) or else Present (Full_Discr) then
Error_Msg_N
("full view must inherit discriminants of the parent type"
& " used in the private extension", Full_Indic);
elsif Priv_Constr and then not Full_Constr then
Error_Msg_N
("parent subtype of full type must be constrained",
Full_Indic);
elsif Full_Constr and then not Priv_Constr then
Error_Msg_N
("parent subtype of full type must be unconstrained",
Full_Indic);
end if;
end;
-- Check the rules of 7.3(12): if a partial view has neither known
-- or unknown discriminants, then the full type declaration shall
-- define a definite subtype.
elsif not Has_Unknown_Discriminants (Priv_T)
and then not Has_Discriminants (Priv_T)
and then not Is_Constrained (Full_T)
then
Error_Msg_N
("full view must define a constrained type if partial view"
& " has no discriminants", Full_T);
end if;
-- ??????? Do we implement the following properly ?????
-- If the ancestor subtype of a private extension has constrained
-- discriminants, then the parent subtype of the full view shall
-- impose a statically matching constraint on those discriminants
-- [7.3(13)].
else
-- For untagged types, verify that a type without discriminants
-- is not completed with an unconstrained type.
if not Is_Indefinite_Subtype (Priv_T)
and then Is_Indefinite_Subtype (Full_T)
then
Error_Msg_N ("full view of type must be definite subtype", Full_T);
end if;
end if;
-- AI-419: verify that the use of "limited" is consistent
declare
Orig_Decl : constant Node_Id := Original_Node (N);
begin
if Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
and then not Limited_Present (Parent (Priv_T))
and then Nkind (Orig_Decl) = N_Full_Type_Declaration
and then Nkind
(Type_Definition (Orig_Decl)) = N_Derived_Type_Definition
and then Limited_Present (Type_Definition (Orig_Decl))
then
Error_Msg_N
("full view of non-limited extension cannot be limited", N);
end if;
end;
-- Ada 2005 AI-363: if the full view has discriminants with
-- defaults, it is illegal to declare constrained access subtypes
-- whose designated type is the current type. This allows objects
-- of the type that are declared in the heap to be unconstrained.
if not Has_Unknown_Discriminants (Priv_T)
and then not Has_Discriminants (Priv_T)
and then Has_Discriminants (Full_T)
and then
Present
(Discriminant_Default_Value (First_Discriminant (Full_T)))
then
Set_Has_Constrained_Partial_View (Full_T);
Set_Has_Constrained_Partial_View (Priv_T);
end if;
-- Create a full declaration for all its subtypes recorded in
-- Private_Dependents and swap them similarly to the base type. These
-- are subtypes that have been define before the full declaration of
-- the private type. We also swap the entry in Private_Dependents list
-- so we can properly restore the private view on exit from the scope.
declare
Priv_Elmt : Elmt_Id;
Priv : Entity_Id;
Full : Entity_Id;
begin
Priv_Elmt := First_Elmt (Private_Dependents (Priv_T));
while Present (Priv_Elmt) loop
Priv := Node (Priv_Elmt);
if Ekind (Priv) = E_Private_Subtype
or else Ekind (Priv) = E_Limited_Private_Subtype
or else Ekind (Priv) = E_Record_Subtype_With_Private
then
Full := Make_Defining_Identifier (Sloc (Priv), Chars (Priv));
Set_Is_Itype (Full);
Set_Parent (Full, Parent (Priv));
Set_Associated_Node_For_Itype (Full, N);
-- Now we need to complete the private subtype, but since the
-- base type has already been swapped, we must also swap the
-- subtypes (and thus, reverse the arguments in the call to
-- Complete_Private_Subtype).
Copy_And_Swap (Priv, Full);
Complete_Private_Subtype (Full, Priv, Full_T, N);
Replace_Elmt (Priv_Elmt, Full);
end if;
Next_Elmt (Priv_Elmt);
end loop;
end;
-- If the private view was tagged, copy the new Primitive
-- operations from the private view to the full view.
if Is_Tagged_Type (Full_T) then
declare
Priv_List : Elist_Id;
Full_List : constant Elist_Id := Primitive_Operations (Full_T);
P1, P2 : Elmt_Id;
Prim : Entity_Id;
D_Type : Entity_Id;
begin
if Is_Tagged_Type (Priv_T) then
Priv_List := Primitive_Operations (Priv_T);
P1 := First_Elmt (Priv_List);
while Present (P1) loop
Prim := Node (P1);
-- Transfer explicit primitives, not those inherited from
-- parent of partial view, which will be re-inherited on
-- the full view.
if Comes_From_Source (Prim) then
P2 := First_Elmt (Full_List);
while Present (P2) and then Node (P2) /= Prim loop
Next_Elmt (P2);
end loop;
-- If not found, that is a new one
if No (P2) then
Append_Elmt (Prim, Full_List);
end if;
end if;
Next_Elmt (P1);
end loop;
else
-- In this case the partial view is untagged, so here we
-- locate all of the earlier primitives that need to be
-- treated as dispatching (those that appear between the two
-- views). Note that these additional operations must all be
-- new operations (any earlier operations that override
-- inherited operations of the full view will already have
-- been inserted in the primitives list and marked as
-- dispatching by Check_Operation_From_Private_View. Note that
-- implicit "/=" operators are excluded from being added to
-- the primitives list since they shouldn't be treated as
-- dispatching (tagged "/=" is handled specially).
Prim := Next_Entity (Full_T);
while Present (Prim) and then Prim /= Priv_T loop
if Ekind (Prim) = E_Procedure
or else
Ekind (Prim) = E_Function
then
D_Type := Find_Dispatching_Type (Prim);
if D_Type = Full_T
and then (Chars (Prim) /= Name_Op_Ne
or else Comes_From_Source (Prim))
then
Check_Controlling_Formals (Full_T, Prim);
if not Is_Dispatching_Operation (Prim) then
Append_Elmt (Prim, Full_List);
Set_Is_Dispatching_Operation (Prim, True);
Set_DT_Position (Prim, No_Uint);
end if;
elsif Is_Dispatching_Operation (Prim)
and then D_Type /= Full_T
then
-- Verify that it is not otherwise controlled by
-- a formal or a return value of type T.
Check_Controlling_Formals (D_Type, Prim);
end if;
end if;
Next_Entity (Prim);
end loop;
end if;
-- For the tagged case, the two views can share the same
-- Primitive Operation list and the same class wide type.
-- Update attributes of the class-wide type which depend on
-- the full declaration.
if Is_Tagged_Type (Priv_T) then
Set_Primitive_Operations (Priv_T, Full_List);
Set_Class_Wide_Type
(Base_Type (Full_T), Class_Wide_Type (Priv_T));
-- Any other attributes should be propagated to C_W ???
Set_Has_Task (Class_Wide_Type (Priv_T), Has_Task (Full_T));
end if;
end;
end if;
end Process_Full_View;
-----------------------------------
-- Process_Incomplete_Dependents --
-----------------------------------
procedure Process_Incomplete_Dependents
(N : Node_Id;
Full_T : Entity_Id;
Inc_T : Entity_Id)
is
Inc_Elmt : Elmt_Id;
Priv_Dep : Entity_Id;
New_Subt : Entity_Id;
Disc_Constraint : Elist_Id;
begin
if No (Private_Dependents (Inc_T)) then
return;
end if;
-- Itypes that may be generated by the completion of an incomplete
-- subtype are not used by the back-end and not attached to the tree.
-- They are created only for constraint-checking purposes.
Inc_Elmt := First_Elmt (Private_Dependents (Inc_T));
while Present (Inc_Elmt) loop
Priv_Dep := Node (Inc_Elmt);
if Ekind (Priv_Dep) = E_Subprogram_Type then
-- An Access_To_Subprogram type may have a return type or a
-- parameter type that is incomplete. Replace with the full view.
if Etype (Priv_Dep) = Inc_T then
Set_Etype (Priv_Dep, Full_T);
end if;
declare
Formal : Entity_Id;
begin
Formal := First_Formal (Priv_Dep);
while Present (Formal) loop
if Etype (Formal) = Inc_T then
Set_Etype (Formal, Full_T);
end if;
Next_Formal (Formal);
end loop;
end;
elsif Is_Overloadable (Priv_Dep) then
-- A protected operation is never dispatching: only its
-- wrapper operation (which has convention Ada) is.
if Is_Tagged_Type (Full_T)
and then Convention (Priv_Dep) /= Convention_Protected
then
-- Subprogram has an access parameter whose designated type
-- was incomplete. Reexamine declaration now, because it may
-- be a primitive operation of the full type.
Check_Operation_From_Incomplete_Type (Priv_Dep, Inc_T);
Set_Is_Dispatching_Operation (Priv_Dep);
Check_Controlling_Formals (Full_T, Priv_Dep);
end if;
elsif Ekind (Priv_Dep) = E_Subprogram_Body then
-- Can happen during processing of a body before the completion
-- of a TA type. Ignore, because spec is also on dependent list.
return;
-- Dependent is a subtype
else
-- We build a new subtype indication using the full view of the
-- incomplete parent. The discriminant constraints have been
-- elaborated already at the point of the subtype declaration.
New_Subt := Create_Itype (E_Void, N);
if Has_Discriminants (Full_T) then
Disc_Constraint := Discriminant_Constraint (Priv_Dep);
else
Disc_Constraint := No_Elist;
end if;
Build_Discriminated_Subtype (Full_T, New_Subt, Disc_Constraint, N);
Set_Full_View (Priv_Dep, New_Subt);
end if;
Next_Elmt (Inc_Elmt);
end loop;
end Process_Incomplete_Dependents;
--------------------------------
-- Process_Range_Expr_In_Decl --
--------------------------------
procedure Process_Range_Expr_In_Decl
(R : Node_Id;
T : Entity_Id;
Check_List : List_Id := Empty_List;
R_Check_Off : Boolean := False)
is
Lo, Hi : Node_Id;
R_Checks : Check_Result;
Type_Decl : Node_Id;
Def_Id : Entity_Id;
begin
Analyze_And_Resolve (R, Base_Type (T));
if Nkind (R) = N_Range then
Lo := Low_Bound (R);
Hi := High_Bound (R);
-- If there were errors in the declaration, try and patch up some
-- common mistakes in the bounds. The cases handled are literals
-- which are Integer where the expected type is Real and vice versa.
-- These corrections allow the compilation process to proceed further
-- along since some basic assumptions of the format of the bounds
-- are guaranteed.
if Etype (R) = Any_Type then
if Nkind (Lo) = N_Integer_Literal and then Is_Real_Type (T) then
Rewrite (Lo,
Make_Real_Literal (Sloc (Lo), UR_From_Uint (Intval (Lo))));
elsif Nkind (Hi) = N_Integer_Literal and then Is_Real_Type (T) then
Rewrite (Hi,
Make_Real_Literal (Sloc (Hi), UR_From_Uint (Intval (Hi))));
elsif Nkind (Lo) = N_Real_Literal and then Is_Integer_Type (T) then
Rewrite (Lo,
Make_Integer_Literal (Sloc (Lo), UR_To_Uint (Realval (Lo))));
elsif Nkind (Hi) = N_Real_Literal and then Is_Integer_Type (T) then
Rewrite (Hi,
Make_Integer_Literal (Sloc (Hi), UR_To_Uint (Realval (Hi))));
end if;
Set_Etype (Lo, T);
Set_Etype (Hi, T);
end if;
-- If the bounds of the range have been mistakenly given as string
-- literals (perhaps in place of character literals), then an error
-- has already been reported, but we rewrite the string literal as a
-- bound of the range's type to avoid blowups in later processing
-- that looks at static values.
if Nkind (Lo) = N_String_Literal then
Rewrite (Lo,
Make_Attribute_Reference (Sloc (Lo),
Attribute_Name => Name_First,
Prefix => New_Reference_To (T, Sloc (Lo))));
Analyze_And_Resolve (Lo);
end if;
if Nkind (Hi) = N_String_Literal then
Rewrite (Hi,
Make_Attribute_Reference (Sloc (Hi),
Attribute_Name => Name_First,
Prefix => New_Reference_To (T, Sloc (Hi))));
Analyze_And_Resolve (Hi);
end if;
-- If bounds aren't scalar at this point then exit, avoiding
-- problems with further processing of the range in this procedure.
if not Is_Scalar_Type (Etype (Lo)) then
return;
end if;
-- Resolve (actually Sem_Eval) has checked that the bounds are in
-- then range of the base type. Here we check whether the bounds
-- are in the range of the subtype itself. Note that if the bounds
-- represent the null range the Constraint_Error exception should
-- not be raised.
-- ??? The following code should be cleaned up as follows
-- 1. The Is_Null_Range (Lo, Hi) test should disappear since it
-- is done in the call to Range_Check (R, T); below
-- 2. The use of R_Check_Off should be investigated and possibly
-- removed, this would clean up things a bit.
if Is_Null_Range (Lo, Hi) then
null;
else
-- Capture values of bounds and generate temporaries for them
-- if needed, before applying checks, since checks may cause
-- duplication of the expression without forcing evaluation.
if Expander_Active then
Force_Evaluation (Lo);
Force_Evaluation (Hi);
end if;
-- We use a flag here instead of suppressing checks on the
-- type because the type we check against isn't necessarily
-- the place where we put the check.
if not R_Check_Off then
R_Checks := Range_Check (R, T);
-- Look up tree to find an appropriate insertion point.
-- This seems really junk code, and very brittle, couldn't
-- we just use an insert actions call of some kind ???
Type_Decl := Parent (R);
while Present (Type_Decl) and then not
(Nkind (Type_Decl) = N_Full_Type_Declaration
or else
Nkind (Type_Decl) = N_Subtype_Declaration
or else
Nkind (Type_Decl) = N_Loop_Statement
or else
Nkind (Type_Decl) = N_Task_Type_Declaration
or else
Nkind (Type_Decl) = N_Single_Task_Declaration
or else
Nkind (Type_Decl) = N_Protected_Type_Declaration
or else
Nkind (Type_Decl) = N_Single_Protected_Declaration)
loop
Type_Decl := Parent (Type_Decl);
end loop;
-- Why would Type_Decl not be present??? Without this test,
-- short regression tests fail.
if Present (Type_Decl) then
-- Case of loop statement (more comments ???)
if Nkind (Type_Decl) = N_Loop_Statement then
declare
Indic : Node_Id;
begin
Indic := Parent (R);
while Present (Indic) and then not
(Nkind (Indic) = N_Subtype_Indication)
loop
Indic := Parent (Indic);
end loop;
if Present (Indic) then
Def_Id := Etype (Subtype_Mark (Indic));
Insert_Range_Checks
(R_Checks,
Type_Decl,
Def_Id,
Sloc (Type_Decl),
R,
Do_Before => True);
end if;
end;
-- All other cases (more comments ???)
else
Def_Id := Defining_Identifier (Type_Decl);
if (Ekind (Def_Id) = E_Record_Type
and then Depends_On_Discriminant (R))
or else
(Ekind (Def_Id) = E_Protected_Type
and then Has_Discriminants (Def_Id))
then
Append_Range_Checks
(R_Checks, Check_List, Def_Id, Sloc (Type_Decl), R);
else
Insert_Range_Checks
(R_Checks, Type_Decl, Def_Id, Sloc (Type_Decl), R);
end if;
end if;
end if;
end if;
end if;
elsif Expander_Active then
Get_Index_Bounds (R, Lo, Hi);
Force_Evaluation (Lo);
Force_Evaluation (Hi);
end if;
end Process_Range_Expr_In_Decl;
--------------------------------------
-- Process_Real_Range_Specification --
--------------------------------------
procedure Process_Real_Range_Specification (Def : Node_Id) is
Spec : constant Node_Id := Real_Range_Specification (Def);
Lo : Node_Id;
Hi : Node_Id;
Err : Boolean := False;
procedure Analyze_Bound (N : Node_Id);
-- Analyze and check one bound
-------------------
-- Analyze_Bound --
-------------------
procedure Analyze_Bound (N : Node_Id) is
begin
Analyze_And_Resolve (N, Any_Real);
if not Is_OK_Static_Expression (N) then
Flag_Non_Static_Expr
("bound in real type definition is not static!", N);
Err := True;
end if;
end Analyze_Bound;
-- Start of processing for Process_Real_Range_Specification
begin
if Present (Spec) then
Lo := Low_Bound (Spec);
Hi := High_Bound (Spec);
Analyze_Bound (Lo);
Analyze_Bound (Hi);
-- If error, clear away junk range specification
if Err then
Set_Real_Range_Specification (Def, Empty);
end if;
end if;
end Process_Real_Range_Specification;
---------------------
-- Process_Subtype --
---------------------
function Process_Subtype
(S : Node_Id;
Related_Nod : Node_Id;
Related_Id : Entity_Id := Empty;
Suffix : Character := ' ') return Entity_Id
is
P : Node_Id;
Def_Id : Entity_Id;
Error_Node : Node_Id;
Full_View_Id : Entity_Id;
Subtype_Mark_Id : Entity_Id;
May_Have_Null_Exclusion : Boolean;
procedure Check_Incomplete (T : Entity_Id);
-- Called to verify that an incomplete type is not used prematurely
----------------------
-- Check_Incomplete --
----------------------
procedure Check_Incomplete (T : Entity_Id) is
begin
if Ekind (Root_Type (Entity (T))) = E_Incomplete_Type then
Error_Msg_N ("invalid use of type before its full declaration", T);
end if;
end Check_Incomplete;
-- Start of processing for Process_Subtype
begin
-- Case of no constraints present
if Nkind (S) /= N_Subtype_Indication then
Find_Type (S);
Check_Incomplete (S);
P := Parent (S);
-- Ada 2005 (AI-231): Static check
if Ada_Version >= Ada_05
and then Present (P)
and then Null_Exclusion_Present (P)
and then Nkind (P) /= N_Access_To_Object_Definition
and then not Is_Access_Type (Entity (S))
then
Error_Msg_N
("(Ada 2005) the null-exclusion part requires an access type",
S);
end if;
May_Have_Null_Exclusion :=
Nkind (P) = N_Access_Definition
or else Nkind (P) = N_Access_Function_Definition
or else Nkind (P) = N_Access_Procedure_Definition
or else Nkind (P) = N_Access_To_Object_Definition
or else Nkind (P) = N_Allocator
or else Nkind (P) = N_Component_Definition
or else Nkind (P) = N_Derived_Type_Definition
or else Nkind (P) = N_Discriminant_Specification
or else Nkind (P) = N_Object_Declaration
or else Nkind (P) = N_Parameter_Specification
or else Nkind (P) = N_Subtype_Declaration;
-- Create an Itype that is a duplicate of Entity (S) but with the
-- null-exclusion attribute
if May_Have_Null_Exclusion
and then Is_Access_Type (Entity (S))
and then Null_Exclusion_Present (P)
-- No need to check the case of an access to object definition.
-- It is correct to define double not-null pointers.
-- Example:
-- type Not_Null_Int_Ptr is not null access Integer;
-- type Acc is not null access Not_Null_Int_Ptr;
and then Nkind (P) /= N_Access_To_Object_Definition
then
if Can_Never_Be_Null (Entity (S)) then
case Nkind (Related_Nod) is
when N_Full_Type_Declaration =>
if Nkind (Type_Definition (Related_Nod))
in N_Array_Type_Definition
then
Error_Node :=
Subtype_Indication
(Component_Definition
(Type_Definition (Related_Nod)));
else
Error_Node :=
Subtype_Indication (Type_Definition (Related_Nod));
end if;
when N_Subtype_Declaration =>
Error_Node := Subtype_Indication (Related_Nod);
when N_Object_Declaration =>
Error_Node := Object_Definition (Related_Nod);
when N_Component_Declaration =>
Error_Node :=
Subtype_Indication (Component_Definition (Related_Nod));
when others =>
pragma Assert (False);
Error_Node := Related_Nod;
end case;
Error_Msg_N
("(Ada 2005) already a null-excluding type", Error_Node);
end if;
Set_Etype (S,
Create_Null_Excluding_Itype
(T => Entity (S),
Related_Nod => P));
Set_Entity (S, Etype (S));
end if;
return Entity (S);
-- Case of constraint present, so that we have an N_Subtype_Indication
-- node (this node is created only if constraints are present).
else
Find_Type (Subtype_Mark (S));
if Nkind (Parent (S)) /= N_Access_To_Object_Definition
and then not
(Nkind (Parent (S)) = N_Subtype_Declaration
and then Is_Itype (Defining_Identifier (Parent (S))))
then
Check_Incomplete (Subtype_Mark (S));
end if;
P := Parent (S);
Subtype_Mark_Id := Entity (Subtype_Mark (S));
-- Explicit subtype declaration case
if Nkind (P) = N_Subtype_Declaration then
Def_Id := Defining_Identifier (P);
-- Explicit derived type definition case
elsif Nkind (P) = N_Derived_Type_Definition then
Def_Id := Defining_Identifier (Parent (P));
-- Implicit case, the Def_Id must be created as an implicit type.
-- The one exception arises in the case of concurrent types, array
-- and access types, where other subsidiary implicit types may be
-- created and must appear before the main implicit type. In these
-- cases we leave Def_Id set to Empty as a signal that Create_Itype
-- has not yet been called to create Def_Id.
else
if Is_Array_Type (Subtype_Mark_Id)
or else Is_Concurrent_Type (Subtype_Mark_Id)
or else Is_Access_Type (Subtype_Mark_Id)
then
Def_Id := Empty;
-- For the other cases, we create a new unattached Itype,
-- and set the indication to ensure it gets attached later.
else
Def_Id :=
Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
end if;
end if;
-- If the kind of constraint is invalid for this kind of type,
-- then give an error, and then pretend no constraint was given.
if not Is_Valid_Constraint_Kind
(Ekind (Subtype_Mark_Id), Nkind (Constraint (S)))
then
Error_Msg_N
("incorrect constraint for this kind of type", Constraint (S));
Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
-- Set Ekind of orphan itype, to prevent cascaded errors
if Present (Def_Id) then
Set_Ekind (Def_Id, Ekind (Any_Type));
end if;
-- Make recursive call, having got rid of the bogus constraint
return Process_Subtype (S, Related_Nod, Related_Id, Suffix);
end if;
-- Remaining processing depends on type
case Ekind (Subtype_Mark_Id) is
when Access_Kind =>
Constrain_Access (Def_Id, S, Related_Nod);
when Array_Kind =>
Constrain_Array (Def_Id, S, Related_Nod, Related_Id, Suffix);
when Decimal_Fixed_Point_Kind =>
Constrain_Decimal (Def_Id, S);
when Enumeration_Kind =>
Constrain_Enumeration (Def_Id, S);
when Ordinary_Fixed_Point_Kind =>
Constrain_Ordinary_Fixed (Def_Id, S);
when Float_Kind =>
Constrain_Float (Def_Id, S);
when Integer_Kind =>
Constrain_Integer (Def_Id, S);
when E_Record_Type |
E_Record_Subtype |
Class_Wide_Kind |
E_Incomplete_Type =>
Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
when Private_Kind =>
Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
Set_Private_Dependents (Def_Id, New_Elmt_List);
-- In case of an invalid constraint prevent further processing
-- since the type constructed is missing expected fields.
if Etype (Def_Id) = Any_Type then
return Def_Id;
end if;
-- If the full view is that of a task with discriminants,
-- we must constrain both the concurrent type and its
-- corresponding record type. Otherwise we will just propagate
-- the constraint to the full view, if available.
if Present (Full_View (Subtype_Mark_Id))
and then Has_Discriminants (Subtype_Mark_Id)
and then Is_Concurrent_Type (Full_View (Subtype_Mark_Id))
then
Full_View_Id :=
Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
Set_Entity (Subtype_Mark (S), Full_View (Subtype_Mark_Id));
Constrain_Concurrent (Full_View_Id, S,
Related_Nod, Related_Id, Suffix);
Set_Entity (Subtype_Mark (S), Subtype_Mark_Id);
Set_Full_View (Def_Id, Full_View_Id);
else
Prepare_Private_Subtype_Completion (Def_Id, Related_Nod);
end if;
when Concurrent_Kind =>
Constrain_Concurrent (Def_Id, S,
Related_Nod, Related_Id, Suffix);
when others =>
Error_Msg_N ("invalid subtype mark in subtype indication", S);
end case;
-- Size and Convention are always inherited from the base type
Set_Size_Info (Def_Id, (Subtype_Mark_Id));
Set_Convention (Def_Id, Convention (Subtype_Mark_Id));
return Def_Id;
end if;
end Process_Subtype;
-----------------------------
-- Record_Type_Declaration --
-----------------------------
procedure Record_Type_Declaration
(T : Entity_Id;
N : Node_Id;
Prev : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Def : constant Node_Id := Type_Definition (N);
Inc_T : Entity_Id := Empty;
Is_Tagged : Boolean;
Tag_Comp : Entity_Id;
procedure Check_Anonymous_Access_Types (Comp_List : Node_Id);
-- Ada 2005 AI-382: an access component in a record declaration can
-- refer to the enclosing record, in which case it denotes the type
-- itself, and not the current instance of the type. We create an
-- anonymous access type for the component, and flag it as an access
-- to a component, so that accessibility checks are properly performed
-- on it. The declaration of the access type is placed ahead of that
-- of the record, to prevent circular order-of-elaboration issues in
-- Gigi. We create an incomplete type for the record declaration, which
-- is the designated type of the anonymous access.
procedure Make_Incomplete_Type_Declaration;
-- If the record type contains components that include an access to the
-- current record, create an incomplete type declaration for the record,
-- to be used as the designated type of the anonymous access. This is
-- done only once, and only if there is no previous partial view of the
-- type.
----------------------------------
-- Check_Anonymous_Access_Types --
----------------------------------
procedure Check_Anonymous_Access_Types (Comp_List : Node_Id) is
Anon_Access : Entity_Id;
Acc_Def : Node_Id;
Comp : Node_Id;
Decl : Node_Id;
Type_Def : Node_Id;
function Mentions_T (Acc_Def : Node_Id) return Boolean;
-- Check whether an access definition includes a reference to
-- the enclosing record type. The reference can be a subtype
-- mark in the access definition itself, or a 'Class attribute
-- reference, or recursively a reference appearing in a parameter
-- type in an access_to_subprogram definition.
----------------
-- Mentions_T --
----------------
function Mentions_T (Acc_Def : Node_Id) return Boolean is
Subt : Node_Id;
begin
if No (Access_To_Subprogram_Definition (Acc_Def)) then
Subt := Subtype_Mark (Acc_Def);
if Nkind (Subt) = N_Identifier then
return Chars (Subt) = Chars (T);
-- A reference to the current type may appear as the prefix
-- of a 'Class attribute.
elsif Nkind (Subt) = N_Attribute_Reference
and then Attribute_Name (Subt) = Name_Class
and then Is_Entity_Name (Prefix (Subt))
then
return (Chars (Prefix (Subt))) = Chars (T);
else
return False;
end if;
else
-- Component is an access_to_subprogram: examine its formals
declare
Param_Spec : Node_Id;
begin
Param_Spec :=
First
(Parameter_Specifications
(Access_To_Subprogram_Definition (Acc_Def)));
while Present (Param_Spec) loop
if Nkind (Parameter_Type (Param_Spec))
= N_Access_Definition
and then Mentions_T (Parameter_Type (Param_Spec))
then
return True;
end if;
Next (Param_Spec);
end loop;
return False;
end;
end if;
end Mentions_T;
-- Start of processing for Check_Anonymous_Access_Types
begin
if No (Comp_List) then
return;
end if;
Comp := First (Component_Items (Comp_List));
while Present (Comp) loop
if Nkind (Comp) = N_Component_Declaration
and then
Present (Access_Definition (Component_Definition (Comp)))
and then
Mentions_T (Access_Definition (Component_Definition (Comp)))
then
Acc_Def :=
Access_To_Subprogram_Definition
(Access_Definition (Component_Definition (Comp)));
Make_Incomplete_Type_Declaration;
Anon_Access :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('S'));
-- Create a declaration for the anonymous access type: either
-- an access_to_object or an access_to_subprogram.
if Present (Acc_Def) then
if Nkind (Acc_Def) = N_Access_Function_Definition then
Type_Def :=
Make_Access_Function_Definition (Loc,
Parameter_Specifications =>
Parameter_Specifications (Acc_Def),
Result_Definition => Result_Definition (Acc_Def));
else
Type_Def :=
Make_Access_Procedure_Definition (Loc,
Parameter_Specifications =>
Parameter_Specifications (Acc_Def));
end if;
else
Type_Def :=
Make_Access_To_Object_Definition (Loc,
Subtype_Indication =>
Relocate_Node
(Subtype_Mark
(Access_Definition
(Component_Definition (Comp)))));
end if;
Decl := Make_Full_Type_Declaration (Loc,
Defining_Identifier => Anon_Access,
Type_Definition => Type_Def);
Insert_Before (N, Decl);
Analyze (Decl);
Rewrite (Component_Definition (Comp),
Make_Component_Definition (Loc,
Subtype_Indication =>
New_Occurrence_Of (Anon_Access, Loc)));
Set_Ekind (Anon_Access, E_Anonymous_Access_Type);
Set_Is_Local_Anonymous_Access (Anon_Access);
end if;
Next (Comp);
end loop;
if Present (Variant_Part (Comp_List)) then
declare
V : Node_Id;
begin
V := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
while Present (V) loop
Check_Anonymous_Access_Types (Component_List (V));
Next_Non_Pragma (V);
end loop;
end;
end if;
end Check_Anonymous_Access_Types;
--------------------------------------
-- Make_Incomplete_Type_Declaration --
--------------------------------------
procedure Make_Incomplete_Type_Declaration is
Decl : Node_Id;
H : Entity_Id;
begin
-- If there is a previous partial view, no need to create a new one
-- If the partial view is incomplete, it is given by Prev. If it is
-- a private declaration, full declaration is flagged accordingly.
if Prev /= T
or else Has_Private_Declaration (T)
then
return;
elsif No (Inc_T) then
Inc_T := Make_Defining_Identifier (Loc, Chars (T));
Decl := Make_Incomplete_Type_Declaration (Loc, Inc_T);
-- Type has already been inserted into the current scope.
-- Remove it, and add incomplete declaration for type, so
-- that subsequent anonymous access types can use it.
H := Current_Entity (T);
if H = T then
Set_Name_Entity_Id (Chars (T), Empty);
else
while Present (H)
and then Homonym (H) /= T
loop
H := Homonym (T);
end loop;
Set_Homonym (H, Homonym (T));
end if;
Insert_Before (N, Decl);
Analyze (Decl);
Set_Full_View (Inc_T, T);
if Tagged_Present (Def) then
Make_Class_Wide_Type (Inc_T);
Set_Class_Wide_Type (T, Class_Wide_Type (Inc_T));
Set_Etype (Class_Wide_Type (T), T);
end if;
end if;
end Make_Incomplete_Type_Declaration;
-- Start of processing for Record_Type_Declaration
begin
-- These flags must be initialized before calling Process_Discriminants
-- because this routine makes use of them.
Set_Ekind (T, E_Record_Type);
Set_Etype (T, T);
Init_Size_Align (T);
Set_Abstract_Interfaces (T, No_Elist);
Set_Stored_Constraint (T, No_Elist);
-- Normal case
if Ada_Version < Ada_05
or else not Interface_Present (Def)
then
-- The flag Is_Tagged_Type might have already been set by
-- Find_Type_Name if it detected an error for declaration T. This
-- arises in the case of private tagged types where the full view
-- omits the word tagged.
Is_Tagged :=
Tagged_Present (Def)
or else (Serious_Errors_Detected > 0 and then Is_Tagged_Type (T));
Set_Is_Tagged_Type (T, Is_Tagged);
Set_Is_Limited_Record (T, Limited_Present (Def));
-- Type is abstract if full declaration carries keyword, or if
-- previous partial view did.
Set_Is_Abstract (T, Is_Abstract (T)
or else Abstract_Present (Def));
else
Is_Tagged := True;
Analyze_Interface_Declaration (T, Def);
end if;
-- First pass: if there are self-referential access components,
-- create the required anonymous access type declarations, and if
-- need be an incomplete type declaration for T itself.
Check_Anonymous_Access_Types (Component_List (Def));
if Ada_Version >= Ada_05
and then Present (Interface_List (Def))
then
declare
Iface : Node_Id;
Iface_Def : Node_Id;
Iface_Typ : Entity_Id;
begin
Iface := First (Interface_List (Def));
while Present (Iface) loop
Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
Iface_Def := Type_Definition (Parent (Iface_Typ));
if not Is_Interface (Iface_Typ) then
Error_Msg_NE ("(Ada 2005) & must be an interface",
Iface, Iface_Typ);
else
-- "The declaration of a specific descendant of an
-- interface type freezes the interface type" RM 13.14
Freeze_Before (N, Iface_Typ);
-- Ada 2005 (AI-345): Protected interfaces can only
-- inherit from limited, synchronized or protected
-- interfaces.
if Protected_Present (Def) then
if Limited_Present (Iface_Def)
or else Synchronized_Present (Iface_Def)
or else Protected_Present (Iface_Def)
then
null;
elsif Task_Present (Iface_Def) then
Error_Msg_N ("(Ada 2005) protected interface cannot"
& " inherit from task interface", Iface);
else
Error_Msg_N ("(Ada 2005) protected interface cannot"
& " inherit from non-limited interface", Iface);
end if;
-- Ada 2005 (AI-345): Synchronized interfaces can only
-- inherit from limited and synchronized.
elsif Synchronized_Present (Def) then
if Limited_Present (Iface_Def)
or else Synchronized_Present (Iface_Def)
then
null;
elsif Protected_Present (Iface_Def) then
Error_Msg_N ("(Ada 2005) synchronized interface " &
"cannot inherit from protected interface", Iface);
elsif Task_Present (Iface_Def) then
Error_Msg_N ("(Ada 2005) synchronized interface " &
"cannot inherit from task interface", Iface);
else
Error_Msg_N ("(Ada 2005) synchronized interface " &
"cannot inherit from non-limited interface",
Iface);
end if;
-- Ada 2005 (AI-345): Task interfaces can only inherit
-- from limited, synchronized or task interfaces.
elsif Task_Present (Def) then
if Limited_Present (Iface_Def)
or else Synchronized_Present (Iface_Def)
or else Task_Present (Iface_Def)
then
null;
elsif Protected_Present (Iface_Def) then
Error_Msg_N ("(Ada 2005) task interface cannot" &
" inherit from protected interface", Iface);
else
Error_Msg_N ("(Ada 2005) task interface cannot" &
" inherit from non-limited interface", Iface);
end if;
end if;
end if;
Next (Iface);
end loop;
Set_Abstract_Interfaces (T, New_Elmt_List);
Collect_Interfaces (Def, T);
end;
end if;
-- Records constitute a scope for the component declarations within.
-- The scope is created prior to the processing of these declarations.
-- Discriminants are processed first, so that they are visible when
-- processing the other components. The Ekind of the record type itself
-- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
-- Enter record scope
New_Scope (T);
-- If an incomplete or private type declaration was already given for
-- the type, then this scope already exists, and the discriminants have
-- been declared within. We must verify that the full declaration
-- matches the incomplete one.
Check_Or_Process_Discriminants (N, T, Prev);
Set_Is_Constrained (T, not Has_Discriminants (T));
Set_Has_Delayed_Freeze (T, True);
-- For tagged types add a manually analyzed component corresponding
-- to the component _tag, the corresponding piece of tree will be
-- expanded as part of the freezing actions if it is not a CPP_Class.
if Is_Tagged then
-- Do not add the tag unless we are in expansion mode
if Expander_Active then
Tag_Comp := Make_Defining_Identifier (Sloc (Def), Name_uTag);
Enter_Name (Tag_Comp);
Set_Is_Tag (Tag_Comp);
Set_Is_Aliased (Tag_Comp);
Set_Ekind (Tag_Comp, E_Component);
Set_Etype (Tag_Comp, RTE (RE_Tag));
Set_DT_Entry_Count (Tag_Comp, No_Uint);
Set_Original_Record_Component (Tag_Comp, Tag_Comp);
Init_Component_Location (Tag_Comp);
-- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
-- implemented interfaces
Add_Interface_Tag_Components (N, T);
end if;
Make_Class_Wide_Type (T);
Set_Primitive_Operations (T, New_Elmt_List);
end if;
-- We must suppress range checks when processing the components
-- of a record in the presence of discriminants, since we don't
-- want spurious checks to be generated during their analysis, but
-- must reset the Suppress_Range_Checks flags after having processed
-- the record definition.
if Has_Discriminants (T) and then not Range_Checks_Suppressed (T) then
Set_Kill_Range_Checks (T, True);
Record_Type_Definition (Def, Prev);
Set_Kill_Range_Checks (T, False);
else
Record_Type_Definition (Def, Prev);
end if;
-- Exit from record scope
End_Scope;
if Expander_Active
and then Is_Tagged
and then not Is_Empty_List (Interface_List (Def))
then
-- Ada 2005 (AI-251): Derive the interface subprograms of all the
-- implemented interfaces and check if some of the subprograms
-- inherited from the ancestor cover some interface subprogram.
Derive_Interface_Subprograms (T);
end if;
end Record_Type_Declaration;
----------------------------
-- Record_Type_Definition --
----------------------------
procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id) is
Component : Entity_Id;
Ctrl_Components : Boolean := False;
Final_Storage_Only : Boolean;
T : Entity_Id;
begin
if Ekind (Prev_T) = E_Incomplete_Type then
T := Full_View (Prev_T);
else
T := Prev_T;
end if;
Final_Storage_Only := not Is_Controlled (T);
-- Ada 2005: check whether an explicit Limited is present in a derived
-- type declaration.
if Nkind (Parent (Def)) = N_Derived_Type_Definition
and then Limited_Present (Parent (Def))
then
Set_Is_Limited_Record (T);
end if;
-- If the component list of a record type is defined by the reserved
-- word null and there is no discriminant part, then the record type has
-- no components and all records of the type are null records (RM 3.7)
-- This procedure is also called to process the extension part of a
-- record extension, in which case the current scope may have inherited
-- components.
if No (Def)
or else No (Component_List (Def))
or else Null_Present (Component_List (Def))
then
null;
else
Analyze_Declarations (Component_Items (Component_List (Def)));
if Present (Variant_Part (Component_List (Def))) then
Analyze (Variant_Part (Component_List (Def)));
end if;
end if;
-- After completing the semantic analysis of the record definition,
-- record components, both new and inherited, are accessible. Set
-- their kind accordingly.
Component := First_Entity (Current_Scope);
while Present (Component) loop
if Ekind (Component) = E_Void then
Set_Ekind (Component, E_Component);
Init_Component_Location (Component);
end if;
if Has_Task (Etype (Component)) then
Set_Has_Task (T);
end if;
if Ekind (Component) /= E_Component then
null;
elsif Has_Controlled_Component (Etype (Component))
or else (Chars (Component) /= Name_uParent
and then Is_Controlled (Etype (Component)))
then
Set_Has_Controlled_Component (T, True);
Final_Storage_Only := Final_Storage_Only
and then Finalize_Storage_Only (Etype (Component));
Ctrl_Components := True;
end if;
Next_Entity (Component);
end loop;
-- A type is Finalize_Storage_Only only if all its controlled
-- components are so.
if Ctrl_Components then
Set_Finalize_Storage_Only (T, Final_Storage_Only);
end if;
-- Place reference to end record on the proper entity, which may
-- be a partial view.
if Present (Def) then
Process_End_Label (Def, 'e', Prev_T);
end if;
end Record_Type_Definition;
------------------------
-- Replace_Components --
------------------------
procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id) is
function Process (N : Node_Id) return Traverse_Result;
-------------
-- Process --
-------------
function Process (N : Node_Id) return Traverse_Result is
Comp : Entity_Id;
begin
if Nkind (N) = N_Discriminant_Specification then
Comp := First_Discriminant (Typ);
while Present (Comp) loop
if Chars (Comp) = Chars (Defining_Identifier (N)) then
Set_Defining_Identifier (N, Comp);
exit;
end if;
Next_Discriminant (Comp);
end loop;
elsif Nkind (N) = N_Component_Declaration then
Comp := First_Component (Typ);
while Present (Comp) loop
if Chars (Comp) = Chars (Defining_Identifier (N)) then
Set_Defining_Identifier (N, Comp);
exit;
end if;
Next_Component (Comp);
end loop;
end if;
return OK;
end Process;
procedure Replace is new Traverse_Proc (Process);
-- Start of processing for Replace_Components
begin
Replace (Decl);
end Replace_Components;
-------------------------------
-- Set_Completion_Referenced --
-------------------------------
procedure Set_Completion_Referenced (E : Entity_Id) is
begin
-- If in main unit, mark entity that is a completion as referenced,
-- warnings go on the partial view when needed.
if In_Extended_Main_Source_Unit (E) then
Set_Referenced (E);
end if;
end Set_Completion_Referenced;
---------------------
-- Set_Fixed_Range --
---------------------
-- The range for fixed-point types is complicated by the fact that we
-- do not know the exact end points at the time of the declaration. This
-- is true for three reasons:
-- A size clause may affect the fudging of the end-points
-- A small clause may affect the values of the end-points
-- We try to include the end-points if it does not affect the size
-- This means that the actual end-points must be established at the point
-- when the type is frozen. Meanwhile, we first narrow the range as
-- permitted (so that it will fit if necessary in a small specified size),
-- and then build a range subtree with these narrowed bounds.
-- Set_Fixed_Range constructs the range from real literal values, and sets
-- the range as the Scalar_Range of the given fixed-point type entity.
-- The parent of this range is set to point to the entity so that it is
-- properly hooked into the tree (unlike normal Scalar_Range entries for
-- other scalar types, which are just pointers to the range in the
-- original tree, this would otherwise be an orphan).
-- The tree is left unanalyzed. When the type is frozen, the processing
-- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
-- analyzed, and uses this as an indication that it should complete
-- work on the range (it will know the final small and size values).
procedure Set_Fixed_Range
(E : Entity_Id;
Loc : Source_Ptr;
Lo : Ureal;
Hi : Ureal)
is
S : constant Node_Id :=
Make_Range (Loc,
Low_Bound => Make_Real_Literal (Loc, Lo),
High_Bound => Make_Real_Literal (Loc, Hi));
begin
Set_Scalar_Range (E, S);
Set_Parent (S, E);
end Set_Fixed_Range;
----------------------------------
-- Set_Scalar_Range_For_Subtype --
----------------------------------
procedure Set_Scalar_Range_For_Subtype
(Def_Id : Entity_Id;
R : Node_Id;
Subt : Entity_Id)
is
Kind : constant Entity_Kind := Ekind (Def_Id);
begin
Set_Scalar_Range (Def_Id, R);
-- We need to link the range into the tree before resolving it so
-- that types that are referenced, including importantly the subtype
-- itself, are properly frozen (Freeze_Expression requires that the
-- expression be properly linked into the tree). Of course if it is
-- already linked in, then we do not disturb the current link.
if No (Parent (R)) then
Set_Parent (R, Def_Id);
end if;
-- Reset the kind of the subtype during analysis of the range, to
-- catch possible premature use in the bounds themselves.
Set_Ekind (Def_Id, E_Void);
Process_Range_Expr_In_Decl (R, Subt);
Set_Ekind (Def_Id, Kind);
end Set_Scalar_Range_For_Subtype;
--------------------------------------------------------
-- Set_Stored_Constraint_From_Discriminant_Constraint --
--------------------------------------------------------
procedure Set_Stored_Constraint_From_Discriminant_Constraint
(E : Entity_Id)
is
begin
-- Make sure set if encountered during Expand_To_Stored_Constraint
Set_Stored_Constraint (E, No_Elist);
-- Give it the right value
if Is_Constrained (E) and then Has_Discriminants (E) then
Set_Stored_Constraint (E,
Expand_To_Stored_Constraint (E, Discriminant_Constraint (E)));
end if;
end Set_Stored_Constraint_From_Discriminant_Constraint;
-------------------------------------
-- Signed_Integer_Type_Declaration --
-------------------------------------
procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id) is
Implicit_Base : Entity_Id;
Base_Typ : Entity_Id;
Lo_Val : Uint;
Hi_Val : Uint;
Errs : Boolean := False;
Lo : Node_Id;
Hi : Node_Id;
function Can_Derive_From (E : Entity_Id) return Boolean;
-- Determine whether given bounds allow derivation from specified type
procedure Check_Bound (Expr : Node_Id);
-- Check bound to make sure it is integral and static. If not, post
-- appropriate error message and set Errs flag
---------------------
-- Can_Derive_From --
---------------------
-- Note we check both bounds against both end values, to deal with
-- strange types like ones with a range of 0 .. -12341234.
function Can_Derive_From (E : Entity_Id) return Boolean is
Lo : constant Uint := Expr_Value (Type_Low_Bound (E));
Hi : constant Uint := Expr_Value (Type_High_Bound (E));
begin
return Lo <= Lo_Val and then Lo_Val <= Hi
and then
Lo <= Hi_Val and then Hi_Val <= Hi;
end Can_Derive_From;
-----------------
-- Check_Bound --
-----------------
procedure Check_Bound (Expr : Node_Id) is
begin
-- If a range constraint is used as an integer type definition, each
-- bound of the range must be defined by a static expression of some
-- integer type, but the two bounds need not have the same integer
-- type (Negative bounds are allowed.) (RM 3.5.4)
if not Is_Integer_Type (Etype (Expr)) then
Error_Msg_N
("integer type definition bounds must be of integer type", Expr);
Errs := True;
elsif not Is_OK_Static_Expression (Expr) then
Flag_Non_Static_Expr
("non-static expression used for integer type bound!", Expr);
Errs := True;
-- The bounds are folded into literals, and we set their type to be
-- universal, to avoid typing difficulties: we cannot set the type
-- of the literal to the new type, because this would be a forward
-- reference for the back end, and if the original type is user-
-- defined this can lead to spurious semantic errors (e.g. 2928-003).
else
if Is_Entity_Name (Expr) then
Fold_Uint (Expr, Expr_Value (Expr), True);
end if;
Set_Etype (Expr, Universal_Integer);
end if;
end Check_Bound;
-- Start of processing for Signed_Integer_Type_Declaration
begin
-- Create an anonymous base type
Implicit_Base :=
Create_Itype (E_Signed_Integer_Type, Parent (Def), T, 'B');
-- Analyze and check the bounds, they can be of any integer type
Lo := Low_Bound (Def);
Hi := High_Bound (Def);
-- Arbitrarily use Integer as the type if either bound had an error
if Hi = Error or else Lo = Error then
Base_Typ := Any_Integer;
Set_Error_Posted (T, True);
-- Here both bounds are OK expressions
else
Analyze_And_Resolve (Lo, Any_Integer);
Analyze_And_Resolve (Hi, Any_Integer);
Check_Bound (Lo);
Check_Bound (Hi);
if Errs then
Hi := Type_High_Bound (Standard_Long_Long_Integer);
Lo := Type_Low_Bound (Standard_Long_Long_Integer);
end if;
-- Find type to derive from
Lo_Val := Expr_Value (Lo);
Hi_Val := Expr_Value (Hi);
if Can_Derive_From (Standard_Short_Short_Integer) then
Base_Typ := Base_Type (Standard_Short_Short_Integer);
elsif Can_Derive_From (Standard_Short_Integer) then
Base_Typ := Base_Type (Standard_Short_Integer);
elsif Can_Derive_From (Standard_Integer) then
Base_Typ := Base_Type (Standard_Integer);
elsif Can_Derive_From (Standard_Long_Integer) then
Base_Typ := Base_Type (Standard_Long_Integer);
elsif Can_Derive_From (Standard_Long_Long_Integer) then
Base_Typ := Base_Type (Standard_Long_Long_Integer);
else
Base_Typ := Base_Type (Standard_Long_Long_Integer);
Error_Msg_N ("integer type definition bounds out of range", Def);
Hi := Type_High_Bound (Standard_Long_Long_Integer);
Lo := Type_Low_Bound (Standard_Long_Long_Integer);
end if;
end if;
-- Complete both implicit base and declared first subtype entities
Set_Etype (Implicit_Base, Base_Typ);
Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
Set_Size_Info (Implicit_Base, (Base_Typ));
Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
Set_Ekind (T, E_Signed_Integer_Subtype);
Set_Etype (T, Implicit_Base);
Set_Size_Info (T, (Implicit_Base));
Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
Set_Scalar_Range (T, Def);
Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
Set_Is_Constrained (T);
end Signed_Integer_Type_Declaration;
end Sem_Ch3;
|
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
package P_StructuralTypes is
subtype T_Key is String (1..8);
type T_Bit is mod 2
with Size => 1;
type T_BinaryUnit is array (Positive range <>) of T_Bit
with Default_Component_Value => 0;
pragma Pack (T_BinaryUnit);
subtype T_BinaryBlock is T_BinaryUnit (1..64);
subtype T_Byte is T_BinaryUnit (1..8);
subtype T_BinaryExpandedBlock is T_BinaryUnit (1..48);
subtype T_BinaryHalfBlock is T_BinaryUnit (1..32);
subtype T_BinaryKey is T_BinaryUnit (1..64);
subtype T_BinaryFormattedKey is T_BinaryUnit (1..56);
subtype T_BinaryHalfFormattedKey is T_BinaryUnit (1..28);
subtype T_BinarySubKey is T_BinaryUnit (1..48);
type T_BinaryContainer is array (Positive range <>) of T_BinaryBlock;
pragma Pack (T_BinaryContainer);
type T_BinarySubKeyArray is array (1..16) of T_BinarySubKey;
pragma Pack (T_BinarySubKeyArray);
-----------------------------------------------------------------------------
-------------------------------- ACCESS -------------------------------------
-----------------------------------------------------------------------------
type BinaryContainer_Access is access T_BinaryContainer;
type BinarySubKeyArray_Access is access T_BinarySubKeyArray;
type Key_Access is access T_Key;
-----------------------------------------------------------------------------
----------------------------- FUNCTIONS -------------------------------------
-----------------------------------------------------------------------------
function O_plus (b1 : in T_BinaryUnit ; b2 : in T_BinaryUnit) return T_BinaryUnit;
function TextBlock_To_Binary (Block : String) return T_BinaryBlock;
function Byte_To_CharacterCode (Byte : in T_Byte) return Integer;
function Integer_To_Binary (Number : Integer;
NbBits : Integer) return T_BinaryUnit;
procedure Replace_Block (Ptr_BinaryContainer : in BinaryContainer_Access;
Index : in Integer;
BinaryBlock : in T_BinaryBlock);
procedure Left_Shift (Unit : in out T_BinaryUnit;
Iteration : in Positive);
function Left (Block : T_BinaryUnit) return T_BinaryUnit;
function Right (Block : T_BinaryUnit) return T_BinaryUnit;
procedure Put_BinaryUnit (Unit : T_BinaryUnit);
end P_StructuralTypes;
|
-- Shoot'n'loot
-- Copyright (c) 2020 Fabien Chouteau
with GESTE;
package Levels is
type Level_Id is (Lvl_0, Lvl_1, Lvl_2, Lvl_3, Lvl_4, Lvl_5, Lvl_6, Lvl_7,
Lvl_8);
procedure Enter (Id : Level_Id);
-- Setup a level
procedure Open_Exit;
-- Open the exit tile of the current level
function Test_Exit (Pt : GESTE.Pix_Point) return Boolean;
-- Return True if Pt is within the exit tile of the current level
end Levels;
|
package body Test_Keyboard_Window is
-------------
-- On_Init --
-------------
overriding procedure On_Init
(This : in out Keyboard_Window)
is
begin
On_Init (Test_Window (This));
This.Keyboard.Set_Size (This.Get_Size);
This.Add_Child (This.Keyboard'Unchecked_Access, (0, 0));
end On_Init;
end Test_Keyboard_Window;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- C H E C K S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-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. --
-- --
------------------------------------------------------------------------------
-- Package containing routines used to deal with runtime checks. These
-- routines are used both by the semantics and by the expander. In some
-- cases, checks are enabled simply by setting flags for gigi, and in
-- other cases the code for the check is expanded.
-- The approach used for range and length checks, in regards to suppressed
-- checks, is to attempt to detect at compilation time that a constraint
-- error will occur. If this is detected a warning or error is issued and the
-- offending expression or statement replaced with a constraint error node.
-- This always occurs whether checks are suppressed or not. Dynamic range
-- checks are, of course, not inserted if checks are suppressed.
with Types; use Types;
with Uintp; use Uintp;
package Checks is
procedure Initialize;
-- Called for each new main source program, to initialize internal
-- variables used in the package body of the Checks unit.
function Access_Checks_Suppressed (E : Entity_Id) return Boolean;
function Accessibility_Checks_Suppressed (E : Entity_Id) return Boolean;
function Discriminant_Checks_Suppressed (E : Entity_Id) return Boolean;
function Division_Checks_Suppressed (E : Entity_Id) return Boolean;
function Elaboration_Checks_Suppressed (E : Entity_Id) return Boolean;
function Index_Checks_Suppressed (E : Entity_Id) return Boolean;
function Length_Checks_Suppressed (E : Entity_Id) return Boolean;
function Overflow_Checks_Suppressed (E : Entity_Id) return Boolean;
function Range_Checks_Suppressed (E : Entity_Id) return Boolean;
function Storage_Checks_Suppressed (E : Entity_Id) return Boolean;
function Tag_Checks_Suppressed (E : Entity_Id) return Boolean;
-- These functions check to see if the named check is suppressed,
-- either by an active scope suppress setting, or because the check
-- has been specifically suppressed for the given entity. If no entity
-- is relevant for the current check, then Empty is used as an argument.
-- Note: the reason we insist on specifying Empty is to force the
-- caller to think about whether there is any relevant entity that
-- should be checked.
-- General note on following checks. These checks are always active if
-- Expander_Active and not Inside_A_Generic. They are inactive and have
-- no effect Inside_A_Generic. In the case where not Expander_Active
-- and not Inside_A_Generic, most of them are inactive, but some of them
-- operate anyway since they may generate useful compile time warnings.
procedure Apply_Access_Check (N : Node_Id);
-- Determines whether an expression node requires a runtime access
-- check and if so inserts the appropriate run-time check.
procedure Apply_Accessibility_Check (N : Node_Id; Typ : Entity_Id);
-- Given a name N denoting an access parameter, emits a run-time
-- accessibility check (if necessary), checking that the level of
-- the object denoted by the access parameter is not deeper than the
-- level of the type Typ. Program_Error is raised if the check fails.
procedure Apply_Alignment_Check (E : Entity_Id; N : Node_Id);
-- E is the entity for an object. If there is an address clause for
-- this entity, and checks are enabled, then this procedure generates
-- a check that the specified address has an alignment consistent with
-- the alignment of the object, raising PE if this is not the case. The
-- resulting check (if one is generated) is inserted before node N.
procedure Apply_Array_Size_Check (N : Node_Id; Typ : Entity_Id);
-- N is the node for an object declaration that declares an object of
-- array type Typ. This routine generates, if necessary, a check that
-- the size of the array is not too large, raising Storage_Error if so.
procedure Apply_Arithmetic_Overflow_Check (N : Node_Id);
-- Given a binary arithmetic operator (+ - *) expand a software integer
-- overflow check using range checks on a larger checking type or a call
-- to an appropriate runtime routine. This is used for all three operators
-- for the signed integer case, and for +/- in the fixed-point case. The
-- check is expanded only if Software_Overflow_Checking is enabled and
-- Do_Overflow_Check is set on node N. Note that divide is handled
-- separately using Apply_Arithmetic_Divide_Overflow_Check.
procedure Apply_Constraint_Check
(N : Node_Id;
Typ : Entity_Id;
No_Sliding : Boolean := False);
-- Top-level procedure, calls all the others depending on the class of Typ.
-- Checks that expression N verifies the constraint of type Typ. No_Sliding
-- is only relevant for constrained array types, id set to true, it
-- checks that indexes are in range.
procedure Apply_Discriminant_Check
(N : Node_Id;
Typ : Entity_Id;
Lhs : Node_Id := Empty);
-- Given an expression N of a discriminated type, or of an access type
-- whose designated type is a discriminanted type, generates a check to
-- ensure that the expression can be converted to the subtype given as
-- the second parameter. Lhs is empty except in the case of assignments,
-- where the target object may be needed to determine the subtype to
-- check against (such as the cases of unconstrained formal parameters
-- and unconstrained aliased objects). For the case of unconstrained
-- formals, the check is peformed only if the corresponding actual is
-- constrained, i.e., whether Lhs'Constrained is True.
function Build_Discriminant_Checks
(N : Node_Id;
T_Typ : Entity_Id)
return Node_Id;
-- Subsidiary routine for Apply_Discriminant_Check. Builds the expression
-- that compares discriminants of the expression with discriminants of the
-- type. Also used directly for membership tests (see Exp_Ch4.Expand_N_In).
procedure Apply_Divide_Check (N : Node_Id);
-- The node kind is N_Op_Divide, N_Op_Mod, or N_Op_Rem. An appropriate
-- check is generated to ensure that the right operand is non-zero. In
-- the divide case, we also check that we do not have the annoying case
-- of the largest negative number divided by minus one.
procedure Apply_Type_Conversion_Checks (N : Node_Id);
-- N is an N_Type_Conversion node. A type conversion actually involves
-- two sorts of checks. The first check is the checks that ensures that
-- the operand in the type conversion fits onto the base type of the
-- subtype it is being converted to (see RM 4.6 (28)-(50)). The second
-- check is there to ensure that once the operand has been converted to
-- a value of the target type, this converted value meets the
-- constraints imposed by the target subtype (see RM 4.6 (51)).
procedure Apply_Universal_Integer_Attribute_Checks (N : Node_Id);
-- The argument N is an attribute reference node intended for processing
-- by gigi. The attribute is one that returns a universal integer, but
-- the attribute reference node is currently typed with the expected
-- result type. This routine deals with range and overflow checks needed
-- to make sure that the universal result is in range.
procedure Determine_Range
(N : Node_Id;
OK : out Boolean;
Lo : out Uint;
Hi : out Uint);
-- N is a node for a subexpression. If N is of a discrete type with no
-- error indications, and no other peculiarities (e.g. missing type
-- fields), then OK is True on return, and Lo and Hi are set to a
-- conservative estimate of the possible range of values of N. Thus if OK
-- is True on return, the value of the subexpression N is known to like in
-- the range Lo .. Hi (inclusive). If the expression is not of a discrete
-- type, or some kind of error condition is detected, then OK is False on
-- exit, and Lo/Hi are set to No_Uint. Thus the significance of OK being
-- False on return is that no useful information is available on the range
-- of the expression.
procedure Install_Null_Excluding_Check (N : Node_Id);
-- Determines whether an access node requires a runtime access check and
-- if so inserts the appropriate run-time check.
-------------------------------------------------------
-- Control and Optimization of Range/Overflow Checks --
-------------------------------------------------------
-- Range checks are controlled by the Do_Range_Check flag. The front end
-- is responsible for setting this flag in relevant nodes. Originally
-- the back end generated all corresponding range checks. But later on
-- we decided to generate all range checks in the front end. We are now
-- in the transitional phase where some of these checks are still done
-- by the back end, but many are done by the front end.
-- Overflow checks are similarly controlled by the Do_Overflow_Check flag.
-- The difference here is that if Backend_Overflow_Checks is is
-- (Backend_Overflow_Checks_On_Target set False), then the actual overflow
-- checks are generated by the front end, but if back end overflow checks
-- are active (Backend_Overflow_Checks_On_Target set True), then the back
-- end does generate the checks.
-- The following two routines are used to set these flags, they allow
-- for the possibility of eliminating checks. Checks can be eliminated
-- if an identical check has already been performed.
procedure Enable_Overflow_Check (N : Node_Id);
-- First this routine determines if an overflow check is needed by doing
-- an appropriate range check. If a check is not needed, then the call
-- has no effect. If a check is needed then this routine sets the flag
-- Set Do_Overflow_Check in node N to True, unless it can be determined
-- that the check is not needed. The only condition under which this is
-- the case is if there was an identical check earlier on.
procedure Enable_Range_Check (N : Node_Id);
-- Set Do_Range_Check flag in node N True, unless it can be determined
-- that the check is not needed. The only condition under which this is
-- the case is if there was an identical check earlier on. This routine
-- is not responsible for doing range analysis to determine whether or
-- not such a check is needed -- the caller is expected to do this. The
-- one other case in which the request to set the flag is ignored is
-- when Kill_Range_Check is set in an N_Unchecked_Conversion node.
-- The following routines are used to keep track of processing sequences
-- of statements (e.g. the THEN statements of an IF statement). A check
-- that appears within such a sequence can eliminate an identical check
-- within this sequence of statements. However, after the end of the
-- sequence of statements, such a check is no longer of interest, since
-- it may not have been executed.
procedure Conditional_Statements_Begin;
-- This call marks the start of processing of a sequence of statements.
-- Every call to this procedure must be followed by a matching call to
-- Conditional_Statements_End.
procedure Conditional_Statements_End;
-- This call removes from consideration all saved checks since the
-- corresponding call to Conditional_Statements_Begin. These two
-- procedures operate in a stack like manner.
-- The mechanism for optimizing checks works by remembering checks
-- that have already been made, but certain conditions, for example
-- an assignment to a variable involved in a check, may mean that the
-- remembered check is no longer valid, in the sense that if the same
-- expression appears again, another check is required because the
-- value may have changed.
-- The following routines are used to note conditions which may render
-- some or all of the stored and remembered checks to be invalidated.
procedure Kill_Checks (V : Entity_Id);
-- This procedure records an assignment or other condition that causes
-- the value of the variable to be changed, invalidating any stored
-- checks that reference the value. Note that all such checks must
-- be discarded, even if they are not in the current statement range.
procedure Kill_All_Checks;
-- This procedure kills all remembered checks
-----------------------------
-- Length and Range Checks --
-----------------------------
-- In the following procedures, there are three arguments which have
-- a common meaning as follows:
-- Expr The expression to be checked. If a check is required,
-- the appropriate flag will be placed on this node. Whether
-- this node is further examined depends on the setting of
-- the parameter Source_Typ, as described below.
-- Target_Typ The target type on which the check is to be based. For
-- example, if we have a scalar range check, then the check
-- is that we are in range of this type.
-- Source_Typ Normally Empty, but can be set to a type, in which case
-- this type is used for the check, see below.
-- The checks operate in one of two modes:
-- If Source_Typ is Empty, then the node Expr is examined, at the very
-- least to get the source subtype. In addition for some of the checks,
-- the actual form of the node may be examined. For example, a node of
-- type Integer whose actual form is an Integer conversion from a type
-- with range 0 .. 3 can be determined to have a value in range 0 .. 3.
-- If Source_Typ is given, then nothing can be assumed about the Expr,
-- and indeed its contents are not examined. In this case the check is
-- based on the assumption that Expr can be an arbitrary value of the
-- given Source_Typ.
-- Currently, the only case in which a Source_Typ is explicitly supplied
-- is for the case of Out and In_Out parameters, where, for the conversion
-- on return (the Out direction), the types must be reversed. This is
-- handled by the caller.
procedure Apply_Length_Check
(Ck_Node : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id := Empty);
-- This procedure builds a sequence of declarations to do a length check
-- that checks if the lengths of the two arrays Target_Typ and source type
-- are the same. The resulting actions are inserted at Node using a call
-- to Insert_Actions.
--
-- For access types, the Directly_Designated_Type is retrieved and
-- processing continues as enumerated above, with a guard against null
-- values.
--
-- Note: calls to Apply_Length_Check currently never supply an explicit
-- Source_Typ parameter, but Apply_Length_Check takes this parameter and
-- processes it as described above for consistency with the other routines
-- in this section.
procedure Apply_Range_Check
(Ck_Node : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id := Empty);
-- For an Node of kind N_Range, constructs a range check action that tests
-- first that the range is not null and then that the range is contained in
-- the Target_Typ range.
--
-- For scalar types, constructs a range check action that first tests that
-- the expression is contained in the Target_Typ range. The difference
-- between this and Apply_Scalar_Range_Check is that the latter generates
-- the actual checking code in gigi against the Etype of the expression.
--
-- For constrained array types, construct series of range check actions
-- to check that each Expr range is properly contained in the range of
-- Target_Typ.
--
-- For a type conversion to an unconstrained array type, constructs a range
-- check action to check that the bounds of the source type are within the
-- constraints imposed by the Target_Typ.
--
-- For access types, the Directly_Designated_Type is retrieved and
-- processing continues as enumerated above, with a guard against null
-- values.
--
-- The source type is used by type conversions to unconstrained array
-- types to retrieve the corresponding bounds.
procedure Apply_Static_Length_Check
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id := Empty);
-- Tries to determine statically whether the two array types source type
-- and Target_Typ have the same length. If it can be determined at compile
-- time that they do not, then an N_Raise_Constraint_Error node replaces
-- Expr, and a warning message is issued.
procedure Apply_Scalar_Range_Check
(Expr : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id := Empty;
Fixed_Int : Boolean := False);
-- For scalar types, determines whether an expression node should be
-- flagged as needing a runtime range check. If the node requires such a
-- check, the Do_Range_Check flag is turned on. The Fixed_Int flag if set
-- causes any fixed-point values to be treated as though they were discrete
-- values (i.e. the underlying integer value is used).
type Check_Result is private;
-- Type used to return result of Range_Check call, for later use in
-- call to Insert_Range_Checks procedure.
procedure Append_Range_Checks
(Checks : Check_Result;
Stmts : List_Id;
Suppress_Typ : Entity_Id;
Static_Sloc : Source_Ptr;
Flag_Node : Node_Id);
-- Called to append range checks as returned by a call to Range_Check.
-- Stmts is a list to which either the dynamic check is appended or the
-- raise Constraint_Error statement is appended (for static checks).
-- Static_Sloc is the Sloc at which the raise CE node points, Flag_Node is
-- used as the node at which to set the Has_Dynamic_Check flag. Checks_On
-- is a boolean value that says if range and index checking is on or not.
procedure Insert_Range_Checks
(Checks : Check_Result;
Node : Node_Id;
Suppress_Typ : Entity_Id;
Static_Sloc : Source_Ptr := No_Location;
Flag_Node : Node_Id := Empty;
Do_Before : Boolean := False);
-- Called to insert range checks as returned by a call to Range_Check.
-- Node is the node after which either the dynamic check is inserted or
-- the raise Constraint_Error statement is inserted (for static checks).
-- Suppress_Typ is the type to check to determine if checks are suppressed.
-- Static_Sloc, if passed, is the Sloc at which the raise CE node points,
-- otherwise Sloc (Node) is used. The Has_Dynamic_Check flag is normally
-- set at Node. If Flag_Node is present, then this is used instead as the
-- node at which to set the Has_Dynamic_Check flag. Normally the check is
-- inserted after, if Do_Before is True, the check is inserted before
-- Node.
function Range_Check
(Ck_Node : Node_Id;
Target_Typ : Entity_Id;
Source_Typ : Entity_Id := Empty;
Warn_Node : Node_Id := Empty)
return Check_Result;
-- Like Apply_Range_Check, except it does not modify anything. Instead
-- it returns an encapsulated result of the check operations for later
-- use in a call to Insert_Range_Checks. If Warn_Node is non-empty, its
-- Sloc is used, in the static case, for the generated warning or error.
-- Additionally, it is used rather than Expr (or Low/High_Bound of Expr)
-- in constructing the check.
-----------------------
-- Expander Routines --
-----------------------
-- Some of the earlier processing for checks results in temporarily setting
-- the Do_Range_Check flag rather than actually generating checks. Now we
-- are moving the generation of such checks into the front end for reasons
-- of efficiency and simplicity (there were difficutlies in handling this
-- in the back end when side effects were present in the expressions being
-- checked).
-- Probably we could eliminate the Do_Range_Check flag entirely and
-- generate the checks earlier, but this is a delicate area and it
-- seemed safer to implement the following routines, which are called
-- late on in the expansion process. They check the Do_Range_Check flag
-- and if it is set, generate the actual checks and reset the flag.
procedure Generate_Range_Check
(N : Node_Id;
Target_Type : Entity_Id;
Reason : RT_Exception_Code);
-- This procedure is called to actually generate and insert a range check.
-- A check is generated to ensure that the value of N lies within the range
-- of the target type. Note that the base type of N may be different from
-- the base type of the target type. This happens in the conversion case.
-- The Reason parameter is the exception code to be used for the exception
-- if raised.
--
-- Note on the relation of this routine to the Do_Range_Check flag. Mostly
-- for historical reasons, we often set the Do_Range_Check flag and then
-- later we call Generate_Range_Check if this flag is set. Most probably we
-- could eliminate this intermediate setting of the flag (historically the
-- back end dealt with range checks, using this flag to indicate if a check
-- was required, then we moved checks into the front end).
procedure Generate_Index_Checks (N : Node_Id);
-- This procedure is called to generate index checks on the subscripts for
-- the indexed component node N. Each subscript expression is examined, and
-- if the Do_Range_Check flag is set, an appropriate index check is
-- generated and the flag is reset.
-- Similarly, we set the flag Do_Discriminant_Check in the semantic
-- analysis to indicate that a discriminant check is required for selected
-- component of a discriminated type. The following routine is called from
-- the expander to actually generate the call.
procedure Generate_Discriminant_Check (N : Node_Id);
-- N is a selected component for which a discriminant check is required to
-- make sure that the discriminants have appropriate values for the
-- selection. This is done by calling the appropriate discriminant checking
-- routine for the selector.
-----------------------
-- Validity Checking --
-----------------------
-- In (RM 13.9.1(9-11)) we have the following rules on invalid values
-- If the representation of a scalar object does not represent value of
-- the object's subtype (perhaps because the object was not initialized),
-- the object is said to have an invalid representation. It is a bounded
-- error to evaluate the value of such an object. If the error is
-- detected, either Constraint_Error or Program_Error is raised.
-- Otherwise, execution continues using the invalid representation. The
-- rules of the language outside this subclause assume that all objects
-- have valid representations. The semantics of operations on invalid
-- representations are as follows:
--
-- 10 If the representation of the object represents a value of the
-- object's type, the value of the type is used.
--
-- 11 If the representation of the object does not represent a value
-- of the object's type, the semantics of operations on such
-- representations is implementation-defined, but does not by
-- itself lead to erroneous or unpredictable execution, or to
-- other objects becoming abnormal.
-- We quote the rules in full here since they are quite delicate. Most
-- of the time, we can just compute away with wrong values, and get a
-- possibly wrong result, which is well within the range of allowed
-- implementation defined behavior. The two tricky cases are subscripted
-- array assignments, where we don't want to do wild stores, and case
-- statements where we don't want to do wild jumps.
-- In GNAT, we control validity checking with a switch -gnatV that can take
-- three parameters, n/d/f for None/Default/Full. These modes have the
-- following meanings:
-- None (no validity checking)
-- In this mode, there is no specific checking for invalid values
-- and the code generator assumes that all stored values are always
-- within the bounds of the object subtype. The consequences are as
-- follows:
-- For case statements, an out of range invalid value will cause
-- Constraint_Error to be raised, or an arbitrary one of the case
-- alternatives will be executed. Wild jumps cannot result even
-- in this mode, since we always do a range check
-- For subscripted array assignments, wild stores will result in
-- the expected manner when addresses are calculated using values
-- of subscripts that are out of range.
-- It could perhaps be argued that this mode is still conformant with
-- the letter of the RM, since implementation defined is a rather
-- broad category, but certainly it is not in the spirit of the
-- RM requirement, since wild stores certainly seem to be a case of
-- erroneous behavior.
-- Default (default standard RM-compatible validity checking)
-- In this mode, which is the default, minimal validity checking is
-- performed to ensure no erroneous behavior as follows:
-- For case statements, an out of range invalid value will cause
-- Constraint_Error to be raised.
-- For subscripted array assignments, invalid out of range
-- subscript values will cause Constraint_Error to be raised.
-- Full (Full validity checking)
-- In this mode, the protections guaranteed by the standard mode are
-- in place, and the following additional checks are made:
-- For every assignment, the right side is checked for validity
-- For every call, IN and IN OUT parameters are checked for validity
-- For every subscripted array reference, both for stores and loads,
-- all subscripts are checked for validity.
-- These checks are not required by the RM, but will in practice
-- improve the detection of uninitialized variables, particularly
-- if used in conjunction with pragma Normalize_Scalars.
-- In the above description, we talk about performing validity checks,
-- but we don't actually generate a check in a case where the compiler
-- can be sure that the value is valid. Note that this assurance must
-- be achieved without assuming that any uninitialized value lies within
-- the range of its type. The following are cases in which values are
-- known to be valid. The flag Is_Known_Valid is used to keep track of
-- some of these cases.
-- If all possible stored values are valid, then any uninitialized
-- value must be valid.
-- Literals, including enumeration literals, are clearly always valid
-- Constants are always assumed valid, with a validity check being
-- performed on the initializing value where necessary to ensure that
-- this is the case.
-- For variables, the status is set to known valid if there is an
-- initializing expression. Again a check is made on the initializing
-- value if necessary to ensure that this assumption is valid. The
-- status can change as a result of local assignments to a variable.
-- If a known valid value is unconditionally assigned, then we mark
-- the left side as known valid. If a value is assigned that is not
-- known to be valid, then we mark the left side as invalid. This
-- kind of processing does NOT apply to non-local variables since we
-- are not following the flow graph (more properly the flow of actual
-- processing only corresponds to the flow graph for local assignments).
-- For non-local variables, we preserve the current setting, i.e. a
-- validity check is performed when assigning to a knonwn valid global.
-- Note: no validity checking is required if range checks are suppressed
-- regardless of the setting of the validity checking mode.
-- The following procedures are used in handling validity checking
procedure Apply_Subscript_Validity_Checks (Expr : Node_Id);
-- Expr is the node for an indexed component. If validity checking and
-- range checking are enabled, all subscripts for this indexed component
-- are checked for validity.
procedure Check_Valid_Lvalue_Subscripts (Expr : Node_Id);
-- Expr is a lvalue, i.e. an expression representing the target of an
-- assignment. This procedure checks for this expression involving an
-- assignment to an array value. We have to be sure that all the subscripts
-- in such a case are valid, since according to the rules in (RM
-- 13.9.1(9-11)) such assignments are not permitted to result in erroneous
-- behavior in the case of invalid subscript values.
procedure Ensure_Valid (Expr : Node_Id; Holes_OK : Boolean := False);
-- Ensure that Expr represents a valid value of its type. If this type
-- is not a scalar type, then the call has no effect, since validity
-- is only an issue for scalar types. The effect of this call is to
-- check if the value is known valid, if so, nothing needs to be done.
-- If this is not known, then either Expr is set to be range checked,
-- or specific checking code is inserted so that an exception is raised
-- if the value is not valid.
--
-- The optional argument Holes_OK indicates whether it is necessary to
-- worry about enumeration types with non-standard representations leading
-- to "holes" in the range of possible representations. If Holes_OK is
-- True, then such values are assumed valid (this is used when the caller
-- will make a separate check for this case anyway). If Holes_OK is False,
-- then this case is checked, and code is inserted to ensure that Expr is
-- valid, raising Constraint_Error if the value is not valid.
function Expr_Known_Valid (Expr : Node_Id) return Boolean;
-- This function tests it the value of Expr is known to be valid in the
-- sense of RM 13.9.1(9-11). In the case of GNAT, it is only discrete types
-- which are a concern, since for non-discrete types we simply continue
-- computation with invalid values, which does not lead to erroneous
-- behavior. Thus Expr_Known_Valid always returns True if the type of Expr
-- is non-discrete. For discrete types the value returned is True only if
-- it can be determined that the value is Valid. Otherwise False is
-- returned.
procedure Insert_Valid_Check (Expr : Node_Id);
-- Inserts code that will check for the value of Expr being valid, in
-- the sense of the 'Valid attribute returning True. Constraint_Error
-- will be raised if the value is not valid.
procedure Null_Exclusion_Static_Checks (N : Node_Id);
-- Ada 2005 (AI-231): Check bad usages of the null-exclusion issue
procedure Remove_Checks (Expr : Node_Id);
-- Remove all checks from Expr except those that are only executed
-- conditionally (on the right side of And Then/Or Else. This call
-- removes only embedded checks (Do_Range_Check, Do_Overflow_Check).
private
type Check_Result is array (Positive range 1 .. 2) of Node_Id;
-- There are two cases for the result returned by Range_Check:
--
-- For the static case the result is one or two nodes that should cause
-- a Constraint_Error. Typically these will include Expr itself or the
-- direct descendents of Expr, such as Low/High_Bound (Expr)). It is the
-- responsibility of the caller to rewrite and substitute the nodes with
-- N_Raise_Constraint_Error nodes.
--
-- For the non-static case a single N_Raise_Constraint_Error node with a
-- non-empty Condition field is returned.
--
-- Unused entries in Check_Result, if any, are simply set to Empty For
-- external clients, the required processing on this result is achieved
-- using the Insert_Range_Checks routine.
pragma Inline (Apply_Length_Check);
pragma Inline (Apply_Range_Check);
pragma Inline (Apply_Static_Length_Check);
end Checks;
|
package body PKG is
function fkt1 is
new Foo.Bar (Some_Thing => Some_Thing_Else);
task body Foo_Task is separate;
task body Bar_Task is separate;
end PKG;
|
with Interfaces; use Interfaces;
with GL;
-------------------------------------------------------------------------------
-- Helper geometry primitives and functions
-------------------------------------------------------------------------------
package Render.Util is
type Point is record
x : GL.GLfloat;
y : GL.GLfloat;
s : GL.GLfloat;
t : GL.GLfloat;
end record;
type Box is array (Natural range 1..4) of Point with Convention => C;
type Point2D is record
x : GL.GLfloat;
y : GL.GLfloat;
end record;
type Line2D is array (Natural range 1..2) of Point2D with Convention => C;
type Box2D is array (Natural range 1..4) of Point2D with Convention => C;
-- Can pass these to GL functions with myvec(1)'Access
type Vec2 is array (Natural range 1..2) of aliased GL.GLfloat with Convention => C;
type Vec4 is array (Natural range 1..4) of aliased GL.GLfloat with Convention => C;
-- Make sure you transpose these if not already in column-major form
type Mat4 is array (Natural range 1..16) of aliased GL.GLfloat with Convention => C;
type DecorationColor is record
r : Float;
g : Float;
b : Float;
a : Float;
end record;
---------------------------------------------------------------------------
-- rgbaToGLColor
-- Convenience function for taking 32-bit RGBA and converting to
-- floating-point GL color
---------------------------------------------------------------------------
function rgbaToGLColor (rgb : Unsigned_32) return DecorationColor;
---------------------------------------------------------------------------
-- Build orthographic projection matrix. Akin to glm::ortho
---------------------------------------------------------------------------
function ortho (left : GL.GLfloat;
right : GL.GLfloat;
bottom : GL.GLfloat;
top : GL.GLfloat;
nearVal : GL.GLfloat;
farVal : GL.GLfloat) return Mat4;
end Render.Util;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.