repo_name
stringlengths 9
74
| language
stringclasses 1
value | length_bytes
int64 11
9.34M
| extension
stringclasses 2
values | content
stringlengths 11
9.34M
|
---|---|---|---|---|
RREE/ada-util | Ada | 2,118 | adb | -----------------------------------------------------------------------
-- compress -- Compress file using Util.Streams.Buffered.LZMA
-- Copyright (C) 2019, 2021 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Text_IO;
with Ada.Command_Line;
with Ada.Streams.Stream_IO;
with Util.Streams.Files;
with Util.Streams.Buffered.Lzma;
procedure Compress is
procedure Compress_File (Source : in String;
Destination : in String);
procedure Compress_File (Source : in String;
Destination : in String) is
In_Stream : aliased Util.Streams.Files.File_Stream;
Out_Stream : aliased Util.Streams.Files.File_Stream;
Compressor : aliased Util.Streams.Buffered.Lzma.Compress_Stream;
begin
In_Stream.Open (Mode => Ada.Streams.Stream_IO.In_File, Name => Source);
Out_Stream.Create (Mode => Ada.Streams.Stream_IO.Out_File, Name => Destination);
Compressor.Initialize (Output => Out_Stream'Unchecked_Access, Size => 32768);
Util.Streams.Copy (From => In_Stream, Into => Compressor);
end Compress_File;
begin
if Ada.Command_Line.Argument_Count /= 2 then
Ada.Text_IO.Put_Line ("Usage: compress source destination");
return;
end if;
Compress_File (Source => Ada.Command_Line.Argument (1),
Destination => Ada.Command_Line.Argument (2));
end Compress;
|
stcarrez/dynamo | Ada | 111,915 | ads | ------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT INTERFACE COMPONENTS --
-- --
-- A S I S . D E C L A R A T I O N S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2006-2012, Free Software Foundation, Inc. --
-- --
-- This specification is adapted from the Ada Semantic Interface --
-- Specification Standard (ISO/IEC 15291) for use with GNAT. In accordance --
-- with the copyright of that document, you can freely copy and modify this --
-- specification, provided that if you redistribute a modified version, any --
-- changes that you have made are clearly indicated. --
-- --
-- This specification also contains suggestions and discussion items --
-- related to revising the ASIS Standard according to the changes proposed --
-- for the new revision of the Ada standard. The copyright notice above, --
-- and the license provisions that follow apply solely to these suggestions --
-- and discussion items that are separated by the corresponding comment --
-- sentinels --
-- --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- 15 package Asis.Declarations
-- Suggestions related to changing this specification to accept new Ada
-- features as defined in incoming revision of the Ada Standard (ISO 8652)
-- are marked by following comment sentinels:
--
-- --|A2005 start
-- ... the suggestion goes here ...
-- --|A2005 end
--
-- and the discussion items are marked by the comment sentinels of teh form:
--
-- --|D2005 start
-- ... the discussion item goes here ...
-- --|D2005 end
------------------------------------------------------------------------------
------------------------------------------------------------------------------
package Asis.Declarations is
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Asis.Declarations encapsulates a set of queries that operate on
-- A_Defining_Name and A_Declaration elements.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- --|ER A_Declaration - 3.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- 15.1 function Names
------------------------------------------------------------------------------
function Names
(Declaration : Asis.Declaration)
return Asis.Defining_Name_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the element to query
--
-- Returns a list of names defined by the declaration, in their order of
-- appearance. Declarations that define a single name will return a list of
-- length one.
--
-- Returns Nil_Element_List for A_Declaration Elements representing the
-- (implicit) declarations of universal and root numeric type (that is, if
-- Type_Kind (Type_Declaration_View (Declaration) = A_Root_Type_Definition.
--
-- Examples:
-- type Foo is (Pooh, Baah);
-- -- Returns a list containing one A_Defining_Name: Foo.
--
-- One, Uno : constant Integer := 1;
-- -- Returns a list of two A_Defining_Name elements: One and Uno.
--
-- Function designators that define operators are A_Defining_Operator_Symbol.
--
-- Results of this query may vary across ASIS implementations. Some
-- implementations may normalize all multi-name declarations into an
-- equivalent series of corresponding single name declarations. For those
-- implementations, this query will always return a list containing a single
-- name. See Reference Manual 3.3.1(7).
--
-- Appropriate Element_Kinds:
-- A_Declaration
--
-- Returns Element_Kinds:
-- A_Defining_Name
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Defining_Name - 3.1
-- --|ER---------------------------------------------------------------------
-- --|ER A_Defining_Identifier - 3.1 - no child elements
-- --|ER A_Defining_Operator_Symbol - 6.1 - no child elements
-- --|ER
-- --|ER A string image returned by:
-- --|ER function Defining_Name_Image
------------------------------------------------------------------------------
-- 15.2 function Defining_Name_Image
------------------------------------------------------------------------------
function Defining_Name_Image
(Defining_Name : Asis.Defining_Name)
return Program_Text;
------------------------------------------------------------------------------
-- Defining_Name - Specifies the element to query
--
-- Returns the program text image of the name. Embedded quotes (for operator
-- designator strings) are doubled.
--
-- A_Defining_Identifier elements are simple identifier names "Abc"
-- (name Abc).
--
-- A_Defining_Operator_Symbol elements have names with embedded quotes
-- """abs""" (function "abs").
--
-- A_Defining_Character_Literal elements have names with embedded apostrophes
-- "'x'" (literal 'x').
--
-- A_Defining_Enumeration_Literal elements have simple identifier names
-- "Blue" (literal Blue). If A_Defining_Enumeration_Literal element is of type
-- Character or Wide_Character but does not have a graphical presentation,
-- then the result is implementation-dependent.
--
-- A_Defining_Expanded_Name elements are prefix.selector names "A.B.C"
-- (name A.B.C).
--
-- The case of names returned by this query may vary between implementors.
-- Implementors are encouraged, but not required, to return names in the
-- same case as was used in the original compilation text.
--
-- The Defining_Name_Image of a label_statement_identifier does not include
-- the enclosing "<<" and ">>" that form the label syntax. Similarly, the
-- Defining_Name_Image of an identifier for a loop_statement or
-- block_statement does not include the trailing colon that forms the loop
-- name syntax. Use Asis.Text.Element_Image or Asis.Text.Lines queries to
-- obtain these syntactic constructs and any comments associated with them.
--
-- Appropriate Element_Kinds:
-- A_Defining_Name
-- --|ER---------------------------------------------------------------------
-- --|ER A_Defining_Character_Literal - 3.5.1 - no child elements
-- --|ER A_Defining_Enumeration_Literal - 3.5.1 - no child elements
-- --|ER
-- --|ER A program text image returned by:
-- --|ER function Defining_Name_Image
-- --|ER
-- --|ER A program text image of the enumeration literal value returned by:
-- --|ER function Position_Number_Image
-- --|ER function Representation_Value_Image
-- --
------------------------------------------------------------------------------
-- 15.3 function Position_Number_Image
------------------------------------------------------------------------------
function Position_Number_Image
(Defining_Name : Asis.Defining_Name)
return Wide_String;
------------------------------------------------------------------------------
-- Expression - Specifies the literal expression to query
--
-- Returns the program text image of the position number of the value of the
-- enumeration literal.
--
-- The program text returned is the image of the universal_integer value that
-- is returned by the attribute 'Pos if it were applied to the value.
-- For example: Integer'Image(Color'Pos(Blue)).
--
-- Appropriate Defining_Name_Kinds:
-- A_Defining_Character_Literal
-- A_Defining_Enumeration_Literal
--
------------------------------------------------------------------------------
-- 15.4 function Representation_Value_Image
------------------------------------------------------------------------------
function Representation_Value_Image
(Defining_Name : Asis.Defining_Name)
return Wide_String;
------------------------------------------------------------------------------
-- Expression - Specifies the literal expression to query
--
-- Returns the string image of the internal code for the enumeration literal.
--
-- If a representation_clause is defined for the enumeration type then the
-- string returned is the Integer'Wide_Image of the corresponding value given
-- in the enumeration_aggregate. Otherwise, the string returned is the same
-- as the Position_Number_Image.
--
-- Appropriate Defining_Name_Kinds:
-- A_Defining_Character_Literal
-- A_Defining_Enumeration_Literal
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Defining_Expanded_Name - 6.1
-- --|ER
-- --|ER A string image returned by:
-- --|ER function Defining_Name_Image
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Defining_Prefix
-- --|CR function Defining_Selector
------------------------------------------------------------------------------
-- 15.5 function Defining_Prefix
------------------------------------------------------------------------------
function Defining_Prefix
(Defining_Name : Asis.Defining_Name)
return Asis.Name;
------------------------------------------------------------------------------
-- Defining_Name - Specifies the element to query
--
-- Returns the element that forms the prefix of the name. The prefix is the
-- name to the left of the rightmost 'dot' in the expanded name.
-- The Defining_Prefix of A.B is A, and of A.B.C is A.B.
--
-- Appropriate Defining_Name_Kinds:
-- A_Defining_Expanded_Name
--
-- Returns Expression_Kinds:
-- An_Identifier
-- A_Selected_Component
--
------------------------------------------------------------------------------
-- 15.6 function Defining_Selector
------------------------------------------------------------------------------
function Defining_Selector
(Defining_Name : Asis.Defining_Name)
return Asis.Defining_Name;
------------------------------------------------------------------------------
-- Defining_Name - Specifies the element to query
--
-- Returns the element that forms the selector of the name. The selector is
-- the name to the right of the rightmost 'dot' in the expanded name.
-- The Defining_Selector of A.B is B, and of A.B.C is C.
--
-- Appropriate Defining_Name_Kinds:
-- A_Defining_Expanded_Name
--
-- Returns Defining_Name_Kinds:
-- A_Defining_Identifier
--
-- --|ER---------------------------------------------------------------------
-- --|ER An_Ordinary_Type_Declaration - 3.2.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Discriminant_Part
-- --|CR function Type_Declaration_View
------------------------------------------------------------------------------
-- 15.7 function Discriminant_Part
------------------------------------------------------------------------------
function Discriminant_Part
(Declaration : Asis.Declaration)
return Asis.Definition;
------------------------------------------------------------------------------
-- Declaration - Specifies the type declaration to query
--
-- Returns the discriminant_part, if any, from the type_declaration or
-- formal_type_declaration.
--
-- Returns a Nil_Element if the Declaration has no explicit discriminant_part.
--
-- Appropriate Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- An_Incomplete_Type_Declaration
-- |A2005 start
-- A_Tagged_Incomplete_Type_Declaration (implemented)
-- |A2005 end
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- A_Formal_Type_Declaration
--
-- Returns Definition_Kinds:
-- Not_A_Definition
-- An_Unknown_Discriminant_Part
-- A_Known_Discriminant_Part
--
------------------------------------------------------------------------------
-- 15.8 function Type_Declaration_View
------------------------------------------------------------------------------
function Type_Declaration_View
(Declaration : Asis.Declaration)
return Asis.Definition;
------------------------------------------------------------------------------
-- Declaration - Specifies the declaration element to query
--
-- Returns the definition characteristics that form the view of the
-- type_declaration. The view is the remainder of the declaration following
-- the reserved word "is".
--
-- For a full_type_declaration, returns the type_definition, task_definition,
-- or protected_definition following the reserved word "is" in the
-- declaration.
--
-- Returns a Nil_Element for a task_type_declaration that has no explicit
-- task_definition.
--
-- For a private_type_declaration or private_extension_declaration, returns
-- the definition element representing the private declaration view.
--
-- For a subtype_declaration, returns the subtype_indication.
--
-- For a formal_type_declaration, returns the formal_type_definition.
--
-- Appropriate Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- A_Subtype_Declaration
-- A_Formal_Type_Declaration
--
-- Returns Definition_Kinds:
-- Not_A_Definition
-- A_Type_Definition
-- A_Subtype_Indication
-- A_Private_Type_Definition
-- A_Tagged_Private_Type_Definition
-- A_Private_Extension_Definition
-- A_Task_Definition
-- A_Protected_Definition
-- A_Formal_Type_Definition
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Subtype_Declaration - 3.2.2
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Type_Declaration_View
-- --|ER---------------------------------------------------------------------
-- --|ER A_Variable_Declaration - 3.3.1
-- --|CR
-- --|CR Child elements:
-- --|CR function Names
-- --|CR function Object_Declaration_View
-- --|CR function Initialization_Expression
--
------------------------------------------------------------------------------
-- 15.9 function Object_Declaration_View
------------------------------------------------------------------------------
function Object_Declaration_View
(Declaration : Asis.Declaration)
return Asis.Definition;
------------------------------------------------------------------------------
-- Declaration - Specifies the declaration element to query
--
-- Returns the definition characteristics that form the view of the
-- object_declaration.
-- --|A2005 start
-- The view is the subtype_indication, a full type
-- definition of the object_declaration, a subtype mark or an access
-- definition. An initial value, if any, is not
-- part of this view.
-- --|A2005 end
--
-- For a single_task_declaration or single_protected_declaration, returns
-- the task_definition or protected_definition following the reserved word
-- "is".
--
-- Returns a Nil_Element for a single_task_declaration that has no explicit
-- task_definition.
--
-- --D2005 start
-- For a declaration containing a colon, returns the definition element
-- representing the part of the declaration following the colon.
-- --|D2005 end
--
-- Appropriate Declaration_Kinds:
-- A_Variable_Declaration
-- A_Constant_Declaration
-- A_Deferred_Constant_Declaration
-- A_Single_Protected_Declaration
-- A_Single_Task_Declaration
-- A_Component_Declaration
-- --|A2005 start
-- A_Discriminant_Specification (implemented)
-- A_Parameter_Specification (implemented)
-- A_Return_Object_Declaration
-- A_Formal_Object_Declaration
-- An_Object_Renaming_Declaration
-- --|A2005 end
--
-- Returns Definition_Kinds:
-- Not_A_Definition
-- A_Type_Definition
-- Returns Type_Kinds:
-- A_Constrained_Array_Definition
-- A_Subtype_Indication
-- A_Task_Definition
-- A_Protected_Definition
-- A_Component_Definition
-- --|A2005 start
-- An_Access_Definition
--
-- Returns Expression_Kinds:
-- An_Identifier
-- A_Selected_Component
-- An_Attribute_Reference
-- --D2005 start
-- The wording of the query definition needs some more revising
--
-- Probably we need a kind of an Application Note here that would say that
-- in ASIS this query is the only proper way to get a definition of any
-- object, and that Declaration_Subtype_Mark query should not be used in ASIS
-- applications that are supposed to analyze Ada 2005 code.
-- --|D2005 end
-- --|A2005 end
-- --|A2010 start
function Aspect_Specifications
(Declaration : Asis.Element)
return Asis.Element_List;
------------------------------------------------------------------------------
-- Returns a list of aspect specifications given for the declaration, in
-- their order of appearance. Returns Nil_Element_List if no aspect
-- specification is given for the declaration. Returns Nil_Element_List
-- if Is_Part_Of_Inherited (Declaration)
--
-- Appropriate Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Single_Task_Declaration
-- A_Single_Protected_Declaration
-- A_Variable_Declaration
-- A_Constant_Declaration
-- A_Component_Declaration
-- A_Procedure_Declaration
-- A_Null_Procedure_Declaration
-- A_Function_Declaration
-- An_Expression_Function_Declaration
-- A_Package_Declaration
-- A_Package_Body_Declaration
-- An_Object_Renaming_Declaration
-- An_Exception_Renaming_Declaration
-- A_Package_Renaming_Declaration
-- A_Procedure_Renaming_Declaration
-- A_Function_Renaming_Declaration
-- A_Generic_Package_Renaming_Declaration
-- A_Generic_Procedure_Renaming_Declaration
-- A_Generic_Function_Renaming_Declaration
-- A_Task_Body_Declaration
-- A_Protected_Body_Declaration
-- An_Exception_Declaration
-- A_Generic_Package_Declaration
-- A_Package_Instantiation
-- A_Procedure_Instantiation
-- A_Function_Instantiation
-- A_Formal_Object_Declaration
-- A_Formal_Type_Declaration
-- A_Formal_Procedure_Declaration
-- A_Formal_Function_Declaration
-- A_Formal_Package_Declaration
-- A_Formal_Package_Declaration_With_Box)
--
-- Returns Definition_Kinds:
-- An_Aspect_Specification
-- --|A2010 end
------------------------------------------------------------------------------
-- 15.10 function Initialization_Expression
------------------------------------------------------------------------------
function Initialization_Expression
(Declaration : Asis.Declaration)
return Asis.Expression;
------------------------------------------------------------------------------
-- Declaration - Specifies the object declaration to query
--
-- Returns the initialization expression [:= expression] of the declaration.
--
-- Returns a Nil_Element if the declaration does not include an explicit
-- initialization.
--
-- Appropriate Declaration_Kinds:
-- A_Variable_Declaration
-- A_Constant_Declaration
-- An_Integer_Number_Declaration
-- A_Real_Number_Declaration
-- A_Discriminant_Specification
-- A_Component_Declaration
-- A_Parameter_Specification
-- |A2005 start
-- A_Return_Object_Declaration
-- |A2005 end
-- A_Formal_Object_Declaration
--
-- Returns Element_Kinds:
-- Not_An_Element
-- An_Expression
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Constant_Declaration - 3.3.1
-- --|CR
-- --|CR Child elements:
-- --|CR function Names
-- --|CR function Object_Declaration_View
-- --|CR function Initialization_Expression
-- --|CR
-- --|CR Element queries that provide semantically related elements:
-- --|CR function Corresponding_Constant_Declaration
--
------------------------------------------------------------------------------
-- 15.11 function Corresponding_Constant_Declaration
------------------------------------------------------------------------------
function Corresponding_Constant_Declaration
(Name : Asis.Defining_Name)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Name - Specifies the name of a constant declaration to query
--
-- Returns the corresponding full constant declaration when given the name
-- from a deferred constant declaration.
--
-- Returns the corresponding deferred constant declaration when given the name
-- from a full constant declaration.
--
-- Returns a Nil_Element if the deferred constant declaration is completed
-- by a pragma Import.
--
-- Returns a Nil_Element if the full constant declaration has no corresponding
-- deferred constant declaration.
--
-- Raises ASIS_Inappropriate_Element with a Status of Value_Error if the
-- argument is not the name of a constant or a deferred constant.
--
-- The name of a constant declaration is available from both the Names and the
-- Corresponding_Name_Definition queries.
--
-- Appropriate Element_Kinds:
-- A_Defining_Name
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- A_Constant_Declaration
-- A_Deferred_Constant_Declaration
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Deferred_Constant_Declaration - 3.3.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Object_Declaration_View
-- --|ER---------------------------------------------------------------------
-- --|ER An_Integer_Number_Declaration - 3.3.2
-- --|ER A_Real_Number_Declaration - 3.3.2
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Initialization_Expression
-- --|ER---------------------------------------------------------------------
-- --|ER An_Enumeration_Literal_Specification - 3.5.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|ER---------------------------------------------------------------------
-- --|ER A_Discriminant_Specification - 3.7
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Declaration_Subtype_Mark
-- --|CR function Initialization_Expression
--
------------------------------------------------------------------------------
-- 15.12 function Declaration_Subtype_Mark
------------------------------------------------------------------------------
function Declaration_Subtype_Mark
(Declaration : Asis.Declaration)
return Asis.Expression;
------------------------------------------------------------------------------
-- Declaration - Specifies the declaration element to query
--
-- Returns the expression element that names the subtype_mark of the
-- declaration.
--
-- --|A2005 start
-- --|D2005 start
-- In ASIS 2005 this query is an obsolescent feature, it should not be used
-- for analyzing Ada 2005 code. We need a proper warning note in the ASIS
-- Standard. See also Object_Declaration_View
-- --|D2005 end
-- --|A2005 end
-- Appropriate Declaration_Kinds:
-- A_Discriminant_Specification
-- A_Parameter_Specification
-- A_Formal_Object_Declaration
-- An_Object_Renaming_Declaration
--
-- Returns Expression_Kinds:
-- An_Identifier
-- A_Selected_Component
-- An_Attribute_Reference
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Component_Declaration - 3.8
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Object_Declaration_View
-- --|CR function Initialization_Expression
-- --|ER---------------------------------------------------------------------
-- --|ER An_Incomplete_Type_Declaration - 3.10.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Discriminant_Part
--
------------------------------------------------------------------------------
-- 15.13 function Corresponding_Type_Declaration
------------------------------------------------------------------------------
function Corresponding_Type_Declaration
(Declaration : Asis.Declaration)
return Asis.Declaration;
function Corresponding_Type_Declaration
(Declaration : Asis.Declaration;
The_Context : Asis.Context)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Declaration - Specifies the type declaration to query
-- The_Context - Specifies the program Context to use for obtaining package
-- body information
--
-- Returns the corresponding full type declaration when given a private or
-- incomplete type declaration. Returns the corresponding private or
-- incomplete type declaration when given a full type declaration.
--
-- These two function calls will always produce identical results:
--
-- Decl2 := Corresponding_Type_Declaration ( Decl1 );
-- Decl2 := Corresponding_Type_Declaration
-- ( Decl1,
-- Enclosing_Context ( Enclosing_Compilation_Unit ( Decl1 )));
--
-- Returns a Nil_Element when a full type declaration is given that has no
-- corresponding private or incomplete type declaration, or when a
-- corresponding type declaration does not exist within The_Context.
--
-- The parameter The_Context is used whenever the corresponding full type of
-- an incomplete type is in a corresponding package body. See Reference Manual
-- 3.10.1(3). Any non-Nil result will always have the given Context as its
-- Enclosing_Context.
--
-- Appropriate Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- An_Incomplete_Type_Declaration
-- |A2005 start
-- A_Tagged_Incomplete_Type_Declaration (implemented)
-- |A2005 end
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- An_Incomplete_Type_Declaration
-- |A2005 start
-- A_Tagged_Incomplete_Type_Declaration (implemented)
-- |A2005 end
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
--
-- --|AN Application Note:
-- --|AN
-- --|AN This function is an obsolescent feature for Ada/ASIS 2012, because
-- --|AN in Ada 2012 an incomplete type can be completed by a private type
-- --|AN and then the private type is completed by a full type declaration.
-- --|AN In this case when allied to the private type declaration, the query
-- --|AN has no way to know which corresponding type declaration (incomplete
-- --|AN or full) should be returned as the result. In this case the query
-- --|AN raises ASIS_Inappropriate_Element
-- --|AN
-- --|AN If an application is supposed to be able to process Ada 2012,
-- --|AN do not use this query and use two new queries:
-- --|AN
-- --|AN Corresponding_Type_Completion
-- --|AN and
-- --|AN Corresponding_Type_Partial_View
-- --|A2010 start
------------------------------------------------------------------------------
-- 15.??? function Corresponding_Type_Completion
------------------------------------------------------------------------------
function Corresponding_Type_Completion
(Declaration : Asis.Declaration)
return Asis.Declaration;
-- Declaration - Specifies the type declaration to query
--
-- Returns the type declaration that is a completion of an argument private or
-- incomplete type declaration. In case when the argument is an incomplete
-- type declaration that is completed by a private type declaration and this
-- private type declaration is in turn completed by a full type declaration,
-- the result is the private type declaration but not the full type
-- declaration.
--
-- Returns a Nil_Element when an incomplete type declaration is given but
-- the corresponding completion does not exist within the enclosing Context.
--
-- Appropriate Declaration_Kinds:
-- An_Incomplete_Type_Declaration
-- A_Tagged_Incomplete_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
------------------------------------------------------------------------------
-- 15.??? function Corresponding_Type_Partial_View
------------------------------------------------------------------------------
function Corresponding_Type_Partial_View
(Declaration : Asis.Declaration)
return Asis.Declaration;
-- Declaration - Specifies the type declaration to query
--
-- Returns the type declaration the argument declaration is a completion for.
-- In case when the argument is a full type declaration that is a completion
-- of a private type (or private extension) declaration that is in turn the
-- completion of an incomplete type declaration, the result is the private
-- type (private extension) declaration but not the incomplete type
-- declaration.
--
-- Returns a Nil_Element when an argument declaration is not a completion of
-- any incomplete/private type declaration.
--
-- Appropriate Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- An_Incomplete_Type_Declaration
-- A_Tagged_Incomplete_Type_Declaration (implemented)
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- --|A2010 end
------------------------------------------------------------------------------
-- 15.14 function Corresponding_First_Subtype
------------------------------------------------------------------------------
function Corresponding_First_Subtype
(Declaration : Asis.Declaration)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Declaration - Specifies the subtype_declaration to query
--
-- This function recursively unwinds subtyping to return at a type_declaration
-- that defines the first subtype of the argument.
--
-- Returns a declaration that Is_Identical to the argument if the argument is
-- already the first subtype.
--
-- --|D2005 start
-- We need to define the effect of this function in case if the argument
-- represents a subtype declaration of the form:
--
-- subtype St is T'Class;
-- or
-- subtype St_1 is St;
--
-- I would add the following paragraph:
--
-- If the argument is a subtype of a class-wide type, returns the
-- declaration of the specific type that is a root type of the class.
--
-- Probably, we need also to add to the core ASIS the following query:
--
-- function Is_Class_Wide
-- (Declaration : Asis.Declaration)
-- return Boolean;
--
------------------------------------------------------------------------------
-- Declaration - Specifies the subtype_declaration to query
--
-- This function checks if the argument subtype is a subtype of some
-- class-wide type.
--
-- Returns False for any unexpected Element
--
-- Expected Declaration_Kinds:
-- A_Subtype_Declaration
--
-- |D2005 end
--
-- Appropriate Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- A_Subtype_Declaration
-- A_Formal_Type_Declaration
--
-- Returns Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- A_Formal_Type_Declaration
--
------------------------------------------------------------------------------
-- 15.15 function Corresponding_Last_Constraint
------------------------------------------------------------------------------
function Corresponding_Last_Constraint
(Declaration : Asis.Declaration)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Declaration - Specifies the subtype_declaration or type_declaration to
-- query.
--
-- This function recursively unwinds subtyping to return at a declaration
-- that is either a type_declaration or subtype_declaration that imposes
-- an explicit constraint on the argument.
--
-- Unwinds a minimum of one level of subtyping even if an argument declaration
-- itself has a constraint.
--
-- Returns a declaration that Is_Identical to the argument if the argument is
-- a type_declaration, i.e. the first subtype.
--
-- Appropriate Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- A_Subtype_Declaration
-- A_Formal_Type_Declaration
--
-- Returns Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- A_Subtype_Declaration
-- A_Formal_Type_Declaration
--
------------------------------------------------------------------------------
-- 15.16 function Corresponding_Last_Subtype
------------------------------------------------------------------------------
function Corresponding_Last_Subtype
(Declaration : Asis.Declaration)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Declaration - Specifies the subtype_declaration or type_declaration
-- to query.
--
-- This function unwinds subtyping a single level to arrive at a declaration
-- that is either a type_declaration or subtype_declaration.
--
-- Returns a declaration that Is_Identical to the argument if the argument is
-- a type_declaration (i.e., the first subtype).
--
-- --|D2005 start
-- The existing definition of this query does not work in case if the argument
-- A_Subtype_Declaration Element contains an attribute reference as
-- subtype_mark in subtype_indication part. Consider:
--
-- subtype A is B'Class;
-- or
-- subtype C is D'Base;
--
-- The proper solution here seems to be returning the declaration of B and D
-- respectively. We need a paragraph in the query definition describing this.
--
-- --|D2005 end
--
-- Appropriate Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- A_Subtype_Declaration
-- A_Formal_Type_Declaration
--
-- Returns Declaration_Kinds:
-- An_Ordinary_Type_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- A_Subtype_Declaration
-- A_Formal_Type_Declaration
--
------------------------------------------------------------------------------
-- 15.17 function Corresponding_Representation_Clauses
------------------------------------------------------------------------------
function Corresponding_Representation_Clauses
(Declaration : Asis.Declaration)
return Asis.Representation_Clause_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the declaration to query
--
-- Returns all representation_clause elements that apply to the declaration.
--
-- Returns a Nil_Element_List if no clauses apply to the declaration.
--
-- The clauses returned may be the clauses applying to a parent type if the
-- type is a derived type with no explicit representation. These clauses
-- are not Is_Part_Of_Implicit, they are the representation_clause elements
-- specified in conjunction with the declaration of the parent type.
--
-- All Declaration_Kinds are appropriate except Not_A_Declaration.
--
-- Returns Clause_Kinds:
-- A_Representation_Clause
--
-- --|D2005 start
-- This query works on declarations, but representation clauses are applied
-- to entities, but not declarations. The problem here is that one declaration
-- may declare several entities, and each of these entities may have its
-- own collection of representation clauses applied to the entity. It seems
-- that what is of areal interest for an ASIS application is a set of queries
-- applied to a particular entity, but not a union of representation clauses
-- applied to all the entities declared in the given declaration.
--
-- So it would be nice to have Corresponding_Representation_Clauses working on
-- entities (A_Defining_Name Elements), but not declarations. We can not
-- change the semantic of this query because of upward compatibility reasons,
-- so we can consider adding a new query -
-- Corresponding_Entity_Representation_Clauses, that will work on entities
-- (A_Defining_Name Elements)
-- --|D2005 end
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Loop_Parameter_Specification - 5.5
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Specification_Subtype_Definition
--
------------------------------------------------------------------------------
-- 15.18 function Specification_Subtype_Definition
------------------------------------------------------------------------------
function Specification_Subtype_Definition
(Specification : Asis.Declaration)
return Asis.Discrete_Subtype_Definition;
------------------------------------------------------------------------------
-- Specification - Specifies the loop_parameter_specification or
-- Entry_Index_Specification to query
--
-- Returns the Discrete_Subtype_Definition of the specification.
--
-- Appropriate Declaration_Kinds:
-- A_Loop_Parameter_Specification
-- An_Entry_Index_Specification
--
-- Returns Definition_Kinds:
-- A_Discrete_Subtype_Definition
--
-- --|A2012 start
--
-- Below is the draft proposal for new iterator syntax in Ada 2012. This
-- proposal has not been discussed with ARG yet, so it has enough chances
-- to be changed
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Generalized_Iterator_Specification - 5.5.2
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Iteration_Scheme_Name
--
-- --|ER---------------------------------------------------------------------
-- --|ER An_Element_Iterator_Specification - 5.5.2
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Subtype_Indication
-- --|CR function Name
--
-- --|A2012 end
function Iteration_Scheme_Name
(Iterator_Specification : Asis.Element)
return Asis.Element;
-- Specification - Specifies the iterator specification to query
--
-- Returns the name of the iterator routine or array/iterable name that
-- follows the keywird IN/OF [RESERVE]
--
-- Appropriate Declaration_Kinds:
-- A_Generalized_Iterator_Specification
-- An_Element_Iterator_Specification
--
-- Returns Element_Kind
-- An_Expression
--
function Subtype_Indication
(Iterator_Specification : Asis.Element)
return Asis.Element;
-- Specification - Specifies the iterator specification to query
--
-- Returns the subtype indication that is used in the specification of
-- iterator parameter. Returns Nil_Element if there is no subtype indication.
--
-- Appropriate Declaration_Kinds:
-- An_Element_Iterator_Specification
--
-- Returns Definition_Kinds:
-- A_Subtype_Indication
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Procedure_Declaration - 6.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Parameter_Profile
--
------------------------------------------------------------------------------
-- 15.19 function Parameter_Profile
------------------------------------------------------------------------------
function Parameter_Profile
(Declaration : Asis.Declaration)
return Asis.Parameter_Specification_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the subprogram or entry declaration to query
--
-- Returns a list of parameter specifications in the formal part of the
-- subprogram or entry declaration, in their order of appearance.
--
-- Returns a Nil_Element_List if the subprogram or entry has no
-- parameters.
--
-- Results of this query may vary across ASIS implementations. Some
-- implementations normalize all multiple name parameter specifications into
-- an equivalent sequence of corresponding single name parameter
-- specifications. See Reference Manual 3.3.1(7).
--
-- Appropriate Declaration_Kinds:
-- A_Procedure_Declaration
-- A_Function_Declaration
-- A_Procedure_Body_Declaration
-- A_Function_Body_Declaration
-- |A2005 start
-- A_Null_Procedure_Declaration (implemented)
-- |A2005 end
-- A_Procedure_Renaming_Declaration
-- A_Function_Renaming_Declaration
-- An_Entry_Declaration
-- An_Entry_Body_Declaration
-- A_Procedure_Body_Stub
-- A_Function_Body_Stub
-- A_Generic_Function_Declaration
-- A_Generic_Procedure_Declaration
-- A_Formal_Function_Declaration
-- A_Formal_Procedure_Declaration
-- An_Expression_Function_Declaration
--
-- Returns Declaration_Kinds:
-- A_Parameter_Specification
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Function_Declaration - 6.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Parameter_Profile
-- --|CR function Result_Profile
--
------------------------------------------------------------------------------
-- 15.20 function Result_Profile
------------------------------------------------------------------------------
function Result_Profile
(Declaration : Asis.Declaration)
-- |A2005 start
return Asis.Element;
-- |A2005 end
------------------------------------------------------------------------------
-- Declaration - Specifies the function declaration to query
--
-- |A2005 start
-- Returns the definition for the return type for the function. It may
-- be subtype_mark expression or anonymous access_definition
-- |A2005 end
--
-- Appropriate Declaration_Kinds:
-- A_Function_Declaration
-- A_Function_Body_Declaration
-- A_Function_Body_Stub
-- A_Function_Renaming_Declaration
-- A_Generic_Function_Declaration
-- A_Formal_Function_Declaration
--
-- Returns Expression_Kinds:
-- An_Identifier
-- A_Selected_Component
-- An_Attribute_Reference
--
-- |A2005 start
-- Returns Definition_Kinds:
-- An_Access_Definition
-- |A2005 end
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Parameter_Specification - 6.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Declaration_Subtype_Mark
-- --|CR function Initialization_Expression
-- --|ER---------------------------------------------------------------------
-- --|ER A_Procedure_Body_Declaration - 6.3
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Parameter_Profile
-- --|CR function Body_Declarative_Items
-- --|CR function Body_Statements
-- --|CR function Body_Exception_Handlers
-- --|CR function Body_Block_Statement - obsolescent, not recommended
--
-- |A2012 start
------------------------------------------------------------------------------
-- 15.#??? function Result_Expression
------------------------------------------------------------------------------
function Result_Expression
(Declaration : Asis.Declaration)
return Asis.Expression;
------------------------------------------------------------------------------
-- Declaration specifies the expression function declaration to query.
-- Returns an expression that defines the result of an expression function.
-- The parentheses that syntactically surround the expression are considered
-- as the part of the result. Thus, the Expression_Kind of the result is
-- always A_Parenthesized_Expression
--
-- Appropriate Declaration_Kinds:
-- An_Expression_Function_Declaration
--
-- Returns Expression_Kinds:
-- A_Parenthesized_Expression
--
-- |A2012 end
-- |A2005 start
------------------------------------------------------------------------------
-- 15.#??? function Is_Overriding_Declaration
------------------------------------------------------------------------------
function Is_Overriding_Declaration
(Declaration : Asis.Declaration)
return Boolean;
------------------------------------------------------------------------------
-- Declaration - Specifies the subprogram declaration to query
--
-- Returns True if the declaration contains the overriding indicator of the
-- form "overriding"
--
-- Returns False for any unexpected Element.
--
-- Expected Declaration_Kinds:
-- A_Procedure_Declaration
-- A_Function_Declaration
-- A_Procedure_Body_Declaration
-- A_Function_Body_Declaration
-- A_Null_Procedure_Declaration
-- A_Procedure_Renaming_Declaration
-- A_Function_Renaming_Declaration
-- An_Entry_Declaration
-- A_Procedure_Body_Stub
-- A_Function_Body_Stub
-- A_Procedure_Instantiation
-- A_Function_Instantiation
--
--
------------------------------------------------------------------------------
-- 15.#??? function Is_Not_Overriding_Declaration
------------------------------------------------------------------------------
function Is_Not_Overriding_Declaration
(Declaration : Asis.Declaration)
return Boolean;
------------------------------------------------------------------------------
-- Declaration - Specifies the subprogram declaration to query
--
-- Returns True if the declaration contains the overriding indicator of the
-- form "not overriding"
--
-- Returns False for any unexpected Element.
--
-- Expected Declaration_Kinds:
-- A_Procedure_Declaration
-- A_Function_Declaration
-- A_Procedure_Body_Declaration
-- A_Function_Body_Declaration
-- A_Null_Procedure_Declaration
-- A_Procedure_Renaming_Declaration
-- A_Function_Renaming_Declaration
-- An_Entry_Declaration
-- A_Procedure_Body_Stub
-- A_Function_Body_Stub
-- A_Procedure_Instantiation
-- A_Function_Instantiation
--
--
-- |A2005 end
------------------------------------------------------------------------------
-- 15.21 function Body_Declarative_Items
------------------------------------------------------------------------------
function Body_Declarative_Items
(Declaration : Asis.Declaration;
Include_Pragmas : Boolean := False)
return Asis.Element_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the body declaration to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of all basic declarations, representation specifications,
-- use clauses, and pragmas in the declarative part of the body, in their
-- order of appearance.
--
-- Returns a Nil_Element_List if there are no declarative_item or pragma
-- elements.
--
-- Results of this query may vary across ASIS implementations. Some
-- implementations normalize all multi-name declarations into an
-- equivalent sequence of corresponding single name object declarations.
-- See Reference Manual 3.3.1(7).
--
-- Appropriate Declaration_Kinds:
-- A_Function_Body_Declaration
-- A_Procedure_Body_Declaration
-- A_Package_Body_Declaration
-- A_Task_Body_Declaration
-- An_Entry_Body_Declaration
--
-- Returns Element_Kinds:
-- A_Pragma
-- A_Declaration
-- A_Clause
--
------------------------------------------------------------------------------
-- 15.22 function Body_Statements
------------------------------------------------------------------------------
function Body_Statements
(Declaration : Asis.Declaration;
Include_Pragmas : Boolean := False)
return Asis.Statement_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the body declaration to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of the statements and pragmas for the body, in
-- their order of appearance.
--
-- --|A2012 start
-- In case if a sequence_of_Statements in the argument Element contains
-- 'floating' labels (labels that completes sequence_of_statements and that
-- are not attached to any statement in the source code), the result list
-- contains as its last element an implicit A_Null_Statement element these
-- 'floating' labels are attached to. The Enclosing_Element of this implicit
-- A_Null_Statement element is the argument Element.
-- --|A2012 start
--
-- Returns a Nil_Element_List if there are no statements or pragmas.
--
-- Appropriate Declaration_Kinds:
-- A_Function_Body_Declaration
-- A_Procedure_Body_Declaration
-- A_Package_Body_Declaration
-- A_Task_Body_Declaration
-- An_Entry_Body_Declaration
--
-- Returns Element_Kinds:
-- A_Pragma
-- A_Statement
--
------------------------------------------------------------------------------
-- 15.23 function Body_Exception_Handlers
------------------------------------------------------------------------------
function Body_Exception_Handlers
(Declaration : Asis.Declaration;
Include_Pragmas : Boolean := False)
return Asis.Exception_Handler_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the body declaration to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of the exception_handler elements of the body, in their
-- order of appearance.
--
-- The only pragmas returned are those following the reserved word "exception"
-- and preceding the reserved word "when" of first exception handler.
--
-- Returns a Nil_Element_List if there are no exception_handler or pragma
-- elements.
--
-- Appropriate Declaration_Kinds:
-- A_Function_Body_Declaration
-- A_Procedure_Body_Declaration
-- A_Package_Body_Declaration
-- A_Task_Body_Declaration
-- An_Entry_Body_Declaration
--
-- Returns Element_Kinds:
-- An_Exception_Handler
-- A_Pragma
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Function_Body_Declaration - 6.3
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Parameter_Profile
-- --|CR function Result_Profile
-- --|CR function Body_Declarative_Items
-- --|CR function Body_Statements
-- --|CR function Body_Exception_Handlers
-- --|CR function Body_Block_Statement - obsolescent, not recommended
--
------------------------------------------------------------------------------
-- 15.24 function Body_Block_Statement
------------------------------------------------------------------------------
-- Function Body_Block_Statement is a new query that supplies the
-- equivalent combined functionality of the replaced queries:
-- Subprogram_Body_Block, Package_Body_Block, and Task_Body_Block.
-- Use of the query Body_Block_Statement is not recommended in new programs.
-- This functionality is redundant with the queries Body_Declarative_Items,
-- Body_Statements, and Body_Exception_Handlers.
-------------------------------------------------------------------------------
function Body_Block_Statement
(Declaration : Asis.Declaration)
return Asis.Statement;
-------------------------------------------------------------------------------
-- Declaration - Specifies the program unit body to query
--
-- Returns a block statement that is the structural equivalent of the body.
-- The block statement is not Is_Part_Of_Implicit. The block includes
-- the declarative part, the sequence of statements, and any exception
-- handlers.
--
-- Appropriate Declaration_Kinds:
-- A_Function_Body_Declaration
-- A_Procedure_Body_Declaration
-- A_Package_Body_Declaration
-- A_Task_Body_Declaration
-- An_Entry_Body_Declaration
--
-- Returns Statement_Kinds:
-- A_Block_Statement
--
-- --|AN Application Note:
-- --|AN
-- --|AN This function is an obsolescent feature retained for compatibility
-- --|AN with ASIS 83. It is never called by Traverse_Element. Use of this
-- --|AN query is not recommended in new programs.
--
------------------------------------------------------------------------------
-- 15.25 function Is_Name_Repeated
------------------------------------------------------------------------------
function Is_Name_Repeated
(Declaration : Asis.Declaration)
return Boolean;
------------------------------------------------------------------------------
-- Declaration - Specifies the declaration to query
--
-- Returns True if the name of the declaration is repeated after the "end"
-- which terminates the declaration.
--
-- Returns False for any unexpected Element.
--
-- Expected Declaration_Kinds:
-- A_Package_Declaration
-- A_Package_Body_Declaration
-- A_Procedure_Body_Declaration
-- A_Function_Body_Declaration
-- A_Generic_Package_Declaration
-- A_Task_Type_Declaration
-- A_Single_Task_Declaration
-- A_Task_Body_Declaration
-- A_Protected_Type_Declaration
-- A_Single_Protected_Declaration
-- A_Protected_Body_Declaration
-- An_Entry_Body_Declaration
--
------------------------------------------------------------------------------
-- 15.26 function Corresponding_Declaration
------------------------------------------------------------------------------
function Corresponding_Declaration
(Declaration : Asis.Declaration)
return Asis.Declaration;
function Corresponding_Declaration
(Declaration : Asis.Declaration;
The_Context : Asis.Context)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Declaration - Specifies the specification to query
-- The_Context - Specifies a Context to use
--
-- Returns the corresponding specification of a subprogram, package, or task
-- body declaration or an expression function declaration. Returns the
-- expanded generic specification template for generic instantiations. The
-- argument can be a Unit_Declaration from a Compilation_Unit, or, it can be
-- any appropriate body declaration from any declarative context.
--
-- These two function calls will always produce identical results:
--
-- Decl2 := Corresponding_Declaration (Decl1);
-- Decl2 := Corresponding_Declaration
-- (Decl1,
-- Enclosing_Context ( Enclosing_Compilation_Unit ( Decl1 )));
--
-- If a specification declaration is given, the same element is returned,
-- unless it is a generic instantiation or an inherited subprogram declaration
-- (see below).
--
-- If a subprogram renaming declaration is given:
--
-- a) in case of renaming-as-declaration, the same element is returned;
-- b) in case of renaming-as-body, the subprogram declaration completed
-- by this subprogram renaming declaration is returned.
-- (Reference Manual, 8.5.4(1))
--
-- Returns a Nil_Element if no explicit specification exists, or the
-- declaration is the proper body of a subunit.
--
-- The parameter The_Context is used to locate the corresponding specification
-- within a particular Context. The_Context need not be the Enclosing_Context
-- of the Declaration. Any non-Nil result will always have The_Context
-- as its Enclosing_Context. This implies that while a non-Nil result may be
-- Is_Equal with the argument, it will only be Is_Identical if the
-- Enclosing_Context of the Declaration is the same as the parameter
-- The_Context.
--
-- If a generic instantiation is given, the expanded generic specification
-- template representing the instance is returned and Is_Part_Of_Instance.
-- For example, an argument that is A_Package_Instantiation, results in a
-- value that is A_Package_Declaration that can be analyzed with all
-- appropriate queries.
--
-- The Enclosing_Element of the expanded specification is the generic
-- instantiation. The Enclosing_Compilation_Unit of the expanded template is
-- that of the instantiation.
--
-- If an inherited subprogram declaration is given, the specification
-- returned is the one for the user-defined subprogram from which the
-- argument was ultimately inherited.
--
-- Appropriate Declaration_Kinds returning a specification:
-- A_Function_Body_Declaration
-- |A2012 start
-- An_Expression_Function_Declaration -- not implemented yet!!!
-- |A2012 end
-- A_Function_Renaming_Declaration (renaming-as-body)
-- A_Function_Body_Stub
-- A_Function_Instantiation
-- A_Package_Body_Declaration
-- A_Package_Body_Stub
-- A_Package_Instantiation
-- A_Procedure_Body_Declaration
-- A_Procedure_Renaming_Declaration (renaming-as-body)
-- A_Procedure_Body_Stub
-- A_Procedure_Instantiation
-- A_Task_Body_Declaration
-- A_Task_Body_Stub
-- A_Protected_Body_Declaration
-- A_Protected_Body_Stub
-- A_Formal_Package_Declaration
-- A_Formal_Package_Declaration_With_Box
-- A_Generic_Package_Renaming_Declaration
-- A_Generic_Procedure_Renaming_Declaration
-- A_Generic_Function_Renaming_Declaration
-- An_Entry_Body_Declaration
--
-- Appropriate Declaration_Kinds returning the argument Declaration:
-- A_Function_Declaration
-- A_Function_Renaming_Declaration (renaming-as-declaration)
-- A_Generic_Function_Declaration
-- A_Generic_Package_Declaration
-- A_Generic_Procedure_Declaration
-- A_Package_Declaration
-- A_Package_Renaming_Declaration
-- A_Procedure_Declaration
-- A_Null_Procedure_Declaration -- Ada 2005
-- A_Procedure_Renaming_Declaration (renaming-as-declaration)
-- A_Single_Task_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Single_Protected_Declaration
-- A_Generic_Package_Renaming_Declaration
-- A_Generic_Procedure_Renaming_Declaration
-- A_Generic_Function_Renaming_Declaration
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- A_Function_Declaration
-- A_Function_Renaming_Declaration
-- A_Generic_Function_Declaration
-- A_Generic_Package_Declaration
-- A_Generic_Procedure_Declaration
-- A_Package_Declaration
-- A_Package_Renaming_Declaration
-- A_Procedure_Declaration
-- A_Procedure_Renaming_Declaration
-- A_Single_Task_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Single_Protected_Declaration
-- An_Entry_Declaration
--
-- --|D2005 start
--
-- This function is defined for A_Formal_Package_Declaration_With_Box, and it
-- is supposed to return "the expanded generic specification template" for it.
-- But this form of a formal package denotes any possible instantiation of
-- some generic package, so we do not know anything about the actual
-- parameters to create an expanded instantiation. Moreover, RM95 12.7(10)
-- says:
--
-- The visible part of a formal package includes the first list of
-- basic_declarative_items of the package_specification. In addition, if
-- the formal_package_actual_part is (<>), it also includes the
-- generic_formal_part of the template for the formal package.
--
-- It seems that it would be more reasonable if this query would return the
-- argument declaration for the for A_Formal_Package_Declaration_With_Box
-- argument.
--
-- And for Ada/ASIS 2005 a similar problem arises for
-- A_Formal_Package_Declaration argument: what should be returned if
-- formal_package_actual_part contains formal_package_associations only for
-- some part of the formal parameters of the generic formal package?
--
-- --|D2005 end
------------------------------------------------------------------------------
-- 15.27 function Corresponding_Body
------------------------------------------------------------------------------
function Corresponding_Body
(Declaration : Asis.Declaration)
return Asis.Declaration;
function Corresponding_Body
(Declaration : Asis.Declaration;
The_Context : Asis.Context)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Declaration - Specifies the specification to query
-- The_Context - Specifies a Context to use
--
-- Returns the corresponding body for a given subprogram, package, or task
-- specification declaration. Returns the expanded generic body template for
-- generic instantiations. The argument can be a Unit_Declaration from a
-- Compilation_Unit, or, it can be any appropriate specification declaration
-- from any declarative context.
--
-- These two function calls will always produce identical results:
--
-- Decl2 := Corresponding_Body (Decl1);
-- Decl2 := Corresponding_Body
-- (Decl1,
-- Enclosing_Context ( Enclosing_Compilation_Unit( Decl1 )));
--
-- If a body declaration is given, the same element is returned.
--
-- Returns a Nil_Element if no body exists in The_Context.
--
-- The parameter The_Context is used to locate the corresponding specification
-- within a particular Context. The_Context need not be the Enclosing_Context
-- of the Declaration. Any non-Nil result will always have The_Context
-- as its Enclosing_Context. This implies that while a non-Nil result may be
-- Is_Equal with the argument, it will only be Is_Identical if the
-- Enclosing_Context of the Declaration is the same as the parameter
-- The_Context.
--
-- Implicit predefined operations (e.g., "+", "=", etc.) will not typically
-- have unit bodies. (Corresponding_Body returns a Nil_Element.)
-- User-defined overloads of the predefined operations will have
-- Corresponding_Body values once the bodies have inserted into the
-- environment. The Corresponding_Body of an inherited subprogram is that
-- of the original user-defined subprogram.
--
-- If a generic instantiation is given, the body representing the expanded
-- generic body template is returned. (i.e., an argument that is
-- A_Package_Instantiation, results in a value that is
-- A_Package_Body_Declaration that can be analyzed with all appropriate ASIS
-- queries).
--
-- Returns a Nil_Element if the body of the generic has not yet been compiled
-- or inserted into the Ada Environment Context.
--
-- The Enclosing_Element of the expanded body is the generic instantiation.
-- The Enclosing_Compilation_Unit of the expanded template is that of the
-- instantiation.
--
-- Returns Nil_Element for an implicit generic child unit specification.
-- Reference Manual 10.1.1(19).
--
-- Returns A_Pragma if the Declaration is completed by pragma Import.
--
-- Appropriate Declaration_Kinds returning a body:
-- A_Function_Declaration
-- A_Function_Instantiation
-- A_Generic_Package_Declaration
-- A_Generic_Procedure_Declaration
-- A_Generic_Function_Declaration
-- A_Package_Declaration
-- A_Package_Instantiation
-- A_Procedure_Declaration
-- A_Procedure_Instantiation
-- A_Single_Task_Declaration
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Single_Protected_Declaration
-- A_Formal_Package_Declaration
-- A_Formal_Package_Declaration_With_Box
-- An_Entry_Declaration (restricted to protected entry)
--
-- Appropriate Declaration_Kinds returning the argument Declaration:
-- A_Function_Body_Declaration
-- A_Function_Body_Stub
-- |A2012 start
-- An_Expression_Function_Declaration -- not implemented yet!!!
-- |A2012 end
-- A_Function_Renaming_Declaration
-- A_Package_Body_Declaration
-- A_Package_Body_Stub
-- A_Package_Renaming_Declaration
-- A_Procedure_Body_Declaration
-- A_Procedure_Renaming_Declaration
-- A_Procedure_Body_Stub
-- A_Task_Body_Declaration
-- A_Task_Body_Stub
-- A_Protected_Body_Declaration
-- A_Protected_Body_Stub
-- A_Generic_Package_Renaming_Declaration
-- A_Generic_Procedure_Renaming_Declaration
-- A_Generic_Function_Renaming_Declaration
-- An_Entry_Body_Declaration
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- A_Function_Body_Declaration
-- A_Function_Body_Stub
-- A_Function_Renaming_Declaration
-- A_Package_Body_Declaration
-- A_Package_Body_Stub
-- A_Procedure_Body_Declaration
-- A_Procedure_Renaming_Declaration
-- A_Procedure_Body_Stub
-- A_Task_Body_Declaration
-- A_Task_Body_Stub
-- A_Protected_Body_Declaration
-- A_Protected_Body_Stub
-- An_Entry_Body_Declaration
--
-- Returns Element_Kinds:
-- Not_An_Element
-- A_Declaration
-- A_Pragma
--
------------------------------------------------------------------------------
-- 15.28 function Corresponding_Subprogram_Derivation
------------------------------------------------------------------------------
function Corresponding_Subprogram_Derivation
(Declaration : Asis.Declaration)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Declaration - Specifies an implicit inherited subprogram declaration
--
-- Returns the subprogram declaration from which the given implicit inherited
-- subprogram argument was inherited. The result can itself be an implicitly
-- inherited subprogram.
--
-- Appropriate Element_Kinds:
-- A_Declaration
--
-- Appropriate Declaration_Kinds:
-- A_Function_Declaration
-- A_Procedure_Declaration
--
-- Returns Element_Kinds:
-- A_Declaration
--
-- Returns Declaration_Kinds:
-- A_Function_Body_Declaration
-- A_Function_Declaration
-- A_Function_Renaming_Declaration
-- A_Procedure_Body_Declaration
-- A_Procedure_Declaration
-- A_Procedure_Renaming_Declaration
--
-- Raises ASIS_Inappropriate_Element for a subprogram declaration that is not
-- Is_Part_Of_Inherited.
--
------------------------------------------------------------------------------
-- 15.29 function Corresponding_Type
------------------------------------------------------------------------------
function Corresponding_Type
(Declaration : Asis.Declaration)
return Asis.Type_Definition;
------------------------------------------------------------------------------
-- Declaration - Specifies the subprogram_declaration to query
--
-- Returns the type definition for which this entity is an implicit
-- declaration. The result will often be a derived type. However, this query
-- also works for declarations of predefined operators such as "+" and "=".
-- Raises ASIS_Inappropriate_Element if the argument is not an implicit
-- declaration resulting from the declaration of a type.
--
-- Appropriate Element_Kinds:
-- A_Declaration
--
-- Appropriate Declaration_Kinds:
-- A_Function_Declaration
-- A_Procedure_Declaration
--
-- Returns Definition_Kinds:
-- A_Type_Definition
--
------------------------------------------------------------------------------
-- 15.30 function Corresponding_Equality_Operator
------------------------------------------------------------------------------
function Corresponding_Equality_Operator
(Declaration : Asis.Declaration)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Declaration - Specifies an equality or an inequality operator declaration
--
-- If given an explicit Declaration of "=" whose result type is Boolean:
--
-- - Returns the complimentary implicit "/=" operator declaration.
--
-- - Returns a Nil_Element if the Ada implementation has not defined an
-- implicit "/=" for the "=". Implementations of this sort will transform
-- a A/=B expression into a NOT(A=B) expression. The function call
-- representing the NOT operation is Is_Part_Of_Implicit in this case.
--
-- If given an implicit Declaration of "/=" whose result type is Boolean:
--
-- - Returns the complimentary explicit "=" operator declaration.
--
-- Returns a Nil_Element for any other function declaration.
--
-- Appropriate Declaration_Kinds:
-- A_Function_Declaration
--
-- --|D2005 start
--
-- There are two problems with this query:
--
-- First, according to RM95 6.6, this query should also return the implicit
-- "/=" declaration also for the following Declaraion_Kinds
--
-- A_Function_Body_Declaration (in case if it acts as declaration,
-- otherwise the result should be
-- Nil_Element)
-- A_Function_Renaming_Declaration
--
-- The case of a function instantiation is covered by applying this query to
-- the result of Corresponding_Declaration
--
-- Second, what should be the result of the following queries applied to the
-- Element representing the implicit declaration of "/=":
-- Enclosing_Element
-- Corresponding_Declaration
-- Corresponding_Body?
--
-- For the moment, the following decision is made in the GNAT ASIS
-- implementation. If Decl is an Element representing this implicit
-- declaration of "/=", then:
--
--
-- - Is_Equal
-- (Enclosing_Element (Decl),
-- Enclosing_Element (Corresponding_Equality_Operator (Decl)))
--
-- - Is_Equal (Decl, Corresponding_Declaration (Decl))
--
-- - Is_Nil (Corresponding_Body (Decl)
--
-- --|D2005 end
--
-- Returns Declaration_Kinds:
-- A_Function_Declaration
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Package_Declaration - 7.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Visible_Part_Declarative_Items
-- --|CR function Private_Part_Declarative_Items
--
------------------------------------------------------------------------------
-- 15.31 function Visible_Part_Declarative_Items
------------------------------------------------------------------------------
function Visible_Part_Declarative_Items
(Declaration : Asis.Declaration;
Include_Pragmas : Boolean := False)
return Asis.Declarative_Item_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the package to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of all basic declarations, representation specifications,
-- use clauses, and pragmas in the visible part of a package, in their order
-- of appearance.
--
-- Results of this query may vary across ASIS implementations. Some
-- implementations normalize all multi-name object declarations into an
-- equivalent sequence of corresponding single name object declarations.
-- See Reference Manual 3.3.1(7).
--
-- Appropriate Declaration_Kinds:
-- A_Generic_Package_Declaration
-- A_Package_Declaration
--
-- Returns Element_Kinds:
-- A_Declaration
-- A_Pragma
-- A_Clause
--
------------------------------------------------------------------------------
-- 15.32 function Is_Private_Present
------------------------------------------------------------------------------
function Is_Private_Present
(Declaration : Asis.Declaration)
return Boolean;
------------------------------------------------------------------------------
-- Declaration - Specifies the declaration to query
--
-- Returns True if the argument is a package specification which has a
-- reserved word "private" which marks the beginning of a (possibly empty)
-- private part.
--
-- Returns False for any package specification without a private part.
-- Returns False for any unexpected Element.
--
-- Expected Element_Kinds:
-- A_Declaration
--
-- Expected Declaration_Kinds:
-- A_Generic_Package_Declaration
-- A_Package_Declaration
--
------------------------------------------------------------------------------
-- 15.33 function Private_Part_Declarative_Items
------------------------------------------------------------------------------
function Private_Part_Declarative_Items
(Declaration : Asis.Declaration;
Include_Pragmas : Boolean := False)
return Asis.Declarative_Item_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the package to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of all basic declarations, representation specifications,
-- use clauses, and pragmas in the private part of a package in their order of
-- appearance.
--
-- Results of this query may vary across ASIS implementations. Some
-- implementations normalize all multi-name object declarations into an
-- equivalent sequence of corresponding single name object declarations.
-- See Reference Manual 3.3.1(7).
--
-- Appropriate Declaration_Kinds:
-- A_Generic_Package_Declaration
-- A_Package_Declaration
--
-- Returns Element_Kinds:
-- A_Declaration
-- A_Pragma
-- A_Clause
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Package_Body_Declaration - 7.2
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Body_Declarative_Items
-- --|CR function Body_Statements
-- --|CR function Body_Exception_Handlers
-- --|CR function Body_Block_Statement - obsolescent, not recommended
-- --|ER---------------------------------------------------------------------
-- --|ER A_Private_Type_Declaration - 7.3
-- --|ER A_Private_Extension_Declaration - 7.3
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Discriminant_Part
-- --|CR function Type_Declaration_View
------------------------------------------------------------------------------
-- --|A2005 start (implemented)
-- 15.#??? function Declaration_Interface_List
------------------------------------------------------------------------------
function Declaration_Interface_List
(Declaration : Asis.Definition)
return Asis.Expression_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the declaration to query
--
-- Returns a list of subtype mark names making up the interface_list in the
-- argument declaration, in their order of appearance.
--
-- Appropriate Declaration_Kinds:
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- A_Single_Task_Declaration
-- A_Single_Protected_Declaration
--
-- Returns Expression_Kinds:
-- An_Identifier
-- A_Selected_Component
--
-- --|D2005 start
-- Note, that this function does NOT return an interface list for
-- A_Private_Extension_Declaration. Instead, an application should get to
-- the corresponding A_Private_Extension_Definition Element and get the
-- interface list by Asis.Definitions.Definition_Interface_List query. This
-- does not correspond to the Ada syntax, but ASIS 95 has already introduced
-- A_Private_Extension_Definition position in the Element classification
-- hierarchy, so we have to use it.
-- --|D2005 end
--
-- --|A2005 end
------------------------------------------------------------------------------
-- --|ER---------------------------------------------------------------------
-- --|ER An_Object_Renaming_Declaration - 8.5.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Declaration_Subtype_Mark
-- --|CR function Renamed_Entity
--
------------------------------------------------------------------------------
-- 15.34 function Renamed_Entity
------------------------------------------------------------------------------
function Renamed_Entity
(Declaration : Asis.Declaration)
return Asis.Expression;
------------------------------------------------------------------------------
-- Declaration - Specifies the rename declaration to query
--
-- Returns the name expression that follows the reserved word "renames" in the
-- renaming declaration.
--
-- Appropriate Declaration_Kinds:
-- An_Exception_Renaming_Declaration
-- A_Function_Renaming_Declaration
-- An_Object_Renaming_Declaration
-- A_Package_Renaming_Declaration
-- A_Procedure_Renaming_Declaration
-- A_Generic_Package_Renaming_Declaration
-- A_Generic_Procedure_Renaming_Declaration
-- A_Generic_Function_Renaming_Declaration
--
-- Returns Element_Kinds:
-- An_Expression
--
-- --|ER---------------------------------------------------------------------
-- --|ER An_Exception_Renaming_Declaration - 8.5.2
-- --|ER A_Package_Renaming_Declaration - 8.5.3
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Renamed_Entity
-- --|ER---------------------------------------------------------------------
-- --|ER A_Procedure_Renaming_Declaration - 8.5.4
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Parameter_Profile
-- --|CR function Renamed_Entity
-- --|ER---------------------------------------------------------------------
-- --|ER A_Function_Renaming_Declaration - 8.5.4
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Parameter_Profile
-- --|CR function Result_Profile
-- --|CR function Renamed_Entity
-- --|ER---------------------------------------------------------------------
-- --|ER A_Generic_Package_Renaming_Declaration - 8.5.5
-- --|ER A_Generic_Procedure_Renaming_Declaration - 8.5.5
-- --|ER A_Generic_Function_Renaming_Declaration - 8.5.5
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Renamed_Entity
--
------------------------------------------------------------------------------
-- 15.35 function Corresponding_Base_Entity
------------------------------------------------------------------------------
function Corresponding_Base_Entity
(Declaration : Asis.Declaration)
return Asis.Expression;
-----------------------------------------------------------------------------
-- Declaration - Specifies the rename declaration to query
--
-- The base entity is defined to be the renamed entity that is not itself
-- defined by another renaming declaration.
--
-- If the name following the reserved word "renames" is itself declared
-- by a previous renaming_declaration, then this query unwinds the renamings
-- by recursively operating on the previous renaming_declaration.
--
-- Otherwise, the name following the reserved word "renames" is returned.
--
-- Appropriate Declaration_Kinds:
-- An_Object_Renaming_Declaration
-- An_Exception_Renaming_Declaration
-- A_Procedure_Renaming_Declaration
-- A_Function_Renaming_Declaration
-- A_Package_Renaming_Declaration
-- A_Generic_Package_Renaming_Declaration
-- A_Generic_Procedure_Renaming_Declaration
-- A_Generic_Function_Renaming_Declaration
--
-- Returns Element_Kinds:
-- An_Expression
--
-- --|ER--------------------------------------------------------------------
-- --|ER A_Task_Type_Declaration - 9.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Discriminant_Part
-- --|CR function Type_Declaration_View
-- --|ER--------------------------------------------------------------------
-- --|ER A_Single_Task_Declaration - 9.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Object_Declaration_View
-- --|ER--------------------------------------------------------------------
-- --|ER A_Task_Body_Declaration - 9.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Body_Declarative_Items
-- --|CR function Body_Statements
-- --|CR function Body_Exception_Handlers
-- --|CR function Body_Block_Statement - obsolescent, not recommended
-- --|ER--------------------------------------------------------------------
-- --|ER A_Protected_Type_Declaration - 9.4
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Discriminant_Part
-- --|CR function Type_Declaration_View
-- --|ER--------------------------------------------------------------------
-- --|ER A_Single_Protected_Declaration - 9.4
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Object_Declaration_View
-- --|ER--------------------------------------------------------------------
-- --|ER A_Protected_Body_Declaration - 9.4
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Protected_Operation_Items
--
------------------------------------------------------------------------------
-- 15.36 function Protected_Operation_Items
------------------------------------------------------------------------------
function Protected_Operation_Items
(Declaration : Asis.Declaration;
Include_Pragmas : Boolean := False)
return Asis.Declaration_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the protected_body declaration to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of protected_operation_item and pragma elements of the
-- protected_body, in order of appearance.
--
-- Returns a Nil_Element_List if there are no items or pragmas.
--
-- Appropriate Declaration_Kinds:
-- A_Protected_Body_Declaration
--
-- Returns Element_Kinds:
-- A_Pragma
-- A_Declaration
-- A_Clause
--
-- Returns Declaration_Kinds:
-- A_Procedure_Declaration
-- A_Function_Declaration
-- A_Procedure_Body_Declaration
-- A_Function_Body_Declaration
-- An_Entry_Body_Declaration
--
-- Returns Clause_Kinds:
-- A_Representation_Clause
--
-- --|ER---------------------------------------------------------------------
-- --|ER An_Entry_Declaration - 9.5.2
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Entry_Family_Definition
-- --|CR function Parameter_Profile
--
------------------------------------------------------------------------------
-- 15.37 function Entry_Family_Definition
------------------------------------------------------------------------------
function Entry_Family_Definition
(Declaration : Asis.Declaration)
return Asis.Discrete_Subtype_Definition;
------------------------------------------------------------------------------
-- Declaration - Specifies the entry declaration to query
--
-- Returns the Discrete_Subtype_Definition element for the entry family of
-- an entry_declaration.
--
-- Returns a Nil_Element if the entry_declaration does not define a family
-- of entries.
--
-- Appropriate Declaration_Kinds:
-- An_Entry_Declaration
--
-- Returns Definition_Kinds:
-- Not_A_Definition
-- A_Discrete_Subtype_Definition
--
-- --|ER---------------------------------------------------------------------
-- --|ER An_Entry_Body_Declaration - 9.5.2
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Entry_Index_Specification
-- --|CR function Parameter_Profile
-- --|CR function Entry_Barrier
-- --|CR function Body_Declarative_Items
-- --|CR function Body_Statements
-- --|CR function Body_Exception_Handlers
-- --|CR function Body_Block_Statement - obsolescent, not recommended
--
------------------------------------------------------------------------------
-- 15.38 function Entry_Index_Specification
------------------------------------------------------------------------------
function Entry_Index_Specification
(Declaration : Asis.Declaration)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Declaration - Specifies the entry body declaration to query
--
-- Returns the An_Entry_Index_Specification element of an entry body
-- declaration.
--
-- Returns a Nil_Element if the entry does not declare any
-- An_Entry_Index_Specification element.
--
-- Appropriate Declaration_Kinds:
-- An_Entry_Body_Declaration
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- An_Entry_Index_Specification
--
------------------------------------------------------------------------------
-- 15.39 function Entry_Barrier
------------------------------------------------------------------------------
function Entry_Barrier
(Declaration : Asis.Declaration)
return Asis.Expression;
------------------------------------------------------------------------------
-- Declaration - Specifies the entry body declaration to query
--
-- Returns the expression following the reserved word "when" in an entry body
-- declaration.
--
-- Appropriate Declaration_Kinds:
-- An_Entry_Body_Declaration
--
-- Returns Element_Kinds:
-- An_Expression
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Procedure_Body_Stub - 10.1.3
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Parameter_Profile
-- --|ER---------------------------------------------------------------------
-- --|ER A_Function_Body_Stub - 10.1.3
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Parameter_Profile
-- --|CR function Result_Profile
-- --|ER---------------------------------------------------------------------
-- --|ER A_Package_Body_Stub - 10.1.3
-- --|ER A_Task_Body_Stub - 10.1.3
-- --|ER A_Protected_Body_Stub - 10.1.3
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
--
------------------------------------------------------------------------------
-- 15.40 function Corresponding_Subunit
------------------------------------------------------------------------------
function Corresponding_Subunit
(Body_Stub : Asis.Declaration)
return Asis.Declaration;
function Corresponding_Subunit
(Body_Stub : Asis.Declaration;
The_Context : Asis.Context)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Body_Stub - Specifies the stub to query
-- The_Context - Specifies a Context to use to locate the subunit
--
-- Returns the Unit_Declaration of the subunit compilation unit corresponding
-- to the body stub.
--
-- Returns a Nil_Element if the subunit does not exist in The_Context.
--
-- These two function calls will always produce identical results:
--
-- Decl2 := Corresponding_Subunit (Decl1);
-- Decl2 := Corresponding_Subunit
-- (Decl1,
-- Enclosing_Context ( Enclosing_Compilation_Unit( Decl1 )));
--
-- The parameter The_Context is used to locate the corresponding subunit body.
-- Any non-Nil result will always have The_Context as its Enclosing_Context.
--
-- Appropriate Declaration_Kinds:
-- A_Function_Body_Stub
-- A_Package_Body_Stub
-- A_Procedure_Body_Stub
-- A_Task_Body_Stub
-- A_Protected_Body_Stub
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- A_Function_Body_Declaration
-- A_Package_Body_Declaration
-- A_Procedure_Body_Declaration
-- A_Task_Body_Declaration
-- A_Protected_Body_Declaration
--
------------------------------------------------------------------------------
-- 15.41 function Is_Subunit
------------------------------------------------------------------------------
function Is_Subunit (Declaration : Asis.Declaration) return Boolean;
------------------------------------------------------------------------------
-- Declaration - Specifies the declaration to query
--
-- Returns True if the declaration is the proper_body of a subunit.
--
-- Returns False for any unexpected Element.
--
-- --|AN
-- Equivalent to:
-- Declaration = Unit_Declaration(Enclosing_Compilation_Unit (Declaration))
-- and Unit_Kind(Enclosing_Compilation_Unit (Declaration)) in A_Subunit.
--
-- Expected Declaration_Kinds:
-- A_Procedure_Body_Declaration
-- A_Function_Body_Declaration
-- A_Package_Body_Declaration
-- A_Task_Body_Declaration
-- A_Protected_Body_Declaration
--
------------------------------------------------------------------------------
-- 15.42 function Corresponding_Body_Stub
------------------------------------------------------------------------------
function Corresponding_Body_Stub
(Subunit : Asis.Declaration)
return Asis.Declaration;
function Corresponding_Body_Stub
(Subunit : Asis.Declaration;
The_Context : Asis.Context)
return Asis.Declaration;
------------------------------------------------------------------------------
-- Subunit - Specifies the Is_Subunit declaration to query
-- The_Context - Specifies a Context to use to locate the parent unit
--
-- Returns the body stub declaration located in the subunit's parent unit.
--
-- Returns a Nil_Element if the parent unit does not exist in The_Context.
--
-- These two function calls will always produce identical results:
--
-- Decl2 := Corresponding_Body_Stub (Decl1);
-- Decl2 := Corresponding_Body_Stub
-- (Decl1,
-- Enclosing_Context ( Enclosing_Compilation_Unit( Decl1 )));
--
-- The parameter The_Context is used to locate the corresponding parent body.
-- Any non-Nil result will always have The_Context as its Enclosing_Context.
--
-- Appropriate Declaration Kinds:
-- (Is_Subunit(Declaration) shall also be True)
-- A_Function_Body_Declaration
-- A_Package_Body_Declaration
-- A_Procedure_Body_Declaration
-- A_Task_Body_Declaration
-- A_Protected_Body_Declaration
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- A_Function_Body_Stub
-- A_Package_Body_Stub
-- A_Procedure_Body_Stub
-- A_Task_Body_Stub
-- A_Protected_Body_Stub
--
-- --|ER---------------------------------------------------------------------
-- --|ER An_Exception_Declaration - 11.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|ER---------------------------------------------------------------------
-- --|ER A_Choice_Parameter_Specification - 11.2
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|ER---------------------------------------------------------------------
-- --|ER A_Generic_Procedure_Declaration - 12.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Generic_Formal_Part
-- --|CR function Names
-- --|CR function Parameter_Profile
--
------------------------------------------------------------------------------
-- 15.43 function Generic_Formal_Part
------------------------------------------------------------------------------
function Generic_Formal_Part
(Declaration : Asis.Declaration;
Include_Pragmas : Boolean := False)
return Asis.Element_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the generic declaration to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of generic formal parameter declarations, use clauses,
-- and pragmas, in their order of appearance.
--
-- Results of this query may vary across ASIS implementations. Some
-- implementations normalize all multi-name object declarations into an
-- equivalent sequence of corresponding single name object declarations.
-- See Reference Manual 3.3.1(7).
--
-- Appropriate Declaration_Kinds:
-- A_Generic_Package_Declaration
-- A_Generic_Procedure_Declaration
-- A_Generic_Function_Declaration
--
-- Returns Element_Kinds:
-- A_Pragma
-- A_Declaration
-- A_Clause
--
-- Returns Declaration_Kinds:
-- A_Formal_Object_Declaration
-- A_Formal_Type_Declaration
-- A_Formal_Procedure_Declaration
-- A_Formal_Function_Declaration
-- A_Formal_Package_Declaration
-- A_Formal_Package_Declaration_With_Box
--
-- Returns Clause_Kinds:
-- A_Use_Package_Clause
-- A_Use_Type_Clause
-- A_Use_All_Type_Clause -- Ada 2012
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Generic_Function_Declaration - 12.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Generic_Formal_Part
-- --|CR function Names
-- --|CR function Parameter_Profile
-- --|CR function Result_Profile
-- --|ER---------------------------------------------------------------------
-- --|ER A_Generic_Package_Declaration - 12.1
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Generic_Formal_Part
-- --|CR function Names
-- --|CR function Visible_Part_Declarative_Items
-- --|CR function Private_Part_Declarative_Items
-- --|ER---------------------------------------------------------------------
-- --|ER A_Package_Instantiation - 12.3
-- --|ER A_Procedure_Instantiation - 12.3
-- --|ER A_Function_Instantiation - 12.3
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Generic_Unit_Name
-- --|CR function Generic_Actual_Part
------------------------------------------------------------------------------
--
-- Instantiations can always be analyzed in terms of the generic actual
-- parameters supplied with the instantiation. A generic instance is a copy
-- of the generic unit, and while there is no explicit (textual) specification
-- in the program text, an implicit specification and body, if there is one,
-- with the generic actual parameters is implied.
--
-- To analyze the implicit instance specification or body of a generic
-- instantiation:
-- - Use Corresponding_Declaration to return the implicit expanded
-- specification of an instantiation.
-- - Use Corresponding_Body to return the implicit body of an
-- instantiation.
-- - Then analyze the specification or body with any appropriate
-- queries.
--
-- To analyze the explicit generic specification or body referenced by a
-- generic instantiation:
-- - Use Generic_Unit_Name to obtain the name of the generic unit.
-- - Then use Corresponding_Name_Declaration to get to the generic
-- declaration.
-- - Then use Corresponding_Body to get to the body of the generic
-- declaration.
--
------------------------------------------------------------------------------
-- 15.44 function Generic_Unit_Name
------------------------------------------------------------------------------
function Generic_Unit_Name
(Declaration : Asis.Declaration)
return Asis.Expression;
------------------------------------------------------------------------------
-- Declaration - Specifies the generic instantiation to query
--
-- Returns the name following the reserved word "new" in the generic
-- instantiation. The name denotes the generic package, generic procedure, or
-- generic function that is the template for this generic instance.
--
-- Appropriate Declaration_Kinds:
-- A_Function_Instantiation
-- A_Package_Instantiation
-- A_Procedure_Instantiation
-- A_Formal_Package_Declaration
-- A_Formal_Package_Declaration_With_Box
--
-- Returns Expression_Kinds:
-- An_Identifier
-- An_Operator_Symbol
-- A_Selected_Component
--
------------------------------------------------------------------------------
-- 15.45 function Generic_Actual_Part
------------------------------------------------------------------------------
function Generic_Actual_Part
(Declaration : Asis.Declaration;
Normalized : Boolean := False)
return Asis.Association_List;
------------------------------------------------------------------------------
-- Declaration - Specifies the generic_instantiation to query
-- Normalized - Specifies whether the normalized form is desired
--
-- Returns a list of the generic_association elements of the instantiation.
--
-- Returns a Nil_Element_List if there are no generic_association elements.
--
-- An unnormalized list contains only explicit associations ordered as they
-- appear in the program text. Each unnormalized association has an optional
-- generic_formal_parameter_selector_name and an
-- explicit_generic_actual_parameter component.
--
-- A normalized list contains artificial associations representing all
-- explicit and default associations. It has a length equal to the number of
-- generic_formal_parameter_declaration elements of the generic_formal_part
-- of the template. The order of normalized associations matches the order of
-- the generic_formal_parameter_declaration elements.
--
-- Each normalized association represents a one-on-one mapping of a
-- generic_formal_parameter_declaration to the explicit or default expression
-- or name. A normalized association has:
-- - one A_Defining_Name component that denotes the
-- generic_formal_parameter_declaration, and
-- - one An_Expression component that is either:
-- o the explicit_generic_actual_parameter,
-- o a default_expression, or
-- o a default_name from the generic_formal_parameter_declaration or
-- an implicit naming expression which denotes the actual subprogram
-- selected at the place of instantiation for a formal subprogram
-- having A_Box_Default.
--
-- |D2006 start
--
-- In Ada 2005 we have a new notion - formal_package_association. It differs
-- from generic_association in having a box instead of an actual parameter.
-- There are two ways to represent in ASIS this new construct:
--
-- 1. Use the existing notion of A_Generic_Association
--
-- - if Normalized is OFF, then a corresponding A_Generic_Association has
-- Nil_Element as its Actual_Parameter part, and its Formal_Parameter
-- part can have the same kinds as for a generic_association plus
-- An_Others_Choice. For A_Formal_Package_Declaration_With_Box the
-- result list contains a singe A_Generic_Association that has
-- Nil_Element for its both Actual_Parameter and Formal_Parameter parts.
--
-- - if Normalized is ON, if an association from the result list
-- corresponds to formal_package_association, then as its
-- Actual_Parameter part it contains either the corresponding default
-- parameter or Nil_Element if there is no such default;
--
-- 2. Add a new value to Association_Kinds - A_Formal_Package_Association. Add
-- this value to the list of returned kinds of this query and to the lists
-- of appropriate kinds for Asis.Expressions.Formal_Parameter and
-- Asis.Expressions.Actual_Parameter. Return this
-- A_Formal_Package_Association element for any association containing a
-- box and as a single association in the result list, with the structure
-- described in paragraph 1 above.
--
-- For the current proposal, the first approach is taken.
--
-- |D2006 end
--
-- Appropriate Declaration_Kinds:
-- A_Function_Instantiation
-- A_Package_Instantiation
-- A_Procedure_Instantiation
-- A_Formal_Package_Declaration
-- |A2005 start
-- A_Formal_Package_Declaration_With_Box
-- |A2005 end
--
-- Returns Association_Kinds:
-- A_Generic_Association
--
-- --|IR Implementation Requirements:
-- --|IR
-- --|IR Normalized associations are Is_Normalized and Is_Part_Of_Implicit.
-- --|IR Normalized associations provided by default are
-- --|IR Is_Defaulted_Association. Normalized associations are never Is_Equal
-- --|IR to unnormalized associations.
-- --|IR
-- --|IP Implementation Permissions:
-- --|IP
-- --|IP An implementation may choose to always include default parameters in
-- --|IP its internal representation.
-- --|IP
-- --|IP An implementation may also choose to normalize its representation
-- --|IP to use the defining_identifier element rather than the
-- --|IP generic_formal_parameter_selector_name elements.
-- --|IP
-- --|IP In either case, this query will return Is_Normalized associations
-- --|IP even if Normalized is False, and the query
-- --|IP Generic_Actual_Part_Normalized will return True.
-- --|IP
-- --|ER---------------------------------------------------------------------
-- --|ER A_Formal_Object_Declaration - 12.4
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Declaration_Subtype_Mark
-- --|CR function Initialization_Expression
-- --|ER---------------------------------------------------------------------
-- --|ER A_Formal_Type_Declaration - 12.5
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Discriminant_Part
-- --|CR function Type_Declaration_View
-- --|ER---------------------------------------------------------------------
-- --|ER A_Formal_Procedure_Declaration - 12.6
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Parameter_Profile
-- --|CR function Formal_Subprogram_Default
--
------------------------------------------------------------------------------
-- 15.46 function Formal_Subprogram_Default
------------------------------------------------------------------------------
function Formal_Subprogram_Default
(Declaration : Asis.Generic_Formal_Parameter)
return Asis.Expression;
------------------------------------------------------------------------------
-- Declaration - Specifies the generic formal subprogram declaration to query
--
-- Returns the name appearing after the reserved word "is" in the given
-- generic formal subprogram declaration.
--
-- Appropriate Declaration_Kinds:
-- A_Formal_Function_Declaration
-- A_Formal_Procedure_Declaration
--
-- Appropriate Subprogram_Default_Kinds:
-- A_Name_Default
--
-- Returns Element_Kinds:
-- An_Expression
--
-- --|ER---------------------------------------------------------------------
-- --|ER A_Formal_Function_Declaration - 12.6
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Parameter_Profile
-- --|CR function Result_Profile
-- --|CR function Formal_Subprogram_Default
-- --|ER---------------------------------------------------------------------
-- --|ER A_Formal_Package_Declaration - 12.7
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Generic_Unit_Name
-- --|CR function Generic_Actual_Part
-- --|ER---------------------------------------------------------------------
-- --|ER A_Formal_Package_Declaration_With_Box - 12.7
-- --|CR
-- --|CR Child elements returned by:
-- --|CR function Names
-- --|CR function Generic_Unit_Name
--
------------------------------------------------------------------------------
-- 15.47 function Corresponding_Generic_Element
------------------------------------------------------------------------------
function Corresponding_Generic_Element
(Reference : Asis.Element)
return Asis.Defining_Name;
------------------------------------------------------------------------------
-- Reference - Specifies an expression that references an entity declared
-- within the implicit specification of a generic instantiation,
-- or, specifies the defining name of such an entity.
--
-- Given a reference to some implicit entity, whose declaration occurs within
-- an implicit generic instance, returns the corresponding entity name
-- definition from the generic template used to create the generic instance.
-- (Reference Manual 12.3 (16))
--
-- Returns the first A_Defining_Name, from the generic template, that
-- corresponds to the entity referenced.
--
-- Returns a Nil_Element if the argument does not refer to an entity declared
-- as a component of a generic package instantiation. The entity name can
-- refer to an ordinary declaration, an inherited subprogram declaration, or a
-- predefined operator declaration.
--
-- Appropriate Element_Kinds:
-- A_Defining_Name
-- An_Expression
--
-- Appropriate Expression_Kinds:
-- An_Identifier
-- An_Operator_Symbol
-- A_Character_Literal
-- An_Enumeration_Literal
--
-- Returns Element_Kinds:
-- Not_An_Element
-- A_Defining_Name
--
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- 15.48 function Is_Dispatching_Operation
------------------------------------------------------------------------------
function Is_Dispatching_Operation
(Declaration : Asis.Element)
return Boolean;
------------------------------------------------------------------------------
-- Declaration - Specifies the declaration to query.
--
-- Returns True if the declaration is a primitive subprogram of a tagged type.
--
-- Returns False for any unexpected argument.
--
-- Expected Element_Kinds:
-- A_Procedure_Declaration
-- A_Function_Declaration
-- A_Procedure_Renaming_Declaration
-- A_Function_Renaming_Declaration
--
-- (values not included in the official ASIS 2005 Standard)
-- A_Null_Procedure_Declaration
-- A_Procedure_Body_Declaration
-- A_Function_Body_Declaration
-- A_Procedure_Body_Stub
-- A_Function_Body_Stub
--
------------------------------------------------------------------------------
-- New ASIS 2012 queries --
------------------------------------------------------------------------------
end Asis.Declarations;
|
zhmu/ananas | Ada | 553 | adb | -- { dg-do compile }
-- { dg-options "-gnatf" }
procedure Unreferenced2 is
protected Example is
procedure Callme;
end Example;
procedure Other (X : Boolean) is
begin
null;
end;
protected body Example is
procedure Internal (X : Boolean) is
pragma Unreferenced (X);
Y : Integer;
begin
Y := 3;
end Internal;
procedure Callme is
begin
Internal (X => True);
end Callme;
end Example;
begin
Example.Callme;
Other (True);
end Unreferenced2;
|
MinimSecure/unum-sdk | Ada | 973 | adb | -- Copyright 2018-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 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Pck; use Pck;
procedure Bar is
type String_Access is access String;
type Array_Of_String is array (1 .. 2) of String_Access;
Aos : Array_Of_String := (new String'("ab"), new String'("cd"));
begin
Do_Nothing (Aos'Address); -- STOP
end Bar;
|
damaki/SPARKNaCl | Ada | 948 | ads | with HAL; use HAL;
with SPARKNaCl; use SPARKNaCl;
with Interfaces; use Interfaces;
package IO is
procedure Put (X : Integer);
-- Output integer to specified file, or to current output file, same
-- output as if Ada.Text_IO.Integer_IO had been instantiated for Integer.
procedure Put (X : UInt64);
procedure Put (C : Character);
-- Output character to specified file, or to current output file
procedure Put (S : String);
-- Output string to specified file, or to current output file
procedure Put_Line (S : String);
-- Output string followed by new line to stdout
procedure Put_Line (S : String; X : Unsigned_64);
-- Output string followed by X, then new line to stdout
procedure New_Line (Spacing : Positive := 1);
-- Output new line character to specified file, or to current output file
procedure Put (B : in Byte);
procedure Put (S : in String; D : in Byte_Seq);
end IO;
|
AdaCore/ada-traits-containers | Ada | 4,401 | ads | --
-- Copyright (C) 2015-2016, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--
-- This package provides a specialization of the Element_Traits package for
-- use with Ada arrays.
-- It stores small arrays directly in the data, without requiring memory
-- allocations. On the other hand, for larger arrays it uses actual memory
-- allocations. This will in general result in much faster handling, since
-- calls to malloc are slow. On the other hand, this also uses more memory
-- since there is systematically space allocated for the small arrays, even
-- when we end up allocating memory.
pragma Ada_2012;
generic
type Index_Type is new Integer;
-- The index type for the array. For now, we need a type based on integer
-- so that we can declare a specific subrange for small arrays
type Element_Type is private;
type Array_Type is array (Index_Type range <>) of Element_Type;
with package Pool is new Conts.Pools (<>);
-- Storage pool used to allocate memory
Short_Size : Natural := Standard'Address_Size / Element_Type'Object_Size;
-- Arrays below this size are stored inline (no memory allocation).
-- Above this size, an actual allocation will be used.
-- This size might have a big influence on performance, since it
-- impact the processor cache. You should measure performance to
-- find the optimal size in your case.
-- The default value is chosen so that the Stored element has the
-- same size whether we store the string inline or via a malloc.
package Conts.Elements.Arrays with SPARK_Mode => Off is
type Constant_Ref_Type (Element : not null access constant Array_Type) is
null record with Implicit_Dereference => Element;
-- This package stores a string with explicit bounds, but is able to
-- cast it as a standard string acces by simulating the fat pointers,
-- while avoiding a copy of the string.
package Fat_Pointers is
type Fat_Pointer is private;
procedure Set (FP : in out Fat_Pointer; A : Array_Type) with Inline;
function Get
(FP : not null access constant Fat_Pointer) return Constant_Ref_Type
with Inline;
private
type Both_Bounds is record
First, Last : Integer;
end record;
type Fat_Pointer is record
Bounds : Both_Bounds;
Data : Array_Type (1 .. Index_Type (Short_Size));
end record;
end Fat_Pointers;
package Impl is
type Stored_Array is private;
function To_Stored (A : Array_Type) return Stored_Array with Inline;
function To_Ref (S : Stored_Array) return Constant_Ref_Type with Inline;
function To_Element (R : Constant_Ref_Type) return Array_Type
is (R.Element.all) with Inline;
function Copy (S : Stored_Array) return Stored_Array with Inline;
procedure Release (S : in out Stored_Array) with Inline;
private
type Storage_Kind is (Short_Array, Long_Array);
type Array_Access is access all Array_Type;
for Array_Access'Storage_Pool use Pool.Pool;
type Stored_Array (Kind : Storage_Kind := Short_Array) is record
case Kind is
when Short_Array => Short : aliased Fat_Pointers.Fat_Pointer;
when Long_Array => Long : Array_Access;
end case;
end record;
end Impl;
package Traits is new Conts.Elements.Traits
(Element_Type => Array_Type,
Stored_Type => Impl.Stored_Array,
Returned_Type => Constant_Ref_Type,
Constant_Returned_Type => Constant_Ref_Type,
To_Stored => Impl.To_Stored,
To_Returned => Impl.To_Ref,
To_Constant_Returned => Impl.To_Ref,
To_Element => Impl.To_Element,
Copy => Impl.Copy,
Release => Impl.Release,
Copyable => False, -- would create aliases
Movable => True);
function From_Ref_To_Element (R : Constant_Ref_Type) return Array_Type
is (R.Element.all) with Inline;
-- Convenience function for use in algorithms, to convert from a Ref_Type
-- to an Element_Type. This is not needed in general, since the compiler
-- will automatically (and efficiently) dereference the reference_type.
-- But generic algorithm need an explicit conversion.
end Conts.Elements.Arrays;
|
LionelDraghi/smk | Ada | 3,015 | ads | -- -----------------------------------------------------------------------------
-- smk, the smart make (http://lionel.draghi.free.fr/smk/)
-- © 2018, 2019 Lionel Draghi <[email protected]>
-- SPDX-License-Identifier: APSL-2.0
-- -----------------------------------------------------------------------------
-- 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 Smk.Definitions; use Smk.Definitions;
with Smk.Files;
with Ada.Calendar;
with Ada.Containers.Doubly_Linked_Lists;
private package Smk.Smkfiles is
-- --------------------------------------------------------------------------
-- Purpose:
-- This package defines and manages the Smkfile (equivalent of the
-- Makefile for make) data structure, and provided related services.
-- --------------------------------------------------------------------------
type Smkfile_Entry is record
Line : Positive;
Section : Section_Names := Default_Section;
Command : Command_Lines := Null_Command_Line;
Was_Run : Boolean := False;
-- used to avoid running the same command for a different reason
-- during the analysis.
end record;
package Smkfile_Entry_Lists is
new Ada.Containers.Doubly_Linked_Lists (Smkfile_Entry, "=");
type Smk_File_Name is new Files.File_Name;
function "+" (Name : Smk_File_Name) return String;
function "+" (Name : String) return Smk_File_Name;
-- --------------------------------------------------------------------------
type Smkfile is record
Name : Smk_File_Name;
Time_Tag : Ada.Calendar.Time;
Entries : Smkfile_Entry_Lists.List;
end record;
-- --------------------------------------------------------------------------
function Load_Smkfile return Smkfile;
-- Load the Makefile provided on command line.
-- --------------------------------------------------------------------------
procedure Dump;
-- Dump Smk understanding of a Makefile, only the useful part of the
-- Current Makefile, that is without any comment or blank line.
-- --------------------------------------------------------------------------
function Contains (The_Smkfile : in Smkfile;
The_Command : in Command_Lines)
return Boolean;
-- --------------------------------------------------------------------------
procedure Add_To_Smkfile (Cmd_Line : String);
end Smk.Smkfiles;
|
NCommander/dnscatcher | Ada | 11,578 | adb | -- Copyright 2019 Michael Casadevall <[email protected]>
--
-- 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 Ada.Unchecked_Deallocation;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Strings.Hash;
with DNSCatcher.Utils; use DNSCatcher.Utils;
with DNSCatcher.Utils.Logger; use DNSCatcher.Utils.Logger;
with DNSCatcher.DNS.Processor.Packet; use DNSCatcher.DNS.Processor.Packet;
package body DNSCatcher.DNS.Transaction_Manager is
-- Handle the map for tracking transactions to/from source
task body DNS_Transaction_Manager_Task is
Outbound_Packet_Queue : DNS_Raw_Packet_Queue_Ptr;
Hashmap_Key : IP_Transaction_Key;
Hashmap_Cursor : DNS_Transaction_Maps.Cursor;
Outbound_Packet : Raw_Packet_Record;
Transaction_Hashmap : DNS_Transaction_Maps.Map;
Transaction : DNS_Transaction_Ptr;
Running : Boolean := False;
Logger_Packet : Logger_Message_Packet_Ptr;
Parsed_Packet : Parsed_DNS_Packet_Ptr;
begin
loop
Logger_Packet := null;
while Running = False
loop
Transaction := null;
select
accept Set_Packet_Queue (Queue : in DNS_Raw_Packet_Queue_Ptr) do
Outbound_Packet_Queue := Queue;
end Set_Packet_Queue;
or
accept Start do
if Outbound_Packet_Queue /= null
then
Logger_Packet := new Logger_Message_Packet;
Logger_Packet.Push_Component ("Transaction Manager");
Running := True;
Logger_Packet.Log_Message
(INFO, "Transaction Manager Started!");
Logger_Queue.Add_Packet (Logger_Packet);
end if;
end Start;
or
accept Stop do
null;
end Stop;
or
terminate;
end select;
end loop;
while Running
loop
Logger_Packet := new Logger_Message_Packet;
Logger_Packet.Push_Component ("Transaction Manager");
select
accept From_Client_Resolver_Packet
(Packet : Raw_Packet_Record_Ptr;
Local : Boolean) do
declare
Log_String : Unbounded_String;
Transaction_String : String (1 .. 8);
begin
Log_String :=
To_Unbounded_String ("Downstream DNS Transaction ID: ");
Put
(Transaction_String,
Integer (Packet.Raw_Data.Header.Identifier),
Base => 16);
Log_String :=
Log_String & To_Unbounded_String (Transaction_String);
Logger_Packet.Log_Message (DEBUG, To_String (Log_String));
end;
Hashmap_Key :=
IP_Transaction_Key
(Packet.To_Address & Packet.To_Port'Image &
Packet.Raw_Data.Header.Identifier'Image);
-- Create the key if necessary
Hashmap_Cursor := Transaction_Hashmap.Find (Hashmap_Key);
if Hashmap_Cursor = DNS_Transaction_Maps.No_Element
then
Transaction := new DNS_Transaction;
Transaction.Client_Resolver_Address :=
Packet.From_Address;
Transaction.Client_Resolver_Port := Packet.From_Port;
Transaction.Server_Resolver_Address := Packet.To_Address;
Transaction.Server_Resolver_Port := Packet.To_Port;
Transaction.DNS_Transaction_Id :=
Packet.Raw_Data.Header.Identifier;
Transaction.Local_Request := Local;
Transaction_Hashmap.Insert (Hashmap_Key, Transaction);
end if;
-- Save the packet
Transaction := Transaction_Hashmap (Hashmap_Key);
Transaction.From_Client_Resolver_Packet := Packet;
-- Try to parse the packet
Parsed_Packet := Packet_Parser (Logger_Packet, Packet);
Free_Parsed_DNS_Packet (Parsed_Packet);
-- Rewrite the DNS Packet and send it on it's way
Outbound_Packet_Queue.Put (Packet.all);
exception
when Exp_Error : others =>
begin
Logger_Packet.Log_Message
(ERROR,
"Transaction error: " &
Exception_Information (Exp_Error));
end;
end From_Client_Resolver_Packet;
or
accept From_Upstream_Resolver_Packet
(Packet : Raw_Packet_Record_Ptr) do
declare
Log_String : Unbounded_String;
Transaction_String : String (1 .. 8);
begin
Log_String :=
To_Unbounded_String ("Upstream DNS Transaction ID: ");
Put
(Transaction_String,
Integer (Packet.Raw_Data.Header.Identifier),
Base => 16);
Log_String :=
Log_String & To_Unbounded_String (Transaction_String);
Logger_Packet.Log_Message (DEBUG, To_String (Log_String));
end;
Hashmap_Key :=
IP_Transaction_Key
(Packet.From_Address & Packet.From_Port'Image &
Packet.Raw_Data.Header.Identifier'Image);
-- Create the key if necessary
Hashmap_Cursor := Transaction_Hashmap.Find (Hashmap_Key);
if Hashmap_Cursor = DNS_Transaction_Maps.No_Element
then
Transaction := new DNS_Transaction;
Transaction.Client_Resolver_Address := Packet.To_Address;
Transaction.Client_Resolver_Port := Packet.To_Port;
Transaction.Server_Resolver_Address :=
Packet.From_Address;
Transaction.Server_Resolver_Port := Packet.From_Port;
Transaction.DNS_Transaction_Id :=
Packet.Raw_Data.Header.Identifier;
Transaction_Hashmap.Insert (Hashmap_Key, Transaction);
end if;
-- Save the packet
Transaction := Transaction_Hashmap (Hashmap_Key);
Transaction.From_Upstream_Resolver_Packet := Packet;
-- Try to parse the packet
Parsed_Packet := Packet_Parser (Logger_Packet, Packet);
Logger_Packet.Log_Message
(INFO,
To_String (Transaction.Server_Resolver_Address) & " -> " &
To_String (Transaction.Client_Resolver_Address));
for I of Parsed_Packet.Answer
loop
Logger_Packet.Log_Message (INFO, " " & I.Print_Packet);
end loop;
Free_Parsed_DNS_Packet (Parsed_Packet);
-- If we're a local response, we don't resend it
if Transaction.Local_Request /= True
then
-- Flip the packet around so it goes to the right place
Outbound_Packet := Packet.all;
Outbound_Packet.To_Address :=
Transaction.Client_Resolver_Address;
Outbound_Packet.To_Port :=
Transaction.Client_Resolver_Port;
Outbound_Packet_Queue.Put (Outbound_Packet);
end if;
exception
when Exp_Error : others =>
begin
Logger_Packet.Log_Message
(ERROR,
"Transaction error: " &
Exception_Information (Exp_Error));
end;
end From_Upstream_Resolver_Packet;
or
accept Stop do
begin
Transaction_Hashmap.Iterate (Free_Hash_Map_Entry'Access);
end;
Running := False;
end Stop;
or
delay 0.1;
end select;
if Logger_Packet /= null
then
Logger_Queue.Add_Packet (Logger_Packet);
end if;
end loop;
end loop;
end DNS_Transaction_Manager_Task;
-- Clean up the pool and get rid of everything we don't need
procedure Free_Hash_Map_Entry (c : DNS_Transaction_Maps.Cursor) is
procedure Free_Transaction is new Ada.Unchecked_Deallocation
(Object => DNS_Transaction, Name => DNS_Transaction_Ptr);
procedure Free_Packet is new Ada.Unchecked_Deallocation
(Object => Raw_Packet_Record, Name => Raw_Packet_Record_Ptr);
P : DNS_Transaction_Ptr;
begin
P := Element (c);
if P.From_Client_Resolver_Packet /= null
then
if P.From_Client_Resolver_Packet.Raw_Data.Data /= null
then
Free_Stream_Element_Array_Ptr
(P.From_Client_Resolver_Packet.Raw_Data.Data);
end if;
Free_Packet (P.From_Client_Resolver_Packet);
end if;
if P.From_Upstream_Resolver_Packet /= null
then
if P.From_Upstream_Resolver_Packet.Raw_Data.Data /= null
then
Free_Stream_Element_Array_Ptr
(P.From_Upstream_Resolver_Packet.Raw_Data.Data);
end if;
Free_Packet (P.From_Upstream_Resolver_Packet);
end if;
Free_Transaction (P);
end Free_Hash_Map_Entry;
function IP_Transaction_Key_HashID
(id : IP_Transaction_Key)
return Hash_Type
is
begin
return Ada.Strings.Hash (To_String (id));
end IP_Transaction_Key_HashID;
end DNSCatcher.DNS.Transaction_Manager;
|
cborao/Ada-P4-chat | Ada | 2,476 | adb |
--PRÁCTICA 4: CÉSAR BORAO MORATINOS (Chat_Client_2)
with Handlers;
with Ada.Text_IO;
with Chat_Messages;
with Lower_Layer_UDP;
with Ada.Command_Line;
with Ada.Strings.Unbounded;
procedure Chat_Client_2 is
package ATI renames Ada.Text_IO;
package CM renames Chat_Messages;
package LLU renames Lower_Layer_UDP;
package ACL renames Ada.Command_Line;
package ASU renames Ada.Strings.Unbounded;
use type CM.Message_Type;
Server_EP: LLU.End_Point_Type;
Port: Integer;
Nick: ASU.Unbounded_String;
Client_EP_Receive: LLU.End_Point_Type;
Client_EP_Handler: LLU.End_Point_Type;
Buffer_In: aliased LLU.Buffer_Type(1024);
Buffer_Out: aliased LLU.Buffer_Type(1024);
Mess: CM.Message_Type;
Expired: Boolean;
Accepted: Boolean;
Comment: ASU.Unbounded_String;
begin
--Binding
Port := Integer'Value(ACL.Argument(2));
Server_EP := LLU.Build(LLU.To_IP(ACL.Argument(1)),Port);
Nick := ASU.To_Unbounded_String(ACL.Argument(3));
LLU.Bind_Any(Client_EP_Receive);
LLU.Bind_Any(Client_EP_Handler, Handlers.Client_Handler'Access);
LLU.Reset(Buffer_In);
if ACL.Argument_Count = 3 then
if ASU.To_String(Nick) /= "server" then
--Init Message
CM.Init_Message(Server_EP,Client_EP_Receive,
Client_EP_Handler,Nick,Buffer_Out'Access);
LLU.Receive(Client_EP_Receive, Buffer_In'Access, 10.0, Expired);
if Expired then
ATI.Put_Line("Server unreachable");
else
--Server Reply
Mess := CM.Message_Type'Input(Buffer_In'Access);
Accepted := Boolean'Input(Buffer_In'Access);
LLU.Reset(Buffer_In);
if Accepted then
ATI.Put_Line("Mini-Chat v2.0: Welcome "
& ASU.To_String(Nick));
loop
ATI.Put(">> ");
Comment := ASU.To_Unbounded_String(ATI.Get_Line);
exit when ASU.To_String(Comment) = ".quit";
--Writer Message
CM.Writer_Message(Server_EP,Client_EP_Handler,
Nick,Comment,Buffer_Out'Access);
end loop;
--Logout Message
CM.Logout_Message(Server_EP,Client_EP_Handler,
Nick,Buffer_Out'Access);
else
ATI.Put_Line("Mini-Chat v2.0: IGNORED new user " &
ASU.To_String(Nick) & ", nick already used");
end if;
end if;
else
ATI.New_Line;
ATI.Put_Line("Nick 'server' not avaliable, try again");
ATI.New_Line;
end if;
else
ATI.New_Line;
ATI.Put_Line("Client Usage: [user] [Port] <nick>");
ATI.New_Line;
end if;
LLU.Finalize;
end Chat_Client_2;
|
sonneveld/adazmq | Ada | 1,039 | adb | -- Pubsub envelope subscriber
with Ada.Command_Line;
with Ada.Text_IO;
with GNAT.Formatted_String;
with ZMQ;
use type GNAT.Formatted_String.Formatted_String;
procedure PSEnvSub is
function Main return Ada.Command_Line.Exit_Status
is
-- Prepare our context and subscriber
Context : ZMQ.Context_Type := ZMQ.New_Context;
Subscriber : ZMQ.Socket_Type'Class := Context.New_Socket (ZMQ.ZMQ_SUB);
begin
Subscriber.Connect ("tcp://localhost:5563");
Subscriber.Set_Sock_Opt (ZMQ.ZMQ_SUBSCRIBE, "B");
loop
declare
Address : constant String := Subscriber.Recv; -- Read envelope with address
Contents : constant String := Subscriber.Recv; -- Read message contents
begin
Ada.Text_IO.Put_Line(-(+"[%s] %s"&Address&Contents));
end;
end loop;
-- We never get here, but clean up anyhow
Subscriber.Close;
Context.Term;
return 0;
end Main;
begin
Ada.Command_Line.Set_Exit_Status (Main);
end PSEnvSub;
|
bracke/Meaning | Ada | 2,648 | adb | with RASCAL.Memory; use RASCAL.Memory;
with RASCAL.OS; use RASCAL.OS;
with RASCAL.Utility; use RASCAL.Utility;
with RASCAL.FileExternal; use RASCAL.FileExternal;
with RASCAL.ToolboxMenu; use RASCAL.ToolboxMenu;
with RASCAL.Toolbox; use RASCAL.Toolbox;
with RASCAL.Bugz; use RASCAL.Bugz;
with RASCAL.WimpTask; use RASCAL.WimpTask;
with AcronymList; use AcronymList;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Interfaces.C; use Interfaces.C;
with Main; use Main;
with Ada.Exceptions;
with Ada.Characters.Handling;
with Reporter;
package body Controller_DataMenu is
--
package Memory renames RASCAL.Memory;
package OS renames RASCAL.OS;
package Utility renames RASCAL.Utility;
package FileExternal renames RASCAL.FileExternal;
package ToolboxMenu renames RASCAL.ToolboxMenu;
package Toolbox renames RASCAL.Toolbox;
package Bugz renames RASCAL.Bugz;
package WimpTask renames RASCAL.WimpTask;
--
procedure Handle (The : in TEL_DataMenuOpen_Type) is
Object : Object_ID := Get_Self_Id(Main_Task);
Dir_List : Directory_Type := Get_Directory_List(Choices_Write & ".Data");
begin
-- Delete old entries
if Data_Menu_Entries > 0 then
ToolboxMenu.Remove_Entries(Object,Data_Menu_Entries,1);
end if;
-- Insert new entries
for i in Dir_List'Range loop
ToolboxMenu.Add_Last_Entry(Object,S(Dir_List(i)),Component_ID(i),Click_Event => 16#35#);
end loop;
Data_Menu_Entries := Dir_List'Last;
exception
when e: others => Report_Error("OPENDATAMENU",Ada.Exceptions.Exception_Information (e));
end Handle;
--
procedure Handle (The : in TEL_DataEntrySelected_Type) is
Object : Object_ID := Get_Self_Id(Main_Task);
Component : Component_ID := Get_Self_Component(Main_Task);
FileName : String := ToolboxMenu.Get_Entry_Text(Object,Component);
begin
Call_OS_CLI("Filer_Run " & Choices_Write & ".Data." & FileName);
exception
when e: others => Report_Error("VIEWDATAENTRY",Ada.Exceptions.Exception_Information (e));
end Handle;
--
procedure Handle (The : in TEL_ViewDataDir_Type) is
begin
Call_OS_CLI ("Filer_OpenDir " & Choices_Write & ".Data");
exception
when e: others => Report_Error("VIEWDATA",Ada.Exceptions.Exception_Information (e));
end Handle;
--
end Controller_DataMenu;
|
AdaCore/gpr | Ada | 2,094 | adb | --
-- Copyright (C) 2019-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0
--
with Ada.Text_IO;
with Ada.Exceptions;
with GPR2.Project.View;
with GPR2.Project.Tree;
with GPR2.Project.Attribute.Set;
with GPR2.Context;
with GPR2.Source_Reference.Value;
with GPR2.Message;
with GPR2.Log;
procedure Main is
use Ada;
use GPR2;
use GPR2.Project;
procedure Display (Prj : Project.View.Object; Full : Boolean := True);
-------------
-- Display --
-------------
procedure Display (Prj : Project.View.Object; Full : Boolean := True) is
use GPR2.Project.Attribute.Set;
procedure Display (Att : Project.Attribute.Object) is
begin
Text_IO.Put (" " & String (Image (Att.Name.Id.Attr)));
if Att.Has_Index then
Text_IO.Put (" (" & Att.Index.Value & ")");
end if;
Text_IO.Put (" -> ");
for V of Att.Values loop
Text_IO.Put (V.Text & " ");
end loop;
Text_IO.New_Line;
end Display;
begin
Text_IO.Put (String (Prj.Name) & " ");
Text_IO.Set_Col (10);
Text_IO.Put_Line (Prj.Qualifier'Img);
if Full then
for A of Prj.Attributes loop
Display (A);
end loop;
Text_IO.New_Line;
end if;
end Display;
Prj : Project.Tree.Object;
Ctx : Context.Object;
procedure Print_Messages is
begin
if Prj.Has_Messages then
for C in Prj.Log_Messages.Iterate
(False, True, True, True, True)
loop
Ada.Text_IO.Put_Line (GPR2.Log.Element (C).Format);
end loop;
end if;
end Print_Messages;
begin
Project.Tree.Load
(Self => Prj, Filename => Create ("demo.gpr"), Context => Ctx);
Ctx.Include ("CASESTMT_OS", "Linux");
Prj.Set_Context (Ctx);
Display (Prj.Root_Project);
Ctx.Clear;
Ctx.Include ("CASESTMT_OS", "Windows");
Prj.Set_Context (Ctx);
Display (Prj.Root_Project);
exception
when Ex : others =>
Text_IO.Put_Line (Ada.Exceptions.Exception_Message (Ex));
Print_Messages;
end Main;
|
tum-ei-rcs/StratoX | Ada | 14,043 | ads | -- Initially based on stm32f7xx_hal_sd.h
-- V1.0.4
-- 09-December-2015
--
-- SDCard driver. Controls the SDMMC peripheral.
with System;
with STM32_SVD.SDMMC; use STM32_SVD.SDMMC;
with STM32.DMA;
package STM32.SDMMC is
type SDMMC_Controller is private;
function As_Controller
(Periph : access STM32_SVD.SDMMC.SDMMC1_Peripheral)
return SDMMC_Controller;
type SD_Error is
(OK,
Error,
Timeout_Error,
Unsupported_Card,
Rx_Overrun,
Tx_Underrun,
Startbit_Not_Detected,
Request_Not_Applicable,
CRC_Check_Fail,
Illegal_Cmd,
Address_Out_Of_Range,
Address_Missaligned,
Block_Length_Error,
Erase_Seq_Error,
Bad_Erase_Parameter,
Write_Protection_Violation,
Lock_Unlock_Failed,
Card_ECC_Failed,
Card_ECC_Disabled,
CC_Error,
General_Unknown_Error,
Stream_Read_Underrun,
Stream_Write_Underrun,
CID_CSD_Overwrite,
WP_Erase_Skip,
Erase_Reset,
AKE_SEQ_Error,
Invalid_Voltage_Range,
DMA_Alignment_Error);
type Supported_SD_Memory_Cards is
(STD_Capacity_SD_Card_V1_1,
STD_Capacity_SD_Card_v2_0,
High_Capacity_SD_Card,
Multimedia_Card,
Secure_Digital_IO_Card,
High_Speed_Multimedia_Card,
Secure_Digital_IO_Combo_Card,
High_Capacity_MMC_Card);
type Card_Specific_Data_Register is record
CSD_Structure : Byte;
System_Specification_Version : Byte;
Reserved : Byte;
Data_Read_Access_Time_1 : Byte;
Data_Read_Access_Time_2 : Byte; -- In CLK Cycles
Max_Bus_Clock_Frequency : Byte;
Card_Command_Class : Short;
Max_Read_Data_Block_Length : Byte;
Partial_Block_For_Read_Allowed : Boolean;
Write_Block_Missalignment : Boolean;
Read_Block_Missalignment : Boolean;
DSR_Implemented : Boolean;
Reserved_2 : Byte;
Device_Size : Word;
Max_Read_Current_At_VDD_Min : Byte;
Max_Read_Current_At_VDD_Max : Byte;
Max_Write_Current_At_VDD_Min : Byte;
Max_Write_Current_At_VDD_Max : Byte;
Device_Size_Multiplier : Byte;
Erase_Group_Size : Byte;
Erase_Group_Size_Multiplier : Byte;
Write_Protect_Group_Size : Byte;
Write_Protect_Group_Enable : Boolean;
Manufacturer_Default_ECC : Byte;
Write_Speed_Factor : Byte;
Max_Write_Data_Block_Length : Byte;
Partial_Blocks_For_Write_Allowed : Boolean;
Reserved_3 : Byte;
Content_Protection_Application : Boolean;
File_Format_Group : Boolean;
Copy_Flag : Boolean;
Permanent_Write_Protection : Boolean;
Temporary_Write_Protection : Boolean;
File_Format : Byte;
ECC_Code : Byte;
CSD_CRC : Byte;
Reserved_4 : Byte; -- Always 1
end record;
type Card_Revision is record
Major : UInt4;
Minor : UInt4;
end record with Pack;
type Manufacturing_Year is range 2000 .. 2255;
type Manufacturing_Month is
(January,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December) with Size => 4;
type Manufacturing_Date_Type is record
Year : Manufacturing_Year;
Month : Manufacturing_Month;
end record;
type Card_Identification_Data_Register is record
Manufacturer_ID : Byte;
OEM_Application_ID : String (1 .. 2);
Product_Name : String (1 .. 5);
Product_Revision : Card_Revision;
Product_Serial_Number : Word;
Reserved_1 : Byte;
Manufacturing_Date : Manufacturing_Date_Type;
CID_CRC : Byte;
Reserved_2 : Byte; -- Always 1
end record;
type Card_Information is record
SD_CSD : Card_Specific_Data_Register;
SD_CID : Card_Identification_Data_Register;
Card_Capacity : Unsigned_64;
Card_Block_Size : Unsigned_32;
RCA : Short; -- SD relative card address
Card_Type : Supported_SD_Memory_Cards :=
STD_Capacity_SD_Card_V1_1;
end record;
-- Wide bus mode
type Wide_Bus_Mode is
(
-- Default bus mode: SDMMC_D0 is used.
Wide_Bus_1B,
-- 4-wide bus mode: SDMMC_D[3:0] used.
Wide_Bus_4B,
-- 8-wide bus mode: SDMMC_D[7:0] used.
Wide_Bus_8B)
with Size => 2;
for Wide_Bus_Mode use
(Wide_Bus_1B => 0,
Wide_Bus_4B => 1,
Wide_Bus_8B => 2);
function Initialize
(Controller : in out SDMMC_Controller;
Info : out Card_Information) return SD_Error;
function Initialized (Controller : SDMMC_Controller) return Boolean;
function Get_Card_Type
(Controller : SDMMC_Controller) return Supported_SD_Memory_Cards
with Pre => Initialized (Controller);
function Configure_Wide_Bus_Mode
(Controller : in out SDMMC_Controller;
Wide_Mode : Wide_Bus_Mode) return SD_Error;
type SD_Data is array (Unsigned_32 range <>) of Byte
with Pack;
function Read_Blocks
(Controller : in out SDMMC_Controller;
Addr : Unsigned_64;
Data : out SD_Data) return SD_Error
with Pre => Data'Length mod 512 = 0;
function Read_Blocks_DMA
(Controller : in out SDMMC_Controller;
Addr : Unsigned_64;
DMA : STM32.DMA.DMA_Controller;
Stream : STM32.DMA.DMA_Stream_Selector;
Data : out SD_Data) return SD_Error
with Pre => Data'Length <= 65535;
function Write_Blocks_DMA
(Controller : in out SDMMC_Controller;
Addr : Unsigned_64;
DMA : STM32.DMA.DMA_Controller;
Stream : STM32.DMA.DMA_Stream_Selector;
Data : SD_Data) return SD_Error
with Pre => Data'Length <= 65535;
function Stop_Transfer
(Controller : in out SDMMC_Controller) return SD_Error;
function Get_FIFO_Address
(Controller : SDMMC_Controller) return System.Address;
function Get_Transfer_Status
(Controller : in out SDMMC_Controller) return SD_Error;
type SDMMC_Flags is
(Data_End,
Data_CRC_Fail,
Data_Timeout,
RX_Overrun,
TX_Underrun,
RX_Active,
TX_Active);
subtype SDMMC_Clearable_Flags is SDMMC_Flags range Data_End .. TX_Underrun;
function Get_Flag
(Controller : SDMMC_Controller;
Flag : SDMMC_Flags) return Boolean;
procedure Clear_Flag
(Controller : in out SDMMC_Controller;
Flag : SDMMC_Clearable_Flags);
procedure Clear_Static_Flags (Controller : in out SDMMC_Controller);
type SDMMC_Interrupts is
(Data_End_Interrupt,
Data_CRC_Fail_Interrupt,
Data_Timeout_Interrupt,
TX_FIFO_Empty_Interrupt,
RX_FIFO_Full_Interrupt,
TX_Underrun_Interrupt,
RX_Overrun_Interrupt);
procedure Enable_Interrupt
(Controller : in out SDMMC_Controller;
Interrupt : SDMMC_Interrupts);
procedure Disable_Interrupt
(Controller : in out SDMMC_Controller;
Interrupt : SDMMC_Interrupts);
type SDMMC_Operation is
(No_Operation,
Read_Single_Block_Operation,
Read_Multiple_Blocks_Operation,
Write_Single_Block_Operation,
Write_Multiple_Blocks_Operation);
function Last_Operation
(Controller : SDMMC_Controller) return SDMMC_Operation;
private
type SDMMC_Command is new Byte;
-- Resets the SD memory card
Go_Idle_State : constant SDMMC_Command := 0;
-- Sends host capacity support information and activates the card's
-- initialization process
Send_Op_Cond : constant SDMMC_Command := 1;
-- Asks any card connected to the host to send the CID numbers on the
-- CMD line.
All_Send_CID : constant SDMMC_Command := 2;
-- Asks the card to publish a new relative address (RCA).
Set_Rel_Addr : constant SDMMC_Command := 3;
-- Programs the DSR of all cards.
Set_DSR : constant SDMMC_Command := 4;
-- Sends host capacity support information (HCS) and asks the accessed
-- card to send its operating condition register (OCR) content in the
-- response on the CMD line.
SDMMC_Send_Op_Cond : constant SDMMC_Command := 5;
-- Checks switchable function (mode 0) and switch card function (mode
-- 1).
HS_Switch : constant SDMMC_Command := 6;
-- Selects the card by its own relative address and gets deselected by
-- any other address
Sel_Desel_Card : constant SDMMC_Command := 7;
-- Sends SD Memory Card interface condition
HS_Send_Ext_CSD : constant SDMMC_Command := 8;
-- Addressed card sends its card specific data
Send_CSD : constant SDMMC_Command := 9;
-- Addressed card sends its card identification (CID) on the CMD line.
Send_CID : constant SDMMC_Command := 10;
Read_Dat_Until_Stop : constant SDMMC_Command := 11;
Stop_Transmission : constant SDMMC_Command := 12;
Send_Status : constant SDMMC_Command := 13;
HS_Bustest_Read : constant SDMMC_Command := 14;
Go_Inactive_State : constant SDMMC_Command := 15;
Set_Blocklen : constant SDMMC_Command := 16;
Read_Single_Block : constant SDMMC_Command := 17;
Read_Multi_Block : constant SDMMC_Command := 18;
HS_Bustest_Write : constant SDMMC_Command := 19;
Write_Dat_Until_Stop : constant SDMMC_Command := 20;
Set_Block_Count : constant SDMMC_Command := 23; -- Only for MMC
Write_Single_Block : constant SDMMC_Command := 24;
Write_Multi_Block : constant SDMMC_Command := 25;
Prog_CID : constant SDMMC_Command := 26;
Prog_CSD : constant SDMMC_Command := 27;
Set_Write_Prot : constant SDMMC_Command := 28;
Clr_Write_Prot : constant SDMMC_Command := 29;
Send_Write_Prot : constant SDMMC_Command := 30;
SD_Erase_Grp_Start : constant SDMMC_Command := 32;
SD_Erase_Grp_End : constant SDMMC_Command := 33;
Erase_Grp_Start : constant SDMMC_Command := 35;
Erase_Grp_End : constant SDMMC_Command := 36;
Erase : constant SDMMC_Command := 38;
Fast_IO : constant SDMMC_Command := 39;
Go_IRQ_State : constant SDMMC_Command := 40;
Lock_Unlock : constant SDMMC_Command := 42;
App_Cmd : constant SDMMC_Command := 55;
Gen_Cmd : constant SDMMC_Command := 56;
No_Cmd : constant SDMMC_Command := 64;
-- SD-Card speciric commands
-- App_Cmd should be sent before sending these commands
subtype SD_Specific_Command is SDMMC_Command;
SD_App_Set_Buswidth : constant SD_Specific_Command := 6;
SD_App_Status : constant SD_Specific_Command := 13;
SD_App_Secure_Read_Multi_Block : constant SD_Specific_Command := 18;
SD_App_Send_Num_Write_Blocks : constant SD_Specific_Command := 22;
SD_App_Set_Write_Block_Erase_Count : constant SD_Specific_Command := 23;
SD_App_Secure_Write_Multi_Block : constant SD_Specific_Command := 25;
SD_App_Secure_Erase : constant SD_Specific_Command := 38;
SD_App_Op_Cond : constant SD_Specific_Command := 41;
SD_App_Get_MKB : constant SD_Specific_Command := 43;
SD_App_Get_MID : constant SD_Specific_Command := 44;
SD_App_Set_CER_RN1 : constant SD_Specific_Command := 45;
SD_App_Get_CER_RN2 : constant SD_Specific_Command := 46;
SD_App_Set_CER_RES2 : constant SD_Specific_Command := 47;
SD_App_Get_CER_RES1 : constant SD_Specific_Command := 48;
SD_App_Change_Secure_Area : constant SD_Specific_Command := 49;
SD_App_Send_SCR : constant SD_Specific_Command := 51;
type Card_Data_Table is array (0 .. 3) of Word;
type SDMMC_Controller is record
Periph : access STM32_SVD.SDMMC.SDMMC1_Peripheral;
CID : Card_Data_Table;
CSD : Card_Data_Table;
Card_Type : Supported_SD_Memory_Cards :=
STD_Capacity_SD_Card_V1_1;
RCA : Word;
Operation : SDMMC_Operation := No_Operation;
end record;
function As_Controller
(Periph : access STM32_SVD.SDMMC.SDMMC1_Peripheral)
return SDMMC_Controller
is (Periph, CID => (others => 0), CSD => (others => 0), others => <>);
function Initialized (Controller : SDMMC_Controller) return Boolean
is (Controller.CID /= (0, 0, 0, 0));
function Get_Card_Type
(Controller : SDMMC_Controller) return Supported_SD_Memory_Cards
is (Controller.Card_Type);
type Data_Direction is (Read, Write);
function Get_FIFO_Address
(Controller : SDMMC_Controller) return System.Address
is (Controller.Periph.FIFO'Address);
function Get_Flag
(Controller : SDMMC_Controller;
Flag : SDMMC_Flags) return Boolean
is (case Flag is
when Data_End => Controller.Periph.STA.DATAEND,
when Data_CRC_Fail => Controller.Periph.STA.DCRCFAIL,
when Data_Timeout => Controller.Periph.STA.DTIMEOUT,
when RX_Overrun => Controller.Periph.STA.RXOVERR,
when TX_Underrun => Controller.Periph.STA.TXUNDERR,
when RX_Active => Controller.Periph.STA.RXACT,
when TX_Active => Controller.Periph.STA.TXACT);
function Last_Operation
(Controller : SDMMC_Controller) return SDMMC_Operation
is (Controller.Operation);
end STM32.SDMMC;
|
zhmu/ananas | Ada | 306 | adb | -- { dg-do run }
with OCONST1, OCONST2, OCONST3, OCONST4, OCONST5;
procedure Test_Oconst is
begin
OCONST1.check (OCONST1.My_R);
OCONST2.check (OCONST2.My_R);
OCONST3.check (OCONST3.My_R);
OCONST4.check (OCONST4.My_R);
OCONST5.check (OCONST5.My_R0, 0);
OCONST5.check (OCONST5.My_R1, 1);
end;
|
sungyeon/drake | Ada | 312 | ads | pragma License (Unrestricted);
-- with Ada.Strings.Unbounded;
with Ada.Strings.Unbounded_Strings;
with Ada.Text_IO.Generic_Unbounded_IO;
package Ada.Text_IO.Unbounded_IO is
new Generic_Unbounded_IO (
Strings.Unbounded_Strings,
Put => Put,
Put_Line => Put_Line,
Get_Line => Get_Line);
|
google-code/ada-util | Ada | 2,688 | ads | -----------------------------------------------------------------------
-- util-streams-sockets -- Socket streams
-- Copyright (C) 2012, 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Finalization;
with GNAT.Sockets;
-- The <b>Util.Streams.Sockets</b> package defines a socket stream.
package Util.Streams.Sockets is
-- -----------------------
-- Socket stream
-- -----------------------
-- The <b>Socket_Stream</b> is an output/input stream that reads or writes
-- to or from a socket.
type Socket_Stream is limited new Output_Stream and Input_Stream with private;
-- Initialize the socket stream.
procedure Open (Stream : in out Socket_Stream;
Socket : in GNAT.Sockets.Socket_Type);
-- Initialize the socket stream by opening a connection to the server defined in <b>Server</b>.
procedure Connect (Stream : in out Socket_Stream;
Server : in GNAT.Sockets.Sock_Addr_Type);
-- Close the socket stream.
overriding
procedure Close (Stream : in out Socket_Stream);
-- Write the buffer array to the output stream.
overriding
procedure Write (Stream : in out Socket_Stream;
Buffer : in Ada.Streams.Stream_Element_Array);
-- Read into the buffer as many bytes as possible and return in
-- <b>last</b> the position of the last byte read.
overriding
procedure Read (Stream : in out Socket_Stream;
Into : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset);
private
use Ada.Streams;
type Socket_Stream is new Ada.Finalization.Limited_Controlled
and Output_Stream and Input_Stream with record
Sock : GNAT.Sockets.Socket_Type := GNAT.Sockets.No_Socket;
end record;
-- Flush the stream and release the buffer.
overriding
procedure Finalize (Object : in out Socket_Stream);
end Util.Streams.Sockets;
|
reznikmm/matreshka | Ada | 3,913 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.ODF_Elements.Text.Outline_Level_Style;
package ODF.DOM.Elements.Text.Outline_Level_Style.Internals is
function Create
(Node : Matreshka.ODF_Elements.Text.Outline_Level_Style.Text_Outline_Level_Style_Access)
return ODF.DOM.Elements.Text.Outline_Level_Style.ODF_Text_Outline_Level_Style;
function Wrap
(Node : Matreshka.ODF_Elements.Text.Outline_Level_Style.Text_Outline_Level_Style_Access)
return ODF.DOM.Elements.Text.Outline_Level_Style.ODF_Text_Outline_Level_Style;
end ODF.DOM.Elements.Text.Outline_Level_Style.Internals;
|
zhmu/ananas | Ada | 66,254 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G H O S T --
-- --
-- B o d y --
-- --
-- Copyright (C) 2014-2022, 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 Alloc;
with Aspects; use Aspects;
with Atree; use Atree;
with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
with Elists; use Elists;
with Errout; use Errout;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Disp; use Sem_Disp;
with Sem_Eval; use Sem_Eval;
with Sem_Prag; use Sem_Prag;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Snames; use Snames;
with Table;
package body Ghost is
---------------------
-- Data strictures --
---------------------
-- The following table contains all ignored Ghost nodes that must be
-- eliminated from the tree by routine Remove_Ignored_Ghost_Code.
package Ignored_Ghost_Nodes is new Table.Table (
Table_Component_Type => Node_Id,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => Alloc.Ignored_Ghost_Nodes_Initial,
Table_Increment => Alloc.Ignored_Ghost_Nodes_Increment,
Table_Name => "Ignored_Ghost_Nodes");
-----------------------
-- Local subprograms --
-----------------------
function Whole_Object_Ref (Ref : Node_Id) return Node_Id;
-- For a name that denotes an object, returns a name that denotes the whole
-- object, declared by an object declaration, formal parameter declaration,
-- etc. For example, for P.X.Comp (J), if P is a package X is a record
-- object, this returns P.X.
function Ghost_Entity (Ref : Node_Id) return Entity_Id;
pragma Inline (Ghost_Entity);
-- Obtain the entity of a Ghost entity from reference Ref. Return Empty if
-- no such entity exists.
procedure Install_Ghost_Mode (Mode : Ghost_Mode_Type);
pragma Inline (Install_Ghost_Mode);
-- Install Ghost mode Mode as the Ghost mode in effect
procedure Install_Ghost_Region (Mode : Name_Id; N : Node_Id);
pragma Inline (Install_Ghost_Region);
-- Install a Ghost region comprised of mode Mode and ignored region start
-- node N.
function Is_Subject_To_Ghost (N : Node_Id) return Boolean;
-- Determine whether declaration or body N is subject to aspect or pragma
-- Ghost. This routine must be used in cases where pragma Ghost has not
-- been analyzed yet, but the context needs to establish the "ghostness"
-- of N.
procedure Mark_Ghost_Declaration_Or_Body
(N : Node_Id;
Mode : Name_Id);
-- Mark the defining entity of declaration or body N as Ghost depending on
-- mode Mode. Mark all formals parameters when N denotes a subprogram or a
-- body.
function Name_To_Ghost_Mode (Mode : Name_Id) return Ghost_Mode_Type;
pragma Inline (Name_To_Ghost_Mode);
-- Convert a Ghost mode denoted by name Mode into its respective enumerated
-- value.
procedure Record_Ignored_Ghost_Node (N : Node_Or_Entity_Id);
-- Save ignored Ghost node or entity N in table Ignored_Ghost_Nodes for
-- later elimination.
----------------------------
-- Check_Ghost_Completion --
----------------------------
procedure Check_Ghost_Completion
(Prev_Id : Entity_Id;
Compl_Id : Entity_Id)
is
Policy : constant Name_Id := Policy_In_Effect (Name_Ghost);
begin
-- Nothing to do if one of the views is missing
if No (Prev_Id) or else No (Compl_Id) then
null;
-- The Ghost policy in effect at the point of declaration and at the
-- point of completion must match (SPARK RM 6.9(14)).
elsif Is_Checked_Ghost_Entity (Prev_Id)
and then Policy = Name_Ignore
then
Error_Msg_Sloc := Sloc (Compl_Id);
Error_Msg_N ("incompatible ghost policies in effect", Prev_Id);
Error_Msg_N ("\& declared with ghost policy `Check`", Prev_Id);
Error_Msg_N ("\& completed # with ghost policy `Ignore`", Prev_Id);
elsif Is_Ignored_Ghost_Entity (Prev_Id)
and then Policy = Name_Check
then
Error_Msg_Sloc := Sloc (Compl_Id);
Error_Msg_N ("incompatible ghost policies in effect", Prev_Id);
Error_Msg_N ("\& declared with ghost policy `Ignore`", Prev_Id);
Error_Msg_N ("\& completed # with ghost policy `Check`", Prev_Id);
end if;
end Check_Ghost_Completion;
-------------------------
-- Check_Ghost_Context --
-------------------------
procedure Check_Ghost_Context (Ghost_Id : Entity_Id; Ghost_Ref : Node_Id) is
procedure Check_Ghost_Policy (Id : Entity_Id; Ref : Node_Id);
-- Verify that the Ghost policy at the point of declaration of entity Id
-- matches the policy at the point of reference Ref. If this is not the
-- case emit an error at Ref.
function Is_OK_Ghost_Context (Context : Node_Id) return Boolean;
-- Determine whether node Context denotes a Ghost-friendly context where
-- a Ghost entity can safely reside (SPARK RM 6.9(10)).
function In_Aspect_Or_Pragma_Predicate (N : Node_Id) return Boolean;
-- Return True iff N is enclosed in an aspect or pragma Predicate
-------------------------
-- Is_OK_Ghost_Context --
-------------------------
function Is_OK_Ghost_Context (Context : Node_Id) return Boolean is
function Is_OK_Declaration (Decl : Node_Id) return Boolean;
-- Determine whether node Decl is a suitable context for a reference
-- to a Ghost entity. To qualify as such, Decl must either
--
-- * Define a Ghost entity
--
-- * Be subject to pragma Ghost
function Is_OK_Pragma (Prag : Node_Id) return Boolean;
-- Determine whether node Prag is a suitable context for a reference
-- to a Ghost entity. To qualify as such, Prag must either
--
-- * Be an assertion expression pragma
--
-- * Denote pragma Global, Depends, Initializes, Refined_Global,
-- Refined_Depends or Refined_State.
--
-- * Specify an aspect of a Ghost entity
--
-- * Contain a reference to a Ghost entity
function Is_OK_Statement (Stmt : Node_Id) return Boolean;
-- Determine whether node Stmt is a suitable context for a reference
-- to a Ghost entity. To qualify as such, Stmt must either
--
-- * Denote a procedure call to a Ghost procedure
--
-- * Denote an assignment statement whose target is Ghost
-----------------------
-- Is_OK_Declaration --
-----------------------
function Is_OK_Declaration (Decl : Node_Id) return Boolean is
function In_Subprogram_Body_Profile (N : Node_Id) return Boolean;
-- Determine whether node N appears in the profile of a subprogram
-- body.
--------------------------------
-- In_Subprogram_Body_Profile --
--------------------------------
function In_Subprogram_Body_Profile (N : Node_Id) return Boolean is
Spec : constant Node_Id := Parent (N);
begin
-- The node appears in a parameter specification in which case
-- it is either the parameter type or the default expression or
-- the node appears as the result definition of a function.
return
(Nkind (N) = N_Parameter_Specification
or else
(Nkind (Spec) = N_Function_Specification
and then N = Result_Definition (Spec)))
and then Nkind (Parent (Spec)) = N_Subprogram_Body;
end In_Subprogram_Body_Profile;
-- Local variables
Subp_Decl : Node_Id;
Subp_Id : Entity_Id;
-- Start of processing for Is_OK_Declaration
begin
if Is_Ghost_Declaration (Decl) then
return True;
-- Special cases
-- A reference to a Ghost entity may appear within the profile of
-- a subprogram body. This context is treated as suitable because
-- it duplicates the context of the corresponding spec. The real
-- check was already performed during the analysis of the spec.
elsif In_Subprogram_Body_Profile (Decl) then
return True;
-- A reference to a Ghost entity may appear within an expression
-- function which is still being analyzed. This context is treated
-- as suitable because it is not yet known whether the expression
-- function is an initial declaration or a completion. The real
-- check is performed when the expression function is expanded.
elsif Nkind (Decl) = N_Expression_Function
and then not Analyzed (Decl)
then
return True;
-- References to Ghost entities may be relocated in internally
-- generated bodies.
elsif Nkind (Decl) = N_Subprogram_Body
and then not Comes_From_Source (Decl)
then
Subp_Id := Corresponding_Spec (Decl);
if Present (Subp_Id) then
-- The context is the internally built _Postconditions
-- procedure, which is OK because the real check was done
-- before expansion activities.
if Chars (Subp_Id) = Name_uPostconditions then
return True;
-- The context is the internally built predicate function,
-- which is OK because the real check was done before the
-- predicate function was generated.
elsif Is_Predicate_Function (Subp_Id) then
return True;
else
Subp_Decl :=
Original_Node (Unit_Declaration_Node (Subp_Id));
-- The original context is an expression function that
-- has been split into a spec and a body. The context is
-- OK as long as the initial declaration is Ghost.
if Nkind (Subp_Decl) = N_Expression_Function then
return Is_Ghost_Declaration (Subp_Decl);
end if;
end if;
-- Otherwise this is either an internal body or an internal
-- completion. Both are OK because the real check was done
-- before expansion activities.
else
return True;
end if;
end if;
return False;
end Is_OK_Declaration;
------------------
-- Is_OK_Pragma --
------------------
function Is_OK_Pragma (Prag : Node_Id) return Boolean is
procedure Check_Policies (Prag_Nam : Name_Id);
-- Verify that the Ghost policy in effect is the same as the
-- assertion policy for pragma name Prag_Nam. Emit an error if
-- this is not the case.
--------------------
-- Check_Policies --
--------------------
procedure Check_Policies (Prag_Nam : Name_Id) is
AP : constant Name_Id := Check_Kind (Prag_Nam);
GP : constant Name_Id := Policy_In_Effect (Name_Ghost);
begin
-- If the Ghost policy in effect at the point of a Ghost entity
-- reference is Ignore, then the assertion policy of the pragma
-- must be Ignore (SPARK RM 6.9(18)).
if GP = Name_Ignore and then AP /= Name_Ignore then
Error_Msg_N
("incompatible ghost policies in effect",
Ghost_Ref);
Error_Msg_NE
("\ghost entity & has policy `Ignore`",
Ghost_Ref, Ghost_Id);
Error_Msg_Name_1 := AP;
Error_Msg_N
("\assertion expression has policy %", Ghost_Ref);
end if;
end Check_Policies;
-- Local variables
Prag_Id : Pragma_Id;
Prag_Nam : Name_Id;
-- Start of processing for Is_OK_Pragma
begin
if Nkind (Prag) = N_Pragma then
Prag_Id := Get_Pragma_Id (Prag);
Prag_Nam := Original_Aspect_Pragma_Name (Prag);
-- A pragma that applies to a Ghost construct or specifies an
-- aspect of a Ghost entity is a Ghost pragma (SPARK RM 6.9(3))
if Is_Ghost_Pragma (Prag) then
return True;
-- An assertion expression pragma is Ghost when it contains a
-- reference to a Ghost entity (SPARK RM 6.9(10)), except for
-- predicate pragmas (SPARK RM 6.9(11)).
elsif Assertion_Expression_Pragma (Prag_Id)
and then Prag_Id /= Pragma_Predicate
then
-- Ensure that the assertion policy and the Ghost policy are
-- compatible (SPARK RM 6.9(18)).
Check_Policies (Prag_Nam);
return True;
-- Several pragmas that may apply to a non-Ghost entity are
-- treated as Ghost when they contain a reference to a Ghost
-- entity (SPARK RM 6.9(11)).
elsif Prag_Nam in Name_Global
| Name_Depends
| Name_Initializes
| Name_Refined_Global
| Name_Refined_Depends
| Name_Refined_State
then
return True;
end if;
end if;
return False;
end Is_OK_Pragma;
---------------------
-- Is_OK_Statement --
---------------------
function Is_OK_Statement (Stmt : Node_Id) return Boolean is
begin
-- An assignment statement is Ghost when the target is a Ghost
-- entity.
if Nkind (Stmt) = N_Assignment_Statement then
return Is_Ghost_Assignment (Stmt);
-- A procedure call is Ghost when it calls a Ghost procedure
elsif Nkind (Stmt) = N_Procedure_Call_Statement then
return Is_Ghost_Procedure_Call (Stmt);
-- Special cases
-- An if statement is a suitable context for a Ghost entity if it
-- is the byproduct of assertion expression expansion. Note that
-- the assertion expression may not be related to a Ghost entity,
-- but it may still contain references to Ghost entities.
elsif Nkind (Stmt) = N_If_Statement
and then Nkind (Original_Node (Stmt)) = N_Pragma
and then Assertion_Expression_Pragma
(Get_Pragma_Id (Original_Node (Stmt)))
then
return True;
end if;
return False;
end Is_OK_Statement;
-- Local variables
Par : Node_Id;
-- Start of processing for Is_OK_Ghost_Context
begin
-- The context is Ghost when it appears within a Ghost package or
-- subprogram.
if Ghost_Mode > None then
return True;
-- A Ghost type may be referenced in a use_type clause
-- (SPARK RM 6.9.10).
elsif Present (Parent (Context))
and then Nkind (Parent (Context)) = N_Use_Type_Clause
then
return True;
-- Routine Expand_Record_Extension creates a parent subtype without
-- inserting it into the tree. There is no good way of recognizing
-- this special case as there is no parent. Try to approximate the
-- context.
elsif No (Parent (Context)) and then Is_Tagged_Type (Ghost_Id) then
return True;
-- Otherwise climb the parent chain looking for a suitable Ghost
-- context.
else
Par := Context;
while Present (Par) loop
if Is_Ignored_Ghost_Node (Par) then
return True;
-- A reference to a Ghost entity can appear within an aspect
-- specification (SPARK RM 6.9(10)). The precise checking will
-- occur when analyzing the corresponding pragma. We make an
-- exception for predicate aspects that only allow referencing
-- a Ghost entity when the corresponding type declaration is
-- Ghost (SPARK RM 6.9(11)).
elsif Nkind (Par) = N_Aspect_Specification
and then not Same_Aspect
(Get_Aspect_Id (Par), Aspect_Predicate)
then
return True;
elsif Is_OK_Declaration (Par) then
return True;
elsif Is_OK_Pragma (Par) then
return True;
elsif Is_OK_Statement (Par) then
return True;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
end loop;
-- The expansion of assertion expression pragmas and attribute Old
-- may cause a legal Ghost entity reference to become illegal due
-- to node relocation. Check the In_Assertion_Expr counter as last
-- resort to try and infer the original legal context.
if In_Assertion_Expr > 0 then
return True;
-- Otherwise the context is not suitable for a reference to a
-- Ghost entity.
else
return False;
end if;
end if;
end Is_OK_Ghost_Context;
------------------------
-- Check_Ghost_Policy --
------------------------
procedure Check_Ghost_Policy (Id : Entity_Id; Ref : Node_Id) is
Policy : constant Name_Id := Policy_In_Effect (Name_Ghost);
begin
-- The Ghost policy in effect a the point of declaration and at the
-- point of use must match (SPARK RM 6.9(13)).
if Is_Checked_Ghost_Entity (Id)
and then Policy = Name_Ignore
and then Known_To_Be_Assigned (Ref)
then
Error_Msg_Sloc := Sloc (Ref);
Error_Msg_N ("incompatible ghost policies in effect", Ref);
Error_Msg_NE ("\& declared with ghost policy `Check`", Ref, Id);
Error_Msg_NE ("\& used # with ghost policy `Ignore`", Ref, Id);
elsif Is_Ignored_Ghost_Entity (Id) and then Policy = Name_Check then
Error_Msg_Sloc := Sloc (Ref);
Error_Msg_N ("incompatible ghost policies in effect", Ref);
Error_Msg_NE ("\& declared with ghost policy `Ignore`", Ref, Id);
Error_Msg_NE ("\& used # with ghost policy `Check`", Ref, Id);
end if;
end Check_Ghost_Policy;
-----------------------------------
-- In_Aspect_Or_Pragma_Predicate --
-----------------------------------
function In_Aspect_Or_Pragma_Predicate (N : Node_Id) return Boolean is
Par : Node_Id := N;
begin
while Present (Par) loop
if Nkind (Par) = N_Pragma
and then Get_Pragma_Id (Par) = Pragma_Predicate
then
return True;
elsif Nkind (Par) = N_Aspect_Specification
and then Same_Aspect (Get_Aspect_Id (Par), Aspect_Predicate)
then
return True;
-- Stop the search when it's clear it cannot be inside an aspect
-- or pragma.
elsif Is_Declaration (Par)
or else Is_Statement (Par)
or else Is_Body (Par)
then
return False;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Aspect_Or_Pragma_Predicate;
-- Start of processing for Check_Ghost_Context
begin
-- Class-wide pre/postconditions of ignored pragmas are preanalyzed
-- to report errors on wrong conditions; however, ignored pragmas may
-- also have references to ghost entities and we must disable checking
-- their context to avoid reporting spurious errors.
if Inside_Class_Condition_Preanalysis then
return;
end if;
-- Once it has been established that the reference to the Ghost entity
-- is within a suitable context, ensure that the policy at the point of
-- declaration and at the point of use match.
if Is_OK_Ghost_Context (Ghost_Ref) then
Check_Ghost_Policy (Ghost_Id, Ghost_Ref);
-- Otherwise the Ghost entity appears in a non-Ghost context and affects
-- its behavior or value (SPARK RM 6.9(10,11)).
else
Error_Msg_N ("ghost entity cannot appear in this context", Ghost_Ref);
-- When the Ghost entity appears in a pragma Predicate, explain the
-- reason for this being illegal, and suggest a fix instead.
if In_Aspect_Or_Pragma_Predicate (Ghost_Ref) then
Error_Msg_N
("\as predicates are checked in membership tests, "
& "the type and its predicate must be both ghost",
Ghost_Ref);
Error_Msg_N
("\either make the type ghost "
& "or use a type invariant on a private type", Ghost_Ref);
end if;
end if;
end Check_Ghost_Context;
----------------------------
-- Check_Ghost_Overriding --
----------------------------
procedure Check_Ghost_Overriding
(Subp : Entity_Id;
Overridden_Subp : Entity_Id)
is
Deriv_Typ : Entity_Id;
Over_Subp : Entity_Id;
begin
if Present (Subp) and then Present (Overridden_Subp) then
Over_Subp := Ultimate_Alias (Overridden_Subp);
Deriv_Typ := Find_Dispatching_Type (Subp);
-- A Ghost primitive of a non-Ghost type extension cannot override an
-- inherited non-Ghost primitive (SPARK RM 6.9(8)).
if Is_Ghost_Entity (Subp)
and then Present (Deriv_Typ)
and then not Is_Ghost_Entity (Deriv_Typ)
and then not Is_Ghost_Entity (Over_Subp)
and then not Is_Abstract_Subprogram (Over_Subp)
then
Error_Msg_N ("incompatible overriding in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N ("\& declared # as non-ghost subprogram", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N ("\overridden # with ghost subprogram", Subp);
end if;
-- A non-Ghost primitive of a type extension cannot override an
-- inherited Ghost primitive (SPARK RM 6.9(8)).
if Is_Ghost_Entity (Over_Subp)
and then not Is_Ghost_Entity (Subp)
and then not Is_Abstract_Subprogram (Subp)
then
Error_Msg_N ("incompatible overriding in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N ("\& declared # as ghost subprogram", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N ("\overridden # with non-ghost subprogram", Subp);
end if;
if Present (Deriv_Typ)
and then not Is_Ignored_Ghost_Entity (Deriv_Typ)
then
-- When a tagged type is either non-Ghost or checked Ghost and
-- one of its primitives overrides an inherited operation, the
-- overridden operation of the ancestor type must be ignored Ghost
-- if the primitive is ignored Ghost (SPARK RM 6.9(17)).
if Is_Ignored_Ghost_Entity (Subp) then
-- Both the parent subprogram and overriding subprogram are
-- ignored Ghost.
if Is_Ignored_Ghost_Entity (Over_Subp) then
null;
-- The parent subprogram carries policy Check
elsif Is_Checked_Ghost_Entity (Over_Subp) then
Error_Msg_N
("incompatible ghost policies in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N
("\& declared # with ghost policy `Check`", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N
("\overridden # with ghost policy `Ignore`", Subp);
-- The parent subprogram is non-Ghost
else
Error_Msg_N
("incompatible ghost policies in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N ("\& declared # as non-ghost subprogram", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N
("\overridden # with ghost policy `Ignore`", Subp);
end if;
-- When a tagged type is either non-Ghost or checked Ghost and
-- one of its primitives overrides an inherited operation, the
-- the primitive of the tagged type must be ignored Ghost if the
-- overridden operation is ignored Ghost (SPARK RM 6.9(17)).
elsif Is_Ignored_Ghost_Entity (Over_Subp) then
-- Both the parent subprogram and the overriding subprogram are
-- ignored Ghost.
if Is_Ignored_Ghost_Entity (Subp) then
null;
-- The overriding subprogram carries policy Check
elsif Is_Checked_Ghost_Entity (Subp) then
Error_Msg_N
("incompatible ghost policies in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N
("\& declared # with ghost policy `Ignore`", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N
("\overridden # with Ghost policy `Check`", Subp);
-- The overriding subprogram is non-Ghost
else
Error_Msg_N
("incompatible ghost policies in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N
("\& declared # with ghost policy `Ignore`", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N
("\overridden # with non-ghost subprogram", Subp);
end if;
end if;
end if;
end if;
end Check_Ghost_Overriding;
---------------------------
-- Check_Ghost_Primitive --
---------------------------
procedure Check_Ghost_Primitive (Prim : Entity_Id; Typ : Entity_Id) is
begin
-- The Ghost policy in effect at the point of declaration of a primitive
-- operation and a tagged type must match (SPARK RM 6.9(16)).
if Is_Tagged_Type (Typ) then
if Is_Checked_Ghost_Entity (Prim)
and then Is_Ignored_Ghost_Entity (Typ)
then
Error_Msg_N ("incompatible ghost policies in effect", Prim);
Error_Msg_Sloc := Sloc (Typ);
Error_Msg_NE
("\tagged type & declared # with ghost policy `Ignore`",
Prim, Typ);
Error_Msg_Sloc := Sloc (Prim);
Error_Msg_N
("\primitive subprogram & declared # with ghost policy `Check`",
Prim);
elsif Is_Ignored_Ghost_Entity (Prim)
and then Is_Checked_Ghost_Entity (Typ)
then
Error_Msg_N ("incompatible ghost policies in effect", Prim);
Error_Msg_Sloc := Sloc (Typ);
Error_Msg_NE
("\tagged type & declared # with ghost policy `Check`",
Prim, Typ);
Error_Msg_Sloc := Sloc (Prim);
Error_Msg_N
("\primitive subprogram & declared # with ghost policy `Ignore`",
Prim);
end if;
end if;
end Check_Ghost_Primitive;
----------------------------
-- Check_Ghost_Refinement --
----------------------------
procedure Check_Ghost_Refinement
(State : Node_Id;
State_Id : Entity_Id;
Constit : Node_Id;
Constit_Id : Entity_Id)
is
begin
if Is_Ghost_Entity (State_Id) then
if Is_Ghost_Entity (Constit_Id) then
-- The Ghost policy in effect at the point of abstract state
-- declaration and constituent must match (SPARK RM 6.9(15)).
if Is_Checked_Ghost_Entity (State_Id)
and then Is_Ignored_Ghost_Entity (Constit_Id)
then
Error_Msg_Sloc := Sloc (Constit);
SPARK_Msg_N ("incompatible ghost policies in effect", State);
SPARK_Msg_NE
("\abstract state & declared with ghost policy `Check`",
State, State_Id);
SPARK_Msg_NE
("\constituent & declared # with ghost policy `Ignore`",
State, Constit_Id);
elsif Is_Ignored_Ghost_Entity (State_Id)
and then Is_Checked_Ghost_Entity (Constit_Id)
then
Error_Msg_Sloc := Sloc (Constit);
SPARK_Msg_N ("incompatible ghost policies in effect", State);
SPARK_Msg_NE
("\abstract state & declared with ghost policy `Ignore`",
State, State_Id);
SPARK_Msg_NE
("\constituent & declared # with ghost policy `Check`",
State, Constit_Id);
end if;
-- A constituent of a Ghost abstract state must be a Ghost entity
-- (SPARK RM 7.2.2(12)).
else
SPARK_Msg_NE
("constituent of ghost state & must be ghost",
Constit, State_Id);
end if;
end if;
end Check_Ghost_Refinement;
----------------------
-- Check_Ghost_Type --
----------------------
procedure Check_Ghost_Type (Typ : Entity_Id) is
Conc_Typ : Entity_Id;
Full_Typ : Entity_Id;
begin
if Is_Ghost_Entity (Typ) then
Conc_Typ := Empty;
Full_Typ := Typ;
if Is_Single_Concurrent_Type (Typ) then
Conc_Typ := Anonymous_Object (Typ);
Full_Typ := Conc_Typ;
elsif Is_Concurrent_Type (Typ) then
Conc_Typ := Typ;
end if;
-- A Ghost type cannot be concurrent (SPARK RM 6.9(19)). Verify this
-- legality rule first to give a finer-grained diagnostic.
if Present (Conc_Typ) then
Error_Msg_N ("ghost type & cannot be concurrent", Conc_Typ);
end if;
-- A Ghost type cannot be effectively volatile (SPARK RM 6.9(7))
if Is_Effectively_Volatile (Full_Typ) then
Error_Msg_N ("ghost type & cannot be volatile", Full_Typ);
end if;
end if;
end Check_Ghost_Type;
------------------
-- Ghost_Entity --
------------------
function Ghost_Entity (Ref : Node_Id) return Entity_Id is
Obj_Ref : constant Node_Id := Ultimate_Prefix (Ref);
begin
-- When the reference denotes a subcomponent, recover the related whole
-- object (SPARK RM 6.9(1)).
if Is_Entity_Name (Obj_Ref) then
return Entity (Obj_Ref);
-- Otherwise the reference cannot possibly denote a Ghost entity
else
return Empty;
end if;
end Ghost_Entity;
--------------------------------
-- Implements_Ghost_Interface --
--------------------------------
function Implements_Ghost_Interface (Typ : Entity_Id) return Boolean is
Iface_Elmt : Elmt_Id;
begin
-- Traverse the list of interfaces looking for a Ghost interface
if Is_Tagged_Type (Typ) and then Present (Interfaces (Typ)) then
Iface_Elmt := First_Elmt (Interfaces (Typ));
while Present (Iface_Elmt) loop
if Is_Ghost_Entity (Node (Iface_Elmt)) then
return True;
end if;
Next_Elmt (Iface_Elmt);
end loop;
end if;
return False;
end Implements_Ghost_Interface;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Ignored_Ghost_Nodes.Init;
-- Set the soft link which enables Atree.Mark_New_Ghost_Node to record
-- an ignored Ghost node or entity.
Set_Ignored_Ghost_Recording_Proc (Record_Ignored_Ghost_Node'Access);
end Initialize;
------------------------
-- Install_Ghost_Mode --
------------------------
procedure Install_Ghost_Mode (Mode : Ghost_Mode_Type) is
begin
Install_Ghost_Region (Mode, Empty);
end Install_Ghost_Mode;
--------------------------
-- Install_Ghost_Region --
--------------------------
procedure Install_Ghost_Region (Mode : Ghost_Mode_Type; N : Node_Id) is
begin
-- The context is already within an ignored Ghost region. Maintain the
-- start of the outermost ignored Ghost region.
if Present (Ignored_Ghost_Region) then
null;
-- The current region is the outermost ignored Ghost region. Save its
-- starting node.
elsif Present (N) and then Mode = Ignore then
Ignored_Ghost_Region := N;
-- Otherwise the current region is not ignored, nothing to save
else
Ignored_Ghost_Region := Empty;
end if;
Ghost_Mode := Mode;
end Install_Ghost_Region;
procedure Install_Ghost_Region (Mode : Name_Id; N : Node_Id) is
begin
Install_Ghost_Region (Name_To_Ghost_Mode (Mode), N);
end Install_Ghost_Region;
-------------------------
-- Is_Ghost_Assignment --
-------------------------
function Is_Ghost_Assignment (N : Node_Id) return Boolean is
Id : Entity_Id;
begin
-- An assignment statement is Ghost when its target denotes a Ghost
-- entity.
if Nkind (N) = N_Assignment_Statement then
Id := Ghost_Entity (Name (N));
return Present (Id) and then Is_Ghost_Entity (Id);
end if;
return False;
end Is_Ghost_Assignment;
--------------------------
-- Is_Ghost_Declaration --
--------------------------
function Is_Ghost_Declaration (N : Node_Id) return Boolean is
Id : Entity_Id;
begin
-- A declaration is Ghost when it elaborates a Ghost entity or is
-- subject to pragma Ghost.
if Is_Declaration (N) then
Id := Defining_Entity (N);
return Is_Ghost_Entity (Id) or else Is_Subject_To_Ghost (N);
end if;
return False;
end Is_Ghost_Declaration;
---------------------
-- Is_Ghost_Pragma --
---------------------
function Is_Ghost_Pragma (N : Node_Id) return Boolean is
begin
return Is_Checked_Ghost_Pragma (N) or else Is_Ignored_Ghost_Pragma (N);
end Is_Ghost_Pragma;
-----------------------------
-- Is_Ghost_Procedure_Call --
-----------------------------
function Is_Ghost_Procedure_Call (N : Node_Id) return Boolean is
Id : Entity_Id;
begin
-- A procedure call is Ghost when it invokes a Ghost procedure
if Nkind (N) = N_Procedure_Call_Statement then
Id := Ghost_Entity (Name (N));
return Present (Id) and then Is_Ghost_Entity (Id);
end if;
return False;
end Is_Ghost_Procedure_Call;
---------------------------
-- Is_Ignored_Ghost_Unit --
---------------------------
function Is_Ignored_Ghost_Unit (N : Node_Id) return Boolean is
function Ultimate_Original_Node (Nod : Node_Id) return Node_Id;
-- Obtain the original node of arbitrary node Nod following a potential
-- chain of rewritings.
----------------------------
-- Ultimate_Original_Node --
----------------------------
function Ultimate_Original_Node (Nod : Node_Id) return Node_Id is
Res : Node_Id := Nod;
begin
while Original_Node (Res) /= Res loop
Res := Original_Node (Res);
end loop;
return Res;
end Ultimate_Original_Node;
-- Start of processing for Is_Ignored_Ghost_Unit
begin
-- Inspect the original node of the unit in case removal of ignored
-- Ghost code has already taken place.
return
Nkind (N) = N_Compilation_Unit
and then Is_Ignored_Ghost_Entity
(Defining_Entity (Ultimate_Original_Node (Unit (N))));
end Is_Ignored_Ghost_Unit;
-------------------------
-- Is_Subject_To_Ghost --
-------------------------
function Is_Subject_To_Ghost (N : Node_Id) return Boolean is
function Enables_Ghostness (Arg : Node_Id) return Boolean;
-- Determine whether aspect or pragma argument Arg enables "ghostness"
-----------------------
-- Enables_Ghostness --
-----------------------
function Enables_Ghostness (Arg : Node_Id) return Boolean is
Expr : Node_Id;
begin
Expr := Arg;
if Nkind (Expr) = N_Pragma_Argument_Association then
Expr := Get_Pragma_Arg (Expr);
end if;
-- Determine whether the expression of the aspect or pragma is static
-- and denotes True.
if Present (Expr) then
Preanalyze_And_Resolve (Expr);
return
Is_OK_Static_Expression (Expr)
and then Is_True (Expr_Value (Expr));
-- Otherwise Ghost defaults to True
else
return True;
end if;
end Enables_Ghostness;
-- Local variables
Id : constant Entity_Id := Defining_Entity (N);
Asp : Node_Id;
Decl : Node_Id;
Prev_Id : Entity_Id;
-- Start of processing for Is_Subject_To_Ghost
begin
-- The related entity of the declaration has not been analyzed yet, do
-- not inspect its attributes.
if Ekind (Id) = E_Void then
null;
elsif Is_Ghost_Entity (Id) then
return True;
-- The completion of a type or a constant is not fully analyzed when the
-- reference to the Ghost entity is resolved. Because the completion is
-- not marked as Ghost yet, inspect the partial view.
elsif Is_Record_Type (Id)
or else Ekind (Id) = E_Constant
or else (Nkind (N) = N_Object_Declaration
and then Constant_Present (N))
then
Prev_Id := Incomplete_Or_Partial_View (Id);
if Present (Prev_Id) and then Is_Ghost_Entity (Prev_Id) then
return True;
end if;
end if;
-- Examine the aspect specifications (if any) looking for aspect Ghost
if Permits_Aspect_Specifications (N) then
Asp := First (Aspect_Specifications (N));
while Present (Asp) loop
if Chars (Identifier (Asp)) = Name_Ghost then
return Enables_Ghostness (Expression (Asp));
end if;
Next (Asp);
end loop;
end if;
Decl := Empty;
-- When the context is a [generic] package declaration, pragma Ghost
-- resides in the visible declarations.
if Nkind (N) in N_Generic_Package_Declaration | N_Package_Declaration
then
Decl := First (Visible_Declarations (Specification (N)));
-- When the context is a package or a subprogram body, pragma Ghost
-- resides in the declarative part.
elsif Nkind (N) in N_Package_Body | N_Subprogram_Body then
Decl := First (Declarations (N));
-- Otherwise pragma Ghost appears in the declarations following N
elsif Is_List_Member (N) then
Decl := Next (N);
end if;
while Present (Decl) loop
if Nkind (Decl) = N_Pragma
and then Pragma_Name (Decl) = Name_Ghost
then
return
Enables_Ghostness (First (Pragma_Argument_Associations (Decl)));
-- A source construct ends the region where pragma Ghost may appear,
-- stop the traversal. Check the original node as source constructs
-- may be rewritten into something else by expansion.
elsif Comes_From_Source (Original_Node (Decl)) then
exit;
end if;
Next (Decl);
end loop;
return False;
end Is_Subject_To_Ghost;
----------
-- Lock --
----------
procedure Lock is
begin
Ignored_Ghost_Nodes.Release;
Ignored_Ghost_Nodes.Locked := True;
end Lock;
-----------------------------------
-- Mark_And_Set_Ghost_Assignment --
-----------------------------------
procedure Mark_And_Set_Ghost_Assignment (N : Node_Id) is
-- A ghost assignment is an assignment whose left-hand side denotes a
-- ghost object. Subcomponents are not marked "ghost", so we need to
-- find the containing "whole" object. So, for "P.X.Comp (J) := ...",
-- where P is a package, X is a record, and Comp is an array, we need
-- to check the ghost flags of X.
Orig_Lhs : constant Node_Id := Name (N);
begin
-- Ghost assignments are irrelevant when the expander is inactive, and
-- processing them in that mode can lead to spurious errors.
if Expander_Active then
-- Cases where full analysis is needed, involving array indexing
-- which would otherwise be missing array-bounds checks:
if not Analyzed (Orig_Lhs)
and then
((Nkind (Orig_Lhs) = N_Indexed_Component
and then Nkind (Prefix (Orig_Lhs)) = N_Selected_Component
and then Nkind (Prefix (Prefix (Orig_Lhs))) =
N_Indexed_Component)
or else
(Nkind (Orig_Lhs) = N_Selected_Component
and then Nkind (Prefix (Orig_Lhs)) = N_Indexed_Component
and then Nkind (Prefix (Prefix (Orig_Lhs))) =
N_Selected_Component
and then Nkind (Parent (N)) /= N_Loop_Statement))
then
Analyze (Orig_Lhs);
end if;
-- Make sure Lhs is at least preanalyzed, so we can tell whether
-- it denotes a ghost variable. In some cases we need to do a full
-- analysis, or else the back end gets confused. Note that in the
-- preanalysis case, we are preanalyzing a copy of the left-hand
-- side name, temporarily attached to the tree.
declare
Lhs : constant Node_Id :=
(if Analyzed (Orig_Lhs) then Orig_Lhs
else New_Copy_Tree (Orig_Lhs));
begin
if not Analyzed (Lhs) then
Set_Name (N, Lhs);
Set_Parent (Lhs, N);
Preanalyze_Without_Errors (Lhs);
Set_Name (N, Orig_Lhs);
end if;
declare
Whole : constant Node_Id := Whole_Object_Ref (Lhs);
Id : Entity_Id;
begin
if Is_Entity_Name (Whole) then
Id := Entity (Whole);
if Present (Id) then
-- Left-hand side denotes a Checked ghost entity, so
-- install the region.
if Is_Checked_Ghost_Entity (Id) then
Install_Ghost_Region (Check, N);
-- Left-hand side denotes an Ignored ghost entity, so
-- install the region, and mark the assignment statement
-- as an ignored ghost assignment, so it will be removed
-- later.
elsif Is_Ignored_Ghost_Entity (Id) then
Install_Ghost_Region (Ignore, N);
Set_Is_Ignored_Ghost_Node (N);
Record_Ignored_Ghost_Node (N);
end if;
end if;
end if;
end;
end;
end if;
end Mark_And_Set_Ghost_Assignment;
-----------------------------
-- Mark_And_Set_Ghost_Body --
-----------------------------
procedure Mark_And_Set_Ghost_Body
(N : Node_Id;
Spec_Id : Entity_Id)
is
Body_Id : constant Entity_Id := Defining_Entity (N);
Policy : Name_Id := No_Name;
begin
-- A body becomes Ghost when it is subject to aspect or pragma Ghost
if Is_Subject_To_Ghost (N) then
Policy := Policy_In_Effect (Name_Ghost);
-- A body declared within a Ghost region is automatically Ghost
-- (SPARK RM 6.9(2)).
elsif Ghost_Mode = Check then
Policy := Name_Check;
elsif Ghost_Mode = Ignore then
Policy := Name_Ignore;
-- Inherit the "ghostness" of the previous declaration when the body
-- acts as a completion.
elsif Present (Spec_Id) then
if Is_Checked_Ghost_Entity (Spec_Id) then
Policy := Name_Check;
elsif Is_Ignored_Ghost_Entity (Spec_Id) then
Policy := Name_Ignore;
end if;
end if;
-- The Ghost policy in effect at the point of declaration and at the
-- point of completion must match (SPARK RM 6.9(14)).
Check_Ghost_Completion
(Prev_Id => Spec_Id,
Compl_Id => Body_Id);
-- Mark the body as its formals as Ghost
Mark_Ghost_Declaration_Or_Body (N, Policy);
-- Install the appropriate Ghost region
Install_Ghost_Region (Policy, N);
end Mark_And_Set_Ghost_Body;
-----------------------------------
-- Mark_And_Set_Ghost_Completion --
-----------------------------------
procedure Mark_And_Set_Ghost_Completion
(N : Node_Id;
Prev_Id : Entity_Id)
is
Compl_Id : constant Entity_Id := Defining_Entity (N);
Policy : Name_Id := No_Name;
begin
-- A completion elaborated in a Ghost region is automatically Ghost
-- (SPARK RM 6.9(2)).
if Ghost_Mode = Check then
Policy := Name_Check;
elsif Ghost_Mode = Ignore then
Policy := Name_Ignore;
-- The completion becomes Ghost when its initial declaration is also
-- Ghost.
elsif Is_Checked_Ghost_Entity (Prev_Id) then
Policy := Name_Check;
elsif Is_Ignored_Ghost_Entity (Prev_Id) then
Policy := Name_Ignore;
end if;
-- The Ghost policy in effect at the point of declaration and at the
-- point of completion must match (SPARK RM 6.9(14)).
Check_Ghost_Completion
(Prev_Id => Prev_Id,
Compl_Id => Compl_Id);
-- Mark the completion as Ghost
Mark_Ghost_Declaration_Or_Body (N, Policy);
-- Install the appropriate Ghost region
Install_Ghost_Region (Policy, N);
end Mark_And_Set_Ghost_Completion;
------------------------------------
-- Mark_And_Set_Ghost_Declaration --
------------------------------------
procedure Mark_And_Set_Ghost_Declaration (N : Node_Id) is
Par_Id : Entity_Id;
Policy : Name_Id := No_Name;
begin
-- A declaration becomes Ghost when it is subject to aspect or pragma
-- Ghost.
if Is_Subject_To_Ghost (N) then
Policy := Policy_In_Effect (Name_Ghost);
-- A declaration elaborated in a Ghost region is automatically Ghost
-- (SPARK RM 6.9(2)).
elsif Ghost_Mode = Check then
Policy := Name_Check;
elsif Ghost_Mode = Ignore then
Policy := Name_Ignore;
-- A child package or subprogram declaration becomes Ghost when its
-- parent is Ghost (SPARK RM 6.9(2)).
elsif Nkind (N) in N_Generic_Function_Renaming_Declaration
| N_Generic_Package_Declaration
| N_Generic_Package_Renaming_Declaration
| N_Generic_Procedure_Renaming_Declaration
| N_Generic_Subprogram_Declaration
| N_Package_Declaration
| N_Package_Renaming_Declaration
| N_Subprogram_Declaration
| N_Subprogram_Renaming_Declaration
and then Present (Parent_Spec (N))
then
Par_Id := Defining_Entity (Unit (Parent_Spec (N)));
if Is_Checked_Ghost_Entity (Par_Id) then
Policy := Name_Check;
elsif Is_Ignored_Ghost_Entity (Par_Id) then
Policy := Name_Ignore;
end if;
end if;
-- Mark the declaration and its formals as Ghost
Mark_Ghost_Declaration_Or_Body (N, Policy);
-- Install the appropriate Ghost region
Install_Ghost_Region (Policy, N);
end Mark_And_Set_Ghost_Declaration;
--------------------------------------
-- Mark_And_Set_Ghost_Instantiation --
--------------------------------------
procedure Mark_And_Set_Ghost_Instantiation
(N : Node_Id;
Gen_Id : Entity_Id)
is
procedure Check_Ghost_Actuals;
-- Check the context of ghost actuals
-------------------------
-- Check_Ghost_Actuals --
-------------------------
procedure Check_Ghost_Actuals is
Assoc : Node_Id := First (Generic_Associations (N));
Act : Node_Id;
begin
while Present (Assoc) loop
if Nkind (Assoc) /= N_Others_Choice then
Act := Explicit_Generic_Actual_Parameter (Assoc);
-- Within a nested instantiation, a defaulted actual is an
-- empty association, so nothing to check.
if No (Act) then
null;
elsif Comes_From_Source (Act)
and then Nkind (Act) in N_Has_Etype
and then Present (Etype (Act))
and then Is_Ghost_Entity (Etype (Act))
then
Check_Ghost_Context (Etype (Act), Act);
end if;
end if;
Next (Assoc);
end loop;
end Check_Ghost_Actuals;
-- Local variables
Policy : Name_Id := No_Name;
begin
-- An instantiation becomes Ghost when it is subject to pragma Ghost
if Is_Subject_To_Ghost (N) then
Policy := Policy_In_Effect (Name_Ghost);
-- An instantiation declaration within a Ghost region is automatically
-- Ghost (SPARK RM 6.9(2)).
elsif Ghost_Mode = Check then
Policy := Name_Check;
elsif Ghost_Mode = Ignore then
Policy := Name_Ignore;
-- Inherit the "ghostness" of the generic unit
elsif Is_Checked_Ghost_Entity (Gen_Id) then
Policy := Name_Check;
elsif Is_Ignored_Ghost_Entity (Gen_Id) then
Policy := Name_Ignore;
end if;
-- Mark the instantiation as Ghost
Mark_Ghost_Declaration_Or_Body (N, Policy);
-- Install the appropriate Ghost region
Install_Ghost_Region (Policy, N);
-- Check Ghost actuals. Given that this routine is unconditionally
-- invoked with subprogram and package instantiations, this check
-- verifies the context of all the ghost entities passed in generic
-- instantiations.
Check_Ghost_Actuals;
end Mark_And_Set_Ghost_Instantiation;
---------------------------------------
-- Mark_And_Set_Ghost_Procedure_Call --
---------------------------------------
procedure Mark_And_Set_Ghost_Procedure_Call (N : Node_Id) is
Id : Entity_Id;
begin
-- A procedure call becomes Ghost when the procedure being invoked is
-- Ghost. Install the Ghost mode of the procedure.
Id := Ghost_Entity (Name (N));
if Present (Id) then
if Is_Checked_Ghost_Entity (Id) then
Install_Ghost_Region (Check, N);
elsif Is_Ignored_Ghost_Entity (Id) then
Install_Ghost_Region (Ignore, N);
Set_Is_Ignored_Ghost_Node (N);
Record_Ignored_Ghost_Node (N);
end if;
end if;
end Mark_And_Set_Ghost_Procedure_Call;
-----------------------
-- Mark_Ghost_Clause --
-----------------------
procedure Mark_Ghost_Clause (N : Node_Id) is
Nam : Node_Id := Empty;
begin
if Nkind (N) = N_Use_Package_Clause then
Nam := Name (N);
elsif Nkind (N) = N_Use_Type_Clause then
Nam := Subtype_Mark (N);
elsif Nkind (N) = N_With_Clause then
Nam := Name (N);
end if;
if Present (Nam)
and then Is_Entity_Name (Nam)
and then Present (Entity (Nam))
and then Is_Ignored_Ghost_Entity (Entity (Nam))
then
Set_Is_Ignored_Ghost_Node (N);
Record_Ignored_Ghost_Node (N);
end if;
end Mark_Ghost_Clause;
------------------------------------
-- Mark_Ghost_Declaration_Or_Body --
------------------------------------
procedure Mark_Ghost_Declaration_Or_Body
(N : Node_Id;
Mode : Name_Id)
is
Id : constant Entity_Id := Defining_Entity (N);
Mark_Formals : Boolean := False;
Param : Node_Id;
Param_Id : Entity_Id;
begin
-- Mark the related node and its entity
if Mode = Name_Check then
Mark_Formals := True;
Set_Is_Checked_Ghost_Entity (Id);
elsif Mode = Name_Ignore then
Mark_Formals := True;
Set_Is_Ignored_Ghost_Entity (Id);
Set_Is_Ignored_Ghost_Node (N);
Record_Ignored_Ghost_Node (N);
end if;
-- Mark all formal parameters when the related node denotes a subprogram
-- or a body. The traversal is performed via the specification because
-- the related subprogram or body may be unanalyzed.
-- ??? could extra formal parameters cause a Ghost leak?
if Mark_Formals
and then Nkind (N) in N_Abstract_Subprogram_Declaration
| N_Formal_Abstract_Subprogram_Declaration
| N_Formal_Concrete_Subprogram_Declaration
| N_Generic_Subprogram_Declaration
| N_Subprogram_Body
| N_Subprogram_Body_Stub
| N_Subprogram_Declaration
| N_Subprogram_Renaming_Declaration
then
Param := First (Parameter_Specifications (Specification (N)));
while Present (Param) loop
Param_Id := Defining_Entity (Param);
if Mode = Name_Check then
Set_Is_Checked_Ghost_Entity (Param_Id);
elsif Mode = Name_Ignore then
Set_Is_Ignored_Ghost_Entity (Param_Id);
end if;
Next (Param);
end loop;
end if;
end Mark_Ghost_Declaration_Or_Body;
-----------------------
-- Mark_Ghost_Pragma --
-----------------------
procedure Mark_Ghost_Pragma
(N : Node_Id;
Id : Entity_Id)
is
begin
-- A pragma becomes Ghost when it encloses a Ghost entity or relates to
-- a Ghost entity.
if Is_Checked_Ghost_Entity (Id) then
Set_Is_Checked_Ghost_Pragma (N);
elsif Is_Ignored_Ghost_Entity (Id) then
Set_Is_Ignored_Ghost_Pragma (N);
Set_Is_Ignored_Ghost_Node (N);
Record_Ignored_Ghost_Node (N);
end if;
end Mark_Ghost_Pragma;
-------------------------
-- Mark_Ghost_Renaming --
-------------------------
procedure Mark_Ghost_Renaming
(N : Node_Id;
Id : Entity_Id)
is
Policy : Name_Id := No_Name;
begin
-- A renaming becomes Ghost when it renames a Ghost entity
if Is_Checked_Ghost_Entity (Id) then
Policy := Name_Check;
elsif Is_Ignored_Ghost_Entity (Id) then
Policy := Name_Ignore;
end if;
Mark_Ghost_Declaration_Or_Body (N, Policy);
end Mark_Ghost_Renaming;
------------------------
-- Name_To_Ghost_Mode --
------------------------
function Name_To_Ghost_Mode (Mode : Name_Id) return Ghost_Mode_Type is
begin
if Mode = Name_Check then
return Check;
elsif Mode = Name_Ignore then
return Ignore;
-- Otherwise the mode must denote one of the following:
--
-- * Disable indicates that the Ghost policy in effect is Disable
--
-- * None or No_Name indicates that the associated construct is not
-- subject to any Ghost annotation.
else
pragma Assert (Mode in Name_Disable | Name_None | No_Name);
return None;
end if;
end Name_To_Ghost_Mode;
-------------------------------
-- Record_Ignored_Ghost_Node --
-------------------------------
procedure Record_Ignored_Ghost_Node (N : Node_Or_Entity_Id) is
begin
-- Save all "top level" ignored Ghost nodes which can be safely replaced
-- with a null statement. Note that there is need to save other kinds of
-- nodes because those will always be enclosed by some top level ignored
-- Ghost node.
if Is_Body (N)
or else Is_Declaration (N)
or else Nkind (N) in N_Generic_Instantiation
| N_Push_Pop_xxx_Label
| N_Raise_xxx_Error
| N_Representation_Clause
| N_Statement_Other_Than_Procedure_Call
| N_Call_Marker
| N_Freeze_Entity
| N_Freeze_Generic_Entity
| N_Itype_Reference
| N_Pragma
| N_Procedure_Call_Statement
| N_Use_Package_Clause
| N_Use_Type_Clause
| N_Variable_Reference_Marker
| N_With_Clause
then
-- Only ignored Ghost nodes must be recorded in the table
pragma Assert (Is_Ignored_Ghost_Node (N));
Ignored_Ghost_Nodes.Append (N);
end if;
end Record_Ignored_Ghost_Node;
-------------------------------
-- Remove_Ignored_Ghost_Code --
-------------------------------
procedure Remove_Ignored_Ghost_Code is
procedure Remove_Ignored_Ghost_Node (N : Node_Id);
-- Eliminate ignored Ghost node N from the tree
-------------------------------
-- Remove_Ignored_Ghost_Node --
-------------------------------
procedure Remove_Ignored_Ghost_Node (N : Node_Id) is
begin
-- The generation and processing of ignored Ghost nodes may cause the
-- same node to be saved multiple times. Reducing the number of saves
-- to one involves costly solutions such as a hash table or the use
-- of a flag shared by all nodes. To solve this problem, the removal
-- machinery allows for multiple saves, but does not eliminate a node
-- which has already been eliminated.
if Nkind (N) = N_Null_Statement then
null;
-- Otherwise the ignored Ghost node must be eliminated
else
-- Only ignored Ghost nodes must be eliminated from the tree
pragma Assert (Is_Ignored_Ghost_Node (N));
-- Eliminate the node by rewriting it into null. Another option
-- is to remove it from the tree, however multiple corner cases
-- emerge which have be dealt individually.
Rewrite (N, Make_Null_Statement (Sloc (N)));
-- Eliminate any aspects hanging off the ignored Ghost node
Remove_Aspects (N);
end if;
end Remove_Ignored_Ghost_Node;
-- Start of processing for Remove_Ignored_Ghost_Code
begin
for Index in Ignored_Ghost_Nodes.First .. Ignored_Ghost_Nodes.Last loop
Remove_Ignored_Ghost_Node (Ignored_Ghost_Nodes.Table (Index));
end loop;
end Remove_Ignored_Ghost_Code;
--------------------------
-- Restore_Ghost_Region --
--------------------------
procedure Restore_Ghost_Region (Mode : Ghost_Mode_Type; N : Node_Id) is
begin
Ghost_Mode := Mode;
Ignored_Ghost_Region := N;
end Restore_Ghost_Region;
--------------------
-- Set_Ghost_Mode --
--------------------
procedure Set_Ghost_Mode (N : Node_Or_Entity_Id) is
procedure Set_Ghost_Mode_From_Entity (Id : Entity_Id);
-- Install the Ghost mode of entity Id
--------------------------------
-- Set_Ghost_Mode_From_Entity --
--------------------------------
procedure Set_Ghost_Mode_From_Entity (Id : Entity_Id) is
begin
if Is_Checked_Ghost_Entity (Id) then
Install_Ghost_Mode (Check);
elsif Is_Ignored_Ghost_Entity (Id) then
Install_Ghost_Mode (Ignore);
else
Install_Ghost_Mode (None);
end if;
end Set_Ghost_Mode_From_Entity;
-- Local variables
Id : Entity_Id;
-- Start of processing for Set_Ghost_Mode
begin
-- The Ghost mode of an assignment statement depends on the Ghost mode
-- of the target.
if Nkind (N) = N_Assignment_Statement then
Id := Ghost_Entity (Name (N));
if Present (Id) then
Set_Ghost_Mode_From_Entity (Id);
end if;
-- The Ghost mode of a body or a declaration depends on the Ghost mode
-- of its defining entity.
elsif Is_Body (N) or else Is_Declaration (N) then
Set_Ghost_Mode_From_Entity (Defining_Entity (N));
-- The Ghost mode of an entity depends on the entity itself
elsif Nkind (N) in N_Entity then
Set_Ghost_Mode_From_Entity (N);
-- The Ghost mode of a [generic] freeze node depends on the Ghost mode
-- of the entity being frozen.
elsif Nkind (N) in N_Freeze_Entity | N_Freeze_Generic_Entity then
Set_Ghost_Mode_From_Entity (Entity (N));
-- The Ghost mode of a pragma depends on the associated entity. The
-- property is encoded in the pragma itself.
elsif Nkind (N) = N_Pragma then
if Is_Checked_Ghost_Pragma (N) then
Install_Ghost_Mode (Check);
elsif Is_Ignored_Ghost_Pragma (N) then
Install_Ghost_Mode (Ignore);
else
Install_Ghost_Mode (None);
end if;
-- The Ghost mode of a procedure call depends on the Ghost mode of the
-- procedure being invoked.
elsif Nkind (N) = N_Procedure_Call_Statement then
Id := Ghost_Entity (Name (N));
if Present (Id) then
Set_Ghost_Mode_From_Entity (Id);
end if;
end if;
end Set_Ghost_Mode;
-------------------------
-- Set_Is_Ghost_Entity --
-------------------------
procedure Set_Is_Ghost_Entity (Id : Entity_Id) is
Policy : constant Name_Id := Policy_In_Effect (Name_Ghost);
begin
if Policy = Name_Check then
Set_Is_Checked_Ghost_Entity (Id);
elsif Policy = Name_Ignore then
Set_Is_Ignored_Ghost_Entity (Id);
end if;
end Set_Is_Ghost_Entity;
----------------------
-- Whole_Object_Ref --
----------------------
function Whole_Object_Ref (Ref : Node_Id) return Node_Id is
begin
if Nkind (Ref) in N_Indexed_Component | N_Slice
or else (Nkind (Ref) = N_Selected_Component
and then Is_Object_Reference (Prefix (Ref)))
then
if Is_Access_Type (Etype (Prefix (Ref))) then
return Ref;
else
return Whole_Object_Ref (Prefix (Ref));
end if;
else
return Ref;
end if;
end Whole_Object_Ref;
end Ghost;
|
AdaCore/Ada_Drivers_Library | Ada | 2,997 | ads | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2016, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- This package defines an abstract data machine representing the USER button
-- on many (most) STM boards. It uses an interrupt handler to track presses,
-- reflected in the result of calling function Has_Been_Pressed.
package STM32.User_Button is
procedure Initialize (Use_Rising_Edge : Boolean := True) with
Pre => not Initialized,
Post => Initialized;
function Has_Been_Pressed return Boolean with
Pre => Initialized;
-- Returns whether the user button has been pressed since the last time
-- this subprogram was called.
function Initialized return Boolean;
end STM32.User_Button;
|
1Crazymoney/LearnAda | Ada | 14,252 | ads | pragma Ada_95;
with System;
package ada_main is
pragma Warnings (Off);
gnat_argc : Integer;
gnat_argv : System.Address;
gnat_envp : System.Address;
pragma Import (C, gnat_argc);
pragma Import (C, gnat_argv);
pragma Import (C, gnat_envp);
gnat_exit_status : Integer;
pragma Import (C, gnat_exit_status);
GNAT_Version : constant String :=
"GNAT Version: GPL 2015 (20150428-49)" & ASCII.NUL;
pragma Export (C, GNAT_Version, "__gnat_version");
Ada_Main_Program_Name : constant String := "_ada_max2" & ASCII.NUL;
pragma Export (C, Ada_Main_Program_Name, "__gnat_ada_main_program_name");
procedure adainit;
pragma Export (C, adainit, "adainit");
procedure adafinal;
pragma Export (C, adafinal, "adafinal");
function main
(argc : Integer;
argv : System.Address;
envp : System.Address)
return Integer;
pragma Export (C, main, "main");
type Version_32 is mod 2 ** 32;
u00001 : constant Version_32 := 16#1b071161#;
pragma Export (C, u00001, "max2B");
u00002 : constant Version_32 := 16#fbff4c67#;
pragma Export (C, u00002, "system__standard_libraryB");
u00003 : constant Version_32 := 16#f72f352b#;
pragma Export (C, u00003, "system__standard_libraryS");
u00004 : constant Version_32 := 16#3ffc8e18#;
pragma Export (C, u00004, "adaS");
u00005 : constant Version_32 := 16#f64b89a4#;
pragma Export (C, u00005, "ada__integer_text_ioB");
u00006 : constant Version_32 := 16#f1daf268#;
pragma Export (C, u00006, "ada__integer_text_ioS");
u00007 : constant Version_32 := 16#b612ca65#;
pragma Export (C, u00007, "ada__exceptionsB");
u00008 : constant Version_32 := 16#1d190453#;
pragma Export (C, u00008, "ada__exceptionsS");
u00009 : constant Version_32 := 16#a46739c0#;
pragma Export (C, u00009, "ada__exceptions__last_chance_handlerB");
u00010 : constant Version_32 := 16#3aac8c92#;
pragma Export (C, u00010, "ada__exceptions__last_chance_handlerS");
u00011 : constant Version_32 := 16#f4ce8c3a#;
pragma Export (C, u00011, "systemS");
u00012 : constant Version_32 := 16#a207fefe#;
pragma Export (C, u00012, "system__soft_linksB");
u00013 : constant Version_32 := 16#af945ded#;
pragma Export (C, u00013, "system__soft_linksS");
u00014 : constant Version_32 := 16#b01dad17#;
pragma Export (C, u00014, "system__parametersB");
u00015 : constant Version_32 := 16#8ae48145#;
pragma Export (C, u00015, "system__parametersS");
u00016 : constant Version_32 := 16#b19b6653#;
pragma Export (C, u00016, "system__secondary_stackB");
u00017 : constant Version_32 := 16#5faf4353#;
pragma Export (C, u00017, "system__secondary_stackS");
u00018 : constant Version_32 := 16#39a03df9#;
pragma Export (C, u00018, "system__storage_elementsB");
u00019 : constant Version_32 := 16#d90dc63e#;
pragma Export (C, u00019, "system__storage_elementsS");
u00020 : constant Version_32 := 16#41837d1e#;
pragma Export (C, u00020, "system__stack_checkingB");
u00021 : constant Version_32 := 16#7a71e7d2#;
pragma Export (C, u00021, "system__stack_checkingS");
u00022 : constant Version_32 := 16#393398c1#;
pragma Export (C, u00022, "system__exception_tableB");
u00023 : constant Version_32 := 16#5ad7ea2f#;
pragma Export (C, u00023, "system__exception_tableS");
u00024 : constant Version_32 := 16#ce4af020#;
pragma Export (C, u00024, "system__exceptionsB");
u00025 : constant Version_32 := 16#9cade1cc#;
pragma Export (C, u00025, "system__exceptionsS");
u00026 : constant Version_32 := 16#37d758f1#;
pragma Export (C, u00026, "system__exceptions__machineS");
u00027 : constant Version_32 := 16#b895431d#;
pragma Export (C, u00027, "system__exceptions_debugB");
u00028 : constant Version_32 := 16#472c9584#;
pragma Export (C, u00028, "system__exceptions_debugS");
u00029 : constant Version_32 := 16#570325c8#;
pragma Export (C, u00029, "system__img_intB");
u00030 : constant Version_32 := 16#f6156cf8#;
pragma Export (C, u00030, "system__img_intS");
u00031 : constant Version_32 := 16#b98c3e16#;
pragma Export (C, u00031, "system__tracebackB");
u00032 : constant Version_32 := 16#6af355e1#;
pragma Export (C, u00032, "system__tracebackS");
u00033 : constant Version_32 := 16#9ed49525#;
pragma Export (C, u00033, "system__traceback_entriesB");
u00034 : constant Version_32 := 16#f4957a4a#;
pragma Export (C, u00034, "system__traceback_entriesS");
u00035 : constant Version_32 := 16#8c33a517#;
pragma Export (C, u00035, "system__wch_conB");
u00036 : constant Version_32 := 16#efb3aee8#;
pragma Export (C, u00036, "system__wch_conS");
u00037 : constant Version_32 := 16#9721e840#;
pragma Export (C, u00037, "system__wch_stwB");
u00038 : constant Version_32 := 16#c2a282e9#;
pragma Export (C, u00038, "system__wch_stwS");
u00039 : constant Version_32 := 16#92b797cb#;
pragma Export (C, u00039, "system__wch_cnvB");
u00040 : constant Version_32 := 16#e004141b#;
pragma Export (C, u00040, "system__wch_cnvS");
u00041 : constant Version_32 := 16#6033a23f#;
pragma Export (C, u00041, "interfacesS");
u00042 : constant Version_32 := 16#ece6fdb6#;
pragma Export (C, u00042, "system__wch_jisB");
u00043 : constant Version_32 := 16#60740d3a#;
pragma Export (C, u00043, "system__wch_jisS");
u00044 : constant Version_32 := 16#28f088c2#;
pragma Export (C, u00044, "ada__text_ioB");
u00045 : constant Version_32 := 16#1a9b0017#;
pragma Export (C, u00045, "ada__text_ioS");
u00046 : constant Version_32 := 16#10558b11#;
pragma Export (C, u00046, "ada__streamsB");
u00047 : constant Version_32 := 16#2e6701ab#;
pragma Export (C, u00047, "ada__streamsS");
u00048 : constant Version_32 := 16#db5c917c#;
pragma Export (C, u00048, "ada__io_exceptionsS");
u00049 : constant Version_32 := 16#12c8cd7d#;
pragma Export (C, u00049, "ada__tagsB");
u00050 : constant Version_32 := 16#ce72c228#;
pragma Export (C, u00050, "ada__tagsS");
u00051 : constant Version_32 := 16#c3335bfd#;
pragma Export (C, u00051, "system__htableB");
u00052 : constant Version_32 := 16#700c3fd0#;
pragma Export (C, u00052, "system__htableS");
u00053 : constant Version_32 := 16#089f5cd0#;
pragma Export (C, u00053, "system__string_hashB");
u00054 : constant Version_32 := 16#d25254ae#;
pragma Export (C, u00054, "system__string_hashS");
u00055 : constant Version_32 := 16#699628fa#;
pragma Export (C, u00055, "system__unsigned_typesS");
u00056 : constant Version_32 := 16#b44f9ae7#;
pragma Export (C, u00056, "system__val_unsB");
u00057 : constant Version_32 := 16#793ec5c1#;
pragma Export (C, u00057, "system__val_unsS");
u00058 : constant Version_32 := 16#27b600b2#;
pragma Export (C, u00058, "system__val_utilB");
u00059 : constant Version_32 := 16#586e3ac4#;
pragma Export (C, u00059, "system__val_utilS");
u00060 : constant Version_32 := 16#d1060688#;
pragma Export (C, u00060, "system__case_utilB");
u00061 : constant Version_32 := 16#d0c7e5ed#;
pragma Export (C, u00061, "system__case_utilS");
u00062 : constant Version_32 := 16#84a27f0d#;
pragma Export (C, u00062, "interfaces__c_streamsB");
u00063 : constant Version_32 := 16#8bb5f2c0#;
pragma Export (C, u00063, "interfaces__c_streamsS");
u00064 : constant Version_32 := 16#845f5a34#;
pragma Export (C, u00064, "system__crtlS");
u00065 : constant Version_32 := 16#431faf3c#;
pragma Export (C, u00065, "system__file_ioB");
u00066 : constant Version_32 := 16#53bf6d5f#;
pragma Export (C, u00066, "system__file_ioS");
u00067 : constant Version_32 := 16#b7ab275c#;
pragma Export (C, u00067, "ada__finalizationB");
u00068 : constant Version_32 := 16#19f764ca#;
pragma Export (C, u00068, "ada__finalizationS");
u00069 : constant Version_32 := 16#95817ed8#;
pragma Export (C, u00069, "system__finalization_rootB");
u00070 : constant Version_32 := 16#bb3cffaa#;
pragma Export (C, u00070, "system__finalization_rootS");
u00071 : constant Version_32 := 16#769e25e6#;
pragma Export (C, u00071, "interfaces__cB");
u00072 : constant Version_32 := 16#4a38bedb#;
pragma Export (C, u00072, "interfaces__cS");
u00073 : constant Version_32 := 16#ee0f26dd#;
pragma Export (C, u00073, "system__os_libB");
u00074 : constant Version_32 := 16#d7b69782#;
pragma Export (C, u00074, "system__os_libS");
u00075 : constant Version_32 := 16#1a817b8e#;
pragma Export (C, u00075, "system__stringsB");
u00076 : constant Version_32 := 16#8a719d5c#;
pragma Export (C, u00076, "system__stringsS");
u00077 : constant Version_32 := 16#09511692#;
pragma Export (C, u00077, "system__file_control_blockS");
u00078 : constant Version_32 := 16#f6fdca1c#;
pragma Export (C, u00078, "ada__text_io__integer_auxB");
u00079 : constant Version_32 := 16#b9793d30#;
pragma Export (C, u00079, "ada__text_io__integer_auxS");
u00080 : constant Version_32 := 16#181dc502#;
pragma Export (C, u00080, "ada__text_io__generic_auxB");
u00081 : constant Version_32 := 16#a6c327d3#;
pragma Export (C, u00081, "ada__text_io__generic_auxS");
u00082 : constant Version_32 := 16#18d57884#;
pragma Export (C, u00082, "system__img_biuB");
u00083 : constant Version_32 := 16#afb4a0b7#;
pragma Export (C, u00083, "system__img_biuS");
u00084 : constant Version_32 := 16#e7d8734f#;
pragma Export (C, u00084, "system__img_llbB");
u00085 : constant Version_32 := 16#ee73b049#;
pragma Export (C, u00085, "system__img_llbS");
u00086 : constant Version_32 := 16#9777733a#;
pragma Export (C, u00086, "system__img_lliB");
u00087 : constant Version_32 := 16#e581d9eb#;
pragma Export (C, u00087, "system__img_lliS");
u00088 : constant Version_32 := 16#0e8808d4#;
pragma Export (C, u00088, "system__img_llwB");
u00089 : constant Version_32 := 16#471f93df#;
pragma Export (C, u00089, "system__img_llwS");
u00090 : constant Version_32 := 16#428b07f8#;
pragma Export (C, u00090, "system__img_wiuB");
u00091 : constant Version_32 := 16#c1f52725#;
pragma Export (C, u00091, "system__img_wiuS");
u00092 : constant Version_32 := 16#7ebd8839#;
pragma Export (C, u00092, "system__val_intB");
u00093 : constant Version_32 := 16#bc6ba605#;
pragma Export (C, u00093, "system__val_intS");
u00094 : constant Version_32 := 16#b3aa7b17#;
pragma Export (C, u00094, "system__val_lliB");
u00095 : constant Version_32 := 16#6eea6a9a#;
pragma Export (C, u00095, "system__val_lliS");
u00096 : constant Version_32 := 16#06052bd0#;
pragma Export (C, u00096, "system__val_lluB");
u00097 : constant Version_32 := 16#13647f88#;
pragma Export (C, u00097, "system__val_lluS");
u00098 : constant Version_32 := 16#890726fa#;
pragma Export (C, u00098, "matB");
u00099 : constant Version_32 := 16#3a00bf52#;
pragma Export (C, u00099, "matS");
u00100 : constant Version_32 := 16#2bce1226#;
pragma Export (C, u00100, "system__memoryB");
u00101 : constant Version_32 := 16#adb3ea0e#;
pragma Export (C, u00101, "system__memoryS");
-- BEGIN ELABORATION ORDER
-- ada%s
-- interfaces%s
-- system%s
-- system.case_util%s
-- system.case_util%b
-- system.htable%s
-- system.img_int%s
-- system.img_int%b
-- system.img_lli%s
-- system.img_lli%b
-- system.parameters%s
-- system.parameters%b
-- system.crtl%s
-- interfaces.c_streams%s
-- interfaces.c_streams%b
-- system.standard_library%s
-- system.exceptions_debug%s
-- system.exceptions_debug%b
-- system.storage_elements%s
-- system.storage_elements%b
-- system.stack_checking%s
-- system.stack_checking%b
-- system.string_hash%s
-- system.string_hash%b
-- system.htable%b
-- system.strings%s
-- system.strings%b
-- system.os_lib%s
-- system.traceback_entries%s
-- system.traceback_entries%b
-- ada.exceptions%s
-- system.soft_links%s
-- system.unsigned_types%s
-- system.img_biu%s
-- system.img_biu%b
-- system.img_llb%s
-- system.img_llb%b
-- system.img_llw%s
-- system.img_llw%b
-- system.img_wiu%s
-- system.img_wiu%b
-- system.val_int%s
-- system.val_lli%s
-- system.val_llu%s
-- system.val_uns%s
-- system.val_util%s
-- system.val_util%b
-- system.val_uns%b
-- system.val_llu%b
-- system.val_lli%b
-- system.val_int%b
-- system.wch_con%s
-- system.wch_con%b
-- system.wch_cnv%s
-- system.wch_jis%s
-- system.wch_jis%b
-- system.wch_cnv%b
-- system.wch_stw%s
-- system.wch_stw%b
-- ada.exceptions.last_chance_handler%s
-- ada.exceptions.last_chance_handler%b
-- system.exception_table%s
-- system.exception_table%b
-- ada.io_exceptions%s
-- ada.tags%s
-- ada.streams%s
-- ada.streams%b
-- interfaces.c%s
-- system.exceptions%s
-- system.exceptions%b
-- system.exceptions.machine%s
-- system.file_control_block%s
-- system.file_io%s
-- system.finalization_root%s
-- system.finalization_root%b
-- ada.finalization%s
-- ada.finalization%b
-- system.memory%s
-- system.memory%b
-- system.standard_library%b
-- system.secondary_stack%s
-- system.file_io%b
-- interfaces.c%b
-- ada.tags%b
-- system.soft_links%b
-- system.os_lib%b
-- system.secondary_stack%b
-- system.traceback%s
-- ada.exceptions%b
-- system.traceback%b
-- ada.text_io%s
-- ada.text_io%b
-- ada.text_io.generic_aux%s
-- ada.text_io.generic_aux%b
-- ada.text_io.integer_aux%s
-- ada.text_io.integer_aux%b
-- ada.integer_text_io%s
-- ada.integer_text_io%b
-- mat%s
-- mat%b
-- max2%b
-- END ELABORATION ORDER
end ada_main;
|
zhmu/ananas | Ada | 4,924 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . W I D _ E N U M --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
package body System.Wid_Enum is
-------------------------
-- Width_Enumeration_8 --
-------------------------
function Width_Enumeration_8
(Names : String;
Indexes : System.Address;
Lo, Hi : Natural)
return Natural
is
pragma Warnings (Off, Names);
W : Natural;
type Natural_8 is range 0 .. 2 ** 7 - 1;
type Index_Table is array (Natural) of Natural_8;
type Index_Table_Ptr is access Index_Table;
function To_Index_Table_Ptr is
new Ada.Unchecked_Conversion (System.Address, Index_Table_Ptr);
IndexesT : constant Index_Table_Ptr := To_Index_Table_Ptr (Indexes);
begin
W := 0;
for J in Lo .. Hi loop
W := Natural'Max (W, Natural (IndexesT (J + 1) - IndexesT (J)));
end loop;
return W;
end Width_Enumeration_8;
--------------------------
-- Width_Enumeration_16 --
--------------------------
function Width_Enumeration_16
(Names : String;
Indexes : System.Address;
Lo, Hi : Natural)
return Natural
is
pragma Warnings (Off, Names);
W : Natural;
type Natural_16 is range 0 .. 2 ** 15 - 1;
type Index_Table is array (Natural) of Natural_16;
type Index_Table_Ptr is access Index_Table;
function To_Index_Table_Ptr is
new Ada.Unchecked_Conversion (System.Address, Index_Table_Ptr);
IndexesT : constant Index_Table_Ptr := To_Index_Table_Ptr (Indexes);
begin
W := 0;
for J in Lo .. Hi loop
W := Natural'Max (W, Natural (IndexesT (J + 1) - IndexesT (J)));
end loop;
return W;
end Width_Enumeration_16;
--------------------------
-- Width_Enumeration_32 --
--------------------------
function Width_Enumeration_32
(Names : String;
Indexes : System.Address;
Lo, Hi : Natural)
return Natural
is
pragma Warnings (Off, Names);
W : Natural;
type Natural_32 is range 0 .. 2 ** 31 - 1;
type Index_Table is array (Natural) of Natural_32;
type Index_Table_Ptr is access Index_Table;
function To_Index_Table_Ptr is
new Ada.Unchecked_Conversion (System.Address, Index_Table_Ptr);
IndexesT : constant Index_Table_Ptr := To_Index_Table_Ptr (Indexes);
begin
W := 0;
for J in Lo .. Hi loop
W := Natural'Max (W, Natural (IndexesT (J + 1) - IndexesT (J)));
end loop;
return W;
end Width_Enumeration_32;
end System.Wid_Enum;
|
reznikmm/matreshka | Ada | 6,928 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Presentation.Notes_Elements is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Presentation_Notes_Element_Node is
begin
return Self : Presentation_Notes_Element_Node do
Matreshka.ODF_Presentation.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Presentation_Prefix);
end return;
end Create;
----------------
-- Enter_Node --
----------------
overriding procedure Enter_Node
(Self : not null access Presentation_Notes_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Enter_Presentation_Notes
(ODF.DOM.Presentation_Notes_Elements.ODF_Presentation_Notes_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Enter_Node (Visitor, Control);
end if;
end Enter_Node;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Presentation_Notes_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Notes_Element;
end Get_Local_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Presentation_Notes_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Leave_Presentation_Notes
(ODF.DOM.Presentation_Notes_Elements.ODF_Presentation_Notes_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Leave_Node (Visitor, Control);
end if;
end Leave_Node;
----------------
-- Visit_Node --
----------------
overriding procedure Visit_Node
(Self : not null access Presentation_Notes_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then
ODF.DOM.Iterators.Abstract_ODF_Iterator'Class
(Iterator).Visit_Presentation_Notes
(Visitor,
ODF.DOM.Presentation_Notes_Elements.ODF_Presentation_Notes_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Visit_Node (Iterator, Visitor, Control);
end if;
end Visit_Node;
begin
Matreshka.DOM_Documents.Register_Element
(Matreshka.ODF_String_Constants.Presentation_URI,
Matreshka.ODF_String_Constants.Notes_Element,
Presentation_Notes_Element_Node'Tag);
end Matreshka.ODF_Presentation.Notes_Elements;
|
usnistgov/rcslib | Ada | 1,523 | ads | --
-- New Ada Spec File starts here.
-- This file should be named nml_ex1_n_ada.ads
-- Automatically generated by NML CodeGen Java Applet.
with Nml_Msg; use Nml_Msg;
with Cms;
with Posemath_N_Ada; use Posemath_N_Ada;
-- Some standard Ada Packages we always need.
with Unchecked_Deallocation;
with Unchecked_Conversion;
with Interfaces.C; use Interfaces.C;
package nml_ex1_n_ada is
-- Create Ada versions of the Enumeration types.
function Format(Nml_Type : in long;
Msg : in NmlMsg_Access;
Cms_Ptr : in Cms.Cms_Access)
return int;
pragma Export(C,Format,"ada_nml_ex1_n_ada_format");
-- Redefine the C++ NML message classes as Ada Records.
EXAMPLE_MSG_TYPE : constant := 101;
type EXAMPLE_MSG is new NMLmsg with
record
d : double;
f : c_float;
c : char;
s : short;
i : int;
l : long;
uc : unsigned_char;
us : unsigned_short;
ui : unsigned;
ul : unsigned_long;
da_length : int;
da : Cms.Double_Array(1..20); -- NML_DYNAMIC_LENGTH_ARRAY --
end record;
type EXAMPLE_MSG_Access is access all EXAMPLE_MSG;
procedure Initialize(Msg : in out EXAMPLE_MSG);
function NmlMsg_to_EXAMPLE_MSG is new Unchecked_Conversion(NmlMsg_Access,EXAMPLE_MSG_Access);
procedure Update_Internal_EXAMPLE_MSG(Cms_Ptr : in Cms.Cms_Access; Msg : in out EXAMPLE_MSG);
procedure Free is new Unchecked_Deallocation(EXAMPLE_MSG,EXAMPLE_MSG_Access);
type EXAMPLE_MSG_Array is array(Integer range <>) of EXAMPLE_MSG;
end nml_ex1_n_ada;
-- End of Ada spec file nml_ex1_n_ada.ads
|
philipbjorge/Parallel-Elliptic-Partial-Differential-Equation-Solver | Ada | 632 | adb | -- Philip Bjorge
-- Simple barrier using protected types that
-- waits on a certain number of entrants
package body Barrier is
protected body Barrier_Type is
entry Here when not leave is begin
count := count + 1;
if count < wait_for then
requeue Wait;
else
count := count - 1;
if count /= 0 then
leave := True;
end if;
end if;
end;
entry Wait when leave is begin
count := count - 1;
if count = 0 then
leave := False;
end if;
end;
end Barrier_Type;
end Barrier;
|
zhmu/ananas | Ada | 30,574 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . T A G S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
-- apply solely to the contents of the part following the private keyword. --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
-- For performance analysis, take into account that the operations in this
-- package provide the guarantee that all dispatching calls on primitive
-- operations of tagged types and interfaces take constant time (in terms
-- of source lines executed), that is to say, the cost of these calls is
-- independent of the number of primitives of the type or interface, and
-- independent of the number of ancestors or interface progenitors that a
-- tagged type may have.
-- The following subprograms of the public part of this package take constant
-- time (in terms of source lines executed):
-- Expanded_Name, Wide_Expanded_Name, Wide_Wide_Expanded_Name, External_Tag,
-- Is_Abstract, Is_Descendant_At_Same_Level, Parent_Tag,
-- Descendant_Tag (when used with a library-level tagged type),
-- Internal_Tag (when used with a library-level tagged type).
-- The following subprograms of the public part of this package execute in
-- time that is not constant (in terms of sources line executed):
-- Internal_Tag (when used with a locally defined tagged type), because in
-- such cases this routine processes the external tag, extracts from it an
-- address available there, and converts it into the tag value returned by
-- this function. The number of instructions executed is not constant since
-- it depends on the length of the external tag string.
-- Descendant_Tag (when used with a locally defined tagged type), because
-- it relies on the subprogram Internal_Tag() to provide its functionality.
-- Interface_Ancestor_Tags, because this function returns a table whose
-- length depends on the number of interfaces covered by a tagged type.
with System.Storage_Elements;
with Ada.Unchecked_Conversion;
package Ada.Tags is
pragma Preelaborate;
-- In accordance with Ada 2005 AI-362
type Tag is private;
pragma Preelaborable_Initialization (Tag);
No_Tag : constant Tag;
function Expanded_Name (T : Tag) return String;
function Wide_Expanded_Name (T : Tag) return Wide_String;
pragma Ada_05 (Wide_Expanded_Name);
function Wide_Wide_Expanded_Name (T : Tag) return Wide_Wide_String;
pragma Ada_05 (Wide_Wide_Expanded_Name);
function External_Tag (T : Tag) return String;
function Internal_Tag (External : String) return Tag;
function Descendant_Tag
(External : String;
Ancestor : Tag) return Tag;
pragma Ada_05 (Descendant_Tag);
function Is_Descendant_At_Same_Level
(Descendant : Tag;
Ancestor : Tag) return Boolean;
pragma Ada_05 (Is_Descendant_At_Same_Level);
function Parent_Tag (T : Tag) return Tag;
pragma Ada_05 (Parent_Tag);
type Tag_Array is array (Positive range <>) of Tag;
function Interface_Ancestor_Tags (T : Tag) return Tag_Array;
pragma Ada_05 (Interface_Ancestor_Tags);
function Is_Abstract (T : Tag) return Boolean;
pragma Ada_2012 (Is_Abstract);
Tag_Error : exception;
private
-- Structure of the GNAT Primary Dispatch Table
-- +--------------------+
-- | Signature |
-- +--------------------+
-- | Tagged_Kind |
-- +--------------------+ Predef Prims
-- | Predef_Prims -----------------------------> +------------+
-- +--------------------+ | table of |
-- | Offset_To_Top | | predefined |
-- +--------------------+ | primitives |
-- |Typeinfo_Ptr/TSD_Ptr---> Type Specific Data +------------+
-- Tag ---> +--------------------+ +-------------------+
-- | table of | | inheritance depth |
-- : primitive ops : +-------------------+
-- | pointers | | access level |
-- +--------------------+ +-------------------+
-- | alignment |
-- +-------------------+
-- | expanded name |
-- +-------------------+
-- | external tag |
-- +-------------------+
-- | hash table link |
-- +-------------------+
-- | transportable |
-- +-------------------+
-- | is_abstract |
-- +-------------------+
-- | needs finalization|
-- +-------------------+
-- | Ifaces_Table ---> Interface Data
-- +-------------------+ +------------+
-- Select Specific Data <---- SSD | | Nb_Ifaces |
-- +------------------+ +-------------------+ +------------+
-- |table of primitive| | table of | | table |
-- : operation : : ancestor : : of :
-- | kinds | | tags | | interfaces |
-- +------------------+ +-------------------+ +------------+
-- |table of |
-- : entry :
-- | indexes |
-- +------------------+
-- Structure of the GNAT Secondary Dispatch Table
-- +--------------------+
-- | Signature |
-- +--------------------+
-- | Tagged_Kind |
-- +--------------------+ Predef Prims
-- | Predef_Prims -----------------------------> +------------+
-- +--------------------+ | table of |
-- | Offset_To_Top | | predefined |
-- +--------------------+ | primitives |
-- | OSD_Ptr |---> Object Specific Data | thunks |
-- Tag ---> +--------------------+ +---------------+ +------------+
-- | table of | | num prim ops |
-- : primitive op : +---------------+
-- | thunk pointers | | table of |
-- +--------------------+ + primitive |
-- | op offsets |
-- +---------------+
-- The runtime information kept for each tagged type is separated into two
-- objects: the Dispatch Table and the Type Specific Data record.
package SSE renames System.Storage_Elements;
subtype Cstring is String (Positive);
type Cstring_Ptr is access all Cstring;
pragma No_Strict_Aliasing (Cstring_Ptr);
-- Declarations for the table of interfaces
type Offset_To_Top_Function_Ptr is
access function (This : System.Address) return SSE.Storage_Offset;
-- Type definition used to call the function that is generated by the
-- expander in case of tagged types with discriminants that have secondary
-- dispatch tables. This function provides the Offset_To_Top value in this
-- specific case.
type Interface_Data_Element is record
Iface_Tag : Tag;
Static_Offset_To_Top : Boolean;
Offset_To_Top_Value : SSE.Storage_Offset;
Offset_To_Top_Func : Offset_To_Top_Function_Ptr;
Secondary_DT : Tag;
end record;
-- If some ancestor of the tagged type has discriminants the field
-- Static_Offset_To_Top is False and the field Offset_To_Top_Func
-- is used to store the access to the function generated by the
-- expander which provides this value; otherwise Static_Offset_To_Top
-- is True and such value is stored in the Offset_To_Top_Value field.
-- Secondary_DT references a secondary dispatch table whose contents
-- are pointers to the primitives of the tagged type that cover the
-- interface primitives. Secondary_DT gives support to dispatching
-- calls through interface types associated with Generic Dispatching
-- Constructors.
type Interfaces_Array is array (Natural range <>) of Interface_Data_Element;
type Interface_Data (Nb_Ifaces : Positive) is record
Ifaces_Table : Interfaces_Array (1 .. Nb_Ifaces);
end record;
type Interface_Data_Ptr is access all Interface_Data;
-- Table of abstract interfaces used to give support to backward interface
-- conversions and also to IW_Membership.
-- Primitive operation kinds. These values differentiate the kinds of
-- callable entities stored in the dispatch table. Certain kinds may
-- not be used, but are added for completeness.
type Prim_Op_Kind is
(POK_Function,
POK_Procedure,
POK_Protected_Entry,
POK_Protected_Function,
POK_Protected_Procedure,
POK_Task_Entry,
POK_Task_Function,
POK_Task_Procedure);
-- Select specific data types
type Select_Specific_Data_Element is record
Index : Positive;
Kind : Prim_Op_Kind;
end record;
type Select_Specific_Data_Array is
array (Positive range <>) of Select_Specific_Data_Element;
type Select_Specific_Data (Nb_Prim : Positive) is record
SSD_Table : Select_Specific_Data_Array (1 .. Nb_Prim);
-- NOTE: Nb_Prim is the number of non-predefined primitive operations
end record;
type Select_Specific_Data_Ptr is access all Select_Specific_Data;
-- A table used to store the primitive operation kind and entry index of
-- primitive subprograms of a type that implements a limited interface.
-- The Select Specific Data table resides in the Type Specific Data of a
-- type. This construct is used in the handling of dispatching triggers
-- in select statements.
type Prim_Ptr is access procedure;
type Address_Array is array (Positive range <>) of Prim_Ptr;
subtype Dispatch_Table is Address_Array (1 .. 1);
-- Used by GDB to identify the _tags and traverse the run-time structure
-- associated with tagged types. For compatibility with older versions of
-- gdb, its name must not be changed.
type Tag is access all Dispatch_Table;
pragma No_Strict_Aliasing (Tag);
type Interface_Tag is access all Dispatch_Table;
No_Tag : constant Tag := null;
-- The expander ensures that Tag objects reference the Prims_Ptr component
-- of the wrapper.
type Tag_Ptr is access all Tag;
pragma No_Strict_Aliasing (Tag_Ptr);
type Offset_To_Top_Ptr is access all SSE.Storage_Offset;
pragma No_Strict_Aliasing (Offset_To_Top_Ptr);
type Tag_Table is array (Natural range <>) of Tag;
type Size_Ptr is
access function (A : System.Address) return Long_Long_Integer;
type Type_Specific_Data (Idepth : Natural) is record
-- The discriminant Idepth is the Inheritance Depth Level: Used to
-- implement the membership test associated with single inheritance of
-- tagged types in constant-time. It also indicates the size of the
-- Tags_Table component.
Access_Level : Natural;
-- Accessibility level required to give support to Ada 2005 nested type
-- extensions. This feature allows safe nested type extensions by
-- shifting the accessibility checks to certain operations, rather than
-- being enforced at the type declaration. In particular, by performing
-- run-time accessibility checks on class-wide allocators, class-wide
-- function return, and class-wide stream I/O, the danger of objects
-- outliving their type declaration can be eliminated (Ada 2005: AI-344)
Alignment : Natural;
Expanded_Name : Cstring_Ptr;
External_Tag : Cstring_Ptr;
HT_Link : Tag_Ptr;
-- Components used to support to the Ada.Tags subprograms in RM 3.9
-- Note: Expanded_Name is referenced by GDB to determine the actual name
-- of the tagged type. Its requirements are: 1) it must have this exact
-- name, and 2) its contents must point to a C-style Nul terminated
-- string containing its expanded name. GDB has no requirement on a
-- given position inside the record.
Transportable : Boolean;
-- Used to check RM E.4(18), set for types that satisfy the requirements
-- for being used in remote calls as actuals for classwide formals or as
-- return values for classwide functions.
Is_Abstract : Boolean;
-- True if the type is abstract (Ada 2012: AI05-0173)
Needs_Finalization : Boolean;
-- Used to dynamically check whether an object is controlled or not
Size_Func : Size_Ptr;
-- Pointer to the subprogram computing the _size of the object. Used by
-- the run-time whenever a call to the 'size primitive is required. We
-- cannot assume that the contents of dispatch tables are addresses
-- because in some architectures the ABI allows descriptors.
Interfaces_Table : Interface_Data_Ptr;
-- Pointer to the table of interface tags. It is used to implement the
-- membership test associated with interfaces and also for backward
-- abstract interface type conversions (Ada 2005:AI-251)
SSD : Select_Specific_Data_Ptr;
-- Pointer to a table of records used in dispatching selects. This field
-- has a meaningful value for all tagged types that implement a limited,
-- protected, synchronized or task interfaces and have non-predefined
-- primitive operations.
Tags_Table : Tag_Table (0 .. Idepth);
-- Table of ancestor tags. Its size actually depends on the inheritance
-- depth level of the tagged type.
end record;
type Type_Specific_Data_Ptr is access all Type_Specific_Data;
pragma No_Strict_Aliasing (Type_Specific_Data_Ptr);
-- Declarations for the dispatch table record
type Signature_Kind is
(Unknown,
Primary_DT,
Secondary_DT);
-- Tagged type kinds with respect to concurrency and limitedness
type Tagged_Kind is
(TK_Abstract_Limited_Tagged,
TK_Abstract_Tagged,
TK_Limited_Tagged,
TK_Protected,
TK_Tagged,
TK_Task);
type Dispatch_Table_Wrapper (Num_Prims : Natural) is record
Signature : Signature_Kind;
Tag_Kind : Tagged_Kind;
Predef_Prims : System.Address;
-- Pointer to the dispatch table of predefined Ada primitives
-- According to the C++ ABI the components Offset_To_Top and TSD are
-- stored just "before" the dispatch table, and they are referenced with
-- negative offsets referring to the base of the dispatch table. The
-- _Tag (or the VTable_Ptr in C++ terminology) must point to the base
-- of the virtual table, just after these components, to point to the
-- Prims_Ptr table.
Offset_To_Top : SSE.Storage_Offset;
-- Offset between the _Tag field and the field that contains the
-- reference to this dispatch table. For primary dispatch tables it is
-- zero. For secondary dispatch tables: if the parent record type (if
-- any) has a compile-time-known size, then Offset_To_Top contains the
-- expected value, otherwise it contains SSE.Storage_Offset'Last and the
-- actual offset is to be found in the tagged record, right after the
-- field that contains the reference to this dispatch table. See the
-- implementation of Ada.Tags.Offset_To_Top for the corresponding logic.
TSD : System.Address;
Prims_Ptr : aliased Address_Array (1 .. Num_Prims);
-- The size of the Prims_Ptr array actually depends on the tagged type
-- to which it applies. For each tagged type, the expander computes the
-- actual array size, allocating the Dispatch_Table record accordingly.
end record;
type Dispatch_Table_Ptr is access all Dispatch_Table_Wrapper;
pragma No_Strict_Aliasing (Dispatch_Table_Ptr);
-- The following type declaration is used by the compiler when the program
-- is compiled with restriction No_Dispatching_Calls. It is also used with
-- interface types to generate the tag and run-time information associated
-- with them.
type No_Dispatch_Table_Wrapper is record
NDT_TSD : System.Address;
NDT_Prims_Ptr : Natural;
end record;
DT_Predef_Prims_Size : constant SSE.Storage_Count :=
SSE.Storage_Count
(1 * (Standard'Address_Size /
System.Storage_Unit));
-- Size of the Predef_Prims field of the Dispatch_Table
DT_Offset_To_Top_Size : constant SSE.Storage_Count :=
SSE.Storage_Count
(1 * (Standard'Address_Size /
System.Storage_Unit));
-- Size of the Offset_To_Top field of the Dispatch Table
DT_Typeinfo_Ptr_Size : constant SSE.Storage_Count :=
SSE.Storage_Count
(1 * (Standard'Address_Size /
System.Storage_Unit));
-- Size of the Typeinfo_Ptr field of the Dispatch Table
use type System.Storage_Elements.Storage_Offset;
DT_Offset_To_Top_Offset : constant SSE.Storage_Count :=
DT_Typeinfo_Ptr_Size
+ DT_Offset_To_Top_Size;
DT_Predef_Prims_Offset : constant SSE.Storage_Count :=
DT_Typeinfo_Ptr_Size
+ DT_Offset_To_Top_Size
+ DT_Predef_Prims_Size;
-- Offset from Prims_Ptr to Predef_Prims component
-- Object Specific Data record of secondary dispatch tables
type Object_Specific_Data_Array is array (Positive range <>) of Positive;
type Object_Specific_Data (OSD_Num_Prims : Positive) is record
OSD_Table : Object_Specific_Data_Array (1 .. OSD_Num_Prims);
-- Table used in secondary DT to reference their counterpart in the
-- select specific data (in the TSD of the primary DT). This construct
-- is used in the handling of dispatching triggers in select statements.
-- Nb_Prim is the number of non-predefined primitive operations.
end record;
type Object_Specific_Data_Ptr is access all Object_Specific_Data;
pragma No_Strict_Aliasing (Object_Specific_Data_Ptr);
-- The following subprogram specifications are placed here instead of the
-- package body to see them from the frontend through rtsfind.
function Base_Address (This : System.Address) return System.Address;
-- Ada 2005 (AI-251): Displace "This" to point to the base address of the
-- object (that is, the address of the primary tag of the object).
procedure Check_TSD (TSD : Type_Specific_Data_Ptr);
-- Ada 2012 (AI-113): Raise Program_Error if the external tag of this TSD
-- is the same as the external tag for some other tagged type declaration.
function Displace (This : System.Address; T : Tag) return System.Address;
-- Ada 2005 (AI-251): Displace "This" to point to the secondary dispatch
-- table of T.
function Secondary_Tag (T, Iface : Tag) return Tag;
-- Ada 2005 (AI-251): Given a primary tag T associated with a tagged type
-- Typ, search for the secondary tag of the interface type Iface covered
-- by Typ.
function DT (T : Tag) return Dispatch_Table_Ptr;
-- Return the pointer to the TSD record associated with T
function Get_Entry_Index (T : Tag; Position : Positive) return Positive;
-- Ada 2005 (AI-251): Return a primitive operation's entry index (if entry)
-- given a dispatch table T and a position of a primitive operation in T.
function Get_Offset_Index
(T : Tag;
Position : Positive) return Positive;
-- Ada 2005 (AI-251): Given a pointer to a secondary dispatch table (T)
-- and a position of an operation in the DT, retrieve the corresponding
-- operation's position in the primary dispatch table from the Offset
-- Specific Data table of T.
function Get_Prim_Op_Kind
(T : Tag;
Position : Positive) return Prim_Op_Kind;
-- Ada 2005 (AI-251): Return a primitive operation's kind given a dispatch
-- table T and a position of a primitive operation in T.
function Get_Tagged_Kind (T : Tag) return Tagged_Kind;
-- Ada 2005 (AI-345): Given a pointer to either a primary or a secondary
-- dispatch table, return the tagged kind of a type in the context of
-- concurrency and limitedness.
function IW_Membership (This : System.Address; T : Tag) return Boolean;
-- Ada 2005 (AI-251): General routine that checks if a given object
-- implements a tagged type. Its common usage is to check if Obj is in
-- Iface'Class, but it is also used to check if a class-wide interface
-- implements a given type (Iface_CW_Typ in T'Class). For example:
--
-- type I is interface;
-- type T is tagged ...
--
-- function Test (O : I'Class) is
-- begin
-- return O in T'Class.
-- end Test;
function Offset_To_Top
(This : System.Address) return SSE.Storage_Offset;
-- Ada 2005 (AI-251): Returns the current value of the Offset_To_Top
-- component available in the prologue of the dispatch table. If the parent
-- of the tagged type has discriminants this value is stored in a record
-- component just immediately after the tag component.
function Needs_Finalization (T : Tag) return Boolean;
-- A helper routine used in conjunction with finalization collections which
-- service class-wide types. The function dynamically determines whether an
-- object is controlled or has controlled components.
function Parent_Size
(Obj : System.Address;
T : Tag) return SSE.Storage_Count;
-- Computes the size the ancestor part of a tagged extension object whose
-- address is 'obj' by calling indirectly the ancestor _size function. The
-- ancestor is the parent of the type represented by tag T. This function
-- assumes that _size is always in slot one of the dispatch table.
procedure Register_Interface_Offset
(Prim_T : Tag;
Interface_T : Tag;
Is_Static : Boolean;
Offset_Value : SSE.Storage_Offset;
Offset_Func : Offset_To_Top_Function_Ptr);
-- Register in the table of interfaces of the tagged type associated with
-- Prim_T the offset of the record component associated with the progenitor
-- Interface_T (that is, the distance from "This" to the object component
-- containing the tag of the secondary dispatch table). In case of constant
-- offset, Is_Static is true and Offset_Value has such value. In case of
-- variable offset, Is_Static is false and Offset_Func is an access to
-- function that must be called to evaluate the offset.
procedure Register_Tag (T : Tag);
-- Insert the Tag and its associated external_tag in a table for the sake
-- of Internal_Tag.
procedure Set_Dynamic_Offset_To_Top
(This : System.Address;
Prim_T : Tag;
Interface_T : Tag;
Offset_Value : SSE.Storage_Offset;
Offset_Func : Offset_To_Top_Function_Ptr);
-- Ada 2005 (AI-251): The compiler generates calls to this routine only
-- when initializing the Offset_To_Top field of dispatch tables of tagged
-- types that cover interface types whose parent type has variable size
-- components.
--
-- "This" is the object whose dispatch table is being initialized. Prim_T
-- is the primary tag of such object. Interface_T is the interface tag for
-- which the secondary dispatch table is being initialized. Offset_Value
-- is the distance from "This" to the object component containing the tag
-- of the secondary dispatch table (a zero value means that this interface
-- shares the primary dispatch table). Offset_Func references a function
-- that must be called to evaluate the offset at run time. This routine
-- also takes care of registering these values in the table of interfaces
-- of the type.
procedure Set_Entry_Index (T : Tag; Position : Positive; Value : Positive);
-- Ada 2005 (AI-345): Set the entry index of a primitive operation in T's
-- TSD table indexed by Position.
procedure Set_Prim_Op_Kind
(T : Tag;
Position : Positive;
Value : Prim_Op_Kind);
-- Ada 2005 (AI-251): Set the kind of a primitive operation in T's TSD
-- table indexed by Position.
procedure Unregister_Tag (T : Tag);
-- Remove a particular tag from the external tag hash table
Max_Predef_Prims : constant Positive := 16;
-- Number of reserved slots for the following predefined ada primitives:
--
-- 1. Size
-- 2. Read
-- 3. Write
-- 4. Input
-- 5. Output
-- 6. "="
-- 7. assignment
-- 8. deep adjust
-- 9. deep finalize
-- 10. Put_Image
-- 11. async select
-- 12. conditional select
-- 13. prim_op kind
-- 14. task_id
-- 15. dispatching requeue
-- 16. timed select
--
-- The compiler checks that the value here is correct
subtype Predef_Prims_Table is Address_Array (1 .. Max_Predef_Prims);
type Predef_Prims_Table_Ptr is access Predef_Prims_Table;
pragma No_Strict_Aliasing (Predef_Prims_Table_Ptr);
type Addr_Ptr is access System.Address;
pragma No_Strict_Aliasing (Addr_Ptr);
-- This type is used by the frontend to generate the code that handles
-- dispatch table slots of types declared at the local level.
-------------------
-- CW_Membership --
-------------------
function To_Address is
new Ada.Unchecked_Conversion (Tag, System.Address);
function To_Addr_Ptr is
new Ada.Unchecked_Conversion (System.Address, Addr_Ptr);
function To_Type_Specific_Data_Ptr is
new Ada.Unchecked_Conversion (System.Address, Type_Specific_Data_Ptr);
-- Canonical implementation of Classwide Membership corresponding to:
-- Obj in Typ'Class
-- Each dispatch table contains a reference to a table of ancestors (stored
-- in the first part of the Tags_Table) and a count of the level of
-- inheritance "Idepth".
-- Obj is in Typ'Class if Typ'Tag is in the table of ancestors that are
-- contained in the dispatch table referenced by Obj'Tag . Knowing the
-- level of inheritance of both types, this can be computed in constant
-- time by the formula:
-- TSD (Obj'tag).Tags_Table (TSD (Obj'tag).Idepth - TSD (Typ'tag).Idepth)
-- = Typ'tag
function CW_Membership (Obj_Tag : Tag; Typ_Tag : Tag) return Boolean is
(declare
Obj_TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (Obj_Tag) - DT_Typeinfo_Ptr_Size);
Typ_TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (Typ_Tag) - DT_Typeinfo_Ptr_Size);
Obj_TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (Obj_TSD_Ptr.all);
Typ_TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (Typ_TSD_Ptr.all);
Pos : constant Integer := Obj_TSD.Idepth - Typ_TSD.Idepth;
begin
Pos >= 0 and then Obj_TSD.Tags_Table (Pos) = Typ_Tag);
-- Given the tag of an object and the tag associated to a type, return
-- true if Obj is in Typ'Class.
end Ada.Tags;
|
Componolit/libsparkcrypto | Ada | 2,848 | adb | -------------------------------------------------------------------------------
-- This file is part of libsparkcrypto.
--
-- Copyright (C) 2010, Alexander Senier
-- Copyright (C) 2010, secunet Security Networks AG
-- 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 nor the names of its contributors may be used
-- to endorse or promote products derived from this software without
-- specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
-- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------
with LSC.Internal.Debug;
package body LSC.Internal.RIPEMD160.Print
with SPARK_Mode => Off
is
procedure Print_Schedule (M : String;
A : Types.Word32;
B : Types.Word32;
C : Types.Word32;
D : Types.Word32;
E : Types.Word32;
X : Types.Word32;
S : Natural)
is
begin
Debug.Put (M);
Debug.Put (": ");
Debug.Print_Word32 (A);
Debug.Put (" ");
Debug.Print_Word32 (B);
Debug.Put (" ");
Debug.Print_Word32 (C);
Debug.Put (" ");
Debug.Print_Word32 (D);
Debug.Put (" ");
Debug.Print_Word32 (E);
Debug.Put (" ");
Debug.Print_Word32 (X);
Debug.Put (" ");
Debug.Print_Natural (S);
Debug.New_Line;
end Print_Schedule;
end LSC.Internal.RIPEMD160.Print;
|
stcarrez/ada-servlet | Ada | 9,247 | adb | -----------------------------------------------------------------------
-- servlet-sessions -- Servlet Sessions
-- Copyright (C) 2010, 2011, 2018 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
-- The <b>Servlet.Sessions</b> package is an Ada implementation of the
-- Java servlet Specification (See JSR 315 at jcp.org).
package body Servlet.Sessions is
use Ada.Strings.Unbounded;
-- ------------------------------
-- Returns true if the session is valid.
-- ------------------------------
function Is_Valid (Sess : in Session'Class) return Boolean is
begin
return Sess.Impl /= null and then Sess.Impl.Is_Active;
end Is_Valid;
-- ------------------------------
-- Returns a string containing the unique identifier assigned to this session.
-- The identifier is assigned by the servlet container and is implementation dependent.
-- ------------------------------
function Get_Id (Sess : in Session) return String is
begin
if Sess.Impl = null or else not Sess.Impl.Is_Active then
raise No_Session;
else
return Sess.Impl.Id.all;
end if;
end Get_Id;
-- ------------------------------
-- Returns the last time the client sent a request associated with this session,
-- as the number of milliseconds since midnight January 1, 1970 GMT, and marked
-- by the time the container received the request.
--
-- Actions that your application takes, such as getting or setting a value associated
-- with the session, do not affect the access time.
-- ------------------------------
function Get_Last_Accessed_Time (Sess : in Session) return Ada.Calendar.Time is
begin
if Sess.Impl = null or else not Sess.Impl.Is_Active then
raise No_Session;
else
return Sess.Impl.Access_Time;
end if;
end Get_Last_Accessed_Time;
-- ------------------------------
-- Returns the maximum time interval, in seconds, that the servlet container will
-- keep this session open between client accesses. After this interval, the servlet
-- container will invalidate the session. The maximum time interval can be set with
-- the Set_Max_Inactive_Interval method.
-- A negative time indicates the session should never timeout.
-- ------------------------------
function Get_Max_Inactive_Interval (Sess : in Session) return Duration is
begin
if Sess.Impl = null or else not Sess.Impl.Is_Active then
raise No_Session;
else
return Sess.Impl.Max_Inactive;
end if;
end Get_Max_Inactive_Interval;
-- ------------------------------
-- Specifies the time, in seconds, between client requests before the servlet
-- container will invalidate this session. A negative time indicates the session
-- should never timeout.
-- ------------------------------
procedure Set_Max_Inactive_Interval (Sess : in Session;
Interval : in Duration) is
begin
if Sess.Impl = null or else not Sess.Impl.Is_Active then
raise No_Session;
else
Sess.Impl.Max_Inactive := Interval;
end if;
end Set_Max_Inactive_Interval;
-- ------------------------------
-- Returns the object bound with the specified name in this session,
-- or null if no object is bound under the name.
-- ------------------------------
function Get_Attribute (Sess : in Session;
Name : in String) return EL.Objects.Object is
begin
if Sess.Impl = null or else not Sess.Impl.Is_Active then
raise No_Session;
end if;
Sess.Impl.Lock.Read;
declare
Pos : constant EL.Objects.Maps.Cursor := Sess.Impl.Attributes.Find (Name);
begin
if EL.Objects.Maps.Has_Element (Pos) then
return Value : constant EL.Objects.Object := EL.Objects.Maps.Element (Pos) do
Sess.Impl.Lock.Release_Read;
end return;
end if;
exception
when others =>
Sess.Impl.Lock.Release_Read;
raise;
end;
Sess.Impl.Lock.Release_Read;
return EL.Objects.Null_Object;
end Get_Attribute;
-- ------------------------------
-- Binds an object to this session, using the name specified.
-- If an object of the same name is already bound to the session,
-- the object is replaced.
--
-- If the value passed in is null, this has the same effect as calling
-- removeAttribute().
-- ------------------------------
procedure Set_Attribute (Sess : in out Session;
Name : in String;
Value : in EL.Objects.Object) is
begin
if Sess.Impl = null or else not Sess.Impl.Is_Active then
raise No_Session;
end if;
begin
Sess.Impl.Lock.Write;
if EL.Objects.Is_Null (Value) then
-- Do not complain if there is no attribute with the given name.
if Sess.Impl.Attributes.Contains (Name) then
Sess.Impl.Attributes.Delete (Name);
end if;
else
Sess.Impl.Attributes.Include (Name, Value);
end if;
exception
when others =>
Sess.Impl.Lock.Release_Write;
raise;
end;
Sess.Impl.Lock.Release_Write;
end Set_Attribute;
-- ------------------------------
-- Removes the object bound with the specified name from this session.
-- If the session does not have an object bound with the specified name,
-- this method does nothing.
-- ------------------------------
procedure Remove_Attribute (Sess : in out Session;
Name : in String) is
begin
Set_Attribute (Sess, Name, EL.Objects.Null_Object);
end Remove_Attribute;
-- ------------------------------
-- Gets the principal that authenticated to the session.
-- Returns null if there is no principal authenticated.
-- ------------------------------
function Get_Principal (Sess : in Session) return Servlet.Principals.Principal_Access is
begin
if Sess.Impl = null or else not Sess.Impl.Is_Active then
raise No_Session;
end if;
return Sess.Impl.Principal;
end Get_Principal;
-- ------------------------------
-- Sets the principal associated with the session.
-- ------------------------------
procedure Set_Principal (Sess : in out Session;
Principal : in Servlet.Principals.Principal_Access) is
begin
if Sess.Impl = null or else not Sess.Impl.Is_Active then
raise No_Session;
end if;
Sess.Impl.Principal := Principal;
end Set_Principal;
-- ------------------------------
-- Invalidates this session then unbinds any objects bound to it.
-- ------------------------------
procedure Invalidate (Sess : in out Session) is
begin
if Sess.Impl /= null then
Sess.Impl.Is_Active := False;
Finalize (Sess);
end if;
end Invalidate;
-- ------------------------------
-- Adjust (increment) the session record reference counter.
-- ------------------------------
overriding
procedure Adjust (Object : in out Session) is
begin
if Object.Impl /= null then
Util.Concurrent.Counters.Increment (Object.Impl.Ref_Counter);
end if;
end Adjust;
procedure Free is
new Ada.Unchecked_Deallocation (Object => Session_Record'Class,
Name => Session_Record_Access);
procedure Free is
new Ada.Unchecked_Deallocation (Object => Servlet.Principals.Principal'Class,
Name => Servlet.Principals.Principal_Access);
-- ------------------------------
-- Decrement the session record reference counter and free the session record
-- if this was the last session reference.
-- ------------------------------
overriding
procedure Finalize (Object : in out Session) is
Release : Boolean;
begin
if Object.Impl /= null then
Util.Concurrent.Counters.Decrement (Object.Impl.Ref_Counter, Release);
if Release then
Free (Object.Impl.Principal);
Free (Object.Impl);
else
Object.Impl := null;
end if;
end if;
end Finalize;
overriding
procedure Finalize (Object : in out Session_Record) is
begin
Free (Object.Id);
end Finalize;
end Servlet.Sessions;
|
AdaCore/libadalang | Ada | 1,708 | ads | package Valid is
-----------------------------------
-- Binary operations on integers --
-----------------------------------
Int_Add : constant := 2 + 3;
--% node.f_expr.p_eval_as_int
Int_Sub : constant := 2 - 3;
--% node.f_expr.p_eval_as_int
Int_Mul : constant := 2 * 3;
--% node.f_expr.p_eval_as_int
Int_Div : constant := 2 / 3;
--% node.f_expr.p_eval_as_int
Int_Pow : constant := 2 ** 3;
--% node.f_expr.p_eval_as_int
-- TODO: add tests for binops on reals once P_Eval_As_Real is exposed in
-- the public API.
--------------------------------
-- Binary operations on bools --
--------------------------------
Bool_And_Then_1 : constant Boolean := True and then True;
--% node.f_default_expr.p_eval_as_int
Bool_And_Then_2 : constant Boolean := True and then False;
--% node.f_default_expr.p_eval_as_int
Bool_And_Then_3 : constant Boolean := False and then False;
--% node.f_default_expr.p_eval_as_int
Bool_And_Then_4 : constant Boolean := False and then True;
--% node.f_default_expr.p_eval_as_int
Bool_And_Then_5 : constant Boolean := True and False;
--% node.f_default_expr.p_eval_as_int
Bool_Or_Else_1 : constant Boolean := True or else True;
--% node.f_default_expr.p_eval_as_int
Bool_Or_Else_2 : constant Boolean := True or else False;
--% node.f_default_expr.p_eval_as_int
Bool_Or_Else_3 : constant Boolean := False or else False;
--% node.f_default_expr.p_eval_as_int
Bool_Or_Else_4 : constant Boolean := False or else True;
--% node.f_default_expr.p_eval_as_int
Bool_Or_Else_5 : constant Boolean := False or True;
--% node.f_default_expr.p_eval_as_int
end Valid;
|
annexi-strayline/AURA | Ada | 4,117 | ads | ------------------------------------------------------------------------------
-- --
-- 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 generation of a stable hash from a collection
-- of streams that can be hashed in an arbitrary order, but will always
-- result in the same hash regardless
with Ada.Streams;
private with Modular_Hashing.SHA1;
package Stream_Hashing is
type Hash_Type is tagged private;
-- The actual hash type
function "<" (Left, Right: Hash_Type) return Boolean;
not overriding
function To_String (H: Hash_Type) return String;
not overriding
function Digest_Stream
(Stream: not null access Ada.Streams.Root_Stream_Type'Class)
return Hash_Type;
-- Digests the stream until it ends, generating an associated hash value.
private
type Hash_Type is new Modular_Hashing.SHA1.SHA1_Hash with null record;
end Stream_Hashing;
|
stcarrez/ada-asf | Ada | 2,374 | ads | -----------------------------------------------------------------------
-- components-utils-scripts -- Javascript queue
-- Copyright (C) 2011, 2012, 2015 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 ASF.Contexts.Faces;
with ASF.Contexts.Writer;
with ASF.Components.Utils.Escapes;
package ASF.Components.Utils.Scripts is
-- ------------------------------
-- UIScript
-- ------------------------------
-- The <b>UIScript</b> component allows to write Javascript code in the javascript
-- queue in order to collect all the Javascript code of a page in a well defined order
-- and in a single place. The javascript code is queued and will be flushed either
-- by the <b>UIFlush</b> component or before flushing the response.
type UIScript is new ASF.Components.Utils.Escapes.UIEscape with private;
-- Write the content that was collected by rendering the inner children.
-- Write the content in the Javascript queue.
overriding
procedure Write_Content (UI : in UIScript;
Writer : in out Contexts.Writer.Response_Writer'Class;
Content : in String;
Context : in out ASF.Contexts.Faces.Faces_Context'Class);
-- If the component provides a src attribute, render the <script src='xxx'></script>
-- tag with an optional async attribute.
overriding
procedure Encode_Begin (UI : in UIScript;
Context : in out ASF.Contexts.Faces.Faces_Context'Class);
private
type UIScript is new ASF.Components.Utils.Escapes.UIEscape with null record;
end ASF.Components.Utils.Scripts;
|
iyan22/AprendeAda | Ada | 170 | adb | with datos; use datos;
procedure actualizar (
L : in out Lista;
i : in Integer;
Cantidad : in Integer ) is
begin
end actualizar;
|
reznikmm/matreshka | Ada | 3,714 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- 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 XML.DOM.Attributes;
package ODF.DOM.Meta_Page_Count_Attributes is
pragma Preelaborate;
type ODF_Meta_Page_Count_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Meta_Page_Count_Attribute_Access is
access all ODF_Meta_Page_Count_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Meta_Page_Count_Attributes;
|
damaki/libkeccak | Ada | 2,059 | ads | -------------------------------------------------------------------------------
-- 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.
-------------------------------------------------------------------------------
with Keccak.Generic_Hash;
generic
with package Hash is new Keccak.Generic_Hash (<>);
package Hash_Runner is
procedure Run_Tests (File_Name : in String;
Align_Bits : in Boolean;
Num_Passed : out Natural;
Num_Failed : out Natural);
end Hash_Runner;
|
AdaCore/Ada_Drivers_Library | Ada | 1,782 | ads | -- This spec has been automatically generated from cm0.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
-- Data Watchpoint Trace
package Cortex_M_SVD.DWT is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype CTRL_Reserved_0_27_Field is HAL.UInt28;
subtype CTRL_NUMCOMP_Field is HAL.UInt4;
-- Control Register
type CTRL_Register is record
-- Read-only. Reserved bits 0..27
Reserved_0_27 : CTRL_Reserved_0_27_Field := 16#0#;
-- Number of comparators available
NUMCOMP : CTRL_NUMCOMP_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CTRL_Register use record
Reserved_0_27 at 0 range 0 .. 27;
NUMCOMP at 0 range 28 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Data Watchpoint Trace
type DWT_Peripheral is record
-- Control Register
CTRL : aliased CTRL_Register;
-- Program Counter Sample Register
PCSR : aliased HAL.UInt32;
-- Comparator Register 0
COMP0 : aliased HAL.UInt32;
-- Mask Register 0
MASK0 : aliased HAL.UInt32;
-- Function Register 0
FUNCTION0 : aliased HAL.UInt32;
end record
with Volatile;
for DWT_Peripheral use record
CTRL at 16#0# range 0 .. 31;
PCSR at 16#1C# range 0 .. 31;
COMP0 at 16#20# range 0 .. 31;
MASK0 at 16#24# range 0 .. 31;
FUNCTION0 at 16#28# range 0 .. 31;
end record;
-- Data Watchpoint Trace
DWT_Periph : aliased DWT_Peripheral
with Import, Address => DWT_Base;
end Cortex_M_SVD.DWT;
|
ekoeppen/STM32_Generic_Ada_Drivers | Ada | 2,738 | ads | pragma Style_Checks (Off);
-- This spec has been automatically generated from STM32L0x3.svd
pragma Restrictions (No_Elaboration_Code);
with System;
package STM32_SVD.CRC is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype IDR_IDR_Field is STM32_SVD.Byte;
-- Independent data register
type IDR_Register is record
-- General-purpose 8-bit data register bits
IDR : IDR_IDR_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for IDR_Register use record
IDR at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype CR_RESET_Field is STM32_SVD.Bit;
subtype CR_POLYSIZE_Field is STM32_SVD.UInt2;
subtype CR_REV_IN_Field is STM32_SVD.UInt2;
subtype CR_REV_OUT_Field is STM32_SVD.Bit;
-- Control register
type CR_Register is record
-- Write-only. RESET bit
RESET : CR_RESET_Field := 16#0#;
-- unspecified
Reserved_1_2 : STM32_SVD.UInt2 := 16#0#;
-- Polynomial size
POLYSIZE : CR_POLYSIZE_Field := 16#0#;
-- Reverse input data
REV_IN : CR_REV_IN_Field := 16#0#;
-- Reverse output data
REV_OUT : CR_REV_OUT_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CR_Register use record
RESET at 0 range 0 .. 0;
Reserved_1_2 at 0 range 1 .. 2;
POLYSIZE at 0 range 3 .. 4;
REV_IN at 0 range 5 .. 6;
REV_OUT at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Cyclic redundancy check calculation unit
type CRC_Peripheral is record
-- Data register
DR : aliased STM32_SVD.UInt32;
-- Independent data register
IDR : aliased IDR_Register;
-- Control register
CR : aliased CR_Register;
-- Initial CRC value
INIT : aliased STM32_SVD.UInt32;
-- polynomial
POL : aliased STM32_SVD.UInt32;
end record
with Volatile;
for CRC_Peripheral use record
DR at 16#0# range 0 .. 31;
IDR at 16#4# range 0 .. 31;
CR at 16#8# range 0 .. 31;
INIT at 16#10# range 0 .. 31;
POL at 16#14# range 0 .. 31;
end record;
-- Cyclic redundancy check calculation unit
CRC_Periph : aliased CRC_Peripheral
with Import, Address => CRC_Base;
end STM32_SVD.CRC;
|
albertklee/SPARKZumo | Ada | 591 | ads | pragma SPARK_Mode;
with Types; use Types;
with Zumo_LSM303;
with Zumo_L3gd20h;
package Zumo_Motion is
Initd : Boolean := False;
procedure Init
with Global => (In_Out => (Initd,
Zumo_LSM303.Initd,
Zumo_L3gd20h.Initd)),
Pre => not Initd
and then not Zumo_LSM303.Initd
and then not Zumo_L3gd20h.Initd,
Post => Initd
and then Zumo_LSM303.Initd
and then Zumo_L3gd20h.Initd;
function Get_Heading return Degrees
with Pre => Initd and Zumo_LSM303.Initd;
end Zumo_Motion;
|
reznikmm/matreshka | Ada | 6,821 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Style.Columns_Elements is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Style_Columns_Element_Node is
begin
return Self : Style_Columns_Element_Node do
Matreshka.ODF_Style.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Style_Prefix);
end return;
end Create;
----------------
-- Enter_Node --
----------------
overriding procedure Enter_Node
(Self : not null access Style_Columns_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Enter_Style_Columns
(ODF.DOM.Style_Columns_Elements.ODF_Style_Columns_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Enter_Node (Visitor, Control);
end if;
end Enter_Node;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Style_Columns_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Columns_Element;
end Get_Local_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Style_Columns_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Leave_Style_Columns
(ODF.DOM.Style_Columns_Elements.ODF_Style_Columns_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Leave_Node (Visitor, Control);
end if;
end Leave_Node;
----------------
-- Visit_Node --
----------------
overriding procedure Visit_Node
(Self : not null access Style_Columns_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then
ODF.DOM.Iterators.Abstract_ODF_Iterator'Class
(Iterator).Visit_Style_Columns
(Visitor,
ODF.DOM.Style_Columns_Elements.ODF_Style_Columns_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Visit_Node (Iterator, Visitor, Control);
end if;
end Visit_Node;
begin
Matreshka.DOM_Documents.Register_Element
(Matreshka.ODF_String_Constants.Style_URI,
Matreshka.ODF_String_Constants.Columns_Element,
Style_Columns_Element_Node'Tag);
end Matreshka.ODF_Style.Columns_Elements;
|
reznikmm/matreshka | Ada | 4,631 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Draw.Corner_Radius_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Draw_Corner_Radius_Attribute_Node is
begin
return Self : Draw_Corner_Radius_Attribute_Node do
Matreshka.ODF_Draw.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Draw_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Draw_Corner_Radius_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Corner_Radius_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Draw_URI,
Matreshka.ODF_String_Constants.Corner_Radius_Attribute,
Draw_Corner_Radius_Attribute_Node'Tag);
end Matreshka.ODF_Draw.Corner_Radius_Attributes;
|
Fabien-Chouteau/samd51-hal | Ada | 3,635 | ads | -- Generated by a script from an "avr tools device file" (atdf)
package SAM.Clock_Generator.IDs is
TRACE : constant Peripheral_Id := 47;
AC : constant Peripheral_Id := 32;
ADC0 : constant Peripheral_Id := 40;
ADC1 : constant Peripheral_Id := 41;
CCL : constant Peripheral_Id := 33;
DAC : constant Peripheral_Id := 42;
EIC : constant Peripheral_Id := 4;
EVSYS_0 : constant Peripheral_Id := 11;
EVSYS_1 : constant Peripheral_Id := 12;
EVSYS_2 : constant Peripheral_Id := 13;
EVSYS_3 : constant Peripheral_Id := 14;
EVSYS_4 : constant Peripheral_Id := 15;
EVSYS_5 : constant Peripheral_Id := 16;
EVSYS_6 : constant Peripheral_Id := 17;
EVSYS_7 : constant Peripheral_Id := 18;
EVSYS_8 : constant Peripheral_Id := 19;
EVSYS_9 : constant Peripheral_Id := 20;
EVSYS_10 : constant Peripheral_Id := 21;
EVSYS_11 : constant Peripheral_Id := 22;
FREQM_MSR : constant Peripheral_Id := 5;
FREQM_REF : constant Peripheral_Id := 6;
I2S_0 : constant Peripheral_Id := 43;
I2S_1 : constant Peripheral_Id := 44;
OSCCTRL_DFLL48 : constant Peripheral_Id := 0;
OSCCTRL_FDPLL0 : constant Peripheral_Id := 1;
OSCCTRL_FDPLL1 : constant Peripheral_Id := 2;
OSCCTRL_FDPLL032K : constant Peripheral_Id := 3;
OSCCTRL_FDPLL132K : constant Peripheral_Id := 3;
PDEC : constant Peripheral_Id := 31;
SDHC0 : constant Peripheral_Id := 45;
SDHC0_SLOW : constant Peripheral_Id := 3;
SDHC1 : constant Peripheral_Id := 46;
SDHC1_SLOW : constant Peripheral_Id := 3;
SERCOM0_CORE : constant Peripheral_Id := 7;
SERCOM0_SLOW : constant Peripheral_Id := 3;
SERCOM1_CORE : constant Peripheral_Id := 8;
SERCOM1_SLOW : constant Peripheral_Id := 3;
SERCOM2_CORE : constant Peripheral_Id := 23;
SERCOM2_SLOW : constant Peripheral_Id := 3;
SERCOM3_CORE : constant Peripheral_Id := 24;
SERCOM3_SLOW : constant Peripheral_Id := 3;
SERCOM4_CORE : constant Peripheral_Id := 34;
SERCOM4_SLOW : constant Peripheral_Id := 3;
SERCOM5_CORE : constant Peripheral_Id := 35;
SERCOM5_SLOW : constant Peripheral_Id := 3;
SERCOM6_CORE : constant Peripheral_Id := 36;
SERCOM6_SLOW : constant Peripheral_Id := 3;
SERCOM7_CORE : constant Peripheral_Id := 37;
SERCOM7_SLOW : constant Peripheral_Id := 3;
TC0 : constant Peripheral_Id := 9;
TC1 : constant Peripheral_Id := 9;
TC2 : constant Peripheral_Id := 26;
TC3 : constant Peripheral_Id := 26;
TC4 : constant Peripheral_Id := 30;
TC5 : constant Peripheral_Id := 30;
TC6 : constant Peripheral_Id := 39;
TC7 : constant Peripheral_Id := 39;
TCC0 : constant Peripheral_Id := 25;
TCC1 : constant Peripheral_Id := 25;
TCC2 : constant Peripheral_Id := 29;
TCC3 : constant Peripheral_Id := 29;
TCC4 : constant Peripheral_Id := 38;
USB : constant Peripheral_Id := 10;
end SAM.Clock_Generator.IDs;
|
reznikmm/matreshka | Ada | 4,998 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Generic_Collections;
package AMF.UMLDI.UML_Labels.Collections is
pragma Preelaborate;
package UMLDI_UML_Label_Collections is
new AMF.Generic_Collections
(UMLDI_UML_Label,
UMLDI_UML_Label_Access);
type Set_Of_UMLDI_UML_Label is
new UMLDI_UML_Label_Collections.Set with null record;
Empty_Set_Of_UMLDI_UML_Label : constant Set_Of_UMLDI_UML_Label;
type Ordered_Set_Of_UMLDI_UML_Label is
new UMLDI_UML_Label_Collections.Ordered_Set with null record;
Empty_Ordered_Set_Of_UMLDI_UML_Label : constant Ordered_Set_Of_UMLDI_UML_Label;
type Bag_Of_UMLDI_UML_Label is
new UMLDI_UML_Label_Collections.Bag with null record;
Empty_Bag_Of_UMLDI_UML_Label : constant Bag_Of_UMLDI_UML_Label;
type Sequence_Of_UMLDI_UML_Label is
new UMLDI_UML_Label_Collections.Sequence with null record;
Empty_Sequence_Of_UMLDI_UML_Label : constant Sequence_Of_UMLDI_UML_Label;
private
Empty_Set_Of_UMLDI_UML_Label : constant Set_Of_UMLDI_UML_Label
:= (UMLDI_UML_Label_Collections.Set with null record);
Empty_Ordered_Set_Of_UMLDI_UML_Label : constant Ordered_Set_Of_UMLDI_UML_Label
:= (UMLDI_UML_Label_Collections.Ordered_Set with null record);
Empty_Bag_Of_UMLDI_UML_Label : constant Bag_Of_UMLDI_UML_Label
:= (UMLDI_UML_Label_Collections.Bag with null record);
Empty_Sequence_Of_UMLDI_UML_Label : constant Sequence_Of_UMLDI_UML_Label
:= (UMLDI_UML_Label_Collections.Sequence with null record);
end AMF.UMLDI.UML_Labels.Collections;
|
reznikmm/matreshka | Ada | 3,784 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- 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 XML.DOM.Attributes;
package ODF.DOM.Number_Transliteration_Format_Attributes is
pragma Preelaborate;
type ODF_Number_Transliteration_Format_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Number_Transliteration_Format_Attribute_Access is
access all ODF_Number_Transliteration_Format_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Number_Transliteration_Format_Attributes;
|
optikos/ada-lsp | Ada | 4,091 | ads | -- Copyright (c) 2017 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
private package LSP.Servers.Handlers is
pragma Preelaborate;
procedure DidChangeConfiguration
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Notification_Handler_Access);
procedure DidOpenTextDocument
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Notification_Handler_Access);
procedure DidCloseTextDocument
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Notification_Handler_Access);
procedure DidChangeTextDocument
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Notification_Handler_Access);
procedure DidSaveTextDocument
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Notification_Handler_Access);
function Do_Code_Action
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_Completion
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_Definition
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_Document_Symbol
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_Execute_Command
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
procedure Do_Exit
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Notification_Handler_Access);
function Do_Highlight
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_Hover
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_Not_Found
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_Initialize
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_References
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_Shutdown
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_Signature_Help
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
function Do_Workspace_Symbol
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Request_Handler_Access)
return LSP.Messages.ResponseMessage'Class;
procedure Ignore_Notification
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Handler : not null LSP.Message_Handlers.Notification_Handler_Access);
end LSP.Servers.Handlers;
|
AdaCore/langkit | Ada | 197 | ads | with Libfoolang.Implementation; use Libfoolang.Implementation;
private package Libfoolang.Helpers is
function Create_Unit_Provider return Internal_Unit_Provider_Access;
end Libfoolang.Helpers;
|
flyx/OpenGLAda | Ada | 19,977 | ads | -- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with GL.Types;
private with GL.Low_Level;
package GL.Pixels is
pragma Preelaborate;
use GL.Types;
type Internal_Format is (Depth_Component, Red, Alpha, RGB, RGBA, Luminance,
Luminance_Alpha, R3_G3_B2, Alpha4, Alpha8, Alpha12,
Alpha16, Luminance4, Luminance8, Luminance12,
Luminance16, Luminance4_Alpha4, Luminance6_Alpha2,
Luminance8_Alpha8, Luminance12_Alpha4,
Luminance12_Alpha12, Luminance16_Alpha16,
Intensity, Intensity4, Intensity8, Intensity12,
Intensity16, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16,
RGBA2, RGBA4, RGB5_A1, RGBA8, RGB10_A2, RGBA12,
RGBA16, Depth_Component16, Depth_Component24,
Depth_Component32, Compressed_Red, Compressed_RG,
RG, R8, R16, RG8, RG16, R16F, R32F, RG16F, RG32F,
R8I, R8UI, R16I, R16UI, R32I, R32UI, RG8I, RG8UI,
RG16I, RG16UI, RG32I, RG32UI,
Compressed_RGB_S3TC_DXT1, Compressed_RGBA_S3TC_DXT1,
Compressed_RGBA_S3TC_DXT3,
Compressed_RGBA_S3TC_DXT5, Compressed_Alpha,
Compressed_Luminance, Compressed_Luminance_Alpha,
Compressed_Intensity, Compressed_RGB,
Compressed_RGBA, RGBA32F, RGB32F, RGBA16F, RGB16F,
Depth24_Stencil8,
R11F_G11F_B10F, RGB9_E5, SRGB, SRGB8, SRGB_Alpha,
SRGB8_Alpha8, SLuminance_Alpha, SLuminance8_Alpha8,
SLuminance, SLuminance8, Compressed_SRGB,
Compressed_SRGB_Alpha, Compressed_SRGB_S3TC_DXT1,
Compressed_SRGB_Alpha_S3TC_DXT1,
Compressed_SRGB_Alpha_S3TC_DXT3,
Compressed_SRGB_Alpha_S3TC_DXT5,
RGBA32UI, RGB32UI, RGBA16UI, RGB16UI, RGBA8UI,
RGB8UI, RGBA32I, RGB32I, RGBA16I, RGB16I, RGBA8I,
RGB8I, Compressed_Red_RGTC1,
Compressed_Signed_Red_RGTC1, Compressed_RG_RGTC2,
Compressed_Signed_RG_RGTC2,
Compressed_RGBA_BPTC_Unorm,
Compressed_SRGB_Alpha_BPTC_UNorm,
Compressed_RGB_BPTC_Signed_Float,
Compressed_RGB_BPTC_Unsigned_Float, R8_SNorm,
RG8_SNorm, RGB8_SNorm, RGBA8_SNorm, R16_SNorm,
RG16_SNorm, RGB16_SNorm, RGBA16_SNorm, RGB10_A2UI,
Compressed_RGBA_ASTC_4x4, Compressed_RGBA_ASTC_5x4,
Compressed_RGBA_ASTC_5x5, Compressed_RGBA_ASTC_6x5,
Compressed_RGBA_ASTC_6x6, Compressed_RGBA_ASTC_8x5,
Compressed_RGBA_ASTC_8x6, Compressed_RGBA_ASTC_8x8,
Compressed_RGBA_ASTC_10x5,
Compressed_RGBA_ASTC_10x6,
Compressed_RGBA_ASTC_10x8,
Compressed_RGBA_ASTC_10x10,
Compressed_RGBA_ASTC_12x10,
Compressed_RGBA_ASTC_12x12,
Compressed_SRGB8_Alpha8_ASTC_4x4,
Compressed_SRGB8_Alpha8_ASTC_5x4,
Compressed_SRGB8_Alpha8_ASTC_5x5,
Compressed_SRGB8_Alpha8_ASTC_6x5,
Compressed_SRGB8_Alpha8_ASTC_6x6,
Compressed_SRGB8_Alpha8_ASTC_8x5,
Compressed_SRGB8_Alpha8_ASTC_8x6,
Compressed_SRGB8_Alpha8_ASTC_8x8,
Compressed_SRGB8_Alpha8_ASTC_10x5,
Compressed_SRGB8_Alpha8_ASTC_10x6,
Compressed_SRGB8_Alpha8_ASTC_10x8,
Compressed_SRGB8_Alpha8_ASTC_10x10,
Compressed_SRGB8_Alpha8_ASTC_12x10,
Compressed_SRGB8_Alpha8_ASTC_12x12);
type Framebuffer_Format is (Color_Index, Red, Green, Blue, Alpha, RGB, RGBA,
Luminance, Luminance_Alpha, BGR, BGRA);
type Data_Format is (Stencil_Index, Depth_Component, Red,
RGB, RGBA, BGR, BGRA, RG, RG_Integer, Depth_Stencil,
Red_Integer, RGB_Integer, RGBA_Integer, BGR_Integer,
BGRA_Integer);
type Data_Type is (Byte, Unsigned_Byte, Short, Unsigned_Short, Int,
Unsigned_Int, Float, Bitmap, Unsigned_Byte_3_3_2,
Unsigned_Short_4_4_4_4,
Unsigned_Short_5_5_5_1,
Unsigned_Int_8_8_8_8,
Unsigned_Int_10_10_10_2,
Unsigned_Byte_2_3_3_Rev,
Unsigned_Short_5_6_5,
Unsinged_Short_5_6_5_Rev,
Unsigned_Short_4_4_4_4_Rev,
Unsigned_Short_1_5_5_5_Rev,
Unsigned_Int_8_8_8_8_Rev,
Unsigned_Int_2_10_10_10_Rev);
type Channel_Data_Type is (None, Int_Type, Unsigned_Int_Type, Float_Type,
Unsigned_Normalized, Signed_Normalized);
type Alignment is (Bytes, Even_Bytes, Words, Double_Words);
procedure Set_Pack_Swap_Bytes (Value : Boolean);
procedure Set_Pack_LSB_First (Value : Boolean);
procedure Set_Pack_Row_Length (Value : Size);
procedure Set_Pack_Image_Height (Value : Size);
procedure Set_Pack_Skip_Pixels (Value : Size);
procedure Set_Pack_Skip_Rows (Value : Size);
procedure Set_Pack_Skip_Images (Value : Size);
procedure Set_Pack_Alignment (Value : Alignment);
function Pack_Swap_Bytes return Boolean;
function Pack_LSB_First return Boolean;
function Pack_Row_Length return Size;
function Pack_Image_Height return Size;
function Pack_Skip_Pixels return Size;
function Pack_Skip_Rows return Size;
function Pack_Skip_Images return Size;
function Pack_Alignment return Alignment;
procedure Set_Unpack_Swap_Bytes (Value : Boolean);
procedure Set_Unpack_LSB_First (Value : Boolean);
procedure Set_Unpack_Row_Length (Value : Size);
procedure Set_Unpack_Image_Height (Value : Size);
procedure Set_Unpack_Skip_Pixels (Value : Size);
procedure Set_Unpack_Skip_Rows (Value : Size);
procedure Set_Unpack_Skip_Images (Value : Size);
procedure Set_Unpack_Alignment (Value : Alignment);
function Unpack_Swap_Bytes return Boolean;
function Unpack_LSB_First return Boolean;
function Unpack_Row_Length return Size;
function Unpack_Image_Height return Size;
function Unpack_Skip_Pixels return Size;
function Unpack_Skip_Rows return Size;
function Unpack_Skip_Images return Size;
function Unpack_Alignment return Alignment;
private
for Internal_Format use (Depth_Component => 16#1902#,
Red => 16#1903#,
Alpha => 16#1906#,
RGB => 16#1907#,
RGBA => 16#1908#,
Luminance => 16#1909#,
Luminance_Alpha => 16#190A#,
R3_G3_B2 => 16#2A10#,
Alpha4 => 16#803B#,
Alpha8 => 16#803C#,
Alpha12 => 16#803D#,
Alpha16 => 16#803E#,
Luminance4 => 16#803F#,
Luminance8 => 16#8040#,
Luminance12 => 16#8041#,
Luminance16 => 16#8042#,
Luminance4_Alpha4 => 16#8043#,
Luminance6_Alpha2 => 16#8044#,
Luminance8_Alpha8 => 16#8045#,
Luminance12_Alpha4 => 16#8046#,
Luminance12_Alpha12 => 16#8047#,
Luminance16_Alpha16 => 16#8048#,
Intensity => 16#8049#,
Intensity4 => 16#804A#,
Intensity8 => 16#804B#,
Intensity12 => 16#804C#,
Intensity16 => 16#804D#,
RGB4 => 16#804F#,
RGB5 => 16#8050#,
RGB8 => 16#8051#,
RGB10 => 16#8052#,
RGB12 => 16#8053#,
RGB16 => 16#8054#,
RGBA2 => 16#8055#,
RGBA4 => 16#8056#,
RGB5_A1 => 16#8057#,
RGBA8 => 16#8058#,
RGB10_A2 => 16#8059#,
RGBA12 => 16#805A#,
RGBA16 => 16#805B#,
Depth_Component16 => 16#81A5#,
Depth_Component24 => 16#81A6#,
Depth_Component32 => 16#81A7#,
Compressed_Red => 16#8225#,
Compressed_RG => 16#8226#,
RG => 16#8227#,
R8 => 16#8229#,
R16 => 16#822A#,
RG8 => 16#822B#,
RG16 => 16#822C#,
R16F => 16#822D#,
R32F => 16#822E#,
RG16F => 16#822F#,
RG32F => 16#8230#,
R8I => 16#8231#,
R8UI => 16#8232#,
R16I => 16#8233#,
R16UI => 16#8234#,
R32I => 16#8235#,
R32UI => 16#8236#,
RG8I => 16#8237#,
RG8UI => 16#8238#,
RG16I => 16#8239#,
RG16UI => 16#823A#,
RG32I => 16#823B#,
RG32UI => 16#823C#,
Compressed_RGB_S3TC_DXT1 => 16#83F0#,
Compressed_RGBA_S3TC_DXT1 => 16#83F1#,
Compressed_RGBA_S3TC_DXT3 => 16#83F2#,
Compressed_RGBA_S3TC_DXT5 => 16#83F3#,
Compressed_Alpha => 16#84E9#,
Compressed_Luminance => 16#84EA#,
Compressed_Luminance_Alpha => 16#84EB#,
Compressed_Intensity => 16#84EC#,
Compressed_RGB => 16#84ED#,
Compressed_RGBA => 16#84EE#,
RGBA32F => 16#8814#,
RGB32F => 16#8815#,
RGBA16F => 16#881A#,
RGB16F => 16#881B#,
Depth24_Stencil8 => 16#88F0#,
R11F_G11F_B10F => 16#8C3A#,
RGB9_E5 => 16#8C3D#,
SRGB => 16#8C40#,
SRGB8 => 16#8C41#,
SRGB_Alpha => 16#8C42#,
SRGB8_Alpha8 => 16#8C43#,
SLuminance_Alpha => 16#8C44#,
SLuminance8_Alpha8 => 16#8C45#,
SLuminance => 16#8C46#,
SLuminance8 => 16#8C47#,
Compressed_SRGB => 16#8C48#,
Compressed_SRGB_Alpha => 16#8C49#,
Compressed_SRGB_S3TC_DXT1 => 16#8C4C#,
Compressed_SRGB_Alpha_S3TC_DXT1 => 16#8C4D#,
Compressed_SRGB_Alpha_S3TC_DXT3 => 16#8C4E#,
Compressed_SRGB_Alpha_S3TC_DXT5 => 16#8C4F#,
RGBA32UI => 16#8D70#,
RGB32UI => 16#8D71#,
RGBA16UI => 16#8D76#,
RGB16UI => 16#8D77#,
RGBA8UI => 16#8D7C#,
RGB8UI => 16#8D7D#,
RGBA32I => 16#8D82#,
RGB32I => 16#8D83#,
RGBA16I => 16#8D88#,
RGB16I => 16#8D89#,
RGBA8I => 16#8D8E#,
RGB8I => 16#8D8F#,
Compressed_Red_RGTC1 => 16#8DBB#,
Compressed_Signed_Red_RGTC1 => 16#8DBC#,
Compressed_RG_RGTC2 => 16#8DBD#,
Compressed_Signed_RG_RGTC2 => 16#8DBE#,
Compressed_RGBA_BPTC_Unorm => 16#8E8C#,
Compressed_SRGB_Alpha_BPTC_UNorm => 16#8E8D#,
Compressed_RGB_BPTC_Signed_Float => 16#8E8E#,
Compressed_RGB_BPTC_Unsigned_Float => 16#8E8F#,
R8_SNorm => 16#8F94#,
RG8_SNorm => 16#8F95#,
RGB8_SNorm => 16#8F96#,
RGBA8_SNorm => 16#8F97#,
R16_SNorm => 16#8F98#,
RG16_SNorm => 16#8F99#,
RGB16_SNorm => 16#8F9A#,
RGBA16_SNorm => 16#8F9B#,
RGB10_A2UI => 16#906F#,
Compressed_RGBA_ASTC_4x4 => 16#93B0#,
Compressed_RGBA_ASTC_5x4 => 16#93B1#,
Compressed_RGBA_ASTC_5x5 => 16#93B2#,
Compressed_RGBA_ASTC_6x5 => 16#93B3#,
Compressed_RGBA_ASTC_6x6 => 16#93B4#,
Compressed_RGBA_ASTC_8x5 => 16#93B5#,
Compressed_RGBA_ASTC_8x6 => 16#93B6#,
Compressed_RGBA_ASTC_8x8 => 16#93B7#,
Compressed_RGBA_ASTC_10x5 => 16#93B8#,
Compressed_RGBA_ASTC_10x6 => 16#93B9#,
Compressed_RGBA_ASTC_10x8 => 16#93BA#,
Compressed_RGBA_ASTC_10x10 => 16#93BB#,
Compressed_RGBA_ASTC_12x10 => 16#93BC#,
Compressed_RGBA_ASTC_12x12 => 16#93BD#,
Compressed_SRGB8_Alpha8_ASTC_4x4 => 16#93D0#,
Compressed_SRGB8_Alpha8_ASTC_5x4 => 16#93D1#,
Compressed_SRGB8_Alpha8_ASTC_5x5 => 16#93D2#,
Compressed_SRGB8_Alpha8_ASTC_6x5 => 16#93D3#,
Compressed_SRGB8_Alpha8_ASTC_6x6 => 16#93D4#,
Compressed_SRGB8_Alpha8_ASTC_8x5 => 16#93D5#,
Compressed_SRGB8_Alpha8_ASTC_8x6 => 16#93D6#,
Compressed_SRGB8_Alpha8_ASTC_8x8 => 16#93D7#,
Compressed_SRGB8_Alpha8_ASTC_10x5 => 16#93D8#,
Compressed_SRGB8_Alpha8_ASTC_10x6 => 16#93D9#,
Compressed_SRGB8_Alpha8_ASTC_10x8 => 16#93DA#,
Compressed_SRGB8_Alpha8_ASTC_10x10 => 16#93DB#,
Compressed_SRGB8_Alpha8_ASTC_12x10 => 16#93DC#,
Compressed_SRGB8_Alpha8_ASTC_12x12 => 16#93DD#);
for Internal_Format'Size use GL.Types.Int'Size;
for Framebuffer_Format use (Color_Index => 16#1900#,
Red => 16#1903#,
Green => 16#1904#,
Blue => 16#1905#,
Alpha => 16#1906#,
RGB => 16#1907#,
RGBA => 16#1908#,
Luminance => 16#1909#,
Luminance_Alpha => 16#190A#,
BGR => 16#80E0#,
BGRA => 16#80E1#);
for Framebuffer_Format'Size use Low_Level.Enum'Size;
for Data_Format use (Stencil_Index => 16#1901#,
Depth_Component => 16#1902#,
Red => 16#1903#,
RGB => 16#1907#,
RGBA => 16#1908#,
BGR => 16#80E0#,
BGRA => 16#80E1#,
RG => 16#8227#,
RG_Integer => 16#8228#,
Depth_Stencil => 16#84F9#,
Red_Integer => 16#8D94#,
RGB_Integer => 16#8D98#,
RGBA_Integer => 16#8D99#,
BGR_Integer => 16#8D9A#,
BGRA_Integer => 16#8D9B#);
for Data_Format'Size use Low_Level.Enum'Size;
for Data_Type use (Byte => 16#1400#,
Unsigned_Byte => 16#1401#,
Short => 16#1402#,
Unsigned_Short => 16#1403#,
Int => 16#1404#,
Unsigned_Int => 16#1405#,
Float => 16#1406#,
Bitmap => 16#1A00#,
Unsigned_Byte_3_3_2 => 16#8032#,
Unsigned_Short_4_4_4_4 => 16#8033#,
Unsigned_Short_5_5_5_1 => 16#8034#,
Unsigned_Int_8_8_8_8 => 16#8035#,
Unsigned_Int_10_10_10_2 => 16#8036#,
Unsigned_Byte_2_3_3_Rev => 16#8362#,
Unsigned_Short_5_6_5 => 16#8363#,
Unsinged_Short_5_6_5_Rev => 16#8364#,
Unsigned_Short_4_4_4_4_Rev => 16#8365#,
Unsigned_Short_1_5_5_5_Rev => 16#8366#,
Unsigned_Int_8_8_8_8_Rev => 16#8367#,
Unsigned_Int_2_10_10_10_Rev => 16#8368#);
for Data_Type'Size use Low_Level.Enum'Size;
for Channel_Data_Type use (None => 0,
Int_Type => 16#1404#,
Unsigned_Int_Type => 16#1405#,
Float_Type => 16#1406#,
Unsigned_Normalized => 16#8C17#,
Signed_Normalized => 16#8F9C#);
for Channel_Data_Type'Size use Low_Level.Enum'Size;
for Alignment use (Bytes => 1,
Even_Bytes => 2,
Words => 4,
Double_Words => 8);
for Alignment'Size use Types.Int'Size;
end GL.Pixels;
|
tum-ei-rcs/StratoX | Ada | 9,716 | adb | -- Description:
-- Main System File
-- the main loop (TM)
with Ada.Real_Time; use Ada.Real_Time;
with CPU;
with Units; use Units;
-- with Units.Navigation; use Units.Navigation;
with HIL;
with Interfaces; use Interfaces;
with MPU6000.Driver; use MPU6000.Driver;
with PX4IO.Driver;
with ublox8.Driver; use ublox8.Driver;
with NVRAM;
with Logger;
with Config.Software; use Config.Software;
with Bounded_Image; use Bounded_Image;
with Mission; use Mission;
-- with Console;
with Estimator;
with Controller;
with LED_Manager;
with Buzzer_Manager;
with Buildinfo;
with Profiler; use Profiler;
package body Main with SPARK_Mode => On is
type LED_Counter_Type is mod 1000/Config.Software.MAIN_TICK_RATE_MS/2;
G_led_counter : LED_Counter_Type := 0;
----------------
-- Initialize
----------------
procedure Initialize is
num_boots : HIL.Byte;
begin
CPU.initialize;
-- start logger first
declare
ret : Logger.Init_Error_Code;
begin
Logger.Init (ret);
pragma Unreferenced (ret);
end;
Logger.Set_Log_Level (CFG_LOGGER_LEVEL_UART);
-- wait to satisfy some (?) timing
declare
now : constant Time := Clock;
begin
delay until now + Milliseconds (50);
end;
if Config.Software.TEST_MODE_ACTIVE then
Logger.log_console (Logger.ERROR, "TEST-DUMMY MODE IS ACTIVE!");
end if;
-- start NVRAM (bootcounter...)
Logger.log_console (Logger.INFO, "Initializing NVRAM...");
NVRAM.Init;
-- from now on, log everything to SDcard
Logger.log_console (Logger.INFO, "Starting SDLog...");
Logger.Start_SDLog; -- should be called after NVRAM.Init
Buzzer_Manager.Initialize;
Estimator.initialize;
Controller.initialize;
-- wait a bit: UART doesn't seem to write earlier.
declare
now : constant Time := Clock;
begin
delay until now + Milliseconds (1000); -- reduced from 1500
end;
-- Dump general boot & crash info
declare
exception_line : HIL.Byte_Array_2 := (0,0);
exception_addr : Unsigned_32;
high_watermark_us : Unsigned_32;
begin
NVRAM.Load (NVRAM.VAR_BOOTCOUNTER, num_boots); -- is maintained by the NVRAM itself
declare
strboot : constant String := Unsigned8_Img (num_boots);
begin
Logger.log_console (Logger.INFO, ("Boot number: " & strboot));
Logger.log_console (Logger.INFO, "Build date: " & Buildinfo.Compilation_ISO_Date
& " " & Buildinfo.Compilation_Time);
end;
NVRAM.Load (NVRAM.VAR_EXCEPTION_LINE_L, exception_line(1));
NVRAM.Load (NVRAM.VAR_EXCEPTION_LINE_H, exception_line(2));
NVRAM.Load (NVRAM.VAR_EXCEPTION_ADDR_A, exception_addr);
-- write to SD card and console: last crash info
Logger.log (Logger.WARN, "Last Exception: line=" &
Integer_Img (Integer (HIL.toUnsigned_16 (exception_line))) &
" addr=" & Unsigned_Img (exception_addr));
NVRAM.Load (NVRAM.VAR_HIGHWATERMARK_A, high_watermark_us);
Logger.log (Logger.WARN, "High Watermark: " & Unsigned_Img (high_watermark_us));
end;
Mission.load_Mission;
end Initialize;
-----------------------
-- Perform_Self_Test
-----------------------
procedure Perform_Self_Test (passed : out Boolean) is
in_air_reset : constant Boolean := Mission.Is_Resumed;
begin
if in_air_reset then
passed := True;
Logger.log_console (Logger.INFO, "In-Air reset, no self-check");
return;
end if;
Logger.log_console (Logger.INFO, "Starting Self Test");
-- check NVRAM
NVRAM.Self_Check (passed);
if not passed then
Logger.log_console (Logger.ERROR, "NVRAM self-check failed");
return;
else
Logger.log_console (Logger.INFO, "NVRAM self-check passed");
end if;
-- check MPU6000
declare
Status : Boolean;
begin
MPU6000.Driver.Self_Test (Status);
passed := Status;
end;
if not passed then
Logger.log_console (Logger.ERROR, "MPU6000 self-check failed");
return;
else
Logger.log_console (Logger.INFO, "MPU6000 self-check passed");
end if;
-- check PX4IO
declare
Status : Boolean;
begin
PX4IO.Driver.Self_Check (Status);
passed := Status;
end;
if not passed then
Logger.log_console (Logger.ERROR, "PX4IO self-check failed; continuing anyway");
--return; -- this happens a lot
else
Logger.log_console (Logger.INFO, "PX4IO self-check passed");
end if;
-- check GPS
declare
Status : ublox8.Driver.Error_Type;
begin
ublox8.Driver.perform_Self_Check (Status);
passed := Status = ublox8.Driver.SUCCESS;
end;
if not passed then
Logger.log_console (Logger.ERROR, "Ublox8 self-check failed");
return;
else
Logger.log_console (Logger.INFO, "Ublox8 self-check passed");
end if;
end Perform_Self_Test;
--------------
-- Run_Loop
--------------
procedure Run_Loop is
msg : constant String := "Main";
time_next_loop : Time;
time_loop_start : Time;
Main_Profile : Profile_Tag;
--command : Console.User_Command_Type;
type skipper is mod 100; -- every 2 seconds one perf log
skip : skipper := 0;
watermark_high_us : Unsigned_32 := 0;
watermark_last_us : Unsigned_32 := 0;
m_state : Mission.Mission_State_Type;
begin
Main_Profile.init(name => "Main");
LED_Manager.LED_blink (LED_Manager.SLOW);
NVRAM.Load (NVRAM.VAR_HIGHWATERMARK_A, watermark_high_us);
Logger.log_console (Logger.INFO, msg);
-- arm PX4IO
Controller.activate;
time_next_loop := Clock;
loop
Main_Profile.start;
time_loop_start := Clock;
skip := skip + 1;
-- LED alive: toggle with main loop, which allows to see irregularities
G_led_counter := LED_Counter_Type'Succ( G_led_counter );
if G_led_counter < LED_Counter_Type'Last/2 then
LED_Manager.LED_switchOn;
else
LED_Manager.LED_switchOff;
end if;
-- do not use the buzzer here...just call tick. The only one who may buzzer is mission.adb
Buzzer_Manager.Tick;
-- Mission
m_state := Mission.get_state;
Mission.run_Mission; -- may switch to next one
-- -- Console
-- Console.read_Command( command );
--
-- case ( command ) is
-- when Console.TEST =>
-- perform_Self_Test (checks_passed);
-- if not checks_passed then
-- Logger.log_console (Logger.ERROR, "Self-checks failed");
-- else
-- Logger.log_console (Logger.INFO, "Self-checks passed");
-- end if;
--
-- when Console.STATUS =>
-- Estimator.log_Info;
-- Controller.log_Info;
-- PX4IO.Driver.read_Status;
--
-- Logger.log_console (Logger.INFO, "Profile: " & Integer_Img ( Integer(
-- Float( Units.To_Time(loop_duration_max) ) * 1000.0 ) ) & " ms" );
--
-- when Console.ARM => Controller.activate;
--
-- when Console.DISARM => Controller.deactivate;
--
-- when Console.PROFILE =>
-- Logger.log_console (Logger.INFO, "Profile: " & Integer_Img ( Integer(
-- Float( Units.To_Time(loop_duration_max) ) * 1000.0 ) ) & " ms" );
-- Main_Profile.log;
--
-- when others =>
-- null;
-- end case;
-- Maintain high watermark
Main_Profile.stop;
if m_state /= Mission.DETACHING and then m_state /= Mission.STARTING then
-- we measure the loop time, except in detach and start. Because there we screw with timing
declare
t_watermark_sec : constant Float := Float (To_Time (Main_Profile.get_Max));
t_watermark_usec : constant Float := t_watermark_sec * 1.0E6;
begin
if t_watermark_usec > 0.0 then
if Float (Unsigned_32'Last) > t_watermark_usec then
watermark_last_us := Unsigned_32 (t_watermark_usec);
else
watermark_last_us := Unsigned_32'Last;
end if;
if watermark_last_us > watermark_high_us then
watermark_high_us := watermark_last_us;
NVRAM.Store (NVRAM.VAR_HIGHWATERMARK_A, watermark_high_us);
end if;
if skip = 0 then
Main_Profile.reset;
Logger.log_console (Logger.DEBUG, "Main Time: cur=" & Unsigned_Img (watermark_last_us)
& ", high=" & Unsigned_Img (watermark_high_us));
end if;
end if;
end;
else
-- recover timing
Main_Profile.reset;
time_next_loop := time_loop_start;
end if;
-- wait remaining loop time
time_next_loop := time_next_loop + Milliseconds (MAIN_TICK_RATE_MS);
delay until time_next_loop;
end loop;
end Run_Loop;
end Main;
|
charlie5/aIDE | Ada | 1,943 | ads | with
AdaM.Any,
Ada.Containers.Vectors,
Ada.Streams;
private
with
AdaM.Declaration.of_subprogram,
AdaM.Declaration.of_package,
AdaM.task_Unit,
AdaM.protected_Unit,
AdaM.Aspect;
package AdaM.body_Stub
is
type Item is new Any.item with private;
-- View
--
type View is access all Item'Class;
procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : in View);
procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : out View);
for View'write use View_write;
for View'read use View_read;
-- Vector
--
package Vectors is new ada.Containers.Vectors (Positive, View);
subtype Vector is Vectors.Vector;
-- Forge
--
function new_Subprogram return body_Stub.view;
procedure free (Self : in out body_Stub.view);
procedure destruct (Self : in out body_Stub.item);
-- Attributes
--
overriding
function Id (Self : access Item) return AdaM.Id;
private
type Kind is (of_Subprogram,
of_Package,
of_Task,
of_Protected);
type library_Item_or_Subunit (Kind : body_Stub.Kind := of_Subprogram) is
record
Aspects : Aspect.view;
case Kind
is
when of_Subprogram =>
is_Overriding : Boolean;
Subprogram : Declaration.of_subprogram.view;
when of_Package =>
my_Package : Declaration.of_package.view;
when of_Task =>
my_Task : task_Unit.view;
when of_Protected =>
my_Protected : protected_Unit.view;
end case;
end record;
type Item is new Any.item with
record
null;
end record;
end AdaM.body_Stub;
|
charlie5/lace | Ada | 11,246 | adb | with
openGL.Shader,
openGL.Attribute,
openGL.Buffer.general,
openGL.Texture,
openGL.Palette,
openGL.Tasks,
openGL.Errors,
GL.Binding,
GL.lean,
GL.Pointers,
Interfaces.C.Strings,
System.storage_Elements;
package body openGL.Geometry.lit_textured_skinned
is
-----------
-- Globals
--
vertex_Shader : aliased Shader.item;
fragment_Shader : aliased Shader.item;
the_Program : aliased openGL.Program.lit.textured_skinned.item;
is_Defined : Boolean := False;
Name_1 : constant String := "Site";
Name_2 : constant String := "Normal";
Name_3 : constant String := "Coords";
Name_4 : constant String := "Shine";
Name_5 : constant String := "bone_Ids";
Name_6 : constant String := "bone_Weights";
use Interfaces;
Attribute_1_Name : aliased C.char_array := C.to_C (Name_1);
Attribute_2_Name : aliased C.char_array := C.to_C (Name_2);
Attribute_3_Name : aliased C.char_array := C.to_C (Name_3);
Attribute_4_Name : aliased C.char_array := C.to_C (Name_4);
Attribute_5_Name : aliased C.char_array := C.to_C (Name_5);
Attribute_6_Name : aliased C.char_array := C.to_C (Name_6);
Attribute_1_Name_ptr : aliased constant C.strings.chars_ptr := C.strings.to_chars_ptr (Attribute_1_Name'Access);
Attribute_2_Name_ptr : aliased constant C.strings.chars_ptr := C.strings.to_chars_ptr (Attribute_2_Name'Access);
Attribute_3_Name_ptr : aliased constant C.strings.chars_ptr := C.strings.to_chars_ptr (Attribute_3_Name'Access);
Attribute_4_Name_ptr : aliased constant C.strings.chars_ptr := C.strings.to_chars_ptr (Attribute_4_Name'Access);
Attribute_5_Name_ptr : aliased constant C.strings.chars_ptr := C.strings.to_chars_ptr (Attribute_5_Name'Access);
Attribute_6_Name_ptr : aliased constant C.strings.chars_ptr := C.strings.to_chars_ptr (Attribute_6_Name'Access);
white_Texture : openGL.Texture.Object;
----------
-- Vertex
--
function is_Transparent (Self : in Vertex_array) return Boolean -- TODO: Replace this with the generic (check that all similar functions use the generic).
is
pragma Unreferenced (Self);
begin
return False;
end is_Transparent;
---------
-- Forge
--
type Geometry_view is access all Geometry.lit_textured_skinned.item'Class;
function new_Geometry return access Geometry.lit_textured_skinned.item'Class
is
Self : constant Geometry_view := new Geometry.lit_textured_skinned.item;
begin
Self.Program_is (the_Program'Access);
return Self;
end new_Geometry;
procedure define_Program
is
use Palette,
Attribute.Forge,
GL.lean,
GL.Pointers,
System.storage_Elements;
Sample : Vertex;
Attribute_1 : openGL.Attribute.view;
Attribute_2 : openGL.Attribute.view;
Attribute_3 : openGL.Attribute.view;
Attribute_4 : openGL.Attribute.view;
Attribute_5 : openGL.Attribute.view;
Attribute_6 : openGL.Attribute.view;
white_Image : constant openGL.Image := [1 .. 2 => [1 .. 2 => +White]];
begin
Tasks.check;
if is_Defined
then
raise Error with "The 'lit_textured_skinned' program has already been defined.";
end if;
is_Defined := True;
-- Define the shaders and program.
--
white_Texture := openGL.Texture.Forge.to_Texture (white_Image);
vertex_Shader .define (Shader.Vertex, "assets/opengl/shader/lit_textured_skinned.vert");
fragment_Shader.define (Shader.Fragment, "assets/opengl/shader/lit_textured_skinned.frag");
the_Program.define ( vertex_Shader'Access,
fragment_Shader'Access);
the_Program.enable;
Attribute_1 := new_Attribute (Name => Name_1,
gl_Location => the_Program.attribute_Location (Name_1),
Size => 3,
data_Kind => Attribute.GL_FLOAT,
Stride => lit_textured_skinned.Vertex'Size / 8,
Offset => 0,
Normalized => False);
Attribute_2 := new_Attribute (Name => Name_2,
gl_Location => the_Program.attribute_Location (Name_2),
Size => 3,
data_Kind => Attribute.GL_FLOAT,
Stride => lit_textured_skinned.Vertex'Size / 8,
Offset => Sample.Normal (1)'Address
- Sample.Site (1)'Address,
Normalized => False);
Attribute_3 := new_Attribute (Name => Name_3,
gl_Location => the_Program.attribute_Location (Name_3),
Size => 2,
data_Kind => Attribute.GL_FLOAT,
Stride => lit_textured_skinned.Vertex'Size / 8,
Offset => Sample.Coords.S'Address
- Sample.Site (1)'Address,
Normalized => False);
Attribute_4 := new_Attribute (Name => Name_4,
gl_Location => the_Program.attribute_Location (Name_4),
Size => 1,
data_Kind => attribute.GL_FLOAT,
Stride => lit_textured_skinned.Vertex'Size / 8,
Offset => Sample.Shine 'Address
- Sample.Site (1)'Address,
Normalized => False);
Attribute_5 := new_Attribute (Name => Name_5,
gl_Location => the_Program.attribute_Location (Name_5),
Size => 4,
data_Kind => Attribute.GL_FLOAT,
Stride => lit_textured_skinned.Vertex'Size / 8,
Offset => Sample.bone_Ids (1)'Address
- Sample.Site (1)'Address,
Normalized => False);
Attribute_6 := new_Attribute (Name => Name_6,
gl_Location => the_Program.attribute_Location (Name_6),
Size => 4,
data_Kind => Attribute.GL_FLOAT,
Stride => lit_textured_skinned.Vertex'Size / 8,
Offset => Sample.bone_Weights (1)'Address
- Sample.Site (1)'Address,
Normalized => False);
the_Program.add (Attribute_1);
the_Program.add (Attribute_2);
the_Program.add (Attribute_3);
the_Program.add (Attribute_4);
the_Program.add (Attribute_5);
the_Program.add (Attribute_6);
glBindAttribLocation (program => the_Program.gl_Program,
index => the_Program.Attribute (named => Name_1).gl_Location,
name => +Attribute_1_Name_ptr);
Errors.log;
glBindAttribLocation (program => the_Program.gl_Program,
index => the_Program.Attribute (named => Name_2).gl_Location,
name => +Attribute_2_Name_ptr);
Errors.log;
glBindAttribLocation (program => the_Program.gl_Program,
index => the_Program.Attribute (named => Name_3).gl_Location,
name => +Attribute_3_Name_ptr);
Errors.log;
glBindAttribLocation (program => the_Program.gl_Program,
index => the_Program.Attribute (named => Name_4).gl_Location,
name => +Attribute_4_Name_ptr);
Errors.log;
glBindAttribLocation (program => the_Program.gl_Program,
index => the_Program.Attribute (named => Name_5).gl_Location,
name => +Attribute_5_Name_ptr);
Errors.log;
glBindAttribLocation (program => the_Program.gl_Program,
index => the_Program.Attribute (named => Name_6).gl_Location,
name => +Attribute_6_Name_ptr);
Errors.log;
end define_Program;
--------------
-- Attributes
--
function Program return openGL.Program.lit.textured_skinned.view
is
begin
return the_Program'Access;
end Program;
overriding
procedure Indices_are (Self : in out Item; Now : in Indices;
for_Facia : in Positive)
is
begin
raise Error with "openGL.Geometry.lit_textured_skinned - 'Indices_are' ~ TODO";
end Indices_are;
package openGL_Buffer_of_geometry_Vertices is new Buffer.general (base_Object => Buffer.array_Object,
Index => long_Index_t,
Element => Vertex,
Element_Array => Vertex_array);
procedure Vertices_are (Self : in out Item; Now : in Vertex_array)
is
use openGL_Buffer_of_geometry_Vertices.Forge;
begin
Self.Vertices := new openGL_Buffer_of_geometry_Vertices.object' (to_Buffer (Now,
usage => Buffer.static_Draw));
Self.is_Transparent := Self.is_Transparent
or is_Transparent (Now);
-- Set the bounds.
--
declare
function get_Site (Index : in long_Index_t) return Vector_3
is (Now (Index).Site);
function bounding_Box is new get_Bounds (long_Index_t, get_Site);
begin
Self.Bounds_are (bounding_Box (Count => Now'Length));
end;
end Vertices_are;
overriding
procedure enable_Texture (Self : in Item)
is
use GL,
GL.Binding,
openGL.Texture;
begin
Tasks.check;
glActiveTexture (gl.GL_TEXTURE0);
Errors.log;
if Self.Texture = openGL.Texture.null_Object
then
if not white_Texture.is_Defined
then
declare
use Palette;
white_Image : constant openGL.Image := [1 .. 2 => [1 .. 2 => +White]];
begin
white_Texture := openGL.Texture.Forge.to_Texture (white_Image);
end;
end if;
white_Texture.enable;
else
Self.Texture.enable;
end if;
end enable_Texture;
end openGL.Geometry.lit_textured_skinned;
|
reznikmm/matreshka | Ada | 4,239 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Nodes;
with XML.DOM.Attributes.Internals;
package body ODF.DOM.Attributes.FO.Font_Weight.Internals is
------------
-- Create --
------------
function Create
(Node : Matreshka.ODF_Attributes.FO.Font_Weight.FO_Font_Weight_Access)
return ODF.DOM.Attributes.FO.Font_Weight.ODF_FO_Font_Weight is
begin
return
(XML.DOM.Attributes.Internals.Create
(Matreshka.DOM_Nodes.Attribute_Access (Node)) with null record);
end Create;
----------
-- Wrap --
----------
function Wrap
(Node : Matreshka.ODF_Attributes.FO.Font_Weight.FO_Font_Weight_Access)
return ODF.DOM.Attributes.FO.Font_Weight.ODF_FO_Font_Weight is
begin
return
(XML.DOM.Attributes.Internals.Wrap
(Matreshka.DOM_Nodes.Attribute_Access (Node)) with null record);
end Wrap;
end ODF.DOM.Attributes.FO.Font_Weight.Internals;
|
AdaCore/Ada_Drivers_Library | Ada | 45,810 | ads | -- This spec has been automatically generated from STM32F40x.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.Ethernet is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype DMABMR_DSL_Field is HAL.UInt5;
subtype DMABMR_PBL_Field is HAL.UInt6;
subtype DMABMR_RTPR_Field is HAL.UInt2;
subtype DMABMR_RDP_Field is HAL.UInt6;
-- Ethernet DMA bus mode register
type DMABMR_Register is record
-- no description available
SR : Boolean := True;
-- no description available
DA : Boolean := False;
-- no description available
DSL : DMABMR_DSL_Field := 16#0#;
-- no description available
EDFE : Boolean := False;
-- no description available
PBL : DMABMR_PBL_Field := 16#21#;
-- no description available
RTPR : DMABMR_RTPR_Field := 16#0#;
-- no description available
FB : Boolean := False;
-- no description available
RDP : DMABMR_RDP_Field := 16#0#;
-- no description available
USP : Boolean := False;
-- no description available
FPM : Boolean := False;
-- no description available
AAB : Boolean := False;
-- no description available
MB : Boolean := False;
-- unspecified
Reserved_27_31 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DMABMR_Register use record
SR at 0 range 0 .. 0;
DA at 0 range 1 .. 1;
DSL at 0 range 2 .. 6;
EDFE at 0 range 7 .. 7;
PBL at 0 range 8 .. 13;
RTPR at 0 range 14 .. 15;
FB at 0 range 16 .. 16;
RDP at 0 range 17 .. 22;
USP at 0 range 23 .. 23;
FPM at 0 range 24 .. 24;
AAB at 0 range 25 .. 25;
MB at 0 range 26 .. 26;
Reserved_27_31 at 0 range 27 .. 31;
end record;
subtype DMASR_RPS_Field is HAL.UInt3;
subtype DMASR_TPS_Field is HAL.UInt3;
subtype DMASR_EBS_Field is HAL.UInt3;
-- Ethernet DMA status register
type DMASR_Register is record
-- no description available
TS : Boolean := False;
-- no description available
TPSS : Boolean := False;
-- no description available
TBUS : Boolean := False;
-- no description available
TJTS : Boolean := False;
-- no description available
ROS : Boolean := False;
-- no description available
TUS : Boolean := False;
-- no description available
RS : Boolean := False;
-- no description available
RBUS : Boolean := False;
-- no description available
RPSS : Boolean := False;
-- no description available
PWTS : Boolean := False;
-- no description available
ETS : Boolean := False;
-- unspecified
Reserved_11_12 : HAL.UInt2 := 16#0#;
-- no description available
FBES : Boolean := False;
-- no description available
ERS : Boolean := False;
-- no description available
AIS : Boolean := False;
-- no description available
NIS : Boolean := False;
-- Read-only. no description available
RPS : DMASR_RPS_Field := 16#0#;
-- Read-only. no description available
TPS : DMASR_TPS_Field := 16#0#;
-- Read-only. no description available
EBS : DMASR_EBS_Field := 16#0#;
-- unspecified
Reserved_26_26 : HAL.Bit := 16#0#;
-- Read-only. no description available
MMCS : Boolean := False;
-- Read-only. no description available
PMTS : Boolean := False;
-- Read-only. no description available
TSTS : Boolean := False;
-- unspecified
Reserved_30_31 : HAL.UInt2 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DMASR_Register use record
TS at 0 range 0 .. 0;
TPSS at 0 range 1 .. 1;
TBUS at 0 range 2 .. 2;
TJTS at 0 range 3 .. 3;
ROS at 0 range 4 .. 4;
TUS at 0 range 5 .. 5;
RS at 0 range 6 .. 6;
RBUS at 0 range 7 .. 7;
RPSS at 0 range 8 .. 8;
PWTS at 0 range 9 .. 9;
ETS at 0 range 10 .. 10;
Reserved_11_12 at 0 range 11 .. 12;
FBES at 0 range 13 .. 13;
ERS at 0 range 14 .. 14;
AIS at 0 range 15 .. 15;
NIS at 0 range 16 .. 16;
RPS at 0 range 17 .. 19;
TPS at 0 range 20 .. 22;
EBS at 0 range 23 .. 25;
Reserved_26_26 at 0 range 26 .. 26;
MMCS at 0 range 27 .. 27;
PMTS at 0 range 28 .. 28;
TSTS at 0 range 29 .. 29;
Reserved_30_31 at 0 range 30 .. 31;
end record;
subtype DMAOMR_RTC_Field is HAL.UInt2;
subtype DMAOMR_TTC_Field is HAL.UInt3;
-- Ethernet DMA operation mode register
type DMAOMR_Register is record
-- unspecified
Reserved_0_0 : HAL.Bit := 16#0#;
-- SR
SR : Boolean := False;
-- OSF
OSF : Boolean := False;
-- RTC
RTC : DMAOMR_RTC_Field := 16#0#;
-- unspecified
Reserved_5_5 : HAL.Bit := 16#0#;
-- FUGF
FUGF : Boolean := False;
-- FEF
FEF : Boolean := False;
-- unspecified
Reserved_8_12 : HAL.UInt5 := 16#0#;
-- ST
ST : Boolean := False;
-- TTC
TTC : DMAOMR_TTC_Field := 16#0#;
-- unspecified
Reserved_17_19 : HAL.UInt3 := 16#0#;
-- FTF
FTF : Boolean := False;
-- TSF
TSF : Boolean := False;
-- unspecified
Reserved_22_23 : HAL.UInt2 := 16#0#;
-- DFRF
DFRF : Boolean := False;
-- RSF
RSF : Boolean := False;
-- DTCEFD
DTCEFD : Boolean := False;
-- unspecified
Reserved_27_31 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DMAOMR_Register use record
Reserved_0_0 at 0 range 0 .. 0;
SR at 0 range 1 .. 1;
OSF at 0 range 2 .. 2;
RTC at 0 range 3 .. 4;
Reserved_5_5 at 0 range 5 .. 5;
FUGF at 0 range 6 .. 6;
FEF at 0 range 7 .. 7;
Reserved_8_12 at 0 range 8 .. 12;
ST at 0 range 13 .. 13;
TTC at 0 range 14 .. 16;
Reserved_17_19 at 0 range 17 .. 19;
FTF at 0 range 20 .. 20;
TSF at 0 range 21 .. 21;
Reserved_22_23 at 0 range 22 .. 23;
DFRF at 0 range 24 .. 24;
RSF at 0 range 25 .. 25;
DTCEFD at 0 range 26 .. 26;
Reserved_27_31 at 0 range 27 .. 31;
end record;
-- Ethernet DMA interrupt enable register
type DMAIER_Register is record
-- no description available
TIE : Boolean := False;
-- no description available
TPSIE : Boolean := False;
-- no description available
TBUIE : Boolean := False;
-- no description available
TJTIE : Boolean := False;
-- no description available
ROIE : Boolean := False;
-- no description available
TUIE : Boolean := False;
-- no description available
RIE : Boolean := False;
-- no description available
RBUIE : Boolean := False;
-- no description available
RPSIE : Boolean := False;
-- no description available
RWTIE : Boolean := False;
-- no description available
ETIE : Boolean := False;
-- unspecified
Reserved_11_12 : HAL.UInt2 := 16#0#;
-- no description available
FBEIE : Boolean := False;
-- no description available
ERIE : Boolean := False;
-- no description available
AISE : Boolean := False;
-- no description available
NISE : Boolean := False;
-- unspecified
Reserved_17_31 : HAL.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DMAIER_Register use record
TIE at 0 range 0 .. 0;
TPSIE at 0 range 1 .. 1;
TBUIE at 0 range 2 .. 2;
TJTIE at 0 range 3 .. 3;
ROIE at 0 range 4 .. 4;
TUIE at 0 range 5 .. 5;
RIE at 0 range 6 .. 6;
RBUIE at 0 range 7 .. 7;
RPSIE at 0 range 8 .. 8;
RWTIE at 0 range 9 .. 9;
ETIE at 0 range 10 .. 10;
Reserved_11_12 at 0 range 11 .. 12;
FBEIE at 0 range 13 .. 13;
ERIE at 0 range 14 .. 14;
AISE at 0 range 15 .. 15;
NISE at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
subtype DMAMFBOCR_MFC_Field is HAL.UInt16;
subtype DMAMFBOCR_MFA_Field is HAL.UInt11;
-- Ethernet DMA missed frame and buffer overflow counter register
type DMAMFBOCR_Register is record
-- no description available
MFC : DMAMFBOCR_MFC_Field := 16#0#;
-- no description available
OMFC : Boolean := False;
-- no description available
MFA : DMAMFBOCR_MFA_Field := 16#0#;
-- no description available
OFOC : Boolean := False;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DMAMFBOCR_Register use record
MFC at 0 range 0 .. 15;
OMFC at 0 range 16 .. 16;
MFA at 0 range 17 .. 27;
OFOC at 0 range 28 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype DMARSWTR_RSWTC_Field is HAL.UInt8;
-- Ethernet DMA receive status watchdog timer register
type DMARSWTR_Register is record
-- RSWTC
RSWTC : DMARSWTR_RSWTC_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DMARSWTR_Register use record
RSWTC at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype MACCR_BL_Field is HAL.UInt2;
subtype MACCR_IFG_Field is HAL.UInt3;
-- Ethernet MAC configuration register
type MACCR_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- RE
RE : Boolean := False;
-- TE
TE : Boolean := False;
-- DC
DC : Boolean := False;
-- BL
BL : MACCR_BL_Field := 16#0#;
-- APCS
APCS : Boolean := False;
-- unspecified
Reserved_8_8 : HAL.Bit := 16#0#;
-- RD
RD : Boolean := False;
-- IPCO
IPCO : Boolean := False;
-- DM
DM : Boolean := False;
-- LM
LM : Boolean := False;
-- ROD
ROD : Boolean := False;
-- FES
FES : Boolean := False;
-- unspecified
Reserved_15_15 : HAL.Bit := 16#1#;
-- CSD
CSD : Boolean := False;
-- IFG
IFG : MACCR_IFG_Field := 16#0#;
-- unspecified
Reserved_20_21 : HAL.UInt2 := 16#0#;
-- JD
JD : Boolean := False;
-- WD
WD : Boolean := False;
-- unspecified
Reserved_24_24 : HAL.Bit := 16#0#;
-- CSTF
CSTF : Boolean := False;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACCR_Register use record
Reserved_0_1 at 0 range 0 .. 1;
RE at 0 range 2 .. 2;
TE at 0 range 3 .. 3;
DC at 0 range 4 .. 4;
BL at 0 range 5 .. 6;
APCS at 0 range 7 .. 7;
Reserved_8_8 at 0 range 8 .. 8;
RD at 0 range 9 .. 9;
IPCO at 0 range 10 .. 10;
DM at 0 range 11 .. 11;
LM at 0 range 12 .. 12;
ROD at 0 range 13 .. 13;
FES at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
CSD at 0 range 16 .. 16;
IFG at 0 range 17 .. 19;
Reserved_20_21 at 0 range 20 .. 21;
JD at 0 range 22 .. 22;
WD at 0 range 23 .. 23;
Reserved_24_24 at 0 range 24 .. 24;
CSTF at 0 range 25 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
-- Ethernet MAC frame filter register
type MACFFR_Register is record
-- no description available
PM : Boolean := False;
-- no description available
HU : Boolean := False;
-- no description available
HM : Boolean := False;
-- no description available
DAIF : Boolean := False;
-- no description available
RAM : Boolean := False;
-- no description available
BFD : Boolean := False;
-- no description available
PCF : Boolean := False;
-- no description available
SAIF : Boolean := False;
-- no description available
SAF : Boolean := False;
-- no description available
HPF : Boolean := False;
-- unspecified
Reserved_10_30 : HAL.UInt21 := 16#0#;
-- no description available
RA : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACFFR_Register use record
PM at 0 range 0 .. 0;
HU at 0 range 1 .. 1;
HM at 0 range 2 .. 2;
DAIF at 0 range 3 .. 3;
RAM at 0 range 4 .. 4;
BFD at 0 range 5 .. 5;
PCF at 0 range 6 .. 6;
SAIF at 0 range 7 .. 7;
SAF at 0 range 8 .. 8;
HPF at 0 range 9 .. 9;
Reserved_10_30 at 0 range 10 .. 30;
RA at 0 range 31 .. 31;
end record;
subtype MACMIIAR_CR_Field is HAL.UInt3;
subtype MACMIIAR_MR_Field is HAL.UInt5;
subtype MACMIIAR_PA_Field is HAL.UInt5;
-- Ethernet MAC MII address register
type MACMIIAR_Register is record
-- no description available
MB : Boolean := False;
-- no description available
MW : Boolean := False;
-- no description available
CR : MACMIIAR_CR_Field := 16#0#;
-- unspecified
Reserved_5_5 : HAL.Bit := 16#0#;
-- no description available
MR : MACMIIAR_MR_Field := 16#0#;
-- no description available
PA : MACMIIAR_PA_Field := 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 MACMIIAR_Register use record
MB at 0 range 0 .. 0;
MW at 0 range 1 .. 1;
CR at 0 range 2 .. 4;
Reserved_5_5 at 0 range 5 .. 5;
MR at 0 range 6 .. 10;
PA at 0 range 11 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype MACMIIDR_TD_Field is HAL.UInt16;
-- Ethernet MAC MII data register
type MACMIIDR_Register is record
-- no description available
TD : MACMIIDR_TD_Field := 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 MACMIIDR_Register use record
TD at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype MACFCR_PLT_Field is HAL.UInt2;
subtype MACFCR_PT_Field is HAL.UInt16;
-- Ethernet MAC flow control register
type MACFCR_Register is record
-- no description available
FCB : Boolean := False;
-- no description available
TFCE : Boolean := False;
-- no description available
RFCE : Boolean := False;
-- no description available
UPFD : Boolean := False;
-- no description available
PLT : MACFCR_PLT_Field := 16#0#;
-- unspecified
Reserved_6_6 : HAL.Bit := 16#0#;
-- no description available
ZQPD : Boolean := False;
-- unspecified
Reserved_8_15 : HAL.UInt8 := 16#0#;
-- no description available
PT : MACFCR_PT_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACFCR_Register use record
FCB at 0 range 0 .. 0;
TFCE at 0 range 1 .. 1;
RFCE at 0 range 2 .. 2;
UPFD at 0 range 3 .. 3;
PLT at 0 range 4 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
ZQPD at 0 range 7 .. 7;
Reserved_8_15 at 0 range 8 .. 15;
PT at 0 range 16 .. 31;
end record;
subtype MACVLANTR_VLANTI_Field is HAL.UInt16;
-- Ethernet MAC VLAN tag register
type MACVLANTR_Register is record
-- no description available
VLANTI : MACVLANTR_VLANTI_Field := 16#0#;
-- no description available
VLANTC : Boolean := False;
-- unspecified
Reserved_17_31 : HAL.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACVLANTR_Register use record
VLANTI at 0 range 0 .. 15;
VLANTC at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
-- Ethernet MAC PMT control and status register
type MACPMTCSR_Register is record
-- no description available
PD : Boolean := False;
-- no description available
MPE : Boolean := False;
-- no description available
WFE : Boolean := False;
-- unspecified
Reserved_3_4 : HAL.UInt2 := 16#0#;
-- no description available
MPR : Boolean := False;
-- no description available
WFR : Boolean := False;
-- unspecified
Reserved_7_8 : HAL.UInt2 := 16#0#;
-- no description available
GU : Boolean := False;
-- unspecified
Reserved_10_30 : HAL.UInt21 := 16#0#;
-- no description available
WFFRPR : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACPMTCSR_Register use record
PD at 0 range 0 .. 0;
MPE at 0 range 1 .. 1;
WFE at 0 range 2 .. 2;
Reserved_3_4 at 0 range 3 .. 4;
MPR at 0 range 5 .. 5;
WFR at 0 range 6 .. 6;
Reserved_7_8 at 0 range 7 .. 8;
GU at 0 range 9 .. 9;
Reserved_10_30 at 0 range 10 .. 30;
WFFRPR at 0 range 31 .. 31;
end record;
-- Ethernet MAC debug register
type MACDBGR_Register is record
-- Read-only. CR
CR : Boolean;
-- Read-only. CSR
CSR : Boolean;
-- Read-only. ROR
ROR : Boolean;
-- Read-only. MCF
MCF : Boolean;
-- Read-only. MCP
MCP : Boolean;
-- Read-only. MCFHP
MCFHP : Boolean;
-- unspecified
Reserved_6_31 : HAL.UInt26;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACDBGR_Register use record
CR at 0 range 0 .. 0;
CSR at 0 range 1 .. 1;
ROR at 0 range 2 .. 2;
MCF at 0 range 3 .. 3;
MCP at 0 range 4 .. 4;
MCFHP at 0 range 5 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
-- Ethernet MAC interrupt status register
type MACSR_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- Read-only. no description available
PMTS : Boolean := False;
-- Read-only. no description available
MMCS : Boolean := False;
-- Read-only. no description available
MMCRS : Boolean := False;
-- Read-only. no description available
MMCTS : Boolean := False;
-- unspecified
Reserved_7_8 : HAL.UInt2 := 16#0#;
-- no description available
TSTS : Boolean := False;
-- unspecified
Reserved_10_31 : HAL.UInt22 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACSR_Register use record
Reserved_0_2 at 0 range 0 .. 2;
PMTS at 0 range 3 .. 3;
MMCS at 0 range 4 .. 4;
MMCRS at 0 range 5 .. 5;
MMCTS at 0 range 6 .. 6;
Reserved_7_8 at 0 range 7 .. 8;
TSTS at 0 range 9 .. 9;
Reserved_10_31 at 0 range 10 .. 31;
end record;
-- Ethernet MAC interrupt mask register
type MACIMR_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- no description available
PMTIM : Boolean := False;
-- unspecified
Reserved_4_8 : HAL.UInt5 := 16#0#;
-- no description available
TSTIM : Boolean := False;
-- unspecified
Reserved_10_31 : HAL.UInt22 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACIMR_Register use record
Reserved_0_2 at 0 range 0 .. 2;
PMTIM at 0 range 3 .. 3;
Reserved_4_8 at 0 range 4 .. 8;
TSTIM at 0 range 9 .. 9;
Reserved_10_31 at 0 range 10 .. 31;
end record;
subtype MACA0HR_MACA0H_Field is HAL.UInt16;
-- Ethernet MAC address 0 high register
type MACA0HR_Register is record
-- MAC address0 high
MACA0H : MACA0HR_MACA0H_Field := 16#FFFF#;
-- unspecified
Reserved_16_30 : HAL.UInt15 := 16#10#;
-- Read-only. Always 1
MO : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACA0HR_Register use record
MACA0H at 0 range 0 .. 15;
Reserved_16_30 at 0 range 16 .. 30;
MO at 0 range 31 .. 31;
end record;
subtype MACA1HR_MACA1H_Field is HAL.UInt16;
subtype MACA1HR_MBC_Field is HAL.UInt6;
-- Ethernet MAC address 1 high register
type MACA1HR_Register is record
-- no description available
MACA1H : MACA1HR_MACA1H_Field := 16#FFFF#;
-- unspecified
Reserved_16_23 : HAL.UInt8 := 16#0#;
-- no description available
MBC : MACA1HR_MBC_Field := 16#0#;
-- no description available
SA : Boolean := False;
-- no description available
AE : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACA1HR_Register use record
MACA1H at 0 range 0 .. 15;
Reserved_16_23 at 0 range 16 .. 23;
MBC at 0 range 24 .. 29;
SA at 0 range 30 .. 30;
AE at 0 range 31 .. 31;
end record;
subtype MACA2HR_MAC2AH_Field is HAL.UInt16;
subtype MACA2HR_MBC_Field is HAL.UInt6;
-- Ethernet MAC address 2 high register
type MACA2HR_Register is record
-- no description available
MAC2AH : MACA2HR_MAC2AH_Field := 16#FFFF#;
-- unspecified
Reserved_16_23 : HAL.UInt8 := 16#0#;
-- no description available
MBC : MACA2HR_MBC_Field := 16#0#;
-- no description available
SA : Boolean := False;
-- no description available
AE : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACA2HR_Register use record
MAC2AH at 0 range 0 .. 15;
Reserved_16_23 at 0 range 16 .. 23;
MBC at 0 range 24 .. 29;
SA at 0 range 30 .. 30;
AE at 0 range 31 .. 31;
end record;
subtype MACA2LR_MACA2L_Field is HAL.UInt31;
-- Ethernet MAC address 2 low register
type MACA2LR_Register is record
-- no description available
MACA2L : MACA2LR_MACA2L_Field := 16#7FFFFFFF#;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#1#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACA2LR_Register use record
MACA2L at 0 range 0 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype MACA3HR_MACA3H_Field is HAL.UInt16;
subtype MACA3HR_MBC_Field is HAL.UInt6;
-- Ethernet MAC address 3 high register
type MACA3HR_Register is record
-- no description available
MACA3H : MACA3HR_MACA3H_Field := 16#FFFF#;
-- unspecified
Reserved_16_23 : HAL.UInt8 := 16#0#;
-- no description available
MBC : MACA3HR_MBC_Field := 16#0#;
-- no description available
SA : Boolean := False;
-- no description available
AE : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MACA3HR_Register use record
MACA3H at 0 range 0 .. 15;
Reserved_16_23 at 0 range 16 .. 23;
MBC at 0 range 24 .. 29;
SA at 0 range 30 .. 30;
AE at 0 range 31 .. 31;
end record;
-- Ethernet MMC control register
type MMCCR_Register is record
-- no description available
CR : Boolean := False;
-- no description available
CSR : Boolean := False;
-- no description available
ROR : Boolean := False;
-- no description available
MCF : Boolean := False;
-- no description available
MCP : Boolean := False;
-- no description available
MCFHP : Boolean := False;
-- unspecified
Reserved_6_31 : HAL.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MMCCR_Register use record
CR at 0 range 0 .. 0;
CSR at 0 range 1 .. 1;
ROR at 0 range 2 .. 2;
MCF at 0 range 3 .. 3;
MCP at 0 range 4 .. 4;
MCFHP at 0 range 5 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
-- Ethernet MMC receive interrupt register
type MMCRIR_Register is record
-- unspecified
Reserved_0_4 : HAL.UInt5 := 16#0#;
-- no description available
RFCES : Boolean := False;
-- no description available
RFAES : Boolean := False;
-- unspecified
Reserved_7_16 : HAL.UInt10 := 16#0#;
-- no description available
RGUFS : Boolean := False;
-- unspecified
Reserved_18_31 : HAL.UInt14 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MMCRIR_Register use record
Reserved_0_4 at 0 range 0 .. 4;
RFCES at 0 range 5 .. 5;
RFAES at 0 range 6 .. 6;
Reserved_7_16 at 0 range 7 .. 16;
RGUFS at 0 range 17 .. 17;
Reserved_18_31 at 0 range 18 .. 31;
end record;
-- Ethernet MMC transmit interrupt register
type MMCTIR_Register is record
-- unspecified
Reserved_0_13 : HAL.UInt14;
-- Read-only. no description available
TGFSCS : Boolean;
-- Read-only. no description available
TGFMSCS : Boolean;
-- unspecified
Reserved_16_20 : HAL.UInt5;
-- Read-only. no description available
TGFS : Boolean;
-- unspecified
Reserved_22_31 : HAL.UInt10;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MMCTIR_Register use record
Reserved_0_13 at 0 range 0 .. 13;
TGFSCS at 0 range 14 .. 14;
TGFMSCS at 0 range 15 .. 15;
Reserved_16_20 at 0 range 16 .. 20;
TGFS at 0 range 21 .. 21;
Reserved_22_31 at 0 range 22 .. 31;
end record;
-- Ethernet MMC receive interrupt mask register
type MMCRIMR_Register is record
-- unspecified
Reserved_0_4 : HAL.UInt5 := 16#0#;
-- no description available
RFCEM : Boolean := False;
-- no description available
RFAEM : Boolean := False;
-- unspecified
Reserved_7_16 : HAL.UInt10 := 16#0#;
-- no description available
RGUFM : Boolean := False;
-- unspecified
Reserved_18_31 : HAL.UInt14 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MMCRIMR_Register use record
Reserved_0_4 at 0 range 0 .. 4;
RFCEM at 0 range 5 .. 5;
RFAEM at 0 range 6 .. 6;
Reserved_7_16 at 0 range 7 .. 16;
RGUFM at 0 range 17 .. 17;
Reserved_18_31 at 0 range 18 .. 31;
end record;
-- Ethernet MMC transmit interrupt mask register
type MMCTIMR_Register is record
-- unspecified
Reserved_0_13 : HAL.UInt14 := 16#0#;
-- no description available
TGFSCM : Boolean := False;
-- no description available
TGFMSCM : Boolean := False;
-- no description available
TGFM : Boolean := False;
-- unspecified
Reserved_17_31 : HAL.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MMCTIMR_Register use record
Reserved_0_13 at 0 range 0 .. 13;
TGFSCM at 0 range 14 .. 14;
TGFMSCM at 0 range 15 .. 15;
TGFM at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
subtype PTPTSCR_TSCNT_Field is HAL.UInt2;
-- Ethernet PTP time stamp control register
type PTPTSCR_Register is record
-- no description available
TSE : Boolean := False;
-- no description available
TSFCU : Boolean := False;
-- no description available
TSSTI : Boolean := False;
-- no description available
TSSTU : Boolean := False;
-- no description available
TSITE : Boolean := False;
-- no description available
TTSARU : Boolean := False;
-- unspecified
Reserved_6_7 : HAL.UInt2 := 16#0#;
-- no description available
TSSARFE : Boolean := False;
-- no description available
TSSSR : Boolean := False;
-- no description available
TSPTPPSV2E : Boolean := False;
-- no description available
TSSPTPOEFE : Boolean := False;
-- no description available
TSSIPV6FE : Boolean := False;
-- no description available
TSSIPV4FE : Boolean := True;
-- no description available
TSSEME : Boolean := False;
-- no description available
TSSMRME : Boolean := False;
-- no description available
TSCNT : PTPTSCR_TSCNT_Field := 16#0#;
-- no description available
TSPFFMAE : Boolean := False;
-- unspecified
Reserved_19_31 : HAL.UInt13 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for PTPTSCR_Register use record
TSE at 0 range 0 .. 0;
TSFCU at 0 range 1 .. 1;
TSSTI at 0 range 2 .. 2;
TSSTU at 0 range 3 .. 3;
TSITE at 0 range 4 .. 4;
TTSARU at 0 range 5 .. 5;
Reserved_6_7 at 0 range 6 .. 7;
TSSARFE at 0 range 8 .. 8;
TSSSR at 0 range 9 .. 9;
TSPTPPSV2E at 0 range 10 .. 10;
TSSPTPOEFE at 0 range 11 .. 11;
TSSIPV6FE at 0 range 12 .. 12;
TSSIPV4FE at 0 range 13 .. 13;
TSSEME at 0 range 14 .. 14;
TSSMRME at 0 range 15 .. 15;
TSCNT at 0 range 16 .. 17;
TSPFFMAE at 0 range 18 .. 18;
Reserved_19_31 at 0 range 19 .. 31;
end record;
subtype PTPSSIR_STSSI_Field is HAL.UInt8;
-- Ethernet PTP subsecond increment register
type PTPSSIR_Register is record
-- no description available
STSSI : PTPSSIR_STSSI_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for PTPSSIR_Register use record
STSSI at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype PTPTSLR_STSS_Field is HAL.UInt31;
-- Ethernet PTP time stamp low register
type PTPTSLR_Register is record
-- Read-only. no description available
STSS : PTPTSLR_STSS_Field;
-- Read-only. no description available
STPNS : Boolean;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for PTPTSLR_Register use record
STSS at 0 range 0 .. 30;
STPNS at 0 range 31 .. 31;
end record;
subtype PTPTSLUR_TSUSS_Field is HAL.UInt31;
-- Ethernet PTP time stamp low update register
type PTPTSLUR_Register is record
-- no description available
TSUSS : PTPTSLUR_TSUSS_Field := 16#0#;
-- no description available
TSUPNS : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for PTPTSLUR_Register use record
TSUSS at 0 range 0 .. 30;
TSUPNS at 0 range 31 .. 31;
end record;
-- Ethernet PTP time stamp status register
type PTPTSSR_Register is record
-- Read-only. no description available
TSSO : Boolean;
-- Read-only. no description available
TSTTR : Boolean;
-- unspecified
Reserved_2_31 : HAL.UInt30;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for PTPTSSR_Register use record
TSSO at 0 range 0 .. 0;
TSTTR at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- Ethernet PTP PPS control register
type PTPPPSCR_Register is record
-- Read-only. TSSO
TSSO : Boolean;
-- Read-only. TSTTR
TSTTR : Boolean;
-- unspecified
Reserved_2_31 : HAL.UInt30;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for PTPPPSCR_Register use record
TSSO at 0 range 0 .. 0;
TSTTR at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Ethernet: DMA controller operation
type Ethernet_DMA_Peripheral is record
-- Ethernet DMA bus mode register
DMABMR : aliased DMABMR_Register;
-- Ethernet DMA transmit poll demand register
DMATPDR : aliased HAL.UInt32;
-- EHERNET DMA receive poll demand register
DMARPDR : aliased HAL.UInt32;
-- Ethernet DMA receive descriptor list address register
DMARDLAR : aliased HAL.UInt32;
-- Ethernet DMA transmit descriptor list address register
DMATDLAR : aliased HAL.UInt32;
-- Ethernet DMA status register
DMASR : aliased DMASR_Register;
-- Ethernet DMA operation mode register
DMAOMR : aliased DMAOMR_Register;
-- Ethernet DMA interrupt enable register
DMAIER : aliased DMAIER_Register;
-- Ethernet DMA missed frame and buffer overflow counter register
DMAMFBOCR : aliased DMAMFBOCR_Register;
-- Ethernet DMA receive status watchdog timer register
DMARSWTR : aliased DMARSWTR_Register;
-- Ethernet DMA current host transmit descriptor register
DMACHTDR : aliased HAL.UInt32;
-- Ethernet DMA current host receive descriptor register
DMACHRDR : aliased HAL.UInt32;
-- Ethernet DMA current host transmit buffer address register
DMACHTBAR : aliased HAL.UInt32;
-- Ethernet DMA current host receive buffer address register
DMACHRBAR : aliased HAL.UInt32;
end record
with Volatile;
for Ethernet_DMA_Peripheral use record
DMABMR at 16#0# range 0 .. 31;
DMATPDR at 16#4# range 0 .. 31;
DMARPDR at 16#8# range 0 .. 31;
DMARDLAR at 16#C# range 0 .. 31;
DMATDLAR at 16#10# range 0 .. 31;
DMASR at 16#14# range 0 .. 31;
DMAOMR at 16#18# range 0 .. 31;
DMAIER at 16#1C# range 0 .. 31;
DMAMFBOCR at 16#20# range 0 .. 31;
DMARSWTR at 16#24# range 0 .. 31;
DMACHTDR at 16#48# range 0 .. 31;
DMACHRDR at 16#4C# range 0 .. 31;
DMACHTBAR at 16#50# range 0 .. 31;
DMACHRBAR at 16#54# range 0 .. 31;
end record;
-- Ethernet: DMA controller operation
Ethernet_DMA_Periph : aliased Ethernet_DMA_Peripheral
with Import, Address => System'To_Address (16#40029000#);
-- Ethernet: media access control (MAC)
type Ethernet_MAC_Peripheral is record
-- Ethernet MAC configuration register
MACCR : aliased MACCR_Register;
-- Ethernet MAC frame filter register
MACFFR : aliased MACFFR_Register;
-- Ethernet MAC hash table high register
MACHTHR : aliased HAL.UInt32;
-- Ethernet MAC hash table low register
MACHTLR : aliased HAL.UInt32;
-- Ethernet MAC MII address register
MACMIIAR : aliased MACMIIAR_Register;
-- Ethernet MAC MII data register
MACMIIDR : aliased MACMIIDR_Register;
-- Ethernet MAC flow control register
MACFCR : aliased MACFCR_Register;
-- Ethernet MAC VLAN tag register
MACVLANTR : aliased MACVLANTR_Register;
-- Ethernet MAC PMT control and status register
MACPMTCSR : aliased MACPMTCSR_Register;
-- Ethernet MAC debug register
MACDBGR : aliased MACDBGR_Register;
-- Ethernet MAC interrupt status register
MACSR : aliased MACSR_Register;
-- Ethernet MAC interrupt mask register
MACIMR : aliased MACIMR_Register;
-- Ethernet MAC address 0 high register
MACA0HR : aliased MACA0HR_Register;
-- Ethernet MAC address 0 low register
MACA0LR : aliased HAL.UInt32;
-- Ethernet MAC address 1 high register
MACA1HR : aliased MACA1HR_Register;
-- Ethernet MAC address1 low register
MACA1LR : aliased HAL.UInt32;
-- Ethernet MAC address 2 high register
MACA2HR : aliased MACA2HR_Register;
-- Ethernet MAC address 2 low register
MACA2LR : aliased MACA2LR_Register;
-- Ethernet MAC address 3 high register
MACA3HR : aliased MACA3HR_Register;
-- Ethernet MAC address 3 low register
MACA3LR : aliased HAL.UInt32;
end record
with Volatile;
for Ethernet_MAC_Peripheral use record
MACCR at 16#0# range 0 .. 31;
MACFFR at 16#4# range 0 .. 31;
MACHTHR at 16#8# range 0 .. 31;
MACHTLR at 16#C# range 0 .. 31;
MACMIIAR at 16#10# range 0 .. 31;
MACMIIDR at 16#14# range 0 .. 31;
MACFCR at 16#18# range 0 .. 31;
MACVLANTR at 16#1C# range 0 .. 31;
MACPMTCSR at 16#2C# range 0 .. 31;
MACDBGR at 16#34# range 0 .. 31;
MACSR at 16#38# range 0 .. 31;
MACIMR at 16#3C# range 0 .. 31;
MACA0HR at 16#40# range 0 .. 31;
MACA0LR at 16#44# range 0 .. 31;
MACA1HR at 16#48# range 0 .. 31;
MACA1LR at 16#4C# range 0 .. 31;
MACA2HR at 16#50# range 0 .. 31;
MACA2LR at 16#54# range 0 .. 31;
MACA3HR at 16#58# range 0 .. 31;
MACA3LR at 16#5C# range 0 .. 31;
end record;
-- Ethernet: media access control (MAC)
Ethernet_MAC_Periph : aliased Ethernet_MAC_Peripheral
with Import, Address => System'To_Address (16#40028000#);
-- Ethernet: MAC management counters
type Ethernet_MMC_Peripheral is record
-- Ethernet MMC control register
MMCCR : aliased MMCCR_Register;
-- Ethernet MMC receive interrupt register
MMCRIR : aliased MMCRIR_Register;
-- Ethernet MMC transmit interrupt register
MMCTIR : aliased MMCTIR_Register;
-- Ethernet MMC receive interrupt mask register
MMCRIMR : aliased MMCRIMR_Register;
-- Ethernet MMC transmit interrupt mask register
MMCTIMR : aliased MMCTIMR_Register;
-- Ethernet MMC transmitted good frames after a single collision counter
MMCTGFSCCR : aliased HAL.UInt32;
-- Ethernet MMC transmitted good frames after more than a single
-- collision
MMCTGFMSCCR : aliased HAL.UInt32;
-- Ethernet MMC transmitted good frames counter register
MMCTGFCR : aliased HAL.UInt32;
-- Ethernet MMC received frames with CRC error counter register
MMCRFCECR : aliased HAL.UInt32;
-- Ethernet MMC received frames with alignment error counter register
MMCRFAECR : aliased HAL.UInt32;
-- MMC received good unicast frames counter register
MMCRGUFCR : aliased HAL.UInt32;
end record
with Volatile;
for Ethernet_MMC_Peripheral use record
MMCCR at 16#0# range 0 .. 31;
MMCRIR at 16#4# range 0 .. 31;
MMCTIR at 16#8# range 0 .. 31;
MMCRIMR at 16#C# range 0 .. 31;
MMCTIMR at 16#10# range 0 .. 31;
MMCTGFSCCR at 16#4C# range 0 .. 31;
MMCTGFMSCCR at 16#50# range 0 .. 31;
MMCTGFCR at 16#68# range 0 .. 31;
MMCRFCECR at 16#94# range 0 .. 31;
MMCRFAECR at 16#98# range 0 .. 31;
MMCRGUFCR at 16#C4# range 0 .. 31;
end record;
-- Ethernet: MAC management counters
Ethernet_MMC_Periph : aliased Ethernet_MMC_Peripheral
with Import, Address => System'To_Address (16#40028100#);
-- Ethernet: Precision time protocol
type Ethernet_PTP_Peripheral is record
-- Ethernet PTP time stamp control register
PTPTSCR : aliased PTPTSCR_Register;
-- Ethernet PTP subsecond increment register
PTPSSIR : aliased PTPSSIR_Register;
-- Ethernet PTP time stamp high register
PTPTSHR : aliased HAL.UInt32;
-- Ethernet PTP time stamp low register
PTPTSLR : aliased PTPTSLR_Register;
-- Ethernet PTP time stamp high update register
PTPTSHUR : aliased HAL.UInt32;
-- Ethernet PTP time stamp low update register
PTPTSLUR : aliased PTPTSLUR_Register;
-- Ethernet PTP time stamp addend register
PTPTSAR : aliased HAL.UInt32;
-- Ethernet PTP target time high register
PTPTTHR : aliased HAL.UInt32;
-- Ethernet PTP target time low register
PTPTTLR : aliased HAL.UInt32;
-- Ethernet PTP time stamp status register
PTPTSSR : aliased PTPTSSR_Register;
-- Ethernet PTP PPS control register
PTPPPSCR : aliased PTPPPSCR_Register;
end record
with Volatile;
for Ethernet_PTP_Peripheral use record
PTPTSCR at 16#0# range 0 .. 31;
PTPSSIR at 16#4# range 0 .. 31;
PTPTSHR at 16#8# range 0 .. 31;
PTPTSLR at 16#C# range 0 .. 31;
PTPTSHUR at 16#10# range 0 .. 31;
PTPTSLUR at 16#14# range 0 .. 31;
PTPTSAR at 16#18# range 0 .. 31;
PTPTTHR at 16#1C# range 0 .. 31;
PTPTTLR at 16#20# range 0 .. 31;
PTPTSSR at 16#28# range 0 .. 31;
PTPPPSCR at 16#2C# range 0 .. 31;
end record;
-- Ethernet: Precision time protocol
Ethernet_PTP_Periph : aliased Ethernet_PTP_Peripheral
with Import, Address => System'To_Address (16#40028700#);
end STM32_SVD.Ethernet;
|
AdaCore/libadalang | Ada | 620 | adb | procedure Test is
-- ProtectedTypeDecl
protected type T is
entry E;
private
N : Natural;
end T;
protected body T is
entry E when True is
begin
N := 1;
pragma Test_Statement;
T.N := 1;
pragma Test_Statement;
end E;
end T;
-- SingleProtectedDecl
protected P is
entry E;
private
N : Natural;
end P;
protected body P is
entry E when True is
begin
N := 1;
pragma Test_Statement;
P.N := 1;
pragma Test_Statement;
end E;
end P;
begin
null;
end Test;
|
pmderodat/sdlada | Ada | 4,015 | adb | --------------------------------------------------------------------------------------------------------------------
-- Copyright (c) 2013-2018 Luke A. Guest
--
-- 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.
--------------------------------------------------------------------------------------------------------------------
package body SDL.Video.Displays is
use type C.int;
function Closest_Mode (Display : in Natural; Wanted : in Mode; Target : out Mode) return Boolean is
function SDL_Get_Closest_Display_Mode (D : C.int; W : in Mode; T : out Mode) return Access_Mode with
Import => True,
Convention => C,
External_Name => "SDL_GetClosestDisplayMode";
Result : Access_Mode := SDL_Get_Closest_Display_Mode (C.int (Display), Wanted, Target);
begin
return (Result = null);
end Closest_Mode;
function Current_Mode (Display : in Natural; Target : out Mode) return Boolean is
function SDL_Get_Current_Display_Mode (D : C.int; M : out Mode) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetCurrentDisplayMode";
Result : C.int := SDL_Get_Current_Display_Mode (C.int (Display), Target);
begin
return (Result = Success);
end Current_Mode;
function Desktop_Mode (Display : in Natural; Target : out Mode) return Boolean is
function SDL_Get_Desktop_Display_Mode (D : C.int; M : out Mode) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetDesktopDisplayMode";
Result : C.int := SDL_Get_Desktop_Display_Mode (C.int (Display), Target);
begin
return (Result = Success);
end Desktop_Mode;
function Display_Mode (Display : in Natural; Index : in Natural; Target : out Mode) return Boolean is
function SDL_Get_Display_Mode (D : in C.int; I : in C.int; T : out Mode) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetDisplayMode";
Result : C.int := SDL_Get_Display_Mode (C.int (Display), C.int (Index), Target);
begin
return (Result = Success);
end Display_Mode;
function Total_Display_Modes (Display : in Natural; Total : out Positive) return Boolean is
function SDL_Get_Num_Display_Modes (I : in C.int) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetNumDisplayModes";
Result : C.int := SDL_Get_Num_Display_Modes (C.int (Display));
begin
if Result >= 1 then
Total := Positive (Result);
return True;
end if;
return False;
end Total_Display_Modes;
function Display_Bounds (Display : in Natural; Bounds : out Rectangles.Rectangle) return Boolean is
function SDL_Get_Display_Bounds (D : in C.int; B : out Rectangles.Rectangle) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetDisplayBounds";
Result : C.int := SDL_Get_Display_Bounds (C.int (Display), Bounds);
begin
return (Result = Success);
end Display_Bounds;
end SDL.Video.Displays;
|
reznikmm/matreshka | Ada | 4,059 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- 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 ODF.DOM.Style_Page_Layout_Name_Attributes;
package Matreshka.ODF_Style.Page_Layout_Name_Attributes is
type Style_Page_Layout_Name_Attribute_Node is
new Matreshka.ODF_Style.Abstract_Style_Attribute_Node
and ODF.DOM.Style_Page_Layout_Name_Attributes.ODF_Style_Page_Layout_Name_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Style_Page_Layout_Name_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Style_Page_Layout_Name_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Style.Page_Layout_Name_Attributes;
|
charlie5/cBound | Ada | 1,626 | ads | -- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces;
with swig;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_ge_event_t is
-- Item
--
type Item is record
response_type : aliased Interfaces.Unsigned_8;
pad0 : aliased Interfaces.Unsigned_8;
sequence : aliased Interfaces.Unsigned_16;
length : aliased Interfaces.Unsigned_32;
event_type : aliased Interfaces.Unsigned_16;
pad1 : aliased Interfaces.Unsigned_16;
pad : aliased swig.uint32_t_Array (0 .. 4);
full_sequence : aliased Interfaces.Unsigned_32;
end record;
-- Item_Array
--
type Item_Array is
array (Interfaces.C.size_t range <>) of aliased xcb.xcb_ge_event_t.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_ge_event_t.Item,
Element_Array => xcb.xcb_ge_event_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C.size_t range <>) of aliased xcb.xcb_ge_event_t.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_ge_event_t.Pointer,
Element_Array => xcb.xcb_ge_event_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_ge_event_t;
|
zhmu/ananas | Ada | 3,895 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . P A C K _ 7 0 --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2022, 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. --
-- --
------------------------------------------------------------------------------
-- Handling of packed arrays with Component_Size = 70
package System.Pack_70 is
pragma Preelaborate;
Bits : constant := 70;
type Bits_70 is mod 2 ** Bits;
for Bits_70'Size use Bits;
-- In all subprograms below, Rev_SSO is set True if the array has the
-- non-default scalar storage order.
function Get_70
(Arr : System.Address;
N : Natural;
Rev_SSO : Boolean) return Bits_70 with Inline;
-- Arr is the address of the packed array, N is the zero-based
-- subscript. This element is extracted and returned.
procedure Set_70
(Arr : System.Address;
N : Natural;
E : Bits_70;
Rev_SSO : Boolean) with Inline;
-- Arr is the address of the packed array, N is the zero-based
-- subscript. This element is set to the given value.
function GetU_70
(Arr : System.Address;
N : Natural;
Rev_SSO : Boolean) return Bits_70 with Inline;
-- Arr is the address of the packed array, N is the zero-based
-- subscript. This element is extracted and returned. This version
-- is used when Arr may represent an unaligned address.
procedure SetU_70
(Arr : System.Address;
N : Natural;
E : Bits_70;
Rev_SSO : Boolean) with Inline;
-- Arr is the address of the packed array, N is the zero-based
-- subscript. This element is set to the given value. This version
-- is used when Arr may represent an unaligned address
end System.Pack_70;
|
charlie5/cBound | Ada | 1,429 | ads | -- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces.C;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_get_window_attributes_cookie_t is
-- Item
--
type Item is record
sequence : aliased Interfaces.C.unsigned;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_get_window_attributes_cookie_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_get_window_attributes_cookie_t.Item,
Element_Array => xcb.xcb_get_window_attributes_cookie_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_get_window_attributes_cookie_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_get_window_attributes_cookie_t.Pointer,
Element_Array => xcb.xcb_get_window_attributes_cookie_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_get_window_attributes_cookie_t;
|
reznikmm/matreshka | Ada | 3,773 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- 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$
------------------------------------------------------------------------------
package Matreshka.ODF_Attributes.Style.Num_Format is
type Style_Num_Format_Node is
new Matreshka.ODF_Attributes.Style.Style_Node_Base with null record;
type Style_Num_Format_Access is access all Style_Num_Format_Node'Class;
overriding function Get_Local_Name
(Self : not null access constant Style_Num_Format_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Attributes.Style.Num_Format;
|
AdaCore/training_material | Ada | 1,935 | adb | with Ada.Text_IO; use Ada.Text_IO;
package body Queens_Pkg is
procedure Generate (Count : Positive) is
Board : array (1 .. Count, 1 .. Count) of Boolean :=
(others =>
(others => False));
function Test
(Row, Column : Integer)
return Boolean is
begin
for J in 1 .. Column - 1
loop
if
(Board (Row, J)
or else (Row > J and then Board (Row - J, Column - J))
or else (Row + J <= Count and then Board (Row + J, Column - J)))
then
return False;
end if;
end loop;
return True;
end Test;
function Fill
(Column : Integer)
return Boolean is
begin
for Row in Board'range (1)
loop
if Test (Row, Column)
then
Board (Row, Column) := True;
if Column = Count or else Fill (Column + 1)
then
return True;
end if;
Board (Row, Column) := False;
end if;
end loop;
return False;
end Fill;
begin
if not Fill (1)
then
raise Program_Error;
end if;
for I in Board'range (1)
loop
Put (Integer'image (Count + 1 - I));
for J in Board'range (2)
loop
if Board (I, J)
then
Put ("|Q");
elsif (I + J) mod 2 = 1
then
Put ("|/");
else
Put ("| ");
end if;
end loop;
Put_Line ("|");
end loop;
declare
Col : Character := 'A';
begin
Put (" ");
for I in 1 .. Count
loop
Put (Col & " ");
Col := Character'succ (Col);
end loop;
New_Line;
end;
end Generate;
end Queens_Pkg;
|
stcarrez/ada-ado | Ada | 4,942 | ads | -----------------------------------------------------------------------
-- ado-sessions-factory -- Session Factory
-- Copyright (C) 2009, 2010, 2011, 2012, 2015, 2017, 2018 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 ADO.Sequences;
with ADO.Caches;
with ADO.Audits;
with ADO.Sessions.Sources;
-- == Session Factory ==
-- The session factory is the entry point to obtain a database session.
-- The `ADO.Sessions.Factory` package defines the factory for creating
-- sessions.
--
-- with ADO.Sessions.Factory;
-- ...
-- Sess_Factory : ADO.Sessions.Factory;
--
-- The session factory can be initialized by using the `Create` operation and
-- by giving a URI string that identifies the driver and the information to connect
-- to the database. The session factory is created only once when the application starts.
--
-- ADO.Sessions.Factory.Create (Sess_Factory, "mysql://localhost:3306/ado_test?user=test");
--
-- Having a session factory, one can get a database by using the `Get_Session` or
-- `Get_Master_Session` function. Each time this operation is called, a new session
-- is returned. The session is released when the session variable is finalized.
--
-- DB : ADO.Sessions.Session := Sess_Factory.Get_Session;
--
-- The session factory is also responsible for maintaining some data that is shared by
-- all the database connections. This includes:
--
-- * the sequence generators used to allocate unique identifiers for database tables,
-- * the entity cache,
-- * some application specific global cache.
--
package ADO.Sessions.Factory is
pragma Elaborate_Body;
ENTITY_CACHE_NAME : constant String := "entity_type";
-- ------------------------------
-- Session factory
-- ------------------------------
type Session_Factory is tagged limited private;
type Session_Factory_Access is access all Session_Factory'Class;
-- Get a read-only session from the factory.
function Get_Session (Factory : in Session_Factory) return Session;
-- Get a read-write session from the factory.
function Get_Master_Session (Factory : in Session_Factory) return Master_Session;
-- Create the session factory to connect to the database represented
-- by the data source.
procedure Create (Factory : out Session_Factory;
Source : in ADO.Sessions.Sources.Data_Source);
-- Create the session factory to connect to the database identified
-- by the URI.
procedure Create (Factory : out Session_Factory;
URI : in String);
-- Get a read-only session from the session proxy.
-- If the session has been invalidated, raise the Session_Error exception.
function Get_Session (Proxy : in Session_Record_Access) return Session;
-- Set the audit manager to be used for the object auditing support.
procedure Set_Audit_Manager (Factory : in out Session_Factory;
Manager : in ADO.Audits.Audit_Manager_Access);
-- Set a static query loader to load SQL queries.
procedure Set_Query_Loader (Factory : in out Session_Factory;
Loader : in ADO.Queries.Static_Loader_Access);
private
-- The session factory holds the necessary information to obtain a master or slave
-- database connection. The sequence factory is shared by all sessions of the same
-- factory (implementation is thread-safe). The factory also contains the entity type
-- cache which is initialized when the factory is created.
type Session_Factory is tagged limited record
Source : ADO.Sessions.Sources.Data_Source;
Sequences : Factory_Access := null;
Seq_Factory : aliased ADO.Sequences.Factory;
-- Entity_Cache : aliased ADO.Schemas.Entities.Entity_Cache;
Entities : ADO.Sessions.Entity_Cache_Access := null;
Cache : aliased ADO.Caches.Cache_Manager;
Cache_Values : ADO.Caches.Cache_Manager_Access;
Queries : aliased ADO.Queries.Query_Manager;
Audit : ADO.Audits.Audit_Manager_Access;
end record;
-- Initialize the sequence factory associated with the session factory.
procedure Initialize_Sequences (Factory : in out Session_Factory);
end ADO.Sessions.Factory;
|
Fabien-Chouteau/GESTE | Ada | 627 | ads | with GESTE;
with Interfaces; use Interfaces;
generic
Width : Natural;
Height : Natural;
Pixel_Scale : Natural;
Buffer_Size : Positive;
package SDL_Display is
Screen_Rect : constant GESTE.Pix_Rect := ((0, 0), (Width - 1, Height - 1));
Buffer : GESTE.Output_Buffer (1 .. Buffer_Size);
procedure Push_Pixels (Pixels : GESTE.Output_Buffer);
procedure Set_Drawing_Area (Area : GESTE.Pix_Rect);
procedure Set_Screen_Offset (Pt : GESTE.Pix_Point);
procedure Update;
subtype SDL_Pixel is Unsigned_16;
function To_SDL_Color (R, G, B : Unsigned_8) return SDL_Pixel;
end SDL_Display;
|
stcarrez/ada-keystore | Ada | 1,822 | adb | -----------------------------------------------------------------------
-- akt-commands-set -- Set content in keystore
-- Copyright (C) 2019, 2023 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
package body AKT.Commands.Set is
-- ------------------------------
-- Insert a new value in the keystore.
-- ------------------------------
overriding
procedure Execute (Command : in out Command_Type;
Name : in String;
Args : in Argument_List'Class;
Context : in out Context_Type) is
pragma Unreferenced (Command);
begin
-- Open keystore without use workers because we expect small data.
Context.Open_Keystore (Args, Use_Worker => False);
if Args.Get_Count /= Context.First_Arg + 1 then
AKT.Commands.Usage (Args, Context, Name,
-("missing name and value to set"));
else
Context.Wallet.Set (Name => Args.Get_Argument (Context.First_Arg),
Content => Args.Get_Argument (Context.First_Arg + 1));
end if;
end Execute;
end AKT.Commands.Set;
|
RREE/build-avr-ada-toolchain | Ada | 3,808 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . S E C O N D A R Y _ S T A C K --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2011, 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. --
-- --
------------------------------------------------------------------------------
-- This version is a simplified edition of the original
-- System.Secondary_Stack from gcc-4.7 for use in single threaded AVR
-- applications.
with System.Storage_Elements;
package System.Secondary_Stack is
package SSE renames System.Storage_Elements;
Default_Secondary_Stack_Size : constant := 512;
-- Default size of a secondary stack
procedure SS_Init
(Stk : System.Address;
Size : Natural := Default_Secondary_Stack_Size);
-- Initialize the secondary stack with a main stack of the given Size.
procedure SS_Allocate
(Address : out System.Address;
Storage_Size : SSE.Storage_Count);
-- Allocate enough space for a 'Storage_Size' bytes object with Maximum
-- alignment. The address of the allocated space is returned in 'Address'
type Mark_Id is private;
-- Type used to mark the stack for mark/release processing
function SS_Mark return Mark_Id;
-- Return the Mark corresponding to the current state of the stack
procedure SS_Release (M : Mark_Id);
-- Restore the state of the stack corresponding to the mark M. If an
-- additional chunk have been allocated, it will never be freed during a
private
SS_Pool : Integer;
-- Unused entity that is just present to ease the sharing of the pool
-- mechanism for specific allocation/deallocation in the compiler
type Mark_Id is new SSE.Integer_Address;
end System.Secondary_Stack;
|
reznikmm/matreshka | Ada | 5,064 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Generic_Collections;
package AMF.UML.Typed_Elements.Collections is
pragma Preelaborate;
package UML_Typed_Element_Collections is
new AMF.Generic_Collections
(UML_Typed_Element,
UML_Typed_Element_Access);
type Set_Of_UML_Typed_Element is
new UML_Typed_Element_Collections.Set with null record;
Empty_Set_Of_UML_Typed_Element : constant Set_Of_UML_Typed_Element;
type Ordered_Set_Of_UML_Typed_Element is
new UML_Typed_Element_Collections.Ordered_Set with null record;
Empty_Ordered_Set_Of_UML_Typed_Element : constant Ordered_Set_Of_UML_Typed_Element;
type Bag_Of_UML_Typed_Element is
new UML_Typed_Element_Collections.Bag with null record;
Empty_Bag_Of_UML_Typed_Element : constant Bag_Of_UML_Typed_Element;
type Sequence_Of_UML_Typed_Element is
new UML_Typed_Element_Collections.Sequence with null record;
Empty_Sequence_Of_UML_Typed_Element : constant Sequence_Of_UML_Typed_Element;
private
Empty_Set_Of_UML_Typed_Element : constant Set_Of_UML_Typed_Element
:= (UML_Typed_Element_Collections.Set with null record);
Empty_Ordered_Set_Of_UML_Typed_Element : constant Ordered_Set_Of_UML_Typed_Element
:= (UML_Typed_Element_Collections.Ordered_Set with null record);
Empty_Bag_Of_UML_Typed_Element : constant Bag_Of_UML_Typed_Element
:= (UML_Typed_Element_Collections.Bag with null record);
Empty_Sequence_Of_UML_Typed_Element : constant Sequence_Of_UML_Typed_Element
:= (UML_Typed_Element_Collections.Sequence with null record);
end AMF.UML.Typed_Elements.Collections;
|
tum-ei-rcs/StratoX | Ada | 3,231 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2016, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of AdaCore nor the names of its contributors may --
-- be used to endorse or promote products derived from this software --
-- without specific prior written permission.
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
package body Cortex_M.Cache is
------------------
-- Clean_DCache --
------------------
procedure Clean_DCache (Start, Stop : System.Address)
is
pragma Unreferenced (Start, Stop);
begin
null;
end Clean_DCache;
------------------
-- Clean_DCache --
------------------
procedure Clean_DCache (Start : System.Address;
Len : Natural)
is
pragma Unreferenced (Start, Len);
begin
null;
end Clean_DCache;
procedure Invalidate_DCache
(Start : System.Address;
Len : Natural)
is
pragma Unreferenced (Start, Len);
begin
null;
end Invalidate_DCache;
procedure Clean_Invalidate_DCache
(Start : System.Address;
Len : Natural)
is
pragma Unreferenced (Start, Len);
begin
null;
end Clean_Invalidate_DCache;
end Cortex_M.Cache;
|
jrmarino/AdaBase | Ada | 1,620 | ads | -- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../../License.txt
with AdaBase.Interfaces.Driver;
-- with AdaBase.Connection.Base.Firebird;
with AdaBase.Statement;
with AdaBase.DataTypes;
package AdaBase.Driver.Base.Firebird is
package AID renames AdaBase.Interfaces.Driver;
-- package ACF renames AdaBase.Connection.Base.MySQL;
package AS renames AdaBase.Statement;
package AD renames AdaBase.DataTypes;
type Firebird_Driver is new Base_Driver and AID.iDriver with private;
overriding
procedure query_drop_table (driver : Firebird_Driver;
tables : String;
when_exists : Boolean := False;
cascade : Boolean := False);
overriding
procedure query_clear_table (driver : Firebird_Driver;
table : String);
overriding
function last_insert_id (driver : Firebird_Driver) return AD.TraxID;
overriding
function last_sql_state (driver : Firebird_Driver) return AD.TSqlState;
overriding
function last_error_info (driver : Firebird_Driver) return AD.Error_Info;
overriding
function query (driver : Firebird_Driver; sql : String)
return AS.Base'Class;
overriding
function execute (driver : Firebird_Driver; sql : String)
return AD.AffectedRows;
private
type Firebird_Driver is new Base_Driver and AID.iDriver with
record
null;
end record;
end AdaBase.Driver.Base.Firebird;
|
reznikmm/matreshka | Ada | 3,639 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Elements.Generic_Hash;
function AMF.Standard_Profile_L2.Traces.Hash is
new AMF.Elements.Generic_Hash (Standard_Profile_L2_Trace, Standard_Profile_L2_Trace_Access);
|
caqg/linux-home | Ada | 2,098 | ads | -- generated parser support file.
-- command line: wisitoken-bnf-generate.exe --generate LR1 Ada_Emacs re2c PROCESS gpr.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 Interfaces.C;
with WisiToken;
with System;
package gpr_re2c_c is
function New_Lexer
(Buffer : in System.Address;
Length : in Interfaces.C.size_t;
Verbosity : in Interfaces.C.int)
return System.Address
with Import => True,
Convention => C,
External_Name => "gpr_new_lexer";
-- Create the lexer object, passing it the full text to process.
procedure Free_Lexer (Lexer : in out System.Address)
with Import => True,
Convention => C,
External_Name => "gpr_free_lexer";
-- Free the lexer object
procedure Reset_Lexer (Lexer : in System.Address)
with Import => True,
Convention => C,
External_Name => "gpr_reset_lexer";
function Next_Token
(Lexer : in System.Address;
ID : out WisiToken.Token_ID;
Byte_Position : out Interfaces.C.size_t;
Byte_Length : out Interfaces.C.size_t;
Char_Position : out Interfaces.C.size_t;
Char_Length : out Interfaces.C.size_t;
Line_Start : out Interfaces.C.int)
return Interfaces.C.int
with Import => True,
Convention => C,
External_Name => "gpr_next_token";
end gpr_re2c_c;
|
pchapin/acrypto | Ada | 7,091 | adb | ---------------------------------------------------------------------------
-- FILE : aco-crypto-algorithms-sha1.adb
-- SUBJECT : Body of a package holding the raw SHA1 hash algorithm.
-- AUTHOR : (C) Copyright 2014 by Peter Chapin
--
-- Please send comments or bug reports to
--
-- Peter Chapin <[email protected]>
---------------------------------------------------------------------------
pragma SPARK_Mode(On);
with ACO.Bit_Operations;
with ACO.Quadruple_Octet_Operations;
with ACO.Octuple_Octet_Operations;
package body ACO.Crypto.Algorithms.SHA1 is
-- All_Checks is a little heavy handed. It includes things that SPARK's proofs don't cover (such as stack overflow).
-- The full list is long so this should probably just consider what is actually done in the code below.
-- Benchmark experiments show that the pragmas below actually slow the program down!
--pragma Suppress(Division_Check);
--pragma Suppress(Index_Check);
--pragma Suppress(Length_Check);
--pragma Suppress(Overflow_Check);
--pragma Suppress(Range_Check);
-- We can't just ignore everything because we want precondition checks on visible subprograms (called by non-SPARK units).
-- A full list is long so this should probably just consider what is actually done in the code below.
pragma Assertion_Policy
(Assert => Ignore,
Post => Ignore,
Loop_Invariant => Ignore);
type W_Index is range 0 .. 79;
type W_Array is array(W_Index) of ACO.Quadruple_Octet;
-- See FIPS 180-1 for the specifics of this function. The names used here reflect that source.
function F(T : W_Index; B, C, D : ACO.Quadruple_Octet) return ACO.Quadruple_Octet is
Result : ACO.Quadruple_Octet;
begin
case T is
when 0 .. 19 =>
Result := (B and C) or ((not B) and D);
when 20 .. 39 =>
Result := B xor C xor D;
when 40 .. 59 =>
Result := (B and C) or (B and D) or (C and D);
when 60 .. 79 =>
Result := B xor C xor D;
end case;
return Result;
end F;
-- This function returns a constant based on the value of T.
function K(T : W_Index) return ACO.Quadruple_Octet is
Result : ACO.Quadruple_Octet;
begin
case T is
when 0 .. 19 => Result := 16#5A827999#;
when 20 .. 39 => Result := 16#6ED9EBA1#;
when 40 .. 59 => Result := 16#8F1BBCDC#;
when 60 .. 79 => Result := 16#CA62C1D6#;
end case;
return Result;
end K;
procedure Prepare(S : out State) is
begin
S.Total_Bit_Count := 0;
S.H := (0 => 16#67452301#, 1 => 16#EFCDAB89#, 2 => 16#98BADCFE#, 3 => 16#10325476#, 4 => 16#C3D2E1F0#);
S.Active := True;
end Prepare;
procedure Internal_Update_Hash(S : in out State; M : in Message_Block)
with
Depends => (S => (S, M))
is
W : W_Array := W_Array'(others => 0);
Temp : ACO.Quadruple_Octet;
A, B, C, D, E : ACO.Quadruple_Octet;
begin
-- Part (a)
for T in W_Index range 0 .. 15 loop
W(T) := M(Block_Index(T));
end loop;
-- Part (b)
for T in W_Index range 16 .. 79 loop
W(T) := Quadruple_Octet_Operations.Rotate_Left(Value => W(T - 3) xor W(T - 8) xor W(T - 14) xor W(T - 16), Count => 1);
end loop;
-- Part (c)
A := S.H(0);
B := S.H(1);
C := S.H(2);
D := S.H(3);
E := S.H(4);
-- Part (d)
for T in W_Index range 0 .. 79 loop
Temp := Quadruple_Octet_Operations.Rotate_Left(Value => A, Count => 5);
Temp := Temp + F(T, B, C, D) + E + W(T) + K(T);
E := D;
D := C;
C := Quadruple_Octet_Operations.Rotate_Left(Value => B, Count => 30);
B := A;
A := Temp;
end loop;
-- Part (e)
S.H(0) := S.H(0) + A;
S.H(1) := S.H(1) + B;
S.H(2) := S.H(2) + C;
S.H(3) := S.H(3) + D;
S.H(4) := S.H(4) + E;
end Internal_Update_Hash;
procedure Update_Hash(S : in out State; M : in out Message_Block; Number_Of_Bits : in Message_Bit_Count) is
-- This procedure places a 1 bit at the end of the message and zeros out the rest of the message block. The message length
-- (in bits) must be put at the end of the block, but we must first verify that there is sufficient space. That step is
-- not handled here.
--
procedure Compute_Message_Padding
with
Global => (Input => Number_Of_Bits, In_Out => M),
Depends => (M =>+ Number_Of_Bits),
Pre => (Number_Of_Bits < Message_Bit_Count'Last)
is
Padding_Start_Word : Block_Index;
Padding_Offset : Natural;
Padding_On_Mask : ACO.Quadruple_Octet;
Padding_Off_Mask : ACO.Quadruple_Octet;
begin
Padding_Start_Word := Block_Index(Number_Of_Bits / 32);
Padding_Offset := (32 - (Number_Of_Bits mod 32)) - 1;
Padding_On_Mask := Quadruple_Octet_Operations.Shift_Left(16#00000001#, Padding_Offset);
Padding_Off_Mask := Quadruple_Octet_Operations.Shift_Left(16#FFFFFFFF#, Padding_Offset);
M(Padding_Start_Word) := M(Padding_Start_Word) or Padding_On_Mask;
M(Padding_Start_Word) := M(Padding_Start_Word) and Padding_Off_Mask;
for I in Padding_Start_Word + 1 .. Block_Index'Last loop
M(I) := 0;
end loop;
end Compute_Message_Padding;
begin -- Update_Hash
if S.Active then
-- TODO: If Total_Bit_Count wraps around, bad things will happen.
S.Total_Bit_Count := S.Total_Bit_Count + ACO.Octuple_Octet(Number_Of_Bits);
if Number_Of_Bits = Message_Bit_Count'Last then
Internal_Update_Hash(S, M);
else
-- If there ie enough space for the message length at the end of this block...
if Number_Of_Bits <= Message_Bit_Count'Last - 65 then
Compute_Message_Padding;
else
-- Otherwise put the message length in an empty block by itself.
Compute_Message_Padding;
Internal_Update_Hash(S, M);
M := Message_Block'(others => 0);
end if;
ACO.Bit_Operations.Split64_To_Word32(S.Total_Bit_Count, Most => M(14), Least => M(15));
Internal_Update_Hash(S, M);
S.Active := False; -- Sorry. Can't accept any more blocks after doing padding!
end if;
end if;
end Update_Hash;
procedure Partake(S : in out State; Result : out Hash_Array) is
M : Message_Block := (0 => 16#80000000#, others => 0); -- Used only if padding needed.
begin
-- If still active, that means the last block was exactly 512 bits. Pad now.
if S.Active then
ACO.Bit_Operations.Split64_To_Word32(S.Total_Bit_Count, Most => M(14), Least => M(15));
Internal_Update_Hash(S, M);
S.Active := False; -- Sorry. Can't accept any more blocks after doing padding!
end if;
Result := S.H;
end Partake;
end ACO.Crypto.Algorithms.SHA1;
|
zhmu/ananas | Ada | 4,139 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- R E P I N F O - I N P U T --
-- --
-- S p e c --
-- --
-- Copyright (C) 2018-2022, 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. --
-- --
------------------------------------------------------------------------------
-- This package provides an alternate way of populating the internal tables
-- of Repinfo from a JSON input rather than the binary blob of the tree file.
-- Note that this is an additive mechanism, i.e. nothing is destroyed in the
-- internal state of the unit when it is used.
-- The first step is to feed the unit with a JSON stream of a specified format
-- (see the spec of Repinfo for its description) by means of Read_JSON_Stream.
-- Then, for each entity whose representation information is present in the
-- JSON stream, the appropriate Get_JSON_* routines can be invoked to override
-- the eponymous fields of the entity in the tree.
package Repinfo.Input is
function Get_JSON_Esize (Name : String) return Node_Ref_Or_Val;
-- Returns the Esize value of the entity specified by Name, which is not
-- the component of a record type, or else No_Uint if no representation
-- information was supplied for the entity. Name is the full qualified name
-- of the entity in lower case letters.
function Get_JSON_RM_Size (Name : String) return Node_Ref_Or_Val;
-- Likewise for the RM_Size
function Get_JSON_Component_Size (Name : String) return Node_Ref_Or_Val;
-- Likewise for the Component_Size of an array type
function Get_JSON_Component_Bit_Offset
(Name : String;
Record_Name : String) return Node_Ref_Or_Val;
-- Returns the Component_Bit_Offset of the component specified by Name,
-- which is declared in the record type specified by Record_Name, or else
-- No_Uint if no representation information was supplied for the component.
-- Name is the unqualified name of the component whereas Record_Name is the
-- full qualified name of the record type, both in lower case letters.
function Get_JSON_Esize
(Name : String;
Record_Name : String) return Node_Ref_Or_Val;
-- Likewise for the Esize
Invalid_JSON_Stream : exception;
-- Raised if a format error is detected in the JSON stream
procedure Read_JSON_Stream (Text : Text_Buffer; File_Name : String);
-- Reads a JSON stream and populates internal tables from it. File_Name is
-- only used in error messages issued by the JSON parser.
end Repinfo.Input;
|
AdaCore/gpr | Ada | 170 | adb | --
-- Copyright (C) 2019-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0
--
with Pkg1;
with Pkg2;
procedure Main is
begin
Pkg1.Sep;
Pkg2.Sep;
end Main;
|
RREE/ada-util | Ada | 19,982 | adb | -----------------------------------------------------------------------
-- util-log-loggers -- Utility Log Package
-- Copyright (C) 2001 - 2019, 2021 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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;
with Ada.Strings.Fixed;
with Ada.Calendar;
with Ada.Unchecked_Deallocation;
with Ada.IO_Exceptions;
with Util.Strings;
with Util.Strings.Builders;
with Util.Strings.Formats;
with Util.Log.Appenders.Factories;
with Util.Log.Appenders.Consoles;
with Util.Log.Appenders.Files;
package body Util.Log.Loggers is
use Ada.Strings;
use Ada.Strings.Fixed;
use Log.Appenders;
function Traceback (E : in Exception_Occurrence) return String is separate;
package File_Factory is
new Util.Log.Appenders.Factories (Name => "File",
Create => Files.Create'Access);
package Console_Factory is
new Util.Log.Appenders.Factories (Name => "Console",
Create => Consoles.Create'Access);
-- The log manager controls the configuration of loggers.
-- The log appenders are shared by loggers and they are created by
-- the log manager when a logger is created.
--
protected type Log_Manager is
-- Initialize the log environment with the property file.
procedure Initialize (Name : in String);
-- Initialize the log environment with the property file.
procedure Initialize (Properties : in Util.Properties.Manager);
-- Create and initialize the logger
procedure Create (Name : in String;
Log : out Logger_Info_Access);
-- Remove the logger from the list
procedure Remove (Log : in out Logger_Info_Access);
private
-- Initialize the logger by reading the configuration, setting its level
-- and creating the appender
procedure Initialize (Log : in out Logger_Info);
-- Re-initializes the loggers after the configuration is changed.
procedure Initialize_Again;
-- Find the appender to be used for the given logger.
-- Create the appender if necessary.
procedure Find_Appender (Property : in String;
Appender : out Appender_Access);
-- Obtain an appender given its name. If the appender does not exist, it is created.
procedure Build_Appender (Name : in String;
Appender : out Appender_Access);
procedure Create_Default_Appender;
Config : Properties.Manager;
Appenders : Log.Appenders.Appender_List;
Default_Level : Level_Type := WARN_LEVEL;
Default_Appender : Log.Appenders.Appender_Access := null;
First_Logger : Logger_Info_Access := null;
end Log_Manager;
Manager : Log_Manager;
function Get_Appender (Value : in String) return String with Inline_Always;
-- Get the logger property associated with a given logger
function Get_Logger_Property (Properties : in Util.Properties.Manager;
Name : in String) return String;
-- ------------------------------
-- Get the log appender name from the property value
-- ------------------------------
function Get_Appender (Value : in String) return String is
Pos : constant Natural := Index (Value, ",");
begin
if Pos <= Value'First or Pos >= Value'Last then
return "";
else
return Trim (Value (Pos + 1 .. Value'Last), Both);
end if;
end Get_Appender;
-- ------------------------------
-- Get the logger property associated with a given logger
-- ------------------------------
function Get_Logger_Property (Properties : in Util.Properties.Manager;
Name : in String) return String is
Prop_Name : constant String := "logger." & Name;
Pos : Natural := Prop_Name'Last;
begin
while Pos > Prop_Name'First loop
if Properties.Exists (Prop_Name (Prop_Name'First .. Pos)) then
return Trim (Properties.Get (Prop_Name (Prop_Name'First .. Pos)), Both);
end if;
Pos := Util.Strings.Rindex (Prop_Name, '.', Pos);
if Pos > 0 then
Pos := Pos - 1;
end if;
end loop;
return "";
end Get_Logger_Property;
-- ------------------------------
-- Initialize the log environment with the property file.
-- ------------------------------
procedure Initialize (Name : in String) is
begin
Manager.Initialize (Name);
end Initialize;
-- ------------------------------
-- Initialize the log environment with the properties.
-- ------------------------------
procedure Initialize (Properties : in Util.Properties.Manager) is
begin
Manager.Initialize (Properties);
end Initialize;
protected body Log_Manager is
-- ------------------------------
-- Initialize the log environment with the property file.
-- ------------------------------
procedure Initialize (Name : in String) is
begin
Util.Properties.Load_Properties (Config, Path => Name, Prefix => "log4j.", Strip => True);
Initialize_Again;
exception
when Ada.IO_Exceptions.Name_Error =>
declare
Message : Util.Strings.Builders.Builder (256);
Date : constant Ada.Calendar.Time := Ada.Calendar.Clock;
begin
Strings.Formats.Format (Message, "Log configuration file {0} not found", Name);
if Default_Appender = null then
Create_Default_Appender;
end if;
Default_Appender.Append (Message, Date, WARN_LEVEL, "Util.Log");
end;
end Initialize;
-- ------------------------------
-- Re-initializes the loggers after the configuration is changed.
-- ------------------------------
procedure Initialize_Again is
L : Logger_Info_Access := First_Logger;
begin
Util.Log.Appenders.Clear (Appenders);
Default_Appender := null;
-- Initialize the default category.
if Config.Exists ("rootCategory") then
declare
Value : constant String := Config.Get ("rootCategory");
begin
Default_Level := Get_Level (Value, Default_Level);
Find_Appender (Property => Value, Appender => Default_Appender);
end;
end if;
if Default_Appender = null then
Create_Default_Appender;
end if;
-- Re-initialize the existing loggers. Note that there is no concurrency
-- protection if a thread calls 'Initialize' while another thread is using
-- an already initialized logger.
while L /= null loop
Initialize (L.all);
L := L.Next_Logger;
end loop;
end Initialize_Again;
-- ------------------------------
-- Initialize the log environment with the properties.
-- ------------------------------
procedure Initialize (Properties : in Util.Properties.Manager) is
New_Config : Util.Properties.Manager;
begin
New_Config.Copy (From => Properties, Prefix => "log4j.", Strip => True);
Config := New_Config;
Initialize_Again;
end Initialize;
-- ------------------------------
-- Initialize the logger by reading the configuration, setting its level
-- and creating the appender
-- ------------------------------
procedure Initialize (Log : in out Logger_Info) is
Prop : constant String := Get_Logger_Property (Config, Log.Name);
Appender : Appender_Access;
begin
Log.Level := Get_Level (Prop, Default_Level);
Find_Appender (Prop, Appender);
if Appender /= null then
Log.Appender := Appender.all'Access;
end if;
end Initialize;
-- ------------------------------
-- Create and initialize the logger
-- ------------------------------
procedure Create (Name : in String;
Log : out Logger_Info_Access) is
begin
Log := new Logger_Info (Len => Name'Length);
Log.Name := Name;
Initialize (Log.all);
Log.Next_Logger := First_Logger;
Log.Prev_Logger := null;
if First_Logger /= null then
First_Logger.Prev_Logger := Log;
end if;
First_Logger := Log;
end Create;
-- ------------------------------
-- Remove the logger from the list
-- ------------------------------
procedure Remove (Log : in out Logger_Info_Access) is
procedure Free is new Ada.Unchecked_Deallocation (Object => Logger_Info,
Name => Logger_Info_Access);
begin
-- Remove first logger
if Log = First_Logger then
First_Logger := First_Logger.Next_Logger;
if First_Logger /= null then
First_Logger.Prev_Logger := null;
end if;
-- Remove last logger
elsif Log.Next_Logger = null then
Log.Prev_Logger.Next_Logger := null;
else
Log.Next_Logger.Prev_Logger := Log.Prev_Logger;
Log.Prev_Logger.Next_Logger := Log.Next_Logger;
end if;
Free (Log);
end Remove;
-- ------------------------------
-- Obtain an appender given its name. If the appender does not exist, it is created.
-- ------------------------------
procedure Build_Appender (Name : in String;
Appender : out Appender_Access) is
begin
Appender := Util.Log.Appenders.Find_Appender (Appenders, Name);
if Appender /= null then
return;
end if;
if Name'Length > 0 then
Appender := Util.Log.Appenders.Create (Name, Config, Default_Level);
if Appender /= null then
Util.Log.Appenders.Add_Appender (Appenders, Appender);
end if;
end if;
end Build_Appender;
procedure Create_Default_Appender is
begin
if Default_Appender = null then
Default_Appender := Consoles.Create ("root", Config, ERROR_LEVEL);
Set_Layout (Default_Appender.all, MESSAGE);
Util.Log.Appenders.Add_Appender (Appenders, Default_Appender);
end if;
end Create_Default_Appender;
-- ------------------------------
-- Find an appender given the property value
-- ------------------------------
procedure Find_Appender (Property : in String;
Appender : out Appender_Access) is
Appender_Name : constant String := Get_Appender (Property);
begin
if Appender_Name'Length = 0 then
Appender := Default_Appender;
if Appender = null then
Create_Default_Appender;
Appender := Default_Appender;
end if;
return;
end if;
Appender := Util.Log.Appenders.Find_Appender (Appenders, Appender_Name);
if Appender /= null then
return;
end if;
declare
N : Natural := Index (Appender_Name, ",");
Last_Pos : Natural := Appender_Name'First;
List : List_Appender_Access;
A : Appender_Access;
begin
-- The appender configuration refers to a list of appenders.
-- Example: DEBUG, out1, console
if N > 0 then
List := Create_List_Appender (Appender_Name);
loop
Build_Appender (Trim (Appender_Name (Last_Pos .. N - 1), Both), A);
exit when A = null;
List.Add_Appender (A);
exit when N > Appender_Name'Last;
Last_Pos := N + 1;
N := Ada.Strings.Fixed.Index (Appender_Name, ",", Last_Pos);
if N = 0 then
N := Appender_Name'Last + 1;
end if;
end loop;
Appender := List.all'Access;
Util.Log.Appenders.Add_Appender (Appenders, Appender);
else
Build_Appender (Appender_Name, Appender);
end if;
end;
end Find_Appender;
end Log_Manager;
-- ------------------------------
-- Create a logger with the given name.
-- ------------------------------
function Create (Name : in String) return Logger is
Log : Logger_Info_Access;
begin
Manager.Create (Name, Log);
return Logger '(Ada.Finalization.Limited_Controlled with
Instance => Log);
end Create;
-- ------------------------------
-- Create a logger with the given name and use the specified level.
-- ------------------------------
function Create (Name : in String;
Level : in Level_Type) return Logger is
Log : Logger_Info_Access;
begin
Manager.Create (Name, Log);
Log.Level := Level;
return Logger '(Ada.Finalization.Limited_Controlled with
Instance => Log);
end Create;
-- ------------------------------
-- Change the log level
-- ------------------------------
procedure Set_Level (Log : in out Logger;
Level : in Level_Type) is
begin
Log.Instance.Level := Level;
end Set_Level;
-- ------------------------------
-- Get the log level.
-- ------------------------------
function Get_Level (Log : in Logger) return Level_Type is
begin
return Log.Instance.Level;
end Get_Level;
-- ------------------------------
-- Get the log level name.
-- ------------------------------
function Get_Level_Name (Log : in Logger) return String is
begin
return Get_Level_Name (Log.Instance.Level);
end Get_Level_Name;
procedure Print (Log : in Logger;
Level : in Level_Type;
Message : in String;
Arg1 : in String := "";
Arg2 : in String := "";
Arg3 : in String := "";
Arg4 : in String := "") is
Instance : constant Logger_Info_Access := Log.Instance;
begin
if Instance /= null and then Instance.Level >= Level then
declare
Result : Util.Strings.Builders.Builder (256);
Date : constant Ada.Calendar.Time := Ada.Calendar.Clock;
begin
Strings.Formats.Format (Result, Message, Arg1, Arg2, Arg3, Arg4);
Instance.Appender.Append (Result, Date, Level, Instance.Name);
end;
end if;
end Print;
procedure Debug (Log : in Logger'Class;
Message : in String;
Arg1 : in String := "";
Arg2 : in String := "";
Arg3 : in String := "") is
begin
Print (Log, DEBUG_LEVEL, Message, Arg1, Arg2, Arg3);
end Debug;
procedure Debug (Log : in Logger'Class;
Message : in String;
Arg1 : in String;
Arg2 : in String;
Arg3 : in String;
Arg4 : in String) is
begin
Print (Log, DEBUG_LEVEL, Message, Arg1, Arg2, Arg3, Arg4);
end Debug;
procedure Debug (Log : in Logger'Class;
Message : in String;
Arg1 : in Unbounded_String;
Arg2 : in String := "";
Arg3 : in String := "") is
begin
if Log.Instance /= null and then Log.Instance.Level >= DEBUG_LEVEL then
Print (Log, DEBUG_LEVEL, Message, To_String (Arg1), Arg2, Arg3);
end if;
end Debug;
procedure Debug (Log : in Logger'Class;
Message : in String;
Arg1 : in Unbounded_String;
Arg2 : in Unbounded_String;
Arg3 : in String := "") is
begin
if Log.Instance /= null and then Log.Instance.Level >= DEBUG_LEVEL then
Print (Log, DEBUG_LEVEL, Message, To_String (Arg1), To_String (Arg2), Arg3);
end if;
end Debug;
procedure Info (Log : in Logger'Class;
Message : in String;
Arg1 : in String := "";
Arg2 : in String := "";
Arg3 : in String := "") is
begin
Print (Log, INFO_LEVEL, Message, Arg1, Arg2, Arg3);
end Info;
procedure Info (Log : in Logger'Class;
Message : in String;
Arg1 : in String;
Arg2 : in String;
Arg3 : in String;
Arg4 : in String) is
begin
Print (Log, INFO_LEVEL, Message, Arg1, Arg2, Arg3, Arg4);
end Info;
procedure Info (Log : in Logger'Class;
Message : in String;
Arg1 : in Unbounded_String;
Arg2 : in String := "";
Arg3 : in String := "") is
begin
if Log.Instance /= null and then Log.Instance.Level >= INFO_LEVEL then
Print (Log, INFO_LEVEL, Message, To_String (Arg1), Arg2, Arg3);
end if;
end Info;
procedure Warn (Log : in Logger'Class;
Message : in String;
Arg1 : in String := "";
Arg2 : in String := "";
Arg3 : in String := "") is
begin
if Log.Instance /= null and then Log.Instance.Level >= WARN_LEVEL then
Print (Log, WARN_LEVEL, Message, Arg1, Arg2, Arg3);
end if;
end Warn;
procedure Error (Log : in Logger'Class;
Message : in String;
Arg1 : in String := "";
Arg2 : in String := "";
Arg3 : in String := "") is
begin
Print (Log, ERROR_LEVEL, Message, Arg1, Arg2, Arg3);
end Error;
procedure Error (Log : in Logger'Class;
Message : in String;
E : in Exception_Occurrence;
Trace : in Boolean := False) is
begin
if Trace then
Print (Log, ERROR_LEVEL,
"{0}: Exception {1}: {2} at {3}",
Message,
Exception_Name (E),
Exception_Message (E),
Traceback (E));
else
Print (Log, ERROR_LEVEL,
"{0}: Exception {1}: {2}",
Message,
Exception_Name (E),
Exception_Message (E));
end if;
end Error;
-- ------------------------------
-- Finalize the logger and flush the associated appender
-- ------------------------------
procedure Finalize (Log : in out Logger) is
begin
if Log.Instance.Appender /= null then
Log.Instance.Appender.Flush;
end if;
Manager.Remove (Log.Instance);
end Finalize;
begin
Console_Factory.Register;
File_Factory.Register;
end Util.Log.Loggers;
|
stcarrez/ada-asf | Ada | 1,570 | ads | -----------------------------------------------------------------------
-- components-utils-beans -- Bean component utility
-- Copyright (C) 2011 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 ASF.Components.Core;
with ASF.Contexts.Faces;
package ASF.Components.Utils.Beans is
-- ------------------------------
-- UISetBean
-- ------------------------------
-- The <b>UISetBean</b> component is a helper bean used to evaluate an EL expression
-- and save the result in another bean or variable.
type UISetBean is new ASF.Components.Core.UILeaf with null record;
-- Evaluate the <b>value</b> attribute and set it in the value expression
-- referred to by the <b>var</b> attribute.
overriding
procedure Encode_Begin (UI : in UISetBean;
Context : in out ASF.Contexts.Faces.Faces_Context'Class);
end ASF.Components.Utils.Beans;
|
zhmu/ananas | Ada | 6,647 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . A T O M I C _ P R I M I T I V E S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2012-2022, 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. --
-- --
------------------------------------------------------------------------------
-- This package contains both atomic primitives defined from GCC built-in
-- functions and operations used by the compiler to generate the lock-free
-- implementation of protected objects.
with Interfaces.C;
package System.Atomic_Primitives is
pragma Pure;
type uint is mod 2 ** Long_Integer'Size;
type uint8 is mod 2**8
with Size => 8;
type uint16 is mod 2**16
with Size => 16;
type uint32 is mod 2**32
with Size => 32;
type uint64 is mod 2**64
with Size => 64;
Relaxed : constant := 0;
Consume : constant := 1;
Acquire : constant := 2;
Release : constant := 3;
Acq_Rel : constant := 4;
Seq_Cst : constant := 5;
Last : constant := 6;
subtype Mem_Model is Integer range Relaxed .. Last;
------------------------------------
-- GCC built-in atomic primitives --
------------------------------------
generic
type Atomic_Type is mod <>;
function Atomic_Load
(Ptr : Address;
Model : Mem_Model := Seq_Cst) return Atomic_Type;
pragma Import (Intrinsic, Atomic_Load, "__atomic_load_n");
function Atomic_Load_8 is new Atomic_Load (uint8);
function Atomic_Load_16 is new Atomic_Load (uint16);
function Atomic_Load_32 is new Atomic_Load (uint32);
function Atomic_Load_64 is new Atomic_Load (uint64);
generic
type Atomic_Type is mod <>;
function Atomic_Compare_Exchange
(Ptr : Address;
Expected : Address;
Desired : Atomic_Type;
Weak : Boolean := False;
Success_Model : Mem_Model := Seq_Cst;
Failure_Model : Mem_Model := Seq_Cst) return Boolean;
pragma Import
(Intrinsic, Atomic_Compare_Exchange, "__atomic_compare_exchange_n");
function Atomic_Compare_Exchange_8 is new Atomic_Compare_Exchange (uint8);
function Atomic_Compare_Exchange_16 is new Atomic_Compare_Exchange (uint16);
function Atomic_Compare_Exchange_32 is new Atomic_Compare_Exchange (uint32);
function Atomic_Compare_Exchange_64 is new Atomic_Compare_Exchange (uint64);
function Atomic_Test_And_Set
(Ptr : System.Address;
Model : Mem_Model := Seq_Cst) return Boolean;
pragma Import (Intrinsic, Atomic_Test_And_Set, "__atomic_test_and_set");
procedure Atomic_Clear
(Ptr : System.Address;
Model : Mem_Model := Seq_Cst);
pragma Import (Intrinsic, Atomic_Clear, "__atomic_clear");
function Atomic_Always_Lock_Free
(Size : Interfaces.C.size_t;
Ptr : System.Address := System.Null_Address) return Boolean;
pragma Import
(Intrinsic, Atomic_Always_Lock_Free, "__atomic_always_lock_free");
--------------------------
-- Lock-free operations --
--------------------------
-- The lock-free implementation uses two atomic instructions for the
-- expansion of protected operations:
-- * Lock_Free_Read atomically loads the value contained in Ptr (with the
-- Acquire synchronization mode).
-- * Lock_Free_Try_Write atomically tries to write the Desired value into
-- Ptr if Ptr contains the Expected value. It returns true if the value
-- in Ptr was changed, or False if it was not, in which case Expected is
-- updated to the unexpected value in Ptr. Note that it does nothing and
-- returns true if Desired and Expected are equal.
generic
type Atomic_Type is mod <>;
function Lock_Free_Read (Ptr : Address) return Atomic_Type;
function Lock_Free_Read_8 is new Lock_Free_Read (uint8);
function Lock_Free_Read_16 is new Lock_Free_Read (uint16);
function Lock_Free_Read_32 is new Lock_Free_Read (uint32);
function Lock_Free_Read_64 is new Lock_Free_Read (uint64);
generic
type Atomic_Type is mod <>;
function Lock_Free_Try_Write
(Ptr : Address;
Expected : in out Atomic_Type;
Desired : Atomic_Type) return Boolean;
function Lock_Free_Try_Write_8 is new Lock_Free_Try_Write (uint8);
function Lock_Free_Try_Write_16 is new Lock_Free_Try_Write (uint16);
function Lock_Free_Try_Write_32 is new Lock_Free_Try_Write (uint32);
function Lock_Free_Try_Write_64 is new Lock_Free_Try_Write (uint64);
private
pragma Inline (Lock_Free_Read);
pragma Inline (Lock_Free_Try_Write);
end System.Atomic_Primitives;
|
zhmu/ananas | Ada | 213 | adb | -- { dg-do run }
with Renaming4; use Renaming4;
procedure Renaming3 is
type A is array(1..16) of Integer;
Filler : A := (others => 0);
begin
if B(1) /= 1 then
raise Program_Error;
end if;
end;
|
Rodeo-McCabe/orka | Ada | 5,988 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <[email protected]>
--
-- 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 GL.Debug;
with Orka.Strings;
package body Orka.Rendering.Programs.Modules is
use GL.Debug;
package Messages is new GL.Debug.Messages (Third_Party, Other);
function Trim_Image (Value : Integer) return String is
(Orka.Strings.Trim (Integer'Image (Value)));
procedure Load_And_Compile
(Object : in out Module;
Shader_Kind : GL.Objects.Shaders.Shader_Type;
Location : Resources.Locations.Location_Ptr;
Path : String) is
begin
if Path /= "" then
pragma Assert (Object.Shaders (Shader_Kind).Is_Empty);
declare
Shader : GL.Objects.Shaders.Shader (Kind => Shader_Kind);
Source : constant Resources.Byte_Array_Pointers.Pointer
:= Location.Read_Data (Path);
Text : String renames Resources.Convert (Source.Get);
begin
Shader.Set_Source (Text);
Shader.Compile;
if not Shader.Compile_Status then
raise Shader_Compile_Error with Path & ":" & Shader.Info_Log;
end if;
Messages.Log (Notification, "Compiled shader " & Path);
Messages.Log (Notification, " size: " & Trim_Image (Orka.Strings.Lines (Text)) &
" lines (" & Trim_Image (Source.Get.Value'Length) & " bytes)");
Messages.Log (Notification, " kind: " & Shader_Kind'Image);
Object.Shaders (Shader_Kind).Replace_Element (Shader);
end;
end if;
end Load_And_Compile;
procedure Set_And_Compile
(Object : in out Module;
Shader_Kind : GL.Objects.Shaders.Shader_Type;
Source : String) is
begin
if Source /= "" then
pragma Assert (Object.Shaders (Shader_Kind).Is_Empty);
declare
Shader : GL.Objects.Shaders.Shader (Kind => Shader_Kind);
begin
Shader.Set_Source (Source);
Shader.Compile;
if not Shader.Compile_Status then
raise Shader_Compile_Error with Shader_Kind'Image & ":" & Shader.Info_Log;
end if;
Messages.Log (Notification, "Compiled string with " &
Trim_Image (Source'Length) & " characters");
Messages.Log (Notification, " size: " &
Trim_Image (Orka.Strings.Lines (Source)) & " lines");
Messages.Log (Notification, " kind: " & Shader_Kind'Image);
Object.Shaders (Shader_Kind).Replace_Element (Shader);
end;
end if;
end Set_And_Compile;
function Create_Module_From_Sources (VS, TCS, TES, GS, FS, CS : String := "")
return Module
is
use GL.Objects.Shaders;
begin
return Result : Module do
Set_And_Compile (Result, Vertex_Shader, VS);
Set_And_Compile (Result, Tess_Control_Shader, TCS);
Set_And_Compile (Result, Tess_Evaluation_Shader, TES);
Set_And_Compile (Result, Geometry_Shader, GS);
Set_And_Compile (Result, Fragment_Shader, FS);
Set_And_Compile (Result, Compute_Shader, CS);
end return;
end Create_Module_From_Sources;
function Create_Module
(Location : Resources.Locations.Location_Ptr;
VS, TCS, TES, GS, FS, CS : String := "") return Module
is
use GL.Objects.Shaders;
begin
return Result : Module do
Load_And_Compile (Result, Vertex_Shader, Location, VS);
Load_And_Compile (Result, Tess_Control_Shader, Location, TCS);
Load_And_Compile (Result, Tess_Evaluation_Shader, Location, TES);
Load_And_Compile (Result, Geometry_Shader, Location, GS);
Load_And_Compile (Result, Fragment_Shader, Location, FS);
Load_And_Compile (Result, Compute_Shader, Location, CS);
end return;
end Create_Module;
procedure Attach_Shaders (Modules : Module_Array; Program : in out Programs.Program) is
use GL.Objects.Shaders;
procedure Attach (Subject : Module; Stage : GL.Objects.Shaders.Shader_Type) is
Holder : Shader_Holder.Holder renames Subject.Shaders (Stage);
begin
if not Holder.Is_Empty then
Program.GL_Program.Attach (Holder.Element);
Program.Stages (Stage) := True;
end if;
end Attach;
begin
for Module of Modules loop
Attach (Module, Vertex_Shader);
Attach (Module, Tess_Control_Shader);
Attach (Module, Tess_Evaluation_Shader);
Attach (Module, Geometry_Shader);
Attach (Module, Fragment_Shader);
Attach (Module, Compute_Shader);
end loop;
end Attach_Shaders;
procedure Detach_Shaders (Modules : Module_Array; Program : Programs.Program) is
use GL.Objects.Shaders;
procedure Detach (Holder : Shader_Holder.Holder) is
begin
if not Holder.Is_Empty then
Program.GL_Program.Detach (Holder.Element);
end if;
end Detach;
begin
for Module of Modules loop
Detach (Module.Shaders (Vertex_Shader));
Detach (Module.Shaders (Tess_Control_Shader));
Detach (Module.Shaders (Tess_Evaluation_Shader));
Detach (Module.Shaders (Geometry_Shader));
Detach (Module.Shaders (Fragment_Shader));
Detach (Module.Shaders (Compute_Shader));
end loop;
end Detach_Shaders;
end Orka.Rendering.Programs.Modules;
|
Asier98/AdaCar | Ada | 288 | adb | with AdaCar; use AdaCar;
with AdaCar.Alarmas;
with AdaCar.Entrada_Salida;
with AdaCar.Sensor_Proximidad;
with AdaCar.Seguimiento_Sensor;
with AdaCar.Motores;
with AdaCar.Organizador_Movimiento;
with AdaCar.Parametros;
procedure Main is
begin
-- Insert code here.
null;
end Main;
|
stcarrez/ada-keystore | Ada | 1,781 | ads | -----------------------------------------------------------------------
-- akt-commands-password-remove -- Remove a wallet password
-- Copyright (C) 2019 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 AKT.Commands.Drivers;
package AKT.Commands.Password.Remove is
type Command_Type is new AKT.Commands.Drivers.Command_Type with private;
-- Remove the wallet password.
overriding
procedure Execute (Command : in out Command_Type;
Name : in String;
Args : in Argument_List'Class;
Context : in out Context_Type);
-- Setup the command before parsing the arguments and executing it.
overriding
procedure Setup (Command : in out Command_Type;
Config : in out GNAT.Command_Line.Command_Line_Configuration;
Context : in out Context_Type);
private
type Command_Type is new AKT.Commands.Drivers.Command_Type with record
Force : aliased Boolean := False;
Slot : aliased GNAT.Strings.String_Access;
end record;
end AKT.Commands.Password.Remove;
|
Colouratura/caesar-ada | Ada | 5,457 | adb | -- caesar.adb
-- An improved algorithm that uses bit magic to transform ASCII
-- characters instead of looping through a lookup table.
--
-- Written by: A Dikdik <[email protected]>
-- Copyright (c) 2017 A Dikdik
-- All rights reserved.
--
-- Licensed under the BSD clause 3 license.
--
-- About:
-- The goal of this program is to function as a bi-directional way of
-- ciphering and deciphering text using the classical Caesar cipher (ROT-1)
--
-- In order to do this without using a look-up table that contains pairs of
-- both upper and lower-case ASCII letters this program uses tricks in order
-- shift and wrap around ASCII values. In some ways this is more efficient
-- and requires less code while still performing the same basic job as a
-- program that uses a look-up table.
--
-- to compile: ~$ make
--
-- to encipher: ~$ ./bin/caesar --encipher 3 'some text to encipher'
-- to decipher: ~$ ./bin/caesar --decipher 3 'some text to decipher'
with Ada.Text_IO;
with Ada.Command_Line;
procedure Caesar
is
-- to be brief and safe we rename instead of use
package IO renames Ada.Text_IO;
package CL renames Ada.Command_Line;
-- create some variables to hold our argument parsing state
Key_Argument : Integer; -- stores the key argument
Mode : Boolean; -- stores whether or not this is a cipher operation
-- ASCII value constants
ASCII_la : constant Integer := 97;
ASCII_lz : constant Integer := 122;
ASCII_UA : constant Integer := 65;
ASCII_UZ : constant Integer := 90;
-- Shift_Character
-- Takes a valid ASCII letter and either shifts it up in value by one
-- or, in the case of 'z' and 'Z', assigns it the value of 'a' or 'A'
-- or vice versa depending on the mode.
--
-- Parameter: (Character) In_Character - Valid ASCII character to shift
-- Parameter: (Integer) Key - Places to shift
-- Parameter: (Boolean) Mode - Whether or not this is a deciphering
-- Return: (Character) - Valid ASCII character result
function Shift_Character (In_Character : Character;
Key : Integer;
Mode : Boolean)
return Character
is
Temp_Character : Integer;
Key_Text_Sum : Integer;
Key_Text_Sub : Integer;
begin
Temp_Character := Character'Pos (In_Character);
Key_Text_Sum := Temp_Character + Key;
Key_Text_Sub := Key_Text_Sum - (Key * 2);
if Mode = TRUE then
if Key_Text_Sum > ASCII_lz then
Temp_Character := ((Key_Text_Sum - ASCII_lz) + ASCII_La - 1);
elsif Key_Text_Sum > ASCII_UZ and Key_Text_Sum < ASCII_la then
Temp_Character := ((Key_Text_Sum - ASCII_UZ) + ASCII_UA - 1);
else
Temp_Character := Key_Text_Sum;
end if;
elsif Mode = FALSE then
if Key_Text_Sub < ASCII_la and Key_Text_Sub > ASCII_UZ then
Temp_Character := (1 + ASCII_lz - (ASCII_la - Key_Text_Sub));
elsif Key_Text_Sub < ASCII_UA then
Temp_Character := (1 + ASCII_UZ - (ASCII_UA - Key_Text_Sub));
else
Temp_Character := Key_Text_Sub;
end if;
end if;
return Character'Val (Temp_Character);
end Shift_Character;
-- Is_Valid_Character
-- Takes a character and returns whether or not it is considered to be
-- a valid ASCII character that can be shifted.
--
-- Memo:
-- If the character is invalid then it should be readded to the string
-- as is, effectively ignoring it.
--
-- Parameter: (Character) In_Character - Character to be evaluated
-- Return: (Boolean) - Result of whether or not the input is valid
function Is_Valid_Character (In_Character : Character)
return Boolean
is
Character_Code : Integer;
begin
Character_Code := Character'Pos (In_Character);
if Character_Code >= ASCII_UA and Character_Code <= ASCII_UZ then
return TRUE;
elsif Character_Code >= ASCII_la and Character_Code <= ASCII_lz then
return TRUE;
end if;
return FALSE;
end Is_Valid_Character;
-- Cipher
-- Takes a string and applies the cipher algorithm to it
--
-- Parameter (String) Text - Text to be ciphered
-- Parameter (Integer) Key - Places to shift
-- Parameter (Boolean) Mode - Whether to encipher or decipher
procedure Cipher (Text : in String;
Key : in Integer;
Mode : in Boolean)
is
I : Integer := 1; -- loop iterator
begin
for I in 1 .. Text'Length loop
if Is_Valid_Character (Text (I)) = TRUE then
IO.Put (Shift_Character (Text (I), Key, Mode));
else
IO.Put (Text (I));
end if;
end loop;
IO.New_Line (1);
end Cipher;
begin
-- check number of arguments (expects 3)
if CL.Argument_Count /= 3 then
IO.Put_Line ("Unexpected amount of arguments!");
return;
end if;
-- check if it is a mode flag
-- memo: argument 1 must be a mode flag!
if CL.Argument (1) = "--decipher" then
Mode := FALSE;
elsif CL.Argument (1) = "--encipher" then
Mode := TRUE;
else
IO.Put_Line ("Could not find mode flag at position one.");
return;
end if;
-- grab the text and the key
Key_Argument := Integer'Value (CL.Argument (2));
-- generate our cipher-text
Cipher (CL.Argument (3), Key_Argument, Mode);
end Caesar;
|
davidkristola/vole | Ada | 3,689 | ads | with Interfaces;
with kv.avm.Executables;
with kv.avm.Instructions;
with kv.avm.Registers;
with kv.avm.Actors;
with kv.avm.Processors;
with kv.avm.Frames;
with kv.avm.Actor_References;
with kv.avm.Actor_References.Sets;
with kv.avm.Messages;
with kv.avm.Tuples;
with kv.avm.control;
with kv.avm.Memories;
package kv.avm.Instances is
use Interfaces;
use kv.avm.Messages;
type Instance_Type is new kv.avm.Executables.Executable_Interface with private;
type Instance_Access is access all Instance_Type;
function "+"(RHS : Instance_Access) return kv.avm.Executables.Executable_Access;
procedure Initialize
(Self : access Instance_Type;
Actor : in kv.avm.Actors.Actor_Access;
Memory : in kv.avm.Memories.Memory_Type;
Myself : in kv.avm.Actor_References.Actor_Reference_Type);
-- Routine used in unit tests
function Get_Frame(Self : Instance_Type) return kv.avm.Frames.Frame_Access;
overriding
procedure Process_Message
(Self : in out Instance_Type;
Message : in kv.avm.Messages.Message_Type);
overriding
procedure Process_Gosub
(Self : access Instance_Type;
Tailcall : in Boolean;
Supercall : in Boolean;
Reply_To : in kv.avm.Actor_References.Actor_Reference_Type;
Method : in kv.avm.Registers.String_Type;
Data : access constant kv.avm.Memories.Register_Set_Type;
Future : in Interfaces.Unsigned_32);
overriding
function Can_Accept_Message_Now(Self : Instance_Type; Message : kv.avm.Messages.Message_Type) return Boolean;
overriding
function Program_Counter
(Self : in Instance_Type) return Interfaces.Unsigned_32;
overriding
function Is_Running
(Self : in Instance_Type) return Boolean;
overriding
procedure Step
(Self : access Instance_Type;
Processor : access kv.avm.Processors.Processor_Type;
Status : out kv.avm.Control.Status_Type);
overriding
procedure Process_Internal_Response
(Self : in out Instance_Type;
Answer : in kv.avm.Tuples.Tuple_Type);
overriding
procedure Resolve_Future
(Self : in out Instance_Type;
Answer : in kv.avm.Tuples.Tuple_Type;
Future : in Interfaces.Unsigned_32);
function Alive(Self : Instance_Type) return Boolean;
overriding
procedure Halt_Actor
(Self : in out Instance_Type);
overriding
function Reachable(Self : Instance_Type) return kv.avm.Actor_References.Sets.Set;
overriding
function Image(Self : Instance_Type) return String;
overriding
function Debug_Info(Self : Instance_Type) return String;
type Instance_Factory is new kv.avm.Executables.Executable_Factory with null record;
overriding
procedure New_Executable
(Self : in out Instance_Factory;
Actor : in kv.avm.Actors.Actor_Access;
Machine : in kv.avm.Control.Control_Access;
Executable : out kv.avm.Executables.Executable_Access;
Reference : out kv.avm.Actor_References.Actor_Reference_Type);
private
type Instance_Type is new kv.avm.Executables.Executable_Interface with
record
Actor : kv.avm.Actors.Actor_Access;
Myself : kv.avm.Actor_References.Actor_Reference_Type;
Pc : Interfaces.Unsigned_32;
Memory : kv.avm.Memories.Memory_Type;
Attributes : kv.avm.Memories.Register_Array_Type;
Constants : kv.avm.Memories.Register_Array_Type;
Frame : kv.avm.Frames.Frame_Access;
Alive : Boolean;
end record;
end kv.avm.Instances;
|
sungyeon/drake | Ada | 10,528 | adb | with System.Once;
package body Ada.Strings.Canonical_Composites is
type Long_Boolean is new Boolean;
for Long_Boolean'Size use Long_Integer'Size;
function expect (exp, c : Long_Boolean) return Long_Boolean
with Import,
Convention => Intrinsic, External_Name => "__builtin_expect";
procedure unreachable
with Import,
Convention => Intrinsic, External_Name => "__builtin_unreachable";
pragma No_Return (unreachable);
-- decomposition
procedure D_Fill (Map : out D_Map_Array);
procedure D_Fill (Map : out D_Map_Array) is
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_16x1_Type);
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_16x1_Type) is
begin
for J in Table'Range loop
declare
F : UCD.Map_16x1_Item_Type renames Table (J);
begin
Map (I).From := Wide_Wide_Character'Val (F.Code);
Map (I).To (1) := Wide_Wide_Character'Val (F.Mapping);
for K in 2 .. Expanding loop
Map (I).To (K) := Wide_Wide_Character'Val (0);
end loop;
I := I + 1;
end;
end loop;
end Fill;
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_16x2_Type);
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_16x2_Type) is
begin
for J in Table'Range loop
declare
F : UCD.Map_16x2_Item_Type renames Table (J);
begin
Map (I).From := Wide_Wide_Character'Val (F.Code);
for K in 1 .. 2 loop
Map (I).To (K) := Wide_Wide_Character'Val (F.Mapping (K));
end loop;
for K in 3 .. Expanding loop
Map (I).To (K) := Wide_Wide_Character'Val (0);
end loop;
I := I + 1;
end;
end loop;
end Fill;
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_32x2_Type);
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_32x2_Type) is
begin
for J in Table'Range loop
declare
F : UCD.Map_32x2_Item_Type renames Table (J);
begin
Map (I).From := Wide_Wide_Character'Val (F.Code);
for K in 1 .. 2 loop
Map (I).To (K) := Wide_Wide_Character'Val (F.Mapping (K));
end loop;
for K in 3 .. Expanding loop
Map (I).To (K) := Wide_Wide_Character'Val (0);
end loop;
I := I + 1;
end;
end loop;
end Fill;
begin
-- make table
declare
I : Positive := Map'First;
begin
-- 16#00C0# ..
Fill (Map, I, UCD.Normalization.NFD_D_Table_XXXX);
-- 16#0340#
Fill (Map, I, UCD.Normalization.NFD_S_Table_XXXX);
-- 16#0344# ..
Fill (Map, I, UCD.Normalization.NFD_E_Table_XXXX);
-- 16#1109A# ..
Fill (Map, I, UCD.Normalization.NFD_D_Table_XXXXXXXX);
-- 16#1D15E#
Fill (Map, I, UCD.Normalization.NFD_E_Table_XXXXXXXX);
pragma Assert (I = Map'Last + 1);
end;
-- sort
for I in Map'First + 1 .. Map'Last loop
for J in reverse Map'First .. I - 1 loop
exit when Map (J).From <= Map (J + 1).From;
declare
T : constant D_Map_Element := Map (J);
begin
Map (J) := Map (J + 1);
Map (J + 1) := T;
end;
end loop;
end loop;
end D_Fill;
D_Flag : aliased System.Once.Flag := 0;
procedure D_Init;
procedure D_Init is
begin
D_Map := new D_Map_Array;
D_Fill (D_Map.all);
-- expanding re-decomposable
loop
declare
Expanded : Boolean := False;
begin
for I in D_Map'Range loop
declare
To : Decomposed_Wide_Wide_String
renames D_Map (I).To;
To_Last : Natural := Decomposed_Length (To);
J : Natural := To_Last;
begin
while J >= To'First loop
declare
D : constant Natural := D_Find (To (J));
begin
if D > 0 then
Expanded := True;
declare
R_Length : constant Natural :=
Decomposed_Length (D_Map (D).To);
begin
To (J + R_Length .. To_Last + R_Length - 1) :=
To (J + 1 .. To_Last);
To (J .. J + R_Length - 1) :=
D_Map (D).To (1 .. R_Length);
To_Last := To_Last + R_Length - 1;
pragma Assert (To_Last <= Expanding);
J := J + R_Length - 1;
end;
else
J := J - 1;
end if;
end;
end loop;
end;
end loop;
exit when not Expanded;
end;
end loop;
end D_Init;
Unexpanded_D_Flag : aliased System.Once.Flag := 0;
procedure Unexpanded_D_Init;
procedure Unexpanded_D_Init is
begin
Unexpanded_D_Map := new D_Map_Array;
D_Fill (Unexpanded_D_Map.all);
end Unexpanded_D_Init;
-- implementation of decomposition
function Decomposed_Length (Item : Decomposed_Wide_Wide_String)
return Natural is
begin
for I in reverse Item'Range loop
if Item (I) /= Wide_Wide_Character'Val (0) then
return I;
end if;
end loop;
pragma Assert (Boolean'(raise Program_Error));
unreachable;
end Decomposed_Length;
function D_Find (Item : Wide_Wide_Character) return Natural is
L : Positive := D_Map'First;
H : Natural := D_Map'Last;
begin
loop
declare
type Unsigned is mod 2 ** Integer'Size;
M : constant Positive := Integer (Unsigned (L + H) / 2);
M_Item : D_Map_Element
renames D_Map (M);
begin
if Item < M_Item.From then
H := M - 1;
elsif expect (Long_Boolean (Item > M_Item.From), True) then
L := M + 1;
else
return M;
end if;
end;
exit when L > H;
end loop;
return 0;
end D_Find;
procedure Initialize_D is
begin
System.Once.Initialize (D_Flag'Access, D_Init'Access);
end Initialize_D;
procedure Initialize_Unexpanded_D is
begin
System.Once.Initialize (
Unexpanded_D_Flag'Access,
Unexpanded_D_Init'Access);
end Initialize_Unexpanded_D;
-- composition
C_Flag : aliased System.Once.Flag := 0;
procedure C_Init;
procedure C_Init is
procedure Fill (
Map : in out C_Map_Array;
I : in out Positive;
Table : UCD.Map_16x2_Type);
procedure Fill (
Map : in out C_Map_Array;
I : in out Positive;
Table : UCD.Map_16x2_Type) is
begin
for J in Table'Range loop
declare
F : UCD.Map_16x2_Item_Type renames Table (J);
begin
for K in 1 .. 2 loop
Map (I).From (K) := Wide_Wide_Character'Val (F.Mapping (K));
end loop;
Map (I).To := Wide_Wide_Character'Val (F.Code);
I := I + 1;
end;
end loop;
end Fill;
procedure Fill (
Map : in out C_Map_Array;
I : in out Positive;
Table : UCD.Map_32x2_Type);
procedure Fill (
Map : in out C_Map_Array;
I : in out Positive;
Table : UCD.Map_32x2_Type) is
begin
for J in Table'Range loop
declare
F : UCD.Map_32x2_Item_Type renames Table (J);
begin
for K in 1 .. 2 loop
Map (I).From (K) := Wide_Wide_Character'Val (F.Mapping (K));
end loop;
Map (I).To := Wide_Wide_Character'Val (F.Code);
I := I + 1;
end;
end loop;
end Fill;
begin
-- initialize D table, too
Initialize_D;
-- make table
C_Map := new C_Map_Array;
declare
I : Positive := C_Map'First;
begin
-- (16#0041#, 16#0300#) ..
Fill (C_Map.all, I, UCD.Normalization.NFD_D_Table_XXXX);
-- (16#11099#, 16#110BA#) ..
Fill (C_Map.all, I, UCD.Normalization.NFD_D_Table_XXXXXXXX);
pragma Assert (I = C_Map'Last + 1);
end;
-- sort
for I in C_Map'First + 1 .. C_Map'Last loop
for J in reverse C_Map'First .. I - 1 loop
exit when C_Map (J).From <= C_Map (J + 1).From;
declare
T : constant C_Map_Element := C_Map (J);
begin
C_Map (J) := C_Map (J + 1);
C_Map (J + 1) := T;
end;
end loop;
end loop;
end C_Init;
-- implementation of composition
function C_Find (Item : Composing_Wide_Wide_String) return Natural is
L : Positive := C_Map'First;
H : Natural := C_Map'Last;
begin
loop
declare
type Unsigned is mod 2 ** Integer'Size;
M : constant Positive := Integer (Unsigned (L + H) / 2);
M_Item : C_Map_Element
renames C_Map (M);
begin
if Item < M_Item.From then
H := M - 1;
elsif expect (Long_Boolean (Item > M_Item.From), True) then
L := M + 1;
else
return M;
end if;
end;
exit when L > H;
end loop;
return 0;
end C_Find;
procedure Initialize_C is
begin
System.Once.Initialize (C_Flag'Access, C_Init'Access);
end Initialize_C;
end Ada.Strings.Canonical_Composites;
|
AdaCore/Ada_Drivers_Library | Ada | 6,497 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2019-2020, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with NRF_SVD.UART; use NRF_SVD.UART;
package body nRF.UART is
---------------
-- Configure --
---------------
procedure Configure
(This : in out UART_Device; Baud : Baud_Rate; Parity : Boolean)
is
begin
This.Periph.BAUDRATE := Baud'Enum_Rep;
This.Periph.CONFIG.PARITY := (if Parity then Included else Excluded);
end Configure;
------------
-- Enable --
------------
procedure Enable (This : in out UART_Device;
Tx, Rx : GPIO_Pin_Index) is
begin
This.Periph.PSELTXD := UInt32 (Tx);
This.Periph.PSELRXD := UInt32 (Rx);
This.Periph.ENABLE.ENABLE := Enabled;
-- Start TX and RX
This.Periph.TASKS_STARTRX := 1;
This.Periph.TASKS_STARTTX := 1;
-- Send a first character to start the TXREADY events (See nRF Series
-- Reference Manual Version 3.0 Figure 68: UART transmission).
This.Periph.TXD.TXD := 0;
end Enable;
-------------
-- Disable --
-------------
procedure Disable (This : in out UART_Device) is
begin
This.Periph.ENABLE.ENABLE := Disabled;
This.Periph.PSELTXD := 16#FFFF_FFFF#;
This.Periph.PSELRXD := 16#FFFF_FFFF#;
-- Stop TX and RX
This.Periph.TASKS_STOPTX := 1;
This.Periph.TASKS_STOPRX := 1;
end Disable;
-------------------------
-- Enable_Flow_Control --
-------------------------
procedure Enable_Flow_Control
(This : in out UART_Device;
RTS, CTS : GPIO_Pin_Index)
is
begin
This.Periph.PSELRTS := UInt32 (RTS);
This.Periph.PSELCTS := UInt32 (CTS);
This.Periph.CONFIG.HWFC := Enabled;
end Enable_Flow_Control;
--------------------------
-- Disable_Flow_Control --
--------------------------
procedure Disable_Flow_Control (This : in out UART_Device) is
begin
This.Periph.CONFIG.HWFC := Disabled;
This.Periph.PSELRTS := 16#FFFF_FFFF#;
This.Periph.PSELCTS := 16#FFFF_FFFF#;
end Disable_Flow_Control;
--------------
-- Transmit --
--------------
overriding
procedure Transmit
(This : in out UART_Device;
Data : UART_Data_8b;
Status : out UART_Status;
Timeout : Natural := 1_000)
is
pragma Unreferenced (Timeout);
begin
if Data'Length = 0 then
Status := HAL.UART.Ok;
return;
end if;
for C of Data loop
-- Wait for TX Ready event
while UART0_Periph.EVENTS_TXDRDY = 0 loop
null;
end loop;
-- Clear the event
This.Periph.EVENTS_TXDRDY := 0;
-- Send a character
This.Periph.TXD.TXD := C;
end loop;
Status := HAL.UART.Ok;
end Transmit;
-------------
-- Receive --
-------------
overriding
procedure Receive
(This : in out UART_Device;
Data : out UART_Data_8b;
Status : out UART_Status;
Timeout : Natural := 1_000)
is
pragma Unreferenced (Timeout);
begin
if Data'Length = 0 then
Status := HAL.UART.Ok;
return;
end if;
for C of Data loop
-- Wait for RX Ready event
while UART0_Periph.EVENTS_RXDRDY = 0 loop
null;
end loop;
-- Read a character
C := This.Periph.RXD.RXD;
-- Clear the RX event for the character we just received
UART0_Periph.EVENTS_RXDRDY := 0;
end loop;
Status := HAL.UART.Ok;
end Receive;
--------------
-- Transmit --
--------------
overriding
procedure Transmit
(This : in out UART_Device;
Data : UART_Data_9b;
Status : out UART_Status;
Timeout : Natural := 1_000)
is
begin
raise Program_Error;
end Transmit;
-------------
-- Receive --
-------------
overriding
procedure Receive
(This : in out UART_Device;
Data : out UART_Data_9b;
Status : out UART_Status;
Timeout : Natural := 1_000)
is
begin
raise Program_Error;
end Receive;
end nRF.UART;
|
Fabien-Chouteau/GESTE | Ada | 47,322 | ads | with GESTE;
with GESTE.Maths_Types;
with GESTE_Config;
pragma Style_Checks (Off);
package Game_Assets is
Palette : aliased GESTE.Palette_Type := (
0 => 0,
1 => 9580,
2 => 9579,
3 => 9580,
4 => 11660,
5 => 11692,
6 => 11660,
7 => 11660,
8 => 11692,
9 => 9580,
10 => 9580,
11 => 11627,
12 => 11627,
13 => 11628,
14 => 9612,
15 => 9612,
16 => 11724,
17 => 11692,
18 => 11660,
19 => 11627,
20 => 9644,
21 => 9709,
22 => 11757,
23 => 13773,
24 => 13773,
25 => 11660,
26 => 11660,
27 => 9612,
28 => 9741,
29 => 19852,
30 => 31946,
31 => 40009,
32 => 44072,
33 => 44040,
34 => 11692,
35 => 11660,
36 => 13805,
37 => 31914,
38 => 48072,
39 => 50120,
40 => 50152,
41 => 48104,
42 => 48104,
43 => 11789,
44 => 33929,
45 => 50087,
46 => 48136,
47 => 48136,
48 => 48136,
49 => 48136,
50 => 9676,
51 => 21868,
52 => 48071,
53 => 48136,
54 => 48136,
55 => 9709,
56 => 33930,
57 => 50120,
58 => 11757,
59 => 42025,
60 => 50152,
61 => 9612,
62 => 13773,
63 => 44040,
64 => 13773,
65 => 44040,
66 => 48136,
67 => 48136,
68 => 9580,
69 => 13805,
70 => 42024,
71 => 48104,
72 => 48104,
73 => 46024,
74 => 48104,
75 => 11757,
76 => 37993,
77 => 48136,
78 => 46056,
79 => 41863,
80 => 46024,
81 => 11627,
82 => 9709,
83 => 29898,
84 => 50120,
85 => 48104,
86 => 9644,
87 => 17836,
88 => 48072,
89 => 48136,
90 => 50217,
91 => 48136,
92 => 11627,
93 => 31946,
94 => 11789,
95 => 31914,
96 => 48072,
97 => 48104,
98 => 11660,
99 => 9741,
100 => 21868,
101 => 33930,
102 => 42025,
103 => 44040,
104 => 46088,
105 => 11660,
106 => 11628,
107 => 9676,
108 => 9709,
109 => 11757,
110 => 13772,
111 => 15820,
112 => 48104,
113 => 46024,
114 => 43943,
115 => 48136,
116 => 46024,
117 => 43975,
118 => 50217,
119 => 46056,
120 => 46024,
121 => 48136,
122 => 50152,
123 => 50120,
124 => 48072,
125 => 50152,
126 => 48072,
127 => 48072,
128 => 50120,
129 => 35977,
130 => 21868,
131 => 35978,
132 => 21867,
133 => 33962,
134 => 23883,
135 => 35977,
136 => 35977,
137 => 23883,
138 => 9709,
139 => 9676,
140 => 9644,
141 => 9709,
142 => 23883,
143 => 35977,
144 => 9676,
145 => 9709,
146 => 9676,
147 => 9709,
148 => 11628,
149 => 11692,
150 => 11692,
151 => 11660,
152 => 11724,
153 => 11724,
154 => 11692,
155 => 9612,
156 => 9579,
157 => 11660,
158 => 11692,
159 => 11724,
160 => 46088,
161 => 43943,
162 => 46056,
163 => 43943,
164 => 46024,
165 => 48169,
166 => 48136,
167 => 15820,
168 => 44040,
169 => 42025,
170 => 33962,
171 => 48104,
172 => 31946,
173 => 48072,
174 => 19852,
175 => 48104,
176 => 50217,
177 => 50249,
178 => 46088,
179 => 50120,
180 => 50217,
181 => 50249,
182 => 48136,
183 => 40009,
184 => 44040,
185 => 13773,
186 => 13773,
187 => 44040,
188 => 42024,
189 => 13805,
190 => 35978,
191 => 9709,
192 => 48071,
193 => 21868,
194 => 50087,
195 => 31914,
196 => 9741,
197 => 11628,
198 => 29898,
199 => 11789,
200 => 9579,
201 => 42024,
202 => 37993,
203 => 29898,
204 => 13773,
205 => 11757,
206 => 9612,
207 => 11692,
208 => 46024,
209 => 46056,
210 => 41863,
211 => 43976,
212 => 48136,
213 => 50249,
214 => 48136,
215 => 48136,
216 => 46088,
217 => 48104,
218 => 15788,
219 => 19852,
220 => 27915,
221 => 40009,
222 => 50120,
223 => 9612,
224 => 9644,
225 => 9709,
226 => 11789,
227 => 27915,
228 => 48072,
229 => 11595,
230 => 11628,
231 => 9773,
232 => 27915,
233 => 11789,
234 => 40009,
235 => 9709,
236 => 25899,
237 => 50120,
238 => 9644,
239 => 17804,
240 => 48104,
241 => 15821,
242 => 44040,
243 => 9612,
244 => 23883,
245 => 35977,
246 => 23883,
247 => 35978,
248 => 46056,
249 => 21868,
250 => 43943,
251 => 9709,
252 => 33962,
253 => 17804,
254 => 48104,
255 => 9709,
256 => 25867,
257 => 11789,
258 => 40009,
259 => 27915,
260 => 15820,
261 => 19852,
262 => 46056,
263 => 43943,
264 => 48104,
265 => 46056,
266 => 11725,
267 => 44040,
268 => 50217,
269 => 25899,
270 => 15820,
271 => 13773,
272 => 50217,
273 => 52330,
274 => 48136,
275 => 48104,
276 => 48072,
277 => 27915,
278 => 43975,
279 => 48168,
280 => 27882,
281 => 9773,
282 => 11595,
283 => 50152,
284 => 39977,
285 => 11789,
286 => 11660,
287 => 27915,
288 => 19852,
289 => 9644,
290 => 46056,
291 => 15788,
292 => 9612,
293 => 35977,
294 => 37993,
295 => 21835,
296 => 46056,
297 => 50152,
298 => 35945,
299 => 43943,
300 => 48136,
301 => 50152,
302 => 21835,
303 => 23883,
304 => 9676,
305 => 46056,
306 => 15788,
307 => 48104,
308 => 46024,
309 => 27915,
310 => 43943,
311 => 40009,
312 => 48136,
313 => 27883,
314 => 50249,
315 => 48136,
316 => 27915,
317 => 19852,
318 => 46024,
319 => 46056,
320 => 52330,
321 => 63422,
322 => 63390,
323 => 63423,
324 => 63324,
325 => 58244,
326 => 58146,
327 => 63422,
328 => 58146,
329 => 58179,
330 => 58179,
331 => 65535,
332 => 65535,
333 => 65535,
334 => 65437,
335 => 60259,
336 => 60160,
337 => 60160,
338 => 60193,
339 => 60161,
340 => 50875,
341 => 50907,
342 => 50842,
343 => 48302,
344 => 48269,
345 => 50907,
346 => 48269,
347 => 48269,
348 => 48269,
349 => 40440,
350 => 40440,
351 => 40538,
352 => 40538,
353 => 44633,
354 => 44633,
355 => 44633,
356 => 42585,
357 => 65437,
358 => 59359,
359 => 61309,
360 => 63390,
361 => 61113,
362 => 58244,
363 => 58146,
364 => 58146,
365 => 58146,
366 => 53888,
367 => 58507,
368 => 63357,
369 => 63422,
370 => 63455,
371 => 65437,
372 => 60456,
373 => 60194,
374 => 60226,
375 => 58178,
376 => 56066,
377 => 56066,
378 => 58244,
379 => 63127,
380 => 65535,
381 => 63422,
382 => 61342,
383 => 56624,
384 => 52233,
385 => 50284,
386 => 48269,
387 => 56065,
388 => 58146,
389 => 58178,
390 => 60194,
391 => 58507,
392 => 55035,
393 => 48794,
394 => 44601,
395 => 42520,
396 => 40472,
397 => 40472,
398 => 40504,
399 => 61342,
400 => 60784,
401 => 60259,
402 => 58178,
403 => 52199,
404 => 44338,
405 => 40472,
406 => 40472,
407 => 42552,
408 => 42553,
409 => 42585,
410 => 61309,
411 => 63390,
412 => 65470,
413 => 60817,
414 => 50251,
415 => 42454,
416 => 42553,
417 => 61439,
418 => 63390,
419 => 65503,
420 => 65503,
421 => 55035,
422 => 42487,
423 => 42553,
424 => 58835,
425 => 63324,
426 => 59229,
427 => 42552,
428 => 42552,
429 => 51905,
430 => 56131,
431 => 60522,
432 => 61046,
433 => 46713,
434 => 56066,
435 => 58146,
436 => 54280,
437 => 42487,
438 => 56033,
439 => 58146,
440 => 48302,
441 => 58376,
442 => 60292,
443 => 56164,
444 => 44403,
445 => 42553,
446 => 63324,
447 => 63225,
448 => 56788,
449 => 42487,
450 => 42553,
451 => 40505,
452 => 63422,
453 => 57148,
454 => 40472,
455 => 42356,
456 => 48334,
457 => 63422,
458 => 65503,
459 => 52987,
460 => 44633,
461 => 56721,
462 => 58211,
463 => 63422,
464 => 65503,
465 => 52955,
466 => 48826,
467 => 65437,
468 => 62865,
469 => 58146,
470 => 48268,
471 => 40472,
472 => 46286,
473 => 58211,
474 => 60784,
475 => 58146,
476 => 50283,
477 => 42356,
478 => 56689,
479 => 65437,
480 => 50874,
481 => 58244,
482 => 60456,
483 => 54576,
484 => 42520,
485 => 61112,
486 => 65405,
487 => 61341,
488 => 44633,
489 => 63390,
490 => 61309,
491 => 55035,
492 => 61277,
493 => 63357,
494 => 63127,
495 => 58507,
496 => 44338,
497 => 58540,
498 => 58244,
499 => 53728,
500 => 56066,
501 => 58146,
502 => 60259,
503 => 60784,
504 => 55035,
505 => 56065,
506 => 60752,
507 => 65470,
508 => 61342,
509 => 63390,
510 => 65503,
511 => 61047,
512 => 54281,
513 => 44403,
514 => 42487,
515 => 40472,
516 => 63390,
517 => 63356,
518 => 60554,
519 => 56787,
520 => 52987,
521 => 52955,
522 => 59294,
523 => 58868,
524 => 56131,
525 => 58146,
526 => 58146,
527 => 58244,
528 => 63193,
529 => 65503,
530 => 56066,
531 => 56065,
532 => 58343,
533 => 63292,
534 => 63422,
535 => 63422,
536 => 63422,
537 => 51905,
538 => 56033,
539 => 58474,
540 => 56066,
541 => 56098,
542 => 58146,
543 => 53985,
544 => 56066,
545 => 58146,
546 => 60226,
547 => 58179,
548 => 56066,
549 => 56066,
550 => 58146,
551 => 60226,
552 => 58178,
553 => 54215,
554 => 46320,
555 => 53824,
556 => 56066,
557 => 58178,
558 => 56164,
559 => 48269,
560 => 42454,
561 => 40504,
562 => 61374,
563 => 60784,
564 => 58211,
565 => 54149,
566 => 46353,
567 => 40472,
568 => 61277,
569 => 63390,
570 => 63390,
571 => 62865,
572 => 54215,
573 => 44371,
574 => 40472,
575 => 59196,
576 => 63390,
577 => 63422,
578 => 65503,
579 => 59196,
580 => 44502,
581 => 61309,
582 => 63422,
583 => 61309,
584 => 44633,
585 => 61309,
586 => 63390,
587 => 65503,
588 => 48794,
589 => 42585,
590 => 63390,
591 => 63422,
592 => 40472,
593 => 42553,
594 => 61342,
595 => 63422,
596 => 59261,
597 => 42553,
598 => 60981,
599 => 63389,
600 => 50875,
601 => 56066,
602 => 58146,
603 => 60358,
604 => 56755,
605 => 42552,
606 => 42552,
607 => 56066,
608 => 58178,
609 => 48302,
610 => 53985,
611 => 56098,
612 => 58178,
613 => 56197,
614 => 42388,
615 => 56066,
616 => 58146,
617 => 50218,
618 => 56066,
619 => 58178,
620 => 58178,
621 => 46320,
622 => 40505,
623 => 49793,
624 => 56098,
625 => 56196,
626 => 42389,
627 => 42553,
628 => 53888,
629 => 58114,
630 => 60194,
631 => 52200,
632 => 40439,
633 => 58638,
634 => 58441,
635 => 60324,
636 => 48269,
637 => 61309,
638 => 63357,
639 => 63225,
640 => 46582,
641 => 40504,
642 => 63390,
643 => 65503,
644 => 63422,
645 => 44633,
646 => 63390,
647 => 61309,
648 => 42552,
649 => 63390,
650 => 59229,
651 => 42520,
652 => 63390,
653 => 65503,
654 => 57148,
655 => 63422,
656 => 55068,
657 => 63422,
658 => 52987,
659 => 42585,
660 => 58146,
661 => 48268,
662 => 50284,
663 => 58146,
664 => 50251,
665 => 58146,
666 => 52266,
667 => 40472,
668 => 58146,
669 => 52200,
670 => 40439,
671 => 56098,
672 => 60226,
673 => 54182,
674 => 42454,
675 => 42553,
676 => 56098,
677 => 56164,
678 => 42553,
679 => 56098,
680 => 58244,
681 => 58408,
682 => 44469,
683 => 58769,
684 => 63160,
685 => 63356,
686 => 48794,
687 => 61342,
688 => 63423,
689 => 65503,
690 => 55035,
691 => 61277,
692 => 63390,
693 => 59229,
694 => 42552,
695 => 42553,
696 => 63390,
697 => 63390,
698 => 44633,
699 => 63422,
700 => 50907,
701 => 61277,
702 => 42520,
703 => 42553,
704 => 63390,
705 => 63422,
706 => 48762,
707 => 61309,
708 => 63422,
709 => 65339,
710 => 52561,
711 => 40439,
712 => 61407,
713 => 58507,
714 => 58211,
715 => 46320,
716 => 56033,
717 => 42454,
718 => 56098,
719 => 58178,
720 => 56066,
721 => 58146,
722 => 44305,
723 => 56066,
724 => 53985,
725 => 54215,
726 => 56066,
727 => 56098,
728 => 58211,
729 => 62832,
730 => 59196,
731 => 46681,
732 => 53921,
733 => 60751,
734 => 63389,
735 => 65503,
736 => 61439,
737 => 63390,
738 => 59229,
739 => 50874,
740 => 52857,
741 => 61309,
742 => 63422,
743 => 61309,
744 => 63390,
745 => 63389,
746 => 61310,
747 => 60981,
748 => 61439,
749 => 53985,
750 => 56230,
751 => 61145,
752 => 53824,
753 => 56066,
754 => 58146,
755 => 58178,
756 => 62799,
757 => 61277,
758 => 61145,
759 => 58277,
760 => 58146,
761 => 58179,
762 => 54281,
763 => 61407,
764 => 61309,
765 => 63390,
766 => 63422,
767 => 62799,
768 => 58179,
769 => 52200,
770 => 46352,
771 => 53985,
772 => 58311,
773 => 63259,
774 => 63423,
775 => 63423,
776 => 56984,
777 => 46385,
778 => 42487,
779 => 42553,
780 => 53888,
781 => 56066,
782 => 58146,
783 => 58179,
784 => 62963,
785 => 57148,
786 => 46714,
787 => 42552,
788 => 61310,
789 => 61080,
790 => 58245,
791 => 58146,
792 => 58179,
793 => 54444,
794 => 46713,
795 => 40472,
796 => 61309,
797 => 63390,
798 => 63390,
799 => 60620,
800 => 58146,
801 => 54182,
802 => 46320,
803 => 40406,
804 => 63455,
805 => 65535,
806 => 65535,
807 => 56984,
808 => 44338,
809 => 40472,
810 => 42585,
811 => 65503,
812 => 57148,
813 => 46713,
814 => 40472,
815 => 40537,
816 => 42585,
817 => 46681,
818 => 40440,
819 => 40472,
820 => 42585,
821 => 40472,
822 => 42520,
823 => 44371,
824 => 42520,
825 => 46713,
826 => 55035,
827 => 58605,
828 => 42553,
829 => 42488,
830 => 46713,
831 => 57116,
832 => 63193,
833 => 44337,
834 => 52265,
835 => 61014,
836 => 65503,
837 => 63422,
838 => 63390,
839 => 63390,
840 => 42520,
841 => 44338,
842 => 52233,
843 => 58211,
844 => 58146,
845 => 60554,
846 => 63357,
847 => 63390,
848 => 61277,
849 => 55067,
850 => 58539,
851 => 58178,
852 => 58146,
853 => 56131,
854 => 58770,
855 => 63094,
856 => 58211,
857 => 56066,
858 => 53986,
859 => 42487,
860 => 63390,
861 => 61277,
862 => 56493,
863 => 52200,
864 => 58211,
865 => 58178,
866 => 58146,
867 => 56131,
868 => 58146,
869 => 56066,
870 => 53986,
871 => 56066,
872 => 53888,
873 => 56098,
874 => 58376,
875 => 58211,
876 => 61277,
877 => 63292,
878 => 63062,
879 => 61309,
880 => 63423,
881 => 65503,
882 => 61407,
883 => 63390,
884 => 61080,
885 => 63422,
886 => 63422,
887 => 53986,
888 => 58245,
889 => 60685,
890 => 56952,
891 => 56066,
892 => 58146,
893 => 46385,
894 => 53888,
895 => 58146,
896 => 52200,
897 => 42487,
898 => 56262,
899 => 58178,
900 => 58179,
901 => 46352,
902 => 61277,
903 => 63259,
904 => 62963,
905 => 54412,
906 => 42455,
907 => 61309,
908 => 63423,
909 => 48761,
910 => 61375,
911 => 63390,
912 => 57148,
913 => 42552,
914 => 61145,
915 => 63422,
916 => 63422,
917 => 48794,
918 => 53985,
919 => 58310,
920 => 62865,
921 => 59130,
922 => 42552,
923 => 58178,
924 => 46353,
925 => 53888,
926 => 58146,
927 => 54247,
928 => 42454,
929 => 56262,
930 => 58178,
931 => 46352,
932 => 61277,
933 => 63259,
934 => 62930,
935 => 54412,
936 => 61309,
937 => 63423,
938 => 63423,
939 => 48761,
940 => 61407,
941 => 63390,
942 => 57148,
943 => 61113,
944 => 63422,
945 => 48794,
946 => 53986,
947 => 58245,
948 => 60686,
949 => 56952,
950 => 46353,
951 => 53888,
952 => 58146,
953 => 58343,
954 => 58179,
955 => 61277,
956 => 63291,
957 => 62996,
958 => 54445,
959 => 61309,
960 => 46713,
961 => 61277,
962 => 63390,
963 => 61309,
964 => 63422,
965 => 63422,
966 => 46714,
967 => 63390,
968 => 58146,
969 => 52200,
970 => 56066,
971 => 58178,
972 => 58179,
973 => 46353,
974 => 54018,
975 => 58146,
976 => 52233,
977 => 42487,
978 => 56131,
979 => 60555,
980 => 61046,
981 => 46713,
982 => 58901,
983 => 63357,
984 => 61342,
985 => 63422,
986 => 46746,
987 => 57115,
988 => 61276,
989 => 63094,
990 => 60587,
991 => 46385,
992 => 56394,
993 => 58179,
994 => 42487,
995 => 56066,
996 => 58179,
997 => 54018,
998 => 58146,
999 => 63390,
1000 => 57115,
1001 => 42520,
1002 => 61309,
1003 => 63192,
1004 => 60620,
1005 => 44370,
1006 => 53986,
1007 => 58146,
1008 => 56066,
1009 => 58178,
1010 => 52200,
1011 => 42455,
1012 => 46320,
1013 => 58146,
1014 => 54215,
1015 => 60555,
1016 => 63061,
1017 => 65503,
1018 => 63390,
1019 => 61309,
1020 => 61309,
1021 => 61342,
1022 => 63422,
1023 => 63422,
1024 => 44601,
1025 => 48794,
1026 => 40472,
1027 => 42586,
1028 => 40538,
1029 => 42586,
1030 => 42388,
1031 => 46254,
1032 => 48301,
1033 => 58146,
1034 => 60160,
1035 => 56098,
1036 => 58146,
1037 => 58244,
1038 => 50842,
1039 => 50842,
1040 => 48302,
1041 => 60259,
1042 => 63423,
1043 => 48826,
1044 => 46254,
1045 => 60160,
1046 => 63422,
1047 => 63422,
1048 => 44601,
1049 => 42388,
1050 => 58146,
1051 => 63390,
1052 => 50907,
1053 => 42618,
1054 => 48301,
1055 => 56066,
1056 => 63422,
1057 => 63324,
1058 => 58376,
1059 => 56065,
1060 => 56066,
1061 => 65535,
1062 => 63225,
1063 => 60325,
1064 => 56131,
1065 => 58835,
1066 => 59294,
1067 => 52955,
1068 => 56820,
1069 => 56164,
1070 => 60522,
1071 => 63324,
1072 => 63390,
1073 => 61309,
1074 => 42487,
1075 => 48302,
1076 => 52232,
1077 => 61014,
1078 => 63390,
1079 => 61342,
1080 => 59229,
1081 => 65470,
1082 => 60784,
1083 => 56066,
1084 => 52987,
1085 => 60817,
1086 => 60259,
1087 => 58146,
1088 => 56066,
1089 => 50283,
1090 => 58178,
1091 => 56066,
1092 => 53760,
1093 => 52200,
1094 => 58244,
1095 => 58507,
1096 => 44338,
1097 => 58507,
1098 => 63127,
1099 => 63357,
1100 => 61277,
1101 => 55035,
1102 => 63422,
1103 => 61309,
1104 => 40472,
1105 => 48794,
1106 => 63422,
1107 => 63455,
1108 => 63390,
1109 => 44601,
1110 => 61309,
1111 => 65405,
1112 => 61112,
1113 => 54576,
1114 => 60456,
1115 => 58244,
1116 => 40472,
1117 => 50185,
1118 => 58146,
1119 => 50284,
1120 => 58146,
1121 => 48269,
1122 => 58146,
1123 => 63422,
1124 => 63422,
1125 => 57148,
1126 => 63422,
1127 => 42487,
1128 => 56788,
1129 => 63225,
1130 => 63292,
1131 => 44403,
1132 => 56164,
1133 => 60292,
1134 => 58343,
1135 => 48302,
1136 => 58178,
1137 => 58146,
1138 => 56033,
1139 => 52233,
1140 => 58146,
1141 => 56066,
1142 => 46713,
1143 => 61046,
1144 => 60554,
1145 => 56131,
1146 => 53953,
1147 => 57181,
1148 => 63356,
1149 => 58868,
1150 => 55003,
1151 => 63390,
1152 => 61439,
1153 => 50251,
1154 => 63390,
1155 => 44338,
1156 => 52200,
1157 => 60752,
1158 => 61310,
1159 => 48794,
1160 => 55035,
1161 => 58539,
1162 => 58146,
1163 => 56033,
1164 => 52233,
1165 => 54575,
1166 => 63159,
1167 => 56066,
1168 => 60456,
1169 => 65404,
1170 => 63422,
1171 => 63357,
1172 => 58540,
1173 => 53888,
1174 => 58212,
1175 => 61112,
1176 => 63390,
1177 => 59327,
1178 => 59196,
1179 => 61342,
1180 => 58802,
1181 => 56098,
1182 => 56098,
1183 => 56098,
1184 => 58146,
1185 => 58146,
1186 => 58146,
1187 => 61277,
1188 => 63390,
1189 => 63390,
1190 => 63423,
1191 => 63160,
1192 => 58244,
1193 => 63390,
1194 => 65503,
1195 => 63356,
1196 => 58408,
1197 => 56164,
1198 => 52266,
1199 => 50251,
1200 => 50284,
1201 => 48269,
1202 => 63422,
1203 => 59229,
1204 => 55035,
1205 => 48794,
1206 => 42388,
1207 => 65338,
1208 => 52561,
1209 => 44404,
1210 => 56721,
1211 => 65438,
1212 => 58211,
1213 => 56689,
1214 => 44633,
1215 => 42553,
1216 => 56787,
1217 => 48302,
1218 => 60390,
1219 => 46320,
1220 => 42389,
1221 => 58146,
1222 => 58178,
1223 => 58179,
1224 => 56197,
1225 => 48269,
1226 => 46582,
1227 => 56098,
1228 => 58146,
1229 => 60292,
1230 => 63193,
1231 => 59229,
1232 => 55036,
1233 => 52987,
1234 => 52955,
1235 => 51905,
1236 => 56066,
1237 => 56098,
1238 => 58114,
1239 => 58408,
1240 => 63357,
1241 => 65503,
1242 => 53953,
1243 => 58605,
1244 => 61309,
1245 => 63390,
1246 => 63390,
1247 => 63390,
1248 => 63390,
1249 => 63422,
1250 => 53986,
1251 => 58146,
1252 => 53888,
1253 => 56066,
1254 => 58178,
1255 => 61309,
1256 => 61112,
1257 => 58277,
1258 => 61407,
1259 => 63422,
1260 => 60686,
1261 => 58179,
1262 => 52200,
1263 => 53953,
1264 => 56263,
1265 => 56952,
1266 => 46385,
1267 => 53824,
1268 => 58146,
1269 => 58178,
1270 => 62930,
1271 => 61277,
1272 => 61145,
1273 => 58310,
1274 => 54412,
1275 => 46713,
1276 => 40472,
1277 => 61309,
1278 => 63390,
1279 => 63422,
1280 => 62831,
1281 => 63422,
1282 => 57017,
1283 => 46385,
1284 => 40472,
1285 => 40440,
1286 => 44633,
1287 => 40440,
1288 => 46681,
1289 => 57148,
1290 => 40472,
1291 => 44633,
1292 => 57116,
1293 => 65503,
1294 => 40505,
1295 => 40439,
1296 => 46353,
1297 => 54248,
1298 => 63061,
1299 => 63422,
1300 => 63390,
1301 => 61309,
1302 => 44338,
1303 => 52233,
1304 => 60554,
1305 => 63390,
1306 => 61309,
1307 => 56066,
1308 => 53985,
1309 => 58179,
1310 => 60193,
1311 => 44338,
1312 => 40537,
1313 => 60193,
1314 => 54215,
1315 => 40473,
1316 => 42585,
1317 => 58080,
1318 => 44338,
1319 => 40538,
1320 => 54412,
1321 => 44666,
1322 => 40440,
1323 => 42585,
1324 => 42552,
1325 => 40472,
1326 => 40537,
1327 => 42356,
1328 => 40473,
1329 => 52200,
1330 => 44633,
1331 => 44338,
1332 => 58145,
1333 => 40505,
1334 => 52200,
1335 => 60193,
1336 => 44370,
1337 => 58146,
1338 => 58179,
1339 => 57148,
1340 => 46681,
1341 => 65535,
1342 => 40472,
1343 => 54904,
1344 => 40537,
1345 => 42290,
1346 => 40472,
1347 => 44633,
1348 => 57148,
1349 => 40472,
1350 => 48269,
1351 => 42388,
1352 => 63422,
1353 => 60160,
1354 => 46254,
1355 => 40538,
1356 => 48302,
1357 => 40472,
1358 => 50842,
1359 => 58146,
1360 => 56066,
1361 => 42388,
1362 => 63390,
1363 => 56721,
1364 => 50874,
1365 => 56689,
1366 => 63324,
1367 => 60259,
1368 => 65437,
1369 => 65535,
1370 => 65535,
1371 => 65437,
1372 => 60259,
1373 => 50874,
1374 => 50382,
1375 => 48302,
1376 => 52955,
1377 => 55068,
1378 => 52987,
1379 => 52922,
1380 => 48302,
1381 => 38392,
1382 => 42651,
1383 => 40538,
1384 => 40538,
1385 => 44698,
1386 => 46746,
1387 => 44633,
1388 => 40538,
1389 => 40538,
1390 => 44665,
1391 => 46714,
1392 => 42552,
1393 => 42553,
1394 => 48859,
1395 => 50939,
1396 => 48826,
1397 => 46746,
1398 => 44633,
1399 => 42553,
1400 => 44633,
1401 => 44698,
1402 => 46746,
1403 => 48827,
1404 => 46778,
1405 => 44666,
1406 => 44665,
1407 => 46746,
1408 => 44665,
1409 => 46778,
1410 => 46778,
1411 => 48859,
1412 => 61309,
1413 => 58638,
1414 => 63389,
1415 => 58441,
1416 => 58114,
1417 => 56098,
1418 => 56066,
1419 => 53953,
1420 => 63422,
1421 => 63226,
1422 => 60325,
1423 => 56066,
1424 => 46615,
1425 => 56197,
1426 => 46320,
1427 => 50218,
1428 => 56197,
1429 => 60357,
1430 => 48302,
1431 => 56755,
1432 => 44633,
1433 => 58769,
1434 => 44403,
1435 => 48302,
1436 => 65437,
1437 => 50874,
1438 => 56689,
1439 => 44633,
1440 => 40439,
1441 => 46714,
1442 => 52593,
1443 => 42553,
1444 => 44633,
1445 => 63422,
1446 => 65339,
1447 => 44469,
1448 => 63422,
1449 => 48269,
1450 => 56164,
1451 => 58376,
1452 => 63324,
1453 => 63422,
1454 => 63390,
1455 => 63390,
1456 => 61309,
1457 => 58178,
1458 => 58212,
1459 => 63127,
1460 => 63423,
1461 => 63390,
1462 => 63390,
1463 => 61309,
1464 => 58146,
1465 => 56098,
1466 => 58769,
1467 => 61342,
1468 => 63390,
1469 => 63390,
1470 => 61309,
1471 => 61375,
1472 => 57148,
1473 => 63422,
1474 => 63455,
1475 => 63291,
1476 => 58376,
1477 => 53985,
1478 => 46713,
1479 => 62996,
1480 => 58179,
1481 => 53888,
1482 => 46713,
1483 => 54477,
1484 => 58245,
1485 => 61080,
1486 => 46353,
1487 => 52232,
1488 => 60686,
1489 => 63422,
1490 => 61407,
1491 => 46385,
1492 => 63259,
1493 => 56262,
1494 => 53985,
1495 => 62930,
1496 => 58178,
1497 => 56066,
1498 => 52200,
1499 => 44337,
1500 => 44338,
1501 => 58145,
1502 => 52167,
1503 => 40472,
1504 => 52200,
1505 => 44403,
1506 => 56066,
1507 => 56098,
1508 => 60587,
1509 => 59196,
1510 => 48794,
1511 => 42520,
1512 => 56066,
1513 => 56066,
1514 => 58179,
1515 => 63062,
1516 => 46713,
1517 => 56460,
1518 => 61276,
1519 => 63390,
1520 => 52265,
1521 => 63390,
1522 => 63357,
1523 => 60587,
1524 => 52233,
1525 => 44338,
1526 => 58803,
1527 => 56131,
1528 => 58146,
1529 => 58507,
1530 => 57083,
1531 => 46714,
1532 => 53986,
1533 => 56066,
1534 => 58179,
1535 => 63062,
1536 => 63390,
1537 => 63390,
1538 => 57148,
1539 => 63390,
1540 => 46714,
1541 => 63390,
1542 => 63390,
1543 => 61277,
1544 => 44338,
1545 => 63062,
1546 => 61276,
1547 => 42487,
1548 => 58179,
1549 => 56361,
1550 => 56066,
1551 => 42520,
1552 => 58146,
1553 => 61046,
1554 => 60587,
1555 => 56131,
1556 => 63357,
1557 => 58933,
1558 => 63390,
1559 => 63390,
1560 => 61277,
1561 => 52266,
1562 => 58146,
1563 => 46681,
1564 => 60981,
1565 => 60489,
1566 => 56098,
1567 => 63390,
1568 => 60587,
1569 => 58178,
1570 => 56066,
1571 => 56098,
1572 => 56066,
1573 => 56066,
1574 => 61309,
1575 => 63390,
1576 => 61407,
1577 => 63390,
1578 => 61079,
1579 => 60620,
1580 => 58245,
1581 => 56066,
1582 => 58146,
1583 => 56066,
1584 => 54215,
1585 => 58146,
1586 => 53888,
1587 => 58179,
1588 => 58179,
1589 => 58343,
1590 => 40407,
1591 => 52397,
1592 => 62963,
1593 => 63291,
1594 => 61277,
1595 => 46713,
1596 => 57148,
1597 => 61375,
1598 => 63422,
1599 => 61145,
1600 => 56984,
1601 => 62767,
1602 => 58277,
1603 => 46386,
1604 => 56066,
1605 => 52200,
1606 => 58146,
1607 => 53920,
1608 => 46353,
1609 => 58179,
1610 => 58179,
1611 => 56262,
1612 => 42454,
1613 => 54313,
1614 => 62832,
1615 => 61178,
1616 => 61277,
1617 => 61309,
1618 => 63390,
1619 => 61375,
1620 => 61145,
1621 => 56985,
1622 => 62799,
1623 => 58277,
1624 => 46385,
1625 => 56066,
1626 => 58311,
1627 => 62963,
1628 => 63291,
1629 => 46713,
1630 => 63455,
1631 => 57148,
1632 => 61407,
1633 => 63422,
1634 => 61112,
1635 => 54904,
1636 => 58245,
1637 => 46386,
1638 => 58146,
1639 => 56066,
1640 => 52233,
1641 => 58146,
1642 => 44338,
1643 => 56066,
1644 => 58146,
1645 => 40472,
1646 => 42553,
1647 => 42585,
1648 => 40538,
1649 => 50874,
1650 => 44698,
1651 => 40472,
1652 => 42290,
1653 => 48269,
1654 => 60784,
1655 => 42258,
1656 => 40537,
1657 => 60784,
1658 => 60096,
1659 => 60849,
1660 => 60096,
1661 => 48269,
1662 => 50874,
1663 => 48301,
1664 => 60096,
1665 => 60816,
1666 => 42290,
1667 => 60752,
1668 => 40472,
1669 => 40440,
1670 => 48269,
1671 => 60784,
1672 => 50907,
1673 => 48269,
1674 => 60752,
1675 => 44698,
1676 => 42290,
1677 => 60752,
1678 => 48269,
1679 => 48269,
1680 => 44698,
1681 => 60784,
1682 => 60751,
1683 => 48301,
1684 => 42290,
1685 => 50875,
1686 => 44698,
1687 => 44305,
1688 => 48269,
1689 => 56492,
1690 => 56099,
1691 => 56098,
1692 => 58146,
1693 => 58310,
1694 => 63291,
1695 => 63422,
1696 => 58310,
1697 => 58146,
1698 => 61309,
1699 => 63357,
1700 => 60587,
1701 => 65371,
1702 => 58146,
1703 => 61342,
1704 => 63390,
1705 => 63160,
1706 => 56262,
1707 => 52233,
1708 => 50382,
1709 => 50841,
1710 => 50907,
1711 => 48335,
1712 => 58671,
1713 => 63324,
1714 => 65503,
1715 => 65503,
1716 => 55068,
1717 => 44502,
1718 => 40439,
1719 => 56098,
1720 => 60555,
1721 => 63160,
1722 => 55068,
1723 => 40504,
1724 => 56098,
1725 => 56262,
1726 => 58310,
1727 => 50350,
1728 => 63259,
1729 => 52889,
1730 => 63422,
1731 => 65503,
1732 => 55068,
1733 => 63390,
1734 => 61244,
1735 => 44534,
1736 => 61309,
1737 => 63062,
1738 => 60521,
1739 => 52233,
1740 => 42422,
1741 => 58671,
1742 => 56131,
1743 => 58146,
1744 => 52233,
1745 => 44534,
1746 => 56033,
1747 => 60489,
1748 => 61243,
1749 => 55068,
1750 => 50841,
1751 => 56066,
1752 => 56131,
1753 => 63061,
1754 => 58737,
1755 => 61277,
1756 => 63390,
1757 => 63259,
1758 => 63422,
1759 => 50350,
1760 => 50841,
1761 => 63291,
1762 => 58146,
1763 => 55068,
1764 => 63422,
1765 => 56098,
1766 => 56262,
1767 => 44535,
1768 => 61243,
1769 => 63390,
1770 => 56098,
1771 => 60555,
1772 => 63159,
1773 => 42454,
1774 => 60489,
1775 => 63061,
1776 => 61276,
1777 => 58737,
1778 => 63324,
1779 => 44535,
1780 => 52233,
1781 => 56131,
1782 => 56460,
1783 => 61342,
1784 => 63390,
1785 => 63160,
1786 => 56262,
1787 => 52233,
1788 => 50841,
1789 => 55068,
1790 => 61244,
1791 => 60521,
1792 => 56033,
1793 => 61309,
1794 => 63357,
1795 => 60587,
1796 => 63062,
1797 => 56131,
1798 => 56066,
1799 => 56426,
1800 => 56098,
1801 => 56098,
1802 => 58146,
1803 => 58310,
1804 => 63259,
1805 => 63422,
1806 => 61309,
1807 => 58836,
1808 => 60949,
1809 => 61342,
1810 => 63389,
1811 => 63422,
1812 => 63390,
1813 => 61309,
1814 => 63390,
1815 => 54970,
1816 => 59229,
1817 => 63422,
1818 => 63390,
1819 => 52987,
1820 => 63422,
1821 => 63422,
1822 => 63390,
1823 => 61439,
1824 => 48794,
1825 => 60784,
1826 => 53921,
1827 => 59196,
1828 => 44534,
1829 => 54247,
1830 => 56098,
1831 => 53985,
1832 => 54149,
1833 => 58146,
1834 => 56164,
1835 => 48269,
1836 => 58178,
1837 => 56098,
1838 => 42454,
1839 => 58146,
1840 => 56033,
1841 => 46352,
1842 => 58507,
1843 => 61407,
1844 => 52561,
1845 => 65339,
1846 => 61309,
1847 => 63390,
1848 => 63390,
1849 => 61309,
1850 => 44633,
1851 => 63390,
1852 => 61277,
1853 => 63423,
1854 => 61342,
1855 => 48794,
1856 => 63356,
1857 => 63160,
1858 => 58802,
1859 => 58408,
1860 => 58244,
1861 => 56098,
1862 => 54182,
1863 => 56098,
1864 => 58146,
1865 => 50218,
1866 => 58146,
1867 => 58146,
1868 => 48236,
1869 => 52955,
1870 => 63422,
1871 => 55035,
1872 => 63390,
1873 => 63390,
1874 => 61309,
1875 => 63390,
1876 => 44633,
1877 => 46615,
1878 => 63225,
1879 => 63357,
1880 => 61309,
1881 => 58409,
1882 => 58606,
1883 => 40439,
1884 => 52232,
1885 => 58114,
1886 => 53920,
1887 => 42389,
1888 => 56098,
1889 => 51873,
1890 => 58146,
1891 => 56066,
1892 => 56098,
1893 => 53985,
1894 => 56787,
1895 => 60358,
1896 => 50874,
1897 => 60981,
1898 => 63422,
1899 => 61342,
1900 => 63390,
1901 => 63390,
1902 => 63422,
1903 => 44502,
1904 => 44403,
1905 => 54215,
1906 => 63390,
1907 => 54149,
1908 => 58211,
1909 => 60751,
1910 => 61374,
1911 => 48269,
1912 => 56098,
1913 => 53824,
1914 => 56066,
1915 => 56066,
1916 => 58146,
1917 => 56066,
1918 => 58211,
1919 => 56098,
1920 => 58507,
1921 => 51905,
1922 => 51456,
1923 => 58310,
1924 => 61145,
1925 => 61277,
1926 => 62865,
1927 => 63422,
1928 => 57082,
1929 => 54445,
1930 => 61112,
1931 => 61309,
1932 => 60685,
1933 => 61309,
1934 => 61375,
1935 => 54904,
1936 => 63423,
1937 => 63324,
1938 => 58408,
1939 => 56033,
1940 => 42520,
1941 => 63094,
1942 => 58211,
1943 => 44666,
1944 => 52396,
1945 => 58080,
1946 => 44338,
1947 => 46681,
1948 => 61013,
1949 => 60489,
1950 => 56098,
1951 => 58146,
1952 => 61276,
1953 => 63390,
1954 => 60259,
1955 => 48302,
1956 => 48269,
1957 => 48334,
1958 => 50842,
1959 => 42651,
1960 => 44764,
1961 => 48925,
1962 => 46844,
1963 => 40472,
1964 => 40505,
1965 => 46746,
1966 => 48826,
1967 => 50907,
1968 => 48859,
1969 => 46746,
1970 => 44665,
1971 => 46746,
1972 => 44666,
1973 => 50939,
1974 => 46778,
1975 => 44666,
1976 => 48859,
1977 => 46746,
1978 => 46746,
1979 => 44665,
1980 => 48827,
1981 => 46746,
1982 => 44665,
1983 => 48859,
1984 => 48891,
1985 => 46778,
1986 => 46746,
1987 => 46778,
1988 => 48859,
1989 => 48859,
1990 => 44665,
1991 => 42585,
1992 => 46746,
1993 => 46713,
1994 => 40538,
1995 => 42585,
1996 => 40440,
1997 => 46876,
1998 => 44731,
1999 => 38392,
2000 => 50842,
2001 => 48302,
2002 => 42585,
2003 => 44666,
2004 => 48827,
2005 => 48827,
2006 => 46746,
2007 => 46746,
2008 => 60752,
2009 => 42290,
2010 => 48269,
2011 => 42290,
2012 => 60784,
2013 => 44666,
2014 => 40472,
2015 => 60850,
2016 => 46713,
2017 => 44370,
2018 => 65438,
2019 => 58736,
2020 => 44370,
2021 => 58770,
2022 => 60259,
2023 => 60816,
2024 => 60259,
2025 => 48269,
2026 => 40504,
2027 => 42585,
2028 => 40472,
2029 => 50875,
2030 => 65470,
2031 => 62897,
2032 => 58836,
2033 => 61277,
2034 => 63259,
2035 => 56098,
2036 => 56394,
2037 => 56131,
2038 => 63061,
2039 => 60555,
2040 => 63324,
2041 => 61309,
2042 => 56033,
2043 => 56098,
2044 => 60489,
2045 => 61243,
2046 => 63159,
2047 => 61342,
2048 => 56525,
2049 => 56131,
2050 => 44534,
2051 => 40472,
2052 => 44502,
2053 => 55067,
2054 => 63357,
2055 => 58802,
2056 => 61277,
2057 => 63160,
2058 => 60587,
2059 => 56099,
2060 => 63390,
2061 => 61244,
2062 => 44534,
2063 => 56098,
2064 => 40440,
2065 => 58146,
2066 => 52889,
2067 => 48334,
2068 => 58310,
2069 => 61277,
2070 => 58769,
2071 => 63062,
2072 => 56131,
2073 => 61244,
2074 => 56033,
2075 => 56131,
2076 => 56492,
2077 => 63061,
2078 => 61277,
2079 => 63422,
2080 => 58146,
2081 => 56262,
2082 => 56098,
2083 => 60587,
2084 => 44502,
2085 => 63357,
2086 => 58802,
2087 => 50382,
2088 => 52233,
2089 => 56262,
2090 => 63127,
2091 => 61310,
2092 => 60555,
2093 => 63324,
2094 => 56098,
2095 => 56492,
2096 => 50842,
2097 => 38392,
2098 => 40538,
2099 => 38392,
2100 => 38391,
2101 => 46746,
2102 => 46746,
2103 => 44633,
2104 => 38392,
2105 => 46778,
2106 => 44633,
2107 => 44633,
2108 => 38457,
2109 => 46778,
2110 => 48859,
2111 => 44763,
2112 => 48826,
2113 => 48925,
2114 => 50939,
2115 => 48891,
2116 => 44764,
2117 => 50907,
2118 => 46844,
2119 => 42552,
2120 => 48859,
2121 => 48827,
2122 => 14726,
2123 => 14758,
2124 => 14758,
2125 => 14758,
2126 => 14758,
2127 => 4193,
2128 => 14758,
2129 => 12613,
2130 => 12678,
2131 => 14758,
2132 => 12678,
2133 => 21130,
2134 => 25356,
2135 => 23210,
2136 => 31695,
2137 => 23243,
2138 => 23275,
2139 => 21130,
2140 => 16871,
2141 => 19017,
2142 => 23275,
2143 => 29582,
2144 => 57083,
2145 => 31727,
2146 => 38001,
2147 => 29549,
2148 => 16904,
2149 => 18984,
2150 => 29614,
2151 => 59131,
2152 => 31727,
2153 => 38034,
2154 => 29549,
2155 => 21097,
2156 => 23243,
2157 => 33808,
2158 => 25323,
2159 => 25356,
2160 => 21130,
2161 => 16871,
2162 => 10532,
2163 => 12645,
2164 => 14758,
2165 => 14726,
2166 => 14791,
2167 => 14791,
2168 => 14791);
type Object_Kind is (Rectangle_Obj, Point_Obj,
Ellipse_Obj, Polygon_Obj, Tile_Obj, Text_Obj);
type String_Access is access all String;
type Object
(Kind : Object_Kind := Rectangle_Obj)
is record
Name : String_Access;
Id : Natural;
X : GESTE.Maths_Types.Value;
Y : GESTE.Maths_Types.Value;
Width : GESTE.Maths_Types.Value;
Height : GESTE.Maths_Types.Value;
Str : String_Access;
Tile_Id : GESTE_Config.Tile_Index;
end record;
type Object_Array is array (Natural range <>)
of Object;
end Game_Assets;
|
charlie5/aIDE | Ada | 1,573 | ads | with
AdaM.compilation_Unit,
AdaM.a_Package,
AdaM.a_Type,
AdaM.Declaration.of_exception;
package AdaM.Environment
--
--
--
is
type Item is tagged private;
procedure add_package_Standard (Self : in out Item);
procedure add (Self : in out Item; Unit : in compilation_Unit.view);
procedure clear (Self : in out Item);
function Length (Self : in Item) return Natural;
function Unit (Self : in Item; Index : Positive) return compilation_Unit.View;
function all_Types (Self : in Item) return AdaM.a_Type.Vector;
procedure print (Self : in Item);
procedure print_Entities (Self : in Item);
procedure standard_package_is (Self : in out Item; Now : in AdaM.a_Package.view);
function standard_Package (Self : in Item) return AdaM.a_Package.view;
function find (Self : in Item; Identifier : in AdaM.Identifier) return AdaM.a_Type.view;
function find (Self : in Item; Identifier : in AdaM.Identifier) return AdaM.Declaration.of_exception.view;
function find (Self : in Item; Identifier : in AdaM.Identifier) return AdaM.a_Package.view;
function fetch (Self : in Item; Identifier : in AdaM.Identifier) return AdaM.a_Package.view;
-- function parent_Name (Identifier : in String) return String;
-- function simple_Name (Identifier : in String) return String;
private
type Item is tagged
record
Units : Compilation_Unit.Vector;
standard_Package : AdaM.a_Package.view;
end record;
end AdaM.Environment;
|
pombredanne/ravenadm | Ada | 5,110 | ads | -- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Ada.Calendar;
package PortScan.Log is
package CAL renames Ada.Calendar;
overall_log : exception;
-- Open log, dump diagnostic data and stop timer.
function initialize_log
(log_handle : in out TIO.File_Type;
head_time : out CAL.Time;
seq_id : port_id;
slave_root : String;
UNAME : String;
BENV : String;
COPTS : String;
PTVAR : String) return Boolean;
-- Stop time, write duration data, close log
procedure finalize_log
(log_handle : in out TIO.File_Type;
head_time : CAL.Time;
tail_time : out CAL.Time);
-- Helper to format phase/section heading
function log_section (title : String) return String;
-- Format start of build phase in log
procedure log_phase_begin (log_handle : TIO.File_Type; phase : String);
-- Format end of build phase in log
procedure log_phase_end (log_handle : TIO.File_Type);
-- Standard log name based on port origin and variant.
function log_name (sid : port_id) return String;
-- Returns formatted difference in seconds between two times
function elapsed_HH_MM_SS (start, stop : CAL.Time) return String;
-- Returns formatted difference in seconds between overall start time and now.
function elapsed_now return String;
-- Establish times before the start and upon completion of a scan.
procedure set_scan_start_time (mark : CAL.Time);
procedure set_scan_complete (mark : CAL.Time);
-- Establish times before the start and upon completion of a bulk run
procedure set_overall_start_time (mark : CAL.Time);
procedure set_overall_complete (mark : CAL.Time);
-- build log operations
procedure start_logging (flavor : count_type);
procedure stop_logging (flavor : count_type);
procedure scribe (flavor : count_type; line : String; flush_after : Boolean);
procedure flush_log (flavor : count_type);
-- Establish values of build counters
procedure set_build_counters (A, B, C, D, E : Natural);
-- Increments the indicated build counter by some quality.
procedure increment_build_counter (flavor : count_type; quantity : Natural := 1);
-- Open log to document packages that get deleted and the reason why
procedure start_obsolete_package_logging;
procedure stop_obsolete_package_logging;
-- Write to log if open and optionally output a copy to screen.
procedure obsolete_notice (message : String; write_to_screen : Boolean);
-- Return WWW report-formatted timestamp of start time.
function www_timestamp_start_time return String;
-- Return current build queue size
function ports_remaining_to_build return Integer;
-- Return value of individual port counter
function port_counter_value (flavor : count_type) return Integer;
-- Return number of packages built since build started
function hourly_build_rate return Natural;
-- Return number of packages built in the last 600 seconds
function impulse_rate return Natural;
-- Show duration between overall start and stop times.
function bulk_run_duration return String;
-- Return formatted duration of scan
function scan_duration return String;
-- Former private function exposed for web page generator
function timestamp (hack : CAL.Time; www_format : Boolean := False) return String;
private
type impulse_rec is
record
hack : CAL.Time;
packages : Natural := 0;
virgin : Boolean := True;
end record;
subtype logname_field is String (1 .. 19);
subtype impulse_range is Integer range 1 .. 600;
type dim_handlers is array (count_type) of TIO.File_Type;
type dim_counters is array (count_type) of Natural;
type dim_logname is array (count_type) of logname_field;
type dim_impulse is array (impulse_range) of impulse_rec;
function log_duration (start, stop : CAL.Time) return String;
function split_collection (line : String; title : String) return String;
procedure dump_port_variables (log_handle : TIO.File_Type; contents : String);
-- Simple time calculation (guts)
function get_packages_per_hour (packages_done : Natural; from_when : CAL.Time) return Natural;
-- bulk run variables
Flog : dim_handlers;
start_time : CAL.Time;
stop_time : CAL.Time;
scan_start : CAL.Time;
scan_stop : CAL.Time;
bld_counter : dim_counters := (0, 0, 0, 0, 0);
impulse_counter : impulse_range := impulse_range'Last;
impulse_data : dim_impulse;
obsolete_pkg_log : TIO.File_Type;
obsolete_log_open : Boolean := False;
bailing : constant String := " (ravenadm must exit)";
logname : constant dim_logname := ("00_last_results.log",
"01_success_list.log",
"02_failure_list.log",
"03_ignored_list.log",
"04_skipped_list.log");
end PortScan.Log;
|
ohenley/ada-util | Ada | 3,480 | adb | -----------------------------------------------------------------------
-- util-streams-raw -- Raw streams (OS specific)
-- Copyright (C) 2011, 2016 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.IO_Exceptions;
package body Util.Streams.Raw is
use Util.Systems.Os;
-- -----------------------
-- Initialize the raw stream to read and write on the given file descriptor.
-- -----------------------
procedure Initialize (Stream : in out Raw_Stream;
File : in File_Type) is
begin
if Stream.File /= NO_FILE then
raise Ada.IO_Exceptions.Status_Error;
end if;
Stream.File := File;
end Initialize;
-- -----------------------
-- Close the stream.
-- -----------------------
overriding
procedure Close (Stream : in out Raw_Stream) is
begin
if Stream.File /= NO_FILE then
if Close (Stream.File) /= 0 then
raise Ada.IO_Exceptions.Device_Error;
end if;
Stream.File := NO_FILE;
end if;
end Close;
-- -----------------------
-- Write the buffer array to the output stream.
-- -----------------------
procedure Write (Stream : in out Raw_Stream;
Buffer : in Ada.Streams.Stream_Element_Array) is
begin
if Write (Stream.File, Buffer'Address, Buffer'Length) < 0 then
raise Ada.IO_Exceptions.Device_Error;
end if;
end Write;
-- -----------------------
-- Read into the buffer as many bytes as possible and return in
-- <b>last</b> the position of the last byte read.
-- -----------------------
procedure Read (Stream : in out Raw_Stream;
Into : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset) is
Res : Ssize_T;
begin
Res := Read (Stream.File, Into'Address, Into'Length);
if Res < 0 then
raise Ada.IO_Exceptions.Device_Error;
end if;
Last := Into'First + Ada.Streams.Stream_Element_Offset (Res) - 1;
end Read;
-- -----------------------
-- Reposition the read/write file offset.
-- -----------------------
procedure Seek (Stream : in out Raw_Stream;
Pos : in Util.Systems.Types.off_t;
Mode : in Util.Systems.Types.Seek_Mode) is
use type Util.Systems.Types.off_t;
Res : Util.Systems.Types.off_t;
begin
Res := Sys_Lseek (Stream.File, Pos, Mode);
if Res < 0 then
raise Ada.IO_Exceptions.Device_Error;
end if;
end Seek;
-- -----------------------
-- Flush the stream and release the buffer.
-- -----------------------
procedure Finalize (Object : in out Raw_Stream) is
begin
Close (Object);
end Finalize;
end Util.Streams.Raw;
|
zhmu/ananas | Ada | 569 | ads | -- { dg-do compile }
package Unchecked_Union2 is
type Small_Int is range 0 .. 2**19 - 1;
type R1 (B : Boolean := True) is record
case B is
when True => Data1 : Small_Int;
when False => Data2 : Small_Int;
end case;
end record;
for R1 use record
Data1 at 0 range 0 .. 18;
Data2 at 0 range 0 .. 18;
end record;
for R1'Size use 24;
pragma Unchecked_Union (R1);
type R2 is record
Data : R1;
end record;
for R2 use record
Data at 0 range 3 .. 26;
end record;
end Unchecked_Union2;
|
kjseefried/coreland-cgbc | Ada | 1,034 | adb | with Ada.Strings;
with CGBC.Bounded_Wide_Wide_Strings;
with Test;
procedure T_WWBstr_Element_01 is
package BS renames CGBC.Bounded_Wide_Wide_Strings;
TC : Test.Context_t;
S1 : BS.Bounded_String (8);
Error : Boolean;
E : Wide_Wide_Character;
begin
Test.Initialize
(Test_Context => TC,
Program => "t_wwbstr_element_01",
Test_DB => "TEST_DB",
Test_Results => "TEST_RESULTS");
BS.Append (S1, "ABCD");
pragma Assert (BS.Length (S1) = 4);
Test.Check (TC, 2251, BS.Element (S1, 1) = 'A', "BS.Element (S1, 1) = 'A'");
Test.Check (TC, 2252, BS.Element (S1, 2) = 'B', "BS.Element (S1, 2) = 'B'");
Test.Check (TC, 2253, BS.Element (S1, 3) = 'C', "BS.Element (S1, 3) = 'C'");
Test.Check (TC, 2254, BS.Element (S1, 4) = 'D', "BS.Element (S1, 4) = 'D'");
Error := False;
begin
E := BS.Element (S1, 5);
pragma Assert (not E'Valid);
exception
when Ada.Strings.Index_Error => Error := True;
end;
Test.Check (TC, 2255, Error, "Error");
end T_WWBstr_Element_01;
|
stcarrez/ada-util | Ada | 6,922 | ads | -----------------------------------------------------------------------
-- util-texts-builders -- Text builder
-- Copyright (C) 2013, 2017, 2021, 2022 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.
-----------------------------------------------------------------------
private with Ada.Finalization;
-- == Text Builders ==
-- The `Util.Texts.Builders` generic package was designed to provide string builders.
-- The interface was designed to reduce memory copies as much as possible.
--
-- * The `Builder` type holds a list of chunks into which texts are appended.
-- * The builder type holds an initial chunk whose capacity is defined when the builder
-- instance is declared.
-- * There is only an `Append` procedure which allows to append text to the builder.
-- This is the only time when a copy is made.
-- * The package defines the `Iterate` operation that allows to get the content
-- collected by the builder. When using the `Iterate` operation, no copy is
-- performed since chunks data are passed passed by reference.
-- * The type is limited to forbid copies of the builder instance.
--
-- First, instantiate the package for the element type (eg, String):
--
-- package String_Builder is new Util.Texts.Builders (Character, String);
--
-- Declare the string builder instance with its initial capacity:
--
-- Builder : String_Builder.Builder (256);
--
-- And append to it:
--
-- String_Builder.Append (Builder, "Hello");
--
-- To get the content collected in the builder instance, write a procedure that receives
-- the chunk data as parameter:
--
-- procedure Collect (Item : in String) is ...
--
-- And use the `Iterate` operation:
--
-- String_Builder.Iterate (Builder, Collect'Access);
--
generic
type Element_Type is (<>);
type Input is array (Positive range <>) of Element_Type;
Chunk_Size : Positive := 80;
package Util.Texts.Builders is
pragma Preelaborate;
type Builder (Len : Positive) is limited private;
-- Get the length of the item builder.
function Length (Source : in Builder) return Natural;
-- Get the capacity of the builder.
function Capacity (Source : in Builder) return Natural;
-- Get the builder block size.
function Block_Size (Source : in Builder) return Positive;
-- Set the block size for the allocation of next chunks.
procedure Set_Block_Size (Source : in out Builder;
Size : in Positive);
-- Append the <tt>New_Item</tt> at the end of the source growing the buffer if necessary.
procedure Append (Source : in out Builder;
New_Item : in Input);
-- Append the <tt>New_Item</tt> at the end of the source growing the buffer if necessary.
procedure Append (Source : in out Builder;
New_Item : in Element_Type);
-- Append in `Into` builder the `Content` builder starting at `From` position
-- and the up to and including the `To` position.
procedure Append (Into : in out Builder;
Content : in Builder;
From : in Positive;
To : in Positive);
generic
with procedure Process (Content : in out Input; Last : out Natural);
procedure Inline_Append (Source : in out Builder);
-- Clear the source freeing any storage allocated for the buffer.
procedure Clear (Source : in out Builder);
-- Iterate over the buffer content calling the <tt>Process</tt> procedure with each
-- chunk.
procedure Iterate (Source : in Builder;
Process : not null access procedure (Chunk : in Input));
generic
with procedure Process (Content : in Input);
procedure Inline_Iterate (Source : in Builder);
generic
with procedure Process (Content : in out Input);
procedure Inline_Update (Source : in out Builder);
-- Get the buffer content as an array.
function To_Array (Source : in Builder) return Input;
-- Return the content starting from the tail and up to <tt>Length</tt> items.
function Tail (Source : in Builder;
Length : in Natural) return Input;
-- Get the element at the given position.
function Element (Source : in Builder;
Position : in Positive) return Element_Type;
-- Find the position of some content by running the `Index` function.
-- The `Index` function is called with chunks starting at the given position and
-- until it returns a positive value or we reach the last chunk. It must return
-- the found position in the chunk.
generic
with function Index (Content : in Input) return Natural;
function Find (Source : in Builder;
Position : in Positive) return Natural;
-- Call the <tt>Process</tt> procedure with the full buffer content, trying to avoid
-- secondary stack copies as much as possible.
generic
with procedure Process (Content : in Input);
procedure Get (Source : in Builder);
-- Format the message and replace occurrences of argument patterns by
-- their associated value.
-- Returns the formatted message in the stream
generic
type Value is limited private;
type Value_List is array (Positive range <>) of Value;
with procedure Append (Input : in out Builder; Item : in Value);
procedure Format (Into : in out Builder;
Message : in Input;
Arguments : in Value_List);
private
pragma Inline (Length);
pragma Inline (Iterate);
type Block;
type Block_Access is access all Block;
type Block (Len : Positive) is limited record
Next_Block : Block_Access;
Last : Natural := 0;
Content : Input (1 .. Len);
end record;
type Builder (Len : Positive) is new Ada.Finalization.Limited_Controlled with record
Current : Block_Access;
Block_Size : Positive := Chunk_Size;
Length : Natural := 0;
First : aliased Block (Len);
end record;
pragma Finalize_Storage_Only (Builder);
-- Setup the builder.
overriding
procedure Initialize (Source : in out Builder);
-- Finalize the builder releasing the storage.
overriding
procedure Finalize (Source : in out Builder);
end Util.Texts.Builders;
|
reznikmm/matreshka | Ada | 3,714 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- 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 XML.DOM.Elements;
package ODF.DOM.Text_Sender_Postal_Code_Elements is
pragma Preelaborate;
type ODF_Text_Sender_Postal_Code is limited interface
and XML.DOM.Elements.DOM_Element;
type ODF_Text_Sender_Postal_Code_Access is
access all ODF_Text_Sender_Postal_Code'Class
with Storage_Size => 0;
end ODF.DOM.Text_Sender_Postal_Code_Elements;
|
MinimSecure/unum-sdk | Ada | 815 | adb | -- Copyright 2008-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 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Pck; use Pck;
procedure Foo is
begin
if Is_First then
Increment;
end if;
end Foo;
|
zhmu/ananas | Ada | 2,469 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- A D A . S T R I N G S . H A S H --
-- --
-- B o d y --
-- --
-- Copyright (C) 2004-2022, 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 System.String_Hash;
function Ada.Strings.Hash (Key : String) return Containers.Hash_Type is
use Ada.Containers;
function Hash is new System.String_Hash.Hash
(Character, String, Hash_Type);
begin
return Hash (Key);
end Ada.Strings.Hash;
|
reznikmm/matreshka | Ada | 3,749 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- 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 XML.DOM.Attributes;
package ODF.DOM.Form_Escape_Processing_Attributes is
pragma Preelaborate;
type ODF_Form_Escape_Processing_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Form_Escape_Processing_Attribute_Access is
access all ODF_Form_Escape_Processing_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Form_Escape_Processing_Attributes;
|
charlie5/lace | Ada | 83,028 | adb | with
openGL.Model.any,
openGL.Model.box.colored,
-- openGL.Model.box.lit_colored_textured,
-- gel.cone_twist_Joint,
gel.Conversions,
collada.Document,
collada.Library,
collada.Library.controllers,
-- collada.Library.visual_scenes,
collada.Library.animations,
opengl.Palette,
opengl.Geometry.lit_textured_skinned,
opengl.Program.lit_textured_skinned,
ada.Strings.unbounded,
ada.unchecked_Deallocation,
ada.Text_IO;
package body gel.Human_v1
is
use ada.Text_IO,
gel.linear_Algebra_3D;
package std_Physics renames standard.Physics;
my_Scale : constant := 1.0;
model_Name : access String;
procedure use_Model (Named : in String)
is
begin
if model_Name /= null then
raise Program_Error with "'gel.human' model name has already been set";
end if;
model_Name := new String' (Named);
end use_Model;
-----------
--- Utility
--
function "+" (From : in ada.strings.unbounded.unbounded_String) return String
renames ada.strings.unbounded.to_String;
function to_joint_Id (From : in String) return scene_joint_Id
is
Pad : String := From;
begin
if From = "" then
raise Constraint_Error;
-- return Armature;
end if;
for Each in Pad'Range loop
if Pad (Each) = '-'
or Pad (Each) = '.'
then
Pad (Each) := '_';
end if;
end loop;
-- put_Line ("Pad: '" & Pad & "'");
return scene_joint_Id'Value (Pad);
end to_joint_Id;
function to_Math (From : in collada.Matrix_4x4) return math.Matrix_4x4
is
use type math.Real;
begin
return (1 => (From (1, 1), From (1, 2), From (1, 3), From (1, 4)),
2 => (From (2, 1), From (2, 2), From (2, 3), From (2, 4)),
3 => (From (3, 1), From (3, 2), From (3, 3), From (3, 4)),
4 => (From (4, 1), From (4, 2), From (4, 3), From (4, 4)));
end to_Math;
to_scene_joint_Id : array (controller_joint_Id) of scene_joint_Id;
to_controller_joint_Id : array (scene_joint_Id ) of controller_joint_Id;
---------
--- Forge
--
package body Forge
is
function new_Human (World : access gel .World.item'Class;
Model : access openGL .Model.item'Class;
physics_Model : access std_Physics.Model.item'Class;
Mass : in math.Real := 0.0;
is_Kinematic : in Boolean := False) return Human_v1.view
is
Self : constant Human_v1.view := new Human_v1.item;
begin
Self.define (World, --Space,
Model,
physics_Model,
Mass,
is_Kinematic);
return Self;
end new_Human;
function new_Human (bone_Sprites : in human_v1.bone_Sprites;
controller_Joints : in human_types_v1.controller_Joints;
Model : access openGL.Model.item'Class) return Human_v1.view
is
the_Human : constant human_v1.View := new human_v1.item;
begin
the_Human.bone_Sprites := bone_Sprites;
the_Human.controller_Joints := controller_Joints;
the_Human.Model := Model;
return the_Human;
end new_Human;
end Forge;
---------------------------
--- Skin Program Parameters
--
overriding
procedure enable (Self : in out skin_program_Parameters)
is
begin
for Each in Self.bone_Transforms'Range
loop
openGL.Program.lit_textured_skinned.view (Self.Program)
.bone_Transform_is (which => controller_joint_Id'Pos (Each) + 1,
now => Self.bone_Transforms (Each));
end loop;
end enable;
procedure set_global_Transform_for (Self : in out Item'Class;
the_Joint : in collada.Library.visual_scenes.Node_view)
is
use collada.Library, Math;
which_Joint : constant scene_joint_Id := to_joint_Id (+the_Joint.Name);
child_Joints : constant visual_scenes.Nodes := the_Joint.Children;
begin
Self.scene_Joints (which_Joint).Transform := (the_Joint.global_Transform);
declare
use type gel.Sprite.view;
the_bone_Id : bone_Id := bone_Id'Value (scene_joint_Id'Image (which_Joint));
the_global_Transform : Matrix_4x4 := the_Joint.global_Transform; -- * to_rotate_Matrix (X_Rotation_from (to_Radians (90.0)));
the_controller_Joint : controller_Joint renames Self.controller_Joints (controller_joint_Id (the_Bone_Id));
Site : Vector_3;
Rotation : Matrix_3x3;
bone_Offset : Vector_3 := the_controller_Joint.joint_to_bone_site_Offet;
begin
-- put_Line ("KKK: " & scene_joint_Id'Image (which_Joint));
if Self.bone_Sprites (the_bone_Id) /= null
then
if false -- which_Joint = Hips
then
null;
-- Site := get_Translation (the_global_Transform);
-- Site := (Site (1), Site (3), -Site (2)); -- Convert from Z-up to Y-up.
-- -- Site := get_Translation (to_translation_Matrix ( (Site (1), Site (3), -Site (2)))); -- Convert from Z-up to Y-up.
-- -- * Self.bone_Sprites (Hips).Transform);
--
-- Rotation := Inverse (get_Rotation (the_global_Transform));
-- Rotation := (1 => ( Rotation (1, 1), Rotation (1, 2), Rotation (1, 3)), -- Convert from Z-up to Y-up.
-- 2 => ( Rotation (3, 1), Rotation (3, 2), Rotation (3, 3)), --
-- 3 => (-Rotation (2, 1), -Rotation (2, 2), -Rotation (2, 3))); --
--
-- -- Rotation := Inverse (get_Rotation (Self.bone_Sprites (Hips).Transform))
-- -- * Rotation;
--
-- Site := Rotation * Site;
-- Self.bone_Sprites (the_bone_Id).Site_is (Site);
-- -- Self.bone_Sprites (the_bone_Id).Spin_is (Rotation);
else
Rotation := Inverse (get_Rotation (the_global_Transform));
Rotation := (1 => ( Rotation (1, 1), Rotation (1, 2), Rotation (1, 3)), -- Convert from Z-up to Y-up.
2 => ( Rotation (3, 1), Rotation (3, 2), Rotation (3, 3)), --
3 => (-Rotation (2, 1), -Rotation (2, 2), -Rotation (2, 3))); --
-- -- Rotation := Inverse (get_Rotation (Self.bone_Sprites (Hips).Transform))
-- Rotation := Inverse (get_Rotation (Self.skin_Sprite.Transform)) -- animation_Origin))
-- * Rotation;
-- Rotation := Rotation * get_Rotation (Self.skin_Sprite.Transform);
Site := get_Translation (the_global_Transform);
Site := Site - the_controller_Joint.joint_to_bone_site_Offet * (get_Rotation (the_global_Transform));
-- Site := Site - the_controller_Joint.joint_to_bone_site_Offet * Inverse (Rotation);
-- Site := (Site (1), Site (3), -Site (2)) -- Convert from Z-up to Y-up.
-- * get_Rotation (Self.animation_Origin);
Site := (Site (1), Site (3), -Site (2)) -- Convert from Z-up to Y-up.
* Self.skin_Sprite.Transform; -- animation_Origin);
-- * Self.bone_Sprites (Hips).Transform);
bone_Offset := (bone_Offset (1), bone_Offset (3), -bone_Offset (2));
bone_Offset := bone_Offset * (Rotation);
-- Site := Site - bone_Offset;
-- Site := Site + (bone_Offset (1), bone_Offset (3), -bone_Offset (2));
-- Site := Site + (bone_Offset (1), bone_Offset (2), bone_Offset (3));
Self.bone_Sprites (the_bone_Id).Site_is (Site);
Self.bone_Sprites (the_bone_Id).Spin_is (Rotation);
end if;
end if;
end;
Self.scene_Joints (which_Joint).Node := the_Joint; -- tbd: move this to initialisation.
for Each in child_Joints'Range
loop
set_global_Transform_for (Self, child_Joints (Each)); -- Recurse over children.
end loop;
end set_global_Transform_for;
procedure update_all_global_Transforms (Self : in out Item'Class)
is
begin
set_global_Transform_for (Self, Self.root_Joint); -- Re-determine all joint transforms, recursively.
-- Self.skin_Sprite.Transform_is (Self.animation_Origin);
end update_all_global_Transforms;
procedure set_rotation_Angle (Self : in out Item'Class; for_Joint : in scene_joint_Id;
Axis : in Axis_Kind;
To : in math.Real)
is
begin
case Axis is
when x_Axis => Self.set_x_rotation_Angle (for_Joint, To);
when y_Axis => Self.set_y_rotation_Angle (for_Joint, To);
when z_Axis => Self.set_z_rotation_Angle (for_Joint, To);
end case;
end set_rotation_Angle;
procedure set_Location (Self : in out Item'Class; for_Joint : in scene_joint_Id;
To : in math.Vector_3)
is
begin
Self.scene_Joints (for_Joint).Node.set_Location (To);
end set_Location;
procedure set_Transform (Self : in out Item'Class; for_Joint : in scene_joint_Id;
To : in math.Matrix_4x4)
is
begin
Self.scene_Joints (for_Joint).Node.set_Transform (To);
end set_Transform;
procedure set_x_rotation_Angle (Self : in out Item'Class; for_Joint : in scene_joint_Id;
To : in math.Real)
is
begin
Self.scene_Joints (for_Joint).Node.set_x_rotation_Angle (To);
end set_x_rotation_Angle;
procedure set_y_rotation_Angle (Self : in out Item'Class; for_Joint : in scene_joint_Id;
To : in math.Real)
is
begin
Self.scene_Joints (for_Joint).Node.set_y_rotation_Angle (To);
end set_y_rotation_Angle;
procedure set_z_rotation_Angle (Self : in out Item'Class; for_Joint : in scene_joint_Id;
To : in math.Real)
is
begin
Self.scene_Joints (for_Joint).Node.set_z_rotation_Angle (To);
end set_z_rotation_Angle;
procedure destroy (Self : in out Item)
is
use openGL.Model, gel.Sprite;
the_base_Sprite : gel.Sprite.view := Self.base_Sprite;
procedure free_Model_for (the_Sprite : in out gel.Sprite.view)
is
type Model_view is access all openGL.Model.item'Class;
procedure deallocate is new ada.unchecked_Deallocation (openGL.Model.item'Class, Model_view);
the_Model : Model_view := Model_view (the_sprite.graphics_Model);
the_child_Joints : constant gel.Joint.views := the_Sprite.child_Joints;
the_Child : gel.Sprite.view;
begin
if the_Sprite /= the_base_Sprite then
destroy (the_Model.all);
deallocate (the_Model);
end if;
-- do children
--
for Each in the_child_Joints'Range loop
the_Child := the_child_Joints (Each).Sprite_B.all'Access;
free_Model_for (the_Child); -- recurse
end loop;
end free_Model_for;
begin
free_Model_for (the_base_Sprite);
free (the_base_Sprite);
end destroy;
procedure free (Self : in out View)
is
procedure deallocate is new ada.Unchecked_Deallocation (Item'Class, View);
begin
Self.destroy;
deallocate (Self);
end free;
--------------
--- Human Item
--
the_global_Document : collada.Document.item;
the_global_Document_is_defined : Boolean := False;
procedure define (Self : in out Item; World : access gel .World.item'Class;
Model : access openGL .Model.item'Class;
physics_Model : access std_Physics.Model.item'Class;
Mass : in math.Real := 0.0;
is_Kinematic : in Boolean := True)
is
pragma Unreferenced (Mass);
use collada.Library,
collada.Library.visual_scenes,
math.Algebra.linear.d3,
ada.Strings,
ada.Strings.unbounded;
type gl_Model_view is access all openGL.Model.any.item;
-- the_Model : constant gl_Model_view := gl_Model_view (Model);
function the_Document return collada.Document.item
is
begin
if not the_global_Document_is_defined then
the_global_Document := collada.Document.to_Document (model_Name.all); -- tbd: free this at app close.
the_global_Document_is_defined := True;
end if;
return the_global_Document;
end the_Document;
-- the_root_Joint : visual_scenes.Node_view := the_Document.libraries.visual_Scenes.Contents (1).root_Node;
the_root_Joint : constant visual_scenes.Node_view
:= the_Document.libraries.visual_Scenes.Contents (1).root_Node.Child (1);
joint_Sites : array (scene_joint_Id) of math.Vector_3;
procedure set_Site_for (the_Joint : visual_scenes.Node_view; parent_Site : in math.Vector_3)
is
pragma Unreferenced (parent_Site);
use Math;
-- collada_Translation : collada.Vector_3 := the_Joint.Translation;
-- the_Site : math.Vector_3 := parent_Site + math.Vector_3'(math.Real (collada_Translation (1)),
-- math.Real (collada_Translation (2)),
-- math.Real (collada_Translation (3)));
which_Joint : constant scene_joint_Id := to_joint_Id (+the_Joint.Name);
child_Joints : constant visual_scenes.Nodes := the_Joint.Children;
begin
-- joint_Sites (which_Joint) := the_Site;
-- joint_Sites (which_Joint) := get_Translation (the_Joint.global_Transform);
joint_Sites (which_Joint)
:= get_Translation (Inverse (Self.controller_Joints (to_controller_joint_Id (which_Joint))
.inverse_bind_Matrix));
-- joint_Sites (which_Joint) := joint_Sites (which_Joint) * my_Scale;
for Each in child_Joints'Range
loop
set_Site_for (child_Joints (Each), parent_site => joint_Sites (which_Joint)); -- do children, recursively
end loop;
end set_Site_for;
begin
-- Set the inverse bind matrices for all joints.
--
declare
use collada.Library.controllers, Math;
the_Skin : constant controllers.Skin := the_Document.libraries.controllers.Contents (1).Skin;
the_bind_Poses : constant collada.Matrix_4x4_array := bind_Poses_of (the_Skin);
begin
for Each in Self.controller_Joints'Range
loop
Self.controller_Joints (Each).inverse_bind_Matrix
:= Transpose (the_bind_Poses (controller_joint_Id'Pos (Each) + 1)); -- Transpose to correct for collada col major.
-- Scale the site in the joints inverse bind matrix.
declare
the_Site : math.Vector_3 := get_Translation (Self.controller_Joints (Each).inverse_bind_Matrix);
begin
-- the_Site := (the_Site (1),-- * my_Scale * 1.0,
-- the_Site (2),-- * my_Scale * 1.0,
-- the_Site (3));-- * my_Scale * 1.0);
the_Site := (the_Site (1) * my_Scale * 1.0,
the_Site (2) * my_Scale * 1.0,
the_Site (3) * my_Scale * 1.0);
set_Translation (Self.controller_Joints (Each).inverse_bind_Matrix,
the_Site);
end;
end loop;
end;
set_global_Transform_for (Self, the_root_Joint); -- Determine all joint transforms, recursively.
set_Site_for (the_root_Joint, parent_site => (0.0, 0.0, 0.0)); -- Determine all joint sites.
Self.Model := Model; --.all'Unchecked_Access; -- Remember our model.
Self.root_Joint := the_root_Joint; -- Remember our root joint.
-- the_Model.Scale := (my_Scale, my_Scale, my_Scale);
-- Define a sprite for each bone.
--
declare
use openGL.Model.box.colored, openGL.Model.box,
openGL, opengl.Palette,
math.Vectors;
use type math.Degrees;
procedure create_Bone (the_Bone : in human_Types_v1.bone_Id;
start_Joint : in scene_joint_Id;
end_Point : in math.Vector_3;
Scale : in math.Vector_3;
Mass : in math.Real)
is
use Math;
the_bone_Site : constant math.Vector_3 := midPoint (joint_Sites (start_Joint), end_Point);
the_controller_Joint : controller_Joint renames Self.controller_Joints (controller_joint_Id (the_Bone));
sprite_Name : constant String := "human.bone_Sprite" & bone_Id'Image (the_Bone);
function get_Mass return math.Real
is
begin
if is_Kinematic then
return 0.0;
else
return Mass;
end if;
end get_Mass;
the_physics_Model : constant standard.physics.Model.view
:= standard.physics.Model.Forge.new_physics_Model (shape_Info => (kind => std_Physics.Model.Cube,
half_extents => Scale / 2.0),
Mass => get_Mass);
begin
-- if the_Bone = Hips
-- then
-- declare
-- the_graphics_Model : constant gel.graphics_Model.box.lit_colored_textured.view
-- := gel.graphics_Model.Box.lit_colored_textured.Forge.new_Box
-- (scale => 1.0 * (Scale (1) * my_Scale, Scale (2) * my_Scale, Scale (3) * my_Scale), -- Self.Model.Scale,
-- faces => (front => (colors => (others => (Red, Opaque)),
-- texture_Name => null_Asset,
-- texture_object => <>),
-- rear => (colors => (others => (Blue, Opaque)),
-- texture_Name => null_Asset,
-- texture_object => <>),
-- upper => (colors => (others => (Green, Opaque)),
-- texture_Name => null_Asset,
-- texture_object => <>),
-- lower => (colors => (others => (Yellow, Opaque)),
-- texture_Name => null_Asset,
-- texture_object => <>),
-- left => (colors => (others => (Cyan, Opaque)),
-- texture_Name => null_Asset,
-- texture_object => <>),
-- right => (colors => (others => (Magenta, Opaque)),
-- texture_Name => null_Asset,
-- texture_object => <>)));
--
-- -- the_human_graphics_Model : aliased gel.graphics_Model.open_gl.view
-- -- := gel.graphics_Model.open_gl.forge.new_Model (scale => (1.0, 1.0, 1.0),
-- -- -- model => gel.to_Asset ("assets/gel/model/gel-human.dae"),
-- -- model => to_Asset (model_Name.all), --gel.to_Asset ("assets/gel/collada/mh-human-dae.dae"),
-- -- -- model => gel.to_Asset ("assets/gel/collada/alfieri.dae"),
-- -- texture => gel.null_Asset, -- gel.to_Asset ("assets/collada/gel-human-texture.tga"),
-- -- Texture_is_lucid => False);
-- begin
-- -- if the_display_Mode = Skin
-- -- or the_display_Mode = Skin_and_Bones
-- -- then
-- -- Self.bone_Sprites (the_Bone) := gel.Sprite.forge.new_Sprite (sprite_Name,
-- -- World,
-- -- the_human_graphics_Model,
-- -- -- Model,
-- -- the_physics_Model,
-- -- owns_graphics => True,
-- -- owns_physics => True,
-- -- is_kinematic => is_Kinematic);
-- -- else
-- Self.bone_Sprites (the_Bone) := gel.Sprite.forge.new_Sprite (sprite_Name,
-- World,
-- the_graphics_Model,
-- the_physics_Model,
-- owns_graphics => True,
-- owns_physics => True,
-- is_kinematic => is_Kinematic);
--
-- -- end if;
-- end;
-- else
declare
the_graphics_Model : constant openGL.Model.box.colored.view
:= openGL.Model.Box.colored.new_Box
(Size => (Scale (1) * my_Scale, Scale (2) * my_Scale, Scale (3) * my_Scale),
Faces => (front => (colors => (others => (Red, Opaque))),
rear => (colors => (others => (Blue, Opaque))),
upper => (colors => (others => (Green, Opaque))),
lower => (colors => (others => (Yellow, Opaque))),
left => (colors => (others => (Cyan, Opaque))),
right => (colors => (others => (Magenta, Opaque)))));
begin
Self.bone_Sprites (the_Bone) := gel.Sprite.forge.new_Sprite (sprite_Name,
gel.sprite.World_view (World),
Origin_3D,
the_graphics_Model,
the_physics_Model,
owns_graphics => True,
owns_physics => True,
is_kinematic => is_Kinematic);
if the_display_Mode = Skin
then
Self.bone_Sprites (the_Bone).is_Visible (False);
end if;
end;
-- end if;
-- the_bone_Site := the_bone_Site * my_Scale;
Self.bone_Sprites (the_Bone).Site_is (the_bone_Site);
-- if the_Bone = Hips
-- then
-- Self.bone_Sprites (the_Bone).Spin_is (get_Rotation (the_controller_Joint.inverse_bind_Matrix)); -- * x_Rotation_from (to_Radians (180.0)));
-- else
Self.bone_Sprites (the_Bone).Spin_is (get_Rotation (the_controller_Joint.inverse_bind_Matrix));
-- end if;
the_controller_Joint.joint_to_bone_site_Offet
:= Inverse (get_Rotation (the_controller_Joint.inverse_bind_Matrix))
* (joint_Sites (start_Joint) - the_bone_Site);
end create_Bone;
procedure attach_via_Ball (bone_A_Id,
bone_B_Id : in Bone_Id;
pitch_limits,
yaw_limits,
roll_Limits : in gel.Sprite.dof_limits := (math.to_Radians (-0.0),
math.to_Radians ( 0.0))) -- -20.0 .. 20.0
is
use Math;
joint_Id : constant controller_joint_Id
:= controller_joint_Id (bone_B_Id);
the_joint_Site : constant math.Vector_3
:= joint_Sites (scene_joint_id'Value (bone_id'Image (bone_B_Id)));
Bone_A : constant gel.Sprite.view := Self.bone_Sprites (bone_A_Id);
Bone_B : constant gel.Sprite.view := Self.bone_Sprites (bone_B_Id);
Frame_A : math.Matrix_4x4 := Self.controller_Joints (controller_joint_Id (bone_A_Id)).inverse_bind_Matrix;
Frame_B : math.Matrix_4x4 := Self.controller_Joints (controller_joint_Id (bone_B_Id)).inverse_bind_Matrix;
A_rot : constant math.Matrix_3x3 := inverse (get_Rotation (Frame_A));
B_rot : constant math.Matrix_3x3 := inverse (get_Rotation (Frame_B));
begin
set_Translation (Frame_A, A_rot * (the_joint_Site - Bone_A.Site));
set_Translation (Frame_B, B_rot * (the_joint_Site - Bone_B.Site));
-- set_Translation (Frame_A, A_rot * (the_joint_Site - Bone_A.Site) * my_Scale);
-- set_Translation (Frame_B, B_rot * (the_joint_Site - Bone_B.Site) * my_Scale);
-- if bone_A_Id = hips
-- and bone_B_Id = spine1
-- then
-- set_Rotation (Frame_B, X_Rotation_from (to_Radians (180.0)));
-- end if;
Self.bone_Sprites (bone_A_Id).attach_via_ball_Socket (Self.bone_Sprites (bone_B_Id),
frame_in_parent => Frame_A,
frame_in_child => Frame_B,
pitch_limits => pitch_Limits,
yaw_limits => yaw_limits,
roll_limits => roll_limits,
new_joint => Self.Joints (joint_Id));
end attach_via_Ball;
procedure attach_via_Hinge (bone_A_Id,
bone_B_Id : in Bone_Id;
Limits : in gel.Sprite.dof_limits := (math.to_Radians ( 0.0),
math.to_Radians (90.0)))
is
use Math;
joint_Id : constant controller_joint_Id
:= controller_joint_Id (bone_B_Id);
the_joint_Site : constant math.Vector_3
:= joint_Sites (scene_joint_id'Value (bone_id'Image (bone_B_Id)));
Bone_A : constant gel.Sprite.view := Self.bone_Sprites (bone_A_Id);
Bone_B : constant gel.Sprite.view := Self.bone_Sprites (bone_B_Id);
Frame_A : math.Matrix_4x4 := Self.controller_Joints (controller_joint_Id (bone_A_Id)).inverse_bind_Matrix;
Frame_B : math.Matrix_4x4 := Self.controller_Joints (controller_joint_Id (bone_B_Id)).inverse_bind_Matrix;
A_rot : constant math.Matrix_3x3 := inverse (get_Rotation (Frame_A));
B_rot : constant math.Matrix_3x3 := inverse (get_Rotation (Frame_B));
begin
set_Translation (Frame_A, A_rot * (the_joint_Site - Bone_A.Site));
set_Translation (Frame_B, B_rot * (the_joint_Site - Bone_B.Site));
-- set_Translation (Frame_A, A_rot * (the_joint_Site - Bone_A.Site) * my_Scale);
-- set_Translation (Frame_B, B_rot * (the_joint_Site - Bone_B.Site) * my_Scale);
set_Rotation (Frame_A, A_rot * z_rotation_from (math.to_Radians (-90.0)));
set_Rotation (Frame_B, B_rot * z_rotation_from (math.to_Radians (-90.0)));
Self.bone_Sprites (bone_A_Id).attach_via_Hinge (Self.bone_Sprites (bone_B_Id),
Frame_in_parent => Frame_A,
Frame_in_child => Frame_B,
Limits => Limits,
collide_Connected => False,
new_Joint => Self.Joints (joint_Id));
end attach_via_Hinge;
use Math;
bone_Extent : math.Real;
begin
-- Skin
--
declare
the_human_graphics_Model : aliased openGL.Model.any.view
:= openGL.Model.any.new_Model (Model => to_Asset (model_Name.all),
Texture => openGL.null_Asset, -- gel.to_Asset ("assets/collada/gel-human-texture.tga"),
Texture_is_lucid => False);
the_physics_Model : constant standard.physics.Model.view
:= standard.physics.Model.Forge.new_physics_Model (shape_Info => (Kind => standard.physics.Model.Cube,
half_Extents => (0.1, 0.1, 0.1)),
Mass => 1.0,
is_Tangible => False);
begin
Self.skin_Sprite := gel.Sprite.forge.new_Sprite ("human.skin_Sprite",
gel.sprite.World_view (World),
Origin_3D,
the_human_graphics_Model,
the_physics_Model,
owns_graphics => True,
owns_physics => True,
is_kinematic => is_Kinematic);
if the_display_Mode = Bones
then
Self.skin_Sprite.is_Visible (False);
end if;
end;
-- Hips
--
bone_Extent := 0.25 * Distance (joint_Sites (Hips), to => joint_Sites (Spine));
create_Bone (Hips,
Hips,
joint_Sites (Spine),
bone_Extent * (1.3, 0.6, 0.6),
Mass => 1.0);
-- Thigh_L
--
bone_Extent := 1.0 * Distance (joint_Sites (Thigh_L), to => joint_Sites (Shin_L));
create_Bone (Thigh_L, Thigh_L, joint_Sites (Shin_L), (0.25, 0.5, 0.25) * bone_Extent, 0.5);
attach_via_Ball (bone_A_Id => Hips,
bone_B_Id => Thigh_L,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- Shin_L
--
bone_Extent := 1.0 * Distance (joint_Sites (Shin_L), to => joint_Sites (Foot_L));
create_Bone (Shin_L, Shin_L, joint_Sites (Foot_L), (0.2, 0.8, 0.2) * bone_Extent, 0.5);
attach_via_Ball (bone_A_Id => Thigh_L,
bone_B_Id => Shin_L,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- Foot_L
--
bone_Extent := 1.0 * Distance (joint_Sites (Foot_L), to => joint_Sites (Toe_L));
create_Bone (Foot_L, Foot_L, joint_Sites (Toe_L), (0.4, 0.8, 0.2) * bone_Extent, 0.5);
attach_via_Ball (bone_A_Id => Shin_L,
bone_B_Id => Foot_L,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- Toe_L
--
bone_Extent := 1.0 * Distance (joint_Sites (Toe_L), to => joint_Sites (Foot_L));
create_Bone (Toe_L, Toe_L, joint_Sites (Toe_L) + (0.0, -0.05, 0.0), (0.6, 0.3, 0.1) * bone_Extent, 0.5);
attach_via_Ball (bone_A_Id => Foot_L,
bone_B_Id => Toe_L,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- Thigh_R
--
bone_Extent := 1.0 * Distance (joint_Sites (Thigh_R), to => joint_Sites (Shin_R));
create_Bone (Thigh_R, Thigh_R, joint_Sites (Shin_R), (0.25, 0.5, 0.25) * bone_Extent, 0.5);
attach_via_Ball (bone_A_Id => Hips,
bone_B_Id => Thigh_R,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- Shin_R
--
bone_Extent := 1.0 * Distance (joint_Sites (Shin_R), to => joint_Sites (Foot_R));
create_Bone (Shin_R, Shin_R, joint_Sites (Foot_R), (0.2, 0.8, 0.2) * bone_Extent, 0.5);
attach_via_Ball (bone_A_Id => Thigh_R,
bone_B_Id => Shin_R,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- Foot_R
--
bone_Extent := 1.0 * Distance (joint_Sites (Foot_R), to => joint_Sites (Toe_R));
create_Bone (Foot_R, Foot_R, joint_Sites (Toe_R), (0.4, 0.8, 0.2) * bone_Extent, 0.5);
attach_via_Ball (bone_A_Id => Shin_R,
bone_B_Id => Foot_R,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- Toe_R
--
bone_Extent := 1.0 * Distance (joint_Sites (Toe_R), to => joint_Sites (Foot_R));
create_Bone (Toe_R, Toe_R, joint_Sites (Toe_R) + (0.0, -0.05, 0.0), (0.6, 0.3, 0.1) * bone_Extent, 0.5);
attach_via_Ball (bone_A_Id => Foot_R,
bone_B_Id => Toe_R,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- Spine
--
bone_Extent := 1.0 * Distance (joint_Sites (Spine), to => joint_Sites (Chest));
create_Bone (Spine, Spine, joint_Sites (Chest), (1.4, 0.6, 0.9) * bone_Extent, 0.5);
attach_via_Ball (bone_A_Id => Hips,
bone_B_Id => Spine,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- Chest
--
bone_Extent := 1.0 * Distance (joint_Sites (Chest), to => joint_Sites (Neck));
create_Bone (Chest, Chest, joint_Sites (Neck), (0.8, 0.2, 0.20) * bone_Extent, 0.5); -- 0.6 * 0.5);
attach_via_Ball (bone_A_Id => Spine,
bone_B_Id => Chest,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
--- Right Arm
--
-- Right Clavicle
--
bone_Extent := 1.0 * Distance (joint_Sites (Clavicle_R), to => joint_Sites (upper_Arm_R));
create_Bone (Clavicle_R, Clavicle_R, joint_Sites (upper_Arm_R), (0.25, 0.25, 0.25) * bone_Extent, 0.5);
attach_via_Ball (Chest, Clavicle_R,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_limits => (-0.5, 0.5));
-- Right Upper Arm
--
bone_Extent := 1.0 * Distance (joint_Sites (upper_Arm_R), to => joint_Sites (Forearm_R));
create_Bone (upper_Arm_R, upper_Arm_R, joint_Sites (Forearm_R), (0.2, 0.7, 0.2) * bone_Extent, 0.5);
attach_via_Ball (Clavicle_R, upper_Arm_R,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_limits => (-0.5, 0.5));
-- Right Forearm
--
bone_Extent := 1.0 * Distance (joint_Sites (Forearm_R), to => joint_Sites (Hand_R));
create_Bone (Forearm_R, Forearm_R, joint_Sites (Hand_R), (0.2, 0.8, 0.2) * bone_Extent, 0.5);
attach_via_Ball (upper_Arm_R, Forearm_R,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_limits => (-0.5, 0.5));
-- Right Hand
--
bone_Extent := 1.0 * Distance (joint_Sites (Hand_R), to => joint_Sites (Thumb_02_R));
create_Bone (Hand_R, Hand_R, joint_Sites (Thumb_02_R) - (0.0, 0.0, 0.0), (0.8, 0.9, 0.2) * bone_Extent, 0.5);
attach_via_Ball (Forearm_R, Hand_R,
pitch_limits => (-0.5, 0.0),
yaw_limits => (-0.5, 0.0),
roll_limits => (-0.0, 0.0));
-- -- Right Thumb_02
-- --
-- bone_Extent := 1.0 * Distance (joint_Sites (Thumb_02_R), to => joint_Sites (Hand_R));
-- create_Bone (Thumb_02_R, Thumb_02_R, joint_Sites (Hand_R) - (0.5, 0.0, 0.0), (0.4, 0.15, 0.08) * bone_Extent, 0.5);
--
-- attach_via_Ball (Hand_R, Thumb_02_R,
-- pitch_limits => (-0.5, 0.0),
-- yaw_limits => (-0.5, 0.0),
-- roll_limits => (-0.0, 0.0));
--
-- -- Right Thumb_03
-- --
-- bone_Extent := 1.0 * Distance (joint_Sites (Thumb_03_R), to => joint_Sites (Hand_R));
-- create_Bone (Thumb_03_R, Thumb_03_R, joint_Sites (Hand_R) - (0.5, 0.0, 0.0), (0.4, 0.15, 0.08) * bone_Extent, 0.5);
--
-- attach_via_Ball (Hand_R, Thumb_03_R,
-- pitch_limits => (-0.5, 0.0),
-- yaw_limits => (-0.5, 0.0),
-- roll_limits => (-0.0, 0.0));
--
-- -- Right Index Finger
-- --
-- bone_Extent := 1.0 * Distance (joint_Sites (F_ring_01_R), to => joint_Sites (Hand_R));
-- create_Bone (F_ring_01_R, F_ring_01_R, joint_Sites (Hand_R) - (0.5, 0.0, 0.0), (0.4, 0.15, 0.08) * bone_Extent, 0.5);
--
-- attach_via_Ball (Hand_R, F_ring_01_R,
-- pitch_limits => (-0.5, 0.0),
-- yaw_limits => (-0.5, 0.0),
-- roll_limits => (-0.0, 0.0));
--
-- -- Right Ring Finger
-- --
-- bone_Extent := 1.0 * Distance (joint_Sites (F_index_01_R), to => joint_Sites (Hand_R));
-- create_Bone (F_index_01_R, F_index_01_R, joint_Sites (Hand_R) - (0.5, 0.0, 0.0), (0.4, 0.15, 0.08) * bone_Extent, 0.5);
--
-- attach_via_Ball (Hand_R, F_index_01_R,
-- pitch_limits => (-0.5, 0.0),
-- yaw_limits => (-0.5, 0.0),
-- roll_limits => (-0.0, 0.0));
--- Left Arm
--
-- Left Clavicle
--
bone_Extent := 1.0 * Distance (joint_Sites (Clavicle_L), to => joint_Sites (upper_Arm_L));
create_Bone (Clavicle_L, Clavicle_L, joint_Sites (upper_Arm_L), (0.25, 0.25, 0.25) * bone_Extent, 0.5);
attach_via_Ball (Chest, Clavicle_L,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_limits => (-0.5, 0.5));
-- Left Upper Arm
--
bone_Extent := 1.0 * Distance (joint_Sites (upper_Arm_L), to => joint_Sites (Forearm_L));
create_Bone (upper_Arm_L, upper_Arm_L, joint_Sites (Forearm_L), (0.2, 0.7, 0.2) * bone_Extent, 0.5);
attach_via_Ball (Clavicle_L, upper_Arm_L,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_limits => (-0.5, 0.5));
-- Left Forearm
--
bone_Extent := 0.75 * Distance (joint_Sites (Forearm_L), to => joint_Sites (Hand_L));
create_Bone (Forearm_L, Forearm_L, joint_Sites (Hand_L), (0.2, 0.8, 0.2) * bone_Extent, 0.5);
attach_via_Ball (upper_Arm_L, Forearm_L,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_limits => (-0.5, 0.5));
-- Left Hand
--
bone_Extent := 1.0 * Distance (joint_Sites (Hand_L), to => joint_Sites (Thumb_02_L));
create_Bone (Hand_L, Hand_L, joint_Sites (Thumb_02_L) - (0.0, 0.0, 0.0), (0.8, 0.9, 0.2) * bone_Extent, 0.5);
attach_via_Ball (Forearm_L, Hand_L,
pitch_limits => (-0.5, 0.0),
yaw_limits => (-0.5, 0.0),
roll_limits => (-0.0, 0.0));
-- -- Left Thumb_02
-- --
-- bone_Extent := 1.0 * Distance (joint_Sites (Thumb_02_L), to => joint_Sites (Hand_L));
-- create_Bone (Thumb_02_L, Thumb_02_L, joint_Sites (Hand_L) + (0.5, 0.0, 0.0), (0.4, 0.15, 0.08) * bone_Extent, 0.5);
--
-- attach_via_Ball (Hand_L, Thumb_02_L,
-- pitch_limits => (-0.5, 0.0),
-- yaw_limits => (-0.5, 0.0),
-- roll_limits => (-0.0, 0.0));
--
-- -- Left Thumb_03
-- --
-- bone_Extent := 1.0 * Distance (joint_Sites (Thumb_03_L), to => joint_Sites (Hand_L));
-- create_Bone (Thumb_03_L, Thumb_03_L, joint_Sites (Hand_L) + (0.5, 0.0, 0.0), (0.4, 0.15, 0.08) * bone_Extent, 0.5);
--
-- attach_via_Ball (Hand_L, Thumb_03_L,
-- pitch_limits => (-0.5, 0.0),
-- yaw_limits => (-0.5, 0.0),
-- roll_limits => (-0.0, 0.0));
--
-- -- Left Index Finger
-- --
-- bone_Extent := 1.0 * Distance (joint_Sites (F_ring_01_L), to => joint_Sites (Hand_L));
-- create_Bone (F_ring_01_L, F_ring_01_L, joint_Sites (Hand_L) + (0.5, 0.0, 0.0), (0.4, 0.15, 0.08) * bone_Extent, 0.5);
--
-- attach_via_Ball (Hand_L, F_ring_01_L,
-- pitch_limits => (-0.5, 0.0),
-- yaw_limits => (-0.5, 0.0),
-- roll_limits => (-0.0, 0.0));
--
-- -- Left Ring Finger
-- --
-- bone_Extent := 1.0 * Distance (joint_Sites (F_index_01_L), to => joint_Sites (Hand_L));
-- create_Bone (F_index_01_L, F_index_01_L, joint_Sites (Hand_L) + (0.5, 0.0, 0.0), (0.4, 0.15, 0.08) * bone_Extent, 0.5);
--
-- attach_via_Ball (Hand_L, F_index_01_L,
-- pitch_limits => (-0.5, 0.0),
-- yaw_limits => (-0.5, 0.0),
-- roll_limits => (-0.0, 0.0));
-- Neck
--
bone_Extent := 1.0 * Distance (joint_Sites (Neck), to => joint_Sites (Head));
create_Bone (Neck, Neck, joint_Sites (Head), (0.4, 0.6, 0.4) * bone_Extent, 0.4); -- 0.4 * 0.5);
attach_via_Ball (bone_A_Id => Chest,
bone_B_Id => Neck,
pitch_limits => (-0.4, 0.3),
yaw_limits => (-0.3, 0.3),
roll_Limits => (-0.2, 0.2));
-- Head
--
bone_Extent := 1.0 * Distance (joint_Sites (Head), to => joint_Sites (Neck));
create_Bone (Head, Head, joint_Sites (Head) + (0.0, 0.0, 0.05), (0.8, 0.6, 0.7) * bone_Extent, 0.25);
attach_via_Ball (bone_A_Id => Neck,
bone_B_Id => Head,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- Jaw
--
bone_Extent := 1.0 * Distance (joint_Sites (Jaw), to => joint_Sites (Head));
create_Bone (Jaw, Jaw, joint_Sites (Jaw) + (0.0, -0.07, 0.03), (0.9, 1.0, 0.3) * bone_Extent, 0.25);
attach_via_Ball (bone_A_Id => Head,
bone_B_Id => Jaw,
pitch_limits => (-0.5, 0.5),
yaw_limits => (-0.5, 0.5),
roll_Limits => (-0.5, 0.5));
-- -- Eye_R
-- --
-- bone_Extent := 0.1 * Distance (joint_Sites (Eye_R), to => joint_Sites (Head));
-- create_Bone (Eye_R, Eye_R, joint_Sites (Eye_R) + (0.0, 0.0, 0.0), (1.0, 1.4, 0.7) * bone_Extent, 0.25);
--
-- attach_via_Ball (Head, Eye_R);
--
-- -- Eye_L
-- --
-- bone_Extent := 0.1 * Distance (joint_Sites (Eye_L), to => joint_Sites (Head));
-- create_Bone (Eye_L, Eye_L, joint_Sites (Eye_L) + (0.0, 0.0, 0.0), (1.0, 1.4, 0.7) * bone_Extent, 0.25);
--
-- attach_via_Ball (Head, Eye_L);
end;
--- Parse the Collada animations file.
--
declare
use collada.Library.animations;
the_Animations : constant access animations.Animation_array := the_Document.Libraries.Animations.Contents;
begin
if the_Animations /= null
then
for Each in the_Animations'Range
loop
declare
the_Animation : constant animations.Animation := the_Animations (Each);
the_Inputs : access collada.float_Array := Inputs_of (the_Animation);
procedure common_setup (Channel : channel_Id; scene_Joint : scene_Joint_Id; Sid : in String)
is
begin
Self.Channels (Channel).Target := Self.scene_Joints (scene_Joint).Node.fetch_Transform (Sid);
Self.Channels (Channel).Times := Inputs_of (the_Animation);
Self.Channels (Channel).Values := Outputs_of (the_Animation);
for Each in Self.Channels (Channel).Times'Range
loop
Self.Channels (Channel).Times (Each) := Self.Channels (Channel).Times (Each) / 1.0; -- ???
end loop;
end common_setup;
procedure setup_Rotation (Channel : channel_Id; scene_Joint : scene_Joint_Id; Sid : in String)
is
begin
common_setup (Channel, scene_Joint, Sid);
-- For angle interpolation during 'rotation' animation.
--
Self.Channels (Channel).initial_Angle := Self.Channels (Channel).Values (1);
Self.Channels (Channel).current_Angle := Self.Channels (Channel).initial_Angle;
end setup_Rotation;
procedure setup_Location (Channel : channel_Id; scene_Joint : scene_Joint_Id; Sid : in String)
is
begin
common_setup (Channel, scene_Joint, Sid);
-- For location interpolation during 'translation' animation.
--
Self.Channels (Channel).current_Site := (Self.Channels (Channel).Values (1),
Self.Channels (Channel).Values (2),
Self.Channels (Channel).Values (3));
Self.Channels (Channel).initial_Site := Self.Channels (Channel).current_Site;
end setup_Location;
procedure setup_full_Transform (Channel : channel_Id; scene_Joint : scene_Joint_Id; Sid : in String)
is
begin
common_setup (Channel, scene_Joint, Sid);
-- For matrix interpolation during 'full_transform' animation.
--
Self.Channels (Channel).Transforms := new Transforms (1 .. Collada.matrix_Count (Self.Channels (Channel).Values.all));
for i in Self.Channels (Channel).Transforms'Range
loop
declare
the_Matrix : math.Matrix_4x4 := math.Transpose (Collada.get_Matrix (Self.Channels (Channel).Values.all, which => i));
begin
Self.Channels (Channel).Transforms (i) := (rotation => to_Quaternion (get_Rotation (the_Matrix)),
translation => get_Translation (the_Matrix));
end;
end loop;
Self.Channels (Channel).initial_Transform := Self.Channels (Channel).Transforms (1);
Self.Channels (Channel).current_Transform := Self.Channels (Channel).initial_Transform;
Self.Channels (Channel).current_Site := Self.Channels (Channel).initial_Transform.Translation;
Self.Channels (Channel).initial_Site := Self.Channels (Channel).current_Site;
end setup_full_Transform;
begin
if Index (the_Animation.Channel.Target, "hips/transform") /= 0 then
setup_full_Transform (Hips, Hips, "transform");
elsif Index (the_Animation.Channel.Target, "thigh_L/transform") /= 0 then
setup_full_Transform (Thigh_L, Thigh_L, "transform");
elsif Index (the_Animation.Channel.Target, "shin_L/transform") /= 0 then
setup_full_Transform (Shin_L, Shin_L, "transform");
elsif Index (the_Animation.Channel.Target, "foot_L/transform") /= 0 then
setup_full_Transform (Foot_L, Foot_L, "transform");
elsif Index (the_Animation.Channel.Target, "toe_L/transform") /= 0 then
setup_full_Transform (Toe_L, Toe_L, "transform");
elsif Index (the_Animation.Channel.Target, "thigh_R/transform") /= 0 then
setup_full_Transform (Thigh_R, Thigh_R, "transform");
elsif Index (the_Animation.Channel.Target, "shin_R/transform") /= 0 then
setup_full_Transform (Shin_R, Shin_R, "transform");
elsif Index (the_Animation.Channel.Target, "foot_R/transform") /= 0 then
setup_full_Transform (Foot_R, Foot_R, "transform");
elsif Index (the_Animation.Channel.Target, "toe_R/transform") /= 0 then
setup_full_Transform (Toe_R, Toe_R, "transform");
elsif Index (the_Animation.Channel.Target, "spine/transform") /= 0 then
setup_full_Transform (Spine, Spine, "transform");
elsif Index (the_Animation.Channel.Target, "chest/transform") /= 0 then
setup_full_Transform (Chest, Chest, "transform");
elsif Index (the_Animation.Channel.Target, "clavicle_R/transform") /= 0 then
setup_full_Transform (Clavicle_R, Clavicle_R, "transform");
elsif Index (the_Animation.Channel.Target, "upper_arm_R/transform") /= 0 then
setup_full_Transform (upper_Arm_R, upper_Arm_R, "transform");
elsif Index (the_Animation.Channel.Target, "forearm_R/transform") /= 0 then
setup_full_Transform (Forearm_R, Forearm_R, "transform");
elsif Index (the_Animation.Channel.Target, "hand_R/transform") /= 0 then
setup_full_Transform (Hand_R, Hand_R, "transform");
elsif Index (the_Animation.Channel.Target, "thumb_02_R/transform") /= 0 then
setup_full_Transform (Thumb_02_R, Thumb_02_R, "transform");
elsif Index (the_Animation.Channel.Target, "thumb_03_R/transform") /= 0 then
setup_full_Transform (Thumb_03_R, Thumb_03_R, "transform");
elsif Index (the_Animation.Channel.Target, "f_ring_01_R/transform") /= 0 then
setup_full_Transform (F_ring_01_R, F_ring_01_R, "transform");
elsif Index (the_Animation.Channel.Target, "f_index_01_R/transform") /= 0 then
setup_full_Transform (F_index_01_R, F_index_01_R, "transform");
elsif Index (the_Animation.Channel.Target, "clavicle_L/transform") /= 0 then
setup_full_Transform (Clavicle_L, Clavicle_L, "transform");
elsif Index (the_Animation.Channel.Target, "upper_arm_L/transform") /= 0 then
setup_full_Transform (upper_Arm_L, upper_Arm_L, "transform");
elsif Index (the_Animation.Channel.Target, "forearm_L/transform") /= 0 then
setup_full_Transform (Forearm_L, Forearm_L, "transform");
elsif Index (the_Animation.Channel.Target, "hand_L/transform") /= 0 then
setup_full_Transform (Hand_L, Hand_L, "transform");
elsif Index (the_Animation.Channel.Target, "thumb_02_L/transform") /= 0 then
setup_full_Transform (Thumb_02_L, Thumb_02_L, "transform");
elsif Index (the_Animation.Channel.Target, "thumb_03_L/transform") /= 0 then
setup_full_Transform (Thumb_03_L, Thumb_03_L, "transform");
elsif Index (the_Animation.Channel.Target, "f_ring_01_L/transform") /= 0 then
setup_full_Transform (F_ring_01_L, F_ring_01_L, "transform");
elsif Index (the_Animation.Channel.Target, "f_index_01_L/transform") /= 0 then
setup_full_Transform (F_index_01_L, F_index_01_L, "transform");
elsif Index (the_Animation.Channel.Target, "neck/transform") /= 0 then
setup_full_Transform (Neck, Neck, "transform");
elsif Index (the_Animation.Channel.Target, "head/transform") /= 0 then
setup_full_Transform (Head, Head, "transform");
elsif Index (the_Animation.Channel.Target, "jaw/transform") /= 0 then
setup_full_Transform (Jaw, Jaw, "transform");
elsif Index (the_Animation.Channel.Target, "eye_R/transform") /= 0 then
setup_full_Transform (Eye_R, Eye_R, "transform");
elsif Index (the_Animation.Channel.Target, "eye_L/transform") /= 0 then
setup_full_Transform (Eye_L, Eye_L, "transform");
end if;
end;
end loop;
end if;
end;
end define;
procedure motion_Mode_is (Self : in out Item; Now : in motion_Mode)
is
begin
Self.Mode := Now;
end motion_Mode_is;
procedure enable_Graphics (Self : in out Item)
is
begin
if the_display_Mode /= Bones
then
Self.program_Parameters.Program_is (opengl.Program.view (opengl.Geometry.lit_textured_skinned.Program));
Self.skin_Sprite.program_Parameters_are (Self.program_Parameters'Unchecked_Access);
-- Self.base_Sprite.program_Parameters_are (Self.program_Parameters'Unchecked_Access);
end if;
end enable_Graphics;
function controller_Joints (Self : in Item'Class) return human_types_v1.controller_Joints
is
begin
return Self.controller_Joints;
end controller_Joints;
procedure controller_Joints_are (Self : in out Item'Class; Now : in human_types_v1.controller_Joints)
is
begin
Self.controller_Joints := Now;
end controller_Joints_are;
--------------
--- Attributes
--
function Sprite (Self : in Item'Class; for_Bone : in bone_Id) return gel.Sprite.view
is
begin
return Self.bone_Sprites (for_Bone);
end Sprite;
function base_Sprite (Self : in Item'Class) return gel.Sprite.view
is
begin
return Self.bone_Sprites (Hips);
end base_Sprite;
function skin_Sprite (Self : in Item'Class) return gel.Sprite.view
is
begin
return Self.skin_Sprite;
end skin_Sprite;
procedure set_GL_program_Parameters (Self : in out Item'Class; for_Bone : in controller_joint_Id;
To : in math.Matrix_4x4)
is
use gel.Conversions;
begin
Self.program_Parameters.bone_Transforms (for_Bone) := to_GL (To);
end set_GL_program_Parameters;
--------------
--- Operations
--
procedure evolve (Self : in out Item'Class; world_Age : in Duration)
is
use Math, math.Vectors;
function get_root_Transform return math.Matrix_4x4
is
begin
if Self.Mode = Physics
then
put_Line ("Self.base_Sprite.Transform: ");
put_Line (math.Image (math.Matrix (Self.base_Sprite.Transform)));
return Self.base_Sprite.Transform;
-- return math.Identity_4x4;
-- return to_transform_Matrix (Rotation => x_Rotation_from (the_Angle => to_Radians (-90.0)),
-- Translation => (0.0, 0.0, 0.0));
else -- Is an animation.
-- return (Self.skin_Sprite.Transform);
-- return Inverse (Self.animation_Origin);
declare
the_Transform : math.Matrix_4x4 := math.Identity_4x4;
begin
set_Rotation (the_Transform, x_Rotation_from (to_Radians (-90.0))); -- Convert from Z-up to Y-up.
-- set_Rotation (the_Transform, Inverse (get_Rotation ( (Self.controller_Joints (Hips).inverse_bind_Matrix))));
set_Translation (the_Transform,
-- -get_Translation (Inverse (Self.animation_Origin)));
-get_Translation (Inverse (Self.controller_Joints (Hips).inverse_bind_Matrix)));
return the_Transform;
end;
end if;
end get_root_Transform;
root_Transform : constant math.Matrix_4x4 := get_root_Transform;
inv_root_Transform : constant math.Matrix_4x4 := Inverse (root_Transform);
function joint_Transform_for (the_collada_Joint : in controller_joint_Id) return math.Matrix_4x4
is
begin
-- put_Line ("KKKKKKKK: '" & controller_joint_Id'Image (the_collada_Joint) & "'");
if Self.Mode = Physics
then
declare
the_bone_Transform : constant math.Matrix_4x4
:= Self.bone_Sprites (bone_Id (the_collada_Joint)).Transform;
the_bone_Rotation : constant math.Matrix_3x3
:= get_Rotation (the_bone_Transform);
-- the_inv_bone_Rotation : math.Matrix_3x3 := Inverse (the_bone_Rotation);
the_joint_site_Offset : constant math.Vector_3
:= Self.controller_Joints (the_collada_Joint).joint_to_bone_site_Offet * the_bone_Rotation;
the_joint_Transform : math.Matrix_4x4;
begin
set_Translation (the_joint_Transform, get_Translation (the_bone_Transform) + the_joint_site_Offset);
set_Rotation (the_joint_Transform, get_Rotation (the_bone_Transform));
return the_joint_Transform;
end;
else -- Must be animation mode.
return Self.scene_Joints (to_scene_joint_Id (the_collada_Joint)).Transform;
end if;
end joint_Transform_for;
procedure set_Transform_for (the_Bone : in controller_joint_Id)
is
begin
-- new_Line;
-- put_Line ("JOINT_TRANS for Bone:" & controller_joint_Id'Image (the_Bone));
-- put_Line (math.Image (math.Matrix (joint_Transform_for (the_Bone))));
--
-- new_Line;
-- put_Line ("Self.controller_Joints (the_Bone).inverse_bind_Matrix:");
-- put_Line (math.Image (math.Matrix (Self.controller_Joints (the_Bone).inverse_bind_Matrix)));
Self.set_GL_program_Parameters (for_bone => the_Bone,
to => Self.controller_Joints (the_Bone).inverse_bind_Matrix
* joint_Transform_for (the_Bone)
* inv_root_Transform);
end set_Transform_for;
procedure set_proxy_Transform_for (the_Bone : in controller_joint_Id; the_Proxy : in controller_joint_Id)
is
begin
Self.set_GL_program_Parameters (for_bone => the_Bone,
to => Self.controller_Joints (the_Proxy).inverse_bind_Matrix
* joint_Transform_for (the_Proxy)
* inv_root_Transform);
end set_proxy_Transform_for;
begin
if not Self.Graphics_enabled
then
Self.enable_Graphics;
Self.Graphics_enabled := True;
end if;
if Self.Mode = Animation
then
Self.animate (world_Age);
else
-- -- Self.skin_Sprite.Transform_is (Self.base_Sprite.Transform);
Self.skin_Sprite.rotate (Self.base_Sprite.Spin);
Self.skin_Sprite.move (Self.base_Sprite.Site);
null;
end if;
-- tbd: Can probly do the below 'set_Transform_for' calls in a loop.
-- Torso
--
set_Transform_for (Hips);
-- set_Transform_for (Spine);
-- set_Transform_for (Chest);
-- set_Transform_for (Neck);
--
-- set_Transform_for (Head);
-- set_Transform_for (Jaw);
-- set_proxy_Transform_for (Eye_R, Head);
-- set_proxy_Transform_for (Eye_L, Head);
--
--
-- -- Left Arm
-- --
-- set_Transform_for (Clavicle_L);
-- set_Transform_for (upper_Arm_L);
-- set_Transform_for (Forearm_L);
-- set_Transform_for (Hand_L);
-- set_proxy_Transform_for (Thumb_02_L, Hand_L);
-- set_proxy_Transform_for (Thumb_03_L, Hand_L);
-- set_proxy_Transform_for (F_ring_01_L, Hand_L);
-- set_proxy_Transform_for (F_index_01_L, Hand_L);
--
--
-- -- Right Arm
-- --
-- set_Transform_for (Clavicle_R);
-- set_Transform_for (upper_Arm_R);
-- set_Transform_for (Forearm_R);
-- set_Transform_for (Hand_R);
-- set_proxy_Transform_for (Thumb_02_R, Hand_R);
-- set_proxy_Transform_for (Thumb_03_R, Hand_R);
-- set_proxy_Transform_for (F_ring_01_R, Hand_R);
-- set_proxy_Transform_for (F_index_01_R, Hand_R);
--
--
-- -- Left Leg
-- --
-- set_Transform_for (Thigh_L);
-- set_Transform_for (Shin_L);
-- set_Transform_for (Foot_L);
-- set_Transform_for (Toe_L);
--
--
-- -- Right Leg
-- --
-- set_Transform_for (Thigh_R);
-- set_Transform_for (Shin_R);
-- set_Transform_for (Foot_R);
-- set_Transform_for (Toe_R);
end evolve;
-------------
-- Animation
--
procedure animate (Self : in out Item; world_Age : in Duration)
is
Now : Duration;
Elapsed : Duration;
procedure update_rotation_Animation (for_Channel : in channel_Id;
for_Joint : in gel.human_v1.scene_joint_Id;
for_Axis : in axis_Kind)
is
use Math;
the_Channel : animation_Channel renames Self.Channels (for_Channel);
Cursor : math.Index renames the_Channel.Cursor;
-- Elapsed : Duration := Now - start_Time;
function Reduced (Angle : in math.Real) return math.Real
is
begin
if Angle > 180.0 then return -360.0 + Angle;
elsif Angle < -180.0 then return 360.0 + Angle;
else return Angle;
end if;
end Reduced;
begin
if Cursor < the_Channel.Times'Last
then
if Cursor = 0
or else Elapsed > Duration (the_Channel.Times (Cursor))
then
Cursor := Cursor + 1;
if Cursor = 1
then
if the_Channel.Times (Cursor) = 0.0
then
the_Channel.interp_Delta := Reduced (the_Channel.Values (Cursor) - the_Channel.current_Angle);
else
the_Channel.interp_Delta := Reduced (the_Channel.Values (Cursor) - the_Channel.current_Angle)
/ (the_Channel.Times (Cursor));
end if;
else
the_Channel.interp_Delta := Reduced (the_Channel.Values (Cursor) - the_Channel.current_Angle)
/ (the_Channel.Times (Cursor) - the_Channel.Times (Cursor - 1));
end if;
the_Channel.interp_Delta := the_Channel.interp_Delta / 60.0; -- 60.0 is frames/sec
end if;
end if;
if Elapsed < Duration (the_Channel.Times (the_Channel.Times'Last))
then
the_Channel.current_Angle := Reduced ( the_Channel.current_Angle
+ the_Channel.interp_Delta);
Self.set_rotation_Angle (for_Joint, for_Axis,
to => to_Radians (math.Degrees (the_Channel.current_Angle)));
end if;
end update_rotation_Animation;
procedure update_location_Animation (for_Channel : in channel_Id;
for_Joint : in gel.human_v1.scene_joint_Id)
is
the_Channel : animation_Channel renames Self.Channels (for_Channel);
Cursor : math.Index renames the_Channel.Cursor;
Elapsed : constant Duration := Now - Self.start_Time;
function site_X return math.Real is begin return the_Channel.Values ((Cursor - 1) * 3 + 1); end site_X;
function site_Y return math.Real is begin return the_Channel.Values ((Cursor - 1) * 3 + 2); end site_Y;
function site_Z return math.Real is begin return the_Channel.Values ((Cursor - 1) * 3 + 3); end site_Z;
begin
if Cursor < the_Channel.Times'Last
then
if Cursor = 0
or else Elapsed > Duration (the_Channel.Times (Cursor))
then
Cursor := Cursor + 1;
if Cursor = 1 then
if the_Channel.Times (Cursor) = 0.0
then
the_Channel.site_interp_Delta (1) := site_X - the_Channel.current_Site (1);
the_Channel.site_interp_Delta (2) := site_Y - the_Channel.current_Site (2);
the_Channel.site_interp_Delta (3) := site_Z - the_Channel.current_Site (3);
else
the_Channel.site_interp_Delta (1) := (site_X - the_Channel.current_Site (1))
/ (the_Channel.Times (Cursor));
the_Channel.site_interp_Delta (2) := (site_Y - the_Channel.current_Site (2))
/ (the_Channel.Times (Cursor));
the_Channel.site_interp_Delta (3) := (site_Z - the_Channel.current_Site (3))
/ (the_Channel.Times (Cursor));
end if;
else
the_Channel.site_interp_Delta (1) := (site_X - the_Channel.current_Site (1))
/ (the_Channel.Times (Cursor) - the_Channel.Times (Cursor - 1));
the_Channel.site_interp_Delta (2) := (site_Y - the_Channel.current_Site (2))
/ (the_Channel.Times (Cursor) - the_Channel.Times (Cursor - 1));
the_Channel.site_interp_Delta (3) := (site_Z - the_Channel.current_Site (3))
/ (the_Channel.Times (Cursor) - the_Channel.Times (Cursor - 1));
end if;
the_Channel.site_interp_Delta (1) := the_Channel.site_interp_Delta (1) / 60.0; -- 60.0 is frames/sec
the_Channel.site_interp_Delta (2) := the_Channel.site_interp_Delta (2) / 60.0; -- 60.0 is frames/sec
the_Channel.site_interp_Delta (3) := the_Channel.site_interp_Delta (3) / 60.0; -- 60.0 is frames/sec
end if;
Self.set_Location (for_Joint, to => the_Channel.current_Site);
the_Channel.current_Site (1) := the_Channel.current_Site (1) + the_Channel.site_interp_Delta (1);
the_Channel.current_Site (2) := the_Channel.current_Site (2) + the_Channel.site_interp_Delta (2);
the_Channel.current_Site (3) := the_Channel.current_Site (3) + the_Channel.site_interp_Delta (3);
end if;
end update_location_Animation;
procedure update_full_transform_Animation (for_Channel : in channel_Id;
for_Joint : in gel.Human_v1.scene_joint_Id)
is
the_Channel : animation_Channel renames Self.Channels (for_Channel);
Cursor : math.Index renames the_Channel.Cursor;
Cursor_updated : Boolean := False;
new_Transform : math.Matrix_4x4;
begin
if Cursor = the_Channel.Times'Last
then
-- the_Channel.initial_Transform := the_Channel.Transforms (1);
-- the_Channel.current_Transform := the_Channel.initial_Transform;
--
-- the_Channel.current_Site := the_Channel.initial_Transform.Translation;
-- the_Channel.initial_Site := the_Channel.current_Site;
Cursor := 0;
Self.start_Time := Now;
end if;
-- Rotation
--
declare
use Math;
Initial : Transform;
begin
if Cursor < the_Channel.Times'Last
then
if Cursor = 0
or else Elapsed > Duration (the_Channel.Times (Cursor))
then
Cursor := Cursor + 1;
Cursor_updated := True;
if Cursor = 1
then
Initial := the_Channel.current_Transform;
if the_Channel.Times (Cursor) = 0.0
then
the_Channel.Transform_interp_Delta := 1.0 / 60.0; -- the_Channel.Values (Cursor) - the_Channel.current_Angle;
else
the_Channel.Transform_interp_Delta := the_Channel.Times (Cursor);
end if;
else
Initial := the_Channel.Transforms (Cursor - 1);
the_Channel.Transform_interp_Delta := the_Channel.Times (Cursor) - the_Channel.Times (Cursor - 1);
end if;
the_Channel.current_Transform := the_Channel.Transforms (Cursor);
the_Channel.Transform_interp_Delta := 1.0 / (the_Channel.Transform_interp_Delta * 60.0); -- 60.0 is frames/sec
the_Channel.slerp_Time := 0.0;
else
if Cursor > 1 then
Initial := the_Channel.Transforms (Cursor - 1);
else
Initial := the_Channel.Transforms (Cursor);
end if;
end if;
else
Initial := the_Channel.Transforms (1);
end if;
if Elapsed < Duration (the_Channel.Times (the_Channel.Times'Last))
then
-- put_Line ("Initial.Rotation: " & Image (Initial.Rotation)
-- & " current_Transform.Rotation: " & Image (the_Channel.current_Transform.Rotation));
set_Rotation (new_Transform, to_Matrix (Interpolated (Initial.Rotation,
the_Channel.current_Transform.Rotation,
to_Percentage (the_Channel.slerp_Time))));
-- set_Rotation (new_Transform, to_Matrix (Slerp (the_Channel.Transforms (Cursor ).Rotation,
-- the_Channel.Transforms (Cursor+1).Rotation,
-- the_Channel.slerp_Time)));
-- put_Line ("SLERP Time: " & Real'Image (the_Channel.slerp_Time)
-- & " Transform_interp_Delta: " & Real'Image (the_Channel.Transform_interp_Delta));
the_Channel.slerp_Time := the_Channel.slerp_Time
+ the_Channel.Transform_interp_Delta;
end if;
end;
-- new_Line;
-- put_Line ("Cursor: " & math.Index'Image (Cursor));
-- put_Line ("Elapsed: " & Duration'Image (Elapsed));
-- put_Line ("next Time: " & math.Real'Image (the_Channel.Times (Cursor)));
--
-- if cursor = 2
-- and elapsed > Duration (the_Channel.Times (Cursor))
-- then
-- put_Line ("*** Cursor: " & math.Index'Image (Cursor));
-- end if;
-- Location
--
declare
use type math.Vector_3;
-- function site_X return math.Real is begin return the_Channel.Values ((Cursor - 1) * 3 + 1); end site_X;
-- function site_Y return math.Real is begin return the_Channel.Values ((Cursor - 1) * 3 + 2); end site_Y;
-- function site_Z return math.Real is begin return the_Channel.Values ((Cursor - 1) * 3 + 3); end site_Z;
desired_Site : math.Vector_3 := the_Channel.Transforms (Cursor + 0).Translation;
begin
if Cursor < the_Channel.Times'Last
then
if Cursor_updated -- Cursor = 1
-- or else Elapsed > Duration (the_Channel.Times (Cursor))
then
if Cursor = 1
then
if the_Channel.Times (Cursor) = 0.0
then
the_Channel.site_interp_Delta := desired_Site - the_Channel.current_Site;
else
the_Channel.site_interp_Delta := (desired_Site - the_Channel.current_Site)
/ (the_Channel.Times (Cursor));
end if;
else
the_Channel.site_interp_Delta := (desired_Site - the_Channel.current_Site)
/ (the_Channel.Times (Cursor) - the_Channel.Times (Cursor - 1));
end if;
the_Channel.site_interp_Delta := the_Channel.site_interp_Delta / 60.0; -- 60.0 is frames/sec
end if;
the_Channel.current_Site := the_Channel.current_Site + the_Channel.site_interp_Delta;
-- if for_Channel = Hips
-- then
-- new_Line;
-- put_Line ("the_Channel.site_interp_Delta: " & math.Image (the_Channel.site_interp_Delta));
-- put_Line ("the_Channel.current_Site: " & math.Image (the_Channel.current_Site));
-- end if;
set_Translation (new_Transform, to => the_Channel.current_Site);
else
null;
end if;
end;
-- Scale
--
-- (TODO)
-- Store the new transform.
--
Self.set_Transform (for_Joint, to => new_Transform);
end update_full_transform_Animation;
begin
Now := world_Age;
if Self.start_Time = 0.0 then
Self.start_Time := Now;
end if;
Elapsed := Now - Self.start_Time;
update_full_transform_Animation (Hips, Hips);
update_full_transform_Animation (Thigh_L, Thigh_L);
update_full_transform_Animation (Shin_L, Shin_L);
update_full_transform_Animation (Foot_L, Foot_L);
update_full_transform_Animation (Toe_L, Toe_L);
update_full_transform_Animation (Thigh_R, Thigh_R);
update_full_transform_Animation (Shin_R, Shin_R);
update_full_transform_Animation (Foot_R, Foot_R);
update_full_transform_Animation (Toe_R, Toe_R);
update_full_transform_Animation (Spine, Spine);
update_full_transform_Animation (Chest, Chest);
update_full_transform_Animation (Clavicle_R, Clavicle_R);
update_full_transform_Animation (upper_Arm_R, upper_Arm_R);
update_full_transform_Animation (Forearm_R, Forearm_R);
update_full_transform_Animation (Hand_R, Hand_R);
-- update_full_transform_Animation (Thumb_02_R, Thumb_02_R);
-- update_full_transform_Animation (Thumb_03_R, Thumb_03_R);
-- update_full_transform_Animation (F_ring_01_R, F_ring_01_R);
-- update_full_transform_Animation (F_index_01_R, F_index_01_R);
update_full_transform_Animation (Clavicle_L, Clavicle_L);
update_full_transform_Animation (upper_Arm_L, upper_Arm_L);
update_full_transform_Animation (Forearm_L, Forearm_L);
update_full_transform_Animation (Hand_L, Hand_L);
-- update_full_transform_Animation (Thumb_02_L, Thumb_02_L);
-- update_full_transform_Animation (Thumb_03_L, Thumb_03_L);
-- update_full_transform_Animation (F_ring_01_L, F_ring_01_L);
-- update_full_transform_Animation (F_index_01_L, F_index_01_L);
update_full_transform_Animation (Neck, Neck);
update_full_transform_Animation (Head, Head);
update_full_transform_Animation (Jaw, Jaw);
-- update_full_transform_Animation (Eye_R, Eye_R);
-- update_full_transform_Animation (Eye_L, Eye_L);
Self.update_all_global_Transforms;
end animate;
procedure reset_Animation (Self : in out Item)
is
begin
Self.start_Time := 0.0;
for Each in Self.Channels'Range
loop
Self.Channels (Each).Cursor := 0;
Self.Channels (Each).current_Angle := Self.Channels (Each).initial_Angle;
Self.Channels (Each).current_Site := Self.Channels (Each).initial_Site;
Self.Channels (Each).interp_Delta := 0.0;
end loop;
end reset_Animation;
procedure Mode_is (Now : in display_Mode)
is
begin
the_display_Mode := Now;
end Mode_is;
begin
for Each in to_scene_joint_Id'Range
loop
to_scene_joint_Id (Each) := scene_joint_Id'Value (controller_joint_Id'Image (Each));
end loop;
for Each in to_controller_joint_Id'Range
loop
begin
to_controller_joint_Id (Each) := controller_joint_Id'Value (scene_joint_Id'Image (Each));
-- exception
-- when constraint_Error =>
-- if Each /= Armature then raise; end if;
end;
end loop;
end gel.Human_v1;
|
reznikmm/matreshka | Ada | 4,796 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- 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 XML.DOM.Visitors;
with ODF.DOM.Table_Data_Pilot_Group_Elements;
package Matreshka.ODF_Table.Data_Pilot_Group_Elements is
type Table_Data_Pilot_Group_Element_Node is
new Matreshka.ODF_Table.Abstract_Table_Element_Node
and ODF.DOM.Table_Data_Pilot_Group_Elements.ODF_Table_Data_Pilot_Group
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Table_Data_Pilot_Group_Element_Node;
overriding function Get_Local_Name
(Self : not null access constant Table_Data_Pilot_Group_Element_Node)
return League.Strings.Universal_String;
overriding procedure Enter_Node
(Self : not null access Table_Data_Pilot_Group_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Leave_Node
(Self : not null access Table_Data_Pilot_Group_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Visit_Node
(Self : not null access Table_Data_Pilot_Group_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
end Matreshka.ODF_Table.Data_Pilot_Group_Elements;
|
AdaCore/libadalang | Ada | 141 | adb | procedure Test_New_Int is
type New_Int is range Integer'First .. Integer'Last;
pragma Test_Statement;
begin
null;
end Test_New_Int;
|
reznikmm/matreshka | Ada | 6,469 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- 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 AMF.CMOF.Constraints;
with AMF.CMOF.Elements.Collections;
with AMF.CMOF.Named_Elements;
with AMF.CMOF.Namespaces;
with AMF.CMOF.Value_Specifications;
with AMF.Internals.CMOF_Named_Elements;
with AMF.Visitors;
package AMF.Internals.CMOF_Constraints is
type CMOF_Constraint_Proxy is
limited new AMF.Internals.CMOF_Named_Elements.CMOF_Named_Element_Proxy
and AMF.CMOF.Constraints.CMOF_Constraint
with null record;
-- XXX These subprograms are stubs
overriding function All_Owned_Elements
(Self : not null access constant CMOF_Constraint_Proxy)
return AMF.CMOF.Elements.Collections.Set_Of_CMOF_Element;
overriding function Get_Qualified_Name
(Self : not null access constant CMOF_Constraint_Proxy)
return Optional_String;
overriding function Is_Distinguishable_From
(Self : not null access constant CMOF_Constraint_Proxy;
N : AMF.CMOF.Named_Elements.CMOF_Named_Element_Access;
Ns : AMF.CMOF.Namespaces.CMOF_Namespace_Access)
return Boolean;
overriding function Get_Constrained_Element
(Self : not null access constant CMOF_Constraint_Proxy)
return AMF.CMOF.Elements.Collections.Ordered_Set_Of_CMOF_Element;
-- Getter of Constraint::constrainedElement.
--
-- The ordered set of Elements referenced by this Constraint.
overriding function Get_Specification
(Self : not null access constant CMOF_Constraint_Proxy)
return AMF.CMOF.Value_Specifications.CMOF_Value_Specification_Access;
-- Getter of Constraint::specification.
--
-- A condition that must be true when evaluated in order for the
-- constraint to be satisfied.
overriding procedure Set_Specification
(Self : not null access CMOF_Constraint_Proxy;
To : AMF.CMOF.Value_Specifications.CMOF_Value_Specification_Access);
overriding function Get_Context
(Self : not null access constant CMOF_Constraint_Proxy)
return AMF.CMOF.Namespaces.CMOF_Namespace_Access;
-- Getter of Constraint::context.
overriding procedure Set_Context
(Self : not null access CMOF_Constraint_Proxy;
To : AMF.CMOF.Namespaces.CMOF_Namespace_Access);
overriding procedure Enter_Element
(Self : not null access constant CMOF_Constraint_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding procedure Leave_Element
(Self : not null access constant CMOF_Constraint_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding procedure Visit_Element
(Self : not null access constant CMOF_Constraint_Proxy;
Iterator : in out AMF.Visitors.Abstract_Iterator'Class;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of iterator interface.
end AMF.Internals.CMOF_Constraints;
|
io7m/coreland-vector-ada | Ada | 537 | adb | package body vector.zero is
-- C imports
procedure vec_zero_f
(a : vector_f_t;
n : ic.int);
pragma import (c, vec_zero_f, "vec_zeroNf_aligned");
procedure vec_zero_d
(a : vector_d_t;
n : ic.int);
pragma import (c, vec_zero_d, "vec_zeroNd_aligned");
-- zero, in place
procedure f (a : in vector_f_t) is
begin
vec_zero_f (a, ic.int (size));
end f;
pragma inline (f);
procedure d (a : in vector_d_t) is
begin
vec_zero_d (a, ic.int (size));
end d;
pragma inline (d);
end vector.zero;
|
zhmu/ananas | Ada | 400,968 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ C H 8 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, 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 Debug; use Debug;
with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Disp; use Exp_Disp;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Freeze; use Freeze;
with Ghost; use Ghost;
with Impunit; use Impunit;
with Lib; use Lib;
with Lib.Load; use Lib.Load;
with Lib.Xref; use Lib.Xref;
with Namet; use Namet;
with Namet.Sp; use Namet.Sp;
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_Cat; use Sem_Cat;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch4; use Sem_Ch4;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch10; use Sem_Ch10;
with Sem_Ch12; use Sem_Ch12;
with Sem_Ch13; use Sem_Ch13;
with Sem_Dim; use Sem_Dim;
with Sem_Disp; use Sem_Disp;
with Sem_Dist; use Sem_Dist;
with Sem_Elab; use Sem_Elab;
with Sem_Eval; use Sem_Eval;
with Sem_Prag; use Sem_Prag;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sem_Type; use Sem_Type;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Sinfo.CN; use Sinfo.CN;
with Snames; use Snames;
with Style;
with Table;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
package body Sem_Ch8 is
------------------------------------
-- Visibility and Name Resolution --
------------------------------------
-- This package handles name resolution and the collection of possible
-- interpretations for overloaded names, prior to overload resolution.
-- Name resolution is the process that establishes a mapping between source
-- identifiers and the entities they denote at each point in the program.
-- Each entity is represented by a defining occurrence. Each identifier
-- that denotes an entity points to the corresponding defining occurrence.
-- This is the entity of the applied occurrence. Each occurrence holds
-- an index into the names table, where source identifiers are stored.
-- Each entry in the names table for an identifier or designator uses the
-- Info pointer to hold a link to the currently visible entity that has
-- this name (see subprograms Get_Name_Entity_Id and Set_Name_Entity_Id
-- in package Sem_Util). The visibility is initialized at the beginning of
-- semantic processing to make entities in package Standard immediately
-- visible. The visibility table is used in a more subtle way when
-- compiling subunits (see below).
-- Entities that have the same name (i.e. homonyms) are chained. In the
-- case of overloaded entities, this chain holds all the possible meanings
-- of a given identifier. The process of overload resolution uses type
-- information to select from this chain the unique meaning of a given
-- identifier.
-- Entities are also chained in their scope, through the Next_Entity link.
-- As a consequence, the name space is organized as a sparse matrix, where
-- each row corresponds to a scope, and each column to a source identifier.
-- Open scopes, that is to say scopes currently being compiled, have their
-- corresponding rows of entities in order, innermost scope first.
-- The scopes of packages that are mentioned in context clauses appear in
-- no particular order, interspersed among open scopes. This is because
-- in the course of analyzing the context of a compilation, a package
-- declaration is first an open scope, and subsequently an element of the
-- context. If subunits or child units are present, a parent unit may
-- appear under various guises at various times in the compilation.
-- When the compilation of the innermost scope is complete, the entities
-- defined therein are no longer visible. If the scope is not a package
-- declaration, these entities are never visible subsequently, and can be
-- removed from visibility chains. If the scope is a package declaration,
-- its visible declarations may still be accessible. Therefore the entities
-- defined in such a scope are left on the visibility chains, and only
-- their visibility (immediately visibility or potential use-visibility)
-- is affected.
-- The ordering of homonyms on their chain does not necessarily follow
-- the order of their corresponding scopes on the scope stack. For
-- example, if package P and the enclosing scope both contain entities
-- named E, then when compiling the package body the chain for E will
-- hold the global entity first, and the local one (corresponding to
-- the current inner scope) next. As a result, name resolution routines
-- do not assume any relative ordering of the homonym chains, either
-- for scope nesting or to order of appearance of context clauses.
-- When compiling a child unit, entities in the parent scope are always
-- immediately visible. When compiling the body of a child unit, private
-- entities in the parent must also be made immediately visible. There
-- are separate routines to make the visible and private declarations
-- visible at various times (see package Sem_Ch7).
-- +--------+ +-----+
-- | In use |-------->| EU1 |-------------------------->
-- +--------+ +-----+
-- | |
-- +--------+ +-----+ +-----+
-- | Stand. |---------------->| ES1 |--------------->| ES2 |--->
-- +--------+ +-----+ +-----+
-- | |
-- +---------+ | +-----+
-- | with'ed |------------------------------>| EW2 |--->
-- +---------+ | +-----+
-- | |
-- +--------+ +-----+ +-----+
-- | Scope2 |---------------->| E12 |--------------->| E22 |--->
-- +--------+ +-----+ +-----+
-- | |
-- +--------+ +-----+ +-----+
-- | Scope1 |---------------->| E11 |--------------->| E12 |--->
-- +--------+ +-----+ +-----+
-- ^ | |
-- | | |
-- | +---------+ | |
-- | | with'ed |----------------------------------------->
-- | +---------+ | |
-- | | |
-- Scope stack | |
-- (innermost first) | |
-- +----------------------------+
-- Names table => | Id1 | | | | Id2 |
-- +----------------------------+
-- Name resolution must deal with several syntactic forms: simple names,
-- qualified names, indexed names, and various forms of calls.
-- Each identifier points to an entry in the names table. The resolution
-- of a simple name consists in traversing the homonym chain, starting
-- from the names table. If an entry is immediately visible, it is the one
-- designated by the identifier. If only potentially use-visible entities
-- are on the chain, we must verify that they do not hide each other. If
-- the entity we find is overloadable, we collect all other overloadable
-- entities on the chain as long as they are not hidden.
--
-- To resolve expanded names, we must find the entity at the intersection
-- of the entity chain for the scope (the prefix) and the homonym chain
-- for the selector. In general, homonym chains will be much shorter than
-- entity chains, so it is preferable to start from the names table as
-- well. If the entity found is overloadable, we must collect all other
-- interpretations that are defined in the scope denoted by the prefix.
-- For records, protected types, and tasks, their local entities are
-- removed from visibility chains on exit from the corresponding scope.
-- From the outside, these entities are always accessed by selected
-- notation, and the entity chain for the record type, protected type,
-- etc. is traversed sequentially in order to find the designated entity.
-- The discriminants of a type and the operations of a protected type or
-- task are unchained on exit from the first view of the type, (such as
-- a private or incomplete type declaration, or a protected type speci-
-- fication) and re-chained when compiling the second view.
-- In the case of operators, we do not make operators on derived types
-- explicit. As a result, the notation P."+" may denote either a user-
-- defined function with name "+", or else an implicit declaration of the
-- operator "+" in package P. The resolution of expanded names always
-- tries to resolve an operator name as such an implicitly defined entity,
-- in addition to looking for explicit declarations.
-- All forms of names that denote entities (simple names, expanded names,
-- character literals in some cases) have a Entity attribute, which
-- identifies the entity denoted by the name.
---------------------
-- The Scope Stack --
---------------------
-- The Scope stack keeps track of the scopes currently been compiled.
-- Every entity that contains declarations (including records) is placed
-- on the scope stack while it is being processed, and removed at the end.
-- Whenever a non-package scope is exited, the entities defined therein
-- are removed from the visibility table, so that entities in outer scopes
-- become visible (see previous description). On entry to Sem, the scope
-- stack only contains the package Standard. As usual, subunits complicate
-- this picture ever so slightly.
-- The Rtsfind mechanism can force a call to Semantics while another
-- compilation is in progress. The unit retrieved by Rtsfind must be
-- compiled in its own context, and has no access to the visibility of
-- the unit currently being compiled. The procedures Save_Scope_Stack and
-- Restore_Scope_Stack make entities in current open scopes invisible
-- before compiling the retrieved unit, and restore the compilation
-- environment afterwards.
------------------------
-- Compiling subunits --
------------------------
-- Subunits must be compiled in the environment of the corresponding stub,
-- that is to say with the same visibility into the parent (and its
-- context) that is available at the point of the stub declaration, but
-- with the additional visibility provided by the context clause of the
-- subunit itself. As a result, compilation of a subunit forces compilation
-- of the parent (see description in lib-). At the point of the stub
-- declaration, Analyze is called recursively to compile the proper body of
-- the subunit, but without reinitializing the names table, nor the scope
-- stack (i.e. standard is not pushed on the stack). In this fashion the
-- context of the subunit is added to the context of the parent, and the
-- subunit is compiled in the correct environment. Note that in the course
-- of processing the context of a subunit, Standard will appear twice on
-- the scope stack: once for the parent of the subunit, and once for the
-- unit in the context clause being compiled. However, the two sets of
-- entities are not linked by homonym chains, so that the compilation of
-- any context unit happens in a fresh visibility environment.
-------------------------------
-- Processing of USE Clauses --
-------------------------------
-- Every defining occurrence has a flag indicating if it is potentially use
-- visible. Resolution of simple names examines this flag. The processing
-- of use clauses consists in setting this flag on all visible entities
-- defined in the corresponding package. On exit from the scope of the use
-- clause, the corresponding flag must be reset. However, a package may
-- appear in several nested use clauses (pathological but legal, alas)
-- which forces us to use a slightly more involved scheme:
-- a) The defining occurrence for a package holds a flag -In_Use- to
-- indicate that it is currently in the scope of a use clause. If a
-- redundant use clause is encountered, then the corresponding occurrence
-- of the package name is flagged -Redundant_Use-.
-- b) On exit from a scope, the use clauses in its declarative part are
-- scanned. The visibility flag is reset in all entities declared in
-- package named in a use clause, as long as the package is not flagged
-- as being in a redundant use clause (in which case the outer use
-- clause is still in effect, and the direct visibility of its entities
-- must be retained).
-- Note that entities are not removed from their homonym chains on exit
-- from the package specification. A subsequent use clause does not need
-- to rechain the visible entities, but only to establish their direct
-- visibility.
-----------------------------------
-- Handling private declarations --
-----------------------------------
-- The principle that each entity has a single defining occurrence clashes
-- with the presence of two separate definitions for private types: the
-- first is the private type declaration, and second is the full type
-- declaration. It is important that all references to the type point to
-- the same defining occurrence, namely the first one. To enforce the two
-- separate views of the entity, the corresponding information is swapped
-- between the two declarations. Outside of the package, the defining
-- occurrence only contains the private declaration information, while in
-- the private part and the body of the package the defining occurrence
-- contains the full declaration. To simplify the swap, the defining
-- occurrence that currently holds the private declaration points to the
-- full declaration. During semantic processing the defining occurrence
-- also points to a list of private dependents, that is to say access types
-- or composite types whose designated types or component types are
-- subtypes or derived types of the private type in question. After the
-- full declaration has been seen, the private dependents are updated to
-- indicate that they have full definitions.
------------------------------------
-- Handling of Undefined Messages --
------------------------------------
-- In normal mode, only the first use of an undefined identifier generates
-- a message. The table Urefs is used to record error messages that have
-- been issued so that second and subsequent ones do not generate further
-- messages. However, the second reference causes text to be added to the
-- original undefined message noting "(more references follow)". The
-- full error list option (-gnatf) forces messages to be generated for
-- every reference and disconnects the use of this table.
type Uref_Entry is record
Node : Node_Id;
-- Node for identifier for which original message was posted. The
-- Chars field of this identifier is used to detect later references
-- to the same identifier.
Err : Error_Msg_Id;
-- Records error message Id of original undefined message. Reset to
-- No_Error_Msg after the second occurrence, where it is used to add
-- text to the original message as described above.
Nvis : Boolean;
-- Set if the message is not visible rather than undefined
Loc : Source_Ptr;
-- Records location of error message. Used to make sure that we do
-- not consider a, b : undefined as two separate instances, which
-- would otherwise happen, since the parser converts this sequence
-- to a : undefined; b : undefined.
end record;
package Urefs is new Table.Table (
Table_Component_Type => Uref_Entry,
Table_Index_Type => Nat,
Table_Low_Bound => 1,
Table_Initial => 10,
Table_Increment => 100,
Table_Name => "Urefs");
Candidate_Renaming : Entity_Id;
-- Holds a candidate interpretation that appears in a subprogram renaming
-- declaration and does not match the given specification, but matches at
-- least on the first formal. Allows better error message when given
-- specification omits defaulted parameters, a common error.
-----------------------
-- Local Subprograms --
-----------------------
procedure Analyze_Generic_Renaming
(N : Node_Id;
K : Entity_Kind);
-- Common processing for all three kinds of generic renaming declarations.
-- Enter new name and indicate that it renames the generic unit.
procedure Analyze_Renamed_Character
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean);
-- Renamed entity is given by a character literal, which must belong
-- to the return type of the new entity. Is_Body indicates whether the
-- declaration is a renaming_as_body. If the original declaration has
-- already been frozen (because of an intervening body, e.g.) the body of
-- the function must be built now. The same applies to the following
-- various renaming procedures.
procedure Analyze_Renamed_Dereference
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean);
-- Renamed entity is given by an explicit dereference. Prefix must be a
-- conformant access_to_subprogram type.
procedure Analyze_Renamed_Entry
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean);
-- If the renamed entity in a subprogram renaming is an entry or protected
-- subprogram, build a body for the new entity whose only statement is a
-- call to the renamed entity.
procedure Analyze_Renamed_Family_Member
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean);
-- Used when the renamed entity is an indexed component. The prefix must
-- denote an entry family.
procedure Analyze_Renamed_Primitive_Operation
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean);
-- If the renamed entity in a subprogram renaming is a primitive operation
-- or a class-wide operation in prefix form, save the target object,
-- which must be added to the list of actuals in any subsequent call.
-- The renaming operation is intrinsic because the compiler must in
-- fact generate a wrapper for it (6.3.1 (10 1/2)).
procedure Attribute_Renaming (N : Node_Id);
-- Analyze renaming of attribute as subprogram. The renaming declaration N
-- is rewritten as a subprogram body that returns the attribute reference
-- applied to the formals of the function.
procedure Set_Entity_Or_Discriminal (N : Node_Id; E : Entity_Id);
-- Set Entity, with style check if need be. For a discriminant reference,
-- replace by the corresponding discriminal, i.e. the parameter of the
-- initialization procedure that corresponds to the discriminant.
procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id);
-- A renaming_as_body may occur after the entity of the original decla-
-- ration has been frozen. In that case, the body of the new entity must
-- be built now, because the usual mechanism of building the renamed
-- body at the point of freezing will not work. Subp is the subprogram
-- for which N provides the Renaming_As_Body.
procedure Check_In_Previous_With_Clause (N, Nam : Node_Id);
-- N is a use_package clause and Nam the package name, or N is a use_type
-- clause and Nam is the prefix of the type name. In either case, verify
-- that the package is visible at that point in the context: either it
-- appears in a previous with_clause, or because it is a fully qualified
-- name and the root ancestor appears in a previous with_clause.
procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id);
-- Verify that the entity in a renaming declaration that is a library unit
-- is itself a library unit and not a nested unit or subunit. Also check
-- that if the renaming is a child unit of a generic parent, then the
-- renamed unit must also be a child unit of that parent. Finally, verify
-- that a renamed generic unit is not an implicit child declared within
-- an instance of the parent.
procedure Chain_Use_Clause (N : Node_Id);
-- Chain use clause onto list of uses clauses headed by First_Use_Clause in
-- the proper scope table entry. This is usually the current scope, but it
-- will be an inner scope when installing the use clauses of the private
-- declarations of a parent unit prior to compiling the private part of a
-- child unit. This chain is traversed when installing/removing use clauses
-- when compiling a subunit or instantiating a generic body on the fly,
-- when it is necessary to save and restore full environments.
function Enclosing_Instance return Entity_Id;
-- In an instance nested within another one, several semantic checks are
-- unnecessary because the legality of the nested instance has been checked
-- in the enclosing generic unit. This applies in particular to legality
-- checks on actuals for formal subprograms of the inner instance, which
-- are checked as subprogram renamings, and may be complicated by confusion
-- in private/full views. This function returns the instance enclosing the
-- current one if there is such, else it returns Empty.
--
-- If the renaming determines the entity for the default of a formal
-- subprogram nested within another instance, choose the innermost
-- candidate. This is because if the formal has a box, and we are within
-- an enclosing instance where some candidate interpretations are local
-- to this enclosing instance, we know that the default was properly
-- resolved when analyzing the generic, so we prefer the local
-- candidates to those that are external. This is not always the case
-- but is a reasonable heuristic on the use of nested generics. The
-- proper solution requires a full renaming model.
function Entity_Of_Unit (U : Node_Id) return Entity_Id;
-- Return the appropriate entity for determining which unit has a deeper
-- scope: the defining entity for U, unless U is a package instance, in
-- which case we retrieve the entity of the instance spec.
procedure Find_Expanded_Name (N : Node_Id);
-- The input is a selected component known to be an expanded name. Verify
-- legality of selector given the scope denoted by prefix, and change node
-- N into a expanded name with a properly set Entity field.
function Find_First_Use (Use_Clause : Node_Id) return Node_Id;
-- Find the most previous use clause (that is, the first one to appear in
-- the source) by traversing the previous clause chain that exists in both
-- N_Use_Package_Clause nodes and N_Use_Type_Clause nodes.
function Find_Renamed_Entity
(N : Node_Id;
Nam : Node_Id;
New_S : Entity_Id;
Is_Actual : Boolean := False) return Entity_Id;
-- Find the renamed entity that corresponds to the given parameter profile
-- in a subprogram renaming declaration. The renamed entity may be an
-- operator, a subprogram, an entry, or a protected operation. Is_Actual
-- indicates that the renaming is the one generated for an actual subpro-
-- gram in an instance, for which special visibility checks apply.
function Has_Implicit_Character_Literal (N : Node_Id) return Boolean;
-- Find a type derived from Character or Wide_Character in the prefix of N.
-- Used to resolved qualified names whose selector is a character literal.
function Has_Private_With (E : Entity_Id) return Boolean;
-- Ada 2005 (AI-262): Determines if the current compilation unit has a
-- private with on E.
function Has_Components (Typ : Entity_Id) return Boolean;
-- Determine if given type has components, i.e. is either a record type or
-- type or a type that has discriminants.
function Has_Implicit_Operator (N : Node_Id) return Boolean;
-- N is an expanded name whose selector is an operator name (e.g. P."+").
-- declarative part contains an implicit declaration of an operator if it
-- has a declaration of a type to which one of the predefined operators
-- apply. The existence of this routine is an implementation artifact. A
-- more straightforward but more space-consuming choice would be to make
-- all inherited operators explicit in the symbol table.
procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id);
-- A subprogram defined by a renaming declaration inherits the parameter
-- profile of the renamed entity. The subtypes given in the subprogram
-- specification are discarded and replaced with those of the renamed
-- subprogram, which are then used to recheck the default values.
function Most_Descendant_Use_Clause
(Clause1 : Entity_Id;
Clause2 : Entity_Id) return Entity_Id;
-- Determine which use clause parameter is the most descendant in terms of
-- scope.
procedure Premature_Usage (N : Node_Id);
-- Diagnose usage of an entity before it is visible
procedure Use_One_Package
(N : Node_Id;
Pack_Name : Entity_Id := Empty;
Force : Boolean := False);
-- Make visible entities declared in package P potentially use-visible
-- in the current context. Also used in the analysis of subunits, when
-- re-installing use clauses of parent units. N is the use_clause that
-- names P (and possibly other packages).
procedure Use_One_Type
(Id : Node_Id;
Installed : Boolean := False;
Force : Boolean := False);
-- Id is the subtype mark from a use_type_clause. This procedure makes
-- the primitive operators of the type potentially use-visible. The
-- boolean flag Installed indicates that the clause is being reinstalled
-- after previous analysis, and primitive operations are already chained
-- on the Used_Operations list of the clause.
procedure Write_Info;
-- Write debugging information on entities declared in current scope
--------------------------------
-- Analyze_Exception_Renaming --
--------------------------------
-- The language only allows a single identifier, but the tree holds an
-- identifier list. The parser has already issued an error message if
-- there is more than one element in the list.
procedure Analyze_Exception_Renaming (N : Node_Id) is
Id : constant Entity_Id := Defining_Entity (N);
Nam : constant Node_Id := Name (N);
begin
Enter_Name (Id);
Analyze (Nam);
Mutate_Ekind (Id, E_Exception);
Set_Etype (Id, Standard_Exception_Type);
Set_Is_Pure (Id, Is_Pure (Current_Scope));
if Is_Entity_Name (Nam)
and then Present (Entity (Nam))
and then Ekind (Entity (Nam)) = E_Exception
then
if Present (Renamed_Entity (Entity (Nam))) then
Set_Renamed_Entity (Id, Renamed_Entity (Entity (Nam)));
else
Set_Renamed_Entity (Id, Entity (Nam));
end if;
-- The exception renaming declaration may become Ghost if it renames
-- a Ghost entity.
Mark_Ghost_Renaming (N, Entity (Nam));
else
Error_Msg_N ("invalid exception name in renaming", Nam);
end if;
-- Implementation-defined aspect specifications can appear in a renaming
-- declaration, but not language-defined ones. The call to procedure
-- Analyze_Aspect_Specifications will take care of this error check.
if Has_Aspects (N) then
Analyze_Aspect_Specifications (N, Id);
end if;
end Analyze_Exception_Renaming;
---------------------------
-- Analyze_Expanded_Name --
---------------------------
procedure Analyze_Expanded_Name (N : Node_Id) is
begin
-- If the entity pointer is already set, this is an internal node, or a
-- node that is analyzed more than once, after a tree modification. In
-- such a case there is no resolution to perform, just set the type. In
-- either case, start by analyzing the prefix.
Analyze (Prefix (N));
if Present (Entity (N)) then
if Is_Type (Entity (N)) then
Set_Etype (N, Entity (N));
else
Set_Etype (N, Etype (Entity (N)));
end if;
else
Find_Expanded_Name (N);
end if;
-- In either case, propagate dimension of entity to expanded name
Analyze_Dimension (N);
end Analyze_Expanded_Name;
---------------------------------------
-- Analyze_Generic_Function_Renaming --
---------------------------------------
procedure Analyze_Generic_Function_Renaming (N : Node_Id) is
begin
Analyze_Generic_Renaming (N, E_Generic_Function);
end Analyze_Generic_Function_Renaming;
--------------------------------------
-- Analyze_Generic_Package_Renaming --
--------------------------------------
procedure Analyze_Generic_Package_Renaming (N : Node_Id) is
begin
-- Test for the Text_IO special unit case here, since we may be renaming
-- one of the subpackages of Text_IO, then join common routine.
Check_Text_IO_Special_Unit (Name (N));
Analyze_Generic_Renaming (N, E_Generic_Package);
end Analyze_Generic_Package_Renaming;
----------------------------------------
-- Analyze_Generic_Procedure_Renaming --
----------------------------------------
procedure Analyze_Generic_Procedure_Renaming (N : Node_Id) is
begin
Analyze_Generic_Renaming (N, E_Generic_Procedure);
end Analyze_Generic_Procedure_Renaming;
------------------------------
-- Analyze_Generic_Renaming --
------------------------------
procedure Analyze_Generic_Renaming
(N : Node_Id;
K : Entity_Kind)
is
New_P : constant Entity_Id := Defining_Entity (N);
Inst : Boolean := False;
Old_P : Entity_Id;
begin
if Name (N) = Error then
return;
end if;
Generate_Definition (New_P);
if Current_Scope /= Standard_Standard then
Set_Is_Pure (New_P, Is_Pure (Current_Scope));
end if;
if Nkind (Name (N)) = N_Selected_Component then
Check_Generic_Child_Unit (Name (N), Inst);
else
Analyze (Name (N));
end if;
if not Is_Entity_Name (Name (N)) then
Error_Msg_N ("expect entity name in renaming declaration", Name (N));
Old_P := Any_Id;
else
Old_P := Entity (Name (N));
end if;
Enter_Name (New_P);
Mutate_Ekind (New_P, K);
if Etype (Old_P) = Any_Type then
null;
elsif Ekind (Old_P) /= K then
Error_Msg_N ("invalid generic unit name", Name (N));
else
if Present (Renamed_Entity (Old_P)) then
Set_Renamed_Entity (New_P, Renamed_Entity (Old_P));
else
Set_Renamed_Entity (New_P, Old_P);
end if;
-- The generic renaming declaration may become Ghost if it renames a
-- Ghost entity.
Mark_Ghost_Renaming (N, Old_P);
Set_Is_Pure (New_P, Is_Pure (Old_P));
Set_Is_Preelaborated (New_P, Is_Preelaborated (Old_P));
Set_Etype (New_P, Etype (Old_P));
Set_Has_Completion (New_P);
if In_Open_Scopes (Old_P) then
Error_Msg_N ("within its scope, generic denotes its instance", N);
end if;
-- For subprograms, propagate the Intrinsic flag, to allow, e.g.
-- renamings and subsequent instantiations of Unchecked_Conversion.
if Is_Generic_Subprogram (Old_P) then
Set_Is_Intrinsic_Subprogram
(New_P, Is_Intrinsic_Subprogram (Old_P));
end if;
Check_Library_Unit_Renaming (N, Old_P);
end if;
-- Implementation-defined aspect specifications can appear in a renaming
-- declaration, but not language-defined ones. The call to procedure
-- Analyze_Aspect_Specifications will take care of this error check.
if Has_Aspects (N) then
Analyze_Aspect_Specifications (N, New_P);
end if;
end Analyze_Generic_Renaming;
-----------------------------
-- Analyze_Object_Renaming --
-----------------------------
procedure Analyze_Object_Renaming (N : Node_Id) is
Id : constant Entity_Id := Defining_Identifier (N);
Loc : constant Source_Ptr := Sloc (N);
Nam : constant Node_Id := Name (N);
Is_Object_Ref : Boolean;
Dec : Node_Id;
T : Entity_Id;
T2 : Entity_Id;
Q : Node_Id;
procedure Check_Constrained_Object;
-- If the nominal type is unconstrained but the renamed object is
-- constrained, as can happen with renaming an explicit dereference or
-- a function return, build a constrained subtype from the object. If
-- the renaming is for a formal in an accept statement, the analysis
-- has already established its actual subtype. This is only relevant
-- if the renamed object is an explicit dereference.
function Get_Object_Name (Nod : Node_Id) return Node_Id;
-- Obtain the name of the object from node Nod which is being renamed by
-- the object renaming declaration N.
function Find_Raise_Node (N : Node_Id) return Traverse_Result;
-- Process one node in search for N_Raise_xxx_Error nodes.
-- Return Abandon if found, OK otherwise.
---------------------
-- Find_Raise_Node --
---------------------
function Find_Raise_Node (N : Node_Id) return Traverse_Result is
begin
if Nkind (N) in N_Raise_xxx_Error then
return Abandon;
else
return OK;
end if;
end Find_Raise_Node;
------------------------
-- No_Raise_xxx_Error --
------------------------
function No_Raise_xxx_Error is new Traverse_Func (Find_Raise_Node);
-- Traverse tree to look for a N_Raise_xxx_Error node and returns
-- Abandon if so and OK if none found.
------------------------------
-- Check_Constrained_Object --
------------------------------
procedure Check_Constrained_Object is
Typ : constant Entity_Id := Etype (Nam);
Subt : Entity_Id;
Loop_Scheme : Node_Id;
begin
if Nkind (Nam) in N_Function_Call | N_Explicit_Dereference
and then Is_Composite_Type (Typ)
and then not Is_Constrained (Typ)
and then not Has_Unknown_Discriminants (Typ)
and then Expander_Active
then
-- If Actual_Subtype is already set, nothing to do
if Ekind (Id) in E_Variable | E_Constant
and then Present (Actual_Subtype (Id))
then
null;
-- A renaming of an unchecked union has no actual subtype
elsif Is_Unchecked_Union (Typ) then
null;
-- If a record is limited its size is invariant. This is the case
-- in particular with record types with an access discriminant
-- that are used in iterators. This is an optimization, but it
-- also prevents typing anomalies when the prefix is further
-- expanded.
-- Note that we cannot just use the Is_Limited_Record flag because
-- it does not apply to records with limited components, for which
-- this syntactic flag is not set, but whose size is also fixed.
-- Note also that we need to build the constrained subtype for an
-- array in order to make the bounds explicit in most cases, but
-- not if the object comes from an extended return statement, as
-- this would create dangling references to them later on.
elsif Is_Limited_Type (Typ)
and then (not Is_Array_Type (Typ) or else Is_Return_Object (Id))
then
null;
else
Subt := Make_Temporary (Loc, 'T');
Remove_Side_Effects (Nam);
Insert_Action (N,
Make_Subtype_Declaration (Loc,
Defining_Identifier => Subt,
Subtype_Indication =>
Make_Subtype_From_Expr (Nam, Typ)));
Rewrite (Subtype_Mark (N), New_Occurrence_Of (Subt, Loc));
Set_Etype (Nam, Subt);
-- Suppress discriminant checks on this subtype if the original
-- type has defaulted discriminants and Id is a "for of" loop
-- iterator.
if Has_Defaulted_Discriminants (Typ)
and then Nkind (Original_Node (Parent (N))) = N_Loop_Statement
then
Loop_Scheme := Iteration_Scheme (Original_Node (Parent (N)));
if Present (Loop_Scheme)
and then Present (Iterator_Specification (Loop_Scheme))
and then
Defining_Identifier
(Iterator_Specification (Loop_Scheme)) = Id
then
Set_Checks_May_Be_Suppressed (Subt);
Push_Local_Suppress_Stack_Entry
(Entity => Subt,
Check => Discriminant_Check,
Suppress => True);
end if;
end if;
-- Freeze subtype at once, to prevent order of elaboration
-- issues in the backend. The renamed object exists, so its
-- type is already frozen in any case.
Freeze_Before (N, Subt);
end if;
end if;
end Check_Constrained_Object;
---------------------
-- Get_Object_Name --
---------------------
function Get_Object_Name (Nod : Node_Id) return Node_Id is
Obj_Nam : Node_Id;
begin
Obj_Nam := Nod;
while Present (Obj_Nam) loop
case Nkind (Obj_Nam) is
when N_Attribute_Reference
| N_Explicit_Dereference
| N_Indexed_Component
| N_Slice
=>
Obj_Nam := Prefix (Obj_Nam);
when N_Selected_Component =>
Obj_Nam := Selector_Name (Obj_Nam);
when N_Qualified_Expression | N_Type_Conversion =>
Obj_Nam := Expression (Obj_Nam);
when others =>
exit;
end case;
end loop;
return Obj_Nam;
end Get_Object_Name;
-- Start of processing for Analyze_Object_Renaming
begin
if Nam = Error then
return;
end if;
Set_Is_Pure (Id, Is_Pure (Current_Scope));
Enter_Name (Id);
-- The renaming of a component that depends on a discriminant requires
-- an actual subtype, because in subsequent use of the object Gigi will
-- be unable to locate the actual bounds. This explicit step is required
-- when the renaming is generated in removing side effects of an
-- already-analyzed expression.
if Nkind (Nam) = N_Selected_Component and then Analyzed (Nam) then
-- The object renaming declaration may become Ghost if it renames a
-- Ghost entity.
if Is_Entity_Name (Nam) then
Mark_Ghost_Renaming (N, Entity (Nam));
end if;
T := Etype (Nam);
Dec := Build_Actual_Subtype_Of_Component (Etype (Nam), Nam);
if Present (Dec) then
Insert_Action (N, Dec);
T := Defining_Identifier (Dec);
Set_Etype (Nam, T);
end if;
elsif Present (Subtype_Mark (N))
or else not Present (Access_Definition (N))
then
if Present (Subtype_Mark (N)) then
Find_Type (Subtype_Mark (N));
T := Entity (Subtype_Mark (N));
Analyze (Nam);
-- AI12-0275: Case of object renaming without a subtype_mark
else
Analyze (Nam);
-- Normal case of no overloading in object name
if not Is_Overloaded (Nam) then
-- Catch error cases (such as attempting to rename a procedure
-- or package) using the shorthand form.
if No (Etype (Nam))
or else Etype (Nam) = Standard_Void_Type
then
Error_Msg_N
("object name or value expected in renaming", Nam);
Mutate_Ekind (Id, E_Variable);
Set_Etype (Id, Any_Type);
return;
else
T := Etype (Nam);
end if;
-- Case of overloaded name, which will be illegal if there's more
-- than one acceptable interpretation (such as overloaded function
-- calls).
else
declare
I : Interp_Index;
I1 : Interp_Index;
It : Interp;
It1 : Interp;
Nam1 : Entity_Id;
begin
-- More than one candidate interpretation is available
-- Remove procedure calls, which syntactically cannot appear
-- in this context, but which cannot be removed by type
-- checking, because the context does not impose a type.
Get_First_Interp (Nam, I, It);
while Present (It.Typ) loop
if It.Typ = Standard_Void_Type then
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
Get_First_Interp (Nam, I, It);
I1 := I;
It1 := It;
-- If there's no type present, we have an error case (such
-- as overloaded procedures named in the object renaming).
if No (It.Typ) then
Error_Msg_N
("object name or value expected in renaming", Nam);
Mutate_Ekind (Id, E_Variable);
Set_Etype (Id, Any_Type);
return;
end if;
Get_Next_Interp (I, It);
if Present (It.Typ) then
Nam1 := It1.Nam;
It1 := Disambiguate (Nam, I1, I, Any_Type);
if It1 = No_Interp then
Error_Msg_N ("ambiguous name in object renaming", Nam);
Error_Msg_Sloc := Sloc (It.Nam);
Error_Msg_N ("\\possible interpretation#!", Nam);
Error_Msg_Sloc := Sloc (Nam1);
Error_Msg_N ("\\possible interpretation#!", Nam);
return;
end if;
end if;
Set_Etype (Nam, It1.Typ);
T := It1.Typ;
end;
end if;
if Etype (Nam) = Standard_Exception_Type then
Error_Msg_N
("exception requires a subtype mark in renaming", Nam);
return;
end if;
end if;
-- The object renaming declaration may become Ghost if it renames a
-- Ghost entity.
if Is_Entity_Name (Nam) then
Mark_Ghost_Renaming (N, Entity (Nam));
end if;
-- Check against AI12-0401 here before Resolve may rewrite Nam and
-- potentially generate spurious warnings.
-- In the case where the object_name is a qualified_expression with
-- a nominal subtype T and whose expression is a name that denotes
-- an object Q:
-- * if T is an elementary subtype, then:
-- * Q shall be a constant other than a dereference of an access
-- type; or
-- * the nominal subtype of Q shall be statically compatible with
-- T; or
-- * T shall statically match the base subtype of its type if
-- scalar, or the first subtype of its type if an access type.
-- * if T is a composite subtype, then Q shall be known to be
-- constrained or T shall statically match the first subtype of
-- its type.
if Nkind (Nam) = N_Qualified_Expression
and then Is_Object_Reference (Expression (Nam))
then
Q := Expression (Nam);
if (Is_Elementary_Type (T)
and then
not ((not Is_Variable (Q)
and then Nkind (Q) /= N_Explicit_Dereference)
or else Subtypes_Statically_Compatible (Etype (Q), T)
or else (Is_Scalar_Type (T)
and then Subtypes_Statically_Match
(T, Base_Type (T)))
or else (Is_Access_Type (T)
and then Subtypes_Statically_Match
(T, First_Subtype (T)))))
or else (Is_Composite_Type (T)
and then
-- If Q is an aggregate, Is_Constrained may not be set
-- yet and its type may not be resolved yet.
-- This doesn't quite correspond to the complex notion
-- of "known to be constrained" but this is good enough
-- for a rule which is in any case too complex.
not (Is_Constrained (Etype (Q))
or else Nkind (Q) = N_Aggregate
or else Subtypes_Statically_Match
(T, First_Subtype (T))))
then
Error_Msg_N
("subtype of renamed qualified expression does not " &
"statically match", N);
return;
end if;
end if;
Resolve (Nam, T);
-- If the renamed object is a function call of a limited type,
-- the expansion of the renaming is complicated by the presence
-- of various temporaries and subtypes that capture constraints
-- of the renamed object. Rewrite node as an object declaration,
-- whose expansion is simpler. Given that the object is limited
-- there is no copy involved and no performance hit.
if Nkind (Nam) = N_Function_Call
and then Is_Limited_View (Etype (Nam))
and then not Is_Constrained (Etype (Nam))
and then Comes_From_Source (N)
then
Set_Etype (Id, T);
Mutate_Ekind (Id, E_Constant);
Rewrite (N,
Make_Object_Declaration (Loc,
Defining_Identifier => Id,
Constant_Present => True,
Object_Definition => New_Occurrence_Of (Etype (Nam), Loc),
Expression => Relocate_Node (Nam)));
return;
end if;
-- Ada 2012 (AI05-149): Reject renaming of an anonymous access object
-- when renaming declaration has a named access type. The Ada 2012
-- coverage rules allow an anonymous access type in the context of
-- an expected named general access type, but the renaming rules
-- require the types to be the same. (An exception is when the type
-- of the renaming is also an anonymous access type, which can only
-- happen due to a renaming created by the expander.)
if Nkind (Nam) = N_Type_Conversion
and then not Comes_From_Source (Nam)
and then Is_Anonymous_Access_Type (Etype (Expression (Nam)))
and then not Is_Anonymous_Access_Type (T)
then
Error_Msg_NE
("cannot rename anonymous access object "
& "as a named access type", Expression (Nam), T);
end if;
-- Check that a class-wide object is not being renamed as an object
-- of a specific type. The test for access types is needed to exclude
-- cases where the renamed object is a dynamically tagged access
-- result, such as occurs in certain expansions.
if Is_Tagged_Type (T) then
Check_Dynamically_Tagged_Expression
(Expr => Nam,
Typ => T,
Related_Nod => N);
end if;
-- Ada 2005 (AI-230/AI-254): Access renaming
else pragma Assert (Present (Access_Definition (N)));
T :=
Access_Definition
(Related_Nod => N,
N => Access_Definition (N));
Analyze (Nam);
-- The object renaming declaration may become Ghost if it renames a
-- Ghost entity.
if Is_Entity_Name (Nam) then
Mark_Ghost_Renaming (N, Entity (Nam));
end if;
-- Ada 2005 AI05-105: if the declaration has an anonymous access
-- type, the renamed object must also have an anonymous type, and
-- this is a name resolution rule. This was implicit in the last part
-- of the first sentence in 8.5.1(3/2), and is made explicit by this
-- recent AI.
if not Is_Overloaded (Nam) then
if Ekind (Etype (Nam)) /= Ekind (T) then
Error_Msg_N
("expect anonymous access type in object renaming", N);
end if;
else
declare
I : Interp_Index;
It : Interp;
Typ : Entity_Id := Empty;
Seen : Boolean := False;
begin
Get_First_Interp (Nam, I, It);
while Present (It.Typ) loop
-- Renaming is ambiguous if more than one candidate
-- interpretation is type-conformant with the context.
if Ekind (It.Typ) = Ekind (T) then
if Ekind (T) = E_Anonymous_Access_Subprogram_Type
and then
Type_Conformant
(Designated_Type (T), Designated_Type (It.Typ))
then
if not Seen then
Seen := True;
else
Error_Msg_N
("ambiguous expression in renaming", Nam);
end if;
elsif Ekind (T) = E_Anonymous_Access_Type
and then
Covers (Designated_Type (T), Designated_Type (It.Typ))
then
if not Seen then
Seen := True;
else
Error_Msg_N
("ambiguous expression in renaming", Nam);
end if;
end if;
if Covers (T, It.Typ) then
Typ := It.Typ;
Set_Etype (Nam, Typ);
Set_Is_Overloaded (Nam, False);
end if;
end if;
Get_Next_Interp (I, It);
end loop;
end;
end if;
Resolve (Nam, T);
-- Do not perform the legality checks below when the resolution of
-- the renaming name failed because the associated type is Any_Type.
if Etype (Nam) = Any_Type then
null;
-- Ada 2005 (AI-231): In the case where the type is defined by an
-- access_definition, the renamed entity shall be of an access-to-
-- constant type if and only if the access_definition defines an
-- access-to-constant type. ARM 8.5.1(4)
elsif Constant_Present (Access_Definition (N))
and then not Is_Access_Constant (Etype (Nam))
then
Error_Msg_N
("(Ada 2005): the renamed object is not access-to-constant "
& "(RM 8.5.1(6))", N);
elsif not Constant_Present (Access_Definition (N))
and then Is_Access_Constant (Etype (Nam))
then
Error_Msg_N
("(Ada 2005): the renamed object is not access-to-variable "
& "(RM 8.5.1(6))", N);
end if;
if Is_Access_Subprogram_Type (Etype (Nam)) then
Check_Subtype_Conformant
(Designated_Type (T), Designated_Type (Etype (Nam)));
elsif not Subtypes_Statically_Match
(Designated_Type (T),
Available_View (Designated_Type (Etype (Nam))))
then
Error_Msg_N
("subtype of renamed object does not statically match", N);
end if;
end if;
-- Special processing for renaming function return object. Some errors
-- and warnings are produced only for calls that come from source.
if Nkind (Nam) = N_Function_Call then
case Ada_Version is
-- Usage is illegal in Ada 83, but renamings are also introduced
-- during expansion, and error does not apply to those.
when Ada_83 =>
if Comes_From_Source (N) then
Error_Msg_N
("(Ada 83) cannot rename function return object", Nam);
end if;
-- In Ada 95, warn for odd case of renaming parameterless function
-- call if this is not a limited type (where this is useful).
when others =>
if Warn_On_Object_Renames_Function
and then No (Parameter_Associations (Nam))
and then not Is_Limited_Type (Etype (Nam))
and then Comes_From_Source (Nam)
then
Error_Msg_N
("renaming function result object is suspicious?.r?", Nam);
Error_Msg_NE
("\function & will be called only once?.r?", Nam,
Entity (Name (Nam)));
Error_Msg_N -- CODEFIX
("\suggest using an initialized constant object "
& "instead?.r?", Nam);
end if;
end case;
end if;
Check_Constrained_Object;
-- An object renaming requires an exact match of the type. Class-wide
-- matching is not allowed.
if Is_Class_Wide_Type (T)
and then Base_Type (Etype (Nam)) /= Base_Type (T)
then
Wrong_Type (Nam, T);
end if;
-- We must search for an actual subtype here so that the bounds of
-- objects of unconstrained types don't get dropped on the floor - such
-- as with renamings of formal parameters.
T2 := Get_Actual_Subtype_If_Available (Nam);
-- Ada 2005 (AI-326): Handle wrong use of incomplete type
if Nkind (Nam) = N_Explicit_Dereference
and then Ekind (Etype (T2)) = E_Incomplete_Type
then
Error_Msg_NE ("invalid use of incomplete type&", Id, T2);
return;
elsif Ekind (Etype (T)) = E_Incomplete_Type then
Error_Msg_NE ("invalid use of incomplete type&", Id, T);
return;
end if;
if Ada_Version >= Ada_2005 and then Nkind (Nam) in N_Has_Entity then
declare
Nam_Ent : constant Entity_Id := Entity (Get_Object_Name (Nam));
Nam_Decl : constant Node_Id := Declaration_Node (Nam_Ent);
begin
if Has_Null_Exclusion (N)
and then not Has_Null_Exclusion (Nam_Decl)
then
-- Ada 2005 (AI-423): If the object name denotes a generic
-- formal object of a generic unit G, and the object renaming
-- declaration occurs within the body of G or within the body
-- of a generic unit declared within the declarative region
-- of G, then the declaration of the formal object of G must
-- have a null exclusion or a null-excluding subtype.
if Is_Formal_Object (Nam_Ent)
and then In_Generic_Scope (Id)
then
if not Can_Never_Be_Null (Etype (Nam_Ent)) then
Error_Msg_N
("object does not exclude `NULL` "
& "(RM 8.5.1(4.6/2))", N);
elsif In_Package_Body (Scope (Id)) then
Error_Msg_N
("formal object does not have a null exclusion"
& "(RM 8.5.1(4.6/2))", N);
end if;
-- Ada 2005 (AI-423): Otherwise, the subtype of the object name
-- shall exclude null.
elsif not Can_Never_Be_Null (Etype (Nam_Ent)) then
Error_Msg_N
("object does not exclude `NULL` "
& "(RM 8.5.1(4.6/2))", N);
-- An instance is illegal if it contains a renaming that
-- excludes null, and the actual does not. The renaming
-- declaration has already indicated that the declaration
-- of the renamed actual in the instance will raise
-- constraint_error.
elsif Nkind (Nam_Decl) = N_Object_Declaration
and then In_Instance
and then
Present (Corresponding_Generic_Association (Nam_Decl))
and then Nkind (Expression (Nam_Decl)) =
N_Raise_Constraint_Error
then
Error_Msg_N
("actual does not exclude `NULL` (RM 8.5.1(4.6/2))", N);
-- Finally, if there is a null exclusion, the subtype mark
-- must not be null-excluding.
elsif No (Access_Definition (N))
and then Can_Never_Be_Null (T)
then
Error_Msg_NE
("`NOT NULL` not allowed (& already excludes null)",
N, T);
end if;
elsif Can_Never_Be_Null (T)
and then not Can_Never_Be_Null (Etype (Nam_Ent))
then
Error_Msg_N
("object does not exclude `NULL` (RM 8.5.1(4.6/2))", N);
elsif Has_Null_Exclusion (N)
and then No (Access_Definition (N))
and then Can_Never_Be_Null (T)
then
Error_Msg_NE
("`NOT NULL` not allowed (& already excludes null)", N, T);
end if;
end;
end if;
-- Set the Ekind of the entity, unless it has been set already, as is
-- the case for the iteration object over a container with no variable
-- indexing. In that case it's been marked as a constant, and we do not
-- want to change it to a variable.
if Ekind (Id) /= E_Constant then
Mutate_Ekind (Id, E_Variable);
end if;
Reinit_Object_Size_Align (Id);
-- If N comes from source then check that the original node is an
-- object reference since there may have been several rewritting and
-- folding. Do not do this for N_Function_Call or N_Explicit_Dereference
-- which might correspond to rewrites of e.g. N_Selected_Component
-- (for example Object.Method rewriting).
-- If N does not come from source then assume the tree is properly
-- formed and accept any object reference. In such cases we do support
-- more cases of renamings anyway, so the actual check on which renaming
-- is valid is better left to the code generator as a last sanity
-- check.
if Comes_From_Source (N) then
if Nkind (Nam) in N_Function_Call | N_Explicit_Dereference then
Is_Object_Ref := Is_Object_Reference (Nam);
else
Is_Object_Ref := Is_Object_Reference (Original_Node (Nam));
end if;
else
Is_Object_Ref := True;
end if;
if T = Any_Type or else Etype (Nam) = Any_Type then
return;
-- Verify that the renamed entity is an object or function call
elsif Is_Object_Ref then
if Comes_From_Source (N) then
if Is_Dependent_Component_Of_Mutable_Object (Nam) then
Error_Msg_N
("illegal renaming of discriminant-dependent component", Nam);
end if;
-- If the renaming comes from source and the renamed object is a
-- dereference, then mark the prefix as needing debug information,
-- since it might have been rewritten hence internally generated
-- and Debug_Renaming_Declaration will link the renaming to it.
if Nkind (Nam) = N_Explicit_Dereference
and then Is_Entity_Name (Prefix (Nam))
then
Set_Debug_Info_Needed (Entity (Prefix (Nam)));
end if;
end if;
-- Weird but legal, equivalent to renaming a function call. Illegal
-- if the literal is the result of constant-folding an attribute
-- reference that is not a function.
elsif Is_Entity_Name (Nam)
and then Ekind (Entity (Nam)) = E_Enumeration_Literal
and then Nkind (Original_Node (Nam)) /= N_Attribute_Reference
then
null;
-- A named number can only be renamed without a subtype mark
elsif Nkind (Nam) in N_Real_Literal | N_Integer_Literal
and then Present (Subtype_Mark (N))
and then Present (Original_Entity (Nam))
then
Error_Msg_N ("incompatible types in renaming", Nam);
-- AI12-0383: Names that denote values can be renamed.
-- Ignore (accept) N_Raise_xxx_Error nodes in this context.
elsif No_Raise_xxx_Error (Nam) = OK then
Error_Msg_Ada_2022_Feature ("value in renaming", Sloc (Nam));
end if;
Set_Etype (Id, T2);
if not Is_Variable (Nam) then
Mutate_Ekind (Id, E_Constant);
Set_Never_Set_In_Source (Id, True);
Set_Is_True_Constant (Id, True);
end if;
-- The entity of the renaming declaration needs to reflect whether the
-- renamed object is atomic, independent, volatile or VFA. These flags
-- are set on the renamed object in the RM legality sense.
Set_Is_Atomic (Id, Is_Atomic_Object (Nam));
Set_Is_Independent (Id, Is_Independent_Object (Nam));
Set_Is_Volatile (Id, Is_Volatile_Object_Ref (Nam));
Set_Is_Volatile_Full_Access
(Id, Is_Volatile_Full_Access_Object_Ref (Nam));
-- Treat as volatile if we just set the Volatile flag
if Is_Volatile (Id)
-- Or if we are renaming an entity which was marked this way
-- Are there more cases, e.g. X(J) where X is Treat_As_Volatile ???
or else (Is_Entity_Name (Nam)
and then Treat_As_Volatile (Entity (Nam)))
then
Set_Treat_As_Volatile (Id, True);
end if;
-- Now make the link to the renamed object
Set_Renamed_Object (Id, Nam);
-- Implementation-defined aspect specifications can appear in a renaming
-- declaration, but not language-defined ones. The call to procedure
-- Analyze_Aspect_Specifications will take care of this error check.
if Has_Aspects (N) then
Analyze_Aspect_Specifications (N, Id);
end if;
-- Deal with dimensions
Analyze_Dimension (N);
end Analyze_Object_Renaming;
------------------------------
-- Analyze_Package_Renaming --
------------------------------
procedure Analyze_Package_Renaming (N : Node_Id) is
New_P : constant Entity_Id := Defining_Entity (N);
Old_P : Entity_Id;
Spec : Node_Id;
begin
if Name (N) = Error then
return;
end if;
-- Check for Text_IO special units (we may be renaming a Text_IO child),
-- but make sure not to catch renamings generated for package instances
-- that have nothing to do with them but are nevertheless homonyms.
if Is_Entity_Name (Name (N))
and then Present (Entity (Name (N)))
and then Is_Generic_Instance (Entity (Name (N)))
then
null;
else
Check_Text_IO_Special_Unit (Name (N));
end if;
if Current_Scope /= Standard_Standard then
Set_Is_Pure (New_P, Is_Pure (Current_Scope));
end if;
Enter_Name (New_P);
Analyze (Name (N));
if Is_Entity_Name (Name (N)) then
Old_P := Entity (Name (N));
else
Old_P := Any_Id;
end if;
if Etype (Old_P) = Any_Type then
Error_Msg_N ("expect package name in renaming", Name (N));
elsif Ekind (Old_P) /= E_Package
and then not (Ekind (Old_P) = E_Generic_Package
and then In_Open_Scopes (Old_P))
then
if Ekind (Old_P) = E_Generic_Package then
Error_Msg_N
("generic package cannot be renamed as a package", Name (N));
else
Error_Msg_Sloc := Sloc (Old_P);
Error_Msg_NE
("expect package name in renaming, found& declared#",
Name (N), Old_P);
end if;
-- Set basic attributes to minimize cascaded errors
Mutate_Ekind (New_P, E_Package);
Set_Etype (New_P, Standard_Void_Type);
elsif Present (Renamed_Entity (Old_P))
and then (From_Limited_With (Renamed_Entity (Old_P))
or else Has_Limited_View (Renamed_Entity (Old_P)))
and then not
Unit_Is_Visible (Cunit (Get_Source_Unit (Renamed_Entity (Old_P))))
then
Error_Msg_NE
("renaming of limited view of package & not usable in this context"
& " (RM 8.5.3(3.1/2))", Name (N), Renamed_Entity (Old_P));
-- Set basic attributes to minimize cascaded errors
Mutate_Ekind (New_P, E_Package);
Set_Etype (New_P, Standard_Void_Type);
-- Here for OK package renaming
else
-- Entities in the old package are accessible through the renaming
-- entity. The simplest implementation is to have both packages share
-- the entity list.
Mutate_Ekind (New_P, E_Package);
Set_Etype (New_P, Standard_Void_Type);
if Present (Renamed_Entity (Old_P)) then
Set_Renamed_Entity (New_P, Renamed_Entity (Old_P));
else
Set_Renamed_Entity (New_P, Old_P);
end if;
-- The package renaming declaration may become Ghost if it renames a
-- Ghost entity.
Mark_Ghost_Renaming (N, Old_P);
Set_Has_Completion (New_P);
Set_First_Entity (New_P, First_Entity (Old_P));
Set_Last_Entity (New_P, Last_Entity (Old_P));
Set_First_Private_Entity (New_P, First_Private_Entity (Old_P));
Check_Library_Unit_Renaming (N, Old_P);
Generate_Reference (Old_P, Name (N));
-- If the renaming is in the visible part of a package, then we set
-- Renamed_In_Spec for the renamed package, to prevent giving
-- warnings about no entities referenced. Such a warning would be
-- overenthusiastic, since clients can see entities in the renamed
-- package via the visible package renaming.
declare
Ent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
begin
if Ekind (Ent) = E_Package
and then not In_Private_Part (Ent)
and then In_Extended_Main_Source_Unit (N)
and then Ekind (Old_P) = E_Package
then
Set_Renamed_In_Spec (Old_P);
end if;
end;
-- If this is the renaming declaration of a package instantiation
-- within itself, it is the declaration that ends the list of actuals
-- for the instantiation. At this point, the subtypes that rename
-- the actuals are flagged as generic, to avoid spurious ambiguities
-- if the actuals for two distinct formals happen to coincide. If
-- the actual is a private type, the subtype has a private completion
-- that is flagged in the same fashion.
-- Resolution is identical to what is was in the original generic.
-- On exit from the generic instance, these are turned into regular
-- subtypes again, so they are compatible with types in their class.
if not Is_Generic_Instance (Old_P) then
return;
else
Spec := Specification (Unit_Declaration_Node (Old_P));
end if;
if Nkind (Spec) = N_Package_Specification
and then Present (Generic_Parent (Spec))
and then Old_P = Current_Scope
and then Chars (New_P) = Chars (Generic_Parent (Spec))
then
declare
E : Entity_Id;
begin
E := First_Entity (Old_P);
while Present (E) and then E /= New_P loop
if Is_Type (E)
and then Nkind (Parent (E)) = N_Subtype_Declaration
then
Set_Is_Generic_Actual_Type (E);
if Is_Private_Type (E)
and then Present (Full_View (E))
then
Set_Is_Generic_Actual_Type (Full_View (E));
end if;
end if;
Next_Entity (E);
end loop;
end;
end if;
end if;
-- Implementation-defined aspect specifications can appear in a renaming
-- declaration, but not language-defined ones. The call to procedure
-- Analyze_Aspect_Specifications will take care of this error check.
if Has_Aspects (N) then
Analyze_Aspect_Specifications (N, New_P);
end if;
end Analyze_Package_Renaming;
-------------------------------
-- Analyze_Renamed_Character --
-------------------------------
procedure Analyze_Renamed_Character
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean)
is
C : constant Node_Id := Name (N);
begin
if Ekind (New_S) = E_Function then
Resolve (C, Etype (New_S));
if Is_Body then
Check_Frozen_Renaming (N, New_S);
end if;
else
Error_Msg_N ("character literal can only be renamed as function", N);
end if;
end Analyze_Renamed_Character;
---------------------------------
-- Analyze_Renamed_Dereference --
---------------------------------
procedure Analyze_Renamed_Dereference
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean)
is
Nam : constant Node_Id := Name (N);
P : constant Node_Id := Prefix (Nam);
Typ : Entity_Id;
Ind : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (P) then
if Ekind (Etype (Nam)) /= E_Subprogram_Type
or else not Type_Conformant (Etype (Nam), New_S)
then
Error_Msg_N ("designated type does not match specification", P);
else
Resolve (P);
end if;
return;
else
Typ := Any_Type;
Get_First_Interp (Nam, Ind, It);
while Present (It.Nam) loop
if Ekind (It.Nam) = E_Subprogram_Type
and then Type_Conformant (It.Nam, New_S)
then
if Typ /= Any_Id then
Error_Msg_N ("ambiguous renaming", P);
return;
else
Typ := It.Nam;
end if;
end if;
Get_Next_Interp (Ind, It);
end loop;
if Typ = Any_Type then
Error_Msg_N ("designated type does not match specification", P);
else
Resolve (N, Typ);
if Is_Body then
Check_Frozen_Renaming (N, New_S);
end if;
end if;
end if;
end Analyze_Renamed_Dereference;
---------------------------
-- Analyze_Renamed_Entry --
---------------------------
procedure Analyze_Renamed_Entry
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean)
is
Nam : constant Node_Id := Name (N);
Sel : constant Node_Id := Selector_Name (Nam);
Is_Actual : constant Boolean := Present (Corresponding_Formal_Spec (N));
Old_S : Entity_Id;
begin
if Entity (Sel) = Any_Id then
-- Selector is undefined on prefix. Error emitted already
Set_Has_Completion (New_S);
return;
end if;
-- Otherwise find renamed entity and build body of New_S as a call to it
Old_S := Find_Renamed_Entity (N, Selector_Name (Nam), New_S);
if Old_S = Any_Id then
Error_Msg_N ("no subprogram or entry matches specification", N);
else
if Is_Body then
Check_Subtype_Conformant (New_S, Old_S, N);
Generate_Reference (New_S, Defining_Entity (N), 'b');
Style.Check_Identifier (Defining_Entity (N), New_S);
else
-- Only mode conformance required for a renaming_as_declaration
Check_Mode_Conformant (New_S, Old_S, N);
end if;
Inherit_Renamed_Profile (New_S, Old_S);
-- The prefix can be an arbitrary expression that yields a task or
-- protected object, so it must be resolved.
if Is_Access_Type (Etype (Prefix (Nam))) then
Insert_Explicit_Dereference (Prefix (Nam));
end if;
Resolve (Prefix (Nam), Scope (Old_S));
end if;
Set_Convention (New_S, Convention (Old_S));
Set_Has_Completion (New_S, Inside_A_Generic);
-- AI05-0225: If the renamed entity is a procedure or entry of a
-- protected object, the target object must be a variable.
if Is_Protected_Type (Scope (Old_S))
and then Ekind (New_S) = E_Procedure
and then not Is_Variable (Prefix (Nam))
then
if Is_Actual then
Error_Msg_N
("target object of protected operation used as actual for "
& "formal procedure must be a variable", Nam);
else
Error_Msg_N
("target object of protected operation renamed as procedure, "
& "must be a variable", Nam);
end if;
end if;
if Is_Body then
Check_Frozen_Renaming (N, New_S);
end if;
end Analyze_Renamed_Entry;
-----------------------------------
-- Analyze_Renamed_Family_Member --
-----------------------------------
procedure Analyze_Renamed_Family_Member
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean)
is
Nam : constant Node_Id := Name (N);
P : constant Node_Id := Prefix (Nam);
Old_S : Entity_Id;
begin
if (Is_Entity_Name (P) and then Ekind (Entity (P)) = E_Entry_Family)
or else (Nkind (P) = N_Selected_Component
and then Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
then
if Is_Entity_Name (P) then
Old_S := Entity (P);
else
Old_S := Entity (Selector_Name (P));
end if;
if not Entity_Matches_Spec (Old_S, New_S) then
Error_Msg_N ("entry family does not match specification", N);
elsif Is_Body then
Check_Subtype_Conformant (New_S, Old_S, N);
Generate_Reference (New_S, Defining_Entity (N), 'b');
Style.Check_Identifier (Defining_Entity (N), New_S);
end if;
else
Error_Msg_N ("no entry family matches specification", N);
end if;
Set_Has_Completion (New_S, Inside_A_Generic);
if Is_Body then
Check_Frozen_Renaming (N, New_S);
end if;
end Analyze_Renamed_Family_Member;
-----------------------------------------
-- Analyze_Renamed_Primitive_Operation --
-----------------------------------------
procedure Analyze_Renamed_Primitive_Operation
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean)
is
Old_S : Entity_Id;
Nam : Entity_Id;
function Conforms
(Subp : Entity_Id;
Ctyp : Conformance_Type) return Boolean;
-- Verify that the signatures of the renamed entity and the new entity
-- match. The first formal of the renamed entity is skipped because it
-- is the target object in any subsequent call.
--------------
-- Conforms --
--------------
function Conforms
(Subp : Entity_Id;
Ctyp : Conformance_Type) return Boolean
is
Old_F : Entity_Id;
New_F : Entity_Id;
begin
if Ekind (Subp) /= Ekind (New_S) then
return False;
end if;
Old_F := Next_Formal (First_Formal (Subp));
New_F := First_Formal (New_S);
while Present (Old_F) and then Present (New_F) loop
if not Conforming_Types (Etype (Old_F), Etype (New_F), Ctyp) then
return False;
end if;
if Ctyp >= Mode_Conformant
and then Ekind (Old_F) /= Ekind (New_F)
then
return False;
end if;
Next_Formal (New_F);
Next_Formal (Old_F);
end loop;
return True;
end Conforms;
-- Start of processing for Analyze_Renamed_Primitive_Operation
begin
if not Is_Overloaded (Selector_Name (Name (N))) then
Old_S := Entity (Selector_Name (Name (N)));
if not Conforms (Old_S, Type_Conformant) then
Old_S := Any_Id;
end if;
else
-- Find the operation that matches the given signature
declare
It : Interp;
Ind : Interp_Index;
begin
Old_S := Any_Id;
Get_First_Interp (Selector_Name (Name (N)), Ind, It);
while Present (It.Nam) loop
if Conforms (It.Nam, Type_Conformant) then
Old_S := It.Nam;
end if;
Get_Next_Interp (Ind, It);
end loop;
end;
end if;
if Old_S = Any_Id then
Error_Msg_N ("no subprogram or entry matches specification", N);
else
if Is_Body then
if not Conforms (Old_S, Subtype_Conformant) then
Error_Msg_N ("subtype conformance error in renaming", N);
end if;
Generate_Reference (New_S, Defining_Entity (N), 'b');
Style.Check_Identifier (Defining_Entity (N), New_S);
else
-- Only mode conformance required for a renaming_as_declaration
if not Conforms (Old_S, Mode_Conformant) then
Error_Msg_N ("mode conformance error in renaming", N);
end if;
-- AI12-0204: The prefix of a prefixed view that is renamed or
-- passed as a formal subprogram must be renamable as an object.
Nam := Prefix (Name (N));
if Is_Object_Reference (Nam) then
if Is_Dependent_Component_Of_Mutable_Object (Nam) then
Error_Msg_N
("illegal renaming of discriminant-dependent component",
Nam);
end if;
else
Error_Msg_N ("expect object name in renaming", Nam);
end if;
-- Enforce the rule given in (RM 6.3.1 (10.1/2)): a prefixed
-- view of a subprogram is intrinsic, because the compiler has
-- to generate a wrapper for any call to it. If the name in a
-- subprogram renaming is a prefixed view, the entity is thus
-- intrinsic, and 'Access cannot be applied to it.
Set_Convention (New_S, Convention_Intrinsic);
end if;
-- Inherit_Renamed_Profile (New_S, Old_S);
-- The prefix can be an arbitrary expression that yields an
-- object, so it must be resolved.
Resolve (Prefix (Name (N)));
end if;
end Analyze_Renamed_Primitive_Operation;
---------------------------------
-- Analyze_Subprogram_Renaming --
---------------------------------
procedure Analyze_Subprogram_Renaming (N : Node_Id) is
Formal_Spec : constant Entity_Id := Corresponding_Formal_Spec (N);
Is_Actual : constant Boolean := Present (Formal_Spec);
Nam : constant Node_Id := Name (N);
Save_AV : constant Ada_Version_Type := Ada_Version;
Save_AVP : constant Node_Id := Ada_Version_Pragma;
Save_AV_Exp : constant Ada_Version_Type := Ada_Version_Explicit;
Spec : constant Node_Id := Specification (N);
Old_S : Entity_Id := Empty;
Rename_Spec : Entity_Id;
procedure Check_Null_Exclusion
(Ren : Entity_Id;
Sub : Entity_Id);
-- Ada 2005 (AI-423): Given renaming Ren of subprogram Sub, check the
-- following AI rules:
--
-- If Ren denotes a generic formal object of a generic unit G, and the
-- renaming (or instantiation containing the actual) occurs within the
-- body of G or within the body of a generic unit declared within the
-- declarative region of G, then the corresponding parameter of G
-- shall have a null_exclusion; Otherwise the subtype of the Sub's
-- formal parameter shall exclude null.
--
-- Similarly for its return profile.
procedure Check_SPARK_Primitive_Operation (Subp_Id : Entity_Id);
-- Ensure that a SPARK renaming denoted by its entity Subp_Id does not
-- declare a primitive operation of a tagged type (SPARK RM 6.1.1(3)).
procedure Freeze_Actual_Profile;
-- In Ada 2012, enforce the freezing rule concerning formal incomplete
-- types: a callable entity freezes its profile, unless it has an
-- incomplete untagged formal (RM 13.14(10.2/3)).
function Has_Class_Wide_Actual return Boolean;
-- Ada 2012 (AI05-071, AI05-0131) and Ada 2022 (AI12-0165): True if N is
-- the renaming for a defaulted formal subprogram where the actual for
-- the controlling formal type is class-wide.
procedure Handle_Instance_With_Class_Wide_Type
(Inst_Node : Node_Id;
Ren_Id : Entity_Id;
Wrapped_Prim : out Entity_Id;
Wrap_Id : out Entity_Id);
-- Ada 2012 (AI05-0071), Ada 2022 (AI12-0165): when the actual type
-- of an instantiation is a class-wide type T'Class we may need to
-- wrap a primitive operation of T; this routine looks for a suitable
-- primitive to be wrapped and (if the wrapper is required) returns the
-- Id of the wrapped primitive and the Id of the built wrapper. Ren_Id
-- is the defining entity for the renamed subprogram specification.
function Original_Subprogram (Subp : Entity_Id) return Entity_Id;
-- Find renamed entity when the declaration is a renaming_as_body and
-- the renamed entity may itself be a renaming_as_body. Used to enforce
-- rule that a renaming_as_body is illegal if the declaration occurs
-- before the subprogram it completes is frozen, and renaming indirectly
-- renames the subprogram itself.(Defect Report 8652/0027).
--------------------------
-- Check_Null_Exclusion --
--------------------------
procedure Check_Null_Exclusion
(Ren : Entity_Id;
Sub : Entity_Id)
is
Ren_Formal : Entity_Id;
Sub_Formal : Entity_Id;
function Null_Exclusion_Mismatch
(Renaming : Entity_Id; Renamed : Entity_Id) return Boolean;
-- Return True if there is a null exclusion mismatch between
-- Renaming and Renamed, False otherwise.
-----------------------------
-- Null_Exclusion_Mismatch --
-----------------------------
function Null_Exclusion_Mismatch
(Renaming : Entity_Id; Renamed : Entity_Id) return Boolean is
begin
return Has_Null_Exclusion (Parent (Renaming))
and then
not (Has_Null_Exclusion (Parent (Renamed))
or else (Can_Never_Be_Null (Etype (Renamed))
and then not
(Is_Formal_Subprogram (Sub)
and then In_Generic_Body (Current_Scope))));
end Null_Exclusion_Mismatch;
begin
-- Parameter check
Ren_Formal := First_Formal (Ren);
Sub_Formal := First_Formal (Sub);
while Present (Ren_Formal) and then Present (Sub_Formal) loop
if Null_Exclusion_Mismatch (Ren_Formal, Sub_Formal) then
Error_Msg_Sloc := Sloc (Sub_Formal);
Error_Msg_NE
("`NOT NULL` required for parameter &#",
Ren_Formal, Sub_Formal);
end if;
Next_Formal (Ren_Formal);
Next_Formal (Sub_Formal);
end loop;
-- Return profile check
if Nkind (Parent (Ren)) = N_Function_Specification
and then Nkind (Parent (Sub)) = N_Function_Specification
and then Null_Exclusion_Mismatch (Ren, Sub)
then
Error_Msg_Sloc := Sloc (Sub);
Error_Msg_N ("return must specify `NOT NULL`#", Ren);
end if;
end Check_Null_Exclusion;
-------------------------------------
-- Check_SPARK_Primitive_Operation --
-------------------------------------
procedure Check_SPARK_Primitive_Operation (Subp_Id : Entity_Id) is
Prag : constant Node_Id := SPARK_Pragma (Subp_Id);
Typ : Entity_Id;
begin
-- Nothing to do when the subprogram is not subject to SPARK_Mode On
-- because this check applies to SPARK code only.
if not (Present (Prag)
and then Get_SPARK_Mode_From_Annotation (Prag) = On)
then
return;
-- Nothing to do when the subprogram is not a primitive operation
elsif not Is_Primitive (Subp_Id) then
return;
end if;
Typ := Find_Dispatching_Type (Subp_Id);
-- Nothing to do when the subprogram is a primitive operation of an
-- untagged type.
if No (Typ) then
return;
end if;
-- At this point a renaming declaration introduces a new primitive
-- operation for a tagged type.
Error_Msg_Node_2 := Typ;
Error_Msg_NE
("subprogram renaming & cannot declare primitive for type & "
& "(SPARK RM 6.1.1(3))", N, Subp_Id);
end Check_SPARK_Primitive_Operation;
---------------------------
-- Freeze_Actual_Profile --
---------------------------
procedure Freeze_Actual_Profile is
F : Entity_Id;
Has_Untagged_Inc : Boolean;
Instantiation_Node : constant Node_Id := Parent (N);
begin
if Ada_Version >= Ada_2012 then
F := First_Formal (Formal_Spec);
Has_Untagged_Inc := False;
while Present (F) loop
if Ekind (Etype (F)) = E_Incomplete_Type
and then not Is_Tagged_Type (Etype (F))
then
Has_Untagged_Inc := True;
exit;
end if;
Next_Formal (F);
end loop;
if Ekind (Formal_Spec) = E_Function
and then not Is_Tagged_Type (Etype (Formal_Spec))
then
Has_Untagged_Inc := True;
end if;
if not Has_Untagged_Inc then
F := First_Formal (Old_S);
while Present (F) loop
Freeze_Before (Instantiation_Node, Etype (F));
if Is_Incomplete_Or_Private_Type (Etype (F))
and then No (Underlying_Type (Etype (F)))
then
-- Exclude generic types, or types derived from them.
-- They will be frozen in the enclosing instance.
if Is_Generic_Type (Etype (F))
or else Is_Generic_Type (Root_Type (Etype (F)))
then
null;
-- A limited view of a type declared elsewhere needs no
-- freezing actions.
elsif From_Limited_With (Etype (F)) then
null;
else
Error_Msg_NE
("type& must be frozen before this point",
Instantiation_Node, Etype (F));
end if;
end if;
Next_Formal (F);
end loop;
end if;
end if;
end Freeze_Actual_Profile;
---------------------------
-- Has_Class_Wide_Actual --
---------------------------
function Has_Class_Wide_Actual return Boolean is
Formal : Entity_Id;
Formal_Typ : Entity_Id;
begin
if Is_Actual then
Formal := First_Formal (Formal_Spec);
while Present (Formal) loop
Formal_Typ := Etype (Formal);
if Has_Unknown_Discriminants (Formal_Typ)
and then not Is_Class_Wide_Type (Formal_Typ)
and then Is_Class_Wide_Type (Get_Instance_Of (Formal_Typ))
then
return True;
end if;
Next_Formal (Formal);
end loop;
end if;
return False;
end Has_Class_Wide_Actual;
------------------------------------------
-- Handle_Instance_With_Class_Wide_Type --
------------------------------------------
procedure Handle_Instance_With_Class_Wide_Type
(Inst_Node : Node_Id;
Ren_Id : Entity_Id;
Wrapped_Prim : out Entity_Id;
Wrap_Id : out Entity_Id)
is
procedure Build_Class_Wide_Wrapper
(Ren_Id : Entity_Id;
Prim_Op : Entity_Id;
Wrap_Id : out Entity_Id);
-- Build a wrapper for the renaming Ren_Id of subprogram Prim_Op.
procedure Find_Suitable_Candidate
(Prim_Op : out Entity_Id;
Is_CW_Prim : out Boolean);
-- Look for a suitable primitive to be wrapped (Prim_Op); Is_CW_Prim
-- indicates that the found candidate is a class-wide primitive (to
-- help the caller decide if the wrapper is required).
------------------------------
-- Build_Class_Wide_Wrapper --
------------------------------
procedure Build_Class_Wide_Wrapper
(Ren_Id : Entity_Id;
Prim_Op : Entity_Id;
Wrap_Id : out Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
function Build_Call
(Subp_Id : Entity_Id;
Params : List_Id) return Node_Id;
-- Create a dispatching call to invoke routine Subp_Id with
-- actuals built from the parameter specifications of list Params.
function Build_Expr_Fun_Call
(Subp_Id : Entity_Id;
Params : List_Id) return Node_Id;
-- Create a dispatching call to invoke function Subp_Id with
-- actuals built from the parameter specifications of list Params.
-- Directly return the call, so that it can be used inside an
-- expression function. This is a requirement of GNATprove mode.
function Build_Spec (Subp_Id : Entity_Id) return Node_Id;
-- Create a subprogram specification based on the subprogram
-- profile of Subp_Id.
----------------
-- Build_Call --
----------------
function Build_Call
(Subp_Id : Entity_Id;
Params : List_Id) return Node_Id
is
Actuals : constant List_Id := New_List;
Call_Ref : constant Node_Id := New_Occurrence_Of (Subp_Id, Loc);
Formal : Node_Id;
begin
-- Build the actual parameters of the call
Formal := First (Params);
while Present (Formal) loop
Append_To (Actuals,
Make_Identifier (Loc,
Chars (Defining_Identifier (Formal))));
Next (Formal);
end loop;
-- Generate:
-- return Subp_Id (Actuals);
if Ekind (Subp_Id) in E_Function | E_Operator then
return
Make_Simple_Return_Statement (Loc,
Expression =>
Make_Function_Call (Loc,
Name => Call_Ref,
Parameter_Associations => Actuals));
-- Generate:
-- Subp_Id (Actuals);
else
return
Make_Procedure_Call_Statement (Loc,
Name => Call_Ref,
Parameter_Associations => Actuals);
end if;
end Build_Call;
-------------------------
-- Build_Expr_Fun_Call --
-------------------------
function Build_Expr_Fun_Call
(Subp_Id : Entity_Id;
Params : List_Id) return Node_Id
is
Actuals : constant List_Id := New_List;
Call_Ref : constant Node_Id := New_Occurrence_Of (Subp_Id, Loc);
Formal : Node_Id;
begin
pragma Assert (Ekind (Subp_Id) in E_Function | E_Operator);
-- Build the actual parameters of the call
Formal := First (Params);
while Present (Formal) loop
Append_To (Actuals,
Make_Identifier (Loc,
Chars (Defining_Identifier (Formal))));
Next (Formal);
end loop;
-- Generate:
-- Subp_Id (Actuals);
return
Make_Function_Call (Loc,
Name => Call_Ref,
Parameter_Associations => Actuals);
end Build_Expr_Fun_Call;
----------------
-- Build_Spec --
----------------
function Build_Spec (Subp_Id : Entity_Id) return Node_Id is
Params : constant List_Id := Copy_Parameter_List (Subp_Id);
Spec_Id : constant Entity_Id :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (Subp_Id), 'R'));
begin
if Ekind (Formal_Spec) = E_Procedure then
return
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Spec_Id,
Parameter_Specifications => Params);
else
return
Make_Function_Specification (Loc,
Defining_Unit_Name => Spec_Id,
Parameter_Specifications => Params,
Result_Definition =>
New_Copy_Tree (Result_Definition (Spec)));
end if;
end Build_Spec;
-- Local variables
Body_Decl : Node_Id;
Spec_Decl : Node_Id;
New_Spec : Node_Id;
-- Start of processing for Build_Class_Wide_Wrapper
begin
pragma Assert (not Error_Posted (Nam));
-- Step 1: Create the declaration and the body of the wrapper,
-- insert all the pieces into the tree.
-- In GNATprove mode, create a function wrapper in the form of an
-- expression function, so that an implicit postcondition relating
-- the result of calling the wrapper function and the result of
-- the dispatching call to the wrapped function is known during
-- proof.
if GNATprove_Mode
and then Ekind (Ren_Id) in E_Function | E_Operator
then
New_Spec := Build_Spec (Ren_Id);
Body_Decl :=
Make_Expression_Function (Loc,
Specification => New_Spec,
Expression =>
Build_Expr_Fun_Call
(Subp_Id => Prim_Op,
Params => Parameter_Specifications (New_Spec)));
Wrap_Id := Defining_Entity (Body_Decl);
-- Otherwise, create separate spec and body for the subprogram
else
Spec_Decl :=
Make_Subprogram_Declaration (Loc,
Specification => Build_Spec (Ren_Id));
Insert_Before_And_Analyze (N, Spec_Decl);
Wrap_Id := Defining_Entity (Spec_Decl);
Body_Decl :=
Make_Subprogram_Body (Loc,
Specification => Build_Spec (Ren_Id),
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Build_Call
(Subp_Id => Prim_Op,
Params =>
Parameter_Specifications
(Specification (Spec_Decl))))));
Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
end if;
Set_Is_Class_Wide_Wrapper (Wrap_Id);
-- If the operator carries an Eliminated pragma, indicate that
-- the wrapper is also to be eliminated, to prevent spurious
-- errors when using gnatelim on programs that include box-
-- defaulted initialization of equality operators.
Set_Is_Eliminated (Wrap_Id, Is_Eliminated (Prim_Op));
-- In GNATprove mode, insert the body in the tree for analysis
if GNATprove_Mode then
Insert_Before_And_Analyze (N, Body_Decl);
end if;
-- The generated body does not freeze and must be analyzed when
-- the class-wide wrapper is frozen. The body is only needed if
-- expansion is enabled.
if Expander_Active then
Append_Freeze_Action (Wrap_Id, Body_Decl);
end if;
-- Step 2: The subprogram renaming aliases the wrapper
Rewrite (Name (N), New_Occurrence_Of (Wrap_Id, Loc));
end Build_Class_Wide_Wrapper;
-----------------------------
-- Find_Suitable_Candidate --
-----------------------------
procedure Find_Suitable_Candidate
(Prim_Op : out Entity_Id;
Is_CW_Prim : out Boolean)
is
Loc : constant Source_Ptr := Sloc (N);
function Find_Primitive (Typ : Entity_Id) return Entity_Id;
-- Find a primitive subprogram of type Typ which matches the
-- profile of the renaming declaration.
procedure Interpretation_Error (Subp_Id : Entity_Id);
-- Emit a continuation error message suggesting subprogram Subp_Id
-- as a possible interpretation.
function Is_Intrinsic_Equality
(Subp_Id : Entity_Id) return Boolean;
-- Determine whether subprogram Subp_Id denotes the intrinsic "="
-- operator.
function Is_Suitable_Candidate
(Subp_Id : Entity_Id) return Boolean;
-- Determine whether subprogram Subp_Id is a suitable candidate
-- for the role of a wrapped subprogram.
--------------------
-- Find_Primitive --
--------------------
function Find_Primitive (Typ : Entity_Id) return Entity_Id is
procedure Replace_Parameter_Types (Spec : Node_Id);
-- Given a specification Spec, replace all class-wide parameter
-- types with reference to type Typ.
-----------------------------
-- Replace_Parameter_Types --
-----------------------------
procedure Replace_Parameter_Types (Spec : Node_Id) is
Formal : Node_Id;
Formal_Id : Entity_Id;
Formal_Typ : Node_Id;
begin
Formal := First (Parameter_Specifications (Spec));
while Present (Formal) loop
Formal_Id := Defining_Identifier (Formal);
Formal_Typ := Parameter_Type (Formal);
-- Create a new entity for each class-wide formal to
-- prevent aliasing with the original renaming. Replace
-- the type of such a parameter with the candidate type.
if Nkind (Formal_Typ) = N_Identifier
and then Is_Class_Wide_Type (Etype (Formal_Typ))
then
Set_Defining_Identifier (Formal,
Make_Defining_Identifier (Loc, Chars (Formal_Id)));
Set_Parameter_Type (Formal,
New_Occurrence_Of (Typ, Loc));
end if;
Next (Formal);
end loop;
end Replace_Parameter_Types;
-- Local variables
Alt_Ren : constant Node_Id := New_Copy_Tree (N);
Alt_Nam : constant Node_Id := Name (Alt_Ren);
Alt_Spec : constant Node_Id := Specification (Alt_Ren);
Subp_Id : Entity_Id;
-- Start of processing for Find_Primitive
begin
-- Each attempt to find a suitable primitive of a particular
-- type operates on its own copy of the original renaming.
-- As a result the original renaming is kept decoration and
-- side-effect free.
-- Inherit the overloaded status of the renamed subprogram name
if Is_Overloaded (Nam) then
Set_Is_Overloaded (Alt_Nam);
Save_Interps (Nam, Alt_Nam);
end if;
-- The copied renaming is hidden from visibility to prevent the
-- pollution of the enclosing context.
Set_Defining_Unit_Name (Alt_Spec, Make_Temporary (Loc, 'R'));
-- The types of all class-wide parameters must be changed to
-- the candidate type.
Replace_Parameter_Types (Alt_Spec);
-- Try to find a suitable primitive that matches the altered
-- profile of the renaming specification.
Subp_Id :=
Find_Renamed_Entity
(N => Alt_Ren,
Nam => Name (Alt_Ren),
New_S => Analyze_Subprogram_Specification (Alt_Spec),
Is_Actual => Is_Actual);
-- Do not return Any_Id if the resolution of the altered
-- profile failed as this complicates further checks on
-- the caller side; return Empty instead.
if Subp_Id = Any_Id then
return Empty;
else
return Subp_Id;
end if;
end Find_Primitive;
--------------------------
-- Interpretation_Error --
--------------------------
procedure Interpretation_Error (Subp_Id : Entity_Id) is
begin
Error_Msg_Sloc := Sloc (Subp_Id);
if Is_Internal (Subp_Id) then
Error_Msg_NE
("\\possible interpretation: predefined & #",
Spec, Formal_Spec);
else
Error_Msg_NE
("\\possible interpretation: & defined #",
Spec, Formal_Spec);
end if;
end Interpretation_Error;
---------------------------
-- Is_Intrinsic_Equality --
---------------------------
function Is_Intrinsic_Equality (Subp_Id : Entity_Id) return Boolean
is
begin
return
Ekind (Subp_Id) = E_Operator
and then Chars (Subp_Id) = Name_Op_Eq
and then Is_Intrinsic_Subprogram (Subp_Id);
end Is_Intrinsic_Equality;
---------------------------
-- Is_Suitable_Candidate --
---------------------------
function Is_Suitable_Candidate (Subp_Id : Entity_Id) return Boolean
is
begin
if No (Subp_Id) then
return False;
-- An intrinsic subprogram is never a good candidate. This
-- is an indication of a missing primitive, either defined
-- directly or inherited from a parent tagged type.
elsif Is_Intrinsic_Subprogram (Subp_Id) then
return False;
else
return True;
end if;
end Is_Suitable_Candidate;
-- Local variables
Actual_Typ : Entity_Id := Empty;
-- The actual class-wide type for Formal_Typ
CW_Prim_OK : Boolean;
CW_Prim_Op : Entity_Id;
-- The class-wide subprogram (if available) that corresponds to
-- the renamed generic formal subprogram.
Formal_Typ : Entity_Id := Empty;
-- The generic formal type with unknown discriminants
Root_Prim_OK : Boolean;
Root_Prim_Op : Entity_Id;
-- The root type primitive (if available) that corresponds to the
-- renamed generic formal subprogram.
Root_Typ : Entity_Id := Empty;
-- The root type of Actual_Typ
Formal : Node_Id;
-- Start of processing for Find_Suitable_Candidate
begin
pragma Assert (not Error_Posted (Nam));
Prim_Op := Empty;
Is_CW_Prim := False;
-- Analyze the renamed name, but do not resolve it. The resolution
-- is completed once a suitable subprogram is found.
Analyze (Nam);
-- When the renamed name denotes the intrinsic operator equals,
-- the name must be treated as overloaded. This allows for a
-- potential match against the root type's predefined equality
-- function.
if Is_Intrinsic_Equality (Entity (Nam)) then
Set_Is_Overloaded (Nam);
Collect_Interps (Nam);
end if;
-- Step 1: Find the generic formal type and its corresponding
-- class-wide actual type from the renamed generic formal
-- subprogram.
Formal := First_Formal (Formal_Spec);
while Present (Formal) loop
if Has_Unknown_Discriminants (Etype (Formal))
and then not Is_Class_Wide_Type (Etype (Formal))
and then Is_Class_Wide_Type (Get_Instance_Of (Etype (Formal)))
then
Formal_Typ := Etype (Formal);
Actual_Typ := Base_Type (Get_Instance_Of (Formal_Typ));
Root_Typ := Root_Type (Actual_Typ);
exit;
end if;
Next_Formal (Formal);
end loop;
-- The specification of the generic formal subprogram should
-- always contain a formal type with unknown discriminants whose
-- actual is a class-wide type; otherwise this indicates a failure
-- in function Has_Class_Wide_Actual.
pragma Assert (Present (Formal_Typ));
-- Step 2: Find the proper class-wide subprogram or primitive
-- that corresponds to the renamed generic formal subprogram.
CW_Prim_Op := Find_Primitive (Actual_Typ);
CW_Prim_OK := Is_Suitable_Candidate (CW_Prim_Op);
Root_Prim_Op := Find_Primitive (Root_Typ);
Root_Prim_OK := Is_Suitable_Candidate (Root_Prim_Op);
-- The class-wide actual type has two subprograms that correspond
-- to the renamed generic formal subprogram:
-- with procedure Prim_Op (Param : Formal_Typ);
-- procedure Prim_Op (Param : Actual_Typ); -- may be inherited
-- procedure Prim_Op (Param : Actual_Typ'Class);
-- Even though the declaration of the two subprograms is legal, a
-- call to either one is ambiguous and therefore illegal.
if CW_Prim_OK and Root_Prim_OK then
-- A user-defined primitive has precedence over a predefined
-- one.
if Is_Internal (CW_Prim_Op)
and then not Is_Internal (Root_Prim_Op)
then
Prim_Op := Root_Prim_Op;
elsif Is_Internal (Root_Prim_Op)
and then not Is_Internal (CW_Prim_Op)
then
Prim_Op := CW_Prim_Op;
Is_CW_Prim := True;
elsif CW_Prim_Op = Root_Prim_Op then
Prim_Op := Root_Prim_Op;
-- The two subprograms are legal but the class-wide subprogram
-- is a class-wide wrapper built for a previous instantiation;
-- the wrapper has precedence.
elsif Present (Alias (CW_Prim_Op))
and then Is_Class_Wide_Wrapper (Ultimate_Alias (CW_Prim_Op))
then
Prim_Op := CW_Prim_Op;
Is_CW_Prim := True;
-- Otherwise both candidate subprograms are user-defined and
-- ambiguous.
else
Error_Msg_NE
("ambiguous actual for generic subprogram &",
Spec, Formal_Spec);
Interpretation_Error (Root_Prim_Op);
Interpretation_Error (CW_Prim_Op);
return;
end if;
elsif CW_Prim_OK and not Root_Prim_OK then
Prim_Op := CW_Prim_Op;
Is_CW_Prim := True;
elsif not CW_Prim_OK and Root_Prim_OK then
Prim_Op := Root_Prim_Op;
-- An intrinsic equality may act as a suitable candidate in the
-- case of a null type extension where the parent's equality
-- is hidden. A call to an intrinsic equality is expanded as
-- dispatching.
elsif Present (Root_Prim_Op)
and then Is_Intrinsic_Equality (Root_Prim_Op)
then
Prim_Op := Root_Prim_Op;
-- Otherwise there are no candidate subprograms. Let the caller
-- diagnose the error.
else
return;
end if;
-- At this point resolution has taken place and the name is no
-- longer overloaded. Mark the primitive as referenced.
Set_Is_Overloaded (Name (N), False);
Set_Referenced (Prim_Op);
end Find_Suitable_Candidate;
-- Local variables
Is_CW_Prim : Boolean;
-- Start of processing for Handle_Instance_With_Class_Wide_Type
begin
Wrapped_Prim := Empty;
Wrap_Id := Empty;
-- Ada 2012 (AI05-0071): A generic/instance scenario involving a
-- formal type with unknown discriminants and a generic primitive
-- operation of the said type with a box require special processing
-- when the actual is a class-wide type:
--
-- generic
-- type Formal_Typ (<>) is private;
-- with procedure Prim_Op (Param : Formal_Typ) is <>;
-- package Gen is ...
--
-- package Inst is new Gen (Actual_Typ'Class);
--
-- In this case the general renaming mechanism used in the prologue
-- of an instance no longer applies:
--
-- procedure Prim_Op (Param : Formal_Typ) renames Prim_Op;
--
-- The above is replaced the following wrapper/renaming combination:
--
-- procedure Wrapper (Param : Formal_Typ) is -- wrapper
-- begin
-- Prim_Op (Param); -- primitive
-- end Wrapper;
--
-- procedure Prim_Op (Param : Formal_Typ) renames Wrapper;
--
-- This transformation applies only if there is no explicit visible
-- class-wide operation at the point of the instantiation. Ren_Id is
-- the entity of the renaming declaration. When the transformation
-- applies, Wrapped_Prim is the entity of the wrapped primitive.
if Box_Present (Inst_Node) then
Find_Suitable_Candidate
(Prim_Op => Wrapped_Prim,
Is_CW_Prim => Is_CW_Prim);
if Present (Wrapped_Prim) then
if not Is_CW_Prim then
Build_Class_Wide_Wrapper (Ren_Id, Wrapped_Prim, Wrap_Id);
-- Small optimization: When the candidate is a class-wide
-- subprogram we don't build the wrapper; we modify the
-- renaming declaration to directly map the actual to the
-- generic formal and discard the candidate.
else
Rewrite (Nam, New_Occurrence_Of (Wrapped_Prim, Sloc (N)));
Wrapped_Prim := Empty;
end if;
end if;
-- Ada 2022 (AI12-0165, RM 12.6(8.5/3)): The actual subprogram for a
-- formal_abstract_subprogram_declaration shall be:
-- a) a dispatching operation of the controlling type; or
-- b) if the controlling type is a formal type, and the actual
-- type corresponding to that formal type is a specific type T,
-- a dispatching operation of type T; or
-- c) if the controlling type is a formal type, and the actual
-- type is a class-wide type T'Class, an implicitly declared
-- subprogram corresponding to a primitive operation of type T.
elsif Nkind (Inst_Node) = N_Formal_Abstract_Subprogram_Declaration
and then Is_Entity_Name (Nam)
then
Find_Suitable_Candidate
(Prim_Op => Wrapped_Prim,
Is_CW_Prim => Is_CW_Prim);
if Present (Wrapped_Prim) then
-- Cases (a) and (b); see previous description.
if not Is_CW_Prim then
Build_Class_Wide_Wrapper (Ren_Id, Wrapped_Prim, Wrap_Id);
-- Case (c); see previous description.
-- Implicit operations of T'Class for subtype declarations
-- are built by Derive_Subprogram, and their Alias attribute
-- references the primitive operation of T.
elsif not Comes_From_Source (Wrapped_Prim)
and then Nkind (Parent (Wrapped_Prim)) = N_Subtype_Declaration
and then Present (Alias (Wrapped_Prim))
then
-- We don't need to build the wrapper; we modify the
-- renaming declaration to directly map the actual to
-- the generic formal and discard the candidate.
Rewrite (Nam,
New_Occurrence_Of (Alias (Wrapped_Prim), Sloc (N)));
Wrapped_Prim := Empty;
-- Legality rules do not apply; discard the candidate.
else
Wrapped_Prim := Empty;
end if;
end if;
end if;
end Handle_Instance_With_Class_Wide_Type;
-------------------------
-- Original_Subprogram --
-------------------------
function Original_Subprogram (Subp : Entity_Id) return Entity_Id is
Orig_Decl : Node_Id;
Orig_Subp : Entity_Id;
begin
-- First case: renamed entity is itself a renaming
if Present (Alias (Subp)) then
return Alias (Subp);
elsif Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
and then Present (Corresponding_Body (Unit_Declaration_Node (Subp)))
then
-- Check if renamed entity is a renaming_as_body
Orig_Decl :=
Unit_Declaration_Node
(Corresponding_Body (Unit_Declaration_Node (Subp)));
if Nkind (Orig_Decl) = N_Subprogram_Renaming_Declaration then
Orig_Subp := Entity (Name (Orig_Decl));
if Orig_Subp = Rename_Spec then
-- Circularity detected
return Orig_Subp;
else
return (Original_Subprogram (Orig_Subp));
end if;
else
return Subp;
end if;
else
return Subp;
end if;
end Original_Subprogram;
-- Local variables
CW_Actual : constant Boolean := Has_Class_Wide_Actual;
-- Ada 2012 (AI05-071, AI05-0131) and Ada 2022 (AI12-0165): True if the
-- renaming is for a defaulted formal subprogram when the actual for a
-- related formal type is class-wide.
Inst_Node : Node_Id := Empty;
New_S : Entity_Id := Empty;
Wrapped_Prim : Entity_Id := Empty;
-- Start of processing for Analyze_Subprogram_Renaming
begin
-- We must test for the attribute renaming case before the Analyze
-- call because otherwise Sem_Attr will complain that the attribute
-- is missing an argument when it is analyzed.
if Nkind (Nam) = N_Attribute_Reference then
-- In the case of an abstract formal subprogram association, rewrite
-- an actual given by a stream or Put_Image attribute as the name of
-- the corresponding stream or Put_Image primitive of the type.
-- In a generic context the stream and Put_Image operations are not
-- generated, and this must be treated as a normal attribute
-- reference, to be expanded in subsequent instantiations.
if Is_Actual
and then Is_Abstract_Subprogram (Formal_Spec)
and then Expander_Active
then
declare
Prefix_Type : constant Entity_Id := Entity (Prefix (Nam));
Prim : Entity_Id;
begin
-- The class-wide forms of the stream and Put_Image attributes
-- are not primitive dispatching operations (even though they
-- internally dispatch).
if Is_Class_Wide_Type (Prefix_Type) then
Error_Msg_N
("attribute must be a primitive dispatching operation",
Nam);
return;
end if;
-- Retrieve the primitive subprogram associated with the
-- attribute. This can only be a stream attribute, since those
-- are the only ones that are dispatching (and the actual for
-- an abstract formal subprogram must be dispatching
-- operation).
case Attribute_Name (Nam) is
when Name_Input =>
Prim :=
Find_Optional_Prim_Op (Prefix_Type, TSS_Stream_Input);
when Name_Output =>
Prim :=
Find_Optional_Prim_Op (Prefix_Type, TSS_Stream_Output);
when Name_Read =>
Prim :=
Find_Optional_Prim_Op (Prefix_Type, TSS_Stream_Read);
when Name_Write =>
Prim :=
Find_Optional_Prim_Op (Prefix_Type, TSS_Stream_Write);
when Name_Put_Image =>
Prim :=
Find_Optional_Prim_Op (Prefix_Type, TSS_Put_Image);
when others =>
Error_Msg_N
("attribute must be a primitive dispatching operation",
Nam);
return;
end case;
-- If no stream operation was found, and the type is limited,
-- the user should have defined one. This rule does not apply
-- to Put_Image.
if No (Prim)
and then Attribute_Name (Nam) /= Name_Put_Image
then
if Is_Limited_Type (Prefix_Type) then
Error_Msg_NE
("stream operation not defined for type&",
N, Prefix_Type);
return;
-- Otherwise, compiler should have generated default
else
raise Program_Error;
end if;
end if;
-- Rewrite the attribute into the name of its corresponding
-- primitive dispatching subprogram. We can then proceed with
-- the usual processing for subprogram renamings.
declare
Prim_Name : constant Node_Id :=
Make_Identifier (Sloc (Nam),
Chars => Chars (Prim));
begin
Set_Entity (Prim_Name, Prim);
Rewrite (Nam, Prim_Name);
Analyze (Nam);
end;
end;
-- Normal processing for a renaming of an attribute
else
Attribute_Renaming (N);
return;
end if;
end if;
-- Check whether this declaration corresponds to the instantiation of a
-- formal subprogram.
-- If this is an instantiation, the corresponding actual is frozen and
-- error messages can be made more precise. If this is a default
-- subprogram, the entity is already established in the generic, and is
-- not retrieved by visibility. If it is a default with a box, the
-- candidate interpretations, if any, have been collected when building
-- the renaming declaration. If overloaded, the proper interpretation is
-- determined in Find_Renamed_Entity. If the entity is an operator,
-- Find_Renamed_Entity applies additional visibility checks.
if Is_Actual then
Inst_Node := Unit_Declaration_Node (Formal_Spec);
-- Ada 2012 (AI05-0071) and Ada 2022 (AI12-0165): when the actual
-- type is a class-wide type T'Class we may need to wrap a primitive
-- operation of T. Search for the wrapped primitive and (if required)
-- build a wrapper whose body consists of a dispatching call to the
-- wrapped primitive of T, with its formal parameters as the actual
-- parameters.
if CW_Actual and then
-- Ada 2012 (AI05-0071): Check whether the renaming is for a
-- defaulted actual subprogram with a class-wide actual.
(Box_Present (Inst_Node)
or else
-- Ada 2022 (AI12-0165): Check whether the renaming is for a formal
-- abstract subprogram declaration with a class-wide actual.
(Nkind (Inst_Node) = N_Formal_Abstract_Subprogram_Declaration
and then Is_Entity_Name (Nam)))
then
New_S := Analyze_Subprogram_Specification (Spec);
-- Do not attempt to build the wrapper if the renaming is in error
if not Error_Posted (Nam) then
Handle_Instance_With_Class_Wide_Type
(Inst_Node => Inst_Node,
Ren_Id => New_S,
Wrapped_Prim => Wrapped_Prim,
Wrap_Id => Old_S);
-- If several candidates were found, then we reported the
-- ambiguity; stop processing the renaming declaration to
-- avoid reporting further (spurious) errors.
if Error_Posted (Spec) then
return;
end if;
end if;
end if;
if Present (Wrapped_Prim) then
-- When the wrapper is built, the subprogram renaming aliases
-- the wrapper.
Analyze (Nam);
pragma Assert (Old_S = Entity (Nam)
and then Is_Class_Wide_Wrapper (Old_S));
-- The subprogram renaming declaration may become Ghost if it
-- renames a wrapper of a Ghost entity.
Mark_Ghost_Renaming (N, Wrapped_Prim);
elsif Is_Entity_Name (Nam)
and then Present (Entity (Nam))
and then not Comes_From_Source (Nam)
and then not Is_Overloaded (Nam)
then
Old_S := Entity (Nam);
-- The subprogram renaming declaration may become Ghost if it
-- renames a Ghost entity.
Mark_Ghost_Renaming (N, Old_S);
New_S := Analyze_Subprogram_Specification (Spec);
-- Operator case
if Ekind (Old_S) = E_Operator then
-- Box present
if Box_Present (Inst_Node) then
Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
-- If there is an immediately visible homonym of the operator
-- and the declaration has a default, this is worth a warning
-- because the user probably did not intend to get the pre-
-- defined operator, visible in the generic declaration. To
-- find if there is an intended candidate, analyze the renaming
-- again in the current context.
elsif Scope (Old_S) = Standard_Standard
and then Present (Default_Name (Inst_Node))
then
declare
Decl : constant Node_Id := New_Copy_Tree (N);
Hidden : Entity_Id;
begin
Set_Entity (Name (Decl), Empty);
Analyze (Name (Decl));
Hidden :=
Find_Renamed_Entity (Decl, Name (Decl), New_S, True);
if Present (Hidden)
and then In_Open_Scopes (Scope (Hidden))
and then Is_Immediately_Visible (Hidden)
and then Comes_From_Source (Hidden)
and then Hidden /= Old_S
then
Error_Msg_Sloc := Sloc (Hidden);
Error_Msg_N
("default subprogram is resolved in the generic "
& "declaration (RM 12.6(17))??", N);
Error_Msg_NE ("\and will not use & #??", N, Hidden);
end if;
end;
end if;
end if;
else
Analyze (Nam);
-- The subprogram renaming declaration may become Ghost if it
-- renames a Ghost entity.
if Is_Entity_Name (Nam) then
Mark_Ghost_Renaming (N, Entity (Nam));
end if;
New_S := Analyze_Subprogram_Specification (Spec);
end if;
else
-- Renamed entity must be analyzed first, to avoid being hidden by
-- new name (which might be the same in a generic instance).
Analyze (Nam);
-- The subprogram renaming declaration may become Ghost if it renames
-- a Ghost entity.
if Is_Entity_Name (Nam) then
Mark_Ghost_Renaming (N, Entity (Nam));
end if;
-- The renaming defines a new overloaded entity, which is analyzed
-- like a subprogram declaration.
New_S := Analyze_Subprogram_Specification (Spec);
end if;
if Current_Scope /= Standard_Standard then
Set_Is_Pure (New_S, Is_Pure (Current_Scope));
end if;
-- Set SPARK mode from current context
Set_SPARK_Pragma (New_S, SPARK_Mode_Pragma);
Set_SPARK_Pragma_Inherited (New_S);
Rename_Spec := Find_Corresponding_Spec (N);
-- Case of Renaming_As_Body
if Present (Rename_Spec) then
Check_Previous_Null_Procedure (N, Rename_Spec);
-- Renaming declaration is the completion of the declaration of
-- Rename_Spec. We build an actual body for it at the freezing point.
Set_Corresponding_Spec (N, Rename_Spec);
-- Deal with special case of stream functions of abstract types
-- and interfaces.
if Nkind (Unit_Declaration_Node (Rename_Spec)) =
N_Abstract_Subprogram_Declaration
then
-- Input stream functions are abstract if the object type is
-- abstract. Similarly, all default stream functions for an
-- interface type are abstract. However, these subprograms may
-- receive explicit declarations in representation clauses, making
-- the attribute subprograms usable as defaults in subsequent
-- type extensions.
-- In this case we rewrite the declaration to make the subprogram
-- non-abstract. We remove the previous declaration, and insert
-- the new one at the point of the renaming, to prevent premature
-- access to unfrozen types. The new declaration reuses the
-- specification of the previous one, and must not be analyzed.
pragma Assert
(Is_Primitive (Entity (Nam))
and then
Is_Abstract_Type (Find_Dispatching_Type (Entity (Nam))));
declare
Old_Decl : constant Node_Id :=
Unit_Declaration_Node (Rename_Spec);
New_Decl : constant Node_Id :=
Make_Subprogram_Declaration (Sloc (N),
Specification =>
Relocate_Node (Specification (Old_Decl)));
begin
Remove (Old_Decl);
Insert_After (N, New_Decl);
Set_Is_Abstract_Subprogram (Rename_Spec, False);
Set_Analyzed (New_Decl);
end;
end if;
Set_Corresponding_Body (Unit_Declaration_Node (Rename_Spec), New_S);
if Ada_Version = Ada_83 and then Comes_From_Source (N) then
Error_Msg_N ("(Ada 83) renaming cannot serve as a body", N);
end if;
Set_Convention (New_S, Convention (Rename_Spec));
Check_Fully_Conformant (New_S, Rename_Spec);
Set_Public_Status (New_S);
if No_Return (Rename_Spec)
and then not No_Return (Entity (Nam))
then
Error_Msg_NE
("renamed subprogram & must be No_Return", N, Entity (Nam));
Error_Msg_N
("\since renaming subprogram is No_Return (RM 6.5.1(7/2))", N);
end if;
-- The specification does not introduce new formals, but only
-- repeats the formals of the original subprogram declaration.
-- For cross-reference purposes, and for refactoring tools, we
-- treat the formals of the renaming declaration as body formals.
Reference_Body_Formals (Rename_Spec, New_S);
-- Indicate that the entity in the declaration functions like the
-- corresponding body, and is not a new entity. The body will be
-- constructed later at the freeze point, so indicate that the
-- completion has not been seen yet.
Reinit_Field_To_Zero (New_S, F_Has_Out_Or_In_Out_Parameter);
Reinit_Field_To_Zero (New_S, F_Needs_No_Actuals,
Old_Ekind => (E_Function | E_Procedure => True, others => False));
Mutate_Ekind (New_S, E_Subprogram_Body);
New_S := Rename_Spec;
Set_Has_Completion (Rename_Spec, False);
-- Ada 2005: check overriding indicator
if Present (Overridden_Operation (Rename_Spec)) then
if Must_Not_Override (Specification (N)) then
Error_Msg_NE
("subprogram& overrides inherited operation",
N, Rename_Spec);
elsif Style_Check
and then not Must_Override (Specification (N))
then
Style.Missing_Overriding (N, Rename_Spec);
end if;
elsif Must_Override (Specification (N))
and then not Can_Override_Operator (Rename_Spec)
then
Error_Msg_NE ("subprogram& is not overriding", N, Rename_Spec);
end if;
-- AI12-0132: a renames-as-body freezes the expression of any
-- expression function that it renames.
if Is_Entity_Name (Nam)
and then Is_Expression_Function (Entity (Nam))
and then not Inside_A_Generic
then
Freeze_Expr_Types
(Def_Id => Entity (Nam),
Typ => Etype (Entity (Nam)),
Expr =>
Expression
(Original_Node (Unit_Declaration_Node (Entity (Nam)))),
N => N);
end if;
-- Normal subprogram renaming (not renaming as body)
else
Generate_Definition (New_S);
New_Overloaded_Entity (New_S);
if not (Is_Entity_Name (Nam)
and then Is_Intrinsic_Subprogram (Entity (Nam)))
then
Check_Delayed_Subprogram (New_S);
end if;
-- Verify that a SPARK renaming does not declare a primitive
-- operation of a tagged type.
Check_SPARK_Primitive_Operation (New_S);
end if;
-- There is no need for elaboration checks on the new entity, which may
-- be called before the next freezing point where the body will appear.
-- Elaboration checks refer to the real entity, not the one created by
-- the renaming declaration.
Set_Kill_Elaboration_Checks (New_S, True);
-- If we had a previous error, indicate a completion is present to stop
-- junk cascaded messages, but don't take any further action.
if Etype (Nam) = Any_Type then
Set_Has_Completion (New_S);
return;
-- Case where name has the form of a selected component
elsif Nkind (Nam) = N_Selected_Component then
-- A name which has the form A.B can designate an entry of task A, a
-- protected operation of protected object A, or finally a primitive
-- operation of object A. In the later case, A is an object of some
-- tagged type, or an access type that denotes one such. To further
-- distinguish these cases, note that the scope of a task entry or
-- protected operation is type of the prefix.
-- The prefix could be an overloaded function call that returns both
-- kinds of operations. This overloading pathology is left to the
-- dedicated reader ???
declare
T : constant Entity_Id := Etype (Prefix (Nam));
begin
if Present (T)
and then
(Is_Tagged_Type (T)
or else
(Is_Access_Type (T)
and then Is_Tagged_Type (Designated_Type (T))))
and then Scope (Entity (Selector_Name (Nam))) /= T
then
Analyze_Renamed_Primitive_Operation
(N, New_S, Present (Rename_Spec));
return;
else
-- Renamed entity is an entry or protected operation. For those
-- cases an explicit body is built (at the point of freezing of
-- this entity) that contains a call to the renamed entity.
-- This is not allowed for renaming as body if the renamed
-- spec is already frozen (see RM 8.5.4(5) for details).
if Present (Rename_Spec) and then Is_Frozen (Rename_Spec) then
Error_Msg_N
("renaming-as-body cannot rename entry as subprogram", N);
Error_Msg_NE
("\since & is already frozen (RM 8.5.4(5))",
N, Rename_Spec);
else
Analyze_Renamed_Entry (N, New_S, Present (Rename_Spec));
end if;
return;
end if;
end;
-- Case where name is an explicit dereference X.all
elsif Nkind (Nam) = N_Explicit_Dereference then
-- Renamed entity is designated by access_to_subprogram expression.
-- Must build body to encapsulate call, as in the entry case.
Analyze_Renamed_Dereference (N, New_S, Present (Rename_Spec));
return;
-- Indexed component
elsif Nkind (Nam) = N_Indexed_Component then
Analyze_Renamed_Family_Member (N, New_S, Present (Rename_Spec));
return;
-- Character literal
elsif Nkind (Nam) = N_Character_Literal then
Analyze_Renamed_Character (N, New_S, Present (Rename_Spec));
return;
-- Only remaining case is where we have a non-entity name, or a renaming
-- of some other non-overloadable entity.
elsif not Is_Entity_Name (Nam)
or else not Is_Overloadable (Entity (Nam))
then
-- Do not mention the renaming if it comes from an instance
if not Is_Actual then
Error_Msg_N ("expect valid subprogram name in renaming", N);
else
Error_Msg_NE ("no visible subprogram for formal&", N, Nam);
end if;
return;
end if;
-- Find the renamed entity that matches the given specification. Disable
-- Ada_83 because there is no requirement of full conformance between
-- renamed entity and new entity, even though the same circuit is used.
-- This is a bit of an odd case, which introduces a really irregular use
-- of Ada_Version[_Explicit]. Would be nice to find cleaner way to do
-- this. ???
Ada_Version := Ada_Version_Type'Max (Ada_Version, Ada_95);
Ada_Version_Pragma := Empty;
Ada_Version_Explicit := Ada_Version;
if No (Old_S) then
Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
-- The visible operation may be an inherited abstract operation that
-- was overridden in the private part, in which case a call will
-- dispatch to the overriding operation. Use the overriding one in
-- the renaming declaration, to prevent spurious errors below.
if Is_Overloadable (Old_S)
and then Is_Abstract_Subprogram (Old_S)
and then No (DTC_Entity (Old_S))
and then Present (Alias (Old_S))
and then not Is_Abstract_Subprogram (Alias (Old_S))
and then Present (Overridden_Operation (Alias (Old_S)))
then
Old_S := Alias (Old_S);
end if;
-- When the renamed subprogram is overloaded and used as an actual
-- of a generic, its entity is set to the first available homonym.
-- We must first disambiguate the name, then set the proper entity.
if Is_Actual and then Is_Overloaded (Nam) then
Set_Entity (Nam, Old_S);
end if;
end if;
-- Most common case: subprogram renames subprogram. No body is generated
-- in this case, so we must indicate the declaration is complete as is.
-- and inherit various attributes of the renamed subprogram.
if No (Rename_Spec) then
Set_Has_Completion (New_S);
Set_Is_Imported (New_S, Is_Imported (Entity (Nam)));
Set_Is_Pure (New_S, Is_Pure (Entity (Nam)));
Set_Is_Preelaborated (New_S, Is_Preelaborated (Entity (Nam)));
-- Ada 2005 (AI-423): Check the consistency of null exclusions
-- between a subprogram and its correct renaming.
-- Note: the Any_Id check is a guard that prevents compiler crashes
-- when performing a null exclusion check between a renaming and a
-- renamed subprogram that has been found to be illegal.
if Ada_Version >= Ada_2005 and then Entity (Nam) /= Any_Id then
Check_Null_Exclusion
(Ren => New_S,
Sub => Entity (Nam));
end if;
-- Enforce the Ada 2005 rule that the renamed entity cannot require
-- overriding. The flag Requires_Overriding is set very selectively
-- and misses some other illegal cases. The additional conditions
-- checked below are sufficient but not necessary ???
-- The rule does not apply to the renaming generated for an actual
-- subprogram in an instance.
if Is_Actual then
null;
-- Guard against previous errors, and omit renamings of predefined
-- operators.
elsif Ekind (Old_S) not in E_Function | E_Procedure then
null;
elsif Requires_Overriding (Old_S)
or else
(Is_Abstract_Subprogram (Old_S)
and then Present (Find_Dispatching_Type (Old_S))
and then not Is_Abstract_Type (Find_Dispatching_Type (Old_S)))
then
Error_Msg_N
("renamed entity cannot be subprogram that requires overriding "
& "(RM 8.5.4 (5.1))", N);
end if;
declare
Prev : constant Entity_Id := Overridden_Operation (New_S);
begin
if Present (Prev)
and then
(Has_Non_Trivial_Precondition (Prev)
or else Has_Non_Trivial_Precondition (Old_S))
then
Error_Msg_NE
("conflicting inherited classwide preconditions in renaming "
& "of& (RM 6.1.1 (17)", N, Old_S);
end if;
end;
end if;
if Old_S /= Any_Id then
if Is_Actual and then From_Default (N) then
-- This is an implicit reference to the default actual
Generate_Reference (Old_S, Nam, Typ => 'i', Force => True);
else
Generate_Reference (Old_S, Nam);
end if;
Check_Internal_Protected_Use (N, Old_S);
-- For a renaming-as-body, require subtype conformance, but if the
-- declaration being completed has not been frozen, then inherit the
-- convention of the renamed subprogram prior to checking conformance
-- (unless the renaming has an explicit convention established; the
-- rule stated in the RM doesn't seem to address this ???).
if Present (Rename_Spec) then
Generate_Reference (Rename_Spec, Defining_Entity (Spec), 'b');
Style.Check_Identifier (Defining_Entity (Spec), Rename_Spec);
if not Is_Frozen (Rename_Spec) then
if not Has_Convention_Pragma (Rename_Spec) then
Set_Convention (New_S, Convention (Old_S));
end if;
if Ekind (Old_S) /= E_Operator then
Check_Mode_Conformant (New_S, Old_S, Spec);
end if;
if Original_Subprogram (Old_S) = Rename_Spec then
Error_Msg_N ("unfrozen subprogram cannot rename itself", N);
else
Check_Formal_Subprogram_Conformance (New_S, Old_S, Spec);
end if;
else
Check_Subtype_Conformant (New_S, Old_S, Spec);
end if;
Check_Frozen_Renaming (N, Rename_Spec);
-- Check explicitly that renamed entity is not intrinsic, because
-- in a generic the renamed body is not built. In this case,
-- the renaming_as_body is a completion.
if Inside_A_Generic then
if Is_Frozen (Rename_Spec)
and then Is_Intrinsic_Subprogram (Old_S)
then
Error_Msg_N
("subprogram in renaming_as_body cannot be intrinsic",
Name (N));
end if;
Set_Has_Completion (Rename_Spec);
end if;
elsif Ekind (Old_S) /= E_Operator then
-- If this a defaulted subprogram for a class-wide actual there is
-- no check for mode conformance, given that the signatures don't
-- match (the source mentions T but the actual mentions T'Class).
if CW_Actual then
null;
-- No need for a redundant error message if this is a nested
-- instance, unless the current instantiation (of a child unit)
-- is a compilation unit, which is not analyzed when the parent
-- generic is analyzed.
elsif not Is_Actual
or else No (Enclosing_Instance)
or else Is_Compilation_Unit (Current_Scope)
then
Check_Mode_Conformant (New_S, Old_S);
end if;
end if;
if No (Rename_Spec) then
-- The parameter profile of the new entity is that of the renamed
-- entity: the subtypes given in the specification are irrelevant.
Inherit_Renamed_Profile (New_S, Old_S);
-- A call to the subprogram is transformed into a call to the
-- renamed entity. This is transitive if the renamed entity is
-- itself a renaming.
if Present (Alias (Old_S)) then
Set_Alias (New_S, Alias (Old_S));
else
Set_Alias (New_S, Old_S);
end if;
-- Note that we do not set Is_Intrinsic_Subprogram if we have a
-- renaming as body, since the entity in this case is not an
-- intrinsic (it calls an intrinsic, but we have a real body for
-- this call, and it is in this body that the required intrinsic
-- processing will take place).
-- Also, if this is a renaming of inequality, the renamed operator
-- is intrinsic, but what matters is the corresponding equality
-- operator, which may be user-defined.
Set_Is_Intrinsic_Subprogram
(New_S,
Is_Intrinsic_Subprogram (Old_S)
and then
(Chars (Old_S) /= Name_Op_Ne
or else Ekind (Old_S) = E_Operator
or else Is_Intrinsic_Subprogram
(Corresponding_Equality (Old_S))));
if Ekind (Alias (New_S)) = E_Operator then
Set_Has_Delayed_Freeze (New_S, False);
end if;
-- If the renaming corresponds to an association for an abstract
-- formal subprogram, then various attributes must be set to
-- indicate that the renaming is an abstract dispatching operation
-- with a controlling type.
-- Skip this decoration when the renaming corresponds to an
-- association with class-wide wrapper (see above) because such
-- wrapper is neither abstract nor a dispatching operation (its
-- body has the dispatching call to the wrapped primitive).
if Is_Actual
and then Is_Abstract_Subprogram (Formal_Spec)
and then No (Wrapped_Prim)
then
-- Mark the renaming as abstract here, so Find_Dispatching_Type
-- see it as corresponding to a generic association for a
-- formal abstract subprogram
Set_Is_Abstract_Subprogram (New_S);
declare
New_S_Ctrl_Type : constant Entity_Id :=
Find_Dispatching_Type (New_S);
Old_S_Ctrl_Type : constant Entity_Id :=
Find_Dispatching_Type (Old_S);
begin
-- The actual must match the (instance of the) formal,
-- and must be a controlling type.
if Old_S_Ctrl_Type /= New_S_Ctrl_Type
or else No (New_S_Ctrl_Type)
then
if No (New_S_Ctrl_Type) then
Error_Msg_N
("actual must be dispatching subprogram", Nam);
else
Error_Msg_NE
("actual must be dispatching subprogram for type&",
Nam, New_S_Ctrl_Type);
end if;
else
Set_Is_Dispatching_Operation (New_S);
Check_Controlling_Formals (New_S_Ctrl_Type, New_S);
-- If the actual in the formal subprogram is itself a
-- formal abstract subprogram association, there's no
-- dispatch table component or position to inherit.
if Present (DTC_Entity (Old_S)) then
Set_DTC_Entity (New_S, DTC_Entity (Old_S));
Set_DT_Position_Value (New_S, DT_Position (Old_S));
end if;
end if;
end;
end if;
end if;
if Is_Actual then
null;
-- The following is illegal, because F hides whatever other F may
-- be around:
-- function F (...) renames F;
elsif Old_S = New_S
or else (Nkind (Nam) /= N_Expanded_Name
and then Chars (Old_S) = Chars (New_S))
then
Error_Msg_N ("subprogram cannot rename itself", N);
-- This is illegal even if we use a selector:
-- function F (...) renames Pkg.F;
-- because F is still hidden.
elsif Nkind (Nam) = N_Expanded_Name
and then Entity (Prefix (Nam)) = Current_Scope
and then Chars (Selector_Name (Nam)) = Chars (New_S)
then
-- This is an error, but we overlook the error and accept the
-- renaming if the special Overriding_Renamings mode is in effect.
if not Overriding_Renamings then
Error_Msg_NE
("implicit operation& is not visible (RM 8.3 (15))",
Nam, Old_S);
end if;
end if;
Set_Convention (New_S, Convention (Old_S));
if Is_Abstract_Subprogram (Old_S) then
if Present (Rename_Spec) then
Error_Msg_N
("a renaming-as-body cannot rename an abstract subprogram",
N);
Set_Has_Completion (Rename_Spec);
else
Set_Is_Abstract_Subprogram (New_S);
end if;
end if;
Check_Library_Unit_Renaming (N, Old_S);
-- Pathological case: procedure renames entry in the scope of its
-- task. Entry is given by simple name, but body must be built for
-- procedure. Of course if called it will deadlock.
if Ekind (Old_S) = E_Entry then
Set_Has_Completion (New_S, False);
Set_Alias (New_S, Empty);
end if;
-- Do not freeze the renaming nor the renamed entity when the context
-- is an enclosing generic. Freezing is an expansion activity, and in
-- addition the renamed entity may depend on the generic formals of
-- the enclosing generic.
if Is_Actual and not Inside_A_Generic then
Freeze_Before (N, Old_S);
Freeze_Actual_Profile;
Set_Has_Delayed_Freeze (New_S, False);
Freeze_Before (N, New_S);
if (Ekind (Old_S) = E_Procedure or else Ekind (Old_S) = E_Function)
and then not Is_Abstract_Subprogram (Formal_Spec)
then
-- An abstract subprogram is only allowed as an actual in the
-- case where the formal subprogram is also abstract.
if Is_Abstract_Subprogram (Old_S) then
Error_Msg_N
("abstract subprogram not allowed as generic actual", Nam);
end if;
-- AI12-0412: A primitive of an abstract type with Pre'Class
-- or Post'Class aspects specified with nonstatic expressions
-- is not allowed as actual for a nonabstract formal subprogram
-- (see RM 6.1.1(18.2/5).
if Is_Dispatching_Operation (Old_S)
and then
Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post (Old_S)
then
Error_Msg_N
("primitive of abstract type with nonstatic class-wide "
& "pre/postconditions not allowed as actual",
Nam);
end if;
end if;
end if;
else
-- A common error is to assume that implicit operators for types are
-- defined in Standard, or in the scope of a subtype. In those cases
-- where the renamed entity is given with an expanded name, it is
-- worth mentioning that operators for the type are not declared in
-- the scope given by the prefix.
if Nkind (Nam) = N_Expanded_Name
and then Nkind (Selector_Name (Nam)) = N_Operator_Symbol
and then Scope (Entity (Nam)) = Standard_Standard
then
declare
T : constant Entity_Id :=
Base_Type (Etype (First_Formal (New_S)));
begin
Error_Msg_Node_2 := Prefix (Nam);
Error_Msg_NE
("operator for type& is not declared in&", Prefix (Nam), T);
end;
else
Error_Msg_NE
("no visible subprogram matches the specification for&",
Spec, New_S);
end if;
if Present (Candidate_Renaming) then
declare
F1 : Entity_Id;
F2 : Entity_Id;
T1 : Entity_Id;
begin
F1 := First_Formal (Candidate_Renaming);
F2 := First_Formal (New_S);
T1 := First_Subtype (Etype (F1));
while Present (F1) and then Present (F2) loop
Next_Formal (F1);
Next_Formal (F2);
end loop;
if Present (F1) and then Present (Default_Value (F1)) then
if Present (Next_Formal (F1)) then
Error_Msg_NE
("\missing specification for & and other formals with "
& "defaults", Spec, F1);
else
Error_Msg_NE ("\missing specification for &", Spec, F1);
end if;
end if;
if Nkind (Nam) = N_Operator_Symbol
and then From_Default (N)
then
Error_Msg_Node_2 := T1;
Error_Msg_NE
("default & on & is not directly visible", Nam, Nam);
end if;
end;
end if;
end if;
-- Ada 2005 AI 404: if the new subprogram is dispatching, verify that
-- controlling access parameters are known non-null for the renamed
-- subprogram. Test also applies to a subprogram instantiation that
-- is dispatching. Test is skipped if some previous error was detected
-- that set Old_S to Any_Id.
if Ada_Version >= Ada_2005
and then Old_S /= Any_Id
and then not Is_Dispatching_Operation (Old_S)
and then Is_Dispatching_Operation (New_S)
then
declare
Old_F : Entity_Id;
New_F : Entity_Id;
begin
Old_F := First_Formal (Old_S);
New_F := First_Formal (New_S);
while Present (Old_F) loop
if Ekind (Etype (Old_F)) = E_Anonymous_Access_Type
and then Is_Controlling_Formal (New_F)
and then not Can_Never_Be_Null (Old_F)
then
Error_Msg_N ("access parameter is controlling,", New_F);
Error_Msg_NE
("\corresponding parameter of& must be explicitly null "
& "excluding", New_F, Old_S);
end if;
Next_Formal (Old_F);
Next_Formal (New_F);
end loop;
end;
end if;
-- A useful warning, suggested by Ada Bug Finder (Ada-Europe 2005)
-- is to warn if an operator is being renamed as a different operator.
-- If the operator is predefined, examine the kind of the entity, not
-- the abbreviated declaration in Standard.
if Comes_From_Source (N)
and then Present (Old_S)
and then (Nkind (Old_S) = N_Defining_Operator_Symbol
or else Ekind (Old_S) = E_Operator)
and then Nkind (New_S) = N_Defining_Operator_Symbol
and then Chars (Old_S) /= Chars (New_S)
then
Error_Msg_NE
("& is being renamed as a different operator??", N, Old_S);
end if;
-- Check for renaming of obsolescent subprogram
Check_Obsolescent_2005_Entity (Entity (Nam), Nam);
-- Another warning or some utility: if the new subprogram as the same
-- name as the old one, the old one is not hidden by an outer homograph,
-- the new one is not a public symbol, and the old one is otherwise
-- directly visible, the renaming is superfluous.
if Chars (Old_S) = Chars (New_S)
and then Comes_From_Source (N)
and then Scope (Old_S) /= Standard_Standard
and then Warn_On_Redundant_Constructs
and then (Is_Immediately_Visible (Old_S)
or else Is_Potentially_Use_Visible (Old_S))
and then Is_Overloadable (Current_Scope)
and then Chars (Current_Scope) /= Chars (Old_S)
then
Error_Msg_N
("redundant renaming, entity is directly visible?r?", Name (N));
end if;
-- Implementation-defined aspect specifications can appear in a renaming
-- declaration, but not language-defined ones. The call to procedure
-- Analyze_Aspect_Specifications will take care of this error check.
if Has_Aspects (N) then
Analyze_Aspect_Specifications (N, New_S);
end if;
-- AI12-0279
if Is_Actual
and then Has_Yield_Aspect (Formal_Spec)
and then not Has_Yield_Aspect (Old_S)
then
Error_Msg_Name_1 := Name_Yield;
Error_Msg_N
("actual subprogram& must have aspect% to match formal", Name (N));
end if;
Ada_Version := Save_AV;
Ada_Version_Pragma := Save_AVP;
Ada_Version_Explicit := Save_AV_Exp;
-- Check if we are looking at an Ada 2012 defaulted formal subprogram
-- and mark any use_package_clauses that affect the visibility of the
-- implicit generic actual.
-- Also, we may be looking at an internal renaming of a user-defined
-- subprogram created for a generic formal subprogram association,
-- which will also have to be marked here. This can occur when the
-- corresponding formal subprogram contains references to other generic
-- formals.
if Is_Generic_Actual_Subprogram (New_S)
and then (Is_Intrinsic_Subprogram (New_S)
or else From_Default (N)
or else Nkind (N) = N_Subprogram_Renaming_Declaration)
then
Mark_Use_Clauses (New_S);
-- Handle overloaded subprograms
if Present (Alias (New_S)) then
Mark_Use_Clauses (Alias (New_S));
end if;
end if;
end Analyze_Subprogram_Renaming;
-------------------------
-- Analyze_Use_Package --
-------------------------
-- Resolve the package names in the use clause, and make all the visible
-- entities defined in the package potentially use-visible. If the package
-- is already in use from a previous use clause, its visible entities are
-- already use-visible. In that case, mark the occurrence as a redundant
-- use. If the package is an open scope, i.e. if the use clause occurs
-- within the package itself, ignore it.
procedure Analyze_Use_Package (N : Node_Id; Chain : Boolean := True) is
procedure Analyze_Package_Name (Clause : Node_Id);
-- Perform analysis on a package name from a use_package_clause
procedure Analyze_Package_Name_List (Head_Clause : Node_Id);
-- Similar to Analyze_Package_Name but iterates over all the names
-- in a use clause.
--------------------------
-- Analyze_Package_Name --
--------------------------
procedure Analyze_Package_Name (Clause : Node_Id) is
Pack : constant Node_Id := Name (Clause);
Pref : Node_Id;
begin
pragma Assert (Nkind (Clause) = N_Use_Package_Clause);
Analyze (Pack);
-- Verify that the package standard is not directly named in a
-- use_package_clause.
if Nkind (Parent (Clause)) = N_Compilation_Unit
and then Nkind (Pack) = N_Expanded_Name
then
Pref := Prefix (Pack);
while Nkind (Pref) = N_Expanded_Name loop
Pref := Prefix (Pref);
end loop;
if Entity (Pref) = Standard_Standard then
Error_Msg_N
("predefined package Standard cannot appear in a context "
& "clause", Pref);
end if;
end if;
end Analyze_Package_Name;
-------------------------------
-- Analyze_Package_Name_List --
-------------------------------
procedure Analyze_Package_Name_List (Head_Clause : Node_Id) is
Curr : Node_Id;
begin
-- Due to the way source use clauses are split during parsing we are
-- forced to simply iterate through all entities in scope until the
-- clause representing the last name in the list is found.
Curr := Head_Clause;
while Present (Curr) loop
Analyze_Package_Name (Curr);
-- Stop iterating over the names in the use clause when we are at
-- the last one.
exit when not More_Ids (Curr) and then Prev_Ids (Curr);
Next (Curr);
end loop;
end Analyze_Package_Name_List;
-- Local variables
Pack : Entity_Id;
-- Start of processing for Analyze_Use_Package
begin
Set_Hidden_By_Use_Clause (N, No_Elist);
-- Use clause not allowed in a spec of a predefined package declaration
-- except that packages whose file name starts a-n are OK (these are
-- children of Ada.Numerics, which are never loaded by Rtsfind).
if Is_Predefined_Unit (Current_Sem_Unit)
and then Get_Name_String
(Unit_File_Name (Current_Sem_Unit)) (1 .. 3) /= "a-n"
and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
N_Package_Declaration
then
Error_Msg_N ("use clause not allowed in predefined spec", N);
end if;
-- Loop through all package names from the original use clause in
-- order to analyze referenced packages. A use_package_clause with only
-- one name does not have More_Ids or Prev_Ids set, while a clause with
-- More_Ids only starts the chain produced by the parser.
if not More_Ids (N) and then not Prev_Ids (N) then
Analyze_Package_Name (N);
elsif More_Ids (N) and then not Prev_Ids (N) then
Analyze_Package_Name_List (N);
end if;
if not Is_Entity_Name (Name (N)) then
Error_Msg_N ("& is not a package", Name (N));
return;
end if;
if Chain then
Chain_Use_Clause (N);
end if;
Pack := Entity (Name (N));
-- There are many cases where scopes are manipulated during analysis, so
-- check that Pack's current use clause has not already been chained
-- before setting its previous use clause.
if Ekind (Pack) = E_Package
and then Present (Current_Use_Clause (Pack))
and then Current_Use_Clause (Pack) /= N
and then No (Prev_Use_Clause (N))
and then Prev_Use_Clause (Current_Use_Clause (Pack)) /= N
then
Set_Prev_Use_Clause (N, Current_Use_Clause (Pack));
end if;
-- Mark all entities as potentially use visible
if Ekind (Pack) /= E_Package and then Etype (Pack) /= Any_Type then
if Ekind (Pack) = E_Generic_Package then
Error_Msg_N -- CODEFIX
("a generic package is not allowed in a use clause", Name (N));
elsif Is_Generic_Subprogram (Pack) then
Error_Msg_N -- CODEFIX
("a generic subprogram is not allowed in a use clause",
Name (N));
elsif Is_Subprogram (Pack) then
Error_Msg_N -- CODEFIX
("a subprogram is not allowed in a use clause", Name (N));
else
Error_Msg_N ("& is not allowed in a use clause", Name (N));
end if;
else
if Nkind (Parent (N)) = N_Compilation_Unit then
Check_In_Previous_With_Clause (N, Name (N));
end if;
Use_One_Package (N, Name (N));
end if;
Mark_Ghost_Clause (N);
end Analyze_Use_Package;
----------------------
-- Analyze_Use_Type --
----------------------
procedure Analyze_Use_Type (N : Node_Id; Chain : Boolean := True) is
E : Entity_Id;
Id : Node_Id;
begin
Set_Hidden_By_Use_Clause (N, No_Elist);
-- Chain clause to list of use clauses in current scope when flagged
if Chain then
Chain_Use_Clause (N);
end if;
-- Obtain the base type of the type denoted within the use_type_clause's
-- subtype mark.
Id := Subtype_Mark (N);
Find_Type (Id);
E := Base_Type (Entity (Id));
-- There are many cases where a use_type_clause may be reanalyzed due to
-- manipulation of the scope stack so we much guard against those cases
-- here, otherwise, we must add the new use_type_clause to the previous
-- use_type_clause chain in order to mark redundant use_type_clauses as
-- used. When the redundant use-type clauses appear in a parent unit and
-- a child unit we must prevent a circularity in the chain that would
-- otherwise result from the separate steps of analysis and installation
-- of the parent context.
if Present (Current_Use_Clause (E))
and then Current_Use_Clause (E) /= N
and then Prev_Use_Clause (Current_Use_Clause (E)) /= N
and then No (Prev_Use_Clause (N))
then
Set_Prev_Use_Clause (N, Current_Use_Clause (E));
end if;
-- If the Used_Operations list is already initialized, the clause has
-- been analyzed previously, and it is being reinstalled, for example
-- when the clause appears in a package spec and we are compiling the
-- corresponding package body. In that case, make the entities on the
-- existing list use_visible, and mark the corresponding types In_Use.
if Present (Used_Operations (N)) then
declare
Elmt : Elmt_Id;
begin
Use_One_Type (Subtype_Mark (N), Installed => True);
Elmt := First_Elmt (Used_Operations (N));
while Present (Elmt) loop
Set_Is_Potentially_Use_Visible (Node (Elmt));
Next_Elmt (Elmt);
end loop;
end;
return;
end if;
-- Otherwise, create new list and attach to it the operations that are
-- made use-visible by the clause.
Set_Used_Operations (N, New_Elmt_List);
E := Entity (Id);
if E /= Any_Type then
Use_One_Type (Id);
if Nkind (Parent (N)) = N_Compilation_Unit then
if Nkind (Id) = N_Identifier then
Error_Msg_N ("type is not directly visible", Id);
elsif Is_Child_Unit (Scope (E))
and then Scope (E) /= System_Aux_Id
then
Check_In_Previous_With_Clause (N, Prefix (Id));
end if;
end if;
else
-- If the use_type_clause appears in a compilation unit context,
-- check whether it comes from a unit that may appear in a
-- limited_with_clause, for a better error message.
if Nkind (Parent (N)) = N_Compilation_Unit
and then Nkind (Id) /= N_Identifier
then
declare
Item : Node_Id;
Pref : Node_Id;
function Mentioned (Nam : Node_Id) return Boolean;
-- Check whether the prefix of expanded name for the type
-- appears in the prefix of some limited_with_clause.
---------------
-- Mentioned --
---------------
function Mentioned (Nam : Node_Id) return Boolean is
begin
return Nkind (Name (Item)) = N_Selected_Component
and then Chars (Prefix (Name (Item))) = Chars (Nam);
end Mentioned;
begin
Pref := Prefix (Id);
Item := First (Context_Items (Parent (N)));
while Present (Item) and then Item /= N loop
if Nkind (Item) = N_With_Clause
and then Limited_Present (Item)
and then Mentioned (Pref)
then
Change_Error_Text
(Get_Msg_Id, "premature usage of incomplete type");
end if;
Next (Item);
end loop;
end;
end if;
end if;
Mark_Ghost_Clause (N);
end Analyze_Use_Type;
------------------------
-- Attribute_Renaming --
------------------------
procedure Attribute_Renaming (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Nam : constant Node_Id := Name (N);
Spec : constant Node_Id := Specification (N);
New_S : constant Entity_Id := Defining_Unit_Name (Spec);
Aname : constant Name_Id := Attribute_Name (Nam);
Form_Num : Nat := 0;
Expr_List : List_Id := No_List;
Attr_Node : Node_Id;
Body_Node : Node_Id;
Param_Spec : Node_Id;
begin
Generate_Definition (New_S);
-- This procedure is called in the context of subprogram renaming, and
-- thus the attribute must be one that is a subprogram. All of those
-- have at least one formal parameter, with the exceptions of the GNAT
-- attribute 'Img, which GNAT treats as renameable.
if not Is_Non_Empty_List (Parameter_Specifications (Spec)) then
if Aname /= Name_Img then
Error_Msg_N
("subprogram renaming an attribute must have formals", N);
return;
end if;
else
Param_Spec := First (Parameter_Specifications (Spec));
while Present (Param_Spec) loop
Form_Num := Form_Num + 1;
if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
Find_Type (Parameter_Type (Param_Spec));
-- The profile of the new entity denotes the base type (s) of
-- the types given in the specification. For access parameters
-- there are no subtypes involved.
Rewrite (Parameter_Type (Param_Spec),
New_Occurrence_Of
(Base_Type (Entity (Parameter_Type (Param_Spec))), Loc));
end if;
if No (Expr_List) then
Expr_List := New_List;
end if;
Append_To (Expr_List,
Make_Identifier (Loc,
Chars => Chars (Defining_Identifier (Param_Spec))));
-- The expressions in the attribute reference are not freeze
-- points. Neither is the attribute as a whole, see below.
Set_Must_Not_Freeze (Last (Expr_List));
Next (Param_Spec);
end loop;
end if;
-- Immediate error if too many formals. Other mismatches in number or
-- types of parameters are detected when we analyze the body of the
-- subprogram that we construct.
if Form_Num > 2 then
Error_Msg_N ("too many formals for attribute", N);
-- Error if the attribute reference has expressions that look like
-- formal parameters.
elsif Present (Expressions (Nam)) then
Error_Msg_N ("illegal expressions in attribute reference", Nam);
elsif Aname in Name_Compose | Name_Exponent | Name_Leading_Part |
Name_Pos | Name_Round | Name_Scaling |
Name_Val
then
if Nkind (N) = N_Subprogram_Renaming_Declaration
and then Present (Corresponding_Formal_Spec (N))
then
Error_Msg_N
("generic actual cannot be attribute involving universal type",
Nam);
else
Error_Msg_N
("attribute involving a universal type cannot be renamed",
Nam);
end if;
end if;
-- Rewrite attribute node to have a list of expressions corresponding to
-- the subprogram formals. A renaming declaration is not a freeze point,
-- and the analysis of the attribute reference should not freeze the
-- type of the prefix. We use the original node in the renaming so that
-- its source location is preserved, and checks on stream attributes are
-- properly applied.
Attr_Node := Relocate_Node (Nam);
Set_Expressions (Attr_Node, Expr_List);
Set_Must_Not_Freeze (Attr_Node);
Set_Must_Not_Freeze (Prefix (Nam));
-- Case of renaming a function
if Nkind (Spec) = N_Function_Specification then
if Is_Procedure_Attribute_Name (Aname) then
Error_Msg_N ("attribute can only be renamed as procedure", Nam);
return;
end if;
Find_Type (Result_Definition (Spec));
Rewrite (Result_Definition (Spec),
New_Occurrence_Of
(Base_Type (Entity (Result_Definition (Spec))), Loc));
Body_Node :=
Make_Subprogram_Body (Loc,
Specification => Spec,
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Simple_Return_Statement (Loc,
Expression => Attr_Node))));
-- Case of renaming a procedure
else
if not Is_Procedure_Attribute_Name (Aname) then
Error_Msg_N ("attribute can only be renamed as function", Nam);
return;
end if;
Body_Node :=
Make_Subprogram_Body (Loc,
Specification => Spec,
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Attr_Node)));
end if;
-- Signal the ABE mechanism that the generated subprogram body has not
-- ABE ramifications.
Set_Was_Attribute_Reference (Body_Node);
-- In case of tagged types we add the body of the generated function to
-- the freezing actions of the type (because in the general case such
-- type is still not frozen). We exclude from this processing generic
-- formal subprograms found in instantiations.
-- We must exclude restricted run-time libraries because
-- entity AST_Handler is defined in package System.Aux_Dec which is not
-- available in those platforms. Note that we cannot use the function
-- Restricted_Profile (instead of Configurable_Run_Time_Mode) because
-- the ZFP run-time library is not defined as a profile, and we do not
-- want to deal with AST_Handler in ZFP mode.
if not Configurable_Run_Time_Mode
and then not Present (Corresponding_Formal_Spec (N))
and then not Is_RTE (Etype (Nam), RE_AST_Handler)
then
declare
P : constant Node_Id := Prefix (Nam);
begin
-- The prefix of 'Img is an object that is evaluated for each call
-- of the function that renames it.
if Aname = Name_Img then
Preanalyze_And_Resolve (P);
-- For all other attribute renamings, the prefix is a subtype
else
Find_Type (P);
end if;
-- If the target type is not yet frozen, add the body to the
-- actions to be elaborated at freeze time.
if Is_Tagged_Type (Etype (P))
and then In_Open_Scopes (Scope (Etype (P)))
then
Append_Freeze_Action (Etype (P), Body_Node);
else
Rewrite (N, Body_Node);
Analyze (N);
Set_Etype (New_S, Base_Type (Etype (New_S)));
end if;
end;
-- Generic formal subprograms or AST_Handler renaming
else
Rewrite (N, Body_Node);
Analyze (N);
Set_Etype (New_S, Base_Type (Etype (New_S)));
end if;
if Is_Compilation_Unit (New_S) then
Error_Msg_N
("a library unit can only rename another library unit", N);
end if;
-- We suppress elaboration warnings for the resulting entity, since
-- clearly they are not needed, and more particularly, in the case
-- of a generic formal subprogram, the resulting entity can appear
-- after the instantiation itself, and thus look like a bogus case
-- of access before elaboration.
if Legacy_Elaboration_Checks then
Set_Suppress_Elaboration_Warnings (New_S);
end if;
end Attribute_Renaming;
----------------------
-- Chain_Use_Clause --
----------------------
procedure Chain_Use_Clause (N : Node_Id) is
Level : Int := Scope_Stack.Last;
Pack : Entity_Id;
begin
-- Common case
if not Is_Compilation_Unit (Current_Scope)
or else not Is_Child_Unit (Current_Scope)
then
null;
-- Common case for compilation unit
elsif Defining_Entity (Parent (N)) = Current_Scope then
null;
else
-- If declaration appears in some other scope, it must be in some
-- parent unit when compiling a child.
Pack := Defining_Entity (Parent (N));
if not In_Open_Scopes (Pack) then
null;
-- If the use clause appears in an ancestor and we are in the
-- private part of the immediate parent, the use clauses are
-- already installed.
elsif Pack /= Scope (Current_Scope)
and then In_Private_Part (Scope (Current_Scope))
then
null;
else
-- Find entry for parent unit in scope stack
while Scope_Stack.Table (Level).Entity /= Pack loop
Level := Level - 1;
end loop;
end if;
end if;
Set_Next_Use_Clause (N,
Scope_Stack.Table (Level).First_Use_Clause);
Scope_Stack.Table (Level).First_Use_Clause := N;
end Chain_Use_Clause;
---------------------------
-- Check_Frozen_Renaming --
---------------------------
procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id) is
B_Node : Node_Id;
Old_S : Entity_Id;
begin
if Is_Frozen (Subp) and then not Has_Completion (Subp) then
B_Node :=
Build_Renamed_Body
(Parent (Declaration_Node (Subp)), Defining_Entity (N));
if Is_Entity_Name (Name (N)) then
Old_S := Entity (Name (N));
if not Is_Frozen (Old_S)
and then Operating_Mode /= Check_Semantics
then
Append_Freeze_Action (Old_S, B_Node);
else
Insert_After (N, B_Node);
Analyze (B_Node);
end if;
if Is_Intrinsic_Subprogram (Old_S)
and then not In_Instance
and then not Relaxed_RM_Semantics
then
Error_Msg_N
("subprogram used in renaming_as_body cannot be intrinsic",
Name (N));
end if;
else
Insert_After (N, B_Node);
Analyze (B_Node);
end if;
end if;
end Check_Frozen_Renaming;
-------------------------------
-- Set_Entity_Or_Discriminal --
-------------------------------
procedure Set_Entity_Or_Discriminal (N : Node_Id; E : Entity_Id) is
P : Node_Id;
begin
-- If the entity is not a discriminant, or else expansion is disabled,
-- simply set the entity.
if not In_Spec_Expression
or else Ekind (E) /= E_Discriminant
or else Inside_A_Generic
then
Set_Entity_With_Checks (N, E);
-- The replacement of a discriminant by the corresponding discriminal
-- is not done for a task discriminant that appears in a default
-- expression of an entry parameter. See Exp_Ch2.Expand_Discriminant
-- for details on their handling.
elsif Is_Concurrent_Type (Scope (E)) then
P := Parent (N);
while Present (P)
and then Nkind (P) not in
N_Parameter_Specification | N_Component_Declaration
loop
P := Parent (P);
end loop;
if Present (P)
and then Nkind (P) = N_Parameter_Specification
then
null;
else
Set_Entity (N, Discriminal (E));
end if;
-- Otherwise, this is a discriminant in a context in which
-- it is a reference to the corresponding parameter of the
-- init proc for the enclosing type.
else
Set_Entity (N, Discriminal (E));
end if;
end Set_Entity_Or_Discriminal;
-----------------------------------
-- Check_In_Previous_With_Clause --
-----------------------------------
procedure Check_In_Previous_With_Clause (N, Nam : Node_Id) is
Pack : constant Entity_Id := Entity (Original_Node (Nam));
Item : Node_Id;
Par : Node_Id;
begin
Item := First (Context_Items (Parent (N)));
while Present (Item) and then Item /= N loop
if Nkind (Item) = N_With_Clause
-- Protect the frontend against previous critical errors
and then Nkind (Name (Item)) /= N_Selected_Component
and then Entity (Name (Item)) = Pack
then
Par := Nam;
-- Find root library unit in with_clause
while Nkind (Par) = N_Expanded_Name loop
Par := Prefix (Par);
end loop;
if Is_Child_Unit (Entity (Original_Node (Par))) then
Error_Msg_NE ("& is not directly visible", Par, Entity (Par));
else
return;
end if;
end if;
Next (Item);
end loop;
-- On exit, package is not mentioned in a previous with_clause.
-- Check if its prefix is.
if Nkind (Nam) = N_Expanded_Name then
Check_In_Previous_With_Clause (N, Prefix (Nam));
elsif Pack /= Any_Id then
Error_Msg_NE ("& is not visible", Nam, Pack);
end if;
end Check_In_Previous_With_Clause;
---------------------------------
-- Check_Library_Unit_Renaming --
---------------------------------
procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id) is
New_E : Entity_Id;
begin
if Nkind (Parent (N)) /= N_Compilation_Unit then
return;
-- Check for library unit. Note that we used to check for the scope
-- being Standard here, but that was wrong for Standard itself.
elsif not Is_Compilation_Unit (Old_E)
and then not Is_Child_Unit (Old_E)
then
Error_Msg_N ("renamed unit must be a library unit", Name (N));
-- Entities defined in Standard (operators and boolean literals) cannot
-- be renamed as library units.
elsif Scope (Old_E) = Standard_Standard
and then Sloc (Old_E) = Standard_Location
then
Error_Msg_N ("renamed unit must be a library unit", Name (N));
elsif Present (Parent_Spec (N))
and then Nkind (Unit (Parent_Spec (N))) = N_Generic_Package_Declaration
and then not Is_Child_Unit (Old_E)
then
Error_Msg_N
("renamed unit must be a child unit of generic parent", Name (N));
elsif Nkind (N) in N_Generic_Renaming_Declaration
and then Nkind (Name (N)) = N_Expanded_Name
and then Is_Generic_Instance (Entity (Prefix (Name (N))))
and then Is_Generic_Unit (Old_E)
then
Error_Msg_N
("renamed generic unit must be a library unit", Name (N));
elsif Is_Package_Or_Generic_Package (Old_E) then
-- Inherit categorization flags
New_E := Defining_Entity (N);
Set_Is_Pure (New_E, Is_Pure (Old_E));
Set_Is_Preelaborated (New_E, Is_Preelaborated (Old_E));
Set_Is_Remote_Call_Interface (New_E,
Is_Remote_Call_Interface (Old_E));
Set_Is_Remote_Types (New_E, Is_Remote_Types (Old_E));
Set_Is_Shared_Passive (New_E, Is_Shared_Passive (Old_E));
end if;
end Check_Library_Unit_Renaming;
------------------------
-- Enclosing_Instance --
------------------------
function Enclosing_Instance return Entity_Id is
S : Entity_Id;
begin
if not Is_Generic_Instance (Current_Scope) then
return Empty;
end if;
S := Scope (Current_Scope);
while S /= Standard_Standard loop
if Is_Generic_Instance (S) then
return S;
end if;
S := Scope (S);
end loop;
return Empty;
end Enclosing_Instance;
---------------
-- End_Scope --
---------------
procedure End_Scope is
Id : Entity_Id;
Prev : Entity_Id;
Outer : Entity_Id;
begin
Id := First_Entity (Current_Scope);
while Present (Id) loop
-- An entity in the current scope is not necessarily the first one
-- on its homonym chain. Find its predecessor if any,
-- If it is an internal entity, it will not be in the visibility
-- chain altogether, and there is nothing to unchain.
if Id /= Current_Entity (Id) then
Prev := Current_Entity (Id);
while Present (Prev)
and then Present (Homonym (Prev))
and then Homonym (Prev) /= Id
loop
Prev := Homonym (Prev);
end loop;
-- Skip to end of loop if Id is not in the visibility chain
if No (Prev) or else Homonym (Prev) /= Id then
goto Next_Ent;
end if;
else
Prev := Empty;
end if;
Set_Is_Immediately_Visible (Id, False);
Outer := Homonym (Id);
while Present (Outer) and then Scope (Outer) = Current_Scope loop
Outer := Homonym (Outer);
end loop;
-- Reset homonym link of other entities, but do not modify link
-- between entities in current scope, so that the back-end can have
-- a proper count of local overloadings.
if No (Prev) then
Set_Name_Entity_Id (Chars (Id), Outer);
elsif Scope (Prev) /= Scope (Id) then
Set_Homonym (Prev, Outer);
end if;
<<Next_Ent>>
Next_Entity (Id);
end loop;
-- If the scope generated freeze actions, place them before the
-- current declaration and analyze them. Type declarations and
-- the bodies of initialization procedures can generate such nodes.
-- We follow the parent chain until we reach a list node, which is
-- the enclosing list of declarations. If the list appears within
-- a protected definition, move freeze nodes outside the protected
-- type altogether.
if Present
(Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions)
then
declare
Decl : Node_Id;
L : constant List_Id := Scope_Stack.Table
(Scope_Stack.Last).Pending_Freeze_Actions;
begin
if Is_Itype (Current_Scope) then
Decl := Associated_Node_For_Itype (Current_Scope);
else
Decl := Parent (Current_Scope);
end if;
Pop_Scope;
while not Is_List_Member (Decl)
or else Nkind (Parent (Decl)) in N_Protected_Definition
| N_Task_Definition
loop
Decl := Parent (Decl);
end loop;
Insert_List_Before_And_Analyze (Decl, L);
end;
else
Pop_Scope;
end if;
end End_Scope;
---------------------
-- End_Use_Clauses --
---------------------
procedure End_Use_Clauses (Clause : Node_Id) is
U : Node_Id;
begin
-- Remove use_type_clauses first, because they affect the visibility of
-- operators in subsequent used packages.
U := Clause;
while Present (U) loop
if Nkind (U) = N_Use_Type_Clause then
End_Use_Type (U);
end if;
Next_Use_Clause (U);
end loop;
U := Clause;
while Present (U) loop
if Nkind (U) = N_Use_Package_Clause then
End_Use_Package (U);
end if;
Next_Use_Clause (U);
end loop;
end End_Use_Clauses;
---------------------
-- End_Use_Package --
---------------------
procedure End_Use_Package (N : Node_Id) is
Pack : Entity_Id;
Pack_Name : Node_Id;
Id : Entity_Id;
Elmt : Elmt_Id;
function Is_Primitive_Operator_In_Use
(Op : Entity_Id;
F : Entity_Id) return Boolean;
-- Check whether Op is a primitive operator of a use-visible type
----------------------------------
-- Is_Primitive_Operator_In_Use --
----------------------------------
function Is_Primitive_Operator_In_Use
(Op : Entity_Id;
F : Entity_Id) return Boolean
is
T : constant Entity_Id := Base_Type (Etype (F));
begin
return In_Use (T) and then Scope (T) = Scope (Op);
end Is_Primitive_Operator_In_Use;
-- Start of processing for End_Use_Package
begin
Pack_Name := Name (N);
-- Test that Pack_Name actually denotes a package before processing
if Is_Entity_Name (Pack_Name)
and then Ekind (Entity (Pack_Name)) = E_Package
then
Pack := Entity (Pack_Name);
if In_Open_Scopes (Pack) then
null;
elsif not Redundant_Use (Pack_Name) then
Set_In_Use (Pack, False);
Set_Current_Use_Clause (Pack, Empty);
Id := First_Entity (Pack);
while Present (Id) loop
-- Preserve use-visibility of operators that are primitive
-- operators of a type that is use-visible through an active
-- use_type_clause.
if Nkind (Id) = N_Defining_Operator_Symbol
and then
(Is_Primitive_Operator_In_Use (Id, First_Formal (Id))
or else
(Present (Next_Formal (First_Formal (Id)))
and then
Is_Primitive_Operator_In_Use
(Id, Next_Formal (First_Formal (Id)))))
then
null;
else
Set_Is_Potentially_Use_Visible (Id, False);
end if;
if Is_Private_Type (Id)
and then Present (Full_View (Id))
then
Set_Is_Potentially_Use_Visible (Full_View (Id), False);
end if;
Next_Entity (Id);
end loop;
if Present (Renamed_Entity (Pack)) then
Set_In_Use (Renamed_Entity (Pack), False);
Set_Current_Use_Clause (Renamed_Entity (Pack), Empty);
end if;
if Chars (Pack) = Name_System
and then Scope (Pack) = Standard_Standard
and then Present_System_Aux
then
Id := First_Entity (System_Aux_Id);
while Present (Id) loop
Set_Is_Potentially_Use_Visible (Id, False);
if Is_Private_Type (Id)
and then Present (Full_View (Id))
then
Set_Is_Potentially_Use_Visible (Full_View (Id), False);
end if;
Next_Entity (Id);
end loop;
Set_In_Use (System_Aux_Id, False);
end if;
else
Set_Redundant_Use (Pack_Name, False);
end if;
end if;
if Present (Hidden_By_Use_Clause (N)) then
Elmt := First_Elmt (Hidden_By_Use_Clause (N));
while Present (Elmt) loop
declare
E : constant Entity_Id := Node (Elmt);
begin
-- Reset either Use_Visibility or Direct_Visibility, depending
-- on how the entity was hidden by the use clause.
if In_Use (Scope (E))
and then Used_As_Generic_Actual (Scope (E))
then
Set_Is_Potentially_Use_Visible (Node (Elmt));
else
Set_Is_Immediately_Visible (Node (Elmt));
end if;
Next_Elmt (Elmt);
end;
end loop;
Set_Hidden_By_Use_Clause (N, No_Elist);
end if;
end End_Use_Package;
------------------
-- End_Use_Type --
------------------
procedure End_Use_Type (N : Node_Id) is
Elmt : Elmt_Id;
Id : Entity_Id;
T : Entity_Id;
-- Start of processing for End_Use_Type
begin
Id := Subtype_Mark (N);
-- A call to Rtsfind may occur while analyzing a use_type_clause, in
-- which case the type marks are not resolved yet, so guard against that
-- here.
if Is_Entity_Name (Id) and then Present (Entity (Id)) then
T := Entity (Id);
if T = Any_Type or else From_Limited_With (T) then
null;
-- Note that the use_type_clause may mention a subtype of the type
-- whose primitive operations have been made visible. Here as
-- elsewhere, it is the base type that matters for visibility.
elsif In_Open_Scopes (Scope (Base_Type (T))) then
null;
elsif not Redundant_Use (Id) then
Set_In_Use (T, False);
Set_In_Use (Base_Type (T), False);
Set_Current_Use_Clause (T, Empty);
Set_Current_Use_Clause (Base_Type (T), Empty);
-- See Use_One_Type for the rationale. This is a bit on the naive
-- side, but should be good enough in practice.
if Is_Tagged_Type (T) then
Set_In_Use (Class_Wide_Type (T), False);
end if;
end if;
end if;
if Is_Empty_Elmt_List (Used_Operations (N)) then
return;
else
Elmt := First_Elmt (Used_Operations (N));
while Present (Elmt) loop
Set_Is_Potentially_Use_Visible (Node (Elmt), False);
Next_Elmt (Elmt);
end loop;
end if;
end End_Use_Type;
--------------------
-- Entity_Of_Unit --
--------------------
function Entity_Of_Unit (U : Node_Id) return Entity_Id is
begin
if Nkind (U) = N_Package_Instantiation and then Analyzed (U) then
return Defining_Entity (Instance_Spec (U));
else
return Defining_Entity (U);
end if;
end Entity_Of_Unit;
----------------------
-- Find_Direct_Name --
----------------------
procedure Find_Direct_Name (N : Node_Id) is
E : Entity_Id;
E2 : Entity_Id;
Msg : Boolean;
Homonyms : Entity_Id;
-- Saves start of homonym chain
Inst : Entity_Id := Empty;
-- Enclosing instance, if any
Nvis_Entity : Boolean;
-- Set True to indicate that there is at least one entity on the homonym
-- chain which, while not visible, is visible enough from the user point
-- of view to warrant an error message of "not visible" rather than
-- undefined.
Nvis_Is_Private_Subprg : Boolean := False;
-- Ada 2005 (AI-262): Set True to indicate that a form of Beaujolais
-- effect concerning library subprograms has been detected. Used to
-- generate the precise error message.
function From_Actual_Package (E : Entity_Id) return Boolean;
-- Returns true if the entity is an actual for a package that is itself
-- an actual for a formal package of the current instance. Such an
-- entity requires special handling because it may be use-visible but
-- hides directly visible entities defined outside the instance, because
-- the corresponding formal did so in the generic.
function Is_Actual_Parameter return Boolean;
-- This function checks if the node N is an identifier that is an actual
-- parameter of a procedure call. If so it returns True, otherwise it
-- return False. The reason for this check is that at this stage we do
-- not know what procedure is being called if the procedure might be
-- overloaded, so it is premature to go setting referenced flags or
-- making calls to Generate_Reference. We will wait till Resolve_Actuals
-- for that processing.
-- Note: there is a similar routine Sem_Util.Is_Actual_Parameter, but
-- it works for both function and procedure calls, while here we are
-- only concerned with procedure calls (and with entry calls as well,
-- but they are parsed as procedure calls and only later rewritten to
-- entry calls).
function Known_But_Invisible (E : Entity_Id) return Boolean;
-- This function determines whether a reference to the entity E, which
-- is not visible, can reasonably be considered to be known to the
-- writer of the reference. This is a heuristic test, used only for
-- the purposes of figuring out whether we prefer to complain that an
-- entity is undefined or invisible (and identify the declaration of
-- the invisible entity in the latter case). The point here is that we
-- don't want to complain that something is invisible and then point to
-- something entirely mysterious to the writer.
procedure Nvis_Messages;
-- Called if there are no visible entries for N, but there is at least
-- one non-directly visible, or hidden declaration. This procedure
-- outputs an appropriate set of error messages.
procedure Undefined (Nvis : Boolean);
-- This function is called if the current node has no corresponding
-- visible entity or entities. The value set in Msg indicates whether
-- an error message was generated (multiple error messages for the
-- same variable are generally suppressed, see body for details).
-- Msg is True if an error message was generated, False if not. This
-- value is used by the caller to determine whether or not to output
-- additional messages where appropriate. The parameter is set False
-- to get the message "X is undefined", and True to get the message
-- "X is not visible".
-------------------------
-- From_Actual_Package --
-------------------------
function From_Actual_Package (E : Entity_Id) return Boolean is
Scop : constant Entity_Id := Scope (E);
-- Declared scope of candidate entity
function Declared_In_Actual (Pack : Entity_Id) return Boolean;
-- Recursive function that does the work and examines actuals of
-- actual packages of current instance.
------------------------
-- Declared_In_Actual --
------------------------
function Declared_In_Actual (Pack : Entity_Id) return Boolean is
pragma Assert (Ekind (Pack) = E_Package);
Act : Entity_Id;
begin
if No (Associated_Formal_Package (Pack)) then
return False;
else
Act := First_Entity (Pack);
while Present (Act) loop
if Renamed_Entity (Pack) = Scop then
return True;
-- Check for end of list of actuals
elsif Ekind (Act) = E_Package
and then Renamed_Entity (Act) = Pack
then
return False;
elsif Ekind (Act) = E_Package
and then Declared_In_Actual (Act)
then
return True;
end if;
Next_Entity (Act);
end loop;
return False;
end if;
end Declared_In_Actual;
-- Local variables
Act : Entity_Id;
-- Start of processing for From_Actual_Package
begin
if not In_Instance then
return False;
else
Inst := Current_Scope;
while Present (Inst)
and then Ekind (Inst) /= E_Package
and then not Is_Generic_Instance (Inst)
loop
Inst := Scope (Inst);
end loop;
if No (Inst) then
return False;
end if;
Act := First_Entity (Inst);
while Present (Act) loop
if Ekind (Act) = E_Package
and then Declared_In_Actual (Act)
then
return True;
end if;
Next_Entity (Act);
end loop;
return False;
end if;
end From_Actual_Package;
-------------------------
-- Is_Actual_Parameter --
-------------------------
function Is_Actual_Parameter return Boolean is
begin
if Nkind (N) = N_Identifier then
case Nkind (Parent (N)) is
when N_Procedure_Call_Statement =>
return Is_List_Member (N)
and then List_Containing (N) =
Parameter_Associations (Parent (N));
when N_Parameter_Association =>
return N = Explicit_Actual_Parameter (Parent (N))
and then Nkind (Parent (Parent (N))) =
N_Procedure_Call_Statement;
when others =>
return False;
end case;
else
return False;
end if;
end Is_Actual_Parameter;
-------------------------
-- Known_But_Invisible --
-------------------------
function Known_But_Invisible (E : Entity_Id) return Boolean is
Fname : File_Name_Type;
begin
-- Entities in Standard are always considered to be known
if Sloc (E) <= Standard_Location then
return True;
-- An entity that does not come from source is always considered
-- to be unknown, since it is an artifact of code expansion.
elsif not Comes_From_Source (E) then
return False;
end if;
-- Here we have an entity that is not from package Standard, and
-- which comes from Source. See if it comes from an internal file.
Fname := Unit_File_Name (Get_Source_Unit (E));
-- Case of from internal file
if In_Internal_Unit (E) then
-- Private part entities in internal files are never considered
-- to be known to the writer of normal application code.
if Is_Hidden (E) then
return False;
end if;
-- Entities from System packages other than System and
-- System.Storage_Elements are not considered to be known.
-- System.Auxxxx files are also considered known to the user.
-- Should refine this at some point to generally distinguish
-- between known and unknown internal files ???
Get_Name_String (Fname);
return
Name_Len < 2
or else
Name_Buffer (1 .. 2) /= "s-"
or else
Name_Buffer (3 .. 8) = "stoele"
or else
Name_Buffer (3 .. 5) = "aux";
-- If not an internal file, then entity is definitely known, even if
-- it is in a private part (the message generated will note that it
-- is in a private part).
else
return True;
end if;
end Known_But_Invisible;
-------------------
-- Nvis_Messages --
-------------------
procedure Nvis_Messages is
Comp_Unit : Node_Id;
Ent : Entity_Id;
Found : Boolean := False;
Hidden : Boolean := False;
Item : Node_Id;
begin
-- Ada 2005 (AI-262): Generate a precise error concerning the
-- Beaujolais effect that was previously detected
if Nvis_Is_Private_Subprg then
pragma Assert (Nkind (E2) = N_Defining_Identifier
and then Ekind (E2) = E_Function
and then Scope (E2) = Standard_Standard
and then Has_Private_With (E2));
-- Find the sloc corresponding to the private with'ed unit
Comp_Unit := Cunit (Current_Sem_Unit);
Error_Msg_Sloc := No_Location;
Item := First (Context_Items (Comp_Unit));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then Private_Present (Item)
and then Entity (Name (Item)) = E2
then
Error_Msg_Sloc := Sloc (Item);
exit;
end if;
Next (Item);
end loop;
pragma Assert (Error_Msg_Sloc /= No_Location);
Error_Msg_N ("(Ada 2005): hidden by private with clause #", N);
return;
end if;
Undefined (Nvis => True);
if Msg then
-- First loop does hidden declarations
Ent := Homonyms;
while Present (Ent) loop
if Is_Potentially_Use_Visible (Ent) then
if not Hidden then
Error_Msg_N -- CODEFIX
("multiple use clauses cause hiding!", N);
Hidden := True;
end if;
Error_Msg_Sloc := Sloc (Ent);
Error_Msg_N -- CODEFIX
("hidden declaration#!", N);
end if;
Ent := Homonym (Ent);
end loop;
-- If we found hidden declarations, then that's enough, don't
-- bother looking for non-visible declarations as well.
if Hidden then
return;
end if;
-- Second loop does non-directly visible declarations
Ent := Homonyms;
while Present (Ent) loop
if not Is_Potentially_Use_Visible (Ent) then
-- Do not bother the user with unknown entities
if not Known_But_Invisible (Ent) then
goto Continue;
end if;
Error_Msg_Sloc := Sloc (Ent);
-- Output message noting that there is a non-visible
-- declaration, distinguishing the private part case.
if Is_Hidden (Ent) then
Error_Msg_N ("non-visible (private) declaration#!", N);
-- If the entity is declared in a generic package, it
-- cannot be visible, so there is no point in adding it
-- to the list of candidates if another homograph from a
-- non-generic package has been seen.
elsif Ekind (Scope (Ent)) = E_Generic_Package
and then Found
then
null;
else
-- When the entity comes from a generic instance the
-- normal error message machinery will give the line
-- number of the generic package and the location of
-- the generic instance, but not the name of the
-- the instance.
-- So, in order to give more descriptive error messages
-- in this case, we include the name of the generic
-- package.
if Is_Generic_Instance (Scope (Ent)) then
Error_Msg_Name_1 := Chars (Scope (Ent));
Error_Msg_N -- CODEFIX
("non-visible declaration from %#!", N);
-- Otherwise print the message normally
else
Error_Msg_N -- CODEFIX
("non-visible declaration#!", N);
end if;
if Ekind (Scope (Ent)) /= E_Generic_Package then
Found := True;
end if;
if Is_Compilation_Unit (Ent)
and then
Nkind (Parent (Parent (N))) = N_Use_Package_Clause
then
Error_Msg_Qual_Level := 99;
Error_Msg_NE -- CODEFIX
("\\missing `WITH &;`", N, Ent);
Error_Msg_Qual_Level := 0;
end if;
if Ekind (Ent) = E_Discriminant
and then Present (Corresponding_Discriminant (Ent))
and then Scope (Corresponding_Discriminant (Ent)) =
Etype (Scope (Ent))
then
Error_Msg_N
("inherited discriminant not allowed here" &
" (RM 3.8 (12), 3.8.1 (6))!", N);
end if;
end if;
-- Set entity and its containing package as referenced. We
-- can't be sure of this, but this seems a better choice
-- to avoid unused entity messages.
if Comes_From_Source (Ent) then
Set_Referenced (Ent);
Set_Referenced (Cunit_Entity (Get_Source_Unit (Ent)));
end if;
end if;
<<Continue>>
Ent := Homonym (Ent);
end loop;
end if;
end Nvis_Messages;
---------------
-- Undefined --
---------------
procedure Undefined (Nvis : Boolean) is
Emsg : Error_Msg_Id;
begin
-- We should never find an undefined internal name. If we do, then
-- see if we have previous errors. If so, ignore on the grounds that
-- it is probably a cascaded message (e.g. a block label from a badly
-- formed block). If no previous errors, then we have a real internal
-- error of some kind so raise an exception.
if Is_Internal_Name (Chars (N)) then
if Total_Errors_Detected /= 0 then
return;
else
raise Program_Error;
end if;
end if;
-- A very specialized error check, if the undefined variable is
-- a case tag, and the case type is an enumeration type, check
-- for a possible misspelling, and if so, modify the identifier
-- Named aggregate should also be handled similarly ???
if Nkind (N) = N_Identifier
and then Nkind (Parent (N)) = N_Case_Statement_Alternative
then
declare
Case_Stm : constant Node_Id := Parent (Parent (N));
Case_Typ : constant Entity_Id := Etype (Expression (Case_Stm));
Lit : Node_Id;
begin
if Is_Enumeration_Type (Case_Typ)
and then not Is_Standard_Character_Type (Case_Typ)
then
Lit := First_Literal (Case_Typ);
Get_Name_String (Chars (Lit));
if Chars (Lit) /= Chars (N)
and then Is_Bad_Spelling_Of (Chars (N), Chars (Lit))
then
Error_Msg_Node_2 := Lit;
Error_Msg_N -- CODEFIX
("& is undefined, assume misspelling of &", N);
Rewrite (N, New_Occurrence_Of (Lit, Sloc (N)));
return;
end if;
Next_Literal (Lit);
end if;
end;
end if;
-- Normal processing
Set_Entity (N, Any_Id);
Set_Etype (N, Any_Type);
-- We use the table Urefs to keep track of entities for which we
-- have issued errors for undefined references. Multiple errors
-- for a single name are normally suppressed, however we modify
-- the error message to alert the programmer to this effect.
for J in Urefs.First .. Urefs.Last loop
if Chars (N) = Chars (Urefs.Table (J).Node) then
if Urefs.Table (J).Err /= No_Error_Msg
and then Sloc (N) /= Urefs.Table (J).Loc
then
Error_Msg_Node_1 := Urefs.Table (J).Node;
if Urefs.Table (J).Nvis then
Change_Error_Text (Urefs.Table (J).Err,
"& is not visible (more references follow)");
else
Change_Error_Text (Urefs.Table (J).Err,
"& is undefined (more references follow)");
end if;
Urefs.Table (J).Err := No_Error_Msg;
end if;
-- Although we will set Msg False, and thus suppress the
-- message, we also set Error_Posted True, to avoid any
-- cascaded messages resulting from the undefined reference.
Msg := False;
Set_Error_Posted (N);
return;
end if;
end loop;
-- If entry not found, this is first undefined occurrence
if Nvis then
Error_Msg_N ("& is not visible!", N);
Emsg := Get_Msg_Id;
else
Error_Msg_N ("& is undefined!", N);
Emsg := Get_Msg_Id;
-- A very bizarre special check, if the undefined identifier
-- is Put or Put_Line, then add a special error message (since
-- this is a very common error for beginners to make).
if Chars (N) in Name_Put | Name_Put_Line then
Error_Msg_N -- CODEFIX
("\\possible missing `WITH Ada.Text_'I'O; " &
"USE Ada.Text_'I'O`!", N);
-- Another special check if N is the prefix of a selected
-- component which is a known unit: add message complaining
-- about missing with for this unit.
elsif Nkind (Parent (N)) = N_Selected_Component
and then N = Prefix (Parent (N))
and then Is_Known_Unit (Parent (N))
then
declare
P : Node_Id := Parent (N);
begin
Error_Msg_Name_1 := Chars (N);
Error_Msg_Name_2 := Chars (Selector_Name (P));
if Nkind (Parent (P)) = N_Selected_Component
and then Is_Known_Unit (Parent (P))
then
P := Parent (P);
Error_Msg_Name_3 := Chars (Selector_Name (P));
Error_Msg_N -- CODEFIX
("\\missing `WITH %.%.%;`", N);
else
Error_Msg_N -- CODEFIX
("\\missing `WITH %.%;`", N);
end if;
end;
end if;
-- Now check for possible misspellings
declare
E : Entity_Id;
Ematch : Entity_Id := Empty;
begin
for Nam in First_Name_Id .. Last_Name_Id loop
E := Get_Name_Entity_Id (Nam);
if Present (E)
and then (Is_Immediately_Visible (E)
or else
Is_Potentially_Use_Visible (E))
then
if Is_Bad_Spelling_Of (Chars (N), Nam) then
Ematch := E;
exit;
end if;
end if;
end loop;
if Present (Ematch) then
Error_Msg_NE -- CODEFIX
("\possible misspelling of&", N, Ematch);
end if;
end;
end if;
-- Make entry in undefined references table unless the full errors
-- switch is set, in which case by refraining from generating the
-- table entry we guarantee that we get an error message for every
-- undefined reference. The entry is not added if we are ignoring
-- errors.
if not All_Errors_Mode
and then Ignore_Errors_Enable = 0
and then not Get_Ignore_Errors
then
Urefs.Append (
(Node => N,
Err => Emsg,
Nvis => Nvis,
Loc => Sloc (N)));
end if;
Msg := True;
end Undefined;
-- Local variables
Nested_Inst : Entity_Id := Empty;
-- The entity of a nested instance which appears within Inst (if any)
-- Start of processing for Find_Direct_Name
begin
-- If the entity pointer is already set, this is an internal node, or
-- a node that is analyzed more than once, after a tree modification.
-- In such a case there is no resolution to perform, just set the type.
if Present (Entity (N)) then
if Is_Type (Entity (N)) then
Set_Etype (N, Entity (N));
-- The exception to this general rule are constants associated with
-- discriminals of protected types because for each protected op
-- a new set of discriminals is internally created by the frontend
-- (see Exp_Ch9.Set_Discriminals), and the current decoration of the
-- entity pointer may have been set as part of a preanalysis, where
-- discriminals still reference the first subprogram or entry to be
-- expanded (see Expand_Protected_Body_Declarations).
elsif Full_Analysis
and then Ekind (Entity (N)) = E_Constant
and then Present (Discriminal_Link (Entity (N)))
and then Is_Protected_Type (Scope (Discriminal_Link (Entity (N))))
then
goto Find_Name;
else
declare
Entyp : constant Entity_Id := Etype (Entity (N));
begin
-- One special case here. If the Etype field is already set,
-- and references the packed array type corresponding to the
-- etype of the referenced entity, then leave it alone. This
-- happens for trees generated from Exp_Pakd, where expressions
-- can be deliberately "mis-typed" to the packed array type.
if Is_Packed_Array (Entyp)
and then Present (Etype (N))
and then Etype (N) = Packed_Array_Impl_Type (Entyp)
then
null;
-- If not that special case, then just reset the Etype
else
Set_Etype (N, Etype (Entity (N)));
end if;
end;
end if;
-- Although the marking of use clauses happens at the end of
-- Find_Direct_Name, a certain case where a generic actual satisfies
-- a use clause must be checked here due to how the generic machinery
-- handles the analysis of said actuals.
if In_Instance
and then Nkind (Parent (N)) = N_Generic_Association
then
Mark_Use_Clauses (Entity (N));
end if;
return;
end if;
<<Find_Name>>
-- Preserve relevant elaboration-related attributes of the context which
-- are no longer available or very expensive to recompute once analysis,
-- resolution, and expansion are over.
if Nkind (N) = N_Identifier then
Mark_Elaboration_Attributes
(N_Id => N,
Checks => True,
Modes => True,
Warnings => True);
end if;
-- Here if Entity pointer was not set, we need full visibility analysis
-- First we generate debugging output if the debug E flag is set.
if Debug_Flag_E then
Write_Str ("Looking for ");
Write_Name (Chars (N));
Write_Eol;
end if;
Homonyms := Current_Entity (N);
Nvis_Entity := False;
E := Homonyms;
while Present (E) loop
-- If entity is immediately visible or potentially use visible, then
-- process the entity and we are done.
if Is_Immediately_Visible (E) then
goto Immediately_Visible_Entity;
elsif Is_Potentially_Use_Visible (E) then
goto Potentially_Use_Visible_Entity;
-- Note if a known but invisible entity encountered
elsif Known_But_Invisible (E) then
Nvis_Entity := True;
end if;
-- Move to next entity in chain and continue search
E := Homonym (E);
end loop;
-- If no entries on homonym chain that were potentially visible,
-- and no entities reasonably considered as non-visible, then
-- we have a plain undefined reference, with no additional
-- explanation required.
if not Nvis_Entity then
Undefined (Nvis => False);
-- Otherwise there is at least one entry on the homonym chain that
-- is reasonably considered as being known and non-visible.
else
Nvis_Messages;
end if;
goto Done;
-- Processing for a potentially use visible entry found. We must search
-- the rest of the homonym chain for two reasons. First, if there is a
-- directly visible entry, then none of the potentially use-visible
-- entities are directly visible (RM 8.4(10)). Second, we need to check
-- for the case of multiple potentially use-visible entries hiding one
-- another and as a result being non-directly visible (RM 8.4(11)).
<<Potentially_Use_Visible_Entity>> declare
Only_One_Visible : Boolean := True;
All_Overloadable : Boolean := Is_Overloadable (E);
begin
E2 := Homonym (E);
while Present (E2) loop
if Is_Immediately_Visible (E2) then
-- If the use-visible entity comes from the actual for a
-- formal package, it hides a directly visible entity from
-- outside the instance.
if From_Actual_Package (E)
and then Scope_Depth (Scope (E2)) < Scope_Depth (Inst)
then
goto Found;
else
E := E2;
goto Immediately_Visible_Entity;
end if;
elsif Is_Potentially_Use_Visible (E2) then
Only_One_Visible := False;
All_Overloadable := All_Overloadable and Is_Overloadable (E2);
-- Ada 2005 (AI-262): Protect against a form of Beaujolais effect
-- that can occur in private_with clauses. Example:
-- with A;
-- private with B; package A is
-- package C is function B return Integer;
-- use A; end A;
-- V1 : Integer := B;
-- private function B return Integer;
-- V2 : Integer := B;
-- end C;
-- V1 resolves to A.B, but V2 resolves to library unit B
elsif Ekind (E2) = E_Function
and then Scope (E2) = Standard_Standard
and then Has_Private_With (E2)
then
Only_One_Visible := False;
All_Overloadable := False;
Nvis_Is_Private_Subprg := True;
exit;
end if;
E2 := Homonym (E2);
end loop;
-- On falling through this loop, we have checked that there are no
-- immediately visible entities. Only_One_Visible is set if exactly
-- one potentially use visible entity exists. All_Overloadable is
-- set if all the potentially use visible entities are overloadable.
-- The condition for legality is that either there is one potentially
-- use visible entity, or if there is more than one, then all of them
-- are overloadable.
if Only_One_Visible or All_Overloadable then
goto Found;
-- If there is more than one potentially use-visible entity and at
-- least one of them non-overloadable, we have an error (RM 8.4(11)).
-- Note that E points to the first such entity on the homonym list.
else
-- If one of the entities is declared in an actual package, it
-- was visible in the generic, and takes precedence over other
-- entities that are potentially use-visible. The same applies
-- if the entity is declared in a local instantiation of the
-- current instance.
if In_Instance then
-- Find the current instance
Inst := Current_Scope;
while Present (Inst) and then Inst /= Standard_Standard loop
if Is_Generic_Instance (Inst) then
exit;
end if;
Inst := Scope (Inst);
end loop;
-- Reexamine the candidate entities, giving priority to those
-- that were visible within the generic.
E2 := E;
while Present (E2) loop
Nested_Inst := Nearest_Enclosing_Instance (E2);
-- The entity is declared within an actual package, or in a
-- nested instance. The ">=" accounts for the case where the
-- current instance and the nested instance are the same.
if From_Actual_Package (E2)
or else (Present (Nested_Inst)
and then Scope_Depth (Nested_Inst) >=
Scope_Depth (Inst))
then
E := E2;
goto Found;
end if;
E2 := Homonym (E2);
end loop;
Nvis_Messages;
goto Done;
elsif Is_Predefined_Unit (Current_Sem_Unit) then
-- A use clause in the body of a system file creates conflict
-- with some entity in a user scope, while rtsfind is active.
-- Keep only the entity coming from another predefined unit.
E2 := E;
while Present (E2) loop
if In_Predefined_Unit (E2) then
E := E2;
goto Found;
end if;
E2 := Homonym (E2);
end loop;
-- Entity must exist because predefined unit is correct
raise Program_Error;
else
Nvis_Messages;
goto Done;
end if;
end if;
end;
-- Come here with E set to the first immediately visible entity on
-- the homonym chain. This is the one we want unless there is another
-- immediately visible entity further on in the chain for an inner
-- scope (RM 8.3(8)).
<<Immediately_Visible_Entity>> declare
Level : Int;
Scop : Entity_Id;
begin
-- Find scope level of initial entity. When compiling through
-- Rtsfind, the previous context is not completely invisible, and
-- an outer entity may appear on the chain, whose scope is below
-- the entry for Standard that delimits the current scope stack.
-- Indicate that the level for this spurious entry is outside of
-- the current scope stack.
Level := Scope_Stack.Last;
loop
Scop := Scope_Stack.Table (Level).Entity;
exit when Scop = Scope (E);
Level := Level - 1;
exit when Scop = Standard_Standard;
end loop;
-- Now search remainder of homonym chain for more inner entry
-- If the entity is Standard itself, it has no scope, and we
-- compare it with the stack entry directly.
E2 := Homonym (E);
while Present (E2) loop
if Is_Immediately_Visible (E2) then
-- If a generic package contains a local declaration that
-- has the same name as the generic, there may be a visibility
-- conflict in an instance, where the local declaration must
-- also hide the name of the corresponding package renaming.
-- We check explicitly for a package declared by a renaming,
-- whose renamed entity is an instance that is on the scope
-- stack, and that contains a homonym in the same scope. Once
-- we have found it, we know that the package renaming is not
-- immediately visible, and that the identifier denotes the
-- other entity (and its homonyms if overloaded).
if Scope (E) = Scope (E2)
and then Ekind (E) = E_Package
and then Present (Renamed_Entity (E))
and then Is_Generic_Instance (Renamed_Entity (E))
and then In_Open_Scopes (Renamed_Entity (E))
and then Comes_From_Source (N)
then
Set_Is_Immediately_Visible (E, False);
E := E2;
else
for J in Level + 1 .. Scope_Stack.Last loop
if Scope_Stack.Table (J).Entity = Scope (E2)
or else Scope_Stack.Table (J).Entity = E2
then
Level := J;
E := E2;
exit;
end if;
end loop;
end if;
end if;
E2 := Homonym (E2);
end loop;
-- At the end of that loop, E is the innermost immediately
-- visible entity, so we are all set.
end;
-- Come here with entity found, and stored in E
<<Found>> begin
-- Check violation of No_Wide_Characters restriction
Check_Wide_Character_Restriction (E, N);
-- When distribution features are available (Get_PCS_Name /=
-- Name_No_DSA), a remote access-to-subprogram type is converted
-- into a record type holding whatever information is needed to
-- perform a remote call on an RCI subprogram. In that case we
-- rewrite any occurrence of the RAS type into the equivalent record
-- type here. 'Access attribute references and RAS dereferences are
-- then implemented using specific TSSs. However when distribution is
-- not available (case of Get_PCS_Name = Name_No_DSA), we bypass the
-- generation of these TSSs, and we must keep the RAS type in its
-- original access-to-subprogram form (since all calls through a
-- value of such type will be local anyway in the absence of a PCS).
if Comes_From_Source (N)
and then Is_Remote_Access_To_Subprogram_Type (E)
and then Ekind (E) = E_Access_Subprogram_Type
and then Expander_Active
and then Get_PCS_Name /= Name_No_DSA
then
Rewrite (N, New_Occurrence_Of (Equivalent_Type (E), Sloc (N)));
goto Done;
end if;
-- Set the entity. Note that the reason we call Set_Entity for the
-- overloadable case, as opposed to Set_Entity_With_Checks is
-- that in the overloaded case, the initial call can set the wrong
-- homonym. The call that sets the right homonym is in Sem_Res and
-- that call does use Set_Entity_With_Checks, so we don't miss
-- a style check.
if Is_Overloadable (E) then
Set_Entity (N, E);
else
Set_Entity_With_Checks (N, E);
end if;
if Is_Type (E) then
Set_Etype (N, E);
else
Set_Etype (N, Get_Full_View (Etype (E)));
end if;
if Debug_Flag_E then
Write_Str (" found ");
Write_Entity_Info (E, " ");
end if;
-- If the Ekind of the entity is Void, it means that all homonyms
-- are hidden from all visibility (RM 8.3(5,14-20)). However, this
-- test is skipped if the current scope is a record and the name is
-- a pragma argument expression (case of Atomic and Volatile pragmas
-- and possibly other similar pragmas added later, which are allowed
-- to reference components in the current record).
if Ekind (E) = E_Void
and then
(not Is_Record_Type (Current_Scope)
or else Nkind (Parent (N)) /= N_Pragma_Argument_Association)
then
Premature_Usage (N);
-- If the entity is overloadable, collect all interpretations of the
-- name for subsequent overload resolution. We optimize a bit here to
-- do this only if we have an overloadable entity that is not on its
-- own on the homonym chain.
elsif Is_Overloadable (E)
and then (Present (Homonym (E)) or else Current_Entity (N) /= E)
then
Collect_Interps (N);
-- If no homonyms were visible, the entity is unambiguous
if not Is_Overloaded (N) then
if not Is_Actual_Parameter then
Generate_Reference (E, N);
end if;
end if;
-- Case of non-overloadable entity, set the entity providing that
-- we do not have the case of a discriminant reference within a
-- default expression. Such references are replaced with the
-- corresponding discriminal, which is the formal corresponding to
-- to the discriminant in the initialization procedure.
else
-- Entity is unambiguous, indicate that it is referenced here
-- For a renaming of an object, always generate simple reference,
-- we don't try to keep track of assignments in this case, except
-- in SPARK mode where renamings are traversed for generating
-- local effects of subprograms.
if Is_Object (E)
and then Present (Renamed_Object (E))
and then not GNATprove_Mode
then
Generate_Reference (E, N);
-- If the renamed entity is a private protected component,
-- reference the original component as well. This needs to be
-- done because the private renamings are installed before any
-- analysis has occurred. Reference to a private component will
-- resolve to the renaming and the original component will be
-- left unreferenced, hence the following.
if Is_Prival (E) then
Generate_Reference (Prival_Link (E), N);
end if;
-- One odd case is that we do not want to set the Referenced flag
-- if the entity is a label, and the identifier is the label in
-- the source, since this is not a reference from the point of
-- view of the user.
elsif Nkind (Parent (N)) = N_Label then
declare
R : constant Boolean := Referenced (E);
begin
-- Generate reference unless this is an actual parameter
-- (see comment below).
if not Is_Actual_Parameter then
Generate_Reference (E, N);
Set_Referenced (E, R);
end if;
end;
-- Normal case, not a label: generate reference
else
if not Is_Actual_Parameter then
-- Package or generic package is always a simple reference
if Is_Package_Or_Generic_Package (E) then
Generate_Reference (E, N, 'r');
-- Else see if we have a left hand side
else
case Known_To_Be_Assigned (N, Only_LHS => True) is
when True =>
Generate_Reference (E, N, 'm');
when False =>
Generate_Reference (E, N, 'r');
end case;
end if;
end if;
end if;
Set_Entity_Or_Discriminal (N, E);
-- The name may designate a generalized reference, in which case
-- the dereference interpretation will be included. Context is
-- one in which a name is legal.
if Ada_Version >= Ada_2012
and then
(Nkind (Parent (N)) in N_Subexpr
or else Nkind (Parent (N)) in N_Assignment_Statement
| N_Object_Declaration
| N_Parameter_Association)
then
Check_Implicit_Dereference (N, Etype (E));
end if;
end if;
end;
-- Mark relevant use-type and use-package clauses as effective if the
-- node in question is not overloaded and therefore does not require
-- resolution.
--
-- Note: Generic actual subprograms do not follow the normal resolution
-- path, so ignore the fact that they are overloaded and mark them
-- anyway.
if Nkind (N) not in N_Subexpr or else not Is_Overloaded (N) then
Mark_Use_Clauses (N);
end if;
-- Come here with entity set
<<Done>>
Check_Restriction_No_Use_Of_Entity (N);
-- Annotate the tree by creating a variable reference marker in case the
-- original variable reference is folded or optimized away. The variable
-- reference marker is automatically saved for later examination by the
-- ABE Processing phase. Variable references which act as actuals in a
-- call require special processing and are left to Resolve_Actuals. The
-- reference is a write when it appears on the left hand side of an
-- assignment.
if Needs_Variable_Reference_Marker (N => N, Calls_OK => False) then
declare
Is_Assignment_LHS : constant Boolean := Known_To_Be_Assigned (N);
begin
Build_Variable_Reference_Marker
(N => N,
Read => not Is_Assignment_LHS,
Write => Is_Assignment_LHS);
end;
end if;
end Find_Direct_Name;
------------------------
-- Find_Expanded_Name --
------------------------
-- This routine searches the homonym chain of the entity until it finds
-- an entity declared in the scope denoted by the prefix. If the entity
-- is private, it may nevertheless be immediately visible, if we are in
-- the scope of its declaration.
procedure Find_Expanded_Name (N : Node_Id) is
function In_Abstract_View_Pragma (Nod : Node_Id) return Boolean;
-- Determine whether expanded name Nod appears within a pragma which is
-- a suitable context for an abstract view of a state or variable. The
-- following pragmas fall in this category:
-- Depends
-- Global
-- Initializes
-- Refined_Depends
-- Refined_Global
--
-- In addition, pragma Abstract_State is also considered suitable even
-- though it is an illegal context for an abstract view as this allows
-- for proper resolution of abstract views of variables. This illegal
-- context is later flagged in the analysis of indicator Part_Of.
-----------------------------
-- In_Abstract_View_Pragma --
-----------------------------
function In_Abstract_View_Pragma (Nod : Node_Id) return Boolean is
Par : Node_Id;
begin
-- Climb the parent chain looking for a pragma
Par := Nod;
while Present (Par) loop
if Nkind (Par) = N_Pragma then
if Pragma_Name_Unmapped (Par)
in Name_Abstract_State
| Name_Depends
| Name_Global
| Name_Initializes
| Name_Refined_Depends
| Name_Refined_Global
then
return True;
-- Otherwise the pragma is not a legal context for an abstract
-- view.
else
exit;
end if;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Abstract_View_Pragma;
-- Local variables
Selector : constant Node_Id := Selector_Name (N);
Candidate : Entity_Id := Empty;
P_Name : Entity_Id;
Id : Entity_Id;
-- Start of processing for Find_Expanded_Name
begin
P_Name := Entity (Prefix (N));
-- If the prefix is a renamed package, look for the entity in the
-- original package.
if Ekind (P_Name) = E_Package
and then Present (Renamed_Entity (P_Name))
then
P_Name := Renamed_Entity (P_Name);
if From_Limited_With (P_Name)
and then not Unit_Is_Visible (Cunit (Get_Source_Unit (P_Name)))
then
Error_Msg_NE
("renaming of limited view of package & not usable in this"
& " context (RM 8.5.3(3.1/2))", Prefix (N), P_Name);
elsif Has_Limited_View (P_Name)
and then not Unit_Is_Visible (Cunit (Get_Source_Unit (P_Name)))
and then not Is_Visible_Through_Renamings (P_Name)
then
Error_Msg_NE
("renaming of limited view of package & not usable in this"
& " context (RM 8.5.3(3.1/2))", Prefix (N), P_Name);
end if;
-- Rewrite node with entity field pointing to renamed object
Rewrite (Prefix (N), New_Copy (Prefix (N)));
Set_Entity (Prefix (N), P_Name);
-- If the prefix is an object of a concurrent type, look for
-- the entity in the associated task or protected type.
elsif Is_Concurrent_Type (Etype (P_Name)) then
P_Name := Etype (P_Name);
end if;
Id := Current_Entity (Selector);
declare
Is_New_Candidate : Boolean;
begin
while Present (Id) loop
if Scope (Id) = P_Name then
Candidate := Id;
Is_New_Candidate := True;
-- Handle abstract views of states and variables. These are
-- acceptable candidates only when the reference to the view
-- appears in certain pragmas.
if Ekind (Id) = E_Abstract_State
and then From_Limited_With (Id)
and then Present (Non_Limited_View (Id))
then
if In_Abstract_View_Pragma (N) then
Candidate := Non_Limited_View (Id);
Is_New_Candidate := True;
-- Hide the candidate because it is not used in a proper
-- context.
else
Candidate := Empty;
Is_New_Candidate := False;
end if;
end if;
-- Ada 2005 (AI-217): Handle shadow entities associated with
-- types declared in limited-withed nested packages. We don't need
-- to handle E_Incomplete_Subtype entities because the entities
-- in the limited view are always E_Incomplete_Type and
-- E_Class_Wide_Type entities (see Build_Limited_Views).
-- Regarding the expression used to evaluate the scope, it
-- is important to note that the limited view also has shadow
-- entities associated nested packages. For this reason the
-- correct scope of the entity is the scope of the real entity.
-- The non-limited view may itself be incomplete, in which case
-- get the full view if available.
elsif Ekind (Id) in E_Incomplete_Type | E_Class_Wide_Type
and then From_Limited_With (Id)
and then Present (Non_Limited_View (Id))
and then Scope (Non_Limited_View (Id)) = P_Name
then
Candidate := Get_Full_View (Non_Limited_View (Id));
Is_New_Candidate := True;
-- Handle special case where the prefix is a renaming of a shadow
-- package which is visible. Required to avoid reporting spurious
-- errors.
elsif Ekind (P_Name) = E_Package
and then From_Limited_With (P_Name)
and then not From_Limited_With (Id)
and then Sloc (Scope (Id)) = Sloc (P_Name)
and then Unit_Is_Visible (Cunit (Get_Source_Unit (P_Name)))
then
Candidate := Get_Full_View (Id);
Is_New_Candidate := True;
-- An unusual case arises with a fully qualified name for an
-- entity local to a generic child unit package, within an
-- instantiation of that package. The name of the unit now
-- denotes the renaming created within the instance. This is
-- only relevant in an instance body, see below.
elsif Is_Generic_Instance (Scope (Id))
and then In_Open_Scopes (Scope (Id))
and then In_Instance_Body
and then Ekind (Scope (Id)) = E_Package
and then Ekind (Id) = E_Package
and then Renamed_Entity (Id) = Scope (Id)
and then Is_Immediately_Visible (P_Name)
then
Is_New_Candidate := True;
else
Is_New_Candidate := False;
end if;
if Is_New_Candidate then
-- If entity is a child unit, either it is a visible child of
-- the prefix, or we are in the body of a generic prefix, as
-- will happen when a child unit is instantiated in the body
-- of a generic parent. This is because the instance body does
-- not restore the full compilation context, given that all
-- non-local references have been captured.
if Is_Child_Unit (Id) or else P_Name = Standard_Standard then
exit when Is_Visible_Lib_Unit (Id)
or else (Is_Child_Unit (Id)
and then In_Open_Scopes (Scope (Id))
and then In_Instance_Body);
else
exit when not Is_Hidden (Id);
end if;
exit when Is_Immediately_Visible (Id);
end if;
Id := Homonym (Id);
end loop;
end;
if No (Id)
and then Ekind (P_Name) in E_Procedure | E_Function
and then Is_Generic_Instance (P_Name)
then
-- Expanded name denotes entity in (instance of) generic subprogram.
-- The entity may be in the subprogram instance, or may denote one of
-- the formals, which is declared in the enclosing wrapper package.
P_Name := Scope (P_Name);
Id := Current_Entity (Selector);
while Present (Id) loop
exit when Scope (Id) = P_Name;
Id := Homonym (Id);
end loop;
end if;
if No (Id) or else Chars (Id) /= Chars (Selector) then
Set_Etype (N, Any_Type);
-- If we are looking for an entity defined in System, try to find it
-- in the child package that may have been provided as an extension
-- to System. The Extend_System pragma will have supplied the name of
-- the extension, which may have to be loaded.
if Chars (P_Name) = Name_System
and then Scope (P_Name) = Standard_Standard
and then Present (System_Extend_Unit)
and then Present_System_Aux (N)
then
Set_Entity (Prefix (N), System_Aux_Id);
Find_Expanded_Name (N);
return;
-- There is an implicit instance of the predefined operator in
-- the given scope. The operator entity is defined in Standard.
-- Has_Implicit_Operator makes the node into an Expanded_Name.
elsif Nkind (Selector) = N_Operator_Symbol
and then Has_Implicit_Operator (N)
then
return;
-- If there is no literal defined in the scope denoted by the
-- prefix, the literal may belong to (a type derived from)
-- Standard_Character, for which we have no explicit literals.
elsif Nkind (Selector) = N_Character_Literal
and then Has_Implicit_Character_Literal (N)
then
return;
else
-- If the prefix is a single concurrent object, use its name in
-- the error message, rather than that of the anonymous type.
if Is_Concurrent_Type (P_Name)
and then Is_Internal_Name (Chars (P_Name))
then
Error_Msg_Node_2 := Entity (Prefix (N));
else
Error_Msg_Node_2 := P_Name;
end if;
if P_Name = System_Aux_Id then
P_Name := Scope (P_Name);
Set_Entity (Prefix (N), P_Name);
end if;
if Present (Candidate) then
-- If we know that the unit is a child unit we can give a more
-- accurate error message.
if Is_Child_Unit (Candidate) then
-- If the candidate is a private child unit and we are in
-- the visible part of a public unit, specialize the error
-- message. There might be a private with_clause for it,
-- but it is not currently active.
if Is_Private_Descendant (Candidate)
and then Ekind (Current_Scope) = E_Package
and then not In_Private_Part (Current_Scope)
and then not Is_Private_Descendant (Current_Scope)
then
Error_Msg_N
("private child unit& is not visible here", Selector);
-- Normal case where we have a missing with for a child unit
else
Error_Msg_Qual_Level := 99;
Error_Msg_NE -- CODEFIX
("missing `WITH &;`", Selector, Candidate);
Error_Msg_Qual_Level := 0;
end if;
-- Here we don't know that this is a child unit
else
Error_Msg_NE ("& is not a visible entity of&", N, Selector);
end if;
else
-- Within the instantiation of a child unit, the prefix may
-- denote the parent instance, but the selector has the name
-- of the original child. That is to say, when A.B appears
-- within an instantiation of generic child unit B, the scope
-- stack includes an instance of A (P_Name) and an instance
-- of B under some other name. We scan the scope to find this
-- child instance, which is the desired entity.
-- Note that the parent may itself be a child instance, if
-- the reference is of the form A.B.C, in which case A.B has
-- already been rewritten with the proper entity.
if In_Open_Scopes (P_Name)
and then Is_Generic_Instance (P_Name)
then
declare
Gen_Par : constant Entity_Id :=
Generic_Parent (Specification
(Unit_Declaration_Node (P_Name)));
S : Entity_Id := Current_Scope;
P : Entity_Id;
begin
for J in reverse 0 .. Scope_Stack.Last loop
S := Scope_Stack.Table (J).Entity;
exit when S = Standard_Standard;
if Ekind (S) in E_Function | E_Package | E_Procedure
then
P :=
Generic_Parent (Specification
(Unit_Declaration_Node (S)));
-- Check that P is a generic child of the generic
-- parent of the prefix.
if Present (P)
and then Chars (P) = Chars (Selector)
and then Scope (P) = Gen_Par
then
Id := S;
goto Found;
end if;
end if;
end loop;
end;
end if;
-- If this is a selection from Ada, System or Interfaces, then
-- we assume a missing with for the corresponding package.
if Is_Known_Unit (N)
and then not (Present (Entity (Prefix (N)))
and then Scope (Entity (Prefix (N))) /=
Standard_Standard)
then
if not Error_Posted (N) then
Error_Msg_Node_2 := Selector;
Error_Msg_N -- CODEFIX
("missing `WITH &.&;`", Prefix (N));
end if;
-- If this is a selection from a dummy package, then suppress
-- the error message, of course the entity is missing if the
-- package is missing.
elsif Sloc (Error_Msg_Node_2) = No_Location then
null;
-- Here we have the case of an undefined component
else
-- The prefix may hide a homonym in the context that
-- declares the desired entity. This error can use a
-- specialized message.
if In_Open_Scopes (P_Name) then
declare
H : constant Entity_Id := Homonym (P_Name);
begin
if Present (H)
and then Is_Compilation_Unit (H)
and then
(Is_Immediately_Visible (H)
or else Is_Visible_Lib_Unit (H))
then
Id := First_Entity (H);
while Present (Id) loop
if Chars (Id) = Chars (Selector) then
Error_Msg_Qual_Level := 99;
Error_Msg_Name_1 := Chars (Selector);
Error_Msg_NE
("% not declared in&", N, P_Name);
Error_Msg_NE
("\use fully qualified name starting with "
& "Standard to make& visible", N, H);
Error_Msg_Qual_Level := 0;
goto Done;
end if;
Next_Entity (Id);
end loop;
end if;
-- If not found, standard error message
Error_Msg_NE ("& not declared in&", N, Selector);
<<Done>> null;
end;
else
-- Might be worth specializing the case when the prefix
-- is a limited view.
-- ... not declared in limited view of...
Error_Msg_NE ("& not declared in&", N, Selector);
end if;
-- Check for misspelling of some entity in prefix
Id := First_Entity (P_Name);
while Present (Id) loop
if Is_Bad_Spelling_Of (Chars (Id), Chars (Selector))
and then not Is_Internal_Name (Chars (Id))
then
Error_Msg_NE -- CODEFIX
("possible misspelling of&", Selector, Id);
exit;
end if;
Next_Entity (Id);
end loop;
-- Specialize the message if this may be an instantiation
-- of a child unit that was not mentioned in the context.
if Nkind (Parent (N)) = N_Package_Instantiation
and then Is_Generic_Instance (Entity (Prefix (N)))
and then Is_Compilation_Unit
(Generic_Parent (Parent (Entity (Prefix (N)))))
then
Error_Msg_Node_2 := Selector;
Error_Msg_N -- CODEFIX
("\missing `WITH &.&;`", Prefix (N));
end if;
end if;
end if;
Id := Any_Id;
end if;
end if;
<<Found>>
if Comes_From_Source (N)
and then Is_Remote_Access_To_Subprogram_Type (Id)
and then Ekind (Id) = E_Access_Subprogram_Type
and then Present (Equivalent_Type (Id))
then
-- If we are not actually generating distribution code (i.e. the
-- current PCS is the dummy non-distributed version), then the
-- Equivalent_Type will be missing, and Id should be treated as
-- a regular access-to-subprogram type.
Id := Equivalent_Type (Id);
Set_Chars (Selector, Chars (Id));
end if;
-- Ada 2005 (AI-50217): Check usage of entities in limited withed units
if Ekind (P_Name) = E_Package and then From_Limited_With (P_Name) then
if From_Limited_With (Id)
or else Is_Type (Id)
or else Ekind (Id) = E_Package
then
null;
else
Error_Msg_N
("limited withed package can only be used to access incomplete "
& "types", N);
end if;
end if;
if Is_Task_Type (P_Name)
and then ((Ekind (Id) = E_Entry
and then Nkind (Parent (N)) /= N_Attribute_Reference)
or else
(Ekind (Id) = E_Entry_Family
and then
Nkind (Parent (Parent (N))) /= N_Attribute_Reference))
then
-- If both the task type and the entry are in scope, this may still
-- be the expanded name of an entry formal.
if In_Open_Scopes (Id)
and then Nkind (Parent (N)) = N_Selected_Component
then
null;
else
-- It is an entry call after all, either to the current task
-- (which will deadlock) or to an enclosing task.
Analyze_Selected_Component (N);
return;
end if;
end if;
case Nkind (N) is
when N_Selected_Component =>
Reinit_Field_To_Zero (N, F_Is_Prefixed_Call);
Change_Selected_Component_To_Expanded_Name (N);
when N_Expanded_Name =>
null;
when others =>
pragma Assert (False);
end case;
-- Preserve relevant elaboration-related attributes of the context which
-- are no longer available or very expensive to recompute once analysis,
-- resolution, and expansion are over.
Mark_Elaboration_Attributes
(N_Id => N,
Checks => True,
Modes => True,
Warnings => True);
-- Set appropriate type
if Is_Type (Id) then
Set_Etype (N, Id);
else
Set_Etype (N, Get_Full_View (Etype (Id)));
end if;
-- Do style check and generate reference, but skip both steps if this
-- entity has homonyms, since we may not have the right homonym set yet.
-- The proper homonym will be set during the resolve phase.
if Has_Homonym (Id) then
Set_Entity (N, Id);
else
Set_Entity_Or_Discriminal (N, Id);
case Known_To_Be_Assigned (N, Only_LHS => True) is
when True =>
Generate_Reference (Id, N, 'm');
when False =>
Generate_Reference (Id, N, 'r');
end case;
end if;
-- Check for violation of No_Wide_Characters
Check_Wide_Character_Restriction (Id, N);
-- If the Ekind of the entity is Void, it means that all homonyms are
-- hidden from all visibility (RM 8.3(5,14-20)).
if Ekind (Id) = E_Void then
Premature_Usage (N);
elsif Is_Overloadable (Id) and then Present (Homonym (Id)) then
declare
H : Entity_Id := Homonym (Id);
begin
while Present (H) loop
if Scope (H) = Scope (Id)
and then (not Is_Hidden (H)
or else Is_Immediately_Visible (H))
then
Collect_Interps (N);
exit;
end if;
H := Homonym (H);
end loop;
-- If an extension of System is present, collect possible explicit
-- overloadings declared in the extension.
if Chars (P_Name) = Name_System
and then Scope (P_Name) = Standard_Standard
and then Present (System_Extend_Unit)
and then Present_System_Aux (N)
then
H := Current_Entity (Id);
while Present (H) loop
if Scope (H) = System_Aux_Id then
Add_One_Interp (N, H, Etype (H));
end if;
H := Homonym (H);
end loop;
end if;
end;
end if;
if Nkind (Selector_Name (N)) = N_Operator_Symbol
and then Scope (Id) /= Standard_Standard
then
-- In addition to user-defined operators in the given scope, there
-- may be an implicit instance of the predefined operator. The
-- operator (defined in Standard) is found in Has_Implicit_Operator,
-- and added to the interpretations. Procedure Add_One_Interp will
-- determine which hides which.
if Has_Implicit_Operator (N) then
null;
end if;
end if;
-- If there is a single interpretation for N we can generate a
-- reference to the unique entity found.
if Is_Overloadable (Id) and then not Is_Overloaded (N) then
Generate_Reference (Id, N);
end if;
-- Mark relevant use-type and use-package clauses as effective if the
-- node in question is not overloaded and therefore does not require
-- resolution.
if Nkind (N) not in N_Subexpr or else not Is_Overloaded (N) then
Mark_Use_Clauses (N);
end if;
Check_Restriction_No_Use_Of_Entity (N);
-- Annotate the tree by creating a variable reference marker in case the
-- original variable reference is folded or optimized away. The variable
-- reference marker is automatically saved for later examination by the
-- ABE Processing phase. Variable references which act as actuals in a
-- call require special processing and are left to Resolve_Actuals. The
-- reference is a write when it appears on the left hand side of an
-- assignment.
if Needs_Variable_Reference_Marker
(N => N,
Calls_OK => False)
then
declare
Is_Assignment_LHS : constant Boolean := Known_To_Be_Assigned (N);
begin
Build_Variable_Reference_Marker
(N => N,
Read => not Is_Assignment_LHS,
Write => Is_Assignment_LHS);
end;
end if;
end Find_Expanded_Name;
--------------------
-- Find_First_Use --
--------------------
function Find_First_Use (Use_Clause : Node_Id) return Node_Id is
Curr : Node_Id;
begin
-- Loop through the Prev_Use_Clause chain
Curr := Use_Clause;
while Present (Prev_Use_Clause (Curr)) loop
Curr := Prev_Use_Clause (Curr);
end loop;
return Curr;
end Find_First_Use;
-------------------------
-- Find_Renamed_Entity --
-------------------------
function Find_Renamed_Entity
(N : Node_Id;
Nam : Node_Id;
New_S : Entity_Id;
Is_Actual : Boolean := False) return Entity_Id
is
Ind : Interp_Index;
I1 : Interp_Index := 0; -- Suppress junk warnings
It : Interp;
It1 : Interp;
Old_S : Entity_Id;
Inst : Entity_Id;
function Find_Nearer_Entity
(New_S : Entity_Id;
Old1_S : Entity_Id;
Old2_S : Entity_Id) return Entity_Id;
-- Determine whether one of Old_S1 and Old_S2 is nearer to New_S than
-- the other, and return it if so. Return Empty otherwise. We use this
-- in conjunction with Inherit_Renamed_Profile to simplify later type
-- disambiguation for actual subprograms in instances.
function Is_Visible_Operation (Op : Entity_Id) return Boolean;
-- If the renamed entity is an implicit operator, check whether it is
-- visible because its operand type is properly visible. This check
-- applies to explicit renamed entities that appear in the source in a
-- renaming declaration or a formal subprogram instance, but not to
-- default generic actuals with a name.
function Report_Overload return Entity_Id;
-- List possible interpretations, and specialize message in the
-- case of a generic actual.
function Within (Inner, Outer : Entity_Id) return Boolean;
-- Determine whether a candidate subprogram is defined within the
-- enclosing instance. If yes, it has precedence over outer candidates.
--------------------------
-- Find_Nearer_Entity --
--------------------------
function Find_Nearer_Entity
(New_S : Entity_Id;
Old1_S : Entity_Id;
Old2_S : Entity_Id) return Entity_Id
is
New_F : Entity_Id;
Old1_F : Entity_Id;
Old2_F : Entity_Id;
Anc_T : Entity_Id;
begin
New_F := First_Formal (New_S);
Old1_F := First_Formal (Old1_S);
Old2_F := First_Formal (Old2_S);
-- The criterion is whether the type of the formals of one of Old1_S
-- and Old2_S is an ancestor subtype of the type of the corresponding
-- formals of New_S while the other is not (we already know that they
-- are all subtypes of the same base type).
-- This makes it possible to find the more correct renamed entity in
-- the case of a generic instantiation nested in an enclosing one for
-- which different formal types get the same actual type, which will
-- in turn make it possible for Inherit_Renamed_Profile to preserve
-- types on formal parameters and ultimately simplify disambiguation.
-- Consider the follow package G:
-- generic
-- type Item_T is private;
-- with function Compare (L, R: Item_T) return Boolean is <>;
-- type Bound_T is private;
-- with function Compare (L, R : Bound_T) return Boolean is <>;
-- package G is
-- ...
-- end G;
-- package body G is
-- package My_Inner is Inner_G (Bound_T);
-- ...
-- end G;
-- with the following package Inner_G:
-- generic
-- type T is private;
-- with function Compare (L, R: T) return Boolean is <>;
-- package Inner_G is
-- function "<" (L, R: T) return Boolean is (Compare (L, R));
-- end Inner_G;
-- If G is instantiated on the same actual type with a single Compare
-- function:
-- type T is ...
-- function Compare (L, R : T) return Boolean;
-- package My_G is new (T, T);
-- then the renaming generated for Compare in the inner instantiation
-- is ambiguous: it can rename either of the renamings generated for
-- the outer instantiation. Now if the first one is picked up, then
-- the subtypes of the formal parameters of the renaming will not be
-- preserved in Inherit_Renamed_Profile because they are subtypes of
-- the Bound_T formal type and not of the Item_T formal type, so we
-- need to arrange for the second one to be picked up instead.
while Present (New_F) loop
if Etype (Old1_F) /= Etype (Old2_F) then
Anc_T := Ancestor_Subtype (Etype (New_F));
if Etype (Old1_F) = Anc_T then
return Old1_S;
elsif Etype (Old2_F) = Anc_T then
return Old2_S;
end if;
end if;
Next_Formal (New_F);
Next_Formal (Old1_F);
Next_Formal (Old2_F);
end loop;
pragma Assert (No (Old1_F));
pragma Assert (No (Old2_F));
return Empty;
end Find_Nearer_Entity;
--------------------------
-- Is_Visible_Operation --
--------------------------
function Is_Visible_Operation (Op : Entity_Id) return Boolean is
Scop : Entity_Id;
Typ : Entity_Id;
Btyp : Entity_Id;
begin
if Ekind (Op) /= E_Operator
or else Scope (Op) /= Standard_Standard
or else (In_Instance
and then (not Is_Actual
or else Present (Enclosing_Instance)))
then
return True;
else
-- For a fixed point type operator, check the resulting type,
-- because it may be a mixed mode integer * fixed operation.
if Present (Next_Formal (First_Formal (New_S)))
and then Is_Fixed_Point_Type (Etype (New_S))
then
Typ := Etype (New_S);
else
Typ := Etype (First_Formal (New_S));
end if;
Btyp := Base_Type (Typ);
if Nkind (Nam) /= N_Expanded_Name then
return (In_Open_Scopes (Scope (Btyp))
or else Is_Potentially_Use_Visible (Btyp)
or else In_Use (Btyp)
or else In_Use (Scope (Btyp)));
else
Scop := Entity (Prefix (Nam));
if Ekind (Scop) = E_Package
and then Present (Renamed_Entity (Scop))
then
Scop := Renamed_Entity (Scop);
end if;
-- Operator is visible if prefix of expanded name denotes
-- scope of type, or else type is defined in System_Aux
-- and the prefix denotes System.
return Scope (Btyp) = Scop
or else (Scope (Btyp) = System_Aux_Id
and then Scope (Scope (Btyp)) = Scop);
end if;
end if;
end Is_Visible_Operation;
------------
-- Within --
------------
function Within (Inner, Outer : Entity_Id) return Boolean is
Sc : Entity_Id;
begin
Sc := Scope (Inner);
while Sc /= Standard_Standard loop
if Sc = Outer then
return True;
else
Sc := Scope (Sc);
end if;
end loop;
return False;
end Within;
---------------------
-- Report_Overload --
---------------------
function Report_Overload return Entity_Id is
begin
if Is_Actual then
Error_Msg_NE -- CODEFIX
("ambiguous actual subprogram&, " &
"possible interpretations:", N, Nam);
else
Error_Msg_N -- CODEFIX
("ambiguous subprogram, " &
"possible interpretations:", N);
end if;
List_Interps (Nam, N);
return Old_S;
end Report_Overload;
-- Start of processing for Find_Renamed_Entity
begin
Old_S := Any_Id;
Candidate_Renaming := Empty;
if Is_Overloaded (Nam) then
Get_First_Interp (Nam, Ind, It);
while Present (It.Nam) loop
if Entity_Matches_Spec (It.Nam, New_S)
and then Is_Visible_Operation (It.Nam)
then
if Old_S /= Any_Id then
-- Note: The call to Disambiguate only happens if a
-- previous interpretation was found, in which case I1
-- has received a value.
It1 := Disambiguate (Nam, I1, Ind, Etype (Old_S));
if It1 = No_Interp then
Inst := Enclosing_Instance;
if Present (Inst) then
if Within (It.Nam, Inst) then
if Within (Old_S, Inst) then
declare
It_D : constant Uint :=
Scope_Depth_Default_0 (It.Nam);
Old_D : constant Uint :=
Scope_Depth_Default_0 (Old_S);
N_Ent : Entity_Id;
begin
-- Choose the innermost subprogram, which
-- would hide the outer one in the generic.
if Old_D > It_D then
return Old_S;
elsif It_D > Old_D then
return It.Nam;
end if;
-- Otherwise, if we can determine that one
-- of the entities is nearer to the renaming
-- than the other, choose it. If not, then
-- return the newer one as done historically.
N_Ent :=
Find_Nearer_Entity (New_S, Old_S, It.Nam);
if Present (N_Ent) then
return N_Ent;
else
return It.Nam;
end if;
end;
end if;
elsif Within (Old_S, Inst) then
return Old_S;
else
return Report_Overload;
end if;
-- If not within an instance, ambiguity is real
else
return Report_Overload;
end if;
else
Old_S := It1.Nam;
exit;
end if;
else
I1 := Ind;
Old_S := It.Nam;
end if;
elsif
Present (First_Formal (It.Nam))
and then Present (First_Formal (New_S))
and then (Base_Type (Etype (First_Formal (It.Nam))) =
Base_Type (Etype (First_Formal (New_S))))
then
Candidate_Renaming := It.Nam;
end if;
Get_Next_Interp (Ind, It);
end loop;
Set_Entity (Nam, Old_S);
if Old_S /= Any_Id then
Set_Is_Overloaded (Nam, False);
end if;
-- Non-overloaded case
else
if Is_Actual
and then Present (Enclosing_Instance)
and then Entity_Matches_Spec (Entity (Nam), New_S)
then
Old_S := Entity (Nam);
elsif Entity_Matches_Spec (Entity (Nam), New_S) then
Candidate_Renaming := New_S;
if Is_Visible_Operation (Entity (Nam)) then
Old_S := Entity (Nam);
end if;
elsif Present (First_Formal (Entity (Nam)))
and then Present (First_Formal (New_S))
and then (Base_Type (Etype (First_Formal (Entity (Nam)))) =
Base_Type (Etype (First_Formal (New_S))))
then
Candidate_Renaming := Entity (Nam);
end if;
end if;
return Old_S;
end Find_Renamed_Entity;
-----------------------------
-- Find_Selected_Component --
-----------------------------
procedure Find_Selected_Component (N : Node_Id) is
P : constant Node_Id := Prefix (N);
P_Name : Entity_Id;
-- Entity denoted by prefix
P_Type : Entity_Id;
-- and its type
Nam : Node_Id;
function Available_Subtype return Boolean;
-- A small optimization: if the prefix is constrained and the component
-- is an array type we may already have a usable subtype for it, so we
-- can use it rather than generating a new one, because the bounds
-- will be the values of the discriminants and not discriminant refs.
-- This simplifies value tracing in GNATprove. For consistency, both
-- the entity name and the subtype come from the constrained component.
-- This is only used in GNATprove mode: when generating code it may be
-- necessary to create an itype in the scope of use of the selected
-- component, e.g. in the context of a expanded record equality.
function Is_Reference_In_Subunit return Boolean;
-- In a subunit, the scope depth is not a proper measure of hiding,
-- because the context of the proper body may itself hide entities in
-- parent units. This rare case requires inspecting the tree directly
-- because the proper body is inserted in the main unit and its context
-- is simply added to that of the parent.
-----------------------
-- Available_Subtype --
-----------------------
function Available_Subtype return Boolean is
Comp : Entity_Id;
begin
if GNATprove_Mode then
Comp := First_Entity (Etype (P));
while Present (Comp) loop
if Chars (Comp) = Chars (Selector_Name (N)) then
Set_Etype (N, Etype (Comp));
Set_Entity (Selector_Name (N), Comp);
Set_Etype (Selector_Name (N), Etype (Comp));
return True;
end if;
Next_Component (Comp);
end loop;
end if;
return False;
end Available_Subtype;
-----------------------------
-- Is_Reference_In_Subunit --
-----------------------------
function Is_Reference_In_Subunit return Boolean is
Clause : Node_Id;
Comp_Unit : Node_Id;
begin
Comp_Unit := N;
while Present (Comp_Unit)
and then Nkind (Comp_Unit) /= N_Compilation_Unit
loop
Comp_Unit := Parent (Comp_Unit);
end loop;
if No (Comp_Unit) or else Nkind (Unit (Comp_Unit)) /= N_Subunit then
return False;
end if;
-- Now check whether the package is in the context of the subunit
Clause := First (Context_Items (Comp_Unit));
while Present (Clause) loop
if Nkind (Clause) = N_With_Clause
and then Entity (Name (Clause)) = P_Name
then
return True;
end if;
Next (Clause);
end loop;
return False;
end Is_Reference_In_Subunit;
-- Start of processing for Find_Selected_Component
begin
Analyze (P);
if Nkind (P) = N_Error then
return;
end if;
-- If the selector already has an entity, the node has been constructed
-- in the course of expansion, and is known to be valid. Do not verify
-- that it is defined for the type (it may be a private component used
-- in the expansion of record equality).
if Present (Entity (Selector_Name (N))) then
if No (Etype (N)) or else Etype (N) = Any_Type then
declare
Sel_Name : constant Node_Id := Selector_Name (N);
Selector : constant Entity_Id := Entity (Sel_Name);
C_Etype : Node_Id;
begin
Set_Etype (Sel_Name, Etype (Selector));
if not Is_Entity_Name (P) then
Resolve (P);
end if;
-- Build an actual subtype except for the first parameter
-- of an init proc, where this actual subtype is by
-- definition incorrect, since the object is uninitialized
-- (and does not even have defined discriminants etc.)
if Is_Entity_Name (P)
and then Ekind (Entity (P)) = E_Function
then
Nam := New_Copy (P);
if Is_Overloaded (P) then
Save_Interps (P, Nam);
end if;
Rewrite (P, Make_Function_Call (Sloc (P), Name => Nam));
Analyze_Call (P);
Analyze_Selected_Component (N);
return;
elsif Ekind (Selector) = E_Component
and then (not Is_Entity_Name (P)
or else Chars (Entity (P)) /= Name_uInit)
then
-- Check if we already have an available subtype we can use
if Ekind (Etype (P)) = E_Record_Subtype
and then Nkind (Parent (Etype (P))) = N_Subtype_Declaration
and then Is_Array_Type (Etype (Selector))
and then not Is_Packed (Etype (Selector))
and then Available_Subtype
then
return;
-- Do not build the subtype when referencing components of
-- dispatch table wrappers. Required to avoid generating
-- elaboration code with HI runtimes.
elsif Is_RTE (Scope (Selector), RE_Dispatch_Table_Wrapper)
or else
Is_RTE (Scope (Selector), RE_No_Dispatch_Table_Wrapper)
then
C_Etype := Empty;
else
C_Etype :=
Build_Actual_Subtype_Of_Component
(Etype (Selector), N);
end if;
else
C_Etype := Empty;
end if;
if No (C_Etype) then
C_Etype := Etype (Selector);
else
Insert_Action (N, C_Etype);
C_Etype := Defining_Identifier (C_Etype);
end if;
Set_Etype (N, C_Etype);
end;
-- If the selected component appears within a default expression
-- and it has an actual subtype, the preanalysis has not yet
-- completed its analysis, because Insert_Actions is disabled in
-- that context. Within the init proc of the enclosing type we
-- must complete this analysis, if an actual subtype was created.
elsif Inside_Init_Proc then
declare
Typ : constant Entity_Id := Etype (N);
Decl : constant Node_Id := Declaration_Node (Typ);
begin
if Nkind (Decl) = N_Subtype_Declaration
and then not Analyzed (Decl)
and then Is_List_Member (Decl)
and then No (Parent (Decl))
then
Remove (Decl);
Insert_Action (N, Decl);
end if;
end;
end if;
return;
elsif Is_Entity_Name (P) then
P_Name := Entity (P);
-- The prefix may denote an enclosing type which is the completion
-- of an incomplete type declaration.
if Is_Type (P_Name) then
Set_Entity (P, Get_Full_View (P_Name));
Set_Etype (P, Entity (P));
P_Name := Entity (P);
end if;
P_Type := Base_Type (Etype (P));
if Debug_Flag_E then
Write_Str ("Found prefix type to be ");
Write_Entity_Info (P_Type, " "); Write_Eol;
end if;
-- If the prefix's type is an access type, get to the record type
if Is_Access_Type (P_Type) then
P_Type := Implicitly_Designated_Type (P_Type);
end if;
-- First check for components of a record object (not the result of
-- a call, which is handled below). This also covers the case where
-- the extension feature that supports the prefixed form of calls
-- for primitives of untagged types is enabled (excluding concurrent
-- cases, which are handled further below).
if Is_Type (P_Type)
and then (Has_Components (P_Type)
or else (Extensions_Allowed
and then not Is_Concurrent_Type (P_Type)))
and then not Is_Overloadable (P_Name)
and then not Is_Type (P_Name)
then
-- Selected component of record. Type checking will validate
-- name of selector.
-- ??? Could we rewrite an implicit dereference into an explicit
-- one here?
Analyze_Selected_Component (N);
-- Reference to type name in predicate/invariant expression
elsif Is_Concurrent_Type (P_Type)
and then not In_Open_Scopes (P_Name)
and then (not Is_Concurrent_Type (Etype (P_Name))
or else not In_Open_Scopes (Etype (P_Name)))
then
-- Call to protected operation or entry. Type checking is
-- needed on the prefix.
Analyze_Selected_Component (N);
elsif (In_Open_Scopes (P_Name)
and then Ekind (P_Name) /= E_Void
and then not Is_Overloadable (P_Name))
or else (Is_Concurrent_Type (Etype (P_Name))
and then In_Open_Scopes (Etype (P_Name)))
then
-- Prefix denotes an enclosing loop, block, or task, i.e. an
-- enclosing construct that is not a subprogram or accept.
-- A special case: a protected body may call an operation
-- on an external object of the same type, in which case it
-- is not an expanded name. If the prefix is the type itself,
-- or the context is a single synchronized object it can only
-- be interpreted as an expanded name.
if Is_Concurrent_Type (Etype (P_Name)) then
if Is_Type (P_Name)
or else Present (Anonymous_Object (Etype (P_Name)))
then
Find_Expanded_Name (N);
else
Analyze_Selected_Component (N);
return;
end if;
else
Find_Expanded_Name (N);
end if;
elsif Ekind (P_Name) = E_Package then
Find_Expanded_Name (N);
elsif Is_Overloadable (P_Name) then
-- The subprogram may be a renaming (of an enclosing scope) as
-- in the case of the name of the generic within an instantiation.
if Ekind (P_Name) in E_Procedure | E_Function
and then Present (Alias (P_Name))
and then Is_Generic_Instance (Alias (P_Name))
then
P_Name := Alias (P_Name);
end if;
if Is_Overloaded (P) then
-- The prefix must resolve to a unique enclosing construct
declare
Found : Boolean := False;
Ind : Interp_Index;
It : Interp;
begin
Get_First_Interp (P, Ind, It);
while Present (It.Nam) loop
if In_Open_Scopes (It.Nam) then
if Found then
Error_Msg_N (
"prefix must be unique enclosing scope", N);
Set_Entity (N, Any_Id);
Set_Etype (N, Any_Type);
return;
else
Found := True;
P_Name := It.Nam;
end if;
end if;
Get_Next_Interp (Ind, It);
end loop;
end;
end if;
if In_Open_Scopes (P_Name) then
Set_Entity (P, P_Name);
Set_Is_Overloaded (P, False);
Find_Expanded_Name (N);
else
-- If no interpretation as an expanded name is possible, it
-- must be a selected component of a record returned by a
-- function call. Reformat prefix as a function call, the rest
-- is done by type resolution.
-- Error if the prefix is procedure or entry, as is P.X
if Ekind (P_Name) /= E_Function
and then
(not Is_Overloaded (P)
or else Nkind (Parent (N)) = N_Procedure_Call_Statement)
then
-- Prefix may mention a package that is hidden by a local
-- declaration: let the user know. Scan the full homonym
-- chain, the candidate package may be anywhere on it.
if Present (Homonym (Current_Entity (P_Name))) then
P_Name := Current_Entity (P_Name);
while Present (P_Name) loop
exit when Ekind (P_Name) = E_Package;
P_Name := Homonym (P_Name);
end loop;
if Present (P_Name) then
if not Is_Reference_In_Subunit then
Error_Msg_Sloc := Sloc (Entity (Prefix (N)));
Error_Msg_NE
("package& is hidden by declaration#", N, P_Name);
end if;
Set_Entity (Prefix (N), P_Name);
Find_Expanded_Name (N);
return;
else
P_Name := Entity (Prefix (N));
end if;
end if;
Error_Msg_NE
("invalid prefix in selected component&", N, P_Name);
Change_Selected_Component_To_Expanded_Name (N);
Set_Entity (N, Any_Id);
Set_Etype (N, Any_Type);
-- Here we have a function call, so do the reformatting
else
Nam := New_Copy (P);
Save_Interps (P, Nam);
-- We use Replace here because this is one of those cases
-- where the parser has missclassified the node, and we fix
-- things up and then do the semantic analysis on the fixed
-- up node. Normally we do this using one of the Sinfo.CN
-- routines, but this is too tricky for that.
-- Note that using Rewrite would be wrong, because we would
-- have a tree where the original node is unanalyzed.
Replace (P,
Make_Function_Call (Sloc (P), Name => Nam));
-- Now analyze the reformatted node
Analyze_Call (P);
-- If the prefix is illegal after this transformation, there
-- may be visibility errors on the prefix. The safest is to
-- treat the selected component as an error.
if Error_Posted (P) then
Set_Etype (N, Any_Type);
return;
else
Analyze_Selected_Component (N);
end if;
end if;
end if;
-- Remaining cases generate various error messages
else
-- Format node as expanded name, to avoid cascaded errors
Change_Selected_Component_To_Expanded_Name (N);
Set_Entity (N, Any_Id);
Set_Etype (N, Any_Type);
-- Issue error message, but avoid this if error issued already.
-- Use identifier of prefix if one is available.
if P_Name = Any_Id then
null;
-- It is not an error if the prefix is the current instance of
-- type name, e.g. the expression of a type aspect, when it is
-- analyzed within a generic unit. We still have to verify that a
-- component of that name exists, and decorate the node
-- accordingly.
elsif Is_Entity_Name (P) and then Is_Current_Instance (P) then
declare
Comp : Entity_Id;
begin
Comp := First_Entity (Entity (P));
while Present (Comp) loop
if Chars (Comp) = Chars (Selector_Name (N)) then
Set_Entity (N, Comp);
Set_Etype (N, Etype (Comp));
Set_Entity (Selector_Name (N), Comp);
Set_Etype (Selector_Name (N), Etype (Comp));
return;
end if;
Next_Entity (Comp);
end loop;
end;
elsif Ekind (P_Name) = E_Void then
Premature_Usage (P);
elsif Ekind (P_Name) = E_Generic_Package then
Error_Msg_N ("prefix must not be a generic package", N);
Error_Msg_N ("\use package instantiation as prefix instead", N);
elsif Nkind (P) /= N_Attribute_Reference then
-- This may have been meant as a prefixed call to a primitive
-- of an untagged type. If it is a function call check type of
-- its first formal and add explanation.
declare
F : constant Entity_Id :=
Current_Entity (Selector_Name (N));
begin
if Present (F)
and then Is_Overloadable (F)
and then Present (First_Entity (F))
and then not Is_Tagged_Type (Etype (First_Entity (F)))
then
Error_Msg_N
("prefixed call is only allowed for objects of a "
& "tagged type unless -gnatX is used", N);
if not Extensions_Allowed
and then
Try_Object_Operation (N, Allow_Extensions => True)
then
Error_Msg_N
("\using -gnatX would make the prefixed call legal",
N);
end if;
end if;
end;
Error_Msg_N ("invalid prefix in selected component&", P);
if Is_Incomplete_Type (P_Type)
and then Is_Access_Type (Etype (P))
then
Error_Msg_N
("\dereference must not be of an incomplete type "
& "(RM 3.10.1)", P);
end if;
else
Error_Msg_N ("invalid prefix in selected component", P);
end if;
end if;
else
-- If prefix is not the name of an entity, it must be an expression,
-- whose type is appropriate for a record. This is determined by
-- type resolution.
Analyze_Selected_Component (N);
end if;
Analyze_Dimension (N);
end Find_Selected_Component;
---------------
-- Find_Type --
---------------
procedure Find_Type (N : Node_Id) is
C : Entity_Id;
Typ : Entity_Id;
T : Entity_Id;
T_Name : Entity_Id;
begin
if N = Error then
return;
elsif Nkind (N) = N_Attribute_Reference then
-- Class attribute. This is not valid in Ada 83 mode, but we do not
-- need to enforce that at this point, since the declaration of the
-- tagged type in the prefix would have been flagged already.
if Attribute_Name (N) = Name_Class then
Check_Restriction (No_Dispatch, N);
Find_Type (Prefix (N));
-- Propagate error from bad prefix
if Etype (Prefix (N)) = Any_Type then
Set_Entity (N, Any_Type);
Set_Etype (N, Any_Type);
return;
end if;
T := Base_Type (Entity (Prefix (N)));
-- Case where type is not known to be tagged. Its appearance in
-- the prefix of the 'Class attribute indicates that the full view
-- will be tagged.
if not Is_Tagged_Type (T) then
if Ekind (T) = E_Incomplete_Type then
-- It is legal to denote the class type of an incomplete
-- type. The full type will have to be tagged, of course.
-- In Ada 2005 this usage is declared obsolescent, so we
-- warn accordingly. This usage is only legal if the type
-- is completed in the current scope, and not for a limited
-- view of a type.
if Ada_Version >= Ada_2005 then
-- Test whether the Available_View of a limited type view
-- is tagged, since the limited view may not be marked as
-- tagged if the type itself has an untagged incomplete
-- type view in its package.
if From_Limited_With (T)
and then not Is_Tagged_Type (Available_View (T))
then
Error_Msg_N
("prefix of Class attribute must be tagged", N);
Set_Etype (N, Any_Type);
Set_Entity (N, Any_Type);
return;
else
if Restriction_Check_Required (No_Obsolescent_Features)
then
Check_Restriction
(No_Obsolescent_Features, Prefix (N));
end if;
if Warn_On_Obsolescent_Feature then
Error_Msg_N
("applying ''Class to an untagged incomplete type"
& " is an obsolescent feature (RM J.11)?r?", N);
end if;
end if;
end if;
Set_Is_Tagged_Type (T);
Set_Direct_Primitive_Operations (T, New_Elmt_List);
Make_Class_Wide_Type (T);
Set_Entity (N, Class_Wide_Type (T));
Set_Etype (N, Class_Wide_Type (T));
elsif Ekind (T) = E_Private_Type
and then not Is_Generic_Type (T)
and then In_Private_Part (Scope (T))
then
-- The Class attribute can be applied to an untagged private
-- type fulfilled by a tagged type prior to the full type
-- declaration (but only within the parent package's private
-- part). Create the class-wide type now and check that the
-- full type is tagged later during its analysis. Note that
-- we do not mark the private type as tagged, unlike the
-- case of incomplete types, because the type must still
-- appear untagged to outside units.
if No (Class_Wide_Type (T)) then
Make_Class_Wide_Type (T);
end if;
Set_Entity (N, Class_Wide_Type (T));
Set_Etype (N, Class_Wide_Type (T));
else
-- Should we introduce a type Any_Tagged and use Wrong_Type
-- here, it would be a bit more consistent???
Error_Msg_NE
("tagged type required, found}",
Prefix (N), First_Subtype (T));
Set_Entity (N, Any_Type);
return;
end if;
-- Case of tagged type
else
if Is_Concurrent_Type (T) then
if No (Corresponding_Record_Type (Entity (Prefix (N)))) then
-- Previous error. Create a class-wide type for the
-- synchronized type itself, with minimal semantic
-- attributes, to catch other errors in some ACATS tests.
pragma Assert (Serious_Errors_Detected /= 0);
Make_Class_Wide_Type (T);
C := Class_Wide_Type (T);
Set_First_Entity (C, First_Entity (T));
else
C := Class_Wide_Type
(Corresponding_Record_Type (Entity (Prefix (N))));
end if;
else
C := Class_Wide_Type (Entity (Prefix (N)));
end if;
Set_Entity_With_Checks (N, C);
Generate_Reference (C, N);
Set_Etype (N, C);
end if;
-- Base attribute, not allowed in Ada 83
elsif Attribute_Name (N) = Name_Base then
if Ada_Version = Ada_83 and then Comes_From_Source (N) then
Error_Msg_N
("(Ada 83) Base attribute not allowed in subtype mark", N);
else
Find_Type (Prefix (N));
Typ := Entity (Prefix (N));
if Ada_Version >= Ada_95
and then not Is_Scalar_Type (Typ)
and then not Is_Generic_Type (Typ)
then
Error_Msg_N
("prefix of Base attribute must be scalar type",
Prefix (N));
elsif Warn_On_Redundant_Constructs
and then Base_Type (Typ) = Typ
then
Error_Msg_NE -- CODEFIX
("redundant attribute, & is its own base type?r?", N, Typ);
end if;
T := Base_Type (Typ);
-- Rewrite attribute reference with type itself (see similar
-- processing in Analyze_Attribute, case Base). Preserve prefix
-- if present, for other legality checks.
if Nkind (Prefix (N)) = N_Expanded_Name then
Rewrite (N,
Make_Expanded_Name (Sloc (N),
Chars => Chars (T),
Prefix => New_Copy (Prefix (Prefix (N))),
Selector_Name => New_Occurrence_Of (T, Sloc (N))));
else
Rewrite (N, New_Occurrence_Of (T, Sloc (N)));
end if;
Set_Entity (N, T);
Set_Etype (N, T);
end if;
elsif Attribute_Name (N) = Name_Stub_Type then
-- This is handled in Analyze_Attribute
Analyze (N);
-- All other attributes are invalid in a subtype mark
else
Error_Msg_N ("invalid attribute in subtype mark", N);
end if;
else
Analyze (N);
if Is_Entity_Name (N) then
T_Name := Entity (N);
else
Error_Msg_N ("subtype mark required in this context", N);
Set_Etype (N, Any_Type);
return;
end if;
if T_Name = Any_Id or else Etype (N) = Any_Type then
-- Undefined id. Make it into a valid type
Set_Entity (N, Any_Type);
elsif not Is_Type (T_Name)
and then T_Name /= Standard_Void_Type
then
Error_Msg_Sloc := Sloc (T_Name);
Error_Msg_N ("subtype mark required in this context", N);
Error_Msg_NE ("\\found & declared#", N, T_Name);
Set_Entity (N, Any_Type);
else
-- If the type is an incomplete type created to handle
-- anonymous access components of a record type, then the
-- incomplete type is the visible entity and subsequent
-- references will point to it. Mark the original full
-- type as referenced, to prevent spurious warnings.
if Is_Incomplete_Type (T_Name)
and then Present (Full_View (T_Name))
and then not Comes_From_Source (T_Name)
then
Set_Referenced (Full_View (T_Name));
end if;
T_Name := Get_Full_View (T_Name);
-- Ada 2005 (AI-251, AI-50217): Handle interfaces visible through
-- limited-with clauses
if From_Limited_With (T_Name)
and then Is_Incomplete_Type (T_Name)
and then Present (Non_Limited_View (T_Name))
and then Is_Interface (Non_Limited_View (T_Name))
then
T_Name := Non_Limited_View (T_Name);
end if;
if In_Open_Scopes (T_Name) then
if Ekind (Base_Type (T_Name)) = E_Task_Type then
-- In Ada 2005, a task name can be used in an access
-- definition within its own body.
if Ada_Version >= Ada_2005
and then Nkind (Parent (N)) = N_Access_Definition
then
Set_Entity (N, T_Name);
Set_Etype (N, T_Name);
return;
else
Error_Msg_N
("task type cannot be used as type mark " &
"within its own spec or body", N);
end if;
elsif Ekind (Base_Type (T_Name)) = E_Protected_Type then
-- In Ada 2005, a protected name can be used in an access
-- definition within its own body.
if Ada_Version >= Ada_2005
and then Nkind (Parent (N)) = N_Access_Definition
then
Set_Entity (N, T_Name);
Set_Etype (N, T_Name);
return;
else
Error_Msg_N
("protected type cannot be used as type mark " &
"within its own spec or body", N);
end if;
else
Error_Msg_N ("type declaration cannot refer to itself", N);
end if;
Set_Etype (N, Any_Type);
Set_Entity (N, Any_Type);
Set_Error_Posted (T_Name);
return;
end if;
Set_Entity (N, T_Name);
Set_Etype (N, T_Name);
end if;
end if;
if Present (Etype (N)) and then Comes_From_Source (N) then
if Is_Fixed_Point_Type (Etype (N)) then
Check_Restriction (No_Fixed_Point, N);
elsif Is_Floating_Point_Type (Etype (N)) then
Check_Restriction (No_Floating_Point, N);
end if;
-- A Ghost type must appear in a specific context
if Is_Ghost_Entity (Etype (N)) then
Check_Ghost_Context (Etype (N), N);
end if;
end if;
end Find_Type;
--------------------
-- Has_Components --
--------------------
function Has_Components (Typ : Entity_Id) return Boolean is
begin
return Is_Record_Type (Typ)
or else (Is_Private_Type (Typ) and then Has_Discriminants (Typ))
or else (Is_Task_Type (Typ) and then Has_Discriminants (Typ))
or else (Is_Incomplete_Type (Typ)
and then From_Limited_With (Typ)
and then Is_Record_Type (Available_View (Typ)));
end Has_Components;
------------------------------------
-- Has_Implicit_Character_Literal --
------------------------------------
function Has_Implicit_Character_Literal (N : Node_Id) return Boolean is
Id : Entity_Id;
Found : Boolean := False;
P : constant Entity_Id := Entity (Prefix (N));
Priv_Id : Entity_Id := Empty;
begin
if Ekind (P) = E_Package and then not In_Open_Scopes (P) then
Priv_Id := First_Private_Entity (P);
end if;
if P = Standard_Standard then
Change_Selected_Component_To_Expanded_Name (N);
Rewrite (N, Selector_Name (N));
Analyze (N);
Set_Etype (Original_Node (N), Standard_Character);
return True;
end if;
Id := First_Entity (P);
while Present (Id) and then Id /= Priv_Id loop
if Is_Standard_Character_Type (Id) and then Is_Base_Type (Id) then
-- We replace the node with the literal itself, resolve as a
-- character, and set the type correctly.
if not Found then
Change_Selected_Component_To_Expanded_Name (N);
Rewrite (N, Selector_Name (N));
Analyze (N);
Set_Etype (N, Id);
Set_Etype (Original_Node (N), Id);
Found := True;
else
-- More than one type derived from Character in given scope.
-- Collect all possible interpretations.
Add_One_Interp (N, Id, Id);
end if;
end if;
Next_Entity (Id);
end loop;
return Found;
end Has_Implicit_Character_Literal;
----------------------
-- Has_Private_With --
----------------------
function Has_Private_With (E : Entity_Id) return Boolean is
Comp_Unit : constant Node_Id := Cunit (Current_Sem_Unit);
Item : Node_Id;
begin
Item := First (Context_Items (Comp_Unit));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then Private_Present (Item)
and then Entity (Name (Item)) = E
then
return True;
end if;
Next (Item);
end loop;
return False;
end Has_Private_With;
---------------------------
-- Has_Implicit_Operator --
---------------------------
function Has_Implicit_Operator (N : Node_Id) return Boolean is
Op_Id : constant Name_Id := Chars (Selector_Name (N));
P : constant Entity_Id := Entity (Prefix (N));
Id : Entity_Id;
Priv_Id : Entity_Id := Empty;
procedure Add_Implicit_Operator
(T : Entity_Id;
Op_Type : Entity_Id := Empty);
-- Add implicit interpretation to node N, using the type for which a
-- predefined operator exists. If the operator yields a boolean type,
-- the Operand_Type is implicitly referenced by the operator, and a
-- reference to it must be generated.
---------------------------
-- Add_Implicit_Operator --
---------------------------
procedure Add_Implicit_Operator
(T : Entity_Id;
Op_Type : Entity_Id := Empty)
is
Predef_Op : Entity_Id;
begin
Predef_Op := Current_Entity (Selector_Name (N));
while Present (Predef_Op)
and then Scope (Predef_Op) /= Standard_Standard
loop
Predef_Op := Homonym (Predef_Op);
end loop;
if Nkind (N) = N_Selected_Component then
Change_Selected_Component_To_Expanded_Name (N);
end if;
-- If the context is an unanalyzed function call, determine whether
-- a binary or unary interpretation is required.
if Nkind (Parent (N)) = N_Indexed_Component then
declare
Is_Binary_Call : constant Boolean :=
Present
(Next (First (Expressions (Parent (N)))));
Is_Binary_Op : constant Boolean :=
First_Entity
(Predef_Op) /= Last_Entity (Predef_Op);
Predef_Op2 : constant Entity_Id := Homonym (Predef_Op);
begin
if Is_Binary_Call then
if Is_Binary_Op then
Add_One_Interp (N, Predef_Op, T);
else
Add_One_Interp (N, Predef_Op2, T);
end if;
else
if not Is_Binary_Op then
Add_One_Interp (N, Predef_Op, T);
-- Predef_Op2 may be empty in case of previous errors
elsif Present (Predef_Op2) then
Add_One_Interp (N, Predef_Op2, T);
end if;
end if;
end;
else
Add_One_Interp (N, Predef_Op, T);
-- For operators with unary and binary interpretations, if
-- context is not a call, add both
if Present (Homonym (Predef_Op)) then
Add_One_Interp (N, Homonym (Predef_Op), T);
end if;
end if;
-- The node is a reference to a predefined operator, and
-- an implicit reference to the type of its operands.
if Present (Op_Type) then
Generate_Operator_Reference (N, Op_Type);
else
Generate_Operator_Reference (N, T);
end if;
end Add_Implicit_Operator;
-- Start of processing for Has_Implicit_Operator
begin
if Ekind (P) = E_Package and then not In_Open_Scopes (P) then
Priv_Id := First_Private_Entity (P);
end if;
Id := First_Entity (P);
case Op_Id is
-- Boolean operators: an implicit declaration exists if the scope
-- contains a declaration for a derived Boolean type, or for an
-- array of Boolean type.
when Name_Op_And
| Name_Op_Not
| Name_Op_Or
| Name_Op_Xor
=>
while Id /= Priv_Id loop
if Valid_Boolean_Arg (Id) and then Is_Base_Type (Id) then
Add_Implicit_Operator (Id);
return True;
end if;
Next_Entity (Id);
end loop;
-- Equality: look for any non-limited type (result is Boolean)
when Name_Op_Eq
| Name_Op_Ne
=>
while Id /= Priv_Id loop
if Is_Type (Id)
and then not Is_Limited_Type (Id)
and then Is_Base_Type (Id)
then
Add_Implicit_Operator (Standard_Boolean, Id);
return True;
end if;
Next_Entity (Id);
end loop;
-- Comparison operators: scalar type, or array of scalar
when Name_Op_Ge
| Name_Op_Gt
| Name_Op_Le
| Name_Op_Lt
=>
while Id /= Priv_Id loop
if (Is_Scalar_Type (Id)
or else (Is_Array_Type (Id)
and then Is_Scalar_Type (Component_Type (Id))))
and then Is_Base_Type (Id)
then
Add_Implicit_Operator (Standard_Boolean, Id);
return True;
end if;
Next_Entity (Id);
end loop;
-- Arithmetic operators: any numeric type
when Name_Op_Abs
| Name_Op_Add
| Name_Op_Divide
| Name_Op_Expon
| Name_Op_Mod
| Name_Op_Multiply
| Name_Op_Rem
| Name_Op_Subtract
=>
while Id /= Priv_Id loop
if Is_Numeric_Type (Id) and then Is_Base_Type (Id) then
Add_Implicit_Operator (Id);
return True;
end if;
Next_Entity (Id);
end loop;
-- Concatenation: any one-dimensional array type
when Name_Op_Concat =>
while Id /= Priv_Id loop
if Is_Array_Type (Id)
and then Number_Dimensions (Id) = 1
and then Is_Base_Type (Id)
then
Add_Implicit_Operator (Id);
return True;
end if;
Next_Entity (Id);
end loop;
-- What is the others condition here? Should we be using a
-- subtype of Name_Id that would restrict to operators ???
when others =>
null;
end case;
-- If we fall through, then we do not have an implicit operator
return False;
end Has_Implicit_Operator;
-----------------------------------
-- Has_Loop_In_Inner_Open_Scopes --
-----------------------------------
function Has_Loop_In_Inner_Open_Scopes (S : Entity_Id) return Boolean is
begin
-- Several scope stacks are maintained by Scope_Stack. The base of the
-- currently active scope stack is denoted by the Is_Active_Stack_Base
-- flag in the scope stack entry. Note that the scope stacks used to
-- simply be delimited implicitly by the presence of Standard_Standard
-- at their base, but there now are cases where this is not sufficient
-- because Standard_Standard actually may appear in the middle of the
-- active set of scopes.
for J in reverse 0 .. Scope_Stack.Last loop
-- S was reached without seing a loop scope first
if Scope_Stack.Table (J).Entity = S then
return False;
-- S was not yet reached, so it contains at least one inner loop
elsif Ekind (Scope_Stack.Table (J).Entity) = E_Loop then
return True;
end if;
-- Check Is_Active_Stack_Base to tell us when to stop, as there are
-- cases where Standard_Standard appears in the middle of the active
-- set of scopes. This affects the declaration and overriding of
-- private inherited operations in instantiations of generic child
-- units.
pragma Assert (not Scope_Stack.Table (J).Is_Active_Stack_Base);
end loop;
raise Program_Error; -- unreachable
end Has_Loop_In_Inner_Open_Scopes;
--------------------
-- In_Open_Scopes --
--------------------
function In_Open_Scopes (S : Entity_Id) return Boolean is
begin
-- Several scope stacks are maintained by Scope_Stack. The base of the
-- currently active scope stack is denoted by the Is_Active_Stack_Base
-- flag in the scope stack entry. Note that the scope stacks used to
-- simply be delimited implicitly by the presence of Standard_Standard
-- at their base, but there now are cases where this is not sufficient
-- because Standard_Standard actually may appear in the middle of the
-- active set of scopes.
for J in reverse 0 .. Scope_Stack.Last loop
if Scope_Stack.Table (J).Entity = S then
return True;
end if;
-- Check Is_Active_Stack_Base to tell us when to stop, as there are
-- cases where Standard_Standard appears in the middle of the active
-- set of scopes. This affects the declaration and overriding of
-- private inherited operations in instantiations of generic child
-- units.
exit when Scope_Stack.Table (J).Is_Active_Stack_Base;
end loop;
return False;
end In_Open_Scopes;
-----------------------------
-- Inherit_Renamed_Profile --
-----------------------------
procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id) is
New_F : Entity_Id;
Old_F : Entity_Id;
Old_T : Entity_Id;
New_T : Entity_Id;
begin
if Ekind (Old_S) = E_Operator then
New_F := First_Formal (New_S);
while Present (New_F) loop
Set_Etype (New_F, Base_Type (Etype (New_F)));
Next_Formal (New_F);
end loop;
Set_Etype (New_S, Base_Type (Etype (New_S)));
else
New_F := First_Formal (New_S);
Old_F := First_Formal (Old_S);
while Present (New_F) loop
New_T := Etype (New_F);
Old_T := Etype (Old_F);
-- If the new type is a renaming of the old one, as is the case
-- for actuals in instances, retain its name, to simplify later
-- disambiguation.
if Nkind (Parent (New_T)) = N_Subtype_Declaration
and then Is_Entity_Name (Subtype_Indication (Parent (New_T)))
and then Entity (Subtype_Indication (Parent (New_T))) = Old_T
then
null;
else
Set_Etype (New_F, Old_T);
end if;
Next_Formal (New_F);
Next_Formal (Old_F);
end loop;
pragma Assert (No (Old_F));
if Ekind (Old_S) in E_Function | E_Enumeration_Literal then
Set_Etype (New_S, Etype (Old_S));
end if;
end if;
end Inherit_Renamed_Profile;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Urefs.Init;
end Initialize;
-------------------------
-- Install_Use_Clauses --
-------------------------
procedure Install_Use_Clauses
(Clause : Node_Id;
Force_Installation : Boolean := False)
is
U : Node_Id;
begin
U := Clause;
while Present (U) loop
-- Case of USE package
if Nkind (U) = N_Use_Package_Clause then
Use_One_Package (U, Name (U), True);
-- Case of USE TYPE
else
Use_One_Type (Subtype_Mark (U), Force => Force_Installation);
end if;
Next_Use_Clause (U);
end loop;
end Install_Use_Clauses;
----------------------
-- Mark_Use_Clauses --
----------------------
procedure Mark_Use_Clauses (Id : Node_Or_Entity_Id) is
procedure Mark_Parameters (Call : Entity_Id);
-- Perform use_type_clause marking for all parameters in a subprogram
-- or operator call.
procedure Mark_Use_Package (Pak : Entity_Id);
-- Move up the Prev_Use_Clause chain for packages denoted by Pak -
-- marking each clause in the chain as effective in the process.
procedure Mark_Use_Type (E : Entity_Id);
-- Similar to Do_Use_Package_Marking except we move up the
-- Prev_Use_Clause chain for the type denoted by E.
---------------------
-- Mark_Parameters --
---------------------
procedure Mark_Parameters (Call : Entity_Id) is
Curr : Node_Id;
begin
-- Move through all of the formals
Curr := First_Formal (Call);
while Present (Curr) loop
Mark_Use_Type (Curr);
Next_Formal (Curr);
end loop;
-- Handle the return type
Mark_Use_Type (Call);
end Mark_Parameters;
----------------------
-- Mark_Use_Package --
----------------------
procedure Mark_Use_Package (Pak : Entity_Id) is
Curr : Node_Id;
begin
-- Ignore cases where the scope of the type is not a package (e.g.
-- Standard_Standard).
if Ekind (Pak) /= E_Package then
return;
end if;
Curr := Current_Use_Clause (Pak);
while Present (Curr)
and then not Is_Effective_Use_Clause (Curr)
loop
-- We need to mark the previous use clauses as effective, but
-- each use clause may in turn render other use_package_clauses
-- effective. Additionally, it is possible to have a parent
-- package renamed as a child of itself so we must check the
-- prefix entity is not the same as the package we are marking.
if Nkind (Name (Curr)) /= N_Identifier
and then Present (Prefix (Name (Curr)))
and then Entity (Prefix (Name (Curr))) /= Pak
then
Mark_Use_Package (Entity (Prefix (Name (Curr))));
-- It is also possible to have a child package without a prefix
-- that relies on a previous use_package_clause.
elsif Nkind (Name (Curr)) = N_Identifier
and then Is_Child_Unit (Entity (Name (Curr)))
then
Mark_Use_Package (Scope (Entity (Name (Curr))));
end if;
-- Mark the use_package_clause as effective and move up the chain
Set_Is_Effective_Use_Clause (Curr);
Curr := Prev_Use_Clause (Curr);
end loop;
end Mark_Use_Package;
-------------------
-- Mark_Use_Type --
-------------------
procedure Mark_Use_Type (E : Entity_Id) is
Curr : Node_Id;
Base : Entity_Id;
begin
-- Ignore void types and unresolved string literals and primitives
if Nkind (E) = N_String_Literal
or else Nkind (Etype (E)) not in N_Entity
or else not Is_Type (Etype (E))
then
return;
end if;
-- Primitives with class-wide operands might additionally render
-- their base type's use_clauses effective - so do a recursive check
-- here.
Base := Base_Type (Etype (E));
if Ekind (Base) = E_Class_Wide_Type then
Mark_Use_Type (Base);
end if;
-- The package containing the type or operator function being used
-- may be in use as well, so mark any use_package_clauses for it as
-- effective. There are also additional sanity checks performed here
-- for ignoring previous errors.
Mark_Use_Package (Scope (Base));
if Nkind (E) in N_Op
and then Present (Entity (E))
and then Present (Scope (Entity (E)))
then
Mark_Use_Package (Scope (Entity (E)));
end if;
Curr := Current_Use_Clause (Base);
while Present (Curr)
and then not Is_Effective_Use_Clause (Curr)
loop
-- Current use_type_clause may render other use_package_clauses
-- effective.
if Nkind (Subtype_Mark (Curr)) /= N_Identifier
and then Present (Prefix (Subtype_Mark (Curr)))
then
Mark_Use_Package (Entity (Prefix (Subtype_Mark (Curr))));
end if;
-- Mark the use_type_clause as effective and move up the chain
Set_Is_Effective_Use_Clause (Curr);
Curr := Prev_Use_Clause (Curr);
end loop;
end Mark_Use_Type;
-- Start of processing for Mark_Use_Clauses
begin
-- Use clauses in and of themselves do not count as a "use" of a
-- package.
if Nkind (Parent (Id)) in N_Use_Package_Clause | N_Use_Type_Clause then
return;
end if;
-- Handle entities
if Nkind (Id) in N_Entity then
-- Mark the entity's package
if Is_Potentially_Use_Visible (Id) then
Mark_Use_Package (Scope (Id));
end if;
-- Mark enumeration literals
if Ekind (Id) = E_Enumeration_Literal then
Mark_Use_Type (Id);
-- Mark primitives
elsif (Is_Overloadable (Id)
or else Is_Generic_Subprogram (Id))
and then (Is_Potentially_Use_Visible (Id)
or else Is_Intrinsic_Subprogram (Id)
or else (Ekind (Id) in E_Function | E_Procedure
and then Is_Generic_Actual_Subprogram (Id)))
then
Mark_Parameters (Id);
end if;
-- Handle nodes
else
-- Mark operators
if Nkind (Id) in N_Op then
-- At this point the left operand may not be resolved if we are
-- encountering multiple operators next to eachother in an
-- expression.
if Nkind (Id) in N_Binary_Op
and then not (Nkind (Left_Opnd (Id)) in N_Op)
then
Mark_Use_Type (Left_Opnd (Id));
end if;
Mark_Use_Type (Right_Opnd (Id));
Mark_Use_Type (Id);
-- Mark entity identifiers
elsif Nkind (Id) in N_Has_Entity
and then (Is_Potentially_Use_Visible (Entity (Id))
or else (Is_Generic_Instance (Entity (Id))
and then Is_Immediately_Visible (Entity (Id))))
then
-- Ignore fully qualified names as they do not count as a "use" of
-- a package.
if Nkind (Id) in N_Identifier | N_Operator_Symbol
or else (Present (Prefix (Id))
and then Scope (Entity (Id)) /= Entity (Prefix (Id)))
then
Mark_Use_Clauses (Entity (Id));
end if;
end if;
end if;
end Mark_Use_Clauses;
--------------------------------
-- Most_Descendant_Use_Clause --
--------------------------------
function Most_Descendant_Use_Clause
(Clause1 : Entity_Id;
Clause2 : Entity_Id) return Entity_Id
is
Scope1 : Entity_Id;
Scope2 : Entity_Id;
begin
if Clause1 = Clause2 then
return Clause1;
end if;
-- We determine which one is the most descendant by the scope distance
-- to the ultimate parent unit.
Scope1 := Entity_Of_Unit (Unit (Parent (Clause1)));
Scope2 := Entity_Of_Unit (Unit (Parent (Clause2)));
while Scope1 /= Standard_Standard
and then Scope2 /= Standard_Standard
loop
Scope1 := Scope (Scope1);
Scope2 := Scope (Scope2);
if not Present (Scope1) then
return Clause1;
elsif not Present (Scope2) then
return Clause2;
end if;
end loop;
if Scope1 = Standard_Standard then
return Clause1;
end if;
return Clause2;
end Most_Descendant_Use_Clause;
---------------
-- Pop_Scope --
---------------
procedure Pop_Scope is
SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
S : constant Entity_Id := SST.Entity;
begin
if Debug_Flag_E then
Write_Info;
end if;
-- Set Default_Storage_Pool field of the library unit if necessary
if Is_Package_Or_Generic_Package (S)
and then
Nkind (Parent (Unit_Declaration_Node (S))) = N_Compilation_Unit
then
declare
Aux : constant Node_Id :=
Aux_Decls_Node (Parent (Unit_Declaration_Node (S)));
begin
if No (Default_Storage_Pool (Aux)) then
Set_Default_Storage_Pool (Aux, Default_Pool);
end if;
end;
end if;
Scope_Suppress := SST.Save_Scope_Suppress;
Local_Suppress_Stack_Top := SST.Save_Local_Suppress_Stack_Top;
Check_Policy_List := SST.Save_Check_Policy_List;
Default_Pool := SST.Save_Default_Storage_Pool;
No_Tagged_Streams := SST.Save_No_Tagged_Streams;
SPARK_Mode := SST.Save_SPARK_Mode;
SPARK_Mode_Pragma := SST.Save_SPARK_Mode_Pragma;
Default_SSO := SST.Save_Default_SSO;
Uneval_Old := SST.Save_Uneval_Old;
if Debug_Flag_W then
Write_Str ("<-- exiting scope: ");
Write_Name (Chars (Current_Scope));
Write_Str (", Depth=");
Write_Int (Int (Scope_Stack.Last));
Write_Eol;
end if;
End_Use_Clauses (SST.First_Use_Clause);
-- If the actions to be wrapped are still there they will get lost
-- causing incomplete code to be generated. It is better to abort in
-- this case (and we do the abort even with assertions off since the
-- penalty is incorrect code generation).
if SST.Actions_To_Be_Wrapped /= Scope_Actions'(others => No_List) then
raise Program_Error;
end if;
-- Free last subprogram name if allocated, and pop scope
Free (SST.Last_Subprogram_Name);
Scope_Stack.Decrement_Last;
end Pop_Scope;
----------------
-- Push_Scope --
----------------
procedure Push_Scope (S : Entity_Id) is
E : constant Entity_Id := Scope (S);
function Component_Alignment_Default return Component_Alignment_Kind;
-- Return Component_Alignment_Kind for the newly-pushed scope.
function Component_Alignment_Default return Component_Alignment_Kind is
begin
-- Each new scope pushed onto the scope stack inherits the component
-- alignment of the previous scope. This emulates the "visibility"
-- semantics of pragma Component_Alignment.
if Scope_Stack.Last > Scope_Stack.First then
return Scope_Stack.Table
(Scope_Stack.Last - 1).Component_Alignment_Default;
-- Otherwise, this is the first scope being pushed on the scope
-- stack. Inherit the component alignment from the configuration
-- form of pragma Component_Alignment (if any).
else
return Configuration_Component_Alignment;
end if;
end Component_Alignment_Default;
begin
if Ekind (S) = E_Void then
null;
-- Set scope depth if not a nonconcurrent type, and we have not yet set
-- the scope depth. This means that we have the first occurrence of the
-- scope, and this is where the depth is set.
elsif (not Is_Type (S) or else Is_Concurrent_Type (S))
and then not Scope_Depth_Set (S)
then
if S = Standard_Standard then
Set_Scope_Depth_Value (S, Uint_0);
elsif Is_Child_Unit (S) then
Set_Scope_Depth_Value (S, Uint_1);
elsif not Is_Record_Type (Current_Scope) then
if Scope_Depth_Set (Current_Scope) then
if Ekind (S) = E_Loop then
Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope));
else
Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope) + 1);
end if;
end if;
end if;
end if;
Scope_Stack.Increment_Last;
Scope_Stack.Table (Scope_Stack.Last) :=
(Entity => S,
Save_Scope_Suppress => Scope_Suppress,
Save_Local_Suppress_Stack_Top => Local_Suppress_Stack_Top,
Save_Check_Policy_List => Check_Policy_List,
Save_Default_Storage_Pool => Default_Pool,
Save_No_Tagged_Streams => No_Tagged_Streams,
Save_SPARK_Mode => SPARK_Mode,
Save_SPARK_Mode_Pragma => SPARK_Mode_Pragma,
Save_Default_SSO => Default_SSO,
Save_Uneval_Old => Uneval_Old,
Component_Alignment_Default => Component_Alignment_Default,
Last_Subprogram_Name => null,
Is_Transient => False,
Node_To_Be_Wrapped => Empty,
Pending_Freeze_Actions => No_List,
Actions_To_Be_Wrapped => (others => No_List),
First_Use_Clause => Empty,
Is_Active_Stack_Base => False,
Previous_Visibility => False,
Locked_Shared_Objects => No_Elist);
if Debug_Flag_W then
Write_Str ("--> new scope: ");
Write_Name (Chars (Current_Scope));
Write_Str (", Id=");
Write_Int (Int (Current_Scope));
Write_Str (", Depth=");
Write_Int (Int (Scope_Stack.Last));
Write_Eol;
end if;
-- Deal with copying flags from the previous scope to this one. This is
-- not necessary if either scope is standard, or if the new scope is a
-- child unit.
if S /= Standard_Standard
and then Scope (S) /= Standard_Standard
and then not Is_Child_Unit (S)
then
if Nkind (E) not in N_Entity then
return;
end if;
-- Copy categorization flags from Scope (S) to S, this is not done
-- when Scope (S) is Standard_Standard since propagation is from
-- library unit entity inwards. Copy other relevant attributes as
-- well (Discard_Names in particular).
-- We only propagate inwards for library level entities,
-- inner level subprograms do not inherit the categorization.
if Is_Library_Level_Entity (S) then
Set_Is_Preelaborated (S, Is_Preelaborated (E));
Set_Is_Shared_Passive (S, Is_Shared_Passive (E));
Set_Discard_Names (S, Discard_Names (E));
Set_Suppress_Value_Tracking_On_Call
(S, Suppress_Value_Tracking_On_Call (E));
Set_Categorization_From_Scope (E => S, Scop => E);
end if;
end if;
if Is_Child_Unit (S)
and then Present (E)
and then Is_Package_Or_Generic_Package (E)
and then
Nkind (Parent (Unit_Declaration_Node (E))) = N_Compilation_Unit
then
declare
Aux : constant Node_Id :=
Aux_Decls_Node (Parent (Unit_Declaration_Node (E)));
begin
if Present (Default_Storage_Pool (Aux)) then
Default_Pool := Default_Storage_Pool (Aux);
end if;
end;
end if;
end Push_Scope;
---------------------
-- Premature_Usage --
---------------------
procedure Premature_Usage (N : Node_Id) is
Kind : constant Node_Kind := Nkind (Parent (Entity (N)));
E : Entity_Id := Entity (N);
begin
-- Within an instance, the analysis of the actual for a formal object
-- does not see the name of the object itself. This is significant only
-- if the object is an aggregate, where its analysis does not do any
-- name resolution on component associations. (see 4717-008). In such a
-- case, look for the visible homonym on the chain.
if In_Instance and then Present (Homonym (E)) then
E := Homonym (E);
while Present (E) and then not In_Open_Scopes (Scope (E)) loop
E := Homonym (E);
end loop;
if Present (E) then
Set_Entity (N, E);
Set_Etype (N, Etype (E));
return;
end if;
end if;
case Kind is
when N_Component_Declaration =>
Error_Msg_N
("component&! cannot be used before end of record declaration",
N);
when N_Parameter_Specification =>
Error_Msg_N
("formal parameter&! cannot be used before end of specification",
N);
when N_Discriminant_Specification =>
Error_Msg_N
("discriminant&! cannot be used before end of discriminant part",
N);
when N_Procedure_Specification | N_Function_Specification =>
Error_Msg_N
("subprogram&! cannot be used before end of its declaration",
N);
when N_Full_Type_Declaration | N_Subtype_Declaration =>
Error_Msg_N
("type& cannot be used before end of its declaration!", N);
when others =>
Error_Msg_N
("object& cannot be used before end of its declaration!", N);
-- If the premature reference appears as the expression in its own
-- declaration, rewrite it to prevent compiler loops in subsequent
-- uses of this mangled declaration in address clauses.
if Nkind (Parent (N)) = N_Object_Declaration then
Set_Entity (N, Any_Id);
end if;
end case;
end Premature_Usage;
------------------------
-- Present_System_Aux --
------------------------
function Present_System_Aux (N : Node_Id := Empty) return Boolean is
Loc : Source_Ptr;
Aux_Name : Unit_Name_Type;
Unum : Unit_Number_Type;
Withn : Node_Id;
With_Sys : Node_Id;
The_Unit : Node_Id;
function Find_System (C_Unit : Node_Id) return Entity_Id;
-- Scan context clause of compilation unit to find with_clause
-- for System.
-----------------
-- Find_System --
-----------------
function Find_System (C_Unit : Node_Id) return Entity_Id is
With_Clause : Node_Id;
begin
With_Clause := First (Context_Items (C_Unit));
while Present (With_Clause) loop
if (Nkind (With_Clause) = N_With_Clause
and then Chars (Name (With_Clause)) = Name_System)
and then Comes_From_Source (With_Clause)
then
return With_Clause;
end if;
Next (With_Clause);
end loop;
return Empty;
end Find_System;
-- Start of processing for Present_System_Aux
begin
-- The child unit may have been loaded and analyzed already
if Present (System_Aux_Id) then
return True;
-- If no previous pragma for System.Aux, nothing to load
elsif No (System_Extend_Unit) then
return False;
-- Use the unit name given in the pragma to retrieve the unit.
-- Verify that System itself appears in the context clause of the
-- current compilation. If System is not present, an error will
-- have been reported already.
else
With_Sys := Find_System (Cunit (Current_Sem_Unit));
The_Unit := Unit (Cunit (Current_Sem_Unit));
if No (With_Sys)
and then
(Nkind (The_Unit) = N_Package_Body
or else (Nkind (The_Unit) = N_Subprogram_Body
and then not Acts_As_Spec (Cunit (Current_Sem_Unit))))
then
With_Sys := Find_System (Library_Unit (Cunit (Current_Sem_Unit)));
end if;
if No (With_Sys) and then Present (N) then
-- If we are compiling a subunit, we need to examine its
-- context as well (Current_Sem_Unit is the parent unit);
The_Unit := Parent (N);
while Nkind (The_Unit) /= N_Compilation_Unit loop
The_Unit := Parent (The_Unit);
end loop;
if Nkind (Unit (The_Unit)) = N_Subunit then
With_Sys := Find_System (The_Unit);
end if;
end if;
if No (With_Sys) then
return False;
end if;
Loc := Sloc (With_Sys);
Get_Name_String (Chars (Expression (System_Extend_Unit)));
Name_Buffer (8 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
Name_Buffer (1 .. 7) := "system.";
Name_Buffer (Name_Len + 8) := '%';
Name_Buffer (Name_Len + 9) := 's';
Name_Len := Name_Len + 9;
Aux_Name := Name_Find;
Unum :=
Load_Unit
(Load_Name => Aux_Name,
Required => False,
Subunit => False,
Error_Node => With_Sys);
if Unum /= No_Unit then
Semantics (Cunit (Unum));
System_Aux_Id :=
Defining_Entity (Specification (Unit (Cunit (Unum))));
Withn :=
Make_With_Clause (Loc,
Name =>
Make_Expanded_Name (Loc,
Chars => Chars (System_Aux_Id),
Prefix =>
New_Occurrence_Of (Scope (System_Aux_Id), Loc),
Selector_Name => New_Occurrence_Of (System_Aux_Id, Loc)));
Set_Entity (Name (Withn), System_Aux_Id);
Set_Corresponding_Spec (Withn, System_Aux_Id);
Set_First_Name (Withn);
Set_Implicit_With (Withn);
Set_Library_Unit (Withn, Cunit (Unum));
Insert_After (With_Sys, Withn);
Mark_Rewrite_Insertion (Withn);
Set_Context_Installed (Withn);
return True;
-- Here if unit load failed
else
Error_Msg_Name_1 := Name_System;
Error_Msg_Name_2 := Chars (Expression (System_Extend_Unit));
Error_Msg_N
("extension package `%.%` does not exist",
Opt.System_Extend_Unit);
return False;
end if;
end if;
end Present_System_Aux;
-------------------------
-- Restore_Scope_Stack --
-------------------------
procedure Restore_Scope_Stack
(List : Elist_Id;
Handle_Use : Boolean := True)
is
SS_Last : constant Int := Scope_Stack.Last;
Elmt : Elmt_Id;
begin
-- Restore visibility of previous scope stack, if any, using the list
-- we saved (we use Remove, since this list will not be used again).
loop
Elmt := Last_Elmt (List);
exit when Elmt = No_Elmt;
Set_Is_Immediately_Visible (Node (Elmt));
Remove_Last_Elmt (List);
end loop;
-- Restore use clauses
if SS_Last >= Scope_Stack.First
and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
and then Handle_Use
then
Install_Use_Clauses
(Scope_Stack.Table (SS_Last).First_Use_Clause,
Force_Installation => True);
end if;
end Restore_Scope_Stack;
----------------------
-- Save_Scope_Stack --
----------------------
-- Save_Scope_Stack/Restore_Scope_Stack were originally designed to avoid
-- consuming any memory. That is, Save_Scope_Stack took care of removing
-- from immediate visibility entities and Restore_Scope_Stack took care
-- of restoring their visibility analyzing the context of each entity. The
-- problem of such approach is that it was fragile and caused unexpected
-- visibility problems, and indeed one test was found where there was a
-- real problem.
-- Furthermore, the following experiment was carried out:
-- - Save_Scope_Stack was modified to store in an Elist1 all those
-- entities whose attribute Is_Immediately_Visible is modified
-- from True to False.
-- - Restore_Scope_Stack was modified to store in another Elist2
-- all the entities whose attribute Is_Immediately_Visible is
-- modified from False to True.
-- - Extra code was added to verify that all the elements of Elist1
-- are found in Elist2
-- This test shows that there may be more occurrences of this problem which
-- have not yet been detected. As a result, we replaced that approach by
-- the current one in which Save_Scope_Stack returns the list of entities
-- whose visibility is changed, and that list is passed to Restore_Scope_
-- Stack to undo that change. This approach is simpler and safer, although
-- it consumes more memory.
function Save_Scope_Stack (Handle_Use : Boolean := True) return Elist_Id is
Result : constant Elist_Id := New_Elmt_List;
E : Entity_Id;
S : Entity_Id;
SS_Last : constant Int := Scope_Stack.Last;
procedure Remove_From_Visibility (E : Entity_Id);
-- If E is immediately visible then append it to the result and remove
-- it temporarily from visibility.
----------------------------
-- Remove_From_Visibility --
----------------------------
procedure Remove_From_Visibility (E : Entity_Id) is
begin
if Is_Immediately_Visible (E) then
Append_Elmt (E, Result);
Set_Is_Immediately_Visible (E, False);
end if;
end Remove_From_Visibility;
-- Start of processing for Save_Scope_Stack
begin
if SS_Last >= Scope_Stack.First
and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
then
if Handle_Use then
End_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
end if;
-- If the call is from within a compilation unit, as when called from
-- Rtsfind, make current entries in scope stack invisible while we
-- analyze the new unit.
for J in reverse 0 .. SS_Last loop
exit when Scope_Stack.Table (J).Entity = Standard_Standard
or else No (Scope_Stack.Table (J).Entity);
S := Scope_Stack.Table (J).Entity;
Remove_From_Visibility (S);
E := First_Entity (S);
while Present (E) loop
Remove_From_Visibility (E);
Next_Entity (E);
end loop;
end loop;
end if;
return Result;
end Save_Scope_Stack;
-------------
-- Set_Use --
-------------
procedure Set_Use (L : List_Id) is
Decl : Node_Id;
begin
if Present (L) then
Decl := First (L);
while Present (Decl) loop
if Nkind (Decl) = N_Use_Package_Clause then
Chain_Use_Clause (Decl);
Use_One_Package (Decl, Name (Decl));
elsif Nkind (Decl) = N_Use_Type_Clause then
Chain_Use_Clause (Decl);
Use_One_Type (Subtype_Mark (Decl));
end if;
Next (Decl);
end loop;
end if;
end Set_Use;
-----------------------------
-- Update_Use_Clause_Chain --
-----------------------------
procedure Update_Use_Clause_Chain is
procedure Update_Chain_In_Scope (Level : Int);
-- Iterate through one level in the scope stack verifying each use-type
-- clause within said level is used then reset the Current_Use_Clause
-- to a redundant use clause outside of the current ending scope if such
-- a clause exists.
---------------------------
-- Update_Chain_In_Scope --
---------------------------
procedure Update_Chain_In_Scope (Level : Int) is
Curr : Node_Id;
N : Node_Id;
begin
-- Loop through all use clauses within the scope dictated by Level
Curr := Scope_Stack.Table (Level).First_Use_Clause;
while Present (Curr) loop
-- Retrieve the subtype mark or name within the current current
-- use clause.
if Nkind (Curr) = N_Use_Type_Clause then
N := Subtype_Mark (Curr);
else
N := Name (Curr);
end if;
-- If warnings for unreferenced entities are enabled and the
-- current use clause has not been marked effective.
if Check_Unreferenced
and then Comes_From_Source (Curr)
and then not Is_Effective_Use_Clause (Curr)
and then not In_Instance
and then not In_Inlined_Body
then
-- We are dealing with a potentially unused use_package_clause
if Nkind (Curr) = N_Use_Package_Clause then
-- Renamings and formal subprograms may cause the associated
-- node to be marked as effective instead of the original.
if not (Present (Associated_Node (N))
and then Present
(Current_Use_Clause
(Associated_Node (N)))
and then Is_Effective_Use_Clause
(Current_Use_Clause
(Associated_Node (N))))
then
Error_Msg_Node_1 := Entity (N);
Error_Msg_NE
("use clause for package & has no effect?u?",
Curr, Entity (N));
end if;
-- We are dealing with an unused use_type_clause
else
Error_Msg_Node_1 := Etype (N);
Error_Msg_NE
("use clause for } has no effect?u?", Curr, Etype (N));
end if;
end if;
-- Verify that we haven't already processed a redundant
-- use_type_clause within the same scope before we move the
-- current use clause up to a previous one for type T.
if Present (Prev_Use_Clause (Curr)) then
Set_Current_Use_Clause (Entity (N), Prev_Use_Clause (Curr));
end if;
Next_Use_Clause (Curr);
end loop;
end Update_Chain_In_Scope;
-- Start of processing for Update_Use_Clause_Chain
begin
Update_Chain_In_Scope (Scope_Stack.Last);
-- Deal with use clauses within the context area if the current
-- scope is a compilation unit.
if Is_Compilation_Unit (Current_Scope)
and then Sloc (Scope_Stack.Table
(Scope_Stack.Last - 1).Entity) = Standard_Location
then
Update_Chain_In_Scope (Scope_Stack.Last - 1);
end if;
end Update_Use_Clause_Chain;
---------------------
-- Use_One_Package --
---------------------
procedure Use_One_Package
(N : Node_Id;
Pack_Name : Entity_Id := Empty;
Force : Boolean := False)
is
procedure Note_Redundant_Use (Clause : Node_Id);
-- Mark the name in a use clause as redundant if the corresponding
-- entity is already use-visible. Emit a warning if the use clause comes
-- from source and the proper warnings are enabled.
------------------------
-- Note_Redundant_Use --
------------------------
procedure Note_Redundant_Use (Clause : Node_Id) is
Decl : constant Node_Id := Parent (Clause);
Pack_Name : constant Entity_Id := Entity (Clause);
Cur_Use : Node_Id := Current_Use_Clause (Pack_Name);
Prev_Use : Node_Id := Empty;
Redundant : Node_Id := Empty;
-- The Use_Clause which is actually redundant. In the simplest case
-- it is Pack itself, but when we compile a body we install its
-- context before that of its spec, in which case it is the
-- use_clause in the spec that will appear to be redundant, and we
-- want the warning to be placed on the body. Similar complications
-- appear when the redundancy is between a child unit and one of its
-- ancestors.
begin
-- Could be renamed...
if No (Cur_Use) then
Cur_Use := Current_Use_Clause (Renamed_Entity (Pack_Name));
end if;
Set_Redundant_Use (Clause, True);
-- Do not check for redundant use if clause is generated, or in an
-- instance, or in a predefined unit to avoid misleading warnings
-- that may occur as part of a rtsfind load.
if not Comes_From_Source (Clause)
or else In_Instance
or else not Warn_On_Redundant_Constructs
or else Is_Predefined_Unit (Current_Sem_Unit)
then
return;
end if;
if not Is_Compilation_Unit (Current_Scope) then
-- If the use_clause is in an inner scope, it is made redundant by
-- some clause in the current context, with one exception: If we
-- are compiling a nested package body, and the use_clause comes
-- from then corresponding spec, the clause is not necessarily
-- fully redundant, so we should not warn. If a warning was
-- warranted, it would have been given when the spec was
-- processed.
if Nkind (Parent (Decl)) = N_Package_Specification then
declare
Package_Spec_Entity : constant Entity_Id :=
Defining_Unit_Name (Parent (Decl));
begin
if In_Package_Body (Package_Spec_Entity) then
return;
end if;
end;
end if;
Redundant := Clause;
Prev_Use := Cur_Use;
elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then
declare
Cur_Unit : constant Unit_Number_Type :=
Get_Source_Unit (Cur_Use);
New_Unit : constant Unit_Number_Type :=
Get_Source_Unit (Clause);
Scop : Entity_Id;
begin
if Cur_Unit = New_Unit then
-- Redundant clause in same body
Redundant := Clause;
Prev_Use := Cur_Use;
elsif Cur_Unit = Current_Sem_Unit then
-- If the new clause is not in the current unit it has been
-- analyzed first, and it makes the other one redundant.
-- However, if the new clause appears in a subunit, Cur_Unit
-- is still the parent, and in that case the redundant one
-- is the one appearing in the subunit.
if Nkind (Unit (Cunit (New_Unit))) = N_Subunit then
Redundant := Clause;
Prev_Use := Cur_Use;
-- Most common case: redundant clause in body, original
-- clause in spec. Current scope is spec entity.
elsif Current_Scope = Cunit_Entity (Current_Sem_Unit) then
Redundant := Cur_Use;
Prev_Use := Clause;
else
-- The new clause may appear in an unrelated unit, when
-- the parents of a generic are being installed prior to
-- instantiation. In this case there must be no warning.
-- We detect this case by checking whether the current
-- top of the stack is related to the current
-- compilation.
Scop := Current_Scope;
while Present (Scop)
and then Scop /= Standard_Standard
loop
if Is_Compilation_Unit (Scop)
and then not Is_Child_Unit (Scop)
then
return;
elsif Scop = Cunit_Entity (Current_Sem_Unit) then
exit;
end if;
Scop := Scope (Scop);
end loop;
Redundant := Cur_Use;
Prev_Use := Clause;
end if;
elsif New_Unit = Current_Sem_Unit then
Redundant := Clause;
Prev_Use := Cur_Use;
else
-- Neither is the current unit, so they appear in parent or
-- sibling units. Warning will be emitted elsewhere.
return;
end if;
end;
elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
and then Present (Parent_Spec (Unit (Cunit (Current_Sem_Unit))))
then
-- Use_clause is in child unit of current unit, and the child unit
-- appears in the context of the body of the parent, so it has
-- been installed first, even though it is the redundant one.
-- Depending on their placement in the context, the visible or the
-- private parts of the two units, either might appear as
-- redundant, but the message has to be on the current unit.
if Get_Source_Unit (Cur_Use) = Current_Sem_Unit then
Redundant := Cur_Use;
Prev_Use := Clause;
else
Redundant := Clause;
Prev_Use := Cur_Use;
end if;
-- If the new use clause appears in the private part of a parent
-- unit it may appear to be redundant w.r.t. a use clause in a
-- child unit, but the previous use clause was needed in the
-- visible part of the child, and no warning should be emitted.
if Nkind (Parent (Decl)) = N_Package_Specification
and then List_Containing (Decl) =
Private_Declarations (Parent (Decl))
then
declare
Par : constant Entity_Id :=
Defining_Entity (Parent (Decl));
Spec : constant Node_Id :=
Specification (Unit (Cunit (Current_Sem_Unit)));
Cur_List : constant List_Id := List_Containing (Cur_Use);
begin
if Is_Compilation_Unit (Par)
and then Par /= Cunit_Entity (Current_Sem_Unit)
then
if Cur_List = Context_Items (Cunit (Current_Sem_Unit))
or else Cur_List = Visible_Declarations (Spec)
then
return;
end if;
end if;
end;
end if;
-- Finally, if the current use clause is in the context then the
-- clause is redundant when it is nested within the unit.
elsif Nkind (Parent (Cur_Use)) = N_Compilation_Unit
and then Nkind (Parent (Parent (Clause))) /= N_Compilation_Unit
and then Get_Source_Unit (Cur_Use) = Get_Source_Unit (Clause)
then
Redundant := Clause;
Prev_Use := Cur_Use;
end if;
if Present (Redundant) and then Parent (Redundant) /= Prev_Use then
-- Make sure we are looking at most-descendant use_package_clause
-- by traversing the chain with Find_First_Use and then verifying
-- there is no scope manipulation via Most_Descendant_Use_Clause.
if Nkind (Prev_Use) = N_Use_Package_Clause
and then
(Nkind (Parent (Prev_Use)) /= N_Compilation_Unit
or else Most_Descendant_Use_Clause
(Prev_Use, Find_First_Use (Prev_Use)) /= Prev_Use)
then
Prev_Use := Find_First_Use (Prev_Use);
end if;
Error_Msg_Sloc := Sloc (Prev_Use);
Error_Msg_NE -- CODEFIX
("& is already use-visible through previous use_clause #?r?",
Redundant, Pack_Name);
end if;
end Note_Redundant_Use;
-- Local variables
Current_Instance : Entity_Id := Empty;
Id : Entity_Id;
P : Entity_Id;
Prev : Entity_Id;
Private_With_OK : Boolean := False;
Real_P : Entity_Id;
-- Start of processing for Use_One_Package
begin
-- Use_One_Package may have been called recursively to handle an
-- implicit use for a auxiliary system package, so set P accordingly
-- and skip redundancy checks.
if No (Pack_Name) and then Present_System_Aux (N) then
P := System_Aux_Id;
-- Check for redundant use_package_clauses
else
-- Ignore cases where we are dealing with a non user defined package
-- like Standard_Standard or something other than a valid package.
if not Is_Entity_Name (Pack_Name)
or else No (Entity (Pack_Name))
or else Ekind (Entity (Pack_Name)) /= E_Package
then
return;
end if;
-- When a renaming exists we must check it for redundancy. The
-- original package would have already been seen at this point.
if Present (Renamed_Entity (Entity (Pack_Name))) then
P := Renamed_Entity (Entity (Pack_Name));
else
P := Entity (Pack_Name);
end if;
-- Check for redundant clauses then set the current use clause for
-- P if were are not "forcing" an installation from a scope
-- reinstallation that is done throughout analysis for various
-- reasons.
if In_Use (P) then
Note_Redundant_Use (Pack_Name);
if not Force then
Set_Current_Use_Clause (P, N);
end if;
return;
-- Warn about detected redundant clauses
elsif not Force
and then In_Open_Scopes (P)
and then not Is_Hidden_Open_Scope (P)
then
if Warn_On_Redundant_Constructs and then P = Current_Scope then
Error_Msg_NE -- CODEFIX
("& is already use-visible within itself?r?",
Pack_Name, P);
end if;
return;
end if;
-- Set P back to the non-renamed package so that visibility of the
-- entities within the package can be properly set below.
P := Entity (Pack_Name);
end if;
Set_In_Use (P);
Set_Current_Use_Clause (P, N);
-- Ada 2005 (AI-50217): Check restriction
if From_Limited_With (P) then
Error_Msg_N ("limited withed package cannot appear in use clause", N);
end if;
-- Find enclosing instance, if any
if In_Instance then
Current_Instance := Current_Scope;
while not Is_Generic_Instance (Current_Instance) loop
Current_Instance := Scope (Current_Instance);
end loop;
if No (Hidden_By_Use_Clause (N)) then
Set_Hidden_By_Use_Clause (N, New_Elmt_List);
end if;
end if;
-- If unit is a package renaming, indicate that the renamed package is
-- also in use (the flags on both entities must remain consistent, and a
-- subsequent use of either of them should be recognized as redundant).
if Present (Renamed_Entity (P)) then
Set_In_Use (Renamed_Entity (P));
Set_Current_Use_Clause (Renamed_Entity (P), N);
Real_P := Renamed_Entity (P);
else
Real_P := P;
end if;
-- Ada 2005 (AI-262): Check the use_clause of a private withed package
-- found in the private part of a package specification
if In_Private_Part (Current_Scope)
and then Has_Private_With (P)
and then Is_Child_Unit (Current_Scope)
and then Is_Child_Unit (P)
and then Is_Ancestor_Package (Scope (Current_Scope), P)
then
Private_With_OK := True;
end if;
-- Loop through entities in one package making them potentially
-- use-visible.
Id := First_Entity (P);
while Present (Id)
and then (Id /= First_Private_Entity (P)
or else Private_With_OK) -- Ada 2005 (AI-262)
loop
Prev := Current_Entity (Id);
while Present (Prev) loop
if Is_Immediately_Visible (Prev)
and then (not Is_Overloadable (Prev)
or else not Is_Overloadable (Id)
or else (Type_Conformant (Id, Prev)))
then
if No (Current_Instance) then
-- Potentially use-visible entity remains hidden
goto Next_Usable_Entity;
-- A use clause within an instance hides outer global entities,
-- which are not used to resolve local entities in the
-- instance. Note that the predefined entities in Standard
-- could not have been hidden in the generic by a use clause,
-- and therefore remain visible. Other compilation units whose
-- entities appear in Standard must be hidden in an instance.
-- To determine whether an entity is external to the instance
-- we compare the scope depth of its scope with that of the
-- current instance. However, a generic actual of a subprogram
-- instance is declared in the wrapper package but will not be
-- hidden by a use-visible entity. similarly, an entity that is
-- declared in an enclosing instance will not be hidden by an
-- an entity declared in a generic actual, which can only have
-- been use-visible in the generic and will not have hidden the
-- entity in the generic parent.
-- If Id is called Standard, the predefined package with the
-- same name is in the homonym chain. It has to be ignored
-- because it has no defined scope (being the only entity in
-- the system with this mandated behavior).
elsif not Is_Hidden (Id)
and then Present (Scope (Prev))
and then not Is_Wrapper_Package (Scope (Prev))
and then Scope_Depth (Scope (Prev)) <
Scope_Depth (Current_Instance)
and then (Scope (Prev) /= Standard_Standard
or else Sloc (Prev) > Standard_Location)
then
if In_Open_Scopes (Scope (Prev))
and then Is_Generic_Instance (Scope (Prev))
and then Present (Associated_Formal_Package (P))
then
null;
else
Set_Is_Potentially_Use_Visible (Id);
Set_Is_Immediately_Visible (Prev, False);
Append_Elmt (Prev, Hidden_By_Use_Clause (N));
end if;
end if;
-- A user-defined operator is not use-visible if the predefined
-- operator for the type is immediately visible, which is the case
-- if the type of the operand is in an open scope. This does not
-- apply to user-defined operators that have operands of different
-- types, because the predefined mixed mode operations (multiply
-- and divide) apply to universal types and do not hide anything.
elsif Ekind (Prev) = E_Operator
and then Operator_Matches_Spec (Prev, Id)
and then In_Open_Scopes
(Scope (Base_Type (Etype (First_Formal (Id)))))
and then (No (Next_Formal (First_Formal (Id)))
or else Etype (First_Formal (Id)) =
Etype (Next_Formal (First_Formal (Id)))
or else Chars (Prev) = Name_Op_Expon)
then
goto Next_Usable_Entity;
-- In an instance, two homonyms may become use_visible through the
-- actuals of distinct formal packages. In the generic, only the
-- current one would have been visible, so make the other one
-- not use_visible.
-- In certain pathological cases it is possible that unrelated
-- homonyms from distinct formal packages may exist in an
-- uninstalled scope. We must test for that here.
elsif Present (Current_Instance)
and then Is_Potentially_Use_Visible (Prev)
and then not Is_Overloadable (Prev)
and then Scope (Id) /= Scope (Prev)
and then Used_As_Generic_Actual (Scope (Prev))
and then Used_As_Generic_Actual (Scope (Id))
and then Is_List_Member (Scope (Prev))
and then not In_Same_List (Current_Use_Clause (Scope (Prev)),
Current_Use_Clause (Scope (Id)))
then
Set_Is_Potentially_Use_Visible (Prev, False);
Append_Elmt (Prev, Hidden_By_Use_Clause (N));
end if;
Prev := Homonym (Prev);
end loop;
-- On exit, we know entity is not hidden, unless it is private
if not Is_Hidden (Id)
and then ((not Is_Child_Unit (Id)) or else Is_Visible_Lib_Unit (Id))
then
Set_Is_Potentially_Use_Visible (Id);
if Is_Private_Type (Id) and then Present (Full_View (Id)) then
Set_Is_Potentially_Use_Visible (Full_View (Id));
end if;
end if;
<<Next_Usable_Entity>>
Next_Entity (Id);
end loop;
-- Child units are also made use-visible by a use clause, but they may
-- appear after all visible declarations in the parent entity list.
while Present (Id) loop
if Is_Child_Unit (Id) and then Is_Visible_Lib_Unit (Id) then
Set_Is_Potentially_Use_Visible (Id);
end if;
Next_Entity (Id);
end loop;
if Chars (Real_P) = Name_System
and then Scope (Real_P) = Standard_Standard
and then Present_System_Aux (N)
then
Use_One_Package (N);
end if;
end Use_One_Package;
------------------
-- Use_One_Type --
------------------
procedure Use_One_Type
(Id : Node_Id;
Installed : Boolean := False;
Force : Boolean := False)
is
function Spec_Reloaded_For_Body return Boolean;
-- Determine whether the compilation unit is a package body and the use
-- type clause is in the spec of the same package. Even though the spec
-- was analyzed first, its context is reloaded when analysing the body.
procedure Use_Class_Wide_Operations (Typ : Entity_Id);
-- AI05-150: if the use_type_clause carries the "all" qualifier,
-- class-wide operations of ancestor types are use-visible if the
-- ancestor type is visible.
----------------------------
-- Spec_Reloaded_For_Body --
----------------------------
function Spec_Reloaded_For_Body return Boolean is
begin
if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then
declare
Spec : constant Node_Id :=
Parent (List_Containing (Parent (Id)));
begin
-- Check whether type is declared in a package specification,
-- and current unit is the corresponding package body. The
-- use clauses themselves may be within a nested package.
return
Nkind (Spec) = N_Package_Specification
and then In_Same_Source_Unit
(Corresponding_Body (Parent (Spec)),
Cunit_Entity (Current_Sem_Unit));
end;
end if;
return False;
end Spec_Reloaded_For_Body;
-------------------------------
-- Use_Class_Wide_Operations --
-------------------------------
procedure Use_Class_Wide_Operations (Typ : Entity_Id) is
function Is_Class_Wide_Operation_Of
(Op : Entity_Id;
T : Entity_Id) return Boolean;
-- Determine whether a subprogram has a class-wide parameter or
-- result that is T'Class.
---------------------------------
-- Is_Class_Wide_Operation_Of --
---------------------------------
function Is_Class_Wide_Operation_Of
(Op : Entity_Id;
T : Entity_Id) return Boolean
is
Formal : Entity_Id;
begin
Formal := First_Formal (Op);
while Present (Formal) loop
if Etype (Formal) = Class_Wide_Type (T) then
return True;
end if;
Next_Formal (Formal);
end loop;
if Etype (Op) = Class_Wide_Type (T) then
return True;
end if;
return False;
end Is_Class_Wide_Operation_Of;
-- Local variables
Ent : Entity_Id;
Scop : Entity_Id;
-- Start of processing for Use_Class_Wide_Operations
begin
Scop := Scope (Typ);
if not Is_Hidden (Scop) then
Ent := First_Entity (Scop);
while Present (Ent) loop
if Is_Overloadable (Ent)
and then Is_Class_Wide_Operation_Of (Ent, Typ)
and then not Is_Potentially_Use_Visible (Ent)
then
Set_Is_Potentially_Use_Visible (Ent);
Append_Elmt (Ent, Used_Operations (Parent (Id)));
end if;
Next_Entity (Ent);
end loop;
end if;
if Is_Derived_Type (Typ) then
Use_Class_Wide_Operations (Etype (Base_Type (Typ)));
end if;
end Use_Class_Wide_Operations;
-- Local variables
Elmt : Elmt_Id;
Is_Known_Used : Boolean;
Op_List : Elist_Id;
T : Entity_Id;
-- Start of processing for Use_One_Type
begin
if Entity (Id) = Any_Type then
return;
end if;
-- It is the type determined by the subtype mark (8.4(8)) whose
-- operations become potentially use-visible.
T := Base_Type (Entity (Id));
-- Either the type itself is used, the package where it is declared is
-- in use or the entity is declared in the current package, thus
-- use-visible.
Is_Known_Used :=
(In_Use (T)
and then ((Present (Current_Use_Clause (T))
and then All_Present (Current_Use_Clause (T)))
or else not All_Present (Parent (Id))))
or else In_Use (Scope (T))
or else Scope (T) = Current_Scope;
Set_Redundant_Use (Id,
Is_Known_Used or else Is_Potentially_Use_Visible (T));
if Ekind (T) = E_Incomplete_Type then
Error_Msg_N ("premature usage of incomplete type", Id);
elsif In_Open_Scopes (Scope (T)) then
null;
-- A limited view cannot appear in a use_type_clause. However, an access
-- type whose designated type is limited has the flag but is not itself
-- a limited view unless we only have a limited view of its enclosing
-- package.
elsif From_Limited_With (T) and then From_Limited_With (Scope (T)) then
Error_Msg_N
("incomplete type from limited view cannot appear in use clause",
Id);
-- If the use clause is redundant, Used_Operations will usually be
-- empty, but we need to set it to empty here in one case: If we are
-- instantiating a generic library unit, then we install the ancestors
-- of that unit in the scope stack, which involves reprocessing use
-- clauses in those ancestors. Such a use clause will typically have a
-- nonempty Used_Operations unless it was redundant in the generic unit,
-- even if it is redundant at the place of the instantiation.
elsif Redundant_Use (Id) then
-- We must avoid incorrectly setting the Current_Use_Clause when we
-- are working with a redundant clause that has already been linked
-- in the Prev_Use_Clause chain, otherwise the chain will break.
if Present (Current_Use_Clause (T))
and then Present (Prev_Use_Clause (Current_Use_Clause (T)))
and then Parent (Id) = Prev_Use_Clause (Current_Use_Clause (T))
then
null;
else
Set_Current_Use_Clause (T, Parent (Id));
end if;
Set_Used_Operations (Parent (Id), New_Elmt_List);
-- If the subtype mark designates a subtype in a different package,
-- we have to check that the parent type is visible, otherwise the
-- use_type_clause is a no-op. Not clear how to do that???
else
Set_Current_Use_Clause (T, Parent (Id));
Set_In_Use (T);
-- If T is tagged, primitive operators on class-wide operands are
-- also deemed available. Note that this is really necessary only
-- in semantics-only mode, because the primitive operators are not
-- fully constructed in this mode, but we do it in all modes for the
-- sake of uniformity, as this should not matter in practice.
if Is_Tagged_Type (T) then
Set_In_Use (Class_Wide_Type (T));
end if;
-- Iterate over primitive operations of the type. If an operation is
-- already use_visible, it is the result of a previous use_clause,
-- and already appears on the corresponding entity chain. If the
-- clause is being reinstalled, operations are already use-visible.
if Installed then
null;
else
Op_List := Collect_Primitive_Operations (T);
Elmt := First_Elmt (Op_List);
while Present (Elmt) loop
if (Nkind (Node (Elmt)) = N_Defining_Operator_Symbol
or else Chars (Node (Elmt)) in Any_Operator_Name)
and then not Is_Hidden (Node (Elmt))
and then not Is_Potentially_Use_Visible (Node (Elmt))
then
Set_Is_Potentially_Use_Visible (Node (Elmt));
Append_Elmt (Node (Elmt), Used_Operations (Parent (Id)));
elsif Ada_Version >= Ada_2012
and then All_Present (Parent (Id))
and then not Is_Hidden (Node (Elmt))
and then not Is_Potentially_Use_Visible (Node (Elmt))
then
Set_Is_Potentially_Use_Visible (Node (Elmt));
Append_Elmt (Node (Elmt), Used_Operations (Parent (Id)));
end if;
Next_Elmt (Elmt);
end loop;
end if;
if Ada_Version >= Ada_2012
and then All_Present (Parent (Id))
and then Is_Tagged_Type (T)
then
Use_Class_Wide_Operations (T);
end if;
end if;
-- If warning on redundant constructs, check for unnecessary WITH
if not Force
and then Warn_On_Redundant_Constructs
and then Is_Known_Used
-- with P; with P; use P;
-- package P is package X is package body X is
-- type T ... use P.T;
-- The compilation unit is the body of X. GNAT first compiles the
-- spec of X, then proceeds to the body. At that point P is marked
-- as use visible. The analysis then reinstalls the spec along with
-- its context. The use clause P.T is now recognized as redundant,
-- but in the wrong context. Do not emit a warning in such cases.
-- Do not emit a warning either if we are in an instance, there is
-- no redundancy between an outer use_clause and one that appears
-- within the generic.
and then not Spec_Reloaded_For_Body
and then not In_Instance
and then not In_Inlined_Body
then
-- The type already has a use clause
if In_Use (T) then
-- Case where we know the current use clause for the type
if Present (Current_Use_Clause (T)) then
Use_Clause_Known : declare
Clause1 : constant Node_Id :=
Find_First_Use (Current_Use_Clause (T));
Clause2 : constant Node_Id := Parent (Id);
Ent1 : Entity_Id;
Ent2 : Entity_Id;
Err_No : Node_Id;
Unit1 : Node_Id;
Unit2 : Node_Id;
-- Start of processing for Use_Clause_Known
begin
-- If both current use_type_clause and the use_type_clause
-- for the type are at the compilation unit level, one of
-- the units must be an ancestor of the other, and the
-- warning belongs on the descendant.
if Nkind (Parent (Clause1)) = N_Compilation_Unit
and then
Nkind (Parent (Clause2)) = N_Compilation_Unit
then
-- If the unit is a subprogram body that acts as spec,
-- the context clause is shared with the constructed
-- subprogram spec. Clearly there is no redundancy.
if Clause1 = Clause2 then
return;
end if;
Unit1 := Unit (Parent (Clause1));
Unit2 := Unit (Parent (Clause2));
-- If both clauses are on same unit, or one is the body
-- of the other, or one of them is in a subunit, report
-- redundancy on the later one.
if Unit1 = Unit2 or else Nkind (Unit1) = N_Subunit then
Error_Msg_Sloc := Sloc (Current_Use_Clause (T));
Error_Msg_NE -- CODEFIX
("& is already use-visible through previous "
& "use_type_clause #??", Clause1, T);
return;
elsif Nkind (Unit2) in N_Package_Body | N_Subprogram_Body
and then Nkind (Unit1) /= Nkind (Unit2)
and then Nkind (Unit1) /= N_Subunit
then
Error_Msg_Sloc := Sloc (Clause1);
Error_Msg_NE -- CODEFIX
("& is already use-visible through previous "
& "use_type_clause #??", Current_Use_Clause (T), T);
return;
end if;
-- There is a redundant use_type_clause in a child unit.
-- Determine which of the units is more deeply nested.
-- If a unit is a package instance, retrieve the entity
-- and its scope from the instance spec.
Ent1 := Entity_Of_Unit (Unit1);
Ent2 := Entity_Of_Unit (Unit2);
if Scope (Ent2) = Standard_Standard then
Error_Msg_Sloc := Sloc (Current_Use_Clause (T));
Err_No := Clause1;
elsif Scope (Ent1) = Standard_Standard then
Error_Msg_Sloc := Sloc (Id);
Err_No := Clause2;
-- If both units are child units, we determine which one
-- is the descendant by the scope distance to the
-- ultimate parent unit.
else
declare
S1 : Entity_Id;
S2 : Entity_Id;
begin
S1 := Scope (Ent1);
S2 := Scope (Ent2);
while Present (S1)
and then Present (S2)
and then S1 /= Standard_Standard
and then S2 /= Standard_Standard
loop
S1 := Scope (S1);
S2 := Scope (S2);
end loop;
if S1 = Standard_Standard then
Error_Msg_Sloc := Sloc (Id);
Err_No := Clause2;
else
Error_Msg_Sloc := Sloc (Current_Use_Clause (T));
Err_No := Clause1;
end if;
end;
end if;
if Parent (Id) /= Err_No then
if Most_Descendant_Use_Clause
(Err_No, Parent (Id)) = Parent (Id)
then
Error_Msg_Sloc := Sloc (Err_No);
Err_No := Parent (Id);
end if;
Error_Msg_NE -- CODEFIX
("& is already use-visible through previous "
& "use_type_clause #??", Err_No, Id);
end if;
-- Case where current use_type_clause and use_type_clause
-- for the type are not both at the compilation unit level.
-- In this case we don't have location information.
else
Error_Msg_NE -- CODEFIX
("& is already use-visible through previous "
& "use_type_clause??", Id, T);
end if;
end Use_Clause_Known;
-- Here if Current_Use_Clause is not set for T, another case where
-- we do not have the location information available.
else
Error_Msg_NE -- CODEFIX
("& is already use-visible through previous "
& "use_type_clause??", Id, T);
end if;
-- The package where T is declared is already used
elsif In_Use (Scope (T)) then
-- Due to expansion of contracts we could be attempting to issue
-- a spurious warning - so verify there is a previous use clause.
if Current_Use_Clause (Scope (T)) /=
Find_First_Use (Current_Use_Clause (Scope (T)))
then
Error_Msg_Sloc :=
Sloc (Find_First_Use (Current_Use_Clause (Scope (T))));
Error_Msg_NE -- CODEFIX
("& is already use-visible through package use clause #??",
Id, T);
end if;
-- The current scope is the package where T is declared
else
Error_Msg_Node_2 := Scope (T);
Error_Msg_NE -- CODEFIX
("& is already use-visible inside package &??", Id, T);
end if;
end if;
end Use_One_Type;
----------------
-- Write_Info --
----------------
procedure Write_Info is
Id : Entity_Id := First_Entity (Current_Scope);
begin
-- No point in dumping standard entities
if Current_Scope = Standard_Standard then
return;
end if;
Write_Str ("========================================================");
Write_Eol;
Write_Str (" Defined Entities in ");
Write_Name (Chars (Current_Scope));
Write_Eol;
Write_Str ("========================================================");
Write_Eol;
if No (Id) then
Write_Str ("-- none --");
Write_Eol;
else
while Present (Id) loop
Write_Entity_Info (Id, " ");
Next_Entity (Id);
end loop;
end if;
if Scope (Current_Scope) = Standard_Standard then
-- Print information on the current unit itself
Write_Entity_Info (Current_Scope, " ");
end if;
Write_Eol;
end Write_Info;
--------
-- ws --
--------
procedure ws is
S : Entity_Id;
begin
for J in reverse 1 .. Scope_Stack.Last loop
S := Scope_Stack.Table (J).Entity;
Write_Int (Int (S));
Write_Str (" === ");
Write_Name (Chars (S));
Write_Eol;
end loop;
end ws;
--------
-- we --
--------
procedure we (S : Entity_Id) is
E : Entity_Id;
begin
E := First_Entity (S);
while Present (E) loop
Write_Int (Int (E));
Write_Str (" === ");
Write_Name (Chars (E));
Write_Eol;
Next_Entity (E);
end loop;
end we;
end Sem_Ch8;
|
faelys/natools | Ada | 6,482 | adb | ------------------------------------------------------------------------------
-- Copyright (c) 2011, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
package body Natools.Accumulators.String_Accumulator_Linked_Lists is
procedure Initialize_If_Needed
(Object : in out String_Accumulator_Linked_List) is
begin
if Object.Stack.Is_Empty then
Object.Stack.Append (Object.Build (1));
Object.Position := Object.Stack.Last;
end if;
end Initialize_If_Needed;
procedure Append (To : in out String_Accumulator_Linked_List;
Text : String)
is
procedure Process (Element : in out String_Accumulator'Class);
procedure Process (Element : in out String_Accumulator'Class) is
begin
Element.Append (Text);
end Process;
begin
Initialize_If_Needed (To);
To.Stack.Update_Element (To.Position, Process'Access);
end Append;
procedure Hard_Reset (Acc : in out String_Accumulator_Linked_List) is
begin
Acc.Stack.Clear;
Acc.Position := Lists.No_Element;
end Hard_Reset;
function Length (Acc : String_Accumulator_Linked_List) return Natural is
procedure Process (Element : String_Accumulator'Class);
Result : Natural;
procedure Process (Element : String_Accumulator'Class) is
begin
Result := Element.Length;
end Process;
begin
if Acc.Stack.Is_Empty then
return 0;
else
Lists.Query_Element (Acc.Position, Process'Access);
return Result;
end if;
end Length;
procedure Push (Acc : in out String_Accumulator_Linked_List) is
procedure Process (Element : in out String_Accumulator'Class);
use type Lists.Cursor;
procedure Process (Element : in out String_Accumulator'Class) is
begin
Soft_Reset (Element);
end Process;
begin
Initialize_If_Needed (Acc);
Lists.Next (Acc.Position);
if Acc.Position = Lists.No_Element then
declare
Level_Created : constant Positive
:= Natural (Acc.Stack.Length) + 1;
begin
Acc.Stack.Append (Acc.Build (Level_Created));
Acc.Position := Acc.Stack.Last;
end;
else
Acc.Stack.Update_Element (Acc.Position, Process'Access);
end if;
end Push;
procedure Pop (Acc : in out String_Accumulator_Linked_List) is
use type Lists.Cursor;
begin
if Acc.Stack.Is_Empty then
raise Program_Error;
end if;
Lists.Previous (Acc.Position);
if Acc.Position = Lists.No_Element then
Acc.Position := Lists.First (Acc.Stack);
raise Program_Error;
end if;
end Pop;
procedure Soft_Reset (Acc : in out String_Accumulator_Linked_List) is
procedure Process (Element : in out String_Accumulator'Class);
procedure Process (Element : in out String_Accumulator'Class) is
begin
Element.Soft_Reset;
end Process;
begin
Initialize_If_Needed (Acc);
Acc.Position := Lists.First (Acc.Stack);
Acc.Stack.Update_Element (Acc.Position, Process'Access);
end Soft_Reset;
function Tail (Acc : String_Accumulator_Linked_List; Size : Natural)
return String
is
procedure Process (Element : String_Accumulator'Class);
Result : String (1 .. Size);
Actual_Size : Natural;
procedure Process (Element : String_Accumulator'Class)
is
Output : constant String := Tail (Element, Size);
begin
Actual_Size := Output'Length;
Result (1 .. Actual_Size) := Output;
end Process;
begin
if Acc.Stack.Is_Empty then
return "";
else
Lists.Query_Element (Acc.Position, Process'Access);
return Result (1 .. Actual_Size);
end if;
end Tail;
function To_String (Acc : String_Accumulator_Linked_List) return String is
begin
if Acc.Stack.Is_Empty then
return "";
end if;
declare
procedure Process (Element : String_Accumulator'Class);
Result : String (1 .. Acc.Length);
procedure Process (Element : String_Accumulator'Class) is
begin
Result := Element.To_String;
end Process;
begin
Lists.Query_Element (Acc.Position, Process'Access);
return Result;
end;
end To_String;
procedure To_String (Acc : String_Accumulator_Linked_List;
Output : out String) is
begin
if Acc.Stack.Is_Empty then
return;
end if;
declare
procedure Process (Element : String_Accumulator'Class);
procedure Process (Element : String_Accumulator'Class) is
begin
Element.To_String (Output);
end Process;
begin
Lists.Query_Element (Acc.Position, Process'Access);
end;
end To_String;
procedure Unappend (From : in out String_Accumulator_Linked_List;
Text : String)
is
procedure Process (Element : in out String_Accumulator'Class);
procedure Process (Element : in out String_Accumulator'Class) is
begin
Element.Unappend (Text);
end Process;
begin
if not From.Stack.Is_Empty then
From.Stack.Update_Element (From.Position, Process'Access);
end if;
end Unappend;
end Natools.Accumulators.String_Accumulator_Linked_Lists;
|
reznikmm/matreshka | Ada | 3,744 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- 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 XML.DOM.Attributes;
package ODF.DOM.Text_Placeholder_Type_Attributes is
pragma Preelaborate;
type ODF_Text_Placeholder_Type_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Text_Placeholder_Type_Attribute_Access is
access all ODF_Text_Placeholder_Type_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Text_Placeholder_Type_Attributes;
|
reznikmm/matreshka | Ada | 6,242 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014-2015, Vadim Godunko <[email protected]> --
-- 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 Wiki.Parsers;
package body Wiki.Block_Parsers.Headers is
HTML5_URI : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("http://www.w3.org/1999/xhtml");
H_Tag : constant
array (Positive range 1 .. 6) of League.Strings.Universal_String
:= (League.Strings.To_Universal_String ("h1"),
League.Strings.To_Universal_String ("h2"),
League.Strings.To_Universal_String ("h3"),
League.Strings.To_Universal_String ("h4"),
League.Strings.To_Universal_String ("h5"),
League.Strings.To_Universal_String ("h6"));
----------------------
-- Can_Be_Continued --
----------------------
overriding function Can_Be_Continued
(Self : not null access constant Header_Block_Parser) return Boolean is
begin
return False;
end Can_Be_Continued;
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Constructor_Parameters)
return Header_Block_Parser is
begin
return
Header_Block_Parser'
(Writer => Parameters.Writer,
Depth => Integer'Min (Parameters.Markup.Length, 6));
end Create;
---------------
-- End_Block --
---------------
overriding function End_Block
(Self : not null access Header_Block_Parser;
Next : access Abstract_Block_Parser'Class) return End_Block_Action is
begin
Self.Writer.End_Element
(Local_Name => H_Tag (Self.Depth),
Namespace_URI => HTML5_URI);
if Next /= null then
return Continue;
else
-- This is special case to simplify unwind of stack of block element
-- parsers at the end of the document processing.
return Unwind;
end if;
end End_Block;
----------
-- Line --
----------
overriding procedure Line
(Self : not null access Header_Block_Parser;
Text : League.Strings.Universal_String) is
begin
-- XXX trailing '='* must be removed first!!!
Self.Writer.Characters (Text);
end Line;
--------------
-- Register --
--------------
procedure Register is
begin
Wiki.Parsers.Register_Block_Parser
(League.Strings.To_Universal_String
("^\p{White_Space}* (\=+) \p{White_Space}*"
& " (\P{White_Space}.*?) \p{White_Space}* \=*$"),
2,
1,
2,
Header_Block_Parser'Tag);
end Register;
-----------------
-- Start_Block --
-----------------
overriding function Start_Block
(Self : not null access Header_Block_Parser;
Previous : access Abstract_Block_Parser'Class)
return Block_Parser_Access is
begin
Self.Writer.Start_Element
(Local_Name => H_Tag (Self.Depth),
Namespace_URI => HTML5_URI);
return null;
end Start_Block;
end Wiki.Block_Parsers.Headers;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.