content
stringlengths
23
1.05M
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- C O M P E R R -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by AdaCore. -- -- -- ------------------------------------------------------------------------------ -- This package contains routines called when a fatal internal compiler error -- is detected. Calls to these routines cause termination of the current -- compilation with appropriate error output. with Atree; use Atree; with Debug; use Debug; with Errout; use Errout; with Gnatvsn; use Gnatvsn; with Lib; use Lib; with Namet; use Namet; with Opt; use Opt; with Osint; use Osint; with Output; use Output; with Sinfo; use Sinfo; with Sinput; use Sinput; with Sprint; use Sprint; with Sdefault; use Sdefault; with Treepr; use Treepr; with Types; use Types; with Ada.Exceptions; use Ada.Exceptions; with System.OS_Lib; use System.OS_Lib; with System.Soft_Links; use System.Soft_Links; package body Comperr is ---------------- -- Local Data -- ---------------- Abort_In_Progress : Boolean := False; -- Used to prevent runaway recursion if something segfaults -- while processing a previous abort. ----------------------- -- Local Subprograms -- ----------------------- procedure Repeat_Char (Char : Character; Col : Nat; After : Character); -- Output Char until current column is at or past Col, and then output -- the character given by After (if column is already past Col on entry, -- then the effect is simply to output the After character). -------------------- -- Compiler_Abort -- -------------------- procedure Compiler_Abort (X : String; Fallback_Loc : String := ""; From_GCC : Boolean := False) is -- The procedures below output a "bug box" with information about -- the cause of the compiler abort and about the preferred method -- of reporting bugs. The default is a bug box appropriate for -- the FSF version of GNAT, but there are specializations for -- the GNATPRO and Public releases by AdaCore. XF : constant Positive := X'First; -- Start index, usually 1, but we won't assume this procedure End_Line; -- Add blanks up to column 76, and then a final vertical bar -------------- -- End_Line -- -------------- procedure End_Line is begin Repeat_Char (' ', 76, '|'); Write_Eol; end End_Line; Is_GPL_Version : constant Boolean := Gnatvsn.Build_Type = GPL; Is_FSF_Version : constant Boolean := Gnatvsn.Build_Type = FSF; -- Start of processing for Compiler_Abort begin Cancel_Special_Output; -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV if Abort_In_Progress then Exit_Program (E_Abort); end if; Abort_In_Progress := True; -- Generate a "standard" error message instead of a bug box in case -- of CodePeer rather than generating a bug box, friendlier. -- Note that the call to Error_Msg_N below sets Serious_Errors_Detected -- to 1, so we use the regular mechanism below in order to display a -- "compilation abandoned" message and exit, so we still know we have -- this case (and -gnatdk can still be used to get the bug box). if CodePeer_Mode and then Serious_Errors_Detected = 0 and then not Debug_Flag_K and then Sloc (Current_Error_Node) > No_Location then Error_Msg_N ("cannot generate 'S'C'I'L", Current_Error_Node); end if; -- If we are in CodePeer mode, we must also delete SCIL files if CodePeer_Mode then Delete_SCIL_Files; end if; -- If any errors have already occurred, then we guess that the abort -- may well be caused by previous errors, and we don't make too much -- fuss about it, since we want to let programmer fix the errors first. -- Debug flag K disables this behavior (useful for debugging) if Serious_Errors_Detected /= 0 and then not Debug_Flag_K then Errout.Finalize (Last_Call => True); Errout.Output_Messages; Set_Standard_Error; Write_Str ("compilation abandoned due to previous error"); Write_Eol; Set_Standard_Output; Source_Dump; Tree_Dump; Exit_Program (E_Errors); -- Otherwise give message with details of the abort else Set_Standard_Error; -- Generate header for bug box Write_Char ('+'); Repeat_Char ('=', 29, 'G'); Write_Str ("NAT BUG DETECTED"); Repeat_Char ('=', 76, '+'); Write_Eol; -- Output GNAT version identification Write_Str ("| "); Write_Str (Gnat_Version_String); Write_Str (" ("); -- Output target name, deleting junk final reverse slash if Target_Name.all (Target_Name.all'Last) = '\' or else Target_Name.all (Target_Name.all'Last) = '/' then Write_Str (Target_Name.all (1 .. Target_Name.all'Last - 1)); else Write_Str (Target_Name.all); end if; -- Output identification of error Write_Str (") "); if X'Length + Column > 76 then if From_GCC then Write_Str ("GCC error:"); end if; End_Line; Write_Str ("| "); end if; if X'Length > 70 then declare Last_Blank : Integer := 70; begin for P in 39 .. 68 loop if X (XF + P) = ' ' then Last_Blank := P; end if; end loop; Write_Str (X (XF .. XF - 1 + Last_Blank)); End_Line; Write_Str ("| "); Write_Str (X (XF + Last_Blank .. X'Last)); end; else Write_Str (X); end if; if not From_GCC then -- For exception case, get exception message from the TSD. Note -- that it would be neater and cleaner to pass the exception -- message (obtained from Exception_Message) as a parameter to -- Compiler_Abort, but we can't do this quite yet since it would -- cause bootstrap path problems for 3.10 to 3.11. Write_Char (' '); Write_Str (Exception_Message (Get_Current_Excep.all.all)); end if; End_Line; -- Output source location information if Sloc (Current_Error_Node) <= No_Location then if Fallback_Loc'Length > 0 then Write_Str ("| Error detected around "); Write_Str (Fallback_Loc); else Write_Str ("| No source file position information available"); end if; End_Line; else Write_Str ("| Error detected at "); Write_Location (Sloc (Current_Error_Node)); End_Line; end if; -- There are two cases now. If the file gnat_bug.box exists, -- we use the contents of this file at this point. declare Lo : Source_Ptr; Hi : Source_Ptr; Src : Source_Buffer_Ptr; begin Namet.Unlock; Name_Buffer (1 .. 12) := "gnat_bug.box"; Name_Len := 12; Read_Source_File (Name_Enter, 0, Hi, Src); -- If we get a Src file, we use it if Src /= null then Lo := 0; Outer : while Lo < Hi loop Write_Str ("| "); Inner : loop exit Inner when Src (Lo) = ASCII.CR or else Src (Lo) = ASCII.LF; Write_Char (Src (Lo)); Lo := Lo + 1; end loop Inner; End_Line; while Lo <= Hi and then (Src (Lo) = ASCII.CR or else Src (Lo) = ASCII.LF) loop Lo := Lo + 1; end loop; end loop Outer; -- Otherwise we use the standard fixed text else if Is_FSF_Version then Write_Str ("| Please submit a bug report; see" & " https://gcc.gnu.org/bugs/ ."); End_Line; elsif Is_GPL_Version then Write_Str ("| Please submit a bug report by email " & "to report@adacore.com."); End_Line; Write_Str ("| GAP members can alternatively use GNAT Tracker:"); End_Line; Write_Str ("| http://www.adacore.com/ " & "section 'send a report'."); End_Line; Write_Str ("| See gnatinfo.txt for full info on procedure " & "for submitting bugs."); End_Line; else Write_Str ("| Please submit a bug report using GNAT Tracker:"); End_Line; Write_Str ("| http://www.adacore.com/gnattracker/ " & "section 'send a report'."); End_Line; Write_Str ("| alternatively submit a bug report by email " & "to report@adacore.com,"); End_Line; Write_Str ("| including your customer number #nnn " & "in the subject line."); End_Line; end if; Write_Str ("| Use a subject line meaningful to you" & " and us to track the bug."); End_Line; Write_Str ("| Include the entire contents of this bug " & "box in the report."); End_Line; Write_Str ("| Include the exact command that you entered."); End_Line; Write_Str ("| Also include sources listed below."); End_Line; if not Is_FSF_Version then Write_Str ("| Use plain ASCII or MIME attachment(s)."); End_Line; end if; end if; end; -- Complete output of bug box Write_Char ('+'); Repeat_Char ('=', 76, '+'); Write_Eol; if Debug_Flag_3 then Write_Eol; Write_Eol; Print_Tree_Node (Current_Error_Node); Write_Eol; end if; Write_Eol; Write_Line ("Please include these source files with error report"); Write_Line ("Note that list may not be accurate in some cases, "); Write_Line ("so please double check that the problem can still "); Write_Line ("be reproduced with the set of files listed."); Write_Line ("Consider also -gnatd.n switch (see debug.adb)."); Write_Eol; begin Dump_Source_File_Names; -- If we blow up trying to print the list of file names, just output -- informative msg and continue. exception when others => Write_Str ("list may be incomplete"); end; Write_Eol; Set_Standard_Output; Tree_Dump; Source_Dump; raise Unrecoverable_Error; end if; end Compiler_Abort; ----------------------- -- Delete_SCIL_Files -- ----------------------- procedure Delete_SCIL_Files is Main : Node_Id; Unit_Name : Node_Id; Success : Boolean; pragma Unreferenced (Success); procedure Decode_Name_Buffer; -- Replace "__" by "." in Name_Buffer, and adjust Name_Len accordingly ------------------------ -- Decode_Name_Buffer -- ------------------------ procedure Decode_Name_Buffer is J : Natural; K : Natural; begin J := 1; K := 0; while J <= Name_Len loop K := K + 1; if J < Name_Len and then Name_Buffer (J) = '_' and then Name_Buffer (J + 1) = '_' then Name_Buffer (K) := '.'; J := J + 1; else Name_Buffer (K) := Name_Buffer (J); end if; J := J + 1; end loop; Name_Len := K; end Decode_Name_Buffer; -- Start of processing for Delete_SCIL_Files begin -- If parsing was not successful, no Main_Unit is available, so return -- immediately. if Main_Source_File = No_Source_File then return; end if; -- Retrieve unit name, and remove old versions of SCIL/<unit>.scil and -- SCIL/<unit>__body.scil, ditto for .scilx files. Main := Unit (Cunit (Main_Unit)); case Nkind (Main) is when N_Package_Declaration | N_Subprogram_Body | N_Subprogram_Declaration => Unit_Name := Defining_Unit_Name (Specification (Main)); when N_Package_Body => Unit_Name := Corresponding_Spec (Main); when N_Package_Renaming_Declaration => Unit_Name := Defining_Unit_Name (Main); -- No SCIL file generated for generic package declarations when N_Generic_Package_Declaration => return; -- Should never happen, but can be ignored in production when others => pragma Assert (False); return; end case; case Nkind (Unit_Name) is when N_Defining_Identifier => Get_Name_String (Chars (Unit_Name)); when N_Defining_Program_Unit_Name => Get_Name_String (Chars (Defining_Identifier (Unit_Name))); Decode_Name_Buffer; -- Should never happen, but can be ignored in production when others => pragma Assert (False); return; end case; Delete_File ("SCIL/" & Name_Buffer (1 .. Name_Len) & ".scil", Success); Delete_File ("SCIL/" & Name_Buffer (1 .. Name_Len) & ".scilx", Success); Delete_File ("SCIL/" & Name_Buffer (1 .. Name_Len) & "__body.scil", Success); Delete_File ("SCIL/" & Name_Buffer (1 .. Name_Len) & "__body.scilx", Success); end Delete_SCIL_Files; ----------------- -- Repeat_Char -- ----------------- procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is begin while Column < Col loop Write_Char (Char); end loop; Write_Char (After); end Repeat_Char; end Comperr;
with Ada.Text_IO; with Ada.Command_Line; with Stemmer.Factory; procedure Stemwords is use Stemmer.Factory; function Get_Language (Name : in String) return Language_Type; function Is_Space (C : in Character) return Boolean; function Is_Space (C : in Character) return Boolean is begin return C = ' ' or C = ASCII.HT; end Is_Space; function Get_Language (Name : in String) return Language_Type is begin return Language_Type'Value ("L_" & Name); exception when Constraint_Error => Ada.Text_IO.Put_Line ("Unsupported language: " & Name); return L_ENGLISH; end Get_Language; Count : constant Natural := Ada.Command_Line.Argument_Count; begin if Count /= 3 then Ada.Text_IO.Put_Line ("Usage: stemwords <language> <input file> <output file>"); return; end if; declare Lang : constant Language_Type := Get_Language (Ada.Command_Line.Argument (1)); Input : constant String := Ada.Command_Line.Argument (2); Output : constant String := Ada.Command_Line.Argument (3); Src_File : Ada.Text_IO.File_Type; Dst_File : Ada.Text_IO.File_Type; begin Ada.Text_IO.Open (Src_File, Ada.Text_IO.In_File, Input); Ada.Text_IO.Create (Dst_File, Ada.Text_IO.Out_File, Output); while not Ada.Text_IO.End_Of_File (Src_File) loop declare Line : constant String := Ada.Text_IO.Get_Line (Src_File); Pos : Positive := Line'First; Last_Pos : Positive; Start_Pos : Positive; begin while Pos <= Line'Last loop Last_Pos := Pos; while Pos <= Line'Last and then Is_Space (Line (Pos)) loop Pos := Pos + 1; end loop; if Last_Pos < Pos then Ada.Text_IO.Put (Dst_File, Line (Last_Pos .. Pos - 1)); end if; exit when Pos > Line'Last; Start_Pos := Pos; while Pos <= Line'Last and then not Is_Space (Line (Pos)) loop Pos := Pos + 1; end loop; Ada.Text_IO.Put (Dst_File, Stemmer.Factory.Stem (Lang, Line (Start_Pos .. Pos - 1))); end loop; Ada.Text_IO.New_Line (Dst_File); end; end loop; Ada.Text_IO.Close (Src_File); Ada.Text_IO.Close (Dst_File); end; end Stemwords;
package body Loop_Optimization16_Pkg is function F return Natural is begin return Natural (Index_Base'Last); end; end Loop_Optimization16_Pkg;
----------------------------------------------------------------------- -- ADO SQL -- Basic SQL Generation -- Copyright (C) 2010, 2011, 2012, 2015, 2019 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Strings.Unbounded; with Ada.Calendar; with ADO.Parameters; with ADO.Dialects; -- Utilities for creating SQL queries and statements. package ADO.SQL is use Ada.Strings.Unbounded; -- -------------------- -- Buffer -- -------------------- -- The <b>Buffer</b> type allows to build easily an SQL statement. -- type Buffer is private; type Buffer_Access is access all Buffer; -- Clear the SQL buffer. procedure Clear (Target : in out Buffer); -- Append an SQL extract into the buffer. procedure Append (Target : in out Buffer; SQL : in String); -- Append a name in the buffer and escape that -- name if this is a reserved keyword. procedure Append_Name (Target : in out Buffer; Name : in String); -- Append a string value in the buffer and -- escape any special character if necessary. procedure Append_Value (Target : in out Buffer; Value : in String); -- Append a string value in the buffer and -- escape any special character if necessary. procedure Append_Value (Target : in out Buffer; Value : in Unbounded_String); -- Append the integer value in the buffer. procedure Append_Value (Target : in out Buffer; Value : in Long_Integer); -- Append the integer value in the buffer. procedure Append_Value (Target : in out Buffer; Value : in Integer); -- Append the identifier value in the buffer. procedure Append_Value (Target : in out Buffer; Value : in Identifier); -- Get the SQL string that was accumulated in the buffer. function To_String (From : in Buffer) return String; -- -------------------- -- Query -- -------------------- -- The <b>Query</b> type contains the elements for building and -- executing the request. This includes: -- <ul> -- <li>The SQL request (full request or a fragment)</li> -- <li>The SQL request parameters </li> -- <li>An SQL filter condition</li> -- </ul> -- type Query is new ADO.Parameters.List with record SQL : Buffer; Filter : Buffer; Join : Buffer; end record; type Query_Access is access all Query'Class; -- Clear the query object. overriding procedure Clear (Target : in out Query); -- Set the SQL dialect description object. procedure Set_Dialect (Target : in out Query; D : in ADO.Dialects.Dialect_Access); procedure Set_Filter (Target : in out Query; Filter : in String); function Has_Filter (Source : in Query) return Boolean; function Get_Filter (Source : in Query) return String; -- Set the join condition. procedure Set_Join (Target : in out Query; Join : in String); -- Returns true if there is a join condition function Has_Join (Source : in Query) return Boolean; -- Get the join condition function Get_Join (Source : in Query) return String; -- Set the parameters from another parameter list. -- If the parameter list is a query object, also copy the filter part. procedure Set_Parameters (Params : in out Query; From : in ADO.Parameters.Abstract_List'Class); -- Expand the parameters into the query and return the expanded SQL query. function Expand (Source : in Query) return String; -- -------------------- -- Update Query -- -------------------- -- The <b>Update_Query</b> provides additional helper functions to construct -- and <i>insert</i> or an <i>update</i> statement. type Update_Query is new Query with private; type Update_Query_Access is access all Update_Query'Class; -- Set the SQL dialect description object. procedure Set_Dialect (Target : in out Update_Query; D : in ADO.Dialects.Dialect_Access); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to the <b>Value</b>. procedure Save_Field (Update : in out Update_Query; Name : in String; Value : in Boolean); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to the <b>Value</b>. procedure Save_Field (Update : in out Update_Query; Name : in String; Value : in Integer); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to the <b>Value</b>. procedure Save_Field (Update : in out Update_Query; Name : in String; Value : in Long_Long_Integer); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to the <b>Value</b>. procedure Save_Field (Update : in out Update_Query; Name : in String; Value : in Long_Float); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to the <b>Value</b>. procedure Save_Field (Update : in out Update_Query; Name : in String; Value : in Identifier); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to the <b>Value</b>. procedure Save_Field (Update : in out Update_Query; Name : in String; Value : in Entity_Type); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to the <b>Value</b>. procedure Save_Field (Update : in out Update_Query; Name : in String; Value : in Ada.Calendar.Time); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to the <b>Value</b>. procedure Save_Field (Update : in out Update_Query; Name : in String; Value : in String); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to the <b>Value</b>. procedure Save_Field (Update : in out Update_Query; Name : in String; Value : in Unbounded_String); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to the <b>Value</b>. procedure Save_Field (Update : in out Update_Query; Name : in String; Value : in ADO.Blob_Ref); -- Prepare the update/insert query to save the table field -- identified by <b>Name</b> and set it to NULL. procedure Save_Null_Field (Update : in out Update_Query; Name : in String); -- Check if the update/insert query has some fields to update. function Has_Save_Fields (Update : in Update_Query) return Boolean; procedure Set_Insert_Mode (Update : in out Update_Query); procedure Append_Fields (Update : in out Update_Query; Mode : in Boolean := False); private type Buffer is new ADO.Parameters.List with record Buf : Unbounded_String; end record; type Update_Query is new Query with record Pos : Natural := 0; Set_Fields : Buffer; Fields : Buffer; Is_Update_Stmt : Boolean := True; end record; procedure Add_Field (Update : in out Update_Query'Class; Name : in String); end ADO.SQL;
----------------------------------------------------------------------- -- are-tests -- Various tests for the are tool (based on examples) -- Copyright (C) 2021 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Text_IO; with Ada.Directories; with Ada.Strings.Maps; with Util.Test_Caller; package body Are.Tests is package Caller is new Util.Test_Caller (Test, "Are.Examples"); procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is begin Caller.Add_Test (Suite, "Test examples c-config", Test_Example_C_Config'Access); Caller.Add_Test (Suite, "Test examples c-help", Test_Example_C_Help'Access); Caller.Add_Test (Suite, "Test examples c-lines", Test_Example_C_Lines'Access); Caller.Add_Test (Suite, "Test examples ada-config", Test_Example_Ada_Config'Access); Caller.Add_Test (Suite, "Test examples ada-help", Test_Example_Ada_Help'Access); Caller.Add_Test (Suite, "Test examples ada-lines", Test_Example_Ada_Lines'Access); if Ada.Directories.Exists ("/usr/bin/go") then Caller.Add_Test (Suite, "Test examples go-config", Test_Example_Go_Config'Access); Caller.Add_Test (Suite, "Test examples go-help", Test_Example_Go_Help'Access); end if; Caller.Add_Test (Suite, "Test Are.Convert_To_Lines_1", Test_Convert_Lines_1'Access); Caller.Add_Test (Suite, "Test Are.Convert_To_Lines_2", Test_Convert_Lines_2'Access); end Add_Tests; procedure Test_Example_C_Config (T : in out Test) is Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute ("make -C examples/c-config clean", Result, Status => 0); T.Execute ("make -C examples/c-config ARE=../../bin/are", Result, Status => 0); T.Execute ("examples/c-config/show-config" & Are.Testsuite.EXE, Result, Status => 0); Util.Tests.Assert_Matches (T, ".*Example of embedded configuration.*", Result, "Invalid C show-config"); end Test_Example_C_Config; procedure Test_Example_Ada_Config (T : in out Test) is Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute ("make -C examples/ada-config clean", Result, Status => 0); T.Execute ("make -C examples/ada-config ARE=../../bin/are", Result, Status => 0); T.Execute ("examples/ada-config/show_config" & Are.Testsuite.EXE, Result, Status => 0); Util.Tests.Assert_Matches (T, ".*Example of embedded configuration.*", Result, "Invalid Ada show_config"); end Test_Example_Ada_Config; procedure Test_Example_Go_Config (T : in out Test) is Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute ("make -C examples/go-config clean", Result, Status => 0); T.Execute ("make -C examples/go-config ARE=../../bin/are", Result, Status => 0); T.Execute ("examples/go-config/show-config", Result, Status => 0); Util.Tests.Assert_Matches (T, ".*Example of embedded configuration.*", Result, "Invalid Go show-config"); end Test_Example_Go_Config; procedure Test_Example_C_Help (T : in out Test) is Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute ("make -C examples/c-help clean", Result, Status => 0); T.Execute ("make -C examples/c-help ARE=../../bin/are", Result, Status => 0); T.Execute ("examples/c-help/show-help" & Are.Testsuite.EXE, Result, Status => 0); Util.Tests.Assert_Matches (T, ".*sh.*", Result, "Invalid C show-help: sh missing"); Util.Tests.Assert_Matches (T, ".*extract.*", Result, "Invalid C show-help: extract missing"); T.Execute ("examples/c-help/show-help sh", Result, Status => 0); Util.Tests.Assert_Matches (T, ".*shell.*", Result, "Invalid C show-help: sh"); T.Execute ("examples/c-help/show-help extract", Result, Status => 0); Util.Tests.Assert_Matches (T, ".*extract files.*", Result, "Invalid C show-help: extract"); end Test_Example_C_Help; procedure Test_Example_C_Lines (T : in out Test) is Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute ("make -C examples/c-lines clean", Result, Status => 0); T.Execute ("make -C examples/c-lines ARE=../../bin/are", Result, Status => 0); T.Execute ("examples/c-lines/show-script" & Are.Testsuite.EXE, Result, Status => 0); Util.Tests.Assert_Matches (T, "Create SQLite 7 lines.*", Result, "Invalid C show-script: SQL statement"); Util.Tests.Assert_Matches (T, "Drop SQLite 4 lines.*", Result, "Invalid C show-script: SQL statement"); end Test_Example_C_Lines; procedure Test_Example_Ada_Help (T : in out Test) is Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute ("make -C examples/ada-help clean", Result, Status => 0); T.Execute ("make -C examples/ada-help ARE=../../bin/are", Result, Status => 0); T.Execute ("examples/ada-help/show_help" & Are.Testsuite.EXE, Result, Status => 0); Util.Tests.Assert_Matches (T, ".*sh.*", Result, "Invalid Ada show-help: sh missing"); Util.Tests.Assert_Matches (T, ".*extract.*", Result, "Invalid Ada show-help: extract missing"); T.Execute ("examples/ada-help/show_help sh", Result, Status => 0); Util.Tests.Assert_Matches (T, ".*shell.*", Result, "Invalid Ada show-help: sh"); T.Execute ("examples/ada-help/show_help extract", Result, Status => 0); Util.Tests.Assert_Matches (T, ".*extract files.*", Result, "Invalid Ada show-help: extract"); end Test_Example_Ada_Help; procedure Test_Example_Ada_Lines (T : in out Test) is Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute ("make -C examples/ada-lines clean", Result, Status => 0); T.Execute ("make -C examples/ada-lines ARE=../../bin/are", Result, Status => 0); T.Execute ("examples/ada-lines/show_script" & Are.Testsuite.EXE, Result, Status => 0); Util.Tests.Assert_Matches (T, "Create SQLite 7 lines.*", Result, "Invalid Ada show_script: SQL statement"); Util.Tests.Assert_Matches (T, "Drop SQLite 4 lines.*", Result, "Invalid Ada show_script: SQL statement"); end Test_Example_Ada_Lines; procedure Test_Example_Go_Help (T : in out Test) is Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute ("make -C examples/go-help clean", Result, Status => 0); T.Execute ("make -C examples/go-help ARE=../../bin/are", Result, Status => 0); T.Execute ("examples/go-help/show-help", Result, Status => 0); Util.Tests.Assert_Matches (T, ".*sh.*", Result, "Invalid Go show-help: sh missing"); Util.Tests.Assert_Matches (T, ".*extract.*", Result, "Invalid Go show-help: extract missing"); T.Execute ("examples/go-help/show-help sh", Result, Status => 0); Util.Tests.Assert_Matches (T, ".*shell.*", Result, "Invalid Go show-help: sh"); T.Execute ("examples/go-help/show-help extract", Result, Status => 0); Util.Tests.Assert_Matches (T, ".*extract files.*", Result, "Invalid Go show-help: extract"); end Test_Example_Go_Help; procedure Test_Convert_Lines_1 (T : in out Test) is use Ada.Strings.Maps; Resource : Resource_Type; Lines : Util.Strings.Vectors.Vector; File : File_Info; begin Resource.Add_File ("lines", "regtests/files/lines-1.txt"); Resource.Separators := To_Set (ASCII.CR) or To_Set (ASCII.LF); File := Resource.Files.First_Element; Resource.Convert_To_Lines (File, Lines); Util.Tests.Assert_Equals (T, 9, Natural (Lines.Length), "Invalid number of lines"); for I in 1 .. 9 loop Util.Tests.Assert_Equals (T, "line" & Util.Strings.Image (I), Lines.Element (I), "Invalid line"); end loop; end Test_Convert_Lines_1; procedure Test_Convert_Lines_2 (T : in out Test) is use Ada.Strings.Maps; Resource : Resource_Type; Lines : Util.Strings.Vectors.Vector; File : File_Info; begin Resource.Add_File ("lines", "regtests/files/lines-2.txt"); Resource.Separators := To_Set (";"); -- Remove newlines and contiguous spaces. Are.Add_Line_Filter (Resource, "[\r\n]", ""); Are.Add_Line_Filter (Resource, "[ \t][ \t]+", " "); -- Remove C comments. Are.Add_Line_Filter (Resource, "/\*[^/]*\*/", ""); -- Remove contiguous spaces (can happen after C comment removal). Are.Add_Line_Filter (Resource, "[ \t][ \t]+", " "); File := Resource.Files.First_Element; Resource.Convert_To_Lines (File, Lines); Util.Tests.Assert_Equals (T, 5, Natural (Lines.Length), "Invalid number of lines"); for I in 1 .. 5 loop Ada.Text_IO.Put_Line (Lines.Element (I)); end loop; Util.Tests.Assert_Equals (T, "pragma synchronous=OFF", Lines.Element (1), "Invalid line 1"); Util.Tests.Assert_Equals (T, "CREATE TABLE IF NOT EXISTS entity_type ( `id`" & " INTEGER PRIMARY KEY AUTOINCREMENT, `name`" & " VARCHAR(127) UNIQUE )", Lines.Element (2), "Invalid line 2"); Util.Tests.Assert_Equals (T, "CREATE TABLE IF NOT EXISTS sequence ( `name`" & " VARCHAR(127) UNIQUE NOT NULL, `version` INTEGER NOT NULL," & " `value` BIGINT NOT NULL, `block_size` BIGINT NOT NULL," & " PRIMARY KEY (`name`))", Lines.Element (3), "Invalid line 3"); Util.Tests.Assert_Equals (T, "INSERT OR IGNORE INTO entity_type (name) VALUES" & " (""entity_type"")", Lines.Element (4), "Invalid line 4"); Util.Tests.Assert_Equals (T, "INSERT OR IGNORE INTO entity_type (name) VALUES" & " (""sequence"")", Lines.Element (5), "Invalid line 5"); end Test_Convert_Lines_2; end Are.Tests;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- I N T E R F A C E S . C -- -- -- -- S p e c -- -- -- -- This specification is derived from the Ada Reference Manual 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. -- -- -- ------------------------------------------------------------------------------ -- SweetAda SFP cutted-down version -- ------------------------------------------------------------------------------ -- GBADA C conversion functions removed -- ------------------------------------------------------------------------------ with System.Parameters; package Interfaces.C is pragma Pure; -- Declaration's based on C's <limits.h> CHAR_BIT : constant := 8; SCHAR_MIN : constant := -128; SCHAR_MAX : constant := 127; UCHAR_MAX : constant := 255; -- Signed and Unsigned Integers. Note that in GNAT, we have ensured that -- the standard predefined Ada types correspond to the standard C types -- Note: the Integer qualifications used in the declaration of type long -- avoid ambiguities when compiling in the presence of s-auxdec.ads and -- a non-private system.address type. type int is new Integer; type short is new Short_Integer; type long is range -(2 ** (System.Parameters.long_bits - Integer'(1))) .. +(2 ** (System.Parameters.long_bits - Integer'(1))) - 1; type long_long is new Long_Long_Integer; type signed_char is range SCHAR_MIN .. SCHAR_MAX; for signed_char'Size use CHAR_BIT; type unsigned is mod 2 ** int'Size; type unsigned_short is mod 2 ** short'Size; type unsigned_long is mod 2 ** long'Size; type unsigned_long_long is mod 2 ** long_long'Size; type unsigned_char is mod (UCHAR_MAX + 1); for unsigned_char'Size use CHAR_BIT; -- Note: the Integer qualifications used in the declaration of ptrdiff_t -- avoid ambiguities when compiling in the presence of s-auxdec.ads and -- a non-private system.address type. type ptrdiff_t is range -(2 ** (System.Parameters.ptr_bits - Integer'(1))) .. +(2 ** (System.Parameters.ptr_bits - Integer'(1)) - 1); type size_t is mod 2 ** System.Parameters.ptr_bits; ---------------------------- -- Characters and Strings -- ---------------------------- type char is new Character; nul : constant char := char'First; function To_C (Item : Character) return char with Inline_Always; function To_Ada (Item : char) return Character with Inline_Always; type char_array is array (size_t range <>) of aliased char; for char_array'Component_Size use CHAR_BIT; function Is_Nul_Terminated (Item : char_array) return Boolean; ------------------------------------ -- Wide Character and Wide String -- ------------------------------------ type wchar_t is new Wide_Character; for wchar_t'Size use Standard'Wchar_T_Size; wide_nul : constant wchar_t := wchar_t'First; function To_C (Item : Wide_Character) return wchar_t with Inline_Always; function To_Ada (Item : wchar_t) return Wide_Character with Inline_Always; type wchar_array is array (size_t range <>) of aliased wchar_t; function Is_Nul_Terminated (Item : wchar_array) return Boolean; type char16_t is new Wide_Character; char16_nul : constant char16_t := char16_t'Val (0); function To_C (Item : Wide_Character) return char16_t; function To_Ada (Item : char16_t) return Wide_Character; type char16_array is array (size_t range <>) of aliased char16_t; function Is_Nul_Terminated (Item : char16_array) return Boolean; type char32_t is new Wide_Wide_Character; char32_nul : constant char32_t := char32_t'Val (0); function To_C (Item : Wide_Wide_Character) return char32_t with Inline_Always; function To_Ada (Item : char32_t) return Wide_Wide_Character with Inline_Always; type char32_array is array (size_t range <>) of aliased char32_t; function Is_Nul_Terminated (Item : char32_array) return Boolean; end Interfaces.C;
with Ada.Containers.Vectors; with GL.Objects.Programs; with GL.Types; with GA_Maths; with Multivectors; package Geosphere is -- some very ancient code to compute a triangulated sphere use Multivectors; type Geosphere is private; type Indices is array (1 .. 3) of integer; Geosphere_Exception : Exception; procedure Add_To_Sphere_List (Sphere : Geosphere); procedure Draw_Sphere_List (Render_Program : GL.Objects.Programs.Program; Normal : GL.Types.Single := 0.0); procedure GS_Compute (Sphere : in out Geosphere; Depth : integer); procedure GS_Draw (Render_Program : GL.Objects.Programs.Program; Sphere : Geosphere; Normal : GL.Types.Single := 0.0); procedure New_Sphere_List (Sphere : Geosphere); private subtype Int3_Range is Integer range 1 .. 3; subtype Int4_Range is Integer range 1 .. 4; subtype Contour_Intersect_Array is GA_Maths.Integer_Array (Int3_Range); subtype Contour_Visited_Array is GA_Maths.Integer_Array (Int3_Range); subtype Neighbour_Array is GA_Maths.Integer_Array (Int3_Range); subtype Indices_Vector is GA_Maths.Integer_Array (Int3_Range); type Child_Array is array (Int4_Range) of Integer; type Geosphere_Face is record Indices : Indices_Vector := (-1, -1, -1); -- Three indices into Vertices vector Child : Child_Array := (-1, -1, -1, -1); Plane : Multivectors.Bivector; D : float := 0.0; Depth : integer := 0; Neighbour : Neighbour_Array := (-1, -1, -1); Contour_Intersect : Contour_Intersect_Array := (-1, -1, -1); Contour_Visited : Contour_Visited_Array := (-1, -1, -1); end record; package Vertex_Vectors is new Ada.Containers.Vectors (Element_Type => Multivectors.M_Vector, Index_Type => Natural); type MV_Vector is new Vertex_Vectors.Vector with null record; package Face_Vectors is new Ada.Containers.Vectors (Element_Type => Geosphere_Face, Index_Type => Positive); type F_Vector is new Face_Vectors.Vector with null record; type Geosphere is record Depth : integer := 0; Vertices : MV_Vector; Faces : F_Vector; end record; end Geosphere;
with STM32GD.Board; with STM32_SVD; use STM32_SVD; with STM32_SVD.USART; use STM32_SVD.USART; package body Last_Chance_Handler is procedure Put_Char (Char : Byte) is begin while USART1_Periph.ISR.TXE = 0 loop null; end loop; USART1_Periph.TDR.TDR := UInt9 (Char); end Put_Char; procedure Put_String (String : System.Address) is S : array (0 .. 31) of Byte; for S'Address use String; begin for C of S loop exit when C = Byte (0); Put_Char (C); end loop; end Put_String; function String_Length (String : System.Address) return Natural is S : array (0 .. 31) of Byte; for S'Address use String; Length : Natural := 0; begin for C of S loop exit when C = Byte (0); Length := Length + 1; end loop; return Length; end String_Length; ------------------------- -- Last_Chance_Handler -- ------------------------- procedure Last_Chance_Handler (Msg : System.Address; Line : Integer) is begin Put_Char (Byte (16#10#)); Put_Char (Byte (16#02#)); Put_Char (Byte (16#D8#)); Put_Char (Byte (16#45#)); Put_Char (Byte (16#82#)); Put_Char (Byte (16#40# + String_Length (Msg))); Put_String (Msg); Put_Char (Byte (16#19#)); Put_Char (Byte (Line / 256)); Put_Char (Byte (Line mod 256)); Put_Char (Byte (16#10#)); Put_Char (Byte (16#03#)); STM32GD.Board.LED2.Set; loop null; end loop; end Last_Chance_Handler; end Last_Chance_Handler;
-- -- The author disclaims copyright to this source code. In place of -- a legal notice, here is a blessing: -- -- May you do good and not evil. -- May you find forgiveness for yourself and forgive others. -- May you share freely, not taking more than you give. -- with Ada.Strings.Fixed; with Ada.Strings.Unbounded; with Ada.Calendar; with Ada.Exceptions; with Ada.Text_IO; with Setup; with Database.Jobs; with Database.Events; with Commands; with Terminal_IO; with Navigate; with CSV_IO; with Types; package body Parser is Run_Program : Boolean := True; Last_Command : Ada.Strings.Unbounded.Unbounded_String; procedure Set (Command : in String); procedure Add (Command : in String); procedure Event (Command : in String); procedure Transfer (Command : in String); function Exit_Program return Boolean is begin return not Run_Program; end Exit_Program; procedure Set (Command : in String) is Space_Pos : constant Natural := Ada.Strings.Fixed.Index (Command, " "); First : constant String := (if Space_Pos = 0 then Command else Command (Command'First .. Space_Pos - 1)); Rest : constant String := (if Space_Pos = 0 then "" else Ada.Strings.Fixed.Trim (Command (Space_Pos .. Command'Last), Ada.Strings.Both)); Lookup_Success : Boolean; begin if First = "job" then declare New_Current_Job : Types.Job_Id; begin Navigate.Lookup_Job (Text => Rest, Job => New_Current_Job, Success => Lookup_Success); if Lookup_Success then Commands.Set_Current_Job (New_Current_Job); else raise Constraint_Error with "Could not lookup Text"; end if; end; else raise Constraint_Error with "Set with unknown First"; end if; end Set; procedure Add (Command : in String) is Space_Pos : constant Natural := Ada.Strings.Fixed.Index (Command, " "); First : constant String := (if Space_Pos = 0 then Command else Command (Command'First .. Space_Pos - 1)); Rest : constant String := (if Space_Pos = 0 then "" else Command (Space_Pos .. Command'Last)); begin if First = "job" then Commands.Create_Job (Database.Jobs.Get_New_Job_Id, Ada.Strings.Fixed.Trim (Rest, Ada.Strings.Both), Parent => Database.Jobs.Get_Current_Job); -- elsif First = "list" then -- Database.Create_List -- (Ada.Strings.Fixed.Trim (Rest, Ada.Strings.Both)); else raise Constraint_Error; end if; end Add; procedure Event (Command : in String) is pragma Unreferenced (Command); -- Space_Pos : constant Natural -- := Ada.Strings.Fixed.Index (Command, " "); -- First : constant String -- := (if Space_Pos = 0 then Command -- else Command (Command'First .. Space_Pos - 1)); -- Rest : constant String -- := (if Space_Pos = 0 then "" -- else Command (Space_Pos .. Command'Last)); Id : Database.Events.Event_Id; pragma Unreferenced (Id); begin Database.Events.Add_Event (Database.Jobs.Get_Current_Job, Ada.Calendar.Clock, Database.Events.Done, Id); end Event; procedure Transfer (Command : in String) is use Database.Jobs; Success : Boolean; To_Parent : Types.Job_Id; begin Navigate.Lookup_Job (Command, To_Parent, Success); Transfer (Job => Get_Current_Job, To_Parent => To_Parent); end Transfer; procedure Parse_Input (Input : in String) is Space_Pos : constant Natural := Ada.Strings.Fixed.Index (Input, " "); First : constant String := (if Space_Pos = 0 then Input else Input (Input'First .. Space_Pos - 1)); Rest : constant String := (if Space_Pos = 0 then "" else Ada.Strings.Fixed.Trim (Input (Space_Pos .. Input'Last), Ada.Strings.Both)); begin Last_Command := Ada.Strings.Unbounded.To_Unbounded_String (Input); if First = "" then null; elsif First = "quit" then Run_Program := False; elsif First = "help" then Terminal_IO.Put_Help; elsif First = "view" or First = "ls" then Terminal_IO.Put_Jobs; -- Terminal_IO.Put_Jobs -- (Database.Jobs.Get_Jobs (Database.Jobs.Get_Current_Job)); elsif First = "top" or First = "cd" then Terminal_IO.Put_Jobs; -- Terminal_IO.Put_Jobs -- (Database.Jobs.Get_Jobs (Database.Jobs.Top_Level)); elsif First = "set" then Set (Rest); elsif First = "show" or First = "cat" then Terminal_IO.Show_Job (Database.Jobs.Get_Current_Job); elsif First = "add" then Add (Rest); elsif First = "split" then raise Program_Error; elsif First = "move" then Transfer (Rest); elsif First = "trans" then Transfer (Rest); elsif First = "event" then Event (Rest); elsif First = "export" then CSV_IO.Export (Setup.Program_Name & ".csv"); else Terminal_IO.Put_Error ("Unknown command: '" & Get_Last_Command & "'"); end if; exception when Constraint_Error => Terminal_IO.Put_Error ("Constraint_Error in parser"); when E : others => Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (E)); Terminal_IO.Put_Error (" Other exception raised"); end Parse_Input; function Get_Last_Command return String is begin return Ada.Strings.Unbounded.To_String (Last_Command); end Get_Last_Command; end Parser;
------------------------------------------------------------------------------ -- Copyright (c) 2011-2013, 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. -- ------------------------------------------------------------------------------ with Natools.Chunked_Strings.Tests.Bugfixes; with Natools.Chunked_Strings.Tests.Coverage; with Natools.Chunked_Strings.Tests.CXA4010; with Natools.Chunked_Strings.Tests.CXA4011; with Natools.Chunked_Strings.Tests.CXA4030; with Natools.Chunked_Strings.Tests.CXA4031; with Natools.Chunked_Strings.Tests.CXA4032; with Natools.Chunked_Strings.Tests.Memory; with Natools.Accumulators.Tests; package body Natools.Chunked_Strings.Tests is package NT renames Natools.Tests; procedure All_Blackbox_Tests (Report : in out Natools.Tests.Reporter'Class) is procedure Test_CXA4010 is new CXA4010; procedure Test_CXA4011 is new CXA4011; procedure Test_CXA4030 is new CXA4030; procedure Test_CXA4031 is new CXA4031; procedure Test_CXA4032 is new CXA4032; procedure Test_Bugfixes is new Bugfixes; begin NT.Section (Report, "Blackbox tests of Chunked_Strings"); Test_CXA4010 (Report); Test_CXA4011 (Report); Test_CXA4030 (Report); Test_CXA4031 (Report); Test_CXA4032 (Report); NT.Section (Report, "String_Accumulator interface"); declare Acc : Chunked_String; begin Accumulators.Tests.Test (Report, Acc); end; NT.End_Section (Report); Test_Bugfixes (Report); NT.End_Section (Report); end All_Blackbox_Tests; procedure All_Greybox_Tests (Report : in out Natools.Tests.Reporter'Class) is procedure Test_Coverage is new Coverage; begin NT.Section (Report, "Greybox tests for Chunked_Strings"); Test_Coverage (Report); NT.End_Section (Report); end All_Greybox_Tests; procedure All_Whitebox_Tests (Report : in out Natools.Tests.Reporter'Class) is procedure Test_Memory is new Memory; begin NT.Section (Report, "Whitebox tests for Chunked_Strings"); Test_Memory (Report); NT.End_Section (Report); end All_Whitebox_Tests; procedure All_Tests (Report : in out Natools.Tests.Reporter'Class) is begin NT.Section (Report, "All tests of Chunked_Strings"); All_Blackbox_Tests (Report); All_Greybox_Tests (Report); All_Whitebox_Tests (Report); NT.End_Section (Report); end All_Tests; procedure Dump (Report : in out Natools.Tests.Reporter'Class; Dumped : in Chunked_String) is package Maps renames Ada.Strings.Maps; use type Maps.Character_Set; procedure Print_Chunk (Index : Positive; Chunk : String_Access); procedure Print_Chunks (Data : Chunk_Array_Access); procedure Print_Line (Raw : String); Printable : constant Maps.Character_Set := Maps.To_Set (Maps.Character_Ranges'((Low => 'a', High => 'z'), (Low => 'A', High => 'Z'), (Low => '0', High => '9'))) or Maps.To_Set (" -_"); Non_Printable : constant Character := '.'; procedure Print_Chunk (Index : Positive; Chunk : String_Access) is I : Natural; begin if Chunk = null then NT.Info (Report, "Chunk" & Positive'Image (Index) & ": null"); else NT.Info (Report, "Chunk" & Positive'Image (Index) & ": " & Natural'Image (Chunk.all'First) & " .." & Natural'Image (Chunk.all'Last)); I := Chunk.all'First; while I <= Chunk.all'Last loop Print_Line (Chunk.all (I .. Positive'Min (Chunk.all'Last, I + 16))); I := I + 16; end loop; end if; end Print_Chunk; procedure Print_Chunks (Data : Chunk_Array_Access) is begin if Data = null then NT.Info (Report, "Null data"); end if; if Data.all'Length = 0 then NT.Info (Report, "Empty data"); end if; for C in Data.all'Range loop Print_Chunk (C, Data.all (C)); end loop; end Print_Chunks; procedure Print_Line (Raw : String) is Hex : constant String := "0123456789ABCDEF"; Line : String (1 .. 4 * Raw'Length + 2) := (others => ' '); begin for I in Raw'Range loop declare Pos : constant Natural := Character'Pos (Raw (I)); High : constant Natural := (Pos - 1) / 16; Low : constant Natural := (Pos - 1) mod 16; Hex_Base : constant Positive := Line'First + 3 * (I - Raw'First); Raw_Base : constant Positive := Line'First + 3 * Raw'Length + 2 + (I - Raw'First); begin Line (Hex_Base) := Hex (Hex'First + High); Line (Hex_Base + 1) := Hex (Hex'First + Low); if Maps.Is_In (Raw (I), Printable) then Line (Raw_Base) := Raw (I); else Line (Raw_Base) := Non_Printable; end if; end; end loop; NT.Info (Report, Line); end Print_Line; begin NT.Info (Report, "Chunk_Size " & Positive'Image (Dumped.Chunk_Size) & " (default" & Positive'Image (Default_Chunk_Size) & ')'); NT.Info (Report, "Allocation_Unit " & Positive'Image (Dumped.Allocation_Unit) & " (default" & Positive'Image (Default_Allocation_Unit) & ')'); NT.Info (Report, "Size " & Natural'Image (Dumped.Size)); Print_Chunks (Dumped.Data); end Dump; procedure Test (Report : in out Natools.Tests.Reporter'Class; Test_Name : in String; Computed : in Chunked_String; Reference : in String) is begin if not Is_Valid (Computed) then NT.Item (Report, Test_Name, NT.Error); return; end if; if Computed = To_Chunked_String (Reference) then NT.Item (Report, Test_Name, NT.Success); else NT.Item (Report, Test_Name, NT.Fail); NT.Info (Report, "Computed """ & To_String (Computed) & '"'); NT.Info (Report, "Reference """ & Reference & '"'); end if; end Test; procedure Test (Report : in out Natools.Tests.Reporter'Class; Test_Name : in String; Computed : in Chunked_String; Reference : in Chunked_String) is begin if not Is_Valid (Computed) then NT.Item (Report, Test_Name, NT.Error); return; end if; if not Is_Valid (Reference) then NT.Item (Report, Test_Name, NT.Error); return; end if; if Computed = Reference then NT.Item (Report, Test_Name, NT.Success); else NT.Item (Report, Test_Name, NT.Fail); NT.Info (Report, "Computed """ & To_String (Computed) & '"'); NT.Info (Report, "Reference """ & To_String (Reference) & '"'); end if; end Test; procedure Test (Report : in out Natools.Tests.Reporter'Class; Test_Name : in String; Computed : in Natural; Reference : in Natural) is begin if Computed = Reference then NT.Item (Report, Test_Name, NT.Success); else NT.Item (Report, Test_Name, NT.Fail); NT.Info (Report, "Computed" & Natural'Image (Computed) & ", expected" & Natural'Image (Reference)); end if; end Test; end Natools.Chunked_Strings.Tests;
------------------------------------------------------------------------------ -- -- package Debugged (body) -- ------------------------------------------------------------------------------ -- Update information: -- -- 1996.07.26 (Jacob Sparre Andersen) -- Copied from Debugging (1996.07.26). -- -- (Insert additional update information above this line.) ------------------------------------------------------------------------------ with Ada.Command_Line; with Ada.Text_IO; package body JSA.Debugged is --------------------------------------------------------------------------- -- procedure Message: -- -- Writes a message to Current_Error if debugging is activated. procedure Message (Item : in String) is use Ada.Text_IO; begin -- Message if Debug then Put (Current_Error, Item); -- Flush (Current_Error); end if; end Message; --------------------------------------------------------------------------- -- procedure Message_Line: -- -- Writes a message and a new line to Current_Error if debugging is -- activated. procedure Message_Line (Item : in String) is use Ada.Text_IO; begin -- Message_Line if Debug then Put_Line (Current_Error, Item); -- Flush (Current_Error); end if; end Message_Line; --------------------------------------------------------------------------- use Ada.Command_Line; use Ada.Text_IO; Error_Log : File_Type; Log_To_Current_Error : Boolean := True; Log_File_Argument_Index : Positive; begin -- Debugged for Index in 1 .. Argument_Count - 1 loop if Argument (Index) = "-errorlog" then Log_To_Current_Error := False; Log_File_Argument_Index := Index + 1; exit; end if; end loop; if not Log_To_Current_Error then if Argument (Log_File_Argument_Index) = "-" then Set_Error (Standard_Output); else Create (File => Error_Log, Name => Argument (Log_File_Argument_Index)); Set_Error (Error_Log); end if; end if; end JSA.Debugged;
package Enclosing_Record_Reference is pragma elaborate_body; type T is record F1: access function(x: integer) return T; F2: access function(x: T) return integer; --?? F3: access function(x: T) return T; --?? F4: access function(x: integer) return access T; --?? F5: access function(x: access T) return integer; F6: access function(x: access T) return access T; F7: access function(x: T) return access T; --?? F8: access function(x: access T) return T; end record; end Enclosing_Record_Reference;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2010-2012, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- Abstract API for text decoders/encoders. -- -- Decoder's states and decoders implementation are separate objects. ------------------------------------------------------------------------------ with Ada.Streams; with League.Strings; with Matreshka.Internals.Stream_Element_Vectors; with Matreshka.Internals.Strings; private with Matreshka.Internals.Unicode; package Matreshka.Internals.Text_Codecs is pragma Preelaborate; type Character_Set is range 0 .. 2999; -- IANA MIB code of the character set. MIB_UTF8 : constant Character_Set := 106; MIB_UTF16 : constant Character_Set := 1012; MIB_UTF16BE : constant Character_Set := 1013; MIB_UTF16LE : constant Character_Set := 1014; MIB_UTF32 : constant Character_Set := 1017; MIB_UTF32BE : constant Character_Set := 1018; MIB_UTF32LE : constant Character_Set := 1019; function To_Character_Set (Item : League.Strings.Universal_String) return Character_Set; -- Converts name of character encoding into internal representation. function Transform_Character_Set_Name (Name : League.Strings.Universal_String) return League.Strings.Universal_String; -- Transforms name of character set to normalized form. Returns empty -- string when name starts or ends from/by separator character or contains -- not valid characters. ---------------------- -- Abstract_Decoder -- ---------------------- type Decoder_Mode is (Raw, XML_1_0, XML_1_1); -- Mode of text postprocessing after decoding. -- -- Decoder is responsible for XML1.0/XML1.1 end-of-line handling when -- its state created with corresponding mode. type Abstract_Decoder is abstract tagged private; -- Abstract root tagged type for decoders. type Decoder_Access is access all Abstract_Decoder'Class; not overriding function Is_Error (Self : Abstract_Decoder) return Boolean is abstract; -- Returns True when error is occured during decoding. not overriding function Is_Mailformed (Self : Abstract_Decoder) return Boolean is abstract; -- Returns True when error is occured during decoding or decoding is -- incomplete. procedure Decode (Self : in out Abstract_Decoder'Class; Data : Ada.Streams.Stream_Element_Array; String : out Matreshka.Internals.Strings.Shared_String_Access); -- Decodes data and save results in new allocated string. not overriding procedure Decode_Append (Self : in out Abstract_Decoder; Data : Ada.Streams.Stream_Element_Array; String : in out Matreshka.Internals.Strings.Shared_String_Access) is abstract; -- Decodes data and appends them to specified string. String can be -- reallocated when necessary. type Decoder_Factory is access function (Mode : Decoder_Mode) return Abstract_Decoder'Class; -- Decoder factory ---------------------- -- Abstract_Encoder -- ---------------------- package MISEV renames Matreshka.Internals.Stream_Element_Vectors; type Abstract_Encoder is abstract tagged limited null record; -- Abstract root tagged type for encoders. not overriding procedure Encode (Self : in out Abstract_Encoder; String : not null Matreshka.Internals.Strings.Shared_String_Access; Buffer : out MISEV.Shared_Stream_Element_Vector_Access) is abstract; type Encoder_Factory is access function return Abstract_Encoder'Class; ---------------------- -- Factory registry -- ---------------------- function Decoder (Set : Character_Set) return Decoder_Factory; -- Returns decoder factory for the specified character set. function Encoder (Set : Character_Set) return Encoder_Factory; -- Returns encoder factory for the specified character set. private procedure Unchecked_Append_Raw (Self : in out Abstract_Decoder'Class; Buffer : not null Matreshka.Internals.Strings.Shared_String_Access; Code : Matreshka.Internals.Unicode.Code_Point); -- Appends code to the string. procedure Unchecked_Append_XML10 (Self : in out Abstract_Decoder'Class; Buffer : not null Matreshka.Internals.Strings.Shared_String_Access; Code : Matreshka.Internals.Unicode.Code_Point); -- Appends code to the string filtering out and replacing end of line -- characters according to XML 1.0 specification. procedure Unchecked_Append_XML11 (Self : in out Abstract_Decoder'Class; Buffer : not null Matreshka.Internals.Strings.Shared_String_Access; Code : Matreshka.Internals.Unicode.Code_Point); -- Appends code to the string filtering out and replacing end of line -- characters according to XML 1.1 specification. type Abstract_Decoder is abstract tagged record Skip_LF : Boolean := False; Unchecked_Append : not null access procedure (Self : in out Abstract_Decoder'Class; Buffer : not null Matreshka.Internals.Strings.Shared_String_Access; Code : Matreshka.Internals.Unicode.Code_Point) := Unchecked_Append_Raw'Access; end record; end Matreshka.Internals.Text_Codecs;
-- -- Copyright 2018 The wookey project team <wookey@ssi.gouv.fr> -- - Ryad Benadjila -- - Arnauld Michelizza -- - Mathieu Renard -- - Philippe Thierry -- - Philippe Trebuchet -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- with ewok.tasks; use ewok.tasks; with ewok.sanitize; with ewok.perm; with ewok.debug; with types.c; use type types.c.t_retval; with c.kernel; package body ewok.syscalls.rng with spark_mode => off is pragma warnings (off); function to_integer is new ada.unchecked_conversion (unsigned_16, integer); pragma warnings (on); procedure sys_get_random (caller_id : in ewok.tasks_shared.t_task_id; params : in out t_parameters; mode : in ewok.tasks_shared.t_task_mode) is length : unsigned_16 with address => params(1)'address; buffer : types.c.c_string (1 .. to_integer(length)) with address => to_address (params(0)); begin -- Forbidden after end of task initialization if not is_init_done (caller_id) then goto ret_denied; end if; -- Does buffer'address is in the caller address space ? if not ewok.sanitize.is_range_in_data_slot (to_system_address (buffer'address), types.to_unsigned_32(length), caller_id, mode) then pragma DEBUG (debug.log (debug.ERROR, ewok.tasks.tasks_list(caller_id).name & ": sys_get_random(): 'value' parameter not in caller space")); goto ret_inval; end if; -- Size is arbitrary limited to 16 bytes to avoid exhausting the entropy pool -- FIXME - is that check really correct? if length > 16 then goto ret_inval; end if; -- Is the task allowed to use the RNG? if not ewok.perm.ressource_is_granted (ewok.perm.PERM_RES_TSK_RNG, caller_id) then pragma DEBUG (debug.log (debug.ERROR, ewok.tasks.tasks_list(caller_id).name & ": sys_get_random(): permission not granted")); goto ret_denied; end if; -- Calling the RNG which handle the potential random source errors (case -- of harware random sources such as TRNG IP) -- NOTE: there is some time when the generated random -- content may be weak for various reason due to arch-specific -- constraint. In this case, the return value is set to -- busy. Please check this return value when using this -- syscall to avoid using weak random content if c.kernel.get_random (buffer, length) /= types.c.SUCCESS then pragma DEBUG (debug.log (debug.ERROR, ewok.tasks.tasks_list(caller_id).name & ": sys_get_random(): weak seed")); goto ret_busy; end if; set_return_value (caller_id, mode, SYS_E_DONE); ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE); return; <<ret_inval>> set_return_value (caller_id, mode, SYS_E_INVAL); ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE); return; <<ret_busy>> set_return_value (caller_id, mode, SYS_E_BUSY); ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE); return; <<ret_denied>> set_return_value (caller_id, mode, SYS_E_DENIED); ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE); return; end sys_get_random; end ewok.syscalls.rng;
----------------------------------------------------------------------- -- awa-blogs-module -- Blog and post management module -- Copyright (C) 2011, 2012, 2013, 2017 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Util.Log.Loggers; with AWA.Modules.Get; with AWA.Modules.Beans; with AWA.Blogs.Beans; with AWA.Applications; with AWA.Services.Contexts; with AWA.Permissions; with AWA.Permissions.Services; with AWA.Workspaces.Models; with AWA.Workspaces.Modules; with ADO.Objects; with ADO.Sessions; with Ada.Calendar; package body AWA.Blogs.Modules is package ASC renames AWA.Services.Contexts; Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("AWA.Blogs.Module"); package Register is new AWA.Modules.Beans (Module => Blog_Module, Module_Access => Blog_Module_Access); -- ------------------------------ -- Initialize the blog module. -- ------------------------------ overriding procedure Initialize (Plugin : in out Blog_Module; App : in AWA.Modules.Application_Access; Props : in ASF.Applications.Config) is begin Log.Info ("Initializing the blogs module"); -- Setup the resource bundles. App.Register ("blogMsg", "blogs"); Register.Register (Plugin => Plugin, Name => "AWA.Blogs.Beans.Post_Bean", Handler => AWA.Blogs.Beans.Create_Post_Bean'Access); Register.Register (Plugin => Plugin, Name => "AWA.Blogs.Beans.Post_List_Bean", Handler => AWA.Blogs.Beans.Create_Post_List_Bean'Access); Register.Register (Plugin => Plugin, Name => "AWA.Blogs.Beans.Blog_Admin_Bean", Handler => AWA.Blogs.Beans.Create_Blog_Admin_Bean'Access); Register.Register (Plugin => Plugin, Name => "AWA.Blogs.Beans.Blog_Bean", Handler => AWA.Blogs.Beans.Create_Blog_Bean'Access); Register.Register (Plugin => Plugin, Name => "AWA.Blogs.Beans.Status_List_Bean", Handler => AWA.Blogs.Beans.Create_Status_List'Access); Register.Register (Plugin => Plugin, Name => "AWA.Blogs.Beans.Stat_Bean", Handler => AWA.Blogs.Beans.Create_Blog_Stat_Bean'Access); AWA.Modules.Module (Plugin).Initialize (App, Props); end Initialize; -- ------------------------------ -- Get the blog module instance associated with the current application. -- ------------------------------ function Get_Blog_Module return Blog_Module_Access is function Get is new AWA.Modules.Get (Blog_Module, Blog_Module_Access, NAME); begin return Get; end Get_Blog_Module; -- ------------------------------ -- Create a new blog for the user workspace. -- ------------------------------ procedure Create_Blog (Model : in Blog_Module; Title : in String; Result : out ADO.Identifier) is pragma Unreferenced (Model); use type ADO.Identifier; Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current; User : constant ADO.Identifier := Ctx.Get_User_Identifier; DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx); Blog : AWA.Blogs.Models.Blog_Ref; WS : AWA.Workspaces.Models.Workspace_Ref; begin Log.Info ("Creating blog {0} for user", Title); Ctx.Start; AWA.Workspaces.Modules.Get_Workspace (DB, Ctx, WS); -- Check that the user has the create blog permission on the given workspace. AWA.Permissions.Check (Permission => ACL_Create_Blog.Permission, Entity => WS); Blog.Set_Name (Title); Blog.Set_Workspace (WS); Blog.Set_Create_Date (Ada.Calendar.Clock); Blog.Save (DB); -- Add the permission for the user to use the new blog. AWA.Workspaces.Modules.Add_Permission (Session => DB, User => User, Entity => Blog, Workspace => WS.Get_Id, List => (ACL_Delete_Blog.Permission, ACL_Update_Post.Permission, ACL_Create_Post.Permission, ACL_Delete_Post.Permission)); Ctx.Commit; Result := Blog.Get_Id; Log.Info ("Blog {0} created for user {1}", ADO.Identifier'Image (Result), ADO.Identifier'Image (User)); end Create_Blog; -- ------------------------------ -- Create a new post associated with the given blog identifier. -- ------------------------------ procedure Create_Post (Model : in Blog_Module; Blog_Id : in ADO.Identifier; Title : in String; URI : in String; Text : in String; Comment : in Boolean; Status : in AWA.Blogs.Models.Post_Status_Type; Result : out ADO.Identifier) is pragma Unreferenced (Model); use type ADO.Identifier; Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current; User : constant ADO.Identifier := Ctx.Get_User_Identifier; DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx); Blog : AWA.Blogs.Models.Blog_Ref; Post : AWA.Blogs.Models.Post_Ref; Found : Boolean; begin Log.Debug ("Creating post for user"); Ctx.Start; -- Get the blog instance. Blog.Load (Session => DB, Id => Blog_Id, Found => Found); if not Found then Log.Error ("Blog {0} not found", ADO.Identifier'Image (Blog_Id)); raise Not_Found with "Blog not found"; end if; -- Check that the user has the create post permission on the given blog. AWA.Permissions.Check (Permission => ACL_Create_Post.Permission, Entity => Blog); -- Build the new post. Post.Set_Title (Title); Post.Set_Text (Text); Post.Set_Create_Date (Ada.Calendar.Clock); Post.Set_Uri (URI); Post.Set_Author (Ctx.Get_User); Post.Set_Status (Status); Post.Set_Blog (Blog); Post.Set_Allow_Comments (Comment); Post.Save (DB); Ctx.Commit; Result := Post.Get_Id; Log.Info ("Post {0} created for user {1}", ADO.Identifier'Image (Result), ADO.Identifier'Image (User)); end Create_Post; -- ------------------------------ -- Update the post title and text associated with the blog post identified by <b>Post</b>. -- ------------------------------ procedure Update_Post (Model : in Blog_Module; Post_Id : in ADO.Identifier; Title : in String; URI : in String; Text : in String; Comment : in Boolean; Status : in AWA.Blogs.Models.Post_Status_Type) is pragma Unreferenced (Model); use type AWA.Blogs.Models.Post_Status_Type; Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current; DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx); Post : AWA.Blogs.Models.Post_Ref; Found : Boolean; begin Ctx.Start; Post.Load (Session => DB, Id => Post_Id, Found => Found); if not Found then Log.Error ("Post {0} not found", ADO.Identifier'Image (Post_Id)); raise Not_Found; end if; -- Check that the user has the update post permission on the given post. AWA.Permissions.Check (Permission => ACL_Update_Post.Permission, Entity => Post); if Status = AWA.Blogs.Models.POST_PUBLISHED and then Post.Get_Publish_Date.Is_Null then Post.Set_Publish_Date (ADO.Nullable_Time '(Is_Null => False, Value => Ada.Calendar.Clock)); end if; Post.Set_Title (Title); Post.Set_Text (Text); Post.Set_Uri (URI); Post.Set_Status (Status); Post.Set_Allow_Comments (Comment); Post.Save (DB); Ctx.Commit; end Update_Post; -- ------------------------------ -- Delete the post identified by the given identifier. -- ------------------------------ procedure Delete_Post (Model : in Blog_Module; Post_Id : in ADO.Identifier) is pragma Unreferenced (Model); Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current; DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx); Post : AWA.Blogs.Models.Post_Ref; Found : Boolean; begin Ctx.Start; Post.Load (Session => DB, Id => Post_Id, Found => Found); if not Found then Log.Error ("Post {0} not found", ADO.Identifier'Image (Post_Id)); raise Not_Found; end if; -- Check that the user has the delete post permission on the given post. AWA.Permissions.Check (Permission => ACL_Delete_Post.Permission, Entity => Post); Post.Delete (Session => DB); Ctx.Commit; end Delete_Post; end AWA.Blogs.Modules;
-- ----------------------------------------------------------------------------- -- Copyright (C) 2003-2019 Stichting Mapcode Foundation (http://www.mapcode.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- ----------------------------------------------------------------------------- with Ada.Characters.Handling; package body Mapcodes.Languages is use Mapcode_Utils; -- Get the Language from its name in its language -- Raises, if the output language is not known: -- Unknown_Language : exception; function Get_Language (Name : Unicode_Sequence) return Language_List is use type Language_Utils.Unicode_Sequence; begin for L in Language_Defs.Langs'Range loop if Language_Defs.Langs(L).Name.Txt = Name then -- Name is the name of language L return Language_List (L); end if; end loop; return Default_Language; end Get_Language; -- Get the language of a text (territory name or mapcode) -- All the characters must be of the same language, otherwise raises -- Invalid_Text : exception; function Get_Language (Input : Wide_String) return Language_List is First : Natural; Found : Boolean; Lang : Language_Defs.Language_List; function Is_Shared (C : Wide_Character) return Boolean is (C <= '9' or else C = 'I' or else C = 'O'); begin -- Discard empty string if Input'Length = 0 then raise Invalid_Text; end if; -- Find first non shared character First := 0; for I in Input'Range loop if not Is_Shared (Input(I)) then First := I; exit; end if; end loop; if First = 0 then -- All characters are shared => Roman Lang := Language_Defs.Language_List (Default_Language); else -- Find language of first character Found := False; for L in Language_Defs.Langs'Range loop if not Is_Shared (Input(First)) and then Input(First) >= Language_Defs.Langs(L).First and then Input(First) <= Language_Defs.Langs(L).Last then Found := True; Lang := L; exit; end if; end loop; if not Found then raise Invalid_Text; end if; end if; -- Check that all characters belong to this language for W of Input loop if W /= '.' and then W /= '-' and then not Is_Shared (W) and then (W < Language_Defs.Langs(Lang).First or else W > Language_Defs.Langs(Lang).Last) then raise Invalid_Text; end if; end loop; return Language_List (Lang); end Get_Language; -- Does a language use Abjad conversion function Is_Abjad (Language : Language_List) return Boolean is begin return Language = Greek or else Language = Hebrew or else Language = Arabic or else Language = Korean; end Is_Abjad; -- Convert From Abjad procedure Convert_From_Abjad (Str : in out As_U.Asu_Us) is Lstr, Tail : As_U.Asu_Us; Index, Form : Natural; Code : Integer; use type As_U.Asu_Us; -- Character code at a given index ( '4' -> 4) function Str_At (P : Positive) return Natural is (Character'Pos (Lstr.Element (P)) - Character'Pos ('0')); begin -- Save precision tail, including '-' Lstr := Str; Index := Lstr.Locate ("-"); if Index /= 0 then Tail := Lstr.Uslice (Index, Lstr.Length); Lstr.Delete (Index, Lstr.Length); end if; Lstr := As_U.Tus (Aeu_Unpack (Lstr.Image)); Index := Lstr.Locate ("."); if Index < 3 or else Index > 6 then return; end if; Form := 10 * (Index - 1) + (Lstr.Length - Index); if Form = 23 then Code := Str_At (4) * 8 + Str_At (5) - 18; Lstr := Lstr.Uslice (1, 2) & '.' & Encode_A_Char (Code) & Lstr.Element (6); elsif Form = 24 then Code := Str_At (4) * 8 + Str_At (5) - 18; if Code >= 32 then Lstr := Lstr.Uslice (1, 2) & Encode_A_Char (Code - 32) & '.' & Lstr.Element (6) & Lstr.Element (7); else Lstr := Lstr.Uslice (1, 2) & '.' & Encode_A_Char (Code) & Lstr.Element (6) & Lstr.Element (7); end if; elsif Form = 34 then Code := Str_At (3) * 10 + Str_At (6) - 7; if Code < 31 then Lstr := Lstr.Uslice (1, 2) & '.' & Encode_A_Char (Code) & Lstr.Element (5) & Lstr.Element (7) & Lstr.Element (8); elsif Code < 62 then Lstr := Lstr.Uslice (1, 2) & Encode_A_Char (Code - 31) & '.' & Lstr.Element (5) & Lstr.Element (7) & Lstr.Element (8); else Lstr := Lstr.Uslice (1, 2) & Encode_A_Char (Code - 62) & Lstr.Element (5) & '.' & Lstr.Element (7) & Lstr.Element (8); end if; elsif Form = 35 then Code := Str_At (3) * 8 + Str_At (7) - 18; if Code >= 32 then Lstr := Lstr.Uslice (1, 2) & Encode_A_Char (Code - 32) & Lstr.Element (5) & '.' & Lstr.Element (6) & Lstr.Element (8) & Lstr.Element (9); else Lstr := Lstr.Uslice (1, 2) & Encode_A_Char (Code) & '.' & Lstr.Element (5) & Lstr.Element (6) & Lstr.Element (8) & Lstr.Element (9); end if; elsif Form = 45 then Code := Str_At (3) * 100 + Str_At (6) * 10 + Str_At (9) - 39; Lstr := Lstr.Uslice (1, 2) & Encode_A_Char (Code / 31) & Lstr.Element (4) & '.' & Lstr.Element (7) & Lstr.Element (8) & Lstr.Element (10) & Encode_A_Char (Code rem 31); elsif Form = 55 then Code := Str_At (3) * 100 + Str_At (7) * 10 + Str_At (10) - 39; Lstr := Lstr.Uslice (1, 2) & Encode_A_Char (Code / 31) & Lstr.Element (4) & Lstr.Element (5) & '.' & Lstr.Element (8) & Lstr.Element (9) & Lstr.Element (11) & Encode_A_Char (Code rem 31); else return; end if; Str := As_U.Tus (Aeu_Pack (Lstr, False)) & Tail; end Convert_From_Abjad; -- Convert into Abjad procedure Convert_Into_Abjad (Str : in out As_U.Asu_Us) is Lstr, Tail : As_U.Asu_Us; Index, Form : Natural; Code : Integer; C1, C2, C3 : Integer := 0; use type As_U.Asu_Us; -- Character pos at a given index function Str_At (P : Positive) return Natural is (Character'Pos (Lstr.Element (P))); function Char_Of (P : Natural) return Character is (Character'Val (P + Character'Pos('0'))); begin -- Save precision tail, including '-' Lstr := Str; Index := Str.Locate ("-"); if Index /= 0 then Tail := Lstr.Uslice (Index, Str.Length); Lstr.Delete (Index, Lstr.Length); end if; Lstr := As_U.Tus (Aeu_Unpack (Lstr.Image)); Index := Lstr.Locate ("."); if Index < 3 or else Index > 6 then return; end if; Form := 10 * (Index - 1) + (Lstr.Length - Index); -- See if more than 2 non-digits in a row Index := 0; for I in 1 .. Lstr.Length loop Code := Str_At (I); -- Skip the dot if Code /= 46 then Index := Index + 1; if Decode_A_Char (Code) <= 9 then -- A digit Index := 0; elsif Index > 2 then exit; end if; end if; end loop; -- No need to convert if Index < 3 and then (Form = 22 or else Form = 32 or else Form = 33 or else Form = 42 or else Form = 43 or else Form = 44 or else Form = 54) then return; end if; Code := Decode_A_Char (Str_At (3)); if Code < 0 then Code := Decode_A_Char (Str_At (4)); if Code < 0 then return; end if; end if; -- Convert if Form >= 44 then Code := Code * 31 + Decode_A_Char (Str_At (Lstr.Length)) + 39; if Code < 39 or else Code > 999 then return; end if; C1 := Code / 100; C2 := (Code rem 100) / 10; C3 := Code rem 10; elsif Lstr.Length = 7 then if Form = 24 then Code := Code + 7; elsif Form = 33 then Code := Code + 38; elsif Form = 42 then Code := Code + 69; end if; C1 := Code / 10; C2 := Code rem 10; else C1 := 2 + Code / 8; C2 := 2 + Code rem 8; end if; if Form = 22 then Lstr := Lstr.Uslice (1, 2) & '.' & Char_Of (C1) & Char_Of (C2) & Lstr.Element (5); elsif Form = 23 then Lstr := Lstr.Uslice (1, 2) & '.' & Char_Of (C1) & Char_Of (C2) & Lstr.Element (5) & Lstr.Element (6); elsif Form = 32 then Lstr := Lstr.Uslice (1, 2) & '.' & Char_Of (C1 + 4) & Char_Of (C2) & Lstr.Element (5) & Lstr.Element (6); elsif Form = 24 or else Form = 33 then Lstr := Lstr.Uslice (1, 2) & Char_Of (C1) & '.' & Lstr.Element (5) & Char_Of (C2) & Lstr.Element (6) & Lstr.Element (7); elsif Form = 42 then Lstr := Lstr.Uslice (1, 2) & Char_Of (C1) & '.' & Lstr.Element (4) & Char_Of (C2) & Lstr.Element (6) & Lstr.Element (7); elsif Form = 43 then Lstr := Lstr.Uslice (1, 2) & Char_Of (C1 + 4) & '.' & Lstr.Element (4) & Lstr.Element (6) & Char_Of (C2) & Lstr.Element (7) & Lstr.Element (8); elsif Form = 34 then Lstr := Lstr.Uslice (1, 2) & Char_Of (C1) & '.' & Lstr.Element (5) & Lstr.Element (6) & Char_Of (C2) & Lstr.Element (7) & Lstr.Element (8); elsif Form = 44 then Lstr := Lstr.Uslice (1, 2) & Char_Of (C1) & Lstr.Element (4) & '.' & Char_Of (C2) & Lstr.Element (6) & Lstr.Element (7) & Char_Of (C3) & Lstr.Element (8); elsif Form = 54 then Lstr := Lstr.Uslice (1, 2) & Char_Of (C1) & Lstr.Element (4) & Lstr.Element (5) & '.' & Char_Of (C2) & Lstr.Element (7) & Lstr.Element (8) & Char_Of (C3) & Lstr.Element (9); else return; end if; Str := As_U.Tus (Aeu_Pack (Lstr, False)) & Tail; end Convert_Into_Abjad; --Conversion of a text (territory name or mapcode) into a given language -- The language of the input is detected automatically -- Raises Invalid_Text if the input is not valid function Convert (Input : Wide_String; Output_Language : Language_List := Default_Language) return Wide_String is Input_Language : constant Language_List := Get_Language (Input); Def_Input : constant Language_Defs.Language_List := Language_Defs.Language_List (Input_Language); Def_Output : constant Language_Defs.Language_List := Language_Defs.Language_List (Output_Language); Tmp_Wide : Wide_String (1 .. Input'Length); Found : Boolean; Tmp_Str, Tail : As_U.Asu_Us; Index : Natural; Code : Positive; use type As_U.Asu_Us; begin -- Optim: nothing to do if Output_Language = Input_Language then return Input; end if; -- Convert Input into Roman --------------------------- if Input_Language = Roman then Tmp_Str := As_U.Tus (Ada.Characters.Handling.To_String (Input)); else Index := 0; -- Replace each wide char for W of Input loop Index := Index + 1; if W = '-' or else W = '.' then Tmp_Wide(Index) := W; else Found := False; for J in Language_Defs.Langs(Def_Input).Set'Range loop if W = Language_Defs.Langs(Def_Input).Set(J) then -- Found W in Set of Input_Language -- => Replace by corresponding Romain Found := True; Tmp_Wide(Index) := Language_Defs.Langs(Language_Defs.Roman).Set(J); exit; end if; end loop; if not Found then raise Invalid_Text; end if; end if; end loop; -- Roman string Tmp_Str := As_U.Tus (Ada.Characters.Handling.To_String (Tmp_Wide)); -- Repack if Tmp_Str.Element (1) = 'A' then Index := Tmp_Str.Locate ("-"); if Index /= 0 then -- Save precision tail, including '-' Tail := Tmp_Str.Uslice (Index, Tmp_Str.Length); Tmp_Str.Delete (Index, Tmp_Str.Length); end if; Tmp_Str := Mapcodes.Aeu_Pack ( As_U.Tus (Aeu_Unpack (Tmp_Str.Image)), False) & Tail; end if; -- Abjad conversion if Is_Abjad (Input_Language) then Convert_From_Abjad (Tmp_Str); end if; end if; if Output_Language = Roman then return Ada.Characters.Handling.To_Wide_String (Tmp_Str.Image); end if; -- Convert Roman into output language ------------------------------------- if Is_Abjad (Output_Language) then -- Abjad conversion Convert_Into_Abjad (Tmp_Str); end if; -- Unpack for languages that do not support E and U if Output_Language = Greek then Index := Tmp_Str.Locate ("-"); Tail.Set_Null; if Index /= 0 then -- Save precision tail, including '-' Tail := Tmp_Str.Uslice (Index, Tmp_Str.Length); Tmp_Str.Delete (Index, Tmp_Str.Length); end if; if Tmp_Str.Locate ("E") /= 0 or else Tmp_Str.Locate ("U") /= 0 then Tmp_Str := As_U.Tus (Aeu_Pack (As_U.Tus (Aeu_Unpack (Tmp_Str.Image)), True)); end if; Tmp_Str := Tmp_Str & Tail; end if; -- Substitute declare Result : Wide_String (1 .. Tmp_Str.Length); begin for I in 1 .. Tmp_Str.Length loop Code := Character'Pos (Tmp_Str.Element (I)); if Code >= 65 and then Code <= 90 then Result(I) := Language_Defs.Langs(Def_Output).Set(Code - 64); elsif Code >= 48 and then Code <= 57 then Result(I) := Language_Defs.Langs(Def_Output).Set(Code + 26 - 47); else Result(I) := Wide_Character'Val (Code); end if; end loop; return Result; end; end Convert; end Mapcodes.Languages;
----------------------------------------------------------------------- -- awa-events-queues-persistents -- Persistent event queues -- Copyright (C) 2012, 2020 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with EL.Beans; with EL.Contexts; with AWA.Events.Models; private package AWA.Events.Queues.Persistents is type Persistent_Queue (Name_Length : Natural) is limited new Queue with private; type Persistent_Queue_Access is access all Persistent_Queue'Class; -- Get the queue name. overriding function Get_Name (From : in Persistent_Queue) return String; -- Get the model queue reference object. -- Returns a null object if the queue is not persistent. overriding function Get_Queue (From : in Persistent_Queue) return Events.Models.Queue_Ref; -- Queue the event. The event is saved in the database with a relation to -- the user, the user session, the event queue and the event type. overriding procedure Enqueue (Into : in out Persistent_Queue; Event : in AWA.Events.Module_Event'Class); overriding procedure Dequeue (From : in out Persistent_Queue; Process : access procedure (Event : in Module_Event'Class)); -- Create the queue associated with the given name and configure it by using -- the configuration properties. function Create_Queue (Name : in String; Props : in EL.Beans.Param_Vectors.Vector; Context : in EL.Contexts.ELContext'Class) return Queue_Access; private type Persistent_Queue (Name_Length : Natural) is limited new Queue with record Queue : AWA.Events.Models.Queue_Ref; Server_Id : Natural := 0; Max_Batch : Positive := 1; Name : String (1 .. Name_Length); end record; end AWA.Events.Queues.Persistents;
------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- ADA.CONTAINERS.HASH_TABLES.GENERIC_BOUNDED_KEYS -- -- -- -- S p e c -- -- -- -- Copyright (C) 2004-2015, 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. -- ------------------------------------------------------------------------------ -- Hash_Table_Type is used to implement hashed containers. This package -- declares hash-table operations that depend on keys. generic with package HT_Types is new Generic_Bounded_Hash_Table_Types (<>); use HT_Types, HT_Types.Implementation; with function Next (Node : Node_Type) return Count_Type; with procedure Set_Next (Node : in out Node_Type; Next : Count_Type); type Key_Type (<>) is limited private; with function Hash (Key : Key_Type) return Hash_Type; with function Equivalent_Keys (Key : Key_Type; Node : Node_Type) return Boolean; package Ada.Containers.Hash_Tables.Generic_Bounded_Keys is pragma Pure; function Index (HT : Hash_Table_Type'Class; Key : Key_Type) return Hash_Type; pragma Inline (Index); -- Returns the bucket number (array index value) for the given key function Checked_Index (HT : aliased in out Hash_Table_Type'Class; Key : Key_Type) return Hash_Type; pragma Inline (Checked_Index); -- Calls Index, but also locks and unlocks the container, per AI05-0022, in -- order to detect element tampering by the generic actual Hash function. function Checked_Equivalent_Keys (HT : aliased in out Hash_Table_Type'Class; Key : Key_Type; Node : Count_Type) return Boolean; -- Calls Equivalent_Keys, but locks and unlocks the container, per -- AI05-0022, in order to detect element tampering by that generic actual. procedure Delete_Key_Sans_Free (HT : in out Hash_Table_Type'Class; Key : Key_Type; X : out Count_Type); -- Removes the node (if any) with the given key from the hash table, -- without deallocating it. Program_Error is raised if the hash -- table is busy. function Find (HT : Hash_Table_Type'Class; Key : Key_Type) return Count_Type; -- Returns the node (if any) corresponding to the given key generic with function New_Node return Count_Type; procedure Generic_Conditional_Insert (HT : in out Hash_Table_Type'Class; Key : Key_Type; Node : out Count_Type; Inserted : out Boolean); -- Attempts to insert a new node with the given key into the hash table. -- If a node with that key already exists in the table, then that node -- is returned and Inserted returns False. Otherwise New_Node is called -- to allocate a new node, and Inserted returns True. Program_Error is -- raised if the hash table is busy. generic with function Hash (Node : Node_Type) return Hash_Type; with procedure Assign (Node : in out Node_Type; Key : Key_Type); procedure Generic_Replace_Element (HT : in out Hash_Table_Type'Class; Node : Count_Type; Key : Key_Type); -- Assigns Key to Node, possibly changing its equivalence class. If Node -- is in the same equivalence class as Key (that is, it's already in the -- bucket implied by Key), then if the hash table is locked then -- Program_Error is raised; otherwise Assign is called to assign Key to -- Node. If Node is in a different bucket from Key, then Program_Error is -- raised if the hash table is busy. Otherwise it Assigns Key to Node and -- moves the Node from its current bucket to the bucket implied by Key. -- Note that it is never proper to assign to Node a key value already -- in the map, and so if Key is equivalent to some other node then -- Program_Error is raised. end Ada.Containers.Hash_Tables.Generic_Bounded_Keys;
package enum_colors is type Traffic_Light is (Red, Yellow, Green); end enum_colors;
generic type Element is private; type Index is (<>); type Seq is array (Index range <>) of Element; function Is_Palindrome(S: Seq) return Boolean;
------------------------------------------------------------------------------ -- Copyright (c) 2017-2019, 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. -- ------------------------------------------------------------------------------ with Natools.S_Expressions.Atom_Ref_Constructors; with Natools.S_Expressions.File_Readers; with Natools.S_Expressions.Interpreter_Loop; package body Natools.Web.ACL.Sx_Backends is type Hashed_Token_List_Array is array (Hash_Id range <>) of Containers.Unsafe_Atom_Lists.List; type Hashed_Token_Map_Array is array (Hash_Id range <>) of Token_Maps.Unsafe_Maps.Map; type User_Builder (Hash_Id_First, Hash_Id_Last : Hash_Id) is record Tokens, Groups : Containers.Unsafe_Atom_Lists.List; Hashed : Hashed_Token_List_Array (Hash_Id_First .. Hash_Id_Last); end record; type Backend_Builder (Hash_Id_First, Hash_Id_Last : Hash_Id) is record Map : Token_Maps.Unsafe_Maps.Map; Hashed : Hashed_Token_Map_Array (Hash_Id_First .. Hash_Id_Last); end record; Cookie_Name : constant String := "User-Token"; Hash_Mark : constant Character := '$'; procedure Process_User (Builder : in out Backend_Builder; Context : in Meaningless_Type; Name : in S_Expressions.Atom; Arguments : in out Natools.S_Expressions.Lockable.Descriptor'Class); procedure Process_User_Element (Builder : in out User_Builder; Context : in Meaningless_Type; Name : in S_Expressions.Atom; Arguments : in out Natools.S_Expressions.Lockable.Descriptor'Class); procedure Read_DB is new S_Expressions.Interpreter_Loop (Backend_Builder, Meaningless_Type, Process_User); procedure Read_User is new S_Expressions.Interpreter_Loop (User_Builder, Meaningless_Type, Process_User_Element); -------------------------- -- Constructor Elements -- -------------------------- procedure Process_User (Builder : in out Backend_Builder; Context : in Meaningless_Type; Name : in S_Expressions.Atom; Arguments : in out Natools.S_Expressions.Lockable.Descriptor'Class) is pragma Unreferenced (Context); User : User_Builder (Builder.Hash_Id_First, Builder.Hash_Id_Last); Identity : Containers.Identity; begin Read_User (Arguments, User, Meaningless_Value); Identity := (User => S_Expressions.Atom_Ref_Constructors.Create (Name), Groups => Containers.Create (User.Groups)); for Token of User.Tokens loop Builder.Map.Include (Token, Identity); end loop; for Id in User.Hashed'Range loop for Hashed_Token of User.Hashed (Id) loop Builder.Hashed (Id).Include (Hashed_Token, Identity); end loop; end loop; end Process_User; procedure Process_User_Element (Builder : in out User_Builder; Context : in Meaningless_Type; Name : in S_Expressions.Atom; Arguments : in out Natools.S_Expressions.Lockable.Descriptor'Class) is pragma Unreferenced (Context); S_Name : constant String := S_Expressions.To_String (Name); begin if S_Name = "tokens" or else S_Name = "token" then Containers.Append_Atoms (Builder.Tokens, Arguments); elsif S_Name = "groups" or else S_Name = "group" then Containers.Append_Atoms (Builder.Groups, Arguments); elsif (S_Name'Length = 8 or else (S_Name'Length = 9 and then S_Name (S_Name'Last) = 's')) and then S_Name (S_Name'First) = Hash_Mark and then S_Name (S_Name'First + 2 .. S_Name'First + 7) = Hash_Mark & "token" and then not Hash_Function_DB.Is_Empty then declare Id : constant Character := S_Name (S_Name'First + 1); Acc : constant Hash_Function_Array_Refs.Accessor := Hash_Function_DB.Query; begin if Id in Acc.Data.all'Range and then Acc.Data (Id) /= null then Containers.Append_Atoms (Builder.Hashed (Id), Arguments); else Log (Severities.Error, "Unknown hash function id" & Character'Image (Id)); end if; end; else Log (Severities.Error, "Unknown user element """ & S_Name & '"'); end if; end Process_User_Element; ---------------------- -- Public Interface -- ---------------------- overriding procedure Authenticate (Self : in Backend; Exchange : in out Exchanges.Exchange) is Cookie : constant String := Exchange.Cookie (Cookie_Name); Identity : Containers.Identity; begin if Cookie'Length > 3 and then Cookie (Cookie'First) = Hash_Mark and then Cookie (Cookie'First + 2) = Hash_Mark and then not Self.Hashed.Is_Empty and then Cookie (Cookie'First + 1) in Self.Hashed.Query.Data.all'Range then declare Token : constant S_Expressions.Atom := S_Expressions.To_Atom (Cookie (Cookie'First + 3 .. Cookie'Last)); Hash : constant S_Expressions.Atom := Hash_Function_DB.Query.Data (Cookie (Cookie'First + 1)).all (Token); Cursor : constant Token_Maps.Cursor := Self.Hashed.Query.Data (Cookie (Cookie'First + 1)).Find (Hash); begin if Token_Maps.Has_Element (Cursor) then Identity := Token_Maps.Element (Cursor); end if; end; else declare Cursor : constant Token_Maps.Cursor := Self.Map.Find (S_Expressions.To_Atom (Cookie)); begin if Token_Maps.Has_Element (Cursor) then Identity := Token_Maps.Element (Cursor); end if; end; end if; Exchange.Set_Identity (Identity); end Authenticate; function Create (Arguments : in out S_Expressions.Lockable.Descriptor'Class) return ACL.Backend'Class is Hash_Id_First : constant Hash_Id := (if Hash_Function_DB.Is_Empty then Hash_Id'Last else Hash_Function_DB.Query.Data.all'First); Hash_Id_Last : constant Hash_Id := (if Hash_Function_DB.Is_Empty then Hash_Id'First else Hash_Function_DB.Query.Data.all'Last); Builder : Backend_Builder (Hash_Id_First, Hash_Id_Last); begin case Arguments.Current_Event is when S_Expressions.Events.Open_List => Read_DB (Arguments, Builder, Meaningless_Value); when S_Expressions.Events.Add_Atom => declare Reader : S_Expressions.File_Readers.S_Reader := S_Expressions.File_Readers.Reader (S_Expressions.To_String (Arguments.Current_Atom)); begin Read_DB (Reader, Builder, Meaningless_Value); end; when others => Log (Severities.Error, "Unable to create ACL from S-expression" & " starting with " & Arguments.Current_Event'Img); end case; return Result : Backend := (Map => Token_Maps.Create (Builder.Map), Hashed => <>) do declare Min : Hash_Id := Hash_Id'Last; Max : Hash_Id := Hash_Id'First; begin for Id in Builder.Hashed'Range loop if not Builder.Hashed (Id).Is_Empty then -- Hash_Id'Min seems broken, using a basic `if` instead if Id < Min then Min := Id; end if; if Id > Max then Max := Id; end if; end if; end loop; if Min <= Max then declare Data : constant Hashed_Token_Array_Refs.Data_Access := new Hashed_Token_Array (Min .. Max); begin Result.Hashed := Hashed_Token_Array_Refs.Create (Data); for Id in Min .. Max loop if not Builder.Hashed (Id).Is_Empty then Data (Id) := Token_Maps.Create (Builder.Hashed (Id)); end if; end loop; end; end if; end; end return; end Create; procedure Register (Id : in Character; Fn : in Hash_Function) is begin if Fn = null then null; elsif Hash_Function_DB.Is_Empty then Hash_Function_DB.Replace (new Hash_Function_Array'(Id => Fn)); elsif Id in Hash_Function_DB.Query.Data.all'Range then Hash_Function_DB.Update.Data.all (Id) := Fn; else declare New_First : constant Hash_Id := Hash_Id'Min (Id, Hash_Function_DB.Query.Data.all'First); New_Last : constant Hash_Id := Hash_Id'Max (Id, Hash_Function_DB.Query.Data.all'Last); New_Data : constant Hash_Function_Array_Refs.Data_Access := new Hash_Function_Array'(New_First .. New_Last => null); begin New_Data (Hash_Function_DB.Query.Data.all'First .. Hash_Function_DB.Query.Data.all'Last) := Hash_Function_DB.Query.Data.all; New_Data (Id) := Fn; Hash_Function_DB.Replace (New_Data); end; end if; end Register; end Natools.Web.ACL.Sx_Backends;
package Asis.Gela.Parser.Tokens is subtype YYSTYPE is Asis.Element; subtype T is YYSTYPE; YYLVal, YYVal : YYSType; type Token is (End_Of_Input, Error, New_Line_Token, Separator_Token, Comment_Token, Identifier_Token, Integer_Literal_Token, Real_Literal_Token, Character_Literal_Token, String_Literal_Token, Double_Star_Token, Right_Label_Token, Greater_Or_Equal_Token, Box_Token, Left_Label_Token, Less_Or_Equal_Token, Inequality_Token, Assignment_Token, Arrow_Token, Double_Dot_Token, Ampersand_Token, Greater_Token, Less_Token, Apostrophe_Token, Left_Parenthesis_Token, Right_Parenthesis_Token, Star_Token, Plus_Token, Comma_Token, Hyphen_Token, Dot_Token, Slash_Token, Colon_Token, Semicolon_Token, Equal_Token, Vertical_Line_Token, Abort_Token, Abs_Token, Abstract_Token, Accept_Token, Access_Token, Aliased_Token, All_Token, And_Token, Array_Token, At_Token, Begin_Token, Body_Token, Case_Token, Constant_Token, Declare_Token, Delay_Token, Delta_Token, Digits_Token, Do_Token, Else_Token, Elsif_Token, End_Token, Entry_Token, Exception_Token, Exit_Token, For_Token, Function_Token, Generic_Token, Goto_Token, If_Token, In_Token, Interface_Token, Is_Token, Limited_Token, Loop_Token, Mod_Token, New_Token, Not_Token, Null_Token, Of_Token, Or_Token, Others_Token, Out_Token, Overriding_Token, Package_Token, Pragma_Token, Private_Token, Procedure_Token, Protected_Token, Raise_Token, Range_Token, Record_Token, Rem_Token, Renames_Token, Requeue_Token, Return_Token, Reverse_Token, Select_Token, Separate_Token, Subtype_Token, Synchronized_Token, Tagged_Token, Task_Token, Terminate_Token, Then_Token, Type_Token, Until_Token, Use_Token, When_Token, While_Token, With_Token, Xor_Token ); Syntax_Error : exception; end Asis.Gela.Parser.Tokens;
--------------------------------------------------------------------------------- -- Copyright 2004-2005 © Luke A. Guest -- -- This code is to be used for tutorial purposes only. -- You may not redistribute this code in any form without my express permission. --------------------------------------------------------------------------------- with Interfaces.C; with Interfaces.C.Strings; with Unchecked_Conversion; with Ada.Strings.Fixed; with GL; with GLU; with SDL.Video; with System; package body GLUtils is package C renames Interfaces.C; function To_chars_ptr is new Unchecked_Conversion(Source => GL.GLubytePtr, Target => C.Strings.chars_ptr); function GL_Vendor return String is begin return C.Strings.Value(To_chars_ptr(GL.glGetString(GL.GL_VENDOR))); end GL_Vendor; function GL_Version return String is begin return C.Strings.Value(To_chars_ptr(GL.glGetString(GL.GL_VERSION))); end GL_Version; function GL_Renderer return String is begin return C.Strings.Value(To_chars_ptr(GL.glGetString(GL.GL_RENDERER))); end GL_Renderer; function GL_Extensions return String is begin return C.Strings.Value(To_chars_ptr(GL.glGetString(GL.GL_EXTENSIONS))); end GL_Extensions; function GLU_Version return String is begin return C.Strings.Value(To_chars_ptr(GLU.gluGetString(GLU.GLU_VERSION))); end GLU_Version; function GLU_Extensions return String is begin return C.Strings.Value(To_chars_ptr(GLU.gluGetString(GLU.GLU_EXTENSIONS))); end GLU_Extensions; function IsExtensionAvailable(ExtensionToFind : in String) return Boolean is Extensions : String := GL_Extensions; Start : Integer := Ada.Strings.Fixed.Index(Extensions, ExtensionToFind); Finish : Integer := Start + ExtensionToFind'Length - 1; begin if ExtensionToFind = Extensions(Start .. Finish) then return True; end if; return False; end IsExtensionAvailable; function GetProc(Name : in String) return ELEMENT is function To_EXT is new Unchecked_Conversion(Source => System.Address, Target => ELEMENT); begin return To_EXT(SDL.Video.GL_GetProcAddress(Interfaces.C.Strings.New_String(Name))); end GetProc; end GLUtils;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO; use Ada.Text_IO; procedure Test_Amb is type Alternatives is array (Positive range <>) of Unbounded_String; type Amb (Count : Positive) is record This : Positive := 1; Left : access Amb; List : Alternatives (1..Count); end record; function Image (L : Amb) return String is begin return To_String (L.List (L.This)); end Image; function "/" (L, R : String) return Amb is Result : Amb (2); begin Append (Result.List (1), L); Append (Result.List (2), R); return Result; end "/"; function "/" (L : Amb; R : String) return Amb is Result : Amb (L.Count + 1); begin Result.List (1..L.Count) := L.List ; Append (Result.List (Result.Count), R); return Result; end "/"; function "=" (L, R : Amb) return Boolean is Left : Unbounded_String renames L.List (L.This); begin return Element (Left, Length (Left)) = Element (R.List (R.This), 1); end "="; procedure Failure (L : in out Amb) is begin loop if L.This < L.Count then L.This := L.This + 1; else L.This := 1; Failure (L.Left.all); end if; exit when L.Left = null or else L.Left.all = L; end loop; end Failure; procedure Join (L : access Amb; R : in out Amb) is begin R.Left := L; while L.all /= R loop Failure (R); end loop; end Join; W_1 : aliased Amb := "the" / "that" / "a"; W_2 : aliased Amb := "frog" / "elephant" / "thing"; W_3 : aliased Amb := "walked" / "treaded" / "grows"; W_4 : aliased Amb := "slowly" / "quickly"; begin Join (W_1'Access, W_2); Join (W_2'Access, W_3); Join (W_3'Access, W_4); Put_Line (Image (W_1) & ' ' & Image (W_2) & ' ' & Image (W_3) & ' ' & Image (W_4)); end Test_Amb;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S Y S T E M . A D D R E S S _ O P E R A T I O N S -- -- -- -- S p e c -- -- -- -- Copyright (C) 2004-2005 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 implementation dependent sections of this file. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- -- Boston, MA 02110-1301, USA. -- -- -- -- -- -- -- -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package provides arithmetic and logical operations on type Address. -- It is intended for use by other packages in the System hierarchy. For -- applications requiring this capability, see System.Storage_Elements or -- the operations introduced in System.Aux_DEC; -- The reason we need this package is that arithmetic operations may not -- be available in the case where type Address is non-private and the -- operations have been made abstract in the spec of System (to avoid -- inappropriate use by applications programs). In addition, the logical -- operations may not be available if type Address is a signed integer. package System.Address_Operations is pragma Pure; -- The semantics of the arithmetic operations are those that apply to -- a modular type with the same length as Address, i.e. they provide -- twos complement wrap around arithmetic treating the address value -- as an unsigned value, with no overflow checking. -- Note that we do not use the infix names for these operations to -- avoid problems with ambiguities coming from declarations in package -- Standard (which may or may not be visible depending on the exact -- form of the declaration of type System.Address). function AddA (Left, Right : Address) return Address; function SubA (Left, Right : Address) return Address; function MulA (Left, Right : Address) return Address; function DivA (Left, Right : Address) return Address; function ModA (Left, Right : Address) return Address; -- The semantics of the logical operations are those that apply to -- a modular type with the same length as Address, i.e. they provide -- bit-wise operations on all bits of the value (including the sign -- bit if Address is a signed integer type). function AndA (Left, Right : Address) return Address; function OrA (Left, Right : Address) return Address; pragma Inline_Always (AddA); pragma Inline_Always (SubA); pragma Inline_Always (MulA); pragma Inline_Always (DivA); pragma Inline_Always (ModA); pragma Inline_Always (AndA); pragma Inline_Always (OrA); end System.Address_Operations;
-- This file is covered by the Internet Software Consortium (ISC) License -- Reference: ../License.txt with Definitions; use Definitions; private with HelperText; private with PortScan; private with Ada.Containers.Vectors; package Pilot is procedure display_usage; procedure react_to_unknown_first_level_command (argument : String); procedure react_to_unknown_second_level_command (level1, level2 : String); procedure dump_ravensource (optional_directory : String); procedure show_short_help; procedure launch_man_page (level2 : String); procedure generate_makefile (optional_directory : String; optional_variant : String); procedure generate_webpage (required_namebase : String; optional_variant : String); procedure generate_buildsheet (sourcedir : String; save_command : String); procedure regenerate_patches (optional_directory : String; optional_variant : String); procedure resort_manifests (sourcedir : String); procedure show_config_value (AQvalue : String); procedure generate_website; -- Return True when TERM is defined in environment (required) function TERM_defined_in_environment return Boolean; -- The current working directory will cause ravenadm to fail -- Known issue for when cwd is within <system root>/usr/local function launch_clash_detected return Boolean; -- Returns True if the root user didn't execute ravenadm. function insufficient_privileges return Boolean; -- Returns True if a pidfile is found and it's a valid ravenadm process function already_running return Boolean; -- Create a pidfile on major actions and remove it when complete. procedure create_pidfile; procedure destroy_pidfile; -- Checks if things are mounted from aborted previous run. -- The action upon "True" would be to try to clean them up (else abort) function previous_run_mounts_detected return Boolean; -- Checks if work directories are left over from aborted previous run -- The action upon "True" would be to remove them completely function previous_realfs_work_detected return Boolean; -- Returns True if all the old mounts were unmounted without issue. -- If not, it will emit messages so ravenadm can just eject directly. function old_mounts_successfully_removed return Boolean; -- Returns True if all the old SL*_(work|localbase) directories -- were removed without any problems function old_realfs_work_successfully_removed return Boolean; -- libexec/ravenexec is required, make sure it's installed! function ravenexec_missing return Boolean; -- pass-through for configure package procedure launch_configure_menu; -- Returns the conspiracy location for candidate. The wording changes bases on if the -- buildsheet exists or not. procedure locate (candidate : String); -- Searches the customsource first (if active) then ravensource for a match of candidate -- to a ravenport's namebase. If found, returns "cd full-path-to-ravensource-port otherwise -- returns "echo <candidate> port not found". This is suitable for shell's eval statement -- to allow quick jumping to directory for editing. procedure jump (candidate : String); -- Scan sysroot to get exact OS versions, return False if anything fails function slave_platform_determined return Boolean; -- Iterate through stack of individual build requests and scan each one. -- If any scan fails, return False. function scan_stack_of_single_ports (always_build : Boolean) return Boolean; -- Runs post-scan sanity check -- If successful, then scans for all "ignored" ports, failing them -- For each ignored port, cascade the failures (designated "skipped" ports) -- Starts the build log documenting all this. -- Return True if no problems are encountered. function sanity_check_then_prefail (delete_first : Boolean := False; dry_run : Boolean := False) return Boolean; -- Everything is fine so kick of the parallel builders. They will -- continue until everything is complete. procedure perform_bulk_run (testmode : Boolean); -- Returns "True" when all the port origins -- (command line or inside file) are verified and arguments are correct. function store_origins (start_from : Positive) return Boolean; -- Sends a basic template for writing specifications to standard out. procedure print_spec_template (save_command : String); -- Explodes current directory specfication into scan slave and generates a distinfo -- file which is copied back to current directory. procedure generate_distinfo; -- This procedure removes the single CLI listed port from the queue, -- executes "perform_bulk_run" and then builds the final port, but -- breaks into the jail at the specified (by ENTERAFTER env) point -- The test mode is always "True" so that's not an argument. procedure bulk_run_then_interact_with_final_port; -- If ENTERAFTER is defined to valid phase and there's only one port -- given on the command line, then return True function interact_with_single_builder return Boolean; -- If the toolchain compiler packages are missing from the packages directory, copy -- the missing ones from the system root. Returns True on success. function install_compiler_packages return Boolean; -- Generates the conspiracy_variants file at Mk/Misc of the conspiracy directory procedure generate_ports_index; -- Scans the source directory and regenerates buildsheets for every single port -- Works in parallel (1 per ncpu) procedure generate_conspiracy (sourcedir : String); -- Call portscan procedure of the same name procedure display_results_of_dry_run; -- Determines all possible unique distfiles, then scans the distfiles directory for -- actual downloads and removes any distfiles that don't belong. procedure purge_distfiles; -- Determines all possible log files of the ports tree, then scans the log directory for -- the purpose of removing any logs to ports that no longer exist. procedure purge_logs; -- Launches options dialog to allow user to set them procedure change_options; -- Provides information about currency of installed ravenports procedure check_ravenports_version; -- Executes routine to update to the latest published ravenports procedure update_to_latest_ravenports; -- Scan entire ports tree function fully_scan_ports_tree return Boolean; -- Executes routine to validate and create repository files procedure generate_repository; -- Lists the subpackages of all given ports procedure list_subpackages; -- Print info message if [conspiracy]/Mk/Misc/raverreq contents is <= ravenadm version -- If file does not exist, do nothing procedure check_that_ravenadm_is_modern_enough; private package HT renames HelperText; subtype logname_field is String (1 .. 19); type dim_logname is array (count_type) of logname_field; type verdiff is (newbuild, rebuild, change); specfile : constant String := "specification"; errprefix : constant String := "Error : "; pidfile : constant String := "/var/run/ravenadm.pid"; bailing : constant String := " (ravenadm must exit)"; shutreq : constant String := "Graceful shutdown requested, exiting ..."; brkname : constant String := "ENTERAFTER"; badformat : constant String := "Invalid format: "; badname : constant String := "Invalid port namebase: "; badvariant : constant String := "Invalid port variant: "; scan_slave : constant builders := 9; ss_base : constant String := "/SL09"; sysrootver : PortScan.sysroot_characteristics; all_stdvar : Boolean := False; logname : constant dim_logname := ("00_last_results.log", "01_success_list.log", "02_failure_list.log", "03_ignored_list.log", "04_skipped_list.log"); procedure DNE (filename : String); -- Returns True if given port-variant name is valid (existing buildsheet and variant -- exists on that buildsheet. Unkindness directory takes precedence over conspiracy. function valid_origin (port_variant : String; bad_namebase : out Boolean; bad_format : out Boolean; assume_std : out Boolean; known_std : out Boolean) return Boolean; -- scan given file. Everything line must be either blank (whitespace -- ignored) or a valid port origin, and returns true if it is. -- Internally, the ports are stacked. function valid_origin_file (regular_file : String) return Boolean; -- Generates unkindness buildsheets and index if obsolete or missing -- Returns true on success function unkindness_index_current return Boolean; end Pilot;
-- ----------------------------------------------------- -- Copyright (C) by: -- Antonio F. Vargas - Ponta Delgada - Azores - Portugal -- avargas@adapower.net -- www.adapower.net/~avargas -- ----------------------------------------------------- -- This program is in the public domain -- ----------------------------------------------------- -- Command line options: -- -info Print GL implementation information -- (this is the original option). -- -slow To slow down velocity under acelerated -- hardware. -- -window GUI window. Fullscreen is the default. -- -nosound To play without sound. -- -800x600 To create a video display of 800 by 600 -- the default mode is 640x480 -- -1024x768 To create a video display of 1024 by 768 -- ----------------------------------------------------- with Interfaces.C; with Ada.Numerics.Generic_Elementary_Functions; with Ada.Command_Line; with Ada.Text_IO; use Ada.Text_IO; with GNAT.OS_Lib; with SDL.Video; with SDL.Error; with SDL.Events; with SDL.Keyboard; with SDL.Keysym; with SDL.Types; use SDL.Types; with gl_h; use gl_h; with AdaGL; use AdaGL; procedure GenericGL is package CL renames Ada.Command_Line; package C renames Interfaces.C; use type C.unsigned; use type C.int; use type SDL.Init_Flags; package Vd renames SDL.Video; use type Vd.Surface_ptr; use type Vd.Surface_Flags; package Er renames SDL.Error; package Ev renames SDL.Events; package Kb renames SDL.Keyboard; package Ks renames SDL.Keysym; use type Ks.SDLMod; -- =================================================================== procedure init (info : Boolean) is begin null; end init; -- =================================================================== procedure draw is begin glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); glPushMatrix; -- ... glPopMatrix; Vd.GL_SwapBuffers; end draw; -- =================================================================== procedure idle is begin null; end idle; -- =================================================================== -- New window size of exposure procedure reshape (width : C.int; height : C.int) is h : GLdouble := GLdouble (height) / GLdouble (width); begin glViewport (0, 0, GLint (width), GLint (height)); glMatrixMode (GL_PROJECTION); glLoadIdentity; glFrustum (-1.0, 1.0, -h, h, 5.0, 60.0); glMatrixMode (GL_MODELVIEW); glLoadIdentity; glTranslatef (0.0, 0.0, -40.0); end reshape; -- =================================================================== screen : Vd.Surface_ptr; done : Boolean; keys : Uint8_ptr; Screen_Width : C.int := 640; Screen_Hight : C.int := 480; Slowly : Boolean := False; Info : Boolean := False; Full_Screen : Boolean := True; argc : Integer := CL.Argument_Count; Video_Flags : Vd.Surface_Flags := 0; Initialization_Flags : SDL.Init_Flags := 0; -- =================================================================== procedure Manage_Command_Line is begin while argc > 0 loop if (argc >= 1) and then CL.Argument (argc) = "-slow" then Slowly := True; argc := argc - 1; elsif CL.Argument (argc) = "-window" then Full_Screen := False; argc := argc - 1; elsif CL.Argument (argc) = "-1024x768" then Screen_Width := 1024; Screen_Hight := 768; argc := argc - 1; elsif CL.Argument (argc) = "-800x600" then Screen_Width := 800; Screen_Hight := 600; argc := argc - 1; elsif CL.Argument (argc) = "-info" then Info := True; argc := argc - 1; else Put_Line ("Usage: " & CL.Command_Name & " " & "[-slow] [-window] [-h] [[-800x600] | [-1024x768]]"); argc := argc - 1; GNAT.OS_Lib.OS_Exit (0); end if; end loop; end Manage_Command_Line; -- =================================================================== procedure Main_System_Loop is begin while not done loop declare event : Ev.Event; PollEvent_Result : C.int; begin idle; loop Ev.PollEventVP (PollEvent_Result, event); exit when PollEvent_Result = 0; case event.the_type is when Ev.VIDEORESIZE => screen := Vd.SetVideoMode ( event.resize.w, event.resize.h, 16, Vd.OPENGL or Vd.RESIZABLE); if screen /= null then reshape (screen.w, screen.h); else -- Couldn't set the new video mode null; end if; when Ev.QUIT => done := True; when others => null; end case; end loop; keys := Kb.GetKeyState (null); if Kb.Is_Key_Pressed (keys, Ks.K_ESCAPE) then done := True; end if; draw; end; -- declare end loop; end Main_System_Loop; -- =================================================================== -- Gears Procedure body -- =================================================================== begin Manage_Command_Line; Initialization_Flags := SDL.INIT_VIDEO; if SDL.Init (Initialization_Flags) < 0 then Put_Line ("Couldn't load SDL: " & Er.Get_Error); GNAT.OS_Lib.OS_Exit (1); end if; Video_Flags := Vd.OPENGL or Vd.RESIZABLE; if Full_Screen then Video_Flags := Video_Flags or Vd.FULLSCREEN; end if; screen := Vd.SetVideoMode (Screen_Width, Screen_Hight, 16, Video_Flags); if screen = null then Put_Line ("Couldn't set " & C.int'Image (Screen_Width) & "x" & C.int'Image (Screen_Hight) & " GL video mode: " & Er.Get_Error); SDL.SDL_Quit; GNAT.OS_Lib.OS_Exit (2); end if; Vd.WM_Set_Caption ("Generic GL", "Generic"); init (Info); reshape (screen.w, screen.h); done := False; Main_System_Loop; SDL.SDL_Quit; end GenericGL;
-- { dg-do compile } -- { dg-options "-cargs --param max-completely-peeled-insns=200 -margs -O3" } package body Opt42 is function "*" (Left, Right : in Array_Type) return Array_Type is Temp : Float; Result : Array_Type; begin for I in Index_Type loop for J in Index_Type loop Temp := 0.0; for K in Index_Type loop Temp := Temp + Left (I) (K) * Right (K) (J); end loop; Result (I) (J) := Temp; end loop; end loop; return Result; end "*"; end Opt42;
with Ada.Text_IO; use Ada.Text_IO; package body base_iface is procedure class_wide(Self : The_Interface'Class) is begin Put_Line(" iface'Class:class-wide, calling Self.simple"); Self.simple; end; end base_iface;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ P R A G -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2006, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- -- Boston, MA 02110-1301, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This unit contains the semantic processing for all pragmas, both language -- and implementation defined. For most pragmas, the parser only does the -- most basic job of checking the syntax, so Sem_Prag also contains the code -- to complete the syntax checks. Certain pragmas are handled partially or -- completely by the parser (see Par.Prag for further details). with Atree; use Atree; with Casing; use Casing; with Csets; use Csets; with Debug; use Debug; with Einfo; use Einfo; with Elists; use Elists; with Errout; use Errout; with Exp_Dist; use Exp_Dist; with Hostparm; use Hostparm; with Lib; use Lib; with Lib.Writ; use Lib.Writ; with Lib.Xref; use Lib.Xref; with Namet; use Namet; 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_Ch3; use Sem_Ch3; with Sem_Ch8; use Sem_Ch8; with Sem_Ch13; use Sem_Ch13; with Sem_Disp; use Sem_Disp; with Sem_Dist; use Sem_Dist; with Sem_Elim; use Sem_Elim; with Sem_Eval; use Sem_Eval; with Sem_Intr; use Sem_Intr; with Sem_Mech; use Sem_Mech; with Sem_Res; use Sem_Res; with Sem_Type; use Sem_Type; with Sem_Util; use Sem_Util; with Sem_VFpt; use Sem_VFpt; with Sem_Warn; use Sem_Warn; with Stand; use Stand; with Sinfo; use Sinfo; with Sinfo.CN; use Sinfo.CN; with Sinput; use Sinput; with Snames; use Snames; with Stringt; use Stringt; with Stylesw; use Stylesw; with Table; with Targparm; use Targparm; with Tbuild; use Tbuild; with Ttypes; with Uintp; use Uintp; with Urealp; use Urealp; with Validsw; use Validsw; with GNAT.Spelling_Checker; use GNAT.Spelling_Checker; package body Sem_Prag is ---------------------------------------------- -- Common Handling of Import-Export Pragmas -- ---------------------------------------------- -- In the following section, a number of Import_xxx and Export_xxx -- pragmas are defined by GNAT. These are compatible with the DEC -- pragmas of the same name, and all have the following common -- form and processing: -- pragma Export_xxx -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL] -- [, other optional parameters ]); -- pragma Import_xxx -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL] -- [, other optional parameters ]); -- EXTERNAL_SYMBOL ::= -- IDENTIFIER -- | static_string_EXPRESSION -- The internal LOCAL_NAME designates the entity that is imported or -- exported, and must refer to an entity in the current declarative -- part (as required by the rules for LOCAL_NAME). -- The external linker name is designated by the External parameter -- if given, or the Internal parameter if not (if there is no External -- parameter, the External parameter is a copy of the Internal name). -- If the External parameter is given as a string, then this string -- is treated as an external name (exactly as though it had been given -- as an External_Name parameter for a normal Import pragma). -- If the External parameter is given as an identifier (or there is no -- External parameter, so that the Internal identifier is used), then -- the external name is the characters of the identifier, translated -- to all upper case letters for OpenVMS versions of GNAT, and to all -- lower case letters for all other versions -- Note: the external name specified or implied by any of these special -- Import_xxx or Export_xxx pragmas override an external or link name -- specified in a previous Import or Export pragma. -- Note: these and all other DEC-compatible GNAT pragmas allow full -- use of named notation, following the standard rules for subprogram -- calls, i.e. parameters can be given in any order if named notation -- is used, and positional and named notation can be mixed, subject to -- the rule that all positional parameters must appear first. -- Note: All these pragmas are implemented exactly following the DEC -- design and implementation and are intended to be fully compatible -- with the use of these pragmas in the DEC Ada compiler. -------------------------------------------- -- Checking for Duplicated External Names -- -------------------------------------------- -- It is suspicious if two separate Export pragmas use the same external -- name. The following table is used to diagnose this situation so that -- an appropriate warning can be issued. -- The Node_Id stored is for the N_String_Literal node created to -- hold the value of the external name. The Sloc of this node is -- used to cross-reference the location of the duplication. package Externals is new Table.Table ( Table_Component_Type => Node_Id, Table_Index_Type => Int, Table_Low_Bound => 0, Table_Initial => 100, Table_Increment => 100, Table_Name => "Name_Externals"); ------------------------------------- -- Local Subprograms and Variables -- ------------------------------------- function Adjust_External_Name_Case (N : Node_Id) return Node_Id; -- This routine is used for possible casing adjustment of an explicit -- external name supplied as a string literal (the node N), according -- to the casing requirement of Opt.External_Name_Casing. If this is -- set to As_Is, then the string literal is returned unchanged, but if -- it is set to Uppercase or Lowercase, then a new string literal with -- appropriate casing is constructed. function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id; -- If Def_Id refers to a renamed subprogram, then the base subprogram -- (the original one, following the renaming chain) is returned. -- Otherwise the entity is returned unchanged. Should be in Einfo??? procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id); -- Place semantic information on the argument of an Elaborate or -- Elaborate_All pragma. Entity name for unit and its parents is -- taken from item in previous with_clause that mentions the unit. ------------------------------- -- Adjust_External_Name_Case -- ------------------------------- function Adjust_External_Name_Case (N : Node_Id) return Node_Id is CC : Char_Code; begin -- Adjust case of literal if required if Opt.External_Name_Exp_Casing = As_Is then return N; else -- Copy existing string Start_String; -- Set proper casing for J in 1 .. String_Length (Strval (N)) loop CC := Get_String_Char (Strval (N), J); if Opt.External_Name_Exp_Casing = Uppercase and then CC >= Get_Char_Code ('a') and then CC <= Get_Char_Code ('z') then Store_String_Char (CC - 32); elsif Opt.External_Name_Exp_Casing = Lowercase and then CC >= Get_Char_Code ('A') and then CC <= Get_Char_Code ('Z') then Store_String_Char (CC + 32); else Store_String_Char (CC); end if; end loop; return Make_String_Literal (Sloc (N), Strval => End_String); end if; end Adjust_External_Name_Case; -------------------- -- Analyze_Pragma -- -------------------- procedure Analyze_Pragma (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Prag_Id : Pragma_Id; Pragma_Exit : exception; -- This exception is used to exit pragma processing completely. It -- is used when an error is detected, and no further processing is -- required. It is also used if an earlier error has left the tree -- in a state where the pragma should not be processed. Arg_Count : Nat; -- Number of pragma argument associations Arg1 : Node_Id; Arg2 : Node_Id; Arg3 : Node_Id; Arg4 : Node_Id; -- First four pragma arguments (pragma argument association nodes, -- or Empty if the corresponding argument does not exist). type Name_List is array (Natural range <>) of Name_Id; type Args_List is array (Natural range <>) of Node_Id; -- Types used for arguments to Check_Arg_Order and Gather_Associations procedure Check_Ada_83_Warning; -- Issues a warning message for the current pragma if operating in Ada -- 83 mode (used for language pragmas that are not a standard part of -- Ada 83). This procedure does not raise Error_Pragma. Also notes use -- of 95 pragma. procedure Check_Arg_Count (Required : Nat); -- Check argument count for pragma is equal to given parameter. -- If not, then issue an error message and raise Pragma_Exit. -- Note: all routines whose name is Check_Arg_Is_xxx take an -- argument Arg which can either be a pragma argument association, -- in which case the check is applied to the expression of the -- association or an expression directly. procedure Check_Arg_Is_External_Name (Arg : Node_Id); -- Check that an argument has the right form for an EXTERNAL_NAME -- parameter of an extended import/export pragma. The rule is that -- the name must be an identifier or string literal (in Ada 83 mode) -- or a static string expression (in Ada 95 mode). procedure Check_Arg_Is_Identifier (Arg : Node_Id); -- Check the specified argument Arg to make sure that it is an -- identifier. If not give error and raise Pragma_Exit. procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id); -- Check the specified argument Arg to make sure that it is an -- integer literal. If not give error and raise Pragma_Exit. procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id); -- Check the specified argument Arg to make sure that it has the -- proper syntactic form for a local name and meets the semantic -- requirements for a local name. The local name is analyzed as -- part of the processing for this call. In addition, the local -- name is required to represent an entity at the library level. procedure Check_Arg_Is_Local_Name (Arg : Node_Id); -- Check the specified argument Arg to make sure that it has the -- proper syntactic form for a local name and meets the semantic -- requirements for a local name. The local name is analyzed as -- part of the processing for this call. procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id); -- Check the specified argument Arg to make sure that it is a valid -- locking policy name. If not give error and raise Pragma_Exit. procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id); procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id); -- Check the specified argument Arg to make sure that it is an -- identifier whose name matches either N1 or N2 (or N3 if present). -- If not then give error and raise Pragma_Exit. procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id); -- Check the specified argument Arg to make sure that it is a valid -- queuing policy name. If not give error and raise Pragma_Exit. procedure Check_Arg_Is_Static_Expression (Arg : Node_Id; Typ : Entity_Id); -- Check the specified argument Arg to make sure that it is a static -- expression of the given type (i.e. it will be analyzed and resolved -- using this type, which can be any valid argument to Resolve, e.g. -- Any_Integer is OK). If not, given error and raise Pragma_Exit. procedure Check_Arg_Is_String_Literal (Arg : Node_Id); -- Check the specified argument Arg to make sure that it is a -- string literal. If not give error and raise Pragma_Exit procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id); -- Check the specified argument Arg to make sure that it is a valid -- valid task dispatching policy name. If not give error and raise -- Pragma_Exit. procedure Check_Arg_Order (Names : Name_List); -- Checks for an instance of two arguments with identifiers for the -- current pragma which are not in the sequence indicated by Names, -- and if so, generates a fatal message about bad order of arguments. procedure Check_At_Least_N_Arguments (N : Nat); -- Check there are at least N arguments present procedure Check_At_Most_N_Arguments (N : Nat); -- Check there are no more than N arguments present procedure Check_Component (Comp : Node_Id); -- Examine Unchecked_Union component for correct use of per-object -- constrained subtypes, and for restrictions on finalizable components. procedure Check_Duplicated_Export_Name (Nam : Node_Id); -- Nam is an N_String_Literal node containing the external name set -- by an Import or Export pragma (or extended Import or Export pragma). -- This procedure checks for possible duplications if this is the -- export case, and if found, issues an appropriate error message. procedure Check_First_Subtype (Arg : Node_Id); -- Checks that Arg, whose expression is an entity name referencing -- a subtype, does not reference a type that is not a first subtype. procedure Check_In_Main_Program; -- Common checks for pragmas that appear within a main program -- (Priority, Main_Storage, Time_Slice). procedure Check_Interrupt_Or_Attach_Handler; -- Common processing for first argument of pragma Interrupt_Handler -- or pragma Attach_Handler. procedure Check_Is_In_Decl_Part_Or_Package_Spec; -- Check that pragma appears in a declarative part, or in a package -- specification, i.e. that it does not occur in a statement sequence -- in a body. procedure Check_No_Identifier (Arg : Node_Id); -- Checks that the given argument does not have an identifier. If -- an identifier is present, then an error message is issued, and -- Pragma_Exit is raised. procedure Check_No_Identifiers; -- Checks that none of the arguments to the pragma has an identifier. -- If any argument has an identifier, then an error message is issued, -- and Pragma_Exit is raised. procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id); -- Checks if the given argument has an identifier, and if so, requires -- it to match the given identifier name. If there is a non-matching -- identifier, then an error message is given and Error_Pragmas raised. procedure Check_Optional_Identifier (Arg : Node_Id; Id : String); -- Checks if the given argument has an identifier, and if so, requires -- it to match the given identifier name. If there is a non-matching -- identifier, then an error message is given and Error_Pragmas raised. -- In this version of the procedure, the identifier name is given as -- a string with lower case letters. procedure Check_Static_Constraint (Constr : Node_Id); -- Constr is a constraint from an N_Subtype_Indication node from a -- component constraint in an Unchecked_Union type. This routine checks -- that the constraint is static as required by the restrictions for -- Unchecked_Union. procedure Check_Valid_Configuration_Pragma; -- Legality checks for placement of a configuration pragma procedure Check_Valid_Library_Unit_Pragma; -- Legality checks for library unit pragmas. A special case arises for -- pragmas in generic instances that come from copies of the original -- library unit pragmas in the generic templates. In the case of other -- than library level instantiations these can appear in contexts which -- would normally be invalid (they only apply to the original template -- and to library level instantiations), and they are simply ignored, -- which is implemented by rewriting them as null statements. procedure Check_Variant (Variant : Node_Id); -- Check Unchecked_Union variant for lack of nested variants and -- presence of at least one component. procedure Error_Pragma (Msg : String); pragma No_Return (Error_Pragma); -- Outputs error message for current pragma. The message contains an % -- that will be replaced with the pragma name, and the flag is placed -- on the pragma itself. Pragma_Exit is then raised. procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id); pragma No_Return (Error_Pragma_Arg); -- Outputs error message for current pragma. The message may contain -- a % that will be replaced with the pragma name. The parameter Arg -- may either be a pragma argument association, in which case the flag -- is placed on the expression of this association, or an expression, -- in which case the flag is placed directly on the expression. The -- message is placed using Error_Msg_N, so the message may also contain -- an & insertion character which will reference the given Arg value. -- After placing the message, Pragma_Exit is raised. procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id); pragma No_Return (Error_Pragma_Arg); -- Similar to above form of Error_Pragma_Arg except that two messages -- are provided, the second is a continuation comment starting with \. procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id); pragma No_Return (Error_Pragma_Arg_Ident); -- Outputs error message for current pragma. The message may contain -- a % that will be replaced with the pragma name. The parameter Arg -- must be a pragma argument association with a non-empty identifier -- (i.e. its Chars field must be set), and the error message is placed -- on the identifier. The message is placed using Error_Msg_N so -- the message may also contain an & insertion character which will -- reference the identifier. After placing the message, Pragma_Exit -- is raised. function Find_Lib_Unit_Name return Entity_Id; -- Used for a library unit pragma to find the entity to which the -- library unit pragma applies, returns the entity found. procedure Find_Program_Unit_Name (Id : Node_Id); -- If the pragma is a compilation unit pragma, the id must denote the -- compilation unit in the same compilation, and the pragma must appear -- in the list of preceding or trailing pragmas. If it is a program -- unit pragma that is not a compilation unit pragma, then the -- identifier must be visible. function Find_Unique_Parameterless_Procedure (Name : Entity_Id; Arg : Node_Id) return Entity_Id; -- Used for a procedure pragma to find the unique parameterless -- procedure identified by Name, returns it if it exists, otherwise -- errors out and uses Arg as the pragma argument for the message. procedure Gather_Associations (Names : Name_List; Args : out Args_List); -- This procedure is used to gather the arguments for a pragma that -- permits arbitrary ordering of parameters using the normal rules -- for named and positional parameters. The Names argument is a list -- of Name_Id values that corresponds to the allowed pragma argument -- association identifiers in order. The result returned in Args is -- a list of corresponding expressions that are the pragma arguments. -- Note that this is a list of expressions, not of pragma argument -- associations (Gather_Associations has completely checked all the -- optional identifiers when it returns). An entry in Args is Empty -- on return if the corresponding argument is not present. function Get_Pragma_Arg (Arg : Node_Id) return Node_Id; -- All the routines that check pragma arguments take either a pragma -- argument association (in which case the expression of the argument -- association is checked), or the expression directly. The function -- Get_Pragma_Arg is a utility used to deal with these two cases. If -- Arg is a pragma argument association node, then its expression is -- returned, otherwise Arg is returned unchanged. procedure GNAT_Pragma; -- Called for all GNAT defined pragmas to note the use of the feature, -- and also check the relevant restriction (No_Implementation_Pragmas). function Is_Before_First_Decl (Pragma_Node : Node_Id; Decls : List_Id) return Boolean; -- Return True if Pragma_Node is before the first declarative item in -- Decls where Decls is the list of declarative items. function Is_Configuration_Pragma return Boolean; -- Deterermines if the placement of the current pragma is appropriate -- for a configuration pragma (precedes the current compilation unit) procedure Pragma_Misplaced; -- Issue fatal error message for misplaced pragma procedure Process_Atomic_Shared_Volatile; -- Common processing for pragmas Atomic, Shared, Volatile. Note that -- Shared is an obsolete Ada 83 pragma, treated as being identical -- in effect to pragma Atomic. procedure Process_Convention (C : out Convention_Id; E : out Entity_Id); -- Common procesing for Convention, Interface, Import and Export. -- Checks first two arguments of pragma, and sets the appropriate -- convention value in the specified entity or entities. On return -- C is the convention, E is the referenced entity. procedure Process_Extended_Import_Export_Exception_Pragma (Arg_Internal : Node_Id; Arg_External : Node_Id; Arg_Form : Node_Id; Arg_Code : Node_Id); -- Common processing for the pragmas Import/Export_Exception. -- The three arguments correspond to the three named parameters of -- the pragma. An argument is empty if the corresponding parameter -- is not present in the pragma. procedure Process_Extended_Import_Export_Object_Pragma (Arg_Internal : Node_Id; Arg_External : Node_Id; Arg_Size : Node_Id); -- Common processing for the pragmass Import/Export_Object. -- The three arguments correspond to the three named parameters -- of the pragmas. An argument is empty if the corresponding -- parameter is not present in the pragma. procedure Process_Extended_Import_Export_Internal_Arg (Arg_Internal : Node_Id := Empty); -- Common processing for all extended Import and Export pragmas. The -- argument is the pragma parameter for the Internal argument. If -- Arg_Internal is empty or inappropriate, an error message is posted. -- Otherwise, on normal return, the Entity_Field of Arg_Internal is -- set to identify the referenced entity. procedure Process_Extended_Import_Export_Subprogram_Pragma (Arg_Internal : Node_Id; Arg_External : Node_Id; Arg_Parameter_Types : Node_Id; Arg_Result_Type : Node_Id := Empty; Arg_Mechanism : Node_Id; Arg_Result_Mechanism : Node_Id := Empty; Arg_First_Optional_Parameter : Node_Id := Empty); -- Common processing for all extended Import and Export pragmas -- applying to subprograms. The caller omits any arguments that do -- bnot apply to the pragma in question (for example, Arg_Result_Type -- can be non-Empty only in the Import_Function and Export_Function -- cases). The argument names correspond to the allowed pragma -- association identifiers. procedure Process_Generic_List; -- Common processing for Share_Generic and Inline_Generic procedure Process_Import_Or_Interface; -- Common processing for Import of Interface procedure Process_Inline (Active : Boolean); -- Common processing for Inline and Inline_Always. The parameter -- indicates if the inline pragma is active, i.e. if it should -- actually cause inlining to occur. procedure Process_Interface_Name (Subprogram_Def : Entity_Id; Ext_Arg : Node_Id; Link_Arg : Node_Id); -- Given the last two arguments of pragma Import, pragma Export, or -- pragma Interface_Name, performs validity checks and sets the -- Interface_Name field of the given subprogram entity to the -- appropriate external or link name, depending on the arguments -- given. Ext_Arg is always present, but Link_Arg may be missing. -- Note that Ext_Arg may represent the Link_Name if Link_Arg is -- missing, and appropriate named notation is used for Ext_Arg. -- If neither Ext_Arg nor Link_Arg is present, the interface name -- is set to the default from the subprogram name. procedure Process_Interrupt_Or_Attach_Handler; -- Common processing for Interrupt and Attach_Handler pragmas procedure Process_Restrictions_Or_Restriction_Warnings; -- Common processing for Restrictions and Restriction_Warnings pragmas procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean); -- Common processing for Suppress and Unsuppress. The boolean parameter -- Suppress_Case is True for the Suppress case, and False for the -- Unsuppress case. procedure Set_Exported (E : Entity_Id; Arg : Node_Id); -- This procedure sets the Is_Exported flag for the given entity, -- checking that the entity was not previously imported. Arg is -- the argument that specified the entity. A check is also made -- for exporting inappropriate entities. procedure Set_Extended_Import_Export_External_Name (Internal_Ent : Entity_Id; Arg_External : Node_Id); -- Common processing for all extended import export pragmas. The first -- argument, Internal_Ent, is the internal entity, which has already -- been checked for validity by the caller. Arg_External is from the -- Import or Export pragma, and may be null if no External parameter -- was present. If Arg_External is present and is a non-null string -- (a null string is treated as the default), then the Interface_Name -- field of Internal_Ent is set appropriately. procedure Set_Imported (E : Entity_Id); -- This procedure sets the Is_Imported flag for the given entity, -- checking that it is not previously exported or imported. procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id); -- Mech is a parameter passing mechanism (see Import_Function syntax -- for MECHANISM_NAME). This routine checks that the mechanism argument -- has the right form, and if not issues an error message. If the -- argument has the right form then the Mechanism field of Ent is -- set appropriately. procedure Set_Ravenscar_Profile (N : Node_Id); -- Activate the set of configuration pragmas and restrictions that -- make up the Ravenscar Profile. N is the corresponding pragma -- node, which is used for error messages on any constructs -- that violate the profile. -------------------------- -- Check_Ada_83_Warning -- -------------------------- procedure Check_Ada_83_Warning is begin if Ada_Version = Ada_83 and then Comes_From_Source (N) then Error_Msg_N ("(Ada 83) pragma& is non-standard?", N); end if; end Check_Ada_83_Warning; --------------------- -- Check_Arg_Count -- --------------------- procedure Check_Arg_Count (Required : Nat) is begin if Arg_Count /= Required then Error_Pragma ("wrong number of arguments for pragma%"); end if; end Check_Arg_Count; -------------------------------- -- Check_Arg_Is_External_Name -- -------------------------------- procedure Check_Arg_Is_External_Name (Arg : Node_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin if Nkind (Argx) = N_Identifier then return; else Analyze_And_Resolve (Argx, Standard_String); if Is_OK_Static_Expression (Argx) then return; elsif Etype (Argx) = Any_Type then raise Pragma_Exit; -- An interesting special case, if we have a string literal and -- we are in Ada 83 mode, then we allow it even though it will -- not be flagged as static. This allows expected Ada 83 mode -- use of external names which are string literals, even though -- technically these are not static in Ada 83. elsif Ada_Version = Ada_83 and then Nkind (Argx) = N_String_Literal then return; -- Static expression that raises Constraint_Error. This has -- already been flagged, so just exit from pragma processing. elsif Is_Static_Expression (Argx) then raise Pragma_Exit; -- Here we have a real error (non-static expression) else Error_Msg_Name_1 := Chars (N); Flag_Non_Static_Expr ("argument for pragma% must be a identifier or " & "static string expression!", Argx); raise Pragma_Exit; end if; end if; end Check_Arg_Is_External_Name; ----------------------------- -- Check_Arg_Is_Identifier -- ----------------------------- procedure Check_Arg_Is_Identifier (Arg : Node_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin if Nkind (Argx) /= N_Identifier then Error_Pragma_Arg ("argument for pragma% must be identifier", Argx); end if; end Check_Arg_Is_Identifier; ---------------------------------- -- Check_Arg_Is_Integer_Literal -- ---------------------------------- procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin if Nkind (Argx) /= N_Integer_Literal then Error_Pragma_Arg ("argument for pragma% must be integer literal", Argx); end if; end Check_Arg_Is_Integer_Literal; ------------------------------------------- -- Check_Arg_Is_Library_Level_Local_Name -- ------------------------------------------- -- LOCAL_NAME ::= -- DIRECT_NAME -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR -- | library_unit_NAME procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is begin Check_Arg_Is_Local_Name (Arg); if not Is_Library_Level_Entity (Entity (Expression (Arg))) and then Comes_From_Source (N) then Error_Pragma_Arg ("argument for pragma% must be library level entity", Arg); end if; end Check_Arg_Is_Library_Level_Local_Name; ----------------------------- -- Check_Arg_Is_Local_Name -- ----------------------------- -- LOCAL_NAME ::= -- DIRECT_NAME -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR -- | library_unit_NAME procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin Analyze (Argx); if Nkind (Argx) not in N_Direct_Name and then (Nkind (Argx) /= N_Attribute_Reference or else Present (Expressions (Argx)) or else Nkind (Prefix (Argx)) /= N_Identifier) and then (not Is_Entity_Name (Argx) or else not Is_Compilation_Unit (Entity (Argx))) then Error_Pragma_Arg ("argument for pragma% must be local name", Argx); end if; if Is_Entity_Name (Argx) and then Scope (Entity (Argx)) /= Current_Scope then Error_Pragma_Arg ("pragma% argument must be in same declarative part", Arg); end if; end Check_Arg_Is_Local_Name; --------------------------------- -- Check_Arg_Is_Locking_Policy -- --------------------------------- procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin Check_Arg_Is_Identifier (Argx); if not Is_Locking_Policy_Name (Chars (Argx)) then Error_Pragma_Arg ("& is not a valid locking policy name", Argx); end if; end Check_Arg_Is_Locking_Policy; ------------------------- -- Check_Arg_Is_One_Of -- ------------------------- procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin Check_Arg_Is_Identifier (Argx); if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then Error_Msg_Name_2 := N1; Error_Msg_Name_3 := N2; Error_Pragma_Arg ("argument for pragma% must be% or%", Argx); end if; end Check_Arg_Is_One_Of; procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin Check_Arg_Is_Identifier (Argx); if Chars (Argx) /= N1 and then Chars (Argx) /= N2 and then Chars (Argx) /= N3 then Error_Pragma_Arg ("invalid argument for pragma%", Argx); end if; end Check_Arg_Is_One_Of; --------------------------------- -- Check_Arg_Is_Queuing_Policy -- --------------------------------- procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin Check_Arg_Is_Identifier (Argx); if not Is_Queuing_Policy_Name (Chars (Argx)) then Error_Pragma_Arg ("& is not a valid queuing policy name", Argx); end if; end Check_Arg_Is_Queuing_Policy; ------------------------------------ -- Check_Arg_Is_Static_Expression -- ------------------------------------ procedure Check_Arg_Is_Static_Expression (Arg : Node_Id; Typ : Entity_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin Analyze_And_Resolve (Argx, Typ); if Is_OK_Static_Expression (Argx) then return; elsif Etype (Argx) = Any_Type then raise Pragma_Exit; -- An interesting special case, if we have a string literal and -- we are in Ada 83 mode, then we allow it even though it will -- not be flagged as static. This allows the use of Ada 95 -- pragmas like Import in Ada 83 mode. They will of course be -- flagged with warnings as usual, but will not cause errors. elsif Ada_Version = Ada_83 and then Nkind (Argx) = N_String_Literal then return; -- Static expression that raises Constraint_Error. This has -- already been flagged, so just exit from pragma processing. elsif Is_Static_Expression (Argx) then raise Pragma_Exit; -- Finally, we have a real error else Error_Msg_Name_1 := Chars (N); Flag_Non_Static_Expr ("argument for pragma% must be a static expression!", Argx); raise Pragma_Exit; end if; end Check_Arg_Is_Static_Expression; --------------------------------- -- Check_Arg_Is_String_Literal -- --------------------------------- procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin if Nkind (Argx) /= N_String_Literal then Error_Pragma_Arg ("argument for pragma% must be string literal", Argx); end if; end Check_Arg_Is_String_Literal; ------------------------------------------ -- Check_Arg_Is_Task_Dispatching_Policy -- ------------------------------------------ procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin Check_Arg_Is_Identifier (Argx); if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then Error_Pragma_Arg ("& is not a valid task dispatching policy name", Argx); end if; end Check_Arg_Is_Task_Dispatching_Policy; --------------------- -- Check_Arg_Order -- --------------------- procedure Check_Arg_Order (Names : Name_List) is Arg : Node_Id; Highest_So_Far : Natural := 0; -- Highest index in Names seen do far begin Arg := Arg1; for J in 1 .. Arg_Count loop if Chars (Arg) /= No_Name then for K in Names'Range loop if Chars (Arg) = Names (K) then if K < Highest_So_Far then Error_Msg_Name_1 := Chars (N); Error_Msg_N ("parameters out of order for pragma%", Arg); Error_Msg_Name_1 := Names (K); Error_Msg_Name_2 := Names (Highest_So_Far); Error_Msg_N ("\% must appear before %", Arg); raise Pragma_Exit; else Highest_So_Far := K; end if; end if; end loop; end if; Arg := Next (Arg); end loop; end Check_Arg_Order; -------------------------------- -- Check_At_Least_N_Arguments -- -------------------------------- procedure Check_At_Least_N_Arguments (N : Nat) is begin if Arg_Count < N then Error_Pragma ("too few arguments for pragma%"); end if; end Check_At_Least_N_Arguments; ------------------------------- -- Check_At_Most_N_Arguments -- ------------------------------- procedure Check_At_Most_N_Arguments (N : Nat) is Arg : Node_Id; begin if Arg_Count > N then Arg := Arg1; for J in 1 .. N loop Next (Arg); Error_Pragma_Arg ("too many arguments for pragma%", Arg); end loop; end if; end Check_At_Most_N_Arguments; --------------------- -- Check_Component -- --------------------- procedure Check_Component (Comp : Node_Id) is begin if Nkind (Comp) = N_Component_Declaration then declare Sindic : constant Node_Id := Subtype_Indication (Component_Definition (Comp)); Typ : constant Entity_Id := Etype (Defining_Identifier (Comp)); begin if Nkind (Sindic) = N_Subtype_Indication then -- Ada 2005 (AI-216): If a component subtype is subject to -- a per-object constraint, then the component type shall -- be an Unchecked_Union. if Has_Per_Object_Constraint (Defining_Identifier (Comp)) and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic))) then Error_Msg_N ("component subtype subject to per-object" & " constraint must be an Unchecked_Union", Comp); end if; end if; if Is_Controlled (Typ) then Error_Msg_N ("component of unchecked union cannot be controlled", Comp); elsif Has_Task (Typ) then Error_Msg_N ("component of unchecked union cannot have tasks", Comp); end if; end; end if; end Check_Component; ---------------------------------- -- Check_Duplicated_Export_Name -- ---------------------------------- procedure Check_Duplicated_Export_Name (Nam : Node_Id) is String_Val : constant String_Id := Strval (Nam); begin -- We are only interested in the export case, and in the case of -- generics, it is the instance, not the template, that is the -- problem (the template will generate a warning in any case). if not Inside_A_Generic and then (Prag_Id = Pragma_Export or else Prag_Id = Pragma_Export_Procedure or else Prag_Id = Pragma_Export_Valued_Procedure or else Prag_Id = Pragma_Export_Function) then for J in Externals.First .. Externals.Last loop if String_Equal (String_Val, Strval (Externals.Table (J))) then Error_Msg_Sloc := Sloc (Externals.Table (J)); Error_Msg_N ("external name duplicates name given#", Nam); exit; end if; end loop; Externals.Append (Nam); end if; end Check_Duplicated_Export_Name; ------------------------- -- Check_First_Subtype -- ------------------------- procedure Check_First_Subtype (Arg : Node_Id) is Argx : constant Node_Id := Get_Pragma_Arg (Arg); begin if not Is_First_Subtype (Entity (Argx)) then Error_Pragma_Arg ("pragma% cannot apply to subtype", Argx); end if; end Check_First_Subtype; --------------------------- -- Check_In_Main_Program -- --------------------------- procedure Check_In_Main_Program is P : constant Node_Id := Parent (N); begin -- Must be at in subprogram body if Nkind (P) /= N_Subprogram_Body then Error_Pragma ("% pragma allowed only in subprogram"); -- Otherwise warn if obviously not main program elsif Present (Parameter_Specifications (Specification (P))) or else not Is_Compilation_Unit (Defining_Entity (P)) then Error_Msg_Name_1 := Chars (N); Error_Msg_N ("?pragma% is only effective in main program", N); end if; end Check_In_Main_Program; --------------------------------------- -- Check_Interrupt_Or_Attach_Handler -- --------------------------------------- procedure Check_Interrupt_Or_Attach_Handler is Arg1_X : constant Node_Id := Expression (Arg1); Handler_Proc, Proc_Scope : Entity_Id; begin Analyze (Arg1_X); if Prag_Id = Pragma_Interrupt_Handler then Check_Restriction (No_Dynamic_Attachment, N); end if; Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1); Proc_Scope := Scope (Handler_Proc); -- On AAMP only, a pragma Interrupt_Handler is supported for -- nonprotected parameterless procedures. if not AAMP_On_Target or else Prag_Id = Pragma_Attach_Handler then if Ekind (Proc_Scope) /= E_Protected_Type then Error_Pragma_Arg ("argument of pragma% must be protected procedure", Arg1); end if; if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then Error_Pragma ("pragma% must be in protected definition"); end if; end if; if not Is_Library_Level_Entity (Proc_Scope) or else (AAMP_On_Target and then not Is_Library_Level_Entity (Handler_Proc)) then Error_Pragma_Arg ("argument for pragma% must be library level entity", Arg1); end if; end Check_Interrupt_Or_Attach_Handler; ------------------------------------------- -- Check_Is_In_Decl_Part_Or_Package_Spec -- ------------------------------------------- procedure Check_Is_In_Decl_Part_Or_Package_Spec is P : Node_Id; begin P := Parent (N); loop if No (P) then exit; elsif Nkind (P) = N_Handled_Sequence_Of_Statements then exit; elsif Nkind (P) = N_Package_Specification then return; elsif Nkind (P) = N_Block_Statement then return; -- Note: the following tests seem a little peculiar, because -- they test for bodies, but if we were in the statement part -- of the body, we would already have hit the handled statement -- sequence, so the only way we get here is by being in the -- declarative part of the body. elsif Nkind (P) = N_Subprogram_Body or else Nkind (P) = N_Package_Body or else Nkind (P) = N_Task_Body or else Nkind (P) = N_Entry_Body then return; end if; P := Parent (P); end loop; Error_Pragma ("pragma% is not in declarative part or package spec"); end Check_Is_In_Decl_Part_Or_Package_Spec; ------------------------- -- Check_No_Identifier -- ------------------------- procedure Check_No_Identifier (Arg : Node_Id) is begin if Chars (Arg) /= No_Name then Error_Pragma_Arg_Ident ("pragma% does not permit identifier& here", Arg); end if; end Check_No_Identifier; -------------------------- -- Check_No_Identifiers -- -------------------------- procedure Check_No_Identifiers is Arg_Node : Node_Id; begin if Arg_Count > 0 then Arg_Node := Arg1; while Present (Arg_Node) loop Check_No_Identifier (Arg_Node); Next (Arg_Node); end loop; end if; end Check_No_Identifiers; ------------------------------- -- Check_Optional_Identifier -- ------------------------------- procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is begin if Present (Arg) and then Chars (Arg) /= No_Name then if Chars (Arg) /= Id then Error_Msg_Name_1 := Chars (N); Error_Msg_Name_2 := Id; Error_Msg_N ("pragma% argument expects identifier%", Arg); raise Pragma_Exit; end if; end if; end Check_Optional_Identifier; procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is begin Name_Buffer (1 .. Id'Length) := Id; Name_Len := Id'Length; Check_Optional_Identifier (Arg, Name_Find); end Check_Optional_Identifier; ----------------------------- -- Check_Static_Constraint -- ----------------------------- -- Note: for convenience in writing this procedure, in addition to -- the officially (i.e. by spec) allowed argument which is always -- a constraint, it also allows ranges and discriminant associations. -- Above is not clear ??? procedure Check_Static_Constraint (Constr : Node_Id) is -------------------- -- Require_Static -- -------------------- procedure Require_Static (E : Node_Id); -- Require given expression to be static expression procedure Require_Static (E : Node_Id) is begin if not Is_OK_Static_Expression (E) then Flag_Non_Static_Expr ("non-static constraint not allowed in Unchecked_Union!", E); raise Pragma_Exit; end if; end Require_Static; -- Start of processing for Check_Static_Constraint begin case Nkind (Constr) is when N_Discriminant_Association => Require_Static (Expression (Constr)); when N_Range => Require_Static (Low_Bound (Constr)); Require_Static (High_Bound (Constr)); when N_Attribute_Reference => Require_Static (Type_Low_Bound (Etype (Prefix (Constr)))); Require_Static (Type_High_Bound (Etype (Prefix (Constr)))); when N_Range_Constraint => Check_Static_Constraint (Range_Expression (Constr)); when N_Index_Or_Discriminant_Constraint => declare IDC : Entity_Id; begin IDC := First (Constraints (Constr)); while Present (IDC) loop Check_Static_Constraint (IDC); Next (IDC); end loop; end; when others => null; end case; end Check_Static_Constraint; -------------------------------------- -- Check_Valid_Configuration_Pragma -- -------------------------------------- -- A configuration pragma must appear in the context clause of -- a compilation unit, at the start of the list (i.e. only other -- pragmas may precede it). procedure Check_Valid_Configuration_Pragma is begin if not Is_Configuration_Pragma then Error_Pragma ("incorrect placement for configuration pragma%"); end if; end Check_Valid_Configuration_Pragma; ------------------------------------- -- Check_Valid_Library_Unit_Pragma -- ------------------------------------- procedure Check_Valid_Library_Unit_Pragma is Plist : List_Id; Parent_Node : Node_Id; Unit_Name : Entity_Id; Unit_Kind : Node_Kind; Unit_Node : Node_Id; Sindex : Source_File_Index; begin if not Is_List_Member (N) then Pragma_Misplaced; else Plist := List_Containing (N); Parent_Node := Parent (Plist); if Parent_Node = Empty then Pragma_Misplaced; -- Case of pragma appearing after a compilation unit. In this -- case it must have an argument with the corresponding name -- and must be part of the following pragmas of its parent. elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then if Plist /= Pragmas_After (Parent_Node) then Pragma_Misplaced; elsif Arg_Count = 0 then Error_Pragma ("argument required if outside compilation unit"); else Check_No_Identifiers; Check_Arg_Count (1); Unit_Node := Unit (Parent (Parent_Node)); Unit_Kind := Nkind (Unit_Node); Analyze (Expression (Arg1)); if Unit_Kind = N_Generic_Subprogram_Declaration or else Unit_Kind = N_Subprogram_Declaration then Unit_Name := Defining_Entity (Unit_Node); elsif Unit_Kind in N_Generic_Instantiation then Unit_Name := Defining_Entity (Unit_Node); else Unit_Name := Cunit_Entity (Current_Sem_Unit); end if; if Chars (Unit_Name) /= Chars (Entity (Expression (Arg1))) then Error_Pragma_Arg ("pragma% argument is not current unit name", Arg1); end if; if Ekind (Unit_Name) = E_Package and then Present (Renamed_Entity (Unit_Name)) then Error_Pragma ("pragma% not allowed for renamed package"); end if; end if; -- Pragma appears other than after a compilation unit else -- Here we check for the generic instantiation case and also -- for the case of processing a generic formal package. We -- detect these cases by noting that the Sloc on the node -- does not belong to the current compilation unit. Sindex := Source_Index (Current_Sem_Unit); if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then Rewrite (N, Make_Null_Statement (Loc)); return; -- If before first declaration, the pragma applies to the -- enclosing unit, and the name if present must be this name. elsif Is_Before_First_Decl (N, Plist) then Unit_Node := Unit_Declaration_Node (Current_Scope); Unit_Kind := Nkind (Unit_Node); if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then Pragma_Misplaced; elsif Unit_Kind = N_Subprogram_Body and then not Acts_As_Spec (Unit_Node) then Pragma_Misplaced; elsif Nkind (Parent_Node) = N_Package_Body then Pragma_Misplaced; elsif Nkind (Parent_Node) = N_Package_Specification and then Plist = Private_Declarations (Parent_Node) then Pragma_Misplaced; elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration or else Nkind (Parent_Node) = N_Generic_Subprogram_Declaration) and then Plist = Generic_Formal_Declarations (Parent_Node) then Pragma_Misplaced; elsif Arg_Count > 0 then Analyze (Expression (Arg1)); if Entity (Expression (Arg1)) /= Current_Scope then Error_Pragma_Arg ("name in pragma% must be enclosing unit", Arg1); end if; -- It is legal to have no argument in this context else return; end if; -- Error if not before first declaration. This is because a -- library unit pragma argument must be the name of a library -- unit (RM 10.1.5(7)), but the only names permitted in this -- context are (RM 10.1.5(6)) names of subprogram declarations, -- generic subprogram declarations or generic instantiations. else Error_Pragma ("pragma% misplaced, must be before first declaration"); end if; end if; end if; end Check_Valid_Library_Unit_Pragma; ------------------- -- Check_Variant -- ------------------- procedure Check_Variant (Variant : Node_Id) is Clist : constant Node_Id := Component_List (Variant); Comp : Node_Id; begin if not Is_Non_Empty_List (Component_Items (Clist)) then Error_Msg_N ("Unchecked_Union may not have empty component list", Variant); return; end if; Comp := First (Component_Items (Clist)); while Present (Comp) loop Check_Component (Comp); Next (Comp); end loop; end Check_Variant; ------------------ -- Error_Pragma -- ------------------ procedure Error_Pragma (Msg : String) is begin Error_Msg_Name_1 := Chars (N); Error_Msg_N (Msg, N); raise Pragma_Exit; end Error_Pragma; ---------------------- -- Error_Pragma_Arg -- ---------------------- procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is begin Error_Msg_Name_1 := Chars (N); Error_Msg_N (Msg, Get_Pragma_Arg (Arg)); raise Pragma_Exit; end Error_Pragma_Arg; procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is begin Error_Msg_Name_1 := Chars (N); Error_Msg_N (Msg1, Get_Pragma_Arg (Arg)); Error_Pragma_Arg (Msg2, Arg); end Error_Pragma_Arg; ---------------------------- -- Error_Pragma_Arg_Ident -- ---------------------------- procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is begin Error_Msg_Name_1 := Chars (N); Error_Msg_N (Msg, Arg); raise Pragma_Exit; end Error_Pragma_Arg_Ident; ------------------------ -- Find_Lib_Unit_Name -- ------------------------ function Find_Lib_Unit_Name return Entity_Id is begin -- Return inner compilation unit entity, for case of nested -- categorization pragmas. This happens in generic unit. if Nkind (Parent (N)) = N_Package_Specification and then Defining_Entity (Parent (N)) /= Current_Scope then return Defining_Entity (Parent (N)); else return Current_Scope; end if; end Find_Lib_Unit_Name; ---------------------------- -- Find_Program_Unit_Name -- ---------------------------- procedure Find_Program_Unit_Name (Id : Node_Id) is Unit_Name : Entity_Id; Unit_Kind : Node_Kind; P : constant Node_Id := Parent (N); begin if Nkind (P) = N_Compilation_Unit then Unit_Kind := Nkind (Unit (P)); if Unit_Kind = N_Subprogram_Declaration or else Unit_Kind = N_Package_Declaration or else Unit_Kind in N_Generic_Declaration then Unit_Name := Defining_Entity (Unit (P)); if Chars (Id) = Chars (Unit_Name) then Set_Entity (Id, Unit_Name); Set_Etype (Id, Etype (Unit_Name)); else Set_Etype (Id, Any_Type); Error_Pragma ("cannot find program unit referenced by pragma%"); end if; else Set_Etype (Id, Any_Type); Error_Pragma ("pragma% inapplicable to this unit"); end if; else Analyze (Id); end if; end Find_Program_Unit_Name; ----------------------------------------- -- Find_Unique_Parameterless_Procedure -- ----------------------------------------- function Find_Unique_Parameterless_Procedure (Name : Entity_Id; Arg : Node_Id) return Entity_Id is Proc : Entity_Id := Empty; begin -- The body of this procedure needs some comments ??? if not Is_Entity_Name (Name) then Error_Pragma_Arg ("argument of pragma% must be entity name", Arg); elsif not Is_Overloaded (Name) then Proc := Entity (Name); if Ekind (Proc) /= E_Procedure or else Present (First_Formal (Proc)) then Error_Pragma_Arg ("argument of pragma% must be parameterless procedure", Arg); end if; else declare Found : Boolean := False; It : Interp; Index : Interp_Index; begin Get_First_Interp (Name, Index, It); while Present (It.Nam) loop Proc := It.Nam; if Ekind (Proc) = E_Procedure and then No (First_Formal (Proc)) then if not Found then Found := True; Set_Entity (Name, Proc); Set_Is_Overloaded (Name, False); else Error_Pragma_Arg ("ambiguous handler name for pragma% ", Arg); end if; end if; Get_Next_Interp (Index, It); end loop; if not Found then Error_Pragma_Arg ("argument of pragma% must be parameterless procedure", Arg); else Proc := Entity (Name); end if; end; end if; return Proc; end Find_Unique_Parameterless_Procedure; ------------------------- -- Gather_Associations -- ------------------------- procedure Gather_Associations (Names : Name_List; Args : out Args_List) is Arg : Node_Id; begin -- Initialize all parameters to Empty for J in Args'Range loop Args (J) := Empty; end loop; -- That's all we have to do if there are no argument associations if No (Pragma_Argument_Associations (N)) then return; end if; -- Otherwise first deal with any positional parameters present Arg := First (Pragma_Argument_Associations (N)); for Index in Args'Range loop exit when No (Arg) or else Chars (Arg) /= No_Name; Args (Index) := Expression (Arg); Next (Arg); end loop; -- Positional parameters all processed, if any left, then we -- have too many positional parameters. if Present (Arg) and then Chars (Arg) = No_Name then Error_Pragma_Arg ("too many positional associations for pragma%", Arg); end if; -- Process named parameters if any are present while Present (Arg) loop if Chars (Arg) = No_Name then Error_Pragma_Arg ("positional association cannot follow named association", Arg); else for Index in Names'Range loop if Names (Index) = Chars (Arg) then if Present (Args (Index)) then Error_Pragma_Arg ("duplicate argument association for pragma%", Arg); else Args (Index) := Expression (Arg); exit; end if; end if; if Index = Names'Last then Error_Msg_Name_1 := Chars (N); Error_Msg_N ("pragma% does not allow & argument", Arg); -- Check for possible misspelling for Index1 in Names'Range loop if Is_Bad_Spelling_Of (Get_Name_String (Chars (Arg)), Get_Name_String (Names (Index1))) then Error_Msg_Name_1 := Names (Index1); Error_Msg_N ("\possible misspelling of%", Arg); exit; end if; end loop; raise Pragma_Exit; end if; end loop; end if; Next (Arg); end loop; end Gather_Associations; -------------------- -- Get_Pragma_Arg -- -------------------- function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is begin if Nkind (Arg) = N_Pragma_Argument_Association then return Expression (Arg); else return Arg; end if; end Get_Pragma_Arg; ----------------- -- GNAT_Pragma -- ----------------- procedure GNAT_Pragma is begin Check_Restriction (No_Implementation_Pragmas, N); end GNAT_Pragma; -------------------------- -- Is_Before_First_Decl -- -------------------------- function Is_Before_First_Decl (Pragma_Node : Node_Id; Decls : List_Id) return Boolean is Item : Node_Id := First (Decls); begin -- Only other pragmas can come before this pragma loop if No (Item) or else Nkind (Item) /= N_Pragma then return False; elsif Item = Pragma_Node then return True; end if; Next (Item); end loop; end Is_Before_First_Decl; ----------------------------- -- Is_Configuration_Pragma -- ----------------------------- -- A configuration pragma must appear in the context clause of -- a compilation unit, at the start of the list (i.e. only other -- pragmas may precede it). function Is_Configuration_Pragma return Boolean is Lis : constant List_Id := List_Containing (N); Par : constant Node_Id := Parent (N); Prg : Node_Id; begin -- If no parent, then we are in the configuration pragma file, -- so the placement is definitely appropriate. if No (Par) then return True; -- Otherwise we must be in the context clause of a compilation unit -- and the only thing allowed before us in the context list is more -- configuration pragmas. elsif Nkind (Par) = N_Compilation_Unit and then Context_Items (Par) = Lis then Prg := First (Lis); loop if Prg = N then return True; elsif Nkind (Prg) /= N_Pragma then return False; end if; Next (Prg); end loop; else return False; end if; end Is_Configuration_Pragma; ---------------------- -- Pragma_Misplaced -- ---------------------- procedure Pragma_Misplaced is begin Error_Pragma ("incorrect placement of pragma%"); end Pragma_Misplaced; ------------------------------------ -- Process Atomic_Shared_Volatile -- ------------------------------------ procedure Process_Atomic_Shared_Volatile is E_Id : Node_Id; E : Entity_Id; D : Node_Id; K : Node_Kind; Utyp : Entity_Id; procedure Set_Atomic (E : Entity_Id); -- Set given type as atomic, and if no explicit alignment was -- given, set alignment to unknown, since back end knows what -- the alignment requirements are for atomic arrays. Note that -- this step is necessary for derived types. ---------------- -- Set_Atomic -- ---------------- procedure Set_Atomic (E : Entity_Id) is begin Set_Is_Atomic (E); if not Has_Alignment_Clause (E) then Set_Alignment (E, Uint_0); end if; end Set_Atomic; -- Start of processing for Process_Atomic_Shared_Volatile begin Check_Ada_83_Warning; Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_Local_Name (Arg1); E_Id := Expression (Arg1); if Etype (E_Id) = Any_Type then return; end if; E := Entity (E_Id); D := Declaration_Node (E); K := Nkind (D); if Is_Type (E) then if Rep_Item_Too_Early (E, N) or else Rep_Item_Too_Late (E, N) then return; else Check_First_Subtype (Arg1); end if; if Prag_Id /= Pragma_Volatile then Set_Atomic (E); Set_Atomic (Underlying_Type (E)); Set_Atomic (Base_Type (E)); end if; -- Attribute belongs on the base type. If the -- view of the type is currently private, it also -- belongs on the underlying type. Set_Is_Volatile (Base_Type (E)); Set_Is_Volatile (Underlying_Type (E)); Set_Treat_As_Volatile (E); Set_Treat_As_Volatile (Underlying_Type (E)); elsif K = N_Object_Declaration or else (K = N_Component_Declaration and then Original_Record_Component (E) = E) then if Rep_Item_Too_Late (E, N) then return; end if; if Prag_Id /= Pragma_Volatile then Set_Is_Atomic (E); -- If the object declaration has an explicit -- initialization, a temporary may have to be -- created to hold the expression, to insure -- that access to the object remain atomic. if Nkind (Parent (E)) = N_Object_Declaration and then Present (Expression (Parent (E))) then Set_Has_Delayed_Freeze (E); end if; -- An interesting improvement here. If an object of type X -- is declared atomic, and the type X is not atomic, that's -- a pity, since it may not have appropraite alignment etc. -- We can rescue this in the special case where the object -- and type are in the same unit by just setting the type -- as atomic, so that the back end will process it as atomic. Utyp := Underlying_Type (Etype (E)); if Present (Utyp) and then Sloc (E) > No_Location and then Sloc (Utyp) > No_Location and then Get_Source_File_Index (Sloc (E)) = Get_Source_File_Index (Sloc (Underlying_Type (Etype (E)))) then Set_Is_Atomic (Underlying_Type (Etype (E))); end if; end if; Set_Is_Volatile (E); Set_Treat_As_Volatile (E); else Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1); end if; end Process_Atomic_Shared_Volatile; ------------------------ -- Process_Convention -- ------------------------ procedure Process_Convention (C : out Convention_Id; E : out Entity_Id) is Id : Node_Id; E1 : Entity_Id; Cname : Name_Id; Comp_Unit : Unit_Number_Type; procedure Set_Convention_From_Pragma (E : Entity_Id); -- Set convention in entity E, and also flag that the entity has a -- convention pragma. If entity is for a private or incomplete type, -- also set convention and flag on underlying type. This procedure -- also deals with the special case of C_Pass_By_Copy convention. -------------------------------- -- Set_Convention_From_Pragma -- -------------------------------- procedure Set_Convention_From_Pragma (E : Entity_Id) is begin -- Check invalid attempt to change convention for an overridden -- dispatching operation. This is Ada 2005 AI 430. Technically -- this is an amendment and should only be done in Ada 2005 mode. -- However, this is clearly a mistake, since the problem that is -- addressed by this AI is that there is a clear gap in the RM! if Is_Dispatching_Operation (E) and then Present (Overridden_Operation (E)) and then C /= Convention (Overridden_Operation (E)) then Error_Pragma_Arg ("cannot change convention for " & "overridden dispatching operation", Arg1); end if; -- Set the convention Set_Convention (E, C); Set_Has_Convention_Pragma (E); if Is_Incomplete_Or_Private_Type (E) then Set_Convention (Underlying_Type (E), C); Set_Has_Convention_Pragma (Underlying_Type (E), True); end if; -- A class-wide type should inherit the convention of -- the specific root type (although this isn't specified -- clearly by the RM). if Is_Type (E) and then Present (Class_Wide_Type (E)) then Set_Convention (Class_Wide_Type (E), C); end if; -- If the entity is a record type, then check for special case -- of C_Pass_By_Copy, which is treated the same as C except that -- the special record flag is set. This convention is also only -- permitted on record types (see AI95-00131). if Cname = Name_C_Pass_By_Copy then if Is_Record_Type (E) then Set_C_Pass_By_Copy (Base_Type (E)); elsif Is_Incomplete_Or_Private_Type (E) and then Is_Record_Type (Underlying_Type (E)) then Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E))); else Error_Pragma_Arg ("C_Pass_By_Copy convention allowed only for record type", Arg2); end if; end if; -- If the entity is a derived boolean type, check for the -- special case of convention C, C++, or Fortran, where we -- consider any nonzero value to represent true. if Is_Discrete_Type (E) and then Root_Type (Etype (E)) = Standard_Boolean and then (C = Convention_C or else C = Convention_CPP or else C = Convention_Fortran) then Set_Nonzero_Is_True (Base_Type (E)); end if; end Set_Convention_From_Pragma; -- Start of processing for Process_Convention begin Check_At_Least_N_Arguments (2); Check_Optional_Identifier (Arg1, Name_Convention); Check_Arg_Is_Identifier (Arg1); Cname := Chars (Expression (Arg1)); -- C_Pass_By_Copy is treated as a synonym for convention C -- (this is tested again below to set the critical flag) if Cname = Name_C_Pass_By_Copy then C := Convention_C; -- Otherwise we must have something in the standard convention list elsif Is_Convention_Name (Cname) then C := Get_Convention_Id (Chars (Expression (Arg1))); -- In DEC VMS, it seems that there is an undocumented feature -- that any unrecognized convention is treated as the default, -- which for us is convention C. It does not seem so terrible -- to do this unconditionally, silently in the VMS case, and -- with a warning in the non-VMS case. else if Warn_On_Export_Import and not OpenVMS_On_Target then Error_Msg_N ("?unrecognized convention name, C assumed", Expression (Arg1)); end if; C := Convention_C; end if; Check_Optional_Identifier (Arg2, Name_Entity); Check_Arg_Is_Local_Name (Arg2); Id := Expression (Arg2); Analyze (Id); if not Is_Entity_Name (Id) then Error_Pragma_Arg ("entity name required", Arg2); end if; E := Entity (Id); -- Go to renamed subprogram if present, since convention applies -- to the actual renamed entity, not to the renaming entity. -- If subprogram is inherited, go to parent subprogram. if Is_Subprogram (E) and then Present (Alias (E)) then if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Renaming_Declaration then E := Alias (E); elsif Nkind (Parent (E)) = N_Full_Type_Declaration and then Scope (E) = Scope (Alias (E)) then E := Alias (E); end if; end if; -- Check that we are not applying this to a specless body if Is_Subprogram (E) and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then Error_Pragma ("pragma% requires separate spec and must come before body"); end if; -- Check that we are not applying this to a named constant if Ekind (E) = E_Named_Integer or else Ekind (E) = E_Named_Real then Error_Msg_Name_1 := Chars (N); Error_Msg_N ("cannot apply pragma% to named constant!", Get_Pragma_Arg (Arg2)); Error_Pragma_Arg ("\supply appropriate type for&!", Arg2); end if; if Etype (E) = Any_Type or else Rep_Item_Too_Early (E, N) then raise Pragma_Exit; else E := Underlying_Type (E); end if; if Rep_Item_Too_Late (E, N) then raise Pragma_Exit; end if; if Has_Convention_Pragma (E) then Error_Pragma_Arg ("at most one Convention/Export/Import pragma is allowed", Arg2); elsif Convention (E) = Convention_Protected or else Ekind (Scope (E)) = E_Protected_Type then Error_Pragma_Arg ("a protected operation cannot be given a different convention", Arg2); end if; -- For Intrinsic, a subprogram is required if C = Convention_Intrinsic and then not Is_Subprogram (E) and then not Is_Generic_Subprogram (E) then Error_Pragma_Arg ("second argument of pragma% must be a subprogram", Arg2); end if; -- For Stdcall, a subprogram, variable or subprogram type is required if C = Convention_Stdcall and then not Is_Subprogram (E) and then not Is_Generic_Subprogram (E) and then Ekind (E) /= E_Variable and then not (Is_Access_Type (E) and then Ekind (Designated_Type (E)) = E_Subprogram_Type) then Error_Pragma_Arg ("second argument of pragma% must be subprogram (type)", Arg2); end if; if not Is_Subprogram (E) and then not Is_Generic_Subprogram (E) then Set_Convention_From_Pragma (E); if Is_Type (E) then Check_First_Subtype (Arg2); Set_Convention_From_Pragma (Base_Type (E)); -- For subprograms, we must set the convention on the -- internally generated directly designated type as well. if Ekind (E) = E_Access_Subprogram_Type then Set_Convention_From_Pragma (Directly_Designated_Type (E)); end if; end if; -- For the subprogram case, set proper convention for all homonyms -- in same scope and the same declarative part, i.e. the same -- compilation unit. else Comp_Unit := Get_Source_Unit (E); Set_Convention_From_Pragma (E); -- Treat a pragma Import as an implicit body, for GPS use if Prag_Id = Pragma_Import then Generate_Reference (E, Id, 'b'); end if; E1 := E; loop E1 := Homonym (E1); exit when No (E1) or else Scope (E1) /= Current_Scope; -- Note: below we are missing a check for Rep_Item_Too_Late. -- That is deliberate, we cannot chain the rep item on more -- than one Rep_Item chain, to be fixed later ??? if Comes_From_Source (E1) and then Comp_Unit = Get_Source_Unit (E1) and then Nkind (Original_Node (Parent (E1))) /= N_Full_Type_Declaration then Set_Convention_From_Pragma (E1); if Prag_Id = Pragma_Import then Generate_Reference (E, Id, 'b'); end if; end if; end loop; end if; end Process_Convention; ----------------------------------------------------- -- Process_Extended_Import_Export_Exception_Pragma -- ----------------------------------------------------- procedure Process_Extended_Import_Export_Exception_Pragma (Arg_Internal : Node_Id; Arg_External : Node_Id; Arg_Form : Node_Id; Arg_Code : Node_Id) is Def_Id : Entity_Id; Code_Val : Uint; begin GNAT_Pragma; if not OpenVMS_On_Target then Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)"); end if; Process_Extended_Import_Export_Internal_Arg (Arg_Internal); Def_Id := Entity (Arg_Internal); if Ekind (Def_Id) /= E_Exception then Error_Pragma_Arg ("pragma% must refer to declared exception", Arg_Internal); end if; Set_Extended_Import_Export_External_Name (Def_Id, Arg_External); if Present (Arg_Form) then Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS); end if; if Present (Arg_Form) and then Chars (Arg_Form) = Name_Ada then null; else Set_Is_VMS_Exception (Def_Id); Set_Exception_Code (Def_Id, No_Uint); end if; if Present (Arg_Code) then if not Is_VMS_Exception (Def_Id) then Error_Pragma_Arg ("Code option for pragma% not allowed for Ada case", Arg_Code); end if; Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer); Code_Val := Expr_Value (Arg_Code); if not UI_Is_In_Int_Range (Code_Val) then Error_Pragma_Arg ("Code option for pragma% must be in 32-bit range", Arg_Code); else Set_Exception_Code (Def_Id, Code_Val); end if; end if; end Process_Extended_Import_Export_Exception_Pragma; ------------------------------------------------- -- Process_Extended_Import_Export_Internal_Arg -- ------------------------------------------------- procedure Process_Extended_Import_Export_Internal_Arg (Arg_Internal : Node_Id := Empty) is begin GNAT_Pragma; if No (Arg_Internal) then Error_Pragma ("Internal parameter required for pragma%"); end if; if Nkind (Arg_Internal) = N_Identifier then null; elsif Nkind (Arg_Internal) = N_Operator_Symbol and then (Prag_Id = Pragma_Import_Function or else Prag_Id = Pragma_Export_Function) then null; else Error_Pragma_Arg ("wrong form for Internal parameter for pragma%", Arg_Internal); end if; Check_Arg_Is_Local_Name (Arg_Internal); end Process_Extended_Import_Export_Internal_Arg; -------------------------------------------------- -- Process_Extended_Import_Export_Object_Pragma -- -------------------------------------------------- procedure Process_Extended_Import_Export_Object_Pragma (Arg_Internal : Node_Id; Arg_External : Node_Id; Arg_Size : Node_Id) is Def_Id : Entity_Id; begin Process_Extended_Import_Export_Internal_Arg (Arg_Internal); Def_Id := Entity (Arg_Internal); if Ekind (Def_Id) /= E_Constant and then Ekind (Def_Id) /= E_Variable then Error_Pragma_Arg ("pragma% must designate an object", Arg_Internal); end if; if Has_Rep_Pragma (Def_Id, Name_Common_Object) or else Has_Rep_Pragma (Def_Id, Name_Psect_Object) then Error_Pragma_Arg ("previous Common/Psect_Object applies, pragma % not permitted", Arg_Internal); end if; if Rep_Item_Too_Late (Def_Id, N) then raise Pragma_Exit; end if; Set_Extended_Import_Export_External_Name (Def_Id, Arg_External); if Present (Arg_Size) then Check_Arg_Is_External_Name (Arg_Size); end if; -- Export_Object case if Prag_Id = Pragma_Export_Object then if not Is_Library_Level_Entity (Def_Id) then Error_Pragma_Arg ("argument for pragma% must be library level entity", Arg_Internal); end if; if Ekind (Current_Scope) = E_Generic_Package then Error_Pragma ("pragma& cannot appear in a generic unit"); end if; if not Size_Known_At_Compile_Time (Etype (Def_Id)) then Error_Pragma_Arg ("exported object must have compile time known size", Arg_Internal); end if; if Warn_On_Export_Import and then Is_Exported (Def_Id) then Error_Msg_N ("?duplicate Export_Object pragma", N); else Set_Exported (Def_Id, Arg_Internal); end if; -- Import_Object case else if Is_Concurrent_Type (Etype (Def_Id)) then Error_Pragma_Arg ("cannot use pragma% for task/protected object", Arg_Internal); end if; if Ekind (Def_Id) = E_Constant then Error_Pragma_Arg ("cannot import a constant", Arg_Internal); end if; if Warn_On_Export_Import and then Has_Discriminants (Etype (Def_Id)) then Error_Msg_N ("imported value must be initialized?", Arg_Internal); end if; if Warn_On_Export_Import and then Is_Access_Type (Etype (Def_Id)) then Error_Pragma_Arg ("cannot import object of an access type?", Arg_Internal); end if; if Warn_On_Export_Import and then Is_Imported (Def_Id) then Error_Msg_N ("?duplicate Import_Object pragma", N); -- Check for explicit initialization present. Note that an -- initialization that generated by the code generator, e.g. -- for an access type, does not count here. elsif Present (Expression (Parent (Def_Id))) and then Comes_From_Source (Original_Node (Expression (Parent (Def_Id)))) then Error_Msg_Sloc := Sloc (Def_Id); Error_Pragma_Arg ("no initialization allowed for declaration of& #", "\imported entities cannot be initialized ('R'M' 'B.1(24))", Arg1); else Set_Imported (Def_Id); Note_Possible_Modification (Arg_Internal); end if; end if; end Process_Extended_Import_Export_Object_Pragma; ------------------------------------------------------ -- Process_Extended_Import_Export_Subprogram_Pragma -- ------------------------------------------------------ procedure Process_Extended_Import_Export_Subprogram_Pragma (Arg_Internal : Node_Id; Arg_External : Node_Id; Arg_Parameter_Types : Node_Id; Arg_Result_Type : Node_Id := Empty; Arg_Mechanism : Node_Id; Arg_Result_Mechanism : Node_Id := Empty; Arg_First_Optional_Parameter : Node_Id := Empty) is Ent : Entity_Id; Def_Id : Entity_Id; Hom_Id : Entity_Id; Formal : Entity_Id; Ambiguous : Boolean; Match : Boolean; Dval : Node_Id; function Same_Base_Type (Ptype : Node_Id; Formal : Entity_Id) return Boolean; -- Determines if Ptype references the type of Formal. Note that -- only the base types need to match according to the spec. Ptype -- here is the argument from the pragma, which is either a type -- name, or an access attribute. -------------------- -- Same_Base_Type -- -------------------- function Same_Base_Type (Ptype : Node_Id; Formal : Entity_Id) return Boolean is Ftyp : constant Entity_Id := Base_Type (Etype (Formal)); Pref : Node_Id; begin -- Case where pragma argument is typ'Access if Nkind (Ptype) = N_Attribute_Reference and then Attribute_Name (Ptype) = Name_Access then Pref := Prefix (Ptype); Find_Type (Pref); if not Is_Entity_Name (Pref) or else Entity (Pref) = Any_Type then raise Pragma_Exit; end if; -- We have a match if the corresponding argument is of an -- anonymous access type, and its designicated type matches -- the type of the prefix of the access attribute return Ekind (Ftyp) = E_Anonymous_Access_Type and then Base_Type (Entity (Pref)) = Base_Type (Etype (Designated_Type (Ftyp))); -- Case where pragma argument is a type name else Find_Type (Ptype); if not Is_Entity_Name (Ptype) or else Entity (Ptype) = Any_Type then raise Pragma_Exit; end if; -- We have a match if the corresponding argument is of -- the type given in the pragma (comparing base types) return Base_Type (Entity (Ptype)) = Ftyp; end if; end Same_Base_Type; -- Start of processing for -- Process_Extended_Import_Export_Subprogram_Pragma begin Process_Extended_Import_Export_Internal_Arg (Arg_Internal); Ent := Empty; Ambiguous := False; -- Loop through homonyms (overloadings) of the entity Hom_Id := Entity (Arg_Internal); while Present (Hom_Id) loop Def_Id := Get_Base_Subprogram (Hom_Id); -- We need a subprogram in the current scope if not Is_Subprogram (Def_Id) or else Scope (Def_Id) /= Current_Scope then null; else Match := True; -- Pragma cannot apply to subprogram body if Is_Subprogram (Def_Id) and then Nkind (Parent (Declaration_Node (Def_Id))) = N_Subprogram_Body then Error_Pragma ("pragma% requires separate spec" & " and must come before body"); end if; -- Test result type if given, note that the result type -- parameter can only be present for the function cases. if Present (Arg_Result_Type) and then not Same_Base_Type (Arg_Result_Type, Def_Id) then Match := False; elsif Etype (Def_Id) /= Standard_Void_Type and then (Chars (N) = Name_Export_Procedure or else Chars (N) = Name_Import_Procedure) then Match := False; -- Test parameter types if given. Note that this parameter -- has not been analyzed (and must not be, since it is -- semantic nonsense), so we get it as the parser left it. elsif Present (Arg_Parameter_Types) then Check_Matching_Types : declare Formal : Entity_Id; Ptype : Node_Id; begin Formal := First_Formal (Def_Id); if Nkind (Arg_Parameter_Types) = N_Null then if Present (Formal) then Match := False; end if; -- A list of one type, e.g. (List) is parsed as -- a parenthesized expression. elsif Nkind (Arg_Parameter_Types) /= N_Aggregate and then Paren_Count (Arg_Parameter_Types) = 1 then if No (Formal) or else Present (Next_Formal (Formal)) then Match := False; else Match := Same_Base_Type (Arg_Parameter_Types, Formal); end if; -- A list of more than one type is parsed as a aggregate elsif Nkind (Arg_Parameter_Types) = N_Aggregate and then Paren_Count (Arg_Parameter_Types) = 0 then Ptype := First (Expressions (Arg_Parameter_Types)); while Present (Ptype) or else Present (Formal) loop if No (Ptype) or else No (Formal) or else not Same_Base_Type (Ptype, Formal) then Match := False; exit; else Next_Formal (Formal); Next (Ptype); end if; end loop; -- Anything else is of the wrong form else Error_Pragma_Arg ("wrong form for Parameter_Types parameter", Arg_Parameter_Types); end if; end Check_Matching_Types; end if; -- Match is now False if the entry we found did not match -- either a supplied Parameter_Types or Result_Types argument if Match then if No (Ent) then Ent := Def_Id; -- Ambiguous case, the flag Ambiguous shows if we already -- detected this and output the initial messages. else if not Ambiguous then Ambiguous := True; Error_Msg_Name_1 := Chars (N); Error_Msg_N ("pragma% does not uniquely identify subprogram!", N); Error_Msg_Sloc := Sloc (Ent); Error_Msg_N ("matching subprogram #!", N); Ent := Empty; end if; Error_Msg_Sloc := Sloc (Def_Id); Error_Msg_N ("matching subprogram #!", N); end if; end if; end if; Hom_Id := Homonym (Hom_Id); end loop; -- See if we found an entry if No (Ent) then if not Ambiguous then if Is_Generic_Subprogram (Entity (Arg_Internal)) then Error_Pragma ("pragma% cannot be given for generic subprogram"); else Error_Pragma ("pragma% does not identify local subprogram"); end if; end if; return; end if; -- Import pragmas must be be for imported entities if Prag_Id = Pragma_Import_Function or else Prag_Id = Pragma_Import_Procedure or else Prag_Id = Pragma_Import_Valued_Procedure then if not Is_Imported (Ent) then Error_Pragma ("pragma Import or Interface must precede pragma%"); end if; -- Here we have the Export case which can set the entity as exported -- But does not do so if the specified external name is null, -- since that is taken as a signal in DEC Ada 83 (with which -- we want to be compatible) to request no external name. elsif Nkind (Arg_External) = N_String_Literal and then String_Length (Strval (Arg_External)) = 0 then null; -- In all other cases, set entit as exported else Set_Exported (Ent, Arg_Internal); end if; -- Special processing for Valued_Procedure cases if Prag_Id = Pragma_Import_Valued_Procedure or else Prag_Id = Pragma_Export_Valued_Procedure then Formal := First_Formal (Ent); if No (Formal) then Error_Pragma ("at least one parameter required for pragma%"); elsif Ekind (Formal) /= E_Out_Parameter then Error_Pragma ("first parameter must have mode out for pragma%"); else Set_Is_Valued_Procedure (Ent); end if; end if; Set_Extended_Import_Export_External_Name (Ent, Arg_External); -- Process Result_Mechanism argument if present. We have already -- checked that this is only allowed for the function case. if Present (Arg_Result_Mechanism) then Set_Mechanism_Value (Ent, Arg_Result_Mechanism); end if; -- Process Mechanism parameter if present. Note that this parameter -- is not analyzed, and must not be analyzed since it is semantic -- nonsense, so we get it in exactly as the parser left it. if Present (Arg_Mechanism) then declare Formal : Entity_Id; Massoc : Node_Id; Mname : Node_Id; Choice : Node_Id; begin -- A single mechanism association without a formal parameter -- name is parsed as a parenthesized expression. All other -- cases are parsed as aggregates, so we rewrite the single -- parameter case as an aggregate for consistency. if Nkind (Arg_Mechanism) /= N_Aggregate and then Paren_Count (Arg_Mechanism) = 1 then Rewrite (Arg_Mechanism, Make_Aggregate (Sloc (Arg_Mechanism), Expressions => New_List ( Relocate_Node (Arg_Mechanism)))); end if; -- Case of only mechanism name given, applies to all formals if Nkind (Arg_Mechanism) /= N_Aggregate then Formal := First_Formal (Ent); while Present (Formal) loop Set_Mechanism_Value (Formal, Arg_Mechanism); Next_Formal (Formal); end loop; -- Case of list of mechanism associations given else if Null_Record_Present (Arg_Mechanism) then Error_Pragma_Arg ("inappropriate form for Mechanism parameter", Arg_Mechanism); end if; -- Deal with positional ones first Formal := First_Formal (Ent); if Present (Expressions (Arg_Mechanism)) then Mname := First (Expressions (Arg_Mechanism)); while Present (Mname) loop if No (Formal) then Error_Pragma_Arg ("too many mechanism associations", Mname); end if; Set_Mechanism_Value (Formal, Mname); Next_Formal (Formal); Next (Mname); end loop; end if; -- Deal with named entries if Present (Component_Associations (Arg_Mechanism)) then Massoc := First (Component_Associations (Arg_Mechanism)); while Present (Massoc) loop Choice := First (Choices (Massoc)); if Nkind (Choice) /= N_Identifier or else Present (Next (Choice)) then Error_Pragma_Arg ("incorrect form for mechanism association", Massoc); end if; Formal := First_Formal (Ent); loop if No (Formal) then Error_Pragma_Arg ("parameter name & not present", Choice); end if; if Chars (Choice) = Chars (Formal) then Set_Mechanism_Value (Formal, Expression (Massoc)); exit; end if; Next_Formal (Formal); end loop; Next (Massoc); end loop; end if; end if; end; end if; -- Process First_Optional_Parameter argument if present. We have -- already checked that this is only allowed for the Import case. if Present (Arg_First_Optional_Parameter) then if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then Error_Pragma_Arg ("first optional parameter must be formal parameter name", Arg_First_Optional_Parameter); end if; Formal := First_Formal (Ent); loop if No (Formal) then Error_Pragma_Arg ("specified formal parameter& not found", Arg_First_Optional_Parameter); end if; exit when Chars (Formal) = Chars (Arg_First_Optional_Parameter); Next_Formal (Formal); end loop; Set_First_Optional_Parameter (Ent, Formal); -- Check specified and all remaining formals have right form while Present (Formal) loop if Ekind (Formal) /= E_In_Parameter then Error_Msg_NE ("optional formal& is not of mode in!", Arg_First_Optional_Parameter, Formal); else Dval := Default_Value (Formal); if No (Dval) then Error_Msg_NE ("optional formal& does not have default value!", Arg_First_Optional_Parameter, Formal); elsif Compile_Time_Known_Value_Or_Aggr (Dval) then null; else Error_Msg_FE ("default value for optional formal& is non-static!", Arg_First_Optional_Parameter, Formal); end if; end if; Set_Is_Optional_Parameter (Formal); Next_Formal (Formal); end loop; end if; end Process_Extended_Import_Export_Subprogram_Pragma; -------------------------- -- Process_Generic_List -- -------------------------- procedure Process_Generic_List is Arg : Node_Id; Exp : Node_Id; begin GNAT_Pragma; Check_No_Identifiers; Check_At_Least_N_Arguments (1); Arg := Arg1; while Present (Arg) loop Exp := Expression (Arg); Analyze (Exp); if not Is_Entity_Name (Exp) or else (not Is_Generic_Instance (Entity (Exp)) and then not Is_Generic_Unit (Entity (Exp))) then Error_Pragma_Arg ("pragma% argument must be name of generic unit/instance", Arg); end if; Next (Arg); end loop; end Process_Generic_List; --------------------------------- -- Process_Import_Or_Interface -- --------------------------------- procedure Process_Import_Or_Interface is C : Convention_Id; Def_Id : Entity_Id; Hom_Id : Entity_Id; begin Process_Convention (C, Def_Id); Kill_Size_Check_Code (Def_Id); Note_Possible_Modification (Expression (Arg2)); if Ekind (Def_Id) = E_Variable or else Ekind (Def_Id) = E_Constant then -- User initialization is not allowed for imported object, but -- the object declaration may contain a default initialization, -- that will be discarded. Note that an explicit initialization -- only counts if it comes from source, otherwise it is simply -- the code generator making an implicit initialization explicit. if Present (Expression (Parent (Def_Id))) and then Comes_From_Source (Expression (Parent (Def_Id))) then Error_Msg_Sloc := Sloc (Def_Id); Error_Pragma_Arg ("no initialization allowed for declaration of& #", "\imported entities cannot be initialized ('R'M' 'B.1(24))", Arg2); else Set_Imported (Def_Id); Process_Interface_Name (Def_Id, Arg3, Arg4); -- Note that we do not set Is_Public here. That's because we -- only want to set if if there is no address clause, and we -- don't know that yet, so we delay that processing till -- freeze time. -- pragma Import completes deferred constants if Ekind (Def_Id) = E_Constant then Set_Has_Completion (Def_Id); end if; -- It is not possible to import a constant of an unconstrained -- array type (e.g. string) because there is no simple way to -- write a meaningful subtype for it. if Is_Array_Type (Etype (Def_Id)) and then not Is_Constrained (Etype (Def_Id)) then Error_Msg_NE ("imported constant& must have a constrained subtype", N, Def_Id); end if; end if; elsif Is_Subprogram (Def_Id) or else Is_Generic_Subprogram (Def_Id) then -- If the name is overloaded, pragma applies to all of the -- denoted entities in the same declarative part. Hom_Id := Def_Id; while Present (Hom_Id) loop Def_Id := Get_Base_Subprogram (Hom_Id); -- Ignore inherited subprograms because the pragma will -- apply to the parent operation, which is the one called. if Is_Overloadable (Def_Id) and then Present (Alias (Def_Id)) then null; -- If it is not a subprogram, it must be in an outer -- scope and pragma does not apply. elsif not Is_Subprogram (Def_Id) and then not Is_Generic_Subprogram (Def_Id) then null; -- Verify that the homonym is in the same declarative -- part (not just the same scope). elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N) and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux then exit; else Set_Imported (Def_Id); -- Special processing for Convention_Intrinsic if C = Convention_Intrinsic then -- Link_Name argument not allowed for intrinsic if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then Arg4 := Arg3; end if; if Present (Arg4) then Error_Pragma_Arg ("Link_Name argument not allowed for " & "Import Intrinsic", Arg4); end if; Set_Is_Intrinsic_Subprogram (Def_Id); -- If no external name is present, then check that -- this is a valid intrinsic subprogram. If an external -- name is present, then this is handled by the back end. if No (Arg3) then Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2)); end if; end if; -- All interfaced procedures need an external symbol -- created for them since they are always referenced -- from another object file. Set_Is_Public (Def_Id); -- Verify that the subprogram does not have a completion -- through a renaming declaration. For other completions -- the pragma appears as a too late representation. declare Decl : constant Node_Id := Unit_Declaration_Node (Def_Id); begin if Present (Decl) and then Nkind (Decl) = N_Subprogram_Declaration and then Present (Corresponding_Body (Decl)) and then Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) = N_Subprogram_Renaming_Declaration then Error_Msg_Sloc := Sloc (Def_Id); Error_Msg_NE ("cannot import&#," & " already completed by a renaming", N, Def_Id); end if; end; Set_Has_Completion (Def_Id); Process_Interface_Name (Def_Id, Arg3, Arg4); end if; if Is_Compilation_Unit (Hom_Id) then -- Its possible homonyms are not affected by the pragma. -- Such homonyms might be present in the context of other -- units being compiled. exit; else Hom_Id := Homonym (Hom_Id); end if; end loop; -- When the convention is Java, we also allow Import to be given -- for packages, exceptions, and record components. elsif C = Convention_Java and then (Ekind (Def_Id) = E_Package or else Ekind (Def_Id) = E_Exception or else Nkind (Parent (Def_Id)) = N_Component_Declaration) then Set_Imported (Def_Id); Set_Is_Public (Def_Id); Process_Interface_Name (Def_Id, Arg3, Arg4); else Error_Pragma_Arg ("second argument of pragma% must be object or subprogram", Arg2); end if; -- If this pragma applies to a compilation unit, then the unit, -- which is a subprogram, does not require (or allow) a body. -- We also do not need to elaborate imported procedures. if Nkind (Parent (N)) = N_Compilation_Unit_Aux then declare Cunit : constant Node_Id := Parent (Parent (N)); begin Set_Body_Required (Cunit, False); end; end if; end Process_Import_Or_Interface; -------------------- -- Process_Inline -- -------------------- procedure Process_Inline (Active : Boolean) is Assoc : Node_Id; Decl : Node_Id; Subp_Id : Node_Id; Subp : Entity_Id; Applies : Boolean; Effective : Boolean := False; procedure Make_Inline (Subp : Entity_Id); -- Subp is the defining unit name of the subprogram -- declaration. Set the flag, as well as the flag in the -- corresponding body, if there is one present. procedure Set_Inline_Flags (Subp : Entity_Id); -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp function Inlining_Not_Possible (Subp : Entity_Id) return Boolean; -- Returns True if it can be determined at this stage that inlining -- is not possible, for examle if the body is available and contains -- exception handlers, we prevent inlining, since otherwise we can -- get undefined symbols at link time. This function also emits a -- warning if front-end inlining is enabled and the pragma appears -- too late. -- ??? is business with link symbols still valid, or does it relate -- to front end ZCX which is being phased out ??? --------------------------- -- Inlining_Not_Possible -- --------------------------- function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is Decl : constant Node_Id := Unit_Declaration_Node (Subp); Stats : Node_Id; begin if Nkind (Decl) = N_Subprogram_Body then Stats := Handled_Statement_Sequence (Decl); return Present (Exception_Handlers (Stats)) or else Present (At_End_Proc (Stats)); elsif Nkind (Decl) = N_Subprogram_Declaration and then Present (Corresponding_Body (Decl)) then if Front_End_Inlining and then Analyzed (Corresponding_Body (Decl)) then Error_Msg_N ("pragma appears too late, ignored?", N); return True; -- If the subprogram is a renaming as body, the body is -- just a call to the renamed subprogram, and inlining is -- trivially possible. elsif Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) = N_Subprogram_Renaming_Declaration then return False; else Stats := Handled_Statement_Sequence (Unit_Declaration_Node (Corresponding_Body (Decl))); return Present (Exception_Handlers (Stats)) or else Present (At_End_Proc (Stats)); end if; else -- If body is not available, assume the best, the check is -- performed again when compiling enclosing package bodies. return False; end if; end Inlining_Not_Possible; ----------------- -- Make_Inline -- ----------------- procedure Make_Inline (Subp : Entity_Id) is Kind : constant Entity_Kind := Ekind (Subp); Inner_Subp : Entity_Id := Subp; begin if Etype (Subp) = Any_Type then return; -- If inlining is not possible, for now do not treat as an error elsif Inlining_Not_Possible (Subp) then Applies := True; return; -- Here we have a candidate for inlining, but we must exclude -- derived operations. Otherwise we will end up trying to -- inline a phantom declaration, and the result would be to -- drag in a body which has no direct inlining associated with -- it. That would not only be inefficient but would also result -- in the backend doing cross-unit inlining in cases where it -- was definitely inappropriate to do so. -- However, a simple Comes_From_Source test is insufficient, -- since we do want to allow inlining of generic instances, -- which also do not come from source. Predefined operators do -- not come from source but are not inlineable either. elsif not Comes_From_Source (Subp) and then not Is_Generic_Instance (Subp) and then Scope (Subp) /= Standard_Standard then Applies := True; return; -- The referenced entity must either be the enclosing entity, -- or an entity declared within the current open scope. elsif Present (Scope (Subp)) and then Scope (Subp) /= Current_Scope and then Subp /= Current_Scope then Error_Pragma_Arg ("argument of% must be entity in current scope", Assoc); return; end if; -- Processing for procedure, operator or function. -- If subprogram is aliased (as for an instance) indicate -- that the renamed entity (if declared in the same unit) -- is inlined. if Is_Subprogram (Subp) then while Present (Alias (Inner_Subp)) loop Inner_Subp := Alias (Inner_Subp); end loop; if In_Same_Source_Unit (Subp, Inner_Subp) then Set_Inline_Flags (Inner_Subp); Decl := Parent (Parent (Inner_Subp)); if Nkind (Decl) = N_Subprogram_Declaration and then Present (Corresponding_Body (Decl)) then Set_Inline_Flags (Corresponding_Body (Decl)); end if; end if; Applies := True; -- For a generic subprogram set flag as well, for use at -- the point of instantiation, to determine whether the -- body should be generated. elsif Is_Generic_Subprogram (Subp) then Set_Inline_Flags (Subp); Applies := True; -- Literals are by definition inlined elsif Kind = E_Enumeration_Literal then null; -- Anything else is an error else Error_Pragma_Arg ("expect subprogram name for pragma%", Assoc); end if; end Make_Inline; ---------------------- -- Set_Inline_Flags -- ---------------------- procedure Set_Inline_Flags (Subp : Entity_Id) is begin if Active then Set_Is_Inlined (Subp, True); end if; if not Has_Pragma_Inline (Subp) then Set_Has_Pragma_Inline (Subp); Set_Next_Rep_Item (N, First_Rep_Item (Subp)); Set_First_Rep_Item (Subp, N); Effective := True; end if; end Set_Inline_Flags; -- Start of processing for Process_Inline begin Check_No_Identifiers; Check_At_Least_N_Arguments (1); if Active then Inline_Processing_Required := True; end if; Assoc := Arg1; while Present (Assoc) loop Subp_Id := Expression (Assoc); Analyze (Subp_Id); Applies := False; if Is_Entity_Name (Subp_Id) then Subp := Entity (Subp_Id); if Subp = Any_Id then -- If previous error, avoid cascaded errors Applies := True; Effective := True; else Make_Inline (Subp); while Present (Homonym (Subp)) and then Scope (Homonym (Subp)) = Current_Scope loop Make_Inline (Homonym (Subp)); Subp := Homonym (Subp); end loop; end if; end if; if not Applies then Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc); elsif not Effective and then Warn_On_Redundant_Constructs then if Inlining_Not_Possible (Subp) then Error_Msg_NE ("pragma Inline for& is ignored?", N, Entity (Subp_Id)); else Error_Msg_NE ("pragma Inline for& is redundant?", N, Entity (Subp_Id)); end if; end if; Next (Assoc); end loop; end Process_Inline; ---------------------------- -- Process_Interface_Name -- ---------------------------- procedure Process_Interface_Name (Subprogram_Def : Entity_Id; Ext_Arg : Node_Id; Link_Arg : Node_Id) is Ext_Nam : Node_Id; Link_Nam : Node_Id; String_Val : String_Id; procedure Check_Form_Of_Interface_Name (SN : Node_Id); -- SN is a string literal node for an interface name. This routine -- performs some minimal checks that the name is reasonable. In -- particular that no spaces or other obviously incorrect characters -- appear. This is only a warning, since any characters are allowed. ---------------------------------- -- Check_Form_Of_Interface_Name -- ---------------------------------- procedure Check_Form_Of_Interface_Name (SN : Node_Id) is S : constant String_Id := Strval (Expr_Value_S (SN)); SL : constant Nat := String_Length (S); C : Char_Code; begin if SL = 0 then Error_Msg_N ("interface name cannot be null string", SN); end if; for J in 1 .. SL loop C := Get_String_Char (S, J); if Warn_On_Export_Import and then (not In_Character_Range (C) or else Get_Character (C) = ' ' or else Get_Character (C) = ',') then Error_Msg_N ("?interface name contains illegal character", SN); end if; end loop; end Check_Form_Of_Interface_Name; -- Start of processing for Process_Interface_Name begin if No (Link_Arg) then if No (Ext_Arg) then return; elsif Chars (Ext_Arg) = Name_Link_Name then Ext_Nam := Empty; Link_Nam := Expression (Ext_Arg); else Check_Optional_Identifier (Ext_Arg, Name_External_Name); Ext_Nam := Expression (Ext_Arg); Link_Nam := Empty; end if; else Check_Optional_Identifier (Ext_Arg, Name_External_Name); Check_Optional_Identifier (Link_Arg, Name_Link_Name); Ext_Nam := Expression (Ext_Arg); Link_Nam := Expression (Link_Arg); end if; -- Check expressions for external name and link name are static if Present (Ext_Nam) then Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String); Check_Form_Of_Interface_Name (Ext_Nam); -- Verify that the external name is not the name of a local -- entity, which would hide the imported one and lead to -- run-time surprises. The problem can only arise for entities -- declared in a package body (otherwise the external name is -- fully qualified and won't conflict). declare Nam : Name_Id; E : Entity_Id; Par : Node_Id; begin if Prag_Id = Pragma_Import then String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam))); Nam := Name_Find; E := Entity_Id (Get_Name_Table_Info (Nam)); if Nam /= Chars (Subprogram_Def) and then Present (E) and then not Is_Overloadable (E) and then Is_Immediately_Visible (E) and then not Is_Imported (E) and then Ekind (Scope (E)) = E_Package then Par := Parent (E); while Present (Par) loop if Nkind (Par) = N_Package_Body then Error_Msg_Sloc := Sloc (E); Error_Msg_NE ("imported entity is hidden by & declared#", Ext_Arg, E); exit; end if; Par := Parent (Par); end loop; end if; end if; end; end if; if Present (Link_Nam) then Check_Arg_Is_Static_Expression (Link_Nam, Standard_String); Check_Form_Of_Interface_Name (Link_Nam); end if; -- If there is no link name, just set the external name if No (Link_Nam) then Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam)); -- For the Link_Name case, the given literal is preceded by an -- asterisk, which indicates to GCC that the given name should -- be taken literally, and in particular that no prepending of -- underlines should occur, even in systems where this is the -- normal default. else Start_String; Store_String_Char (Get_Char_Code ('*')); String_Val := Strval (Expr_Value_S (Link_Nam)); for J in 1 .. String_Length (String_Val) loop Store_String_Char (Get_String_Char (String_Val, J)); end loop; Link_Nam := Make_String_Literal (Sloc (Link_Nam), End_String); end if; Set_Encoded_Interface_Name (Get_Base_Subprogram (Subprogram_Def), Link_Nam); Check_Duplicated_Export_Name (Link_Nam); end Process_Interface_Name; ----------------------------------------- -- Process_Interrupt_Or_Attach_Handler -- ----------------------------------------- procedure Process_Interrupt_Or_Attach_Handler is Arg1_X : constant Node_Id := Expression (Arg1); Handler_Proc : constant Entity_Id := Entity (Arg1_X); Proc_Scope : constant Entity_Id := Scope (Handler_Proc); begin Set_Is_Interrupt_Handler (Handler_Proc); -- If the pragma is not associated with a handler procedure -- within a protected type, then it must be for a nonprotected -- procedure for the AAMP target, in which case we don't -- associate a representation item with the procedure's scope. if Ekind (Proc_Scope) = E_Protected_Type then if Prag_Id = Pragma_Interrupt_Handler or else Prag_Id = Pragma_Attach_Handler then Record_Rep_Item (Proc_Scope, N); end if; end if; end Process_Interrupt_Or_Attach_Handler; -------------------------------------------------- -- Process_Restrictions_Or_Restriction_Warnings -- -------------------------------------------------- -- Note: some of the simple identifier cases were handled in par-prag, -- but it is harmless (and more straightforward) to simply handle all -- cases here, even if it means we repeat a bit of work in some cases. procedure Process_Restrictions_Or_Restriction_Warnings is Arg : Node_Id; R_Id : Restriction_Id; Id : Name_Id; Expr : Node_Id; Val : Uint; procedure Check_Unit_Name (N : Node_Id); -- Checks unit name parameter for No_Dependence. Returns if it has -- an appropriate form, otherwise raises pragma argument error. procedure Set_Warning (R : All_Restrictions); -- If this is a Restriction_Warnings pragma, set warning flag, -- otherwise reset the flag. --------------------- -- Check_Unit_Name -- --------------------- procedure Check_Unit_Name (N : Node_Id) is begin if Nkind (N) = N_Selected_Component then Check_Unit_Name (Prefix (N)); Check_Unit_Name (Selector_Name (N)); elsif Nkind (N) = N_Identifier then return; else Error_Pragma_Arg ("wrong form for unit name for No_Dependence", N); end if; end Check_Unit_Name; ----------------- -- Set_Warning -- ----------------- procedure Set_Warning (R : All_Restrictions) is begin if Prag_Id = Pragma_Restriction_Warnings then Restriction_Warnings (R) := True; else Restriction_Warnings (R) := False; end if; end Set_Warning; -- Start of processing for Process_Restrictions_Or_Restriction_Warnings begin Check_Ada_83_Warning; Check_At_Least_N_Arguments (1); Check_Valid_Configuration_Pragma; Arg := Arg1; while Present (Arg) loop Id := Chars (Arg); Expr := Expression (Arg); -- Case of no restriction identifier present if Id = No_Name then if Nkind (Expr) /= N_Identifier then Error_Pragma_Arg ("invalid form for restriction", Arg); end if; R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Expr)); if R_Id not in All_Boolean_Restrictions then Error_Pragma_Arg ("invalid restriction identifier", Arg); end if; if Implementation_Restriction (R_Id) then Check_Restriction (No_Implementation_Restrictions, Arg); end if; Set_Restriction (R_Id, N); Set_Warning (R_Id); -- A very special case that must be processed here: -- pragma Restrictions (No_Exceptions) turns off -- all run-time checking. This is a bit dubious in -- terms of the formal language definition, but it -- is what is intended by RM H.4(12). if R_Id = No_Exceptions then Scope_Suppress := (others => True); end if; -- Case of No_Dependence => unit-name. Note that the parser -- already made the necessary entry in the No_Dependence table. elsif Id = Name_No_Dependence then Check_Unit_Name (Expr); -- All other cases of restriction identifier present else R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg)); Analyze_And_Resolve (Expr, Any_Integer); if R_Id not in All_Parameter_Restrictions then Error_Pragma_Arg ("invalid restriction parameter identifier", Arg); elsif not Is_OK_Static_Expression (Expr) then Flag_Non_Static_Expr ("value must be static expression!", Expr); raise Pragma_Exit; elsif not Is_Integer_Type (Etype (Expr)) or else Expr_Value (Expr) < 0 then Error_Pragma_Arg ("value must be non-negative integer", Arg); -- Restriction pragma is active else Val := Expr_Value (Expr); if not UI_Is_In_Int_Range (Val) then Error_Pragma_Arg ("pragma ignored, value too large?", Arg); else Set_Restriction (R_Id, N, Integer (UI_To_Int (Val))); Set_Warning (R_Id); end if; end if; end if; Next (Arg); end loop; end Process_Restrictions_Or_Restriction_Warnings; --------------------------------- -- Process_Suppress_Unsuppress -- --------------------------------- -- Note: this procedure makes entries in the check suppress data -- structures managed by Sem. See spec of package Sem for full -- details on how we handle recording of check suppression. procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is C : Check_Id; E_Id : Node_Id; E : Entity_Id; In_Package_Spec : constant Boolean := (Ekind (Current_Scope) = E_Package or else Ekind (Current_Scope) = E_Generic_Package) and then not In_Package_Body (Current_Scope); procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id); -- Used to suppress a single check on the given entity -------------------------------- -- Suppress_Unsuppress_Echeck -- -------------------------------- procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is ESR : constant Entity_Check_Suppress_Record := (Entity => E, Check => C, Suppress => Suppress_Case); begin Set_Checks_May_Be_Suppressed (E); if In_Package_Spec then Global_Entity_Suppress.Append (ESR); else Local_Entity_Suppress.Append (ESR); end if; -- If this is a first subtype, and the base type is distinct, -- then also set the suppress flags on the base type. if Is_First_Subtype (E) and then Etype (E) /= E then Suppress_Unsuppress_Echeck (Etype (E), C); end if; end Suppress_Unsuppress_Echeck; -- Start of processing for Process_Suppress_Unsuppress begin -- Suppress/Unsuppress can appear as a configuration pragma, -- or in a declarative part or a package spec (RM 11.5(5)) if not Is_Configuration_Pragma then Check_Is_In_Decl_Part_Or_Package_Spec; end if; Check_At_Least_N_Arguments (1); Check_At_Most_N_Arguments (2); Check_No_Identifier (Arg1); Check_Arg_Is_Identifier (Arg1); if not Is_Check_Name (Chars (Expression (Arg1))) then Error_Pragma_Arg ("argument of pragma% is not valid check name", Arg1); else C := Get_Check_Id (Chars (Expression (Arg1))); end if; if Arg_Count = 1 then -- Make an entry in the local scope suppress table. This is the -- table that directly shows the current value of the scope -- suppress check for any check id value. if C = All_Checks then -- For All_Checks, we set all specific checks with the -- exception of Elaboration_Check, which is handled specially -- because of not wanting All_Checks to have the effect of -- deactivating static elaboration order processing. for J in Scope_Suppress'Range loop if J /= Elaboration_Check then Scope_Suppress (J) := Suppress_Case; end if; end loop; -- If not All_Checks, just set appropriate entry. Note that we -- will set Elaboration_Check if this is explicitly specified. else Scope_Suppress (C) := Suppress_Case; end if; -- Also make an entry in the Local_Entity_Suppress table. See -- extended description in the package spec of Sem for details. Local_Entity_Suppress.Append ((Entity => Empty, Check => C, Suppress => Suppress_Case)); -- Case of two arguments present, where the check is -- suppressed for a specified entity (given as the second -- argument of the pragma) else Check_Optional_Identifier (Arg2, Name_On); E_Id := Expression (Arg2); Analyze (E_Id); if not Is_Entity_Name (E_Id) then Error_Pragma_Arg ("second argument of pragma% must be entity name", Arg2); end if; E := Entity (E_Id); if E = Any_Id then return; end if; -- Enforce RM 11.5(7) which requires that for a pragma that -- appears within a package spec, the named entity must be -- within the package spec. We allow the package name itself -- to be mentioned since that makes sense, although it is not -- strictly allowed by 11.5(7). if In_Package_Spec and then E /= Current_Scope and then Scope (E) /= Current_Scope then Error_Pragma_Arg ("entity in pragma% is not in package spec ('R'M 11.5(7))", Arg2); end if; -- Loop through homonyms. As noted below, in the case of a package -- spec, only homonyms within the package spec are considered. loop Suppress_Unsuppress_Echeck (E, C); if Is_Generic_Instance (E) and then Is_Subprogram (E) and then Present (Alias (E)) then Suppress_Unsuppress_Echeck (Alias (E), C); end if; -- Move to next homonym E := Homonym (E); exit when No (E); -- If we are within a package specification, the -- pragma only applies to homonyms in the same scope. exit when In_Package_Spec and then Scope (E) /= Current_Scope; end loop; end if; end Process_Suppress_Unsuppress; ------------------ -- Set_Exported -- ------------------ procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is begin if Is_Imported (E) then Error_Pragma_Arg ("cannot export entity& that was previously imported", Arg); elsif Present (Address_Clause (E)) then Error_Pragma_Arg ("cannot export entity& that has an address clause", Arg); end if; Set_Is_Exported (E); -- Generate a reference for entity explicitly, because the -- identifier may be overloaded and name resolution will not -- generate one. Generate_Reference (E, Arg); -- Deal with exporting non-library level entity if not Is_Library_Level_Entity (E) then -- Not allowed at all for subprograms if Is_Subprogram (E) then Error_Pragma_Arg ("local subprogram& cannot be exported", Arg); -- Otherwise set public and statically allocated else Set_Is_Public (E); Set_Is_Statically_Allocated (E); -- Warn if the corresponding W flag is set and the pragma -- comes from source. The latter may not be true e.g. on -- VMS where we expand export pragmas for exception codes -- associated with imported or exported exceptions. We do -- not want to generate a warning for something that the -- user did not write. if Warn_On_Export_Import and then Comes_From_Source (Arg) then Error_Msg_NE ("?& has been made static as a result of Export", Arg, E); Error_Msg_N ("\this usage is non-standard and non-portable", Arg); end if; end if; end if; if Warn_On_Export_Import and then Is_Type (E) then Error_Msg_NE ("exporting a type has no effect?", Arg, E); end if; if Warn_On_Export_Import and Inside_A_Generic then Error_Msg_NE ("all instances of& will have the same external name?", Arg, E); end if; end Set_Exported; ---------------------------------------------- -- Set_Extended_Import_Export_External_Name -- ---------------------------------------------- procedure Set_Extended_Import_Export_External_Name (Internal_Ent : Entity_Id; Arg_External : Node_Id) is Old_Name : constant Node_Id := Interface_Name (Internal_Ent); New_Name : Node_Id; begin if No (Arg_External) then return; end if; Check_Arg_Is_External_Name (Arg_External); if Nkind (Arg_External) = N_String_Literal then if String_Length (Strval (Arg_External)) = 0 then return; else New_Name := Adjust_External_Name_Case (Arg_External); end if; elsif Nkind (Arg_External) = N_Identifier then New_Name := Get_Default_External_Name (Arg_External); -- Check_Arg_Is_External_Name should let through only -- identifiers and string literals or static string -- expressions (which are folded to string literals). else raise Program_Error; end if; -- If we already have an external name set (by a prior normal -- Import or Export pragma), then the external names must match if Present (Interface_Name (Internal_Ent)) then Check_Matching_Internal_Names : declare S1 : constant String_Id := Strval (Old_Name); S2 : constant String_Id := Strval (New_Name); procedure Mismatch; -- Called if names do not match -------------- -- Mismatch -- -------------- procedure Mismatch is begin Error_Msg_Sloc := Sloc (Old_Name); Error_Pragma_Arg ("external name does not match that given #", Arg_External); end Mismatch; -- Start of processing for Check_Matching_Internal_Names begin if String_Length (S1) /= String_Length (S2) then Mismatch; else for J in 1 .. String_Length (S1) loop if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then Mismatch; end if; end loop; end if; end Check_Matching_Internal_Names; -- Otherwise set the given name else Set_Encoded_Interface_Name (Internal_Ent, New_Name); Check_Duplicated_Export_Name (New_Name); end if; end Set_Extended_Import_Export_External_Name; ------------------ -- Set_Imported -- ------------------ procedure Set_Imported (E : Entity_Id) is begin Error_Msg_Sloc := Sloc (E); if Is_Exported (E) or else Is_Imported (E) then Error_Msg_NE ("import of& declared# not allowed", N, E); if Is_Exported (E) then Error_Msg_N ("\entity was previously exported", N); else Error_Msg_N ("\entity was previously imported", N); end if; Error_Pragma ("\(pragma% applies to all previous entities)"); else Set_Is_Imported (E); -- If the entity is an object that is not at the library -- level, then it is statically allocated. We do not worry -- about objects with address clauses in this context since -- they are not really imported in the linker sense. if Is_Object (E) and then not Is_Library_Level_Entity (E) and then No (Address_Clause (E)) then Set_Is_Statically_Allocated (E); end if; end if; end Set_Imported; ------------------------- -- Set_Mechanism_Value -- ------------------------- -- Note: the mechanism name has not been analyzed (and cannot indeed -- be analyzed, since it is semantic nonsense), so we get it in the -- exact form created by the parser. procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is Class : Node_Id; Param : Node_Id; procedure Bad_Class; -- Signal bad descriptor class name procedure Bad_Mechanism; -- Signal bad mechanism name --------------- -- Bad_Class -- --------------- procedure Bad_Class is begin Error_Pragma_Arg ("unrecognized descriptor class name", Class); end Bad_Class; ------------------------- -- Bad_Mechanism_Value -- ------------------------- procedure Bad_Mechanism is begin Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name); end Bad_Mechanism; -- Start of processing for Set_Mechanism_Value begin if Mechanism (Ent) /= Default_Mechanism then Error_Msg_NE ("mechanism for & has already been set", Mech_Name, Ent); end if; -- MECHANISM_NAME ::= value | reference | descriptor if Nkind (Mech_Name) = N_Identifier then if Chars (Mech_Name) = Name_Value then Set_Mechanism (Ent, By_Copy); return; elsif Chars (Mech_Name) = Name_Reference then Set_Mechanism (Ent, By_Reference); return; elsif Chars (Mech_Name) = Name_Descriptor then Check_VMS (Mech_Name); Set_Mechanism (Ent, By_Descriptor); return; elsif Chars (Mech_Name) = Name_Copy then Error_Pragma_Arg ("bad mechanism name, Value assumed", Mech_Name); else Bad_Mechanism; end if; -- MECHANISM_NAME ::= descriptor (CLASS_NAME) -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca -- Note: this form is parsed as an indexed component elsif Nkind (Mech_Name) = N_Indexed_Component then Class := First (Expressions (Mech_Name)); if Nkind (Prefix (Mech_Name)) /= N_Identifier or else Chars (Prefix (Mech_Name)) /= Name_Descriptor or else Present (Next (Class)) then Bad_Mechanism; end if; -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca -- Note: this form is parsed as a function call elsif Nkind (Mech_Name) = N_Function_Call then Param := First (Parameter_Associations (Mech_Name)); if Nkind (Name (Mech_Name)) /= N_Identifier or else Chars (Name (Mech_Name)) /= Name_Descriptor or else Present (Next (Param)) or else No (Selector_Name (Param)) or else Chars (Selector_Name (Param)) /= Name_Class then Bad_Mechanism; else Class := Explicit_Actual_Parameter (Param); end if; else Bad_Mechanism; end if; -- Fall through here with Class set to descriptor class name Check_VMS (Mech_Name); if Nkind (Class) /= N_Identifier then Bad_Class; elsif Chars (Class) = Name_UBS then Set_Mechanism (Ent, By_Descriptor_UBS); elsif Chars (Class) = Name_UBSB then Set_Mechanism (Ent, By_Descriptor_UBSB); elsif Chars (Class) = Name_UBA then Set_Mechanism (Ent, By_Descriptor_UBA); elsif Chars (Class) = Name_S then Set_Mechanism (Ent, By_Descriptor_S); elsif Chars (Class) = Name_SB then Set_Mechanism (Ent, By_Descriptor_SB); elsif Chars (Class) = Name_A then Set_Mechanism (Ent, By_Descriptor_A); elsif Chars (Class) = Name_NCA then Set_Mechanism (Ent, By_Descriptor_NCA); else Bad_Class; end if; end Set_Mechanism_Value; --------------------------- -- Set_Ravenscar_Profile -- --------------------------- -- The tasks to be done here are -- Set required policies -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities) -- pragma Locking_Policy (Ceiling_Locking) -- Set Detect_Blocking mode -- Set required restrictions (see System.Rident for detailed list) procedure Set_Ravenscar_Profile (N : Node_Id) is begin -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities) if Task_Dispatching_Policy /= ' ' and then Task_Dispatching_Policy /= 'F' then Error_Msg_Sloc := Task_Dispatching_Policy_Sloc; Error_Pragma ("Profile (Ravenscar) incompatible with policy#"); -- Set the FIFO_Within_Priorities policy, but always preserve -- System_Location since we like the error message with the run time -- name. else Task_Dispatching_Policy := 'F'; if Task_Dispatching_Policy_Sloc /= System_Location then Task_Dispatching_Policy_Sloc := Loc; end if; end if; -- pragma Locking_Policy (Ceiling_Locking) if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then Error_Msg_Sloc := Locking_Policy_Sloc; Error_Pragma ("Profile (Ravenscar) incompatible with policy#"); -- Set the Ceiling_Locking policy, but preserve System_Location since -- we like the error message with the run time name. else Locking_Policy := 'C'; if Locking_Policy_Sloc /= System_Location then Locking_Policy_Sloc := Loc; end if; end if; -- pragma Detect_Blocking Detect_Blocking := True; -- Set the corresponding restrictions Set_Profile_Restrictions (Ravenscar, N, Warn => False); end Set_Ravenscar_Profile; -- Start of processing for Analyze_Pragma begin if not Is_Pragma_Name (Chars (N)) then if Warn_On_Unrecognized_Pragma then Error_Pragma ("unrecognized pragma%?"); else return; end if; else Prag_Id := Get_Pragma_Id (Chars (N)); end if; -- Preset arguments Arg1 := Empty; Arg2 := Empty; Arg3 := Empty; Arg4 := Empty; if Present (Pragma_Argument_Associations (N)) then Arg1 := First (Pragma_Argument_Associations (N)); if Present (Arg1) then Arg2 := Next (Arg1); if Present (Arg2) then Arg3 := Next (Arg2); if Present (Arg3) then Arg4 := Next (Arg3); end if; end if; end if; end if; -- Count number of arguments declare Arg_Node : Node_Id; begin Arg_Count := 0; Arg_Node := Arg1; while Present (Arg_Node) loop Arg_Count := Arg_Count + 1; Next (Arg_Node); end loop; end; -- An enumeration type defines the pragmas that are supported by the -- implementation. Get_Pragma_Id (in package Prag) transorms a name -- into the corresponding enumeration value for the following case. case Prag_Id is ----------------- -- Abort_Defer -- ----------------- -- pragma Abort_Defer; when Pragma_Abort_Defer => GNAT_Pragma; Check_Arg_Count (0); -- The only required semantic processing is to check the -- placement. This pragma must appear at the start of the -- statement sequence of a handled sequence of statements. if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements or else N /= First (Statements (Parent (N))) then Pragma_Misplaced; end if; ------------ -- Ada_83 -- ------------ -- pragma Ada_83; -- Note: this pragma also has some specific processing in Par.Prag -- because we want to set the Ada version mode during parsing. when Pragma_Ada_83 => GNAT_Pragma; Ada_Version := Ada_83; Ada_Version_Explicit := Ada_Version; Check_Arg_Count (0); ------------ -- Ada_95 -- ------------ -- pragma Ada_95; -- Note: this pragma also has some specific processing in Par.Prag -- because we want to set the Ada 83 version mode during parsing. when Pragma_Ada_95 => GNAT_Pragma; Ada_Version := Ada_95; Ada_Version_Explicit := Ada_Version; Check_Arg_Count (0); --------------------- -- Ada_05/Ada_2005 -- --------------------- -- pragma Ada_05; -- pragma Ada_05 (LOCAL_NAME); -- pragma Ada_2005; -- pragma Ada_2005 (LOCAL_NAME): -- Note: these pragma also have some specific processing in Par.Prag -- because we want to set the Ada 2005 version mode during parsing. when Pragma_Ada_05 | Pragma_Ada_2005 => declare E_Id : Node_Id; begin GNAT_Pragma; if Arg_Count = 1 then Check_Arg_Is_Local_Name (Arg1); E_Id := Expression (Arg1); if Etype (E_Id) = Any_Type then return; end if; Set_Is_Ada_2005 (Entity (E_Id)); else Check_Arg_Count (0); Ada_Version := Ada_05; Ada_Version_Explicit := Ada_05; end if; end; ---------------------- -- All_Calls_Remote -- ---------------------- -- pragma All_Calls_Remote [(library_package_NAME)]; when Pragma_All_Calls_Remote => All_Calls_Remote : declare Lib_Entity : Entity_Id; begin Check_Ada_83_Warning; Check_Valid_Library_Unit_Pragma; if Nkind (N) = N_Null_Statement then return; end if; Lib_Entity := Find_Lib_Unit_Name; -- This pragma should only apply to a RCI unit (RM E.2.3(23)) if Present (Lib_Entity) and then not Debug_Flag_U then if not Is_Remote_Call_Interface (Lib_Entity) then Error_Pragma ("pragma% only apply to rci unit"); -- Set flag for entity of the library unit else Set_Has_All_Calls_Remote (Lib_Entity); end if; end if; end All_Calls_Remote; -------------- -- Annotate -- -------------- -- pragma Annotate (IDENTIFIER {, ARG}); -- ARG ::= NAME | EXPRESSION when Pragma_Annotate => Annotate : begin GNAT_Pragma; Check_At_Least_N_Arguments (1); Check_Arg_Is_Identifier (Arg1); declare Arg : Node_Id := Arg2; Exp : Node_Id; begin while Present (Arg) loop Exp := Expression (Arg); Analyze (Exp); if Is_Entity_Name (Exp) then null; elsif Nkind (Exp) = N_String_Literal then Resolve (Exp, Standard_String); elsif Is_Overloaded (Exp) then Error_Pragma_Arg ("ambiguous argument for pragma%", Exp); else Resolve (Exp); end if; Next (Arg); end loop; end; end Annotate; ------------ -- Assert -- ------------ -- pragma Assert ([Check =>] Boolean_EXPRESSION -- [, [Message =>] Static_String_EXPRESSION]); when Pragma_Assert => Check_At_Least_N_Arguments (1); Check_At_Most_N_Arguments (2); Check_Arg_Order ((Name_Check, Name_Message)); Check_Optional_Identifier (Arg1, Name_Check); if Arg_Count > 1 then Check_Optional_Identifier (Arg2, Name_Message); Check_Arg_Is_Static_Expression (Arg2, Standard_String); end if; -- If expansion is active and assertions are inactive, then -- we rewrite the Assertion as: -- if False and then condition then -- null; -- end if; -- The reason we do this rewriting during semantic analysis -- rather than as part of normal expansion is that we cannot -- analyze and expand the code for the boolean expression -- directly, or it may cause insertion of actions that would -- escape the attempt to suppress the assertion code. if Expander_Active and not Assertions_Enabled then Rewrite (N, Make_If_Statement (Loc, Condition => Make_And_Then (Loc, Left_Opnd => New_Occurrence_Of (Standard_False, Loc), Right_Opnd => Get_Pragma_Arg (Arg1)), Then_Statements => New_List ( Make_Null_Statement (Loc)))); Analyze (N); -- Otherwise (if assertions are enabled, or if we are not -- operating with expansion active), then we just analyze -- and resolve the expression. else Analyze_And_Resolve (Expression (Arg1), Any_Boolean); end if; ---------------------- -- Assertion_Policy -- ---------------------- -- pragma Assertion_Policy (Check | Ignore) when Pragma_Assertion_Policy => Check_Arg_Count (1); Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore); Assertions_Enabled := Chars (Expression (Arg1)) = Name_Check; --------------- -- AST_Entry -- --------------- -- pragma AST_Entry (entry_IDENTIFIER); when Pragma_AST_Entry => AST_Entry : declare Ent : Node_Id; begin GNAT_Pragma; Check_VMS (N); Check_Arg_Count (1); Check_No_Identifiers; Check_Arg_Is_Local_Name (Arg1); Ent := Entity (Expression (Arg1)); -- Note: the implementation of the AST_Entry pragma could handle -- the entry family case fine, but for now we are consistent with -- the DEC rules, and do not allow the pragma, which of course -- has the effect of also forbidding the attribute. if Ekind (Ent) /= E_Entry then Error_Pragma_Arg ("pragma% argument must be simple entry name", Arg1); elsif Is_AST_Entry (Ent) then Error_Pragma_Arg ("duplicate % pragma for entry", Arg1); elsif Has_Homonym (Ent) then Error_Pragma_Arg ("pragma% argument cannot specify overloaded entry", Arg1); else declare FF : constant Entity_Id := First_Formal (Ent); begin if Present (FF) then if Present (Next_Formal (FF)) then Error_Pragma_Arg ("entry for pragma% can have only one argument", Arg1); elsif Parameter_Mode (FF) /= E_In_Parameter then Error_Pragma_Arg ("entry parameter for pragma% must have mode IN", Arg1); end if; end if; end; Set_Is_AST_Entry (Ent); end if; end AST_Entry; ------------------ -- Asynchronous -- ------------------ -- pragma Asynchronous (LOCAL_NAME); when Pragma_Asynchronous => Asynchronous : declare Nm : Entity_Id; C_Ent : Entity_Id; L : List_Id; S : Node_Id; N : Node_Id; Formal : Entity_Id; procedure Process_Async_Pragma; -- Common processing for procedure and access-to-procedure case -------------------------- -- Process_Async_Pragma -- -------------------------- procedure Process_Async_Pragma is begin if No (L) then Set_Is_Asynchronous (Nm); return; end if; -- The formals should be of mode IN (RM E.4.1(6)) S := First (L); while Present (S) loop Formal := Defining_Identifier (S); if Nkind (Formal) = N_Defining_Identifier and then Ekind (Formal) /= E_In_Parameter then Error_Pragma_Arg ("pragma% procedure can only have IN parameter", Arg1); end if; Next (S); end loop; Set_Is_Asynchronous (Nm); end Process_Async_Pragma; -- Start of processing for pragma Asynchronous begin Check_Ada_83_Warning; Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_Local_Name (Arg1); if Debug_Flag_U then return; end if; C_Ent := Cunit_Entity (Current_Sem_Unit); Analyze (Expression (Arg1)); Nm := Entity (Expression (Arg1)); if not Is_Remote_Call_Interface (C_Ent) and then not Is_Remote_Types (C_Ent) then -- This pragma should only appear in an RCI or Remote Types -- unit (RM E.4.1(4)) Error_Pragma ("pragma% not in Remote_Call_Interface or " & "Remote_Types unit"); end if; if Ekind (Nm) = E_Procedure and then Nkind (Parent (Nm)) = N_Procedure_Specification then if not Is_Remote_Call_Interface (Nm) then Error_Pragma_Arg ("pragma% cannot be applied on non-remote procedure", Arg1); end if; L := Parameter_Specifications (Parent (Nm)); Process_Async_Pragma; return; elsif Ekind (Nm) = E_Function then Error_Pragma_Arg ("pragma% cannot be applied to function", Arg1); elsif Is_Remote_Access_To_Subprogram_Type (Nm) then if Is_Record_Type (Nm) then -- A record type that is the Equivalent_Type for -- a remote access-to-subprogram type. N := Declaration_Node (Corresponding_Remote_Type (Nm)); else -- A non-expanded RAS type (case where distribution is -- not enabled). N := Declaration_Node (Nm); end if; if Nkind (N) = N_Full_Type_Declaration and then Nkind (Type_Definition (N)) = N_Access_Procedure_Definition then L := Parameter_Specifications (Type_Definition (N)); Process_Async_Pragma; if Is_Asynchronous (Nm) and then Expander_Active and then Get_PCS_Name /= Name_No_DSA then RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm)); end if; else Error_Pragma_Arg ("pragma% cannot reference access-to-function type", Arg1); end if; -- Only other possibility is Access-to-class-wide type elsif Is_Access_Type (Nm) and then Is_Class_Wide_Type (Designated_Type (Nm)) then Check_First_Subtype (Arg1); Set_Is_Asynchronous (Nm); if Expander_Active then RACW_Type_Is_Asynchronous (Nm); end if; else Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1); end if; end Asynchronous; ------------ -- Atomic -- ------------ -- pragma Atomic (LOCAL_NAME); when Pragma_Atomic => Process_Atomic_Shared_Volatile; ----------------------- -- Atomic_Components -- ----------------------- -- pragma Atomic_Components (array_LOCAL_NAME); -- This processing is shared by Volatile_Components when Pragma_Atomic_Components | Pragma_Volatile_Components => Atomic_Components : declare E_Id : Node_Id; E : Entity_Id; D : Node_Id; K : Node_Kind; begin Check_Ada_83_Warning; Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_Local_Name (Arg1); E_Id := Expression (Arg1); if Etype (E_Id) = Any_Type then return; end if; E := Entity (E_Id); if Rep_Item_Too_Early (E, N) or else Rep_Item_Too_Late (E, N) then return; end if; D := Declaration_Node (E); K := Nkind (D); if (K = N_Full_Type_Declaration and then Is_Array_Type (E)) or else ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable) and then Nkind (D) = N_Object_Declaration and then Nkind (Object_Definition (D)) = N_Constrained_Array_Definition) then -- The flag is set on the object, or on the base type if Nkind (D) /= N_Object_Declaration then E := Base_Type (E); end if; Set_Has_Volatile_Components (E); if Prag_Id = Pragma_Atomic_Components then Set_Has_Atomic_Components (E); if Is_Packed (E) then Set_Is_Packed (E, False); Error_Pragma_Arg ("?Pack canceled, cannot pack atomic components", Arg1); end if; end if; else Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1); end if; end Atomic_Components; -------------------- -- Attach_Handler -- -------------------- -- pragma Attach_Handler (handler_NAME, EXPRESSION); when Pragma_Attach_Handler => Check_Ada_83_Warning; Check_No_Identifiers; Check_Arg_Count (2); if No_Run_Time_Mode then Error_Msg_CRT ("Attach_Handler pragma", N); else Check_Interrupt_Or_Attach_Handler; -- The expression that designates the attribute may -- depend on a discriminant, and is therefore a per- -- object expression, to be expanded in the init proc. -- If expansion is enabled, perform semantic checks -- on a copy only. if Expander_Active then declare Temp : constant Node_Id := New_Copy_Tree (Expression (Arg2)); begin Set_Parent (Temp, N); Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID)); end; else Analyze (Expression (Arg2)); Resolve (Expression (Arg2), RTE (RE_Interrupt_ID)); end if; Process_Interrupt_Or_Attach_Handler; end if; -------------------- -- C_Pass_By_Copy -- -------------------- -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION); when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare Arg : Node_Id; Val : Uint; begin GNAT_Pragma; Check_Valid_Configuration_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, "max_size"); Arg := Expression (Arg1); Check_Arg_Is_Static_Expression (Arg, Any_Integer); Val := Expr_Value (Arg); if Val <= 0 then Error_Pragma_Arg ("maximum size for pragma% must be positive", Arg1); elsif UI_Is_In_Int_Range (Val) then Default_C_Record_Mechanism := UI_To_Int (Val); -- If a giant value is given, Int'Last will do well enough. -- If sometime someone complains that a record larger than -- two gigabytes is not copied, we will worry about it then! else Default_C_Record_Mechanism := Mechanism_Type'Last; end if; end C_Pass_By_Copy; ------------- -- Comment -- ------------- -- pragma Comment (static_string_EXPRESSION) -- Processing for pragma Comment shares the circuitry for -- pragma Ident. The only differences are that Ident enforces -- a limit of 31 characters on its argument, and also enforces -- limitations on placement for DEC compatibility. Pragma -- Comment shares neither of these restrictions. ------------------- -- Common_Object -- ------------------- -- pragma Common_Object ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL] -- [, [Size =>] EXTERNAL_SYMBOL]); -- Processing for this pragma is shared with Psect_Object -------------------------- -- Compile_Time_Warning -- -------------------------- -- pragma Compile_Time_Warning -- (boolean_EXPRESSION, static_string_EXPRESSION); when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1); begin GNAT_Pragma; Check_Arg_Count (2); Check_No_Identifiers; Check_Arg_Is_Static_Expression (Arg2, Standard_String); Analyze_And_Resolve (Arg1x, Standard_Boolean); if Compile_Time_Known_Value (Arg1x) then if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2))); Add_Char_To_Name_Buffer ('?'); declare Msg : String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); B : Natural; begin -- This loop looks for multiple lines separated by -- ASCII.LF and breaks them into continuation error -- messages marked with the usual back slash. B := 1; for S in 2 .. Msg'Length - 1 loop if Msg (S) = ASCII.LF then Msg (S) := '?'; Error_Msg_N (Msg (B .. S), Arg1); B := S; Msg (B) := '\'; end if; end loop; Error_Msg_N (Msg (B .. Msg'Length), Arg1); end; end if; end if; end Compile_Time_Warning; ----------------------------- -- Complete_Representation -- ----------------------------- -- pragma Complete_Representation; when Pragma_Complete_Representation => GNAT_Pragma; Check_Arg_Count (0); if Nkind (Parent (N)) /= N_Record_Representation_Clause then Error_Pragma ("pragma & must appear within record representation clause"); end if; ---------------------------- -- Complex_Representation -- ---------------------------- -- pragma Complex_Representation ([Entity =>] LOCAL_NAME); when Pragma_Complex_Representation => Complex_Representation : declare E_Id : Entity_Id; E : Entity_Id; Ent : Entity_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Local_Name (Arg1); E_Id := Expression (Arg1); if Etype (E_Id) = Any_Type then return; end if; E := Entity (E_Id); if not Is_Record_Type (E) then Error_Pragma_Arg ("argument for pragma% must be record type", Arg1); end if; Ent := First_Entity (E); if No (Ent) or else No (Next_Entity (Ent)) or else Present (Next_Entity (Next_Entity (Ent))) or else not Is_Floating_Point_Type (Etype (Ent)) or else Etype (Ent) /= Etype (Next_Entity (Ent)) then Error_Pragma_Arg ("record for pragma% must have two fields of same fpt type", Arg1); else Set_Has_Complex_Representation (Base_Type (E)); end if; end Complex_Representation; ------------------------- -- Component_Alignment -- ------------------------- -- pragma Component_Alignment ( -- [Form =>] ALIGNMENT_CHOICE -- [, [Name =>] type_LOCAL_NAME]); -- -- ALIGNMENT_CHOICE ::= -- Component_Size -- | Component_Size_4 -- | Storage_Unit -- | Default when Pragma_Component_Alignment => Component_AlignmentP : declare Args : Args_List (1 .. 2); Names : constant Name_List (1 .. 2) := ( Name_Form, Name_Name); Form : Node_Id renames Args (1); Name : Node_Id renames Args (2); Atype : Component_Alignment_Kind; Typ : Entity_Id; begin GNAT_Pragma; Gather_Associations (Names, Args); if No (Form) then Error_Pragma ("missing Form argument for pragma%"); end if; Check_Arg_Is_Identifier (Form); -- Get proper alignment, note that Default = Component_Size -- on all machines we have so far, and we want to set this -- value rather than the default value to indicate that it -- has been explicitly set (and thus will not get overridden -- by the default component alignment for the current scope) if Chars (Form) = Name_Component_Size then Atype := Calign_Component_Size; elsif Chars (Form) = Name_Component_Size_4 then Atype := Calign_Component_Size_4; elsif Chars (Form) = Name_Default then Atype := Calign_Component_Size; elsif Chars (Form) = Name_Storage_Unit then Atype := Calign_Storage_Unit; else Error_Pragma_Arg ("invalid Form parameter for pragma%", Form); end if; -- Case with no name, supplied, affects scope table entry if No (Name) then Scope_Stack.Table (Scope_Stack.Last).Component_Alignment_Default := Atype; -- Case of name supplied else Check_Arg_Is_Local_Name (Name); Find_Type (Name); Typ := Entity (Name); if Typ = Any_Type or else Rep_Item_Too_Early (Typ, N) then return; else Typ := Underlying_Type (Typ); end if; if not Is_Record_Type (Typ) and then not Is_Array_Type (Typ) then Error_Pragma_Arg ("Name parameter of pragma% must identify record or " & "array type", Name); end if; -- An explicit Component_Alignment pragma overrides an -- implicit pragma Pack, but not an explicit one. if not Has_Pragma_Pack (Base_Type (Typ)) then Set_Is_Packed (Base_Type (Typ), False); Set_Component_Alignment (Base_Type (Typ), Atype); end if; end if; end Component_AlignmentP; ---------------- -- Controlled -- ---------------- -- pragma Controlled (first_subtype_LOCAL_NAME); when Pragma_Controlled => Controlled : declare Arg : Node_Id; begin Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_Local_Name (Arg1); Arg := Expression (Arg1); if not Is_Entity_Name (Arg) or else not Is_Access_Type (Entity (Arg)) then Error_Pragma_Arg ("pragma% requires access type", Arg1); else Set_Has_Pragma_Controlled (Base_Type (Entity (Arg))); end if; end Controlled; ---------------- -- Convention -- ---------------- -- pragma Convention ([Convention =>] convention_IDENTIFIER, -- [Entity =>] LOCAL_NAME); when Pragma_Convention => Convention : declare C : Convention_Id; E : Entity_Id; begin Check_Arg_Order ((Name_Convention, Name_Entity)); Check_Ada_83_Warning; Check_Arg_Count (2); Process_Convention (C, E); end Convention; --------------------------- -- Convention_Identifier -- --------------------------- -- pragma Convention_Identifier ([Name =>] IDENTIFIER, -- [Convention =>] convention_IDENTIFIER); when Pragma_Convention_Identifier => Convention_Identifier : declare Idnam : Name_Id; Cname : Name_Id; begin GNAT_Pragma; Check_Arg_Order ((Name_Name, Name_Convention)); Check_Arg_Count (2); Check_Optional_Identifier (Arg1, Name_Name); Check_Optional_Identifier (Arg2, Name_Convention); Check_Arg_Is_Identifier (Arg1); Check_Arg_Is_Identifier (Arg1); Idnam := Chars (Expression (Arg1)); Cname := Chars (Expression (Arg2)); if Is_Convention_Name (Cname) then Record_Convention_Identifier (Idnam, Get_Convention_Id (Cname)); else Error_Pragma_Arg ("second arg for % pragma must be convention", Arg2); end if; end Convention_Identifier; --------------- -- CPP_Class -- --------------- -- pragma CPP_Class ([Entity =>] local_NAME) when Pragma_CPP_Class => CPP_Class : declare Arg : Node_Id; Typ : Entity_Id; Default_DTC : Entity_Id := Empty; VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr); C : Entity_Id; Tag_C : Entity_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Local_Name (Arg1); Arg := Expression (Arg1); Analyze (Arg); if Etype (Arg) = Any_Type then return; end if; if not Is_Entity_Name (Arg) or else not Is_Type (Entity (Arg)) then Error_Pragma_Arg ("pragma% requires a type mark", Arg1); end if; Typ := Entity (Arg); if not Is_Record_Type (Typ) then Error_Pragma_Arg ("pragma% applicable to a record, " & "tagged record or record extension", Arg1); end if; Default_DTC := First_Component (Typ); while Present (Default_DTC) and then Etype (Default_DTC) /= VTP_Type loop Next_Component (Default_DTC); end loop; -- Case of non tagged type if not Is_Tagged_Type (Typ) then Set_Is_CPP_Class (Typ); if Present (Default_DTC) then Error_Pragma_Arg ("only tagged records can contain vtable pointers", Arg1); end if; -- Case of tagged type with no user-defined vtable ptr. In this -- case, because of our C++ ABI compatibility, the programmer -- does not need to specify the tag component. elsif Is_Tagged_Type (Typ) and then No (Default_DTC) then Set_Is_CPP_Class (Typ); Set_Is_Limited_Record (Typ); -- Tagged type that has a vtable ptr elsif Present (Default_DTC) then Set_Is_CPP_Class (Typ); Set_Is_Limited_Record (Typ); Set_Is_Tag (Default_DTC); Set_DT_Entry_Count (Default_DTC, No_Uint); -- Since a CPP type has no direct link to its associated tag -- most tags checks cannot be performed Set_Kill_Tag_Checks (Typ); Set_Kill_Tag_Checks (Class_Wide_Type (Typ)); -- Get rid of the _tag component when there was one. -- It is only useful for regular tagged types if Expander_Active and then Typ = Root_Type (Typ) then Tag_C := First_Tag_Component (Typ); C := First_Entity (Typ); if C = Tag_C then Set_First_Entity (Typ, Next_Entity (Tag_C)); else while Next_Entity (C) /= Tag_C loop Next_Entity (C); end loop; Set_Next_Entity (C, Next_Entity (Tag_C)); end if; end if; end if; end CPP_Class; --------------------- -- CPP_Constructor -- --------------------- -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME); when Pragma_CPP_Constructor => CPP_Constructor : declare Id : Entity_Id; Def_Id : Entity_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Local_Name (Arg1); Id := Expression (Arg1); Find_Program_Unit_Name (Id); -- If we did not find the name, we are done if Etype (Id) = Any_Type then return; end if; Def_Id := Entity (Id); if Ekind (Def_Id) = E_Function and then Is_Class_Wide_Type (Etype (Def_Id)) and then Is_CPP_Class (Etype (Etype (Def_Id))) then -- What the heck is this??? this pragma allows only 1 arg if Arg_Count >= 2 then Check_At_Most_N_Arguments (3); Process_Interface_Name (Def_Id, Arg2, Arg3); end if; if No (Parameter_Specifications (Parent (Def_Id))) then Set_Has_Completion (Def_Id); Set_Is_Constructor (Def_Id); else Error_Pragma_Arg ("non-default constructors not implemented", Arg1); end if; else Error_Pragma_Arg ("pragma% requires function returning a 'C'P'P_Class type", Arg1); end if; end CPP_Constructor; ----------------- -- CPP_Virtual -- ----------------- -- pragma CPP_Virtual -- [Entity =>] LOCAL_NAME -- [ [Vtable_Ptr =>] LOCAL_NAME, -- [Position =>] static_integer_EXPRESSION]); when Pragma_CPP_Virtual => CPP_Virtual : declare Arg : Node_Id; Typ : Entity_Id; Subp : Entity_Id; VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr); DTC : Entity_Id; V : Uint; begin GNAT_Pragma; Check_Arg_Order ((Name_Entity, Name_Vtable_Ptr, Name_Position)); if Arg_Count = 3 then Check_Optional_Identifier (Arg2, Name_Vtable_Ptr); -- We allow Entry_Count as well as Position for the third -- parameter for back compatibility with versions of GNAT -- before version 3.12. The documentation has always said -- Position, but the code up to 3.12 said Entry_Count. if Chars (Arg3) /= Name_Entry_Count then Check_Optional_Identifier (Arg3, Name_Position); end if; else Check_Arg_Count (1); end if; Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Local_Name (Arg1); -- First argument must be a subprogram name Arg := Expression (Arg1); Find_Program_Unit_Name (Arg); if Etype (Arg) = Any_Type then return; else Subp := Entity (Arg); end if; if not (Is_Subprogram (Subp) and then Is_Dispatching_Operation (Subp)) then Error_Pragma_Arg ("pragma% must reference a primitive operation", Arg1); end if; Typ := Find_Dispatching_Type (Subp); -- If only one Argument defaults are : -- . DTC_Entity is the default Vtable pointer -- . DT_Position will be set at the freezing point if Arg_Count = 1 then Set_DTC_Entity (Subp, First_Tag_Component (Typ)); return; end if; -- Second argument is a component name of type Vtable_Ptr Arg := Expression (Arg2); if Nkind (Arg) /= N_Identifier then Error_Msg_NE ("must be a& component name", Arg, Typ); raise Pragma_Exit; end if; DTC := First_Component (Typ); while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop Next_Component (DTC); end loop; -- Case of tagged type with no user-defined vtable ptr if No (DTC) then Error_Msg_NE ("must be a& component name", Arg, Typ); raise Pragma_Exit; elsif Etype (DTC) /= VTP_Type then Wrong_Type (Arg, VTP_Type); return; end if; -- Third argument is an integer (DT_Position) Arg := Expression (Arg3); Analyze_And_Resolve (Arg, Any_Integer); if not Is_Static_Expression (Arg) then Flag_Non_Static_Expr ("third argument of pragma CPP_Virtual must be static!", Arg3); raise Pragma_Exit; else V := Expr_Value (Expression (Arg3)); if V <= 0 then Error_Pragma_Arg ("third argument of pragma% must be positive", Arg3); else Set_DTC_Entity (Subp, DTC); Set_DT_Position (Subp, V); end if; end if; end CPP_Virtual; ---------------- -- CPP_Vtable -- ---------------- -- pragma CPP_Vtable ( -- [Entity =>] LOCAL_NAME -- [Vtable_Ptr =>] LOCAL_NAME, -- [Entry_Count =>] static_integer_EXPRESSION); when Pragma_CPP_Vtable => CPP_Vtable : declare Arg : Node_Id; Typ : Entity_Id; VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr); DTC : Entity_Id; V : Uint; Elmt : Elmt_Id; begin GNAT_Pragma; Check_Arg_Order ((Name_Entity, Name_Vtable_Ptr, Name_Entry_Count)); Check_Arg_Count (3); Check_Optional_Identifier (Arg1, Name_Entity); Check_Optional_Identifier (Arg2, Name_Vtable_Ptr); Check_Optional_Identifier (Arg3, Name_Entry_Count); Check_Arg_Is_Local_Name (Arg1); -- First argument is a record type name Arg := Expression (Arg1); Analyze (Arg); if Etype (Arg) = Any_Type then return; else Typ := Entity (Arg); end if; if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1); end if; -- Second argument is a component name of type Vtable_Ptr Arg := Expression (Arg2); if Nkind (Arg) /= N_Identifier then Error_Msg_NE ("must be a& component name", Arg, Typ); raise Pragma_Exit; end if; DTC := First_Component (Typ); while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop Next_Component (DTC); end loop; if No (DTC) then Error_Msg_NE ("must be a& component name", Arg, Typ); raise Pragma_Exit; elsif Etype (DTC) /= VTP_Type then Wrong_Type (DTC, VTP_Type); return; -- If it is the first pragma Vtable, This becomes the default tag elsif (not Is_Tag (DTC)) and then DT_Entry_Count (First_Tag_Component (Typ)) = No_Uint then Set_Is_Tag (First_Tag_Component (Typ), False); Set_Is_Tag (DTC, True); Set_DT_Entry_Count (DTC, No_Uint); end if; -- Those pragmas must appear before any primitive operation -- definition (except inherited ones) otherwise the default -- may be wrong Elmt := First_Elmt (Primitive_Operations (Typ)); while Present (Elmt) loop if No (Alias (Node (Elmt))) then Error_Msg_Sloc := Sloc (Node (Elmt)); Error_Pragma ("pragma% must appear before this primitive operation"); end if; Next_Elmt (Elmt); end loop; -- Third argument is an integer (DT_Entry_Count) Arg := Expression (Arg3); Analyze_And_Resolve (Arg, Any_Integer); if not Is_Static_Expression (Arg) then Flag_Non_Static_Expr ("entry count for pragma CPP_Vtable must be a static " & "expression!", Arg3); raise Pragma_Exit; else V := Expr_Value (Expression (Arg3)); if V <= 0 then Error_Pragma_Arg ("entry count for pragma% must be positive", Arg3); else Set_DT_Entry_Count (DTC, V); end if; end if; end CPP_Vtable; ----------- -- Debug -- ----------- -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT); when Pragma_Debug => Debug : declare Cond : Node_Id; begin GNAT_Pragma; Cond := New_Occurrence_Of (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active), Loc); if Arg_Count = 2 then Cond := Make_And_Then (Loc, Left_Opnd => Relocate_Node (Cond), Right_Opnd => Expression (Arg1)); end if; -- Rewrite into a conditional with an appropriate condition. We -- wrap the procedure call in a block so that overhead from e.g. -- use of the secondary stack does not generate execution overhead -- for suppressed conditions. Rewrite (N, Make_Implicit_If_Statement (N, Condition => Cond, Then_Statements => New_List ( Make_Block_Statement (Loc, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( Relocate_Node (Debug_Statement (N)))))))); Analyze (N); end Debug; ------------------ -- Debug_Policy -- ------------------ -- pragma Debug_Policy (Check | Ignore) when Pragma_Debug_Policy => GNAT_Pragma; Check_Arg_Count (1); Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore); Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check; --------------------- -- Detect_Blocking -- --------------------- -- pragma Detect_Blocking; when Pragma_Detect_Blocking => GNAT_Pragma; Check_Arg_Count (0); Check_Valid_Configuration_Pragma; Detect_Blocking := True; ------------------- -- Discard_Names -- ------------------- -- pragma Discard_Names [([On =>] LOCAL_NAME)]; when Pragma_Discard_Names => Discard_Names : declare E_Id : Entity_Id; E : Entity_Id; begin Check_Ada_83_Warning; -- Deal with configuration pragma case if Arg_Count = 0 and then Is_Configuration_Pragma then Global_Discard_Names := True; return; -- Otherwise, check correct appropriate context else Check_Is_In_Decl_Part_Or_Package_Spec; if Arg_Count = 0 then -- If there is no parameter, then from now on this pragma -- applies to any enumeration, exception or tagged type -- defined in the current declarative part. Set_Discard_Names (Current_Scope); return; else Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_On); Check_Arg_Is_Local_Name (Arg1); E_Id := Expression (Arg1); if Etype (E_Id) = Any_Type then return; else E := Entity (E_Id); end if; if (Is_First_Subtype (E) and then (Is_Enumeration_Type (E) or else Is_Tagged_Type (E))) or else Ekind (E) = E_Exception then Set_Discard_Names (E); else Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1); end if; end if; end if; end Discard_Names; --------------- -- Elaborate -- --------------- -- pragma Elaborate (library_unit_NAME {, library_unit_NAME}); when Pragma_Elaborate => Elaborate : declare Plist : List_Id; Parent_Node : Node_Id; Arg : Node_Id; Citem : Node_Id; begin -- Pragma must be in context items list of a compilation unit if not Is_List_Member (N) then Pragma_Misplaced; return; else Plist := List_Containing (N); Parent_Node := Parent (Plist); if Parent_Node = Empty or else Nkind (Parent_Node) /= N_Compilation_Unit or else Context_Items (Parent_Node) /= Plist then Pragma_Misplaced; return; end if; end if; -- Must be at least one argument if Arg_Count = 0 then Error_Pragma ("pragma% requires at least one argument"); end if; -- In Ada 83 mode, there can be no items following it in the -- context list except other pragmas and implicit with clauses -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this -- placement rule does not apply. if Ada_Version = Ada_83 and then Comes_From_Source (N) then Citem := Next (N); while Present (Citem) loop if Nkind (Citem) = N_Pragma or else (Nkind (Citem) = N_With_Clause and then Implicit_With (Citem)) then null; else Error_Pragma ("(Ada 83) pragma% must be at end of context clause"); end if; Next (Citem); end loop; end if; -- Finally, the arguments must all be units mentioned in a with -- clause in the same context clause. Note we already checked -- (in Par.Prag) that the arguments are either identifiers or Arg := Arg1; Outer : while Present (Arg) loop Citem := First (Plist); Inner : while Citem /= N loop if Nkind (Citem) = N_With_Clause and then Same_Name (Name (Citem), Expression (Arg)) then Set_Elaborate_Present (Citem, True); Set_Unit_Name (Expression (Arg), Name (Citem)); -- With the pragma present, elaboration calls on -- subprograms from the named unit need no further -- checks, as long as the pragma appears in the current -- compilation unit. If the pragma appears in some unit -- in the context, there might still be a need for an -- Elaborate_All_Desirable from the current compilation -- to the the named unit, so we keep the check enabled. if In_Extended_Main_Source_Unit (N) then Set_Suppress_Elaboration_Warnings (Entity (Name (Citem))); end if; exit Inner; end if; Next (Citem); end loop Inner; if Citem = N then Error_Pragma_Arg ("argument of pragma% is not with'ed unit", Arg); end if; Next (Arg); end loop Outer; -- Give a warning if operating in static mode with -gnatwl -- (elaboration warnings eanbled) switch set. if Elab_Warnings and not Dynamic_Elaboration_Checks then Error_Msg_N ("?use of pragma Elaborate may not be safe", N); Error_Msg_N ("?use pragma Elaborate_All instead if possible", N); end if; end Elaborate; ------------------- -- Elaborate_All -- ------------------- -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME}); when Pragma_Elaborate_All => Elaborate_All : declare Plist : List_Id; Parent_Node : Node_Id; Arg : Node_Id; Citem : Node_Id; begin Check_Ada_83_Warning; -- Pragma must be in context items list of a compilation unit if not Is_List_Member (N) then Pragma_Misplaced; return; else Plist := List_Containing (N); Parent_Node := Parent (Plist); if Parent_Node = Empty or else Nkind (Parent_Node) /= N_Compilation_Unit or else Context_Items (Parent_Node) /= Plist then Pragma_Misplaced; return; end if; end if; -- Must be at least one argument if Arg_Count = 0 then Error_Pragma ("pragma% requires at least one argument"); end if; -- Note: unlike pragma Elaborate, pragma Elaborate_All does not -- have to appear at the end of the context clause, but may -- appear mixed in with other items, even in Ada 83 mode. -- Final check: the arguments must all be units mentioned in -- a with clause in the same context clause. Note that we -- already checked (in Par.Prag) that all the arguments are -- either identifiers or selected components. Arg := Arg1; Outr : while Present (Arg) loop Citem := First (Plist); Innr : while Citem /= N loop if Nkind (Citem) = N_With_Clause and then Same_Name (Name (Citem), Expression (Arg)) then Set_Elaborate_All_Present (Citem, True); Set_Unit_Name (Expression (Arg), Name (Citem)); -- Suppress warnings and elaboration checks on the named -- unit if the pragma is in the current compilation, as -- for pragma Elaborate. if In_Extended_Main_Source_Unit (N) then Set_Suppress_Elaboration_Warnings (Entity (Name (Citem))); end if; exit Innr; end if; Next (Citem); end loop Innr; if Citem = N then Set_Error_Posted (N); Error_Pragma_Arg ("argument of pragma% is not with'ed unit", Arg); end if; Next (Arg); end loop Outr; end Elaborate_All; -------------------- -- Elaborate_Body -- -------------------- -- pragma Elaborate_Body [( library_unit_NAME )]; when Pragma_Elaborate_Body => Elaborate_Body : declare Cunit_Node : Node_Id; Cunit_Ent : Entity_Id; begin Check_Ada_83_Warning; Check_Valid_Library_Unit_Pragma; if Nkind (N) = N_Null_Statement then return; end if; Cunit_Node := Cunit (Current_Sem_Unit); Cunit_Ent := Cunit_Entity (Current_Sem_Unit); if Nkind (Unit (Cunit_Node)) = N_Package_Body or else Nkind (Unit (Cunit_Node)) = N_Subprogram_Body then Error_Pragma ("pragma% must refer to a spec, not a body"); else Set_Body_Required (Cunit_Node, True); Set_Has_Pragma_Elaborate_Body (Cunit_Ent); -- If we are in dynamic elaboration mode, then we suppress -- elaboration warnings for the unit, since it is definitely -- fine NOT to do dynamic checks at the first level (and such -- checks will be suppressed because no elaboration boolean -- is created for Elaborate_Body packages). -- But in the static model of elaboration, Elaborate_Body is -- definitely NOT good enough to ensure elaboration safety on -- its own, since the body may WITH other units that are not -- safe from an elaboration point of view, so a client must -- still do an Elaborate_All on such units. -- Debug flag -gnatdD restores the old behavior of 3.13, -- where Elaborate_Body always suppressed elab warnings. if Dynamic_Elaboration_Checks or Debug_Flag_DD then Set_Suppress_Elaboration_Warnings (Cunit_Ent); end if; end if; end Elaborate_Body; ------------------------ -- Elaboration_Checks -- ------------------------ -- pragma Elaboration_Checks (Static | Dynamic); when Pragma_Elaboration_Checks => GNAT_Pragma; Check_Arg_Count (1); Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic); Dynamic_Elaboration_Checks := (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic); --------------- -- Eliminate -- --------------- -- pragma Eliminate ( -- [Unit_Name =>] IDENTIFIER | -- SELECTED_COMPONENT -- [,[Entity =>] IDENTIFIER | -- SELECTED_COMPONENT | -- STRING_LITERAL] -- [,]OVERLOADING_RESOLUTION); -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE | -- SOURCE_LOCATION -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE | -- FUNCTION_PROFILE -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,] -- Result_Type => result_SUBTYPE_NAME] -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME}) -- SUBTYPE_NAME ::= STRING_LITERAL -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE -- SOURCE_TRACE ::= STRING_LITERAL when Pragma_Eliminate => Eliminate : declare Args : Args_List (1 .. 5); Names : constant Name_List (1 .. 5) := ( Name_Unit_Name, Name_Entity, Name_Parameter_Types, Name_Result_Type, Name_Source_Location); Unit_Name : Node_Id renames Args (1); Entity : Node_Id renames Args (2); Parameter_Types : Node_Id renames Args (3); Result_Type : Node_Id renames Args (4); Source_Location : Node_Id renames Args (5); begin GNAT_Pragma; Check_Valid_Configuration_Pragma; Gather_Associations (Names, Args); if No (Unit_Name) then Error_Pragma ("missing Unit_Name argument for pragma%"); end if; if No (Entity) and then (Present (Parameter_Types) or else Present (Result_Type) or else Present (Source_Location)) then Error_Pragma ("missing Entity argument for pragma%"); end if; if (Present (Parameter_Types) or else Present (Result_Type)) and then Present (Source_Location) then Error_Pragma ("parameter profile and source location cannot " & "be used together in pragma%"); end if; Process_Eliminate_Pragma (N, Unit_Name, Entity, Parameter_Types, Result_Type, Source_Location); end Eliminate; ------------------------- -- Explicit_Overriding -- ------------------------- when Pragma_Explicit_Overriding => Check_Valid_Configuration_Pragma; Check_Arg_Count (0); Explicit_Overriding := True; ------------ -- Export -- ------------ -- pragma Export ( -- [ Convention =>] convention_IDENTIFIER, -- [ Entity =>] local_NAME -- [, [External_Name =>] static_string_EXPRESSION ] -- [, [Link_Name =>] static_string_EXPRESSION ]); when Pragma_Export => Export : declare C : Convention_Id; Def_Id : Entity_Id; begin Check_Ada_83_Warning; Check_Arg_Order ((Name_Convention, Name_Entity, Name_External_Name, Name_Link_Name)); Check_At_Least_N_Arguments (2); Check_At_Most_N_Arguments (4); Process_Convention (C, Def_Id); if Ekind (Def_Id) /= E_Constant then Note_Possible_Modification (Expression (Arg2)); end if; Process_Interface_Name (Def_Id, Arg3, Arg4); Set_Exported (Def_Id, Arg2); end Export; ---------------------- -- Export_Exception -- ---------------------- -- pragma Export_Exception ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL,] -- [, [Form =>] Ada | VMS] -- [, [Code =>] static_integer_EXPRESSION]); when Pragma_Export_Exception => Export_Exception : declare Args : Args_List (1 .. 4); Names : constant Name_List (1 .. 4) := ( Name_Internal, Name_External, Name_Form, Name_Code); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Form : Node_Id renames Args (3); Code : Node_Id renames Args (4); begin if Inside_A_Generic then Error_Pragma ("pragma% cannot be used for generic entities"); end if; Gather_Associations (Names, Args); Process_Extended_Import_Export_Exception_Pragma ( Arg_Internal => Internal, Arg_External => External, Arg_Form => Form, Arg_Code => Code); if not Is_VMS_Exception (Entity (Internal)) then Set_Exported (Entity (Internal), Internal); end if; end Export_Exception; --------------------- -- Export_Function -- --------------------- -- pragma Export_Function ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL,] -- [, [Parameter_Types =>] (PARAMETER_TYPES)] -- [, [Result_Type =>] TYPE_DESIGNATOR] -- [, [Mechanism =>] MECHANISM] -- [, [Result_Mechanism =>] MECHANISM_NAME]); -- EXTERNAL_SYMBOL ::= -- IDENTIFIER -- | static_string_EXPRESSION -- PARAMETER_TYPES ::= -- null -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} -- TYPE_DESIGNATOR ::= -- subtype_NAME -- | subtype_Name ' Access -- MECHANISM ::= -- MECHANISM_NAME -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) -- MECHANISM_ASSOCIATION ::= -- [formal_parameter_NAME =>] MECHANISM_NAME -- MECHANISM_NAME ::= -- Value -- | Reference -- | Descriptor [([Class =>] CLASS_NAME)] -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca when Pragma_Export_Function => Export_Function : declare Args : Args_List (1 .. 6); Names : constant Name_List (1 .. 6) := ( Name_Internal, Name_External, Name_Parameter_Types, Name_Result_Type, Name_Mechanism, Name_Result_Mechanism); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Parameter_Types : Node_Id renames Args (3); Result_Type : Node_Id renames Args (4); Mechanism : Node_Id renames Args (5); Result_Mechanism : Node_Id renames Args (6); begin GNAT_Pragma; Gather_Associations (Names, Args); Process_Extended_Import_Export_Subprogram_Pragma ( Arg_Internal => Internal, Arg_External => External, Arg_Parameter_Types => Parameter_Types, Arg_Result_Type => Result_Type, Arg_Mechanism => Mechanism, Arg_Result_Mechanism => Result_Mechanism); end Export_Function; ------------------- -- Export_Object -- ------------------- -- pragma Export_Object ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL] -- [, [Size =>] EXTERNAL_SYMBOL]); -- EXTERNAL_SYMBOL ::= -- IDENTIFIER -- | static_string_EXPRESSION -- PARAMETER_TYPES ::= -- null -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} -- TYPE_DESIGNATOR ::= -- subtype_NAME -- | subtype_Name ' Access -- MECHANISM ::= -- MECHANISM_NAME -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) -- MECHANISM_ASSOCIATION ::= -- [formal_parameter_NAME =>] MECHANISM_NAME -- MECHANISM_NAME ::= -- Value -- | Reference -- | Descriptor [([Class =>] CLASS_NAME)] -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca when Pragma_Export_Object => Export_Object : declare Args : Args_List (1 .. 3); Names : constant Name_List (1 .. 3) := ( Name_Internal, Name_External, Name_Size); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Size : Node_Id renames Args (3); begin GNAT_Pragma; Gather_Associations (Names, Args); Process_Extended_Import_Export_Object_Pragma ( Arg_Internal => Internal, Arg_External => External, Arg_Size => Size); end Export_Object; ---------------------- -- Export_Procedure -- ---------------------- -- pragma Export_Procedure ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL,] -- [, [Parameter_Types =>] (PARAMETER_TYPES)] -- [, [Mechanism =>] MECHANISM]); -- EXTERNAL_SYMBOL ::= -- IDENTIFIER -- | static_string_EXPRESSION -- PARAMETER_TYPES ::= -- null -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} -- TYPE_DESIGNATOR ::= -- subtype_NAME -- | subtype_Name ' Access -- MECHANISM ::= -- MECHANISM_NAME -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) -- MECHANISM_ASSOCIATION ::= -- [formal_parameter_NAME =>] MECHANISM_NAME -- MECHANISM_NAME ::= -- Value -- | Reference -- | Descriptor [([Class =>] CLASS_NAME)] -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca when Pragma_Export_Procedure => Export_Procedure : declare Args : Args_List (1 .. 4); Names : constant Name_List (1 .. 4) := ( Name_Internal, Name_External, Name_Parameter_Types, Name_Mechanism); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Parameter_Types : Node_Id renames Args (3); Mechanism : Node_Id renames Args (4); begin GNAT_Pragma; Gather_Associations (Names, Args); Process_Extended_Import_Export_Subprogram_Pragma ( Arg_Internal => Internal, Arg_External => External, Arg_Parameter_Types => Parameter_Types, Arg_Mechanism => Mechanism); end Export_Procedure; ------------------ -- Export_Value -- ------------------ -- pragma Export_Value ( -- [Value =>] static_integer_EXPRESSION, -- [Link_Name =>] static_string_EXPRESSION); when Pragma_Export_Value => GNAT_Pragma; Check_Arg_Order ((Name_Value, Name_Link_Name)); Check_Arg_Count (2); Check_Optional_Identifier (Arg1, Name_Value); Check_Arg_Is_Static_Expression (Arg1, Any_Integer); Check_Optional_Identifier (Arg2, Name_Link_Name); Check_Arg_Is_Static_Expression (Arg2, Standard_String); ----------------------------- -- Export_Valued_Procedure -- ----------------------------- -- pragma Export_Valued_Procedure ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL,] -- [, [Parameter_Types =>] (PARAMETER_TYPES)] -- [, [Mechanism =>] MECHANISM]); -- EXTERNAL_SYMBOL ::= -- IDENTIFIER -- | static_string_EXPRESSION -- PARAMETER_TYPES ::= -- null -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} -- TYPE_DESIGNATOR ::= -- subtype_NAME -- | subtype_Name ' Access -- MECHANISM ::= -- MECHANISM_NAME -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) -- MECHANISM_ASSOCIATION ::= -- [formal_parameter_NAME =>] MECHANISM_NAME -- MECHANISM_NAME ::= -- Value -- | Reference -- | Descriptor [([Class =>] CLASS_NAME)] -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca when Pragma_Export_Valued_Procedure => Export_Valued_Procedure : declare Args : Args_List (1 .. 4); Names : constant Name_List (1 .. 4) := ( Name_Internal, Name_External, Name_Parameter_Types, Name_Mechanism); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Parameter_Types : Node_Id renames Args (3); Mechanism : Node_Id renames Args (4); begin GNAT_Pragma; Gather_Associations (Names, Args); Process_Extended_Import_Export_Subprogram_Pragma ( Arg_Internal => Internal, Arg_External => External, Arg_Parameter_Types => Parameter_Types, Arg_Mechanism => Mechanism); end Export_Valued_Procedure; ------------------- -- Extend_System -- ------------------- -- pragma Extend_System ([Name =>] Identifier); when Pragma_Extend_System => Extend_System : declare begin GNAT_Pragma; Check_Valid_Configuration_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Name); Check_Arg_Is_Identifier (Arg1); Get_Name_String (Chars (Expression (Arg1))); if Name_Len > 4 and then Name_Buffer (1 .. 4) = "aux_" then if Present (System_Extend_Pragma_Arg) then if Chars (Expression (Arg1)) = Chars (Expression (System_Extend_Pragma_Arg)) then null; else Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg); Error_Pragma ("pragma% conflicts with that at#"); end if; else System_Extend_Pragma_Arg := Arg1; if not GNAT_Mode then System_Extend_Unit := Arg1; end if; end if; else Error_Pragma ("incorrect name for pragma%, must be Aux_xxx"); end if; end Extend_System; ------------------------ -- Extensions_Allowed -- ------------------------ -- pragma Extensions_Allowed (ON | OFF); when Pragma_Extensions_Allowed => GNAT_Pragma; Check_Arg_Count (1); Check_No_Identifiers; Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off); if Chars (Expression (Arg1)) = Name_On then Extensions_Allowed := True; Ada_Version := Ada_Version_Type'Last; else Extensions_Allowed := False; Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95); end if; Ada_Version_Explicit := Ada_Version; -------------- -- External -- -------------- -- pragma External ( -- [ Convention =>] convention_IDENTIFIER, -- [ Entity =>] local_NAME -- [, [External_Name =>] static_string_EXPRESSION ] -- [, [Link_Name =>] static_string_EXPRESSION ]); when Pragma_External => External : declare C : Convention_Id; Def_Id : Entity_Id; begin GNAT_Pragma; Check_Arg_Order ((Name_Convention, Name_Entity, Name_External_Name, Name_Link_Name)); Check_At_Least_N_Arguments (2); Check_At_Most_N_Arguments (4); Process_Convention (C, Def_Id); Note_Possible_Modification (Expression (Arg2)); Process_Interface_Name (Def_Id, Arg3, Arg4); Set_Exported (Def_Id, Arg2); end External; -------------------------- -- External_Name_Casing -- -------------------------- -- pragma External_Name_Casing ( -- UPPERCASE | LOWERCASE -- [, AS_IS | UPPERCASE | LOWERCASE]); when Pragma_External_Name_Casing => External_Name_Casing : declare begin GNAT_Pragma; Check_No_Identifiers; if Arg_Count = 2 then Check_Arg_Is_One_Of (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase); case Chars (Get_Pragma_Arg (Arg2)) is when Name_As_Is => Opt.External_Name_Exp_Casing := As_Is; when Name_Uppercase => Opt.External_Name_Exp_Casing := Uppercase; when Name_Lowercase => Opt.External_Name_Exp_Casing := Lowercase; when others => null; end case; else Check_Arg_Count (1); end if; Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase); case Chars (Get_Pragma_Arg (Arg1)) is when Name_Uppercase => Opt.External_Name_Imp_Casing := Uppercase; when Name_Lowercase => Opt.External_Name_Imp_Casing := Lowercase; when others => null; end case; end External_Name_Casing; --------------------------- -- Finalize_Storage_Only -- --------------------------- -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME); when Pragma_Finalize_Storage_Only => Finalize_Storage : declare Assoc : constant Node_Id := Arg1; Type_Id : constant Node_Id := Expression (Assoc); Typ : Entity_Id; begin Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_Local_Name (Arg1); Find_Type (Type_Id); Typ := Entity (Type_Id); if Typ = Any_Type or else Rep_Item_Too_Early (Typ, N) then return; else Typ := Underlying_Type (Typ); end if; if not Is_Controlled (Typ) then Error_Pragma ("pragma% must specify controlled type"); end if; Check_First_Subtype (Arg1); if Finalize_Storage_Only (Typ) then Error_Pragma ("duplicate pragma%, only one allowed"); elsif not Rep_Item_Too_Late (Typ, N) then Set_Finalize_Storage_Only (Base_Type (Typ), True); end if; end Finalize_Storage; -------------------------- -- Float_Representation -- -------------------------- -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]); -- FLOAT_REP ::= VAX_Float | IEEE_Float when Pragma_Float_Representation => Float_Representation : declare Argx : Node_Id; Digs : Nat; Ent : Entity_Id; begin GNAT_Pragma; if Arg_Count = 1 then Check_Valid_Configuration_Pragma; else Check_Arg_Count (2); Check_Optional_Identifier (Arg2, Name_Entity); Check_Arg_Is_Local_Name (Arg2); end if; Check_No_Identifier (Arg1); Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float); if not OpenVMS_On_Target then if Chars (Expression (Arg1)) = Name_VAX_Float then Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)"); end if; return; end if; -- One argument case if Arg_Count = 1 then if Chars (Expression (Arg1)) = Name_VAX_Float then if Opt.Float_Format = 'I' then Error_Pragma ("'I'E'E'E format previously specified"); end if; Opt.Float_Format := 'V'; else if Opt.Float_Format = 'V' then Error_Pragma ("'V'A'X format previously specified"); end if; Opt.Float_Format := 'I'; end if; Set_Standard_Fpt_Formats; -- Two argument case else Argx := Get_Pragma_Arg (Arg2); if not Is_Entity_Name (Argx) or else not Is_Floating_Point_Type (Entity (Argx)) then Error_Pragma_Arg ("second argument of% pragma must be floating-point type", Arg2); end if; Ent := Entity (Argx); Digs := UI_To_Int (Digits_Value (Ent)); -- Two arguments, VAX_Float case if Chars (Expression (Arg1)) = Name_VAX_Float then case Digs is when 6 => Set_F_Float (Ent); when 9 => Set_D_Float (Ent); when 15 => Set_G_Float (Ent); when others => Error_Pragma_Arg ("wrong digits value, must be 6,9 or 15", Arg2); end case; -- Two arguments, IEEE_Float case else case Digs is when 6 => Set_IEEE_Short (Ent); when 15 => Set_IEEE_Long (Ent); when others => Error_Pragma_Arg ("wrong digits value, must be 6 or 15", Arg2); end case; end if; end if; end Float_Representation; ----------- -- Ident -- ----------- -- pragma Ident (static_string_EXPRESSION) -- Note: pragma Comment shares this processing. Pragma Comment -- is identical to Ident, except that the restriction of the -- argument to 31 characters and the placement restrictions -- are not enforced for pragma Comment. when Pragma_Ident | Pragma_Comment => Ident : declare Str : Node_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_No_Identifiers; Check_Arg_Is_Static_Expression (Arg1, Standard_String); -- For pragma Ident, preserve DEC compatibility by requiring -- the pragma to appear in a declarative part or package spec. if Prag_Id = Pragma_Ident then Check_Is_In_Decl_Part_Or_Package_Spec; end if; Str := Expr_Value_S (Expression (Arg1)); declare CS : Node_Id; GP : Node_Id; begin GP := Parent (Parent (N)); if Nkind (GP) = N_Package_Declaration or else Nkind (GP) = N_Generic_Package_Declaration then GP := Parent (GP); end if; -- If we have a compilation unit, then record the ident -- value, checking for improper duplication. if Nkind (GP) = N_Compilation_Unit then CS := Ident_String (Current_Sem_Unit); if Present (CS) then -- For Ident, we do not permit multiple instances if Prag_Id = Pragma_Ident then Error_Pragma ("duplicate% pragma not permitted"); -- For Comment, we concatenate the string, unless we -- want to preserve the tree structure for ASIS. elsif not ASIS_Mode then Start_String (Strval (CS)); Store_String_Char (' '); Store_String_Chars (Strval (Str)); Set_Strval (CS, End_String); end if; else -- In VMS, the effect of IDENT is achieved by passing -- IDENTIFICATION=name as a --for-linker switch. if OpenVMS_On_Target then Start_String; Store_String_Chars ("--for-linker=IDENTIFICATION="); String_To_Name_Buffer (Strval (Str)); Store_String_Chars (Name_Buffer (1 .. Name_Len)); -- Only the last processed IDENT is saved. The main -- purpose is so an IDENT associated with a main -- procedure will be used in preference to an IDENT -- associated with a with'd package. Replace_Linker_Option_String (End_String, "--for-linker=IDENTIFICATION="); end if; Set_Ident_String (Current_Sem_Unit, Str); end if; -- For subunits, we just ignore the Ident, since in GNAT -- these are not separate object files, and hence not -- separate units in the unit table. elsif Nkind (GP) = N_Subunit then null; -- Otherwise we have a misplaced pragma Ident, but we ignore -- this if we are in an instantiation, since it comes from -- a generic, and has no relevance to the instantiation. elsif Prag_Id = Pragma_Ident then if Instantiation_Location (Loc) = No_Location then Error_Pragma ("pragma% only allowed at outer level"); end if; end if; end; end Ident; ------------ -- Import -- ------------ -- pragma Import ( -- [ Convention =>] convention_IDENTIFIER, -- [ Entity =>] local_NAME -- [, [External_Name =>] static_string_EXPRESSION ] -- [, [Link_Name =>] static_string_EXPRESSION ]); when Pragma_Import => Check_Ada_83_Warning; Check_Arg_Order ((Name_Convention, Name_Entity, Name_External_Name, Name_Link_Name)); Check_At_Least_N_Arguments (2); Check_At_Most_N_Arguments (4); Process_Import_Or_Interface; ---------------------- -- Import_Exception -- ---------------------- -- pragma Import_Exception ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL,] -- [, [Form =>] Ada | VMS] -- [, [Code =>] static_integer_EXPRESSION]); when Pragma_Import_Exception => Import_Exception : declare Args : Args_List (1 .. 4); Names : constant Name_List (1 .. 4) := ( Name_Internal, Name_External, Name_Form, Name_Code); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Form : Node_Id renames Args (3); Code : Node_Id renames Args (4); begin Gather_Associations (Names, Args); if Present (External) and then Present (Code) then Error_Pragma ("cannot give both External and Code options for pragma%"); end if; Process_Extended_Import_Export_Exception_Pragma ( Arg_Internal => Internal, Arg_External => External, Arg_Form => Form, Arg_Code => Code); if not Is_VMS_Exception (Entity (Internal)) then Set_Imported (Entity (Internal)); end if; end Import_Exception; --------------------- -- Import_Function -- --------------------- -- pragma Import_Function ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL] -- [, [Parameter_Types =>] (PARAMETER_TYPES)] -- [, [Result_Type =>] SUBTYPE_MARK] -- [, [Mechanism =>] MECHANISM] -- [, [Result_Mechanism =>] MECHANISM_NAME] -- [, [First_Optional_Parameter =>] IDENTIFIER]); -- EXTERNAL_SYMBOL ::= -- IDENTIFIER -- | static_string_EXPRESSION -- PARAMETER_TYPES ::= -- null -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} -- TYPE_DESIGNATOR ::= -- subtype_NAME -- | subtype_Name ' Access -- MECHANISM ::= -- MECHANISM_NAME -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) -- MECHANISM_ASSOCIATION ::= -- [formal_parameter_NAME =>] MECHANISM_NAME -- MECHANISM_NAME ::= -- Value -- | Reference -- | Descriptor [([Class =>] CLASS_NAME)] -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca when Pragma_Import_Function => Import_Function : declare Args : Args_List (1 .. 7); Names : constant Name_List (1 .. 7) := ( Name_Internal, Name_External, Name_Parameter_Types, Name_Result_Type, Name_Mechanism, Name_Result_Mechanism, Name_First_Optional_Parameter); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Parameter_Types : Node_Id renames Args (3); Result_Type : Node_Id renames Args (4); Mechanism : Node_Id renames Args (5); Result_Mechanism : Node_Id renames Args (6); First_Optional_Parameter : Node_Id renames Args (7); begin GNAT_Pragma; Gather_Associations (Names, Args); Process_Extended_Import_Export_Subprogram_Pragma ( Arg_Internal => Internal, Arg_External => External, Arg_Parameter_Types => Parameter_Types, Arg_Result_Type => Result_Type, Arg_Mechanism => Mechanism, Arg_Result_Mechanism => Result_Mechanism, Arg_First_Optional_Parameter => First_Optional_Parameter); end Import_Function; ------------------- -- Import_Object -- ------------------- -- pragma Import_Object ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL] -- [, [Size =>] EXTERNAL_SYMBOL]); -- EXTERNAL_SYMBOL ::= -- IDENTIFIER -- | static_string_EXPRESSION when Pragma_Import_Object => Import_Object : declare Args : Args_List (1 .. 3); Names : constant Name_List (1 .. 3) := ( Name_Internal, Name_External, Name_Size); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Size : Node_Id renames Args (3); begin GNAT_Pragma; Gather_Associations (Names, Args); Process_Extended_Import_Export_Object_Pragma ( Arg_Internal => Internal, Arg_External => External, Arg_Size => Size); end Import_Object; ---------------------- -- Import_Procedure -- ---------------------- -- pragma Import_Procedure ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL] -- [, [Parameter_Types =>] (PARAMETER_TYPES)] -- [, [Mechanism =>] MECHANISM] -- [, [First_Optional_Parameter =>] IDENTIFIER]); -- EXTERNAL_SYMBOL ::= -- IDENTIFIER -- | static_string_EXPRESSION -- PARAMETER_TYPES ::= -- null -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} -- TYPE_DESIGNATOR ::= -- subtype_NAME -- | subtype_Name ' Access -- MECHANISM ::= -- MECHANISM_NAME -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) -- MECHANISM_ASSOCIATION ::= -- [formal_parameter_NAME =>] MECHANISM_NAME -- MECHANISM_NAME ::= -- Value -- | Reference -- | Descriptor [([Class =>] CLASS_NAME)] -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca when Pragma_Import_Procedure => Import_Procedure : declare Args : Args_List (1 .. 5); Names : constant Name_List (1 .. 5) := ( Name_Internal, Name_External, Name_Parameter_Types, Name_Mechanism, Name_First_Optional_Parameter); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Parameter_Types : Node_Id renames Args (3); Mechanism : Node_Id renames Args (4); First_Optional_Parameter : Node_Id renames Args (5); begin GNAT_Pragma; Gather_Associations (Names, Args); Process_Extended_Import_Export_Subprogram_Pragma ( Arg_Internal => Internal, Arg_External => External, Arg_Parameter_Types => Parameter_Types, Arg_Mechanism => Mechanism, Arg_First_Optional_Parameter => First_Optional_Parameter); end Import_Procedure; ----------------------------- -- Import_Valued_Procedure -- ----------------------------- -- pragma Import_Valued_Procedure ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL] -- [, [Parameter_Types =>] (PARAMETER_TYPES)] -- [, [Mechanism =>] MECHANISM] -- [, [First_Optional_Parameter =>] IDENTIFIER]); -- EXTERNAL_SYMBOL ::= -- IDENTIFIER -- | static_string_EXPRESSION -- PARAMETER_TYPES ::= -- null -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} -- TYPE_DESIGNATOR ::= -- subtype_NAME -- | subtype_Name ' Access -- MECHANISM ::= -- MECHANISM_NAME -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) -- MECHANISM_ASSOCIATION ::= -- [formal_parameter_NAME =>] MECHANISM_NAME -- MECHANISM_NAME ::= -- Value -- | Reference -- | Descriptor [([Class =>] CLASS_NAME)] -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca when Pragma_Import_Valued_Procedure => Import_Valued_Procedure : declare Args : Args_List (1 .. 5); Names : constant Name_List (1 .. 5) := ( Name_Internal, Name_External, Name_Parameter_Types, Name_Mechanism, Name_First_Optional_Parameter); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Parameter_Types : Node_Id renames Args (3); Mechanism : Node_Id renames Args (4); First_Optional_Parameter : Node_Id renames Args (5); begin GNAT_Pragma; Gather_Associations (Names, Args); Process_Extended_Import_Export_Subprogram_Pragma ( Arg_Internal => Internal, Arg_External => External, Arg_Parameter_Types => Parameter_Types, Arg_Mechanism => Mechanism, Arg_First_Optional_Parameter => First_Optional_Parameter); end Import_Valued_Procedure; ------------------------ -- Initialize_Scalars -- ------------------------ -- pragma Initialize_Scalars; when Pragma_Initialize_Scalars => GNAT_Pragma; Check_Arg_Count (0); Check_Valid_Configuration_Pragma; Check_Restriction (No_Initialize_Scalars, N); if not Restriction_Active (No_Initialize_Scalars) then Init_Or_Norm_Scalars := True; Initialize_Scalars := True; end if; ------------ -- Inline -- ------------ -- pragma Inline ( NAME {, NAME} ); when Pragma_Inline => -- Pragma is active if inlining option is active Process_Inline (Inline_Active); ------------------- -- Inline_Always -- ------------------- -- pragma Inline_Always ( NAME {, NAME} ); when Pragma_Inline_Always => Process_Inline (True); -------------------- -- Inline_Generic -- -------------------- -- pragma Inline_Generic (NAME {, NAME}); when Pragma_Inline_Generic => Process_Generic_List; ---------------------- -- Inspection_Point -- ---------------------- -- pragma Inspection_Point [(object_NAME {, object_NAME})]; when Pragma_Inspection_Point => Inspection_Point : declare Arg : Node_Id; Exp : Node_Id; begin if Arg_Count > 0 then Arg := Arg1; loop Exp := Expression (Arg); Analyze (Exp); if not Is_Entity_Name (Exp) or else not Is_Object (Entity (Exp)) then Error_Pragma_Arg ("object name required", Arg); end if; Next (Arg); exit when No (Arg); end loop; end if; end Inspection_Point; --------------- -- Interface -- --------------- -- pragma Interface ( -- convention_IDENTIFIER, -- local_NAME ); when Pragma_Interface => GNAT_Pragma; Check_Arg_Count (2); Check_No_Identifiers; Process_Import_Or_Interface; -------------------- -- Interface_Name -- -------------------- -- pragma Interface_Name ( -- [ Entity =>] local_NAME -- [,[External_Name =>] static_string_EXPRESSION ] -- [,[Link_Name =>] static_string_EXPRESSION ]); when Pragma_Interface_Name => Interface_Name : declare Id : Node_Id; Def_Id : Entity_Id; Hom_Id : Entity_Id; Found : Boolean; begin GNAT_Pragma; Check_Arg_Order ((Name_Entity, Name_External_Name, Name_Link_Name)); Check_At_Least_N_Arguments (2); Check_At_Most_N_Arguments (3); Id := Expression (Arg1); Analyze (Id); if not Is_Entity_Name (Id) then Error_Pragma_Arg ("first argument for pragma% must be entity name", Arg1); elsif Etype (Id) = Any_Type then return; else Def_Id := Entity (Id); end if; -- Special DEC-compatible processing for the object case, -- forces object to be imported. if Ekind (Def_Id) = E_Variable then Kill_Size_Check_Code (Def_Id); Note_Possible_Modification (Id); -- Initialization is not allowed for imported variable if Present (Expression (Parent (Def_Id))) and then Comes_From_Source (Expression (Parent (Def_Id))) then Error_Msg_Sloc := Sloc (Def_Id); Error_Pragma_Arg ("no initialization allowed for declaration of& #", Arg2); else -- For compatibility, support VADS usage of providing both -- pragmas Interface and Interface_Name to obtain the effect -- of a single Import pragma. if Is_Imported (Def_Id) and then Present (First_Rep_Item (Def_Id)) and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma and then Chars (First_Rep_Item (Def_Id)) = Name_Interface then null; else Set_Imported (Def_Id); end if; Set_Is_Public (Def_Id); Process_Interface_Name (Def_Id, Arg2, Arg3); end if; -- Otherwise must be subprogram elsif not Is_Subprogram (Def_Id) then Error_Pragma_Arg ("argument of pragma% is not subprogram", Arg1); else Check_At_Most_N_Arguments (3); Hom_Id := Def_Id; Found := False; -- Loop through homonyms loop Def_Id := Get_Base_Subprogram (Hom_Id); if Is_Imported (Def_Id) then Process_Interface_Name (Def_Id, Arg2, Arg3); Found := True; end if; Hom_Id := Homonym (Hom_Id); exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope; end loop; if not Found then Error_Pragma_Arg ("argument of pragma% is not imported subprogram", Arg1); end if; end if; end Interface_Name; ----------------------- -- Interrupt_Handler -- ----------------------- -- pragma Interrupt_Handler (handler_NAME); when Pragma_Interrupt_Handler => Check_Ada_83_Warning; Check_Arg_Count (1); Check_No_Identifiers; if No_Run_Time_Mode then Error_Msg_CRT ("Interrupt_Handler pragma", N); else Check_Interrupt_Or_Attach_Handler; Process_Interrupt_Or_Attach_Handler; end if; ------------------------ -- Interrupt_Priority -- ------------------------ -- pragma Interrupt_Priority [(EXPRESSION)]; when Pragma_Interrupt_Priority => Interrupt_Priority : declare P : constant Node_Id := Parent (N); Arg : Node_Id; begin Check_Ada_83_Warning; if Arg_Count /= 0 then Arg := Expression (Arg1); Check_Arg_Count (1); Check_No_Identifiers; -- The expression must be analyzed in the special manner -- described in "Handling of Default and Per-Object -- Expressions" in sem.ads. Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority)); end if; if Nkind (P) /= N_Task_Definition and then Nkind (P) /= N_Protected_Definition then Pragma_Misplaced; return; elsif Has_Priority_Pragma (P) then Error_Pragma ("duplicate pragma% not allowed"); else Set_Has_Priority_Pragma (P, True); Record_Rep_Item (Defining_Identifier (Parent (P)), N); end if; end Interrupt_Priority; --------------------- -- Interrupt_State -- --------------------- -- pragma Interrupt_State ( -- [Name =>] INTERRUPT_ID, -- [State =>] INTERRUPT_STATE); -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION -- INTERRUPT_STATE => System | Runtime | User -- Note: if the interrupt id is given as an identifier, then -- it must be one of the identifiers in Ada.Interrupts.Names. -- Otherwise it is given as a static integer expression which -- must be in the range of Ada.Interrupts.Interrupt_ID. when Pragma_Interrupt_State => Interrupt_State : declare Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID); -- This is the entity Ada.Interrupts.Interrupt_ID; State_Type : Character; -- Set to 's'/'r'/'u' for System/Runtime/User IST_Num : Pos; -- Index to entry in Interrupt_States table Int_Val : Uint; -- Value of interrupt Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1); -- The first argument to the pragma Int_Ent : Entity_Id; -- Interrupt entity in Ada.Interrupts.Names begin GNAT_Pragma; Check_Arg_Order ((Name_Name, Name_State)); Check_Arg_Count (2); Check_Optional_Identifier (Arg1, Name_Name); Check_Optional_Identifier (Arg2, Name_State); Check_Arg_Is_Identifier (Arg2); -- First argument is identifier if Nkind (Arg1X) = N_Identifier then -- Search list of names in Ada.Interrupts.Names Int_Ent := First_Entity (RTE (RE_Names)); loop if No (Int_Ent) then Error_Pragma_Arg ("invalid interrupt name", Arg1); elsif Chars (Int_Ent) = Chars (Arg1X) then Int_Val := Expr_Value (Constant_Value (Int_Ent)); exit; end if; Next_Entity (Int_Ent); end loop; -- First argument is not an identifier, so it must be a -- static expression of type Ada.Interrupts.Interrupt_ID. else Check_Arg_Is_Static_Expression (Arg1, Any_Integer); Int_Val := Expr_Value (Arg1X); if Int_Val < Expr_Value (Type_Low_Bound (Int_Id)) or else Int_Val > Expr_Value (Type_High_Bound (Int_Id)) then Error_Pragma_Arg ("value not in range of type " & """Ada.Interrupts.Interrupt_'I'D""", Arg1); end if; end if; -- Check OK state case Chars (Get_Pragma_Arg (Arg2)) is when Name_Runtime => State_Type := 'r'; when Name_System => State_Type := 's'; when Name_User => State_Type := 'u'; when others => Error_Pragma_Arg ("invalid interrupt state", Arg2); end case; -- Check if entry is already stored IST_Num := Interrupt_States.First; loop -- If entry not found, add it if IST_Num > Interrupt_States.Last then Interrupt_States.Append ((Interrupt_Number => UI_To_Int (Int_Val), Interrupt_State => State_Type, Pragma_Loc => Loc)); exit; -- Case of entry for the same entry elsif Int_Val = Interrupt_States.Table (IST_Num). Interrupt_Number then -- If state matches, done, no need to make redundant entry exit when State_Type = Interrupt_States.Table (IST_Num). Interrupt_State; -- Otherwise if state does not match, error Error_Msg_Sloc := Interrupt_States.Table (IST_Num).Pragma_Loc; Error_Pragma_Arg ("state conflicts with that given at #", Arg2); exit; end if; IST_Num := IST_Num + 1; end loop; end Interrupt_State; ---------------------- -- Java_Constructor -- ---------------------- -- pragma Java_Constructor ([Entity =>] LOCAL_NAME); when Pragma_Java_Constructor => Java_Constructor : declare Id : Entity_Id; Def_Id : Entity_Id; Hom_Id : Entity_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Local_Name (Arg1); Id := Expression (Arg1); Find_Program_Unit_Name (Id); -- If we did not find the name, we are done if Etype (Id) = Any_Type then return; end if; Hom_Id := Entity (Id); -- Loop through homonyms loop Def_Id := Get_Base_Subprogram (Hom_Id); -- The constructor is required to be a function returning -- an access type whose designated type has convention Java. if Ekind (Def_Id) = E_Function and then Ekind (Etype (Def_Id)) in Access_Kind and then (Atree.Convention (Designated_Type (Etype (Def_Id))) = Convention_Java or else Atree.Convention (Root_Type (Designated_Type (Etype (Def_Id)))) = Convention_Java) then Set_Is_Constructor (Def_Id); Set_Convention (Def_Id, Convention_Java); else Error_Pragma_Arg ("pragma% requires function returning a 'Java access type", Arg1); end if; Hom_Id := Homonym (Hom_Id); exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope; end loop; end Java_Constructor; ---------------------- -- Java_Interface -- ---------------------- -- pragma Java_Interface ([Entity =>] LOCAL_NAME); when Pragma_Java_Interface => Java_Interface : declare Arg : Node_Id; Typ : Entity_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Local_Name (Arg1); Arg := Expression (Arg1); Analyze (Arg); if Etype (Arg) = Any_Type then return; end if; if not Is_Entity_Name (Arg) or else not Is_Type (Entity (Arg)) then Error_Pragma_Arg ("pragma% requires a type mark", Arg1); end if; Typ := Underlying_Type (Entity (Arg)); -- For now we simply check some of the semantic constraints -- on the type. This currently leaves out some restrictions -- on interface types, namely that the parent type must be -- java.lang.Object.Typ and that all primitives of the type -- should be declared abstract. ??? if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then Error_Pragma_Arg ("pragma% requires an abstract " & "tagged type", Arg1); elsif not Has_Discriminants (Typ) or else Ekind (Etype (First_Discriminant (Typ))) /= E_Anonymous_Access_Type or else not Is_Class_Wide_Type (Designated_Type (Etype (First_Discriminant (Typ)))) then Error_Pragma_Arg ("type must have a class-wide access discriminant", Arg1); end if; end Java_Interface; ---------------- -- Keep_Names -- ---------------- -- pragma Keep_Names ([On => ] local_NAME); when Pragma_Keep_Names => Keep_Names : declare Arg : Node_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_On); Check_Arg_Is_Local_Name (Arg1); Arg := Expression (Arg1); Analyze (Arg); if Etype (Arg) = Any_Type then return; end if; if not Is_Entity_Name (Arg) or else Ekind (Entity (Arg)) /= E_Enumeration_Type then Error_Pragma_Arg ("pragma% requires a local enumeration type", Arg1); end if; Set_Discard_Names (Entity (Arg), False); end Keep_Names; ------------- -- License -- ------------- -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL); when Pragma_License => GNAT_Pragma; Check_Arg_Count (1); Check_No_Identifiers; Check_Valid_Configuration_Pragma; Check_Arg_Is_Identifier (Arg1); declare Sind : constant Source_File_Index := Source_Index (Current_Sem_Unit); begin case Chars (Get_Pragma_Arg (Arg1)) is when Name_GPL => Set_License (Sind, GPL); when Name_Modified_GPL => Set_License (Sind, Modified_GPL); when Name_Restricted => Set_License (Sind, Restricted); when Name_Unrestricted => Set_License (Sind, Unrestricted); when others => Error_Pragma_Arg ("invalid license name", Arg1); end case; end; --------------- -- Link_With -- --------------- -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION}); when Pragma_Link_With => Link_With : declare Arg : Node_Id; begin GNAT_Pragma; if Operating_Mode = Generate_Code and then In_Extended_Main_Source_Unit (N) then Check_At_Least_N_Arguments (1); Check_No_Identifiers; Check_Is_In_Decl_Part_Or_Package_Spec; Check_Arg_Is_Static_Expression (Arg1, Standard_String); Start_String; Arg := Arg1; while Present (Arg) loop Check_Arg_Is_Static_Expression (Arg, Standard_String); -- Store argument, converting sequences of spaces -- to a single null character (this is one of the -- differences in processing between Link_With -- and Linker_Options). declare C : constant Char_Code := Get_Char_Code (' '); S : constant String_Id := Strval (Expr_Value_S (Expression (Arg))); L : constant Nat := String_Length (S); F : Nat := 1; procedure Skip_Spaces; -- Advance F past any spaces procedure Skip_Spaces is begin while F <= L and then Get_String_Char (S, F) = C loop F := F + 1; end loop; end Skip_Spaces; begin Skip_Spaces; -- skip leading spaces -- Loop through characters, changing any embedded -- sequence of spaces to a single null character -- (this is how Link_With/Linker_Options differ) while F <= L loop if Get_String_Char (S, F) = C then Skip_Spaces; exit when F > L; Store_String_Char (ASCII.NUL); else Store_String_Char (Get_String_Char (S, F)); F := F + 1; end if; end loop; end; Arg := Next (Arg); if Present (Arg) then Store_String_Char (ASCII.NUL); end if; end loop; Store_Linker_Option_String (End_String); end if; end Link_With; ------------------ -- Linker_Alias -- ------------------ -- pragma Linker_Alias ( -- [Entity =>] LOCAL_NAME -- [Target =>] static_string_EXPRESSION); when Pragma_Linker_Alias => GNAT_Pragma; Check_Arg_Order ((Name_Entity, Name_Target)); Check_Arg_Count (2); Check_Optional_Identifier (Arg1, Name_Entity); Check_Optional_Identifier (Arg2, Name_Target); Check_Arg_Is_Library_Level_Local_Name (Arg1); Check_Arg_Is_Static_Expression (Arg2, Standard_String); -- The only processing required is to link this item on to the -- list of rep items for the given entity. This is accomplished -- by the call to Rep_Item_Too_Late (when no error is detected -- and False is returned). if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then return; else Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1))); end if; ------------------------ -- Linker_Constructor -- ------------------------ -- pragma Linker_Constructor (procedure_LOCAL_NAME); -- Code is shared with Linker_Destructor ----------------------- -- Linker_Destructor -- ----------------------- -- pragma Linker_Destructor (procedure_LOCAL_NAME); when Pragma_Linker_Constructor | Pragma_Linker_Destructor => Linker_Constructor : declare Arg1_X : Node_Id; Proc : Entity_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_No_Identifiers; Check_Arg_Is_Local_Name (Arg1); Arg1_X := Expression (Arg1); Analyze (Arg1_X); Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1); if not Is_Library_Level_Entity (Proc) then Error_Pragma_Arg ("argument for pragma% must be library level entity", Arg1); end if; -- The only processing required is to link this item on to the -- list of rep items for the given entity. This is accomplished -- by the call to Rep_Item_Too_Late (when no error is detected -- and False is returned). if Rep_Item_Too_Late (Proc, N) then return; else Set_Has_Gigi_Rep_Item (Proc); end if; end Linker_Constructor; -------------------- -- Linker_Options -- -------------------- -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION}); when Pragma_Linker_Options => Linker_Options : declare Arg : Node_Id; begin Check_Ada_83_Warning; Check_No_Identifiers; Check_Arg_Count (1); Check_Is_In_Decl_Part_Or_Package_Spec; if Operating_Mode = Generate_Code and then In_Extended_Main_Source_Unit (N) then Check_Arg_Is_Static_Expression (Arg1, Standard_String); Start_String (Strval (Expr_Value_S (Expression (Arg1)))); Arg := Arg2; while Present (Arg) loop Check_Arg_Is_Static_Expression (Arg, Standard_String); Store_String_Char (ASCII.NUL); Store_String_Chars (Strval (Expr_Value_S (Expression (Arg)))); Arg := Next (Arg); end loop; Store_Linker_Option_String (End_String); end if; end Linker_Options; -------------------- -- Linker_Section -- -------------------- -- pragma Linker_Section ( -- [Entity =>] LOCAL_NAME -- [Section =>] static_string_EXPRESSION); when Pragma_Linker_Section => GNAT_Pragma; Check_Arg_Order ((Name_Entity, Name_Section)); Check_Arg_Count (2); Check_Optional_Identifier (Arg1, Name_Entity); Check_Optional_Identifier (Arg2, Name_Section); Check_Arg_Is_Library_Level_Local_Name (Arg1); Check_Arg_Is_Static_Expression (Arg2, Standard_String); -- The only processing required is to link this item on to the -- list of rep items for the given entity. This is accomplished -- by the call to Rep_Item_Too_Late (when no error is detected -- and False is returned). if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then return; else Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1))); end if; ---------- -- List -- ---------- -- pragma List (On | Off) -- There is nothing to do here, since we did all the processing -- for this pragma in Par.Prag (so that it works properly even in -- syntax only mode) when Pragma_List => null; -------------------- -- Locking_Policy -- -------------------- -- pragma Locking_Policy (policy_IDENTIFIER); when Pragma_Locking_Policy => declare LP : Character; begin Check_Ada_83_Warning; Check_Arg_Count (1); Check_No_Identifiers; Check_Arg_Is_Locking_Policy (Arg1); Check_Valid_Configuration_Pragma; Get_Name_String (Chars (Expression (Arg1))); LP := Fold_Upper (Name_Buffer (1)); if Locking_Policy /= ' ' and then Locking_Policy /= LP then Error_Msg_Sloc := Locking_Policy_Sloc; Error_Pragma ("locking policy incompatible with policy#"); -- Set new policy, but always preserve System_Location since -- we like the error message with the run time name. else Locking_Policy := LP; if Locking_Policy_Sloc /= System_Location then Locking_Policy_Sloc := Loc; end if; end if; end; ---------------- -- Long_Float -- ---------------- -- pragma Long_Float (D_Float | G_Float); when Pragma_Long_Float => GNAT_Pragma; Check_Valid_Configuration_Pragma; Check_Arg_Count (1); Check_No_Identifier (Arg1); Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float); if not OpenVMS_On_Target then Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)"); end if; -- D_Float case if Chars (Expression (Arg1)) = Name_D_Float then if Opt.Float_Format_Long = 'G' then Error_Pragma ("G_Float previously specified"); end if; Opt.Float_Format_Long := 'D'; -- G_Float case (this is the default, does not need overriding) else if Opt.Float_Format_Long = 'D' then Error_Pragma ("D_Float previously specified"); end if; Opt.Float_Format_Long := 'G'; end if; Set_Standard_Fpt_Formats; ----------------------- -- Machine_Attribute -- ----------------------- -- pragma Machine_Attribute ( -- [Entity =>] LOCAL_NAME, -- [Attribute_Name =>] static_string_EXPRESSION -- [,[Info =>] static_string_EXPRESSION] ); when Pragma_Machine_Attribute => Machine_Attribute : declare Def_Id : Entity_Id; begin GNAT_Pragma; Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info)); if Arg_Count = 3 then Check_Optional_Identifier (Arg3, Name_Info); Check_Arg_Is_Static_Expression (Arg3, Standard_String); else Check_Arg_Count (2); end if; Check_Optional_Identifier (Arg1, Name_Entity); Check_Optional_Identifier (Arg2, Name_Attribute_Name); Check_Arg_Is_Local_Name (Arg1); Check_Arg_Is_Static_Expression (Arg2, Standard_String); Def_Id := Entity (Expression (Arg1)); if Is_Access_Type (Def_Id) then Def_Id := Designated_Type (Def_Id); end if; if Rep_Item_Too_Early (Def_Id, N) then return; end if; Def_Id := Underlying_Type (Def_Id); -- The only processing required is to link this item on to the -- list of rep items for the given entity. This is accomplished -- by the call to Rep_Item_Too_Late (when no error is detected -- and False is returned). if Rep_Item_Too_Late (Def_Id, N) then return; else Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1))); end if; end Machine_Attribute; ---------- -- Main -- ---------- -- pragma Main_Storage -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]); -- MAIN_STORAGE_OPTION ::= -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION when Pragma_Main => Main : declare Args : Args_List (1 .. 3); Names : constant Name_List (1 .. 3) := ( Name_Stack_Size, Name_Task_Stack_Size_Default, Name_Time_Slicing_Enabled); Nod : Node_Id; begin GNAT_Pragma; Gather_Associations (Names, Args); for J in 1 .. 2 loop if Present (Args (J)) then Check_Arg_Is_Static_Expression (Args (J), Any_Integer); end if; end loop; if Present (Args (3)) then Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean); end if; Nod := Next (N); while Present (Nod) loop if Nkind (Nod) = N_Pragma and then Chars (Nod) = Name_Main then Error_Msg_Name_1 := Chars (N); Error_Msg_N ("duplicate pragma% not permitted", Nod); end if; Next (Nod); end loop; end Main; ------------------ -- Main_Storage -- ------------------ -- pragma Main_Storage -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]); -- MAIN_STORAGE_OPTION ::= -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION when Pragma_Main_Storage => Main_Storage : declare Args : Args_List (1 .. 2); Names : constant Name_List (1 .. 2) := ( Name_Working_Storage, Name_Top_Guard); Nod : Node_Id; begin GNAT_Pragma; Gather_Associations (Names, Args); for J in 1 .. 2 loop if Present (Args (J)) then Check_Arg_Is_Static_Expression (Args (J), Any_Integer); end if; end loop; Check_In_Main_Program; Nod := Next (N); while Present (Nod) loop if Nkind (Nod) = N_Pragma and then Chars (Nod) = Name_Main_Storage then Error_Msg_Name_1 := Chars (N); Error_Msg_N ("duplicate pragma% not permitted", Nod); end if; Next (Nod); end loop; end Main_Storage; ----------------- -- Memory_Size -- ----------------- -- pragma Memory_Size (NUMERIC_LITERAL) when Pragma_Memory_Size => GNAT_Pragma; -- Memory size is simply ignored Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_Integer_Literal (Arg1); --------------- -- No_Return -- --------------- -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name}); when Pragma_No_Return => No_Return : declare Id : Node_Id; E : Entity_Id; Found : Boolean; Arg : Node_Id; begin GNAT_Pragma; Check_At_Least_N_Arguments (1); -- Loop through arguments of pragma Arg := Arg1; while Present (Arg) loop Check_Arg_Is_Local_Name (Arg); Id := Expression (Arg); Analyze (Id); if not Is_Entity_Name (Id) then Error_Pragma_Arg ("entity name required", Arg); end if; if Etype (Id) = Any_Type then raise Pragma_Exit; end if; -- Loop to find matching procedures E := Entity (Id); Found := False; while Present (E) and then Scope (E) = Current_Scope loop if Ekind (E) = E_Procedure or else Ekind (E) = E_Generic_Procedure then Set_No_Return (E); Found := True; end if; E := Homonym (E); end loop; if not Found then Error_Pragma_Arg ("no procedure & found for pragma%", Arg); end if; Next (Arg); end loop; end No_Return; ------------------------ -- No_Strict_Aliasing -- ------------------------ -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)]; when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare E_Id : Entity_Id; begin GNAT_Pragma; Check_At_Most_N_Arguments (1); if Arg_Count = 0 then Check_Valid_Configuration_Pragma; Opt.No_Strict_Aliasing := True; else Check_Optional_Identifier (Arg2, Name_Entity); Check_Arg_Is_Local_Name (Arg1); E_Id := Entity (Expression (Arg1)); if E_Id = Any_Type then return; elsif No (E_Id) or else not Is_Access_Type (E_Id) then Error_Pragma_Arg ("pragma% requires access type", Arg1); end if; Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id)); end if; end No_Strict_Alias; ----------------- -- Obsolescent -- ----------------- -- pragma Obsolescent [(static_string_EXPRESSION [, Ada_05])]; when Pragma_Obsolescent => Obsolescent : declare Subp : Node_Or_Entity_Id; S : String_Id; Active : Boolean := True; procedure Check_Obsolete_Subprogram; -- Checks if Subp is a subprogram declaration node, and if so -- replaces Subp by the defining entity of the subprogram. If not, -- issues an error message ------------------------------ -- Check_Obsolete_Subprogram-- ------------------------------ procedure Check_Obsolete_Subprogram is begin if Nkind (Subp) /= N_Subprogram_Declaration then Error_Pragma ("pragma% misplaced, must immediately " & "follow subprogram/package declaration"); else Subp := Defining_Entity (Subp); end if; end Check_Obsolete_Subprogram; -- Start of processing for pragma Obsolescent begin GNAT_Pragma; Check_At_Most_N_Arguments (2); Check_No_Identifiers; -- Check OK placement -- First possibility is within a declarative region, where the -- pragma immediately follows a subprogram declaration. if Present (Prev (N)) then Subp := Prev (N); Check_Obsolete_Subprogram; -- Second possibility, stand alone subprogram declaration with the -- pragma immediately following the declaration. elsif No (Prev (N)) and then Nkind (Parent (N)) = N_Compilation_Unit_Aux then Subp := Unit (Parent (Parent (N))); Check_Obsolete_Subprogram; -- Only other possibility is library unit placement for package else Subp := Find_Lib_Unit_Name; if Ekind (Subp) /= E_Package and then Ekind (Subp) /= E_Generic_Package then Check_Obsolete_Subprogram; end if; end if; -- If OK placement, acquire arguments if Arg_Count >= 1 then -- Deal with static string argument Check_Arg_Is_Static_Expression (Arg1, Standard_String); S := Strval (Expression (Arg1)); for J in 1 .. String_Length (S) loop if not In_Character_Range (Get_String_Char (S, J)) then Error_Pragma_Arg ("pragma% argument does not allow wide characters", Arg1); end if; end loop; Set_Obsolescent_Warning (Subp, Expression (Arg1)); -- Check for Ada_05 parameter if Arg_Count /= 1 then Check_Arg_Count (2); declare Argx : constant Node_Id := Get_Pragma_Arg (Arg2); begin Check_Arg_Is_Identifier (Argx); if Chars (Argx) /= Name_Ada_05 then Error_Msg_Name_2 := Name_Ada_05; Error_Pragma_Arg ("only allowed argument for pragma% is %", Argx); end if; if Ada_Version_Explicit < Ada_05 or else not Warn_On_Ada_2005_Compatibility then Active := False; end if; end; end if; end if; -- Set flag if pragma active if Active then Set_Is_Obsolescent (Subp); end if; end Obsolescent; ----------------- -- No_Run_Time -- ----------------- -- pragma No_Run_Time -- Note: this pragma is retained for backwards compatibiltiy. -- See body of Rtsfind for full details on its handling. when Pragma_No_Run_Time => GNAT_Pragma; Check_Valid_Configuration_Pragma; Check_Arg_Count (0); No_Run_Time_Mode := True; Configurable_Run_Time_Mode := True; declare Word32 : constant Boolean := Ttypes.System_Word_Size = 32; begin if Word32 then Duration_32_Bits_On_Target := True; end if; end; Set_Restriction (No_Finalization, N); Set_Restriction (No_Exception_Handlers, N); Set_Restriction (Max_Tasks, N, 0); Set_Restriction (No_Tasking, N); ----------------------- -- Normalize_Scalars -- ----------------------- -- pragma Normalize_Scalars; when Pragma_Normalize_Scalars => Check_Ada_83_Warning; Check_Arg_Count (0); Check_Valid_Configuration_Pragma; Normalize_Scalars := True; Init_Or_Norm_Scalars := True; -------------- -- Optimize -- -------------- -- pragma Optimize (Time | Space); -- The actual check for optimize is done in Gigi. Note that this -- pragma does not actually change the optimization setting, it -- simply checks that it is consistent with the pragma. when Pragma_Optimize => Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off); ------------------------- -- Optional_Overriding -- ------------------------- -- These pragmas are treated as part of the previous subprogram -- declaration, and analyzed immediately after it (see sem_ch6, -- Check_Overriding_Operation). If the pragma has not been analyzed -- yet, it appears in the wrong place. when Pragma_Optional_Overriding => Error_Msg_N ("pragma must appear immediately after subprogram", N); ---------- -- Pack -- ---------- -- pragma Pack (first_subtype_LOCAL_NAME); when Pragma_Pack => Pack : declare Assoc : constant Node_Id := Arg1; Type_Id : Node_Id; Typ : Entity_Id; begin Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_Local_Name (Arg1); Type_Id := Expression (Assoc); Find_Type (Type_Id); Typ := Entity (Type_Id); if Typ = Any_Type or else Rep_Item_Too_Early (Typ, N) then return; else Typ := Underlying_Type (Typ); end if; if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then Error_Pragma ("pragma% must specify array or record type"); end if; Check_First_Subtype (Arg1); if Has_Pragma_Pack (Typ) then Error_Pragma ("duplicate pragma%, only one allowed"); -- Array type elsif Is_Array_Type (Typ) then -- Pack not allowed for aliased or atomic components if Has_Aliased_Components (Base_Type (Typ)) then Error_Pragma ("pragma% ignored, cannot pack aliased components?"); elsif Has_Atomic_Components (Typ) or else Is_Atomic (Component_Type (Typ)) then Error_Pragma ("?pragma% ignored, cannot pack atomic components"); end if; -- If we had an explicit component size given, then we do not -- let Pack override this given size. We also give a warning -- that Pack is being ignored unless we can tell for sure that -- the Pack would not have had any effect anyway. if Has_Component_Size_Clause (Typ) then if Known_Static_RM_Size (Component_Type (Typ)) and then RM_Size (Component_Type (Typ)) = Component_Size (Typ) then null; else Error_Pragma ("?pragma% ignored, explicit component size given"); end if; -- If no prior array component size given, Pack is effective else if not Rep_Item_Too_Late (Typ, N) then Set_Is_Packed (Base_Type (Typ)); Set_Has_Pragma_Pack (Base_Type (Typ)); Set_Has_Non_Standard_Rep (Base_Type (Typ)); end if; end if; -- For record types, the pack is always effective else pragma Assert (Is_Record_Type (Typ)); if not Rep_Item_Too_Late (Typ, N) then Set_Has_Pragma_Pack (Base_Type (Typ)); Set_Is_Packed (Base_Type (Typ)); Set_Has_Non_Standard_Rep (Base_Type (Typ)); end if; end if; end Pack; ---------- -- Page -- ---------- -- pragma Page; -- There is nothing to do here, since we did all the processing -- for this pragma in Par.Prag (so that it works properly even in -- syntax only mode) when Pragma_Page => null; ------------- -- Passive -- ------------- -- pragma Passive [(PASSIVE_FORM)]; -- PASSIVE_FORM ::= Semaphore | No when Pragma_Passive => GNAT_Pragma; if Nkind (Parent (N)) /= N_Task_Definition then Error_Pragma ("pragma% must be within task definition"); end if; if Arg_Count /= 0 then Check_Arg_Count (1); Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No); end if; ------------- -- Polling -- ------------- -- pragma Polling (ON | OFF); when Pragma_Polling => GNAT_Pragma; Check_Arg_Count (1); Check_No_Identifiers; Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off); Polling_Required := (Chars (Expression (Arg1)) = Name_On); -------------------- -- Persistent_BSS -- -------------------- when Pragma_Persistent_BSS => Persistent_BSS : declare Decl : Node_Id; Ent : Entity_Id; Prag : Node_Id; begin GNAT_Pragma; Check_At_Most_N_Arguments (1); -- Case of application to specific object (one argument) if Arg_Count = 1 then Check_Arg_Is_Library_Level_Local_Name (Arg1); if not Is_Entity_Name (Expression (Arg1)) or else (Ekind (Entity (Expression (Arg1))) /= E_Variable and then Ekind (Entity (Expression (Arg1))) /= E_Constant) then Error_Pragma_Arg ("pragma% only applies to objects", Arg1); end if; Ent := Entity (Expression (Arg1)); Decl := Parent (Ent); if Rep_Item_Too_Late (Ent, N) then return; end if; if Present (Expression (Decl)) then Error_Pragma_Arg ("object for pragma% cannot have initialization", Arg1); end if; if not Is_Potentially_Persistent_Type (Etype (Ent)) then Error_Pragma_Arg ("object type for pragma% is not potentially persistent", Arg1); end if; Prag := Make_Linker_Section_Pragma (Ent, Sloc (N), ".persistent.bss"); Insert_After (N, Prag); Analyze (Prag); -- Case of use as configuration pragma with no arguments else Check_Valid_Configuration_Pragma; Persistent_BSS_Mode := True; end if; end Persistent_BSS; ------------------ -- Preelaborate -- ------------------ -- pragma Preelaborate [(library_unit_NAME)]; -- Set the flag Is_Preelaborated of program unit name entity when Pragma_Preelaborate => Preelaborate : declare Pa : constant Node_Id := Parent (N); Pk : constant Node_Kind := Nkind (Pa); Ent : Entity_Id; begin Check_Ada_83_Warning; Check_Valid_Library_Unit_Pragma; if Nkind (N) = N_Null_Statement then return; end if; Ent := Find_Lib_Unit_Name; -- This filters out pragmas inside generic parent then -- show up inside instantiation if Present (Ent) and then not (Pk = N_Package_Specification and then Present (Generic_Parent (Pa))) then if not Debug_Flag_U then Set_Is_Preelaborated (Ent); Set_Suppress_Elaboration_Warnings (Ent); end if; end if; end Preelaborate; --------------------- -- Preelaborate_05 -- --------------------- -- pragma Preelaborate_05 [(library_unit_NAME)]; -- This pragma is useable only in GNAT_Mode, where it is used like -- pragma Preelaborate but it is only effective in Ada 2005 mode -- (otherwise it is ignored). This is used to implement AI-362 which -- recategorizes some run-time packages in Ada 2005 mode. when Pragma_Preelaborate_05 => Preelaborate_05 : declare Ent : Entity_Id; begin GNAT_Pragma; Check_Valid_Library_Unit_Pragma; if not GNAT_Mode then Error_Pragma ("pragma% only available in GNAT mode"); end if; if Nkind (N) = N_Null_Statement then return; end if; -- This is one of the few cases where we need to test the value of -- Ada_Version_Explicit rather than Ada_Version (which is always -- set to Ada_05 in a predefined unit), we need to know the -- explicit version set to know if this pragma is active. if Ada_Version_Explicit >= Ada_05 then Ent := Find_Lib_Unit_Name; Set_Is_Preelaborated (Ent); Set_Suppress_Elaboration_Warnings (Ent); end if; end Preelaborate_05; -------------- -- Priority -- -------------- -- pragma Priority (EXPRESSION); when Pragma_Priority => Priority : declare P : constant Node_Id := Parent (N); Arg : Node_Id; begin Check_No_Identifiers; Check_Arg_Count (1); -- Subprogram case if Nkind (P) = N_Subprogram_Body then Check_In_Main_Program; Arg := Expression (Arg1); Analyze_And_Resolve (Arg, Standard_Integer); -- Must be static if not Is_Static_Expression (Arg) then Flag_Non_Static_Expr ("main subprogram priority is not static!", Arg); raise Pragma_Exit; -- If constraint error, then we already signalled an error elsif Raises_Constraint_Error (Arg) then null; -- Otherwise check in range else declare Val : constant Uint := Expr_Value (Arg); begin if Val < 0 or else Val > Expr_Value (Expression (Parent (RTE (RE_Max_Priority)))) then Error_Pragma_Arg ("main subprogram priority is out of range", Arg1); end if; end; end if; Set_Main_Priority (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg))); -- Task or Protected, must be of type Integer elsif Nkind (P) = N_Protected_Definition or else Nkind (P) = N_Task_Definition then Arg := Expression (Arg1); -- The expression must be analyzed in the special manner -- described in "Handling of Default and Per-Object -- Expressions" in sem.ads. Analyze_Per_Use_Expression (Arg, Standard_Integer); if not Is_Static_Expression (Arg) then Check_Restriction (Static_Priorities, Arg); end if; -- Anything else is incorrect else Pragma_Misplaced; end if; if Has_Priority_Pragma (P) then Error_Pragma ("duplicate pragma% not allowed"); else Set_Has_Priority_Pragma (P, True); if Nkind (P) = N_Protected_Definition or else Nkind (P) = N_Task_Definition then Record_Rep_Item (Defining_Identifier (Parent (P)), N); -- exp_ch9 should use this ??? end if; end if; end Priority; ------------- -- Profile -- ------------- -- pragma Profile (profile_IDENTIFIER); -- profile_IDENTIFIER => Protected | Ravenscar when Pragma_Profile => Check_Arg_Count (1); Check_Valid_Configuration_Pragma; Check_No_Identifiers; declare Argx : constant Node_Id := Get_Pragma_Arg (Arg1); begin if Chars (Argx) = Name_Ravenscar then Set_Ravenscar_Profile (N); elsif Chars (Argx) = Name_Restricted then Set_Profile_Restrictions (Restricted, N, Warn => False); else Error_Pragma_Arg ("& is not a valid profile", Argx); end if; end; ---------------------- -- Profile_Warnings -- ---------------------- -- pragma Profile_Warnings (profile_IDENTIFIER); -- profile_IDENTIFIER => Protected | Ravenscar when Pragma_Profile_Warnings => GNAT_Pragma; Check_Arg_Count (1); Check_Valid_Configuration_Pragma; Check_No_Identifiers; declare Argx : constant Node_Id := Get_Pragma_Arg (Arg1); begin if Chars (Argx) = Name_Ravenscar then Set_Profile_Restrictions (Ravenscar, N, Warn => True); elsif Chars (Argx) = Name_Restricted then Set_Profile_Restrictions (Restricted, N, Warn => True); else Error_Pragma_Arg ("& is not a valid profile", Argx); end if; end; -------------------------- -- Propagate_Exceptions -- -------------------------- -- pragma Propagate_Exceptions; -- Note: this pragma is obsolete and has no effect when Pragma_Propagate_Exceptions => GNAT_Pragma; Check_Arg_Count (0); if In_Extended_Main_Source_Unit (N) then Propagate_Exceptions := True; end if; ------------------ -- Psect_Object -- ------------------ -- pragma Psect_Object ( -- [Internal =>] LOCAL_NAME, -- [, [External =>] EXTERNAL_SYMBOL] -- [, [Size =>] EXTERNAL_SYMBOL]); when Pragma_Psect_Object | Pragma_Common_Object => Psect_Object : declare Args : Args_List (1 .. 3); Names : constant Name_List (1 .. 3) := ( Name_Internal, Name_External, Name_Size); Internal : Node_Id renames Args (1); External : Node_Id renames Args (2); Size : Node_Id renames Args (3); Def_Id : Entity_Id; procedure Check_Too_Long (Arg : Node_Id); -- Posts message if the argument is an identifier with more -- than 31 characters, or a string literal with more than -- 31 characters, and we are operating under VMS -------------------- -- Check_Too_Long -- -------------------- procedure Check_Too_Long (Arg : Node_Id) is X : constant Node_Id := Original_Node (Arg); begin if Nkind (X) /= N_String_Literal and then Nkind (X) /= N_Identifier then Error_Pragma_Arg ("inappropriate argument for pragma %", Arg); end if; if OpenVMS_On_Target then if (Nkind (X) = N_String_Literal and then String_Length (Strval (X)) > 31) or else (Nkind (X) = N_Identifier and then Length_Of_Name (Chars (X)) > 31) then Error_Pragma_Arg ("argument for pragma % is longer than 31 characters", Arg); end if; end if; end Check_Too_Long; -- Start of processing for Common_Object/Psect_Object begin GNAT_Pragma; Gather_Associations (Names, Args); Process_Extended_Import_Export_Internal_Arg (Internal); Def_Id := Entity (Internal); if Ekind (Def_Id) /= E_Constant and then Ekind (Def_Id) /= E_Variable then Error_Pragma_Arg ("pragma% must designate an object", Internal); end if; Check_Too_Long (Internal); if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then Error_Pragma_Arg ("cannot use pragma% for imported/exported object", Internal); end if; if Is_Concurrent_Type (Etype (Internal)) then Error_Pragma_Arg ("cannot specify pragma % for task/protected object", Internal); end if; if Has_Rep_Pragma (Def_Id, Name_Common_Object) or else Has_Rep_Pragma (Def_Id, Name_Psect_Object) then Error_Msg_N ("?duplicate Common/Psect_Object pragma", N); end if; if Ekind (Def_Id) = E_Constant then Error_Pragma_Arg ("cannot specify pragma % for a constant", Internal); end if; if Is_Record_Type (Etype (Internal)) then declare Ent : Entity_Id; Decl : Entity_Id; begin Ent := First_Entity (Etype (Internal)); while Present (Ent) loop Decl := Declaration_Node (Ent); if Ekind (Ent) = E_Component and then Nkind (Decl) = N_Component_Declaration and then Present (Expression (Decl)) and then Warn_On_Export_Import then Error_Msg_N ("?object for pragma % has defaults", Internal); exit; else Next_Entity (Ent); end if; end loop; end; end if; if Present (Size) then Check_Too_Long (Size); end if; if Present (External) then Check_Arg_Is_External_Name (External); Check_Too_Long (External); end if; -- If all error tests pass, link pragma on to the rep item chain Record_Rep_Item (Def_Id, N); end Psect_Object; ---------- -- Pure -- ---------- -- pragma Pure [(library_unit_NAME)]; when Pragma_Pure => Pure : declare Ent : Entity_Id; begin Check_Ada_83_Warning; Check_Valid_Library_Unit_Pragma; if Nkind (N) = N_Null_Statement then return; end if; Ent := Find_Lib_Unit_Name; Set_Is_Pure (Ent); Set_Has_Pragma_Pure (Ent); Set_Suppress_Elaboration_Warnings (Ent); end Pure; ------------- -- Pure_05 -- ------------- -- pragma Pure_05 [(library_unit_NAME)]; -- This pragma is useable only in GNAT_Mode, where it is used like -- pragma Pure but it is only effective in Ada 2005 mode (otherwise -- it is ignored). It may be used after a pragma Preelaborate, in -- which case it overrides the effect of the pragma Preelaborate. -- This is used to implement AI-362 which recategorizes some run-time -- packages in Ada 2005 mode. when Pragma_Pure_05 => Pure_05 : declare Ent : Entity_Id; begin GNAT_Pragma; Check_Valid_Library_Unit_Pragma; if not GNAT_Mode then Error_Pragma ("pragma% only available in GNAT mode"); end if; if Nkind (N) = N_Null_Statement then return; end if; -- This is one of the few cases where we need to test the value of -- Ada_Version_Explicit rather than Ada_Version (which is always -- set to Ada_05 in a predefined unit), we need to know the -- explicit version set to know if this pragma is active. if Ada_Version_Explicit >= Ada_05 then Ent := Find_Lib_Unit_Name; Set_Is_Preelaborated (Ent, False); Set_Is_Pure (Ent); Set_Suppress_Elaboration_Warnings (Ent); end if; end Pure_05; ------------------- -- Pure_Function -- ------------------- -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME); when Pragma_Pure_Function => Pure_Function : declare E_Id : Node_Id; E : Entity_Id; Def_Id : Entity_Id; Effective : Boolean := False; begin GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Local_Name (Arg1); E_Id := Expression (Arg1); if Error_Posted (E_Id) then return; end if; -- Loop through homonyms (overloadings) of referenced entity E := Entity (E_Id); if Present (E) then loop Def_Id := Get_Base_Subprogram (E); if Ekind (Def_Id) /= E_Function and then Ekind (Def_Id) /= E_Generic_Function and then Ekind (Def_Id) /= E_Operator then Error_Pragma_Arg ("pragma% requires a function name", Arg1); end if; Set_Is_Pure (Def_Id); if not Has_Pragma_Pure_Function (Def_Id) then Set_Has_Pragma_Pure_Function (Def_Id); Effective := True; end if; E := Homonym (E); exit when No (E) or else Scope (E) /= Current_Scope; end loop; if not Effective and then Warn_On_Redundant_Constructs then Error_Msg_NE ("pragma Pure_Function on& is redundant?", N, Entity (E_Id)); end if; end if; end Pure_Function; -------------------- -- Queuing_Policy -- -------------------- -- pragma Queuing_Policy (policy_IDENTIFIER); when Pragma_Queuing_Policy => declare QP : Character; begin Check_Ada_83_Warning; Check_Arg_Count (1); Check_No_Identifiers; Check_Arg_Is_Queuing_Policy (Arg1); Check_Valid_Configuration_Pragma; Get_Name_String (Chars (Expression (Arg1))); QP := Fold_Upper (Name_Buffer (1)); if Queuing_Policy /= ' ' and then Queuing_Policy /= QP then Error_Msg_Sloc := Queuing_Policy_Sloc; Error_Pragma ("queuing policy incompatible with policy#"); -- Set new policy, but always preserve System_Location since -- we like the error message with the run time name. else Queuing_Policy := QP; if Queuing_Policy_Sloc /= System_Location then Queuing_Policy_Sloc := Loc; end if; end if; end; --------------------------- -- Remote_Call_Interface -- --------------------------- -- pragma Remote_Call_Interface [(library_unit_NAME)]; when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare Cunit_Node : Node_Id; Cunit_Ent : Entity_Id; K : Node_Kind; begin Check_Ada_83_Warning; Check_Valid_Library_Unit_Pragma; if Nkind (N) = N_Null_Statement then return; end if; Cunit_Node := Cunit (Current_Sem_Unit); K := Nkind (Unit (Cunit_Node)); Cunit_Ent := Cunit_Entity (Current_Sem_Unit); if K = N_Package_Declaration or else K = N_Generic_Package_Declaration or else K = N_Subprogram_Declaration or else K = N_Generic_Subprogram_Declaration or else (K = N_Subprogram_Body and then Acts_As_Spec (Unit (Cunit_Node))) then null; else Error_Pragma ( "pragma% must apply to package or subprogram declaration"); end if; Set_Is_Remote_Call_Interface (Cunit_Ent); end Remote_Call_Interface; ------------------ -- Remote_Types -- ------------------ -- pragma Remote_Types [(library_unit_NAME)]; when Pragma_Remote_Types => Remote_Types : declare Cunit_Node : Node_Id; Cunit_Ent : Entity_Id; begin Check_Ada_83_Warning; Check_Valid_Library_Unit_Pragma; if Nkind (N) = N_Null_Statement then return; end if; Cunit_Node := Cunit (Current_Sem_Unit); Cunit_Ent := Cunit_Entity (Current_Sem_Unit); if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration and then Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration then Error_Pragma ( "pragma% can only apply to a package declaration"); end if; Set_Is_Remote_Types (Cunit_Ent); end Remote_Types; --------------- -- Ravenscar -- --------------- -- pragma Ravenscar; when Pragma_Ravenscar => GNAT_Pragma; Check_Arg_Count (0); Check_Valid_Configuration_Pragma; Set_Ravenscar_Profile (N); if Warn_On_Obsolescent_Feature then Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N); Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N); end if; ------------------------- -- Restricted_Run_Time -- ------------------------- -- pragma Restricted_Run_Time; when Pragma_Restricted_Run_Time => GNAT_Pragma; Check_Arg_Count (0); Check_Valid_Configuration_Pragma; Set_Profile_Restrictions (Restricted, N, Warn => False); if Warn_On_Obsolescent_Feature then Error_Msg_N ("pragma Restricted_Run_Time is an obsolescent feature?", N); Error_Msg_N ("|use pragma Profile (Restricted) instead", N); end if; ------------------ -- Restrictions -- ------------------ -- pragma Restrictions (RESTRICTION {, RESTRICTION}); -- RESTRICTION ::= -- restriction_IDENTIFIER -- | restriction_parameter_IDENTIFIER => EXPRESSION when Pragma_Restrictions => Process_Restrictions_Or_Restriction_Warnings; -------------------------- -- Restriction_Warnings -- -------------------------- -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION}); -- RESTRICTION ::= -- restriction_IDENTIFIER -- | restriction_parameter_IDENTIFIER => EXPRESSION when Pragma_Restriction_Warnings => Process_Restrictions_Or_Restriction_Warnings; ---------------- -- Reviewable -- ---------------- -- pragma Reviewable; when Pragma_Reviewable => Check_Ada_83_Warning; Check_Arg_Count (0); ------------------- -- Share_Generic -- ------------------- -- pragma Share_Generic (NAME {, NAME}); when Pragma_Share_Generic => GNAT_Pragma; Process_Generic_List; ------------ -- Shared -- ------------ -- pragma Shared (LOCAL_NAME); when Pragma_Shared => GNAT_Pragma; Process_Atomic_Shared_Volatile; -------------------- -- Shared_Passive -- -------------------- -- pragma Shared_Passive [(library_unit_NAME)]; -- Set the flag Is_Shared_Passive of program unit name entity when Pragma_Shared_Passive => Shared_Passive : declare Cunit_Node : Node_Id; Cunit_Ent : Entity_Id; begin Check_Ada_83_Warning; Check_Valid_Library_Unit_Pragma; if Nkind (N) = N_Null_Statement then return; end if; Cunit_Node := Cunit (Current_Sem_Unit); Cunit_Ent := Cunit_Entity (Current_Sem_Unit); if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration and then Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration then Error_Pragma ( "pragma% can only apply to a package declaration"); end if; Set_Is_Shared_Passive (Cunit_Ent); end Shared_Passive; ---------------------- -- Source_File_Name -- ---------------------- -- There are five forms for this pragma: -- pragma Source_File_Name ( -- [UNIT_NAME =>] unit_NAME, -- BODY_FILE_NAME => STRING_LITERAL -- [, [INDEX =>] INTEGER_LITERAL]); -- pragma Source_File_Name ( -- [UNIT_NAME =>] unit_NAME, -- SPEC_FILE_NAME => STRING_LITERAL -- [, [INDEX =>] INTEGER_LITERAL]); -- pragma Source_File_Name ( -- BODY_FILE_NAME => STRING_LITERAL -- [, DOT_REPLACEMENT => STRING_LITERAL] -- [, CASING => CASING_SPEC]); -- pragma Source_File_Name ( -- SPEC_FILE_NAME => STRING_LITERAL -- [, DOT_REPLACEMENT => STRING_LITERAL] -- [, CASING => CASING_SPEC]); -- pragma Source_File_Name ( -- SUBUNIT_FILE_NAME => STRING_LITERAL -- [, DOT_REPLACEMENT => STRING_LITERAL] -- [, CASING => CASING_SPEC]); -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma -- Source_File_Name (SFN), however their usage is exclusive: -- SFN can only be used when no project file is used, while -- SFNP can only be used when a project file is used. -- No processing here. Processing was completed during parsing, -- since we need to have file names set as early as possible. -- Units are loaded well before semantic processing starts. -- The only processing we defer to this point is the check -- for correct placement. when Pragma_Source_File_Name => GNAT_Pragma; Check_Valid_Configuration_Pragma; ------------------------------ -- Source_File_Name_Project -- ------------------------------ -- See Source_File_Name for syntax -- No processing here. Processing was completed during parsing, -- since we need to have file names set as early as possible. -- Units are loaded well before semantic processing starts. -- The only processing we defer to this point is the check -- for correct placement. when Pragma_Source_File_Name_Project => GNAT_Pragma; Check_Valid_Configuration_Pragma; -- Check that a pragma Source_File_Name_Project is used only -- in a configuration pragmas file. -- Pragmas Source_File_Name_Project should only be generated -- by the Project Manager in configuration pragmas files. -- This is really an ugly test. It seems to depend on some -- accidental and undocumented property. At the very least -- it needs to be documented, but it would be better to have -- a clean way of testing if we are in a configuration file??? if Present (Parent (N)) then Error_Pragma ("pragma% can only appear in a configuration pragmas file"); end if; ---------------------- -- Source_Reference -- ---------------------- -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]); -- Nothing to do, all processing completed in Par.Prag, since we -- need the information for possible parser messages that are output when Pragma_Source_Reference => GNAT_Pragma; ------------------ -- Storage_Size -- ------------------ -- pragma Storage_Size (EXPRESSION); when Pragma_Storage_Size => Storage_Size : declare P : constant Node_Id := Parent (N); Arg : Node_Id; begin Check_No_Identifiers; Check_Arg_Count (1); -- The expression must be analyzed in the special manner -- described in "Handling of Default Expressions" in sem.ads. -- Set In_Default_Expression for per-object case ??? Arg := Expression (Arg1); Analyze_Per_Use_Expression (Arg, Any_Integer); if not Is_Static_Expression (Arg) then Check_Restriction (Static_Storage_Size, Arg); end if; if Nkind (P) /= N_Task_Definition then Pragma_Misplaced; return; else if Has_Storage_Size_Pragma (P) then Error_Pragma ("duplicate pragma% not allowed"); else Set_Has_Storage_Size_Pragma (P, True); end if; Record_Rep_Item (Defining_Identifier (Parent (P)), N); -- ??? exp_ch9 should use this! end if; end Storage_Size; ------------------ -- Storage_Unit -- ------------------ -- pragma Storage_Unit (NUMERIC_LITERAL); -- Only permitted argument is System'Storage_Unit value when Pragma_Storage_Unit => Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_Integer_Literal (Arg1); if Intval (Expression (Arg1)) /= UI_From_Int (Ttypes.System_Storage_Unit) then Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit); Error_Pragma_Arg ("the only allowed argument for pragma% is ^", Arg1); end if; -------------------- -- Stream_Convert -- -------------------- -- pragma Stream_Convert ( -- [Entity =>] type_LOCAL_NAME, -- [Read =>] function_NAME, -- [Write =>] function NAME); when Pragma_Stream_Convert => Stream_Convert : declare procedure Check_OK_Stream_Convert_Function (Arg : Node_Id); -- Check that the given argument is the name of a local -- function of one argument that is not overloaded earlier -- in the current local scope. A check is also made that the -- argument is a function with one parameter. -------------------------------------- -- Check_OK_Stream_Convert_Function -- -------------------------------------- procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is Ent : Entity_Id; begin Check_Arg_Is_Local_Name (Arg); Ent := Entity (Expression (Arg)); if Has_Homonym (Ent) then Error_Pragma_Arg ("argument for pragma% may not be overloaded", Arg); end if; if Ekind (Ent) /= E_Function or else No (First_Formal (Ent)) or else Present (Next_Formal (First_Formal (Ent))) then Error_Pragma_Arg ("argument for pragma% must be" & " function of one argument", Arg); end if; end Check_OK_Stream_Convert_Function; -- Start of procecessing for Stream_Convert begin GNAT_Pragma; Check_Arg_Order ((Name_Entity, Name_Read, Name_Write)); Check_Arg_Count (3); Check_Optional_Identifier (Arg1, Name_Entity); Check_Optional_Identifier (Arg2, Name_Read); Check_Optional_Identifier (Arg3, Name_Write); Check_Arg_Is_Local_Name (Arg1); Check_OK_Stream_Convert_Function (Arg2); Check_OK_Stream_Convert_Function (Arg3); declare Typ : constant Entity_Id := Underlying_Type (Entity (Expression (Arg1))); Read : constant Entity_Id := Entity (Expression (Arg2)); Write : constant Entity_Id := Entity (Expression (Arg3)); begin if Etype (Typ) = Any_Type or else Etype (Read) = Any_Type or else Etype (Write) = Any_Type then return; end if; Check_First_Subtype (Arg1); if Rep_Item_Too_Early (Typ, N) or else Rep_Item_Too_Late (Typ, N) then return; end if; if Underlying_Type (Etype (Read)) /= Typ then Error_Pragma_Arg ("incorrect return type for function&", Arg2); end if; if Underlying_Type (Etype (First_Formal (Write))) /= Typ then Error_Pragma_Arg ("incorrect parameter type for function&", Arg3); end if; if Underlying_Type (Etype (First_Formal (Read))) /= Underlying_Type (Etype (Write)) then Error_Pragma_Arg ("result type of & does not match Read parameter type", Arg3); end if; end; end Stream_Convert; ------------------------- -- Style_Checks (GNAT) -- ------------------------- -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL); -- This is processed by the parser since some of the style -- checks take place during source scanning and parsing. This -- means that we don't need to issue error messages here. when Pragma_Style_Checks => Style_Checks : declare A : constant Node_Id := Expression (Arg1); S : String_Id; C : Char_Code; begin GNAT_Pragma; Check_No_Identifiers; -- Two argument form if Arg_Count = 2 then Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off); declare E_Id : Node_Id; E : Entity_Id; begin E_Id := Expression (Arg2); Analyze (E_Id); if not Is_Entity_Name (E_Id) then Error_Pragma_Arg ("second argument of pragma% must be entity name", Arg2); end if; E := Entity (E_Id); if E = Any_Id then return; else loop Set_Suppress_Style_Checks (E, (Chars (Expression (Arg1)) = Name_Off)); exit when No (Homonym (E)); E := Homonym (E); end loop; end if; end; -- One argument form else Check_Arg_Count (1); if Nkind (A) = N_String_Literal then S := Strval (A); declare Slen : constant Natural := Natural (String_Length (S)); Options : String (1 .. Slen); J : Natural; begin J := 1; loop C := Get_String_Char (S, Int (J)); exit when not In_Character_Range (C); Options (J) := Get_Character (C); -- If at end of string, set options. As per discussion -- above, no need to check for errors, since we issued -- them in the parser. if J = Slen then Set_Style_Check_Options (Options); exit; end if; J := J + 1; end loop; end; elsif Nkind (A) = N_Identifier then if Chars (A) = Name_All_Checks then Set_Default_Style_Check_Options; elsif Chars (A) = Name_On then Style_Check := True; elsif Chars (A) = Name_Off then Style_Check := False; end if; end if; end if; end Style_Checks; -------------- -- Subtitle -- -------------- -- pragma Subtitle ([Subtitle =>] STRING_LITERAL); when Pragma_Subtitle => GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Subtitle); Check_Arg_Is_String_Literal (Arg1); -------------- -- Suppress -- -------------- -- pragma Suppress (IDENTIFIER [, [On =>] NAME]); when Pragma_Suppress => Process_Suppress_Unsuppress (True); ------------------ -- Suppress_All -- ------------------ -- pragma Suppress_All; -- The only check made here is that the pragma appears in the -- proper place, i.e. following a compilation unit. If indeed -- it appears in this context, then the parser has already -- inserted an equivalent pragma Suppress (All_Checks) to get -- the required effect. when Pragma_Suppress_All => GNAT_Pragma; Check_Arg_Count (0); if Nkind (Parent (N)) /= N_Compilation_Unit_Aux or else not Is_List_Member (N) or else List_Containing (N) /= Pragmas_After (Parent (N)) then Error_Pragma ("misplaced pragma%, must follow compilation unit"); end if; ------------------------- -- Suppress_Debug_Info -- ------------------------- -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME); when Pragma_Suppress_Debug_Info => GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Local_Name (Arg1); Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1))); ---------------------------------- -- Suppress_Exception_Locations -- ---------------------------------- -- pragma Suppress_Exception_Locations; when Pragma_Suppress_Exception_Locations => GNAT_Pragma; Check_Arg_Count (0); Check_Valid_Configuration_Pragma; Exception_Locations_Suppressed := True; ----------------------------- -- Suppress_Initialization -- ----------------------------- -- pragma Suppress_Initialization ([Entity =>] type_Name); when Pragma_Suppress_Initialization => Suppress_Init : declare E_Id : Node_Id; E : Entity_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Local_Name (Arg1); E_Id := Expression (Arg1); if Etype (E_Id) = Any_Type then return; end if; E := Entity (E_Id); if Is_Type (E) then if Is_Incomplete_Or_Private_Type (E) then if No (Full_View (Base_Type (E))) then Error_Pragma_Arg ("argument of pragma% cannot be an incomplete type", Arg1); else Set_Suppress_Init_Proc (Full_View (Base_Type (E))); end if; else Set_Suppress_Init_Proc (Base_Type (E)); end if; else Error_Pragma_Arg ("pragma% requires argument that is a type name", Arg1); end if; end Suppress_Init; ----------------- -- System_Name -- ----------------- -- pragma System_Name (DIRECT_NAME); -- Syntax check: one argument, which must be the identifier GNAT -- or the identifier GCC, no other identifiers are acceptable. when Pragma_System_Name => Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat); ----------------------------- -- Task_Dispatching_Policy -- ----------------------------- -- pragma Task_Dispatching_Policy (policy_IDENTIFIER); when Pragma_Task_Dispatching_Policy => declare DP : Character; begin Check_Ada_83_Warning; Check_Arg_Count (1); Check_No_Identifiers; Check_Arg_Is_Task_Dispatching_Policy (Arg1); Check_Valid_Configuration_Pragma; Get_Name_String (Chars (Expression (Arg1))); DP := Fold_Upper (Name_Buffer (1)); if Task_Dispatching_Policy /= ' ' and then Task_Dispatching_Policy /= DP then Error_Msg_Sloc := Task_Dispatching_Policy_Sloc; Error_Pragma ("task dispatching policy incompatible with policy#"); -- Set new policy, but always preserve System_Location since -- we like the error message with the run time name. else Task_Dispatching_Policy := DP; if Task_Dispatching_Policy_Sloc /= System_Location then Task_Dispatching_Policy_Sloc := Loc; end if; end if; end; -------------- -- Task_Info -- -------------- -- pragma Task_Info (EXPRESSION); when Pragma_Task_Info => Task_Info : declare P : constant Node_Id := Parent (N); begin GNAT_Pragma; if Nkind (P) /= N_Task_Definition then Error_Pragma ("pragma% must appear in task definition"); end if; Check_No_Identifiers; Check_Arg_Count (1); Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type)); if Etype (Expression (Arg1)) = Any_Type then return; end if; if Has_Task_Info_Pragma (P) then Error_Pragma ("duplicate pragma% not allowed"); else Set_Has_Task_Info_Pragma (P, True); end if; end Task_Info; --------------- -- Task_Name -- --------------- -- pragma Task_Name (string_EXPRESSION); when Pragma_Task_Name => Task_Name : declare -- pragma Priority (EXPRESSION); P : constant Node_Id := Parent (N); Arg : Node_Id; begin Check_No_Identifiers; Check_Arg_Count (1); Arg := Expression (Arg1); Analyze_And_Resolve (Arg, Standard_String); if Nkind (P) /= N_Task_Definition then Pragma_Misplaced; end if; if Has_Task_Name_Pragma (P) then Error_Pragma ("duplicate pragma% not allowed"); else Set_Has_Task_Name_Pragma (P, True); Record_Rep_Item (Defining_Identifier (Parent (P)), N); end if; end Task_Name; ------------------ -- Task_Storage -- ------------------ -- pragma Task_Storage ( -- [Task_Type =>] LOCAL_NAME, -- [Top_Guard =>] static_integer_EXPRESSION); when Pragma_Task_Storage => Task_Storage : declare Args : Args_List (1 .. 2); Names : constant Name_List (1 .. 2) := ( Name_Task_Type, Name_Top_Guard); Task_Type : Node_Id renames Args (1); Top_Guard : Node_Id renames Args (2); Ent : Entity_Id; begin GNAT_Pragma; Gather_Associations (Names, Args); if No (Task_Type) then Error_Pragma ("missing task_type argument for pragma%"); end if; Check_Arg_Is_Local_Name (Task_Type); Ent := Entity (Task_Type); if not Is_Task_Type (Ent) then Error_Pragma_Arg ("argument for pragma% must be task type", Task_Type); end if; if No (Top_Guard) then Error_Pragma_Arg ("pragma% takes two arguments", Task_Type); else Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer); end if; Check_First_Subtype (Task_Type); if Rep_Item_Too_Late (Ent, N) then raise Pragma_Exit; end if; end Task_Storage; ----------------- -- Thread_Body -- ----------------- -- pragma Thread_Body -- ( [Entity =>] LOCAL_NAME -- [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]); when Pragma_Thread_Body => Thread_Body : declare Id : Node_Id; SS : Node_Id; E : Entity_Id; begin GNAT_Pragma; Check_Arg_Order ((Name_Entity, Name_Secondary_Stack_Size)); Check_At_Least_N_Arguments (1); Check_At_Most_N_Arguments (2); Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Local_Name (Arg1); Id := Expression (Arg1); if not Is_Entity_Name (Id) or else not Is_Subprogram (Entity (Id)) then Error_Pragma_Arg ("subprogram name required", Arg1); end if; E := Entity (Id); -- Go to renamed subprogram if present, since Thread_Body applies -- to the actual renamed entity, not to the renaming entity. if Present (Alias (E)) and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Renaming_Declaration then E := Alias (E); end if; -- Various error checks if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then Error_Pragma ("pragma% requires separate spec and must come before body"); elsif Rep_Item_Too_Early (E, N) or else Rep_Item_Too_Late (E, N) then raise Pragma_Exit; elsif Is_Thread_Body (E) then Error_Pragma_Arg ("only one thread body pragma allowed", Arg1); elsif Present (Homonym (E)) and then Scope (Homonym (E)) = Current_Scope then Error_Pragma_Arg ("thread body subprogram must not be overloaded", Arg1); end if; Set_Is_Thread_Body (E); -- Deal with secondary stack argument if Arg_Count = 2 then Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size); SS := Expression (Arg2); Analyze_And_Resolve (SS, Any_Integer); end if; end Thread_Body; ---------------- -- Time_Slice -- ---------------- -- pragma Time_Slice (static_duration_EXPRESSION); when Pragma_Time_Slice => Time_Slice : declare Val : Ureal; Nod : Node_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_No_Identifiers; Check_In_Main_Program; Check_Arg_Is_Static_Expression (Arg1, Standard_Duration); if not Error_Posted (Arg1) then Nod := Next (N); while Present (Nod) loop if Nkind (Nod) = N_Pragma and then Chars (Nod) = Name_Time_Slice then Error_Msg_Name_1 := Chars (N); Error_Msg_N ("duplicate pragma% not permitted", Nod); end if; Next (Nod); end loop; end if; -- Process only if in main unit if Get_Source_Unit (Loc) = Main_Unit then Opt.Time_Slice_Set := True; Val := Expr_Value_R (Expression (Arg1)); if Val <= Ureal_0 then Opt.Time_Slice_Value := 0; elsif Val > UR_From_Uint (UI_From_Int (1000)) then Opt.Time_Slice_Value := 1_000_000_000; else Opt.Time_Slice_Value := UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000))); end if; end if; end Time_Slice; ----------- -- Title -- ----------- -- pragma Title (TITLING_OPTION [, TITLING OPTION]); -- TITLING_OPTION ::= -- [Title =>] STRING_LITERAL -- | [Subtitle =>] STRING_LITERAL when Pragma_Title => Title : declare Args : Args_List (1 .. 2); Names : constant Name_List (1 .. 2) := ( Name_Title, Name_Subtitle); begin GNAT_Pragma; Gather_Associations (Names, Args); for J in 1 .. 2 loop if Present (Args (J)) then Check_Arg_Is_String_Literal (Args (J)); end if; end loop; end Title; --------------------- -- Unchecked_Union -- --------------------- -- pragma Unchecked_Union (first_subtype_LOCAL_NAME) when Pragma_Unchecked_Union => Unchecked_Union : declare Assoc : constant Node_Id := Arg1; Type_Id : constant Node_Id := Expression (Assoc); Typ : Entity_Id; Discr : Entity_Id; Tdef : Node_Id; Clist : Node_Id; Vpart : Node_Id; Comp : Node_Id; Variant : Node_Id; begin GNAT_Pragma; Check_No_Identifiers; Check_Arg_Count (1); Check_Arg_Is_Local_Name (Arg1); Find_Type (Type_Id); Typ := Entity (Type_Id); if Typ = Any_Type or else Rep_Item_Too_Early (Typ, N) then return; else Typ := Underlying_Type (Typ); end if; if Rep_Item_Too_Late (Typ, N) then return; end if; Check_First_Subtype (Arg1); -- Note remaining cases are references to a type in the current -- declarative part. If we find an error, we post the error on -- the relevant type declaration at an appropriate point. if not Is_Record_Type (Typ) then Error_Msg_N ("Unchecked_Union must be record type", Typ); return; elsif Is_Tagged_Type (Typ) then Error_Msg_N ("Unchecked_Union must not be tagged", Typ); return; elsif Is_Limited_Type (Typ) then Error_Msg_N ("Unchecked_Union must not be limited record type", Typ); Explain_Limited_Type (Typ, Typ); return; else if not Has_Discriminants (Typ) then Error_Msg_N ("Unchecked_Union must have one discriminant", Typ); return; end if; Discr := First_Discriminant (Typ); while Present (Discr) loop if No (Discriminant_Default_Value (Discr)) then Error_Msg_N ("Unchecked_Union discriminant must have default value", Discr); end if; Next_Discriminant (Discr); end loop; Tdef := Type_Definition (Declaration_Node (Typ)); Clist := Component_List (Tdef); Comp := First (Component_Items (Clist)); while Present (Comp) loop Check_Component (Comp); Next (Comp); end loop; if No (Clist) or else No (Variant_Part (Clist)) then Error_Msg_N ("Unchecked_Union must have variant part", Tdef); return; end if; Vpart := Variant_Part (Clist); Variant := First (Variants (Vpart)); while Present (Variant) loop Check_Variant (Variant); Next (Variant); end loop; end if; Set_Is_Unchecked_Union (Typ, True); Set_Convention (Typ, Convention_C); Set_Has_Unchecked_Union (Base_Type (Typ), True); Set_Is_Unchecked_Union (Base_Type (Typ), True); end Unchecked_Union; ------------------------ -- Unimplemented_Unit -- ------------------------ -- pragma Unimplemented_Unit; -- Note: this only gives an error if we are generating code, -- or if we are in a generic library unit (where the pragma -- appears in the body, not in the spec). when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare Cunitent : constant Entity_Id := Cunit_Entity (Get_Source_Unit (Loc)); Ent_Kind : constant Entity_Kind := Ekind (Cunitent); begin GNAT_Pragma; Check_Arg_Count (0); if Operating_Mode = Generate_Code or else Ent_Kind = E_Generic_Function or else Ent_Kind = E_Generic_Procedure or else Ent_Kind = E_Generic_Package then Get_Name_String (Chars (Cunitent)); Set_Casing (Mixed_Case); Write_Str (Name_Buffer (1 .. Name_Len)); Write_Str (" is not implemented"); Write_Eol; raise Unrecoverable_Error; end if; end Unimplemented_Unit; -------------------- -- Universal_Data -- -------------------- -- pragma Universal_Data [(library_unit_NAME)]; when Pragma_Universal_Data => GNAT_Pragma; -- If this is a configuration pragma, then set the universal -- addressing option, otherwise confirm that the pragma -- satisfies the requirements of library unit pragma placement -- and leave it to the GNAAMP back end to detect the pragma -- (avoids transitive setting of the option due to withed units). if Is_Configuration_Pragma then Universal_Addressing_On_AAMP := True; else Check_Valid_Library_Unit_Pragma; end if; if not AAMP_On_Target then Error_Pragma ("?pragma% ignored (applies only to AAMP)"); end if; ------------------ -- Unreferenced -- ------------------ -- pragma Unreferenced (local_Name {, local_Name}); when Pragma_Unreferenced => Unreferenced : declare Arg_Node : Node_Id; Arg_Expr : Node_Id; Arg_Ent : Entity_Id; begin GNAT_Pragma; Check_At_Least_N_Arguments (1); Arg_Node := Arg1; while Present (Arg_Node) loop Check_No_Identifier (Arg_Node); -- Note that the analyze call done by Check_Arg_Is_Local_Name -- will in fact generate a reference, so that the entity will -- have a reference, which will inhibit any warnings about it -- not being referenced, and also properly show up in the ali -- file as a reference. But this reference is recorded before -- the Has_Pragma_Unreferenced flag is set, so that no warning -- is generated for this reference. Check_Arg_Is_Local_Name (Arg_Node); Arg_Expr := Get_Pragma_Arg (Arg_Node); if Is_Entity_Name (Arg_Expr) then Arg_Ent := Entity (Arg_Expr); -- If the entity is overloaded, the pragma applies to the -- most recent overloading, as documented. In this case, -- name resolution does not generate a reference, so it -- must be done here explicitly. if Is_Overloaded (Arg_Expr) then Generate_Reference (Arg_Ent, N); end if; Set_Has_Pragma_Unreferenced (Arg_Ent); end if; Next (Arg_Node); end loop; end Unreferenced; ------------------------------ -- Unreserve_All_Interrupts -- ------------------------------ -- pragma Unreserve_All_Interrupts; when Pragma_Unreserve_All_Interrupts => GNAT_Pragma; Check_Arg_Count (0); if In_Extended_Main_Code_Unit (Main_Unit_Entity) then Unreserve_All_Interrupts := True; end if; ---------------- -- Unsuppress -- ---------------- -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]); when Pragma_Unsuppress => GNAT_Pragma; Process_Suppress_Unsuppress (False); ------------------- -- Use_VADS_Size -- ------------------- -- pragma Use_VADS_Size; when Pragma_Use_VADS_Size => GNAT_Pragma; Check_Arg_Count (0); Check_Valid_Configuration_Pragma; Use_VADS_Size := True; --------------------- -- Validity_Checks -- --------------------- -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL); when Pragma_Validity_Checks => Validity_Checks : declare A : constant Node_Id := Expression (Arg1); S : String_Id; C : Char_Code; begin GNAT_Pragma; Check_Arg_Count (1); Check_No_Identifiers; if Nkind (A) = N_String_Literal then S := Strval (A); declare Slen : constant Natural := Natural (String_Length (S)); Options : String (1 .. Slen); J : Natural; begin J := 1; loop C := Get_String_Char (S, Int (J)); exit when not In_Character_Range (C); Options (J) := Get_Character (C); if J = Slen then Set_Validity_Check_Options (Options); exit; else J := J + 1; end if; end loop; end; elsif Nkind (A) = N_Identifier then if Chars (A) = Name_All_Checks then Set_Validity_Check_Options ("a"); elsif Chars (A) = Name_On then Validity_Checks_On := True; elsif Chars (A) = Name_Off then Validity_Checks_On := False; end if; end if; end Validity_Checks; -------------- -- Volatile -- -------------- -- pragma Volatile (LOCAL_NAME); when Pragma_Volatile => Process_Atomic_Shared_Volatile; ------------------------- -- Volatile_Components -- ------------------------- -- pragma Volatile_Components (array_LOCAL_NAME); -- Volatile is handled by the same circuit as Atomic_Components -------------- -- Warnings -- -------------- -- pragma Warnings (On | Off, [LOCAL_NAME]) -- pragma Warnings (static_string_EXPRESSION); when Pragma_Warnings => Warnings : begin GNAT_Pragma; Check_At_Least_N_Arguments (1); Check_No_Identifiers; -- One argument case if Arg_Count = 1 then declare Argx : constant Node_Id := Get_Pragma_Arg (Arg1); begin -- On/Off one argument case was processed by parser if Nkind (Argx) = N_Identifier and then (Chars (Argx) = Name_On or else Chars (Argx) = Name_Off) then null; else Check_Arg_Is_Static_Expression (Arg1, Standard_String); declare Lit : constant Node_Id := Expr_Value_S (Argx); Str : constant String_Id := Strval (Lit); C : Char_Code; begin for J in 1 .. String_Length (Str) loop C := Get_String_Char (Str, J); if In_Character_Range (C) and then Set_Warning_Switch (Get_Character (C)) then null; else Error_Pragma_Arg ("invalid warning switch character", Arg1); end if; end loop; end; end if; end; -- Two argument case elsif Arg_Count /= 1 then Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off); Check_Arg_Count (2); declare E_Id : Node_Id; E : Entity_Id; begin E_Id := Expression (Arg2); Analyze (E_Id); -- In the expansion of an inlined body, a reference to -- the formal may be wrapped in a conversion if the actual -- is a conversion. Retrieve the real entity name. if (In_Instance_Body or else In_Inlined_Body) and then Nkind (E_Id) = N_Unchecked_Type_Conversion then E_Id := Expression (E_Id); end if; if not Is_Entity_Name (E_Id) then Error_Pragma_Arg ("second argument of pragma% must be entity name", Arg2); end if; E := Entity (E_Id); if E = Any_Id then return; else loop Set_Warnings_Off (E, (Chars (Expression (Arg1)) = Name_Off)); if Is_Enumeration_Type (E) then declare Lit : Entity_Id; begin Lit := First_Literal (E); while Present (Lit) loop Set_Warnings_Off (Lit); Next_Literal (Lit); end loop; end; end if; exit when No (Homonym (E)); E := Homonym (E); end loop; end if; end; -- More than two arguments else Check_At_Most_N_Arguments (2); end if; end Warnings; ------------------- -- Weak_External -- ------------------- -- pragma Weak_External ([Entity =>] LOCAL_NAME); when Pragma_Weak_External => Weak_External : declare Ent : Entity_Id; begin GNAT_Pragma; Check_Arg_Count (1); Check_Optional_Identifier (Arg1, Name_Entity); Check_Arg_Is_Library_Level_Local_Name (Arg1); Ent := Entity (Expression (Arg1)); if Rep_Item_Too_Early (Ent, N) then return; else Ent := Underlying_Type (Ent); end if; -- The only processing required is to link this item on to the -- list of rep items for the given entity. This is accomplished -- by the call to Rep_Item_Too_Late (when no error is detected -- and False is returned). if Rep_Item_Too_Late (Ent, N) then return; else Set_Has_Gigi_Rep_Item (Ent); end if; end Weak_External; -------------------- -- Unknown_Pragma -- -------------------- -- Should be impossible, since the case of an unknown pragma is -- separately processed before the case statement is entered. when Unknown_Pragma => raise Program_Error; end case; exception when Pragma_Exit => null; end Analyze_Pragma; --------------------------------- -- Delay_Config_Pragma_Analyze -- --------------------------------- function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is begin return Chars (N) = Name_Interrupt_State; end Delay_Config_Pragma_Analyze; ------------------------- -- Get_Base_Subprogram -- ------------------------- function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is Result : Entity_Id; begin -- Follow subprogram renaming chain Result := Def_Id; while Is_Subprogram (Result) and then (Is_Generic_Instance (Result) or else Nkind (Parent (Declaration_Node (Result))) = N_Subprogram_Renaming_Declaration) and then Present (Alias (Result)) loop Result := Alias (Result); end loop; return Result; end Get_Base_Subprogram; ----------------------------- -- Is_Config_Static_String -- ----------------------------- function Is_Config_Static_String (Arg : Node_Id) return Boolean is function Add_Config_Static_String (Arg : Node_Id) return Boolean; -- This is an internal recursive function that is just like the -- outer function except that it adds the string to the name buffer -- rather than placing the string in the name buffer. ------------------------------ -- Add_Config_Static_String -- ------------------------------ function Add_Config_Static_String (Arg : Node_Id) return Boolean is N : Node_Id; C : Char_Code; begin N := Arg; if Nkind (N) = N_Op_Concat then if Add_Config_Static_String (Left_Opnd (N)) then N := Right_Opnd (N); else return False; end if; end if; if Nkind (N) /= N_String_Literal then Error_Msg_N ("string literal expected for pragma argument", N); return False; else for J in 1 .. String_Length (Strval (N)) loop C := Get_String_Char (Strval (N), J); if not In_Character_Range (C) then Error_Msg ("string literal contains invalid wide character", Sloc (N) + 1 + Source_Ptr (J)); return False; end if; Add_Char_To_Name_Buffer (Get_Character (C)); end loop; end if; return True; end Add_Config_Static_String; -- Start of prorcessing for Is_Config_Static_String begin Name_Len := 0; return Add_Config_Static_String (Arg); end Is_Config_Static_String; ----------------------------------------- -- Is_Non_Significant_Pragma_Reference -- ----------------------------------------- -- This function makes use of the following static table which indicates -- whether a given pragma is significant. A value of -1 in this table -- indicates that the reference is significant. A value of zero indicates -- than appearence as any argument is insignificant, a positive value -- indicates that appearence in that parameter position is significant. Sig_Flags : constant array (Pragma_Id) of Int := (Pragma_AST_Entry => -1, Pragma_Abort_Defer => -1, Pragma_Ada_83 => -1, Pragma_Ada_95 => -1, Pragma_Ada_05 => -1, Pragma_Ada_2005 => -1, Pragma_All_Calls_Remote => -1, Pragma_Annotate => -1, Pragma_Assert => -1, Pragma_Assertion_Policy => 0, Pragma_Asynchronous => -1, Pragma_Atomic => 0, Pragma_Atomic_Components => 0, Pragma_Attach_Handler => -1, Pragma_CPP_Class => 0, Pragma_CPP_Constructor => 0, Pragma_CPP_Virtual => 0, Pragma_CPP_Vtable => 0, Pragma_C_Pass_By_Copy => 0, Pragma_Comment => 0, Pragma_Common_Object => -1, Pragma_Compile_Time_Warning => -1, Pragma_Complete_Representation => 0, Pragma_Complex_Representation => 0, Pragma_Component_Alignment => -1, Pragma_Controlled => 0, Pragma_Convention => 0, Pragma_Convention_Identifier => 0, Pragma_Debug => -1, Pragma_Debug_Policy => 0, Pragma_Detect_Blocking => -1, Pragma_Discard_Names => 0, Pragma_Elaborate => -1, Pragma_Elaborate_All => -1, Pragma_Elaborate_Body => -1, Pragma_Elaboration_Checks => -1, Pragma_Eliminate => -1, Pragma_Explicit_Overriding => -1, Pragma_Export => -1, Pragma_Export_Exception => -1, Pragma_Export_Function => -1, Pragma_Export_Object => -1, Pragma_Export_Procedure => -1, Pragma_Export_Value => -1, Pragma_Export_Valued_Procedure => -1, Pragma_Extend_System => -1, Pragma_Extensions_Allowed => -1, Pragma_External => -1, Pragma_External_Name_Casing => -1, Pragma_Finalize_Storage_Only => 0, Pragma_Float_Representation => 0, Pragma_Ident => -1, Pragma_Import => +2, Pragma_Import_Exception => 0, Pragma_Import_Function => 0, Pragma_Import_Object => 0, Pragma_Import_Procedure => 0, Pragma_Import_Valued_Procedure => 0, Pragma_Initialize_Scalars => -1, Pragma_Inline => 0, Pragma_Inline_Always => 0, Pragma_Inline_Generic => 0, Pragma_Inspection_Point => -1, Pragma_Interface => +2, Pragma_Interface_Name => +2, Pragma_Interrupt_Handler => -1, Pragma_Interrupt_Priority => -1, Pragma_Interrupt_State => -1, Pragma_Java_Constructor => -1, Pragma_Java_Interface => -1, Pragma_Keep_Names => 0, Pragma_License => -1, Pragma_Link_With => -1, Pragma_Linker_Alias => -1, Pragma_Linker_Constructor => -1, Pragma_Linker_Destructor => -1, Pragma_Linker_Options => -1, Pragma_Linker_Section => -1, Pragma_List => -1, Pragma_Locking_Policy => -1, Pragma_Long_Float => -1, Pragma_Machine_Attribute => -1, Pragma_Main => -1, Pragma_Main_Storage => -1, Pragma_Memory_Size => -1, Pragma_No_Return => 0, Pragma_No_Run_Time => -1, Pragma_No_Strict_Aliasing => -1, Pragma_Normalize_Scalars => -1, Pragma_Obsolescent => 0, Pragma_Optimize => -1, Pragma_Optional_Overriding => -1, Pragma_Pack => 0, Pragma_Page => -1, Pragma_Passive => -1, Pragma_Polling => -1, Pragma_Persistent_BSS => 0, Pragma_Preelaborate => -1, Pragma_Preelaborate_05 => -1, Pragma_Priority => -1, Pragma_Profile => 0, Pragma_Profile_Warnings => 0, Pragma_Propagate_Exceptions => -1, Pragma_Psect_Object => -1, Pragma_Pure => -1, Pragma_Pure_05 => -1, Pragma_Pure_Function => -1, Pragma_Queuing_Policy => -1, Pragma_Ravenscar => -1, Pragma_Remote_Call_Interface => -1, Pragma_Remote_Types => -1, Pragma_Restricted_Run_Time => -1, Pragma_Restriction_Warnings => -1, Pragma_Restrictions => -1, Pragma_Reviewable => -1, Pragma_Share_Generic => -1, Pragma_Shared => -1, Pragma_Shared_Passive => -1, Pragma_Source_File_Name => -1, Pragma_Source_File_Name_Project => -1, Pragma_Source_Reference => -1, Pragma_Storage_Size => -1, Pragma_Storage_Unit => -1, Pragma_Stream_Convert => -1, Pragma_Style_Checks => -1, Pragma_Subtitle => -1, Pragma_Suppress => 0, Pragma_Suppress_Exception_Locations => 0, Pragma_Suppress_All => -1, Pragma_Suppress_Debug_Info => 0, Pragma_Suppress_Initialization => 0, Pragma_System_Name => -1, Pragma_Task_Dispatching_Policy => -1, Pragma_Task_Info => -1, Pragma_Task_Name => -1, Pragma_Task_Storage => 0, Pragma_Thread_Body => +2, Pragma_Time_Slice => -1, Pragma_Title => -1, Pragma_Unchecked_Union => 0, Pragma_Unimplemented_Unit => -1, Pragma_Universal_Data => -1, Pragma_Unreferenced => -1, Pragma_Unreserve_All_Interrupts => -1, Pragma_Unsuppress => 0, Pragma_Use_VADS_Size => -1, Pragma_Validity_Checks => -1, Pragma_Volatile => 0, Pragma_Volatile_Components => 0, Pragma_Warnings => -1, Pragma_Weak_External => 0, Unknown_Pragma => 0); function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is P : Node_Id; C : Int; A : Node_Id; begin P := Parent (N); if Nkind (P) /= N_Pragma_Argument_Association then return False; else C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P)))); case C is when -1 => return False; when 0 => return True; when others => A := First (Pragma_Argument_Associations (Parent (P))); for J in 1 .. C - 1 loop if No (A) then return False; end if; Next (A); end loop; return A = P; end case; end if; end Is_Non_Significant_Pragma_Reference; ------------------------------ -- Is_Pragma_String_Literal -- ------------------------------ -- This function returns true if the corresponding pragma argument is -- a static string expression. These are the only cases in which string -- literals can appear as pragma arguments. We also allow a string -- literal as the first argument to pragma Assert (although it will -- of course always generate a type error). function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is Pragn : constant Node_Id := Parent (Par); Assoc : constant List_Id := Pragma_Argument_Associations (Pragn); Pname : constant Name_Id := Chars (Pragn); Argn : Natural; N : Node_Id; begin Argn := 1; N := First (Assoc); loop exit when N = Par; Argn := Argn + 1; Next (N); end loop; if Pname = Name_Assert then return True; elsif Pname = Name_Export then return Argn > 2; elsif Pname = Name_Ident then return Argn = 1; elsif Pname = Name_Import then return Argn > 2; elsif Pname = Name_Interface_Name then return Argn > 1; elsif Pname = Name_Linker_Alias then return Argn = 2; elsif Pname = Name_Linker_Section then return Argn = 2; elsif Pname = Name_Machine_Attribute then return Argn = 2; elsif Pname = Name_Source_File_Name then return True; elsif Pname = Name_Source_Reference then return Argn = 2; elsif Pname = Name_Title then return True; elsif Pname = Name_Subtitle then return True; else return False; end if; end Is_Pragma_String_Literal; -------------------------------------- -- Process_Compilation_Unit_Pragmas -- -------------------------------------- procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is begin -- A special check for pragma Suppress_All. This is a strange DEC -- pragma, strange because it comes at the end of the unit. If we -- have a pragma Suppress_All in the Pragmas_After of the current -- unit, then we insert a pragma Suppress (All_Checks) at the start -- of the context clause to ensure the correct processing. declare PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N)); P : Node_Id; begin if Present (PA) then P := First (PA); while Present (P) loop if Chars (P) = Name_Suppress_All then Prepend_To (Context_Items (N), Make_Pragma (Sloc (P), Chars => Name_Suppress, Pragma_Argument_Associations => New_List ( Make_Pragma_Argument_Association (Sloc (P), Expression => Make_Identifier (Sloc (P), Chars => Name_All_Checks))))); exit; end if; Next (P); end loop; end if; end; end Process_Compilation_Unit_Pragmas; -------------------------------- -- Set_Encoded_Interface_Name -- -------------------------------- procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is Str : constant String_Id := Strval (S); Len : constant Int := String_Length (Str); CC : Char_Code; C : Character; J : Int; Hex : constant array (0 .. 15) of Character := "0123456789abcdef"; procedure Encode; -- Stores encoded value of character code CC. The encoding we -- use an underscore followed by four lower case hex digits. ------------ -- Encode -- ------------ procedure Encode is begin Store_String_Char (Get_Char_Code ('_')); Store_String_Char (Get_Char_Code (Hex (Integer (CC / 2 ** 12)))); Store_String_Char (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#)))); Store_String_Char (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#)))); Store_String_Char (Get_Char_Code (Hex (Integer (CC and 16#0F#)))); end Encode; -- Start of processing for Set_Encoded_Interface_Name begin -- If first character is asterisk, this is a link name, and we -- leave it completely unmodified. We also ignore null strings -- (the latter case happens only in error cases) and no encoding -- should occur for Java interface names. if Len = 0 or else Get_String_Char (Str, 1) = Get_Char_Code ('*') or else Java_VM then Set_Interface_Name (E, S); else J := 1; loop CC := Get_String_Char (Str, J); exit when not In_Character_Range (CC); C := Get_Character (CC); exit when C /= '_' and then C /= '$' and then C not in '0' .. '9' and then C not in 'a' .. 'z' and then C not in 'A' .. 'Z'; if J = Len then Set_Interface_Name (E, S); return; else J := J + 1; end if; end loop; -- Here we need to encode. The encoding we use as follows: -- three underscores + four hex digits (lower case) Start_String; for J in 1 .. String_Length (Str) loop CC := Get_String_Char (Str, J); if not In_Character_Range (CC) then Encode; else C := Get_Character (CC); if C = '_' or else C = '$' or else C in '0' .. '9' or else C in 'a' .. 'z' or else C in 'A' .. 'Z' then Store_String_Char (CC); else Encode; end if; end if; end loop; Set_Interface_Name (E, Make_String_Literal (Sloc (S), Strval => End_String)); end if; end Set_Encoded_Interface_Name; ------------------- -- Set_Unit_Name -- ------------------- procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is Pref : Node_Id; Scop : Entity_Id; begin if Nkind (N) = N_Identifier and then Nkind (With_Item) = N_Identifier then Set_Entity (N, Entity (With_Item)); elsif Nkind (N) = N_Selected_Component then Change_Selected_Component_To_Expanded_Name (N); Set_Entity (N, Entity (With_Item)); Set_Entity (Selector_Name (N), Entity (N)); Pref := Prefix (N); Scop := Scope (Entity (N)); while Nkind (Pref) = N_Selected_Component loop Change_Selected_Component_To_Expanded_Name (Pref); Set_Entity (Selector_Name (Pref), Scop); Set_Entity (Pref, Scop); Pref := Prefix (Pref); Scop := Scope (Scop); end loop; Set_Entity (Pref, Scop); end if; end Set_Unit_Name; end Sem_Prag;
-- part of AdaYaml, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "copying.txt" with Text.Chunk_Test; package body Text.Suite is Result : aliased AUnit.Test_Suites.Test_Suite; Chunk_TC : aliased Chunk_Test.TC; function Suite return AUnit.Test_Suites.Access_Test_Suite is begin AUnit.Test_Suites.Add_Test (Result'Access, Chunk_TC'Access); return Result'Access; end Suite; end Text.Suite;
with SDL; with SDL.Libraries; with SDL.Log; -- Run with: LD_LIBRARY_PATH=./gen/debug/test:$LD_LIBRARY_PATH ./gen/debug/test/libraries procedure Libraries is Lib : SDL.Libraries.Handles; begin SDL.Libraries.Load (Lib, "libtestmaths.so"); SDL.Log.Set (Category => SDL.Log.Application, Priority => SDL.Log.Debug); declare type Access_To_Add is access function (A, B : in Integer) return Integer; type Access_To_Sub is access function (A, B : in Integer) return Integer with Convention => C; function Load is new SDL.Libraries.Load_Sub_Program (Access_To_Sub_Program => Access_To_Add, Name => "Add"); function Load is new SDL.Libraries.Load_Sub_Program (Access_To_Sub_Program => Access_To_Sub, Name => "sub"); Add : constant Access_To_Add := Load (From_Library => Lib); Sub : constant Access_To_Sub := Load (From_Library => Lib); begin SDL.Log.Put_Debug ("1 + 2 = " & Integer'Image (Add (1, 2))); SDL.Log.Put_Debug ("5 - 1 = " & Integer'Image (Sub (5, 1))); end; SDL.Finalise; end Libraries;
with openGL.Tasks, GL.Binding, ada.Text_IO; package body openGL.Errors is use GL; function Current return String is use GL.Binding; check_is_OK : constant Boolean := openGL.Tasks.Check; pragma Unreferenced (check_is_OK); the_Error : constant GL.GLenum := glGetError; begin case the_Error is when GL.GL_NO_ERROR => return "no error"; when GL_INVALID_ENUM => return "invalid Enum"; when GL_INVALID_VALUE => return "invalid Value"; when GL_INVALID_OPERATION => return "invalid Operation"; when GL_OUT_OF_MEMORY => return "out of Memory"; when others => return "unknown openGL error detected"; end case; end Current; procedure log (Prefix : in String := "") is current_Error : constant String := Current; function Error_Message return String is begin if Prefix = "" then return "openGL error: '" & current_Error & "'"; else return Prefix & ": '" & current_Error & "'"; end if; end Error_Message; begin if current_Error = "no error" then return; end if; raise openGL.Error with Error_Message; end log; procedure log (Prefix : in String := ""; Error_occurred : out Boolean) is use ada.Text_IO; current_Error : constant String := Current; begin if current_Error = "no error" then error_Occurred := False; return; end if; error_Occurred := True; if Prefix = "" then put_Line ("openGL error: '" & current_Error & "'"); else put_Line (Prefix & ": '" & current_Error & "'"); end if; end log; end openGL.Errors;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S T Y L E -- -- -- -- B o d y -- -- -- -- $Revision$ -- -- -- Copyright (C) 1992-2001 Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This version of the Style package implements the standard GNAT style -- checking rules. For documentation of these rules, see comments on the -- individual procedures. with Atree; use Atree; with Casing; use Casing; with Csets; use Csets; with Einfo; use Einfo; with Errout; use Errout; with Namet; use Namet; with Opt; use Opt; with Scn; use Scn; with Scans; use Scans; with Sinfo; use Sinfo; with Sinput; use Sinput; with Stand; use Stand; with Stylesw; use Stylesw; package body Style is ----------------------- -- Local Subprograms -- ----------------------- procedure Error_Space_Not_Allowed (S : Source_Ptr); -- Posts an error message indicating that a space is not allowed -- at the given source location. procedure Error_Space_Required (S : Source_Ptr); -- Posts an error message indicating that a space is required at -- the given source location. procedure Require_Following_Space; pragma Inline (Require_Following_Space); -- Require token to be followed by white space. Used only if in GNAT -- style checking mode. procedure Require_Preceding_Space; pragma Inline (Require_Preceding_Space); -- Require token to be preceded by white space. Used only if in GNAT -- style checking mode. ----------------------- -- Body_With_No_Spec -- ----------------------- -- If the check specs mode (-gnatys) is set, then all subprograms must -- have specs unless they are parameterless procedures that are not child -- units at the library level (i.e. they are possible main programs). procedure Body_With_No_Spec (N : Node_Id) is begin if Style_Check_Specs then if Nkind (Parent (N)) = N_Compilation_Unit then declare Spec : constant Node_Id := Specification (N); Defnm : constant Node_Id := Defining_Unit_Name (Spec); begin if Nkind (Spec) = N_Procedure_Specification and then Nkind (Defnm) = N_Defining_Identifier and then No (First_Formal (Defnm)) then return; end if; end; end if; Error_Msg_N ("(style): subprogram body has no previous spec", N); end if; end Body_With_No_Spec; ---------------------- -- Check_Abs_Or_Not -- ---------------------- -- In check tokens mode (-gnatyt), ABS/NOT must be followed by a space procedure Check_Abs_Not is begin if Style_Check_Tokens then if Source (Scan_Ptr) > ' ' then Error_Space_Required (Scan_Ptr); end if; end if; end Check_Abs_Not; ----------------- -- Check_Arrow -- ----------------- -- In check tokens mode (-gnatys), arrow must be surrounded by spaces procedure Check_Arrow is begin if Style_Check_Tokens then Require_Preceding_Space; Require_Following_Space; end if; end Check_Arrow; -------------------------- -- Check_Attribute_Name -- -------------------------- -- In check attribute casing mode (-gnatya), attribute names must be -- mixed case, i.e. start with an upper case letter, and otherwise -- lower case, except after an underline character. procedure Check_Attribute_Name (Reserved : Boolean) is begin if Style_Check_Attribute_Casing then if Determine_Token_Casing /= Mixed_Case then Error_Msg_SC ("(style) bad capitalization, mixed case required"); end if; end if; end Check_Attribute_Name; --------------------------- -- Check_Binary_Operator -- --------------------------- -- In check token mode (-gnatyt), binary operators other than the special -- case of exponentiation require surrounding space characters. procedure Check_Binary_Operator is begin if Style_Check_Tokens then Require_Preceding_Space; Require_Following_Space; end if; end Check_Binary_Operator; --------------- -- Check_Box -- --------------- -- In check token mode (-gnatyt), box must be preceded by a space or by -- a left parenthesis. Spacing checking on the surrounding tokens takes -- care of the remaining checks. procedure Check_Box is begin if Style_Check_Tokens then if Prev_Token /= Tok_Left_Paren then Require_Preceding_Space; end if; end if; end Check_Box; ----------------- -- Check_Colon -- ----------------- -- In check token mode (-gnatyt), colon must be surrounded by spaces procedure Check_Colon is begin if Style_Check_Tokens then Require_Preceding_Space; Require_Following_Space; end if; end Check_Colon; ----------------------- -- Check_Colon_Equal -- ----------------------- -- In check token mode (-gnatyt), := must be surrounded by spaces procedure Check_Colon_Equal is begin if Style_Check_Tokens then Require_Preceding_Space; Require_Following_Space; end if; end Check_Colon_Equal; ----------------- -- Check_Comma -- ----------------- -- In check token mode (-gnatyt), comma must be either the first -- token on a line, or be preceded by a non-blank character. -- It must also always be followed by a blank. procedure Check_Comma is begin if Style_Check_Tokens then if Token_Ptr > First_Non_Blank_Location and then Source (Token_Ptr - 1) = ' ' then Error_Space_Not_Allowed (Token_Ptr - 1); end if; if Source (Scan_Ptr) > ' ' then Error_Space_Required (Scan_Ptr); end if; end if; end Check_Comma; ------------------- -- Check_Comment -- ------------------- -- In check comment mode (-gnatyc) there are several requirements on the -- format of comments. The following are permissible comment formats: -- 1. Any comment that is not at the start of a line, i.e. where the -- initial minuses are not the first non-blank characters on the -- line must have at least one blank after the second minus. -- 2. A row of all minuses of any length is permitted (see procedure -- box above in the source of this routine). -- 3. A comment line starting with two minuses and a space, and ending -- with a space and two minuses. Again see the procedure title box -- immediately above in the source. -- 4. A full line comment where two spaces follow the two minus signs. -- This is the normal comment format in GNAT style, as typified by -- the comments you are reading now. -- 5. A full line comment where the first character after the second -- minus is a special character, i.e. a character in the ASCII -- range 16#21#..16#2F# or 16#3A#..16#3F#. This allows special -- comments, such as those generated by gnatprep, or those that -- appear in the SPARK annotation language to be accepted. procedure Check_Comment is S : Source_Ptr; C : Character; begin -- Can never have a non-blank character preceding the first minus if Style_Check_Comments then if Scan_Ptr > Source_First (Current_Source_File) and then Source (Scan_Ptr - 1) > ' ' then Error_Msg_S ("(style) space required"); end if; end if; -- For a comment that is not at the start of the line, the only -- requirement is that we cannot have a non-blank character after -- the second minus sign. if Scan_Ptr /= First_Non_Blank_Location then if Style_Check_Comments then if Source (Scan_Ptr + 2) > ' ' then Error_Msg ("(style) space required", Scan_Ptr + 2); end if; end if; return; -- Case of a comment that is at the start of a line else -- First check, must be in appropriately indented column if Style_Check_Indentation /= 0 then if Start_Column rem Style_Check_Indentation /= 0 then Error_Msg_S ("(style) bad column"); return; end if; end if; -- Now check form of the comment if not Style_Check_Comments then return; -- Case of not followed by a blank. Usually wrong, but there are -- some exceptions that we permit. elsif Source (Scan_Ptr + 2) /= ' ' then C := Source (Scan_Ptr + 2); -- Case of -- all on its own on a line is OK if C < ' ' then return; -- Case of --x, x special character is OK (gnatprep/SPARK/etc.) elsif Character'Pos (C) in 16#21# .. 16#2F# or else Character'Pos (C) in 16#3A# .. 16#3F# then return; -- Otherwise only cases allowed are when the entire line is -- made up of minus signs (case of a box comment). else S := Scan_Ptr + 2; while Source (S) >= ' ' loop if Source (S) /= '-' then Error_Space_Required (Scan_Ptr + 2); return; end if; S := S + 1; end loop; end if; -- If we are followed by a blank, then the comment is OK if the -- character following this blank is another blank or a format -- effector. elsif Source (Scan_Ptr + 3) <= ' ' then return; -- Here is the case where we only have one blank after the two minus -- signs, which is an error unless the line ends with two blanks, the -- case of a box comment. else S := Scan_Ptr + 3; while Source (S) not in Line_Terminator loop S := S + 1; end loop; if Source (S - 1) /= '-' or else Source (S - 2) /= '-' then Error_Space_Required (Scan_Ptr + 3); end if; end if; end if; end Check_Comment; ------------------- -- Check_Dot_Dot -- ------------------- -- In check token mode (-gnatyt), colon must be surrounded by spaces procedure Check_Dot_Dot is begin if Style_Check_Tokens then Require_Preceding_Space; Require_Following_Space; end if; end Check_Dot_Dot; ----------------------------------- -- Check_Exponentiation_Operator -- ----------------------------------- -- No spaces are required for the ** operator in GNAT style check mode procedure Check_Exponentiation_Operator is begin null; end Check_Exponentiation_Operator; -------------- -- Check_HT -- -------------- -- In check horizontal tab mode (-gnatyh), tab characters are not allowed procedure Check_HT is begin if Style_Check_Horizontal_Tabs then Error_Msg_S ("(style) horizontal tab not allowed"); end if; end Check_HT; ---------------------- -- Check_Identifier -- ---------------------- -- In check references mode (-gnatyr), identifier uses must be cased -- the same way as the corresponding identifier declaration. procedure Check_Identifier (Ref : Node_Or_Entity_Id; Def : Node_Or_Entity_Id) is Sref : Source_Ptr := Sloc (Ref); Sdef : Source_Ptr := Sloc (Def); Tref : Source_Buffer_Ptr; Tdef : Source_Buffer_Ptr; Nlen : Nat; Cas : Casing_Type; begin -- If reference does not come from source, nothing to check if not Comes_From_Source (Ref) then return; -- Case of definition comes from source elsif Comes_From_Source (Def) then -- Check same casing if we are checking references if Style_Check_References then Tref := Source_Text (Get_Source_File_Index (Sref)); Tdef := Source_Text (Get_Source_File_Index (Sdef)); -- Ignore operator name case completely. This also catches the -- case of where one is an operator and the other is not. This -- is a phenomenon from rewriting of operators as functions, -- and is to be ignored. if Tref (Sref) = '"' or else Tdef (Sdef) = '"' then return; else while Tref (Sref) = Tdef (Sdef) loop -- If end of identifier, all done if not Identifier_Char (Tref (Sref)) then return; -- Otherwise loop continues else Sref := Sref + 1; Sdef := Sdef + 1; end if; end loop; -- Fall through loop when mismatch between identifiers -- If either identifier is not terminated, error. if Identifier_Char (Tref (Sref)) or else Identifier_Char (Tdef (Sdef)) then Error_Msg_Node_1 := Def; Error_Msg_Sloc := Sloc (Def); Error_Msg ("(style) bad casing of & declared#", Sref); return; -- Else end of identifiers, and they match else return; end if; end if; end if; -- Case of definition in package Standard elsif Sdef = Standard_Location then -- Check case of identifiers in Standard if Style_Check_Standard then Tref := Source_Text (Get_Source_File_Index (Sref)); -- Ignore operators if Tref (Sref) = '"' then null; -- Special case of ASCII else if Entity (Ref) = Standard_ASCII then Cas := All_Upper_Case; elsif Entity (Ref) in SE (S_LC_A) .. SE (S_LC_Z) or else Entity (Ref) in SE (S_NUL) .. SE (S_US) or else Entity (Ref) = SE (S_DEL) then Cas := All_Upper_Case; else Cas := Mixed_Case; end if; Nlen := Length_Of_Name (Chars (Ref)); if Determine_Casing (Tref (Sref .. Sref + Source_Ptr (Nlen) - 1)) = Cas then null; else Error_Msg_N ("(style) bad casing for entity in Standard", Ref); end if; end if; end if; end if; end Check_Identifier; ----------------------- -- Check_Indentation -- ----------------------- -- In check indentation mode (-gnatyn for n a digit), a new statement or -- declaration is required to start in a column that is a multiple of the -- indentiation amount. procedure Check_Indentation is begin if Style_Check_Indentation /= 0 then if Token_Ptr = First_Non_Blank_Location and then Start_Column rem Style_Check_Indentation /= 0 then Error_Msg_SC ("(style) bad indentation"); end if; end if; end Check_Indentation; ---------------------- -- Check_Left_Paren -- ---------------------- -- In tone check mode (-gnatyt), left paren must not be preceded by an -- identifier character or digit (a separating space is required) and -- may never be followed by a space. procedure Check_Left_Paren is S : Source_Ptr; begin if Style_Check_Tokens then if Token_Ptr > Source_First (Current_Source_File) and then Identifier_Char (Source (Token_Ptr - 1)) then Error_Space_Required (Token_Ptr); end if; if Source (Scan_Ptr) = ' ' then -- Allow one or more spaces if followed by comment S := Scan_Ptr + 1; loop if Source (S) = '-' and then Source (S + 1) = '-' then return; elsif Source (S) /= ' ' then exit; else S := S + 1; end if; end loop; Error_Space_Not_Allowed (Scan_Ptr); end if; end if; end Check_Left_Paren; --------------------------- -- Check_Line_Terminator -- --------------------------- -- In check blanks at end mode (-gnatyb), lines may not end with a -- trailing space. -- In check max line length mode (-gnatym), the line length must -- not exceed the permitted maximum value. -- In check form feeds mode (-gnatyf), the line terminator may not -- be either of the characters FF or VT. procedure Check_Line_Terminator (Len : Int) is S : Source_Ptr; begin -- Check FF/VT terminators if Style_Check_Form_Feeds then if Source (Scan_Ptr) = ASCII.FF then Error_Msg_S ("(style) form feed not allowed"); elsif Source (Scan_Ptr) = ASCII.VT then Error_Msg_S ("(style) vertical tab not allowed"); end if; end if; -- Check trailing space if Style_Check_Blanks_At_End then if Scan_Ptr >= First_Non_Blank_Location then if Source (Scan_Ptr - 1) = ' ' then S := Scan_Ptr - 1; while Source (S - 1) = ' ' loop S := S - 1; end loop; Error_Msg ("(style) trailing spaces not permitted", S); end if; end if; end if; -- Check max line length if Style_Check_Max_Line_Length then if Len > Style_Max_Line_Length then Error_Msg ("(style) this line is too long", Current_Line_Start + Source_Ptr (Style_Max_Line_Length)); end if; end if; end Check_Line_Terminator; ----------------------- -- Check_Pragma_Name -- ----------------------- -- In check pragma casing mode (-gnatyp), pragma names must be mixed -- case, i.e. start with an upper case letter, and otherwise lower case, -- except after an underline character. procedure Check_Pragma_Name is begin if Style_Check_Pragma_Casing then if Determine_Token_Casing /= Mixed_Case then Error_Msg_SC ("(style) bad capitalization, mixed case required"); end if; end if; end Check_Pragma_Name; ----------------------- -- Check_Right_Paren -- ----------------------- -- In check tokens mode (-gnatyt), right paren must never be preceded by -- a space unless it is the initial non-blank character on the line. procedure Check_Right_Paren is begin if Style_Check_Tokens then if Token_Ptr > First_Non_Blank_Location and then Source (Token_Ptr - 1) = ' ' then Error_Space_Not_Allowed (Token_Ptr - 1); end if; end if; end Check_Right_Paren; --------------------- -- Check_Semicolon -- --------------------- -- In check tokens mode (-gnatyt), semicolon does not permit a preceding -- space and a following space is required. procedure Check_Semicolon is begin if Style_Check_Tokens then if Scan_Ptr > Source_First (Current_Source_File) and then Source (Token_Ptr - 1) = ' ' then Error_Space_Not_Allowed (Token_Ptr - 1); elsif Source (Scan_Ptr) > ' ' then Error_Space_Required (Scan_Ptr); end if; end if; end Check_Semicolon; ---------------- -- Check_Then -- ---------------- -- In check if then layout mode (-gnatyi), we expect a THEN keyword -- to appear either on the same line as the IF, or on a separate line -- after multiple conditions. In any case, it may not appear on the -- line immediately following the line with the IF. procedure Check_Then (If_Loc : Source_Ptr) is begin if Style_Check_If_Then_Layout then if Get_Physical_Line_Number (Token_Ptr) = Get_Physical_Line_Number (If_Loc) + 1 then Error_Msg_SC ("(style) misplaced THEN"); end if; end if; end Check_Then; ------------------------------- -- Check_Unary_Plus_Or_Minus -- ------------------------------- -- In check tokem mode (-gnatyt), unary plus or minus must not be -- followed by a space. procedure Check_Unary_Plus_Or_Minus is begin if Style_Check_Tokens then if Source (Scan_Ptr) = ' ' then Error_Space_Not_Allowed (Scan_Ptr); end if; end if; end Check_Unary_Plus_Or_Minus; ------------------------ -- Check_Vertical_Bar -- ------------------------ -- In check token mode (-gnatyt), vertical bar must be surrounded by spaces procedure Check_Vertical_Bar is begin if Style_Check_Tokens then Require_Preceding_Space; Require_Following_Space; end if; end Check_Vertical_Bar; ----------------------------- -- Error_Space_Not_Allowed -- ----------------------------- procedure Error_Space_Not_Allowed (S : Source_Ptr) is begin Error_Msg ("(style) space not allowed", S); end Error_Space_Not_Allowed; -------------------------- -- Error_Space_Required -- -------------------------- procedure Error_Space_Required (S : Source_Ptr) is begin Error_Msg ("(style) space required", S); end Error_Space_Required; ----------------- -- No_End_Name -- ----------------- -- In check end/exit labels mode (-gnatye), always require the name of -- a subprogram or package to be present on the END, so this is an error. procedure No_End_Name (Name : Node_Id) is begin if Style_Check_End_Labels then Error_Msg_Node_1 := Name; Error_Msg_SP ("(style) `END &` required"); end if; end No_End_Name; ------------------ -- No_Exit_Name -- ------------------ -- In check end/exit labels mode (-gnatye), always require the name of -- the loop to be present on the EXIT when exiting a named loop. procedure No_Exit_Name (Name : Node_Id) is begin if Style_Check_End_Labels then Error_Msg_Node_1 := Name; Error_Msg_SP ("(style) `EXIT &` required"); end if; end No_Exit_Name; ---------------------------- -- Non_Lower_Case_Keyword -- ---------------------------- -- In check casing mode (-gnatyk), reserved keywords must be be spelled -- in all lower case (excluding keywords range, access, delta and digits -- used as attribute designators). procedure Non_Lower_Case_Keyword is begin if Style_Check_Keyword_Casing then Error_Msg_SC ("(style) reserved words must be all lower case"); end if; end Non_Lower_Case_Keyword; ----------------------------- -- Require_Following_Space -- ----------------------------- procedure Require_Following_Space is begin if Source (Scan_Ptr) > ' ' then Error_Space_Required (Scan_Ptr); end if; end Require_Following_Space; ----------------------------- -- Require_Preceding_Space -- ----------------------------- procedure Require_Preceding_Space is begin if Token_Ptr > Source_First (Current_Source_File) and then Source (Token_Ptr - 1) > ' ' then Error_Space_Required (Token_Ptr); end if; end Require_Preceding_Space; --------------------- -- RM_Column_Check -- --------------------- function RM_Column_Check return Boolean is begin return Style_Check and Style_Check_Layout; end RM_Column_Check; ----------------------------------- -- Subprogram_Not_In_Alpha_Order -- ----------------------------------- procedure Subprogram_Not_In_Alpha_Order (Name : Node_Id) is begin if Style_Check_Subprogram_Order then Error_Msg_N ("(style) subprogram body& not in alphabetical order", Name); end if; end Subprogram_Not_In_Alpha_Order; end Style;
-- part of AdaYaml, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "copying.txt" with Ada.Strings.Hash; with System; with Yaml.Dom.Node_Memory; package body Yaml.Dom.Node is use type Text.Reference; use type Ada.Containers.Hash_Type; use type Count_Type; use type System.Address; function "=" (Left, Right : Instance) return Boolean is Memory : Node_Memory.Pair_Instance; function Equal (Left, Right : not null access Instance) return Boolean; function Equal (Left, Right : Sequence_Data.Instance) return Boolean is Cur_Left, Cur_Right : Sequence_Data.Cursor; begin if Left.Length /= Right.Length then return False; end if; Cur_Left := Left.First; Cur_Right := Right.First; while Sequence_Data.Has_Element (Cur_Left) loop if not Equal (Left.Element (Cur_Left).Value.Data, Right.Element (Cur_Right).Value.Data) then return False; end if; Cur_Left := Sequence_Data.Next (Cur_Left); Cur_Right := Sequence_Data.Next (Cur_Right); end loop; return True; end Equal; function Equal (Left, Right : Mapping_Data.Instance) return Boolean is Cur_Left, Cur_Right : Mapping_Data.Cursor; begin if Left.Length /= Right.Length then return False; end if; Cur_Left := Left.First; while Mapping_Data.Has_Element (Cur_Left) loop Cur_Right := Right.Find (Mapping_Data.Key (Cur_Left)); if not Mapping_Data.Has_Element (Cur_Right) or else not Equal (Mapping_Data.Value (Cur_Left).Data, Mapping_Data.Value (Cur_Right).Data) then return False; end if; Cur_Left := Mapping_Data.Next (Cur_Left); end loop; return True; end Equal; function Equal (Left, Right : not null access Instance) return Boolean is Visited : Boolean; begin if Left.all'Address = Right.all'Address then return True; else Memory.Visit (Left, Right, Visited); if Visited then return True; elsif Left.Kind = Right.Kind and then Left.Tag = Right.Tag then case Left.Kind is when Scalar => return Left.Content = Right.Content; when Sequence => return Equal (Left.Items, Right.Items); when Mapping => return Equal (Left.Pairs, Right.Pairs); end case; else return False; end if; end if; end Equal; begin return Equal (Left'Unrestricted_Access, Right'Unrestricted_Access); end "="; function Hash (Object : Instance) return Ada.Containers.Hash_Type is -- for efficiency reasons, the hash of a collection node is not -- calculated recursively. Instead, only the content of the node and the -- types and number of its children (and their content for scalars) is -- taken into account. this suffices as hash function as long as the -- objects used as keys do not get too large. begin if Object.Kind = Scalar then return Object.Content.Hash; else declare Ret : Ada.Containers.Hash_Type := Ada.Strings.Hash (Object.Kind'Img); procedure Visit (Prefix : String; Cur : not null access Node.Instance) is begin case Cur.Kind is when Scalar => Ret := Ret * Cur.Content.Hash; when Sequence => Ret := Ret * Ada.Strings.Hash (Prefix & "Sequence" & Cur.Items.Length'Img); when Mapping => Ret := Ret * Ada.Strings.Hash (Prefix & "Mapping" & Cur.Pairs.Length'Img); end case; end Visit; procedure Visit_Item (Cur : not null access Node.Instance) is begin Visit ("Item:", Cur); end Visit_Item; procedure Visit_Pair (Key, Value : not null access Node.Instance) is begin Visit ("Key:", Key); Visit ("Value:", Value); end Visit_Pair; begin if Object.Kind = Sequence then Object.Items.Iterate (Visit_Item'Access); else Object.Pairs.Iterate (Visit_Pair'Access); end if; return Ret; end; end if; end Hash; end Yaml.Dom.Node;
with Ada.Text_IO; use Ada.Text_IO; with Yeison_Experiments; use Yeison_Experiments; procedure Experiments is LS : constant List := ("a", "b", "c"); -- LI : constant List := (1, 2, 3); -- Ideally, this should be allowed in the future begin null; end Experiments;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2022, 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. -- -- -- ------------------------------------------------------------------------------ -- driver for text based LCDs in the typical sizes of 8x1, 16x2 or 20x4 with HAL; use HAL; with HAL.Time; package LCD_HD44780 is subtype Char_Position is UInt8 range 1 .. 40; subtype Line_Position is UInt8 range 1 .. 4; -- typical display formats are: -- 8x1 16x1 20x1 -- 8x2 12x2 16x2 20x2 24x2 40x2 -- 16x4 20x4 40x4 type LCD_Module (Display_Width : Char_Position; Display_Height : Line_Position; Time : not null HAL.Time.Any_Delays) is abstract tagged limited private; type Any_LCD_Module is access all LCD_Module'Class; procedure Initialize (This : in out LCD_Module); procedure Put (This : in out LCD_Module; C : Character) with Inline; procedure Put (This : in out LCD_Module; Text : String); -- output at the current cursor location procedure Put (This : in out LCD_Module; X : Char_Position; Y : Line_Position; Text : String); -- output at the specified cursor location procedure Clear_Screen (This : in out LCD_Module); -- clear display and move cursor to home position procedure Home (This : in out LCD_Module); -- move cursor to home position procedure Goto_XY (This : in out LCD_Module; X : Char_Position; Y : Line_Position); -- move cursor into line Y and before character position X. Lines -- are numbered 1 to 2 (or 1 to 4 on big displays). The left most -- character position is Y = 1. The right most position is -- defined by Display_Width; procedure Set_Backlight (This : in out LCD_Module; Is_On : Boolean := True) is abstract; type HD44780_Pins is (Enable, ReadWrite, RegSel, Backlight, D0, D1, D2, D3, D4, D5, D6, D7); subtype HD44780_4bit_Pins is HD44780_Pins range Enable .. D3; -- -- Custom Characters -- type Custom_Character_Definition is array (1 .. 8) of UInt5; subtype Custom_Character_Index is Integer range 0 .. 7; procedure Create_Custom_Character (This : in out LCD_Module; Position : Custom_Character_Index; Definition : Custom_Character_Definition); function Custom_Char (From_Index : Custom_Character_Index) return Character; type Command_Type is new UInt8; procedure Command (This : in out LCD_Module; Cmd : Command_Type) with Inline; -- send the command code Cmd to the display package Commands is Clear : constant Command_Type := 16#01#; Home : constant Command_Type := 16#02#; -- interface data width and number of lines Mode_4bit_1line : constant Command_Type := 16#20#; Mode_4bit_2line : constant Command_Type := 16#28#; Mode_8bit_1line : constant Command_Type := 16#30#; Mode_8bit_2line : constant Command_Type := 16#38#; -- display on/off, cursor on/off, blinking char at cursor position Display_Off : constant Command_Type := 16#08#; Display_On : constant Command_Type := 16#0C#; Display_On_Blink : constant Command_Type := 16#0D#; Display_On_Cursor : constant Command_Type := 16#0E#; Display_On_Cursor_Blink : constant Command_Type := 16#0F#; -- entry mode Entry_Inc : constant Command_Type := 16#06#; Entry_Dec : constant Command_Type := 16#04#; Entry_Shift_Inc : constant Command_Type := 16#07#; Entry_Shift_Dec : constant Command_Type := 16#05#; -- cursor/shift display Move_Cursor_Left : constant Command_Type := 16#10#; Move_Cursor_Right : constant Command_Type := 16#14#; Move_Display_Left : constant Command_Type := 16#18#; Move_Display_Right : constant Command_Type := 16#1C#; end Commands; private type LCD_Module (Display_Width : Char_Position; Display_Height : Line_Position; Time : not null HAL.Time.Any_Delays) is abstract tagged limited null record; procedure Toggle_Enable (This : LCD_Module) is null; procedure Output (This : LCD_Module; Cmd : UInt8; Is_Data : Boolean := False) is null; procedure Init_4bit_Mode (This : LCD_Module) is null; end LCD_HD44780;
pragma SPARK_Mode; with Interfaces.C; use Interfaces.C; with Sparkduino; use Sparkduino; package body Pwm is Pwm_Resolution : constant := 8; procedure Configure_Timers is begin null; end Configure_Timers; procedure SetRate (Index : Pwm_Index; Value : Word) is Scaled : unsigned; begin Scaled := (unsigned (Value) * ((2 ** Pwm_Resolution) - 1)) / PWM_Max; case Index is when Left => AnalogWrite (Pin => 10, Val => Scaled); when Right => AnalogWrite (Pin => 9, Val => Scaled); end case; end SetRate; end Pwm;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- E X P _ A T T R -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Aspects; use Aspects; with Atree; use Atree; with Checks; use Checks; with Einfo; use Einfo; with Elists; use Elists; with Exp_Atag; use Exp_Atag; with Exp_Ch2; use Exp_Ch2; with Exp_Ch3; use Exp_Ch3; with Exp_Ch6; use Exp_Ch6; with Exp_Ch9; use Exp_Ch9; with Exp_Dist; use Exp_Dist; with Exp_Imgv; use Exp_Imgv; with Exp_Pakd; use Exp_Pakd; with Exp_Strm; use Exp_Strm; with Exp_Tss; use Exp_Tss; with Exp_Util; use Exp_Util; with Fname; use Fname; with Freeze; use Freeze; with Gnatvsn; use Gnatvsn; with Itypes; use Itypes; with Lib; use Lib; with Namet; use Namet; with Nmake; use Nmake; with Nlists; use Nlists; with Opt; use Opt; with Restrict; use Restrict; with Rident; use Rident; with Rtsfind; use Rtsfind; with Sem; use Sem; with Sem_Aux; use Sem_Aux; with Sem_Ch6; use Sem_Ch6; with Sem_Ch7; use Sem_Ch7; with Sem_Ch8; use Sem_Ch8; with Sem_Eval; use Sem_Eval; with Sem_Res; use Sem_Res; with Sem_Util; use Sem_Util; with Sinfo; use Sinfo; with Snames; use Snames; with Stand; use Stand; with Stringt; use Stringt; with Targparm; use Targparm; with Tbuild; use Tbuild; with Ttypes; use Ttypes; with Uintp; use Uintp; with Uname; use Uname; with Validsw; use Validsw; package body Exp_Attr is ----------------------- -- Local Subprograms -- ----------------------- function Build_Array_VS_Func (A_Type : Entity_Id; Nod : Node_Id) return Entity_Id; -- Build function to test Valid_Scalars for array type A_Type. Nod is the -- Valid_Scalars attribute node, used to insert the function body, and the -- value returned is the entity of the constructed function body. We do not -- bother to generate a separate spec for this subprogram. function Build_Record_VS_Func (R_Type : Entity_Id; Nod : Node_Id) return Entity_Id; -- Build function to test Valid_Scalars for record type A_Type. Nod is the -- Valid_Scalars attribute node, used to insert the function body, and the -- value returned is the entity of the constructed function body. We do not -- bother to generate a separate spec for this subprogram. procedure Compile_Stream_Body_In_Scope (N : Node_Id; Decl : Node_Id; Arr : Entity_Id; Check : Boolean); -- The body for a stream subprogram may be generated outside of the scope -- of the type. If the type is fully private, it may depend on the full -- view of other types (e.g. indexes) that are currently private as well. -- We install the declarations of the package in which the type is declared -- before compiling the body in what is its proper environment. The Check -- parameter indicates if checks are to be suppressed for the stream body. -- We suppress checks for array/record reads, since the rule is that these -- are like assignments, out of range values due to uninitialized storage, -- or other invalid values do NOT cause a Constraint_Error to be raised. -- If we are within an instance body all visibility has been established -- already and there is no need to install the package. -- This mechanism is now extended to the component types of the array type, -- when the component type is not in scope and is private, to handle -- properly the case when the full view has defaulted discriminants. -- This special processing is ultimately caused by the fact that the -- compiler lacks a well-defined phase when full views are visible -- everywhere. Having such a separate pass would remove much of the -- special-case code that shuffles partial and full views in the middle -- of semantic analysis and expansion. procedure Expand_Access_To_Protected_Op (N : Node_Id; Pref : Node_Id; Typ : Entity_Id); -- An attribute reference to a protected subprogram is transformed into -- a pair of pointers: one to the object, and one to the operations. -- This expansion is performed for 'Access and for 'Unrestricted_Access. procedure Expand_Fpt_Attribute (N : Node_Id; Pkg : RE_Id; Nam : Name_Id; Args : List_Id); -- This procedure expands a call to a floating-point attribute function. -- N is the attribute reference node, and Args is a list of arguments to -- be passed to the function call. Pkg identifies the package containing -- the appropriate instantiation of System.Fat_Gen. Float arguments in Args -- have already been converted to the floating-point type for which Pkg was -- instantiated. The Nam argument is the relevant attribute processing -- routine to be called. This is the same as the attribute name, except in -- the Unaligned_Valid case. procedure Expand_Fpt_Attribute_R (N : Node_Id); -- This procedure expands a call to a floating-point attribute function -- that takes a single floating-point argument. The function to be called -- is always the same as the attribute name. procedure Expand_Fpt_Attribute_RI (N : Node_Id); -- This procedure expands a call to a floating-point attribute function -- that takes one floating-point argument and one integer argument. The -- function to be called is always the same as the attribute name. procedure Expand_Fpt_Attribute_RR (N : Node_Id); -- This procedure expands a call to a floating-point attribute function -- that takes two floating-point arguments. The function to be called -- is always the same as the attribute name. procedure Expand_Loop_Entry_Attribute (N : Node_Id); -- Handle the expansion of attribute 'Loop_Entry. As a result, the related -- loop may be converted into a conditional block. See body for details. procedure Expand_Min_Max_Attribute (N : Node_Id); -- Handle the expansion of attributes 'Max and 'Min, including expanding -- then out if we are in Modify_Tree_For_C mode. procedure Expand_Pred_Succ_Attribute (N : Node_Id); -- Handles expansion of Pred or Succ attributes for case of non-real -- operand with overflow checking required. procedure Expand_Update_Attribute (N : Node_Id); -- Handle the expansion of attribute Update function Get_Index_Subtype (N : Node_Id) return Entity_Id; -- Used for Last, Last, and Length, when the prefix is an array type. -- Obtains the corresponding index subtype. procedure Find_Fat_Info (T : Entity_Id; Fat_Type : out Entity_Id; Fat_Pkg : out RE_Id); -- Given a floating-point type T, identifies the package containing the -- attributes for this type (returned in Fat_Pkg), and the corresponding -- type for which this package was instantiated from Fat_Gen. Error if T -- is not a floating-point type. function Find_Stream_Subprogram (Typ : Entity_Id; Nam : TSS_Name_Type) return Entity_Id; -- Returns the stream-oriented subprogram attribute for Typ. For tagged -- types, the corresponding primitive operation is looked up, else the -- appropriate TSS from the type itself, or from its closest ancestor -- defining it, is returned. In both cases, inheritance of representation -- aspects is thus taken into account. function Full_Base (T : Entity_Id) return Entity_Id; -- The stream functions need to examine the underlying representation of -- composite types. In some cases T may be non-private but its base type -- is, in which case the function returns the corresponding full view. function Get_Stream_Convert_Pragma (T : Entity_Id) return Node_Id; -- Given a type, find a corresponding stream convert pragma that applies to -- the implementation base type of this type (Typ). If found, return the -- pragma node, otherwise return Empty if no pragma is found. function Is_Constrained_Packed_Array (Typ : Entity_Id) return Boolean; -- Utility for array attributes, returns true on packed constrained -- arrays, and on access to same. function Is_Inline_Floating_Point_Attribute (N : Node_Id) return Boolean; -- Returns true iff the given node refers to an attribute call that -- can be expanded directly by the back end and does not need front end -- expansion. Typically used for rounding and truncation attributes that -- appear directly inside a conversion to integer. ------------------------- -- Build_Array_VS_Func -- ------------------------- function Build_Array_VS_Func (A_Type : Entity_Id; Nod : Node_Id) return Entity_Id is Loc : constant Source_Ptr := Sloc (Nod); Func_Id : constant Entity_Id := Make_Temporary (Loc, 'V'); Comp_Type : constant Entity_Id := Component_Type (A_Type); Body_Stmts : List_Id; Index_List : List_Id; Formals : List_Id; function Test_Component return List_Id; -- Create one statement to test validity of one component designated by -- a full set of indexes. Returns statement list containing test. function Test_One_Dimension (N : Int) return List_Id; -- Create loop to test one dimension of the array. The single statement -- in the loop body tests the inner dimensions if any, or else the -- single component. Note that this procedure is called recursively, -- with N being the dimension to be initialized. A call with N greater -- than the number of dimensions simply generates the component test, -- terminating the recursion. Returns statement list containing tests. -------------------- -- Test_Component -- -------------------- function Test_Component return List_Id is Comp : Node_Id; Anam : Name_Id; begin Comp := Make_Indexed_Component (Loc, Prefix => Make_Identifier (Loc, Name_uA), Expressions => Index_List); if Is_Scalar_Type (Comp_Type) then Anam := Name_Valid; else Anam := Name_Valid_Scalars; end if; return New_List ( Make_If_Statement (Loc, Condition => Make_Op_Not (Loc, Right_Opnd => Make_Attribute_Reference (Loc, Attribute_Name => Anam, Prefix => Comp)), Then_Statements => New_List ( Make_Simple_Return_Statement (Loc, Expression => New_Occurrence_Of (Standard_False, Loc))))); end Test_Component; ------------------------ -- Test_One_Dimension -- ------------------------ function Test_One_Dimension (N : Int) return List_Id is Index : Entity_Id; begin -- If all dimensions dealt with, we simply test the component if N > Number_Dimensions (A_Type) then return Test_Component; -- Here we generate the required loop else Index := Make_Defining_Identifier (Loc, New_External_Name ('J', N)); Append (New_Occurrence_Of (Index, Loc), Index_List); return New_List ( Make_Implicit_Loop_Statement (Nod, Identifier => Empty, Iteration_Scheme => Make_Iteration_Scheme (Loc, Loop_Parameter_Specification => Make_Loop_Parameter_Specification (Loc, Defining_Identifier => Index, Discrete_Subtype_Definition => Make_Attribute_Reference (Loc, Prefix => Make_Identifier (Loc, Name_uA), Attribute_Name => Name_Range, Expressions => New_List ( Make_Integer_Literal (Loc, N))))), Statements => Test_One_Dimension (N + 1)), Make_Simple_Return_Statement (Loc, Expression => New_Occurrence_Of (Standard_True, Loc))); end if; end Test_One_Dimension; -- Start of processing for Build_Array_VS_Func begin Index_List := New_List; Body_Stmts := Test_One_Dimension (1); -- Parameter is always (A : A_Typ) Formals := New_List ( Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uA), In_Present => True, Out_Present => False, Parameter_Type => New_Occurrence_Of (A_Type, Loc))); -- Build body Set_Ekind (Func_Id, E_Function); Set_Is_Internal (Func_Id); Insert_Action (Nod, Make_Subprogram_Body (Loc, Specification => Make_Function_Specification (Loc, Defining_Unit_Name => Func_Id, Parameter_Specifications => Formals, Result_Definition => New_Occurrence_Of (Standard_Boolean, Loc)), Declarations => New_List, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Body_Stmts))); if not Debug_Generated_Code then Set_Debug_Info_Off (Func_Id); end if; Set_Is_Pure (Func_Id); return Func_Id; end Build_Array_VS_Func; -------------------------- -- Build_Record_VS_Func -- -------------------------- -- Generates: -- function _Valid_Scalars (X : T) return Boolean is -- begin -- -- Check discriminants -- if not X.D1'Valid_Scalars or else -- not X.D2'Valid_Scalars or else -- ... -- then -- return False; -- end if; -- -- Check components -- if not X.C1'Valid_Scalars or else -- not X.C2'Valid_Scalars or else -- ... -- then -- return False; -- end if; -- -- Check variant part -- case X.D1 is -- when V1 => -- if not X.C2'Valid_Scalars or else -- not X.C3'Valid_Scalars or else -- ... -- then -- return False; -- end if; -- ... -- when Vn => -- if not X.Cn'Valid_Scalars or else -- ... -- then -- return False; -- end if; -- end case; -- return True; -- end _Valid_Scalars; function Build_Record_VS_Func (R_Type : Entity_Id; Nod : Node_Id) return Entity_Id is Loc : constant Source_Ptr := Sloc (R_Type); Func_Id : constant Entity_Id := Make_Temporary (Loc, 'V'); X : constant Entity_Id := Make_Defining_Identifier (Loc, Name_X); function Make_VS_Case (E : Entity_Id; CL : Node_Id; Discrs : Elist_Id := New_Elmt_List) return List_Id; -- Building block for variant valid scalars. Given a Component_List node -- CL, it generates an 'if' followed by a 'case' statement that compares -- all components of local temporaries named X and Y (that are declared -- as formals at some upper level). E provides the Sloc to be used for -- the generated code. function Make_VS_If (E : Entity_Id; L : List_Id) return Node_Id; -- Building block for variant validate scalars. Given the list, L, of -- components (or discriminants) L, it generates a return statement that -- compares all components of local temporaries named X and Y (that are -- declared as formals at some upper level). E provides the Sloc to be -- used for the generated code. ------------------ -- Make_VS_Case -- ------------------ -- <Make_VS_If on shared components> -- case X.D1 is -- when V1 => <Make_VS_Case> on subcomponents -- ... -- when Vn => <Make_VS_Case> on subcomponents -- end case; function Make_VS_Case (E : Entity_Id; CL : Node_Id; Discrs : Elist_Id := New_Elmt_List) return List_Id is Loc : constant Source_Ptr := Sloc (E); Result : constant List_Id := New_List; Variant : Node_Id; Alt_List : List_Id; begin Append_To (Result, Make_VS_If (E, Component_Items (CL))); if No (Variant_Part (CL)) then return Result; end if; Variant := First_Non_Pragma (Variants (Variant_Part (CL))); if No (Variant) then return Result; end if; Alt_List := New_List; while Present (Variant) loop Append_To (Alt_List, Make_Case_Statement_Alternative (Loc, Discrete_Choices => New_Copy_List (Discrete_Choices (Variant)), Statements => Make_VS_Case (E, Component_List (Variant), Discrs))); Next_Non_Pragma (Variant); end loop; Append_To (Result, Make_Case_Statement (Loc, Expression => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_X), Selector_Name => New_Copy (Name (Variant_Part (CL)))), Alternatives => Alt_List)); return Result; end Make_VS_Case; ---------------- -- Make_VS_If -- ---------------- -- Generates: -- if -- not X.C1'Valid_Scalars -- or else -- not X.C2'Valid_Scalars -- ... -- then -- return False; -- end if; -- or a null statement if the list L is empty function Make_VS_If (E : Entity_Id; L : List_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (E); C : Node_Id; Def_Id : Entity_Id; Field_Name : Name_Id; Cond : Node_Id; begin if No (L) then return Make_Null_Statement (Loc); else Cond := Empty; C := First_Non_Pragma (L); while Present (C) loop Def_Id := Defining_Identifier (C); Field_Name := Chars (Def_Id); -- The tags need not be checked since they will always be valid -- Note also that in the following, we use Make_Identifier for -- the component names. Use of New_Occurrence_Of to identify -- the components would be incorrect because wrong entities for -- discriminants could be picked up in the private type case. -- Don't bother with abstract parent in interface case if Field_Name = Name_uParent and then Is_Interface (Etype (Def_Id)) then null; -- Don't bother with tag, always valid, and not scalar anyway elsif Field_Name = Name_uTag then null; -- Don't bother with component with no scalar components elsif not Scalar_Part_Present (Etype (Def_Id)) then null; -- Normal case, generate Valid_Scalars attribute reference else Evolve_Or_Else (Cond, Make_Op_Not (Loc, Right_Opnd => Make_Attribute_Reference (Loc, Prefix => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_X), Selector_Name => Make_Identifier (Loc, Field_Name)), Attribute_Name => Name_Valid_Scalars))); end if; Next_Non_Pragma (C); end loop; if No (Cond) then return Make_Null_Statement (Loc); else return Make_Implicit_If_Statement (E, Condition => Cond, Then_Statements => New_List ( Make_Simple_Return_Statement (Loc, Expression => New_Occurrence_Of (Standard_False, Loc)))); end if; end if; end Make_VS_If; -- Local variables Def : constant Node_Id := Parent (R_Type); Comps : constant Node_Id := Component_List (Type_Definition (Def)); Stmts : constant List_Id := New_List; Pspecs : constant List_Id := New_List; -- Start of processing for Build_Record_VS_Func begin Append_To (Pspecs, Make_Parameter_Specification (Loc, Defining_Identifier => X, Parameter_Type => New_Occurrence_Of (R_Type, Loc))); Append_To (Stmts, Make_VS_If (R_Type, Discriminant_Specifications (Def))); Append_List_To (Stmts, Make_VS_Case (R_Type, Comps)); Append_To (Stmts, Make_Simple_Return_Statement (Loc, Expression => New_Occurrence_Of (Standard_True, Loc))); Insert_Action (Nod, Make_Subprogram_Body (Loc, Specification => Make_Function_Specification (Loc, Defining_Unit_Name => Func_Id, Parameter_Specifications => Pspecs, Result_Definition => New_Occurrence_Of (Standard_Boolean, Loc)), Declarations => New_List, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts)), Suppress => Discriminant_Check); if not Debug_Generated_Code then Set_Debug_Info_Off (Func_Id); end if; Set_Is_Pure (Func_Id); return Func_Id; end Build_Record_VS_Func; ---------------------------------- -- Compile_Stream_Body_In_Scope -- ---------------------------------- procedure Compile_Stream_Body_In_Scope (N : Node_Id; Decl : Node_Id; Arr : Entity_Id; Check : Boolean) is C_Type : constant Entity_Id := Base_Type (Component_Type (Arr)); Curr : constant Entity_Id := Current_Scope; Install : Boolean := False; Scop : Entity_Id := Scope (Arr); begin if Is_Hidden (Arr) and then not In_Open_Scopes (Scop) and then Ekind (Scop) = E_Package then Install := True; else -- The component type may be private, in which case we install its -- full view to compile the subprogram. -- The component type may be private, in which case we install its -- full view to compile the subprogram. We do not do this if the -- type has a Stream_Convert pragma, which indicates that there are -- special stream-processing operations for that type (for example -- Unbounded_String and its wide varieties). Scop := Scope (C_Type); if Is_Private_Type (C_Type) and then Present (Full_View (C_Type)) and then not In_Open_Scopes (Scop) and then Ekind (Scop) = E_Package and then No (Get_Stream_Convert_Pragma (C_Type)) then Install := True; end if; end if; -- If we are within an instance body, then all visibility has been -- established already and there is no need to install the package. if Install and then not In_Instance_Body then Push_Scope (Scop); Install_Visible_Declarations (Scop); Install_Private_Declarations (Scop); -- The entities in the package are now visible, but the generated -- stream entity must appear in the current scope (usually an -- enclosing stream function) so that itypes all have their proper -- scopes. Push_Scope (Curr); else Install := False; end if; if Check then Insert_Action (N, Decl); else Insert_Action (N, Decl, Suppress => All_Checks); end if; if Install then -- Remove extra copy of current scope, and package itself Pop_Scope; End_Package_Scope (Scop); end if; end Compile_Stream_Body_In_Scope; ----------------------------------- -- Expand_Access_To_Protected_Op -- ----------------------------------- procedure Expand_Access_To_Protected_Op (N : Node_Id; Pref : Node_Id; Typ : Entity_Id) is -- The value of the attribute_reference is a record containing two -- fields: an access to the protected object, and an access to the -- subprogram itself. The prefix is a selected component. Loc : constant Source_Ptr := Sloc (N); Agg : Node_Id; Btyp : constant Entity_Id := Base_Type (Typ); Sub : Entity_Id; Sub_Ref : Node_Id; E_T : constant Entity_Id := Equivalent_Type (Btyp); Acc : constant Entity_Id := Etype (Next_Component (First_Component (E_T))); Obj_Ref : Node_Id; Curr : Entity_Id; -- Start of processing for Expand_Access_To_Protected_Op begin -- Within the body of the protected type, the prefix designates a local -- operation, and the object is the first parameter of the corresponding -- protected body of the current enclosing operation. if Is_Entity_Name (Pref) then -- All indirect calls are external calls, so must do locking and -- barrier reevaluation, even if the 'Access occurs within the -- protected body. Hence the call to External_Subprogram, as opposed -- to Protected_Body_Subprogram, below. See RM-9.5(5). This means -- that indirect calls from within the same protected body will -- deadlock, as allowed by RM-9.5.1(8,15,17). Sub := New_Occurrence_Of (External_Subprogram (Entity (Pref)), Loc); -- Don't traverse the scopes when the attribute occurs within an init -- proc, because we directly use the _init formal of the init proc in -- that case. Curr := Current_Scope; if not Is_Init_Proc (Curr) then pragma Assert (In_Open_Scopes (Scope (Entity (Pref)))); while Scope (Curr) /= Scope (Entity (Pref)) loop Curr := Scope (Curr); end loop; end if; -- In case of protected entries the first formal of its Protected_ -- Body_Subprogram is the address of the object. if Ekind (Curr) = E_Entry then Obj_Ref := New_Occurrence_Of (First_Formal (Protected_Body_Subprogram (Curr)), Loc); -- If the current scope is an init proc, then use the address of the -- _init formal as the object reference. elsif Is_Init_Proc (Curr) then Obj_Ref := Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (First_Formal (Curr), Loc), Attribute_Name => Name_Address); -- In case of protected subprograms the first formal of its -- Protected_Body_Subprogram is the object and we get its address. else Obj_Ref := Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (First_Formal (Protected_Body_Subprogram (Curr)), Loc), Attribute_Name => Name_Address); end if; -- Case where the prefix is not an entity name. Find the -- version of the protected operation to be called from -- outside the protected object. else Sub := New_Occurrence_Of (External_Subprogram (Entity (Selector_Name (Pref))), Loc); Obj_Ref := Make_Attribute_Reference (Loc, Prefix => Relocate_Node (Prefix (Pref)), Attribute_Name => Name_Address); end if; Sub_Ref := Make_Attribute_Reference (Loc, Prefix => Sub, Attribute_Name => Name_Access); -- We set the type of the access reference to the already generated -- access_to_subprogram type, and declare the reference analyzed, to -- prevent further expansion when the enclosing aggregate is analyzed. Set_Etype (Sub_Ref, Acc); Set_Analyzed (Sub_Ref); Agg := Make_Aggregate (Loc, Expressions => New_List (Obj_Ref, Sub_Ref)); -- Sub_Ref has been marked as analyzed, but we still need to make sure -- Sub is correctly frozen. Freeze_Before (N, Entity (Sub)); Rewrite (N, Agg); Analyze_And_Resolve (N, E_T); -- For subsequent analysis, the node must retain its type. The backend -- will replace it with the equivalent type where needed. Set_Etype (N, Typ); end Expand_Access_To_Protected_Op; -------------------------- -- Expand_Fpt_Attribute -- -------------------------- procedure Expand_Fpt_Attribute (N : Node_Id; Pkg : RE_Id; Nam : Name_Id; Args : List_Id) is Loc : constant Source_Ptr := Sloc (N); Typ : constant Entity_Id := Etype (N); Fnm : Node_Id; begin -- The function name is the selected component Attr_xxx.yyy where -- Attr_xxx is the package name, and yyy is the argument Nam. -- Note: it would be more usual to have separate RE entries for each -- of the entities in the Fat packages, but first they have identical -- names (so we would have to have lots of renaming declarations to -- meet the normal RE rule of separate names for all runtime entities), -- and second there would be an awful lot of them. Fnm := Make_Selected_Component (Loc, Prefix => New_Occurrence_Of (RTE (Pkg), Loc), Selector_Name => Make_Identifier (Loc, Nam)); -- The generated call is given the provided set of parameters, and then -- wrapped in a conversion which converts the result to the target type -- We use the base type as the target because a range check may be -- required. Rewrite (N, Unchecked_Convert_To (Base_Type (Etype (N)), Make_Function_Call (Loc, Name => Fnm, Parameter_Associations => Args))); Analyze_And_Resolve (N, Typ); end Expand_Fpt_Attribute; ---------------------------- -- Expand_Fpt_Attribute_R -- ---------------------------- -- The single argument is converted to its root type to call the -- appropriate runtime function, with the actual call being built -- by Expand_Fpt_Attribute procedure Expand_Fpt_Attribute_R (N : Node_Id) is E1 : constant Node_Id := First (Expressions (N)); Ftp : Entity_Id; Pkg : RE_Id; begin Find_Fat_Info (Etype (E1), Ftp, Pkg); Expand_Fpt_Attribute (N, Pkg, Attribute_Name (N), New_List (Unchecked_Convert_To (Ftp, Relocate_Node (E1)))); end Expand_Fpt_Attribute_R; ----------------------------- -- Expand_Fpt_Attribute_RI -- ----------------------------- -- The first argument is converted to its root type and the second -- argument is converted to standard long long integer to call the -- appropriate runtime function, with the actual call being built -- by Expand_Fpt_Attribute procedure Expand_Fpt_Attribute_RI (N : Node_Id) is E1 : constant Node_Id := First (Expressions (N)); Ftp : Entity_Id; Pkg : RE_Id; E2 : constant Node_Id := Next (E1); begin Find_Fat_Info (Etype (E1), Ftp, Pkg); Expand_Fpt_Attribute (N, Pkg, Attribute_Name (N), New_List ( Unchecked_Convert_To (Ftp, Relocate_Node (E1)), Unchecked_Convert_To (Standard_Integer, Relocate_Node (E2)))); end Expand_Fpt_Attribute_RI; ----------------------------- -- Expand_Fpt_Attribute_RR -- ----------------------------- -- The two arguments are converted to their root types to call the -- appropriate runtime function, with the actual call being built -- by Expand_Fpt_Attribute procedure Expand_Fpt_Attribute_RR (N : Node_Id) is E1 : constant Node_Id := First (Expressions (N)); E2 : constant Node_Id := Next (E1); Ftp : Entity_Id; Pkg : RE_Id; begin Find_Fat_Info (Etype (E1), Ftp, Pkg); Expand_Fpt_Attribute (N, Pkg, Attribute_Name (N), New_List ( Unchecked_Convert_To (Ftp, Relocate_Node (E1)), Unchecked_Convert_To (Ftp, Relocate_Node (E2)))); end Expand_Fpt_Attribute_RR; --------------------------------- -- Expand_Loop_Entry_Attribute -- --------------------------------- procedure Expand_Loop_Entry_Attribute (N : Node_Id) is procedure Build_Conditional_Block (Loc : Source_Ptr; Cond : Node_Id; Loop_Stmt : Node_Id; If_Stmt : out Node_Id; Blk_Stmt : out Node_Id); -- Create a block Blk_Stmt with an empty declarative list and a single -- loop Loop_Stmt. The block is encased in an if statement If_Stmt with -- condition Cond. If_Stmt is Empty when there is no condition provided. function Is_Array_Iteration (N : Node_Id) return Boolean; -- Determine whether loop statement N denotes an Ada 2012 iteration over -- an array object. ----------------------------- -- Build_Conditional_Block -- ----------------------------- procedure Build_Conditional_Block (Loc : Source_Ptr; Cond : Node_Id; Loop_Stmt : Node_Id; If_Stmt : out Node_Id; Blk_Stmt : out Node_Id) is begin -- Do not reanalyze the original loop statement because it is simply -- being relocated. Set_Analyzed (Loop_Stmt); Blk_Stmt := Make_Block_Statement (Loc, Declarations => New_List, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List (Loop_Stmt))); if Present (Cond) then If_Stmt := Make_If_Statement (Loc, Condition => Cond, Then_Statements => New_List (Blk_Stmt)); else If_Stmt := Empty; end if; end Build_Conditional_Block; ------------------------ -- Is_Array_Iteration -- ------------------------ function Is_Array_Iteration (N : Node_Id) return Boolean is Stmt : constant Node_Id := Original_Node (N); Iter : Node_Id; begin if Nkind (Stmt) = N_Loop_Statement and then Present (Iteration_Scheme (Stmt)) and then Present (Iterator_Specification (Iteration_Scheme (Stmt))) then Iter := Iterator_Specification (Iteration_Scheme (Stmt)); return Of_Present (Iter) and then Is_Array_Type (Etype (Name (Iter))); end if; return False; end Is_Array_Iteration; -- Local variables Pref : constant Node_Id := Prefix (N); Base_Typ : constant Entity_Id := Base_Type (Etype (Pref)); Exprs : constant List_Id := Expressions (N); Aux_Decl : Node_Id; Blk : Node_Id; Decls : List_Id; Installed : Boolean; Loc : Source_Ptr; Loop_Id : Entity_Id; Loop_Stmt : Node_Id; Result : Node_Id; Scheme : Node_Id; Temp_Decl : Node_Id; Temp_Id : Entity_Id; -- Start of processing for Expand_Loop_Entry_Attribute begin -- Step 1: Find the related loop -- The loop label variant of attribute 'Loop_Entry already has all the -- information in its expression. if Present (Exprs) then Loop_Id := Entity (First (Exprs)); Loop_Stmt := Label_Construct (Parent (Loop_Id)); -- Climb the parent chain to find the nearest enclosing loop. Skip -- all internally generated loops for quantified expressions and for -- element iterators over multidimensional arrays because the pragma -- applies to source loop. else Loop_Stmt := N; while Present (Loop_Stmt) loop if Nkind (Loop_Stmt) = N_Loop_Statement and then Comes_From_Source (Loop_Stmt) then exit; end if; Loop_Stmt := Parent (Loop_Stmt); end loop; Loop_Id := Entity (Identifier (Loop_Stmt)); end if; Loc := Sloc (Loop_Stmt); -- Step 2: Transform the loop -- The loop has already been transformed during the expansion of a prior -- 'Loop_Entry attribute. Retrieve the declarative list of the block. if Has_Loop_Entry_Attributes (Loop_Id) then -- When the related loop name appears as the argument of attribute -- Loop_Entry, the corresponding label construct is the generated -- block statement. This is because the expander reuses the label. if Nkind (Loop_Stmt) = N_Block_Statement then Decls := Declarations (Loop_Stmt); -- In all other cases, the loop must appear in the handled sequence -- of statements of the generated block. else pragma Assert (Nkind (Parent (Loop_Stmt)) = N_Handled_Sequence_Of_Statements and then Nkind (Parent (Parent (Loop_Stmt))) = N_Block_Statement); Decls := Declarations (Parent (Parent (Loop_Stmt))); end if; Result := Empty; -- Transform the loop into a conditional block else Set_Has_Loop_Entry_Attributes (Loop_Id); Scheme := Iteration_Scheme (Loop_Stmt); -- Infinite loops are transformed into: -- declare -- Temp1 : constant <type of Pref1> := <Pref1>; -- . . . -- TempN : constant <type of PrefN> := <PrefN>; -- begin -- loop -- <original source statements with attribute rewrites> -- end loop; -- end; if No (Scheme) then Build_Conditional_Block (Loc, Cond => Empty, Loop_Stmt => Relocate_Node (Loop_Stmt), If_Stmt => Result, Blk_Stmt => Blk); Result := Blk; -- While loops are transformed into: -- function Fnn return Boolean is -- begin -- <condition actions> -- return <condition>; -- end Fnn; -- if Fnn then -- declare -- Temp1 : constant <type of Pref1> := <Pref1>; -- . . . -- TempN : constant <type of PrefN> := <PrefN>; -- begin -- loop -- <original source statements with attribute rewrites> -- exit when not Fnn; -- end loop; -- end; -- end if; -- Note that loops over iterators and containers are already -- converted into while loops. elsif Present (Condition (Scheme)) then declare Func_Decl : Node_Id; Func_Id : Entity_Id; Stmts : List_Id; begin -- Wrap the condition of the while loop in a Boolean function. -- This avoids the duplication of the same code which may lead -- to gigi issues with respect to multiple declaration of the -- same entity in the presence of side effects or checks. Note -- that the condition actions must also be relocated to the -- wrapping function. -- Generate: -- <condition actions> -- return <condition>; if Present (Condition_Actions (Scheme)) then Stmts := Condition_Actions (Scheme); else Stmts := New_List; end if; Append_To (Stmts, Make_Simple_Return_Statement (Loc, Expression => Relocate_Node (Condition (Scheme)))); -- Generate: -- function Fnn return Boolean is -- begin -- <Stmts> -- end Fnn; Func_Id := Make_Temporary (Loc, 'F'); Func_Decl := Make_Subprogram_Body (Loc, Specification => Make_Function_Specification (Loc, Defining_Unit_Name => Func_Id, Result_Definition => New_Occurrence_Of (Standard_Boolean, Loc)), Declarations => Empty_List, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts)); -- The function is inserted before the related loop. Make sure -- to analyze it in the context of the loop's enclosing scope. Push_Scope (Scope (Loop_Id)); Insert_Action (Loop_Stmt, Func_Decl); Pop_Scope; -- Transform the original while loop into an infinite loop -- where the last statement checks the negated condition. This -- placement ensures that the condition will not be evaluated -- twice on the first iteration. Set_Iteration_Scheme (Loop_Stmt, Empty); Scheme := Empty; -- Generate: -- exit when not Fnn; Append_To (Statements (Loop_Stmt), Make_Exit_Statement (Loc, Condition => Make_Op_Not (Loc, Right_Opnd => Make_Function_Call (Loc, Name => New_Occurrence_Of (Func_Id, Loc))))); Build_Conditional_Block (Loc, Cond => Make_Function_Call (Loc, Name => New_Occurrence_Of (Func_Id, Loc)), Loop_Stmt => Relocate_Node (Loop_Stmt), If_Stmt => Result, Blk_Stmt => Blk); end; -- Ada 2012 iteration over an array is transformed into: -- if <Array_Nam>'Length (1) > 0 -- and then <Array_Nam>'Length (N) > 0 -- then -- declare -- Temp1 : constant <type of Pref1> := <Pref1>; -- . . . -- TempN : constant <type of PrefN> := <PrefN>; -- begin -- for X in ... loop -- multiple loops depending on dims -- <original source statements with attribute rewrites> -- end loop; -- end; -- end if; elsif Is_Array_Iteration (Loop_Stmt) then declare Array_Nam : constant Entity_Id := Entity (Name (Iterator_Specification (Iteration_Scheme (Original_Node (Loop_Stmt))))); Num_Dims : constant Pos := Number_Dimensions (Etype (Array_Nam)); Cond : Node_Id := Empty; Check : Node_Id; begin -- Generate a check which determines whether all dimensions of -- the array are non-null. for Dim in 1 .. Num_Dims loop Check := Make_Op_Gt (Loc, Left_Opnd => Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Array_Nam, Loc), Attribute_Name => Name_Length, Expressions => New_List ( Make_Integer_Literal (Loc, Dim))), Right_Opnd => Make_Integer_Literal (Loc, 0)); if No (Cond) then Cond := Check; else Cond := Make_And_Then (Loc, Left_Opnd => Cond, Right_Opnd => Check); end if; end loop; Build_Conditional_Block (Loc, Cond => Cond, Loop_Stmt => Relocate_Node (Loop_Stmt), If_Stmt => Result, Blk_Stmt => Blk); end; -- For loops are transformed into: -- if <Low> <= <High> then -- declare -- Temp1 : constant <type of Pref1> := <Pref1>; -- . . . -- TempN : constant <type of PrefN> := <PrefN>; -- begin -- for <Def_Id> in <Low> .. <High> loop -- <original source statements with attribute rewrites> -- end loop; -- end; -- end if; elsif Present (Loop_Parameter_Specification (Scheme)) then declare Loop_Spec : constant Node_Id := Loop_Parameter_Specification (Scheme); Cond : Node_Id; Subt_Def : Node_Id; begin Subt_Def := Discrete_Subtype_Definition (Loop_Spec); -- When the loop iterates over a subtype indication with a -- range, use the low and high bounds of the subtype itself. if Nkind (Subt_Def) = N_Subtype_Indication then Subt_Def := Scalar_Range (Etype (Subt_Def)); end if; pragma Assert (Nkind (Subt_Def) = N_Range); -- Generate -- Low <= High Cond := Make_Op_Le (Loc, Left_Opnd => New_Copy_Tree (Low_Bound (Subt_Def)), Right_Opnd => New_Copy_Tree (High_Bound (Subt_Def))); Build_Conditional_Block (Loc, Cond => Cond, Loop_Stmt => Relocate_Node (Loop_Stmt), If_Stmt => Result, Blk_Stmt => Blk); end; end if; Decls := Declarations (Blk); end if; -- Step 3: Create a constant to capture the value of the prefix at the -- entry point into the loop. Temp_Id := Make_Temporary (Loc, 'P'); -- Preserve the tag of the prefix by offering a specific view of the -- class-wide version of the prefix. if Is_Tagged_Type (Base_Typ) then Tagged_Case : declare CW_Temp : Entity_Id; CW_Typ : Entity_Id; begin -- Generate: -- CW_Temp : constant Base_Typ'Class := Base_Typ'Class (Pref); CW_Temp := Make_Temporary (Loc, 'T'); CW_Typ := Class_Wide_Type (Base_Typ); Aux_Decl := Make_Object_Declaration (Loc, Defining_Identifier => CW_Temp, Constant_Present => True, Object_Definition => New_Occurrence_Of (CW_Typ, Loc), Expression => Convert_To (CW_Typ, Relocate_Node (Pref))); Append_To (Decls, Aux_Decl); -- Generate: -- Temp : Base_Typ renames Base_Typ (CW_Temp); Temp_Decl := Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Temp_Id, Subtype_Mark => New_Occurrence_Of (Base_Typ, Loc), Name => Convert_To (Base_Typ, New_Occurrence_Of (CW_Temp, Loc))); Append_To (Decls, Temp_Decl); end Tagged_Case; -- Untagged case else Untagged_Case : declare Temp_Expr : Node_Id; begin Aux_Decl := Empty; -- Generate a nominal type for the constant when the prefix is of -- a constrained type. This is achieved by setting the Etype of -- the relocated prefix to its base type. Since the prefix is now -- the initialization expression of the constant, its freezing -- will produce a proper nominal type. Temp_Expr := Relocate_Node (Pref); Set_Etype (Temp_Expr, Base_Typ); -- Generate: -- Temp : constant Base_Typ := Pref; Temp_Decl := Make_Object_Declaration (Loc, Defining_Identifier => Temp_Id, Constant_Present => True, Object_Definition => New_Occurrence_Of (Base_Typ, Loc), Expression => Temp_Expr); Append_To (Decls, Temp_Decl); end Untagged_Case; end if; -- Step 4: Analyze all bits Installed := Current_Scope = Scope (Loop_Id); -- Depending on the pracement of attribute 'Loop_Entry relative to the -- associated loop, ensure the proper visibility for analysis. if not Installed then Push_Scope (Scope (Loop_Id)); end if; -- The analysis of the conditional block takes care of the constant -- declaration. if Present (Result) then Rewrite (Loop_Stmt, Result); Analyze (Loop_Stmt); -- The conditional block was analyzed when a previous 'Loop_Entry was -- expanded. There is no point in reanalyzing the block, simply analyze -- the declaration of the constant. else if Present (Aux_Decl) then Analyze (Aux_Decl); end if; Analyze (Temp_Decl); end if; Rewrite (N, New_Occurrence_Of (Temp_Id, Loc)); Analyze (N); if not Installed then Pop_Scope; end if; end Expand_Loop_Entry_Attribute; ------------------------------ -- Expand_Min_Max_Attribute -- ------------------------------ procedure Expand_Min_Max_Attribute (N : Node_Id) is begin -- Min and Max are handled by the back end (except that static cases -- have already been evaluated during semantic processing, although the -- back end should not count on this). The one bit of special processing -- required in the normal case is that these two attributes typically -- generate conditionals in the code, so check the relevant restriction. Check_Restriction (No_Implicit_Conditionals, N); -- In Modify_Tree_For_C mode, we rewrite as an if expression if Modify_Tree_For_C then declare Loc : constant Source_Ptr := Sloc (N); Typ : constant Entity_Id := Etype (N); Expr : constant Node_Id := First (Expressions (N)); Left : constant Node_Id := Relocate_Node (Expr); Right : constant Node_Id := Relocate_Node (Next (Expr)); function Make_Compare (Left, Right : Node_Id) return Node_Id; -- Returns Left >= Right for Max, Left <= Right for Min ------------------ -- Make_Compare -- ------------------ function Make_Compare (Left, Right : Node_Id) return Node_Id is begin if Attribute_Name (N) = Name_Max then return Make_Op_Ge (Loc, Left_Opnd => Left, Right_Opnd => Right); else return Make_Op_Le (Loc, Left_Opnd => Left, Right_Opnd => Right); end if; end Make_Compare; -- Start of processing for Min_Max begin -- If both Left and Right are side effect free, then we can just -- use Duplicate_Expr to duplicate the references and return -- (if Left >=|<= Right then Left else Right) if Side_Effect_Free (Left) and then Side_Effect_Free (Right) then Rewrite (N, Make_If_Expression (Loc, Expressions => New_List ( Make_Compare (Left, Right), Duplicate_Subexpr_No_Checks (Left), Duplicate_Subexpr_No_Checks (Right)))); -- Otherwise we generate declarations to capture the values. -- The translation is -- do -- T1 : constant typ := Left; -- T2 : constant typ := Right; -- in -- (if T1 >=|<= T2 then T1 else T2) -- end; else declare T1 : constant Entity_Id := Make_Temporary (Loc, 'T', Left); T2 : constant Entity_Id := Make_Temporary (Loc, 'T', Right); begin Rewrite (N, Make_Expression_With_Actions (Loc, Actions => New_List ( Make_Object_Declaration (Loc, Defining_Identifier => T1, Constant_Present => True, Object_Definition => New_Occurrence_Of (Etype (Left), Loc), Expression => Relocate_Node (Left)), Make_Object_Declaration (Loc, Defining_Identifier => T2, Constant_Present => True, Object_Definition => New_Occurrence_Of (Etype (Right), Loc), Expression => Relocate_Node (Right))), Expression => Make_If_Expression (Loc, Expressions => New_List ( Make_Compare (New_Occurrence_Of (T1, Loc), New_Occurrence_Of (T2, Loc)), New_Occurrence_Of (T1, Loc), New_Occurrence_Of (T2, Loc))))); end; end if; Analyze_And_Resolve (N, Typ); end; end if; end Expand_Min_Max_Attribute; ---------------------------------- -- Expand_N_Attribute_Reference -- ---------------------------------- procedure Expand_N_Attribute_Reference (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Typ : constant Entity_Id := Etype (N); Btyp : constant Entity_Id := Base_Type (Typ); Pref : constant Node_Id := Prefix (N); Ptyp : constant Entity_Id := Etype (Pref); Exprs : constant List_Id := Expressions (N); Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (N)); procedure Rewrite_Stream_Proc_Call (Pname : Entity_Id); -- Rewrites a stream attribute for Read, Write or Output with the -- procedure call. Pname is the entity for the procedure to call. ------------------------------ -- Rewrite_Stream_Proc_Call -- ------------------------------ procedure Rewrite_Stream_Proc_Call (Pname : Entity_Id) is Item : constant Node_Id := Next (First (Exprs)); Item_Typ : constant Entity_Id := Etype (Item); Formal : constant Entity_Id := Next_Formal (First_Formal (Pname)); Formal_Typ : constant Entity_Id := Etype (Formal); Is_Written : constant Boolean := Ekind (Formal) /= E_In_Parameter; begin -- The expansion depends on Item, the second actual, which is -- the object being streamed in or out. -- If the item is a component of a packed array type, and -- a conversion is needed on exit, we introduce a temporary to -- hold the value, because otherwise the packed reference will -- not be properly expanded. if Nkind (Item) = N_Indexed_Component and then Is_Packed (Base_Type (Etype (Prefix (Item)))) and then Base_Type (Item_Typ) /= Base_Type (Formal_Typ) and then Is_Written then declare Temp : constant Entity_Id := Make_Temporary (Loc, 'V'); Decl : Node_Id; Assn : Node_Id; begin Decl := Make_Object_Declaration (Loc, Defining_Identifier => Temp, Object_Definition => New_Occurrence_Of (Formal_Typ, Loc)); Set_Etype (Temp, Formal_Typ); Assn := Make_Assignment_Statement (Loc, Name => New_Copy_Tree (Item), Expression => Unchecked_Convert_To (Item_Typ, New_Occurrence_Of (Temp, Loc))); Rewrite (Item, New_Occurrence_Of (Temp, Loc)); Insert_Actions (N, New_List ( Decl, Make_Procedure_Call_Statement (Loc, Name => New_Occurrence_Of (Pname, Loc), Parameter_Associations => Exprs), Assn)); Rewrite (N, Make_Null_Statement (Loc)); return; end; end if; -- For the class-wide dispatching cases, and for cases in which -- the base type of the second argument matches the base type of -- the corresponding formal parameter (that is to say the stream -- operation is not inherited), we are all set, and can use the -- argument unchanged. if not Is_Class_Wide_Type (Entity (Pref)) and then not Is_Class_Wide_Type (Etype (Item)) and then Base_Type (Item_Typ) /= Base_Type (Formal_Typ) then -- Perform a view conversion when either the argument or the -- formal parameter are of a private type. if Is_Private_Type (Formal_Typ) or else Is_Private_Type (Item_Typ) then Rewrite (Item, Unchecked_Convert_To (Formal_Typ, Relocate_Node (Item))); -- Otherwise perform a regular type conversion to ensure that all -- relevant checks are installed. else Rewrite (Item, Convert_To (Formal_Typ, Relocate_Node (Item))); end if; -- For untagged derived types set Assignment_OK, to prevent -- copies from being created when the unchecked conversion -- is expanded (which would happen in Remove_Side_Effects -- if Expand_N_Unchecked_Conversion were allowed to call -- Force_Evaluation). The copy could violate Ada semantics in -- cases such as an actual that is an out parameter. Note that -- this approach is also used in exp_ch7 for calls to controlled -- type operations to prevent problems with actuals wrapped in -- unchecked conversions. if Is_Untagged_Derivation (Etype (Expression (Item))) then Set_Assignment_OK (Item); end if; end if; -- The stream operation to call may be a renaming created by an -- attribute definition clause, and may not be frozen yet. Ensure -- that it has the necessary extra formals. if not Is_Frozen (Pname) then Create_Extra_Formals (Pname); end if; -- And now rewrite the call Rewrite (N, Make_Procedure_Call_Statement (Loc, Name => New_Occurrence_Of (Pname, Loc), Parameter_Associations => Exprs)); Analyze (N); end Rewrite_Stream_Proc_Call; -- Start of processing for Expand_N_Attribute_Reference begin -- Do required validity checking, if enabled. Do not apply check to -- output parameters of an Asm instruction, since the value of this -- is not set till after the attribute has been elaborated, and do -- not apply the check to the arguments of a 'Read or 'Input attribute -- reference since the scalar argument is an OUT scalar. if Validity_Checks_On and then Validity_Check_Operands and then Id /= Attribute_Asm_Output and then Id /= Attribute_Read and then Id /= Attribute_Input then declare Expr : Node_Id; begin Expr := First (Expressions (N)); while Present (Expr) loop Ensure_Valid (Expr); Next (Expr); end loop; end; end if; -- Ada 2005 (AI-318-02): If attribute prefix is a call to a build-in- -- place function, then a temporary return object needs to be created -- and access to it must be passed to the function. Currently we limit -- such functions to those with inherently limited result subtypes, but -- eventually we plan to expand the functions that are treated as -- build-in-place to include other composite result types. if Ada_Version >= Ada_2005 and then Is_Build_In_Place_Function_Call (Pref) then Make_Build_In_Place_Call_In_Anonymous_Context (Pref); end if; -- If prefix is a protected type name, this is a reference to the -- current instance of the type. For a component definition, nothing -- to do (expansion will occur in the init proc). In other contexts, -- rewrite into reference to current instance. if Is_Protected_Self_Reference (Pref) and then not (Nkind_In (Parent (N), N_Index_Or_Discriminant_Constraint, N_Discriminant_Association) and then Nkind (Parent (Parent (Parent (Parent (N))))) = N_Component_Definition) -- No action needed for these attributes since the current instance -- will be rewritten to be the name of the _object parameter -- associated with the enclosing protected subprogram (see below). and then Id /= Attribute_Access and then Id /= Attribute_Unchecked_Access and then Id /= Attribute_Unrestricted_Access then Rewrite (Pref, Concurrent_Ref (Pref)); Analyze (Pref); end if; -- Remaining processing depends on specific attribute -- Note: individual sections of the following case statement are -- allowed to assume there is no code after the case statement, and -- are legitimately allowed to execute return statements if they have -- nothing more to do. case Id is -- Attributes related to Ada 2012 iterators when Attribute_Constant_Indexing | Attribute_Default_Iterator | Attribute_Implicit_Dereference | Attribute_Iterable | Attribute_Iterator_Element | Attribute_Variable_Indexing => null; -- Internal attributes used to deal with Ada 2012 delayed aspects. These -- were already rejected by the parser. Thus they shouldn't appear here. when Internal_Attribute_Id => raise Program_Error; ------------ -- Access -- ------------ when Attribute_Access | Attribute_Unchecked_Access | Attribute_Unrestricted_Access => Access_Cases : declare Ref_Object : constant Node_Id := Get_Referenced_Object (Pref); Btyp_DDT : Entity_Id; function Enclosing_Object (N : Node_Id) return Node_Id; -- If N denotes a compound name (selected component, indexed -- component, or slice), returns the name of the outermost such -- enclosing object. Otherwise returns N. If the object is a -- renaming, then the renamed object is returned. ---------------------- -- Enclosing_Object -- ---------------------- function Enclosing_Object (N : Node_Id) return Node_Id is Obj_Name : Node_Id; begin Obj_Name := N; while Nkind_In (Obj_Name, N_Selected_Component, N_Indexed_Component, N_Slice) loop Obj_Name := Prefix (Obj_Name); end loop; return Get_Referenced_Object (Obj_Name); end Enclosing_Object; -- Local declarations Enc_Object : constant Node_Id := Enclosing_Object (Ref_Object); -- Start of processing for Access_Cases begin Btyp_DDT := Designated_Type (Btyp); -- Handle designated types that come from the limited view if From_Limited_With (Btyp_DDT) and then Has_Non_Limited_View (Btyp_DDT) then Btyp_DDT := Non_Limited_View (Btyp_DDT); end if; -- In order to improve the text of error messages, the designated -- type of access-to-subprogram itypes is set by the semantics as -- the associated subprogram entity (see sem_attr). Now we replace -- such node with the proper E_Subprogram_Type itype. if Id = Attribute_Unrestricted_Access and then Is_Subprogram (Directly_Designated_Type (Typ)) then -- The following conditions ensure that this special management -- is done only for "Address!(Prim'Unrestricted_Access)" nodes. -- At this stage other cases in which the designated type is -- still a subprogram (instead of an E_Subprogram_Type) are -- wrong because the semantics must have overridden the type of -- the node with the type imposed by the context. if Nkind (Parent (N)) = N_Unchecked_Type_Conversion and then Etype (Parent (N)) = RTE (RE_Prim_Ptr) then Set_Etype (N, RTE (RE_Prim_Ptr)); else declare Subp : constant Entity_Id := Directly_Designated_Type (Typ); Etyp : Entity_Id; Extra : Entity_Id := Empty; New_Formal : Entity_Id; Old_Formal : Entity_Id := First_Formal (Subp); Subp_Typ : Entity_Id; begin Subp_Typ := Create_Itype (E_Subprogram_Type, N); Set_Etype (Subp_Typ, Etype (Subp)); Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp)); if Present (Old_Formal) then New_Formal := New_Copy (Old_Formal); Set_First_Entity (Subp_Typ, New_Formal); loop Set_Scope (New_Formal, Subp_Typ); Etyp := Etype (New_Formal); -- Handle itypes. There is no need to duplicate -- here the itypes associated with record types -- (i.e the implicit full view of private types). if Is_Itype (Etyp) and then Ekind (Base_Type (Etyp)) /= E_Record_Type then Extra := New_Copy (Etyp); Set_Parent (Extra, New_Formal); Set_Etype (New_Formal, Extra); Set_Scope (Extra, Subp_Typ); end if; Extra := New_Formal; Next_Formal (Old_Formal); exit when No (Old_Formal); Set_Next_Entity (New_Formal, New_Copy (Old_Formal)); Next_Entity (New_Formal); end loop; Set_Next_Entity (New_Formal, Empty); Set_Last_Entity (Subp_Typ, Extra); end if; -- Now that the explicit formals have been duplicated, -- any extra formals needed by the subprogram must be -- created. if Present (Extra) then Set_Extra_Formal (Extra, Empty); end if; Create_Extra_Formals (Subp_Typ); Set_Directly_Designated_Type (Typ, Subp_Typ); end; end if; end if; if Is_Access_Protected_Subprogram_Type (Btyp) then Expand_Access_To_Protected_Op (N, Pref, Typ); -- If prefix is a type name, this is a reference to the current -- instance of the type, within its initialization procedure. elsif Is_Entity_Name (Pref) and then Is_Type (Entity (Pref)) then declare Par : Node_Id; Formal : Entity_Id; begin -- If the current instance name denotes a task type, then -- the access attribute is rewritten to be the name of the -- "_task" parameter associated with the task type's task -- procedure. An unchecked conversion is applied to ensure -- a type match in cases of expander-generated calls (e.g. -- init procs). if Is_Task_Type (Entity (Pref)) then Formal := First_Entity (Get_Task_Body_Procedure (Entity (Pref))); while Present (Formal) loop exit when Chars (Formal) = Name_uTask; Next_Entity (Formal); end loop; pragma Assert (Present (Formal)); Rewrite (N, Unchecked_Convert_To (Typ, New_Occurrence_Of (Formal, Loc))); Set_Etype (N, Typ); elsif Is_Protected_Type (Entity (Pref)) then -- No action needed for current instance located in a -- component definition (expansion will occur in the -- init proc) if Is_Protected_Type (Current_Scope) then null; -- If the current instance reference is located in a -- protected subprogram or entry then rewrite the access -- attribute to be the name of the "_object" parameter. -- An unchecked conversion is applied to ensure a type -- match in cases of expander-generated calls (e.g. init -- procs). -- The code may be nested in a block, so find enclosing -- scope that is a protected operation. else declare Subp : Entity_Id; begin Subp := Current_Scope; while Ekind_In (Subp, E_Loop, E_Block) loop Subp := Scope (Subp); end loop; Formal := First_Entity (Protected_Body_Subprogram (Subp)); -- For a protected subprogram the _Object parameter -- is the protected record, so we create an access -- to it. The _Object parameter of an entry is an -- address. if Ekind (Subp) = E_Entry then Rewrite (N, Unchecked_Convert_To (Typ, New_Occurrence_Of (Formal, Loc))); Set_Etype (N, Typ); else Rewrite (N, Unchecked_Convert_To (Typ, Make_Attribute_Reference (Loc, Attribute_Name => Name_Unrestricted_Access, Prefix => New_Occurrence_Of (Formal, Loc)))); Analyze_And_Resolve (N); end if; end; end if; -- The expression must appear in a default expression, -- (which in the initialization procedure is the right-hand -- side of an assignment), and not in a discriminant -- constraint. else Par := Parent (N); while Present (Par) loop exit when Nkind (Par) = N_Assignment_Statement; if Nkind (Par) = N_Component_Declaration then return; end if; Par := Parent (Par); end loop; if Present (Par) then Rewrite (N, Make_Attribute_Reference (Loc, Prefix => Make_Identifier (Loc, Name_uInit), Attribute_Name => Attribute_Name (N))); Analyze_And_Resolve (N, Typ); end if; end if; end; -- If the prefix of an Access attribute is a dereference of an -- access parameter (or a renaming of such a dereference, or a -- subcomponent of such a dereference) and the context is a -- general access type (including the type of an object or -- component with an access_definition, but not the anonymous -- type of an access parameter or access discriminant), then -- apply an accessibility check to the access parameter. We used -- to rewrite the access parameter as a type conversion, but that -- could only be done if the immediate prefix of the Access -- attribute was the dereference, and didn't handle cases where -- the attribute is applied to a subcomponent of the dereference, -- since there's generally no available, appropriate access type -- to convert to in that case. The attribute is passed as the -- point to insert the check, because the access parameter may -- come from a renaming, possibly in a different scope, and the -- check must be associated with the attribute itself. elsif Id = Attribute_Access and then Nkind (Enc_Object) = N_Explicit_Dereference and then Is_Entity_Name (Prefix (Enc_Object)) and then (Ekind (Btyp) = E_General_Access_Type or else Is_Local_Anonymous_Access (Btyp)) and then Ekind (Entity (Prefix (Enc_Object))) in Formal_Kind and then Ekind (Etype (Entity (Prefix (Enc_Object)))) = E_Anonymous_Access_Type and then Present (Extra_Accessibility (Entity (Prefix (Enc_Object)))) then Apply_Accessibility_Check (Prefix (Enc_Object), Typ, N); -- Ada 2005 (AI-251): If the designated type is an interface we -- add an implicit conversion to force the displacement of the -- pointer to reference the secondary dispatch table. elsif Is_Interface (Btyp_DDT) and then (Comes_From_Source (N) or else Comes_From_Source (Ref_Object) or else (Nkind (Ref_Object) in N_Has_Chars and then Chars (Ref_Object) = Name_uInit)) then if Nkind (Ref_Object) /= N_Explicit_Dereference then -- No implicit conversion required if types match, or if -- the prefix is the class_wide_type of the interface. In -- either case passing an object of the interface type has -- already set the pointer correctly. if Btyp_DDT = Etype (Ref_Object) or else (Is_Class_Wide_Type (Etype (Ref_Object)) and then Class_Wide_Type (Btyp_DDT) = Etype (Ref_Object)) then null; else Rewrite (Prefix (N), Convert_To (Btyp_DDT, New_Copy_Tree (Prefix (N)))); Analyze_And_Resolve (Prefix (N), Btyp_DDT); end if; -- When the object is an explicit dereference, convert the -- dereference's prefix. else declare Obj_DDT : constant Entity_Id := Base_Type (Directly_Designated_Type (Etype (Prefix (Ref_Object)))); begin -- No implicit conversion required if designated types -- match, or if we have an unrestricted access. if Obj_DDT /= Btyp_DDT and then Id /= Attribute_Unrestricted_Access and then not (Is_Class_Wide_Type (Obj_DDT) and then Etype (Obj_DDT) = Btyp_DDT) then Rewrite (N, Convert_To (Typ, New_Copy_Tree (Prefix (Ref_Object)))); Analyze_And_Resolve (N, Typ); end if; end; end if; end if; end Access_Cases; -------------- -- Adjacent -- -------------- -- Transforms 'Adjacent into a call to the floating-point attribute -- function Adjacent in Fat_xxx (where xxx is the root type) when Attribute_Adjacent => Expand_Fpt_Attribute_RR (N); ------------- -- Address -- ------------- when Attribute_Address => Address : declare Task_Proc : Entity_Id; begin -- If the prefix is a task or a task type, the useful address is that -- of the procedure for the task body, i.e. the actual program unit. -- We replace the original entity with that of the procedure. if Is_Entity_Name (Pref) and then Is_Task_Type (Entity (Pref)) then Task_Proc := Next_Entity (Root_Type (Ptyp)); while Present (Task_Proc) loop exit when Ekind (Task_Proc) = E_Procedure and then Etype (First_Formal (Task_Proc)) = Corresponding_Record_Type (Ptyp); Next_Entity (Task_Proc); end loop; if Present (Task_Proc) then Set_Entity (Pref, Task_Proc); Set_Etype (Pref, Etype (Task_Proc)); end if; -- Similarly, the address of a protected operation is the address -- of the corresponding protected body, regardless of the protected -- object from which it is selected. elsif Nkind (Pref) = N_Selected_Component and then Is_Subprogram (Entity (Selector_Name (Pref))) and then Is_Protected_Type (Scope (Entity (Selector_Name (Pref)))) then Rewrite (Pref, New_Occurrence_Of ( External_Subprogram (Entity (Selector_Name (Pref))), Loc)); elsif Nkind (Pref) = N_Explicit_Dereference and then Ekind (Ptyp) = E_Subprogram_Type and then Convention (Ptyp) = Convention_Protected then -- The prefix is be a dereference of an access_to_protected_ -- subprogram. The desired address is the second component of -- the record that represents the access. declare Addr : constant Entity_Id := Etype (N); Ptr : constant Node_Id := Prefix (Pref); T : constant Entity_Id := Equivalent_Type (Base_Type (Etype (Ptr))); begin Rewrite (N, Unchecked_Convert_To (Addr, Make_Selected_Component (Loc, Prefix => Unchecked_Convert_To (T, Ptr), Selector_Name => New_Occurrence_Of ( Next_Entity (First_Entity (T)), Loc)))); Analyze_And_Resolve (N, Addr); end; -- Ada 2005 (AI-251): Class-wide interface objects are always -- "displaced" to reference the tag associated with the interface -- type. In order to obtain the real address of such objects we -- generate a call to a run-time subprogram that returns the base -- address of the object. -- This processing is not needed in the VM case, where dispatching -- issues are taken care of by the virtual machine. elsif Is_Class_Wide_Type (Ptyp) and then Is_Interface (Ptyp) and then Tagged_Type_Expansion and then not (Nkind (Pref) in N_Has_Entity and then Is_Subprogram (Entity (Pref))) then Rewrite (N, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Base_Address), Loc), Parameter_Associations => New_List ( Relocate_Node (N)))); Analyze (N); return; end if; -- Deal with packed array reference, other cases are handled by -- the back end. if Involves_Packed_Array_Reference (Pref) then Expand_Packed_Address_Reference (N); end if; end Address; --------------- -- Alignment -- --------------- when Attribute_Alignment => Alignment : declare New_Node : Node_Id; begin -- For class-wide types, X'Class'Alignment is transformed into a -- direct reference to the Alignment of the class type, so that the -- back end does not have to deal with the X'Class'Alignment -- reference. if Is_Entity_Name (Pref) and then Is_Class_Wide_Type (Entity (Pref)) then Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc)); return; -- For x'Alignment applied to an object of a class wide type, -- transform X'Alignment into a call to the predefined primitive -- operation _Alignment applied to X. elsif Is_Class_Wide_Type (Ptyp) then New_Node := Make_Attribute_Reference (Loc, Prefix => Pref, Attribute_Name => Name_Tag); New_Node := Build_Get_Alignment (Loc, New_Node); -- Case where the context is a specific integer type with which -- the original attribute was compatible. The function has a -- specific type as well, so to preserve the compatibility we -- must convert explicitly. if Typ /= Standard_Integer then New_Node := Convert_To (Typ, New_Node); end if; Rewrite (N, New_Node); Analyze_And_Resolve (N, Typ); return; -- For all other cases, we just have to deal with the case of -- the fact that the result can be universal. else Apply_Universal_Integer_Attribute_Checks (N); end if; end Alignment; --------- -- Bit -- --------- -- We compute this if a packed array reference was present, otherwise we -- leave the computation up to the back end. when Attribute_Bit => if Involves_Packed_Array_Reference (Pref) then Expand_Packed_Bit_Reference (N); else Apply_Universal_Integer_Attribute_Checks (N); end if; ------------------ -- Bit_Position -- ------------------ -- We compute this if a component clause was present, otherwise we leave -- the computation up to the back end, since we don't know what layout -- will be chosen. -- Note that the attribute can apply to a naked record component -- in generated code (i.e. the prefix is an identifier that -- references the component or discriminant entity). when Attribute_Bit_Position => Bit_Position : declare CE : Entity_Id; begin if Nkind (Pref) = N_Identifier then CE := Entity (Pref); else CE := Entity (Selector_Name (Pref)); end if; if Known_Static_Component_Bit_Offset (CE) then Rewrite (N, Make_Integer_Literal (Loc, Intval => Component_Bit_Offset (CE))); Analyze_And_Resolve (N, Typ); else Apply_Universal_Integer_Attribute_Checks (N); end if; end Bit_Position; ------------------ -- Body_Version -- ------------------ -- A reference to P'Body_Version or P'Version is expanded to -- Vnn : Unsigned; -- pragma Import (C, Vnn, "uuuuT"); -- ... -- Get_Version_String (Vnn) -- where uuuu is the unit name (dots replaced by double underscore) -- and T is B for the cases of Body_Version, or Version applied to a -- subprogram acting as its own spec, and S for Version applied to a -- subprogram spec or package. This sequence of code references the -- unsigned constant created in the main program by the binder. -- A special exception occurs for Standard, where the string returned -- is a copy of the library string in gnatvsn.ads. when Attribute_Body_Version | Attribute_Version => Version : declare E : constant Entity_Id := Make_Temporary (Loc, 'V'); Pent : Entity_Id; S : String_Id; begin -- If not library unit, get to containing library unit Pent := Entity (Pref); while Pent /= Standard_Standard and then Scope (Pent) /= Standard_Standard and then not Is_Child_Unit (Pent) loop Pent := Scope (Pent); end loop; -- Special case Standard and Standard.ASCII if Pent = Standard_Standard or else Pent = Standard_ASCII then Rewrite (N, Make_String_Literal (Loc, Strval => Verbose_Library_Version)); -- All other cases else -- Build required string constant Get_Name_String (Get_Unit_Name (Pent)); Start_String; for J in 1 .. Name_Len - 2 loop if Name_Buffer (J) = '.' then Store_String_Chars ("__"); else Store_String_Char (Get_Char_Code (Name_Buffer (J))); end if; end loop; -- Case of subprogram acting as its own spec, always use body if Nkind (Declaration_Node (Pent)) in N_Subprogram_Specification and then Nkind (Parent (Declaration_Node (Pent))) = N_Subprogram_Body and then Acts_As_Spec (Parent (Declaration_Node (Pent))) then Store_String_Chars ("B"); -- Case of no body present, always use spec elsif not Unit_Requires_Body (Pent) then Store_String_Chars ("S"); -- Otherwise use B for Body_Version, S for spec elsif Id = Attribute_Body_Version then Store_String_Chars ("B"); else Store_String_Chars ("S"); end if; S := End_String; Lib.Version_Referenced (S); -- Insert the object declaration Insert_Actions (N, New_List ( Make_Object_Declaration (Loc, Defining_Identifier => E, Object_Definition => New_Occurrence_Of (RTE (RE_Unsigned), Loc)))); -- Set entity as imported with correct external name Set_Is_Imported (E); Set_Interface_Name (E, Make_String_Literal (Loc, S)); -- Set entity as internal to ensure proper Sprint output of its -- implicit importation. Set_Is_Internal (E); -- And now rewrite original reference Rewrite (N, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Get_Version_String), Loc), Parameter_Associations => New_List ( New_Occurrence_Of (E, Loc)))); end if; Analyze_And_Resolve (N, RTE (RE_Version_String)); end Version; ------------- -- Ceiling -- ------------- -- Transforms 'Ceiling into a call to the floating-point attribute -- function Ceiling in Fat_xxx (where xxx is the root type) when Attribute_Ceiling => Expand_Fpt_Attribute_R (N); -------------- -- Callable -- -------------- -- Transforms 'Callable attribute into a call to the Callable function when Attribute_Callable => -- We have an object of a task interface class-wide type as a prefix -- to Callable. Generate: -- callable (Task_Id (Pref._disp_get_task_id)); if Ada_Version >= Ada_2005 and then Ekind (Ptyp) = E_Class_Wide_Type and then Is_Interface (Ptyp) and then Is_Task_Interface (Ptyp) then Rewrite (N, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Callable), Loc), Parameter_Associations => New_List ( Make_Unchecked_Type_Conversion (Loc, Subtype_Mark => New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc), Expression => Make_Selected_Component (Loc, Prefix => New_Copy_Tree (Pref), Selector_Name => Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))))); else Rewrite (N, Build_Call_With_Task (Pref, RTE (RE_Callable))); end if; Analyze_And_Resolve (N, Standard_Boolean); ------------ -- Caller -- ------------ -- Transforms 'Caller attribute into a call to either the -- Task_Entry_Caller or the Protected_Entry_Caller function. when Attribute_Caller => Caller : declare Id_Kind : constant Entity_Id := RTE (RO_AT_Task_Id); Ent : constant Entity_Id := Entity (Pref); Conctype : constant Entity_Id := Scope (Ent); Nest_Depth : Integer := 0; Name : Node_Id; S : Entity_Id; begin -- Protected case if Is_Protected_Type (Conctype) then case Corresponding_Runtime_Package (Conctype) is when System_Tasking_Protected_Objects_Entries => Name := New_Occurrence_Of (RTE (RE_Protected_Entry_Caller), Loc); when System_Tasking_Protected_Objects_Single_Entry => Name := New_Occurrence_Of (RTE (RE_Protected_Single_Entry_Caller), Loc); when others => raise Program_Error; end case; Rewrite (N, Unchecked_Convert_To (Id_Kind, Make_Function_Call (Loc, Name => Name, Parameter_Associations => New_List ( New_Occurrence_Of (Find_Protection_Object (Current_Scope), Loc))))); -- Task case else -- Determine the nesting depth of the E'Caller attribute, that -- is, how many accept statements are nested within the accept -- statement for E at the point of E'Caller. The runtime uses -- this depth to find the specified entry call. for J in reverse 0 .. Scope_Stack.Last loop S := Scope_Stack.Table (J).Entity; -- We should not reach the scope of the entry, as it should -- already have been checked in Sem_Attr that this attribute -- reference is within a matching accept statement. pragma Assert (S /= Conctype); if S = Ent then exit; elsif Is_Entry (S) then Nest_Depth := Nest_Depth + 1; end if; end loop; Rewrite (N, Unchecked_Convert_To (Id_Kind, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Task_Entry_Caller), Loc), Parameter_Associations => New_List ( Make_Integer_Literal (Loc, Intval => Int (Nest_Depth)))))); end if; Analyze_And_Resolve (N, Id_Kind); end Caller; ------------- -- Compose -- ------------- -- Transforms 'Compose into a call to the floating-point attribute -- function Compose in Fat_xxx (where xxx is the root type) -- Note: we strictly should have special code here to deal with the -- case of absurdly negative arguments (less than Integer'First) -- which will return a (signed) zero value, but it hardly seems -- worth the effort. Absurdly large positive arguments will raise -- constraint error which is fine. when Attribute_Compose => Expand_Fpt_Attribute_RI (N); ----------------- -- Constrained -- ----------------- when Attribute_Constrained => Constrained : declare Formal_Ent : constant Entity_Id := Param_Entity (Pref); function Is_Constrained_Aliased_View (Obj : Node_Id) return Boolean; -- Ada 2005 (AI-363): Returns True if the object name Obj denotes a -- view of an aliased object whose subtype is constrained. --------------------------------- -- Is_Constrained_Aliased_View -- --------------------------------- function Is_Constrained_Aliased_View (Obj : Node_Id) return Boolean is E : Entity_Id; begin if Is_Entity_Name (Obj) then E := Entity (Obj); if Present (Renamed_Object (E)) then return Is_Constrained_Aliased_View (Renamed_Object (E)); else return Is_Aliased (E) and then Is_Constrained (Etype (E)); end if; else return Is_Aliased_View (Obj) and then (Is_Constrained (Etype (Obj)) or else (Nkind (Obj) = N_Explicit_Dereference and then not Object_Type_Has_Constrained_Partial_View (Typ => Base_Type (Etype (Obj)), Scop => Current_Scope))); end if; end Is_Constrained_Aliased_View; -- Start of processing for Constrained begin -- Reference to a parameter where the value is passed as an extra -- actual, corresponding to the extra formal referenced by the -- Extra_Constrained field of the corresponding formal. If this -- is an entry in-parameter, it is replaced by a constant renaming -- for which Extra_Constrained is never created. if Present (Formal_Ent) and then Ekind (Formal_Ent) /= E_Constant and then Present (Extra_Constrained (Formal_Ent)) then Rewrite (N, New_Occurrence_Of (Extra_Constrained (Formal_Ent), Sloc (N))); -- For variables with a Extra_Constrained field, we use the -- corresponding entity. elsif Nkind (Pref) = N_Identifier and then Ekind (Entity (Pref)) = E_Variable and then Present (Extra_Constrained (Entity (Pref))) then Rewrite (N, New_Occurrence_Of (Extra_Constrained (Entity (Pref)), Sloc (N))); -- For all other entity names, we can tell at compile time elsif Is_Entity_Name (Pref) then declare Ent : constant Entity_Id := Entity (Pref); Res : Boolean; begin -- (RM J.4) obsolescent cases if Is_Type (Ent) then -- Private type if Is_Private_Type (Ent) then Res := not Has_Discriminants (Ent) or else Is_Constrained (Ent); -- It not a private type, must be a generic actual type -- that corresponded to a private type. We know that this -- correspondence holds, since otherwise the reference -- within the generic template would have been illegal. else if Is_Composite_Type (Underlying_Type (Ent)) then Res := Is_Constrained (Ent); else Res := True; end if; end if; else -- For access type, apply access check as needed if Is_Access_Type (Ptyp) then Apply_Access_Check (N); end if; -- If the prefix is not a variable or is aliased, then -- definitely true; if it's a formal parameter without an -- associated extra formal, then treat it as constrained. -- Ada 2005 (AI-363): An aliased prefix must be known to be -- constrained in order to set the attribute to True. if not Is_Variable (Pref) or else Present (Formal_Ent) or else (Ada_Version < Ada_2005 and then Is_Aliased_View (Pref)) or else (Ada_Version >= Ada_2005 and then Is_Constrained_Aliased_View (Pref)) then Res := True; -- Variable case, look at type to see if it is constrained. -- Note that the one case where this is not accurate (the -- procedure formal case), has been handled above. -- We use the Underlying_Type here (and below) in case the -- type is private without discriminants, but the full type -- has discriminants. This case is illegal, but we generate -- it internally for passing to the Extra_Constrained -- parameter. else -- In Ada 2012, test for case of a limited tagged type, -- in which case the attribute is always required to -- return True. The underlying type is tested, to make -- sure we also return True for cases where there is an -- unconstrained object with an untagged limited partial -- view which has defaulted discriminants (such objects -- always produce a False in earlier versions of -- Ada). (Ada 2012: AI05-0214) Res := Is_Constrained (Underlying_Type (Etype (Ent))) or else (Ada_Version >= Ada_2012 and then Is_Tagged_Type (Underlying_Type (Ptyp)) and then Is_Limited_Type (Ptyp)); end if; end if; Rewrite (N, New_Occurrence_Of (Boolean_Literals (Res), Loc)); end; -- Prefix is not an entity name. These are also cases where we can -- always tell at compile time by looking at the form and type of the -- prefix. If an explicit dereference of an object with constrained -- partial view, this is unconstrained (Ada 2005: AI95-0363). If the -- underlying type is a limited tagged type, then Constrained is -- required to always return True (Ada 2012: AI05-0214). else Rewrite (N, New_Occurrence_Of ( Boolean_Literals ( not Is_Variable (Pref) or else (Nkind (Pref) = N_Explicit_Dereference and then not Object_Type_Has_Constrained_Partial_View (Typ => Base_Type (Ptyp), Scop => Current_Scope)) or else Is_Constrained (Underlying_Type (Ptyp)) or else (Ada_Version >= Ada_2012 and then Is_Tagged_Type (Underlying_Type (Ptyp)) and then Is_Limited_Type (Ptyp))), Loc)); end if; Analyze_And_Resolve (N, Standard_Boolean); end Constrained; --------------- -- Copy_Sign -- --------------- -- Transforms 'Copy_Sign into a call to the floating-point attribute -- function Copy_Sign in Fat_xxx (where xxx is the root type) when Attribute_Copy_Sign => Expand_Fpt_Attribute_RR (N); ----------- -- Count -- ----------- -- Transforms 'Count attribute into a call to the Count function when Attribute_Count => Count : declare Call : Node_Id; Conctyp : Entity_Id; Entnam : Node_Id; Entry_Id : Entity_Id; Index : Node_Id; Name : Node_Id; begin -- If the prefix is a member of an entry family, retrieve both -- entry name and index. For a simple entry there is no index. if Nkind (Pref) = N_Indexed_Component then Entnam := Prefix (Pref); Index := First (Expressions (Pref)); else Entnam := Pref; Index := Empty; end if; Entry_Id := Entity (Entnam); -- Find the concurrent type in which this attribute is referenced -- (there had better be one). Conctyp := Current_Scope; while not Is_Concurrent_Type (Conctyp) loop Conctyp := Scope (Conctyp); end loop; -- Protected case if Is_Protected_Type (Conctyp) then case Corresponding_Runtime_Package (Conctyp) is when System_Tasking_Protected_Objects_Entries => Name := New_Occurrence_Of (RTE (RE_Protected_Count), Loc); Call := Make_Function_Call (Loc, Name => Name, Parameter_Associations => New_List ( New_Occurrence_Of (Find_Protection_Object (Current_Scope), Loc), Entry_Index_Expression (Loc, Entry_Id, Index, Scope (Entry_Id)))); when System_Tasking_Protected_Objects_Single_Entry => Name := New_Occurrence_Of (RTE (RE_Protected_Count_Entry), Loc); Call := Make_Function_Call (Loc, Name => Name, Parameter_Associations => New_List ( New_Occurrence_Of (Find_Protection_Object (Current_Scope), Loc))); when others => raise Program_Error; end case; -- Task case else Call := Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Task_Count), Loc), Parameter_Associations => New_List ( Entry_Index_Expression (Loc, Entry_Id, Index, Scope (Entry_Id)))); end if; -- The call returns type Natural but the context is universal integer -- so any integer type is allowed. The attribute was already resolved -- so its Etype is the required result type. If the base type of the -- context type is other than Standard.Integer we put in a conversion -- to the required type. This can be a normal typed conversion since -- both input and output types of the conversion are integer types if Base_Type (Typ) /= Base_Type (Standard_Integer) then Rewrite (N, Convert_To (Typ, Call)); else Rewrite (N, Call); end if; Analyze_And_Resolve (N, Typ); end Count; --------------------- -- Descriptor_Size -- --------------------- when Attribute_Descriptor_Size => -- Attribute Descriptor_Size is handled by the back end when applied -- to an unconstrained array type. if Is_Array_Type (Ptyp) and then not Is_Constrained (Ptyp) then Apply_Universal_Integer_Attribute_Checks (N); -- For any other type, the descriptor size is 0 because there is no -- actual descriptor, but the result is not formally static. else Rewrite (N, Make_Integer_Literal (Loc, 0)); Analyze (N); Set_Is_Static_Expression (N, False); end if; --------------- -- Elab_Body -- --------------- -- This processing is shared by Elab_Spec -- What we do is to insert the following declarations -- procedure tnn; -- pragma Import (C, enn, "name___elabb/s"); -- and then the Elab_Body/Spec attribute is replaced by a reference -- to this defining identifier. when Attribute_Elab_Body | Attribute_Elab_Spec => -- Leave attribute unexpanded in CodePeer mode: the gnat2scil -- back-end knows how to handle these attributes directly. if CodePeer_Mode then return; end if; Elab_Body : declare Ent : constant Entity_Id := Make_Temporary (Loc, 'E'); Str : String_Id; Lang : Node_Id; procedure Make_Elab_String (Nod : Node_Id); -- Given Nod, an identifier, or a selected component, put the -- image into the current string literal, with double underline -- between components. ---------------------- -- Make_Elab_String -- ---------------------- procedure Make_Elab_String (Nod : Node_Id) is begin if Nkind (Nod) = N_Selected_Component then Make_Elab_String (Prefix (Nod)); Store_String_Char ('_'); Store_String_Char ('_'); Get_Name_String (Chars (Selector_Name (Nod))); else pragma Assert (Nkind (Nod) = N_Identifier); Get_Name_String (Chars (Nod)); end if; Store_String_Chars (Name_Buffer (1 .. Name_Len)); end Make_Elab_String; -- Start of processing for Elab_Body/Elab_Spec begin -- First we need to prepare the string literal for the name of -- the elaboration routine to be referenced. Start_String; Make_Elab_String (Pref); Store_String_Chars ("___elab"); Lang := Make_Identifier (Loc, Name_C); if Id = Attribute_Elab_Body then Store_String_Char ('b'); else Store_String_Char ('s'); end if; Str := End_String; Insert_Actions (N, New_List ( Make_Subprogram_Declaration (Loc, Specification => Make_Procedure_Specification (Loc, Defining_Unit_Name => Ent)), Make_Pragma (Loc, Chars => Name_Import, Pragma_Argument_Associations => New_List ( Make_Pragma_Argument_Association (Loc, Expression => Lang), Make_Pragma_Argument_Association (Loc, Expression => Make_Identifier (Loc, Chars (Ent))), Make_Pragma_Argument_Association (Loc, Expression => Make_String_Literal (Loc, Str)))))); Set_Entity (N, Ent); Rewrite (N, New_Occurrence_Of (Ent, Loc)); end Elab_Body; -------------------- -- Elab_Subp_Body -- -------------------- -- Always ignored. In CodePeer mode, gnat2scil knows how to handle -- this attribute directly, and if we are not in CodePeer mode it is -- entirely ignored ??? when Attribute_Elab_Subp_Body => return; ---------------- -- Elaborated -- ---------------- -- Elaborated is always True for preelaborated units, predefined units, -- pure units and units which have Elaborate_Body pragmas. These units -- have no elaboration entity. -- Note: The Elaborated attribute is never passed to the back end when Attribute_Elaborated => Elaborated : declare Ent : constant Entity_Id := Entity (Pref); begin if Present (Elaboration_Entity (Ent)) then Rewrite (N, Make_Op_Ne (Loc, Left_Opnd => New_Occurrence_Of (Elaboration_Entity (Ent), Loc), Right_Opnd => Make_Integer_Literal (Loc, Uint_0))); Analyze_And_Resolve (N, Typ); else Rewrite (N, New_Occurrence_Of (Standard_True, Loc)); end if; end Elaborated; -------------- -- Enum_Rep -- -------------- when Attribute_Enum_Rep => Enum_Rep : declare Expr : Node_Id; begin -- Get the expression, which is X for Enum_Type'Enum_Rep (X) or -- X'Enum_Rep. if Is_Non_Empty_List (Exprs) then Expr := First (Exprs); else Expr := Pref; end if; -- If the expression is an enumeration literal, it is replaced by the -- literal value. if Nkind (Expr) in N_Has_Entity and then Ekind (Entity (Expr)) = E_Enumeration_Literal then Rewrite (N, Make_Integer_Literal (Loc, Enumeration_Rep (Entity (Expr)))); -- If this is a renaming of a literal, recover the representation -- of the original. If it renames an expression there is nothing to -- fold. elsif Nkind (Expr) in N_Has_Entity and then Ekind (Entity (Expr)) = E_Constant and then Present (Renamed_Object (Entity (Expr))) and then Is_Entity_Name (Renamed_Object (Entity (Expr))) and then Ekind (Entity (Renamed_Object (Entity (Expr)))) = E_Enumeration_Literal then Rewrite (N, Make_Integer_Literal (Loc, Enumeration_Rep (Entity (Renamed_Object (Entity (Expr)))))); -- If not constant-folded above, Enum_Type'Enum_Rep (X) or -- X'Enum_Rep expands to -- target-type (X) -- This is simply a direct conversion from the enumeration type to -- the target integer type, which is treated by the back end as a -- normal integer conversion, treating the enumeration type as an -- integer, which is exactly what we want. We set Conversion_OK to -- make sure that the analyzer does not complain about what otherwise -- might be an illegal conversion. else Rewrite (N, OK_Convert_To (Typ, Relocate_Node (Expr))); end if; Set_Etype (N, Typ); Analyze_And_Resolve (N, Typ); end Enum_Rep; -------------- -- Enum_Val -- -------------- when Attribute_Enum_Val => Enum_Val : declare Expr : Node_Id; Btyp : constant Entity_Id := Base_Type (Ptyp); begin -- X'Enum_Val (Y) expands to -- [constraint_error when _rep_to_pos (Y, False) = -1, msg] -- X!(Y); Expr := Unchecked_Convert_To (Ptyp, First (Exprs)); Insert_Action (N, Make_Raise_Constraint_Error (Loc, Condition => Make_Op_Eq (Loc, Left_Opnd => Make_Function_Call (Loc, Name => New_Occurrence_Of (TSS (Btyp, TSS_Rep_To_Pos), Loc), Parameter_Associations => New_List ( Relocate_Node (Duplicate_Subexpr (Expr)), New_Occurrence_Of (Standard_False, Loc))), Right_Opnd => Make_Integer_Literal (Loc, -1)), Reason => CE_Range_Check_Failed)); Rewrite (N, Expr); Analyze_And_Resolve (N, Ptyp); end Enum_Val; -------------- -- Exponent -- -------------- -- Transforms 'Exponent into a call to the floating-point attribute -- function Exponent in Fat_xxx (where xxx is the root type) when Attribute_Exponent => Expand_Fpt_Attribute_R (N); ------------------ -- External_Tag -- ------------------ -- transforme X'External_Tag into Ada.Tags.External_Tag (X'tag) when Attribute_External_Tag => Rewrite (N, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_External_Tag), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Attribute_Name => Name_Tag, Prefix => Prefix (N))))); Analyze_And_Resolve (N, Standard_String); ----------------------- -- Finalization_Size -- ----------------------- when Attribute_Finalization_Size => Finalization_Size : declare function Calculate_Header_Size return Node_Id; -- Generate a runtime call to calculate the size of the hidden header -- along with any added padding which would precede a heap-allocated -- object of the prefix type. --------------------------- -- Calculate_Header_Size -- --------------------------- function Calculate_Header_Size return Node_Id is begin -- Generate: -- Universal_Integer -- (Header_Size_With_Padding (Pref'Alignment)) return Convert_To (Universal_Integer, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Header_Size_With_Padding), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Copy_Tree (Pref), Attribute_Name => Name_Alignment)))); end Calculate_Header_Size; -- Local variables Size : Entity_Id; -- Start of Finalization_Size begin -- An object of a class-wide type first requires a runtime check to -- determine whether it is actually controlled or not. Depending on -- the outcome of this check, the Finalization_Size of the object -- may be zero or some positive value. -- -- In this scenario, Pref'Finalization_Size is expanded into -- -- Size : Integer := 0; -- -- if Needs_Finalization (Pref'Tag) then -- Size := -- Universal_Integer -- (Header_Size_With_Padding (Pref'Alignment)); -- end if; -- -- and the attribute reference is replaced with a reference to Size. if Is_Class_Wide_Type (Ptyp) then Size := Make_Temporary (Loc, 'S'); Insert_Actions (N, New_List ( -- Generate: -- Size : Integer := 0; Make_Object_Declaration (Loc, Defining_Identifier => Size, Object_Definition => New_Occurrence_Of (Standard_Integer, Loc), Expression => Make_Integer_Literal (Loc, 0)), -- Generate: -- if Needs_Finalization (Pref'Tag) then -- Size := -- Universal_Integer -- (Header_Size_With_Padding (Pref'Alignment)); -- end if; Make_If_Statement (Loc, Condition => Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Needs_Finalization), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Copy_Tree (Pref), Attribute_Name => Name_Tag))), Then_Statements => New_List ( Make_Assignment_Statement (Loc, Name => New_Occurrence_Of (Size, Loc), Expression => Calculate_Header_Size))))); Rewrite (N, New_Occurrence_Of (Size, Loc)); -- The prefix is known to be controlled at compile time. Calculate -- Finalization_Size by calling function Header_Size_With_Padding. elsif Needs_Finalization (Ptyp) then Rewrite (N, Calculate_Header_Size); -- The prefix is not an object with controlled parts, so its -- Finalization_Size is zero. else Rewrite (N, Make_Integer_Literal (Loc, 0)); end if; -- Due to cases where the entity type of the attribute is already -- resolved the rewritten N must get re-resolved to its appropriate -- type. Analyze_And_Resolve (N, Typ); end Finalization_Size; ----------- -- First -- ----------- when Attribute_First => -- If the prefix type is a constrained packed array type which -- already has a Packed_Array_Impl_Type representation defined, then -- replace this attribute with a direct reference to 'First of the -- appropriate index subtype (since otherwise the back end will try -- to give us the value of 'First for this implementation type). if Is_Constrained_Packed_Array (Ptyp) then Rewrite (N, Make_Attribute_Reference (Loc, Attribute_Name => Name_First, Prefix => New_Occurrence_Of (Get_Index_Subtype (N), Loc))); Analyze_And_Resolve (N, Typ); -- For access type, apply access check as needed elsif Is_Access_Type (Ptyp) then Apply_Access_Check (N); -- For scalar type, if low bound is a reference to an entity, just -- replace with a direct reference. Note that we can only have a -- reference to a constant entity at this stage, anything else would -- have already been rewritten. elsif Is_Scalar_Type (Ptyp) then declare Lo : constant Node_Id := Type_Low_Bound (Ptyp); begin if Is_Entity_Name (Lo) then Rewrite (N, New_Occurrence_Of (Entity (Lo), Loc)); end if; end; end if; --------------- -- First_Bit -- --------------- -- Compute this if component clause was present, otherwise we leave the -- computation to be completed in the back-end, since we don't know what -- layout will be chosen. when Attribute_First_Bit => First_Bit_Attr : declare CE : constant Entity_Id := Entity (Selector_Name (Pref)); begin -- In Ada 2005 (or later) if we have the non-default bit order, then -- we return the original value as given in the component clause -- (RM 2005 13.5.2(3/2)). if Present (Component_Clause (CE)) and then Ada_Version >= Ada_2005 and then Reverse_Bit_Order (Scope (CE)) then Rewrite (N, Make_Integer_Literal (Loc, Intval => Expr_Value (First_Bit (Component_Clause (CE))))); Analyze_And_Resolve (N, Typ); -- Otherwise (Ada 83/95 or Ada 2005 or later with default bit order), -- rewrite with normalized value if we know it statically. elsif Known_Static_Component_Bit_Offset (CE) then Rewrite (N, Make_Integer_Literal (Loc, Component_Bit_Offset (CE) mod System_Storage_Unit)); Analyze_And_Resolve (N, Typ); -- Otherwise left to back end, just do universal integer checks else Apply_Universal_Integer_Attribute_Checks (N); end if; end First_Bit_Attr; ----------------- -- Fixed_Value -- ----------------- -- We transform: -- fixtype'Fixed_Value (integer-value) -- into -- fixtype(integer-value) -- We do all the required analysis of the conversion here, because we do -- not want this to go through the fixed-point conversion circuits. Note -- that the back end always treats fixed-point as equivalent to the -- corresponding integer type anyway. when Attribute_Fixed_Value => Rewrite (N, Make_Type_Conversion (Loc, Subtype_Mark => New_Occurrence_Of (Entity (Pref), Loc), Expression => Relocate_Node (First (Exprs)))); Set_Etype (N, Entity (Pref)); Set_Analyzed (N); -- Note: it might appear that a properly analyzed unchecked -- conversion would be just fine here, but that's not the case, -- since the full range checks performed by the following call -- are critical. Apply_Type_Conversion_Checks (N); ----------- -- Floor -- ----------- -- Transforms 'Floor into a call to the floating-point attribute -- function Floor in Fat_xxx (where xxx is the root type) when Attribute_Floor => Expand_Fpt_Attribute_R (N); ---------- -- Fore -- ---------- -- For the fixed-point type Typ: -- Typ'Fore -- expands into -- Result_Type (System.Fore (Universal_Real (Type'First)), -- Universal_Real (Type'Last)) -- Note that we know that the type is a non-static subtype, or Fore -- would have itself been computed dynamically in Eval_Attribute. when Attribute_Fore => Rewrite (N, Convert_To (Typ, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Fore), Loc), Parameter_Associations => New_List ( Convert_To (Universal_Real, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ptyp, Loc), Attribute_Name => Name_First)), Convert_To (Universal_Real, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ptyp, Loc), Attribute_Name => Name_Last)))))); Analyze_And_Resolve (N, Typ); -------------- -- Fraction -- -------------- -- Transforms 'Fraction into a call to the floating-point attribute -- function Fraction in Fat_xxx (where xxx is the root type) when Attribute_Fraction => Expand_Fpt_Attribute_R (N); -------------- -- From_Any -- -------------- when Attribute_From_Any => From_Any : declare P_Type : constant Entity_Id := Etype (Pref); Decls : constant List_Id := New_List; begin Rewrite (N, Build_From_Any_Call (P_Type, Relocate_Node (First (Exprs)), Decls)); Insert_Actions (N, Decls); Analyze_And_Resolve (N, P_Type); end From_Any; ---------------------- -- Has_Same_Storage -- ---------------------- when Attribute_Has_Same_Storage => Has_Same_Storage : declare Loc : constant Source_Ptr := Sloc (N); X : constant Node_Id := Prefix (N); Y : constant Node_Id := First (Expressions (N)); -- The arguments X_Addr : Node_Id; Y_Addr : Node_Id; -- Rhe expressions for their addresses X_Size : Node_Id; Y_Size : Node_Id; -- Rhe expressions for their sizes begin -- The attribute is expanded as: -- (X'address = Y'address) -- and then (X'Size = Y'Size) -- If both arguments have the same Etype the second conjunct can be -- omitted. X_Addr := Make_Attribute_Reference (Loc, Attribute_Name => Name_Address, Prefix => New_Copy_Tree (X)); Y_Addr := Make_Attribute_Reference (Loc, Attribute_Name => Name_Address, Prefix => New_Copy_Tree (Y)); X_Size := Make_Attribute_Reference (Loc, Attribute_Name => Name_Size, Prefix => New_Copy_Tree (X)); Y_Size := Make_Attribute_Reference (Loc, Attribute_Name => Name_Size, Prefix => New_Copy_Tree (Y)); if Etype (X) = Etype (Y) then Rewrite (N, Make_Op_Eq (Loc, Left_Opnd => X_Addr, Right_Opnd => Y_Addr)); else Rewrite (N, Make_Op_And (Loc, Left_Opnd => Make_Op_Eq (Loc, Left_Opnd => X_Addr, Right_Opnd => Y_Addr), Right_Opnd => Make_Op_Eq (Loc, Left_Opnd => X_Size, Right_Opnd => Y_Size))); end if; Analyze_And_Resolve (N, Standard_Boolean); end Has_Same_Storage; -------------- -- Identity -- -------------- -- For an exception returns a reference to the exception data: -- Exception_Id!(Prefix'Reference) -- For a task it returns a reference to the _task_id component of -- corresponding record: -- taskV!(Prefix)._Task_Id, converted to the type Task_Id defined -- in Ada.Task_Identification when Attribute_Identity => Identity : declare Id_Kind : Entity_Id; begin if Ptyp = Standard_Exception_Type then Id_Kind := RTE (RE_Exception_Id); if Present (Renamed_Object (Entity (Pref))) then Set_Entity (Pref, Renamed_Object (Entity (Pref))); end if; Rewrite (N, Unchecked_Convert_To (Id_Kind, Make_Reference (Loc, Pref))); else Id_Kind := RTE (RO_AT_Task_Id); -- If the prefix is a task interface, the Task_Id is obtained -- dynamically through a dispatching call, as for other task -- attributes applied to interfaces. if Ada_Version >= Ada_2005 and then Ekind (Ptyp) = E_Class_Wide_Type and then Is_Interface (Ptyp) and then Is_Task_Interface (Ptyp) then Rewrite (N, Unchecked_Convert_To (Id_Kind, Make_Selected_Component (Loc, Prefix => New_Copy_Tree (Pref), Selector_Name => Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))); else Rewrite (N, Unchecked_Convert_To (Id_Kind, Concurrent_Ref (Pref))); end if; end if; Analyze_And_Resolve (N, Id_Kind); end Identity; ----------- -- Image -- ----------- -- Image attribute is handled in separate unit Exp_Imgv when Attribute_Image => Exp_Imgv.Expand_Image_Attribute (N); --------- -- Img -- --------- -- X'Img is expanded to typ'Image (X), where typ is the type of X when Attribute_Img => Rewrite (N, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ptyp, Loc), Attribute_Name => Name_Image, Expressions => New_List (Relocate_Node (Pref)))); Analyze_And_Resolve (N, Standard_String); ----------- -- Input -- ----------- when Attribute_Input => Input : declare P_Type : constant Entity_Id := Entity (Pref); B_Type : constant Entity_Id := Base_Type (P_Type); U_Type : constant Entity_Id := Underlying_Type (P_Type); Strm : constant Node_Id := First (Exprs); Fname : Entity_Id; Decl : Node_Id; Call : Node_Id; Prag : Node_Id; Arg2 : Node_Id; Rfunc : Node_Id; Cntrl : Node_Id := Empty; -- Value for controlling argument in call. Always Empty except in -- the dispatching (class-wide type) case, where it is a reference -- to the dummy object initialized to the right internal tag. procedure Freeze_Stream_Subprogram (F : Entity_Id); -- The expansion of the attribute reference may generate a call to -- a user-defined stream subprogram that is frozen by the call. This -- can lead to access-before-elaboration problem if the reference -- appears in an object declaration and the subprogram body has not -- been seen. The freezing of the subprogram requires special code -- because it appears in an expanded context where expressions do -- not freeze their constituents. ------------------------------ -- Freeze_Stream_Subprogram -- ------------------------------ procedure Freeze_Stream_Subprogram (F : Entity_Id) is Decl : constant Node_Id := Unit_Declaration_Node (F); Bod : Node_Id; begin -- If this is user-defined subprogram, the corresponding -- stream function appears as a renaming-as-body, and the -- user subprogram must be retrieved by tree traversal. if Present (Decl) and then Nkind (Decl) = N_Subprogram_Declaration and then Present (Corresponding_Body (Decl)) then Bod := Corresponding_Body (Decl); if Nkind (Unit_Declaration_Node (Bod)) = N_Subprogram_Renaming_Declaration then Set_Is_Frozen (Entity (Name (Unit_Declaration_Node (Bod)))); end if; end if; end Freeze_Stream_Subprogram; -- Start of processing for Input begin -- If no underlying type, we have an error that will be diagnosed -- elsewhere, so here we just completely ignore the expansion. if No (U_Type) then return; end if; -- Stream operations can appear in user code even if the restriction -- No_Streams is active (for example, when instantiating a predefined -- container). In that case rewrite the attribute as a Raise to -- prevent any run-time use. if Restriction_Active (No_Streams) then Rewrite (N, Make_Raise_Program_Error (Sloc (N), Reason => PE_Stream_Operation_Not_Allowed)); Set_Etype (N, B_Type); return; end if; -- If there is a TSS for Input, just call it Fname := Find_Stream_Subprogram (P_Type, TSS_Stream_Input); if Present (Fname) then null; else -- If there is a Stream_Convert pragma, use it, we rewrite -- sourcetyp'Input (stream) -- as -- sourcetyp (streamread (strmtyp'Input (stream))); -- where streamread is the given Read function that converts an -- argument of type strmtyp to type sourcetyp or a type from which -- it is derived (extra conversion required for the derived case). Prag := Get_Stream_Convert_Pragma (P_Type); if Present (Prag) then Arg2 := Next (First (Pragma_Argument_Associations (Prag))); Rfunc := Entity (Expression (Arg2)); Rewrite (N, Convert_To (B_Type, Make_Function_Call (Loc, Name => New_Occurrence_Of (Rfunc, Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Etype (First_Formal (Rfunc)), Loc), Attribute_Name => Name_Input, Expressions => Exprs))))); Analyze_And_Resolve (N, B_Type); return; -- Elementary types elsif Is_Elementary_Type (U_Type) then -- A special case arises if we have a defined _Read routine, -- since in this case we are required to call this routine. declare Typ : Entity_Id := P_Type; begin if Present (Full_View (Typ)) then Typ := Full_View (Typ); end if; if Present (TSS (Base_Type (Typ), TSS_Stream_Read)) then Build_Record_Or_Elementary_Input_Function (Loc, Typ, Decl, Fname, Use_Underlying => False); Insert_Action (N, Decl); -- For normal cases, we call the I_xxx routine directly else Rewrite (N, Build_Elementary_Input_Call (N)); Analyze_And_Resolve (N, P_Type); return; end if; end; -- Array type case elsif Is_Array_Type (U_Type) then Build_Array_Input_Function (Loc, U_Type, Decl, Fname); Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False); -- Dispatching case with class-wide type elsif Is_Class_Wide_Type (P_Type) then -- No need to do anything else compiling under restriction -- No_Dispatching_Calls. During the semantic analysis we -- already notified such violation. if Restriction_Active (No_Dispatching_Calls) then return; end if; declare Rtyp : constant Entity_Id := Root_Type (P_Type); Expr : Node_Id; begin -- Read the internal tag (RM 13.13.2(34)) and use it to -- initialize a dummy tag value: -- Descendant_Tag (String'Input (Strm), P_Type); -- This value is used only to provide a controlling -- argument for the eventual _Input call. Descendant_Tag is -- called rather than Internal_Tag to ensure that we have a -- tag for a type that is descended from the prefix type and -- declared at the same accessibility level (the exception -- Tag_Error will be raised otherwise). The level check is -- required for Ada 2005 because tagged types can be -- extended in nested scopes (AI-344). -- Note: we used to generate an explicit declaration of a -- constant Ada.Tags.Tag object, and use an occurrence of -- this constant in Cntrl, but this caused a secondary stack -- leak. Expr := Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Descendant_Tag), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Standard_String, Loc), Attribute_Name => Name_Input, Expressions => New_List ( Relocate_Node (Duplicate_Subexpr (Strm)))), Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (P_Type, Loc), Attribute_Name => Name_Tag))); Set_Etype (Expr, RTE (RE_Tag)); -- Now we need to get the entity for the call, and construct -- a function call node, where we preset a reference to Dnn -- as the controlling argument (doing an unchecked convert -- to the class-wide tagged type to make it look like a real -- tagged object). Fname := Find_Prim_Op (Rtyp, TSS_Stream_Input); Cntrl := Unchecked_Convert_To (P_Type, Expr); Set_Etype (Cntrl, P_Type); Set_Parent (Cntrl, N); end; -- For tagged types, use the primitive Input function elsif Is_Tagged_Type (U_Type) then Fname := Find_Prim_Op (U_Type, TSS_Stream_Input); -- All other record type cases, including protected records. The -- latter only arise for expander generated code for handling -- shared passive partition access. else pragma Assert (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type)); -- Ada 2005 (AI-216): Program_Error is raised executing default -- implementation of the Input attribute of an unchecked union -- type if the type lacks default discriminant values. if Is_Unchecked_Union (Base_Type (U_Type)) and then No (Discriminant_Constraint (U_Type)) then Insert_Action (N, Make_Raise_Program_Error (Loc, Reason => PE_Unchecked_Union_Restriction)); return; end if; -- Build the type's Input function, passing the subtype rather -- than its base type, because checks are needed in the case of -- constrained discriminants (see Ada 2012 AI05-0192). Build_Record_Or_Elementary_Input_Function (Loc, U_Type, Decl, Fname); Insert_Action (N, Decl); if Nkind (Parent (N)) = N_Object_Declaration and then Is_Record_Type (U_Type) then -- The stream function may contain calls to user-defined -- Read procedures for individual components. declare Comp : Entity_Id; Func : Entity_Id; begin Comp := First_Component (U_Type); while Present (Comp) loop Func := Find_Stream_Subprogram (Etype (Comp), TSS_Stream_Read); if Present (Func) then Freeze_Stream_Subprogram (Func); end if; Next_Component (Comp); end loop; end; end if; end if; end if; -- If we fall through, Fname is the function to be called. The result -- is obtained by calling the appropriate function, then converting -- the result. The conversion does a subtype check. Call := Make_Function_Call (Loc, Name => New_Occurrence_Of (Fname, Loc), Parameter_Associations => New_List ( Relocate_Node (Strm))); Set_Controlling_Argument (Call, Cntrl); Rewrite (N, Unchecked_Convert_To (P_Type, Call)); Analyze_And_Resolve (N, P_Type); if Nkind (Parent (N)) = N_Object_Declaration then Freeze_Stream_Subprogram (Fname); end if; end Input; ------------------- -- Integer_Value -- ------------------- -- We transform -- inttype'Fixed_Value (fixed-value) -- into -- inttype(integer-value)) -- we do all the required analysis of the conversion here, because we do -- not want this to go through the fixed-point conversion circuits. Note -- that the back end always treats fixed-point as equivalent to the -- corresponding integer type anyway. when Attribute_Integer_Value => Rewrite (N, Make_Type_Conversion (Loc, Subtype_Mark => New_Occurrence_Of (Entity (Pref), Loc), Expression => Relocate_Node (First (Exprs)))); Set_Etype (N, Entity (Pref)); Set_Analyzed (N); -- Note: it might appear that a properly analyzed unchecked -- conversion would be just fine here, but that's not the case, since -- the full range check performed by the following call is critical. Apply_Type_Conversion_Checks (N); ------------------- -- Invalid_Value -- ------------------- when Attribute_Invalid_Value => Rewrite (N, Get_Simple_Init_Val (Ptyp, N)); ---------- -- Last -- ---------- when Attribute_Last => -- If the prefix type is a constrained packed array type which -- already has a Packed_Array_Impl_Type representation defined, then -- replace this attribute with a direct reference to 'Last of the -- appropriate index subtype (since otherwise the back end will try -- to give us the value of 'Last for this implementation type). if Is_Constrained_Packed_Array (Ptyp) then Rewrite (N, Make_Attribute_Reference (Loc, Attribute_Name => Name_Last, Prefix => New_Occurrence_Of (Get_Index_Subtype (N), Loc))); Analyze_And_Resolve (N, Typ); -- For access type, apply access check as needed elsif Is_Access_Type (Ptyp) then Apply_Access_Check (N); -- For scalar type, if low bound is a reference to an entity, just -- replace with a direct reference. Note that we can only have a -- reference to a constant entity at this stage, anything else would -- have already been rewritten. elsif Is_Scalar_Type (Ptyp) then declare Hi : constant Node_Id := Type_High_Bound (Ptyp); begin if Is_Entity_Name (Hi) then Rewrite (N, New_Occurrence_Of (Entity (Hi), Loc)); end if; end; end if; -------------- -- Last_Bit -- -------------- -- We compute this if a component clause was present, otherwise we leave -- the computation up to the back end, since we don't know what layout -- will be chosen. when Attribute_Last_Bit => Last_Bit_Attr : declare CE : constant Entity_Id := Entity (Selector_Name (Pref)); begin -- In Ada 2005 (or later) if we have the non-default bit order, then -- we return the original value as given in the component clause -- (RM 2005 13.5.2(3/2)). if Present (Component_Clause (CE)) and then Ada_Version >= Ada_2005 and then Reverse_Bit_Order (Scope (CE)) then Rewrite (N, Make_Integer_Literal (Loc, Intval => Expr_Value (Last_Bit (Component_Clause (CE))))); Analyze_And_Resolve (N, Typ); -- Otherwise (Ada 83/95 or Ada 2005 or later with default bit order), -- rewrite with normalized value if we know it statically. elsif Known_Static_Component_Bit_Offset (CE) and then Known_Static_Esize (CE) then Rewrite (N, Make_Integer_Literal (Loc, Intval => (Component_Bit_Offset (CE) mod System_Storage_Unit) + Esize (CE) - 1)); Analyze_And_Resolve (N, Typ); -- Otherwise leave to back end, just apply universal integer checks else Apply_Universal_Integer_Attribute_Checks (N); end if; end Last_Bit_Attr; ------------------ -- Leading_Part -- ------------------ -- Transforms 'Leading_Part into a call to the floating-point attribute -- function Leading_Part in Fat_xxx (where xxx is the root type) -- Note: strictly, we should generate special case code to deal with -- absurdly large positive arguments (greater than Integer'Last), which -- result in returning the first argument unchanged, but it hardly seems -- worth the effort. We raise constraint error for absurdly negative -- arguments which is fine. when Attribute_Leading_Part => Expand_Fpt_Attribute_RI (N); ------------ -- Length -- ------------ when Attribute_Length => Length : declare Ityp : Entity_Id; Xnum : Uint; begin -- Processing for packed array types if Is_Array_Type (Ptyp) and then Is_Packed (Ptyp) then Ityp := Get_Index_Subtype (N); -- If the index type, Ityp, is an enumeration type with holes, -- then we calculate X'Length explicitly using -- Typ'Max -- (0, Ityp'Pos (X'Last (N)) - -- Ityp'Pos (X'First (N)) + 1); -- Since the bounds in the template are the representation values -- and the back end would get the wrong value. if Is_Enumeration_Type (Ityp) and then Present (Enum_Pos_To_Rep (Base_Type (Ityp))) then if No (Exprs) then Xnum := Uint_1; else Xnum := Expr_Value (First (Expressions (N))); end if; Rewrite (N, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Typ, Loc), Attribute_Name => Name_Max, Expressions => New_List (Make_Integer_Literal (Loc, 0), Make_Op_Add (Loc, Left_Opnd => Make_Op_Subtract (Loc, Left_Opnd => Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ityp, Loc), Attribute_Name => Name_Pos, Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => Duplicate_Subexpr (Pref), Attribute_Name => Name_Last, Expressions => New_List ( Make_Integer_Literal (Loc, Xnum))))), Right_Opnd => Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ityp, Loc), Attribute_Name => Name_Pos, Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => Duplicate_Subexpr_No_Checks (Pref), Attribute_Name => Name_First, Expressions => New_List ( Make_Integer_Literal (Loc, Xnum)))))), Right_Opnd => Make_Integer_Literal (Loc, 1))))); Analyze_And_Resolve (N, Typ, Suppress => All_Checks); return; -- If the prefix type is a constrained packed array type which -- already has a Packed_Array_Impl_Type representation defined, -- then replace this attribute with a reference to 'Range_Length -- of the appropriate index subtype (since otherwise the -- back end will try to give us the value of 'Length for -- this implementation type).s elsif Is_Constrained (Ptyp) then Rewrite (N, Make_Attribute_Reference (Loc, Attribute_Name => Name_Range_Length, Prefix => New_Occurrence_Of (Ityp, Loc))); Analyze_And_Resolve (N, Typ); end if; -- Access type case elsif Is_Access_Type (Ptyp) then Apply_Access_Check (N); -- If the designated type is a packed array type, then we convert -- the reference to: -- typ'Max (0, 1 + -- xtyp'Pos (Pref'Last (Expr)) - -- xtyp'Pos (Pref'First (Expr))); -- This is a bit complex, but it is the easiest thing to do that -- works in all cases including enum types with holes xtyp here -- is the appropriate index type. declare Dtyp : constant Entity_Id := Designated_Type (Ptyp); Xtyp : Entity_Id; begin if Is_Array_Type (Dtyp) and then Is_Packed (Dtyp) then Xtyp := Get_Index_Subtype (N); Rewrite (N, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Typ, Loc), Attribute_Name => Name_Max, Expressions => New_List ( Make_Integer_Literal (Loc, 0), Make_Op_Add (Loc, Make_Integer_Literal (Loc, 1), Make_Op_Subtract (Loc, Left_Opnd => Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Xtyp, Loc), Attribute_Name => Name_Pos, Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => Duplicate_Subexpr (Pref), Attribute_Name => Name_Last, Expressions => New_Copy_List (Exprs)))), Right_Opnd => Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Xtyp, Loc), Attribute_Name => Name_Pos, Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => Duplicate_Subexpr_No_Checks (Pref), Attribute_Name => Name_First, Expressions => New_Copy_List (Exprs))))))))); Analyze_And_Resolve (N, Typ); end if; end; -- Otherwise leave it to the back end else Apply_Universal_Integer_Attribute_Checks (N); end if; end Length; -- Attribute Loop_Entry is replaced with a reference to a constant value -- which captures the prefix at the entry point of the related loop. The -- loop itself may be transformed into a conditional block. when Attribute_Loop_Entry => Expand_Loop_Entry_Attribute (N); ------------- -- Machine -- ------------- -- Transforms 'Machine into a call to the floating-point attribute -- function Machine in Fat_xxx (where xxx is the root type). -- Expansion is avoided for cases the back end can handle directly. when Attribute_Machine => if not Is_Inline_Floating_Point_Attribute (N) then Expand_Fpt_Attribute_R (N); end if; ---------------------- -- Machine_Rounding -- ---------------------- -- Transforms 'Machine_Rounding into a call to the floating-point -- attribute function Machine_Rounding in Fat_xxx (where xxx is the root -- type). Expansion is avoided for cases the back end can handle -- directly. when Attribute_Machine_Rounding => if not Is_Inline_Floating_Point_Attribute (N) then Expand_Fpt_Attribute_R (N); end if; ------------------ -- Machine_Size -- ------------------ -- Machine_Size is equivalent to Object_Size, so transform it into -- Object_Size and that way the back end never sees Machine_Size. when Attribute_Machine_Size => Rewrite (N, Make_Attribute_Reference (Loc, Prefix => Prefix (N), Attribute_Name => Name_Object_Size)); Analyze_And_Resolve (N, Typ); -------------- -- Mantissa -- -------------- -- The only case that can get this far is the dynamic case of the old -- Ada 83 Mantissa attribute for the fixed-point case. For this case, -- we expand: -- typ'Mantissa -- into -- ityp (System.Mantissa.Mantissa_Value -- (Integer'Integer_Value (typ'First), -- Integer'Integer_Value (typ'Last))); when Attribute_Mantissa => Rewrite (N, Convert_To (Typ, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Mantissa_Value), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Standard_Integer, Loc), Attribute_Name => Name_Integer_Value, Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ptyp, Loc), Attribute_Name => Name_First))), Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Standard_Integer, Loc), Attribute_Name => Name_Integer_Value, Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ptyp, Loc), Attribute_Name => Name_Last))))))); Analyze_And_Resolve (N, Typ); --------- -- Max -- --------- when Attribute_Max => Expand_Min_Max_Attribute (N); ---------------------------------- -- Max_Size_In_Storage_Elements -- ---------------------------------- when Attribute_Max_Size_In_Storage_Elements => declare Typ : constant Entity_Id := Etype (N); Attr : Node_Id; Conversion_Added : Boolean := False; -- A flag which tracks whether the original attribute has been -- wrapped inside a type conversion. begin -- If the prefix is X'Class, we transform it into a direct reference -- to the class-wide type, because the back end must not see a 'Class -- reference. See also 'Size. if Is_Entity_Name (Pref) and then Is_Class_Wide_Type (Entity (Pref)) then Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc)); return; end if; Apply_Universal_Integer_Attribute_Checks (N); -- The universal integer check may sometimes add a type conversion, -- retrieve the original attribute reference from the expression. Attr := N; if Nkind (Attr) = N_Type_Conversion then Attr := Expression (Attr); Conversion_Added := True; end if; pragma Assert (Nkind (Attr) = N_Attribute_Reference); -- Heap-allocated controlled objects contain two extra pointers which -- are not part of the actual type. Transform the attribute reference -- into a runtime expression to add the size of the hidden header. if Needs_Finalization (Ptyp) and then not Header_Size_Added (Attr) then Set_Header_Size_Added (Attr); -- Generate: -- P'Max_Size_In_Storage_Elements + -- Universal_Integer -- (Header_Size_With_Padding (Ptyp'Alignment)) Rewrite (Attr, Make_Op_Add (Loc, Left_Opnd => Relocate_Node (Attr), Right_Opnd => Convert_To (Universal_Integer, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Header_Size_With_Padding), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ptyp, Loc), Attribute_Name => Name_Alignment)))))); -- Add a conversion to the target type if not Conversion_Added then Rewrite (Attr, Make_Type_Conversion (Loc, Subtype_Mark => New_Occurrence_Of (Typ, Loc), Expression => Relocate_Node (Attr))); end if; Analyze (Attr); return; end if; end; -------------------- -- Mechanism_Code -- -------------------- when Attribute_Mechanism_Code => -- We must replace the prefix in the renamed case if Is_Entity_Name (Pref) and then Present (Alias (Entity (Pref))) then Set_Renamed_Subprogram (Pref, Alias (Entity (Pref))); end if; --------- -- Min -- --------- when Attribute_Min => Expand_Min_Max_Attribute (N); --------- -- Mod -- --------- when Attribute_Mod => Mod_Case : declare Arg : constant Node_Id := Relocate_Node (First (Exprs)); Hi : constant Node_Id := Type_High_Bound (Etype (Arg)); Modv : constant Uint := Modulus (Btyp); begin -- This is not so simple. The issue is what type to use for the -- computation of the modular value. -- The easy case is when the modulus value is within the bounds -- of the signed integer type of the argument. In this case we can -- just do the computation in that signed integer type, and then -- do an ordinary conversion to the target type. if Modv <= Expr_Value (Hi) then Rewrite (N, Convert_To (Btyp, Make_Op_Mod (Loc, Left_Opnd => Arg, Right_Opnd => Make_Integer_Literal (Loc, Modv)))); -- Here we know that the modulus is larger than type'Last of the -- integer type. There are two cases to consider: -- a) The integer value is non-negative. In this case, it is -- returned as the result (since it is less than the modulus). -- b) The integer value is negative. In this case, we know that the -- result is modulus + value, where the value might be as small as -- -modulus. The trouble is what type do we use to do the subtract. -- No type will do, since modulus can be as big as 2**64, and no -- integer type accommodates this value. Let's do bit of algebra -- modulus + value -- = modulus - (-value) -- = (modulus - 1) - (-value - 1) -- Now modulus - 1 is certainly in range of the modular type. -- -value is in the range 1 .. modulus, so -value -1 is in the -- range 0 .. modulus-1 which is in range of the modular type. -- Furthermore, (-value - 1) can be expressed as -(value + 1) -- which we can compute using the integer base type. -- Once this is done we analyze the if expression without range -- checks, because we know everything is in range, and we want -- to prevent spurious warnings on either branch. else Rewrite (N, Make_If_Expression (Loc, Expressions => New_List ( Make_Op_Ge (Loc, Left_Opnd => Duplicate_Subexpr (Arg), Right_Opnd => Make_Integer_Literal (Loc, 0)), Convert_To (Btyp, Duplicate_Subexpr_No_Checks (Arg)), Make_Op_Subtract (Loc, Left_Opnd => Make_Integer_Literal (Loc, Intval => Modv - 1), Right_Opnd => Convert_To (Btyp, Make_Op_Minus (Loc, Right_Opnd => Make_Op_Add (Loc, Left_Opnd => Duplicate_Subexpr_No_Checks (Arg), Right_Opnd => Make_Integer_Literal (Loc, Intval => 1)))))))); end if; Analyze_And_Resolve (N, Btyp, Suppress => All_Checks); end Mod_Case; ----------- -- Model -- ----------- -- Transforms 'Model into a call to the floating-point attribute -- function Model in Fat_xxx (where xxx is the root type). -- Expansion is avoided for cases the back end can handle directly. when Attribute_Model => if not Is_Inline_Floating_Point_Attribute (N) then Expand_Fpt_Attribute_R (N); end if; ----------------- -- Object_Size -- ----------------- -- The processing for Object_Size shares the processing for Size --------- -- Old -- --------- when Attribute_Old => Old : declare Typ : constant Entity_Id := Etype (N); CW_Temp : Entity_Id; CW_Typ : Entity_Id; Ins_Nod : Node_Id; Subp : Node_Id; Temp : Entity_Id; begin -- Generating C code we don't need to expand this attribute when -- we are analyzing the internally built nested postconditions -- procedure since it will be expanded inline (and later it will -- be removed by Expand_N_Subprogram_Body). It this expansion is -- performed in such case then the compiler generates unreferenced -- extra temporaries. if Modify_Tree_For_C and then Chars (Current_Scope) = Name_uPostconditions then return; end if; -- Climb the parent chain looking for subprogram _Postconditions Subp := N; while Present (Subp) loop exit when Nkind (Subp) = N_Subprogram_Body and then Chars (Defining_Entity (Subp)) = Name_uPostconditions; -- If assertions are disabled, no need to create the declaration -- that preserves the value. The postcondition pragma in which -- 'Old appears will be checked or disabled according to the -- current policy in effect. if Nkind (Subp) = N_Pragma and then not Is_Checked (Subp) then return; end if; Subp := Parent (Subp); end loop; -- 'Old can only appear in a postcondition, the generated body of -- _Postconditions must be in the tree (or inlined if we are -- generating C code). pragma Assert (Present (Subp) or else (Modify_Tree_For_C and then In_Inlined_Body)); Temp := Make_Temporary (Loc, 'T', Pref); -- Set the entity kind now in order to mark the temporary as a -- handler of attribute 'Old's prefix. Set_Ekind (Temp, E_Constant); Set_Stores_Attribute_Old_Prefix (Temp); -- Push the scope of the related subprogram where _Postcondition -- resides as this ensures that the object will be analyzed in the -- proper context. if Present (Subp) then Push_Scope (Scope (Defining_Entity (Subp))); -- No need to push the scope when generating C code since the -- _Postcondition procedure has been inlined. else pragma Assert (Modify_Tree_For_C); pragma Assert (In_Inlined_Body); null; end if; -- Locate the insertion place of the internal temporary that saves -- the 'Old value. if Present (Subp) then Ins_Nod := Subp; -- Generating C, the postcondition procedure has been inlined and the -- temporary is added before the first declaration of the enclosing -- subprogram. else pragma Assert (Modify_Tree_For_C); Ins_Nod := N; while Nkind (Ins_Nod) /= N_Subprogram_Body loop Ins_Nod := Parent (Ins_Nod); end loop; Ins_Nod := First (Declarations (Ins_Nod)); end if; -- Preserve the tag of the prefix by offering a specific view of the -- class-wide version of the prefix. if Is_Tagged_Type (Typ) then -- Generate: -- CW_Temp : constant Typ'Class := Typ'Class (Pref); CW_Temp := Make_Temporary (Loc, 'T'); CW_Typ := Class_Wide_Type (Typ); Insert_Before_And_Analyze (Ins_Nod, Make_Object_Declaration (Loc, Defining_Identifier => CW_Temp, Constant_Present => True, Object_Definition => New_Occurrence_Of (CW_Typ, Loc), Expression => Convert_To (CW_Typ, Relocate_Node (Pref)))); -- Generate: -- Temp : Typ renames Typ (CW_Temp); Insert_Before_And_Analyze (Ins_Nod, Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Temp, Subtype_Mark => New_Occurrence_Of (Typ, Loc), Name => Convert_To (Typ, New_Occurrence_Of (CW_Temp, Loc)))); -- Non-tagged case else -- Generate: -- Temp : constant Typ := Pref; Insert_Before_And_Analyze (Ins_Nod, Make_Object_Declaration (Loc, Defining_Identifier => Temp, Constant_Present => True, Object_Definition => New_Occurrence_Of (Typ, Loc), Expression => Relocate_Node (Pref))); end if; if Present (Subp) then Pop_Scope; end if; -- Ensure that the prefix of attribute 'Old is valid. The check must -- be inserted after the expansion of the attribute has taken place -- to reflect the new placement of the prefix. if Validity_Checks_On and then Validity_Check_Operands then Ensure_Valid (Pref); end if; Rewrite (N, New_Occurrence_Of (Temp, Loc)); end Old; ---------------------- -- Overlaps_Storage -- ---------------------- when Attribute_Overlaps_Storage => Overlaps_Storage : declare Loc : constant Source_Ptr := Sloc (N); X : constant Node_Id := Prefix (N); Y : constant Node_Id := First (Expressions (N)); -- The arguments X_Addr, Y_Addr : Node_Id; -- the expressions for their integer addresses X_Size, Y_Size : Node_Id; -- the expressions for their sizes Cond : Node_Id; begin -- Attribute expands into: -- if X'Address < Y'address then -- (X'address + X'Size - 1) >= Y'address -- else -- (Y'address + Y'size - 1) >= X'Address -- end if; -- with the proper address operations. We convert addresses to -- integer addresses to use predefined arithmetic. The size is -- expressed in storage units. We add copies of X_Addr and Y_Addr -- to prevent the appearance of the same node in two places in -- the tree. X_Addr := Unchecked_Convert_To (RTE (RE_Integer_Address), Make_Attribute_Reference (Loc, Attribute_Name => Name_Address, Prefix => New_Copy_Tree (X))); Y_Addr := Unchecked_Convert_To (RTE (RE_Integer_Address), Make_Attribute_Reference (Loc, Attribute_Name => Name_Address, Prefix => New_Copy_Tree (Y))); X_Size := Make_Op_Divide (Loc, Left_Opnd => Make_Attribute_Reference (Loc, Attribute_Name => Name_Size, Prefix => New_Copy_Tree (X)), Right_Opnd => Make_Integer_Literal (Loc, System_Storage_Unit)); Y_Size := Make_Op_Divide (Loc, Left_Opnd => Make_Attribute_Reference (Loc, Attribute_Name => Name_Size, Prefix => New_Copy_Tree (Y)), Right_Opnd => Make_Integer_Literal (Loc, System_Storage_Unit)); Cond := Make_Op_Le (Loc, Left_Opnd => X_Addr, Right_Opnd => Y_Addr); Rewrite (N, Make_If_Expression (Loc, New_List ( Cond, Make_Op_Ge (Loc, Left_Opnd => Make_Op_Add (Loc, Left_Opnd => New_Copy_Tree (X_Addr), Right_Opnd => Make_Op_Subtract (Loc, Left_Opnd => X_Size, Right_Opnd => Make_Integer_Literal (Loc, 1))), Right_Opnd => Y_Addr), Make_Op_Ge (Loc, Left_Opnd => Make_Op_Add (Loc, Left_Opnd => New_Copy_Tree (Y_Addr), Right_Opnd => Make_Op_Subtract (Loc, Left_Opnd => Y_Size, Right_Opnd => Make_Integer_Literal (Loc, 1))), Right_Opnd => X_Addr)))); Analyze_And_Resolve (N, Standard_Boolean); end Overlaps_Storage; ------------ -- Output -- ------------ when Attribute_Output => Output : declare P_Type : constant Entity_Id := Entity (Pref); U_Type : constant Entity_Id := Underlying_Type (P_Type); Pname : Entity_Id; Decl : Node_Id; Prag : Node_Id; Arg3 : Node_Id; Wfunc : Node_Id; begin -- If no underlying type, we have an error that will be diagnosed -- elsewhere, so here we just completely ignore the expansion. if No (U_Type) then return; end if; -- Stream operations can appear in user code even if the restriction -- No_Streams is active (for example, when instantiating a predefined -- container). In that case rewrite the attribute as a Raise to -- prevent any run-time use. if Restriction_Active (No_Streams) then Rewrite (N, Make_Raise_Program_Error (Sloc (N), Reason => PE_Stream_Operation_Not_Allowed)); Set_Etype (N, Standard_Void_Type); return; end if; -- If TSS for Output is present, just call it Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Output); if Present (Pname) then null; else -- If there is a Stream_Convert pragma, use it, we rewrite -- sourcetyp'Output (stream, Item) -- as -- strmtyp'Output (Stream, strmwrite (acttyp (Item))); -- where strmwrite is the given Write function that converts an -- argument of type sourcetyp or a type acctyp, from which it is -- derived to type strmtyp. The conversion to acttyp is required -- for the derived case. Prag := Get_Stream_Convert_Pragma (P_Type); if Present (Prag) then Arg3 := Next (Next (First (Pragma_Argument_Associations (Prag)))); Wfunc := Entity (Expression (Arg3)); Rewrite (N, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Etype (Wfunc), Loc), Attribute_Name => Name_Output, Expressions => New_List ( Relocate_Node (First (Exprs)), Make_Function_Call (Loc, Name => New_Occurrence_Of (Wfunc, Loc), Parameter_Associations => New_List ( OK_Convert_To (Etype (First_Formal (Wfunc)), Relocate_Node (Next (First (Exprs))))))))); Analyze (N); return; -- For elementary types, we call the W_xxx routine directly. Note -- that the effect of Write and Output is identical for the case -- of an elementary type (there are no discriminants or bounds). elsif Is_Elementary_Type (U_Type) then -- A special case arises if we have a defined _Write routine, -- since in this case we are required to call this routine. declare Typ : Entity_Id := P_Type; begin if Present (Full_View (Typ)) then Typ := Full_View (Typ); end if; if Present (TSS (Base_Type (Typ), TSS_Stream_Write)) then Build_Record_Or_Elementary_Output_Procedure (Loc, Typ, Decl, Pname); Insert_Action (N, Decl); -- For normal cases, we call the W_xxx routine directly else Rewrite (N, Build_Elementary_Write_Call (N)); Analyze (N); return; end if; end; -- Array type case elsif Is_Array_Type (U_Type) then Build_Array_Output_Procedure (Loc, U_Type, Decl, Pname); Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False); -- Class-wide case, first output external tag, then dispatch -- to the appropriate primitive Output function (RM 13.13.2(31)). elsif Is_Class_Wide_Type (P_Type) then -- No need to do anything else compiling under restriction -- No_Dispatching_Calls. During the semantic analysis we -- already notified such violation. if Restriction_Active (No_Dispatching_Calls) then return; end if; Tag_Write : declare Strm : constant Node_Id := First (Exprs); Item : constant Node_Id := Next (Strm); begin -- Ada 2005 (AI-344): Check that the accessibility level -- of the type of the output object is not deeper than -- that of the attribute's prefix type. -- if Get_Access_Level (Item'Tag) -- /= Get_Access_Level (P_Type'Tag) -- then -- raise Tag_Error; -- end if; -- String'Output (Strm, External_Tag (Item'Tag)); -- We cannot figure out a practical way to implement this -- accessibility check on virtual machines, so we omit it. if Ada_Version >= Ada_2005 and then Tagged_Type_Expansion then Insert_Action (N, Make_Implicit_If_Statement (N, Condition => Make_Op_Ne (Loc, Left_Opnd => Build_Get_Access_Level (Loc, Make_Attribute_Reference (Loc, Prefix => Relocate_Node ( Duplicate_Subexpr (Item, Name_Req => True)), Attribute_Name => Name_Tag)), Right_Opnd => Make_Integer_Literal (Loc, Type_Access_Level (P_Type))), Then_Statements => New_List (Make_Raise_Statement (Loc, New_Occurrence_Of ( RTE (RE_Tag_Error), Loc))))); end if; Insert_Action (N, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Standard_String, Loc), Attribute_Name => Name_Output, Expressions => New_List ( Relocate_Node (Duplicate_Subexpr (Strm)), Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_External_Tag), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => Relocate_Node (Duplicate_Subexpr (Item, Name_Req => True)), Attribute_Name => Name_Tag)))))); end Tag_Write; Pname := Find_Prim_Op (U_Type, TSS_Stream_Output); -- Tagged type case, use the primitive Output function elsif Is_Tagged_Type (U_Type) then Pname := Find_Prim_Op (U_Type, TSS_Stream_Output); -- All other record type cases, including protected records. -- The latter only arise for expander generated code for -- handling shared passive partition access. else pragma Assert (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type)); -- Ada 2005 (AI-216): Program_Error is raised when executing -- the default implementation of the Output attribute of an -- unchecked union type if the type lacks default discriminant -- values. if Is_Unchecked_Union (Base_Type (U_Type)) and then No (Discriminant_Constraint (U_Type)) then Insert_Action (N, Make_Raise_Program_Error (Loc, Reason => PE_Unchecked_Union_Restriction)); return; end if; Build_Record_Or_Elementary_Output_Procedure (Loc, Base_Type (U_Type), Decl, Pname); Insert_Action (N, Decl); end if; end if; -- If we fall through, Pname is the name of the procedure to call Rewrite_Stream_Proc_Call (Pname); end Output; --------- -- Pos -- --------- -- For enumeration types with a standard representation, Pos is -- handled by the back end. -- For enumeration types, with a non-standard representation we generate -- a call to the _Rep_To_Pos function created when the type was frozen. -- The call has the form -- _rep_to_pos (expr, flag) -- The parameter flag is True if range checks are enabled, causing -- Program_Error to be raised if the expression has an invalid -- representation, and False if range checks are suppressed. -- For integer types, Pos is equivalent to a simple integer -- conversion and we rewrite it as such when Attribute_Pos => Pos : declare Etyp : Entity_Id := Base_Type (Entity (Pref)); begin -- Deal with zero/non-zero boolean values if Is_Boolean_Type (Etyp) then Adjust_Condition (First (Exprs)); Etyp := Standard_Boolean; Set_Prefix (N, New_Occurrence_Of (Standard_Boolean, Loc)); end if; -- Case of enumeration type if Is_Enumeration_Type (Etyp) then -- Non-standard enumeration type (generate call) if Present (Enum_Pos_To_Rep (Etyp)) then Append_To (Exprs, Rep_To_Pos_Flag (Etyp, Loc)); Rewrite (N, Convert_To (Typ, Make_Function_Call (Loc, Name => New_Occurrence_Of (TSS (Etyp, TSS_Rep_To_Pos), Loc), Parameter_Associations => Exprs))); Analyze_And_Resolve (N, Typ); -- Standard enumeration type (do universal integer check) else Apply_Universal_Integer_Attribute_Checks (N); end if; -- Deal with integer types (replace by conversion) elsif Is_Integer_Type (Etyp) then Rewrite (N, Convert_To (Typ, First (Exprs))); Analyze_And_Resolve (N, Typ); end if; end Pos; -------------- -- Position -- -------------- -- We compute this if a component clause was present, otherwise we leave -- the computation up to the back end, since we don't know what layout -- will be chosen. when Attribute_Position => Position_Attr : declare CE : constant Entity_Id := Entity (Selector_Name (Pref)); begin if Present (Component_Clause (CE)) then -- In Ada 2005 (or later) if we have the non-default bit order, -- then we return the original value as given in the component -- clause (RM 2005 13.5.2(2/2)). if Ada_Version >= Ada_2005 and then Reverse_Bit_Order (Scope (CE)) then Rewrite (N, Make_Integer_Literal (Loc, Intval => Expr_Value (Position (Component_Clause (CE))))); -- Otherwise (Ada 83 or 95, or default bit order specified in -- later Ada version), return the normalized value. else Rewrite (N, Make_Integer_Literal (Loc, Intval => Component_Bit_Offset (CE) / System_Storage_Unit)); end if; Analyze_And_Resolve (N, Typ); -- If back end is doing things, just apply universal integer checks else Apply_Universal_Integer_Attribute_Checks (N); end if; end Position_Attr; ---------- -- Pred -- ---------- -- 1. Deal with enumeration types with holes. -- 2. For floating-point, generate call to attribute function. -- 3. For other cases, deal with constraint checking. when Attribute_Pred => Pred : declare Etyp : constant Entity_Id := Base_Type (Ptyp); begin -- For enumeration types with non-standard representations, we -- expand typ'Pred (x) into -- Pos_To_Rep (Rep_To_Pos (x) - 1) -- If the representation is contiguous, we compute instead -- Lit1 + Rep_to_Pos (x -1), to catch invalid representations. -- The conversion function Enum_Pos_To_Rep is defined on the -- base type, not the subtype, so we have to use the base type -- explicitly for this and other enumeration attributes. if Is_Enumeration_Type (Ptyp) and then Present (Enum_Pos_To_Rep (Etyp)) then if Has_Contiguous_Rep (Etyp) then Rewrite (N, Unchecked_Convert_To (Ptyp, Make_Op_Add (Loc, Left_Opnd => Make_Integer_Literal (Loc, Enumeration_Rep (First_Literal (Ptyp))), Right_Opnd => Make_Function_Call (Loc, Name => New_Occurrence_Of (TSS (Etyp, TSS_Rep_To_Pos), Loc), Parameter_Associations => New_List ( Unchecked_Convert_To (Ptyp, Make_Op_Subtract (Loc, Left_Opnd => Unchecked_Convert_To (Standard_Integer, Relocate_Node (First (Exprs))), Right_Opnd => Make_Integer_Literal (Loc, 1))), Rep_To_Pos_Flag (Ptyp, Loc)))))); else -- Add Boolean parameter True, to request program errror if -- we have a bad representation on our hands. If checks are -- suppressed, then add False instead Append_To (Exprs, Rep_To_Pos_Flag (Ptyp, Loc)); Rewrite (N, Make_Indexed_Component (Loc, Prefix => New_Occurrence_Of (Enum_Pos_To_Rep (Etyp), Loc), Expressions => New_List ( Make_Op_Subtract (Loc, Left_Opnd => Make_Function_Call (Loc, Name => New_Occurrence_Of (TSS (Etyp, TSS_Rep_To_Pos), Loc), Parameter_Associations => Exprs), Right_Opnd => Make_Integer_Literal (Loc, 1))))); end if; Analyze_And_Resolve (N, Typ); -- For floating-point, we transform 'Pred into a call to the Pred -- floating-point attribute function in Fat_xxx (xxx is root type). -- Note that this function takes care of the overflow case. elsif Is_Floating_Point_Type (Ptyp) then Expand_Fpt_Attribute_R (N); Analyze_And_Resolve (N, Typ); -- For modular types, nothing to do (no overflow, since wraps) elsif Is_Modular_Integer_Type (Ptyp) then null; -- For other types, if argument is marked as needing a range check or -- overflow checking is enabled, we must generate a check. elsif not Overflow_Checks_Suppressed (Ptyp) or else Do_Range_Check (First (Exprs)) then Set_Do_Range_Check (First (Exprs), False); Expand_Pred_Succ_Attribute (N); end if; end Pred; -------------- -- Priority -- -------------- -- Ada 2005 (AI-327): Dynamic ceiling priorities -- We rewrite X'Priority as the following run-time call: -- Get_Ceiling (X._Object) -- Note that although X'Priority is notionally an object, it is quite -- deliberately not defined as an aliased object in the RM. This means -- that it works fine to rewrite it as a call, without having to worry -- about complications that would other arise from X'Priority'Access, -- which is illegal, because of the lack of aliasing. when Attribute_Priority => Priority : declare Call : Node_Id; Conctyp : Entity_Id; New_Itype : Entity_Id; Object_Parm : Node_Id; Subprg : Entity_Id; RT_Subprg_Name : Node_Id; begin -- Look for the enclosing concurrent type Conctyp := Current_Scope; while not Is_Concurrent_Type (Conctyp) loop Conctyp := Scope (Conctyp); end loop; pragma Assert (Is_Protected_Type (Conctyp)); -- Generate the actual of the call Subprg := Current_Scope; while not Present (Protected_Body_Subprogram (Subprg)) loop Subprg := Scope (Subprg); end loop; -- Use of 'Priority inside protected entries and barriers (in both -- cases the type of the first formal of their expanded subprogram -- is Address) if Etype (First_Entity (Protected_Body_Subprogram (Subprg))) = RTE (RE_Address) then -- In the expansion of protected entries the type of the first -- formal of the Protected_Body_Subprogram is an Address. In order -- to reference the _object component we generate: -- type T is access p__ptTV; -- freeze T [] New_Itype := Create_Itype (E_Access_Type, N); Set_Etype (New_Itype, New_Itype); Set_Directly_Designated_Type (New_Itype, Corresponding_Record_Type (Conctyp)); Freeze_Itype (New_Itype, N); -- Generate: -- T!(O)._object'unchecked_access Object_Parm := Make_Attribute_Reference (Loc, Prefix => Make_Selected_Component (Loc, Prefix => Unchecked_Convert_To (New_Itype, New_Occurrence_Of (First_Entity (Protected_Body_Subprogram (Subprg)), Loc)), Selector_Name => Make_Identifier (Loc, Name_uObject)), Attribute_Name => Name_Unchecked_Access); -- Use of 'Priority inside a protected subprogram else Object_Parm := Make_Attribute_Reference (Loc, Prefix => Make_Selected_Component (Loc, Prefix => New_Occurrence_Of (First_Entity (Protected_Body_Subprogram (Subprg)), Loc), Selector_Name => Make_Identifier (Loc, Name_uObject)), Attribute_Name => Name_Unchecked_Access); end if; -- Select the appropriate run-time subprogram if Number_Entries (Conctyp) = 0 then RT_Subprg_Name := New_Occurrence_Of (RTE (RE_Get_Ceiling), Loc); else RT_Subprg_Name := New_Occurrence_Of (RTE (RO_PE_Get_Ceiling), Loc); end if; Call := Make_Function_Call (Loc, Name => RT_Subprg_Name, Parameter_Associations => New_List (Object_Parm)); Rewrite (N, Call); -- Avoid the generation of extra checks on the pointer to the -- protected object. Analyze_And_Resolve (N, Typ, Suppress => Access_Check); end Priority; ------------------ -- Range_Length -- ------------------ when Attribute_Range_Length => -- The only special processing required is for the case where -- Range_Length is applied to an enumeration type with holes. -- In this case we transform -- X'Range_Length -- to -- X'Pos (X'Last) - X'Pos (X'First) + 1 -- So that the result reflects the proper Pos values instead -- of the underlying representations. if Is_Enumeration_Type (Ptyp) and then Has_Non_Standard_Rep (Ptyp) then Rewrite (N, Make_Op_Add (Loc, Left_Opnd => Make_Op_Subtract (Loc, Left_Opnd => Make_Attribute_Reference (Loc, Attribute_Name => Name_Pos, Prefix => New_Occurrence_Of (Ptyp, Loc), Expressions => New_List ( Make_Attribute_Reference (Loc, Attribute_Name => Name_Last, Prefix => New_Occurrence_Of (Ptyp, Loc)))), Right_Opnd => Make_Attribute_Reference (Loc, Attribute_Name => Name_Pos, Prefix => New_Occurrence_Of (Ptyp, Loc), Expressions => New_List ( Make_Attribute_Reference (Loc, Attribute_Name => Name_First, Prefix => New_Occurrence_Of (Ptyp, Loc))))), Right_Opnd => Make_Integer_Literal (Loc, 1))); Analyze_And_Resolve (N, Typ); -- For all other cases, the attribute is handled by the back end, but -- we need to deal with the case of the range check on a universal -- integer. else Apply_Universal_Integer_Attribute_Checks (N); end if; ---------- -- Read -- ---------- when Attribute_Read => Read : declare P_Type : constant Entity_Id := Entity (Pref); B_Type : constant Entity_Id := Base_Type (P_Type); U_Type : constant Entity_Id := Underlying_Type (P_Type); Pname : Entity_Id; Decl : Node_Id; Prag : Node_Id; Arg2 : Node_Id; Rfunc : Node_Id; Lhs : Node_Id; Rhs : Node_Id; begin -- If no underlying type, we have an error that will be diagnosed -- elsewhere, so here we just completely ignore the expansion. if No (U_Type) then return; end if; -- Stream operations can appear in user code even if the restriction -- No_Streams is active (for example, when instantiating a predefined -- container). In that case rewrite the attribute as a Raise to -- prevent any run-time use. if Restriction_Active (No_Streams) then Rewrite (N, Make_Raise_Program_Error (Sloc (N), Reason => PE_Stream_Operation_Not_Allowed)); Set_Etype (N, B_Type); return; end if; -- The simple case, if there is a TSS for Read, just call it Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Read); if Present (Pname) then null; else -- If there is a Stream_Convert pragma, use it, we rewrite -- sourcetyp'Read (stream, Item) -- as -- Item := sourcetyp (strmread (strmtyp'Input (Stream))); -- where strmread is the given Read function that converts an -- argument of type strmtyp to type sourcetyp or a type from which -- it is derived. The conversion to sourcetyp is required in the -- latter case. -- A special case arises if Item is a type conversion in which -- case, we have to expand to: -- Itemx := typex (strmread (strmtyp'Input (Stream))); -- where Itemx is the expression of the type conversion (i.e. -- the actual object), and typex is the type of Itemx. Prag := Get_Stream_Convert_Pragma (P_Type); if Present (Prag) then Arg2 := Next (First (Pragma_Argument_Associations (Prag))); Rfunc := Entity (Expression (Arg2)); Lhs := Relocate_Node (Next (First (Exprs))); Rhs := OK_Convert_To (B_Type, Make_Function_Call (Loc, Name => New_Occurrence_Of (Rfunc, Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Etype (First_Formal (Rfunc)), Loc), Attribute_Name => Name_Input, Expressions => New_List ( Relocate_Node (First (Exprs))))))); if Nkind (Lhs) = N_Type_Conversion then Lhs := Expression (Lhs); Rhs := Convert_To (Etype (Lhs), Rhs); end if; Rewrite (N, Make_Assignment_Statement (Loc, Name => Lhs, Expression => Rhs)); Set_Assignment_OK (Lhs); Analyze (N); return; -- For elementary types, we call the I_xxx routine using the first -- parameter and then assign the result into the second parameter. -- We set Assignment_OK to deal with the conversion case. elsif Is_Elementary_Type (U_Type) then declare Lhs : Node_Id; Rhs : Node_Id; begin Lhs := Relocate_Node (Next (First (Exprs))); Rhs := Build_Elementary_Input_Call (N); if Nkind (Lhs) = N_Type_Conversion then Lhs := Expression (Lhs); Rhs := Convert_To (Etype (Lhs), Rhs); end if; Set_Assignment_OK (Lhs); Rewrite (N, Make_Assignment_Statement (Loc, Name => Lhs, Expression => Rhs)); Analyze (N); return; end; -- Array type case elsif Is_Array_Type (U_Type) then Build_Array_Read_Procedure (N, U_Type, Decl, Pname); Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False); -- Tagged type case, use the primitive Read function. Note that -- this will dispatch in the class-wide case which is what we want elsif Is_Tagged_Type (U_Type) then Pname := Find_Prim_Op (U_Type, TSS_Stream_Read); -- All other record type cases, including protected records. The -- latter only arise for expander generated code for handling -- shared passive partition access. else pragma Assert (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type)); -- Ada 2005 (AI-216): Program_Error is raised when executing -- the default implementation of the Read attribute of an -- Unchecked_Union type. if Is_Unchecked_Union (Base_Type (U_Type)) then Insert_Action (N, Make_Raise_Program_Error (Loc, Reason => PE_Unchecked_Union_Restriction)); end if; if Has_Discriminants (U_Type) and then Present (Discriminant_Default_Value (First_Discriminant (U_Type))) then Build_Mutable_Record_Read_Procedure (Loc, Full_Base (U_Type), Decl, Pname); else Build_Record_Read_Procedure (Loc, Full_Base (U_Type), Decl, Pname); end if; -- Suppress checks, uninitialized or otherwise invalid -- data does not cause constraint errors to be raised for -- a complete record read. Insert_Action (N, Decl, All_Checks); end if; end if; Rewrite_Stream_Proc_Call (Pname); end Read; --------- -- Ref -- --------- -- Ref is identical to To_Address, see To_Address for processing --------------- -- Remainder -- --------------- -- Transforms 'Remainder into a call to the floating-point attribute -- function Remainder in Fat_xxx (where xxx is the root type) when Attribute_Remainder => Expand_Fpt_Attribute_RR (N); ------------ -- Result -- ------------ -- Transform 'Result into reference to _Result formal. At the point -- where a legal 'Result attribute is expanded, we know that we are in -- the context of a _Postcondition function with a _Result parameter. when Attribute_Result => Rewrite (N, Make_Identifier (Loc, Chars => Name_uResult)); Analyze_And_Resolve (N, Typ); ----------- -- Round -- ----------- -- The handling of the Round attribute is quite delicate. The processing -- in Sem_Attr introduced a conversion to universal real, reflecting the -- semantics of Round, but we do not want anything to do with universal -- real at runtime, since this corresponds to using floating-point -- arithmetic. -- What we have now is that the Etype of the Round attribute correctly -- indicates the final result type. The operand of the Round is the -- conversion to universal real, described above, and the operand of -- this conversion is the actual operand of Round, which may be the -- special case of a fixed point multiplication or division (Etype = -- universal fixed) -- The exapander will expand first the operand of the conversion, then -- the conversion, and finally the round attribute itself, since we -- always work inside out. But we cannot simply process naively in this -- order. In the semantic world where universal fixed and real really -- exist and have infinite precision, there is no problem, but in the -- implementation world, where universal real is a floating-point type, -- we would get the wrong result. -- So the approach is as follows. First, when expanding a multiply or -- divide whose type is universal fixed, we do nothing at all, instead -- deferring the operation till later. -- The actual processing is done in Expand_N_Type_Conversion which -- handles the special case of Round by looking at its parent to see if -- it is a Round attribute, and if it is, handling the conversion (or -- its fixed multiply/divide child) in an appropriate manner. -- This means that by the time we get to expanding the Round attribute -- itself, the Round is nothing more than a type conversion (and will -- often be a null type conversion), so we just replace it with the -- appropriate conversion operation. when Attribute_Round => Rewrite (N, Convert_To (Etype (N), Relocate_Node (First (Exprs)))); Analyze_And_Resolve (N); -------------- -- Rounding -- -------------- -- Transforms 'Rounding into a call to the floating-point attribute -- function Rounding in Fat_xxx (where xxx is the root type) -- Expansion is avoided for cases the back end can handle directly. when Attribute_Rounding => if not Is_Inline_Floating_Point_Attribute (N) then Expand_Fpt_Attribute_R (N); end if; ------------- -- Scaling -- ------------- -- Transforms 'Scaling into a call to the floating-point attribute -- function Scaling in Fat_xxx (where xxx is the root type) when Attribute_Scaling => Expand_Fpt_Attribute_RI (N); ------------------------- -- Simple_Storage_Pool -- ------------------------- when Attribute_Simple_Storage_Pool => Rewrite (N, Make_Type_Conversion (Loc, Subtype_Mark => New_Occurrence_Of (Etype (N), Loc), Expression => New_Occurrence_Of (Entity (N), Loc))); Analyze_And_Resolve (N, Typ); ---------- -- Size -- ---------- when Attribute_Object_Size | Attribute_Size | Attribute_Value_Size | Attribute_VADS_Size => Size : declare Siz : Uint; New_Node : Node_Id; begin -- Processing for VADS_Size case. Note that this processing -- removes all traces of VADS_Size from the tree, and completes -- all required processing for VADS_Size by translating the -- attribute reference to an appropriate Size or Object_Size -- reference. if Id = Attribute_VADS_Size or else (Use_VADS_Size and then Id = Attribute_Size) then -- If the size is specified, then we simply use the specified -- size. This applies to both types and objects. The size of an -- object can be specified in the following ways: -- An explicit size object is given for an object -- A component size is specified for an indexed component -- A component clause is specified for a selected component -- The object is a component of a packed composite object -- If the size is specified, then VADS_Size of an object if (Is_Entity_Name (Pref) and then Present (Size_Clause (Entity (Pref)))) or else (Nkind (Pref) = N_Component_Clause and then (Present (Component_Clause (Entity (Selector_Name (Pref)))) or else Is_Packed (Etype (Prefix (Pref))))) or else (Nkind (Pref) = N_Indexed_Component and then (Component_Size (Etype (Prefix (Pref))) /= 0 or else Is_Packed (Etype (Prefix (Pref))))) then Set_Attribute_Name (N, Name_Size); -- Otherwise if we have an object rather than a type, then -- the VADS_Size attribute applies to the type of the object, -- rather than the object itself. This is one of the respects -- in which VADS_Size differs from Size. else if (not Is_Entity_Name (Pref) or else not Is_Type (Entity (Pref))) and then (Is_Scalar_Type (Ptyp) or else Is_Constrained (Ptyp)) then Rewrite (Pref, New_Occurrence_Of (Ptyp, Loc)); end if; -- For a scalar type for which no size was explicitly given, -- VADS_Size means Object_Size. This is the other respect in -- which VADS_Size differs from Size. if Is_Scalar_Type (Ptyp) and then No (Size_Clause (Ptyp)) then Set_Attribute_Name (N, Name_Object_Size); -- In all other cases, Size and VADS_Size are the sane else Set_Attribute_Name (N, Name_Size); end if; end if; end if; -- If the prefix is X'Class, transform it into a direct reference -- to the class-wide type, because the back end must not see a -- 'Class reference. if Is_Entity_Name (Pref) and then Is_Class_Wide_Type (Entity (Pref)) then Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc)); return; -- For X'Size applied to an object of a class-wide type, transform -- X'Size into a call to the primitive operation _Size applied to -- X. elsif Is_Class_Wide_Type (Ptyp) then -- No need to do anything else compiling under restriction -- No_Dispatching_Calls. During the semantic analysis we -- already noted this restriction violation. if Restriction_Active (No_Dispatching_Calls) then return; end if; New_Node := Make_Function_Call (Loc, Name => New_Occurrence_Of (Find_Prim_Op (Ptyp, Name_uSize), Loc), Parameter_Associations => New_List (Pref)); if Typ /= Standard_Long_Long_Integer then -- The context is a specific integer type with which the -- original attribute was compatible. The function has a -- specific type as well, so to preserve the compatibility -- we must convert explicitly. New_Node := Convert_To (Typ, New_Node); end if; Rewrite (N, New_Node); Analyze_And_Resolve (N, Typ); return; -- Case of known RM_Size of a type elsif (Id = Attribute_Size or else Id = Attribute_Value_Size) and then Is_Entity_Name (Pref) and then Is_Type (Entity (Pref)) and then Known_Static_RM_Size (Entity (Pref)) then Siz := RM_Size (Entity (Pref)); -- Case of known Esize of a type elsif Id = Attribute_Object_Size and then Is_Entity_Name (Pref) and then Is_Type (Entity (Pref)) and then Known_Static_Esize (Entity (Pref)) then Siz := Esize (Entity (Pref)); -- Case of known size of object elsif Id = Attribute_Size and then Is_Entity_Name (Pref) and then Is_Object (Entity (Pref)) and then Known_Esize (Entity (Pref)) and then Known_Static_Esize (Entity (Pref)) then Siz := Esize (Entity (Pref)); -- For an array component, we can do Size in the front end if the -- component_size of the array is set. elsif Nkind (Pref) = N_Indexed_Component then Siz := Component_Size (Etype (Prefix (Pref))); -- For a record component, we can do Size in the front end if -- there is a component clause, or if the record is packed and the -- component's size is known at compile time. elsif Nkind (Pref) = N_Selected_Component then declare Rec : constant Entity_Id := Etype (Prefix (Pref)); Comp : constant Entity_Id := Entity (Selector_Name (Pref)); begin if Present (Component_Clause (Comp)) then Siz := Esize (Comp); elsif Is_Packed (Rec) then Siz := RM_Size (Ptyp); else Apply_Universal_Integer_Attribute_Checks (N); return; end if; end; -- All other cases are handled by the back end else Apply_Universal_Integer_Attribute_Checks (N); -- If Size is applied to a formal parameter that is of a packed -- array subtype, then apply Size to the actual subtype. if Is_Entity_Name (Pref) and then Is_Formal (Entity (Pref)) and then Is_Array_Type (Ptyp) and then Is_Packed (Ptyp) then Rewrite (N, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Get_Actual_Subtype (Pref), Loc), Attribute_Name => Name_Size)); Analyze_And_Resolve (N, Typ); end if; -- If Size applies to a dereference of an access to -- unconstrained packed array, the back end needs to see its -- unconstrained nominal type, but also a hint to the actual -- constrained type. if Nkind (Pref) = N_Explicit_Dereference and then Is_Array_Type (Ptyp) and then not Is_Constrained (Ptyp) and then Is_Packed (Ptyp) then Set_Actual_Designated_Subtype (Pref, Get_Actual_Subtype (Pref)); end if; return; end if; -- Common processing for record and array component case if Siz /= No_Uint and then Siz /= 0 then declare CS : constant Boolean := Comes_From_Source (N); begin Rewrite (N, Make_Integer_Literal (Loc, Siz)); -- This integer literal is not a static expression. We do -- not call Analyze_And_Resolve here, because this would -- activate the circuit for deciding that a static value -- was out of range, and we don't want that. -- So just manually set the type, mark the expression as -- non-static, and then ensure that the result is checked -- properly if the attribute comes from source (if it was -- internally generated, we never need a constraint check). Set_Etype (N, Typ); Set_Is_Static_Expression (N, False); if CS then Apply_Constraint_Check (N, Typ); end if; end; end if; end Size; ------------------ -- Storage_Pool -- ------------------ when Attribute_Storage_Pool => Rewrite (N, Make_Type_Conversion (Loc, Subtype_Mark => New_Occurrence_Of (Etype (N), Loc), Expression => New_Occurrence_Of (Entity (N), Loc))); Analyze_And_Resolve (N, Typ); ------------------ -- Storage_Size -- ------------------ when Attribute_Storage_Size => Storage_Size : declare Alloc_Op : Entity_Id := Empty; begin -- Access type case, always go to the root type -- The case of access types results in a value of zero for the case -- where no storage size attribute clause has been given. If a -- storage size has been given, then the attribute is converted -- to a reference to the variable used to hold this value. if Is_Access_Type (Ptyp) then if Present (Storage_Size_Variable (Root_Type (Ptyp))) then Rewrite (N, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Typ, Loc), Attribute_Name => Name_Max, Expressions => New_List ( Make_Integer_Literal (Loc, 0), Convert_To (Typ, New_Occurrence_Of (Storage_Size_Variable (Root_Type (Ptyp)), Loc))))); elsif Present (Associated_Storage_Pool (Root_Type (Ptyp))) then -- If the access type is associated with a simple storage pool -- object, then attempt to locate the optional Storage_Size -- function of the simple storage pool type. If not found, -- then the result will default to zero. if Present (Get_Rep_Pragma (Root_Type (Ptyp), Name_Simple_Storage_Pool_Type)) then declare Pool_Type : constant Entity_Id := Base_Type (Etype (Entity (N))); begin Alloc_Op := Get_Name_Entity_Id (Name_Storage_Size); while Present (Alloc_Op) loop if Scope (Alloc_Op) = Scope (Pool_Type) and then Present (First_Formal (Alloc_Op)) and then Etype (First_Formal (Alloc_Op)) = Pool_Type then exit; end if; Alloc_Op := Homonym (Alloc_Op); end loop; end; -- In the normal Storage_Pool case, retrieve the primitive -- function associated with the pool type. else Alloc_Op := Find_Prim_Op (Etype (Associated_Storage_Pool (Root_Type (Ptyp))), Attribute_Name (N)); end if; -- If Storage_Size wasn't found (can only occur in the simple -- storage pool case), then simply use zero for the result. if not Present (Alloc_Op) then Rewrite (N, Make_Integer_Literal (Loc, 0)); -- Otherwise, rewrite the allocator as a call to pool type's -- Storage_Size function. else Rewrite (N, OK_Convert_To (Typ, Make_Function_Call (Loc, Name => New_Occurrence_Of (Alloc_Op, Loc), Parameter_Associations => New_List ( New_Occurrence_Of (Associated_Storage_Pool (Root_Type (Ptyp)), Loc))))); end if; else Rewrite (N, Make_Integer_Literal (Loc, 0)); end if; Analyze_And_Resolve (N, Typ); -- For tasks, we retrieve the size directly from the TCB. The -- size may depend on a discriminant of the type, and therefore -- can be a per-object expression, so type-level information is -- not sufficient in general. There are four cases to consider: -- a) If the attribute appears within a task body, the designated -- TCB is obtained by a call to Self. -- b) If the prefix of the attribute is the name of a task object, -- the designated TCB is the one stored in the corresponding record. -- c) If the prefix is a task type, the size is obtained from the -- size variable created for each task type -- d) If no Storage_Size was specified for the type, there is no -- size variable, and the value is a system-specific default. else if In_Open_Scopes (Ptyp) then -- Storage_Size (Self) Rewrite (N, Convert_To (Typ, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Storage_Size), Loc), Parameter_Associations => New_List ( Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Self), Loc)))))); elsif not Is_Entity_Name (Pref) or else not Is_Type (Entity (Pref)) then -- Storage_Size (Rec (Obj).Size) Rewrite (N, Convert_To (Typ, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Storage_Size), Loc), Parameter_Associations => New_List ( Make_Selected_Component (Loc, Prefix => Unchecked_Convert_To ( Corresponding_Record_Type (Ptyp), New_Copy_Tree (Pref)), Selector_Name => Make_Identifier (Loc, Name_uTask_Id)))))); elsif Present (Storage_Size_Variable (Ptyp)) then -- Static Storage_Size pragma given for type: retrieve value -- from its allocated storage variable. Rewrite (N, Convert_To (Typ, Make_Function_Call (Loc, Name => New_Occurrence_Of ( RTE (RE_Adjust_Storage_Size), Loc), Parameter_Associations => New_List ( New_Occurrence_Of ( Storage_Size_Variable (Ptyp), Loc))))); else -- Get system default Rewrite (N, Convert_To (Typ, Make_Function_Call (Loc, Name => New_Occurrence_Of ( RTE (RE_Default_Stack_Size), Loc)))); end if; Analyze_And_Resolve (N, Typ); end if; end Storage_Size; ----------------- -- Stream_Size -- ----------------- when Attribute_Stream_Size => Rewrite (N, Make_Integer_Literal (Loc, Intval => Get_Stream_Size (Ptyp))); Analyze_And_Resolve (N, Typ); ---------- -- Succ -- ---------- -- 1. Deal with enumeration types with holes. -- 2. For floating-point, generate call to attribute function. -- 3. For other cases, deal with constraint checking. when Attribute_Succ => Succ : declare Etyp : constant Entity_Id := Base_Type (Ptyp); begin -- For enumeration types with non-standard representations, we -- expand typ'Succ (x) into -- Pos_To_Rep (Rep_To_Pos (x) + 1) -- If the representation is contiguous, we compute instead -- Lit1 + Rep_to_Pos (x+1), to catch invalid representations. if Is_Enumeration_Type (Ptyp) and then Present (Enum_Pos_To_Rep (Etyp)) then if Has_Contiguous_Rep (Etyp) then Rewrite (N, Unchecked_Convert_To (Ptyp, Make_Op_Add (Loc, Left_Opnd => Make_Integer_Literal (Loc, Enumeration_Rep (First_Literal (Ptyp))), Right_Opnd => Make_Function_Call (Loc, Name => New_Occurrence_Of (TSS (Etyp, TSS_Rep_To_Pos), Loc), Parameter_Associations => New_List ( Unchecked_Convert_To (Ptyp, Make_Op_Add (Loc, Left_Opnd => Unchecked_Convert_To (Standard_Integer, Relocate_Node (First (Exprs))), Right_Opnd => Make_Integer_Literal (Loc, 1))), Rep_To_Pos_Flag (Ptyp, Loc)))))); else -- Add Boolean parameter True, to request program errror if -- we have a bad representation on our hands. Add False if -- checks are suppressed. Append_To (Exprs, Rep_To_Pos_Flag (Ptyp, Loc)); Rewrite (N, Make_Indexed_Component (Loc, Prefix => New_Occurrence_Of (Enum_Pos_To_Rep (Etyp), Loc), Expressions => New_List ( Make_Op_Add (Loc, Left_Opnd => Make_Function_Call (Loc, Name => New_Occurrence_Of (TSS (Etyp, TSS_Rep_To_Pos), Loc), Parameter_Associations => Exprs), Right_Opnd => Make_Integer_Literal (Loc, 1))))); end if; Analyze_And_Resolve (N, Typ); -- For floating-point, we transform 'Succ into a call to the Succ -- floating-point attribute function in Fat_xxx (xxx is root type) elsif Is_Floating_Point_Type (Ptyp) then Expand_Fpt_Attribute_R (N); Analyze_And_Resolve (N, Typ); -- For modular types, nothing to do (no overflow, since wraps) elsif Is_Modular_Integer_Type (Ptyp) then null; -- For other types, if argument is marked as needing a range check or -- overflow checking is enabled, we must generate a check. elsif not Overflow_Checks_Suppressed (Ptyp) or else Do_Range_Check (First (Exprs)) then Set_Do_Range_Check (First (Exprs), False); Expand_Pred_Succ_Attribute (N); end if; end Succ; --------- -- Tag -- --------- -- Transforms X'Tag into a direct reference to the tag of X when Attribute_Tag => Tag : declare Ttyp : Entity_Id; Prefix_Is_Type : Boolean; begin if Is_Entity_Name (Pref) and then Is_Type (Entity (Pref)) then Ttyp := Entity (Pref); Prefix_Is_Type := True; else Ttyp := Ptyp; Prefix_Is_Type := False; end if; if Is_Class_Wide_Type (Ttyp) then Ttyp := Root_Type (Ttyp); end if; Ttyp := Underlying_Type (Ttyp); -- Ada 2005: The type may be a synchronized tagged type, in which -- case the tag information is stored in the corresponding record. if Is_Concurrent_Type (Ttyp) then Ttyp := Corresponding_Record_Type (Ttyp); end if; if Prefix_Is_Type then -- For VMs we leave the type attribute unexpanded because -- there's not a dispatching table to reference. if Tagged_Type_Expansion then Rewrite (N, Unchecked_Convert_To (RTE (RE_Tag), New_Occurrence_Of (Node (First_Elmt (Access_Disp_Table (Ttyp))), Loc))); Analyze_And_Resolve (N, RTE (RE_Tag)); end if; -- Ada 2005 (AI-251): The use of 'Tag in the sources always -- references the primary tag of the actual object. If 'Tag is -- applied to class-wide interface objects we generate code that -- displaces "this" to reference the base of the object. elsif Comes_From_Source (N) and then Is_Class_Wide_Type (Etype (Prefix (N))) and then Is_Interface (Etype (Prefix (N))) then -- Generate: -- (To_Tag_Ptr (Prefix'Address)).all -- Note that Prefix'Address is recursively expanded into a call -- to Base_Address (Obj.Tag) -- Not needed for VM targets, since all handled by the VM if Tagged_Type_Expansion then Rewrite (N, Make_Explicit_Dereference (Loc, Unchecked_Convert_To (RTE (RE_Tag_Ptr), Make_Attribute_Reference (Loc, Prefix => Relocate_Node (Pref), Attribute_Name => Name_Address)))); Analyze_And_Resolve (N, RTE (RE_Tag)); end if; else Rewrite (N, Make_Selected_Component (Loc, Prefix => Relocate_Node (Pref), Selector_Name => New_Occurrence_Of (First_Tag_Component (Ttyp), Loc))); Analyze_And_Resolve (N, RTE (RE_Tag)); end if; end Tag; ---------------- -- Terminated -- ---------------- -- Transforms 'Terminated attribute into a call to Terminated function when Attribute_Terminated => Terminated : begin -- The prefix of Terminated is of a task interface class-wide type. -- Generate: -- terminated (Task_Id (Pref._disp_get_task_id)); if Ada_Version >= Ada_2005 and then Ekind (Ptyp) = E_Class_Wide_Type and then Is_Interface (Ptyp) and then Is_Task_Interface (Ptyp) then Rewrite (N, Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Terminated), Loc), Parameter_Associations => New_List ( Make_Unchecked_Type_Conversion (Loc, Subtype_Mark => New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc), Expression => Make_Selected_Component (Loc, Prefix => New_Copy_Tree (Pref), Selector_Name => Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))))); elsif Restricted_Profile then Rewrite (N, Build_Call_With_Task (Pref, RTE (RE_Restricted_Terminated))); else Rewrite (N, Build_Call_With_Task (Pref, RTE (RE_Terminated))); end if; Analyze_And_Resolve (N, Standard_Boolean); end Terminated; ---------------- -- To_Address -- ---------------- -- Transforms System'To_Address (X) and System.Address'Ref (X) into -- unchecked conversion from (integral) type of X to type address. when Attribute_Ref | Attribute_To_Address => Rewrite (N, Unchecked_Convert_To (RTE (RE_Address), Relocate_Node (First (Exprs)))); Analyze_And_Resolve (N, RTE (RE_Address)); ------------ -- To_Any -- ------------ when Attribute_To_Any => To_Any : declare P_Type : constant Entity_Id := Etype (Pref); Decls : constant List_Id := New_List; begin Rewrite (N, Build_To_Any_Call (Loc, Convert_To (P_Type, Relocate_Node (First (Exprs))), Decls)); Insert_Actions (N, Decls); Analyze_And_Resolve (N, RTE (RE_Any)); end To_Any; ---------------- -- Truncation -- ---------------- -- Transforms 'Truncation into a call to the floating-point attribute -- function Truncation in Fat_xxx (where xxx is the root type). -- Expansion is avoided for cases the back end can handle directly. when Attribute_Truncation => if not Is_Inline_Floating_Point_Attribute (N) then Expand_Fpt_Attribute_R (N); end if; -------------- -- TypeCode -- -------------- when Attribute_TypeCode => TypeCode : declare P_Type : constant Entity_Id := Etype (Pref); Decls : constant List_Id := New_List; begin Rewrite (N, Build_TypeCode_Call (Loc, P_Type, Decls)); Insert_Actions (N, Decls); Analyze_And_Resolve (N, RTE (RE_TypeCode)); end TypeCode; ----------------------- -- Unbiased_Rounding -- ----------------------- -- Transforms 'Unbiased_Rounding into a call to the floating-point -- attribute function Unbiased_Rounding in Fat_xxx (where xxx is the -- root type). Expansion is avoided for cases the back end can handle -- directly. when Attribute_Unbiased_Rounding => if not Is_Inline_Floating_Point_Attribute (N) then Expand_Fpt_Attribute_R (N); end if; ------------ -- Update -- ------------ when Attribute_Update => Expand_Update_Attribute (N); --------------- -- VADS_Size -- --------------- -- The processing for VADS_Size is shared with Size --------- -- Val -- --------- -- For enumeration types with a standard representation, and for all -- other types, Val is handled by the back end. For enumeration types -- with a non-standard representation we use the _Pos_To_Rep array that -- was created when the type was frozen. when Attribute_Val => Val : declare Etyp : constant Entity_Id := Base_Type (Entity (Pref)); begin if Is_Enumeration_Type (Etyp) and then Present (Enum_Pos_To_Rep (Etyp)) then if Has_Contiguous_Rep (Etyp) then declare Rep_Node : constant Node_Id := Unchecked_Convert_To (Etyp, Make_Op_Add (Loc, Left_Opnd => Make_Integer_Literal (Loc, Enumeration_Rep (First_Literal (Etyp))), Right_Opnd => (Convert_To (Standard_Integer, Relocate_Node (First (Exprs)))))); begin Rewrite (N, Unchecked_Convert_To (Etyp, Make_Op_Add (Loc, Left_Opnd => Make_Integer_Literal (Loc, Enumeration_Rep (First_Literal (Etyp))), Right_Opnd => Make_Function_Call (Loc, Name => New_Occurrence_Of (TSS (Etyp, TSS_Rep_To_Pos), Loc), Parameter_Associations => New_List ( Rep_Node, Rep_To_Pos_Flag (Etyp, Loc)))))); end; else Rewrite (N, Make_Indexed_Component (Loc, Prefix => New_Occurrence_Of (Enum_Pos_To_Rep (Etyp), Loc), Expressions => New_List ( Convert_To (Standard_Integer, Relocate_Node (First (Exprs)))))); end if; Analyze_And_Resolve (N, Typ); -- If the argument is marked as requiring a range check then generate -- it here. elsif Do_Range_Check (First (Exprs)) then Generate_Range_Check (First (Exprs), Etyp, CE_Range_Check_Failed); end if; end Val; ----------- -- Valid -- ----------- -- The code for valid is dependent on the particular types involved. -- See separate sections below for the generated code in each case. when Attribute_Valid => Valid : declare Btyp : Entity_Id := Base_Type (Ptyp); Tst : Node_Id; Save_Validity_Checks_On : constant Boolean := Validity_Checks_On; -- Save the validity checking mode. We always turn off validity -- checking during process of 'Valid since this is one place -- where we do not want the implicit validity checks to intefere -- with the explicit validity check that the programmer is doing. function Make_Range_Test return Node_Id; -- Build the code for a range test of the form -- Btyp!(Pref) in Btyp!(Ptyp'First) .. Btyp!(Ptyp'Last) --------------------- -- Make_Range_Test -- --------------------- function Make_Range_Test return Node_Id is Temp : constant Node_Id := Duplicate_Subexpr (Pref); begin -- The value whose validity is being checked has been captured in -- an object declaration. We certainly don't want this object to -- appear valid because the declaration initializes it. if Is_Entity_Name (Temp) then Set_Is_Known_Valid (Entity (Temp), False); end if; return Make_In (Loc, Left_Opnd => Unchecked_Convert_To (Btyp, Temp), Right_Opnd => Make_Range (Loc, Low_Bound => Unchecked_Convert_To (Btyp, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ptyp, Loc), Attribute_Name => Name_First)), High_Bound => Unchecked_Convert_To (Btyp, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ptyp, Loc), Attribute_Name => Name_Last)))); end Make_Range_Test; -- Start of processing for Attribute_Valid begin -- Do not expand sourced code 'Valid reference in CodePeer mode, -- will be handled by the back-end directly. if CodePeer_Mode and then Comes_From_Source (N) then return; end if; -- Turn off validity checks. We do not want any implicit validity -- checks to intefere with the explicit check from the attribute Validity_Checks_On := False; -- Retrieve the base type. Handle the case where the base type is a -- private enumeration type. if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then Btyp := Full_View (Btyp); end if; -- Floating-point case. This case is handled by the Valid attribute -- code in the floating-point attribute run-time library. if Is_Floating_Point_Type (Ptyp) then Float_Valid : declare Pkg : RE_Id; Ftp : Entity_Id; function Get_Fat_Entity (Nam : Name_Id) return Entity_Id; -- Return entity for Pkg.Nam -------------------- -- Get_Fat_Entity -- -------------------- function Get_Fat_Entity (Nam : Name_Id) return Entity_Id is Exp_Name : constant Node_Id := Make_Selected_Component (Loc, Prefix => New_Occurrence_Of (RTE (Pkg), Loc), Selector_Name => Make_Identifier (Loc, Nam)); begin Find_Selected_Component (Exp_Name); return Entity (Exp_Name); end Get_Fat_Entity; -- Start of processing for Float_Valid begin -- The C and AAMP back-ends handle Valid for fpt types if Modify_Tree_For_C or else Float_Rep (Btyp) = AAMP then Analyze_And_Resolve (Pref, Ptyp); Set_Etype (N, Standard_Boolean); Set_Analyzed (N); else Find_Fat_Info (Ptyp, Ftp, Pkg); -- If the prefix is a reverse SSO component, or is possibly -- unaligned, first create a temporary copy that is in -- native SSO, and properly aligned. Make it Volatile to -- prevent folding in the back-end. Note that we use an -- intermediate constrained string type to initialize the -- temporary, as the value at hand might be invalid, and in -- that case it cannot be copied using a floating point -- register. if In_Reverse_Storage_Order_Object (Pref) or else Is_Possibly_Unaligned_Object (Pref) then declare Temp : constant Entity_Id := Make_Temporary (Loc, 'F'); Fat_S : constant Entity_Id := Get_Fat_Entity (Name_S); -- Constrained string subtype of appropriate size Fat_P : constant Entity_Id := Get_Fat_Entity (Name_P); -- Access to Fat_S Decl : constant Node_Id := Make_Object_Declaration (Loc, Defining_Identifier => Temp, Aliased_Present => True, Object_Definition => New_Occurrence_Of (Ptyp, Loc)); begin Set_Aspect_Specifications (Decl, New_List ( Make_Aspect_Specification (Loc, Identifier => Make_Identifier (Loc, Name_Volatile)))); Insert_Actions (N, New_List ( Decl, Make_Assignment_Statement (Loc, Name => Make_Explicit_Dereference (Loc, Prefix => Unchecked_Convert_To (Fat_P, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Temp, Loc), Attribute_Name => Name_Unrestricted_Access))), Expression => Unchecked_Convert_To (Fat_S, Relocate_Node (Pref)))), Suppress => All_Checks); Rewrite (Pref, New_Occurrence_Of (Temp, Loc)); end; end if; -- We now have an object of the proper endianness and -- alignment, and can construct a Valid attribute. -- We make sure the prefix of this valid attribute is -- marked as not coming from source, to avoid losing -- warnings from 'Valid looking like a possible update. Set_Comes_From_Source (Pref, False); Expand_Fpt_Attribute (N, Pkg, Name_Valid, New_List ( Make_Attribute_Reference (Loc, Prefix => Unchecked_Convert_To (Ftp, Pref), Attribute_Name => Name_Unrestricted_Access))); end if; -- One more task, we still need a range check. Required -- only if we have a constraint, since the Valid routine -- catches infinities properly (infinities are never valid). -- The way we do the range check is simply to create the -- expression: Valid (N) and then Base_Type(Pref) in Typ. if not Subtypes_Statically_Match (Ptyp, Btyp) then Rewrite (N, Make_And_Then (Loc, Left_Opnd => Relocate_Node (N), Right_Opnd => Make_In (Loc, Left_Opnd => Convert_To (Btyp, Pref), Right_Opnd => New_Occurrence_Of (Ptyp, Loc)))); end if; end Float_Valid; -- Enumeration type with holes -- For enumeration types with holes, the Pos value constructed by -- the Enum_Rep_To_Pos function built in Exp_Ch3 called with a -- second argument of False returns minus one for an invalid value, -- and the non-negative pos value for a valid value, so the -- expansion of X'Valid is simply: -- type(X)'Pos (X) >= 0 -- We can't quite generate it that way because of the requirement -- for the non-standard second argument of False in the resulting -- rep_to_pos call, so we have to explicitly create: -- _rep_to_pos (X, False) >= 0 -- If we have an enumeration subtype, we also check that the -- value is in range: -- _rep_to_pos (X, False) >= 0 -- and then -- (X >= type(X)'First and then type(X)'Last <= X) elsif Is_Enumeration_Type (Ptyp) and then Present (Enum_Pos_To_Rep (Btyp)) then Tst := Make_Op_Ge (Loc, Left_Opnd => Make_Function_Call (Loc, Name => New_Occurrence_Of (TSS (Btyp, TSS_Rep_To_Pos), Loc), Parameter_Associations => New_List ( Pref, New_Occurrence_Of (Standard_False, Loc))), Right_Opnd => Make_Integer_Literal (Loc, 0)); if Ptyp /= Btyp and then (Type_Low_Bound (Ptyp) /= Type_Low_Bound (Btyp) or else Type_High_Bound (Ptyp) /= Type_High_Bound (Btyp)) then -- The call to Make_Range_Test will create declarations -- that need a proper insertion point, but Pref is now -- attached to a node with no ancestor. Attach to tree -- even if it is to be rewritten below. Set_Parent (Tst, Parent (N)); Tst := Make_And_Then (Loc, Left_Opnd => Make_Range_Test, Right_Opnd => Tst); end if; Rewrite (N, Tst); -- Fortran convention booleans -- For the very special case of Fortran convention booleans, the -- value is always valid, since it is an integer with the semantics -- that non-zero is true, and any value is permissible. elsif Is_Boolean_Type (Ptyp) and then Convention (Ptyp) = Convention_Fortran then Rewrite (N, New_Occurrence_Of (Standard_True, Loc)); -- For biased representations, we will be doing an unchecked -- conversion without unbiasing the result. That means that the range -- test has to take this into account, and the proper form of the -- test is: -- Btyp!(Pref) < Btyp!(Ptyp'Range_Length) elsif Has_Biased_Representation (Ptyp) then Btyp := RTE (RE_Unsigned_32); Rewrite (N, Make_Op_Lt (Loc, Left_Opnd => Unchecked_Convert_To (Btyp, Duplicate_Subexpr (Pref)), Right_Opnd => Unchecked_Convert_To (Btyp, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Ptyp, Loc), Attribute_Name => Name_Range_Length)))); -- For all other scalar types, what we want logically is a -- range test: -- X in type(X)'First .. type(X)'Last -- But that's precisely what won't work because of possible -- unwanted optimization (and indeed the basic motivation for -- the Valid attribute is exactly that this test does not work). -- What will work is: -- Btyp!(X) >= Btyp!(type(X)'First) -- and then -- Btyp!(X) <= Btyp!(type(X)'Last) -- where Btyp is an integer type large enough to cover the full -- range of possible stored values (i.e. it is chosen on the basis -- of the size of the type, not the range of the values). We write -- this as two tests, rather than a range check, so that static -- evaluation will easily remove either or both of the checks if -- they can be -statically determined to be true (this happens -- when the type of X is static and the range extends to the full -- range of stored values). -- Unsigned types. Note: it is safe to consider only whether the -- subtype is unsigned, since we will in that case be doing all -- unsigned comparisons based on the subtype range. Since we use the -- actual subtype object size, this is appropriate. -- For example, if we have -- subtype x is integer range 1 .. 200; -- for x'Object_Size use 8; -- Now the base type is signed, but objects of this type are bits -- unsigned, and doing an unsigned test of the range 1 to 200 is -- correct, even though a value greater than 127 looks signed to a -- signed comparison. elsif Is_Unsigned_Type (Ptyp) then if Esize (Ptyp) <= 32 then Btyp := RTE (RE_Unsigned_32); else Btyp := RTE (RE_Unsigned_64); end if; Rewrite (N, Make_Range_Test); -- Signed types else if Esize (Ptyp) <= Esize (Standard_Integer) then Btyp := Standard_Integer; else Btyp := Universal_Integer; end if; Rewrite (N, Make_Range_Test); end if; -- If a predicate is present, then we do the predicate test, even if -- within the predicate function (infinite recursion is warned about -- in Sem_Attr in that case). declare Pred_Func : constant Entity_Id := Predicate_Function (Ptyp); begin if Present (Pred_Func) then Rewrite (N, Make_And_Then (Loc, Left_Opnd => Relocate_Node (N), Right_Opnd => Make_Predicate_Call (Ptyp, Pref))); end if; end; Analyze_And_Resolve (N, Standard_Boolean); Validity_Checks_On := Save_Validity_Checks_On; end Valid; ------------------- -- Valid_Scalars -- ------------------- when Attribute_Valid_Scalars => Valid_Scalars : declare Ftyp : Entity_Id; begin if Present (Underlying_Type (Ptyp)) then Ftyp := Underlying_Type (Ptyp); else Ftyp := Ptyp; end if; -- Replace by True if no scalar parts if not Scalar_Part_Present (Ftyp) then Rewrite (N, New_Occurrence_Of (Standard_True, Loc)); -- For scalar types, Valid_Scalars is the same as Valid elsif Is_Scalar_Type (Ftyp) then Rewrite (N, Make_Attribute_Reference (Loc, Attribute_Name => Name_Valid, Prefix => Pref)); -- For array types, we construct a function that determines if there -- are any non-valid scalar subcomponents, and call the function. -- We only do this for arrays whose component type needs checking elsif Is_Array_Type (Ftyp) and then Scalar_Part_Present (Component_Type (Ftyp)) then Rewrite (N, Make_Function_Call (Loc, Name => New_Occurrence_Of (Build_Array_VS_Func (Ftyp, N), Loc), Parameter_Associations => New_List (Pref))); -- For record types, we construct a function that determines if there -- are any non-valid scalar subcomponents, and call the function. elsif Is_Record_Type (Ftyp) and then Nkind (Type_Definition (Declaration_Node (Ftyp))) = N_Record_Definition then Rewrite (N, Make_Function_Call (Loc, Name => New_Occurrence_Of (Build_Record_VS_Func (Ftyp, N), Loc), Parameter_Associations => New_List (Pref))); -- Other record types or types with discriminants elsif Is_Record_Type (Ftyp) or else Has_Discriminants (Ptyp) then -- Build expression with list of equality tests declare C : Entity_Id; X : Node_Id; A : Name_Id; begin X := New_Occurrence_Of (Standard_True, Loc); C := First_Component_Or_Discriminant (Ptyp); while Present (C) loop if not Scalar_Part_Present (Etype (C)) then goto Continue; elsif Is_Scalar_Type (Etype (C)) then A := Name_Valid; else A := Name_Valid_Scalars; end if; X := Make_And_Then (Loc, Left_Opnd => X, Right_Opnd => Make_Attribute_Reference (Loc, Attribute_Name => A, Prefix => Make_Selected_Component (Loc, Prefix => Duplicate_Subexpr (Pref, Name_Req => True), Selector_Name => New_Occurrence_Of (C, Loc)))); <<Continue>> Next_Component_Or_Discriminant (C); end loop; Rewrite (N, X); end; -- For all other types, result is True else Rewrite (N, New_Occurrence_Of (Standard_Boolean, Loc)); end if; -- Result is always boolean, but never static Analyze_And_Resolve (N, Standard_Boolean); Set_Is_Static_Expression (N, False); end Valid_Scalars; ----------- -- Value -- ----------- -- Value attribute is handled in separate unit Exp_Imgv when Attribute_Value => Exp_Imgv.Expand_Value_Attribute (N); ----------------- -- Value_Size -- ----------------- -- The processing for Value_Size shares the processing for Size ------------- -- Version -- ------------- -- The processing for Version shares the processing for Body_Version ---------------- -- Wide_Image -- ---------------- -- Wide_Image attribute is handled in separate unit Exp_Imgv when Attribute_Wide_Image => Exp_Imgv.Expand_Wide_Image_Attribute (N); --------------------- -- Wide_Wide_Image -- --------------------- -- Wide_Wide_Image attribute is handled in separate unit Exp_Imgv when Attribute_Wide_Wide_Image => Exp_Imgv.Expand_Wide_Wide_Image_Attribute (N); ---------------- -- Wide_Value -- ---------------- -- We expand typ'Wide_Value (X) into -- typ'Value -- (Wide_String_To_String (X, Wide_Character_Encoding_Method)) -- Wide_String_To_String is a runtime function that converts its wide -- string argument to String, converting any non-translatable characters -- into appropriate escape sequences. This preserves the required -- semantics of Wide_Value in all cases, and results in a very simple -- implementation approach. -- Note: for this approach to be fully standard compliant for the cases -- where typ is Wide_Character and Wide_Wide_Character, the encoding -- method must cover the entire character range (e.g. UTF-8). But that -- is a reasonable requirement when dealing with encoded character -- sequences. Presumably if one of the restrictive encoding mechanisms -- is in use such as Shift-JIS, then characters that cannot be -- represented using this encoding will not appear in any case. when Attribute_Wide_Value => Rewrite (N, Make_Attribute_Reference (Loc, Prefix => Pref, Attribute_Name => Name_Value, Expressions => New_List ( Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Wide_String_To_String), Loc), Parameter_Associations => New_List ( Relocate_Node (First (Exprs)), Make_Integer_Literal (Loc, Intval => Int (Wide_Character_Encoding_Method))))))); Analyze_And_Resolve (N, Typ); --------------------- -- Wide_Wide_Value -- --------------------- -- We expand typ'Wide_Value_Value (X) into -- typ'Value -- (Wide_Wide_String_To_String (X, Wide_Character_Encoding_Method)) -- Wide_Wide_String_To_String is a runtime function that converts its -- wide string argument to String, converting any non-translatable -- characters into appropriate escape sequences. This preserves the -- required semantics of Wide_Wide_Value in all cases, and results in a -- very simple implementation approach. -- It's not quite right where typ = Wide_Wide_Character, because the -- encoding method may not cover the whole character type ??? when Attribute_Wide_Wide_Value => Rewrite (N, Make_Attribute_Reference (Loc, Prefix => Pref, Attribute_Name => Name_Value, Expressions => New_List ( Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Wide_Wide_String_To_String), Loc), Parameter_Associations => New_List ( Relocate_Node (First (Exprs)), Make_Integer_Literal (Loc, Intval => Int (Wide_Character_Encoding_Method))))))); Analyze_And_Resolve (N, Typ); --------------------- -- Wide_Wide_Width -- --------------------- -- Wide_Wide_Width attribute is handled in separate unit Exp_Imgv when Attribute_Wide_Wide_Width => Exp_Imgv.Expand_Width_Attribute (N, Wide_Wide); ---------------- -- Wide_Width -- ---------------- -- Wide_Width attribute is handled in separate unit Exp_Imgv when Attribute_Wide_Width => Exp_Imgv.Expand_Width_Attribute (N, Wide); ----------- -- Width -- ----------- -- Width attribute is handled in separate unit Exp_Imgv when Attribute_Width => Exp_Imgv.Expand_Width_Attribute (N, Normal); ----------- -- Write -- ----------- when Attribute_Write => Write : declare P_Type : constant Entity_Id := Entity (Pref); U_Type : constant Entity_Id := Underlying_Type (P_Type); Pname : Entity_Id; Decl : Node_Id; Prag : Node_Id; Arg3 : Node_Id; Wfunc : Node_Id; begin -- If no underlying type, we have an error that will be diagnosed -- elsewhere, so here we just completely ignore the expansion. if No (U_Type) then return; end if; -- Stream operations can appear in user code even if the restriction -- No_Streams is active (for example, when instantiating a predefined -- container). In that case rewrite the attribute as a Raise to -- prevent any run-time use. if Restriction_Active (No_Streams) then Rewrite (N, Make_Raise_Program_Error (Sloc (N), Reason => PE_Stream_Operation_Not_Allowed)); Set_Etype (N, U_Type); return; end if; -- The simple case, if there is a TSS for Write, just call it Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Write); if Present (Pname) then null; else -- If there is a Stream_Convert pragma, use it, we rewrite -- sourcetyp'Output (stream, Item) -- as -- strmtyp'Output (Stream, strmwrite (acttyp (Item))); -- where strmwrite is the given Write function that converts an -- argument of type sourcetyp or a type acctyp, from which it is -- derived to type strmtyp. The conversion to acttyp is required -- for the derived case. Prag := Get_Stream_Convert_Pragma (P_Type); if Present (Prag) then Arg3 := Next (Next (First (Pragma_Argument_Associations (Prag)))); Wfunc := Entity (Expression (Arg3)); Rewrite (N, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Etype (Wfunc), Loc), Attribute_Name => Name_Output, Expressions => New_List ( Relocate_Node (First (Exprs)), Make_Function_Call (Loc, Name => New_Occurrence_Of (Wfunc, Loc), Parameter_Associations => New_List ( OK_Convert_To (Etype (First_Formal (Wfunc)), Relocate_Node (Next (First (Exprs))))))))); Analyze (N); return; -- For elementary types, we call the W_xxx routine directly elsif Is_Elementary_Type (U_Type) then Rewrite (N, Build_Elementary_Write_Call (N)); Analyze (N); return; -- Array type case elsif Is_Array_Type (U_Type) then Build_Array_Write_Procedure (N, U_Type, Decl, Pname); Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False); -- Tagged type case, use the primitive Write function. Note that -- this will dispatch in the class-wide case which is what we want elsif Is_Tagged_Type (U_Type) then Pname := Find_Prim_Op (U_Type, TSS_Stream_Write); -- All other record type cases, including protected records. -- The latter only arise for expander generated code for -- handling shared passive partition access. else pragma Assert (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type)); -- Ada 2005 (AI-216): Program_Error is raised when executing -- the default implementation of the Write attribute of an -- Unchecked_Union type. However, if the 'Write reference is -- within the generated Output stream procedure, Write outputs -- the components, and the default values of the discriminant -- are streamed by the Output procedure itself. if Is_Unchecked_Union (Base_Type (U_Type)) and not Is_TSS (Current_Scope, TSS_Stream_Output) then Insert_Action (N, Make_Raise_Program_Error (Loc, Reason => PE_Unchecked_Union_Restriction)); end if; if Has_Discriminants (U_Type) and then Present (Discriminant_Default_Value (First_Discriminant (U_Type))) then Build_Mutable_Record_Write_Procedure (Loc, Full_Base (U_Type), Decl, Pname); else Build_Record_Write_Procedure (Loc, Full_Base (U_Type), Decl, Pname); end if; Insert_Action (N, Decl); end if; end if; -- If we fall through, Pname is the procedure to be called Rewrite_Stream_Proc_Call (Pname); end Write; -- Component_Size is handled by the back end, unless the component size -- is known at compile time, which is always true in the packed array -- case. It is important that the packed array case is handled in the -- front end (see Eval_Attribute) since the back end would otherwise get -- confused by the equivalent packed array type. when Attribute_Component_Size => null; -- The following attributes are handled by the back end (except that -- static cases have already been evaluated during semantic processing, -- but in any case the back end should not count on this). -- The back end also handles the non-class-wide cases of Size when Attribute_Bit_Order | Attribute_Code_Address | Attribute_Definite | Attribute_Deref | Attribute_Null_Parameter | Attribute_Passed_By_Reference | Attribute_Pool_Address | Attribute_Scalar_Storage_Order => null; -- The following attributes are also handled by the back end, but return -- a universal integer result, so may need a conversion for checking -- that the result is in range. when Attribute_Aft | Attribute_Max_Alignment_For_Allocation => Apply_Universal_Integer_Attribute_Checks (N); -- The following attributes should not appear at this stage, since they -- have already been handled by the analyzer (and properly rewritten -- with corresponding values or entities to represent the right values) when Attribute_Abort_Signal | Attribute_Address_Size | Attribute_Atomic_Always_Lock_Free | Attribute_Base | Attribute_Class | Attribute_Compiler_Version | Attribute_Default_Bit_Order | Attribute_Default_Scalar_Storage_Order | Attribute_Delta | Attribute_Denorm | Attribute_Digits | Attribute_Emax | Attribute_Enabled | Attribute_Epsilon | Attribute_Fast_Math | Attribute_First_Valid | Attribute_Has_Access_Values | Attribute_Has_Discriminants | Attribute_Has_Tagged_Values | Attribute_Large | Attribute_Last_Valid | Attribute_Library_Level | Attribute_Lock_Free | Attribute_Machine_Emax | Attribute_Machine_Emin | Attribute_Machine_Mantissa | Attribute_Machine_Overflows | Attribute_Machine_Radix | Attribute_Machine_Rounds | Attribute_Maximum_Alignment | Attribute_Model_Emin | Attribute_Model_Epsilon | Attribute_Model_Mantissa | Attribute_Model_Small | Attribute_Modulus | Attribute_Partition_ID | Attribute_Range | Attribute_Restriction_Set | Attribute_Safe_Emax | Attribute_Safe_First | Attribute_Safe_Large | Attribute_Safe_Last | Attribute_Safe_Small | Attribute_Scale | Attribute_Signed_Zeros | Attribute_Small | Attribute_Storage_Unit | Attribute_Stub_Type | Attribute_System_Allocator_Alignment | Attribute_Target_Name | Attribute_Type_Class | Attribute_Type_Key | Attribute_Unconstrained_Array | Attribute_Universal_Literal_String | Attribute_Wchar_T_Size | Attribute_Word_Size => raise Program_Error; -- The Asm_Input and Asm_Output attributes are not expanded at this -- stage, but will be eliminated in the expansion of the Asm call, see -- Exp_Intr for details. So the back end will never see these either. when Attribute_Asm_Input | Attribute_Asm_Output => null; end case; -- Note: as mentioned earlier, individual sections of the above case -- statement assume there is no code after the case statement, and are -- legitimately allowed to execute return statements if they have nothing -- more to do, so DO NOT add code at this point. exception when RE_Not_Available => return; end Expand_N_Attribute_Reference; -------------------------------- -- Expand_Pred_Succ_Attribute -- -------------------------------- -- For typ'Pred (exp), we generate the check -- [constraint_error when exp = typ'Base'First] -- Similarly, for typ'Succ (exp), we generate the check -- [constraint_error when exp = typ'Base'Last] -- These checks are not generated for modular types, since the proper -- semantics for Succ and Pred on modular types is to wrap, not raise CE. -- We also suppress these checks if we are the right side of an assignment -- statement or the expression of an object declaration, where the flag -- Suppress_Assignment_Checks is set for the assignment/declaration. procedure Expand_Pred_Succ_Attribute (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); P : constant Node_Id := Parent (N); Cnam : Name_Id; begin if Attribute_Name (N) = Name_Pred then Cnam := Name_First; else Cnam := Name_Last; end if; if not Nkind_In (P, N_Assignment_Statement, N_Object_Declaration) or else not Suppress_Assignment_Checks (P) then Insert_Action (N, Make_Raise_Constraint_Error (Loc, Condition => Make_Op_Eq (Loc, Left_Opnd => Duplicate_Subexpr_Move_Checks (First (Expressions (N))), Right_Opnd => Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Base_Type (Etype (Prefix (N))), Loc), Attribute_Name => Cnam)), Reason => CE_Overflow_Check_Failed)); end if; end Expand_Pred_Succ_Attribute; ----------------------------- -- Expand_Update_Attribute -- ----------------------------- procedure Expand_Update_Attribute (N : Node_Id) is procedure Process_Component_Or_Element_Update (Temp : Entity_Id; Comp : Node_Id; Expr : Node_Id; Typ : Entity_Id); -- Generate the statements necessary to update a single component or an -- element of the prefix. The code is inserted before the attribute N. -- Temp denotes the entity of the anonymous object created to reflect -- the changes in values. Comp is the component/index expression to be -- updated. Expr is an expression yielding the new value of Comp. Typ -- is the type of the prefix of attribute Update. procedure Process_Range_Update (Temp : Entity_Id; Comp : Node_Id; Expr : Node_Id; Typ : Entity_Id); -- Generate the statements necessary to update a slice of the prefix. -- The code is inserted before the attribute N. Temp denotes the entity -- of the anonymous object created to reflect the changes in values. -- Comp is range of the slice to be updated. Expr is an expression -- yielding the new value of Comp. Typ is the type of the prefix of -- attribute Update. ----------------------------------------- -- Process_Component_Or_Element_Update -- ----------------------------------------- procedure Process_Component_Or_Element_Update (Temp : Entity_Id; Comp : Node_Id; Expr : Node_Id; Typ : Entity_Id) is Loc : constant Source_Ptr := Sloc (Comp); Exprs : List_Id; LHS : Node_Id; begin -- An array element may be modified by the following relations -- depending on the number of dimensions: -- 1 => Expr -- one dimensional update -- (1, ..., N) => Expr -- multi dimensional update -- The above forms are converted in assignment statements where the -- left hand side is an indexed component: -- Temp (1) := Expr; -- one dimensional update -- Temp (1, ..., N) := Expr; -- multi dimensional update if Is_Array_Type (Typ) then -- The index expressions of a multi dimensional array update -- appear as an aggregate. if Nkind (Comp) = N_Aggregate then Exprs := New_Copy_List_Tree (Expressions (Comp)); else Exprs := New_List (Relocate_Node (Comp)); end if; LHS := Make_Indexed_Component (Loc, Prefix => New_Occurrence_Of (Temp, Loc), Expressions => Exprs); -- A record component update appears in the following form: -- Comp => Expr -- The above relation is transformed into an assignment statement -- where the left hand side is a selected component: -- Temp.Comp := Expr; else pragma Assert (Is_Record_Type (Typ)); LHS := Make_Selected_Component (Loc, Prefix => New_Occurrence_Of (Temp, Loc), Selector_Name => Relocate_Node (Comp)); end if; Insert_Action (N, Make_Assignment_Statement (Loc, Name => LHS, Expression => Relocate_Node (Expr))); end Process_Component_Or_Element_Update; -------------------------- -- Process_Range_Update -- -------------------------- procedure Process_Range_Update (Temp : Entity_Id; Comp : Node_Id; Expr : Node_Id; Typ : Entity_Id) is Index_Typ : constant Entity_Id := Etype (First_Index (Typ)); Loc : constant Source_Ptr := Sloc (Comp); Index : Entity_Id; begin -- A range update appears as -- (Low .. High => Expr) -- The above construct is transformed into a loop that iterates over -- the given range and modifies the corresponding array values to the -- value of Expr: -- for Index in Low .. High loop -- Temp (<Index_Typ> (Index)) := Expr; -- end loop; Index := Make_Temporary (Loc, 'I'); Insert_Action (N, Make_Loop_Statement (Loc, Iteration_Scheme => Make_Iteration_Scheme (Loc, Loop_Parameter_Specification => Make_Loop_Parameter_Specification (Loc, Defining_Identifier => Index, Discrete_Subtype_Definition => Relocate_Node (Comp))), Statements => New_List ( Make_Assignment_Statement (Loc, Name => Make_Indexed_Component (Loc, Prefix => New_Occurrence_Of (Temp, Loc), Expressions => New_List ( Convert_To (Index_Typ, New_Occurrence_Of (Index, Loc)))), Expression => Relocate_Node (Expr))), End_Label => Empty)); end Process_Range_Update; -- Local variables Aggr : constant Node_Id := First (Expressions (N)); Loc : constant Source_Ptr := Sloc (N); Pref : constant Node_Id := Prefix (N); Typ : constant Entity_Id := Etype (Pref); Assoc : Node_Id; Comp : Node_Id; CW_Temp : Entity_Id; CW_Typ : Entity_Id; Expr : Node_Id; Temp : Entity_Id; -- Start of processing for Expand_Update_Attribute begin -- Create the anonymous object to store the value of the prefix and -- capture subsequent changes in value. Temp := Make_Temporary (Loc, 'T', Pref); -- Preserve the tag of the prefix by offering a specific view of the -- class-wide version of the prefix. if Is_Tagged_Type (Typ) then -- Generate: -- CW_Temp : Typ'Class := Typ'Class (Pref); CW_Temp := Make_Temporary (Loc, 'T'); CW_Typ := Class_Wide_Type (Typ); Insert_Action (N, Make_Object_Declaration (Loc, Defining_Identifier => CW_Temp, Object_Definition => New_Occurrence_Of (CW_Typ, Loc), Expression => Convert_To (CW_Typ, Relocate_Node (Pref)))); -- Generate: -- Temp : Typ renames Typ (CW_Temp); Insert_Action (N, Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Temp, Subtype_Mark => New_Occurrence_Of (Typ, Loc), Name => Convert_To (Typ, New_Occurrence_Of (CW_Temp, Loc)))); -- Non-tagged case else -- Generate: -- Temp : Typ := Pref; Insert_Action (N, Make_Object_Declaration (Loc, Defining_Identifier => Temp, Object_Definition => New_Occurrence_Of (Typ, Loc), Expression => Relocate_Node (Pref))); end if; -- Process the update aggregate Assoc := First (Component_Associations (Aggr)); while Present (Assoc) loop Comp := First (Choices (Assoc)); Expr := Expression (Assoc); while Present (Comp) loop if Nkind (Comp) = N_Range then Process_Range_Update (Temp, Comp, Expr, Typ); else Process_Component_Or_Element_Update (Temp, Comp, Expr, Typ); end if; Next (Comp); end loop; Next (Assoc); end loop; -- The attribute is replaced by a reference to the anonymous object Rewrite (N, New_Occurrence_Of (Temp, Loc)); Analyze (N); end Expand_Update_Attribute; ------------------- -- Find_Fat_Info -- ------------------- procedure Find_Fat_Info (T : Entity_Id; Fat_Type : out Entity_Id; Fat_Pkg : out RE_Id) is Rtyp : constant Entity_Id := Root_Type (T); begin -- All we do is use the root type (historically this dealt with -- VAX-float .. to be cleaned up further later ???) Fat_Type := Rtyp; if Fat_Type = Standard_Short_Float then Fat_Pkg := RE_Attr_Short_Float; elsif Fat_Type = Standard_Float then Fat_Pkg := RE_Attr_Float; elsif Fat_Type = Standard_Long_Float then Fat_Pkg := RE_Attr_Long_Float; elsif Fat_Type = Standard_Long_Long_Float then Fat_Pkg := RE_Attr_Long_Long_Float; -- Universal real (which is its own root type) is treated as being -- equivalent to Standard.Long_Long_Float, since it is defined to -- have the same precision as the longest Float type. elsif Fat_Type = Universal_Real then Fat_Type := Standard_Long_Long_Float; Fat_Pkg := RE_Attr_Long_Long_Float; else raise Program_Error; end if; end Find_Fat_Info; ---------------------------- -- Find_Stream_Subprogram -- ---------------------------- function Find_Stream_Subprogram (Typ : Entity_Id; Nam : TSS_Name_Type) return Entity_Id is Base_Typ : constant Entity_Id := Base_Type (Typ); Ent : constant Entity_Id := TSS (Typ, Nam); function Is_Available (Entity : RE_Id) return Boolean; pragma Inline (Is_Available); -- Function to check whether the specified run-time call is available -- in the run time used. In the case of a configurable run time, it -- is normal that some subprograms are not there. -- -- I don't understand this routine at all, why is this not just a -- call to RTE_Available? And if for some reason we need a different -- routine with different semantics, why is not in Rtsfind ??? ------------------ -- Is_Available -- ------------------ function Is_Available (Entity : RE_Id) return Boolean is begin -- Assume that the unit will always be available when using a -- "normal" (not configurable) run time. return not Configurable_Run_Time_Mode or else RTE_Available (Entity); end Is_Available; -- Start of processing for Find_Stream_Subprogram begin if Present (Ent) then return Ent; end if; -- Stream attributes for strings are expanded into library calls. The -- following checks are disabled when the run-time is not available or -- when compiling predefined types due to bootstrap issues. As a result, -- the compiler will generate in-place stream routines for string types -- that appear in GNAT's library, but will generate calls via rtsfind -- to library routines for user code. -- Note: In the case of using a configurable run time, it is very likely -- that stream routines for string types are not present (they require -- file system support). In this case, the specific stream routines for -- strings are not used, relying on the regular stream mechanism -- instead. That is why we include the test Is_Available when dealing -- with these cases. if not Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit)) then -- Storage_Array as defined in package System.Storage_Elements if Is_RTE (Base_Typ, RE_Storage_Array) then -- Case of No_Stream_Optimizations restriction active if Restriction_Active (No_Stream_Optimizations) then if Nam = TSS_Stream_Input and then Is_Available (RE_Storage_Array_Input) then return RTE (RE_Storage_Array_Input); elsif Nam = TSS_Stream_Output and then Is_Available (RE_Storage_Array_Output) then return RTE (RE_Storage_Array_Output); elsif Nam = TSS_Stream_Read and then Is_Available (RE_Storage_Array_Read) then return RTE (RE_Storage_Array_Read); elsif Nam = TSS_Stream_Write and then Is_Available (RE_Storage_Array_Write) then return RTE (RE_Storage_Array_Write); elsif Nam /= TSS_Stream_Input and then Nam /= TSS_Stream_Output and then Nam /= TSS_Stream_Read and then Nam /= TSS_Stream_Write then raise Program_Error; end if; -- Restriction No_Stream_Optimizations is not set, so we can go -- ahead and optimize using the block IO forms of the routines. else if Nam = TSS_Stream_Input and then Is_Available (RE_Storage_Array_Input_Blk_IO) then return RTE (RE_Storage_Array_Input_Blk_IO); elsif Nam = TSS_Stream_Output and then Is_Available (RE_Storage_Array_Output_Blk_IO) then return RTE (RE_Storage_Array_Output_Blk_IO); elsif Nam = TSS_Stream_Read and then Is_Available (RE_Storage_Array_Read_Blk_IO) then return RTE (RE_Storage_Array_Read_Blk_IO); elsif Nam = TSS_Stream_Write and then Is_Available (RE_Storage_Array_Write_Blk_IO) then return RTE (RE_Storage_Array_Write_Blk_IO); elsif Nam /= TSS_Stream_Input and then Nam /= TSS_Stream_Output and then Nam /= TSS_Stream_Read and then Nam /= TSS_Stream_Write then raise Program_Error; end if; end if; -- Stream_Element_Array as defined in package Ada.Streams elsif Is_RTE (Base_Typ, RE_Stream_Element_Array) then -- Case of No_Stream_Optimizations restriction active if Restriction_Active (No_Stream_Optimizations) then if Nam = TSS_Stream_Input and then Is_Available (RE_Stream_Element_Array_Input) then return RTE (RE_Stream_Element_Array_Input); elsif Nam = TSS_Stream_Output and then Is_Available (RE_Stream_Element_Array_Output) then return RTE (RE_Stream_Element_Array_Output); elsif Nam = TSS_Stream_Read and then Is_Available (RE_Stream_Element_Array_Read) then return RTE (RE_Stream_Element_Array_Read); elsif Nam = TSS_Stream_Write and then Is_Available (RE_Stream_Element_Array_Write) then return RTE (RE_Stream_Element_Array_Write); elsif Nam /= TSS_Stream_Input and then Nam /= TSS_Stream_Output and then Nam /= TSS_Stream_Read and then Nam /= TSS_Stream_Write then raise Program_Error; end if; -- Restriction No_Stream_Optimizations is not set, so we can go -- ahead and optimize using the block IO forms of the routines. else if Nam = TSS_Stream_Input and then Is_Available (RE_Stream_Element_Array_Input_Blk_IO) then return RTE (RE_Stream_Element_Array_Input_Blk_IO); elsif Nam = TSS_Stream_Output and then Is_Available (RE_Stream_Element_Array_Output_Blk_IO) then return RTE (RE_Stream_Element_Array_Output_Blk_IO); elsif Nam = TSS_Stream_Read and then Is_Available (RE_Stream_Element_Array_Read_Blk_IO) then return RTE (RE_Stream_Element_Array_Read_Blk_IO); elsif Nam = TSS_Stream_Write and then Is_Available (RE_Stream_Element_Array_Write_Blk_IO) then return RTE (RE_Stream_Element_Array_Write_Blk_IO); elsif Nam /= TSS_Stream_Input and then Nam /= TSS_Stream_Output and then Nam /= TSS_Stream_Read and then Nam /= TSS_Stream_Write then raise Program_Error; end if; end if; -- String as defined in package Ada elsif Base_Typ = Standard_String then -- Case of No_Stream_Optimizations restriction active if Restriction_Active (No_Stream_Optimizations) then if Nam = TSS_Stream_Input and then Is_Available (RE_String_Input) then return RTE (RE_String_Input); elsif Nam = TSS_Stream_Output and then Is_Available (RE_String_Output) then return RTE (RE_String_Output); elsif Nam = TSS_Stream_Read and then Is_Available (RE_String_Read) then return RTE (RE_String_Read); elsif Nam = TSS_Stream_Write and then Is_Available (RE_String_Write) then return RTE (RE_String_Write); elsif Nam /= TSS_Stream_Input and then Nam /= TSS_Stream_Output and then Nam /= TSS_Stream_Read and then Nam /= TSS_Stream_Write then raise Program_Error; end if; -- Restriction No_Stream_Optimizations is not set, so we can go -- ahead and optimize using the block IO forms of the routines. else if Nam = TSS_Stream_Input and then Is_Available (RE_String_Input_Blk_IO) then return RTE (RE_String_Input_Blk_IO); elsif Nam = TSS_Stream_Output and then Is_Available (RE_String_Output_Blk_IO) then return RTE (RE_String_Output_Blk_IO); elsif Nam = TSS_Stream_Read and then Is_Available (RE_String_Read_Blk_IO) then return RTE (RE_String_Read_Blk_IO); elsif Nam = TSS_Stream_Write and then Is_Available (RE_String_Write_Blk_IO) then return RTE (RE_String_Write_Blk_IO); elsif Nam /= TSS_Stream_Input and then Nam /= TSS_Stream_Output and then Nam /= TSS_Stream_Read and then Nam /= TSS_Stream_Write then raise Program_Error; end if; end if; -- Wide_String as defined in package Ada elsif Base_Typ = Standard_Wide_String then -- Case of No_Stream_Optimizations restriction active if Restriction_Active (No_Stream_Optimizations) then if Nam = TSS_Stream_Input and then Is_Available (RE_Wide_String_Input) then return RTE (RE_Wide_String_Input); elsif Nam = TSS_Stream_Output and then Is_Available (RE_Wide_String_Output) then return RTE (RE_Wide_String_Output); elsif Nam = TSS_Stream_Read and then Is_Available (RE_Wide_String_Read) then return RTE (RE_Wide_String_Read); elsif Nam = TSS_Stream_Write and then Is_Available (RE_Wide_String_Write) then return RTE (RE_Wide_String_Write); elsif Nam /= TSS_Stream_Input and then Nam /= TSS_Stream_Output and then Nam /= TSS_Stream_Read and then Nam /= TSS_Stream_Write then raise Program_Error; end if; -- Restriction No_Stream_Optimizations is not set, so we can go -- ahead and optimize using the block IO forms of the routines. else if Nam = TSS_Stream_Input and then Is_Available (RE_Wide_String_Input_Blk_IO) then return RTE (RE_Wide_String_Input_Blk_IO); elsif Nam = TSS_Stream_Output and then Is_Available (RE_Wide_String_Output_Blk_IO) then return RTE (RE_Wide_String_Output_Blk_IO); elsif Nam = TSS_Stream_Read and then Is_Available (RE_Wide_String_Read_Blk_IO) then return RTE (RE_Wide_String_Read_Blk_IO); elsif Nam = TSS_Stream_Write and then Is_Available (RE_Wide_String_Write_Blk_IO) then return RTE (RE_Wide_String_Write_Blk_IO); elsif Nam /= TSS_Stream_Input and then Nam /= TSS_Stream_Output and then Nam /= TSS_Stream_Read and then Nam /= TSS_Stream_Write then raise Program_Error; end if; end if; -- Wide_Wide_String as defined in package Ada elsif Base_Typ = Standard_Wide_Wide_String then -- Case of No_Stream_Optimizations restriction active if Restriction_Active (No_Stream_Optimizations) then if Nam = TSS_Stream_Input and then Is_Available (RE_Wide_Wide_String_Input) then return RTE (RE_Wide_Wide_String_Input); elsif Nam = TSS_Stream_Output and then Is_Available (RE_Wide_Wide_String_Output) then return RTE (RE_Wide_Wide_String_Output); elsif Nam = TSS_Stream_Read and then Is_Available (RE_Wide_Wide_String_Read) then return RTE (RE_Wide_Wide_String_Read); elsif Nam = TSS_Stream_Write and then Is_Available (RE_Wide_Wide_String_Write) then return RTE (RE_Wide_Wide_String_Write); elsif Nam /= TSS_Stream_Input and then Nam /= TSS_Stream_Output and then Nam /= TSS_Stream_Read and then Nam /= TSS_Stream_Write then raise Program_Error; end if; -- Restriction No_Stream_Optimizations is not set, so we can go -- ahead and optimize using the block IO forms of the routines. else if Nam = TSS_Stream_Input and then Is_Available (RE_Wide_Wide_String_Input_Blk_IO) then return RTE (RE_Wide_Wide_String_Input_Blk_IO); elsif Nam = TSS_Stream_Output and then Is_Available (RE_Wide_Wide_String_Output_Blk_IO) then return RTE (RE_Wide_Wide_String_Output_Blk_IO); elsif Nam = TSS_Stream_Read and then Is_Available (RE_Wide_Wide_String_Read_Blk_IO) then return RTE (RE_Wide_Wide_String_Read_Blk_IO); elsif Nam = TSS_Stream_Write and then Is_Available (RE_Wide_Wide_String_Write_Blk_IO) then return RTE (RE_Wide_Wide_String_Write_Blk_IO); elsif Nam /= TSS_Stream_Input and then Nam /= TSS_Stream_Output and then Nam /= TSS_Stream_Read and then Nam /= TSS_Stream_Write then raise Program_Error; end if; end if; end if; end if; if Is_Tagged_Type (Typ) and then Is_Derived_Type (Typ) then return Find_Prim_Op (Typ, Nam); else return Find_Inherited_TSS (Typ, Nam); end if; end Find_Stream_Subprogram; --------------- -- Full_Base -- --------------- function Full_Base (T : Entity_Id) return Entity_Id is BT : Entity_Id; begin BT := Base_Type (T); if Is_Private_Type (BT) and then Present (Full_View (BT)) then BT := Full_View (BT); end if; return BT; end Full_Base; ----------------------- -- Get_Index_Subtype -- ----------------------- function Get_Index_Subtype (N : Node_Id) return Node_Id is P_Type : Entity_Id := Etype (Prefix (N)); Indx : Node_Id; J : Int; begin if Is_Access_Type (P_Type) then P_Type := Designated_Type (P_Type); end if; if No (Expressions (N)) then J := 1; else J := UI_To_Int (Expr_Value (First (Expressions (N)))); end if; Indx := First_Index (P_Type); while J > 1 loop Next_Index (Indx); J := J - 1; end loop; return Etype (Indx); end Get_Index_Subtype; ------------------------------- -- Get_Stream_Convert_Pragma -- ------------------------------- function Get_Stream_Convert_Pragma (T : Entity_Id) return Node_Id is Typ : Entity_Id; N : Node_Id; begin -- Note: we cannot use Get_Rep_Pragma here because of the peculiarity -- that a stream convert pragma for a tagged type is not inherited from -- its parent. Probably what is wrong here is that it is basically -- incorrect to consider a stream convert pragma to be a representation -- pragma at all ??? N := First_Rep_Item (Implementation_Base_Type (T)); while Present (N) loop if Nkind (N) = N_Pragma and then Pragma_Name (N) = Name_Stream_Convert then -- For tagged types this pragma is not inherited, so we -- must verify that it is defined for the given type and -- not an ancestor. Typ := Entity (Expression (First (Pragma_Argument_Associations (N)))); if not Is_Tagged_Type (T) or else T = Typ or else (Is_Private_Type (Typ) and then T = Full_View (Typ)) then return N; end if; end if; Next_Rep_Item (N); end loop; return Empty; end Get_Stream_Convert_Pragma; --------------------------------- -- Is_Constrained_Packed_Array -- --------------------------------- function Is_Constrained_Packed_Array (Typ : Entity_Id) return Boolean is Arr : Entity_Id := Typ; begin if Is_Access_Type (Arr) then Arr := Designated_Type (Arr); end if; return Is_Array_Type (Arr) and then Is_Constrained (Arr) and then Present (Packed_Array_Impl_Type (Arr)); end Is_Constrained_Packed_Array; ---------------------------------------- -- Is_Inline_Floating_Point_Attribute -- ---------------------------------------- function Is_Inline_Floating_Point_Attribute (N : Node_Id) return Boolean is Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (N)); function Is_GCC_Target return Boolean; -- Return True if we are using a GCC target/back-end -- ??? Note: the implementation is kludgy/fragile ------------------- -- Is_GCC_Target -- ------------------- function Is_GCC_Target return Boolean is begin return not CodePeer_Mode and then not AAMP_On_Target and then not Modify_Tree_For_C; end Is_GCC_Target; -- Start of processing for Is_Inline_Floating_Point_Attribute begin -- Machine and Model can be expanded by the GCC and AAMP back ends only if Id = Attribute_Machine or else Id = Attribute_Model then return Is_GCC_Target or else AAMP_On_Target; -- Remaining cases handled by all back ends are Rounding and Truncation -- when appearing as the operand of a conversion to some integer type. elsif Nkind (Parent (N)) /= N_Type_Conversion or else not Is_Integer_Type (Etype (Parent (N))) then return False; end if; -- Here we are in the integer conversion context -- Very probably we should also recognize the cases of Machine_Rounding -- and unbiased rounding in this conversion context, but the back end is -- not yet prepared to handle these cases ??? return Id = Attribute_Rounding or else Id = Attribute_Truncation; end Is_Inline_Floating_Point_Attribute; end Exp_Attr;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- XML Processor -- -- -- -- Testsuite Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2010-2014, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Ada.Command_Line; with Ada.Characters.Conversions; with Ada.Directories; with Ada.Integer_Text_IO; with Ada.Text_IO; with League.Application; with League.Strings; with XML.SAX.File_Input_Sources; with XML.SAX.Simple_Readers; with XMLConf.Testsuite_Handlers; procedure XMLConf_Test is use XMLConf; use Ada.Integer_Text_IO; use Ada.Text_IO; type Percent is delta 0.01 range 0.00 .. 100.00; Data : constant League.Strings.Universal_String := League.Application.Arguments.Element (1); Source : aliased XML.SAX.File_Input_Sources.File_Input_Source; Reader : aliased XML.SAX.Simple_Readers.Simple_Reader; Handler : aliased XMLConf.Testsuite_Handlers.Testsuite_Handler; Enabled : Test_Flags := (others => True); Validating : Boolean := False; Passed : Natural; Failed : Natural; Suppressed : Natural; begin if Ada.Command_Line.Argument_Count > 1 then Enabled := (others => False); for J in 2 .. Ada.Command_Line.Argument_Count loop if Ada.Command_Line.Argument (J) = "--valid" then Enabled (Valid) := True; elsif Ada.Command_Line.Argument (J) = "--invalid" then Enabled (Invalid) := True; elsif Ada.Command_Line.Argument (J) = "--not-wellformed" then Enabled (Not_Wellformed) := True; elsif Ada.Command_Line.Argument (J) = "--error" then Enabled (Error) := True; elsif Ada.Command_Line.Argument (J) = "--validating" then Validating := True; else raise Program_Error; end if; end loop; end if; -- Load set of suppressed tests. Handler.Read_Suppressed (Ada.Directories.Containing_Directory (Ada.Directories.Containing_Directory (Ada.Characters.Conversions.To_String (Data.To_Wide_Wide_String))) & "/suppressed.lst"); -- Because of limitations of current implementation in tracking relative -- paths for entities the current working directory is changed to the -- containing directory of the testsuite description file. Reader.Set_Content_Handler (Handler'Unchecked_Access); Reader.Set_Error_Handler (Handler'Unchecked_Access); Source.Open_By_File_Name (Data); Handler.Enabled := Enabled; Handler.Validating := Validating; Reader.Parse (Source'Access); Passed := Handler.Results (Valid).Passed + Handler.Results (Invalid).Passed + Handler.Results (Not_Wellformed).Passed + Handler.Results (Error).Passed; Failed := Handler.Results (Valid).Failed + Handler.Results (Invalid).Failed + Handler.Results (Not_Wellformed).Failed + Handler.Results (Error).Failed; Suppressed := Handler.Results (Valid).Suppressed + Handler.Results (Invalid).Suppressed + Handler.Results (Not_Wellformed).Suppressed + Handler.Results (Error).Suppressed; if Failed = 0 then return; end if; Put_Line (" Group Passed Failed Skiped | Crash Output SAX"); Put_Line ("------- ------ ------ ------ | ------ ------ ------"); if Enabled (Valid) then Put ("valid "); Put (Handler.Results (Valid).Passed, 7); Put (Handler.Results (Valid).Failed, 7); Put (Handler.Results (Valid).Suppressed, 7); Put (" |"); Put (Handler.Results (Valid).Crash, 7); Put (Handler.Results (Valid).Output, 7); Put (Handler.Results (Valid).SAX, 7); New_Line; end if; if Enabled (Invalid) then Put ("invalid"); Put (Handler.Results (Invalid).Passed, 7); Put (Handler.Results (Invalid).Failed, 7); Put (Handler.Results (Invalid).Suppressed, 7); Put (" |"); Put (Handler.Results (Invalid).Crash, 7); Put (Handler.Results (Invalid).Output, 7); Put (Handler.Results (Invalid).SAX, 7); New_Line; end if; if Enabled (Not_Wellformed) then Put ("not-wf "); Put (Handler.Results (Not_Wellformed).Passed, 7); Put (Handler.Results (Not_Wellformed).Failed, 7); Put (Handler.Results (Not_Wellformed).Suppressed, 7); Put (" |"); Put (Handler.Results (Not_Wellformed).Crash, 7); Put (Handler.Results (Not_Wellformed).Output, 7); Put (Handler.Results (Not_Wellformed).SAX, 7); New_Line; end if; if Enabled (Error) then Put ("error "); Put (Handler.Results (Error).Passed, 7); Put (Handler.Results (Error).Failed, 7); Put (Handler.Results (Error).Suppressed, 7); Put (" |"); Put (Handler.Results (Error).Crash, 7); Put (Handler.Results (Error).Output, 7); Put (Handler.Results (Error).SAX, 7); New_Line; end if; Put_Line (" ------ ------ ------ | ------ ------ ------"); Put (" "); Put (Handler.Results (Valid).Passed + Handler.Results (Invalid).Passed + Handler.Results (Not_Wellformed).Passed + Handler.Results (Error).Passed, 7); Put (Handler.Results (Valid).Failed + Handler.Results (Invalid).Failed + Handler.Results (Not_Wellformed).Failed + Handler.Results (Error).Failed, 7); Put (Handler.Results (Valid).Suppressed + Handler.Results (Invalid).Suppressed + Handler.Results (Not_Wellformed).Suppressed + Handler.Results (Error).Suppressed, 7); Put (" |"); Put (Handler.Results (Valid).Crash + Handler.Results (Invalid).Crash + Handler.Results (Not_Wellformed).Crash + Handler.Results (Error).Crash, 7); Put (Handler.Results (Valid).Output + Handler.Results (Invalid).Output + Handler.Results (Not_Wellformed).Output + Handler.Results (Error).Output, 7); Put (Handler.Results (Valid).SAX + Handler.Results (Invalid).SAX + Handler.Results (Not_Wellformed).SAX + Handler.Results (Error).SAX, 7); New_Line; New_Line; Put_Line ("Status:" & Percent'Image (Percent (Float (Passed) / Float (Passed + Failed + Suppressed) * 100.0)) & "% passed"); if Handler.Results (Valid).Crash /= 0 or Handler.Results (Invalid).Crash /= 0 or Handler.Results (Not_Wellformed).Crash /= 0 or Handler.Results (Error).Crash /= 0 then raise Program_Error; end if; end XMLConf_Test;
------------------------------------------------------------------------------ -- Copyright (c) 2014, 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. -- ------------------------------------------------------------------------------ with Ada.Calendar.Arithmetic; package body Natools.Time_IO.Human is --------------------- -- Duration Images -- --------------------- function Difference_Image (Left, Right : Ada.Calendar.Time; Use_Weeks : Boolean := False) return String is use type Ada.Calendar.Arithmetic.Day_Count; Days, Rounded_Days : Ada.Calendar.Arithmetic.Day_Count; Seconds : Duration; Leap_Seconds : Ada.Calendar.Arithmetic.Leap_Seconds_Count; begin if Ada.Calendar."<" (Left, Right) then return '-' & Difference_Image (Left => Right, Right => Left, Use_Weeks => Use_Weeks); end if; Ada.Calendar.Arithmetic.Difference (Left, Right, Days, Seconds, Leap_Seconds); Seconds := Seconds - 86400.0 + Duration (Leap_Seconds); if Seconds >= 0.0 then Days := Days + 1; else Seconds := Seconds + 86400.0; end if; if Seconds >= 43200.0 then Rounded_Days := Days + 1; else Rounded_Days := Days; end if; if Use_Weeks and then Rounded_Days >= 7 then declare Weeks : constant Ada.Calendar.Arithmetic.Day_Count := Rounded_Days / 7; begin Rounded_Days := Rounded_Days - Weeks * 7; if Weeks >= 10 or Rounded_Days = 0 then return Trim_Image (Ada.Calendar.Arithmetic.Day_Count'Image (Weeks)) & 'w'; else return Trim_Image (Ada.Calendar.Arithmetic.Day_Count'Image (Weeks)) & 'w' & Ada.Calendar.Arithmetic.Day_Count'Image (Rounded_Days) & 'd'; end if; end; elsif Rounded_Days >= 10 then return Trim_Image (Ada.Calendar.Arithmetic.Day_Count'Image (Rounded_Days)) & 'd'; elsif Days > 0 then declare Hours : constant Natural := Natural (Seconds / 3600); begin case Hours is when 0 => return Trim_Image (Ada.Calendar.Arithmetic.Day_Count'Image (Days)) & 'd'; when 1 .. 23 => return Trim_Image (Ada.Calendar.Arithmetic.Day_Count'Image (Days)) & 'd' & Natural'Image (Hours) & 'h'; when 24 => return Trim_Image (Ada.Calendar.Arithmetic.Day_Count'Image (Days + 1)) & 'd'; when others => raise Program_Error; end case; end; else return Image (Seconds); end if; end Difference_Image; function Image (Value : Duration) return String is function Local_Image (Mul_1, Div : Positive; Unit_1 : String; Mul_2 : Positive; Unit_2 : String) return String; function Scientific_Image (Mul : Positive; Unit : String) return String; function Local_Image (Mul_1, Div : Positive; Unit_1 : String; Mul_2 : Positive; Unit_2 : String) return String is Scaled : constant Duration := Value * Mul_1 / Div; Main : constant Natural := Natural (Scaled - 0.5); Secondary : constant Natural := Natural ((Scaled - Duration (Main)) * Mul_2); begin pragma Assert (Secondary <= Mul_2); if Secondary = Mul_2 then return Trim_Image (Natural'Image (Main + 1)) & Unit_1; elsif Secondary = 0 then return Trim_Image (Natural'Image (Main)) & Unit_1; else return Trim_Image (Natural'Image (Main)) & Unit_1 & Natural'Image (Secondary) & Unit_2; end if; end Local_Image; function Scientific_Image (Mul : Positive; Unit : String) return String is Scaled : constant Duration := Value * Mul; I_Part : constant Natural := Natural (Scaled - 0.5); F_Part : constant Natural := Natural ((Scaled - Duration (I_Part)) * 1000); begin if F_Part = 0 then return Trim_Image (Natural'Image (I_Part)) & Unit; elsif F_Part = 1000 then return Trim_Image (Natural'Image (I_Part + 1)) & Unit; else return Trim_Image (Natural'Image (I_Part)) & ('.', Image (F_Part / 100), Image ((F_Part / 10) mod 10), Image (F_Part mod 10)) & Unit; end if; end Scientific_Image; begin if Value < 0.0 then return '-' & Image (-Value); elsif Value = 0.0 then return "0s"; elsif Value >= 86400.0 - 1800.0 then return Local_Image (1, 86400, "d", 24, "h"); elsif Value >= 36000.0 then return Trim_Image (Positive'Image (Positive (Value / 3600))) & 'h'; elsif Value >= 3600.0 - 30.0 then return Local_Image (1, 3600, "h", 60, "m"); elsif Value >= 600.0 then return Trim_Image (Positive'Image (Positive (Value / 60))) & " min"; elsif Value >= 60.0 - 0.5 then return Local_Image (1, 60, " min", 60, "s"); elsif Value >= 10.0 then return Trim_Image (Positive'Image (Positive (Value))) & 's'; elsif Value >= 1.0 then return Scientific_Image (1, " s"); elsif Value >= 0.01 then return Trim_Image (Positive'Image (Positive (Value * 1000))) & " ms"; elsif Value >= 0.001 then return Scientific_Image (1_000, " ms"); elsif Value >= 0.000_01 then return Trim_Image (Positive'Image (Positive (Value * 1_000_000))) & " us"; elsif Value >= 0.000_001 then return Scientific_Image (1_000_000, " us"); else return Scientific_Image (1_000_000_000, " ns"); end if; end Image; end Natools.Time_IO.Human;
-- RUN: %llvmgcc -S -emit-llvm %s -o - | not grep ptrtoint package Constant_Fold is Error : exception; end;
------------------------------------------------------------------------------ -- -- -- 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. -- -- -- ------------------------------------------------------------------------------ with STM32.DCMI; with STM32.DMA; use STM32.DMA; with Ada.Real_Time; use Ada.Real_Time; with OV2640; use OV2640; with OV7725; use OV7725; with HAL.I2C; use HAL.I2C; with HAL.Bitmap; use HAL.Bitmap; with HAL; use HAL; with STM32.PWM; use STM32.PWM; with STM32.Setup; package body OpenMV.Sensor is package DCMI renames STM32.DCMI; function Probe (Cam_Addr : out UInt10) return Boolean; REG_PID : constant := 16#0A#; -- REG_VER : constant := 16#0B#; CLK_PWM_Mod : PWM_Modulator; Camera_PID : HAL.UInt8 := 0; Camera_2640 : OV2640_Camera (Sensor_I2C'Access); Camera_7725 : OV7725_Camera (Sensor_I2C'Access); Is_Initialized : Boolean := False; ----------------- -- Initialized -- ----------------- function Initialized return Boolean is (Is_Initialized); ----------- -- Probe -- ----------- function Probe (Cam_Addr : out UInt10) return Boolean is Status : I2C_Status; begin for Addr in UInt10 range 0 .. 126 loop Sensor_I2C.Master_Transmit (Addr => Addr, Data => (0 => 0), Status => Status, Timeout => 10_000); if Status = Ok then Cam_Addr := Addr; return True; end if; delay until Clock + Milliseconds (1); end loop; return False; end Probe; ---------------- -- Initialize -- ---------------- procedure Initialize is procedure Initialize_Clock; procedure Initialize_Camera; procedure Initialize_IO; procedure Initialize_DCMI; procedure Initialize_DMA; ---------------------- -- Initialize_Clock -- ---------------------- procedure Initialize_Clock is begin Configure_PWM_Timer (SENSOR_CLK_TIM'Access, SENSOR_CLK_FREQ); CLK_PWM_Mod.Attach_PWM_Channel (Generator => SENSOR_CLK_TIM'Access, Channel => SENSOR_CLK_CHAN, Point => SENSOR_CLK_IO, PWM_AF => SENSOR_CLK_AF); CLK_PWM_Mod.Set_Duty_Cycle (Value => 50); CLK_PWM_Mod.Enable_Output; end Initialize_Clock; ----------------------- -- Initialize_Camera -- ----------------------- procedure Initialize_Camera is Cam_Addr : UInt10; Data : I2C_Data (1 .. 1); Status : I2C_Status; begin -- Power cycle Set (DCMI_PWDN); delay until Clock + Milliseconds (10); Clear (DCMI_PWDN); delay until Clock + Milliseconds (10); Initialize_Clock; Set (DCMI_RST); delay until Clock + Milliseconds (10); Clear (DCMI_RST); delay until Clock + Milliseconds (10); if not Probe (Cam_Addr) then -- Retry with reversed reset polarity Set (DCMI_RST); delay until Clock + Milliseconds (10); if not Probe (Cam_Addr) then raise Program_Error; end if; end if; delay until Clock + Milliseconds (10); -- Select sensor bank Sensor_I2C.Mem_Write (Addr => Cam_Addr, Mem_Addr => 16#FF#, Mem_Addr_Size => Memory_Size_8b, Data => (0 => 1), Status => Status); if Status /= Ok then raise Program_Error; end if; delay until Clock + Milliseconds (10); Sensor_I2C.Master_Transmit (Addr => Cam_Addr, Data => (1 => REG_PID), Status => Status); if Status /= Ok then raise Program_Error; end if; Sensor_I2C.Master_Receive (Addr => Cam_Addr, Data => Data, Status => Status); if Status /= Ok then raise Program_Error; end if; if Status /= Ok then raise Program_Error; end if; Camera_PID := Data (Data'First); case Camera_PID is when OV2640_PID => Initialize (Camera_2640, Cam_Addr); Set_Pixel_Format (Camera_2640, Pix_RGB565); Set_Frame_Size (Camera_2640, QQVGA2); when OV7725_PID => Initialize (Camera_7725, Cam_Addr); Set_Pixel_Format (Camera_7725, Pix_RGB565); Set_Frame_Size (Camera_7725, QQVGA2); when others => raise Program_Error with "Unknown camera module"; end case; end Initialize_Camera; ------------------- -- Initialize_IO -- ------------------- procedure Initialize_IO is GPIO_Conf : GPIO_Port_Configuration; DCMI_AF_Points : constant GPIO_Points := GPIO_Points'(DCMI_D0, DCMI_D1, DCMI_D2, DCMI_D3, DCMI_D4, DCMI_D5, DCMI_D6, DCMI_D7, DCMI_VSYNC, DCMI_HSYNC, DCMI_PCLK); DCMI_Out_Points : GPIO_Points := GPIO_Points'(DCMI_PWDN, DCMI_RST, FS_IN); begin STM32.Setup.Setup_I2C_Master (Port => Sensor_I2C, SDA => Sensor_I2C_SDA, SCL => Sensor_I2C_SCL, SDA_AF => Sensor_I2C_AF, SCL_AF => Sensor_I2C_AF, Clock_Speed => 100_000); Enable_Clock (DCMI_Out_Points); -- Sensor PowerDown, Reset and FSIN GPIO_Conf.Mode := Mode_Out; GPIO_Conf.Output_Type := Push_Pull; GPIO_Conf.Resistors := Pull_Down; Configure_IO (DCMI_Out_Points, GPIO_Conf); Clear (DCMI_Out_Points); GPIO_Conf.Mode := Mode_AF; GPIO_Conf.Output_Type := Push_Pull; GPIO_Conf.Resistors := Pull_Down; Configure_IO (DCMI_AF_Points, GPIO_Conf); Configure_Alternate_Function (DCMI_AF_Points, GPIO_AF_DCMI_13); end Initialize_IO; --------------------- -- Initialize_DCMI -- --------------------- procedure Initialize_DCMI is Vertical : DCMI.DCMI_Polarity; Horizontal : DCMI.DCMI_Polarity; Pixel_Clock : DCMI.DCMI_Polarity; begin case Camera_PID is when OV2640_PID => Vertical := DCMI.Active_Low; Horizontal := DCMI.Active_Low; Pixel_Clock := DCMI.Active_High; when OV7725_PID => Vertical := DCMI.Active_High; Horizontal := DCMI.Active_Low; Pixel_Clock := DCMI.Active_High; when others => raise Program_Error with "Unknown camera module"; end case; Enable_DCMI_Clock; DCMI.Configure (Data_Mode => DCMI.DCMI_8bit, Capture_Rate => DCMI.Capture_All, Vertical_Polarity => Vertical, Horizontal_Polarity => Horizontal, Pixel_Clock_Polarity => Pixel_Clock, Hardware_Sync => True, JPEG => False); DCMI.Disable_Crop; DCMI.Enable_DCMI; end Initialize_DCMI; -------------------- -- Initialize_DMA -- -------------------- procedure Initialize_DMA is Config : DMA_Stream_Configuration; begin Enable_Clock (Sensor_DMA); Config.Channel := Sensor_DMA_Chan; Config.Direction := Peripheral_To_Memory; Config.Increment_Peripheral_Address := False; Config.Increment_Memory_Address := True; Config.Peripheral_Data_Format := Words; Config.Memory_Data_Format := Words; Config.Operation_Mode := Normal_Mode; Config.Priority := Priority_High; Config.FIFO_Enabled := True; Config.FIFO_Threshold := FIFO_Threshold_Full_Configuration; Config.Memory_Burst_Size := Memory_Burst_Inc4; Config.Peripheral_Burst_Size := Peripheral_Burst_Single; Configure (Sensor_DMA, Sensor_DMA_Stream, Config); end Initialize_DMA; begin Initialize_IO; Initialize_Camera; Initialize_DCMI; Initialize_DMA; Is_Initialized := True; end Initialize; -------------- -- Snapshot -- -------------- procedure Snapshot (BM : not null HAL.Bitmap.Any_Bitmap_Buffer) is Status : DMA_Error_Code; Cnt : constant UInt16 := UInt16 ((BM.Width * BM.Height) / 2); begin if BM.Width /= Image_Width or else BM.Height /= Image_Height or else not BM.Mapped_In_RAM then raise Program_Error; end if; if not Compatible_Alignments (Sensor_DMA, Sensor_DMA_Stream, DCMI.Data_Register_Address, BM.Memory_Address) then raise Program_Error; end if; Clear_All_Status (Sensor_DMA, Sensor_DMA_Stream); Start_Transfer (This => Sensor_DMA, Stream => Sensor_DMA_Stream, Source => DCMI.Data_Register_Address, Destination => BM.Memory_Address, Data_Count => Cnt); DCMI.Start_Capture (DCMI.Snapshot); Poll_For_Completion (Sensor_DMA, Sensor_DMA_Stream, Full_Transfer, Milliseconds (100), Status); if Status /= DMA_No_Error then if Status = DMA_Timeout_Error then raise Program_Error with "DMA timeout! Transferred: " & Items_Transferred (Sensor_DMA, Sensor_DMA_Stream)'Img; else raise Program_Error; end if; end if; end Snapshot; end OpenMV.Sensor;
-- CD2D11A.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- OBJECTIVE: -- CHECK THAT IF A SMALL SPECIFICATION IS GIVEN FOR A -- FIXED POINT TYPE, THEN ARITHMETIC OPERATIONS ON VALUES OF THE -- TYPE ARE NOT AFFECTED BY THE REPRESENTATION CLAUSE. -- HISTORY: -- BCB 09/01/87 CREATED ORIGINAL TEST. -- PWB 05/11/89 CHANGED EXTENSION FROM '.DEP' TO '.ADA'. WITH REPORT; USE REPORT; PROCEDURE CD2D11A IS BASIC_SMALL : CONSTANT := 2.0 ** (-4); TYPE BASIC_TYPE IS DELTA 2.0 ** (-4) RANGE -4.0 .. 4.0; TYPE CHECK_TYPE IS DELTA 1.0 RANGE -4.0 .. 4.0; FOR CHECK_TYPE'SMALL USE BASIC_SMALL; CNEG1 : CHECK_TYPE := -3.5; CNEG2 : CHECK_TYPE := CHECK_TYPE (-1.0/3.0); CPOS1 : CHECK_TYPE := CHECK_TYPE (4.0/6.0); CPOS2 : CHECK_TYPE := 3.5; CZERO : CHECK_TYPE; TYPE ARRAY_TYPE IS ARRAY (0 .. 3) OF CHECK_TYPE; CHARRAY : ARRAY_TYPE := (-3.5, CHECK_TYPE (-1.0/3.0), CHECK_TYPE (4.0/6.0), 3.5); TYPE REC_TYPE IS RECORD COMPN1 : CHECK_TYPE := -3.5; COMPN2 : CHECK_TYPE := CHECK_TYPE (-1.0/3.0); COMPP1 : CHECK_TYPE := CHECK_TYPE (4.0/6.0); COMPP2 : CHECK_TYPE := 3.5; END RECORD; CHREC : REC_TYPE; FUNCTION IDENT (FX : CHECK_TYPE) RETURN CHECK_TYPE IS BEGIN IF EQUAL (3, 3) THEN RETURN FX; ELSE RETURN 0.0; END IF; END IDENT; PROCEDURE PROC (N1_IN, P1_IN : CHECK_TYPE; N2_INOUT,P2_INOUT : IN OUT CHECK_TYPE; CZOUT : OUT CHECK_TYPE) IS BEGIN IF IDENT (N1_IN) + P1_IN NOT IN -2.875 .. -2.8125 OR P2_INOUT - IDENT (P1_IN) NOT IN 2.8125 .. 2.875 THEN FAILED ("INCORRECT RESULTS FOR " & "BINARY ADDING OPERATORS - 1"); END IF; IF +IDENT (N2_INOUT) NOT IN -0.375 .. -0.3125 OR IDENT (-P1_IN) NOT IN -0.6875 .. -0.625 THEN FAILED ("INCORRECT RESULTS FOR " & "UNARY ADDING OPERATORS - 1"); END IF; IF CHECK_TYPE (N1_IN * IDENT (P1_IN)) NOT IN -2.4375 .. -2.1875 OR CHECK_TYPE (IDENT (N2_INOUT) / P2_INOUT) NOT IN -0.125 .. -0.0625 THEN FAILED ("INCORRECT RESULTS FOR " & "MULTIPLYING OPERATORS - 1"); END IF; IF ABS IDENT (N2_INOUT) NOT IN 0.3125 .. 0.375 OR IDENT (ABS P1_IN) NOT IN 0.625 .. 0.6875 THEN FAILED ("INCORRECT RESULTS FOR " & "ABSOLUTE VALUE OPERATORS - 1"); END IF; CZOUT := 0.0; END PROC; BEGIN TEST ("CD2D11A", "CHECK THAT IF A SMALL SPECIFICATION IS " & "GIVEN FOR AN FIXED POINT TYPE, THEN " & "ARITHMETIC OPERATIONS ON VALUES OF THE " & "TYPE ARE NOT AFFECTED BY THE REPRESENTATION " & "CLAUSE"); PROC (CNEG1, CPOS1, CNEG2, CPOS2, CZERO); IF IDENT (CZERO) /= 0.0 THEN FAILED ("INCORRECT VALUE FOR OUT PARAMETER"); END IF; IF IDENT (CNEG1) + CPOS1 NOT IN -2.875 .. -2.8125 OR CPOS2 - IDENT (CPOS1) NOT IN 2.8125 .. 2.875 THEN FAILED ("INCORRECT RESULTS FOR BINARY ADDING OPERATORS - 2"); END IF; IF +IDENT (CNEG2) NOT IN -0.375 .. -0.3125 OR IDENT (-CPOS1) NOT IN -0.6875 .. -0.625 THEN FAILED ("INCORRECT RESULTS FOR UNARY ADDING OPERATORS - 2"); END IF; IF CHECK_TYPE (CNEG1 * IDENT (CPOS1)) NOT IN -2.4375 .. -2.1875 OR CHECK_TYPE (IDENT (CNEG2) / CPOS2) NOT IN -0.125 .. -0.0625 THEN FAILED ("INCORRECT RESULTS FOR MULTIPLYING OPERATORS - 2"); END IF; IF ABS IDENT (CNEG2) NOT IN 0.3125 .. 0.375 OR IDENT (ABS CPOS1) NOT IN 0.625 .. 0.6875 THEN FAILED ("INCORRECT RESULTS FOR ABSOLUTE VALUE " & "OPERATORS - 2"); END IF; IF IDENT (CPOS1) NOT IN 0.625 .. 0.6875 OR CNEG2 IN -0.25 .. 0.0 OR IDENT (CNEG2) IN -1.0 .. -0.4375 THEN FAILED ("INCORRECT RESULTS FOR MEMBERSHIP OPERATORS - 2"); END IF; IF IDENT (CHARRAY (0)) + CHARRAY (2) NOT IN -2.875 .. -2.8125 OR CHARRAY (3) - IDENT (CHARRAY (2)) NOT IN 2.8125 .. 2.875 THEN FAILED ("INCORRECT RESULTS FOR BINARY ADDING OPERATORS - 3"); END IF; IF +IDENT (CHARRAY (1)) NOT IN -0.375 .. -0.3125 OR IDENT (-CHARRAY (2)) NOT IN -0.6875 .. -0.625 THEN FAILED ("INCORRECT RESULTS FOR UNARY ADDING OPERATORS - 3"); END IF; IF CHECK_TYPE (CHARRAY (0) * IDENT (CHARRAY (2))) NOT IN -2.4375 .. -2.1875 OR CHECK_TYPE (IDENT (CHARRAY (1)) / CHARRAY (3)) NOT IN -0.125 .. -0.0625 THEN FAILED ("INCORRECT RESULTS FOR MULTIPLYING OPERATORS - 3"); END IF; IF ABS IDENT (CHARRAY (1)) NOT IN 0.3125 .. 0.375 OR IDENT (ABS CHARRAY (2)) NOT IN 0.625 .. 0.6875 THEN FAILED ("INCORRECT RESULTS FOR ABSOLUTE VALUE " & "OPERATORS - 3"); END IF; IF IDENT (CHARRAY (2)) NOT IN 0.625 .. 0.6875 OR CHARRAY (1) IN -0.25 .. 0.0 OR IDENT (CHARRAY (1)) IN -1.0 .. -0.4375 THEN FAILED ("INCORRECT RESULTS FOR MEMBERSHIP OPERATORS - 3"); END IF; IF IDENT (CHREC.COMPN1) + CHREC.COMPP1 NOT IN -2.875 .. -2.8125 OR CHREC.COMPP2 - IDENT (CHREC.COMPP1) NOT IN 2.8125 .. 2.875 THEN FAILED ("INCORRECT RESULTS FOR BINARY ADDING OPERATORS - 4"); END IF; IF +IDENT (CHREC.COMPN2) NOT IN -0.375 .. -0.3125 OR IDENT (-CHREC.COMPP1) NOT IN -0.6875 .. -0.625 THEN FAILED ("INCORRECT RESULTS FOR UNARY ADDING OPERATORS - 4"); END IF; IF CHECK_TYPE (CHREC.COMPN1 * IDENT (CHREC.COMPP1)) NOT IN -2.4375 .. -2.1875 OR CHECK_TYPE (IDENT (CHREC.COMPN2) / CHREC.COMPP2) NOT IN -0.125 .. -0.0625 THEN FAILED ("INCORRECT RESULTS FOR MULTIPLYING OPERATORS - 4"); END IF; IF ABS IDENT (CHREC.COMPN2) NOT IN 0.3125 .. 0.375 OR IDENT (ABS CHREC.COMPP1) NOT IN 0.625 .. 0.6875 THEN FAILED ("INCORRECT RESULTS FOR ABSOLUTE VALUE " & "OPERATORS - 4"); END IF; IF IDENT (CHREC.COMPP1) NOT IN 0.625 .. 0.6875 OR CHREC.COMPN2 IN -0.25 .. 0.0 OR IDENT (CHREC.COMPN2) IN -1.0 .. -0.4375 THEN FAILED ("INCORRECT RESULTS FOR MEMBERSHIP OPERATORS - 4"); END IF; RESULT; END CD2D11A;
-- { dg-do run } -- { dg-options "-gnatws" } with Address_Null_Init; use Address_Null_Init; with Ada.Text_IO; use Ada.Text_IO; procedure Test_Address_Null_Init is begin if B /= null then Put_Line ("ERROR: B was not default initialized to null!"); end if; if A /= null then Put_Line ("ERROR: A was not reinitialized to null!"); end if; end Test_Address_Null_Init;
------------------------------------------------------------------------------ -- -- -- 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 program demonstrates use of the LIS3DSH accelerometer and a timer to -- drive the brightness of the LEDs. -- Note that this demonstration program is specific to the STM32F4 Discovery -- boards because it references the specific accelerometer used on (later -- versions of) those boards and because it references the four user LEDs -- on those boards. (The LIS3DSH accelerometer is used on board versions -- designated by the number MB997C printed on the top of the board.) -- -- The idea is that the person holding the board will "pitch" it up and down -- and "roll" it left and right around the Z axis running through the center -- of the chip. As the board is moved, the brightness of the four LEDs -- surrounding the accelerometer will vary with the accelerations experienced -- by the board. In particular, as the angles increase the LEDs corresponding -- to those sides of the board will become brighter. The LEDs will thus become -- brightest as the board is held with any one side down, pointing toward the -- ground. with Last_Chance_Handler; pragma Unreferenced (Last_Chance_Handler); with HAL; use HAL; with Ada.Real_Time; use Ada.Real_Time; with STM32.Board; use STM32.Board; with LIS3DSH; use LIS3DSH; -- on the F4 Disco board with STM32.GPIO; use STM32.GPIO; with STM32.Timers; use STM32.Timers; with STM32.PWM; use STM32.PWM; use STM32; with Demo_PWM_Settings; use Demo_PWM_Settings; procedure Demo_LIS3DSH_PWM is Next_Release : Time := Clock; Period : constant Time_Span := Milliseconds (100); -- arbitrary function Brightness (Acceleration : Axis_Acceleration) return Percentage; -- Computes the output for the PWM. The approach is to compute the -- percentage of the given acceleration relative to a maximum acceleration -- of 1 G. procedure Drive_LEDs; -- Sets the pulse width for the two axes read from the accelerometer so -- that the brightness varies with the angle of the board. procedure Initialize_PWM_Outputs; -- Set up all the PWM output modulators tied to the LEDs procedure Panic with No_Return; -- indicate that there is a fatal problem (accelerometer not found) ----------- -- Panic -- ----------- procedure Panic is begin loop All_LEDs_On; delay until Clock + Milliseconds (250); All_LEDs_Off; delay until Clock + Milliseconds (250); end loop; end Panic; ---------------- -- Brightness -- ---------------- function Brightness (Acceleration : Axis_Acceleration) return Percentage is Result : Percentage; Bracketed_Value : Axis_Acceleration; Max_1g : constant Axis_Acceleration := 1000; -- The approximate reading from the accelerometer for 1g, in -- milligravities, used because this demo is for a person holding the -- board and rotating it, so at most approximately 1g will be seen on -- any axis. -- -- We bracket the value to the range -Max_1g .. Max_1g in order -- to filter out any movement beyond that of simply "pitching" and -- "rolling" around the Z axis running through the center of the chip. -- A person could move the board beyond the parameters intended for this -- demo simply by jerking the board laterally, for example. begin if Acceleration > 0 then Bracketed_Value := Axis_Acceleration'Min (Acceleration, Max_1g); else Bracketed_Value := Axis_Acceleration'Max (Acceleration, -Max_1g); end if; Result := Percentage ((Float (abs (Bracketed_Value)) / Float (Max_1g)) * 100.0); return Result; end Brightness; ---------------- -- Drive_LEDs -- ---------------- procedure Drive_LEDs is Axes : Axes_Accelerations; High_Threshold : constant Axis_Acceleration := 30; -- arbitrary Low_Threshold : constant Axis_Acceleration := -30; -- arbitrary Off : constant Percentage := 0; begin Accelerometer.Get_Accelerations (Axes); if Axes.X < Low_Threshold then Set_Duty_Cycle (PWM_Output_Green, Brightness (Axes.X)); else Set_Duty_Cycle (PWM_Output_Green, Off); end if; if Axes.X > High_Threshold then Set_Duty_Cycle (PWM_Output_Red, Brightness (Axes.X)); else Set_Duty_Cycle (PWM_Output_Red, Off); end if; if Axes.Y > High_Threshold then Set_Duty_Cycle (PWM_Output_Orange, Brightness (Axes.Y)); else Set_Duty_Cycle (PWM_Output_Orange, Off); end if; if Axes.Y < Low_Threshold then Set_Duty_Cycle (PWM_Output_Blue, Brightness (Axes.Y)); else Set_Duty_Cycle (PWM_Output_Blue, Off); end if; end Drive_LEDs; ---------------------------- -- Initialize_PWM_Outputs -- ---------------------------- procedure Initialize_PWM_Outputs is begin Configure_PWM_Timer (PWM_Output_Timer'Access, PWM_Frequency); PWM_Output_Green.Attach_PWM_Channel (Generator => PWM_Output_Timer'Access, Channel => Channel_1, Point => Green_LED, PWM_AF => PWM_Output_AF); PWM_Output_Orange.Attach_PWM_Channel (Generator => PWM_Output_Timer'Access, Channel => Channel_2, Point => Orange_LED, PWM_AF => PWM_Output_AF); PWM_Output_Red.Attach_PWM_Channel (Generator => PWM_Output_Timer'Access, Channel => Channel_3, Point => Red_LED, PWM_AF => PWM_Output_AF); PWM_Output_Blue.Attach_PWM_Channel (Generator => PWM_Output_Timer'Access, Channel => Channel_4, Point => Blue_LED, PWM_AF => PWM_Output_AF); PWM_Output_Green.Enable_Output; PWM_Output_Orange.Enable_Output; PWM_Output_Red.Enable_Output; PWM_Output_Blue.Enable_Output; end Initialize_PWM_Outputs; begin Initialize_Accelerometer; Accelerometer.Configure (Output_DataRate => Data_Rate_100Hz, Axes_Enable => XYZ_Enabled, SPI_Wire => Serial_Interface_4Wire, Self_Test => Self_Test_Normal, Full_Scale => Fullscale_2g, Filter_BW => Filter_800Hz); if Accelerometer.Device_Id /= I_Am_LIS3DSH then Panic; end if; Initialize_PWM_Outputs; loop Drive_LEDs; Next_Release := Next_Release + Period; delay until Next_Release; end loop; end Demo_LIS3DSH_PWM;
with GNAT.OS_Lib; with TOML.File_IO; with Simple_Logging; package body CLIC.Config.Load is package Trace renames Simple_Logging; use TOML; --------------- -- From_TOML -- --------------- procedure From_TOML (C : in out CLIC.Config.Instance; Origin : String; Path : String; Check : Check_Import := null) is Table : constant TOML_Value := Load_TOML_File (Path); begin C.Import (Table, Origin, Check => Check); end From_TOML; -------------------- -- Load_TOML_File -- -------------------- function Load_TOML_File (Path : String) return TOML.TOML_Value is begin if GNAT.OS_Lib.Is_Read_Accessible_File (Path) then declare Config : constant TOML.Read_Result := TOML.File_IO.Load_File (Path); begin if Config.Success then if Config.Value.Kind /= TOML.TOML_Table then Trace.Error ("Bad config file '" & Path & "': TOML table expected."); else return Config.Value; end if; else Trace.Detail ("error while loading '" & Path & "':"); Trace.Detail (Ada.Strings.Unbounded.To_String (Config.Message)); end if; end; else Trace.Detail ("Config file is not readable or doesn't exist: '" & Path & "'"); end if; return No_TOML_Value; end Load_TOML_File; end CLIC.Config.Load;
-- Implantation du module Arbre_Binaire with Ada.Text_IO ; use Ada.Text_IO; with Ada.Unchecked_Deallocation; package body Arbre_Binaire is procedure Free is new Ada.Unchecked_Deallocation (Object => T_Noeud, Name => T_Abr); procedure Initialiser ( Abr : out T_Abr ) is begin Abr := Null ; end Initialiser; function Vide( Abr : in T_Abr ) return boolean is begin return Abr = Null; end Vide; function Taille ( Abr : in T_Abr ) return Integer is begin if Vide ( Abr ) then return 0 ; else return (1 + Taille ( Abr.All.Sous_Arbre_Droit ) + Taille ( Abr.All.Sous_Arbre_Gauche ) ); end if; end Taille; procedure Creer_Arbre ( Abr : out T_Abr ; Cle : T_Cle ) is begin Abr := new T_Noeud'(Cle , null , null); end Creer_Arbre ; procedure Ajouter_Fils_Droit ( Abr : in out T_Abr ; Cle_Donnee : in T_Cle ; Cle : in T_Cle ) is Arbre : T_Abr; begin Arbre := Arbre_Cle (Abr ,Cle_Donnee ); if Existe(Abr , Cle_Donnee) then if not Existe (Abr , Cle ) then if Arbre.All.Sous_Arbre_Droit = Null then Arbre.all.Sous_Arbre_Droit := new T_Noeud'(Cle , null , null); else raise Existe_Fils_Droit ; end if; else raise Cle_Existe_Exception ; end if; else raise Cle_Absente_Exception ; end if; exception when Existe_Fils_Droit => Put_line ("Le fils droit est déja existant"); when Cle_Existe_Exception => Put_Line ("La clé est déja existante "); when Cle_Absente_Exception => Put_Line ("La clé est absente"); end Ajouter_Fils_Droit ; procedure Ajouter_Fils_Gauche ( Abr : in out T_Abr ; Cle_Donnee : in T_Cle ; Cle : in T_Cle ) is Arbre : T_Abr; begin Arbre := Arbre_Cle (Abr ,Cle_Donnee ); if Existe(Abr , Cle_Donnee) then if not Existe (Abr , Cle ) then if Arbre.All.Sous_Arbre_Gauche = Null then Arbre.all.Sous_Arbre_Gauche:=new T_Noeud'(Cle , null , null); else raise Existe_Fils_Gauche ; end if; else raise Cle_Existe_Exception ; end if; else raise Cle_Absente_Exception ; end if; exception when Existe_Fils_Droit => Put_line ("Le fils droit est déja existant"); when Cle_Existe_Exception => Put_Line ("La clé est déja existante "); when Cle_Absente_Exception => Put_Line ("La clé est absente"); end Ajouter_Fils_Gauche; function Arbre_Cle ( Abr : in T_Abr ; Cle_Donnee : in T_Cle) return T_Abr is begin if Abr.all.Cle = Cle_Donnee then return Abr ; elsif Existe (Abr.All.Sous_Arbre_Droit, Cle_Donnee ) then return Arbre_Cle( Abr.all.Sous_Arbre_Droit , Cle_Donnee ); elsif Existe ( Abr.All.Sous_Arbre_Gauche ,Cle_Donnee ) then return Arbre_Cle (Abr.All.Sous_Arbre_Gauche , Cle_Donnee) ; else raise Cle_Absente_Exception ; end if; end Arbre_Cle; function Existe ( Abr : in T_Abr ; Cle_Donnee : in T_Cle ) return Boolean is begin if Vide (Abr) then return False ; elsif Abr.All.Cle = Cle_Donnee then return True ; else return ( Existe(Abr.All.Sous_Arbre_Droit, Cle_Donnee) or Existe ( Abr.All.Sous_Arbre_Gauche, Cle_Donnee )); end if; end Existe ; --Une autre solution possible pour la fonction existe -- function Existe( Abr : in T_Abr ; Cle_Donnee : in T_Cle ) return Boolean is --i : Integer := 0 ; -- procedure ajouter_1(Abr : in T_Abr ; Cle_Donnee : in T_Cle ) is -- -- begin -- if Abr.all.Cle = Cle_Donnee then -- i:=i+1; -- else -- ajouter_1(Abr.all.Sous_Arbre_Gauche , Cle_Donnee); -- ajouter_1(Abr.all.Sous_Arbre_Droit , Cle_Donnee); -- end if ; -- end ajouter_1; -- begin -- ajouter_1 ( Abr , Cle_Donnee ); -- return i=1 ; --end Existe ; procedure Modifier ( Abr : in out T_Abr ; Cle_Donnee : in T_Cle ; Cle : in T_Cle ) is Arbreamodifier : T_Abr ; begin if Existe ( Abr , Cle_Donnee) then Arbreamodifier := Arbre_Cle ( Abr , Cle_Donnee) ; Arbreamodifier.All.Cle := Cle ; else raise Cle_Absente_Exception ; end if; exception when Cle_Absente_Exception => Put_Line(" La clé est absente"); end Modifier ; procedure Supprimer ( Abr : in out T_Abr ; Cle : in T_Cle ) is begin if Vide(Abr) then null; elsif Abr.All.Cle = Cle then Free(Abr); else Supprimer(Abr.All.Sous_Arbre_Droit , Cle ); Supprimer(Abr.All.Sous_Arbre_Gauche , Cle ); end if; end Supprimer; procedure Vider_Arbre ( Abr : out T_Abr ) is begin if Vide(Abr) then null; else Supprimer( Abr , Abr.All.Cle); end if; end Vider_Arbre ; procedure Afficher_Arbre_Binaire ( Abr : in T_Abr ;n : in integer) is begin if Vide( Abr ) then null; else Afficher_Cle ( Abr.All.Cle);New_Line; if not Vide(Abr.All.Sous_Arbre_Droit) then for i in 1..n loop put(' '); end loop; put ("--père : "); Afficher_Arbre_Binaire ( Abr.All.Sous_Arbre_Droit,5+n);New_Line; end if; if not Vide(Abr.All.Sous_Arbre_Gauche) then for i in 1..n loop put(' '); end loop; put ("--mère : "); Afficher_Arbre_Binaire ( Abr.All.Sous_Arbre_Gauche,5+n);New_Line; end if; end if; end Afficher_Arbre_Binaire; function Avoir_Cle ( Abr : in T_Abr ; Cle : in T_Cle ) return T_Cle is Arbre : T_Abr; begin if Existe ( Abr , Cle ) then Arbre := Arbre_Cle ( Abr , Cle ); return Arbre.All.Cle ; else raise Cle_Absente_Exception ; end if; end Avoir_Cle ; function Avoir_Cle_Arbre ( Abr : T_Abr ) return T_Cle is begin return Abr.All.Cle; end Avoir_Cle_Arbre; function Avoir_Sous_Arbre_Droit ( Abr : in T_Abr ) return T_Abr is begin return Abr.All.Sous_Arbre_Droit ; end Avoir_Sous_Arbre_Droit; function Avoir_Sous_Arbre_Gauche ( Abr : in T_Abr ) return T_Abr is begin return Abr.All.Sous_Arbre_Gauche ; end Avoir_Sous_Arbre_Gauche; end Arbre_Binaire;
-- Copyright 2021 Jeff Foley. All rights reserved. -- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. local url = require("url") name = "Searx" type = "scrape" function start() set_rate_limit(4) math.randomseed(os.time()) end function vertical(ctx, domain) -- Qualified best Searx instances local instances = { "https://anon.sx", "https://searx.info", "https://searx.ru", "https://searx.run", "https://searx.sk", "https://xeek.com", } -- Randomly choose one instance for scraping local host = instances[math.random(1, 6)] .. "/search" for i=1,15 do local query = "site:" .. domain .. " -www" local params = { ['q']=query, ['pageno']=i, ['category_general']="1", ['time_range']="None", ['language']="en-US", } local ok = scrape(ctx, { ['url']=host, method="POST", data=url.build_query_string(params), headers={['Content-Type']="application/x-www-form-urlencoded"}, }) if not ok then break end end end
----------------------------------------------------------------------- -- awa-storages-stores -- The storage interface -- Copyright (C) 2012 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with ADO.Sessions; with AWA.Storages.Models; -- == Store Service == -- The `AWA.Storages.Stores` package defines the interface that a store must implement to -- be able to save and retrieve a data content. The store can be a file system, a database -- or a remote store service. -- -- @include awa-storages-stores-databases.ads -- @include awa-storages-stores-files.ads package AWA.Storages.Stores is -- ------------------------------ -- Store Service -- ------------------------------ type Store is limited interface; type Store_Access is access all Store'Class; -- Create a storage procedure Create (Storage : in Store; Session : in out ADO.Sessions.Master_Session; From : in AWA.Storages.Models.Storage_Ref'Class; Into : in out AWA.Storages.Storage_File) is abstract; -- Save the file represented by the `Path` variable into a store and associate that -- content with the storage reference represented by `Into`. procedure Save (Storage : in Store; Session : in out ADO.Sessions.Master_Session; Into : in out AWA.Storages.Models.Storage_Ref'Class; Path : in String) is abstract; -- Load the storage item represented by `From` in a file that can be accessed locally. procedure Load (Storage : in Store; Session : in out ADO.Sessions.Session'Class; From : in AWA.Storages.Models.Storage_Ref'Class; Into : in out AWA.Storages.Storage_File) is abstract; -- Delete the content associate with the storage represented by `From`. procedure Delete (Storage : in Store; Session : in out ADO.Sessions.Master_Session; From : in out AWA.Storages.Models.Storage_Ref'Class) is abstract; end AWA.Storages.Stores;
------------------------------------------------------------------------------ -- -- -- ASIS-for-GNAT IMPLEMENTATION COMPONENTS -- -- -- -- A 4 G . Q U E R I E S -- -- -- -- S p e c -- -- -- -- Copyright (c) 1995-2006, Free Software Foundation, Inc. -- -- -- -- ASIS-for-GNAT is free software; you can redistribute it and/or modify it -- -- under terms of the GNU General Public License as published by the Free -- -- Software Foundation; either version 2, or (at your option) any later -- -- version. ASIS-for-GNAT is distributed in the hope that it will be use- -- -- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- -- -- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -- -- Public License for more details. You should have received a copy of the -- -- GNU General Public License distributed with ASIS-for-GNAT; see file -- -- COPYING. If not, write to the Free Software Foundation, 51 Franklin -- -- Street, Fifth Floor, Boston, MA 02110-1301, USA. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the -- -- Software Engineering Laboratory of the Swiss Federal Institute of -- -- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the -- -- Scientific Research Computer Center of Moscow State University (SRCC -- -- MSU), Russia, with funding partially provided by grants from the Swiss -- -- National Science Foundation and the Swiss Academy of Engineering -- -- Sciences. ASIS-for-GNAT is now maintained by AdaCore -- -- (http://www.adaccore.com). -- -- -- -- The original version of this component has been developed by Jean-Charles-- -- Marteau (Jean-Charles.Marteau@ensimag.imag.fr) and Serge Reboul -- -- (Serge.Reboul@ensimag.imag.fr), ENSIMAG High School Graduates (Computer -- -- sciences) Grenoble, France in Sema Group Grenoble, France. Now this -- -- component is maintained by the ASIS team -- -- -- ------------------------------------------------------------------------------ with Asis; use Asis; ---------------------------------------------------------- -- The goal of this package is, when we have an element -- -- to let us have ALL the possible queries for that -- -- element that return its children. -- ---------------------------------------------------------- package A4G.Queries is -- There is 3 kinds of queries in Asis : type Query_Kinds is (Bug, -- just for the discriminant default expression Single_Element_Query, -- Queries taking an element and returning an element. Element_List_Query, -- Queries taking an element and returning a list of elements. Element_List_Query_With_Boolean -- Queries taking an element and a boolean and returning a list -- of elements. ); type A_Single_Element_Query is access function (Elem : Asis.Element) return Asis.Element; type A_Element_List_Query is access function (Elem : Asis.Element) return Asis.Element_List; type A_Element_List_Query_With_Boolean is access function (Elem : Asis.Element; Bool : Boolean) return Asis.Element_List; -- Discriminant record that can access any type of query. type Func_Elem (Query_Kind : Query_Kinds := Bug) is record case Query_Kind is when Bug => null; when Single_Element_Query => Func_Simple : A_Single_Element_Query; when Element_List_Query => Func_List : A_Element_List_Query; when Element_List_Query_With_Boolean => Func_List_Boolean : A_Element_List_Query_With_Boolean; Bool : Boolean; end case; end record; type Query_Array is array (Positive range <>) of Func_Elem; -- an empty array, when the element is a terminal No_Query : Query_Array (1 .. 0); ---------------------------------------------------- -- This function returns a Query_Array containing -- -- all the existing queries for that element. -- -- If an element has no children, No_Query is -- -- returned. -- ---------------------------------------------------- function Appropriate_Queries (Element : Asis.Element) return Query_Array; end A4G.Queries;
-- Copyright 2016-2019 NXP -- All rights reserved.SPDX-License-Identifier: BSD-3-Clause -- This spec has been automatically generated from LPC55S6x.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package NXP_SVD.HASHCRYPT is pragma Preelaborate; --------------- -- Registers -- --------------- -- The operational mode to use, or 0 if none. Note that the CONFIG register -- will indicate if specific modes beyond SHA1 and SHA2-256 are available. type CTRL_Mode_Field is ( -- Disabled Disabled, -- SHA1 is enabled Sha1, -- SHA2-256 is enabled Sha2_256, -- AES if available (see also CRYPTCFG register for more controls) Aes, -- ICB-AES if available (see also CRYPTCFG register for more controls) Icb_Aes) with Size => 3; for CTRL_Mode_Field use (Disabled => 0, Sha1 => 1, Sha2_256 => 2, Aes => 4, Icb_Aes => 5); -- Written with 1 when starting a new Hash/Crypto. It self clears. Note -- that the WAITING Status bit will clear for a cycle during the -- initialization from New=1. type CTRL_New_Hash_Field is ( -- Reset value for the field Ctrl_New_Hash_Field_Reset, -- Starts a new Hash/Crypto and initializes the Digest/Result. Start) with Size => 1; for CTRL_New_Hash_Field use (Ctrl_New_Hash_Field_Reset => 0, Start => 1); -- Written with 1 to use DMA to fill INDATA. If Hash, will request from DMA -- for 16 words and then will process the Hash. If Cryptographic, it will -- load as many words as needed, including key if not already loaded. It -- will then request again. Normal model is that the DMA interrupts the -- processor when its length expires. Note that if the processor will write -- the key and optionally IV, it should not enable this until it has done -- so. Otherwise, the DMA will be expected to load those for the 1st block -- (when needed). type CTRL_DMA_I_Field is ( -- DMA is not used. Processor writes the necessary words when WAITING is -- set (interrupts), unless AHB Master is used. Not_Used, -- DMA will push in the data. Push) with Size => 1; for CTRL_DMA_I_Field use (Not_Used => 0, Push => 1); -- Written to 1 to use DMA to drain the digest/output. If both DMA_I and -- DMA_O are set, the DMA has to know to switch direction and the -- locations. This can be used for crypto uses. type CTRL_DMA_O_Field is ( -- DMA is not used. Processor reads the digest/output in response to -- DIGEST interrupt. Notused) with Size => 1; for CTRL_DMA_O_Field use (Notused => 0); -- Control register to enable and operate Hash and Crypto type CTRL_Register is record -- The operational mode to use, or 0 if none. Note that the CONFIG -- register will indicate if specific modes beyond SHA1 and SHA2-256 are -- available. Mode : CTRL_Mode_Field := NXP_SVD.HASHCRYPT.Disabled; -- unspecified Reserved_3_3 : HAL.Bit := 16#0#; -- Write-only. Written with 1 when starting a new Hash/Crypto. It self -- clears. Note that the WAITING Status bit will clear for a cycle -- during the initialization from New=1. New_Hash : CTRL_New_Hash_Field := Ctrl_New_Hash_Field_Reset; -- unspecified Reserved_5_7 : HAL.UInt3 := 16#0#; -- Written with 1 to use DMA to fill INDATA. If Hash, will request from -- DMA for 16 words and then will process the Hash. If Cryptographic, it -- will load as many words as needed, including key if not already -- loaded. It will then request again. Normal model is that the DMA -- interrupts the processor when its length expires. Note that if the -- processor will write the key and optionally IV, it should not enable -- this until it has done so. Otherwise, the DMA will be expected to -- load those for the 1st block (when needed). DMA_I : CTRL_DMA_I_Field := NXP_SVD.HASHCRYPT.Not_Used; -- Written to 1 to use DMA to drain the digest/output. If both DMA_I and -- DMA_O are set, the DMA has to know to switch direction and the -- locations. This can be used for crypto uses. DMA_O : CTRL_DMA_O_Field := NXP_SVD.HASHCRYPT.Notused; -- unspecified Reserved_10_11 : HAL.UInt2 := 16#0#; -- If 1, will swap bytes in the word for SHA hashing. The default is -- byte order (so LSB is 1st byte) but this allows swapping to MSB is -- 1st such as is shown in SHS spec. For cryptographic swapping, see the -- CRYPTCFG register. HASHSWPB : Boolean := False; -- unspecified Reserved_13_31 : HAL.UInt19 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CTRL_Register use record Mode at 0 range 0 .. 2; Reserved_3_3 at 0 range 3 .. 3; New_Hash at 0 range 4 .. 4; Reserved_5_7 at 0 range 5 .. 7; DMA_I at 0 range 8 .. 8; DMA_O at 0 range 9 .. 9; Reserved_10_11 at 0 range 10 .. 11; HASHSWPB at 0 range 12 .. 12; Reserved_13_31 at 0 range 13 .. 31; end record; -- If 1, the block is waiting for more data to process. type STATUS_WAITING_Field is ( -- Not waiting for data - may be disabled or may be busy. Note that for -- cryptographic uses, this is not set if IsLast is set nor will it set -- until at least 1 word is read of the output. Not_Waiting, -- Waiting for data to be written in (16 words) Waiting) with Size => 1; for STATUS_WAITING_Field use (Not_Waiting => 0, Waiting => 1); -- For Hash, if 1 then a DIGEST is ready and waiting and there is no active -- next block already started. For Cryptographic uses, this will be set for -- each block processed, indicating OUTDATA (and OUTDATA2 if larger output) -- contains the next value to read out. This is cleared when any data is -- written, when New is written, for Cryptographic uses when the last word -- is read out, or when the block is disabled. type STATUS_DIGEST_Field is ( -- No Digest is ready Not_Ready, -- Digest is ready. Application may read it or may write more data Ready) with Size => 1; for STATUS_DIGEST_Field use (Not_Ready => 0, Ready => 1); -- If 1, an error occurred. For normal uses, this is due to an attempted -- overrun: INDATA was written when it was not appropriate. For Master -- cases, this is an AHB bus error; the COUNT field will indicate which -- block it was on. type STATUS_ERROR_Field is ( -- No error. No_Error, -- An error occurred since last cleared (written 1 to clear). Error) with Size => 1; for STATUS_ERROR_Field use (No_Error => 0, Error => 1); -- Indicates the block wants the key to be written in (set along with -- WAITING) type STATUS_NEEDKEY_Field is ( -- No Key is needed and writes will not be treated as Key Not_Need, -- Key is needed and INDATA/ALIAS will be accepted as Key. Will also set -- WAITING. Need) with Size => 1; for STATUS_NEEDKEY_Field use (Not_Need => 0, Need => 1); -- Indicates the block wants an IV/NONE to be written in (set along with -- WAITING) type STATUS_NEEDIV_Field is ( -- No IV/Nonce is needed, either because written already or because not -- needed. Not_Need, -- IV/Nonce is needed and INDATA/ALIAS will be accepted as IV/Nonce. -- Will also set WAITING. Need) with Size => 1; for STATUS_NEEDIV_Field use (Not_Need => 0, Need => 1); subtype STATUS_ICBIDX_Field is HAL.UInt6; -- Indicates status of Hash peripheral. type STATUS_Register is record -- Read-only. If 1, the block is waiting for more data to process. WAITING : STATUS_WAITING_Field := NXP_SVD.HASHCRYPT.Not_Waiting; -- Read-only. For Hash, if 1 then a DIGEST is ready and waiting and -- there is no active next block already started. For Cryptographic -- uses, this will be set for each block processed, indicating OUTDATA -- (and OUTDATA2 if larger output) contains the next value to read out. -- This is cleared when any data is written, when New is written, for -- Cryptographic uses when the last word is read out, or when the block -- is disabled. DIGEST : STATUS_DIGEST_Field := NXP_SVD.HASHCRYPT.Not_Ready; -- Write data bit of one shall clear (set to zero) the corresponding bit -- in the field. If 1, an error occurred. For normal uses, this is due -- to an attempted overrun: INDATA was written when it was not -- appropriate. For Master cases, this is an AHB bus error; the COUNT -- field will indicate which block it was on. ERROR : STATUS_ERROR_Field := NXP_SVD.HASHCRYPT.No_Error; -- unspecified Reserved_3_3 : HAL.Bit := 16#0#; -- Read-only. Indicates the block wants the key to be written in (set -- along with WAITING) NEEDKEY : STATUS_NEEDKEY_Field := NXP_SVD.HASHCRYPT.Not_Need; -- Read-only. Indicates the block wants an IV/NONE to be written in (set -- along with WAITING) NEEDIV : STATUS_NEEDIV_Field := NXP_SVD.HASHCRYPT.Not_Need; -- unspecified Reserved_6_15 : HAL.UInt10 := 16#0#; -- Read-only. If ICB-AES is selected, then reads as the ICB index count -- based on ICBSTRM (from CRYPTCFG). That is, if 3 bits of ICBSTRM, then -- this will count from 0 to 7 and then back to 0. On 0, it has to -- compute the full ICB, quicker when not 0. ICBIDX : STATUS_ICBIDX_Field := 16#0#; -- unspecified Reserved_22_31 : HAL.UInt10 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for STATUS_Register use record WAITING at 0 range 0 .. 0; DIGEST at 0 range 1 .. 1; ERROR at 0 range 2 .. 2; Reserved_3_3 at 0 range 3 .. 3; NEEDKEY at 0 range 4 .. 4; NEEDIV at 0 range 5 .. 5; Reserved_6_15 at 0 range 6 .. 15; ICBIDX at 0 range 16 .. 21; Reserved_22_31 at 0 range 22 .. 31; end record; -- Indicates if should interrupt when waiting for data input. type INTENSET_WAITING_Field is ( -- Will not interrupt when waiting. No_Interrupt, -- Will interrupt when waiting Interrupt) with Size => 1; for INTENSET_WAITING_Field use (No_Interrupt => 0, Interrupt => 1); -- Indicates if should interrupt when Digest (or Outdata) is ready -- (completed a hash/crypto or completed a full sequence). type INTENSET_DIGEST_Field is ( -- Will not interrupt when Digest is ready No_Interrupt, -- Will interrupt when Digest is ready. Interrupt cleared by writing -- more data, starting a new Hash, or disabling (done). Interrupt) with Size => 1; for INTENSET_DIGEST_Field use (No_Interrupt => 0, Interrupt => 1); -- Indicates if should interrupt on an ERROR (as defined in Status) type INTENSET_ERROR_Field is ( -- Will not interrupt on Error. Not_Interrupt, -- Will interrupt on Error (until cleared). Interrupt) with Size => 1; for INTENSET_ERROR_Field use (Not_Interrupt => 0, Interrupt => 1); -- Write 1 to enable interrupts; reads back with which are set. type INTENSET_Register is record -- Indicates if should interrupt when waiting for data input. WAITING : INTENSET_WAITING_Field := NXP_SVD.HASHCRYPT.No_Interrupt; -- Indicates if should interrupt when Digest (or Outdata) is ready -- (completed a hash/crypto or completed a full sequence). DIGEST : INTENSET_DIGEST_Field := NXP_SVD.HASHCRYPT.No_Interrupt; -- Indicates if should interrupt on an ERROR (as defined in Status) ERROR : INTENSET_ERROR_Field := NXP_SVD.HASHCRYPT.Not_Interrupt; -- unspecified Reserved_3_31 : HAL.UInt29 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for INTENSET_Register use record WAITING at 0 range 0 .. 0; DIGEST at 0 range 1 .. 1; ERROR at 0 range 2 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; -- Write 1 to clear interrupts. type INTENCLR_Register is record -- Write data bit of one shall clear (set to zero) the corresponding bit -- in the field. Write 1 to clear mask. WAITING : Boolean := False; -- Write data bit of one shall clear (set to zero) the corresponding bit -- in the field. Write 1 to clear mask. DIGEST : Boolean := False; -- Write data bit of one shall clear (set to zero) the corresponding bit -- in the field. Write 1 to clear mask. ERROR : Boolean := False; -- unspecified Reserved_3_31 : HAL.UInt29 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for INTENCLR_Register use record WAITING at 0 range 0 .. 0; DIGEST at 0 range 1 .. 1; ERROR at 0 range 2 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; -- Enables mastering. type MEMCTRL_MASTER_Field is ( -- Mastering is not used and the normal DMA or Interrupt based model is -- used with INDATA. Not_Used, -- Mastering is enabled and DMA and INDATA should not be used. Enabled) with Size => 1; for MEMCTRL_MASTER_Field use (Not_Used => 0, Enabled => 1); subtype MEMCTRL_COUNT_Field is HAL.UInt11; -- Setup Master to access memory (if available) type MEMCTRL_Register is record -- Enables mastering. MASTER : MEMCTRL_MASTER_Field := NXP_SVD.HASHCRYPT.Not_Used; -- unspecified Reserved_1_15 : HAL.UInt15 := 16#0#; -- Number of 512-bit (128-bit if AES, except 1st block which may include -- key and IV) blocks to copy starting at MEMADDR. This register will -- decrement after each block is copied, ending in 0. For Hash, the -- DIGEST interrupt will occur when it reaches 0. Fro AES, the -- DIGEST/OUTDATA interrupt will occur on ever block. If a bus error -- occurs, it will stop with this field set to the block that failed. -- 0:Done - nothing to process. 1 to 2K: Number of 512-bit (or 128bit) -- blocks to hash. COUNT : MEMCTRL_COUNT_Field := 16#0#; -- unspecified Reserved_27_31 : HAL.UInt5 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MEMCTRL_Register use record MASTER at 0 range 0 .. 0; Reserved_1_15 at 0 range 1 .. 15; COUNT at 0 range 16 .. 26; Reserved_27_31 at 0 range 27 .. 31; end record; -- no description available -- no description available type ALIAS_Registers is array (0 .. 6) of HAL.UInt32 with Volatile; -- no description available -- no description available type DIGEST0_Registers is array (0 .. 7) of HAL.UInt32 with Volatile; -- AES Cipher mode to use if plain AES type CRYPTCFG_AESMODE_Field is ( -- ECB - used as is Ecb, -- CBC mode (see details on IV/nonce) Cbc, -- CTR mode (see details on IV/nonce). See also AESCTRPOS. Ctr) with Size => 2; for CRYPTCFG_AESMODE_Field use (Ecb => 0, Cbc => 1, Ctr => 2); -- AES ECB direction. Only encryption used if CTR mode or manual modes such -- as CFB type CRYPTCFG_AESDECRYPT_Field is ( -- Encrypt Encrypt, -- Decrypt Decrypt) with Size => 1; for CRYPTCFG_AESDECRYPT_Field use (Encrypt => 0, Decrypt => 1); -- Selects the Hidden Secret key vs. User key, if provided. If security -- levels are used, only the highest level is permitted to select this. type CRYPTCFG_AESSECRET_Field is ( -- User key provided in normal way Normal_Way, -- Secret key provided in hidden way by HW Hidden_Way) with Size => 1; for CRYPTCFG_AESSECRET_Field use (Normal_Way => 0, Hidden_Way => 1); -- Sets the AES key size type CRYPTCFG_AESKEYSZ_Field is ( -- 128 bit key Bits_128, -- 192 bit key Bits_192, -- 256 bit key Bits_256) with Size => 2; for CRYPTCFG_AESKEYSZ_Field use (Bits_128 => 0, Bits_192 => 1, Bits_256 => 2); subtype CRYPTCFG_AESCTRPOS_Field is HAL.UInt3; -- This sets the ICB size between 32 and 128 bits, using the following -- rules. Note that the counter is assumed to occupy the low order bits of -- the IV. type CRYPTCFG_ICBSZ_Field is ( -- 32 bits of the IV/ctr are used (from 127:96) Bits_32, -- 64 bits of the IV/ctr are used (from 127:64) Bits_64, -- 96 bits of the IV/ctr are used (from 127:32) Bits_96, -- All 128 bits of the IV/ctr are used Bit_128) with Size => 2; for CRYPTCFG_ICBSZ_Field use (Bits_32 => 0, Bits_64 => 1, Bits_96 => 2, Bit_128 => 3); -- The size of the ICB-AES stream that can be pushed before needing to -- compute a new IV/ctr (counter start). This optimizes the performance of -- the stream of blocks after the 1st. type CRYPTCFG_ICBSTRM_Field is ( -- 8 blocks Blocks_8, -- 16 blocks Blocks_16, -- 32 blocks Blocks_32, -- 64 blocks Blocks_64) with Size => 2; for CRYPTCFG_ICBSTRM_Field use (Blocks_8 => 0, Blocks_16 => 1, Blocks_32 => 2, Blocks_64 => 3); -- Crypto settings for AES and Salsa and ChaCha type CRYPTCFG_Register is record -- If 1, OUTDATA0 will be read Most significant word 1st for AES. Else -- it will be read in normal little endian - Least significant word 1st. -- Note: only if allowed by configuration. MSW1ST_OUT : Boolean := False; -- If 1, will Swap the key input (bytes in each word). SWAPKEY : Boolean := False; -- If 1, will SWAP the data and IV inputs (bytes in each word). SWAPDAT : Boolean := False; -- If 1, load of key, IV, and data is MSW 1st for AES. Else, the words -- are little endian. Note: only if allowed by configuration. MSW1ST : Boolean := False; -- AES Cipher mode to use if plain AES AESMODE : CRYPTCFG_AESMODE_Field := NXP_SVD.HASHCRYPT.Ecb; -- AES ECB direction. Only encryption used if CTR mode or manual modes -- such as CFB AESDECRYPT : CRYPTCFG_AESDECRYPT_Field := NXP_SVD.HASHCRYPT.Encrypt; -- Selects the Hidden Secret key vs. User key, if provided. If security -- levels are used, only the highest level is permitted to select this. AESSECRET : CRYPTCFG_AESSECRET_Field := NXP_SVD.HASHCRYPT.Normal_Way; -- Sets the AES key size AESKEYSZ : CRYPTCFG_AESKEYSZ_Field := NXP_SVD.HASHCRYPT.Bits_128; -- Halfword position of 16b counter in IV if AESMODE is CTR (position is -- fixed for Salsa and ChaCha). Only supports 16b counter, so -- application must control any additional bytes if using more. The -- 16-bit counter is read from the IV and incremented by 1 each time. -- Any other use CTR should use ECB directly and do its own XOR and so -- on. AESCTRPOS : CRYPTCFG_AESCTRPOS_Field := 16#0#; -- unspecified Reserved_13_15 : HAL.UInt3 := 16#0#; -- Is 1 if last stream block. If not 1, then the engine will compute the -- next "hash". STREAMLAST : Boolean := False; -- unspecified Reserved_17_19 : HAL.UInt3 := 16#0#; -- This sets the ICB size between 32 and 128 bits, using the following -- rules. Note that the counter is assumed to occupy the low order bits -- of the IV. ICBSZ : CRYPTCFG_ICBSZ_Field := NXP_SVD.HASHCRYPT.Bits_32; -- The size of the ICB-AES stream that can be pushed before needing to -- compute a new IV/ctr (counter start). This optimizes the performance -- of the stream of blocks after the 1st. ICBSTRM : CRYPTCFG_ICBSTRM_Field := NXP_SVD.HASHCRYPT.Blocks_8; -- unspecified Reserved_24_31 : HAL.UInt8 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CRYPTCFG_Register use record MSW1ST_OUT at 0 range 0 .. 0; SWAPKEY at 0 range 1 .. 1; SWAPDAT at 0 range 2 .. 2; MSW1ST at 0 range 3 .. 3; AESMODE at 0 range 4 .. 5; AESDECRYPT at 0 range 6 .. 6; AESSECRET at 0 range 7 .. 7; AESKEYSZ at 0 range 8 .. 9; AESCTRPOS at 0 range 10 .. 12; Reserved_13_15 at 0 range 13 .. 15; STREAMLAST at 0 range 16 .. 16; Reserved_17_19 at 0 range 17 .. 19; ICBSZ at 0 range 20 .. 21; ICBSTRM at 0 range 22 .. 23; Reserved_24_31 at 0 range 24 .. 31; end record; -- Returns the configuration of this block in this chip - indicates what -- services are available. type CONFIG_Register is record -- Read-only. 1 if 2 x 512 bit buffers, 0 if only 1 x 512 bit DUAL : Boolean; -- Read-only. 1 if DMA is connected DMA : Boolean; -- unspecified Reserved_2_2 : HAL.Bit; -- Read-only. 1 if AHB Master is enabled AHB : Boolean; -- unspecified Reserved_4_5 : HAL.UInt2; -- Read-only. 1 if AES 128 included AES : Boolean; -- Read-only. 1 if AES 192 and 256 also included AESKEY : Boolean; -- Read-only. 1 if AES Secret key available SECRET : Boolean; -- unspecified Reserved_9_10 : HAL.UInt2; -- Read-only. 1 if ICB over AES included ICB : Boolean; -- unspecified Reserved_12_31 : HAL.UInt20; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CONFIG_Register use record DUAL at 0 range 0 .. 0; DMA at 0 range 1 .. 1; Reserved_2_2 at 0 range 2 .. 2; AHB at 0 range 3 .. 3; Reserved_4_5 at 0 range 4 .. 5; AES at 0 range 6 .. 6; AESKEY at 0 range 7 .. 7; SECRET at 0 range 8 .. 8; Reserved_9_10 at 0 range 9 .. 10; ICB at 0 range 11 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; -- Write 1 to secure-lock this block (if running in a security state). -- Write 0 to unlock. If locked already, may only write if at same or -- higher security level as lock. Reads as: 0 if unlocked, else 1, 2, 3 to -- indicate security level it is locked at. NOTE: this and ID are the only -- readable registers if locked and current state is lower than lock level. type LOCK_SECLOCK_Field is ( -- Unlocks, so block is open to all. But, AHB Master will only issue -- non-secure requests. Unlock, -- Locks to the current security level. AHB Master will issue requests -- at this level. Lock) with Size => 2; for LOCK_SECLOCK_Field use (Unlock => 0, Lock => 1); subtype LOCK_PATTERN_Field is HAL.UInt12; -- Lock register allows locking to the current security level or unlocking -- by the lock holding level. type LOCK_Register is record -- Write 1 to secure-lock this block (if running in a security state). -- Write 0 to unlock. If locked already, may only write if at same or -- higher security level as lock. Reads as: 0 if unlocked, else 1, 2, 3 -- to indicate security level it is locked at. NOTE: this and ID are the -- only readable registers if locked and current state is lower than -- lock level. SECLOCK : LOCK_SECLOCK_Field := NXP_SVD.HASHCRYPT.Unlock; -- unspecified Reserved_2_3 : HAL.UInt2 := 16#0#; -- Must write 0xA75 to change lock state. A75:Pattern needed to change -- bits 1:0 PATTERN : LOCK_PATTERN_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 LOCK_Register use record SECLOCK at 0 range 0 .. 1; Reserved_2_3 at 0 range 2 .. 3; PATTERN at 0 range 4 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- no description available -- no description available type MASK_Registers is array (0 .. 3) of HAL.UInt32 with Volatile; ----------------- -- Peripherals -- ----------------- -- Hash-Crypt peripheral type HASHCRYPT_Peripheral is record -- Control register to enable and operate Hash and Crypto CTRL : aliased CTRL_Register; -- Indicates status of Hash peripheral. STATUS : aliased STATUS_Register; -- Write 1 to enable interrupts; reads back with which are set. INTENSET : aliased INTENSET_Register; -- Write 1 to clear interrupts. INTENCLR : aliased INTENCLR_Register; -- Setup Master to access memory (if available) MEMCTRL : aliased MEMCTRL_Register; -- Address to start memory access from (if available). MEMADDR : aliased HAL.UInt32; -- Input of 16 words at a time to load up buffer. INDATA : aliased HAL.UInt32; -- no description available ALIAS : aliased ALIAS_Registers; -- no description available DIGEST0 : aliased DIGEST0_Registers; -- Crypto settings for AES and Salsa and ChaCha CRYPTCFG : aliased CRYPTCFG_Register; -- Returns the configuration of this block in this chip - indicates what -- services are available. CONFIG : aliased CONFIG_Register; -- Lock register allows locking to the current security level or -- unlocking by the lock holding level. LOCK : aliased LOCK_Register; -- no description available MASK : aliased MASK_Registers; end record with Volatile; for HASHCRYPT_Peripheral use record CTRL at 16#0# range 0 .. 31; STATUS at 16#4# range 0 .. 31; INTENSET at 16#8# range 0 .. 31; INTENCLR at 16#C# range 0 .. 31; MEMCTRL at 16#10# range 0 .. 31; MEMADDR at 16#14# range 0 .. 31; INDATA at 16#20# range 0 .. 31; ALIAS at 16#24# range 0 .. 223; DIGEST0 at 16#40# range 0 .. 255; CRYPTCFG at 16#80# range 0 .. 31; CONFIG at 16#84# range 0 .. 31; LOCK at 16#8C# range 0 .. 31; MASK at 16#90# range 0 .. 127; end record; -- Hash-Crypt peripheral HASHCRYPT_Periph : aliased HASHCRYPT_Peripheral with Import, Address => System'To_Address (16#400A4000#); end NXP_SVD.HASHCRYPT;
with Ada.Text_IO; package body Linereader is SL : constant Natural := Separator_Sequence'Length; function End_Of_Input(Self : Reader) return Boolean is begin return Self.End_Of_Input; end End_Of_Input; procedure Restore (Self : in out Reader) is begin Self.Position := Self.Backup; end Restore; procedure Backup (Self : in out Reader) is begin Self.Backup := Self.Position; end Backup; function Get_Remainder (Self : in out Reader) return String is Result : constant String := Self.Source(Self.Position .. Self.Last); subtype NiceString is String (1 .. Self.Last - Self.Position + 1); begin Self.End_Of_Input := True; return NiceString(Result); end Get_Remainder; function Separator_Position(Self: Reader) return Natural is pragma Inline(Separator_Position); K : Natural := Self.Position; begin while Self.Source(K) /= Separator_Sequence(Separator_Sequence'First) loop K := K + 1; exit when K > Self.Len; end loop; return K; end Separator_Position; function Get_Line(Self: in out Reader) return String is Next_Separator : Natural; begin if Self.End_Of_Input then raise End_Of_Input_Exception; end if; Next_Separator := Separator_Position(Self); if Next_Separator > Self.Last then declare Result : constant String := Self.Source(Self.Position .. Self.Last); subtype NiceString is String (1 .. Self.Last - Self.Position); begin Self.End_Of_Input := True; return NiceString(Result); end; else declare Result : String renames Self.Source(Self.Position .. Next_Separator); subtype NiceString is String (1 .. Next_Separator - Self.Position); begin Self.Position := Next_Separator + SL; return NiceString(Result); end; end if; end Get_Line; end Linereader;
------------------------------------------------------------------------------ -- G N A T C O L L -- -- -- -- Copyright (C) 2009-2019, AdaCore -- -- Copyright (C) 2020, Heisenbug Ltd. -- -- -- -- This library 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 3, or (at your option) any later -- -- version. This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- -- TABILITY 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/>. -- -- -- ------------------------------------------------------------------------------ package GNATCOLL.Opt_Parse.Extension is -- Option parser which accepts empty arguments. generic Parser : in out Argument_Parser; -- Argument_Parser owning this argument. Short : String := ""; -- Short form for this flag. Should start with one dash and be followed -- by one or two alphanumeric characters. Long : String; -- Long form for this flag. Should start with two dashes. Help : String := ""; -- Help string for the argument. type Arg_Type is private; -- Type of the option. with function Convert (Arg : String) return Arg_Type is <>; -- Conversion function to convert from a raw string argument to the -- argument type. Default_Val : Arg_Type; -- Default value if the option is not passed. Enabled : Boolean := True; -- Whether to add this argument parser package Parse_Option_With_Default is function Get (Args : Parsed_Arguments := No_Parsed_Arguments) return Arg_Type; end Parse_Option_With_Default; -- Parse a regular option. A regular option is of the form "--option val", -- or "--option=val", or "-O val", or "-Oval". If option is not passed, -- takes the default value. If no "val" is given for the option, takes the -- Default_If_Empty value. end GNATCOLL.Opt_Parse.Extension;
with Ada.Unchecked_Deallocation; package body Tree_Naive_Pointers is procedure initialize is begin Reset(g); end; procedure make_node(n: out NodePtr; x: Integer) is begin n := new Node; n.x := x; n.y := Random(g); end make_node; procedure delete_node(n: in out NodePtr) is procedure free is new Ada.Unchecked_Deallocation(Object => Node, Name => NodePtr); begin if n /= null then if n.left /= null then delete_node(n.left); end if; if n.right /= null then delete_node(n.right); end if; free(n); end if; end delete_node; function merge(lower, greater: NodePtr) return NodePtr is begin if lower = null then return greater; end if; if greater = null then return lower; end if; if lower.y < greater.y then lower.right := merge(lower.right, greater); return lower; else greater.left := merge(lower, greater.left); return greater; end if; end merge; function merge(lower, equal, greater: NodePtr) return NodePtr is begin return merge(merge(lower, equal), greater); end merge; procedure split(orig: NodePtr; lower, greaterOrEqual: in out NodePtr; val: Integer) is begin if orig = null then lower := null; greaterOrEqual := null; return; end if; if orig.x < val then lower := orig; split(lower.right, lower.right, greaterOrEqual, val); else greaterOrEqual := orig; split(greaterOrEqual.left, lower, greaterOrEqual.left, val); end if; end split; procedure split(orig: NodePtr; lower, equal, greater: in out NodePtr; val: Integer) is equalOrGreater: NodePtr; begin split(orig, lower, equalOrGreater, val); split(equalOrGreater, equal, greater, val + 1); end split; function hasValue(t: in out Tree; x: Integer) return Boolean is lower, equal, greater: NodePtr; result: Boolean; begin split(t.root, lower, equal, greater, x); result := equal /= null; t.root := merge(lower, equal, greater); return result; end hasValue; procedure insert(t: in out Tree; x: Integer) is lower, equal, greater: NodePtr; begin split(t.root, lower, equal, greater, x); if equal = null then make_node(equal, x); end if; t.root := merge(lower, equal, greater); end insert; procedure erase(t: in out Tree; x: Integer) is lower, equal, greater: NodePtr; begin split(t.root, lower, equal, greater, x); t.root := merge(lower, greater); -- commenting out the following line -- doesn't seem to affect running time by much, if at all delete_node(equal); end erase; end Tree_Naive_Pointers;
----------------------------------------------------------------------- -- package Runge_Coeffs_PD_8, coefficients for Prince-Dormand Runge Kutta -- Copyright (C) 2008-2018 Jonathan S. Parker. -- -- Permission to use, copy, modify, and/or distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ------------------------------------------------------------------------------- -- package Runge_Coeffs_PD_8 -- -- Package contains coefficients for the Prince-Dormand -- 8th order, 13 stage Runge Kutta method with error control. -- -- You have a choice between the old 17 significant figure coefficients -- and newer ones, given to about 28 significant figures. -- The older ones are entered in rational form. -- -- A test routine is provided to make make sure that they -- have not been corrupted. If the coefficients do not pass -- the tests, then they are given in redundant and alternate -- forms at the end of this package (commented out). -- -- Reference: "High Order Embedded Runge-Kutta Formulae" by P.J. -- Prince and J.R. Dormand, J. Comp. Appl. Math.,7, pp. 67-75, 1981. -- -- -- NOTES ON THE ALGORITHM -- -- Given a differential equ. dY/dt = F(t,Y) and an initial condition -- Y(t), the Runge-Kutta formulas predict a new value of Y at -- Y(t + h) with the formula -- -- max -- Y(t + h) = Y(t) + SUM (K(j) * B(j)) -- j=1 -- -- where max = Stages'Last, (which equals 13 here, since this is a 13 -- stage Runge-Kutta formula) where the quantities K are calculated from -- -- K(1) = h * F(t, Y(t)) -- -- j-1 -- K(j) = h * F (t + C(j)*h, Y(t) + SUM (K(i)*A(j,i)) ) -- i=1 -- -- The Fehberg method, used here, provides two versions of the array -- B, so that Y(t + h) may be calculated to both 7th order and to -- 8th order using the same K(i)'s. This way, the local truncation -- error can be estimated without calculating the K(i)'s twice. -- -- If we apply this formula to a time-independent linear F, then we can -- derive a condition that can be used to test the correctness of the -- initialization values of the arrays A, B and C. To derive such a -- formula we use the fact that the RK prediction of Y(t + h) must equal -- the Taylor series prediction up to the required order. So, -- -- K(1) = h*F*Y (where F now is a matrix, and Y a vector) -- -- K(2) = h*F*(Y + K(1)*A21) -- -- K(3) = h*F*(Y + K(1)*A31 + K(2)*A32) -- -- K(4) = h*F*(Y + K(1)*A41 + K(2)*A42 + K(3)*A43) -- -- The linearity of F implies that F(a*Y + Z) = a*F*Y + F*Z so: -- -- K(1) = h*F*Y -- -- K(2) = h*F*Y + A21*h^2*F^2*Y -- -- K(3) = h*F*Y + (A31 + A32)*h^2*F^2*Y + A32*A21*h^3*F^3*Y -- -- K(4) = h*F*Y + (A41+A42+A43)*h^2*F^2*Y + (A42*A21+A43*A31)h^3*F^3*Y -- + A43*A32*A21*h^4F^4*Y -- -- Now we use the fact that we must have the RK prediction equal that -- of the Taylor's series up to a certain order: -- -- max -- SUM (K(j) * B(j)) = h*F*Y + ... + (1/n!)*h^n*F^n*Y + O(h^n+1) -- j=1 -- -- Here n=8 for the coefficients B = B8 given below. Its n=7 for B7. -- The above formula gives us a relation between 1/n! and B and A. -- This formula is used in the procedure TestRKPD given at the end -- of this package. We see immediately that we must have: -- -- max -- SUM (B(i)) = 1/1! -- i=1 -- -- max i-1 -- SUM (B(i) * SUM(Aij)) = 1/2! -- i=2 j=1 -- --*************************************************************** generic type Real is digits <>; package Runge_Coeffs_PD_8 is subtype RK_Range is Integer range 0..12; subtype Stages is RK_Range range 0..12; -- always 0 .. 12 type Coefficient is array(RK_Range) of Real; type Coefficient_Array is array(RK_Range) of Coefficient; -- At the bottom a renaming is used to choose which -- version of the Coefficients to use: -- -- A_rational are good to about 17 decimal digits. -- A_extended are good to about 28 decimal digits. -- --C : Coefficient renames C_extended; --B7 : Coefficient renames B7_extended; --B8 : Coefficient renames B8_extended; --A : Coefficient_Array renames A_extended; procedure Test_Runge_Coeffs; -- Below the Coefficients A, B, and C are given to -- 18 significant figures, in rational form. -- coefficients C(0..12) for getting Dt C_rational : constant Coefficient := (0.0, 1.0 / 18.0, 1.0 / 12.0, 1.0 / 8.0, 5.0 / 16.0, 3.0 / 8.0, 59.0 / 400.0, 93.0 / 200.0, 5490023248.0 / 9719169821.0, 13.0 / 20.0, 1201146811.0 / 1299019798.0, 1.0, 1.0, others => 0.0); -- eighth order RKPD coefficients B8(0..12) -- so that Y(t + DeltaT) = Y(t) + SUM(B8*K) B8_rational : constant Coefficient := (14005451.0 / 335480064.0, 0.0, 0.0, 0.0, 0.0, -59238493.0 / 1068277825.0, 181606767.0 / 758867731.0, 561292985.0 / 797845732.0, -1041891430.0 / 1371343529.0, 760417239.0 / 1151165299.0, 118820643.0 / 751138087.0, -528747749.0 / 2220607170.0, 0.25, others => 0.0); -- Seventh order RKPD coefficients B7(0..12) -- so that Y(t + DeltaT) = Y(t) + SUM(B7*K) B7_rational : constant Coefficient := (13451932.0 / 455176623.0, 0.0, 0.0, 0.0, 0.0, -808719846.0 / 976000145.0, 1757004468.0 / 5645159321.0, 656045339.0 / 265891186.0, -3867574721.0 / 1518517206.0, 465885868.0 / 322736535.0, 53011238.0 / 667516719.0, 2.0 / 45.0, others => 0.0); -- The Runge-Kutta matrix for calculating K: A_rational : constant Coefficient_Array := ((others => 0.0), -- coefficients A(1)(0..12) for getting K(1), -- so K(1) = DeltaT*F (Time + Dt(1), Y + SUM (A(1), K)) -- A(1): (1.0 / 18.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(2)(0..12) for getting K(2), -- so K(2) = DeltaT*F (Time + Dt(2),Y+SUM(A2,K)) -- A(2): (1.0 / 48.0, 1.0 / 16.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(3)(0..12) for getting K(3) -- so K4 = DeltaT*F (Time + Dt(3), Y + SUM (A(3), K)) (1.0 / 32.0, 0.0, 3.0 / 32.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(4)(0..12) for getting K(4) (5.0 / 16.0, 0.0, -75.0 / 64.0, 75.0 / 64.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(5)(0..12) for getting K(5) (3.0 / 80.0, 0.0, 0.0, 3.0 / 16.0, 3.0 / 20.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(6)(0..12) for getting K(6) (29443841.0 / 614563906.0, 0.0, 0.0, 77736538.0 / 692538347.0, -28693883.0 / 1125000000.0, 23124283.0 / 1800000000.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(7)(0..12) for getting K(7) (16016141.0 / 946692911.0, 0.0, 0.0, 61564180.0 / 158732637.0, 22789713.0 / 633445777.0, 545815736.0 / 2771057229.0, -180193667.0 / 1043307555.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(8)(0..12) for getting K(9) (39632708.0 / 573591083.0, 0.0, 0.0, -433636366.0 / 683701615.0, -421739975.0 / 2616292301.0, 100302831.0 / 723423059.0, 790204164.0 / 839813087.0, 800635310.0 / 3783071287.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(9)(0..12) for getting K(9) (246121993.0 / 1340847787.0, 0.0, 0.0, -37695042795.0 / 15268766246.0, -309121744.0 / 1061227803.0, -12992083.0 / 490766935.0, 6005943493.0 / 2108947869.0, 393006217.0 / 1396673457.0, 123872331.0 / 1001029789.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(10)(0..12) for getting K(10) (-1028468189.0 / 846180014.0, 0.0, 0.0, 8478235783.0 / 508512852.0, 1311729495.0 / 1432422823.0, -10304129995.0 / 1701304382.0, -48777925059.0 / 3047939560.0, 15336726248.0 / 1032824649.0, -45442868181.0 / 3398467696.0, 3065993473.0 / 597172653.0, 0.0, 0.0, others => 0.0), -- coefficients A(11)(0..12) for getting K(11) (185892177.0 / 718116043.0, 0.0, 0.0, -3185094517.0 / 667107341.0, -477755414.0 / 1098053517.0, -703635378.0 / 230739211.0, 5731566787.0 / 1027545527.0, 5232866602.0 / 850066563.0, -4093664535.0 / 808688257.0, 3962137247.0 / 1805957418.0, 65686358.0 / 487910083.0, 0.0, others => 0.0), -- coefficients A(12)(0..12) for getting K(12) (403863854.0 / 491063109.0, 0.0, 0.0, -5068492393.0 / 434740067.0, -411421997.0 / 543043805.0, 652783627.0 / 914296604.0, 11173962825.0 / 925320556.0, -13158990841.0 / 6184727034.0, 3936647629.0 / 1978049680.0, -160528059.0 / 685178525.0, 248638103.0 / 1413531060.0, 0.0, others => 0.0), others => (others => 0.0)); -- Below the Coefficients A, B, and C are given to (usually) -- 28 significant figures. -- coefficients C(0..12) for getting Dt C_extended : constant Coefficient := (0.0, 5.5555555555555555555555555555556E-02, 8.3333333333333333333333333333333E-02, 1.25E-01, 3.125E-01, 3.75E-01, 1.475E-01, 4.65E-01, 5.64865451382259575398358501426E-01, 6.5E-01, 9.24656277640504446745013574318E-01, 1.0, 1.0, others => 0.0); -- eighth order RKPD coefficients B8(0..12) -- so that Y(t + DeltaT) = Y(t) + SUM(B8*K) B8_extended : constant Coefficient := (4.17474911415302462220859284685E-02, 0.0, 0.0, 0.0, 0.0, -5.54523286112393089615218946547E-02, 2.39312807201180097046747354249E-01, 7.0351066940344302305804641089E-01, -7.59759613814460929884487677085E-01, 6.60563030922286341461378594838E-01, 1.58187482510123335529614838601E-01, -2.38109538752862804471863555306E-01, 0.25, others => 0.0); -- Seventh order RKPD coefficients B7(0..12) -- so that Y(t + DeltaT) = Y(t) + SUM(B7*K) B7_extended : constant Coefficient := (2.9553213676353496981964883112E-02, 0.0, 0.0, 0.0, 0.0, -8.28606276487797039766805612689E-01, 3.11240900051118327929913751627E-01, 2.46734519059988698196468570407E+00, -2.54694165184190873912738007542E+00, 1.44354858367677524030187495069E+00, 7.94155958811272872713019541622E-02, 4.4444444444444444444444444444444E-02, 0.0, others => 0.0); -- Here is the Runge-Kutta matrix for calculating K A_extended : constant Coefficient_Array := -- coefficients A(1)(0..12) for getting K(1), -- so K(2) = DeltaT*F (Time + Dt(1), Y + SUM (A(1), K)) -- A(2): ((others => 0.0), (1.0 / 18.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(2)(0..12) for getting K(2), -- so K(3) = DeltaT*F (Time + Dt(2),Y+SUM(A(2),K)) -- A(3): (1.0 / 48.0, 1.0 / 16.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(3)(0..12) for getting K(3) -- so K4 = DeltaT*F (Time + Dt(3), Y + SUM (A(3), K)) (1.0 / 32.0, 0.0, 3.0 / 32.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(4)(0..12) for getting K(4) -- so K(5) = DeltaT*F (Time + Dt(4), Y + SUM (A(4), K)) (5.0 / 16.0, 0.0, -75.0 / 64.0, 75.0 / 64.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(5)(0..12) for getting K(5) -- so K6 = DeltaT*F (Time + Dt(5),Y+SUM(A(5),K)) (3.0 / 80.0, 0.0, 0.0, 3.0 / 16.0, 3.0 / 20.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(6)(0..12) for getting K(6) -- so K7 = DeltaT*F (Time + Dt(6),Y+SUM(A(6),K)) (4.7910137111111111111111111111111E-02, 0.0, 0.0, 1.1224871277777777777777777777778E-01, -2.5505673777777777777777777777778E-02, 1.2846823888888888888888888888889E-02, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(7)(0..12) for getting K(7) -- so K(8) = DeltaT*F (Time + Dt(7), Y + SUM (A(7), K)) (1.6917989787292281181431107136E-02, 0.0, 0.0, 3.87848278486043169526545744159E-01, 3.59773698515003278967008896348E-02, 1.96970214215666060156715256072E-01, -1.72713852340501838761392997002E-01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(8)(0..12) for getting K(8) -- so K(9) = DeltaT*F (Time + Dt(8),Y + SUM (A(8), K)) (6.90957533591923006485645489846E-02, 0.0, 0.0, -6.34247976728854151882807874972E-01, -1.61197575224604080366876923982E-01, 1.38650309458825255419866950133E-01, 9.4092861403575626972423968413E-01, 2.11636326481943981855372117132E-01, 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(9)(0..12) for getting K(9) -- so K(10) = DeltaT*F (Time + Dt(9),Y + SUM (A(9), K)) (1.83556996839045385489806023537E-01, 0.0, 0.0, -2.46876808431559245274431575997E+00, -2.91286887816300456388002572804E-01, -2.6473020233117375688439799466E-02, 2.84783876419280044916451825422E+00, 2.81387331469849792539403641827E-01, 1.23744899863314657627030212664E-01, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(10)(0..12) for getting K(10) -- so K(11) = DeltaT*F (Time + Dt(10),Y + SUM (A(10), K)) (-1.21542481739588805916051052503E+00, 0.0, 0.0, 1.66726086659457724322804132886E+01, 9.15741828416817960595718650451E-01, -6.05660580435747094755450554309E+00, -1.60035735941561781118417064101E+01, 1.4849303086297662557545391898E+01, -1.33715757352898493182930413962E+01, 5.13418264817963793317325361166E+00, 0.0, 0.0, 0.0, others => 0.0), -- coefficients A(11)(0..12) for getting K(11) -- so K(12) = DeltaT*F (Time + Dt(11),Y + SUM (A(11), K)) (2.58860916438264283815730932232E-01, 0.0, 0.0, -4.77448578548920511231011750971E+00, -4.3509301377703250944070041181E-01, -3.04948333207224150956051286631E+00, 5.57792003993609911742367663447E+00, 6.15583158986104009733868912669E+00, -5.06210458673693837007740643391E+00, 2.19392617318067906127491429047E+00, 1.34627998659334941535726237887E-01, 0.0, 0.0, others => 0.0), -- coefficients A(12)(0..12) for getting K(12) -- so K(13) = DeltaT*F (Time + Dt(12),Y + SUM (A(12), K)) (8.22427599626507477963168204773E-01, 0.0, 0.0, -1.16586732572776642839765530355E+01, -7.57622116690936195881116154088E-01, 7.13973588159581527978269282765E-01, 1.20757749868900567395661704486E+01, -2.12765911392040265639082085897E+00, 1.99016620704895541832807169835E+00, -2.34286471544040292660294691857E-01, 1.7589857770794226507310510589E-01, 0.0, 0.0, others => 0.0), others => (others => 0.0)); --C : Coefficient renames C_rational; --B7 : Coefficient renames B7_rational; --B8 : Coefficient renames B8_rational; --A : Coefficient_Array renames A_rational; -- These are preferred for any Real'Digits > 15: C : Coefficient renames C_extended; B7 : Coefficient renames B7_extended; B8 : Coefficient renames B8_extended; A : Coefficient_Array renames A_extended; ----------------------------------------------------------------------- -- -- coefficients A(2)(0..12) for getting K(2), -- -- so K(2) = DeltaT*F (Time + Dt(2), Y + SUM (A(2), K)) -- -- A(2): -- ((1.0 / 18.0, -- 0.0, -- 0.0, 0.0, 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), -- -- -- -- coefficients A(3)(0..12) for getting K(3), -- -- so K(3) = DeltaT*F (Time + Dt(3),Y+SUM(A3,K)) -- -- A(3): -- (1.0 / 48.0, -- 1.0 / 16.0, -- 0.0, 0.0, 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), -- -- -- -- coefficients A(4)(0..12) for getting K(4) -- -- so K4 = DeltaT*F (Time + Dt(4), Y + SUM (A(4), K)) -- (1.0 / 32.0, -- 0.0, -- 3.0 / 32.0, -- 0.0, 0.0, 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0, 0.0), -- -- -- -- coefficients A(5)(0..12) for getting K(5) -- -- so K(5) = DeltaT*F (Time + Dt(5), Y + SUM (A(5), K)) -- (5.0 / 16.0, -- 0.0, -- -75.0 / 64.0, -- 75.0 / 64.0, -- 0.0, 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0, 0.0), -- -- -- -- coefficients A(6)(0..12) for getting K(6) -- -- so K6 = DeltaT*F (Time + Dt(6),Y+SUM(A6,K)) -- (3.0 / 80.0, -- 0.0, -- 0.0, -- 3.0 / 16.0, -- 3.0 / 20.0, -- 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0, 0.0), -- -- -- -- coefficients A(7)(0..12) for getting K(7) -- -- so K7 = DeltaT*F (Time + Dt(7),Y+SUM(A7,K)) -- (29443841.0 / 614563906.0, -- 0.0, -- 0.0, -- 77736538.0 / 692538347.0, -- -28693883.0 / 1125000000.0, -- 23124283.0 / 1800000000.0, -- 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0), -- -- -- -- coefficients A(8)(0..12) for getting K(8) -- -- so K(8) = DeltaT*F (Time + Dt(8), Y + SUM (A(8), K)) -- (16016141.0 / 946692911.0, -- 0.0, -- 0.0, -- 61564180.0 / 158732637.0, -- 22789713.0 / 633445777.0, -- 545815736.0 / 2771057229.0, -- -180193667.0 / 1043307555.0, -- 0.0, -- 0.0, 0.0, 0.0, 0.0, 0.0), -- -- -- -- coefficients A(9)(0..12) for getting K(9) -- -- so K(9) = DeltaT*F (Time + Dt(9),Y + SUM (A(9), K)) -- (39632708.0 / 573591083.0, -- 0.0, -- 0.0, -- -433636366.0 / 683701615.0, -- -421739975.0 / 2616292301.0, -- 100302831.0 / 723423059.0, -- 790204164.0 / 839813087.0, -- 800635310.0 / 3783071287.0, -- 0.0, -- 0.0, 0.0, 0.0, 0.0), -- -- -- -- coefficients A(10)(0..12) for getting K(10) -- -- so K(10) = DeltaT*F (Time + Dt(10),Y + SUM (A(10), K)) -- (246121993.0 / 1340847787.0, -- 0.0, -- 0.0, -- -37695042795.0 / 15268766246.0, -- -309121744.0 / 1061227803.0, -- -12992083.0 / 490766935.0, -- 6005943493.0 / 2108947869.0, -- 393006217.0 / 1396673457.0, -- 123872331.0 / 1001029789.0, -- 0.0, 0.0, 0.0, 0.0), -- -- -- -- coefficients A(11)(0..12) for getting K(11) -- -- so K(11) = DeltaT*F (Time + Dt(11),Y + SUM (A(11), K)) -- (-1028468189.0 / 846180014.0, -- 0.0, -- 0.0, -- 8478235783.0 / 508512852.0, -- 1311729495.0 / 1432422823.0, -- -10304129995.0 / 1701304382.0, -- -48777925059.0 / 3047939560.0, -- 15336726248.0 / 1032824649.0, -- -45442868181.0 / 3398467696.0, -- 3065993473.0 / 597172653.0, -- 0.0, 0.0, 0.0), -- -- -- -- coefficients A(12)(0..12) for getting K(12) -- -- so K(12) = DeltaT*F (Time + Dt(12),Y + SUM (A(12), K)) -- (185892177.0 / 718116043.0, -- 0.0, -- 0.0, -- -3185094517.0 / 667107341.0, -- -477755414.0 / 1098053517.0, -- -703635378.0 / 230739211.0, -- 5731566787.0 / 1027545527.0, -- 5232866602.0 / 850066563.0, -- -4093664535.0 / 808688257.0, -- 3962137247.0 / 1805957418.0, -- 65686358.0 / 487910083.0, -- 0.0, 0.0), -- -- -- -- coefficients A(13)(0..12) for getting K(13) -- -- so K(13) = DeltaT*F (Time + Dt(13),Y + SUM (A(13), K)) -- (403863854.0 / 491063109.0, -- 0.0, -- 0.0, -- -5068492393.0 / 434740067.0, -- -411421997.0 / 543043805.0, -- 652783627.0 / 914296604.0, -- 11173962825.0 / 925320556.0, -- -13158990841.0 / 6184727034.0, -- 3936647629.0 / 1978049680.0, -- -160528059.0 / 685178525.0, -- 248638103.0 / 1413531060.0, -- 0.0, 0.0)); -- -- This pair is from "High Order Embedded Runge-Kutta Formulae" by P.J. -- Prince and J.R. Dormand, J. Comp. Appl. Math.,7, pp. 67-75, 1981. -- These coefficients were taken from a public domain RK Suite written -- R. W. Brankin,I. Gladwell, and L. F. Shampine. They were calculated by -- Prince and Dormand. -- A(2,1) := 5.55555555555555555555555555556E-2 -- A(3,1) := 2.08333333333333333333333333333E-2 -- A(3,2) := 6.25E-2 -- A(4,1) := 3.125E-2 -- A(4,2) := 0.0 -- A(4,3) := 9.375E-2 -- A(5,1) := 3.125E-1 -- A(5,2) := 0.0 -- A(5,3) := -1.171875E0 -- A(5,4) := 1.171875E0 -- A(6,1) := 3.75E-2 -- A(6,2) := 0.0 -- A(6,3) := 0.0 -- A(6,4) := 1.875E-1 -- A(6,5) := 1.5E-1 -- A(7,1) := 4.79101371111111111111111111111E-2 -- A(7,2) := 0.0 -- A(7,3) := 0.0 -- A(7,4) := 1.12248712777777777777777777778E-1 -- A(7,5) := -2.55056737777777777777777777778E-2 -- A(7,6) := 1.28468238888888888888888888889E-2 -- A(8,1) := 1.6917989787292281181431107136E-2 -- A(8,2) := 0.0 -- A(8,3) := 0.0 -- A(8,4) := 3.87848278486043169526545744159E-1 -- A(8,5) := 3.59773698515003278967008896348E-2 -- A(8,6) := 1.96970214215666060156715256072E-1 -- A(8,7) := -1.72713852340501838761392997002E-1 -- A(9,1) := 6.90957533591923006485645489846E-2 -- A(9,2) := 0.0 -- A(9,3) := 0.0 -- A(9,4) := -6.34247976728854151882807874972E-1 -- A(9,5) := -1.61197575224604080366876923982E-1 -- A(9,6) := 1.38650309458825255419866950133E-1 -- A(9,7) := 9.4092861403575626972423968413E-1 -- A(9,8) := 2.11636326481943981855372117132E-1 -- A(10,1) := 1.83556996839045385489806023537E-1 -- A(10,2) := 0.0 -- A(10,3) := 0.0 -- A(10,4) := -2.46876808431559245274431575997E0 -- A(10,5) := -2.91286887816300456388002572804E-1 -- A(10,6) := -2.6473020233117375688439799466E-2 -- A(10,7) := 2.84783876419280044916451825422E0 -- A(10,8) := 2.81387331469849792539403641827E-1 -- A(10,9) := 1.23744899863314657627030212664E-1 -- A(11,1) := -1.21542481739588805916051052503E0 -- A(11,2) := 0.0 -- A(11,3) := 0.0 -- A(11,4) := 1.66726086659457724322804132886E1 -- A(11,5) := 9.15741828416817960595718650451E-1 -- A(11,6) := -6.05660580435747094755450554309E0 -- A(11,7) := -1.60035735941561781118417064101E1 -- A(11,8) := 1.4849303086297662557545391898E1 -- A(11,9) := -1.33715757352898493182930413962E1 -- A(11,10) := 5.13418264817963793317325361166E0 -- A(12,1) := 2.58860916438264283815730932232E-1 -- A(12,2) := 0.0 -- A(12,3) := 0.0 -- A(12,4) := -4.77448578548920511231011750971E0 -- A(12,5) := -4.3509301377703250944070041181E-1 -- A(12,6) := -3.04948333207224150956051286631E0 -- A(12,7) := 5.57792003993609911742367663447E0 -- A(12,8) := 6.15583158986104009733868912669E0 -- A(12,9) := -5.06210458673693837007740643391E0 -- A(12,10) := 2.19392617318067906127491429047E0 -- A(12,11) := 1.34627998659334941535726237887E-1 -- A(13,1) := 8.22427599626507477963168204773E-1 -- A(13,2) := 0.0 -- A(13,3) := 0.0 -- A(13,4) := -1.16586732572776642839765530355E1 -- A(13,5) := -7.57622116690936195881116154088E-1 -- A(13,6) := 7.13973588159581527978269282765E-1 -- A(13,7) := 1.20757749868900567395661704486E1 -- A(13,8) := -2.12765911392040265639082085897E0 -- A(13,9) := 1.99016620704895541832807169835E0 -- A(13,10) := -2.34286471544040292660294691857E-1 -- A(13,11) := 1.7589857770794226507310510589E-1 -- A(13,12) := 0.0 -- -- B8 : constant Coefficient := -- (4.17474911415302462220859284685E-2, -- 0.0, -- 0.0, -- 0.0, -- 0.0, -- -5.54523286112393089615218946547E-2, -- 2.39312807201180097046747354249E-1, -- 7.0351066940344302305804641089E-1, -- -7.59759613814460929884487677085E-1, -- 6.60563030922286341461378594838E-1, -- 1.58187482510123335529614838601E-1, -- -2.38109538752862804471863555306E-1, -- 2.5E-1); -- -- B7 : constant Coefficient := -- (2.9553213676353496981964883112E-2, -- 0.0, -- 0.0, -- 0.0, -- 0.0, -- -8.28606276487797039766805612689E-1, -- 3.11240900051118327929913751627E-1, -- 2.46734519059988698196468570407E0, -- -2.54694165184190873912738007542E0, -- 1.44354858367677524030187495069E0, -- 7.94155958811272872713019541622E-2, -- 4.44444444444444444444444444445E-2, -- 0.0); -- -- C : constant Coefficient := -- (0.0, -- 5.55555555555555555555555555556E-2, -- 8.33333333333333333333333333334E-2, -- 1.25E-1, -- 3.125E-1, -- 3.75E-1, -- 1.475E-1, -- 4.65E-1, -- 5.64865451382259575398358501426E-1, -- 6.5E-1, -- 9.24656277640504446745013574318E-1, -- 1.0, -- 1.0); --**************coefficients C(0..12) for getting Dt******* -- C : constant Coefficient := -- (0.0, -- 5.5555555555555555555555555555556E-02, -- 8.3333333333333333333333333333333E-02, -- 1.25E-01, -- 3.125E-01, -- 3.75E-01, -- 1.475E-01, -- 4.65E-01, -- 5.64865451382259575398358501426E-01, -- 6.5E-01, -- 9.24656277640504446745013574318E-01, -- 1.0, -- 1.0, -- others => 0.0); -- -- --*******eighth order RKPD coefficients B8(0..12)******* -- --******so that Y(t + DeltaT) = Y(t) + SUM(B8*K)***** -- B8 : constant Coefficient := -- (4.17474911415302462220859284685E-02, -- 0.0, -- 0.0, -- 0.0, -- 0.0, -- -5.54523286112393089615218946547E-02, -- 2.39312807201180097046747354249E-01, -- 7.0351066940344302305804641089E-01, -- -7.59759613814460929884487677085E-01, -- 6.60563030922286341461378594838E-01, -- 1.58187482510123335529614838601E-01, -- -2.38109538752862804471863555306E-01, -- 0.25, others => 0.0); -- -- --*******Seventh order RKPD coefficients B7(0..12)******* -- --******so that Y(t + DeltaT) = Y(t) + SUM(B7*K)***** -- B7 : constant Coefficient := -- (2.9553213676353496981964883112E-02, -- 0.0, -- 0.0, -- 0.0, -- 0.0, -- -8.28606276487797039766805612689E-01, -- 3.11240900051118327929913751627E-01, -- 2.46734519059988698196468570407E+00, -- -2.54694165184190873912738007542E+00, -- 1.44354858367677524030187495069E+00, -- 7.94155958811272872713019541622E-02, -- 4.4444444444444444444444444444444E-02, -- others => 0.0); -- -- -- -- Here is the Runge-Kutta matrix for calculating K -- -- A : constant Coefficient_Array := -- -- -- -- coefficients A(2)(0..12) for getting K(2), -- -- so K(2) = DeltaT*F (Time + Dt(2), Y + SUM (A(2), K)) -- -- A(2): -- ((1.0 / 18.0, -- 0.0, -- 0.0, 0.0, 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- -- -- -- coefficients A(3)(0..12) for getting K(3), -- -- so K(3) = DeltaT*F (Time + Dt(3),Y+SUM(A3,K)) -- -- A(3): -- (1.0 / 48.0, -- 1.0 / 16.0, -- 0.0, 0.0, 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0, 0.0, others => 0.0), -- -- -- -- coefficients A(4)(0..12) for getting K(4) -- -- so K4 = DeltaT*F (Time + Dt(4), Y + SUM (A(4), K)) -- (1.0 / 32.0, -- 0.0, -- 3.0 / 32.0, -- 0.0, 0.0, 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0, others => 0.0), -- -- -- -- coefficients A(5)(0..12) for getting K(5) -- -- so K(5) = DeltaT*F (Time + Dt(5), Y + SUM (A(5), K)) -- (5.0 / 16.0, -- 0.0, -- -75.0 / 64.0, -- 75.0 / 64.0, -- 0.0, 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0, others => 0.0), -- -- -- -- coefficients A(6)(0..12) for getting K(6) -- -- so K6 = DeltaT*F (Time + Dt(6),Y+SUM(A6,K)) -- (3.0 / 80.0, -- 0.0, -- 0.0, -- 3.0 / 16.0, -- 3.0 / 20.0, -- 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, 0.0, others => 0.0), -- -- -- -- coefficients A(7)(0..12) for getting K(7) -- -- so K7 = DeltaT*F (Time + Dt(7),Y+SUM(A7,K)) -- (4.7910137111111111111111111111111E-02, -- 0.0, -- 0.0, -- 1.1224871277777777777777777777778E-01, -- -2.5505673777777777777777777777778E-02, -- 1.2846823888888888888888888888889E-02, -- 0.0, 0.0, 0.0, -- 0.0, 0.0, 0.0, others => 0.0), -- -- -- -- coefficients A(8)(0..12) for getting K(8) -- -- so K(8) = DeltaT*F (Time + Dt(8), Y + SUM (A(8), K)) -- (1.6917989787292281181431107136E-02, -- 0.0, -- 0.0, -- 3.87848278486043169526545744159E-01, -- 3.59773698515003278967008896348E-02, -- 1.96970214215666060156715256072E-01, -- -1.72713852340501838761392997002E-01, -- 0.0, -- 0.0, 0.0, 0.0, 0.0, others => 0.0), -- -- -- -- coefficients A(9)(0..12) for getting K(9) -- -- so K(9) = DeltaT*F (Time + Dt(9),Y + SUM (A(9), K)) -- (6.90957533591923006485645489846E-02, -- 0.0, -- 0.0, -- -6.34247976728854151882807874972E-01, -- -1.61197575224604080366876923982E-01, -- 1.38650309458825255419866950133E-01, -- 9.4092861403575626972423968413E-01, -- 2.11636326481943981855372117132E-01, -- 0.0, -- 0.0, 0.0, 0.0, others => 0.0), -- -- -- -- coefficients A(10)(0..12) for getting K(10) -- -- so K(10) = DeltaT*F (Time + Dt(10),Y + SUM (A(10), K)) -- (1.83556996839045385489806023537E-01, -- 0.0, -- 0.0, -- -2.46876808431559245274431575997E+00, -- -2.91286887816300456388002572804E-01, -- -2.6473020233117375688439799466E-02, -- 2.84783876419280044916451825422E+00, -- 2.81387331469849792539403641827E-01, -- 1.23744899863314657627030212664E-01, -- 0.0, 0.0, 0.0, others => 0.0), -- -- -- -- coefficients A(11)(0..12) for getting K(11) -- -- so K(11) = DeltaT*F (Time + Dt(11),Y + SUM (A(11), K)) -- (-1.21542481739588805916051052503E+00, -- 0.0, -- 0.0, -- 1.66726086659457724322804132886E+01, -- 9.15741828416817960595718650451E-01, -- -6.05660580435747094755450554309E+00, -- -1.60035735941561781118417064101E+01, -- 1.4849303086297662557545391898E+01, -- -1.33715757352898493182930413962E+01, -- 5.13418264817963793317325361166E+00, -- 0.0, 0.0, others => 0.0), -- -- -- -- coefficients A(12)(0..12) for getting K(12) -- -- so K(12) = DeltaT*F (Time + Dt(12),Y + SUM (A(12), K)) -- (2.58860916438264283815730932232E-01, -- 0.0, -- 0.0, -- -4.77448578548920511231011750971E+00, -- -4.3509301377703250944070041181E-01, -- -3.04948333207224150956051286631E+00, -- 5.57792003993609911742367663447E+00, -- 6.15583158986104009733868912669E+00, -- -5.06210458673693837007740643391E+00, -- 2.19392617318067906127491429047E+00, -- 1.34627998659334941535726237887E-01, -- 0.0, others => 0.0), -- -- -- -- coefficients A(13)(0..12) for getting K(13) -- -- so K(13) = DeltaT*F (Time + Dt(13),Y + SUM (A(13), K)) -- (8.22427599626507477963168204773E-01, -- 0.0, -- 0.0, -- -1.16586732572776642839765530355E+01, -- -7.57622116690936195881116154088E-01, -- 7.13973588159581527978269282765E-01, -- 1.20757749868900567395661704486E+01, -- -2.12765911392040265639082085897E+00, -- 1.99016620704895541832807169835E+00, -- -2.34286471544040292660294691857E-01, -- 1.7589857770794226507310510589E-01, -- 0.0, others => 0.0)); end Runge_Coeffs_PD_8;
----------------------------------------------------------------------- -- akt -- Ada Keystore Tool -- Copyright (C) 2019, 2021 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Util.Log.Loggers; with Util.Properties; package body AKT is -- ------------------------------ -- Configure the logs. -- ------------------------------ procedure Configure_Logs (Debug : in Boolean; Dump : in Boolean; Verbose : in Boolean) is Log_Config : Util.Properties.Manager; begin Log_Config.Set ("log4j.rootCategory", "ERROR,errorConsole"); Log_Config.Set ("log4j.appender.errorConsole", "Console"); Log_Config.Set ("log4j.appender.errorConsole.level", "ERROR"); Log_Config.Set ("log4j.appender.errorConsole.layout", "message"); Log_Config.Set ("log4j.appender.errorConsole.stderr", "true"); Log_Config.Set ("log4j.appender.errorConsole.prefix", "akt: "); Log_Config.Set ("log4j.logger.Util", "FATAL"); Log_Config.Set ("log4j.logger.Util.Events", "ERROR"); Log_Config.Set ("log4j.logger.Keystore", "ERROR"); Log_Config.Set ("log4j.logger.AKT", "ERROR"); if Verbose or Debug or Dump then Log_Config.Set ("log4j.logger.Util", "WARN"); Log_Config.Set ("log4j.logger.AKT", "INFO"); Log_Config.Set ("log4j.logger.Keystore.IO", "WARN"); Log_Config.Set ("log4j.logger.Keystore", "INFO"); Log_Config.Set ("log4j.rootCategory", "INFO,errorConsole,verbose"); Log_Config.Set ("log4j.appender.verbose", "Console"); Log_Config.Set ("log4j.appender.verbose.level", "INFO"); Log_Config.Set ("log4j.appender.verbose.layout", "level-message"); end if; if Debug or Dump then Log_Config.Set ("log4j.logger.Util.Processes", "INFO"); Log_Config.Set ("log4j.logger.AKT", "DEBUG"); Log_Config.Set ("log4j.logger.Keystore.IO", "INFO"); Log_Config.Set ("log4j.logger.Keystore", "DEBUG"); Log_Config.Set ("log4j.rootCategory", "DEBUG,errorConsole,debug"); Log_Config.Set ("log4j.appender.debug", "Console"); Log_Config.Set ("log4j.appender.debug.level", "DEBUG"); Log_Config.Set ("log4j.appender.debug.layout", "full"); end if; if Dump then Log_Config.Set ("log4j.logger.Keystore.IO", "DEBUG"); end if; Util.Log.Loggers.Initialize (Log_Config); end Configure_Logs; end AKT;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- G N A T . A L T I V E C . V E C T O R _ T Y P E S -- -- -- -- S p e c -- -- -- -- Copyright (C) 2004-2005, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This unit exposes the various vector types part of the Ada binding to -- Altivec facilities. with GNAT.Altivec.Low_Level_Vectors; package GNAT.Altivec.Vector_Types is use GNAT.Altivec.Low_Level_Vectors; --------------------------------------------------- -- Vector type declarations [PIM-2.1 Data Types] -- --------------------------------------------------- -- Except for assignments and pointer creation/dereference, operations -- on vectors are only performed via subprograms. The vector types are -- then private, and non-limited since assignments are allowed. -- The Hard/Soft binding type-structure differentiation is achieved in -- Low_Level_Vectors. Each version only exposes private vector types, that -- we just sub-type here. This is fine from the design standpoint and -- reduces the amount of explicit conversion required in various places -- internally. subtype vector_unsigned_char is Low_Level_Vectors.LL_VUC; subtype vector_signed_char is Low_Level_Vectors.LL_VSC; subtype vector_bool_char is Low_Level_Vectors.LL_VBC; subtype vector_unsigned_short is Low_Level_Vectors.LL_VUS; subtype vector_signed_short is Low_Level_Vectors.LL_VSS; subtype vector_bool_short is Low_Level_Vectors.LL_VBS; subtype vector_unsigned_int is Low_Level_Vectors.LL_VUI; subtype vector_signed_int is Low_Level_Vectors.LL_VSI; subtype vector_bool_int is Low_Level_Vectors.LL_VBI; subtype vector_float is Low_Level_Vectors.LL_VF; subtype vector_pixel is Low_Level_Vectors.LL_VP; -- [PIM-2.1] shows groups of declarations with exact same component types, -- e.g. vector unsigned short together with vector unsigned short int. It -- so appears tempting to define subtypes for those matches here. -- -- [PIM-2.1] does not qualify items in those groups as "the same types", -- though, and [PIM-2.4.2 Assignments] reads: "if either the left hand -- side or the right hand side of an expression has a vector type, then -- both sides of the expression must be of the same vector type". -- -- Not so clear what is exactly right, then. We go with subtypes for now -- and can adjust later if need be. subtype vector_unsigned_short_int is vector_unsigned_short; subtype vector_signed_short_int is vector_signed_short; subtype vector_char is vector_signed_char; subtype vector_short is vector_signed_short; subtype vector_int is vector_signed_int; -------------------------------- -- Corresponding access types -- -------------------------------- type vector_unsigned_char_ptr is access all vector_unsigned_char; type vector_signed_char_ptr is access all vector_signed_char; type vector_bool_char_ptr is access all vector_bool_char; type vector_unsigned_short_ptr is access all vector_unsigned_short; type vector_signed_short_ptr is access all vector_signed_short; type vector_bool_short_ptr is access all vector_bool_short; type vector_unsigned_int_ptr is access all vector_unsigned_int; type vector_signed_int_ptr is access all vector_signed_int; type vector_bool_int_ptr is access all vector_bool_int; type vector_float_ptr is access all vector_float; type vector_pixel_ptr is access all vector_pixel; -------------------------------------------------------------------- -- Additional access types, for the sake of some argument passing -- -------------------------------------------------------------------- -- ... because some of the operations expect pointers to possibly -- constant objects. type const_vector_bool_char_ptr is access constant vector_bool_char; type const_vector_signed_char_ptr is access constant vector_signed_char; type const_vector_unsigned_char_ptr is access constant vector_unsigned_char; type const_vector_bool_short_ptr is access constant vector_bool_short; type const_vector_signed_short_ptr is access constant vector_signed_short; type const_vector_unsigned_short_ptr is access constant vector_unsigned_short; type const_vector_bool_int_ptr is access constant vector_bool_int; type const_vector_signed_int_ptr is access constant vector_signed_int; type const_vector_unsigned_int_ptr is access constant vector_unsigned_int; type const_vector_float_ptr is access constant vector_float; type const_vector_pixel_ptr is access constant vector_pixel; ---------------------- -- Useful shortcuts -- ---------------------- subtype VUC is vector_unsigned_char; subtype VSC is vector_signed_char; subtype VBC is vector_bool_char; subtype VUS is vector_unsigned_short; subtype VSS is vector_signed_short; subtype VBS is vector_bool_short; subtype VUI is vector_unsigned_int; subtype VSI is vector_signed_int; subtype VBI is vector_bool_int; subtype VP is vector_pixel; subtype VF is vector_float; end GNAT.Altivec.Vector_Types;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ C H 1 0 -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Aspects; use Aspects; with Atree; use Atree; with Contracts; use Contracts; with Debug; use Debug; with Einfo; use Einfo; with Errout; use Errout; with Exp_Util; use Exp_Util; with Elists; use Elists; with Fname; use Fname; with Fname.UF; use Fname.UF; with Freeze; use Freeze; with Ghost; use Ghost; with Impunit; use Impunit; with Inline; use Inline; with Lib; use Lib; with Lib.Load; use Lib.Load; with Lib.Xref; use Lib.Xref; with Namet; use Namet; with Nlists; use Nlists; with Nmake; use Nmake; with Opt; use Opt; with Output; use Output; with Par_SCO; use Par_SCO; with Restrict; use Restrict; with Rident; use Rident; with Rtsfind; use Rtsfind; with Sem; use Sem; with Sem_Aux; use Sem_Aux; with Sem_Ch3; use Sem_Ch3; with Sem_Ch6; use Sem_Ch6; with Sem_Ch7; use Sem_Ch7; with Sem_Ch8; use Sem_Ch8; with Sem_Dist; use Sem_Dist; with Sem_Prag; use Sem_Prag; with Sem_Util; use Sem_Util; with Sem_Warn; use Sem_Warn; with Stand; use Stand; with Sinfo; use Sinfo; with Sinfo.CN; use Sinfo.CN; with Sinput; use Sinput; with Snames; use Snames; with Style; use Style; with Stylesw; use Stylesw; with Tbuild; use Tbuild; with Uname; use Uname; package body Sem_Ch10 is ----------------------- -- Local Subprograms -- ----------------------- procedure Analyze_Context (N : Node_Id); -- Analyzes items in the context clause of compilation unit procedure Build_Limited_Views (N : Node_Id); -- Build and decorate the list of shadow entities for a package mentioned -- in a limited_with clause. If the package was not previously analyzed -- then it also performs a basic decoration of the real entities. This is -- required in order to avoid passing non-decorated entities to the -- back-end. Implements Ada 2005 (AI-50217). procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id); -- Common processing for all stubs (subprograms, tasks, packages, and -- protected cases). N is the stub to be analyzed. Once the subunit name -- is established, load and analyze. Nam is the non-overloadable entity -- for which the proper body provides a completion. Subprogram stubs are -- handled differently because they can be declarations. procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id); -- Check whether the source for the body of a compilation unit must be -- included in a standalone library. procedure Check_No_Elab_Code_All (N : Node_Id); -- Carries out possible tests for violation of No_Elab_Code all for withed -- units in the Context_Items of unit N. procedure Check_Private_Child_Unit (N : Node_Id); -- If a with_clause mentions a private child unit, the compilation unit -- must be a member of the same family, as described in 10.1.2. procedure Check_Stub_Level (N : Node_Id); -- Verify that a stub is declared immediately within a compilation unit, -- and not in an inner frame. procedure Expand_With_Clause (Item : Node_Id; Nam : Node_Id; N : Node_Id); -- When a child unit appears in a context clause, the implicit withs on -- parents are made explicit, and with clauses are inserted in the context -- clause before the one for the child. If a parent in the with_clause -- is a renaming, the implicit with_clause is on the renaming whose name -- is mentioned in the with_clause, and not on the package it renames. -- N is the compilation unit whose list of context items receives the -- implicit with_clauses. procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id); -- Generate cross-reference information for the parents of child units -- and of subunits. N is a defining_program_unit_name, and P_Id is the -- immediate parent scope. function Has_With_Clause (C_Unit : Node_Id; Pack : Entity_Id; Is_Limited : Boolean := False) return Boolean; -- Determine whether compilation unit C_Unit contains a [limited] with -- clause for package Pack. Use the flag Is_Limited to designate desired -- clause kind. procedure Implicit_With_On_Parent (Child_Unit : Node_Id; N : Node_Id); -- If the main unit is a child unit, implicit withs are also added for -- all its ancestors. function In_Chain (E : Entity_Id) return Boolean; -- Check that the shadow entity is not already in the homonym chain, for -- example through a limited_with clause in a parent unit. procedure Install_Context_Clauses (N : Node_Id); -- Subsidiary to Install_Context and Install_Parents. Process all with -- and use clauses for current unit and its library unit if any. procedure Install_Limited_Context_Clauses (N : Node_Id); -- Subsidiary to Install_Context. Process only limited with_clauses for -- current unit. Implements Ada 2005 (AI-50217). procedure Install_Limited_Withed_Unit (N : Node_Id); -- Place shadow entities for a limited_with package in the visibility -- structures for the current compilation. Implements Ada 2005 (AI-50217). procedure Install_Withed_Unit (With_Clause : Node_Id; Private_With_OK : Boolean := False); -- If the unit is not a child unit, make unit immediately visible. The -- caller ensures that the unit is not already currently installed. The -- flag Private_With_OK is set true in Install_Private_With_Clauses, which -- is called when compiling the private part of a package, or installing -- the private declarations of a parent unit. procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean); -- This procedure establishes the context for the compilation of a child -- unit. If Lib_Unit is a child library spec then the context of the parent -- is installed, and the parent itself made immediately visible, so that -- the child unit is processed in the declarative region of the parent. -- Install_Parents makes a recursive call to itself to ensure that all -- parents are loaded in the nested case. If Lib_Unit is a library body, -- the only effect of Install_Parents is to install the private decls of -- the parents, because the visible parent declarations will have been -- installed as part of the context of the corresponding spec. procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id); -- In the compilation of a child unit, a child of any of the ancestor -- units is directly visible if it is visible, because the parent is in -- an enclosing scope. Iterate over context to find child units of U_Name -- or of some ancestor of it. function Is_Ancestor_Unit (U1 : Node_Id; U2 : Node_Id) return Boolean; -- When compiling a unit Q descended from some parent unit P, a limited -- with_clause in the context of P that names some other ancestor of Q -- must not be installed because the ancestor is immediately visible. function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean; -- Lib_Unit is a library unit which may be a spec or a body. Is_Child_Spec -- returns True if Lib_Unit is a library spec which is a child spec, i.e. -- a library spec that has a parent. If the call to Is_Child_Spec returns -- True, then Parent_Spec (Lib_Unit) is non-Empty and points to the -- compilation unit for the parent spec. -- -- Lib_Unit can also be a subprogram body that acts as its own spec. If the -- Parent_Spec is non-empty, this is also a child unit. procedure Remove_Context_Clauses (N : Node_Id); -- Subsidiary of previous one. Remove use_ and with_clauses procedure Remove_Limited_With_Clause (N : Node_Id); -- Remove from visibility the shadow entities introduced for a package -- mentioned in a limited_with clause. Implements Ada 2005 (AI-50217). procedure Remove_Parents (Lib_Unit : Node_Id); -- Remove_Parents checks if Lib_Unit is a child spec. If so then the parent -- contexts established by the corresponding call to Install_Parents are -- removed. Remove_Parents contains a recursive call to itself to ensure -- that all parents are removed in the nested case. procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id); -- Reset all visibility flags on unit after compiling it, either as a main -- unit or as a unit in the context. procedure Unchain (E : Entity_Id); -- Remove single entity from visibility list procedure sm; -- A dummy procedure, for debugging use, called just before analyzing the -- main unit (after dealing with any context clauses). -------------------------- -- Limited_With_Clauses -- -------------------------- -- Limited_With clauses are the mechanism chosen for Ada 2005 to support -- mutually recursive types declared in different units. A limited_with -- clause that names package P in the context of unit U makes the types -- declared in the visible part of P available within U, but with the -- restriction that these types can only be used as incomplete types. -- The limited_with clause does not impose a semantic dependence on P, -- and it is possible for two packages to have limited_with_clauses on -- each other without creating an elaboration circularity. -- To support this feature, the analysis of a limited_with clause must -- create an abbreviated view of the package, without performing any -- semantic analysis on it. This "package abstract" contains shadow types -- that are in one-one correspondence with the real types in the package, -- and that have the properties of incomplete types. -- The implementation creates two element lists: one to chain the shadow -- entities, and one to chain the corresponding type entities in the tree -- of the package. Links between corresponding entities in both chains -- allow the compiler to select the proper view of a given type, depending -- on the context. Note that in contrast with the handling of private -- types, the limited view and the non-limited view of a type are treated -- as separate entities, and no entity exchange needs to take place, which -- makes the implementation much simpler than could be feared. ------------------------------ -- Analyze_Compilation_Unit -- ------------------------------ procedure Analyze_Compilation_Unit (N : Node_Id) is procedure Check_Redundant_Withs (Context_Items : List_Id; Spec_Context_Items : List_Id := No_List); -- Determine whether the context list of a compilation unit contains -- redundant with clauses. When checking body clauses against spec -- clauses, set Context_Items to the context list of the body and -- Spec_Context_Items to that of the spec. Parent packages are not -- examined for documentation purposes. --------------------------- -- Check_Redundant_Withs -- --------------------------- procedure Check_Redundant_Withs (Context_Items : List_Id; Spec_Context_Items : List_Id := No_List) is Clause : Node_Id; procedure Process_Body_Clauses (Context_List : List_Id; Clause : Node_Id; Used : out Boolean; Used_Type_Or_Elab : out Boolean); -- Examine the context clauses of a package body, trying to match the -- name entity of Clause with any list element. If the match occurs -- on a use package clause set Used to True, for a use type clause or -- pragma Elaborate[_All], set Used_Type_Or_Elab to True. procedure Process_Spec_Clauses (Context_List : List_Id; Clause : Node_Id; Used : out Boolean; Withed : out Boolean; Exit_On_Self : Boolean := False); -- Examine the context clauses of a package spec, trying to match -- the name entity of Clause with any list element. If the match -- occurs on a use package clause, set Used to True, for a with -- package clause other than Clause, set Withed to True. Limited -- with clauses, implicitly generated with clauses and withs -- having pragmas Elaborate or Elaborate_All applied to them are -- skipped. Exit_On_Self is used to control the search loop and -- force an exit whenever Clause sees itself in the search. -------------------------- -- Process_Body_Clauses -- -------------------------- procedure Process_Body_Clauses (Context_List : List_Id; Clause : Node_Id; Used : out Boolean; Used_Type_Or_Elab : out Boolean) is Nam_Ent : constant Entity_Id := Entity (Name (Clause)); Cont_Item : Node_Id; Prag_Unit : Node_Id; Subt_Mark : Node_Id; Use_Item : Node_Id; function Same_Unit (N : Node_Id; P : Entity_Id) return Boolean; -- In an expanded name in a use clause, if the prefix is a renamed -- package, the entity is set to the original package as a result, -- when checking whether the package appears in a previous with -- clause, the renaming has to be taken into account, to prevent -- spurious/incorrect warnings. A common case is use of Text_IO. --------------- -- Same_Unit -- --------------- function Same_Unit (N : Node_Id; P : Entity_Id) return Boolean is begin return Entity (N) = P or else (Present (Renamed_Object (P)) and then Entity (N) = Renamed_Object (P)); end Same_Unit; -- Start of processing for Process_Body_Clauses begin Used := False; Used_Type_Or_Elab := False; Cont_Item := First (Context_List); while Present (Cont_Item) loop -- Package use clause if Nkind (Cont_Item) = N_Use_Package_Clause and then not Used then -- Search through use clauses Use_Item := First (Names (Cont_Item)); while Present (Use_Item) and then not Used loop -- Case of a direct use of the one we are looking for if Entity (Use_Item) = Nam_Ent then Used := True; -- Handle nested case, as in "with P; use P.Q.R" else declare UE : Node_Id; begin -- Loop through prefixes looking for match UE := Use_Item; while Nkind (UE) = N_Expanded_Name loop if Same_Unit (Prefix (UE), Nam_Ent) then Used := True; exit; end if; UE := Prefix (UE); end loop; end; end if; Next (Use_Item); end loop; -- USE TYPE clause elsif Nkind (Cont_Item) = N_Use_Type_Clause and then not Used_Type_Or_Elab then Subt_Mark := First (Subtype_Marks (Cont_Item)); while Present (Subt_Mark) and then not Used_Type_Or_Elab loop if Same_Unit (Prefix (Subt_Mark), Nam_Ent) then Used_Type_Or_Elab := True; end if; Next (Subt_Mark); end loop; -- Pragma Elaborate or Elaborate_All elsif Nkind (Cont_Item) = N_Pragma and then Nam_In (Pragma_Name_Unmapped (Cont_Item), Name_Elaborate, Name_Elaborate_All) and then not Used_Type_Or_Elab then Prag_Unit := First (Pragma_Argument_Associations (Cont_Item)); while Present (Prag_Unit) and then not Used_Type_Or_Elab loop if Entity (Expression (Prag_Unit)) = Nam_Ent then Used_Type_Or_Elab := True; end if; Next (Prag_Unit); end loop; end if; Next (Cont_Item); end loop; end Process_Body_Clauses; -------------------------- -- Process_Spec_Clauses -- -------------------------- procedure Process_Spec_Clauses (Context_List : List_Id; Clause : Node_Id; Used : out Boolean; Withed : out Boolean; Exit_On_Self : Boolean := False) is Nam_Ent : constant Entity_Id := Entity (Name (Clause)); Cont_Item : Node_Id; Use_Item : Node_Id; begin Used := False; Withed := False; Cont_Item := First (Context_List); while Present (Cont_Item) loop -- Stop the search since the context items after Cont_Item have -- already been examined in a previous iteration of the reverse -- loop in Check_Redundant_Withs. if Exit_On_Self and Cont_Item = Clause then exit; end if; -- Package use clause if Nkind (Cont_Item) = N_Use_Package_Clause and then not Used then Use_Item := First (Names (Cont_Item)); while Present (Use_Item) and then not Used loop if Entity (Use_Item) = Nam_Ent then Used := True; end if; Next (Use_Item); end loop; -- Package with clause. Avoid processing self, implicitly -- generated with clauses or limited with clauses. Note that -- we examine with clauses having pragmas Elaborate or -- Elaborate_All applied to them due to cases such as: -- with Pack; -- with Pack; -- pragma Elaborate (Pack); -- In this case, the second with clause is redundant since -- the pragma applies only to the first "with Pack;". -- Note that we only consider with_clauses that comes from -- source. In the case of renamings used as prefixes of names -- in with_clauses, we generate a with_clause for the prefix, -- which we do not treat as implicit because it is needed for -- visibility analysis, but is also not redundant. elsif Nkind (Cont_Item) = N_With_Clause and then not Implicit_With (Cont_Item) and then Comes_From_Source (Cont_Item) and then not Limited_Present (Cont_Item) and then Cont_Item /= Clause and then Entity (Name (Cont_Item)) = Nam_Ent then Withed := True; end if; Next (Cont_Item); end loop; end Process_Spec_Clauses; -- Start of processing for Check_Redundant_Withs begin Clause := Last (Context_Items); while Present (Clause) loop -- Avoid checking implicitly generated with clauses, limited with -- clauses or withs that have pragma Elaborate or Elaborate_All. if Nkind (Clause) = N_With_Clause and then not Implicit_With (Clause) and then not Limited_Present (Clause) and then not Elaborate_Present (Clause) -- With_clauses introduced for renamings of parent clauses -- are not marked implicit because they need to be properly -- installed, but they do not come from source and do not -- require warnings. and then Comes_From_Source (Clause) then -- Package body-to-spec check if Present (Spec_Context_Items) then declare Used_In_Body : Boolean; Used_In_Spec : Boolean; Used_Type_Or_Elab : Boolean; Withed_In_Spec : Boolean; begin Process_Spec_Clauses (Context_List => Spec_Context_Items, Clause => Clause, Used => Used_In_Spec, Withed => Withed_In_Spec); Process_Body_Clauses (Context_List => Context_Items, Clause => Clause, Used => Used_In_Body, Used_Type_Or_Elab => Used_Type_Or_Elab); -- "Type Elab" refers to the presence of either a use -- type clause, pragmas Elaborate or Elaborate_All. -- +---------------+---------------------------+------+ -- | Spec | Body | Warn | -- +--------+------+--------+------+-----------+------+ -- | Withed | Used | Withed | Used | Type Elab | | -- | X | | X | | | X | -- | X | | X | X | | | -- | X | | X | | X | | -- | X | | X | X | X | | -- | X | X | X | | | X | -- | X | X | X | | X | | -- | X | X | X | X | | X | -- | X | X | X | X | X | | -- +--------+------+--------+------+-----------+------+ if (Withed_In_Spec and then not Used_Type_Or_Elab) and then ((not Used_In_Spec and then not Used_In_Body) or else Used_In_Spec) then Error_Msg_N -- CODEFIX ("redundant with clause in body?r?", Clause); end if; Used_In_Body := False; Used_In_Spec := False; Used_Type_Or_Elab := False; Withed_In_Spec := False; end; -- Standalone package spec or body check else declare Dont_Care : Boolean := False; Withed : Boolean := False; begin -- The mechanism for examining the context clauses of a -- package spec can be applied to package body clauses. Process_Spec_Clauses (Context_List => Context_Items, Clause => Clause, Used => Dont_Care, Withed => Withed, Exit_On_Self => True); if Withed then Error_Msg_N -- CODEFIX ("redundant with clause?r?", Clause); end if; end; end if; end if; Prev (Clause); end loop; end Check_Redundant_Withs; -- Local variables Main_Cunit : constant Node_Id := Cunit (Main_Unit); Unit_Node : constant Node_Id := Unit (N); Lib_Unit : Node_Id := Library_Unit (N); Par_Spec_Name : Unit_Name_Type; Spec_Id : Entity_Id; Unum : Unit_Number_Type; -- Start of processing for Analyze_Compilation_Unit begin Process_Compilation_Unit_Pragmas (N); -- If the unit is a subunit whose parent has not been analyzed (which -- indicates that the main unit is a subunit, either the current one or -- one of its descendants) then the subunit is compiled as part of the -- analysis of the parent, which we proceed to do. Basically this gets -- handled from the top down and we don't want to do anything at this -- level (i.e. this subunit will be handled on the way down from the -- parent), so at this level we immediately return. If the subunit ends -- up not analyzed, it means that the parent did not contain a stub for -- it, or that there errors were detected in some ancestor. if Nkind (Unit_Node) = N_Subunit and then not Analyzed (Lib_Unit) then Semantics (Lib_Unit); if not Analyzed (Proper_Body (Unit_Node)) then if Serious_Errors_Detected > 0 then Error_Msg_N ("subunit not analyzed (errors in parent unit)", N); else Error_Msg_N ("missing stub for subunit", N); end if; end if; return; end if; -- Analyze context (this will call Sem recursively for with'ed units) To -- detect circularities among with-clauses that are not caught during -- loading, we set the Context_Pending flag on the current unit. If the -- flag is already set there is a potential circularity. We exclude -- predefined units from this check because they are known to be safe. -- We also exclude package bodies that are present because circularities -- between bodies are harmless (and necessary). if Context_Pending (N) then declare Circularity : Boolean := True; begin if Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Unit (N)))) then Circularity := False; else for U in Main_Unit + 1 .. Last_Unit loop if Nkind (Unit (Cunit (U))) = N_Package_Body and then not Analyzed (Cunit (U)) then Circularity := False; exit; end if; end loop; end if; if Circularity then Error_Msg_N ("circular dependency caused by with_clauses", N); Error_Msg_N ("\possibly missing limited_with clause" & " in one of the following", N); for U in Main_Unit .. Last_Unit loop if Context_Pending (Cunit (U)) then Error_Msg_Unit_1 := Get_Unit_Name (Unit (Cunit (U))); Error_Msg_N ("\unit$", N); end if; end loop; raise Unrecoverable_Error; end if; end; else Set_Context_Pending (N); end if; Analyze_Context (N); Set_Context_Pending (N, False); -- If the unit is a package body, the spec is already loaded and must be -- analyzed first, before we analyze the body. if Nkind (Unit_Node) = N_Package_Body then -- If no Lib_Unit, then there was a serious previous error, so just -- ignore the entire analysis effort. if No (Lib_Unit) then Check_Error_Detected; return; else -- Analyze the package spec Semantics (Lib_Unit); -- Check for unused with's Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit)); -- Verify that the library unit is a package declaration if not Nkind_In (Unit (Lib_Unit), N_Package_Declaration, N_Generic_Package_Declaration) then Error_Msg_N ("no legal package declaration for package body", N); return; -- Otherwise, the entity in the declaration is visible. Update the -- version to reflect dependence of this body on the spec. else Spec_Id := Defining_Entity (Unit (Lib_Unit)); Set_Is_Immediately_Visible (Spec_Id, True); Version_Update (N, Lib_Unit); if Nkind (Defining_Unit_Name (Unit_Node)) = N_Defining_Program_Unit_Name then Generate_Parent_References (Unit_Node, Scope (Spec_Id)); end if; end if; end if; -- If the unit is a subprogram body, then we similarly need to analyze -- its spec. However, things are a little simpler in this case, because -- here, this analysis is done mostly for error checking and consistency -- purposes (but not only, e.g. there could be a contract on the spec), -- so there's nothing else to be done. elsif Nkind (Unit_Node) = N_Subprogram_Body then if Acts_As_Spec (N) then -- If the subprogram body is a child unit, we must create a -- declaration for it, in order to properly load the parent(s). -- After this, the original unit does not acts as a spec, because -- there is an explicit one. If this unit appears in a context -- clause, then an implicit with on the parent will be added when -- installing the context. If this is the main unit, there is no -- Unit_Table entry for the declaration (it has the unit number -- of the main unit) and code generation is unaffected. Unum := Get_Cunit_Unit_Number (N); Par_Spec_Name := Get_Parent_Spec_Name (Unit_Name (Unum)); if Par_Spec_Name /= No_Unit_Name then Unum := Load_Unit (Load_Name => Par_Spec_Name, Required => True, Subunit => False, Error_Node => N); if Unum /= No_Unit then -- Build subprogram declaration and attach parent unit to it -- This subprogram declaration does not come from source, -- Nevertheless the backend must generate debugging info for -- it, and this must be indicated explicitly. We also mark -- the body entity as a child unit now, to prevent a -- cascaded error if the spec entity cannot be entered -- in its scope. Finally we create a Units table entry for -- the subprogram declaration, to maintain a one-to-one -- correspondence with compilation unit nodes. This is -- critical for the tree traversals performed by CodePeer. declare Loc : constant Source_Ptr := Sloc (N); SCS : constant Boolean := Get_Comes_From_Source_Default; begin Set_Comes_From_Source_Default (False); -- Note: We copy the Context_Items from the explicit body -- to the implicit spec, setting the former to Empty_List -- to preserve the treeish nature of the tree, during -- analysis of the spec. Then we put it back the way it -- was -- copy the Context_Items from the spec to the -- body, and set the spec Context_Items to Empty_List. -- It is necessary to preserve the treeish nature, -- because otherwise we will call End_Use_* twice on the -- same thing. Lib_Unit := Make_Compilation_Unit (Loc, Context_Items => Context_Items (N), Unit => Make_Subprogram_Declaration (Sloc (N), Specification => Copy_Separate_Tree (Specification (Unit_Node))), Aux_Decls_Node => Make_Compilation_Unit_Aux (Loc)); Set_Context_Items (N, Empty_List); Set_Library_Unit (N, Lib_Unit); Set_Parent_Spec (Unit (Lib_Unit), Cunit (Unum)); Make_Child_Decl_Unit (N); Semantics (Lib_Unit); -- Now that a separate declaration exists, the body -- of the child unit does not act as spec any longer. Set_Acts_As_Spec (N, False); Set_Is_Child_Unit (Defining_Entity (Unit_Node)); Set_Debug_Info_Needed (Defining_Entity (Unit (Lib_Unit))); Set_Comes_From_Source_Default (SCS); -- Restore Context_Items to the body Set_Context_Items (N, Context_Items (Lib_Unit)); Set_Context_Items (Lib_Unit, Empty_List); end; end if; end if; -- Here for subprogram with separate declaration else Semantics (Lib_Unit); Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit)); Version_Update (N, Lib_Unit); end if; -- If this is a child unit, generate references to the parents if Nkind (Defining_Unit_Name (Specification (Unit_Node))) = N_Defining_Program_Unit_Name then Generate_Parent_References (Specification (Unit_Node), Scope (Defining_Entity (Unit (Lib_Unit)))); end if; end if; -- If it is a child unit, the parent must be elaborated first and we -- update version, since we are dependent on our parent. if Is_Child_Spec (Unit_Node) then -- The analysis of the parent is done with style checks off declare Save_Style_Check : constant Boolean := Style_Check; begin if not GNAT_Mode then Style_Check := False; end if; Semantics (Parent_Spec (Unit_Node)); Version_Update (N, Parent_Spec (Unit_Node)); -- Restore style check settings Style_Check := Save_Style_Check; end; end if; -- With the analysis done, install the context. Note that we can't -- install the context from the with clauses as we analyze them, because -- each with clause must be analyzed in a clean visibility context, so -- we have to wait and install them all at once. Install_Context (N); if Is_Child_Spec (Unit_Node) then -- Set the entities of all parents in the program_unit_name Generate_Parent_References (Unit_Node, Get_Parent_Entity (Unit (Parent_Spec (Unit_Node)))); end if; -- All components of the context: with-clauses, library unit, ancestors -- if any, (and their context) are analyzed and installed. -- Call special debug routine sm if this is the main unit if Current_Sem_Unit = Main_Unit then sm; end if; -- Now analyze the unit (package, subprogram spec, body) itself Analyze (Unit_Node); if Warn_On_Redundant_Constructs then Check_Redundant_Withs (Context_Items (N)); if Nkind (Unit_Node) = N_Package_Body then Check_Redundant_Withs (Context_Items => Context_Items (N), Spec_Context_Items => Context_Items (Lib_Unit)); end if; end if; -- The above call might have made Unit_Node an N_Subprogram_Body from -- something else, so propagate any Acts_As_Spec flag. if Nkind (Unit_Node) = N_Subprogram_Body and then Acts_As_Spec (Unit_Node) then Set_Acts_As_Spec (N); end if; -- Register predefined units in Rtsfind declare Unum : constant Unit_Number_Type := Get_Source_Unit (Sloc (N)); begin if Is_Predefined_File_Name (Unit_File_Name (Unum)) then Set_RTU_Loaded (Unit_Node); end if; end; -- Treat compilation unit pragmas that appear after the library unit if Present (Pragmas_After (Aux_Decls_Node (N))) then declare Prag_Node : Node_Id := First (Pragmas_After (Aux_Decls_Node (N))); begin while Present (Prag_Node) loop Analyze (Prag_Node); Next (Prag_Node); end loop; end; end if; -- Analyze the contract of a [generic] subprogram that acts as a -- compilation unit after all compilation pragmas have been analyzed. if Nkind_In (Unit_Node, N_Generic_Subprogram_Declaration, N_Subprogram_Declaration) then Analyze_Entry_Or_Subprogram_Contract (Defining_Entity (Unit_Node)); end if; -- Generate distribution stubs if requested and no error if N = Main_Cunit and then (Distribution_Stub_Mode = Generate_Receiver_Stub_Body or else Distribution_Stub_Mode = Generate_Caller_Stub_Body) and then Fatal_Error (Main_Unit) /= Error_Detected then if Is_RCI_Pkg_Spec_Or_Body (N) then -- Regular RCI package Add_Stub_Constructs (N); elsif (Nkind (Unit_Node) = N_Package_Declaration and then Is_Shared_Passive (Defining_Entity (Specification (Unit_Node)))) or else (Nkind (Unit_Node) = N_Package_Body and then Is_Shared_Passive (Corresponding_Spec (Unit_Node))) then -- Shared passive package Add_Stub_Constructs (N); elsif Nkind (Unit_Node) = N_Package_Instantiation and then Is_Remote_Call_Interface (Defining_Entity (Specification (Instance_Spec (Unit_Node)))) then -- Instantiation of a RCI generic package Add_Stub_Constructs (N); end if; end if; -- Remove unit from visibility, so that environment is clean for the -- next compilation, which is either the main unit or some other unit -- in the context. if Nkind_In (Unit_Node, N_Package_Declaration, N_Package_Renaming_Declaration, N_Subprogram_Declaration) or else Nkind (Unit_Node) in N_Generic_Declaration or else (Nkind (Unit_Node) = N_Subprogram_Body and then Acts_As_Spec (Unit_Node)) then Remove_Unit_From_Visibility (Defining_Entity (Unit_Node)); -- If the unit is an instantiation whose body will be elaborated for -- inlining purposes, use the proper entity of the instance. The entity -- may be missing if the instantiation was illegal. elsif Nkind (Unit_Node) = N_Package_Instantiation and then not Error_Posted (Unit_Node) and then Present (Instance_Spec (Unit_Node)) then Remove_Unit_From_Visibility (Defining_Entity (Instance_Spec (Unit_Node))); elsif Nkind (Unit_Node) = N_Package_Body or else (Nkind (Unit_Node) = N_Subprogram_Body and then not Acts_As_Spec (Unit_Node)) then -- Bodies that are not the main unit are compiled if they are generic -- or contain generic or inlined units. Their analysis brings in the -- context of the corresponding spec (unit declaration) which must be -- removed as well, to return the compilation environment to its -- proper state. Remove_Context (Lib_Unit); Set_Is_Immediately_Visible (Defining_Entity (Unit (Lib_Unit)), False); end if; -- Last step is to deinstall the context we just installed as well as -- the unit just compiled. Remove_Context (N); -- When generating code for a non-generic main unit, check that withed -- generic units have a body if they need it, even if the units have not -- been instantiated. Force the load of the bodies to produce the proper -- error if the body is absent. The same applies to GNATprove mode, with -- the added benefit of capturing global references within the generic. -- This in turn allows for proper inlining of subprogram bodies without -- a previous declaration. if Get_Cunit_Unit_Number (N) = Main_Unit and then ((Operating_Mode = Generate_Code and then Expander_Active) or else (Operating_Mode = Check_Semantics and then GNATprove_Mode)) then -- Check whether the source for the body of the unit must be included -- in a standalone library. Check_Body_Needed_For_SAL (Cunit_Entity (Main_Unit)); -- Indicate that the main unit is now analyzed, to catch possible -- circularities between it and generic bodies. Remove main unit from -- visibility. This might seem superfluous, but the main unit must -- not be visible in the generic body expansions that follow. Set_Analyzed (N, True); Set_Is_Immediately_Visible (Cunit_Entity (Main_Unit), False); declare Item : Node_Id; Nam : Entity_Id; Un : Unit_Number_Type; Save_Style_Check : constant Boolean := Style_Check; begin Item := First (Context_Items (N)); while Present (Item) loop -- Check for explicit with clause if Nkind (Item) = N_With_Clause and then not Implicit_With (Item) -- Ada 2005 (AI-50217): Ignore limited-withed units and then not Limited_Present (Item) then Nam := Entity (Name (Item)); -- Compile the generic subprogram, unless it is intrinsic or -- imported so no body is required, or generic package body -- if the package spec requires a body. if (Is_Generic_Subprogram (Nam) and then not Is_Intrinsic_Subprogram (Nam) and then not Is_Imported (Nam)) or else (Ekind (Nam) = E_Generic_Package and then Unit_Requires_Body (Nam)) then Style_Check := False; if Present (Renamed_Object (Nam)) then Un := Load_Unit (Load_Name => Get_Body_Name (Get_Unit_Name (Unit_Declaration_Node (Renamed_Object (Nam)))), Required => False, Subunit => False, Error_Node => N, Renamings => True); else Un := Load_Unit (Load_Name => Get_Body_Name (Get_Unit_Name (Item)), Required => False, Subunit => False, Error_Node => N, Renamings => True); end if; if Un = No_Unit then Error_Msg_NE ("body of generic unit& not found", Item, Nam); exit; elsif not Analyzed (Cunit (Un)) and then Un /= Main_Unit and then Fatal_Error (Un) /= Error_Detected then Style_Check := False; Semantics (Cunit (Un)); end if; end if; end if; Next (Item); end loop; -- Restore style checks settings Style_Check := Save_Style_Check; end; -- In GNATprove mode, force the loading of a Interrupt_Priority when -- processing compilation units with potentially "main" subprograms. -- This is required for the ceiling priority protocol checks, which -- are trigerred by these subprograms. if GNATprove_Mode and then Nkind_In (Unit_Node, N_Subprogram_Body, N_Procedure_Instantiation, N_Function_Instantiation) then declare Spec : Node_Id; Unused : Entity_Id; begin case Nkind (Unit_Node) is when N_Subprogram_Body => Spec := Specification (Unit_Node); when N_Subprogram_Instantiation => Spec := Subprogram_Specification (Entity (Name (Unit_Node))); when others => raise Program_Error; end case; pragma Assert (Nkind (Spec) in N_Subprogram_Specification); -- Only subprogram with no parameters can act as "main", and if -- it is a function, it needs to return an integer. if No (Parameter_Specifications (Spec)) and then (Nkind (Spec) = N_Procedure_Specification or else Is_Integer_Type (Etype (Result_Definition (Spec)))) then Unused := RTE (RE_Interrupt_Priority); end if; end; end if; end if; -- Deal with creating elaboration counter if needed. We create an -- elaboration counter only for units that come from source since -- units manufactured by the compiler never need elab checks. if Comes_From_Source (N) and then Nkind_In (Unit_Node, N_Package_Declaration, N_Generic_Package_Declaration, N_Subprogram_Declaration, N_Generic_Subprogram_Declaration) then declare Loc : constant Source_Ptr := Sloc (N); Unum : constant Unit_Number_Type := Get_Source_Unit (Loc); begin Spec_Id := Defining_Entity (Unit_Node); Generate_Definition (Spec_Id); -- See if an elaboration entity is required for possible access -- before elaboration checking. Note that we must allow for this -- even if -gnatE is not set, since a client may be compiled in -- -gnatE mode and reference the entity. -- These entities are also used by the binder to prevent multiple -- attempts to execute the elaboration code for the library case -- where the elaboration routine might otherwise be called more -- than once. -- Case of units which do not require elaboration checks if -- Pure units do not need checks Is_Pure (Spec_Id) -- Preelaborated units do not need checks or else Is_Preelaborated (Spec_Id) -- No checks needed if pragma Elaborate_Body present or else Has_Pragma_Elaborate_Body (Spec_Id) -- No checks needed if unit does not require a body or else not Unit_Requires_Body (Spec_Id) -- No checks needed for predefined files or else Is_Predefined_File_Name (Unit_File_Name (Unum)) -- No checks required if no separate spec or else Acts_As_Spec (N) then -- This is a case where we only need the entity for -- checking to prevent multiple elaboration checks. Set_Elaboration_Entity_Required (Spec_Id, False); -- Case of elaboration entity is required for access before -- elaboration checking (so certainly we must build it). else Set_Elaboration_Entity_Required (Spec_Id, True); end if; Build_Elaboration_Entity (N, Spec_Id); end; end if; -- Freeze the compilation unit entity. This for sure is needed because -- of some warnings that can be output (see Freeze_Subprogram), but may -- in general be required. If freezing actions result, place them in the -- compilation unit actions list, and analyze them. declare L : constant List_Id := Freeze_Entity (Cunit_Entity (Current_Sem_Unit), N); begin while Is_Non_Empty_List (L) loop Insert_Library_Level_Action (Remove_Head (L)); end loop; end; Set_Analyzed (N); -- Call Check_Package_Body so that a body containing subprograms with -- Inline_Always can be made available for front end inlining. if Nkind (Unit_Node) = N_Package_Declaration and then Get_Cunit_Unit_Number (N) /= Main_Unit -- We don't need to do this if the Expander is not active, since there -- is no code to inline. and then Expander_Active then declare Save_Style_Check : constant Boolean := Style_Check; Save_Warning : constant Warning_Mode_Type := Warning_Mode; Options : Style_Check_Options; begin Save_Style_Check_Options (Options); Reset_Style_Check_Options; Opt.Warning_Mode := Suppress; Check_Package_Body_For_Inlining (N, Defining_Entity (Unit_Node)); Reset_Style_Check_Options; Set_Style_Check_Options (Options); Style_Check := Save_Style_Check; Warning_Mode := Save_Warning; end; end if; -- If we are generating obsolescent warnings, then here is where we -- generate them for the with'ed items. The reason for this special -- processing is that the normal mechanism of generating the warnings -- for referenced entities does not work for context clause references. -- That's because when we first analyze the context, it is too early to -- know if the with'ing unit is itself obsolescent (which suppresses -- the warnings). if not GNAT_Mode and then Warn_On_Obsolescent_Feature and then Nkind (Unit_Node) not in N_Generic_Instantiation then -- Push current compilation unit as scope, so that the test for -- being within an obsolescent unit will work correctly. The check -- is not performed within an instantiation, because the warning -- will have been emitted in the corresponding generic unit. Push_Scope (Defining_Entity (Unit_Node)); -- Loop through context items to deal with with clauses declare Item : Node_Id; Nam : Node_Id; Ent : Entity_Id; begin Item := First (Context_Items (N)); while Present (Item) loop if Nkind (Item) = N_With_Clause -- Suppress this check in limited-withed units. Further work -- needed here if we decide to incorporate this check on -- limited-withed units. and then not Limited_Present (Item) then Nam := Name (Item); Ent := Entity (Nam); if Is_Obsolescent (Ent) then Output_Obsolescent_Entity_Warnings (Nam, Ent); end if; end if; Next (Item); end loop; end; -- Remove temporary install of current unit as scope Pop_Scope; end if; -- If No_Elaboration_Code_All was encountered, this is where we do the -- transitive test of with'ed units to make sure they have the aspect. -- This is delayed till the end of analyzing the compilation unit to -- ensure that the pragma/aspect, if present, has been analyzed. Check_No_Elab_Code_All (N); end Analyze_Compilation_Unit; --------------------- -- Analyze_Context -- --------------------- procedure Analyze_Context (N : Node_Id) is Ukind : constant Node_Kind := Nkind (Unit (N)); Item : Node_Id; begin -- First process all configuration pragmas at the start of the context -- items. Strictly these are not part of the context clause, but that -- is where the parser puts them. In any case for sure we must analyze -- these before analyzing the actual context items, since they can have -- an effect on that analysis (e.g. pragma Ada_2005 may allow a unit to -- be with'ed as a result of changing categorizations in Ada 2005). Item := First (Context_Items (N)); while Present (Item) and then Nkind (Item) = N_Pragma and then Pragma_Name (Item) in Configuration_Pragma_Names loop Analyze (Item); Next (Item); end loop; -- This is the point at which we capture the configuration settings -- for the unit. At the moment only the Optimize_Alignment setting -- needs to be captured. Probably more later ??? if Optimize_Alignment_Local then Set_OA_Setting (Current_Sem_Unit, 'L'); else Set_OA_Setting (Current_Sem_Unit, Optimize_Alignment); end if; -- Loop through actual context items. This is done in two passes: -- a) The first pass analyzes non-limited with-clauses and also any -- configuration pragmas (we need to get the latter analyzed right -- away, since they can affect processing of subsequent items). -- b) The second pass analyzes limited_with clauses (Ada 2005: AI-50217) while Present (Item) loop -- For with clause, analyze the with clause, and then update the -- version, since we are dependent on a unit that we with. if Nkind (Item) = N_With_Clause and then not Limited_Present (Item) then -- Skip analyzing with clause if no unit, nothing to do (this -- happens for a with that references a non-existent unit). if Present (Library_Unit (Item)) then -- Skip analyzing with clause if this is a with_clause for -- the main unit, which happens if a subunit has a useless -- with_clause on its parent. if Library_Unit (Item) /= Cunit (Current_Sem_Unit) then Analyze (Item); -- Here for the case of a useless with for the main unit else Set_Entity (Name (Item), Cunit_Entity (Current_Sem_Unit)); end if; end if; -- Do version update (skipped for implicit with) if not Implicit_With (Item) then Version_Update (N, Library_Unit (Item)); end if; -- Skip pragmas. Configuration pragmas at the start were handled in -- the loop above, and remaining pragmas are not processed until we -- actually install the context (see Install_Context). We delay the -- analysis of these pragmas to make sure that we have installed all -- the implicit with's on parent units. -- Skip use clauses at this stage, since we don't want to do any -- installing of potentially use-visible entities until we -- actually install the complete context (in Install_Context). -- Otherwise things can get installed in the wrong context. else null; end if; Next (Item); end loop; -- Second pass: examine all limited_with clauses. All other context -- items are ignored in this pass. Item := First (Context_Items (N)); while Present (Item) loop if Nkind (Item) = N_With_Clause and then Limited_Present (Item) then -- No need to check errors on implicitly generated limited-with -- clauses. if not Implicit_With (Item) then -- Verify that the illegal contexts given in 10.1.2 (18/2) are -- properly rejected, including renaming declarations. if not Nkind_In (Ukind, N_Package_Declaration, N_Subprogram_Declaration) and then Ukind not in N_Generic_Declaration and then Ukind not in N_Generic_Instantiation then Error_Msg_N ("limited with_clause not allowed here", Item); -- Check wrong use of a limited with clause applied to the -- compilation unit containing the limited-with clause. -- limited with P.Q; -- package P.Q is ... elsif Unit (Library_Unit (Item)) = Unit (N) then Error_Msg_N ("wrong use of limited-with clause", Item); -- Check wrong use of limited-with clause applied to some -- immediate ancestor. elsif Is_Child_Spec (Unit (N)) then declare Lib_U : constant Entity_Id := Unit (Library_Unit (Item)); P : Node_Id; begin P := Parent_Spec (Unit (N)); loop if Unit (P) = Lib_U then Error_Msg_N ("limited with_clause cannot " & "name ancestor", Item); exit; end if; exit when not Is_Child_Spec (Unit (P)); P := Parent_Spec (Unit (P)); end loop; end; end if; -- Check if the limited-withed unit is already visible through -- some context clause of the current compilation unit or some -- ancestor of the current compilation unit. declare Lim_Unit_Name : constant Node_Id := Name (Item); Comp_Unit : Node_Id; It : Node_Id; Unit_Name : Node_Id; begin Comp_Unit := N; loop It := First (Context_Items (Comp_Unit)); while Present (It) loop if Item /= It and then Nkind (It) = N_With_Clause and then not Limited_Present (It) and then Nkind_In (Unit (Library_Unit (It)), N_Package_Declaration, N_Package_Renaming_Declaration) then if Nkind (Unit (Library_Unit (It))) = N_Package_Declaration then Unit_Name := Name (It); else Unit_Name := Name (Unit (Library_Unit (It))); end if; -- Check if the named package (or some ancestor) -- leaves visible the full-view of the unit given -- in the limited-with clause. loop if Designate_Same_Unit (Lim_Unit_Name, Unit_Name) then Error_Msg_Sloc := Sloc (It); Error_Msg_N ("simultaneous visibility of limited " & "and unlimited views not allowed", Item); Error_Msg_NE ("\unlimited view visible through " & "context clause #", Item, It); exit; elsif Nkind (Unit_Name) = N_Identifier then exit; end if; Unit_Name := Prefix (Unit_Name); end loop; end if; Next (It); end loop; exit when not Is_Child_Spec (Unit (Comp_Unit)); Comp_Unit := Parent_Spec (Unit (Comp_Unit)); end loop; end; end if; -- Skip analyzing with clause if no unit, see above if Present (Library_Unit (Item)) then Analyze (Item); end if; -- A limited_with does not impose an elaboration order, but -- there is a semantic dependency for recompilation purposes. if not Implicit_With (Item) then Version_Update (N, Library_Unit (Item)); end if; -- Pragmas and use clauses and with clauses other than limited -- with's are ignored in this pass through the context items. else null; end if; Next (Item); end loop; end Analyze_Context; ------------------------------- -- Analyze_Package_Body_Stub -- ------------------------------- procedure Analyze_Package_Body_Stub (N : Node_Id) is Id : constant Entity_Id := Defining_Identifier (N); Nam : Entity_Id; Opts : Config_Switches_Type; begin -- The package declaration must be in the current declarative part Check_Stub_Level (N); Nam := Current_Entity_In_Scope (Id); if No (Nam) or else not Is_Package_Or_Generic_Package (Nam) then Error_Msg_N ("missing specification for package stub", N); elsif Has_Completion (Nam) and then Present (Corresponding_Body (Unit_Declaration_Node (Nam))) then Error_Msg_N ("duplicate or redundant stub for package", N); else -- Retain and restore the configuration options of the enclosing -- context as the proper body may introduce a set of its own. Save_Opt_Config_Switches (Opts); -- Indicate that the body of the package exists. If we are doing -- only semantic analysis, the stub stands for the body. If we are -- generating code, the existence of the body will be confirmed -- when we load the proper body. Set_Has_Completion (Nam); Set_Scope (Defining_Entity (N), Current_Scope); Set_Ekind (Defining_Entity (N), E_Package_Body); Set_Corresponding_Spec_Of_Stub (N, Nam); Generate_Reference (Nam, Id, 'b'); Analyze_Proper_Body (N, Nam); Restore_Opt_Config_Switches (Opts); end if; end Analyze_Package_Body_Stub; ------------------------- -- Analyze_Proper_Body -- ------------------------- procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id) is Subunit_Name : constant Unit_Name_Type := Get_Unit_Name (N); procedure Optional_Subunit; -- This procedure is called when the main unit is a stub, or when we -- are not generating code. In such a case, we analyze the subunit if -- present, which is user-friendly and in fact required for ASIS, but we -- don't complain if the subunit is missing. In GNATprove_Mode, we issue -- an error to avoid formal verification of a partial unit. ---------------------- -- Optional_Subunit -- ---------------------- procedure Optional_Subunit is Comp_Unit : Node_Id; Unum : Unit_Number_Type; begin -- Try to load subunit, but ignore any errors that occur during the -- loading of the subunit, by using the special feature in Errout to -- ignore all errors. Note that Fatal_Error will still be set, so we -- will be able to check for this case below. if not (ASIS_Mode or GNATprove_Mode) then Ignore_Errors_Enable := Ignore_Errors_Enable + 1; end if; Unum := Load_Unit (Load_Name => Subunit_Name, Required => GNATprove_Mode, Subunit => True, Error_Node => N); if not (ASIS_Mode or GNATprove_Mode) then Ignore_Errors_Enable := Ignore_Errors_Enable - 1; end if; -- All done if we successfully loaded the subunit if Unum /= No_Unit and then (Fatal_Error (Unum) /= Error_Detected or else Try_Semantics) then Comp_Unit := Cunit (Unum); -- If the file was empty or seriously mangled, the unit itself may -- be missing. if No (Unit (Comp_Unit)) then Error_Msg_N ("subunit does not contain expected proper body", N); elsif Nkind (Unit (Comp_Unit)) /= N_Subunit then Error_Msg_N ("expected SEPARATE subunit, found child unit", Cunit_Entity (Unum)); else Set_Corresponding_Stub (Unit (Comp_Unit), N); Analyze_Subunit (Comp_Unit); Set_Library_Unit (N, Comp_Unit); Set_Corresponding_Body (N, Defining_Entity (Unit (Comp_Unit))); end if; elsif Unum = No_Unit and then Present (Nam) then if Is_Protected_Type (Nam) then Set_Corresponding_Body (Parent (Nam), Defining_Identifier (N)); else Set_Corresponding_Body ( Unit_Declaration_Node (Nam), Defining_Identifier (N)); end if; end if; end Optional_Subunit; -- Local variables Comp_Unit : Node_Id; Unum : Unit_Number_Type; -- Start of processing for Analyze_Proper_Body begin -- If the subunit is already loaded, it means that the main unit is a -- subunit, and that the current unit is one of its parents which was -- being analyzed to provide the needed context for the analysis of the -- subunit. In this case we analyze the subunit and continue with the -- parent, without looking at subsequent subunits. if Is_Loaded (Subunit_Name) then -- If the proper body is already linked to the stub node, the stub is -- in a generic unit and just needs analyzing. if Present (Library_Unit (N)) then Set_Corresponding_Stub (Unit (Library_Unit (N)), N); -- If the subunit has severe errors, the spec of the enclosing -- body may not be available, in which case do not try analysis. if Serious_Errors_Detected > 0 and then No (Library_Unit (Library_Unit (N))) then return; end if; -- Collect SCO information for loaded subunit if we are in the -- extended main unit. if Generate_SCO and then In_Extended_Main_Source_Unit (Cunit_Entity (Current_Sem_Unit)) then SCO_Record_Raw (Get_Cunit_Unit_Number (Library_Unit (N))); end if; Analyze_Subunit (Library_Unit (N)); -- Otherwise we must load the subunit and link to it else -- Load the subunit, this must work, since we originally loaded -- the subunit earlier on. So this will not really load it, just -- give access to it. Unum := Load_Unit (Load_Name => Subunit_Name, Required => True, Subunit => False, Error_Node => N); -- And analyze the subunit in the parent context (note that we -- do not call Semantics, since that would remove the parent -- context). Because of this, we have to manually reset the -- compiler state to Analyzing since it got destroyed by Load. if Unum /= No_Unit then Compiler_State := Analyzing; -- Check that the proper body is a subunit and not a child -- unit. If the unit was previously loaded, the error will -- have been emitted when copying the generic node, so we -- just return to avoid cascaded errors. if Nkind (Unit (Cunit (Unum))) /= N_Subunit then return; end if; Set_Corresponding_Stub (Unit (Cunit (Unum)), N); Analyze_Subunit (Cunit (Unum)); Set_Library_Unit (N, Cunit (Unum)); end if; end if; -- If the main unit is a subunit, then we are just performing semantic -- analysis on that subunit, and any other subunits of any parent unit -- should be ignored, except that if we are building trees for ASIS -- usage we want to annotate the stub properly. If the main unit is -- itself a subunit, another subunit is irrelevant unless it is a -- subunit of the current one, that is to say appears in the current -- source tree. elsif Nkind (Unit (Cunit (Main_Unit))) = N_Subunit and then Subunit_Name /= Unit_Name (Main_Unit) then if ASIS_Mode then declare PB : constant Node_Id := Proper_Body (Unit (Cunit (Main_Unit))); begin if Nkind_In (PB, N_Package_Body, N_Subprogram_Body) and then List_Containing (N) = Declarations (PB) then Optional_Subunit; end if; end; end if; -- But before we return, set the flag for unloaded subunits. This -- will suppress junk warnings of variables in the same declarative -- part (or a higher level one) that are in danger of looking unused -- when in fact there might be a declaration in the subunit that we -- do not intend to load. Unloaded_Subunits := True; return; -- If the subunit is not already loaded, and we are generating code, -- then this is the case where compilation started from the parent, and -- we are generating code for an entire subunit tree. In that case we -- definitely need to load the subunit. -- In order to continue the analysis with the rest of the parent, -- and other subunits, we load the unit without requiring its -- presence, and emit a warning if not found, rather than terminating -- the compilation abruptly, as for other missing file problems. elsif Original_Operating_Mode = Generate_Code then -- If the proper body is already linked to the stub node, the stub is -- in a generic unit and just needs analyzing. -- We update the version. Although we are not strictly technically -- semantically dependent on the subunit, given our approach of macro -- substitution of subunits, it makes sense to include it in the -- version identification. if Present (Library_Unit (N)) then Set_Corresponding_Stub (Unit (Library_Unit (N)), N); Analyze_Subunit (Library_Unit (N)); Version_Update (Cunit (Main_Unit), Library_Unit (N)); -- Otherwise we must load the subunit and link to it else -- Make sure that, if the subunit is preprocessed and -gnateG is -- specified, the preprocessed file will be written. Lib.Analysing_Subunit_Of_Main := True; Unum := Load_Unit (Load_Name => Subunit_Name, Required => False, Subunit => True, Error_Node => N); Lib.Analysing_Subunit_Of_Main := False; -- Give message if we did not get the unit Emit warning even if -- missing subunit is not within main unit, to simplify debugging. pragma Assert (Original_Operating_Mode = Generate_Code); if Unum = No_Unit then Error_Msg_Unit_1 := Subunit_Name; Error_Msg_File_1 := Get_File_Name (Subunit_Name, Subunit => True); Error_Msg_N ("subunit$$ in file{ not found??!!", N); Subunits_Missing := True; end if; -- Load_Unit may reset Compiler_State, since it may have been -- necessary to parse an additional units, so we make sure that -- we reset it to the Analyzing state. Compiler_State := Analyzing; if Unum /= No_Unit then if Debug_Flag_L then Write_Str ("*** Loaded subunit from stub. Analyze"); Write_Eol; end if; Comp_Unit := Cunit (Unum); -- Check for child unit instead of subunit if Nkind (Unit (Comp_Unit)) /= N_Subunit then Error_Msg_N ("expected SEPARATE subunit, found child unit", Cunit_Entity (Unum)); -- OK, we have a subunit else Set_Corresponding_Stub (Unit (Comp_Unit), N); Set_Library_Unit (N, Comp_Unit); -- We update the version. Although we are not technically -- semantically dependent on the subunit, given our approach -- of macro substitution of subunits, it makes sense to -- include it in the version identification. Version_Update (Cunit (Main_Unit), Comp_Unit); -- Collect SCO information for loaded subunit if we are in -- the extended main unit. if Generate_SCO and then In_Extended_Main_Source_Unit (Cunit_Entity (Current_Sem_Unit)) then SCO_Record_Raw (Unum); end if; -- Analyze the unit if semantics active if Fatal_Error (Unum) /= Error_Detected or else Try_Semantics then Analyze_Subunit (Comp_Unit); end if; end if; end if; end if; -- The remaining case is when the subunit is not already loaded and we -- are not generating code. In this case we are just performing semantic -- analysis on the parent, and we are not interested in the subunit. For -- subprograms, analyze the stub as a body. For other entities the stub -- has already been marked as completed. else Optional_Subunit; end if; end Analyze_Proper_Body; ---------------------------------- -- Analyze_Protected_Body_Stub -- ---------------------------------- procedure Analyze_Protected_Body_Stub (N : Node_Id) is Nam : Entity_Id := Current_Entity_In_Scope (Defining_Identifier (N)); begin Check_Stub_Level (N); -- First occurrence of name may have been as an incomplete type if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then Nam := Full_View (Nam); end if; if No (Nam) or else not Is_Protected_Type (Etype (Nam)) then Error_Msg_N ("missing specification for Protected body", N); else Set_Scope (Defining_Entity (N), Current_Scope); Set_Ekind (Defining_Entity (N), E_Protected_Body); Set_Has_Completion (Etype (Nam)); Set_Corresponding_Spec_Of_Stub (N, Nam); Generate_Reference (Nam, Defining_Identifier (N), 'b'); Analyze_Proper_Body (N, Etype (Nam)); end if; end Analyze_Protected_Body_Stub; ---------------------------------- -- Analyze_Subprogram_Body_Stub -- ---------------------------------- -- A subprogram body stub can appear with or without a previous spec. If -- there is one, then the analysis of the body will find it and verify -- conformance. The formals appearing in the specification of the stub play -- no role, except for requiring an additional conformance check. If there -- is no previous subprogram declaration, the stub acts as a spec, and -- provides the defining entity for the subprogram. procedure Analyze_Subprogram_Body_Stub (N : Node_Id) is Decl : Node_Id; Opts : Config_Switches_Type; begin Check_Stub_Level (N); -- Verify that the identifier for the stub is unique within this -- declarative part. if Nkind_In (Parent (N), N_Block_Statement, N_Package_Body, N_Subprogram_Body) then Decl := First (Declarations (Parent (N))); while Present (Decl) and then Decl /= N loop if Nkind (Decl) = N_Subprogram_Body_Stub and then (Chars (Defining_Unit_Name (Specification (Decl))) = Chars (Defining_Unit_Name (Specification (N)))) then Error_Msg_N ("identifier for stub is not unique", N); end if; Next (Decl); end loop; end if; -- Retain and restore the configuration options of the enclosing context -- as the proper body may introduce a set of its own. Save_Opt_Config_Switches (Opts); -- Treat stub as a body, which checks conformance if there is a previous -- declaration, or else introduces entity and its signature. Analyze_Subprogram_Body (N); Analyze_Proper_Body (N, Empty); Restore_Opt_Config_Switches (Opts); end Analyze_Subprogram_Body_Stub; --------------------- -- Analyze_Subunit -- --------------------- -- A subunit is compiled either by itself (for semantic checking) or as -- part of compiling the parent (for code generation). In either case, by -- the time we actually process the subunit, the parent has already been -- installed and analyzed. The node N is a compilation unit, whose context -- needs to be treated here, because we come directly here from the parent -- without calling Analyze_Compilation_Unit. -- The compilation context includes the explicit context of the subunit, -- and the context of the parent, together with the parent itself. In order -- to compile the current context, we remove the one inherited from the -- parent, in order to have a clean visibility table. We restore the parent -- context before analyzing the proper body itself. On exit, we remove only -- the explicit context of the subunit. procedure Analyze_Subunit (N : Node_Id) is Lib_Unit : constant Node_Id := Library_Unit (N); Par_Unit : constant Entity_Id := Current_Scope; Lib_Spec : Node_Id := Library_Unit (Lib_Unit); Num_Scopes : Nat := 0; Use_Clauses : array (1 .. Scope_Stack.Last) of Node_Id; Enclosing_Child : Entity_Id := Empty; Svg : constant Suppress_Record := Scope_Suppress; Save_Cunit_Restrictions : constant Save_Cunit_Boolean_Restrictions := Cunit_Boolean_Restrictions_Save; -- Save non-partition wide restrictions before processing the subunit. -- All subunits are analyzed with config restrictions reset and we need -- to restore these saved values at the end. procedure Analyze_Subunit_Context; -- Capture names in use clauses of the subunit. This must be done before -- re-installing parent declarations, because items in the context must -- not be hidden by declarations local to the parent. procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id); -- Recursive procedure to restore scope of all ancestors of subunit, -- from outermost in. If parent is not a subunit, the call to install -- context installs context of spec and (if parent is a child unit) the -- context of its parents as well. It is confusing that parents should -- be treated differently in both cases, but the semantics are just not -- identical. procedure Re_Install_Use_Clauses; -- As part of the removal of the parent scope, the use clauses are -- removed, to be reinstalled when the context of the subunit has been -- analyzed. Use clauses may also have been affected by the analysis of -- the context of the subunit, so they have to be applied again, to -- insure that the compilation environment of the rest of the parent -- unit is identical. procedure Remove_Scope; -- Remove current scope from scope stack, and preserve the list of use -- clauses in it, to be reinstalled after context is analyzed. ----------------------------- -- Analyze_Subunit_Context -- ----------------------------- procedure Analyze_Subunit_Context is Item : Node_Id; Nam : Node_Id; Unit_Name : Entity_Id; begin Analyze_Context (N); Check_No_Elab_Code_All (N); -- Make withed units immediately visible. If child unit, make the -- ultimate parent immediately visible. Item := First (Context_Items (N)); while Present (Item) loop if Nkind (Item) = N_With_Clause then -- Protect frontend against previous errors in context clauses if Nkind (Name (Item)) /= N_Selected_Component then if Error_Posted (Item) then null; else -- If a subunits has serious syntax errors, the context -- may not have been loaded. Add a harmless unit name to -- attempt processing. if Serious_Errors_Detected > 0 and then No (Entity (Name (Item))) then Set_Entity (Name (Item), Standard_Standard); end if; Unit_Name := Entity (Name (Item)); loop Set_Is_Visible_Lib_Unit (Unit_Name); exit when Scope (Unit_Name) = Standard_Standard; Unit_Name := Scope (Unit_Name); if No (Unit_Name) then Check_Error_Detected; return; end if; end loop; if not Is_Immediately_Visible (Unit_Name) then Set_Is_Immediately_Visible (Unit_Name); Set_Context_Installed (Item); end if; end if; end if; elsif Nkind (Item) = N_Use_Package_Clause then Nam := First (Names (Item)); while Present (Nam) loop Analyze (Nam); Next (Nam); end loop; elsif Nkind (Item) = N_Use_Type_Clause then Nam := First (Subtype_Marks (Item)); while Present (Nam) loop Analyze (Nam); Next (Nam); end loop; end if; Next (Item); end loop; -- Reset visibility of withed units. They will be made visible again -- when we install the subunit context. Item := First (Context_Items (N)); while Present (Item) loop if Nkind (Item) = N_With_Clause -- Protect frontend against previous errors in context clauses and then Nkind (Name (Item)) /= N_Selected_Component and then not Error_Posted (Item) then Unit_Name := Entity (Name (Item)); loop Set_Is_Visible_Lib_Unit (Unit_Name, False); exit when Scope (Unit_Name) = Standard_Standard; Unit_Name := Scope (Unit_Name); end loop; if Context_Installed (Item) then Set_Is_Immediately_Visible (Unit_Name, False); Set_Context_Installed (Item, False); end if; end if; Next (Item); end loop; end Analyze_Subunit_Context; ------------------------ -- Re_Install_Parents -- ------------------------ procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id) is E : Entity_Id; begin if Nkind (Unit (L)) = N_Subunit then Re_Install_Parents (Library_Unit (L), Scope (Scop)); end if; Install_Context (L); -- If the subunit occurs within a child unit, we must restore the -- immediate visibility of any siblings that may occur in context. if Present (Enclosing_Child) then Install_Siblings (Enclosing_Child, L); end if; Push_Scope (Scop); if Scop /= Par_Unit then Set_Is_Immediately_Visible (Scop); end if; -- Make entities in scope visible again. For child units, restore -- visibility only if they are actually in context. E := First_Entity (Current_Scope); while Present (E) loop if not Is_Child_Unit (E) or else Is_Visible_Lib_Unit (E) then Set_Is_Immediately_Visible (E); end if; Next_Entity (E); end loop; -- A subunit appears within a body, and for a nested subunits all the -- parents are bodies. Restore full visibility of their private -- entities. if Is_Package_Or_Generic_Package (Scop) then Set_In_Package_Body (Scop); Install_Private_Declarations (Scop); end if; end Re_Install_Parents; ---------------------------- -- Re_Install_Use_Clauses -- ---------------------------- procedure Re_Install_Use_Clauses is U : Node_Id; begin for J in reverse 1 .. Num_Scopes loop U := Use_Clauses (J); Scope_Stack.Table (Scope_Stack.Last - J + 1).First_Use_Clause := U; Install_Use_Clauses (U, Force_Installation => True); end loop; end Re_Install_Use_Clauses; ------------------ -- Remove_Scope -- ------------------ procedure Remove_Scope is E : Entity_Id; begin Num_Scopes := Num_Scopes + 1; Use_Clauses (Num_Scopes) := Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause; E := First_Entity (Current_Scope); while Present (E) loop Set_Is_Immediately_Visible (E, False); Next_Entity (E); end loop; if Is_Child_Unit (Current_Scope) then Enclosing_Child := Current_Scope; end if; Pop_Scope; end Remove_Scope; -- Start of processing for Analyze_Subunit begin -- For subunit in main extended unit, we reset the configuration values -- for the non-partition-wide restrictions. For other units reset them. if In_Extended_Main_Source_Unit (N) then Restore_Config_Cunit_Boolean_Restrictions; else Reset_Cunit_Boolean_Restrictions; end if; if Style_Check then declare Nam : Node_Id := Name (Unit (N)); begin if Nkind (Nam) = N_Selected_Component then Nam := Selector_Name (Nam); end if; Check_Identifier (Nam, Par_Unit); end; end if; if not Is_Empty_List (Context_Items (N)) then -- Save current use clauses Remove_Scope; Remove_Context (Lib_Unit); -- Now remove parents and their context, including enclosing subunits -- and the outer parent body which is not a subunit. if Present (Lib_Spec) then Remove_Context (Lib_Spec); while Nkind (Unit (Lib_Spec)) = N_Subunit loop Lib_Spec := Library_Unit (Lib_Spec); Remove_Scope; Remove_Context (Lib_Spec); end loop; if Nkind (Unit (Lib_Unit)) = N_Subunit then Remove_Scope; end if; if Nkind (Unit (Lib_Spec)) = N_Package_Body then Remove_Context (Library_Unit (Lib_Spec)); end if; end if; Set_Is_Immediately_Visible (Par_Unit, False); Analyze_Subunit_Context; Re_Install_Parents (Lib_Unit, Par_Unit); Set_Is_Immediately_Visible (Par_Unit); -- If the context includes a child unit of the parent of the subunit, -- the parent will have been removed from visibility, after compiling -- that cousin in the context. The visibility of the parent must be -- restored now. This also applies if the context includes another -- subunit of the same parent which in turn includes a child unit in -- its context. if Is_Package_Or_Generic_Package (Par_Unit) then if not Is_Immediately_Visible (Par_Unit) or else (Present (First_Entity (Par_Unit)) and then not Is_Immediately_Visible (First_Entity (Par_Unit))) then Set_Is_Immediately_Visible (Par_Unit); Install_Visible_Declarations (Par_Unit); Install_Private_Declarations (Par_Unit); end if; end if; Re_Install_Use_Clauses; Install_Context (N); -- Restore state of suppress flags for current body Scope_Suppress := Svg; -- If the subunit is within a child unit, then siblings of any parent -- unit that appear in the context clause of the subunit must also be -- made immediately visible. if Present (Enclosing_Child) then Install_Siblings (Enclosing_Child, N); end if; end if; Generate_Parent_References (Unit (N), Par_Unit); Analyze (Proper_Body (Unit (N))); Remove_Context (N); -- The subunit may contain a with_clause on a sibling of some ancestor. -- Removing the context will remove from visibility those ancestor child -- units, which must be restored to the visibility they have in the -- enclosing body. if Present (Enclosing_Child) then declare C : Entity_Id; begin C := Current_Scope; while Present (C) and then C /= Standard_Standard loop Set_Is_Immediately_Visible (C); Set_Is_Visible_Lib_Unit (C); C := Scope (C); end loop; end; end if; -- Deal with restore of restrictions Cunit_Boolean_Restrictions_Restore (Save_Cunit_Restrictions); end Analyze_Subunit; ---------------------------- -- Analyze_Task_Body_Stub -- ---------------------------- procedure Analyze_Task_Body_Stub (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Nam : Entity_Id := Current_Entity_In_Scope (Defining_Identifier (N)); begin Check_Stub_Level (N); -- First occurrence of name may have been as an incomplete type if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then Nam := Full_View (Nam); end if; if No (Nam) or else not Is_Task_Type (Etype (Nam)) then Error_Msg_N ("missing specification for task body", N); else Set_Scope (Defining_Entity (N), Current_Scope); Set_Ekind (Defining_Entity (N), E_Task_Body); Generate_Reference (Nam, Defining_Identifier (N), 'b'); Set_Corresponding_Spec_Of_Stub (N, Nam); -- Check for duplicate stub, if so give message and terminate if Has_Completion (Etype (Nam)) then Error_Msg_N ("duplicate stub for task", N); return; else Set_Has_Completion (Etype (Nam)); end if; Analyze_Proper_Body (N, Etype (Nam)); -- Set elaboration flag to indicate that entity is callable. This -- cannot be done in the expansion of the body itself, because the -- proper body is not in a declarative part. This is only done if -- expansion is active, because the context may be generic and the -- flag not defined yet. if Expander_Active then Insert_After (N, Make_Assignment_Statement (Loc, Name => Make_Identifier (Loc, Chars => New_External_Name (Chars (Etype (Nam)), 'E')), Expression => New_Occurrence_Of (Standard_True, Loc))); end if; end if; end Analyze_Task_Body_Stub; ------------------------- -- Analyze_With_Clause -- ------------------------- -- Analyze the declaration of a unit in a with clause. At end, label the -- with clause with the defining entity for the unit. procedure Analyze_With_Clause (N : Node_Id) is -- Retrieve the original kind of the unit node, before analysis. If it -- is a subprogram instantiation, its analysis below will rewrite the -- node as the declaration of the wrapper package. If the same -- instantiation appears indirectly elsewhere in the context, it will -- have been analyzed already. Unit_Kind : constant Node_Kind := Nkind (Original_Node (Unit (Library_Unit (N)))); Nam : constant Node_Id := Name (N); E_Name : Entity_Id; Par_Name : Entity_Id; Pref : Node_Id; U : Node_Id; Intunit : Boolean; -- Set True if the unit currently being compiled is an internal unit Restriction_Violation : Boolean := False; -- Set True if a with violates a restriction, no point in giving any -- warnings if we have this definite error. Save_Style_Check : constant Boolean := Opt.Style_Check; begin U := Unit (Library_Unit (N)); -- If this is an internal unit which is a renaming, then this is a -- violation of No_Obsolescent_Features. -- Note: this is not quite right if the user defines one of these units -- himself, but that's a marginal case, and fixing it is hard ??? if Restriction_Check_Required (No_Obsolescent_Features) then declare F : constant File_Name_Type := Unit_File_Name (Get_Source_Unit (U)); begin if Is_Predefined_File_Name (F, Renamings_Included => True) and then not Is_Predefined_File_Name (F, Renamings_Included => False) then Check_Restriction (No_Obsolescent_Features, N); Restriction_Violation := True; end if; end; end if; -- Check No_Implementation_Units violation if Restriction_Check_Required (No_Implementation_Units) then if Not_Impl_Defined_Unit (Get_Source_Unit (U)) then null; else Check_Restriction (No_Implementation_Units, Nam); Restriction_Violation := True; end if; end if; -- Several actions are skipped for dummy packages (those supplied for -- with's where no matching file could be found). Such packages are -- identified by the Sloc value being set to No_Location. if Limited_Present (N) then -- Ada 2005 (AI-50217): Build visibility structures but do not -- analyze the unit. -- If the designated unit is a predefined unit, which might be used -- implicitly through the rtsfind machinery, a limited with clause -- on such a unit is usually pointless, because run-time units are -- unlikely to appear in mutually dependent units, and because this -- disables the rtsfind mechanism. We transform such limited with -- clauses into regular with clauses. if Sloc (U) /= No_Location then if Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (U))) -- In ASIS mode the rtsfind mechanism plays no role, and -- we need to maintain the original tree structure, so -- this transformation is not performed in this case. and then not ASIS_Mode then Set_Limited_Present (N, False); Analyze_With_Clause (N); else Build_Limited_Views (N); end if; end if; return; end if; -- If we are compiling under "don't quit" mode (-gnatq) and we have -- already detected serious errors then we mark the with-clause nodes as -- analyzed before the corresponding compilation unit is analyzed. This -- is done here to protect the frontend against never ending recursion -- caused by circularities in the sources (because the previous errors -- may break the regular machine of the compiler implemented in -- Load_Unit to detect circularities). if Serious_Errors_Detected > 0 and then Try_Semantics then Set_Analyzed (N); end if; Semantics (Library_Unit (N)); Intunit := Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit)); if Sloc (U) /= No_Location then -- Check restrictions, except that we skip the check if this is an -- internal unit unless we are compiling the internal unit as the -- main unit. We also skip this for dummy packages. Check_Restriction_No_Dependence (Nam, N); if not Intunit or else Current_Sem_Unit = Main_Unit then Check_Restricted_Unit (Unit_Name (Get_Source_Unit (U)), N); end if; -- Deal with special case of GNAT.Current_Exceptions which interacts -- with the optimization of local raise statements into gotos. if Nkind (Nam) = N_Selected_Component and then Nkind (Prefix (Nam)) = N_Identifier and then Chars (Prefix (Nam)) = Name_Gnat and then Nam_In (Chars (Selector_Name (Nam)), Name_Most_Recent_Exception, Name_Exception_Traces) then Check_Restriction (No_Exception_Propagation, N); Special_Exception_Package_Used := True; end if; -- Check for inappropriate with of internal implementation unit if we -- are not compiling an internal unit and also check for withing unit -- in wrong version of Ada. Do not issue these messages for implicit -- with's generated by the compiler itself. if Implementation_Unit_Warnings and then not Intunit and then not Implicit_With (N) and then not Restriction_Violation then declare U_Kind : constant Kind_Of_Unit := Get_Kind_Of_Unit (Get_Source_Unit (U)); begin if U_Kind = Implementation_Unit then Error_Msg_F ("& is an internal 'G'N'A'T unit?i?", Name (N)); -- Add alternative name if available, otherwise issue a -- general warning message. if Error_Msg_Strlen /= 0 then Error_Msg_F ("\use ""~"" instead?i?", Name (N)); else Error_Msg_F ("\use of this unit is non-portable " & "and version-dependent?i?", Name (N)); end if; elsif U_Kind = Ada_2005_Unit and then Ada_Version < Ada_2005 and then Warn_On_Ada_2005_Compatibility then Error_Msg_N ("& is an Ada 2005 unit?i?", Name (N)); elsif U_Kind = Ada_2012_Unit and then Ada_Version < Ada_2012 and then Warn_On_Ada_2012_Compatibility then Error_Msg_N ("& is an Ada 2012 unit?i?", Name (N)); end if; end; end if; end if; -- Semantic analysis of a generic unit is performed on a copy of -- the original tree. Retrieve the entity on which semantic info -- actually appears. if Unit_Kind in N_Generic_Declaration then E_Name := Defining_Entity (U); -- Note: in the following test, Unit_Kind is the original Nkind, but in -- the case of an instantiation, semantic analysis above will have -- replaced the unit by its instantiated version. If the instance body -- has been generated, the instance now denotes the body entity. For -- visibility purposes we need the entity of its spec. elsif (Unit_Kind = N_Package_Instantiation or else Nkind (Original_Node (Unit (Library_Unit (N)))) = N_Package_Instantiation) and then Nkind (U) = N_Package_Body then E_Name := Corresponding_Spec (U); elsif Unit_Kind = N_Package_Instantiation and then Nkind (U) = N_Package_Instantiation and then Present (Instance_Spec (U)) then -- If the instance has not been rewritten as a package declaration, -- then it appeared already in a previous with clause. Retrieve -- the entity from the previous instance. E_Name := Defining_Entity (Specification (Instance_Spec (U))); elsif Unit_Kind in N_Subprogram_Instantiation then -- The visible subprogram is created during instantiation, and is -- an attribute of the wrapper package. We retrieve the wrapper -- package directly from the instantiation node. If the instance -- is inlined the unit is still an instantiation. Otherwise it has -- been rewritten as the declaration of the wrapper itself. if Nkind (U) in N_Subprogram_Instantiation then E_Name := Related_Instance (Defining_Entity (Specification (Instance_Spec (U)))); else E_Name := Related_Instance (Defining_Entity (U)); end if; elsif Unit_Kind = N_Package_Renaming_Declaration or else Unit_Kind in N_Generic_Renaming_Declaration then E_Name := Defining_Entity (U); elsif Unit_Kind = N_Subprogram_Body and then Nkind (Name (N)) = N_Selected_Component and then not Acts_As_Spec (Library_Unit (N)) then -- For a child unit that has no spec, one has been created and -- analyzed. The entity required is that of the spec. E_Name := Corresponding_Spec (U); else E_Name := Defining_Entity (U); end if; if Nkind (Name (N)) = N_Selected_Component then -- Child unit in a with clause Change_Selected_Component_To_Expanded_Name (Name (N)); -- If this is a child unit without a spec, and it has been analyzed -- already, a declaration has been created for it. The with_clause -- must reflect the actual body, and not the generated declaration, -- to prevent spurious binding errors involving an out-of-date spec. -- Note that this can only happen if the unit includes more than one -- with_clause for the child unit (e.g. in separate subunits). if Unit_Kind = N_Subprogram_Declaration and then Analyzed (Library_Unit (N)) and then not Comes_From_Source (Library_Unit (N)) then Set_Library_Unit (N, Cunit (Get_Source_Unit (Corresponding_Body (U)))); end if; end if; -- Restore style checks Style_Check := Save_Style_Check; -- Record the reference, but do NOT set the unit as referenced, we want -- to consider the unit as unreferenced if this is the only reference -- that occurs. Set_Entity_With_Checks (Name (N), E_Name); Generate_Reference (E_Name, Name (N), 'w', Set_Ref => False); -- Generate references and check No_Dependence restriction for parents if Is_Child_Unit (E_Name) then Pref := Prefix (Name (N)); Par_Name := Scope (E_Name); while Nkind (Pref) = N_Selected_Component loop Change_Selected_Component_To_Expanded_Name (Pref); if Present (Entity (Selector_Name (Pref))) and then Present (Renamed_Entity (Entity (Selector_Name (Pref)))) and then Entity (Selector_Name (Pref)) /= Par_Name then -- The prefix is a child unit that denotes a renaming declaration. -- Replace the prefix directly with the renamed unit, because the -- rest of the prefix is irrelevant to the visibility of the real -- unit. Rewrite (Pref, New_Occurrence_Of (Par_Name, Sloc (Pref))); exit; end if; Set_Entity_With_Checks (Pref, Par_Name); Generate_Reference (Par_Name, Pref); Check_Restriction_No_Dependence (Pref, N); Pref := Prefix (Pref); -- If E_Name is the dummy entity for a nonexistent unit, its scope -- is set to Standard_Standard, and no attempt should be made to -- further unwind scopes. if Par_Name /= Standard_Standard then Par_Name := Scope (Par_Name); end if; -- Abandon processing in case of previous errors if No (Par_Name) then Check_Error_Detected; return; end if; end loop; if Present (Entity (Pref)) and then not Analyzed (Parent (Parent (Entity (Pref)))) then -- If the entity is set without its unit being compiled, the -- original parent is a renaming, and Par_Name is the renamed -- entity. For visibility purposes, we need the original entity, -- which must be analyzed now because Load_Unit directly retrieves -- the renamed unit, and the renaming declaration itself has not -- been analyzed. Analyze (Parent (Parent (Entity (Pref)))); pragma Assert (Renamed_Object (Entity (Pref)) = Par_Name); Par_Name := Entity (Pref); end if; -- Guard against missing or misspelled child units if Present (Par_Name) then Set_Entity_With_Checks (Pref, Par_Name); Generate_Reference (Par_Name, Pref); else pragma Assert (Serious_Errors_Detected /= 0); -- Mark the node to indicate that a related error has been posted. -- This defends further compilation passes against improper use of -- the invalid WITH clause node. Set_Error_Posted (N); Set_Name (N, Error); return; end if; end if; -- If the withed unit is System, and a system extension pragma is -- present, compile the extension now, rather than waiting for a -- visibility check on a specific entity. if Chars (E_Name) = Name_System and then Scope (E_Name) = Standard_Standard and then Present (System_Extend_Unit) and then Present_System_Aux (N) then -- If the extension is not present, an error will have been emitted null; end if; -- Ada 2005 (AI-262): Remove from visibility the entity corresponding -- to private_with units; they will be made visible later (just before -- the private part is analyzed) if Private_Present (N) then Set_Is_Immediately_Visible (E_Name, False); end if; -- Propagate Fatal_Error setting from with'ed unit to current unit case Fatal_Error (Get_Source_Unit (Library_Unit (N))) is -- Nothing to do if with'ed unit had no error when None => null; -- If with'ed unit had a detected fatal error, propagate it when Error_Detected => Set_Fatal_Error (Current_Sem_Unit, Error_Detected); -- If with'ed unit had an ignored error, then propagate it but do not -- overide an existring setting. when Error_Ignored => if Fatal_Error (Current_Sem_Unit) = None then Set_Fatal_Error (Current_Sem_Unit, Error_Ignored); end if; end case; Mark_Ghost_Clause (N); end Analyze_With_Clause; ------------------------------ -- Check_Private_Child_Unit -- ------------------------------ procedure Check_Private_Child_Unit (N : Node_Id) is Lib_Unit : constant Node_Id := Unit (N); Item : Node_Id; Curr_Unit : Entity_Id; Sub_Parent : Node_Id; Priv_Child : Entity_Id; Par_Lib : Entity_Id; Par_Spec : Node_Id; function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean; -- Returns true if and only if the library unit is declared with -- an explicit designation of private. ----------------------------- -- Is_Private_Library_Unit -- ----------------------------- function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit)); begin return Private_Present (Comp_Unit); end Is_Private_Library_Unit; -- Start of processing for Check_Private_Child_Unit begin if Nkind_In (Lib_Unit, N_Package_Body, N_Subprogram_Body) then Curr_Unit := Defining_Entity (Unit (Library_Unit (N))); Par_Lib := Curr_Unit; elsif Nkind (Lib_Unit) = N_Subunit then -- The parent is itself a body. The parent entity is to be found in -- the corresponding spec. Sub_Parent := Library_Unit (N); Curr_Unit := Defining_Entity (Unit (Library_Unit (Sub_Parent))); -- If the parent itself is a subunit, Curr_Unit is the entity of the -- enclosing body, retrieve the spec entity which is the proper -- ancestor we need for the following tests. if Ekind (Curr_Unit) = E_Package_Body then Curr_Unit := Spec_Entity (Curr_Unit); end if; Par_Lib := Curr_Unit; else Curr_Unit := Defining_Entity (Lib_Unit); Par_Lib := Curr_Unit; Par_Spec := Parent_Spec (Lib_Unit); if No (Par_Spec) then Par_Lib := Empty; else Par_Lib := Defining_Entity (Unit (Par_Spec)); end if; end if; -- Loop through context items Item := First (Context_Items (N)); while Present (Item) loop -- Ada 2005 (AI-262): Allow private_with of a private child package -- in public siblings if Nkind (Item) = N_With_Clause and then not Implicit_With (Item) and then not Limited_Present (Item) and then Is_Private_Descendant (Entity (Name (Item))) then Priv_Child := Entity (Name (Item)); declare Curr_Parent : Entity_Id := Par_Lib; Child_Parent : Entity_Id := Scope (Priv_Child); Prv_Ancestor : Entity_Id := Child_Parent; Curr_Private : Boolean := Is_Private_Library_Unit (Curr_Unit); begin -- If the child unit is a public child then locate the nearest -- private ancestor. Child_Parent will then be set to the -- parent of that ancestor. if not Is_Private_Library_Unit (Priv_Child) then while Present (Prv_Ancestor) and then not Is_Private_Library_Unit (Prv_Ancestor) loop Prv_Ancestor := Scope (Prv_Ancestor); end loop; if Present (Prv_Ancestor) then Child_Parent := Scope (Prv_Ancestor); end if; end if; while Present (Curr_Parent) and then Curr_Parent /= Standard_Standard and then Curr_Parent /= Child_Parent loop Curr_Private := Curr_Private or else Is_Private_Library_Unit (Curr_Parent); Curr_Parent := Scope (Curr_Parent); end loop; if No (Curr_Parent) then Curr_Parent := Standard_Standard; end if; if Curr_Parent /= Child_Parent then if Ekind (Priv_Child) = E_Generic_Package and then Chars (Priv_Child) in Text_IO_Package_Name and then Chars (Scope (Scope (Priv_Child))) = Name_Ada then Error_Msg_NE ("& is a nested package, not a compilation unit", Name (Item), Priv_Child); else Error_Msg_N ("unit in with clause is private child unit!", Item); Error_Msg_NE ("\current unit must also have parent&!", Item, Child_Parent); end if; elsif Curr_Private or else Private_Present (Item) or else Nkind_In (Lib_Unit, N_Package_Body, N_Subunit) or else (Nkind (Lib_Unit) = N_Subprogram_Body and then not Acts_As_Spec (Parent (Lib_Unit))) then null; else Error_Msg_NE ("current unit must also be private descendant of&", Item, Child_Parent); end if; end; end if; Next (Item); end loop; end Check_Private_Child_Unit; ---------------------- -- Check_Stub_Level -- ---------------------- procedure Check_Stub_Level (N : Node_Id) is Par : constant Node_Id := Parent (N); Kind : constant Node_Kind := Nkind (Par); begin if Nkind_In (Kind, N_Package_Body, N_Subprogram_Body, N_Task_Body, N_Protected_Body) and then Nkind_In (Parent (Par), N_Compilation_Unit, N_Subunit) then null; -- In an instance, a missing stub appears at any level. A warning -- message will have been emitted already for the missing file. elsif not In_Instance then Error_Msg_N ("stub cannot appear in an inner scope", N); elsif Expander_Active then Error_Msg_N ("missing proper body", N); end if; end Check_Stub_Level; ------------------------ -- Expand_With_Clause -- ------------------------ procedure Expand_With_Clause (Item : Node_Id; Nam : Node_Id; N : Node_Id) is Loc : constant Source_Ptr := Sloc (Nam); Ent : constant Entity_Id := Entity (Nam); Withn : Node_Id; P : Node_Id; function Build_Unit_Name (Nam : Node_Id) return Node_Id; -- Build name to be used in implicit with_clause. In most cases this -- is the source name, but if renamings are present we must make the -- original unit visible, not the one it renames. The entity in the -- with clause is the renamed unit, but the identifier is the one from -- the source, which allows us to recover the unit renaming. --------------------- -- Build_Unit_Name -- --------------------- function Build_Unit_Name (Nam : Node_Id) return Node_Id is Ent : Entity_Id; Result : Node_Id; begin if Nkind (Nam) = N_Identifier then return New_Occurrence_Of (Entity (Nam), Loc); else Ent := Entity (Nam); if Present (Entity (Selector_Name (Nam))) and then Chars (Entity (Selector_Name (Nam))) /= Chars (Ent) and then Nkind (Unit_Declaration_Node (Entity (Selector_Name (Nam)))) = N_Package_Renaming_Declaration then -- The name in the with_clause is of the form A.B.C, and B is -- given by a renaming declaration. In that case we may not -- have analyzed the unit for B, but replaced it directly in -- lib-load with the unit it renames. We have to make A.B -- visible, so analyze the declaration for B now, in case it -- has not been done yet. Ent := Entity (Selector_Name (Nam)); Analyze (Parent (Unit_Declaration_Node (Entity (Selector_Name (Nam))))); end if; Result := Make_Expanded_Name (Loc, Chars => Chars (Entity (Nam)), Prefix => Build_Unit_Name (Prefix (Nam)), Selector_Name => New_Occurrence_Of (Ent, Loc)); Set_Entity (Result, Ent); return Result; end if; end Build_Unit_Name; -- Start of processing for Expand_With_Clause begin Withn := Make_With_Clause (Loc, Name => Build_Unit_Name (Nam)); P := Parent (Unit_Declaration_Node (Ent)); Set_Library_Unit (Withn, P); Set_Corresponding_Spec (Withn, Ent); Set_First_Name (Withn, True); Set_Implicit_With (Withn, True); -- If the unit is a package or generic package declaration, a private_ -- with_clause on a child unit implies that the implicit with on the -- parent is also private. if Nkind_In (Unit (N), N_Package_Declaration, N_Generic_Package_Declaration) then Set_Private_Present (Withn, Private_Present (Item)); end if; Prepend (Withn, Context_Items (N)); Mark_Rewrite_Insertion (Withn); Install_Withed_Unit (Withn); -- If we have "with X.Y;", we want to recurse on "X", except in the -- unusual case where X.Y is a renaming of X. In that case, the scope -- of X will be null. if Nkind (Nam) = N_Expanded_Name and then Present (Scope (Entity (Prefix (Nam)))) then Expand_With_Clause (Item, Prefix (Nam), N); end if; end Expand_With_Clause; -------------------------------- -- Generate_Parent_References -- -------------------------------- procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id) is Pref : Node_Id; P_Name : Entity_Id := P_Id; begin if Nkind (N) = N_Subunit then Pref := Name (N); else Pref := Name (Parent (Defining_Entity (N))); end if; if Nkind (Pref) = N_Expanded_Name then -- Done already, if the unit has been compiled indirectly as -- part of the closure of its context because of inlining. return; end if; while Nkind (Pref) = N_Selected_Component loop Change_Selected_Component_To_Expanded_Name (Pref); Set_Entity (Pref, P_Name); Set_Etype (Pref, Etype (P_Name)); Generate_Reference (P_Name, Pref, 'r'); Pref := Prefix (Pref); P_Name := Scope (P_Name); end loop; -- The guard here on P_Name is to handle the error condition where -- the parent unit is missing because the file was not found. if Present (P_Name) then Set_Entity (Pref, P_Name); Set_Etype (Pref, Etype (P_Name)); Generate_Reference (P_Name, Pref, 'r'); Style.Check_Identifier (Pref, P_Name); end if; end Generate_Parent_References; --------------------- -- Has_With_Clause -- --------------------- function Has_With_Clause (C_Unit : Node_Id; Pack : Entity_Id; Is_Limited : Boolean := False) return Boolean is Item : Node_Id; function Named_Unit (Clause : Node_Id) return Entity_Id; -- Return the entity for the unit named in a [limited] with clause ---------------- -- Named_Unit -- ---------------- function Named_Unit (Clause : Node_Id) return Entity_Id is begin if Nkind (Name (Clause)) = N_Selected_Component then return Entity (Selector_Name (Name (Clause))); else return Entity (Name (Clause)); end if; end Named_Unit; -- Start of processing for Has_With_Clause begin if Present (Context_Items (C_Unit)) then Item := First (Context_Items (C_Unit)); while Present (Item) loop if Nkind (Item) = N_With_Clause and then Limited_Present (Item) = Is_Limited and then Named_Unit (Item) = Pack then return True; end if; Next (Item); end loop; end if; return False; end Has_With_Clause; ----------------------------- -- Implicit_With_On_Parent -- ----------------------------- procedure Implicit_With_On_Parent (Child_Unit : Node_Id; N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); P : constant Node_Id := Parent_Spec (Child_Unit); P_Unit : Node_Id := Unit (P); P_Name : constant Entity_Id := Get_Parent_Entity (P_Unit); Withn : Node_Id; function Build_Ancestor_Name (P : Node_Id) return Node_Id; -- Build prefix of child unit name. Recurse if needed function Build_Unit_Name return Node_Id; -- If the unit is a child unit, build qualified name with all ancestors ------------------------- -- Build_Ancestor_Name -- ------------------------- function Build_Ancestor_Name (P : Node_Id) return Node_Id is P_Ref : constant Node_Id := New_Occurrence_Of (Defining_Entity (P), Loc); P_Spec : Node_Id := P; begin -- Ancestor may have been rewritten as a package body. Retrieve -- the original spec to trace earlier ancestors. if Nkind (P) = N_Package_Body and then Nkind (Original_Node (P)) = N_Package_Instantiation then P_Spec := Original_Node (P); end if; if No (Parent_Spec (P_Spec)) then return P_Ref; else return Make_Selected_Component (Loc, Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P_Spec))), Selector_Name => P_Ref); end if; end Build_Ancestor_Name; --------------------- -- Build_Unit_Name -- --------------------- function Build_Unit_Name return Node_Id is Result : Node_Id; begin if No (Parent_Spec (P_Unit)) then return New_Occurrence_Of (P_Name, Loc); else Result := Make_Expanded_Name (Loc, Chars => Chars (P_Name), Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P_Unit))), Selector_Name => New_Occurrence_Of (P_Name, Loc)); Set_Entity (Result, P_Name); return Result; end if; end Build_Unit_Name; -- Start of processing for Implicit_With_On_Parent begin -- The unit of the current compilation may be a package body that -- replaces an instance node. In this case we need the original instance -- node to construct the proper parent name. if Nkind (P_Unit) = N_Package_Body and then Nkind (Original_Node (P_Unit)) = N_Package_Instantiation then P_Unit := Original_Node (P_Unit); end if; -- We add the implicit with if the child unit is the current unit being -- compiled. If the current unit is a body, we do not want to add an -- implicit_with a second time to the corresponding spec. if Nkind (Child_Unit) = N_Package_Declaration and then Child_Unit /= Unit (Cunit (Current_Sem_Unit)) then return; end if; Withn := Make_With_Clause (Loc, Name => Build_Unit_Name); Set_Library_Unit (Withn, P); Set_Corresponding_Spec (Withn, P_Name); Set_First_Name (Withn, True); Set_Implicit_With (Withn, True); -- Node is placed at the beginning of the context items, so that -- subsequent use clauses on the parent can be validated. Prepend (Withn, Context_Items (N)); Mark_Rewrite_Insertion (Withn); Install_Withed_Unit (Withn); if Is_Child_Spec (P_Unit) then Implicit_With_On_Parent (P_Unit, N); end if; end Implicit_With_On_Parent; -------------- -- In_Chain -- -------------- function In_Chain (E : Entity_Id) return Boolean is H : Entity_Id; begin H := Current_Entity (E); while Present (H) loop if H = E then return True; else H := Homonym (H); end if; end loop; return False; end In_Chain; --------------------- -- Install_Context -- --------------------- procedure Install_Context (N : Node_Id) is Lib_Unit : constant Node_Id := Unit (N); begin Install_Context_Clauses (N); if Is_Child_Spec (Lib_Unit) then Install_Parents (Lib_Unit, Private_Present (Parent (Lib_Unit))); end if; Install_Limited_Context_Clauses (N); end Install_Context; ----------------------------- -- Install_Context_Clauses -- ----------------------------- procedure Install_Context_Clauses (N : Node_Id) is Lib_Unit : constant Node_Id := Unit (N); Item : Node_Id; Uname_Node : Entity_Id; Check_Private : Boolean := False; Decl_Node : Node_Id; Lib_Parent : Entity_Id; begin -- First skip configuration pragmas at the start of the context. They -- are not technically part of the context clause, but that's where the -- parser puts them. Note they were analyzed in Analyze_Context. Item := First (Context_Items (N)); while Present (Item) and then Nkind (Item) = N_Pragma and then Pragma_Name (Item) in Configuration_Pragma_Names loop Next (Item); end loop; -- Loop through the actual context clause items. We process everything -- except Limited_With clauses in this routine. Limited_With clauses -- are separately installed (see Install_Limited_Context_Clauses). while Present (Item) loop -- Case of explicit WITH clause if Nkind (Item) = N_With_Clause and then not Implicit_With (Item) then if Limited_Present (Item) then -- Limited withed units will be installed later goto Continue; -- If Name (Item) is not an entity name, something is wrong, and -- this will be detected in due course, for now ignore the item elsif not Is_Entity_Name (Name (Item)) then goto Continue; elsif No (Entity (Name (Item))) then Set_Entity (Name (Item), Any_Id); goto Continue; end if; Uname_Node := Entity (Name (Item)); if Is_Private_Descendant (Uname_Node) then Check_Private := True; end if; Install_Withed_Unit (Item); Decl_Node := Unit_Declaration_Node (Uname_Node); -- If the unit is a subprogram instance, it appears nested within -- a package that carries the parent information. if Is_Generic_Instance (Uname_Node) and then Ekind (Uname_Node) /= E_Package then Decl_Node := Parent (Parent (Decl_Node)); end if; if Is_Child_Spec (Decl_Node) then if Nkind (Name (Item)) = N_Expanded_Name then Expand_With_Clause (Item, Prefix (Name (Item)), N); else -- If not an expanded name, the child unit must be a -- renaming, nothing to do. null; end if; elsif Nkind (Decl_Node) = N_Subprogram_Body and then not Acts_As_Spec (Parent (Decl_Node)) and then Is_Child_Spec (Unit (Library_Unit (Parent (Decl_Node)))) then Implicit_With_On_Parent (Unit (Library_Unit (Parent (Decl_Node))), N); end if; -- Check license conditions unless this is a dummy unit if Sloc (Library_Unit (Item)) /= No_Location then License_Check : declare Withu : constant Unit_Number_Type := Get_Source_Unit (Library_Unit (Item)); Withl : constant License_Type := License (Source_Index (Withu)); Unitl : constant License_Type := License (Source_Index (Current_Sem_Unit)); procedure License_Error; -- Signal error of bad license ------------------- -- License_Error -- ------------------- procedure License_Error is begin Error_Msg_N ("license of withed unit & may be inconsistent??", Name (Item)); end License_Error; -- Start of processing for License_Check begin -- Exclude license check if withed unit is an internal unit. -- This situation arises e.g. with the GPL version of GNAT. if Is_Internal_File_Name (Unit_File_Name (Withu)) then null; -- Otherwise check various cases else case Unitl is when Unknown => null; when Restricted => if Withl = GPL then License_Error; end if; when GPL => if Withl = Restricted then License_Error; end if; when Modified_GPL => if Withl = Restricted or else Withl = GPL then License_Error; end if; when Unrestricted => null; end case; end if; end License_Check; end if; -- Case of USE PACKAGE clause elsif Nkind (Item) = N_Use_Package_Clause then Analyze_Use_Package (Item); -- Case of USE TYPE clause elsif Nkind (Item) = N_Use_Type_Clause then Analyze_Use_Type (Item); -- case of PRAGMA elsif Nkind (Item) = N_Pragma then Analyze (Item); end if; <<Continue>> Next (Item); end loop; if Is_Child_Spec (Lib_Unit) then -- The unit also has implicit with_clauses on its own parents if No (Context_Items (N)) then Set_Context_Items (N, New_List); end if; Implicit_With_On_Parent (Lib_Unit, N); end if; -- If the unit is a body, the context of the specification must also -- be installed. That includes private with_clauses in that context. if Nkind (Lib_Unit) = N_Package_Body or else (Nkind (Lib_Unit) = N_Subprogram_Body and then not Acts_As_Spec (N)) then Install_Context (Library_Unit (N)); -- Only install private with-clauses of a spec that comes from -- source, excluding specs created for a subprogram body that is -- a child unit. if Comes_From_Source (Library_Unit (N)) then Install_Private_With_Clauses (Defining_Entity (Unit (Library_Unit (N)))); end if; if Is_Child_Spec (Unit (Library_Unit (N))) then -- If the unit is the body of a public child unit, the private -- declarations of the parent must be made visible. If the child -- unit is private, the private declarations have been installed -- already in the call to Install_Parents for the spec. Installing -- private declarations must be done for all ancestors of public -- child units. In addition, sibling units mentioned in the -- context clause of the body are directly visible. declare Lib_Spec : Node_Id; P : Node_Id; P_Name : Entity_Id; begin Lib_Spec := Unit (Library_Unit (N)); while Is_Child_Spec (Lib_Spec) loop P := Unit (Parent_Spec (Lib_Spec)); P_Name := Defining_Entity (P); if not (Private_Present (Parent (Lib_Spec))) and then not In_Private_Part (P_Name) then Install_Private_Declarations (P_Name); Install_Private_With_Clauses (P_Name); Set_Use (Private_Declarations (Specification (P))); end if; Lib_Spec := P; end loop; end; end if; -- For a package body, children in context are immediately visible Install_Siblings (Defining_Entity (Unit (Library_Unit (N))), N); end if; if Nkind_In (Lib_Unit, N_Generic_Package_Declaration, N_Generic_Subprogram_Declaration, N_Package_Declaration, N_Subprogram_Declaration) then if Is_Child_Spec (Lib_Unit) then Lib_Parent := Defining_Entity (Unit (Parent_Spec (Lib_Unit))); Set_Is_Private_Descendant (Defining_Entity (Lib_Unit), Is_Private_Descendant (Lib_Parent) or else Private_Present (Parent (Lib_Unit))); else Set_Is_Private_Descendant (Defining_Entity (Lib_Unit), Private_Present (Parent (Lib_Unit))); end if; end if; if Check_Private then Check_Private_Child_Unit (N); end if; end Install_Context_Clauses; ------------------------------------- -- Install_Limited_Context_Clauses -- ------------------------------------- procedure Install_Limited_Context_Clauses (N : Node_Id) is Item : Node_Id; procedure Check_Renamings (P : Node_Id; W : Node_Id); -- Check that the unlimited view of a given compilation_unit is not -- already visible through "use + renamings". procedure Check_Private_Limited_Withed_Unit (Item : Node_Id); -- Check that if a limited_with clause of a given compilation_unit -- mentions a descendant of a private child of some library unit, then -- the given compilation_unit must be the declaration of a private -- descendant of that library unit, or a public descendant of such. The -- code is analogous to that of Check_Private_Child_Unit but we cannot -- use entities on the limited with_clauses because their units have not -- been analyzed, so we have to climb the tree of ancestors looking for -- private keywords. procedure Expand_Limited_With_Clause (Comp_Unit : Node_Id; Nam : Node_Id; N : Node_Id); -- If a child unit appears in a limited_with clause, there are implicit -- limited_with clauses on all parents that are not already visible -- through a regular with clause. This procedure creates the implicit -- limited with_clauses for the parents and loads the corresponding -- units. The shadow entities are created when the inserted clause is -- analyzed. Implements Ada 2005 (AI-50217). --------------------- -- Check_Renamings -- --------------------- procedure Check_Renamings (P : Node_Id; W : Node_Id) is Item : Node_Id; Spec : Node_Id; WEnt : Entity_Id; Nam : Node_Id; E : Entity_Id; E2 : Entity_Id; begin pragma Assert (Nkind (W) = N_With_Clause); -- Protect the frontend against previous critical errors case Nkind (Unit (Library_Unit (W))) is when N_Generic_Package_Declaration | N_Generic_Subprogram_Declaration | N_Package_Declaration | N_Subprogram_Declaration => null; when others => return; end case; -- Check "use + renamings" WEnt := Defining_Unit_Name (Specification (Unit (Library_Unit (W)))); Spec := Specification (Unit (P)); Item := First (Visible_Declarations (Spec)); while Present (Item) loop -- Look only at use package clauses if Nkind (Item) = N_Use_Package_Clause then -- Traverse the list of packages Nam := First (Names (Item)); while Present (Nam) loop E := Entity (Nam); pragma Assert (Present (Parent (E))); if Nkind (Parent (E)) = N_Package_Renaming_Declaration and then Renamed_Entity (E) = WEnt then -- The unlimited view is visible through use clause and -- renamings. There is no need to generate the error -- message here because Is_Visible_Through_Renamings -- takes care of generating the precise error message. return; elsif Nkind (Parent (E)) = N_Package_Specification then -- The use clause may refer to a local package. -- Check all the enclosing scopes. E2 := E; while E2 /= Standard_Standard and then E2 /= WEnt loop E2 := Scope (E2); end loop; if E2 = WEnt then Error_Msg_N ("unlimited view visible through use clause ", W); return; end if; end if; Next (Nam); end loop; end if; Next (Item); end loop; -- Recursive call to check all the ancestors if Is_Child_Spec (Unit (P)) then Check_Renamings (P => Parent_Spec (Unit (P)), W => W); end if; end Check_Renamings; --------------------------------------- -- Check_Private_Limited_Withed_Unit -- --------------------------------------- procedure Check_Private_Limited_Withed_Unit (Item : Node_Id) is Curr_Parent : Node_Id; Child_Parent : Node_Id; Curr_Private : Boolean; begin -- Compilation unit of the parent of the withed library unit Child_Parent := Library_Unit (Item); -- If the child unit is a public child, then locate its nearest -- private ancestor, if any, then Child_Parent will then be set to -- the parent of that ancestor. if not Private_Present (Library_Unit (Item)) then while Present (Child_Parent) and then not Private_Present (Child_Parent) loop Child_Parent := Parent_Spec (Unit (Child_Parent)); end loop; if No (Child_Parent) then return; end if; end if; Child_Parent := Parent_Spec (Unit (Child_Parent)); -- Traverse all the ancestors of the current compilation unit to -- check if it is a descendant of named library unit. Curr_Parent := Parent (Item); Curr_Private := Private_Present (Curr_Parent); while Present (Parent_Spec (Unit (Curr_Parent))) and then Curr_Parent /= Child_Parent loop Curr_Parent := Parent_Spec (Unit (Curr_Parent)); Curr_Private := Curr_Private or else Private_Present (Curr_Parent); end loop; if Curr_Parent /= Child_Parent then Error_Msg_N ("unit in with clause is private child unit!", Item); Error_Msg_NE ("\current unit must also have parent&!", Item, Defining_Unit_Name (Specification (Unit (Child_Parent)))); elsif Private_Present (Parent (Item)) or else Curr_Private or else Private_Present (Item) or else Nkind_In (Unit (Parent (Item)), N_Package_Body, N_Subprogram_Body, N_Subunit) then -- Current unit is private, of descendant of a private unit null; else Error_Msg_NE ("current unit must also be private descendant of&", Item, Defining_Unit_Name (Specification (Unit (Child_Parent)))); end if; end Check_Private_Limited_Withed_Unit; -------------------------------- -- Expand_Limited_With_Clause -- -------------------------------- procedure Expand_Limited_With_Clause (Comp_Unit : Node_Id; Nam : Node_Id; N : Node_Id) is Loc : constant Source_Ptr := Sloc (Nam); Unum : Unit_Number_Type; Withn : Node_Id; function Previous_Withed_Unit (W : Node_Id) return Boolean; -- Returns true if the context already includes a with_clause for -- this unit. If the with_clause is non-limited, the unit is fully -- visible and an implicit limited_with should not be created. If -- there is already a limited_with clause for W, a second one is -- simply redundant. -------------------------- -- Previous_Withed_Unit -- -------------------------- function Previous_Withed_Unit (W : Node_Id) return Boolean is Item : Node_Id; begin -- A limited with_clause cannot appear in the same context_clause -- as a nonlimited with_clause which mentions the same library. Item := First (Context_Items (Comp_Unit)); while Present (Item) loop if Nkind (Item) = N_With_Clause and then Library_Unit (Item) = Library_Unit (W) then return True; end if; Next (Item); end loop; return False; end Previous_Withed_Unit; -- Start of processing for Expand_Limited_With_Clause begin if Nkind (Nam) = N_Identifier then -- Create node for name of withed unit Withn := Make_With_Clause (Loc, Name => New_Copy (Nam)); else pragma Assert (Nkind (Nam) = N_Selected_Component); Withn := Make_With_Clause (Loc, Name => Make_Selected_Component (Loc, Prefix => New_Copy_Tree (Prefix (Nam)), Selector_Name => New_Copy (Selector_Name (Nam)))); Set_Parent (Withn, Parent (N)); end if; Set_Limited_Present (Withn); Set_First_Name (Withn); Set_Implicit_With (Withn); Unum := Load_Unit (Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)), Required => True, Subunit => False, Error_Node => Nam); -- Do not generate a limited_with_clause on the current unit. This -- path is taken when a unit has a limited_with clause on one of its -- child units. if Unum = Current_Sem_Unit then return; end if; Set_Library_Unit (Withn, Cunit (Unum)); Set_Corresponding_Spec (Withn, Specification (Unit (Cunit (Unum)))); if not Previous_Withed_Unit (Withn) then Prepend (Withn, Context_Items (Parent (N))); Mark_Rewrite_Insertion (Withn); -- Add implicit limited_with_clauses for parents of child units -- mentioned in limited_with clauses. if Nkind (Nam) = N_Selected_Component then Expand_Limited_With_Clause (Comp_Unit, Prefix (Nam), N); end if; Analyze (Withn); if not Limited_View_Installed (Withn) then Install_Limited_Withed_Unit (Withn); end if; end if; end Expand_Limited_With_Clause; -- Start of processing for Install_Limited_Context_Clauses begin Item := First (Context_Items (N)); while Present (Item) loop if Nkind (Item) = N_With_Clause and then Limited_Present (Item) and then not Error_Posted (Item) then if Nkind (Name (Item)) = N_Selected_Component then Expand_Limited_With_Clause (Comp_Unit => N, Nam => Prefix (Name (Item)), N => Item); end if; Check_Private_Limited_Withed_Unit (Item); if not Implicit_With (Item) and then Is_Child_Spec (Unit (N)) then Check_Renamings (Parent_Spec (Unit (N)), Item); end if; -- A unit may have a limited with on itself if it has a limited -- with_clause on one of its child units. In that case it is -- already being compiled and it makes no sense to install its -- limited view. -- If the item is a limited_private_with_clause, install it if the -- current unit is a body or if it is a private child. Otherwise -- the private clause is installed before analyzing the private -- part of the current unit. if Library_Unit (Item) /= Cunit (Current_Sem_Unit) and then not Limited_View_Installed (Item) and then not Is_Ancestor_Unit (Library_Unit (Item), Cunit (Current_Sem_Unit)) then if not Private_Present (Item) or else Private_Present (N) or else Nkind_In (Unit (N), N_Package_Body, N_Subprogram_Body, N_Subunit) then Install_Limited_Withed_Unit (Item); end if; end if; end if; Next (Item); end loop; -- Ada 2005 (AI-412): Examine visible declarations of a package spec, -- looking for incomplete subtype declarations of incomplete types -- visible through a limited with clause. if Ada_Version >= Ada_2005 and then Analyzed (N) and then Nkind (Unit (N)) = N_Package_Declaration then declare Decl : Node_Id; Def_Id : Entity_Id; Non_Lim_View : Entity_Id; begin Decl := First (Visible_Declarations (Specification (Unit (N)))); while Present (Decl) loop if Nkind (Decl) = N_Subtype_Declaration and then Ekind (Defining_Identifier (Decl)) = E_Incomplete_Subtype and then From_Limited_With (Defining_Identifier (Decl)) then Def_Id := Defining_Identifier (Decl); Non_Lim_View := Non_Limited_View (Def_Id); if not Is_Incomplete_Type (Non_Lim_View) then -- Convert an incomplete subtype declaration into a -- corresponding non-limited view subtype declaration. -- This is usually the case when analyzing a body that -- has regular with clauses, when the spec has limited -- ones. -- If the non-limited view is still incomplete, it is -- the dummy entry already created, and the declaration -- cannot be reanalyzed. This is the case when installing -- a parent unit that has limited with-clauses. Set_Subtype_Indication (Decl, New_Occurrence_Of (Non_Lim_View, Sloc (Def_Id))); Set_Etype (Def_Id, Non_Lim_View); Set_Ekind (Def_Id, Subtype_Kind (Ekind (Non_Lim_View))); Set_Analyzed (Decl, False); -- Reanalyze the declaration, suppressing the call to -- Enter_Name to avoid duplicate names. Analyze_Subtype_Declaration (N => Decl, Skip => True); end if; end if; Next (Decl); end loop; end; end if; end Install_Limited_Context_Clauses; --------------------- -- Install_Parents -- --------------------- procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean) is P : Node_Id; E_Name : Entity_Id; P_Name : Entity_Id; P_Spec : Node_Id; begin P := Unit (Parent_Spec (Lib_Unit)); P_Name := Get_Parent_Entity (P); if Etype (P_Name) = Any_Type then return; end if; if Ekind (P_Name) = E_Generic_Package and then not Nkind_In (Lib_Unit, N_Generic_Subprogram_Declaration, N_Generic_Package_Declaration) and then Nkind (Lib_Unit) not in N_Generic_Renaming_Declaration then Error_Msg_N ("child of a generic package must be a generic unit", Lib_Unit); elsif not Is_Package_Or_Generic_Package (P_Name) then Error_Msg_N ("parent unit must be package or generic package", Lib_Unit); raise Unrecoverable_Error; elsif Present (Renamed_Object (P_Name)) then Error_Msg_N ("parent unit cannot be a renaming", Lib_Unit); raise Unrecoverable_Error; -- Verify that a child of an instance is itself an instance, or the -- renaming of one. Given that an instance that is a unit is replaced -- with a package declaration, check against the original node. The -- parent may be currently being instantiated, in which case it appears -- as a declaration, but the generic_parent is already established -- indicating that we deal with an instance. elsif Nkind (Original_Node (P)) = N_Package_Instantiation then if Nkind (Lib_Unit) in N_Renaming_Declaration or else Nkind (Original_Node (Lib_Unit)) in N_Generic_Instantiation or else (Nkind (Lib_Unit) = N_Package_Declaration and then Present (Generic_Parent (Specification (Lib_Unit)))) then null; else Error_Msg_N ("child of an instance must be an instance or renaming", Lib_Unit); end if; end if; -- This is the recursive call that ensures all parents are loaded if Is_Child_Spec (P) then Install_Parents (P, Is_Private or else Private_Present (Parent (Lib_Unit))); end if; -- Now we can install the context for this parent Install_Context_Clauses (Parent_Spec (Lib_Unit)); Install_Limited_Context_Clauses (Parent_Spec (Lib_Unit)); Install_Siblings (P_Name, Parent (Lib_Unit)); -- The child unit is in the declarative region of the parent. The parent -- must therefore appear in the scope stack and be visible, as when -- compiling the corresponding body. If the child unit is private or it -- is a package body, private declarations must be accessible as well. -- Use declarations in the parent must also be installed. Finally, other -- child units of the same parent that are in the context are -- immediately visible. -- Find entity for compilation unit, and set its private descendant -- status as needed. Indicate that it is a compilation unit, which is -- redundant in general, but needed if this is a generated child spec -- for a child body without previous spec. E_Name := Defining_Entity (Lib_Unit); Set_Is_Child_Unit (E_Name); Set_Is_Compilation_Unit (E_Name); Set_Is_Private_Descendant (E_Name, Is_Private_Descendant (P_Name) or else Private_Present (Parent (Lib_Unit))); P_Spec := Package_Specification (P_Name); Push_Scope (P_Name); -- Save current visibility of unit Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility := Is_Immediately_Visible (P_Name); Set_Is_Immediately_Visible (P_Name); Install_Visible_Declarations (P_Name); Set_Use (Visible_Declarations (P_Spec)); -- If the parent is a generic unit, its formal part may contain formal -- packages and use clauses for them. if Ekind (P_Name) = E_Generic_Package then Set_Use (Generic_Formal_Declarations (Parent (P_Spec))); end if; if Is_Private or else Private_Present (Parent (Lib_Unit)) then Install_Private_Declarations (P_Name); Install_Private_With_Clauses (P_Name); Set_Use (Private_Declarations (P_Spec)); end if; end Install_Parents; ---------------------------------- -- Install_Private_With_Clauses -- ---------------------------------- procedure Install_Private_With_Clauses (P : Entity_Id) is Decl : constant Node_Id := Unit_Declaration_Node (P); Item : Node_Id; begin if Debug_Flag_I then Write_Str ("install private with clauses of "); Write_Name (Chars (P)); Write_Eol; end if; if Nkind (Parent (Decl)) = N_Compilation_Unit then Item := First (Context_Items (Parent (Decl))); while Present (Item) loop if Nkind (Item) = N_With_Clause and then Private_Present (Item) then -- If the unit is an ancestor of the current one, it is the -- case of a private limited with clause on a child unit, and -- the compilation of one of its descendants, In that case the -- limited view is errelevant. if Limited_Present (Item) then if not Limited_View_Installed (Item) and then not Is_Ancestor_Unit (Library_Unit (Item), Cunit (Current_Sem_Unit)) then Install_Limited_Withed_Unit (Item); end if; else Install_Withed_Unit (Item, Private_With_OK => True); end if; end if; Next (Item); end loop; end if; end Install_Private_With_Clauses; ---------------------- -- Install_Siblings -- ---------------------- procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id) is Item : Node_Id; Id : Entity_Id; Prev : Entity_Id; begin -- Iterate over explicit with clauses, and check whether the scope of -- each entity is an ancestor of the current unit, in which case it is -- immediately visible. Item := First (Context_Items (N)); while Present (Item) loop -- Do not install private_with_clauses declaration, unless unit -- is itself a private child unit, or is a body. Note that for a -- subprogram body the private_with_clause does not take effect -- until after the specification. if Nkind (Item) /= N_With_Clause or else Implicit_With (Item) or else Limited_Present (Item) or else Error_Posted (Item) -- Skip processing malformed trees or else (Try_Semantics and then Nkind (Name (Item)) not in N_Has_Entity) then null; elsif not Private_Present (Item) or else Private_Present (N) or else Nkind (Unit (N)) = N_Package_Body then Id := Entity (Name (Item)); if Is_Child_Unit (Id) and then Is_Ancestor_Package (Scope (Id), U_Name) then Set_Is_Immediately_Visible (Id); -- Check for the presence of another unit in the context that -- may be inadvertently hidden by the child. Prev := Current_Entity (Id); if Present (Prev) and then Is_Immediately_Visible (Prev) and then not Is_Child_Unit (Prev) then declare Clause : Node_Id; begin Clause := First (Context_Items (N)); while Present (Clause) loop if Nkind (Clause) = N_With_Clause and then Entity (Name (Clause)) = Prev then Error_Msg_NE ("child unit& hides compilation unit " & "with the same name??", Name (Item), Id); exit; end if; Next (Clause); end loop; end; end if; -- The With_Clause may be on a grand-child or one of its further -- descendants, which makes a child immediately visible. Examine -- ancestry to determine whether such a child exists. For example, -- if current unit is A.C, and with_clause is on A.X.Y.Z, then X -- is immediately visible. elsif Is_Child_Unit (Id) then declare Par : Entity_Id; begin Par := Scope (Id); while Is_Child_Unit (Par) loop if Is_Ancestor_Package (Scope (Par), U_Name) then Set_Is_Immediately_Visible (Par); exit; end if; Par := Scope (Par); end loop; end; end if; -- If the item is a private with-clause on a child unit, the parent -- may have been installed already, but the child unit must remain -- invisible until installed in a private part or body, unless there -- is already a regular with_clause for it in the current unit. elsif Private_Present (Item) then Id := Entity (Name (Item)); if Is_Child_Unit (Id) then declare Clause : Node_Id; function In_Context return Boolean; -- Scan context of current unit, to check whether there is -- a with_clause on the same unit as a private with-clause -- on a parent, in which case child unit is visible. If the -- unit is a grand-child, the same applies to its parent. ---------------- -- In_Context -- ---------------- function In_Context return Boolean is begin Clause := First (Context_Items (Cunit (Current_Sem_Unit))); while Present (Clause) loop if Nkind (Clause) = N_With_Clause and then Comes_From_Source (Clause) and then Is_Entity_Name (Name (Clause)) and then not Private_Present (Clause) then if Entity (Name (Clause)) = Id or else (Nkind (Name (Clause)) = N_Expanded_Name and then Entity (Prefix (Name (Clause))) = Id) then return True; end if; end if; Next (Clause); end loop; return False; end In_Context; begin Set_Is_Visible_Lib_Unit (Id, In_Context); end; end if; end if; Next (Item); end loop; end Install_Siblings; --------------------------------- -- Install_Limited_Withed_Unit -- --------------------------------- procedure Install_Limited_Withed_Unit (N : Node_Id) is P_Unit : constant Entity_Id := Unit (Library_Unit (N)); E : Entity_Id; P : Entity_Id; Is_Child_Package : Boolean := False; Lim_Header : Entity_Id; Lim_Typ : Entity_Id; procedure Check_Body_Required; -- A unit mentioned in a limited with_clause may not be mentioned in -- a regular with_clause, but must still be included in the current -- partition. We need to determine whether the unit needs a body, so -- that the binder can determine the name of the file to be compiled. -- Checking whether a unit needs a body can be done without semantic -- analysis, by examining the nature of the declarations in the package. function Has_Limited_With_Clause (C_Unit : Entity_Id; Pack : Entity_Id) return Boolean; -- Determine whether any package in the ancestor chain starting with -- C_Unit has a limited with clause for package Pack. function Is_Visible_Through_Renamings (P : Entity_Id) return Boolean; -- Check if some package installed though normal with-clauses has a -- renaming declaration of package P. AARM 10.1.2(21/2). ------------------------- -- Check_Body_Required -- ------------------------- procedure Check_Body_Required is PA : constant List_Id := Pragmas_After (Aux_Decls_Node (Parent (P_Unit))); procedure Check_Declarations (Spec : Node_Id); -- Recursive procedure that does the work and checks nested packages ------------------------ -- Check_Declarations -- ------------------------ procedure Check_Declarations (Spec : Node_Id) is Decl : Node_Id; Incomplete_Decls : constant Elist_Id := New_Elmt_List; Subp_List : constant Elist_Id := New_Elmt_List; procedure Check_Pragma_Import (P : Node_Id); -- If a pragma import applies to a previous subprogram, the -- enclosing unit may not need a body. The processing is syntactic -- and does not require a declaration to be analyzed. The code -- below also handles pragma Import when applied to a subprogram -- that renames another. In this case the pragma applies to the -- renamed entity. -- -- Chains of multiple renames are not handled by the code below. -- It is probably impossible to handle all cases without proper -- name resolution. In such cases the algorithm is conservative -- and will indicate that a body is needed??? ------------------------- -- Check_Pragma_Import -- ------------------------- procedure Check_Pragma_Import (P : Node_Id) is Arg : Node_Id; Prev_Id : Elmt_Id; Subp_Id : Elmt_Id; Imported : Node_Id; procedure Remove_Homonyms (E : Node_Id); -- Make one pass over list of subprograms. Called again if -- subprogram is a renaming. E is known to be an identifier. --------------------- -- Remove_Homonyms -- --------------------- procedure Remove_Homonyms (E : Node_Id) is R : Entity_Id := Empty; -- Name of renamed entity, if any begin Subp_Id := First_Elmt (Subp_List); while Present (Subp_Id) loop if Chars (Node (Subp_Id)) = Chars (E) then if Nkind (Parent (Parent (Node (Subp_Id)))) /= N_Subprogram_Renaming_Declaration then Prev_Id := Subp_Id; Next_Elmt (Subp_Id); Remove_Elmt (Subp_List, Prev_Id); else R := Name (Parent (Parent (Node (Subp_Id)))); exit; end if; else Next_Elmt (Subp_Id); end if; end loop; if Present (R) then if Nkind (R) = N_Identifier then Remove_Homonyms (R); elsif Nkind (R) = N_Selected_Component then Remove_Homonyms (Selector_Name (R)); -- Renaming of attribute else null; end if; end if; end Remove_Homonyms; -- Start of processing for Check_Pragma_Import begin -- Find name of entity in Import pragma. We have not analyzed -- the construct, so we must guard against syntax errors. Arg := Next (First (Pragma_Argument_Associations (P))); if No (Arg) or else Nkind (Expression (Arg)) /= N_Identifier then return; else Imported := Expression (Arg); end if; Remove_Homonyms (Imported); end Check_Pragma_Import; -- Start of processing for Check_Declarations begin -- Search for Elaborate Body pragma Decl := First (Visible_Declarations (Spec)); while Present (Decl) and then Nkind (Decl) = N_Pragma loop if Get_Pragma_Id (Decl) = Pragma_Elaborate_Body then Set_Body_Required (Library_Unit (N)); return; end if; Next (Decl); end loop; -- Look for declarations that require the presence of a body. We -- have already skipped pragmas at the start of the list. while Present (Decl) loop -- Subprogram that comes from source means body may be needed. -- Save for subsequent examination of import pragmas. if Comes_From_Source (Decl) and then (Nkind_In (Decl, N_Subprogram_Declaration, N_Subprogram_Renaming_Declaration, N_Generic_Subprogram_Declaration)) then Append_Elmt (Defining_Entity (Decl), Subp_List); -- Package declaration of generic package declaration. We need -- to recursively examine nested declarations. elsif Nkind_In (Decl, N_Package_Declaration, N_Generic_Package_Declaration) then Check_Declarations (Specification (Decl)); elsif Nkind (Decl) = N_Pragma and then Pragma_Name (Decl) = Name_Import then Check_Pragma_Import (Decl); end if; Next (Decl); end loop; -- Same set of tests for private part. In addition to subprograms -- detect the presence of Taft Amendment types (incomplete types -- completed in the body). Decl := First (Private_Declarations (Spec)); while Present (Decl) loop if Comes_From_Source (Decl) and then (Nkind_In (Decl, N_Subprogram_Declaration, N_Subprogram_Renaming_Declaration, N_Generic_Subprogram_Declaration)) then Append_Elmt (Defining_Entity (Decl), Subp_List); elsif Nkind_In (Decl, N_Package_Declaration, N_Generic_Package_Declaration) then Check_Declarations (Specification (Decl)); -- Collect incomplete type declarations for separate pass elsif Nkind (Decl) = N_Incomplete_Type_Declaration then Append_Elmt (Decl, Incomplete_Decls); elsif Nkind (Decl) = N_Pragma and then Pragma_Name (Decl) = Name_Import then Check_Pragma_Import (Decl); end if; Next (Decl); end loop; -- Now check incomplete declarations to locate Taft amendment -- types. This can be done by examining the defining identifiers -- of type declarations without real semantic analysis. declare Inc : Elmt_Id; begin Inc := First_Elmt (Incomplete_Decls); while Present (Inc) loop Decl := Next (Node (Inc)); while Present (Decl) loop if Nkind (Decl) = N_Full_Type_Declaration and then Chars (Defining_Identifier (Decl)) = Chars (Defining_Identifier (Node (Inc))) then exit; end if; Next (Decl); end loop; -- If no completion, this is a TAT, and a body is needed if No (Decl) then Set_Body_Required (Library_Unit (N)); return; end if; Next_Elmt (Inc); end loop; end; -- Finally, check whether there are subprograms that still require -- a body, i.e. are not renamings or null. if not Is_Empty_Elmt_List (Subp_List) then declare Subp_Id : Elmt_Id; Spec : Node_Id; begin Subp_Id := First_Elmt (Subp_List); Spec := Parent (Node (Subp_Id)); while Present (Subp_Id) loop if Nkind (Parent (Spec)) = N_Subprogram_Renaming_Declaration then null; elsif Nkind (Spec) = N_Procedure_Specification and then Null_Present (Spec) then null; else Set_Body_Required (Library_Unit (N)); return; end if; Next_Elmt (Subp_Id); end loop; end; end if; end Check_Declarations; -- Start of processing for Check_Body_Required begin -- If this is an imported package (Java and CIL usage) no body is -- needed. Scan list of pragmas that may follow a compilation unit -- to look for a relevant pragma Import. if Present (PA) then declare Prag : Node_Id; begin Prag := First (PA); while Present (Prag) loop if Nkind (Prag) = N_Pragma and then Get_Pragma_Id (Prag) = Pragma_Import then return; end if; Next (Prag); end loop; end; end if; Check_Declarations (Specification (P_Unit)); end Check_Body_Required; ----------------------------- -- Has_Limited_With_Clause -- ----------------------------- function Has_Limited_With_Clause (C_Unit : Entity_Id; Pack : Entity_Id) return Boolean is Par : Entity_Id; Par_Unit : Node_Id; begin Par := C_Unit; while Present (Par) loop if Ekind (Par) /= E_Package then exit; end if; -- Retrieve the Compilation_Unit node for Par and determine if -- its context clauses contain a limited with for Pack. Par_Unit := Parent (Parent (Parent (Par))); if Nkind (Par_Unit) = N_Package_Declaration then Par_Unit := Parent (Par_Unit); end if; if Has_With_Clause (Par_Unit, Pack, True) then return True; end if; -- If there are more ancestors, climb up the tree, otherwise we -- are done. if Is_Child_Unit (Par) then Par := Scope (Par); else exit; end if; end loop; return False; end Has_Limited_With_Clause; ---------------------------------- -- Is_Visible_Through_Renamings -- ---------------------------------- function Is_Visible_Through_Renamings (P : Entity_Id) return Boolean is Kind : constant Node_Kind := Nkind (Unit (Cunit (Current_Sem_Unit))); Aux_Unit : Node_Id; Item : Node_Id; Decl : Entity_Id; begin -- Example of the error detected by this subprogram: -- package P is -- type T is ... -- end P; -- with P; -- package Q is -- package Ren_P renames P; -- end Q; -- with Q; -- package R is ... -- limited with P; -- ERROR -- package R.C is ... Aux_Unit := Cunit (Current_Sem_Unit); loop Item := First (Context_Items (Aux_Unit)); while Present (Item) loop if Nkind (Item) = N_With_Clause and then not Limited_Present (Item) and then Nkind (Unit (Library_Unit (Item))) = N_Package_Declaration then Decl := First (Visible_Declarations (Specification (Unit (Library_Unit (Item))))); while Present (Decl) loop if Nkind (Decl) = N_Package_Renaming_Declaration and then Entity (Name (Decl)) = P then -- Generate the error message only if the current unit -- is a package declaration; in case of subprogram -- bodies and package bodies we just return True to -- indicate that the limited view must not be -- installed. if Kind = N_Package_Declaration then Error_Msg_N ("simultaneous visibility of the limited and " & "unlimited views not allowed", N); Error_Msg_Sloc := Sloc (Item); Error_Msg_NE ("\\ unlimited view of & visible through the " & "context clause #", N, P); Error_Msg_Sloc := Sloc (Decl); Error_Msg_NE ("\\ and the renaming #", N, P); end if; return True; end if; Next (Decl); end loop; end if; Next (Item); end loop; -- If it is a body not acting as spec, follow pointer to the -- corresponding spec, otherwise follow pointer to parent spec. if Present (Library_Unit (Aux_Unit)) and then Nkind_In (Unit (Aux_Unit), N_Package_Body, N_Subprogram_Body) then if Aux_Unit = Library_Unit (Aux_Unit) then -- Aux_Unit is a body that acts as a spec. Clause has -- already been flagged as illegal. return False; else Aux_Unit := Library_Unit (Aux_Unit); end if; else Aux_Unit := Parent_Spec (Unit (Aux_Unit)); end if; exit when No (Aux_Unit); end loop; return False; end Is_Visible_Through_Renamings; -- Start of processing for Install_Limited_Withed_Unit begin pragma Assert (not Limited_View_Installed (N)); -- In case of limited with_clause on subprograms, generics, instances, -- or renamings, the corresponding error was previously posted and we -- have nothing to do here. If the file is missing altogether, it has -- no source location. if Nkind (P_Unit) /= N_Package_Declaration or else Sloc (P_Unit) = No_Location then return; end if; P := Defining_Unit_Name (Specification (P_Unit)); -- Handle child packages if Nkind (P) = N_Defining_Program_Unit_Name then Is_Child_Package := True; P := Defining_Identifier (P); end if; -- Do not install the limited-view if the context of the unit is already -- available through a regular with clause. if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body and then Has_With_Clause (Cunit (Current_Sem_Unit), P) then return; end if; -- Do not install the limited-view if the full-view is already visible -- through renaming declarations. if Is_Visible_Through_Renamings (P) then return; end if; -- Do not install the limited view if this is the unit being analyzed. -- This unusual case will happen when a unit has a limited_with clause -- on one of its children. The compilation of the child forces the load -- of the parent which tries to install the limited view of the child -- again. Installing the limited view must also be disabled when -- compiling the body of the child unit. if P = Cunit_Entity (Current_Sem_Unit) or else (Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body and then P = Main_Unit_Entity and then Is_Ancestor_Unit (Cunit (Main_Unit), Cunit (Current_Sem_Unit))) then return; end if; -- This scenario is similar to the one above, the difference is that the -- compilation of sibling Par.Sib forces the load of parent Par which -- tries to install the limited view of Lim_Pack [1]. However Par.Sib -- has a with clause for Lim_Pack [2] in its body, and thus needs the -- non-limited views of all entities from Lim_Pack. -- limited with Lim_Pack; -- [1] -- package Par is ... package Lim_Pack is ... -- with Lim_Pack; -- [2] -- package Par.Sib is ... package body Par.Sib is ... -- In this case Main_Unit_Entity is the spec of Par.Sib and Current_ -- Sem_Unit is the body of Par.Sib. if Ekind (P) = E_Package and then Ekind (Main_Unit_Entity) = E_Package and then Is_Child_Unit (Main_Unit_Entity) -- The body has a regular with clause and then Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body and then Has_With_Clause (Cunit (Current_Sem_Unit), P) -- One of the ancestors has a limited with clause and then Nkind (Parent (Parent (Main_Unit_Entity))) = N_Package_Specification and then Has_Limited_With_Clause (Scope (Main_Unit_Entity), P) then return; end if; -- A common use of the limited-with is to have a limited-with in the -- package spec, and a normal with in its package body. For example: -- limited with X; -- [1] -- package A is ... -- with X; -- [2] -- package body A is ... -- The compilation of A's body installs the context clauses found at [2] -- and then the context clauses of its specification (found at [1]). As -- a consequence, at [1] the specification of X has been analyzed and it -- is immediately visible. According to the semantics of limited-with -- context clauses we don't install the limited view because the full -- view of X supersedes its limited view. if Analyzed (P_Unit) and then (Is_Immediately_Visible (P) or else (Is_Child_Package and then Is_Visible_Lib_Unit (P))) then -- The presence of both the limited and the analyzed nonlimited view -- may also be an error, such as an illegal context for a limited -- with_clause. In that case, do not process the context item at all. if Error_Posted (N) then return; end if; if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then declare Item : Node_Id; begin Item := First (Context_Items (Cunit (Current_Sem_Unit))); while Present (Item) loop if Nkind (Item) = N_With_Clause and then Comes_From_Source (Item) and then Entity (Name (Item)) = P then return; end if; Next (Item); end loop; end; -- If this is a child body, assume that the nonlimited with_clause -- appears in an ancestor. Could be refined ??? if Is_Child_Unit (Defining_Entity (Unit (Library_Unit (Cunit (Current_Sem_Unit))))) then return; end if; else -- If in package declaration, nonlimited view brought in from -- parent unit or some error condition. return; end if; end if; if Debug_Flag_I then Write_Str ("install limited view of "); Write_Name (Chars (P)); Write_Eol; end if; -- If the unit has not been analyzed and the limited view has not been -- already installed then we install it. if not Analyzed (P_Unit) then if not In_Chain (P) then -- Minimum decoration Set_Ekind (P, E_Package); Set_Etype (P, Standard_Void_Type); Set_Scope (P, Standard_Standard); Set_Is_Visible_Lib_Unit (P); if Is_Child_Package then Set_Is_Child_Unit (P); Set_Scope (P, Defining_Entity (Unit (Parent_Spec (P_Unit)))); end if; -- Place entity on visibility structure Set_Homonym (P, Current_Entity (P)); Set_Current_Entity (P); if Debug_Flag_I then Write_Str (" (homonym) chain "); Write_Name (Chars (P)); Write_Eol; end if; -- Install the incomplete view. The first element of the limited -- view is a header (an E_Package entity) used to reference the -- first shadow entity in the private part of the package. Lim_Header := Limited_View (P); Lim_Typ := First_Entity (Lim_Header); while Present (Lim_Typ) and then Lim_Typ /= First_Private_Entity (Lim_Header) loop Set_Homonym (Lim_Typ, Current_Entity (Lim_Typ)); Set_Current_Entity (Lim_Typ); if Debug_Flag_I then Write_Str (" (homonym) chain "); Write_Name (Chars (Lim_Typ)); Write_Eol; end if; Next_Entity (Lim_Typ); end loop; end if; -- If the unit appears in a previous regular with_clause, the regular -- entities of the public part of the withed package must be replaced -- by the shadow ones. -- This code must be kept synchronized with the code that replaces the -- shadow entities by the real entities (see body of Remove_Limited -- With_Clause); otherwise the contents of the homonym chains are not -- consistent. else -- Hide all the type entities of the public part of the package to -- avoid its usage. This is needed to cover all the subtype decla- -- rations because we do not remove them from the homonym chain. E := First_Entity (P); while Present (E) and then E /= First_Private_Entity (P) loop if Is_Type (E) then Set_Was_Hidden (E, Is_Hidden (E)); Set_Is_Hidden (E); end if; Next_Entity (E); end loop; -- Replace the real entities by the shadow entities of the limited -- view. The first element of the limited view is a header that is -- used to reference the first shadow entity in the private part -- of the package. Successive elements are the limited views of the -- type (including regular incomplete types) declared in the package. Lim_Header := Limited_View (P); Lim_Typ := First_Entity (Lim_Header); while Present (Lim_Typ) and then Lim_Typ /= First_Private_Entity (Lim_Header) loop pragma Assert (not In_Chain (Lim_Typ)); -- Do not unchain nested packages and child units if Ekind (Lim_Typ) /= E_Package and then not Is_Child_Unit (Lim_Typ) then declare Prev : Entity_Id; begin Prev := Current_Entity (Lim_Typ); E := Prev; -- Replace E in the homonyms list, so that the limited view -- becomes available. -- If the non-limited view is a record with an anonymous -- self-referential component, the analysis of the record -- declaration creates an incomplete type with the same name -- in order to define an internal access type. The visible -- entity is now the incomplete type, and that is the one to -- replace in the visibility structure. if E = Non_Limited_View (Lim_Typ) or else (Ekind (E) = E_Incomplete_Type and then Full_View (E) = Non_Limited_View (Lim_Typ)) then Set_Homonym (Lim_Typ, Homonym (Prev)); Set_Current_Entity (Lim_Typ); else loop E := Homonym (Prev); -- E may have been removed when installing a previous -- limited_with_clause. exit when No (E); exit when E = Non_Limited_View (Lim_Typ); Prev := Homonym (Prev); end loop; if Present (E) then Set_Homonym (Lim_Typ, Homonym (Homonym (Prev))); Set_Homonym (Prev, Lim_Typ); end if; end if; end; if Debug_Flag_I then Write_Str (" (homonym) chain "); Write_Name (Chars (Lim_Typ)); Write_Eol; end if; end if; Next_Entity (Lim_Typ); end loop; end if; -- The package must be visible while the limited-with clause is active -- because references to the type P.T must resolve in the usual way. -- In addition, we remember that the limited-view has been installed to -- uninstall it at the point of context removal. Set_Is_Immediately_Visible (P); Set_Limited_View_Installed (N); -- If unit has not been analyzed in some previous context, check -- (imperfectly ???) whether it might need a body. if not Analyzed (P_Unit) then Check_Body_Required; end if; -- If the package in the limited_with clause is a child unit, the clause -- is unanalyzed and appears as a selected component. Recast it as an -- expanded name so that the entity can be properly set. Use entity of -- parent, if available, for higher ancestors in the name. if Nkind (Name (N)) = N_Selected_Component then declare Nam : Node_Id; Ent : Entity_Id; begin Nam := Name (N); Ent := P; while Nkind (Nam) = N_Selected_Component and then Present (Ent) loop Change_Selected_Component_To_Expanded_Name (Nam); -- Set entity of parent identifiers if the unit is a child -- unit. This ensures that the tree is properly formed from -- semantic point of view (e.g. for ASIS queries). The unit -- entities are not fully analyzed, so we need to follow unit -- links in the tree. Set_Entity (Nam, Ent); Nam := Prefix (Nam); Ent := Defining_Entity (Unit (Parent_Spec (Unit_Declaration_Node (Ent)))); -- Set entity of last ancestor if Nkind (Nam) = N_Identifier then Set_Entity (Nam, Ent); end if; end loop; end; end if; Set_Entity (Name (N), P); Set_From_Limited_With (P); end Install_Limited_Withed_Unit; ------------------------- -- Install_Withed_Unit -- ------------------------- procedure Install_Withed_Unit (With_Clause : Node_Id; Private_With_OK : Boolean := False) is Uname : constant Entity_Id := Entity (Name (With_Clause)); P : constant Entity_Id := Scope (Uname); begin -- Ada 2005 (AI-262): Do not install the private withed unit if we are -- compiling a package declaration and the Private_With_OK flag was not -- set by the caller. These declarations will be installed later (before -- analyzing the private part of the package). if Private_Present (With_Clause) and then Nkind (Unit (Parent (With_Clause))) = N_Package_Declaration and then not (Private_With_OK) then return; end if; if Debug_Flag_I then if Private_Present (With_Clause) then Write_Str ("install private withed unit "); else Write_Str ("install withed unit "); end if; Write_Name (Chars (Uname)); Write_Eol; end if; -- We do not apply the restrictions to an internal unit unless we are -- compiling the internal unit as a main unit. This check is also -- skipped for dummy units (for missing packages). if Sloc (Uname) /= No_Location and then (not Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit)) or else Current_Sem_Unit = Main_Unit) then Check_Restricted_Unit (Unit_Name (Get_Source_Unit (Uname)), With_Clause); end if; if P /= Standard_Standard then -- If the unit is not analyzed after analysis of the with clause and -- it is an instantiation then it awaits a body and is the main unit. -- Its appearance in the context of some other unit indicates a -- circular dependency (DEC suite perversity). if not Analyzed (Uname) and then Nkind (Parent (Uname)) = N_Package_Instantiation then Error_Msg_N ("instantiation depends on itself", Name (With_Clause)); elsif not Is_Visible_Lib_Unit (Uname) then -- Abandon processing in case of previous errors if No (Scope (Uname)) then Check_Error_Detected; return; end if; Set_Is_Visible_Lib_Unit (Uname); -- If the unit is a wrapper package for a compilation unit that is -- a subprogrm instance, indicate that the instance itself is a -- visible unit. This is necessary if the instance is inlined. if Is_Wrapper_Package (Uname) then Set_Is_Visible_Lib_Unit (Related_Instance (Uname)); end if; -- If the child unit appears in the context of its parent, it is -- immediately visible. if In_Open_Scopes (Scope (Uname)) then Set_Is_Immediately_Visible (Uname); end if; if Is_Generic_Instance (Uname) and then Ekind (Uname) in Subprogram_Kind then -- Set flag as well on the visible entity that denotes the -- instance, which renames the current one. Set_Is_Visible_Lib_Unit (Related_Instance (Defining_Entity (Unit (Library_Unit (With_Clause))))); end if; -- The parent unit may have been installed already, and may have -- appeared in a use clause. if In_Use (Scope (Uname)) then Set_Is_Potentially_Use_Visible (Uname); end if; Set_Context_Installed (With_Clause); end if; elsif not Is_Immediately_Visible (Uname) then Set_Is_Visible_Lib_Unit (Uname); if not Private_Present (With_Clause) or else Private_With_OK then Set_Is_Immediately_Visible (Uname); end if; Set_Context_Installed (With_Clause); end if; -- A with-clause overrides a with-type clause: there are no restric- -- tions on the use of package entities. if Ekind (Uname) = E_Package then Set_From_Limited_With (Uname, False); end if; -- Ada 2005 (AI-377): it is illegal for a with_clause to name a child -- unit if there is a visible homograph for it declared in the same -- declarative region. This pathological case can only arise when an -- instance I1 of a generic unit G1 has an explicit child unit I1.G2, -- G1 has a generic child also named G2, and the context includes with_ -- clauses for both I1.G2 and for G1.G2, making an implicit declaration -- of I1.G2 visible as well. If the child unit is named Standard, do -- not apply the check to the Standard package itself. if Is_Child_Unit (Uname) and then Is_Visible_Lib_Unit (Uname) and then Ada_Version >= Ada_2005 then declare Decl1 : constant Node_Id := Unit_Declaration_Node (P); Decl2 : Node_Id; P2 : Entity_Id; U2 : Entity_Id; begin U2 := Homonym (Uname); while Present (U2) and then U2 /= Standard_Standard loop P2 := Scope (U2); Decl2 := Unit_Declaration_Node (P2); if Is_Child_Unit (U2) and then Is_Visible_Lib_Unit (U2) then if Is_Generic_Instance (P) and then Nkind (Decl1) = N_Package_Declaration and then Generic_Parent (Specification (Decl1)) = P2 then Error_Msg_N ("illegal with_clause", With_Clause); Error_Msg_N ("\child unit has visible homograph" & " (RM 8.3(26), 10.1.1(19))", With_Clause); exit; elsif Is_Generic_Instance (P2) and then Nkind (Decl2) = N_Package_Declaration and then Generic_Parent (Specification (Decl2)) = P then -- With_clause for child unit of instance appears before -- in the context. We want to place the error message on -- it, not on the generic child unit itself. declare Prev_Clause : Node_Id; begin Prev_Clause := First (List_Containing (With_Clause)); while Entity (Name (Prev_Clause)) /= U2 loop Next (Prev_Clause); end loop; pragma Assert (Present (Prev_Clause)); Error_Msg_N ("illegal with_clause", Prev_Clause); Error_Msg_N ("\child unit has visible homograph" & " (RM 8.3(26), 10.1.1(19))", Prev_Clause); exit; end; end if; end if; U2 := Homonym (U2); end loop; end; end if; end Install_Withed_Unit; ------------------- -- Is_Child_Spec -- ------------------- function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean is K : constant Node_Kind := Nkind (Lib_Unit); begin return (K in N_Generic_Declaration or else K in N_Generic_Instantiation or else K in N_Generic_Renaming_Declaration or else K = N_Package_Declaration or else K = N_Package_Renaming_Declaration or else K = N_Subprogram_Declaration or else K = N_Subprogram_Renaming_Declaration) and then Present (Parent_Spec (Lib_Unit)); end Is_Child_Spec; ------------------------------------ -- Is_Legal_Shadow_Entity_In_Body -- ------------------------------------ function Is_Legal_Shadow_Entity_In_Body (T : Entity_Id) return Boolean is C_Unit : constant Node_Id := Cunit (Current_Sem_Unit); begin return Nkind (Unit (C_Unit)) = N_Package_Body and then Has_With_Clause (C_Unit, Cunit_Entity (Get_Source_Unit (Non_Limited_View (T)))); end Is_Legal_Shadow_Entity_In_Body; ---------------------- -- Is_Ancestor_Unit -- ---------------------- function Is_Ancestor_Unit (U1 : Node_Id; U2 : Node_Id) return Boolean is E1 : constant Entity_Id := Defining_Entity (Unit (U1)); E2 : Entity_Id; begin if Nkind_In (Unit (U2), N_Package_Body, N_Subprogram_Body) then E2 := Defining_Entity (Unit (Library_Unit (U2))); return Is_Ancestor_Package (E1, E2); else return False; end if; end Is_Ancestor_Unit; ----------------------- -- Load_Needed_Body -- ----------------------- -- N is a generic unit named in a with clause, or else it is a unit that -- contains a generic unit or an inlined function. In order to perform an -- instantiation, the body of the unit must be present. If the unit itself -- is generic, we assume that an instantiation follows, and load & analyze -- the body unconditionally. This forces analysis of the spec as well. -- If the unit is not generic, but contains a generic unit, it is loaded on -- demand, at the point of instantiation (see ch12). procedure Load_Needed_Body (N : Node_Id; OK : out Boolean; Do_Analyze : Boolean := True) is Body_Name : Unit_Name_Type; Unum : Unit_Number_Type; Save_Style_Check : constant Boolean := Opt.Style_Check; -- The loading and analysis is done with style checks off begin if not GNAT_Mode then Style_Check := False; end if; Body_Name := Get_Body_Name (Get_Unit_Name (Unit (N))); Unum := Load_Unit (Load_Name => Body_Name, Required => False, Subunit => False, Error_Node => N, Renamings => True); if Unum = No_Unit then OK := False; else Compiler_State := Analyzing; -- reset after load if Fatal_Error (Unum) /= Error_Detected or else Try_Semantics then if Debug_Flag_L then Write_Str ("*** Loaded generic body"); Write_Eol; end if; if Do_Analyze then Semantics (Cunit (Unum)); end if; end if; OK := True; end if; Style_Check := Save_Style_Check; end Load_Needed_Body; ------------------------- -- Build_Limited_Views -- ------------------------- procedure Build_Limited_Views (N : Node_Id) is Unum : constant Unit_Number_Type := Get_Source_Unit (Library_Unit (N)); Is_Analyzed : constant Boolean := Analyzed (Cunit (Unum)); Shadow_Pack : Entity_Id; -- The corresponding shadow entity of the withed package. This entity -- offers incomplete views of packages and types as well as abstract -- views of states and variables declared within. Last_Shadow : Entity_Id := Empty; -- The last shadow entity created by routine Build_Shadow_Entity procedure Build_Shadow_Entity (Ent : Entity_Id; Scop : Entity_Id; Shadow : out Entity_Id; Is_Tagged : Boolean := False); -- Create a shadow entity that hides Ent and offers an abstract or -- incomplete view of Ent. Scop is the proper scope. Flag Is_Tagged -- should be set when Ent is a tagged type. The generated entity is -- added to Lim_Header. This routine updates the value of Last_Shadow. procedure Decorate_Package (Ent : Entity_Id; Scop : Entity_Id); -- Perform minimal decoration of a package or its corresponding shadow -- entity denoted by Ent. Scop is the proper scope. procedure Decorate_State (Ent : Entity_Id; Scop : Entity_Id); -- Perform full decoration of an abstract state or its corresponding -- shadow entity denoted by Ent. Scop is the proper scope. procedure Decorate_Type (Ent : Entity_Id; Scop : Entity_Id; Is_Tagged : Boolean := False; Materialize : Boolean := False); -- Perform minimal decoration of a type or its corresponding shadow -- entity denoted by Ent. Scop is the proper scope. Flag Is_Tagged -- should be set when Ent is a tagged type. Flag Materialize should be -- set when Ent is a tagged type and its class-wide type needs to appear -- in the tree. procedure Decorate_Variable (Ent : Entity_Id; Scop : Entity_Id); -- Perform minimal decoration of a variable denoted by Ent. Scop is the -- proper scope. procedure Process_Declarations_And_States (Pack : Entity_Id; Decls : List_Id; Scop : Entity_Id; Create_Abstract_Views : Boolean); -- Inspect the states of package Pack and declarative list Decls. Create -- shadow entities for all nested packages, states, types and variables -- encountered. Scop is the proper scope. Create_Abstract_Views should -- be set when the abstract states and variables need to be processed. ------------------------- -- Build_Shadow_Entity -- ------------------------- procedure Build_Shadow_Entity (Ent : Entity_Id; Scop : Entity_Id; Shadow : out Entity_Id; Is_Tagged : Boolean := False) is begin Shadow := Make_Temporary (Sloc (Ent), 'Z'); -- The shadow entity must share the same name and parent as the -- entity it hides. Set_Chars (Shadow, Chars (Ent)); Set_Parent (Shadow, Parent (Ent)); -- The abstract view of a variable is a state, not another variable if Ekind (Ent) = E_Variable then Set_Ekind (Shadow, E_Abstract_State); else Set_Ekind (Shadow, Ekind (Ent)); end if; Set_Is_Internal (Shadow); Set_From_Limited_With (Shadow); -- Add the new shadow entity to the limited view of the package Last_Shadow := Shadow; Append_Entity (Shadow, Shadow_Pack); -- Perform context-specific decoration of the shadow entity if Ekind (Ent) = E_Abstract_State then Decorate_State (Shadow, Scop); Set_Non_Limited_View (Shadow, Ent); elsif Ekind (Ent) = E_Package then Decorate_Package (Shadow, Scop); elsif Is_Type (Ent) then Decorate_Type (Shadow, Scop, Is_Tagged); Set_Non_Limited_View (Shadow, Ent); if Is_Tagged then Set_Non_Limited_View (Class_Wide_Type (Shadow), Class_Wide_Type (Ent)); end if; if Is_Incomplete_Or_Private_Type (Ent) then Set_Private_Dependents (Shadow, New_Elmt_List); end if; elsif Ekind (Ent) = E_Variable then Decorate_State (Shadow, Scop); Set_Non_Limited_View (Shadow, Ent); end if; end Build_Shadow_Entity; ---------------------- -- Decorate_Package -- ---------------------- procedure Decorate_Package (Ent : Entity_Id; Scop : Entity_Id) is begin Set_Ekind (Ent, E_Package); Set_Etype (Ent, Standard_Void_Type); Set_Scope (Ent, Scop); end Decorate_Package; -------------------- -- Decorate_State -- -------------------- procedure Decorate_State (Ent : Entity_Id; Scop : Entity_Id) is begin Set_Ekind (Ent, E_Abstract_State); Set_Etype (Ent, Standard_Void_Type); Set_Scope (Ent, Scop); Set_Encapsulating_State (Ent, Empty); end Decorate_State; ------------------- -- Decorate_Type -- ------------------- procedure Decorate_Type (Ent : Entity_Id; Scop : Entity_Id; Is_Tagged : Boolean := False; Materialize : Boolean := False) is CW_Typ : Entity_Id; begin -- An unanalyzed type or a shadow entity of a type is treated as an -- incomplete type, and carries the corresponding attributes. Set_Ekind (Ent, E_Incomplete_Type); Set_Etype (Ent, Ent); Set_Full_View (Ent, Empty); Set_Is_First_Subtype (Ent); Set_Scope (Ent, Scop); Set_Stored_Constraint (Ent, No_Elist); Init_Size_Align (Ent); if From_Limited_With (Ent) then Set_Private_Dependents (Ent, New_Elmt_List); end if; -- A tagged type and its corresponding shadow entity share one common -- class-wide type. The list of primitive operations for the shadow -- entity is empty. if Is_Tagged then Set_Is_Tagged_Type (Ent); Set_Direct_Primitive_Operations (Ent, New_Elmt_List); CW_Typ := New_External_Entity (E_Void, Scope (Ent), Sloc (Ent), Ent, 'C', 0, 'T'); Set_Class_Wide_Type (Ent, CW_Typ); -- Set parent to be the same as the parent of the tagged type. -- We need a parent field set, and it is supposed to point to -- the declaration of the type. The tagged type declaration -- essentially declares two separate types, the tagged type -- itself and the corresponding class-wide type, so it is -- reasonable for the parent fields to point to the declaration -- in both cases. Set_Parent (CW_Typ, Parent (Ent)); Set_Ekind (CW_Typ, E_Class_Wide_Type); Set_Class_Wide_Type (CW_Typ, CW_Typ); Set_Etype (CW_Typ, Ent); Set_Equivalent_Type (CW_Typ, Empty); Set_From_Limited_With (CW_Typ, From_Limited_With (Ent)); Set_Has_Unknown_Discriminants (CW_Typ); Set_Is_First_Subtype (CW_Typ); Set_Is_Tagged_Type (CW_Typ); Set_Materialize_Entity (CW_Typ, Materialize); Set_Scope (CW_Typ, Scop); Init_Size_Align (CW_Typ); end if; end Decorate_Type; ----------------------- -- Decorate_Variable -- ----------------------- procedure Decorate_Variable (Ent : Entity_Id; Scop : Entity_Id) is begin Set_Ekind (Ent, E_Variable); Set_Etype (Ent, Standard_Void_Type); Set_Scope (Ent, Scop); end Decorate_Variable; ------------------------------------- -- Process_Declarations_And_States -- ------------------------------------- procedure Process_Declarations_And_States (Pack : Entity_Id; Decls : List_Id; Scop : Entity_Id; Create_Abstract_Views : Boolean) is procedure Find_And_Process_States; -- Determine whether package Pack defines abstract state either by -- using an aspect or a pragma. If this is the case, build shadow -- entities for all abstract states of Pack. procedure Process_States (States : Elist_Id); -- Generate shadow entities for all abstract states in list States ----------------------------- -- Find_And_Process_States -- ----------------------------- procedure Find_And_Process_States is procedure Process_State (State : Node_Id); -- Generate shadow entities for a single abstract state or -- multiple states expressed as an aggregate. ------------------- -- Process_State -- ------------------- procedure Process_State (State : Node_Id) is Loc : constant Source_Ptr := Sloc (State); Decl : Node_Id; Dummy : Entity_Id; Elmt : Node_Id; Id : Entity_Id; begin -- Multiple abstract states appear as an aggregate if Nkind (State) = N_Aggregate then Elmt := First (Expressions (State)); while Present (Elmt) loop Process_State (Elmt); Next (Elmt); end loop; return; -- A null state has no abstract view elsif Nkind (State) = N_Null then return; -- State declaration with various options appears as an -- extension aggregate. elsif Nkind (State) = N_Extension_Aggregate then Decl := Ancestor_Part (State); -- Simple state declaration elsif Nkind (State) = N_Identifier then Decl := State; -- Possibly an illegal state declaration else return; end if; -- Abstract states are elaborated when the related pragma is -- elaborated. Since the withed package is not analyzed yet, -- the entities of the abstract states are not available. To -- overcome this complication, create the entities now and -- store them in their respective declarations. The entities -- are later used by routine Create_Abstract_State to declare -- and enter the states into visibility. if No (Entity (Decl)) then Id := Make_Defining_Identifier (Loc, Chars (Decl)); Set_Entity (Decl, Id); Set_Parent (Id, State); Decorate_State (Id, Scop); -- Otherwise the package was previously withed else Id := Entity (Decl); end if; Build_Shadow_Entity (Id, Scop, Dummy); end Process_State; -- Local variables Pack_Decl : constant Node_Id := Unit_Declaration_Node (Pack); Asp : Node_Id; Decl : Node_Id; -- Start of processing for Find_And_Process_States begin -- Find aspect Abstract_State Asp := First (Aspect_Specifications (Pack_Decl)); while Present (Asp) loop if Chars (Identifier (Asp)) = Name_Abstract_State then Process_State (Expression (Asp)); return; end if; Next (Asp); end loop; -- Find pragma Abstract_State by inspecting the declarations Decl := First (Decls); while Present (Decl) and then Nkind (Decl) = N_Pragma loop if Pragma_Name (Decl) = Name_Abstract_State then Process_State (Get_Pragma_Arg (First (Pragma_Argument_Associations (Decl)))); return; end if; Next (Decl); end loop; end Find_And_Process_States; -------------------- -- Process_States -- -------------------- procedure Process_States (States : Elist_Id) is Dummy : Entity_Id; Elmt : Elmt_Id; begin Elmt := First_Elmt (States); while Present (Elmt) loop Build_Shadow_Entity (Node (Elmt), Scop, Dummy); Next_Elmt (Elmt); end loop; end Process_States; -- Local variables Is_Tagged : Boolean; Decl : Node_Id; Def : Node_Id; Def_Id : Entity_Id; Shadow : Entity_Id; -- Start of processing for Process_Declarations_And_States begin -- Build abstract views for all states defined in the package if Create_Abstract_Views then -- When a package has been analyzed, all states are stored in list -- Abstract_States. Generate the shadow entities directly. if Is_Analyzed then if Present (Abstract_States (Pack)) then Process_States (Abstract_States (Pack)); end if; -- The package may declare abstract states by using an aspect or a -- pragma. Attempt to locate one of these construct and if found, -- build the shadow entities. else Find_And_Process_States; end if; end if; -- Inspect the declarative list, looking for nested packages, types -- and variable declarations. Decl := First (Decls); while Present (Decl) loop -- Packages if Nkind (Decl) = N_Package_Declaration then Def_Id := Defining_Entity (Decl); -- Perform minor decoration when the withed package has not -- been analyzed. if not Is_Analyzed then Decorate_Package (Def_Id, Scop); end if; -- Create a shadow entity that offers a limited view of all -- visible types declared within. Build_Shadow_Entity (Def_Id, Scop, Shadow); Process_Declarations_And_States (Pack => Def_Id, Decls => Visible_Declarations (Specification (Decl)), Scop => Shadow, Create_Abstract_Views => Create_Abstract_Views); -- Types elsif Nkind_In (Decl, N_Full_Type_Declaration, N_Incomplete_Type_Declaration, N_Private_Extension_Declaration, N_Private_Type_Declaration, N_Protected_Type_Declaration, N_Task_Type_Declaration) then Def_Id := Defining_Entity (Decl); -- Determine whether the type is tagged. Note that packages -- included via a limited with clause are not always analyzed, -- hence the tree lookup rather than the use of attribute -- Is_Tagged_Type. if Nkind (Decl) = N_Full_Type_Declaration then Def := Type_Definition (Decl); Is_Tagged := (Nkind (Def) = N_Record_Definition and then Tagged_Present (Def)) or else (Nkind (Def) = N_Derived_Type_Definition and then Present (Record_Extension_Part (Def))); elsif Nkind_In (Decl, N_Incomplete_Type_Declaration, N_Private_Type_Declaration) then Is_Tagged := Tagged_Present (Decl); elsif Nkind (Decl) = N_Private_Extension_Declaration then Is_Tagged := True; else Is_Tagged := False; end if; -- Perform minor decoration when the withed package has not -- been analyzed. if not Is_Analyzed then Decorate_Type (Def_Id, Scop, Is_Tagged, True); end if; -- Create a shadow entity that hides the type and offers an -- incomplete view of the said type. Build_Shadow_Entity (Def_Id, Scop, Shadow, Is_Tagged); -- Variables elsif Create_Abstract_Views and then Nkind (Decl) = N_Object_Declaration and then not Constant_Present (Decl) then Def_Id := Defining_Entity (Decl); -- Perform minor decoration when the withed package has not -- been analyzed. if not Is_Analyzed then Decorate_Variable (Def_Id, Scop); end if; -- Create a shadow entity that hides the variable and offers an -- abstract view of the said variable. Build_Shadow_Entity (Def_Id, Scop, Shadow); end if; Next (Decl); end loop; end Process_Declarations_And_States; -- Local variables Nam : constant Node_Id := Name (N); Pack : constant Entity_Id := Cunit_Entity (Unum); Last_Public_Shadow : Entity_Id := Empty; Private_Shadow : Entity_Id; Spec : Node_Id; -- Start of processing for Build_Limited_Views begin pragma Assert (Limited_Present (N)); -- A library_item mentioned in a limited_with_clause is a package -- declaration, not a subprogram declaration, generic declaration, -- generic instantiation, or package renaming declaration. case Nkind (Unit (Library_Unit (N))) is when N_Package_Declaration => null; when N_Subprogram_Declaration => Error_Msg_N ("subprograms not allowed in limited with_clauses", N); return; when N_Generic_Package_Declaration | N_Generic_Subprogram_Declaration => Error_Msg_N ("generics not allowed in limited with_clauses", N); return; when N_Generic_Instantiation => Error_Msg_N ("generic instantiations not allowed in limited with_clauses", N); return; when N_Generic_Renaming_Declaration => Error_Msg_N ("generic renamings not allowed in limited with_clauses", N); return; when N_Subprogram_Renaming_Declaration => Error_Msg_N ("renamed subprograms not allowed in limited with_clauses", N); return; when N_Package_Renaming_Declaration => Error_Msg_N ("renamed packages not allowed in limited with_clauses", N); return; when others => raise Program_Error; end case; -- The withed unit may not be analyzed, but the with calause itself -- must be minimally decorated. This ensures that the checks on unused -- with clauses also process limieted withs. Set_Ekind (Pack, E_Package); Set_Etype (Pack, Standard_Void_Type); if Is_Entity_Name (Nam) then Set_Entity (Nam, Pack); elsif Nkind (Nam) = N_Selected_Component then Set_Entity (Selector_Name (Nam), Pack); end if; -- Check if the chain is already built Spec := Specification (Unit (Library_Unit (N))); if Limited_View_Installed (Spec) then return; end if; -- Create the shadow package wich hides the withed unit and provides -- incomplete view of all types and packages declared within. Shadow_Pack := Make_Temporary (Sloc (N), 'Z'); Set_Ekind (Shadow_Pack, E_Package); Set_Is_Internal (Shadow_Pack); Set_Limited_View (Pack, Shadow_Pack); -- Inspect the abstract states and visible declarations of the withed -- unit and create shadow entities that hide existing packages, states, -- variables and types. Process_Declarations_And_States (Pack => Pack, Decls => Visible_Declarations (Spec), Scop => Pack, Create_Abstract_Views => True); Last_Public_Shadow := Last_Shadow; -- Ada 2005 (AI-262): Build the limited view of the private declarations -- to accomodate limited private with clauses. Process_Declarations_And_States (Pack => Pack, Decls => Private_Declarations (Spec), Scop => Pack, Create_Abstract_Views => False); if Present (Last_Public_Shadow) then Private_Shadow := Next_Entity (Last_Public_Shadow); else Private_Shadow := First_Entity (Shadow_Pack); end if; Set_First_Private_Entity (Shadow_Pack, Private_Shadow); Set_Limited_View_Installed (Spec); end Build_Limited_Views; ---------------------------- -- Check_No_Elab_Code_All -- ---------------------------- procedure Check_No_Elab_Code_All (N : Node_Id) is begin if Present (No_Elab_Code_All_Pragma) and then In_Extended_Main_Source_Unit (N) and then Present (Context_Items (N)) then declare CL : constant List_Id := Context_Items (N); CI : Node_Id; begin CI := First (CL); while Present (CI) loop if Nkind (CI) = N_With_Clause and then not No_Elab_Code_All (Get_Source_Unit (Library_Unit (CI))) -- In GNATprove mode, some runtime units are implicitly -- loaded to make their entities available for analysis. In -- this case, ignore violations of No_Elaboration_Code_All -- for this special analysis mode. and then not (GNATprove_Mode and then Implicit_With (CI)) then Error_Msg_Sloc := Sloc (No_Elab_Code_All_Pragma); Error_Msg_N ("violation of No_Elaboration_Code_All#", CI); Error_Msg_NE ("\unit& does not have No_Elaboration_Code_All", CI, Entity (Name (CI))); end if; Next (CI); end loop; end; end if; end Check_No_Elab_Code_All; ------------------------------- -- Check_Body_Needed_For_SAL -- ------------------------------- procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id) is function Entity_Needs_Body (E : Entity_Id) return Boolean; -- Determine whether use of entity E might require the presence of its -- body. For a package this requires a recursive traversal of all nested -- declarations. ----------------------- -- Entity_Needs_Body -- ----------------------- function Entity_Needs_Body (E : Entity_Id) return Boolean is Ent : Entity_Id; begin if Is_Subprogram (E) and then Has_Pragma_Inline (E) then return True; elsif Ekind_In (E, E_Generic_Function, E_Generic_Procedure) then -- A generic subprogram always requires the presence of its -- body because an instantiation needs both templates. The only -- exceptions is a generic subprogram renaming. In this case the -- body is needed only when the template is declared outside the -- compilation unit being checked. if Present (Renamed_Entity (E)) then return not Within_Scope (E, Unit_Name); else return True; end if; elsif Ekind (E) = E_Generic_Package and then Nkind (Unit_Declaration_Node (E)) = N_Generic_Package_Declaration and then Present (Corresponding_Body (Unit_Declaration_Node (E))) then return True; elsif Ekind (E) = E_Package and then Nkind (Unit_Declaration_Node (E)) = N_Package_Declaration and then Present (Corresponding_Body (Unit_Declaration_Node (E))) then Ent := First_Entity (E); while Present (Ent) loop if Entity_Needs_Body (Ent) then return True; end if; Next_Entity (Ent); end loop; return False; else return False; end if; end Entity_Needs_Body; -- Start of processing for Check_Body_Needed_For_SAL begin if Ekind (Unit_Name) = E_Generic_Package and then Nkind (Unit_Declaration_Node (Unit_Name)) = N_Generic_Package_Declaration and then Present (Corresponding_Body (Unit_Declaration_Node (Unit_Name))) then Set_Body_Needed_For_SAL (Unit_Name); elsif Ekind_In (Unit_Name, E_Generic_Procedure, E_Generic_Function) then Set_Body_Needed_For_SAL (Unit_Name); elsif Is_Subprogram (Unit_Name) and then Nkind (Unit_Declaration_Node (Unit_Name)) = N_Subprogram_Declaration and then Has_Pragma_Inline (Unit_Name) then Set_Body_Needed_For_SAL (Unit_Name); elsif Ekind (Unit_Name) = E_Subprogram_Body then Check_Body_Needed_For_SAL (Corresponding_Spec (Unit_Declaration_Node (Unit_Name))); elsif Ekind (Unit_Name) = E_Package and then Entity_Needs_Body (Unit_Name) then Set_Body_Needed_For_SAL (Unit_Name); elsif Ekind (Unit_Name) = E_Package_Body and then Nkind (Unit_Declaration_Node (Unit_Name)) = N_Package_Body then Check_Body_Needed_For_SAL (Corresponding_Spec (Unit_Declaration_Node (Unit_Name))); end if; end Check_Body_Needed_For_SAL; -------------------- -- Remove_Context -- -------------------- procedure Remove_Context (N : Node_Id) is Lib_Unit : constant Node_Id := Unit (N); begin -- If this is a child unit, first remove the parent units if Is_Child_Spec (Lib_Unit) then Remove_Parents (Lib_Unit); end if; Remove_Context_Clauses (N); end Remove_Context; ---------------------------- -- Remove_Context_Clauses -- ---------------------------- procedure Remove_Context_Clauses (N : Node_Id) is Item : Node_Id; Unit_Name : Entity_Id; begin -- Ada 2005 (AI-50217): We remove the context clauses in two phases: -- limited-views first and regular-views later (to maintain the -- stack model). -- First Phase: Remove limited_with context clauses Item := First (Context_Items (N)); while Present (Item) loop -- We are interested only in with clauses which got installed -- on entry. if Nkind (Item) = N_With_Clause and then Limited_Present (Item) and then Limited_View_Installed (Item) then Remove_Limited_With_Clause (Item); end if; Next (Item); end loop; -- Second Phase: Loop through context items and undo regular -- with_clauses and use_clauses. Item := First (Context_Items (N)); while Present (Item) loop -- We are interested only in with clauses which got installed on -- entry, as indicated by their Context_Installed flag set if Nkind (Item) = N_With_Clause and then Limited_Present (Item) and then Limited_View_Installed (Item) then null; elsif Nkind (Item) = N_With_Clause and then Context_Installed (Item) then -- Remove items from one with'ed unit Unit_Name := Entity (Name (Item)); Remove_Unit_From_Visibility (Unit_Name); Set_Context_Installed (Item, False); elsif Nkind (Item) = N_Use_Package_Clause then End_Use_Package (Item); elsif Nkind (Item) = N_Use_Type_Clause then End_Use_Type (Item); end if; Next (Item); end loop; end Remove_Context_Clauses; -------------------------------- -- Remove_Limited_With_Clause -- -------------------------------- procedure Remove_Limited_With_Clause (N : Node_Id) is P_Unit : constant Entity_Id := Unit (Library_Unit (N)); E : Entity_Id; P : Entity_Id; Lim_Header : Entity_Id; Lim_Typ : Entity_Id; Prev : Entity_Id; begin pragma Assert (Limited_View_Installed (N)); -- In case of limited with_clause on subprograms, generics, instances, -- or renamings, the corresponding error was previously posted and we -- have nothing to do here. if Nkind (P_Unit) /= N_Package_Declaration then return; end if; P := Defining_Unit_Name (Specification (P_Unit)); -- Handle child packages if Nkind (P) = N_Defining_Program_Unit_Name then P := Defining_Identifier (P); end if; if Debug_Flag_I then Write_Str ("remove limited view of "); Write_Name (Chars (P)); Write_Str (" from visibility"); Write_Eol; end if; -- Prepare the removal of the shadow entities from visibility. The first -- element of the limited view is a header (an E_Package entity) that is -- used to reference the first shadow entity in the private part of the -- package Lim_Header := Limited_View (P); Lim_Typ := First_Entity (Lim_Header); -- Remove package and shadow entities from visibility if it has not -- been analyzed if not Analyzed (P_Unit) then Unchain (P); Set_Is_Immediately_Visible (P, False); while Present (Lim_Typ) loop Unchain (Lim_Typ); Next_Entity (Lim_Typ); end loop; -- Otherwise this package has already appeared in the closure and its -- shadow entities must be replaced by its real entities. This code -- must be kept synchronized with the complementary code in Install -- Limited_Withed_Unit. else -- If the limited_with_clause is in some other unit in the context -- then it is not visible in the main unit. if not In_Extended_Main_Source_Unit (N) then Set_Is_Immediately_Visible (P, False); end if; -- Real entities that are type or subtype declarations were hidden -- from visibility at the point of installation of the limited-view. -- Now we recover the previous value of the hidden attribute. E := First_Entity (P); while Present (E) and then E /= First_Private_Entity (P) loop if Is_Type (E) then Set_Is_Hidden (E, Was_Hidden (E)); end if; Next_Entity (E); end loop; while Present (Lim_Typ) and then Lim_Typ /= First_Private_Entity (Lim_Header) loop -- Nested packages and child units were not unchained if Ekind (Lim_Typ) /= E_Package and then not Is_Child_Unit (Non_Limited_View (Lim_Typ)) then -- If the package has incomplete types, the limited view of the -- incomplete type is in fact never visible (AI05-129) but we -- have created a shadow entity E1 for it, that points to E2, -- a non-limited incomplete type. This in turn has a full view -- E3 that is the full declaration. There is a corresponding -- shadow entity E4. When reinstalling the non-limited view, -- E2 must become the current entity and E3 must be ignored. E := Non_Limited_View (Lim_Typ); if Present (Current_Entity (E)) and then Ekind (Current_Entity (E)) = E_Incomplete_Type and then Full_View (Current_Entity (E)) = E then -- Lim_Typ is the limited view of a full type declaration -- that has a previous incomplete declaration, i.e. E3 from -- the previous description. Nothing to insert. null; else pragma Assert (not In_Chain (E)); Prev := Current_Entity (Lim_Typ); if Prev = Lim_Typ then Set_Current_Entity (E); else while Present (Prev) and then Homonym (Prev) /= Lim_Typ loop Prev := Homonym (Prev); end loop; if Present (Prev) then Set_Homonym (Prev, E); end if; end if; -- Preserve structure of homonym chain Set_Homonym (E, Homonym (Lim_Typ)); end if; end if; Next_Entity (Lim_Typ); end loop; end if; -- Indicate that the limited view of the package is not installed Set_From_Limited_With (P, False); Set_Limited_View_Installed (N, False); end Remove_Limited_With_Clause; -------------------- -- Remove_Parents -- -------------------- procedure Remove_Parents (Lib_Unit : Node_Id) is P : Node_Id; P_Name : Entity_Id; P_Spec : Node_Id := Empty; E : Entity_Id; Vis : constant Boolean := Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility; begin if Is_Child_Spec (Lib_Unit) then P_Spec := Parent_Spec (Lib_Unit); elsif Nkind (Lib_Unit) = N_Package_Body and then Nkind (Original_Node (Lib_Unit)) = N_Package_Instantiation then P_Spec := Parent_Spec (Original_Node (Lib_Unit)); end if; if Present (P_Spec) then P := Unit (P_Spec); P_Name := Get_Parent_Entity (P); Remove_Context_Clauses (P_Spec); End_Package_Scope (P_Name); Set_Is_Immediately_Visible (P_Name, Vis); -- Remove from visibility the siblings as well, which are directly -- visible while the parent is in scope. E := First_Entity (P_Name); while Present (E) loop if Is_Child_Unit (E) then Set_Is_Immediately_Visible (E, False); end if; Next_Entity (E); end loop; Set_In_Package_Body (P_Name, False); -- This is the recursive call to remove the context of any higher -- level parent. This recursion ensures that all parents are removed -- in the reverse order of their installation. Remove_Parents (P); end if; end Remove_Parents; --------------------------------- -- Remove_Private_With_Clauses -- --------------------------------- procedure Remove_Private_With_Clauses (Comp_Unit : Node_Id) is Item : Node_Id; function In_Regular_With_Clause (E : Entity_Id) return Boolean; -- Check whether a given unit appears in a regular with_clause. Used to -- determine whether a private_with_clause, implicit or explicit, should -- be ignored. ---------------------------- -- In_Regular_With_Clause -- ---------------------------- function In_Regular_With_Clause (E : Entity_Id) return Boolean is Item : Node_Id; begin Item := First (Context_Items (Comp_Unit)); while Present (Item) loop if Nkind (Item) = N_With_Clause -- The following guard is needed to ensure that the name has -- been properly analyzed before we go fetching its entity. and then Is_Entity_Name (Name (Item)) and then Entity (Name (Item)) = E and then not Private_Present (Item) then return True; end if; Next (Item); end loop; return False; end In_Regular_With_Clause; -- Start of processing for Remove_Private_With_Clauses begin Item := First (Context_Items (Comp_Unit)); while Present (Item) loop if Nkind (Item) = N_With_Clause and then Private_Present (Item) then -- If private_with_clause is redundant, remove it from context, -- as a small optimization to subsequent handling of private_with -- clauses in other nested packages. if In_Regular_With_Clause (Entity (Name (Item))) then declare Nxt : constant Node_Id := Next (Item); begin Remove (Item); Item := Nxt; end; elsif Limited_Present (Item) then if not Limited_View_Installed (Item) then Remove_Limited_With_Clause (Item); end if; Next (Item); else Remove_Unit_From_Visibility (Entity (Name (Item))); Set_Context_Installed (Item, False); Next (Item); end if; else Next (Item); end if; end loop; end Remove_Private_With_Clauses; --------------------------------- -- Remove_Unit_From_Visibility -- --------------------------------- procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id) is begin if Debug_Flag_I then Write_Str ("remove unit "); Write_Name (Chars (Unit_Name)); Write_Str (" from visibility"); Write_Eol; end if; Set_Is_Visible_Lib_Unit (Unit_Name, False); Set_Is_Potentially_Use_Visible (Unit_Name, False); Set_Is_Immediately_Visible (Unit_Name, False); -- If the unit is a wrapper package, the subprogram instance is -- what must be removed from visibility. -- Should we use Related_Instance instead??? if Is_Wrapper_Package (Unit_Name) then Set_Is_Immediately_Visible (Current_Entity (Unit_Name), False); end if; end Remove_Unit_From_Visibility; -------- -- sm -- -------- procedure sm is begin null; end sm; ------------- -- Unchain -- ------------- procedure Unchain (E : Entity_Id) is Prev : Entity_Id; begin Prev := Current_Entity (E); if No (Prev) then return; elsif Prev = E then Set_Name_Entity_Id (Chars (E), Homonym (E)); else while Present (Prev) and then Homonym (Prev) /= E loop Prev := Homonym (Prev); end loop; if Present (Prev) then Set_Homonym (Prev, Homonym (E)); end if; end if; if Debug_Flag_I then Write_Str (" (homonym) unchain "); Write_Name (Chars (E)); Write_Eol; end if; end Unchain; end Sem_Ch10;
-- { dg-do run } with Ada.Text_IO; procedure Modular1 is type T1 is mod 9; package T1_IO is new Ada.Text_IO.Modular_IO(T1); X: T1 := 8; J1: constant := 5; begin for J2 in 5..5 loop pragma Assert(X*(2**J1) = X*(2**J2)); if X*(2**J1) /= X*(2**J2) then raise Program_Error; end if; end loop; end Modular1;
-- ___ _ ___ _ _ -- -- / __| |/ (_) | | Common SKilL implementation -- -- \__ \ ' <| | | |__ implementation of builtin field types -- -- |___/_|\_\_|_|____| by: Timm Felden -- -- -- pragma Ada_2012; with Ada.Containers; with Ada.Containers.Doubly_Linked_Lists; with Ada.Containers.Hashed_Maps; with Ada.Containers.Hashed_Sets; with Ada.Containers.Vectors; with Skill.Types; with Skill.Hashes; use Skill.Hashes; with Skill.Types.Pools; with Ada.Tags; package body Skill.Field_Types.Constant_Types is pragma Warnings (Off); function Read_Box (This : access Field_Type; Input : Streams.Reader.Stream) return Types.Box is function Boxed is new Ada.Unchecked_Conversion(Types.Annotation, Types.Box); begin raise Constraint_Error with "can not read a constant!"; return Boxed(null); end Read_Box; end Skill.Field_Types.Constant_Types;
with collada.Asset, collada.Libraries; package collada.Document -- -- Models a colada document. -- is type Item is tagged private; function to_Document (Filename : in String) return Item; function Asset (Self : in Item) return collada.Asset .item; function Libraries (Self : in Item) return collada.Libraries.item; private type Item is tagged record Asset : collada.Asset .item; Libraries : collada.Libraries.item; end record; end collada.Document;
-- -- Copyright 2021 (C) Holger Rodriguez -- -- SPDX-License-Identifier: BSD-3-Clause -- package body Evaluate.Matrices is -------------------------------------------------------------------------- -- Check functions for the input received -- Those functions set the global variables to the received value -- as a side effect -------------------------------------------------------------------------- function Check_Block (Block_Char : Character) return Boolean; function Check_Size (Size_Char : Character) return Boolean; function Check_Position (Position_Char : Character) return Boolean; function Check_Value (Value_String : Execute.Matrix_Value_Type) return Boolean; -------------------------------------------------------------------------- -- Those variables hold the input received and are set by the -- different Check_ functions -------------------------------------------------------------------------- Block : Blocks; Size : Sizes; Position : Positions; Value : Execute.Matrix_Value_Type; -------------------------------------------------------------------------- -- see .ads -------------------------------------------------------------------------- function Check_Input (Instruction : Matrix_Instruction) return Execute.Matrix_Errors is begin if not Check_Block (Instruction (1)) then return Execute.M_Wrong_Block; end if; if not Check_Size (Instruction (2)) then return Execute.M_Wrong_Size; end if; if Block = Zero then -- only supports Byte/Word_0 if Size /= Byte and Size /= Word then return Execute.M_Wrong_Size; end if; end if; if not Check_Position (Instruction (3)) then return Execute.M_Wrong_Position; end if; if Block = Zero then -- We only allow: -- Byte: 0/1 -- Word: 0 if Size = Byte then -- only supports Zero, One if Position /= Zero and Position /= One then return Execute.M_Wrong_Position; end if; else -- if Word, then only Zero if Position /= Zero then return Execute.M_Wrong_Position; end if; end if; else -- Block 1: Double Word we only support Zero if Size = Double_Word then if Position /= Zero then return Execute.M_Wrong_Position; end if; end if; end if; if not Check_Value (Instruction (4 .. Matrix_Instruction'Last)) then return Execute.M_Wrong_Value; end if; return Execute.M_OK; end Check_Input; -------------------------------------------------------------------------- -- see .ads -------------------------------------------------------------------------- function Evaluate (Instruction : Matrix_Instruction) return Execute.Matrix_Command is RetVal : Execute.Matrix_Command; begin RetVal.Value := Value; if Block = Zero then RetVal.Block := Execute.Block_0; else RetVal.Block := Execute.Block_1; end if; case Size is when Byte => if Position = Zero then RetVal.Command := Execute.Byte_0; elsif Position = One then RetVal.Command := Execute.Byte_1; elsif Position = Two then RetVal.Command := Execute.Byte_2; elsif Position = Three then RetVal.Command := Execute.Byte_3; end if; when Word => if Position = Zero then RetVal.Command := Execute.Word_0; elsif Position = One then RetVal.Command := Execute.Word_1; end if; when Double_Word => RetVal.Command := Execute.Double_Word_0; end case; return RetVal; end Evaluate; -------------------------------------------------------------------------- -- Checks the character for the correct block request -------------------------------------------------------------------------- function Check_Block (Block_Char : Character) return Boolean is type B_2_C_Map is array (Blocks) of Character; B_2_C : constant B_2_C_Map := (Zero => '0', One => '1'); begin for B in B_2_C_Map'First .. B_2_C_Map'Last loop if Block_Char = B_2_C (B) then Block := B; return True; end if; end loop; return False; end Check_Block; -------------------------------------------------------------------------- -- Checks the character for the correct size request -------------------------------------------------------------------------- function Check_Size (Size_Char : Character) return Boolean is type S_2_C_Map is array (Sizes) of Character; S_2_C : constant S_2_C_Map := (Byte => 'B', Word => 'W', Double_Word => 'D' ); begin for S in S_2_C_Map'First .. S_2_C_Map'Last loop if Size_Char = S_2_C (S) then Size := S; return True; end if; end loop; return False; end Check_Size; -------------------------------------------------------------------------- -- Checks the character for the correct position request -------------------------------------------------------------------------- function Check_Position (Position_Char : Character) return Boolean is type P_2_C_Map is array (Positions) of Character; P_2_C : constant P_2_C_Map := (Zero => '0', One => '1', Two => '2', Three => '3'); begin for P in P_2_C_Map'First .. P_2_C_Map'Last loop if Position_Char = P_2_C (P) then Position := P; return True; end if; end loop; return False; end Check_Position; -------------------------------------------------------------------------- -- Checks the characters for the correct value request -------------------------------------------------------------------------- function Check_Value (Value_String : Execute.Matrix_Value_Type) return Boolean is Last : Integer; begin case Size is when Byte => Last := 2; when Word => Last := 4; when Double_Word => Last := 8; end case; for I in 1 .. Last loop case Value_String (I) is when '0' .. 'F' => Value (I) := Value_String (I); when others => return False; end case; end loop; return True; end Check_Value; end Evaluate.Matrices;
with Ada.Unchecked_Conversion, Interfaces.C, Interfaces.C.Extensions; package body Libtcod.Input is use sys_h, console_types_h, mouse_types_h, Interfaces.C; use type Interfaces.C.Extensions.bool; function TCOD_Keycode_To_Key_Type is new Ada.Unchecked_Conversion (Source => TCOD_keycode_t, Target => Key_Type); function get_key_type(k : Key) return Key_Type is (TCOD_Keycode_To_Key_Type(k.vk)); function get_char(k : Key) return Character is (Character(k.text(0))); pragma Warnings (Off, "redundant conversion, expression is *"); function alt(k : Key) return Boolean is (Boolean(k.lalt or k.ralt)); function ctrl(k : Key) return Boolean is (Boolean(k.lctrl or k.rctrl)); function meta(k : Key) return Boolean is (Boolean(k.lmeta or k.rmeta)); function shift(k : Key) return Boolean is (Boolean(k.shift)); pragma Warnings (On, "redundant conversion, expression is *"); type Key_Ptr is access all Key; type TCOD_Key_Ptr is access all TCOD_key_t; type Mouse_Ptr is access all Mouse; type TCOD_Mouse_Ptr is access all TCOD_mouse_t; -- Should be safe to do since Key is a derived type of TCOD_key_T with no -- added constraints function Key_Ptr_To_TCOD_Key_Ptr is new Ada.Unchecked_Conversion (Source => Key_Ptr, Target => TCOD_Key_Ptr); function Mouse_Ptr_To_TCOD_Mouse_Ptr is new Ada.Unchecked_Conversion (Source => Mouse_Ptr, Target => TCOD_Mouse_Ptr); --------------------- -- check_for_event -- --------------------- function check_for_event(kind : Event_Type; k : aliased out Key) return Event_Type is begin return TCOD_sys_check_for_event(int(kind), Key_Ptr_To_TCOD_Key_Ptr(k'Unchecked_Access), null); end check_for_event; function check_for_event(kind : Event_Type; m : aliased out Mouse; k : aliased out Key) return Event_Type is begin return TCOD_sys_check_for_event(int(kind), Key_Ptr_To_TCOD_Key_Ptr(k'Unchecked_Access), Mouse_Ptr_To_TCOD_Mouse_Ptr(m'Unchecked_Access)); end check_for_event; end Libtcod.Input;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- P A R . C H 1 1 -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2005, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- -- Boston, MA 02110-1301, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ pragma Style_Checks (All_Checks); -- Turn off subprogram body ordering check. Subprograms are in order -- by RM section rather than alphabetical with Sinfo.CN; use Sinfo.CN; separate (Par) package body Ch11 is -- Local functions, used only in this chapter function P_Exception_Handler return Node_Id; function P_Exception_Choice return Node_Id; --------------------------------- -- 11.1 Exception Declaration -- --------------------------------- -- Parsed by P_Identifier_Declaration (3.3.1) ------------------------------------------ -- 11.2 Handled Sequence Of Statements -- ------------------------------------------ -- HANDLED_SEQUENCE_OF_STATEMENTS ::= -- SEQUENCE_OF_STATEMENTS -- [exception -- EXCEPTION_HANDLER -- {EXCEPTION_HANDLER}] -- Error_Recovery : Cannot raise Error_Resync function P_Handled_Sequence_Of_Statements return Node_Id is Handled_Stmt_Seq_Node : Node_Id; begin Handled_Stmt_Seq_Node := New_Node (N_Handled_Sequence_Of_Statements, Token_Ptr); Set_Statements (Handled_Stmt_Seq_Node, P_Sequence_Of_Statements (SS_Extm_Sreq)); if Token = Tok_Exception then Scan; -- past EXCEPTION Set_Exception_Handlers (Handled_Stmt_Seq_Node, Parse_Exception_Handlers); end if; return Handled_Stmt_Seq_Node; end P_Handled_Sequence_Of_Statements; ----------------------------- -- 11.2 Exception Handler -- ----------------------------- -- EXCEPTION_HANDLER ::= -- when [CHOICE_PARAMETER_SPECIFICATION :] -- EXCEPTION_CHOICE {| EXCEPTION_CHOICE} => -- SEQUENCE_OF_STATEMENTS -- CHOICE_PARAMETER_SPECIFICATION ::= DEFINING_IDENTIFIER -- Error recovery: cannot raise Error_Resync function P_Exception_Handler return Node_Id is Scan_State : Saved_Scan_State; Handler_Node : Node_Id; Choice_Param_Node : Node_Id; begin Handler_Node := New_Node (N_Exception_Handler, Token_Ptr); T_When; -- Test for possible choice parameter present if Token = Tok_Identifier then Choice_Param_Node := Token_Node; Save_Scan_State (Scan_State); -- at identifier Scan; -- past identifier if Token = Tok_Colon then if Ada_Version = Ada_83 then Error_Msg_SP ("(Ada 83) choice parameter not allowed!"); end if; Scan; -- past : Change_Identifier_To_Defining_Identifier (Choice_Param_Node); Set_Choice_Parameter (Handler_Node, Choice_Param_Node); elsif Token = Tok_Others then Error_Msg_AP ("missing "":"""); Change_Identifier_To_Defining_Identifier (Choice_Param_Node); Set_Choice_Parameter (Handler_Node, Choice_Param_Node); else Restore_Scan_State (Scan_State); -- to identifier end if; end if; -- Loop through exception choices Set_Exception_Choices (Handler_Node, New_List); loop Append (P_Exception_Choice, Exception_Choices (Handler_Node)); exit when Token /= Tok_Vertical_Bar; Scan; -- past vertical bar end loop; TF_Arrow; Set_Statements (Handler_Node, P_Sequence_Of_Statements (SS_Sreq_Whtm)); return Handler_Node; end P_Exception_Handler; ------------------------------------------ -- 11.2 Choice Parameter Specification -- ------------------------------------------ -- Parsed by P_Exception_Handler (11.2) ---------------------------- -- 11.2 Exception Choice -- ---------------------------- -- EXCEPTION_CHOICE ::= exception_NAME | others -- Error recovery: cannot raise Error_Resync. If an error occurs, then the -- scan pointer is advanced to the next arrow or vertical bar or semicolon. function P_Exception_Choice return Node_Id is begin if Token = Tok_Others then Scan; -- past OTHERS return New_Node (N_Others_Choice, Prev_Token_Ptr); else return P_Name; -- exception name end if; exception when Error_Resync => Resync_Choice; return Error; end P_Exception_Choice; --------------------------- -- 11.3 Raise Statement -- --------------------------- -- RAISE_STATEMENT ::= raise [exception_NAME]; -- The caller has verified that the initial token is RAISE -- Error recovery: can raise Error_Resync function P_Raise_Statement return Node_Id is Raise_Node : Node_Id; begin Raise_Node := New_Node (N_Raise_Statement, Token_Ptr); Scan; -- past RAISE if Token /= Tok_Semicolon then Set_Name (Raise_Node, P_Name); end if; if Token = Tok_With then if Ada_Version < Ada_05 then Error_Msg_SC ("string expression in raise is Ada 2005 extension"); Error_Msg_SC ("\unit must be compiled with -gnat05 switch"); end if; Scan; -- past WITH Set_Expression (Raise_Node, P_Expression); end if; TF_Semicolon; return Raise_Node; end P_Raise_Statement; ------------------------------ -- Parse_Exception_Handlers -- ------------------------------ -- This routine scans out a list of exception handlers appearing in a -- construct as: -- exception -- EXCEPTION_HANDLER {EXCEPTION_HANDLER} -- The caller has scanned out the EXCEPTION keyword -- Control returns after scanning the last exception handler, presumably -- at the keyword END, but this is not checked in this routine. -- Error recovery: cannot raise Error_Resync function Parse_Exception_Handlers return List_Id is Handler : Node_Id; Handlers_List : List_Id; begin Handlers_List := New_List; P_Pragmas_Opt (Handlers_List); if Token = Tok_End then Error_Msg_SC ("must have at least one exception handler!"); else loop Handler := P_Exception_Handler; Append (Handler, Handlers_List); -- Note: no need to check for pragmas here. Although the -- syntax officially allows them in this position, they -- will have been swallowed up as part of the statement -- sequence of the handler we just scanned out. exit when Token /= Tok_When; end loop; end if; return Handlers_List; end Parse_Exception_Handlers; end Ch11;
with Ada.Iterator_Interfaces, Ada.Directories, Ada.Containers.Vectors; private with Ada.Finalization; package Shell.Directory_Iteration is type Directory is tagged private with Default_Iterator => Iterate, Iterator_Element => Constant_Reference_Type, Constant_Indexing => Element_Value; function To_Directory (Path : in String; Recurse : in Boolean := False) return Directory; function Path (Container : in Directory) return String; type Cursor is private; function Has_Element (Pos : Cursor) return Boolean; subtype Directory_Entry_Type is Ada.Directories.Directory_Entry_Type; type Constant_Reference_Type (Element : not null access constant Directory_Entry_Type) is private with Implicit_Dereference => Element; package Directory_Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element); function Iterate (Container : Directory) return Directory_Iterators.Forward_Iterator'Class; function Element_Value (Container : Directory; Pos : Cursor) return Constant_Reference_Type; private type Directory is tagged record Path : Unbounded_String; Recurse : Boolean; end record; type Constant_Reference_Type (Element : not null access constant Directory_Entry_Type) is null record; subtype Search_Type is Ada.Directories.Search_Type; type Search_Access is access all Search_Type; type Directory_Access is access all Directory; type Directory_Entry_Access is access all Directory_Entry_Type; -- Entries -- package Entry_Vectors is new ada.Containers.Vectors (Index_Type => Positive, Element_Type => Directory_Entry_Access); type Entries is new Entry_Vectors.Vector with null record; -- Cursor -- type Cursor is record Container : Directory_Access; Directory_Entry : Directory_Entry_Access; end record; No_Element : constant Cursor := Cursor' (Container => null, Directory_Entry => null); -- String Vectors -- package Strings_Vector is new Ada.Containers.Vectors (Index_Type => Positive, Element_Type => Unbounded_String); -- Iterator -- type Iterator_State is record Prior : Directory_Entry_Access; -- Used to free expired directory entries. Subdirs : Strings_Vector.Vector; -- Used to recurse through sub-directories. end record; type Iterator_State_Access is access all Iterator_State; type Iterator is new Ada.Finalization.Controlled and Directory_Iterators.Forward_Iterator with record Container : Directory_Access; Search : Search_Access; -- Access is due to Search_Type being limited. State : Iterator_State_Access; -- Access allows modifying the Iterator state in functions. end record; overriding function First (Object : in Iterator) return Cursor; overriding function Next (Object : in Iterator; Position : in Cursor) return Cursor; overriding procedure Finalize (Object : in out Iterator); end Shell.Directory_Iteration;
-- part of OpenGLAda, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "COPYING" with GL.API; with GL.Enums; package body GL.Tessellation is procedure Set_Patch_Vertices (Value : Int) is begin API.Set_Patch_Parameter_Int (Enums.Vertices, Value); end Set_Patch_Vertices; procedure Set_Patch_Default_Inner_Level (Values : Single_Array) is begin API.Set_Patch_Parameter_Float_Array (Enums.Default_Inner_Level, Values); end Set_Patch_Default_Inner_Level; procedure Set_Patch_Default_Outer_Level (Values : Single_Array) is begin API.Set_Patch_Parameter_Float_Array (Enums.Default_Outer_Level, Values); end Set_Patch_Default_Outer_Level; end GL.Tessellation;
------------------------------------------------------------------------------ -- Copyright (C) 2020 by Heisenbug Ltd. (gh+spat@heisenbug.eu) -- -- This work is free. You can redistribute it and/or modify it under the -- terms of the Do What The Fuck You Want To Public License, Version 2, -- as published by Sam Hocevar. See the LICENSE file for more details. ------------------------------------------------------------------------------ pragma License (Unrestricted); ------------------------------------------------------------------------------ -- -- SPARK Proof Analysis Tool -- -- S.P.A.T. - Main program - separate Print_Summary -- ------------------------------------------------------------------------------ with Ada.Text_IO; with SPAT.Strings; separate (Run_SPAT) ------------------------------------------------------------------------------ -- Print_Summary ------------------------------------------------------------------------------ procedure Print_Summary (Info : in SPAT.Spark_Info.T; Sort_By : in SPAT.Spark_Info.Sorting_Criterion) is Files : constant SPAT.Strings.File_Names := Info.List_All_Files (Sort_By => Sort_By); Second_Column : Ada.Text_IO.Count := 0; Third_Column : Ada.Text_IO.Count; use type Ada.Text_IO.Count; begin for File of Files loop Second_Column := Ada.Text_IO.Count'Max (Second_Column, Ada.Directories.Simple_Name (Name => SPAT.To_String (File))'Length); end loop; Second_Column := Second_Column + 2; Third_Column := Second_Column + 4; for File of Files loop SPAT.Log.Message (Message => Ada.Directories.Simple_Name (Name => SPAT.To_String (Source => File)), New_Line => False); Ada.Text_IO.Set_Col (File => Ada.Text_IO.Standard_Output, To => Second_Column); SPAT.Log.Message (Message => "=> (Flow => " & Image (Value => Info.Flow_Time (File => File)) & ",", New_Line => False); Ada.Text_IO.Set_Col (File => Ada.Text_IO.Standard_Output, To => Third_Column); SPAT.Log.Message (Message => "Proof => " & Image (Value => Info.Proof_Time (File => File)) & ")"); end loop; end Print_Summary;
-- flyweights-untracked_ptrs.adb -- A package of generalised references which point to resources inside a -- Flyweight without tracking or releasing those resources -- Copyright (c) 2016, James Humphry -- -- Permission to use, copy, modify, and/or distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -- PERFORMANCE OF THIS SOFTWARE. pragma Profile (No_Implementation_Extensions); with Ada.Unchecked_Conversion; package body Flyweights.Untracked_Ptrs is type Access_Element is access all Element; function Access_Element_To_Element_Access is new Ada.Unchecked_Conversion(Source => Access_Element, Target => Element_Access); subtype Hash_Type is Ada.Containers.Hash_Type; use type Ada.Containers.Hash_Type; --------------------------- -- Untracked_Element_Ptr -- --------------------------- function P (P : Untracked_Element_Ptr) return E_Ref is (E_Ref'(E => P.E)); function Get (P : Untracked_Element_Ptr) return Element_Access is (P.E); function Make_Ref (P : Untracked_Element_Ptr'Class) return Untracked_Element_Ref is (Untracked_Element_Ref'(E => P.E, Containing_Flyweight => P.Containing_Flyweight, Containing_Bucket => P.Containing_Bucket) ); function Insert_Ptr (F : aliased in out Flyweight_Hashtables.Flyweight; E : in out Element_Access) return Untracked_Element_Ptr is Bucket : Hash_Type ; begin Flyweight_Hashtables.Insert (F => F, Bucket => Bucket, Data_Ptr => E); return Untracked_Element_Ptr'(E => E, Containing_Flyweight => F'Access, Containing_Bucket => Bucket); end Insert_Ptr; --------------------------- -- Untracked_Element_Ref -- --------------------------- function Get (P : Untracked_Element_Ref) return Element_Access is (Access_Element_To_Element_Access(P.E)); function Make_Ptr (R : Untracked_Element_Ref'Class) return Untracked_Element_Ptr is begin return Untracked_Element_Ptr'(E => Access_Element_To_Element_Access(R.E), Containing_Flyweight => R.Containing_Flyweight, Containing_Bucket => R.Containing_Bucket); end Make_Ptr; function Insert_Ref (F : aliased in out Flyweight_Hashtables.Flyweight; E : in out Element_Access) return Untracked_Element_Ref is Bucket : Hash_Type ; begin Flyweight_Hashtables.Insert (F => F, Bucket => Bucket, Data_Ptr => E); return Untracked_Element_Ref'(E => E, Containing_Flyweight => F'Access, Containing_Bucket => Bucket); end Insert_Ref; end Flyweights.Untracked_Ptrs;
generic type Real is digits <>; procedure Real_To_Rational(R: Real; Bound: Positive; Nominator: out Integer; Denominator: out Positive);
with SPARKNaCl; use SPARKNaCl; with SPARKNaCl.Core; use SPARKNaCl.Core; with SPARKNaCl.Debug; use SPARKNaCl.Debug; with SPARKNaCl.Hashing; use SPARKNaCl.Hashing; with Interfaces; use Interfaces; procedure Core3 is Second_Key : constant Salsa20_Key := Construct ((16#dc#, 16#90#, 16#8d#, 16#da#, 16#0b#, 16#93#, 16#44#, 16#a9#, 16#53#, 16#62#, 16#9b#, 16#73#, 16#38#, 16#20#, 16#77#, 16#88#, 16#80#, 16#f3#, 16#ce#, 16#b4#, 16#21#, 16#bb#, 16#61#, 16#b9#, 16#1c#, 16#bd#, 16#4c#, 16#3e#, 16#66#, 16#25#, 16#6c#, 16#e4#)); Nonce_Suffix : constant Bytes_8 := (16#82#, 16#19#, 16#e0#, 16#03#, 16#6b#, 16#7a#, 16#0b#, 16#37#); C : constant Bytes_16 := (16#65#, 16#78#, 16#70#, 16#61#, 16#6e#, 16#64#, 16#20#, 16#33#, 16#32#, 16#2d#, 16#62#, 16#79#, 16#74#, 16#65#, 16#20#, 16#6b#); Input : Bytes_16 := (others => 0); Output : Byte_Seq (0 .. (2 ** 22 - 1)); H : Bytes_64; Pos : I32; begin Input (0 .. 7) := Nonce_Suffix; Pos := 0; loop loop Salsa20 (Output (Pos .. Pos + 63), Input, Second_Key, C); Pos := Pos + 64; Input (8) := Input (8) + 1; exit when Input (8) = 0; end loop; Input (9) := Input (9) + 1; exit when Input (9) = 0; end loop; Hash (H, Output); DH ("Hash is", H); end Core3;
pragma License (Unrestricted); -- implementation unit required by compiler with Ada.Exceptions; with Ada.Finalization; with Ada.Unchecked_Conversion; package System.Tasking.Protected_Objects.Entries is type Node is limited record Super : aliased Synchronous_Objects.Queue_Node; E : Protected_Entry_Index; Uninterpreted_Data : Address; Caller : Task_Id; Action : Boolean; Requeued : Boolean; Waiting : aliased Synchronous_Objects.Event; X : Ada.Exceptions.Exception_Occurrence; end record; pragma Suppress_Initialization (Node); type Node_Access is access all Node; function Downcast is new Ada.Unchecked_Conversion ( Synchronous_Objects.Queue_Node_Access, Node_Access); type Find_Body_Index_Access is access function ( O : Address; E : Protected_Entry_Index) return Protected_Entry_Index; type Protected_Entry_Queue_Max_Array is array (Positive_Protected_Entry_Index range <>) of Natural; type Protected_Entry_Queue_Max_Access is access constant Protected_Entry_Queue_Max_Array; -- required by compiler type Protected_Entry_Body_Array is array (Positive_Protected_Entry_Index range <>) of Entry_Body; pragma Suppress_Initialization (Protected_Entry_Body_Array); type Protected_Entry_Body_Access is access constant Protected_Entry_Body_Array; -- required by compiler -- (if it is not controlled type, compiler may be crashed!) type Protection_Entries (Num_Entries : Protected_Entry_Index) is limited new Ada.Finalization.Limited_Controlled with record Mutex : aliased Synchronous_Objects.Mutex; Calling : aliased Synchronous_Objects.Queue; Compiler_Info : Address; Entry_Bodies : Protected_Entry_Body_Access; Find_Body_Index : Find_Body_Index_Access; Raised_On_Barrier : Boolean; Current_Calling : access Node; end record; -- required for synchronized interface by compiler type Protection_Entries_Access is access all Protection_Entries'Class; for Protection_Entries_Access'Storage_Size use 0; -- required by compiler procedure Initialize_Protection_Entries ( Object : not null access Protection_Entries'Class; Ceiling_Priority : Integer; Compiler_Info : Address; Entry_Queue_Maxes : Protected_Entry_Queue_Max_Access; Entry_Bodies : Protected_Entry_Body_Access; Find_Body_Index : Find_Body_Index_Access); overriding procedure Finalize (Object : in out Protection_Entries); -- required by compiler procedure Lock_Entries ( Object : not null access Protection_Entries'Class); procedure Unlock_Entries ( Object : not null access Protection_Entries'Class); -- for System.Tasking.Protected_Objects.Operations.Service_Entries procedure Cancel_Calls (Object : in out Protection_Entries'Class); -- required by compiler (s-tpoben.ads) function Get_Ceiling (Object : not null access Protection_Entries'Class) return Any_Priority; -- unimplemented subprograms required by compiler -- Set_Ceiling end System.Tasking.Protected_Objects.Entries;
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- package Program.Elements.Definitions is pragma Pure (Program.Elements.Definitions); type Definition is limited interface and Program.Elements.Element; type Definition_Access is access all Definition'Class with Storage_Size => 0; end Program.Elements.Definitions;
------------------------------------------------------------------------------ -- Copyright (c) 2021, Lev Kujawski. -- -- 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 sell copies of the Software, and to permit persons to whom the -- Software is furnished to do so. -- -- 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. -- -- SPDX-License-Identifier: MIT-0 -- -- File: stantext.adb (Ada Package Body) -- Language: Ada (1995) [1] -- Author: Lev Kujawski -- Description: Type-safe printf() emulation for string localization -- -- References: -- [1] Information technology - Programming languages - Ada, -- ISO/IEC 8652:1995(E), 15 Feb. 1995. ------------------------------------------------------------------------------ with Ada.Strings.Unbounded; with Ada.Unchecked_Conversion; with C_Standard_IO; package body Standard_Text is package CIO renames C_Standard_IO; package NLS renames Native_Language_System; Address_Octet_Size : constant := Standard'Address_Size / 8; type Address_Octets_T is new Octet_Array_T (1 .. Address_Octet_Size); for Address_Octets_T'Size use Standard'Address_Size; function Address_To_Octets is new Ada.Unchecked_Conversion (Source => System.Address, Target => Address_Octets_T); function Octets_To_Address is new Ada.Unchecked_Conversion (Source => Address_Octets_T, Target => System.Address); Long_Float_Octet_Size : constant := Long_Float'Size / 8; type Long_Float_Octets_T is new Octet_Array_T (1 .. Long_Float_Octet_Size); for Long_Float_Octets_T'Size use Long_Float'Size; function Long_Float_To_Octets is new Ada.Unchecked_Conversion (Source => Long_Float, Target => Long_Float_Octets_T); function Octets_To_Long_Float is new Ada.Unchecked_Conversion (Source => Long_Float_Octets_T, Target => Long_Float); Long_Long_Float_Octet_Size : constant := Long_Long_Float'Size / 8; type Long_Long_Float_Octets_T is new Octet_Array_T (1 .. Long_Long_Float_Octet_Size); for Long_Long_Float_Octets_T'Size use Long_Long_Float'Size; function Long_Long_Float_To_Octets is new Ada.Unchecked_Conversion (Source => Long_Long_Float, Target => Long_Long_Float_Octets_T); function Octets_To_Long_Long_Float is new Ada.Unchecked_Conversion (Source => Long_Long_Float_Octets_T, Target => Long_Long_Float); Integer_Octet_Size : constant := Integer'Size / 8; type Integer_Octets_T is new Octet_Array_T (1 .. Integer_Octet_Size); for Integer_Octets_T'Size use Integer'Size; function Integer_To_Octets is new Ada.Unchecked_Conversion (Source => Integer, Target => Integer_Octets_T); function Octets_To_Integer is new Ada.Unchecked_Conversion (Source => Integer_Octets_T, Target => Integer); Long_Integer_Octet_Size : constant := Long_Integer'Size / 8; type Long_Integer_Octets_T is new Octet_Array_T (1 .. Long_Integer_Octet_Size); for Long_Integer_Octets_T'Size use Long_Integer'Size; function Long_Integer_To_Octets is new Ada.Unchecked_Conversion (Source => Long_Integer, Target => Long_Integer_Octets_T); function Octets_To_Long_Integer is new Ada.Unchecked_Conversion (Source => Long_Integer_Octets_T, Target => Long_Integer); Flags_Unchanged : constant Settings_T := (others => Unchanged); procedure Append (The_String : in String; To_String : in out String; At_Index : in out Positive) is begin To_String (At_Index .. At_Index + (The_String'Length - 1)) := The_String; At_Index := At_Index + The_String'Length; end Append; function Trim (Source : in String) return String is begin for I in Source'Range loop if Source (I) /= ' ' then declare Normalized : constant String (1 .. Source'Last - (I - 1)) := Source (I .. Source'Last); begin return Normalized; end; end if; end loop; return ""; end Trim; function Integer_Image (Value : in Integer) return String is begin return Trim (Integer'Image (Value)); end Integer_Image; function Is_Digit (This : in Character) return Boolean is begin return This in '0' .. '9'; end Is_Digit; procedure Read_Integer (Source : in String; From : in Positive; Value : out Integer; Last : out Natural) is Result : Integer := 0; Index : Natural := From; begin loop if not Is_Digit (Source (Index)) then Index := Index - 1; exit; end if; Result := Result * 10 + Character'Pos (Source (Index)) - Character'Pos ('0'); exit when Index = Source'Last; Index := Index + 1; end loop; Value := Result; Last := Index; end Read_Integer; function Text return Text_T is begin return Text_T'(Index_Last => 0, Format_Last => 0, Argument_Last => 0, Attribute => Attributes_T'(Flag => (others => False), Precision => 0), Types => (others => Argument_T'First), Indices => (others => Positive'First), Format => (others => Character'First), Arguments => (others => Octet_T'First)); end Text; function Precision (Number_of_Digits : in Natural) return Modifier_T is Flags : Settings_T := Flags_Unchanged; begin Flags (Precision) := On; return Modifier_T'(Setting => Flags, Precision => Number_of_Digits); end Precision; function Positive_Sign return Modifier_T is Flags : Settings_T := Flags_Unchanged; begin Flags (Positive_Sign) := On; return Modifier_T'(Setting => Flags, Precision => 0); end Positive_Sign; function No_Positive_Sign return Modifier_T is Flags : Settings_T := Flags_Unchanged; begin Flags (Positive_Sign) := Off; return Modifier_T'(Setting => Flags, Precision => 0); end No_Positive_Sign; function Thousands_Grouping return Modifier_T is Flags : Settings_T := Flags_Unchanged; begin Flags (Thousands_Grouping) := On; return Modifier_T'(Setting => Flags, Precision => 0); end Thousands_Grouping; function No_Thousands_Grouping return Modifier_T is Flags : Settings_T := Flags_Unchanged; begin Flags (Thousands_Grouping) := Off; return Modifier_T'(Setting => Flags, Precision => 0); end No_Thousands_Grouping; function "&" (Left : in Text_T; Right : in Modifier_T) return Text_T is Combined : Text_T := Left; begin for J in Right.Setting'Range loop case Right.Setting (J) is when On => Combined.Attribute.Flag (J) := True; if J = Precision then Combined.Attribute.Precision := Right.Precision; end if; when Off => Combined.Attribute.Flag (J) := False; if J = Precision then Combined.Attribute.Precision := 0; end if; when Unchanged => null; end case; end loop; return Combined; end "&"; function "&" (Left : in Text_T; Right : in String) return Text_T is Escape : Natural := 0; begin for I in Positive range Right'Range loop if Right (I) = '%' then Escape := Escape + 1; end if; end loop; declare subtype Escape_Index_T is Positive range 1 .. Right'Length + Escape; Escaped : String (Escape_Index_T); Index : Natural := 0; begin for I in Positive range Right'Range loop Index := Index + 1; if Right (I) = '%' then Escaped (Index) := Right (I); Index := Index + 1; Escaped (Index) := Right (I); else Escaped (Index) := Right (I); end if; end loop; return Text_T' (Index_Last => Left.Index_Last, Format_Last => Left.Format_Last + Right'Length, Argument_Last => Left.Argument_Last, Attribute => Left.Attribute, Indices => Left.Indices, Types => Left.Types, Format => Left.Format & Escaped, Arguments => Left.Arguments); end; end "&"; function "&" (Left : in Text_T; Right : in Character) return Text_T is begin if Right = '%' then return Text_T' (Index_Last => Left.Index_Last, Format_Last => Left.Format_Last + 2, Argument_Last => Left.Argument_Last, Attribute => Left.Attribute, Indices => Left.Indices, Types => Left.Types, Format => Left.Format & Right & Right, Arguments => Left.Arguments); else return Text_T' (Index_Last => Left.Index_Last, Format_Last => Left.Format_Last + 1, Argument_Last => Left.Argument_Last, Attribute => Left.Attribute, Indices => Left.Indices, Types => Left.Types, Format => Left.Format & Right, Arguments => Left.Arguments); end if; end "&"; function "&" (Left : in Text_T; Right : in Integer) return Text_T is Octets : constant Integer_Octets_T := Integer_To_Octets (Right); begin return Left & Element_T'(Argument_Last => Octets'Last, Kind => Integer_Regular, Argument => Octet_Array_T (Octets)); end "&"; function "&" (Left : in Text_T; Right : in Long_Long_Float) return Text_T is Octets : constant Long_Long_Float_Octets_T := Long_Long_Float_To_Octets (Right); begin return Left & Element_T'(Argument_Last => Octets'Last, Kind => Float_Long_Long, Argument => Octet_Array_T (Octets)); end "&"; function "&" (Left : in Text_T; Right : in System.Address) return Text_T is Octets : constant Address_Octets_T := Address_To_Octets (Right); begin return Left & Element_T'(Argument_Last => Octets'Last, Kind => Address, Argument => Octet_Array_T (Octets)); end "&"; function Conversion_To_Format (Conversion : in Argument_T; Argument : in Positive; Attribute : in Attributes_T) return String is function Is_Numeric return Boolean is Result : Boolean; begin case Conversion is when Address => Result := False; when Float_Long => Result := True; when Float_Long_Long => Result := True; when Integer_Long => Result := True; when Integer_Regular => Result := True; when Raw_String => Result := False; end case; return Result; end Is_Numeric; subtype Format_Index_T is Positive range 1 .. 256; Format_String : String (Format_Index_T); Format_Index : Format_Index_T := Format_Index_T'First; begin -- Conversion_To_Format Append ('%' & Integer_Image (Argument) & '$', Format_String, Format_Index); if Is_Numeric then if Attribute.Flag (Precision) then Append ("." & Integer_Image (Attribute.Precision), Format_String, Format_Index); end if; if Attribute.Flag (Thousands_Grouping) then Append ("'", Format_String, Format_Index); end if; if Attribute.Flag (Positive_Sign) then Append ("+", Format_String, Format_Index); end if; end if; case Conversion is when Address => Append ("p", Format_String, Format_Index); when Float_Long => Append ("f", Format_String, Format_Index); when Float_Long_Long => Append ("Lf", Format_String, Format_Index); when Integer_Long => Append ("ld", Format_String, Format_Index); when Integer_Regular => Append ("d", Format_String, Format_Index); when Raw_String => Append ("s", Format_String, Format_Index); end case; return Format_String (Format_String'First .. Format_Index - 1); end Conversion_To_Format; function "&" (Left : in Text_T; Right : in Element_T) return Text_T is Format_String : constant String := Conversion_To_Format (Right.Kind, Left.Index_Last + 1, Left.Attribute); begin return Text_T' (Index_Last => Left.Index_Last + 1, Format_Last => Left.Format_Last + Format_String'Length, Argument_Last => Left.Argument_Last + Right.Argument'Length, Attribute => Left.Attribute, Indices => Left.Indices & (1 => Left.Argument_Last + 1), Types => Left.Types & (1 => Right.Kind), Format => Left.Format & Format_String, Arguments => Left.Arguments & Right.Argument); end "&"; function Float_L (Value : in Long_Float) return Element_T is Octets : constant Long_Float_Octets_T := Long_Float_To_Octets (Value); begin return Element_T'(Argument_Last => Octets'Last, Kind => Float_Long, Argument => Octet_Array_T (Octets)); end Float_L; function Integer_L (Value : in Long_Integer) return Element_T is Octets : constant Long_Integer_Octets_T := Long_Integer_To_Octets (Value); begin return Element_T'(Argument_Last => Octets'Last, Kind => Integer_Long, Argument => Octet_Array_T (Octets)); end Integer_L; function Raw (From_String : in String) return Element_T is subtype Octets_Index_T is Positive range 1 .. From_String'Length; Octets : Octet_Array_T (Octets_Index_T); for Octets'Address use From_String (From_String'First)'Address; begin return Element_T'(Argument_Last => Octets'Length, Kind => Raw_String, Argument => Octets); end Raw; function New_Line return String is begin return (1 => ASCII.LF); end New_Line; function Format_Of (The_Text : in Text_T) return String is begin return The_Text.Format; end Format_Of; function String_Of (The_Text : in Text_T; With_Format : in String) return String is Null_File : CIO.File_T; Conv_First : Positive; Argument_Type : Argument_T; Argument : Positive := The_Text.Indices'First; Positional : Boolean := False; Format_Index : Positive := With_Format'First; Output : Ada.Strings.Unbounded.Unbounded_String; procedure C_Print is C_Format_String : String := With_Format (Conv_First .. Format_Index - 1) & ASCII.NUL; begin -- We need to remove any remnant of the argument number. C_Format_String (C_Format_String'First) := '%'; case Argument_Type is when Address => Ada.Strings.Unbounded.Append (Output, CIO.Address_Image (Value => Octets_To_Address (Address_Octets_T (The_Text.Arguments (The_Text.Indices (Argument) .. The_Text.Indices (Argument) + Address_Octet_Size - 1))), Format => C_Format_String)); when Integer_Regular => Ada.Strings.Unbounded.Append (Output, CIO.Integer_Image (Value => Octets_To_Integer (Integer_Octets_T (The_Text.Arguments (The_Text.Indices (Argument) .. The_Text.Indices (Argument) + Integer_Octet_Size - 1))), Format => C_Format_String)); when Integer_Long => Ada.Strings.Unbounded.Append (Output, CIO.Long_Integer_Image (Value => Octets_To_Long_Integer (Long_Integer_Octets_T (The_Text.Arguments (The_Text.Indices (Argument) .. The_Text.Indices (Argument) + Long_Integer_Octet_Size - 1))), Format => C_Format_String)); when Float_Long => Ada.Strings.Unbounded.Append (Output, CIO.Long_Float_Image (Value => Octets_To_Long_Float (Long_Float_Octets_T (The_Text.Arguments (The_Text.Indices (Argument) .. The_Text.Indices (Argument) + Long_Float_Octet_Size - 1))), Format => C_Format_String)); when Float_Long_Long => Ada.Strings.Unbounded.Append (Output, CIO.Long_Long_Float_Image (Value => Octets_To_Long_Long_Float (Long_Long_Float_Octets_T (The_Text.Arguments (The_Text.Indices (Argument) .. The_Text.Indices (Argument) + Long_Long_Float_Octet_Size - 1))), Format => C_Format_String)); when Raw_String => raise Error; end case; end C_Print; function Argument_Length return Natural is Result : Natural; begin if Argument = The_Text.Index_Last then Result := The_Text.Argument_Last - (The_Text.Indices (Argument) - 1); else Result := The_Text.Indices (Argument + 1) - The_Text.Indices (Argument); end if; return Result; end Argument_Length; procedure Print is begin if Argument_Type = Raw_String then -- Handle strings directly declare String_View : String (1 .. Argument_Length); for String_View'Address use The_Text.Arguments (The_Text.Indices (Argument))'Address; begin Ada.Strings.Unbounded.Append (Output, String_View); end; else C_Print; end if; end Print; -- Page 213 of C435 (the Unix 95 standard) procedure Parse_Conversion_Specification is Argument_Number : Integer; Position : Natural; function Is_Flag (This : in Character) return Boolean is Result : Boolean; begin case This is when ''' => Result := True; when '+' => Result := True; when others => Result := False; end case; return Result; end Is_Flag; begin -- Parse_Conversion_Specification Read_Integer (With_Format, Format_Index, Argument_Number, Position); if Position >= Format_Index and then Argument_Number > 0 and then With_Format (Format_Index + 1) = '$' then Conv_First := Format_Index + 1; Positional := True; Argument := Argument_Number; Format_Index := Format_Index + 2; end if; -- Skip precision if With_Format (Format_Index) = '.' then Format_Index := Format_Index + 1; while Is_Digit (With_Format (Format_Index)) loop Format_Index := Format_Index + 1; end loop; end if; -- Skip flags while Is_Flag (With_Format (Format_Index)) loop Format_Index := Format_Index + 1; end loop; case With_Format (Format_Index) is when 'L' => Argument_Type := Float_Long_Long; Format_Index := Format_Index + 1; if With_Format (Format_Index) /= 'f' then raise Usage_Error; end if; when 'c' => Argument_Type := Integer_Regular; when 'd' | 'i' => Argument_Type := Integer_Regular; when 'l' => Argument_Type := Integer_Long; Format_Index := Format_Index + 1; if With_Format (Format_Index) /= 'd' then raise Usage_Error; end if; when 'o' => raise Usage_Error; when 'u' => raise Usage_Error; when 'x' | 'X' => raise Usage_Error; when 'f' => Argument_Type := Float_Long; when 'e' | 'E' => Argument_Type := Float_Long; when 'g' | 'G' => Argument_Type := Float_Long; when 's' => Argument_Type := Raw_String; when 'p' => Argument_Type := Address; when others => raise Usage_Error; end case; Format_Index := Format_Index + 1; end Parse_Conversion_Specification; procedure Verify_Type is begin if Argument_Type /= The_Text.Types (Argument) then raise Usage_Error; end if; end Verify_Type; begin -- String_Of CIO.Open_Null (Null_File); while Format_Index <= With_Format'Last loop if With_Format (Format_Index) = '%' then Conv_First := Format_Index; Format_Index := Format_Index + 1; if With_Format (Format_Index) = '%' then -- Escaped '%'. Ada.Strings.Unbounded.Append (Output, With_Format (Format_Index)); Format_Index := Format_Index + 1; else Parse_Conversion_Specification; Verify_Type; Print; if not Positional then Argument := Argument + 1; end if; end if; else Ada.Strings.Unbounded.Append (Output, With_Format (Format_Index)); Format_Index := Format_Index + 1; end if; end loop; CIO.Close_File (Null_File); return Ada.Strings.Unbounded.To_String (Output); exception when others => CIO.Close_File (Null_File); raise; end String_Of; function String_Of (The_Text : in Text_T) return String is begin return String_Of (The_Text => The_Text, With_Format => The_Text.Format); end String_Of; function Message (From_Catalog : in NLS.Catalog_T; Set_Number : in Positive; Message_Number : in Positive; Default_Message : in Text_T) return String is Localized_Format : constant String := NLS.Message (From_Catalog, Set_Number, Message_Number); begin -- Message if Localized_Format = "" then return String_Of (The_Text => Default_Message); else return String_Of (The_Text => Default_Message, With_Format => Localized_Format); end if; end Message; end Standard_Text;
-- Copyright 2016 Steven Stewart-Gallus -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -- implied. See the License for the specific language governing -- permissions and limitations under the License. with System; with Interfaces.C; use Interfaces.C; limited with Pulse.Mainloop.API; package Pulse.Mainloop with Spark_Mode => Off is -- skipped empty struct pollfd type pa_mainloop is limited private; type pa_mainloop_access is access all pa_mainloop; function pa_mainloop_new return pa_mainloop_access; -- /usr/include/pulse/mainloop.h:83 pragma Import (C, pa_mainloop_new, "pa_mainloop_new"); procedure pa_mainloop_free (m : pa_mainloop_access); -- /usr/include/pulse/mainloop.h:86 pragma Import (C, pa_mainloop_free, "pa_mainloop_free"); function pa_mainloop_prepare (m : pa_mainloop_access; timeout : int) return int; -- /usr/include/pulse/mainloop.h:91 pragma Import (C, pa_mainloop_prepare, "pa_mainloop_prepare"); function pa_mainloop_poll (m : pa_mainloop_access) return int; -- /usr/include/pulse/mainloop.h:94 pragma Import (C, pa_mainloop_poll, "pa_mainloop_poll"); function pa_mainloop_dispatch (m : pa_mainloop_access) return int; -- /usr/include/pulse/mainloop.h:98 pragma Import (C, pa_mainloop_dispatch, "pa_mainloop_dispatch"); function pa_mainloop_get_retval (m : pa_mainloop_access) return int; -- /usr/include/pulse/mainloop.h:101 pragma Import (C, pa_mainloop_get_retval, "pa_mainloop_get_retval"); function pa_mainloop_iterate (m : pa_mainloop_access; block : int; retval : access int) return int; -- /usr/include/pulse/mainloop.h:109 pragma Import (C, pa_mainloop_iterate, "pa_mainloop_iterate"); function pa_mainloop_run (m : pa_mainloop_access; retval : out int) return int; -- /usr/include/pulse/mainloop.h:112 pragma Import (C, pa_mainloop_run, "pa_mainloop_run"); function pa_mainloop_get_api (m : pa_mainloop_access) return access Pulse.Mainloop.API .pa_mainloop_api; -- /usr/include/pulse/mainloop.h:117 pragma Import (C, pa_mainloop_get_api, "pa_mainloop_get_api"); procedure pa_mainloop_quit (m : pa_mainloop_access; r : int); -- /usr/include/pulse/mainloop.h:120 pragma Import (C, pa_mainloop_quit, "pa_mainloop_quit"); procedure pa_mainloop_wakeup (m : pa_mainloop_access); -- /usr/include/pulse/mainloop.h:123 pragma Import (C, pa_mainloop_wakeup, "pa_mainloop_wakeup"); type pa_poll_func is access function (arg1 : System.Address; arg2 : unsigned_long; arg3 : int; arg4 : System.Address) return int; pragma Convention (C, pa_poll_func); -- /usr/include/pulse/mainloop.h:126 procedure pa_mainloop_set_poll_func (m : pa_mainloop_access; poll_func : pa_poll_func; userdata : System.Address); -- /usr/include/pulse/mainloop.h:129 pragma Import (C, pa_mainloop_set_poll_func, "pa_mainloop_set_poll_func"); private type pa_mainloop is limited record null; end record; end Pulse.Mainloop;
------------------------------------------------------------------------------ -- Copyright (c) 2014, 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. -- ------------------------------------------------------------------------------ with Ada.Unchecked_Conversion; package body Natools.HMAC is function To_Stream_Element_Array (Key : String) return Ada.Streams.Stream_Element_Array; pragma Inline (To_Stream_Element_Array); -- Convert a String into a Stream_Element_Array function Pad (Key : Ada.Streams.Stream_Element_Array; Pattern : Ada.Streams.Stream_Element) return Ada.Streams.Stream_Element_Array; -- Scramble Key with the given pattern Outer_Pattern : constant Ada.Streams.Stream_Element := 16#5C#; Inner_Pattern : constant Ada.Streams.Stream_Element := 16#36#; ------------------------------ -- Local Helper Subprograms -- ------------------------------ function To_Stream_Element_Array (Key : String) return Ada.Streams.Stream_Element_Array is subtype Ad_Hoc_String is String (Key'Range); subtype Ad_Hoc_Array is Ada.Streams.Stream_Element_Array (1 .. Key'Length); function Unchecked_Conversion is new Ada.Unchecked_Conversion (Ad_Hoc_String, Ad_Hoc_Array); begin return Unchecked_Conversion (Key); end To_Stream_Element_Array; function Pad (Key : Ada.Streams.Stream_Element_Array; Pattern : Ada.Streams.Stream_Element) return Ada.Streams.Stream_Element_Array is use type Ada.Streams.Stream_Element; Result : Ada.Streams.Stream_Element_Array (Key'Range); begin for I in Result'Range loop Result (I) := Key (I) xor Pattern; end loop; return Result; end Pad; -------------------- -- HAMC Interface -- -------------------- procedure Setup (C : out Context; Key : in Ada.Streams.Stream_Element_Array) is begin C := Create (Key); end Setup; procedure Setup (C : out Context; Key : in String) is begin C := Create (Key); end Setup; function Create (Key : Ada.Streams.Stream_Element_Array) return Context is Result : Context := (Key => (others => 0), Hash => Initial_Context); use type Ada.Streams.Stream_Element_Count; begin if Key'Length <= Block_Size_In_SE then Result.Key (1 .. Key'Length) := Key; else declare Local_Hash : Hash_Context := Initial_Context; begin Update (Local_Hash, Key); declare Hashed_Key : constant Ada.Streams.Stream_Element_Array := Digest (Local_Hash); begin Result.Key (1 .. Hashed_Key'Length) := Hashed_Key; end; end; end if; Update (Result.Hash, Pad (Result.Key, Inner_Pattern)); return Result; end Create; function Create (Key : String) return Context is begin return Create (To_Stream_Element_Array (Key)); end Create; procedure Update (C : in out Context; Input : in Ada.Streams.Stream_Element_Array) is begin Update (C.Hash, Input); end Update; procedure Update (C : in out Context; Input : in String) is begin Update (C.Hash, To_Stream_Element_Array (Input)); end Update; function Digest (C : Context) return Ada.Streams.Stream_Element_Array is Local_Hash : Hash_Context := Initial_Context; begin Update (Local_Hash, Pad (C.Key, Outer_Pattern)); Update (Local_Hash, Digest (C.Hash)); return Digest (Local_Hash); end Digest; function Digest (Key : String; Message : Ada.Streams.Stream_Element_Array) return Ada.Streams.Stream_Element_Array is Local_Context : Context := Create (Key); begin Update (Local_Context, Message); return Digest (Local_Context); end Digest; function Digest (Key, Message : Ada.Streams.Stream_Element_Array) return Ada.Streams.Stream_Element_Array is Local_Context : Context := Create (Key); begin Update (Local_Context, Message); return Digest (Local_Context); end Digest; end Natools.HMAC;
----------------------------------------------------------------------- -- html-factory -- Factory for HTML UI Components -- Copyright (C) 2009, 2010, 2011, 2012, 2014 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with ASF.Components.Base; with ASF.Components.Html.Text; with ASF.Components.Html.Lists; with ASF.Components.Html.Links; with ASF.Components.Html.Panels; with ASF.Components.Html.Forms; with ASF.Components.Html.Pages; with ASF.Components.Html.Selects; with ASF.Components.Html.Messages; with ASF.Views.Nodes; package body ASF.Components.Html.Factory is use ASF.Components.Base; function Create_Body return UIComponent_Access; function Create_Doctype return UIComponent_Access; function Create_Head return UIComponent_Access; function Create_Output return UIComponent_Access; function Create_Output_Label return UIComponent_Access; function Create_Output_Link return UIComponent_Access; function Create_Output_Format return UIComponent_Access; function Create_List return UIComponent_Access; function Create_PanelGroup return UIComponent_Access; function Create_Form return UIComponent_Access; function Create_Input_File return UIComponent_Access; function Create_Input_Hidden return UIComponent_Access; function Create_Input_Text return UIComponent_Access; function Create_Input_Textarea return UIComponent_Access; function Create_Command return UIComponent_Access; function Create_Message return UIComponent_Access; function Create_Messages return UIComponent_Access; function Create_SelectOne return UIComponent_Access; function Create_SelectOneRadio return UIComponent_Access; function Create_SelectBooleanCheckbox return UIComponent_Access; -- Create an UIInput secret component function Create_Input_Secret return ASF.Components.Base.UIComponent_Access; -- ------------------------------ -- Create an UIBody component -- ------------------------------ function Create_Body return UIComponent_Access is begin return new ASF.Components.Html.Pages.UIBody; end Create_Body; -- ------------------------------ -- Create an UIDoctype component -- ------------------------------ function Create_Doctype return UIComponent_Access is begin return new ASF.Components.Html.Pages.UIDoctype; end Create_Doctype; -- ------------------------------ -- Create an UIHead component -- ------------------------------ function Create_Head return UIComponent_Access is begin return new ASF.Components.Html.Pages.UIHead; end Create_Head; -- ------------------------------ -- Create an UIOutput component -- ------------------------------ function Create_Output return UIComponent_Access is begin return new ASF.Components.Html.Text.UIOutput; end Create_Output; -- ------------------------------ -- Create an UIOutputLabel component -- ------------------------------ function Create_Output_Label return UIComponent_Access is begin return new ASF.Components.Html.Text.UIOutputLabel; end Create_Output_Label; -- ------------------------------ -- Create an UIOutputLink component -- ------------------------------ function Create_Output_Link return UIComponent_Access is begin return new ASF.Components.Html.Links.UIOutputLink; end Create_Output_Link; -- ------------------------------ -- Create an UIOutput component -- ------------------------------ function Create_Output_Format return UIComponent_Access is begin return new ASF.Components.Html.Text.UIOutputFormat; end Create_Output_Format; -- ------------------------------ -- Create an UIList component -- ------------------------------ function Create_List return UIComponent_Access is begin return new ASF.Components.Html.Lists.UIList; end Create_List; -- ------------------------------ -- Create an UIPanelGroup component -- ------------------------------ function Create_PanelGroup return UIComponent_Access is begin return new ASF.Components.Html.Panels.UIPanelGroup; end Create_PanelGroup; -- ------------------------------ -- Create an UIForm component -- ------------------------------ function Create_Form return UIComponent_Access is begin return new ASF.Components.Html.Forms.UIForm; end Create_Form; -- ------------------------------ -- Create an UIInput_Hidden component -- ------------------------------ function Create_Input_Hidden return UIComponent_Access is begin return new ASF.Components.Html.Forms.UIInput_Hidden; end Create_Input_Hidden; -- ------------------------------ -- Create an UIInput component -- ------------------------------ function Create_Input_Text return UIComponent_Access is begin return new ASF.Components.Html.Forms.UIInput; end Create_Input_Text; -- ------------------------------ -- Create an UIInput secret component -- ------------------------------ function Create_Input_Secret return ASF.Components.Base.UIComponent_Access is Result : constant Html.Forms.UIInput_Access := new ASF.Components.Html.Forms.UIInput; begin Result.Set_Secret (True); return Result.all'Access; end Create_Input_Secret; -- ------------------------------ -- Create an UIInputTextarea component -- ------------------------------ function Create_Input_Textarea return UIComponent_Access is begin return new ASF.Components.Html.Forms.UIInputTextarea; end Create_Input_Textarea; -- ------------------------------ -- Create an UIInput_File component -- ------------------------------ function Create_Input_File return UIComponent_Access is begin return new ASF.Components.Html.Forms.UIInput_File; end Create_Input_File; -- ------------------------------ -- Create an UICommand component -- ------------------------------ function Create_Command return UIComponent_Access is begin return new ASF.Components.Html.Forms.UICommand; end Create_Command; -- ------------------------------ -- Create an UIMessage component -- ------------------------------ function Create_Message return UIComponent_Access is begin return new ASF.Components.Html.Messages.UIMessage; end Create_Message; -- ------------------------------ -- Create an UIMessages component -- ------------------------------ function Create_Messages return UIComponent_Access is begin return new ASF.Components.Html.Messages.UIMessages; end Create_Messages; -- ------------------------------ -- Create an UISelectOne component -- ------------------------------ function Create_SelectOne return UIComponent_Access is begin return new ASF.Components.Html.Selects.UISelectOne; end Create_SelectOne; -- ------------------------------ -- Create an UISelectOneRadio component -- ------------------------------ function Create_SelectOneRadio return UIComponent_Access is begin return new ASF.Components.Html.Selects.UISelectOneRadio; end Create_SelectOneRadio; -- ------------------------------ -- Create an UISelectBoolean component -- ------------------------------ function Create_SelectBooleanCheckbox return UIComponent_Access is begin return new ASF.Components.Html.Selects.UISelectBoolean; end Create_SelectBooleanCheckbox; use ASF.Views.Nodes; URI : aliased constant String := "http://java.sun.com/jsf/html"; BODY_TAG : aliased constant String := "body"; COMMAND_BUTTON_TAG : aliased constant String := "commandButton"; DOCTYPE_TAG : aliased constant String := "doctype"; FORM_TAG : aliased constant String := "form"; HEAD_TAG : aliased constant String := "head"; INPUT_FILE_TAG : aliased constant String := "inputFile"; INPUT_HIDDEN_TAG : aliased constant String := "inputHidden"; INPUT_SECRET_TAG : aliased constant String := "inputSecret"; INPUT_TEXT_TAG : aliased constant String := "inputText"; INPUT_TEXTAREA_TAG : aliased constant String := "inputTextarea"; LIST_TAG : aliased constant String := "list"; MESSAGE_TAG : aliased constant String := "message"; MESSAGES_TAG : aliased constant String := "messages"; OUTPUT_FORMAT_TAG : aliased constant String := "outputFormat"; OUTPUT_LABEL_TAG : aliased constant String := "outputLabel"; OUTPUT_LINK_TAG : aliased constant String := "outputLink"; OUTPUT_TEXT_TAG : aliased constant String := "outputText"; PANEL_GROUP_TAG : aliased constant String := "panelGroup"; SELECT_BOOLEAN_TAG : aliased constant String := "selectBooleanCheckbox"; SELECT_ONE_MENU_TAG : aliased constant String := "selectOneMenu"; SELECT_ONE_RADIO_TAG : aliased constant String := "selectOneRadio"; Html_Bindings : aliased constant ASF.Factory.Binding_Array := (1 => (Name => BODY_TAG'Access, Component => Create_Body'Access, Tag => Create_Component_Node'Access), 2 => (Name => COMMAND_BUTTON_TAG'Access, Component => Create_Command'Access, Tag => Create_Component_Node'Access), 3 => (Name => DOCTYPE_TAG'Access, Component => Create_Doctype'Access, Tag => Create_Component_Node'Access), 4 => (Name => FORM_TAG'Access, Component => Create_Form'Access, Tag => Create_Component_Node'Access), 5 => (Name => HEAD_TAG'Access, Component => Create_Head'Access, Tag => Create_Component_Node'Access), 6 => (Name => INPUT_FILE_TAG'Access, Component => Create_Input_File'Access, Tag => Create_Component_Node'Access), 7 => (Name => INPUT_HIDDEN_TAG'Access, Component => Create_Input_Hidden'Access, Tag => Create_Component_Node'Access), 8 => (Name => INPUT_SECRET_TAG'Access, Component => Create_Input_Secret'Access, Tag => Create_Component_Node'Access), 9 => (Name => INPUT_TEXT_TAG'Access, Component => Create_Input_Text'Access, Tag => Create_Component_Node'Access), 10 => (Name => INPUT_TEXTAREA_TAG'Access, Component => Create_Input_Textarea'Access, Tag => Create_Component_Node'Access), 11 => (Name => LIST_TAG'Access, Component => Create_List'Access, Tag => Create_Component_Node'Access), 12 => (Name => MESSAGE_TAG'Access, Component => Create_Message'Access, Tag => Create_Component_Node'Access), 13 => (Name => MESSAGES_TAG'Access, Component => Create_Messages'Access, Tag => Create_Component_Node'Access), 14 => (Name => OUTPUT_FORMAT_TAG'Access, Component => Create_Output_Format'Access, Tag => Create_Component_Node'Access), 15 => (Name => OUTPUT_LABEL_TAG'Access, Component => Create_Output_Label'Access, Tag => Create_Component_Node'Access), 16 => (Name => OUTPUT_LINK_TAG'Access, Component => Create_Output_Link'Access, Tag => Create_Component_Node'Access), 17 => (Name => OUTPUT_TEXT_TAG'Access, Component => Create_Output'Access, Tag => Create_Component_Node'Access), 18 => (Name => PANEL_GROUP_TAG'Access, Component => Create_PanelGroup'Access, Tag => Create_Component_Node'Access), 19 => (Name => SELECT_BOOLEAN_TAG'Access, Component => Create_SelectBooleanCheckbox'Access, Tag => Create_Component_Node'Access), 20 => (Name => SELECT_ONE_MENU_TAG'Access, Component => Create_SelectOne'Access, Tag => Create_Component_Node'Access), 21 => (Name => SELECT_ONE_RADIO_TAG'Access, Component => Create_SelectOneRadio'Access, Tag => Create_Component_Node'Access) ); Html_Factory : aliased constant ASF.Factory.Factory_Bindings := (URI => URI'Access, Bindings => Html_Bindings'Access); -- ------------------------------ -- Get the HTML component factory. -- ------------------------------ function Definition return ASF.Factory.Factory_Bindings_Access is begin return Html_Factory'Access; end Definition; end ASF.Components.Html.Factory;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- R T S F I N D -- -- -- -- S p e c -- -- -- -- $Revision$ -- -- -- Copyright (C) 1992-2001, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Types; use Types; package Rtsfind is -- This package contains the routine that is used to obtain runtime library -- entities, loading in the required runtime library packages on demand. It -- is also used for such purposes as finding System.Address when System has -- not been explicitly With'ed. ------------------------ -- Runtime Unit Table -- ------------------------ -- The following type includes an enumeration entry for each runtime -- unit. The enumeration literal represents the fully qualified -- name of the unit, as follows: -- Names of the form Ada_xxx are first level children of Ada, whose -- name is Ada.xxx. For example, the name Ada_Tags refers to package -- Ada.Tags. -- Names of the form Ada_Calendar_xxx are second level children -- of Ada.Calendar. This is part of a temporary implementation of -- delays; eventually, packages implementing delays will be found -- relative to the package that declares the time type. -- Names of the form Interfaces_xxx are first level children of -- Interfaces_CPP refers to package Interfaces.CPP -- Names of the form System_xxx are first level children of System, whose -- name is System.xxx. For example, the name System_Str_Concat refers to -- package System.Str_Concat. -- Names of the form System_Tasking_xxx are second level children of the -- package System.Tasking. For example, System_Tasking_Stages refers to -- refers to the package System.Tasking.Stages. -- Other names stand for themselves (e.g. System for package System) -- This list can contain both subprogram and package unit names. For -- packages, the accessible entities in the package are separately -- listed in the package entity table. The units must be either library -- level package declarations, or library level subprogram declarations. -- Generic units, library level instantiations and subprogram bodies -- acting as specs may not be referenced (all these cases could be added -- at the expense of additional complexity in the body of Rtsfind, but -- it doesn't seem worth while, since the implementation controls the -- set of units that are referenced, and this restrictions is easily met. -- IMPORTANT NOTE: the specs of packages and procedures with'ed using -- this mechanism may not contain use clauses. This is because these -- subprograms are compiled in the current visibility environment, and -- it would be too much trouble to establish a clean environment for the -- compilation. The presence of extraneous visible stuff has no effect -- on the compilation except in the presence of use clauses (which might -- result in unexpected ambiguities). type RTU_Id is ( -- Runtime packages, for list of accessible entities in each -- package see declarations in the runtime entity table below. RTU_Null, -- Used as a null entry. Will cause an error if referenced. -- Children of Ada Ada_Calendar, Ada_Exceptions, Ada_Finalization, Ada_Interrupts, Ada_Real_Time, Ada_Streams, Ada_Tags, Ada_Task_Identification, -- Children of Ada.Calendar Ada_Calendar_Delays, -- Children of Ada.Finalization Ada_Finalization_List_Controller, -- Children of Ada.Real_Time Ada_Real_Time_Delays, -- Children of Ada.Streams Ada_Streams_Stream_IO, -- Children of Ada.Text_IO (for Text_IO_Kludge) Ada_Text_IO_Decimal_IO, Ada_Text_IO_Enumeration_IO, Ada_Text_IO_Fixed_IO, Ada_Text_IO_Float_IO, Ada_Text_IO_Integer_IO, Ada_Text_IO_Modular_IO, -- Children of Ada.Wide_Text_IO (for Text_IO_Kludge) Ada_Wide_Text_IO_Decimal_IO, Ada_Wide_Text_IO_Enumeration_IO, Ada_Wide_Text_IO_Fixed_IO, Ada_Wide_Text_IO_Float_IO, Ada_Wide_Text_IO_Integer_IO, Ada_Wide_Text_IO_Modular_IO, -- Interfaces Interfaces, -- Children of Interfaces Interfaces_CPP, Interfaces_Packed_Decimal, -- Package System System, -- Children of System System_Arith_64, System_AST_Handling, System_Assertions, System_Aux_DEC, System_Bit_Ops, System_Checked_Pools, System_Exception_Table, System_Exceptions, System_Delay_Operations, System_Exn_Flt, System_Exn_Int, System_Exn_LFlt, System_Exn_LInt, System_Exn_LLF, System_Exn_LLI, System_Exn_SFlt, System_Exn_SInt, System_Exn_SSI, System_Exp_Flt, System_Exp_Int, System_Exp_LFlt, System_Exp_LInt, System_Exp_LLF, System_Exp_LLI, System_Exp_LLU, System_Exp_Mod, System_Exp_SFlt, System_Exp_SInt, System_Exp_SSI, System_Exp_Uns, System_Fat_Flt, System_Fat_LFlt, System_Fat_LLF, System_Fat_SFlt, System_Finalization_Implementation, System_Finalization_Root, System_Fore, System_Img_Bool, System_Img_Char, System_Img_Dec, System_Img_Enum, System_Img_Int, System_Img_LLD, System_Img_LLI, System_Img_LLU, System_Img_Name, System_Img_Real, System_Img_Uns, System_Img_WChar, System_Interrupts, System_Machine_Code, System_Mantissa, System_Pack_03, System_Pack_05, System_Pack_06, System_Pack_07, System_Pack_09, System_Pack_10, System_Pack_11, System_Pack_12, System_Pack_13, System_Pack_14, System_Pack_15, System_Pack_17, System_Pack_18, System_Pack_19, System_Pack_20, System_Pack_21, System_Pack_22, System_Pack_23, System_Pack_24, System_Pack_25, System_Pack_26, System_Pack_27, System_Pack_28, System_Pack_29, System_Pack_30, System_Pack_31, System_Pack_33, System_Pack_34, System_Pack_35, System_Pack_36, System_Pack_37, System_Pack_38, System_Pack_39, System_Pack_40, System_Pack_41, System_Pack_42, System_Pack_43, System_Pack_44, System_Pack_45, System_Pack_46, System_Pack_47, System_Pack_48, System_Pack_49, System_Pack_50, System_Pack_51, System_Pack_52, System_Pack_53, System_Pack_54, System_Pack_55, System_Pack_56, System_Pack_57, System_Pack_58, System_Pack_59, System_Pack_60, System_Pack_61, System_Pack_62, System_Pack_63, System_Parameters, System_Partition_Interface, System_Pool_Global, System_Pool_Empty, System_Pool_Local, System_Pool_Size, System_RPC, System_Scalar_Values, System_Secondary_Stack, System_Shared_Storage, System_Soft_Links, System_Standard_Library, System_Storage_Elements, System_Storage_Pools, System_Stream_Attributes, System_String_Ops, System_String_Ops_Concat_3, System_String_Ops_Concat_4, System_String_Ops_Concat_5, System_Task_Info, System_Tasking, System_Unsigned_Types, System_Val_Bool, System_Val_Char, System_Val_Dec, System_Val_Enum, System_Val_Int, System_Val_LLD, System_Val_LLI, System_Val_LLU, System_Val_Name, System_Val_Real, System_Val_Uns, System_Val_WChar, System_Vax_Float_Operations, System_Version_Control, System_VMS_Exception_Table, System_WCh_StW, System_WCh_WtS, System_Wid_Bool, System_Wid_Char, System_Wid_Enum, System_Wid_LLI, System_Wid_LLU, System_Wid_Name, System_Wid_WChar, System_WWd_Char, System_WWd_Enum, System_WWd_Wchar, -- Children of System.Tasking System_Tasking_Async_Delays, System_Tasking_Async_Delays_Enqueue_Calendar, System_Tasking_Async_Delays_Enqueue_RT, System_Tasking_Protected_Objects, System_Tasking_Protected_Objects_Entries, System_Tasking_Protected_Objects_Operations, System_Tasking_Protected_Objects_Single_Entry, System_Tasking_Restricted_Stages, System_Tasking_Rendezvous, System_Tasking_Stages); subtype Ada_Child is RTU_Id range Ada_Calendar .. Ada_Wide_Text_IO_Modular_IO; -- Range of values for children or grand-children of Ada subtype Ada_Calendar_Child is Ada_Child range Ada_Calendar_Delays .. Ada_Calendar_Delays; -- Range of values for children of Ada.Calendar subtype Ada_Finalization_Child is Ada_Child range Ada_Finalization_List_Controller .. Ada_Finalization_List_Controller; -- Range of values for children of Ada.Finalization subtype Ada_Real_Time_Child is Ada_Child range Ada_Real_Time_Delays .. Ada_Real_Time_Delays; -- Range of values for children of Ada.Real_Time subtype Ada_Streams_Child is Ada_Child range Ada_Streams_Stream_IO .. Ada_Streams_Stream_IO; subtype Ada_Text_IO_Child is Ada_Child range Ada_Text_IO_Decimal_IO .. Ada_Text_IO_Modular_IO; -- Range of values for children of Ada.Text_IO subtype Ada_Wide_Text_IO_Child is Ada_Child range Ada_Wide_Text_IO_Decimal_IO .. Ada_Wide_Text_IO_Modular_IO; -- Range of values for children of Ada.Text_IO subtype Interfaces_Child is RTU_Id range Interfaces_CPP .. Interfaces_Packed_Decimal; -- Range of values for children of Interfaces subtype System_Child is RTU_Id range System_Arith_64 .. System_Tasking_Stages; -- Range of values for children or grandchildren of System subtype System_Tasking_Child is System_Child range System_Tasking_Async_Delays .. System_Tasking_Stages; -- Range of values for children of System.Tasking subtype System_Tasking_Protected_Objects_Child is System_Tasking_Child range System_Tasking_Protected_Objects_Entries .. System_Tasking_Protected_Objects_Single_Entry; -- Range of values for children of System.Tasking.Protected_Objects subtype System_Tasking_Restricted_Child is System_Tasking_Child range System_Tasking_Restricted_Stages .. System_Tasking_Restricted_Stages; -- Range of values for children of System.Tasking.Restricted subtype System_Tasking_Async_Delays_Child is System_Tasking_Child range System_Tasking_Async_Delays_Enqueue_Calendar .. System_Tasking_Async_Delays_Enqueue_RT; -- Range of values for children of System.Tasking.Async_Delays OK_To_Use_In_No_Run_Time_Mode : array (RTU_Id) of Boolean := (Ada_Tags => True, Ada_Exceptions => True, Interfaces => True, System => True, System_Fat_Flt => True, System_Fat_LFlt => True, System_Fat_LLF => True, System_Fat_SFlt => True, System_Machine_Code => True, System_Storage_Elements => True, System_Unsigned_Types => True, System_Secondary_Stack => True, others => False); -- This array defines the set of packages that can legitimately be -- accessed by Rtsfind in No_Run_Time mode. Any attempt to load -- any other package in this mode will result in a message noting -- use of a feature not supported in high integrity mode. OK_To_Use_In_Ravenscar_Mode : array (RTU_Id) of Boolean := (System_Interrupts => True, System_Tasking => True, System_Tasking_Protected_Objects => True, System_Tasking_Restricted_Stages => True, System_Tasking_Protected_Objects_Single_Entry => True, System_Task_Info => True, System_Parameters => True, Ada_Real_Time => True, Ada_Real_Time_Delays => True, others => False); -- This array defines the set of packages that can legitimately be -- accessed by Rtsfind in Ravenscar mode, in addition to the -- No_Run_Time units which are also allowed. -------------------------- -- Runtime Entity Table -- -------------------------- -- This is the enumeration type used to define the argument passed to -- the RTE function. The name must exactly match the name of the entity -- involved, and in the case of a package entity, this name must uniquely -- imply the package containing the entity. -- As far as possible, we avoid duplicate names in runtime packages, so -- that the name RE_nnn uniquely identifies the entity nnn. In some cases, -- it is impossible to avoid such duplication because the names come from -- RM defined packages. In such cases, the name is of the form RO_XX_nnn -- where XX is two letters used to differentiate the multiple occurrences -- of the name xx, and nnn is the entity name. -- Note that not all entities in the units contained in the run-time unit -- table are included in the following table, only those that actually -- have to be referenced from generated code. -- Note on RE_Null. This value is used as a null entry where an RE_Id -- value is required syntactically, but no real entry is required or -- needed. Use of this value will cause a fatal error in an RTE call. type RE_Id is ( RE_Null, RE_Code_Loc, -- Ada.Exceptions RE_Current_Target_Exception, -- Ada.Exceptions (JGNAT use only) RE_Exception_Id, -- Ada.Exceptions RE_Exception_Information, -- Ada.Exceptions RE_Exception_Message, -- Ada.Exceptions RE_Exception_Name_Simple, -- Ada.Exceptions RE_Exception_Occurrence, -- Ada.Exceptions RE_Null_Id, -- Ada.Exceptions RE_Null_Occurrence, -- Ada.Exceptions RE_Poll, -- Ada.Exceptions RE_Raise_Exception, -- Ada.Exceptions RE_Raise_Exception_Always, -- Ada.Exceptions RE_Reraise_Occurrence, -- Ada.Exceptions RE_Reraise_Occurrence_Always, -- Ada.Exceptions RE_Reraise_Occurrence_No_Defer, -- Ada.Exceptions RE_Save_Occurrence, -- Ada.Exceptions RE_Simple_List_Controller, -- Ada.Finalization.List_Controller RE_List_Controller, -- Ada.Finalization.List_Controller RE_Interrupt_Id, -- Ada.Interrupts RE_Root_Stream_Type, -- Ada.Streams RE_Stream_Element, -- Ada.Streams RE_Stream_Element_Offset, -- Ada.Streams RE_Stream_Element_Array, -- Ada.Streams RE_Stream_Access, -- Ada.Streams.Stream_IO RE_CW_Membership, -- Ada.Tags RE_DT_Entry_Size, -- Ada.Tags RE_DT_Prologue_Size, -- Ada.Tags RE_External_Tag, -- Ada.Tags RE_Get_Expanded_Name, -- Ada.Tags RE_Get_External_Tag, -- Ada.Tags RE_Get_Prim_Op_Address, -- Ada.Tags RE_Get_RC_Offset, -- Ada.Tags RE_Get_Remotely_Callable, -- Ada.Tags RE_Get_TSD, -- Ada.Tags RE_Inherit_DT, -- Ada.Tags RE_Inherit_TSD, -- Ada.Tags RE_Internal_Tag, -- Ada.Tags RE_Register_Tag, -- Ada.Tags RE_Set_Expanded_Name, -- Ada.Tags RE_Set_External_Tag, -- Ada.Tags RE_Set_Prim_Op_Address, -- Ada.Tags RE_Set_RC_Offset, -- Ada.Tags RE_Set_Remotely_Callable, -- Ada.Tags RE_Set_TSD, -- Ada.Tags RE_Tag_Error, -- Ada.Tags RE_TSD_Entry_Size, -- Ada.Tags RE_TSD_Prologue_Size, -- Ada.Tags RE_Tag, -- Ada.Tags RE_Address_Array, -- Ada.Tags RE_Current_Task, -- Ada.Task_Identification RO_AT_Task_ID, -- Ada.Task_Identification RO_CA_Time, -- Ada.Calendar RO_CA_Delay_For, -- Ada.Calendar.Delays RO_CA_Delay_Until, -- Ada.Calendar.Delays RO_CA_To_Duration, -- Ada.Calendar.Delays RO_RT_Time, -- Ada.Real_Time RO_RT_Delay_Until, -- Ada.Real_Time.Delays RO_RT_To_Duration, -- Ada.Real_Time.Delays RE_Integer_64, -- Interfaces RE_Unsigned_8, -- Interfaces RE_Unsigned_16, -- Interfaces RE_Unsigned_32, -- Interfaces RE_Unsigned_64, -- Interfaces RE_Vtable_Ptr, -- Interfaces.CPP RE_Displaced_This, -- Interfaces.CPP RE_CPP_CW_Membership, -- Interfaces.CPP RE_CPP_DT_Entry_Size, -- Interfaces.CPP RE_CPP_DT_Prologue_Size, -- Interfaces.CPP RE_CPP_Get_Expanded_Name, -- Interfaces.CPP RE_CPP_Get_External_Tag, -- Interfaces.CPP RE_CPP_Get_Prim_Op_Address, -- Interfaces.CPP RE_CPP_Get_RC_Offset, -- Interfaces.CPP RE_CPP_Get_Remotely_Callable, -- Interfaces.CPP RE_CPP_Get_TSD, -- Interfaces.CPP RE_CPP_Inherit_DT, -- Interfaces.CPP RE_CPP_Inherit_TSD, -- Interfaces.CPP RE_CPP_Register_Tag, -- Interfaces.CPP RE_CPP_Set_Expanded_Name, -- Interfaces.CPP RE_CPP_Set_External_Tag, -- Interfaces.CPP RE_CPP_Set_Prim_Op_Address, -- Interfaces.CPP RE_CPP_Set_RC_Offset, -- Interfaces.CPP RE_CPP_Set_Remotely_Callable, -- Interfaces.CPP RE_CPP_Set_TSD, -- Interfaces.CPP RE_CPP_TSD_Entry_Size, -- Interfaces.CPP RE_CPP_TSD_Prologue_Size, -- Interfaces.CPP RE_Packed_Size, -- Interfaces.Packed_Decimal RE_Packed_To_Int32, -- Interfaces.Packed_Decimal RE_Packed_To_Int64, -- Interfaces.Packed_Decimal RE_Int32_To_Packed, -- Interfaces.Packed_Decimal RE_Int64_To_Packed, -- Interfaces.Packed_Decimal RE_Address, -- System RE_Any_Priority, -- System RE_Bit_Order, -- System RE_Default_Priority, -- System RE_High_Order_First, -- System RE_Interrupt_Priority, -- System RE_Lib_Stop, -- System RE_Low_Order_First, -- System RE_Max_Interrupt_Priority, -- System RE_Max_Priority, -- System RE_Null_Address, -- System RE_Priority, -- System RE_Add_With_Ovflo_Check, -- System.Arith_64 RE_Double_Divide, -- System.Arith_64 RE_Multiply_With_Ovflo_Check, -- System.Arith_64 RE_Scaled_Divide, -- System.Arith_64 RE_Subtract_With_Ovflo_Check, -- System.Arith_64 RE_Create_AST_Handler, -- System.AST_Handling RE_Raise_Assert_Failure, -- System.Assertions RE_AST_Handler, -- System.Aux_DEC RE_Import_Value, -- System.Aux_DEC RE_No_AST_Handler, -- System.Aux_DEC RE_Type_Class, -- System.Aux_DEC RE_Type_Class_Enumeration, -- System.Aux_DEC RE_Type_Class_Integer, -- System.Aux_DEC RE_Type_Class_Fixed_Point, -- System.Aux_DEC RE_Type_Class_Floating_Point, -- System.Aux_DEC RE_Type_Class_Array, -- System.Aux_DEC RE_Type_Class_Record, -- System.Aux_DEC RE_Type_Class_Access, -- System.Aux_DEC RE_Type_Class_Task, -- System.Aux_DEC RE_Type_Class_Address, -- System.Aux_DEC RE_Bit_And, -- System.Bit_Ops RE_Bit_Eq, -- System.Bit_Ops RE_Bit_Not, -- System.Bit_Ops RE_Bit_Or, -- System.Bit_Ops RE_Bit_Xor, -- System.Bit_Ops RE_Checked_Pool, -- System.Checked_Pools RE_Register_Exception, -- System.Exception_Table RE_All_Others_Id, -- System.Exceptions RE_Handler_Record, -- System.Exceptions RE_Handler_Record_Ptr, -- System.Exceptions RE_Others_Id, -- System.Exceptions RE_Subprogram_Descriptor, -- System.Exceptions RE_Subprogram_Descriptor_0, -- System.Exceptions RE_Subprogram_Descriptor_1, -- System.Exceptions RE_Subprogram_Descriptor_2, -- System.Exceptions RE_Subprogram_Descriptor_3, -- System.Exceptions RE_Subprogram_Descriptor_List, -- System.Exceptions RE_Subprogram_Descriptor_Ptr, -- System.Exceptions RE_Subprogram_Descriptors_Record, -- System.Exceptions RE_Subprogram_Descriptors_Ptr, -- System.Exceptions RE_Exn_Float, -- System.Exn_Flt RE_Exn_Integer, -- System.Exn_Int RE_Exn_Long_Float, -- System.Exn_LFlt RE_Exn_Long_Integer, -- System.Exn_LInt RE_Exn_Long_Long_Float, -- System.Exn_LLF RE_Exn_Long_Long_Integer, -- System.Exn_LLI RE_Exn_Short_Float, -- System.Exn_SFlt RE_Exn_Short_Integer, -- System.Exn_SInt RE_Exn_Short_Short_Integer, -- System.Exn_SSI RE_Exp_Float, -- System.Exp_Flt RE_Exp_Integer, -- System.Exp_Int RE_Exp_Long_Float, -- System.Exp_LFlt RE_Exp_Long_Integer, -- System.Exp_LInt RE_Exp_Long_Long_Float, -- System.Exp_LLF RE_Exp_Long_Long_Integer, -- System.Exp_LLI RE_Exp_Long_Long_Unsigned, -- System.Exp_LLU RE_Exp_Modular, -- System.Exp_Mod RE_Exp_Short_Float, -- System.Exp_SFlt RE_Exp_Short_Integer, -- System.Exp_SInt RE_Exp_Short_Short_Integer, -- System.Exp_SSI RE_Exp_Unsigned, -- System.Exp_Uns RE_Fat_Float, -- System.Fat_Flt RE_Fat_Long_Float, -- System.Fat_LFlt RE_Fat_Long_Long_Float, -- System.Fat_LLF RE_Fat_Short_Float, -- System.Fat_SFlt RE_Attach_To_Final_List, -- System.Finalization_Implementation RE_Finalize_List, -- System.Finalization_Implementation RE_Finalize_One, -- System.Finalization_Implementation RE_Global_Final_List, -- System.Finalization_Implementation RE_Record_Controller, -- System.Finalization_Implementation RE_Limited_Record_Controller, -- System.Finalization_Implementation RE_Deep_Tag_Initialize, -- System.Finalization_Implementation RE_Deep_Tag_Adjust, -- System.Finalization_Implementation RE_Deep_Tag_Finalize, -- System.Finalization_Implementation RE_Deep_Tag_Attach, -- System.Finalization_Implementation RE_Deep_Rec_Initialize, -- System.Finalization_Implementation RE_Deep_Rec_Adjust, -- System.Finalization_Implementation RE_Deep_Rec_Finalize, -- System.Finalization_Implementation RE_Root_Controlled, -- System.Finalization_Root RE_Finalizable, -- System.Finalization_Root RE_Finalizable_Ptr, -- System.Finalization_Root RE_Fore, -- System.Fore RE_Image_Boolean, -- System.Img_Bool RE_Image_Character, -- System.Img_Char RE_Image_Decimal, -- System.Img_Dec RE_Image_Enumeration_8, -- System.Img_Enum RE_Image_Enumeration_16, -- System.Img_Enum RE_Image_Enumeration_32, -- System.Img_Enum RE_Image_Integer, -- System.Img_Int RE_Image_Long_Long_Decimal, -- System.Img_LLD RE_Image_Long_Long_Integer, -- System.Img_LLI RE_Image_Long_Long_Unsigned, -- System.Img_LLU RE_Image_Ordinary_Fixed_Point, -- System.Img_Real RE_Image_Floating_Point, -- System.Img_Real RE_Image_Unsigned, -- System.Img_Uns RE_Image_Wide_Character, -- System.Img_WChar RE_Bind_Interrupt_To_Entry, -- System.Interrupts RE_Default_Interrupt_Priority, -- System.Interrupts RE_Dynamic_Interrupt_Protection, -- System.Interrupts RE_Install_Handlers, -- System.Interrupts RE_Register_Interrupt_Handler, -- System.Interrupts RE_Static_Interrupt_Protection, -- System.Interrupts RE_Asm_Insn, -- System.Machine_Code RE_Asm_Input_Operand, -- System.Machine_Code RE_Asm_Output_Operand, -- System.Machine_Code RE_Mantissa_Value, -- System_Mantissa RE_Bits_03, -- System.Pack_03 RE_Get_03, -- System.Pack_03 RE_Set_03, -- System.Pack_03 RE_Bits_05, -- System.Pack_05 RE_Get_05, -- System.Pack_05 RE_Set_05, -- System.Pack_05 RE_Bits_06, -- System.Pack_06 RE_Get_06, -- System.Pack_06 RE_GetU_06, -- System.Pack_06 RE_Set_06, -- System.Pack_06 RE_SetU_06, -- System.Pack_06 RE_Bits_07, -- System.Pack_07 RE_Get_07, -- System.Pack_07 RE_Set_07, -- System.Pack_07 RE_Bits_09, -- System.Pack_09 RE_Get_09, -- System.Pack_09 RE_Set_09, -- System.Pack_09 RE_Bits_10, -- System.Pack_10 RE_Get_10, -- System.Pack_10 RE_GetU_10, -- System.Pack_10 RE_Set_10, -- System.Pack_10 RE_SetU_10, -- System.Pack_10 RE_Bits_11, -- System.Pack_11 RE_Get_11, -- System.Pack_11 RE_Set_11, -- System.Pack_11 RE_Bits_12, -- System.Pack_12 RE_Get_12, -- System.Pack_12 RE_GetU_12, -- System.Pack_12 RE_Set_12, -- System.Pack_12 RE_SetU_12, -- System.Pack_12 RE_Bits_13, -- System.Pack_13 RE_Get_13, -- System.Pack_13 RE_Set_13, -- System.Pack_13 RE_Bits_14, -- System.Pack_14 RE_Get_14, -- System.Pack_14 RE_GetU_14, -- System.Pack_14 RE_Set_14, -- System.Pack_14 RE_SetU_14, -- System.Pack_14 RE_Bits_15, -- System.Pack_15 RE_Get_15, -- System.Pack_15 RE_Set_15, -- System.Pack_15 RE_Bits_17, -- System.Pack_17 RE_Get_17, -- System.Pack_17 RE_Set_17, -- System.Pack_17 RE_Bits_18, -- System.Pack_18 RE_Get_18, -- System.Pack_18 RE_GetU_18, -- System.Pack_18 RE_Set_18, -- System.Pack_18 RE_SetU_18, -- System.Pack_18 RE_Bits_19, -- System.Pack_19 RE_Get_19, -- System.Pack_19 RE_Set_19, -- System.Pack_19 RE_Bits_20, -- System.Pack_20 RE_Get_20, -- System.Pack_20 RE_GetU_20, -- System.Pack_20 RE_Set_20, -- System.Pack_20 RE_SetU_20, -- System.Pack_20 RE_Bits_21, -- System.Pack_21 RE_Get_21, -- System.Pack_21 RE_Set_21, -- System.Pack_21 RE_Bits_22, -- System.Pack_22 RE_Get_22, -- System.Pack_22 RE_GetU_22, -- System.Pack_22 RE_Set_22, -- System.Pack_22 RE_SetU_22, -- System.Pack_22 RE_Bits_23, -- System.Pack_23 RE_Get_23, -- System.Pack_23 RE_Set_23, -- System.Pack_23 RE_Bits_24, -- System.Pack_24 RE_Get_24, -- System.Pack_24 RE_GetU_24, -- System.Pack_24 RE_Set_24, -- System.Pack_24 RE_SetU_24, -- System.Pack_24 RE_Bits_25, -- System.Pack_25 RE_Get_25, -- System.Pack_25 RE_Set_25, -- System.Pack_25 RE_Bits_26, -- System.Pack_26 RE_Get_26, -- System.Pack_26 RE_GetU_26, -- System.Pack_26 RE_Set_26, -- System.Pack_26 RE_SetU_26, -- System.Pack_26 RE_Bits_27, -- System.Pack_27 RE_Get_27, -- System.Pack_27 RE_Set_27, -- System.Pack_27 RE_Bits_28, -- System.Pack_28 RE_Get_28, -- System.Pack_28 RE_GetU_28, -- System.Pack_28 RE_Set_28, -- System.Pack_28 RE_SetU_28, -- System.Pack_28 RE_Bits_29, -- System.Pack_29 RE_Get_29, -- System.Pack_29 RE_Set_29, -- System.Pack_29 RE_Bits_30, -- System.Pack_30 RE_Get_30, -- System.Pack_30 RE_GetU_30, -- System.Pack_30 RE_Set_30, -- System.Pack_30 RE_SetU_30, -- System.Pack_30 RE_Bits_31, -- System.Pack_31 RE_Get_31, -- System.Pack_31 RE_Set_31, -- System.Pack_31 RE_Bits_33, -- System.Pack_33 RE_Get_33, -- System.Pack_33 RE_Set_33, -- System.Pack_33 RE_Bits_34, -- System.Pack_34 RE_Get_34, -- System.Pack_34 RE_GetU_34, -- System.Pack_34 RE_Set_34, -- System.Pack_34 RE_SetU_34, -- System.Pack_34 RE_Bits_35, -- System.Pack_35 RE_Get_35, -- System.Pack_35 RE_Set_35, -- System.Pack_35 RE_Bits_36, -- System.Pack_36 RE_Get_36, -- System.Pack_36 RE_GetU_36, -- System.Pack_36 RE_Set_36, -- System.Pack_36 RE_SetU_36, -- System.Pack_36 RE_Bits_37, -- System.Pack_37 RE_Get_37, -- System.Pack_37 RE_Set_37, -- System.Pack_37 RE_Bits_38, -- System.Pack_38 RE_Get_38, -- System.Pack_38 RE_GetU_38, -- System.Pack_38 RE_Set_38, -- System.Pack_38 RE_SetU_38, -- System.Pack_38 RE_Bits_39, -- System.Pack_39 RE_Get_39, -- System.Pack_39 RE_Set_39, -- System.Pack_39 RE_Bits_40, -- System.Pack_40 RE_Get_40, -- System.Pack_40 RE_GetU_40, -- System.Pack_40 RE_Set_40, -- System.Pack_40 RE_SetU_40, -- System.Pack_40 RE_Bits_41, -- System.Pack_41 RE_Get_41, -- System.Pack_41 RE_Set_41, -- System.Pack_41 RE_Bits_42, -- System.Pack_42 RE_Get_42, -- System.Pack_42 RE_GetU_42, -- System.Pack_42 RE_Set_42, -- System.Pack_42 RE_SetU_42, -- System.Pack_42 RE_Bits_43, -- System.Pack_43 RE_Get_43, -- System.Pack_43 RE_Set_43, -- System.Pack_43 RE_Bits_44, -- System.Pack_44 RE_Get_44, -- System.Pack_44 RE_GetU_44, -- System.Pack_44 RE_Set_44, -- System.Pack_44 RE_SetU_44, -- System.Pack_44 RE_Bits_45, -- System.Pack_45 RE_Get_45, -- System.Pack_45 RE_Set_45, -- System.Pack_45 RE_Bits_46, -- System.Pack_46 RE_Get_46, -- System.Pack_46 RE_GetU_46, -- System.Pack_46 RE_Set_46, -- System.Pack_46 RE_SetU_46, -- System.Pack_46 RE_Bits_47, -- System.Pack_47 RE_Get_47, -- System.Pack_47 RE_Set_47, -- System.Pack_47 RE_Bits_48, -- System.Pack_48 RE_Get_48, -- System.Pack_48 RE_GetU_48, -- System.Pack_48 RE_Set_48, -- System.Pack_48 RE_SetU_48, -- System.Pack_48 RE_Bits_49, -- System.Pack_49 RE_Get_49, -- System.Pack_49 RE_Set_49, -- System.Pack_49 RE_Bits_50, -- System.Pack_50 RE_Get_50, -- System.Pack_50 RE_GetU_50, -- System.Pack_50 RE_Set_50, -- System.Pack_50 RE_SetU_50, -- System.Pack_50 RE_Bits_51, -- System.Pack_51 RE_Get_51, -- System.Pack_51 RE_Set_51, -- System.Pack_51 RE_Bits_52, -- System.Pack_52 RE_Get_52, -- System.Pack_52 RE_GetU_52, -- System.Pack_52 RE_Set_52, -- System.Pack_52 RE_SetU_52, -- System.Pack_52 RE_Bits_53, -- System.Pack_53 RE_Get_53, -- System.Pack_53 RE_Set_53, -- System.Pack_53 RE_Bits_54, -- System.Pack_54 RE_Get_54, -- System.Pack_54 RE_GetU_54, -- System.Pack_54 RE_Set_54, -- System.Pack_54 RE_SetU_54, -- System.Pack_54 RE_Bits_55, -- System.Pack_55 RE_Get_55, -- System.Pack_55 RE_Set_55, -- System.Pack_55 RE_Bits_56, -- System.Pack_56 RE_Get_56, -- System.Pack_56 RE_GetU_56, -- System.Pack_56 RE_Set_56, -- System.Pack_56 RE_SetU_56, -- System.Pack_56 RE_Bits_57, -- System.Pack_57 RE_Get_57, -- System.Pack_57 RE_Set_57, -- System.Pack_57 RE_Bits_58, -- System.Pack_58 RE_Get_58, -- System.Pack_58 RE_GetU_58, -- System.Pack_58 RE_Set_58, -- System.Pack_58 RE_SetU_58, -- System.Pack_58 RE_Bits_59, -- System.Pack_59 RE_Get_59, -- System.Pack_59 RE_Set_59, -- System.Pack_59 RE_Bits_60, -- System.Pack_60 RE_Get_60, -- System.Pack_60 RE_GetU_60, -- System.Pack_60 RE_Set_60, -- System.Pack_60 RE_SetU_60, -- System.Pack_60 RE_Bits_61, -- System.Pack_61 RE_Get_61, -- System.Pack_61 RE_Set_61, -- System.Pack_61 RE_Bits_62, -- System.Pack_62 RE_Get_62, -- System.Pack_62 RE_GetU_62, -- System.Pack_62 RE_Set_62, -- System.Pack_62 RE_SetU_62, -- System.Pack_62 RE_Bits_63, -- System.Pack_63 RE_Get_63, -- System.Pack_63 RE_Set_63, -- System.Pack_63 RE_Adjust_Storage_Size, -- System_Parameters RE_Default_Stack_Size, -- System.Parameters RE_Garbage_Collected, -- System.Parameters RE_Size_Type, -- System.Parameters RE_Unspecified_Size, -- System.Parameters RE_Get_Active_Partition_Id, -- System.Partition_Interface RE_Get_Passive_Partition_Id, -- System.Partition_Interface RE_Get_Local_Partition_Id, -- System.Partition_Interface RE_Get_RCI_Package_Receiver, -- System.Partition_Interface RE_Get_Unique_Remote_Pointer, -- System.Partition_Interface RE_RACW_Stub_Type, -- System.Partition_Interface RE_RACW_Stub_Type_Access, -- System.Partition_Interface RE_Raise_Program_Error_For_E_4_18, -- System.Partition_Interface RE_Raise_Program_Error_Unknown_Tag, -- System.Partition_Interface RE_Register_Passive_Package, -- System.Partition_Interface RE_Register_Receiving_Stub, -- System.Partition_Interface RE_RCI_Info, -- System.Partition_Interface RE_Subprogram_Id, -- System.Partition_Interface RE_Global_Pool_Object, -- System.Pool_Global RE_Unbounded_Reclaim_Pool, -- System.Pool_Local RE_Stack_Bounded_Pool, -- System.Pool_Size RE_Do_Apc, -- System.RPC RE_Do_Rpc, -- System.RPC RE_Params_Stream_Type, -- System.RPC RE_Partition_ID, -- System.RPC RE_RPC_Receiver, -- System.RPC RE_IS_Is1, -- System.Scalar_Values RE_IS_Is2, -- System.Scalar_Values RE_IS_Is4, -- System.Scalar_Values RE_IS_Is8, -- System.Scalar_Values RE_IS_Iu1, -- System.Scalar_Values RE_IS_Iu2, -- System.Scalar_Values RE_IS_Iu4, -- System.Scalar_Values RE_IS_Iu8, -- System.Scalar_Values RE_IS_Isf, -- System.Scalar_Values RE_IS_Ifl, -- System.Scalar_Values RE_IS_Ilf, -- System.Scalar_Values RE_IS_Ill, -- System.Scalar_Values RE_Mark_Id, -- System.Secondary_Stack RE_SS_Allocate, -- System.Secondary_Stack RE_SS_Pool, -- System.Secondary_Stack RE_SS_Mark, -- System.Secondary_Stack RE_SS_Release, -- System.Secondary_Stack RE_Shared_Var_Close, -- System.Shared_Storage RE_Shared_Var_Lock, -- System.Shared_Storage RE_Shared_Var_ROpen, -- System.Shared_Storage RE_Shared_Var_Unlock, -- System.Shared_Storage RE_Shared_Var_WOpen, -- System.Shared_Storage RE_Abort_Undefer_Direct, -- System.Standard_Library RE_Exception_Data_Ptr, -- System.Standard_Library RE_Integer_Address, -- System.Storage_Elements RE_Storage_Offset, -- System.Storage_Elements RE_Storage_Array, -- System.Storage_Elements RE_To_Address, -- System.Storage_Elements RE_Root_Storage_Pool, -- System.Storage_Pools RE_Thin_Pointer, -- System.Stream_Attributes RE_Fat_Pointer, -- System.Stream_Attributes RE_I_AD, -- System.Stream_Attributes RE_I_AS, -- System.Stream_Attributes RE_I_B, -- System.Stream_Attributes RE_I_C, -- System.Stream_Attributes RE_I_F, -- System.Stream_Attributes RE_I_I, -- System.Stream_Attributes RE_I_LF, -- System.Stream_Attributes RE_I_LI, -- System.Stream_Attributes RE_I_LLF, -- System.Stream_Attributes RE_I_LLI, -- System.Stream_Attributes RE_I_LLU, -- System.Stream_Attributes RE_I_LU, -- System.Stream_Attributes RE_I_SF, -- System.Stream_Attributes RE_I_SI, -- System.Stream_Attributes RE_I_SSI, -- System.Stream_Attributes RE_I_SSU, -- System.Stream_Attributes RE_I_SU, -- System.Stream_Attributes RE_I_U, -- System.Stream_Attributes RE_I_WC, -- System.Stream_Attributes RE_W_AD, -- System.Stream_Attributes RE_W_AS, -- System.Stream_Attributes RE_W_B, -- System.Stream_Attributes RE_W_C, -- System.Stream_Attributes RE_W_F, -- System.Stream_Attributes RE_W_I, -- System.Stream_Attributes RE_W_LF, -- System.Stream_Attributes RE_W_LI, -- System.Stream_Attributes RE_W_LLF, -- System.Stream_Attributes RE_W_LLI, -- System.Stream_Attributes RE_W_LLU, -- System.Stream_Attributes RE_W_LU, -- System.Stream_Attributes RE_W_SF, -- System.Stream_Attributes RE_W_SI, -- System.Stream_Attributes RE_W_SSI, -- System.Stream_Attributes RE_W_SSU, -- System.Stream_Attributes RE_W_SU, -- System.Stream_Attributes RE_W_U, -- System.Stream_Attributes RE_W_WC, -- System.Stream_Attributes RE_Str_Concat, -- System.String_Ops RE_Str_Concat_CC, -- System.String_Ops RE_Str_Concat_CS, -- System.String_Ops RE_Str_Concat_SC, -- System.String_Ops RE_Str_Equal, -- System.String_Ops RE_Str_Normalize, -- System.String_Ops RE_Wide_Str_Normalize, -- System.String_Ops RE_Str_Concat_3, -- System.String_Ops_Concat_3 RE_Str_Concat_4, -- System.String_Ops_Concat_4 RE_Str_Concat_5, -- System.String_Ops_Concat_5 RE_Free_Task_Image, -- System.Task_Info RE_Task_Info_Type, -- System.Task_Info RE_Task_Image_Type, -- System_Task_Info RE_Unspecified_Task_Info, -- System.Task_Info RE_Library_Task_Level, -- System.Tasking RE_Task_Procedure_Access, -- System.Tasking RO_ST_Task_ID, -- System.Tasking RE_Call_Modes, -- System.Tasking RE_Simple_Call, -- System.Tasking RE_Conditional_Call, -- System.Tasking RE_Asynchronous_Call, -- System.Tasking RE_Timed_Call, -- System.Tasking RE_Task_List, -- System.Tasking RE_Accept_Alternative, -- System.Tasking RE_Accept_List, -- System.Tasking RE_Accept_List_Access, -- System.Tasking RE_Max_Select, -- System.Tasking RE_Max_Task_Entry, -- System.Tasking RE_No_Rendezvous, -- System.Tasking RE_Null_Task_Entry, -- System.Tasking RE_Positive_Select_Index, -- System.Tasking RE_Select_Index, -- System.Tasking RE_Select_Modes, -- System.Tasking RE_Else_Mode, -- System.Tasking RE_Simple_Mode, -- System.Tasking RE_Terminate_Mode, -- System.Tasking RE_Delay_Mode, -- System.Tasking RE_Task_Entry_Index, -- System.Tasking RE_Self, -- System.Tasking RE_Master_Id, -- System.Tasking RE_Unspecified_Priority, -- System.Tasking RE_Activation_Chain, -- System.Tasking RE_Abort_Defer, -- System.Soft_Links RE_Abort_Undefer, -- System.Soft_Links RE_Complete_Master, -- System.Soft_Links RE_Current_Master, -- System.Soft_Links RE_Enter_Master, -- System.Soft_Links RE_Get_Current_Excep, -- System.Soft_Links RE_Get_GNAT_Exception, -- System.Soft_Links RE_Update_Exception, -- System.Soft_Links RE_Bits_1, -- System.Unsigned_Types RE_Bits_2, -- System.Unsigned_Types RE_Bits_4, -- System.Unsigned_Types RE_Float_Unsigned, -- System.Unsigned_Types RE_Long_Long_Unsigned, -- System.Unsigned_Types RE_Packed_Byte, -- System.Unsigned_Types RE_Packed_Bytes1, -- System.Unsigned_Types RE_Packed_Bytes2, -- System.Unsigned_Types RE_Packed_Bytes4, -- System.Unsigned_Types RE_Unsigned, -- System.Unsigned_Types RE_Value_Boolean, -- System.Val_Bool RE_Value_Character, -- System.Val_Char RE_Value_Decimal, -- System.Val_Dec RE_Value_Enumeration_8, -- System.Val_Enum RE_Value_Enumeration_16, -- System.Val_Enum RE_Value_Enumeration_32, -- System.Val_Enum RE_Value_Integer, -- System.Val_Int RE_Value_Long_Long_Decimal, -- System.Val_LLD RE_Value_Long_Long_Integer, -- System.Val_LLI RE_Value_Long_Long_Unsigned, -- System.Val_LLU RE_Value_Real, -- System.Val_Real RE_Value_Unsigned, -- System.Val_Uns RE_Value_Wide_Character, -- System.Val_WChar RE_D, -- System.Vax_Float_Operations RE_F, -- System.Vax_Float_Operations RE_G, -- System.Vax_Float_Operations RE_Q, -- System.Vax_Float_Operations RE_S, -- System.Vax_Float_Operations RE_T, -- System.Vax_Float_Operations RE_D_To_G, -- System.Vax_Float_Operations RE_F_To_G, -- System.Vax_Float_Operations RE_F_To_Q, -- System.Vax_Float_Operations RE_F_To_S, -- System.Vax_Float_Operations RE_G_To_D, -- System.Vax_Float_Operations RE_G_To_F, -- System.Vax_Float_Operations RE_G_To_Q, -- System.Vax_Float_Operations RE_G_To_T, -- System.Vax_Float_Operations RE_Q_To_F, -- System.Vax_Float_Operations RE_Q_To_G, -- System.Vax_Float_Operations RE_S_To_F, -- System.Vax_Float_Operations RE_T_To_D, -- System.Vax_Float_Operations RE_T_To_G, -- System.Vax_Float_Operations RE_Abs_F, -- System.Vax_Float_Operations RE_Abs_G, -- System.Vax_Float_Operations RE_Add_F, -- System.Vax_Float_Operations RE_Add_G, -- System.Vax_Float_Operations RE_Div_F, -- System.Vax_Float_Operations RE_Div_G, -- System.Vax_Float_Operations RE_Mul_F, -- System.Vax_Float_Operations RE_Mul_G, -- System.Vax_Float_Operations RE_Neg_F, -- System.Vax_Float_Operations RE_Neg_G, -- System.Vax_Float_Operations RE_Sub_F, -- System.Vax_Float_Operations RE_Sub_G, -- System.Vax_Float_Operations RE_Eq_F, -- System.Vax_Float_Operations RE_Eq_G, -- System.Vax_Float_Operations RE_Le_F, -- System.Vax_Float_Operations RE_Le_G, -- System.Vax_Float_Operations RE_Lt_F, -- System.Vax_Float_Operations RE_Lt_G, -- System.Vax_Float_Operations RE_Version_String, -- System.Version_Control RE_Get_Version_String, -- System.Version_Control RE_Register_VMS_Exception, -- System.VMS_Exception_Table RE_String_To_Wide_String, -- System.WCh_StW RE_Wide_String_To_String, -- System.WCh_WtS RE_Wide_Width_Character, -- System.WWd_Char RE_Wide_Width_Enumeration_8, -- System.WWd_Enum RE_Wide_Width_Enumeration_16, -- System.WWd_Enum RE_Wide_Width_Enumeration_32, -- System.WWd_Enum RE_Wide_Width_Wide_Character, -- System.WWd_Wchar RE_Width_Boolean, -- System.Wid_Bool RE_Width_Character, -- System.Wid_Char RE_Width_Enumeration_8, -- System.Wid_Enum RE_Width_Enumeration_16, -- System.Wid_Enum RE_Width_Enumeration_32, -- System.Wid_Enum RE_Width_Long_Long_Integer, -- System.Wid_LLI RE_Width_Long_Long_Unsigned, -- System.Wid_LLU RE_Width_Wide_Character, -- System.Wid_WChar RE_Protected_Entry_Body_Array, -- Tasking.Protected_Objects.Entries RE_Protection_Entries, -- Tasking.Protected_Objects.Entries RE_Initialize_Protection_Entries, -- Tasking.Protected_Objects.Entries RE_Lock_Entries, -- Tasking.Protected_Objects.Entries RE_Lock_Read_Only_Entries, -- Tasking.Protected_Objects.Entries RE_Unlock_Entries, -- Tasking.Protected_Objects.Entries RE_Communication_Block, -- Protected_Objects.Operations RE_Protected_Entry_Call, -- Protected_Objects.Operations RE_Service_Entries, -- Protected_Objects.Operations RE_Cancel_Protected_Entry_Call, -- Protected_Objects.Operations RE_Enqueued, -- Protected_Objects.Operations RE_Cancelled, -- Protected_Objects.Operations RE_Complete_Entry_Body, -- Protected_Objects.Operations RE_Exceptional_Complete_Entry_Body, -- Protected_Objects.Operations RE_Requeue_Protected_Entry, -- Protected_Objects.Operations RE_Requeue_Task_To_Protected_Entry, -- Protected_Objects.Operations RE_Protected_Count, -- Protected_Objects.Operations RE_Protected_Entry_Caller, -- Protected_Objects.Operations RE_Timed_Protected_Entry_Call, -- Protected_Objects.Operations RE_Protection_Entry, -- Protected_Objects.Single_Entry RE_Initialize_Protection_Entry, -- Protected_Objects.Single_Entry RE_Lock_Entry, -- Protected_Objects.Single_Entry RE_Lock_Read_Only_Entry, -- Protected_Objects.Single_Entry RE_Unlock_Entry, -- Protected_Objects.Single_Entry RE_Protected_Single_Entry_Call, -- Protected_Objects.Single_Entry RE_Service_Entry, -- Protected_Objects.Single_Entry RE_Complete_Single_Entry_Body, -- Protected_Objects.Single_Entry RE_Exceptional_Complete_Single_Entry_Body, RE_Protected_Count_Entry, -- Protected_Objects.Single_Entry RE_Protected_Single_Entry_Caller, -- Protected_Objects.Single_Entry RE_Timed_Protected_Single_Entry_Call, RE_Protected_Entry_Index, -- System.Tasking.Protected_Objects RE_Entry_Body, -- System.Tasking.Protected_Objects RE_Protection, -- System.Tasking.Protected_Objects RE_Initialize_Protection, -- System.Tasking.Protected_Objects RE_Finalize_Protection, -- System.Tasking.Protected_Objects RE_Lock, -- System.Tasking.Protected_Objects RE_Lock_Read_Only, -- System.Tasking.Protected_Objects RE_Unlock, -- System.Tasking.Protected_Objects RE_Delay_Block, -- System.Tasking.Async_Delays RE_Timed_Out, -- System.Tasking.Async_Delays RE_Cancel_Async_Delay, -- System.Tasking.Async_Delays RE_Enqueue_Duration, -- System.Tasking.Async_Delays RE_Enqueue_Calendar, -- System.Tasking.Async_Delays RE_Enqueue_RT, -- System.Tasking.Async_Delays RE_Accept_Call, -- System.Tasking.Rendezvous RE_Accept_Trivial, -- System.Tasking.Rendezvous RE_Callable, -- System.Tasking.Rendezvous RE_Call_Simple, -- System.Tasking.Rendezvous RE_Requeue_Task_Entry, -- System.Tasking.Rendezvous RE_Requeue_Protected_To_Task_Entry, -- System.Tasking.Rendezvous RE_Cancel_Task_Entry_Call, -- System.Tasking.Rendezvous RE_Complete_Rendezvous, -- System.Tasking.Rendezvous RE_Task_Count, -- System.Tasking.Rendezvous RE_Exceptional_Complete_Rendezvous, -- System.Tasking.Rendezvous RE_Selective_Wait, -- System.Tasking.Rendezvous RE_Task_Entry_Call, -- System.Tasking.Rendezvous RE_Task_Entry_Caller, -- System.Tasking.Rendezvous RE_Timed_Task_Entry_Call, -- System.Tasking.Rendezvous RE_Timed_Selective_Wait, -- System.Tasking.Rendezvous RE_Activate_Restricted_Tasks, -- System.Tasking.Restricted.Stages RE_Complete_Restricted_Activation, -- System.Tasking.Restricted.Stages RE_Create_Restricted_Task, -- System.Tasking.Restricted.Stages RE_Complete_Restricted_Task, -- System.Tasking.Restricted.Stages RE_Restricted_Terminated, -- System.Tasking.Restricted.Stages RE_Abort_Tasks, -- System.Tasking.Stages RE_Activate_Tasks, -- System.Tasking.Stages RE_Complete_Activation, -- System.Tasking.Stages RE_Create_Task, -- System.Tasking.Stages RE_Complete_Task, -- System.Tasking.Stages RE_Free_Task, -- System.Tasking.Stages RE_Expunge_Unactivated_Tasks, -- System.Tasking.Stages RE_Terminated); -- System.Tasking.Stages -- The following declarations build a table that is indexed by the -- RTE function to determine the unit containing the given entity. -- This table is sorted in order of package names. RE_Unit_Table : array (RE_Id) of RTU_Id := ( RE_Null => RTU_Null, RE_Code_Loc => Ada_Exceptions, RE_Current_Target_Exception => Ada_Exceptions, -- of JGNAT RE_Exception_Id => Ada_Exceptions, RE_Exception_Information => Ada_Exceptions, RE_Exception_Message => Ada_Exceptions, RE_Exception_Name_Simple => Ada_Exceptions, RE_Exception_Occurrence => Ada_Exceptions, RE_Null_Id => Ada_Exceptions, RE_Null_Occurrence => Ada_Exceptions, RE_Poll => Ada_Exceptions, RE_Raise_Exception => Ada_Exceptions, RE_Raise_Exception_Always => Ada_Exceptions, RE_Reraise_Occurrence => Ada_Exceptions, RE_Reraise_Occurrence_Always => Ada_Exceptions, RE_Reraise_Occurrence_No_Defer => Ada_Exceptions, RE_Save_Occurrence => Ada_Exceptions, RE_Simple_List_Controller => Ada_Finalization_List_Controller, RE_List_Controller => Ada_Finalization_List_Controller, RE_Interrupt_Id => Ada_Interrupts, RE_Root_Stream_Type => Ada_Streams, RE_Stream_Element => Ada_Streams, RE_Stream_Element_Offset => Ada_Streams, RE_Stream_Element_Array => Ada_Streams, RE_Stream_Access => Ada_Streams_Stream_IO, RE_CW_Membership => Ada_Tags, RE_DT_Entry_Size => Ada_Tags, RE_DT_Prologue_Size => Ada_Tags, RE_External_Tag => Ada_Tags, RE_Get_Expanded_Name => Ada_Tags, RE_Get_External_Tag => Ada_Tags, RE_Get_Prim_Op_Address => Ada_Tags, RE_Get_RC_Offset => Ada_Tags, RE_Get_Remotely_Callable => Ada_Tags, RE_Get_TSD => Ada_Tags, RE_Inherit_DT => Ada_Tags, RE_Inherit_TSD => Ada_Tags, RE_Internal_Tag => Ada_Tags, RE_Register_Tag => Ada_Tags, RE_Set_Expanded_Name => Ada_Tags, RE_Set_External_Tag => Ada_Tags, RE_Set_Prim_Op_Address => Ada_Tags, RE_Set_RC_Offset => Ada_Tags, RE_Set_Remotely_Callable => Ada_Tags, RE_Set_TSD => Ada_Tags, RE_Tag_Error => Ada_Tags, RE_TSD_Entry_Size => Ada_Tags, RE_TSD_Prologue_Size => Ada_Tags, RE_Tag => Ada_Tags, RE_Address_Array => Ada_Tags, RE_Current_Task => Ada_Task_Identification, RO_AT_Task_ID => Ada_Task_Identification, RO_CA_Time => Ada_Calendar, RO_CA_Delay_For => Ada_Calendar_Delays, RO_CA_Delay_Until => Ada_Calendar_Delays, RO_CA_To_Duration => Ada_Calendar_Delays, RO_RT_Time => Ada_Real_Time, RO_RT_Delay_Until => Ada_Real_Time_Delays, RO_RT_To_Duration => Ada_Real_Time_Delays, RE_Integer_64 => Interfaces, RE_Unsigned_8 => Interfaces, RE_Unsigned_16 => Interfaces, RE_Unsigned_32 => Interfaces, RE_Unsigned_64 => Interfaces, RE_Vtable_Ptr => Interfaces_CPP, RE_Displaced_This => Interfaces_CPP, RE_CPP_CW_Membership => Interfaces_CPP, RE_CPP_DT_Entry_Size => Interfaces_CPP, RE_CPP_DT_Prologue_Size => Interfaces_CPP, RE_CPP_Get_Expanded_Name => Interfaces_CPP, RE_CPP_Get_External_Tag => Interfaces_CPP, RE_CPP_Get_Prim_Op_Address => Interfaces_CPP, RE_CPP_Get_RC_Offset => Interfaces_CPP, RE_CPP_Get_Remotely_Callable => Interfaces_CPP, RE_CPP_Get_TSD => Interfaces_CPP, RE_CPP_Inherit_DT => Interfaces_CPP, RE_CPP_Inherit_TSD => Interfaces_CPP, RE_CPP_Register_Tag => Interfaces_CPP, RE_CPP_Set_Expanded_Name => Interfaces_CPP, RE_CPP_Set_External_Tag => Interfaces_CPP, RE_CPP_Set_Prim_Op_Address => Interfaces_CPP, RE_CPP_Set_RC_Offset => Interfaces_CPP, RE_CPP_Set_Remotely_Callable => Interfaces_CPP, RE_CPP_Set_TSD => Interfaces_CPP, RE_CPP_TSD_Entry_Size => Interfaces_CPP, RE_CPP_TSD_Prologue_Size => Interfaces_CPP, RE_Packed_Size => Interfaces_Packed_Decimal, RE_Packed_To_Int32 => Interfaces_Packed_Decimal, RE_Packed_To_Int64 => Interfaces_Packed_Decimal, RE_Int32_To_Packed => Interfaces_Packed_Decimal, RE_Int64_To_Packed => Interfaces_Packed_Decimal, RE_Address => System, RE_Any_Priority => System, RE_Bit_Order => System, RE_Default_Priority => System, RE_High_Order_First => System, RE_Interrupt_Priority => System, RE_Lib_Stop => System, RE_Low_Order_First => System, RE_Max_Interrupt_Priority => System, RE_Max_Priority => System, RE_Null_Address => System, RE_Priority => System, RE_Add_With_Ovflo_Check => System_Arith_64, RE_Double_Divide => System_Arith_64, RE_Multiply_With_Ovflo_Check => System_Arith_64, RE_Scaled_Divide => System_Arith_64, RE_Subtract_With_Ovflo_Check => System_Arith_64, RE_Create_AST_Handler => System_AST_Handling, RE_Raise_Assert_Failure => System_Assertions, RE_AST_Handler => System_Aux_DEC, RE_Import_Value => System_Aux_DEC, RE_No_AST_Handler => System_Aux_DEC, RE_Type_Class => System_Aux_DEC, RE_Type_Class_Enumeration => System_Aux_DEC, RE_Type_Class_Integer => System_Aux_DEC, RE_Type_Class_Fixed_Point => System_Aux_DEC, RE_Type_Class_Floating_Point => System_Aux_DEC, RE_Type_Class_Array => System_Aux_DEC, RE_Type_Class_Record => System_Aux_DEC, RE_Type_Class_Access => System_Aux_DEC, RE_Type_Class_Task => System_Aux_DEC, RE_Type_Class_Address => System_Aux_DEC, RE_Bit_And => System_Bit_Ops, RE_Bit_Eq => System_Bit_Ops, RE_Bit_Not => System_Bit_Ops, RE_Bit_Or => System_Bit_Ops, RE_Bit_Xor => System_Bit_Ops, RE_Checked_Pool => System_Checked_Pools, RE_Register_Exception => System_Exception_Table, RE_All_Others_Id => System_Exceptions, RE_Handler_Record => System_Exceptions, RE_Handler_Record_Ptr => System_Exceptions, RE_Others_Id => System_Exceptions, RE_Subprogram_Descriptor => System_Exceptions, RE_Subprogram_Descriptor_0 => System_Exceptions, RE_Subprogram_Descriptor_1 => System_Exceptions, RE_Subprogram_Descriptor_2 => System_Exceptions, RE_Subprogram_Descriptor_3 => System_Exceptions, RE_Subprogram_Descriptor_List => System_Exceptions, RE_Subprogram_Descriptor_Ptr => System_Exceptions, RE_Subprogram_Descriptors_Record => System_Exceptions, RE_Subprogram_Descriptors_Ptr => System_Exceptions, RE_Exn_Float => System_Exn_Flt, RE_Exn_Integer => System_Exn_Int, RE_Exn_Long_Float => System_Exn_LFlt, RE_Exn_Long_Integer => System_Exn_LInt, RE_Exn_Long_Long_Float => System_Exn_LLF, RE_Exn_Long_Long_Integer => System_Exn_LLI, RE_Exn_Short_Float => System_Exn_SFlt, RE_Exn_Short_Integer => System_Exn_SInt, RE_Exn_Short_Short_Integer => System_Exn_SSI, RE_Exp_Float => System_Exp_Flt, RE_Exp_Integer => System_Exp_Int, RE_Exp_Long_Float => System_Exp_LFlt, RE_Exp_Long_Integer => System_Exp_LInt, RE_Exp_Long_Long_Float => System_Exp_LLF, RE_Exp_Long_Long_Integer => System_Exp_LLI, RE_Exp_Long_Long_Unsigned => System_Exp_LLU, RE_Exp_Modular => System_Exp_Mod, RE_Exp_Short_Float => System_Exp_SFlt, RE_Exp_Short_Integer => System_Exp_SInt, RE_Exp_Short_Short_Integer => System_Exp_SSI, RE_Exp_Unsigned => System_Exp_Uns, RE_Fat_Float => System_Fat_Flt, RE_Fat_Long_Float => System_Fat_LFlt, RE_Fat_Long_Long_Float => System_Fat_LLF, RE_Fat_Short_Float => System_Fat_SFlt, RE_Attach_To_Final_List => System_Finalization_Implementation, RE_Finalize_List => System_Finalization_Implementation, RE_Finalize_One => System_Finalization_Implementation, RE_Global_Final_List => System_Finalization_Implementation, RE_Record_Controller => System_Finalization_Implementation, RE_Limited_Record_Controller => System_Finalization_Implementation, RE_Deep_Tag_Initialize => System_Finalization_Implementation, RE_Deep_Tag_Adjust => System_Finalization_Implementation, RE_Deep_Tag_Finalize => System_Finalization_Implementation, RE_Deep_Tag_Attach => System_Finalization_Implementation, RE_Deep_Rec_Initialize => System_Finalization_Implementation, RE_Deep_Rec_Adjust => System_Finalization_Implementation, RE_Deep_Rec_Finalize => System_Finalization_Implementation, RE_Root_Controlled => System_Finalization_Root, RE_Finalizable => System_Finalization_Root, RE_Finalizable_Ptr => System_Finalization_Root, RE_Fore => System_Fore, RE_Image_Boolean => System_Img_Bool, RE_Image_Character => System_Img_Char, RE_Image_Decimal => System_Img_Dec, RE_Image_Enumeration_8 => System_Img_Enum, RE_Image_Enumeration_16 => System_Img_Enum, RE_Image_Enumeration_32 => System_Img_Enum, RE_Image_Integer => System_Img_Int, RE_Image_Long_Long_Decimal => System_Img_LLD, RE_Image_Long_Long_Integer => System_Img_LLI, RE_Image_Long_Long_Unsigned => System_Img_LLU, RE_Image_Ordinary_Fixed_Point => System_Img_Real, RE_Image_Floating_Point => System_Img_Real, RE_Image_Unsigned => System_Img_Uns, RE_Image_Wide_Character => System_Img_WChar, RE_Bind_Interrupt_To_Entry => System_Interrupts, RE_Default_Interrupt_Priority => System_Interrupts, RE_Dynamic_Interrupt_Protection => System_Interrupts, RE_Install_Handlers => System_Interrupts, RE_Register_Interrupt_Handler => System_Interrupts, RE_Static_Interrupt_Protection => System_Interrupts, RE_Asm_Insn => System_Machine_Code, RE_Asm_Input_Operand => System_Machine_Code, RE_Asm_Output_Operand => System_Machine_Code, RE_Mantissa_Value => System_Mantissa, RE_Bits_03 => System_Pack_03, RE_Get_03 => System_Pack_03, RE_Set_03 => System_Pack_03, RE_Bits_05 => System_Pack_05, RE_Get_05 => System_Pack_05, RE_Set_05 => System_Pack_05, RE_Bits_06 => System_Pack_06, RE_Get_06 => System_Pack_06, RE_GetU_06 => System_Pack_06, RE_Set_06 => System_Pack_06, RE_SetU_06 => System_Pack_06, RE_Bits_07 => System_Pack_07, RE_Get_07 => System_Pack_07, RE_Set_07 => System_Pack_07, RE_Bits_09 => System_Pack_09, RE_Get_09 => System_Pack_09, RE_Set_09 => System_Pack_09, RE_Bits_10 => System_Pack_10, RE_Get_10 => System_Pack_10, RE_GetU_10 => System_Pack_10, RE_Set_10 => System_Pack_10, RE_SetU_10 => System_Pack_10, RE_Bits_11 => System_Pack_11, RE_Get_11 => System_Pack_11, RE_Set_11 => System_Pack_11, RE_Bits_12 => System_Pack_12, RE_Get_12 => System_Pack_12, RE_GetU_12 => System_Pack_12, RE_Set_12 => System_Pack_12, RE_SetU_12 => System_Pack_12, RE_Bits_13 => System_Pack_13, RE_Get_13 => System_Pack_13, RE_Set_13 => System_Pack_13, RE_Bits_14 => System_Pack_14, RE_Get_14 => System_Pack_14, RE_GetU_14 => System_Pack_14, RE_Set_14 => System_Pack_14, RE_SetU_14 => System_Pack_14, RE_Bits_15 => System_Pack_15, RE_Get_15 => System_Pack_15, RE_Set_15 => System_Pack_15, RE_Bits_17 => System_Pack_17, RE_Get_17 => System_Pack_17, RE_Set_17 => System_Pack_17, RE_Bits_18 => System_Pack_18, RE_Get_18 => System_Pack_18, RE_GetU_18 => System_Pack_18, RE_Set_18 => System_Pack_18, RE_SetU_18 => System_Pack_18, RE_Bits_19 => System_Pack_19, RE_Get_19 => System_Pack_19, RE_Set_19 => System_Pack_19, RE_Bits_20 => System_Pack_20, RE_Get_20 => System_Pack_20, RE_GetU_20 => System_Pack_20, RE_Set_20 => System_Pack_20, RE_SetU_20 => System_Pack_20, RE_Bits_21 => System_Pack_21, RE_Get_21 => System_Pack_21, RE_Set_21 => System_Pack_21, RE_Bits_22 => System_Pack_22, RE_Get_22 => System_Pack_22, RE_GetU_22 => System_Pack_22, RE_Set_22 => System_Pack_22, RE_SetU_22 => System_Pack_22, RE_Bits_23 => System_Pack_23, RE_Get_23 => System_Pack_23, RE_Set_23 => System_Pack_23, RE_Bits_24 => System_Pack_24, RE_Get_24 => System_Pack_24, RE_GetU_24 => System_Pack_24, RE_Set_24 => System_Pack_24, RE_SetU_24 => System_Pack_24, RE_Bits_25 => System_Pack_25, RE_Get_25 => System_Pack_25, RE_Set_25 => System_Pack_25, RE_Bits_26 => System_Pack_26, RE_Get_26 => System_Pack_26, RE_GetU_26 => System_Pack_26, RE_Set_26 => System_Pack_26, RE_SetU_26 => System_Pack_26, RE_Bits_27 => System_Pack_27, RE_Get_27 => System_Pack_27, RE_Set_27 => System_Pack_27, RE_Bits_28 => System_Pack_28, RE_Get_28 => System_Pack_28, RE_GetU_28 => System_Pack_28, RE_Set_28 => System_Pack_28, RE_SetU_28 => System_Pack_28, RE_Bits_29 => System_Pack_29, RE_Get_29 => System_Pack_29, RE_Set_29 => System_Pack_29, RE_Bits_30 => System_Pack_30, RE_Get_30 => System_Pack_30, RE_GetU_30 => System_Pack_30, RE_Set_30 => System_Pack_30, RE_SetU_30 => System_Pack_30, RE_Bits_31 => System_Pack_31, RE_Get_31 => System_Pack_31, RE_Set_31 => System_Pack_31, RE_Bits_33 => System_Pack_33, RE_Get_33 => System_Pack_33, RE_Set_33 => System_Pack_33, RE_Bits_34 => System_Pack_34, RE_Get_34 => System_Pack_34, RE_GetU_34 => System_Pack_34, RE_Set_34 => System_Pack_34, RE_SetU_34 => System_Pack_34, RE_Bits_35 => System_Pack_35, RE_Get_35 => System_Pack_35, RE_Set_35 => System_Pack_35, RE_Bits_36 => System_Pack_36, RE_Get_36 => System_Pack_36, RE_GetU_36 => System_Pack_36, RE_Set_36 => System_Pack_36, RE_SetU_36 => System_Pack_36, RE_Bits_37 => System_Pack_37, RE_Get_37 => System_Pack_37, RE_Set_37 => System_Pack_37, RE_Bits_38 => System_Pack_38, RE_Get_38 => System_Pack_38, RE_GetU_38 => System_Pack_38, RE_Set_38 => System_Pack_38, RE_SetU_38 => System_Pack_38, RE_Bits_39 => System_Pack_39, RE_Get_39 => System_Pack_39, RE_Set_39 => System_Pack_39, RE_Bits_40 => System_Pack_40, RE_Get_40 => System_Pack_40, RE_GetU_40 => System_Pack_40, RE_Set_40 => System_Pack_40, RE_SetU_40 => System_Pack_40, RE_Bits_41 => System_Pack_41, RE_Get_41 => System_Pack_41, RE_Set_41 => System_Pack_41, RE_Bits_42 => System_Pack_42, RE_Get_42 => System_Pack_42, RE_GetU_42 => System_Pack_42, RE_Set_42 => System_Pack_42, RE_SetU_42 => System_Pack_42, RE_Bits_43 => System_Pack_43, RE_Get_43 => System_Pack_43, RE_Set_43 => System_Pack_43, RE_Bits_44 => System_Pack_44, RE_Get_44 => System_Pack_44, RE_GetU_44 => System_Pack_44, RE_Set_44 => System_Pack_44, RE_SetU_44 => System_Pack_44, RE_Bits_45 => System_Pack_45, RE_Get_45 => System_Pack_45, RE_Set_45 => System_Pack_45, RE_Bits_46 => System_Pack_46, RE_Get_46 => System_Pack_46, RE_GetU_46 => System_Pack_46, RE_Set_46 => System_Pack_46, RE_SetU_46 => System_Pack_46, RE_Bits_47 => System_Pack_47, RE_Get_47 => System_Pack_47, RE_Set_47 => System_Pack_47, RE_Bits_48 => System_Pack_48, RE_Get_48 => System_Pack_48, RE_GetU_48 => System_Pack_48, RE_Set_48 => System_Pack_48, RE_SetU_48 => System_Pack_48, RE_Bits_49 => System_Pack_49, RE_Get_49 => System_Pack_49, RE_Set_49 => System_Pack_49, RE_Bits_50 => System_Pack_50, RE_Get_50 => System_Pack_50, RE_GetU_50 => System_Pack_50, RE_Set_50 => System_Pack_50, RE_SetU_50 => System_Pack_50, RE_Bits_51 => System_Pack_51, RE_Get_51 => System_Pack_51, RE_Set_51 => System_Pack_51, RE_Bits_52 => System_Pack_52, RE_Get_52 => System_Pack_52, RE_GetU_52 => System_Pack_52, RE_Set_52 => System_Pack_52, RE_SetU_52 => System_Pack_52, RE_Bits_53 => System_Pack_53, RE_Get_53 => System_Pack_53, RE_Set_53 => System_Pack_53, RE_Bits_54 => System_Pack_54, RE_Get_54 => System_Pack_54, RE_GetU_54 => System_Pack_54, RE_Set_54 => System_Pack_54, RE_SetU_54 => System_Pack_54, RE_Bits_55 => System_Pack_55, RE_Get_55 => System_Pack_55, RE_Set_55 => System_Pack_55, RE_Bits_56 => System_Pack_56, RE_Get_56 => System_Pack_56, RE_GetU_56 => System_Pack_56, RE_Set_56 => System_Pack_56, RE_SetU_56 => System_Pack_56, RE_Bits_57 => System_Pack_57, RE_Get_57 => System_Pack_57, RE_Set_57 => System_Pack_57, RE_Bits_58 => System_Pack_58, RE_Get_58 => System_Pack_58, RE_GetU_58 => System_Pack_58, RE_Set_58 => System_Pack_58, RE_SetU_58 => System_Pack_58, RE_Bits_59 => System_Pack_59, RE_Get_59 => System_Pack_59, RE_Set_59 => System_Pack_59, RE_Bits_60 => System_Pack_60, RE_Get_60 => System_Pack_60, RE_GetU_60 => System_Pack_60, RE_Set_60 => System_Pack_60, RE_SetU_60 => System_Pack_60, RE_Bits_61 => System_Pack_61, RE_Get_61 => System_Pack_61, RE_Set_61 => System_Pack_61, RE_Bits_62 => System_Pack_62, RE_Get_62 => System_Pack_62, RE_GetU_62 => System_Pack_62, RE_Set_62 => System_Pack_62, RE_SetU_62 => System_Pack_62, RE_Bits_63 => System_Pack_63, RE_Get_63 => System_Pack_63, RE_Set_63 => System_Pack_63, RE_Adjust_Storage_Size => System_Parameters, RE_Default_Stack_Size => System_Parameters, RE_Garbage_Collected => System_Parameters, RE_Size_Type => System_Parameters, RE_Unspecified_Size => System_Parameters, RE_Get_Active_Partition_Id => System_Partition_Interface, RE_Get_Passive_Partition_Id => System_Partition_Interface, RE_Get_Local_Partition_Id => System_Partition_Interface, RE_Get_RCI_Package_Receiver => System_Partition_Interface, RE_Get_Unique_Remote_Pointer => System_Partition_Interface, RE_RACW_Stub_Type => System_Partition_Interface, RE_RACW_Stub_Type_Access => System_Partition_Interface, RE_Raise_Program_Error_For_E_4_18 => System_Partition_Interface, RE_Raise_Program_Error_Unknown_Tag => System_Partition_Interface, RE_Register_Passive_Package => System_Partition_Interface, RE_Register_Receiving_Stub => System_Partition_Interface, RE_RCI_Info => System_Partition_Interface, RE_Subprogram_Id => System_Partition_Interface, RE_Global_Pool_Object => System_Pool_Global, RE_Unbounded_Reclaim_Pool => System_Pool_Local, RE_Stack_Bounded_Pool => System_Pool_Size, RE_Do_Apc => System_RPC, RE_Do_Rpc => System_RPC, RE_Params_Stream_Type => System_RPC, RE_Partition_ID => System_RPC, RE_RPC_Receiver => System_RPC, RE_IS_Is1 => System_Scalar_Values, RE_IS_Is2 => System_Scalar_Values, RE_IS_Is4 => System_Scalar_Values, RE_IS_Is8 => System_Scalar_Values, RE_IS_Iu1 => System_Scalar_Values, RE_IS_Iu2 => System_Scalar_Values, RE_IS_Iu4 => System_Scalar_Values, RE_IS_Iu8 => System_Scalar_Values, RE_IS_Isf => System_Scalar_Values, RE_IS_Ifl => System_Scalar_Values, RE_IS_Ilf => System_Scalar_Values, RE_IS_Ill => System_Scalar_Values, RE_Mark_Id => System_Secondary_Stack, RE_SS_Allocate => System_Secondary_Stack, RE_SS_Mark => System_Secondary_Stack, RE_SS_Pool => System_Secondary_Stack, RE_SS_Release => System_Secondary_Stack, RE_Shared_Var_Close => System_Shared_Storage, RE_Shared_Var_Lock => System_Shared_Storage, RE_Shared_Var_ROpen => System_Shared_Storage, RE_Shared_Var_Unlock => System_Shared_Storage, RE_Shared_Var_WOpen => System_Shared_Storage, RE_Abort_Undefer_Direct => System_Standard_Library, RE_Exception_Data_Ptr => System_Standard_Library, RE_Integer_Address => System_Storage_Elements, RE_Storage_Offset => System_Storage_Elements, RE_Storage_Array => System_Storage_Elements, RE_To_Address => System_Storage_Elements, RE_Root_Storage_Pool => System_Storage_Pools, RE_Thin_Pointer => System_Stream_Attributes, RE_Fat_Pointer => System_Stream_Attributes, RE_I_AD => System_Stream_Attributes, RE_I_AS => System_Stream_Attributes, RE_I_B => System_Stream_Attributes, RE_I_C => System_Stream_Attributes, RE_I_F => System_Stream_Attributes, RE_I_I => System_Stream_Attributes, RE_I_LF => System_Stream_Attributes, RE_I_LI => System_Stream_Attributes, RE_I_LLF => System_Stream_Attributes, RE_I_LLI => System_Stream_Attributes, RE_I_LLU => System_Stream_Attributes, RE_I_LU => System_Stream_Attributes, RE_I_SF => System_Stream_Attributes, RE_I_SI => System_Stream_Attributes, RE_I_SSI => System_Stream_Attributes, RE_I_SSU => System_Stream_Attributes, RE_I_SU => System_Stream_Attributes, RE_I_U => System_Stream_Attributes, RE_I_WC => System_Stream_Attributes, RE_W_AD => System_Stream_Attributes, RE_W_AS => System_Stream_Attributes, RE_W_B => System_Stream_Attributes, RE_W_C => System_Stream_Attributes, RE_W_F => System_Stream_Attributes, RE_W_I => System_Stream_Attributes, RE_W_LF => System_Stream_Attributes, RE_W_LI => System_Stream_Attributes, RE_W_LLF => System_Stream_Attributes, RE_W_LLI => System_Stream_Attributes, RE_W_LLU => System_Stream_Attributes, RE_W_LU => System_Stream_Attributes, RE_W_SF => System_Stream_Attributes, RE_W_SI => System_Stream_Attributes, RE_W_SSI => System_Stream_Attributes, RE_W_SSU => System_Stream_Attributes, RE_W_SU => System_Stream_Attributes, RE_W_U => System_Stream_Attributes, RE_W_WC => System_Stream_Attributes, RE_Str_Concat => System_String_Ops, RE_Str_Equal => System_String_Ops, RE_Str_Normalize => System_String_Ops, RE_Wide_Str_Normalize => System_String_Ops, RE_Str_Concat_CC => System_String_Ops, RE_Str_Concat_CS => System_String_Ops, RE_Str_Concat_SC => System_String_Ops, RE_Str_Concat_3 => System_String_Ops_Concat_3, RE_Str_Concat_4 => System_String_Ops_Concat_4, RE_Str_Concat_5 => System_String_Ops_Concat_5, RE_Free_Task_Image => System_Task_Info, RE_Task_Info_Type => System_Task_Info, RE_Task_Image_Type => System_Task_Info, RE_Unspecified_Task_Info => System_Task_Info, RE_Library_Task_Level => System_Tasking, RE_Task_Procedure_Access => System_Tasking, RO_ST_Task_ID => System_Tasking, RE_Call_Modes => System_Tasking, RE_Simple_Call => System_Tasking, RE_Conditional_Call => System_Tasking, RE_Asynchronous_Call => System_Tasking, RE_Timed_Call => System_Tasking, RE_Task_List => System_Tasking, RE_Accept_Alternative => System_Tasking, RE_Accept_List => System_Tasking, RE_Accept_List_Access => System_Tasking, RE_Max_Select => System_Tasking, RE_Max_Task_Entry => System_Tasking, RE_No_Rendezvous => System_Tasking, RE_Null_Task_Entry => System_Tasking, RE_Positive_Select_Index => System_Tasking, RE_Select_Index => System_Tasking, RE_Select_Modes => System_Tasking, RE_Else_Mode => System_Tasking, RE_Simple_Mode => System_Tasking, RE_Terminate_Mode => System_Tasking, RE_Delay_Mode => System_Tasking, RE_Task_Entry_Index => System_Tasking, RE_Self => System_Tasking, RE_Master_Id => System_Tasking, RE_Unspecified_Priority => System_Tasking, RE_Activation_Chain => System_Tasking, RE_Abort_Defer => System_Soft_Links, RE_Abort_Undefer => System_Soft_Links, RE_Complete_Master => System_Soft_Links, RE_Current_Master => System_Soft_Links, RE_Enter_Master => System_Soft_Links, RE_Get_Current_Excep => System_Soft_Links, RE_Get_GNAT_Exception => System_Soft_Links, RE_Update_Exception => System_Soft_Links, RE_Bits_1 => System_Unsigned_Types, RE_Bits_2 => System_Unsigned_Types, RE_Bits_4 => System_Unsigned_Types, RE_Float_Unsigned => System_Unsigned_Types, RE_Long_Long_Unsigned => System_Unsigned_Types, RE_Packed_Byte => System_Unsigned_Types, RE_Packed_Bytes1 => System_Unsigned_Types, RE_Packed_Bytes2 => System_Unsigned_Types, RE_Packed_Bytes4 => System_Unsigned_Types, RE_Unsigned => System_Unsigned_Types, RE_Value_Boolean => System_Val_Bool, RE_Value_Character => System_Val_Char, RE_Value_Decimal => System_Val_Dec, RE_Value_Enumeration_8 => System_Val_Enum, RE_Value_Enumeration_16 => System_Val_Enum, RE_Value_Enumeration_32 => System_Val_Enum, RE_Value_Integer => System_Val_Int, RE_Value_Long_Long_Decimal => System_Val_LLD, RE_Value_Long_Long_Integer => System_Val_LLI, RE_Value_Long_Long_Unsigned => System_Val_LLU, RE_Value_Real => System_Val_Real, RE_Value_Unsigned => System_Val_Uns, RE_Value_Wide_Character => System_Val_WChar, RE_D => System_Vax_Float_Operations, RE_F => System_Vax_Float_Operations, RE_G => System_Vax_Float_Operations, RE_Q => System_Vax_Float_Operations, RE_S => System_Vax_Float_Operations, RE_T => System_Vax_Float_Operations, RE_D_To_G => System_Vax_Float_Operations, RE_F_To_G => System_Vax_Float_Operations, RE_F_To_Q => System_Vax_Float_Operations, RE_F_To_S => System_Vax_Float_Operations, RE_G_To_D => System_Vax_Float_Operations, RE_G_To_F => System_Vax_Float_Operations, RE_G_To_Q => System_Vax_Float_Operations, RE_G_To_T => System_Vax_Float_Operations, RE_Q_To_F => System_Vax_Float_Operations, RE_Q_To_G => System_Vax_Float_Operations, RE_S_To_F => System_Vax_Float_Operations, RE_T_To_D => System_Vax_Float_Operations, RE_T_To_G => System_Vax_Float_Operations, RE_Abs_F => System_Vax_Float_Operations, RE_Abs_G => System_Vax_Float_Operations, RE_Add_F => System_Vax_Float_Operations, RE_Add_G => System_Vax_Float_Operations, RE_Div_F => System_Vax_Float_Operations, RE_Div_G => System_Vax_Float_Operations, RE_Mul_F => System_Vax_Float_Operations, RE_Mul_G => System_Vax_Float_Operations, RE_Neg_F => System_Vax_Float_Operations, RE_Neg_G => System_Vax_Float_Operations, RE_Sub_F => System_Vax_Float_Operations, RE_Sub_G => System_Vax_Float_Operations, RE_Eq_F => System_Vax_Float_Operations, RE_Eq_G => System_Vax_Float_Operations, RE_Le_F => System_Vax_Float_Operations, RE_Le_G => System_Vax_Float_Operations, RE_Lt_F => System_Vax_Float_Operations, RE_Lt_G => System_Vax_Float_Operations, RE_Version_String => System_Version_Control, RE_Get_Version_String => System_Version_Control, RE_Register_VMS_Exception => System_VMS_Exception_Table, RE_String_To_Wide_String => System_WCh_StW, RE_Wide_String_To_String => System_WCh_WtS, RE_Wide_Width_Character => System_WWd_Char, RE_Wide_Width_Enumeration_8 => System_WWd_Enum, RE_Wide_Width_Enumeration_16 => System_WWd_Enum, RE_Wide_Width_Enumeration_32 => System_WWd_Enum, RE_Wide_Width_Wide_Character => System_WWd_Wchar, RE_Width_Boolean => System_Wid_Bool, RE_Width_Character => System_Wid_Char, RE_Width_Enumeration_8 => System_Wid_Enum, RE_Width_Enumeration_16 => System_Wid_Enum, RE_Width_Enumeration_32 => System_Wid_Enum, RE_Width_Long_Long_Integer => System_Wid_LLI, RE_Width_Long_Long_Unsigned => System_Wid_LLU, RE_Width_Wide_Character => System_Wid_WChar, RE_Protected_Entry_Body_Array => System_Tasking_Protected_Objects_Entries, RE_Protection_Entries => System_Tasking_Protected_Objects_Entries, RE_Initialize_Protection_Entries => System_Tasking_Protected_Objects_Entries, RE_Lock_Entries => System_Tasking_Protected_Objects_Entries, RE_Lock_Read_Only_Entries => System_Tasking_Protected_Objects_Entries, RE_Unlock_Entries => System_Tasking_Protected_Objects_Entries, RE_Communication_Block => System_Tasking_Protected_Objects_Operations, RE_Protected_Entry_Call => System_Tasking_Protected_Objects_Operations, RE_Service_Entries => System_Tasking_Protected_Objects_Operations, RE_Cancel_Protected_Entry_Call => System_Tasking_Protected_Objects_Operations, RE_Enqueued => System_Tasking_Protected_Objects_Operations, RE_Cancelled => System_Tasking_Protected_Objects_Operations, RE_Complete_Entry_Body => System_Tasking_Protected_Objects_Operations, RE_Exceptional_Complete_Entry_Body => System_Tasking_Protected_Objects_Operations, RE_Requeue_Protected_Entry => System_Tasking_Protected_Objects_Operations, RE_Requeue_Task_To_Protected_Entry => System_Tasking_Protected_Objects_Operations, RE_Protected_Count => System_Tasking_Protected_Objects_Operations, RE_Protected_Entry_Caller => System_Tasking_Protected_Objects_Operations, RE_Timed_Protected_Entry_Call => System_Tasking_Protected_Objects_Operations, RE_Protection_Entry => System_Tasking_Protected_Objects_Single_Entry, RE_Initialize_Protection_Entry => System_Tasking_Protected_Objects_Single_Entry, RE_Lock_Entry => System_Tasking_Protected_Objects_Single_Entry, RE_Lock_Read_Only_Entry => System_Tasking_Protected_Objects_Single_Entry, RE_Unlock_Entry => System_Tasking_Protected_Objects_Single_Entry, RE_Protected_Single_Entry_Call => System_Tasking_Protected_Objects_Single_Entry, RE_Service_Entry => System_Tasking_Protected_Objects_Single_Entry, RE_Complete_Single_Entry_Body => System_Tasking_Protected_Objects_Single_Entry, RE_Exceptional_Complete_Single_Entry_Body => System_Tasking_Protected_Objects_Single_Entry, RE_Protected_Count_Entry => System_Tasking_Protected_Objects_Single_Entry, RE_Protected_Single_Entry_Caller => System_Tasking_Protected_Objects_Single_Entry, RE_Timed_Protected_Single_Entry_Call => System_Tasking_Protected_Objects_Single_Entry, RE_Protected_Entry_Index => System_Tasking_Protected_Objects, RE_Entry_Body => System_Tasking_Protected_Objects, RE_Protection => System_Tasking_Protected_Objects, RE_Initialize_Protection => System_Tasking_Protected_Objects, RE_Finalize_Protection => System_Tasking_Protected_Objects, RE_Lock => System_Tasking_Protected_Objects, RE_Lock_Read_Only => System_Tasking_Protected_Objects, RE_Unlock => System_Tasking_Protected_Objects, RE_Delay_Block => System_Tasking_Async_Delays, RE_Timed_Out => System_Tasking_Async_Delays, RE_Cancel_Async_Delay => System_Tasking_Async_Delays, RE_Enqueue_Duration => System_Tasking_Async_Delays, RE_Enqueue_Calendar => System_Tasking_Async_Delays_Enqueue_Calendar, RE_Enqueue_RT => System_Tasking_Async_Delays_Enqueue_RT, RE_Accept_Call => System_Tasking_Rendezvous, RE_Accept_Trivial => System_Tasking_Rendezvous, RE_Callable => System_Tasking_Rendezvous, RE_Call_Simple => System_Tasking_Rendezvous, RE_Cancel_Task_Entry_Call => System_Tasking_Rendezvous, RE_Requeue_Task_Entry => System_Tasking_Rendezvous, RE_Requeue_Protected_To_Task_Entry => System_Tasking_Rendezvous, RE_Complete_Rendezvous => System_Tasking_Rendezvous, RE_Task_Count => System_Tasking_Rendezvous, RE_Exceptional_Complete_Rendezvous => System_Tasking_Rendezvous, RE_Selective_Wait => System_Tasking_Rendezvous, RE_Task_Entry_Call => System_Tasking_Rendezvous, RE_Task_Entry_Caller => System_Tasking_Rendezvous, RE_Timed_Task_Entry_Call => System_Tasking_Rendezvous, RE_Timed_Selective_Wait => System_Tasking_Rendezvous, RE_Activate_Restricted_Tasks => System_Tasking_Restricted_Stages, RE_Complete_Restricted_Activation => System_Tasking_Restricted_Stages, RE_Create_Restricted_Task => System_Tasking_Restricted_Stages, RE_Complete_Restricted_Task => System_Tasking_Restricted_Stages, RE_Restricted_Terminated => System_Tasking_Restricted_Stages, RE_Abort_Tasks => System_Tasking_Stages, RE_Activate_Tasks => System_Tasking_Stages, RE_Complete_Activation => System_Tasking_Stages, RE_Create_Task => System_Tasking_Stages, RE_Complete_Task => System_Tasking_Stages, RE_Free_Task => System_Tasking_Stages, RE_Expunge_Unactivated_Tasks => System_Tasking_Stages, RE_Terminated => System_Tasking_Stages); ----------------- -- Subprograms -- ----------------- procedure Initialize; -- Procedure to initialize data structures used by RTE. Called at the -- start of processing a new main source file. Must be called after -- Initialize_Snames (since names it enters into name table must come -- after names entered by Snames). function RTE (E : RE_Id) return Entity_Id; -- Given the entity defined in the above tables, as identified by the -- corresponding value in the RE_Id enumeration type, returns the Id -- of the corresponding entity, first loading in (parsing, analyzing and -- expanding) its spec if the unit has not already been loaded. If the -- unit cannot be found, or if it does not contain the specified entity, -- then an appropriate error message is output ("run-time configuration -- error") and an Unrecoverable_Error exception is raised. There is one -- situation in which RTE can generate an error message, and that is if -- an unuathorized entity is accessed in high integrity mode. If this -- occurs, the result returned may be Empty, and the caller must deal -- with this possibility if the call to RTE may occur in high integrity -- mode (often this will have been ruled out by specific checks for -- high integrity mode prior to the RTE call). function Is_RTE (Ent : Entity_Id; E : RE_Id) return Boolean; -- This function determines if the given entity corresponds to the entity -- referenced by RE_Id. It is similar in effect to (Ent = RTE (E)) except -- that the latter would unconditionally load the unit containing E. For -- this call, if the unit is not loaded, then a result of False is returned -- immediately, since obviously Ent cannot be the entity in question if the -- corresponding unit has not been loaded. procedure Text_IO_Kludge (Nam : Node_Id); -- In Ada 83, and hence for compatibility in Ada 9X, package Text_IO has -- generic subpackages (e.g. Integer_IO). They really should be child -- packages, and in GNAT, they *are* child packages. To maintain the -- required compatibility, this routine is called for package renamings -- and generic instantiations, with the simple name of the referenced -- package. If Text_IO has been with'ed and if the simple name of Nam -- matches one of the subpackages of Text_IO, then this subpackage is -- with'ed automatically. The important result of this approach is that -- Text_IO does not drag in all the code for the subpackages unless they -- are used. Our test is a little crude, and could drag in stuff when it -- is not necessary, but that doesn't matter. Wide_Text_IO is handled in -- a similar manner. function Is_Text_IO_Kludge_Unit (Nam : Node_Id) return Boolean; -- Returns True if the given Nam is an Expanded Name, whose Prefix is -- Ada, and whose selector is either Text_IO.xxx or Wide_Text_IO.xxx -- where xxx is one of the subpackages of Text_IO that is specially -- handled as described above for Text_IO_Kludge. end Rtsfind;
with Ada.Text_IO; with Ada.Long_Integer_Text_IO; with Ada.Numerics.Long_Elementary_Functions; -- Copyright 2021 Melwyn Francis Carlo procedure A003 is use Ada.Text_IO; use Ada.Long_Integer_Text_IO; use Ada.Numerics.Long_Elementary_Functions; -- File Reference: http://www.naturalnumbers.org/primes.html FT : File_Type; Last_Index : Natural; Prime_Num : String (1 .. 10); Prime_Num_Max : Long_Integer; Prime_Num_Largest : Long_Integer; N : constant Long_Integer := 600851475143; File_Name : constant String := "problems/003/PrimeNumbers_Upto_1000000"; begin Prime_Num_Max := Long_Integer (Sqrt (Long_Float (N))); Prime_Num_Largest := N; Open (FT, In_File, File_Name); while not End_Of_File (FT) loop Get_Line (FT, Prime_Num, Last_Index); exit when Long_Integer'Value (Prime_Num (1 .. Last_Index)) > Prime_Num_Max; if (N mod Long_Integer'Value (Prime_Num (1 .. Last_Index))) = 0 then Prime_Num_Largest := Long_Integer'Value (Prime_Num (1 .. Last_Index)); end if; end loop; Close (FT); Put (Prime_Num_Largest, Width => 0); end A003;
-- Minimal Example to produce "integer literal expected" error in Dimension Aspect -- -- Steps to reproduce: -- * Dimension_System is applied on Integer type -- * subtype Dimension is set to a negative integer literal -- -- Wrong Behavior: -1 is a valid integer literal, however, compiler complains it is not -- -- Additional Note: The Dimension System requires at least 2 dimensions. -- The reference manual states that only one is required. procedure Dimension_Test is type Unit_Type is new Float with Dimension_System => ( (Unit_Name => Meter, Unit_Symbol => 'm', Dim_Symbol => 'L'), (Unit_Name => Kilogram, Unit_Symbol => "kg", Dim_Symbol => 'M') ); -- positive dimension works subtype Length_Type is Unit_Type with Dimension => (Symbol => 'm', Meter => 1, Kilogram => 0); A : constant Integer := 1; -- negative dimension fails with Error "integer literal expected" subtype Inverse_Length_Type is Unit_Type with Dimension => (Symbol => 'n', Meter => 1, Kilogram => 0); begin null; end Dimension_Test;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2021, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ package LPS25H is type LPS25H_Barometric_Sensor is abstract tagged limited private; procedure Initialize (This : in out LPS25H_Barometric_Sensor) is abstract; subtype Pressure is Float range 450.0 .. 1100.0; -- in mBar subtype Temperature is Float range -20.0 .. 80.0; -- in degrees Celsius subtype Altitude is Float range -8000.0 .. 8000.0; -- Metres above sea level function Is_Initialized (This : LPS25H_Barometric_Sensor) return Boolean; procedure Get_Data (This : in out LPS25H_Barometric_Sensor; Press : out Pressure; Temp : out Temperature; Asl : out Altitude; Status : out Boolean) is abstract with Pre'Class => Is_Initialized (This); private type LPS25H_Barometric_Sensor is abstract tagged limited record Initialized : Boolean := False; end record; function Is_Initialized (This : LPS25H_Barometric_Sensor) return Boolean is (This.Initialized); -- These register addresses are copied from the Crazyflie lps25h.h. REF_P_XL : constant := 16#08#; REF_P_L : constant := 16#09#; REF_P_H : constant := 16#0A#; WHO_AM_I : constant := 16#0F#; RES_CONF : constant := 16#10#; CTRL_REG1 : constant := 16#20#; CTRL_REG2 : constant := 16#21#; CTRL_REG3 : constant := 16#22#; CTRL_REG4 : constant := 16#23#; INTERRUPT_CFG : constant := 16#24#; INT_SOURCE : constant := 16#25#; STATUS_REG : constant := 16#27#; PRESS_OUT_XL : constant := 16#28#; PRESS_OUT_L : constant := 16#29#; PRESS_OUT_H : constant := 16#2A#; TEMP_OUT_L : constant := 16#2B#; TEMP_OUT_H : constant := 16#2C#; FIFO_CTRL : constant := 16#2E#; FIFO_STATUS : constant := 16#2F#; THS_P_L : constant := 16#30#; THS_P_H : constant := 16#31#; RPDS_L : constant := 16#39#; RPDS_H : constant := 16#3A#; -- The expected response to a WHO_AM_I request WAI_ID : constant := 16#BD#; type Bit is range 0 .. 1 with Size => 1; type Zero_Bit is range 0 .. 0 with Size => 1; type Zero_Bits is array (Natural range <>) of Zero_Bit with Component_Size => 1; -- Pressure and temperature internal average configuration type Pressure_Resolution_Configuration is (Avg_8, Avg_32, Avg_128, Avg_512) with Size => 2; for Pressure_Resolution_Configuration use (Avg_8 => 0, Avg_32 => 1, Avg_128 => 2, Avg_512 => 3); type Temp_Resolution_Configuration is (Avg_8, Avg_16, Avg_32, Avg_64) with Size => 2; for Temp_Resolution_Configuration use (Avg_8 => 0, Avg_16 => 1, Avg_32 => 2, Avg_64 => 3); type Res_Conf_Register is record AVGP : Pressure_Resolution_Configuration := Avg_8; AVGT : Temp_Resolution_Configuration := Avg_8; Reserved : Zero_Bits (4 .. 7) := (others => 0); end record with Size => 8; for Res_Conf_Register use record AVGP at 0 range 0 .. 1; AVGT at 0 range 2 .. 3; Reserved at 0 range 4 .. 7; end record; -- Control register 1 type Output_Data_Rate is (One_Shot, Hz_1, Hz_7, Hz_12p5, Hz_25) with Size => 3; for Output_Data_Rate use (One_Shot => 0, Hz_1 => 1, Hz_7 => 2, Hz_12p5 => 3, Hz_25 => 4); type Ctrl_Reg1_Register is record SIM : Bit := 0; RESET_AZ : Bit := 0; BDU : Bit := 0; DIFF_EN : Bit := 0; ODR : Output_Data_Rate := One_Shot; PD : Bit := 0; end record with Size => 8; for Ctrl_Reg1_Register use record SIM at 0 range 0 .. 0; RESET_AZ at 0 range 1 .. 1; BDU at 0 range 2 .. 2; DIFF_EN at 0 range 3 .. 3; ODR at 0 range 4 .. 6; PD at 0 range 7 .. 7; end record; -- Control register 2 type Ctrl_Reg2_Register is record ONE_SHOT : Bit := 0; AUTO_ZERO : Bit := 0; SWRESET : Bit := 0; I2C_ENABLE : Bit := 0; -- ? FIFO_MEAN_DEC : Bit := 0; WTM_EN : Bit := 0; FIFO_EN : Bit := 0; BOOT : Bit := 0; end record with Size => 8; for Ctrl_Reg2_Register use record ONE_SHOT at 0 range 0 .. 0; AUTO_ZERO at 0 range 1 .. 1; SWRESET at 0 range 2 .. 2; I2C_ENABLE at 0 range 3 .. 3; FIFO_MEAN_DEC at 0 range 4 .. 4; WTM_EN at 0 range 5 .. 5; FIFO_EN at 0 range 6 .. 6; BOOT at 0 range 7 .. 7; end record; -- Control register 3 type Interrupt_Configuration is (Data_Signal, Pressure_High, Pressure_Low, Pressure_Low_Or_High) with Size => 2; for Interrupt_Configuration use (Data_Signal => 0, Pressure_High => 1, Pressure_Low => 2, Pressure_Low_Or_High => 3); type Ctrl_Reg3_Register is record INT1 : Interrupt_Configuration := Data_Signal; Reserved : Zero_Bits (2 .. 5) := (others => 0); PP_OD : Bit := 0; Int_H_L : Bit := 0; end record with Size => 8; for Ctrl_Reg3_Register use record INT1 at 0 range 0 .. 1; Reserved at 0 range 2 .. 5; PP_OD at 0 range 6 .. 6; Int_H_L at 0 range 7 .. 7; end record; -- Control register 4 type Ctrl_Reg4_Register is record P1_DRDY : Bit := 0; P1_OVERRUN : Bit := 0; P1_WTM : Bit := 0; P1_EMPTY : Bit := 0; Reserved : Zero_Bits (4 .. 7) := (others => 0); end record with Size => 8; for Ctrl_Reg4_Register use record P1_DRDY at 0 range 0 .. 0; P1_OVERRUN at 0 range 1 .. 1; P1_WTM at 0 range 2 .. 2; P1_EMPTY at 0 range 3 .. 3; Reserved at 0 range 4 .. 7; end record; -- Bored now, leaving out Interrupt_CFG_Register, Int_Source_Register -- Status register type Status_Register is record T_DA : Bit := 0; P_DA : Bit := 0; Reserved_1 : Zero_Bits (2 .. 3) := (others => 0); T_OR : Bit := 0; P_OR : Bit := 0; Reserved_2 : Zero_Bits (6 .. 7) := (others => 0); end record with Size => 8; for Status_Register use record T_DA at 0 range 0 .. 0; P_DA at 0 range 1 .. 1; Reserved_1 at 0 range 2 .. 3; T_OR at 0 range 4 .. 4; P_OR at 0 range 5 .. 5; Reserved_2 at 0 range 6 .. 7; end record; -- FIFO control register type FIFO_Mode is (Bypass, FIFO, Stream, Stream_While_Trigger_Then_FIFO, Bypass_While_Trigger_Then_Stream, FIFO_Mean, Bypass_While_Trigger_Then_FIFO) with Size => 3; for FIFO_Mode use (Bypass => 0, FIFO => 1, Stream => 2, Stream_While_Trigger_Then_FIFO => 3, Bypass_While_Trigger_Then_Stream => 4, FIFO_Mean => 6, Bypass_While_Trigger_Then_FIFO => 7); type Watermark_Level is (Not_Used, Average_Over_2, Average_Over_4, Average_Over_8, Average_Over_16, Average_Over_32) with Size => 5; for Watermark_Level use (Not_Used => 0, Average_Over_2 => 2#00001#, Average_Over_4 => 2#00011#, Average_Over_8 => 2#00111#, Average_Over_16 => 2#01111#, Average_Over_32 => 2#11111#); type FIFO_Ctrl_Register is record WTM_POINT : Watermark_Level := Not_Used; F_MODE : FIFO_Mode := Bypass; end record with Size => 8; for FIFO_Ctrl_Register use record WTM_POINT at 0 range 0 .. 4; F_MODE at 0 range 5 .. 7; end record; -- Left out FIFO Status end LPS25H;
------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- ADA.CONTAINERS.HASH_TABLES.GENERIC_OPERATIONS -- -- -- -- S p e c -- -- -- -- Copyright (C) 2004-2020, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- This unit was originally developed by Matthew J Heaney. -- ------------------------------------------------------------------------------ -- Hash_Table_Type is used to implement hashed containers. This package -- declares hash-table operations that do not depend on keys. with Ada.Streams; generic with package HT_Types is new Generic_Hash_Table_Types (<>); use HT_Types, HT_Types.Implementation; with function Hash_Node (Node : Node_Access) return Hash_Type; with function Next (Node : Node_Access) return Node_Access; with procedure Set_Next (Node : Node_Access; Next : Node_Access); with function Copy_Node (Source : Node_Access) return Node_Access; with procedure Free (X : in out Node_Access); package Ada.Containers.Hash_Tables.Generic_Operations is pragma Preelaborate; procedure Free_Hash_Table (Buckets : in out Buckets_Access); -- First frees the nodes in all non-null buckets of Buckets, and then frees -- the Buckets array itself. function Index (Buckets : Buckets_Type; Node : Node_Access) return Hash_Type; pragma Inline (Index); -- Uses the hash value of Node to compute its Buckets array index function Index (Hash_Table : Hash_Table_Type; Node : Node_Access) return Hash_Type; pragma Inline (Index); -- Uses the hash value of Node to compute its Hash_Table buckets array -- index. function Checked_Index (Hash_Table : aliased in out Hash_Table_Type; Buckets : Buckets_Type; Node : Node_Access) return Hash_Type; -- Calls Index, but also locks and unlocks the container, per AI05-0022, in -- order to detect element tampering by the generic actual Hash function. function Checked_Index (Hash_Table : aliased in out Hash_Table_Type; Node : Node_Access) return Hash_Type; -- Calls Checked_Index using Hash_Table's buckets array. procedure Adjust (HT : in out Hash_Table_Type); -- Used to implement controlled Adjust. It is assumed that HT has the value -- of the bit-wise copy that immediately follows controlled Finalize. -- Adjust first allocates a new buckets array for HT (having the same -- length as the source), and then allocates a copy of each node of source. procedure Finalize (HT : in out Hash_Table_Type); -- Used to implement controlled Finalize. It first calls Clear to -- deallocate any remaining nodes, and then deallocates the buckets array. generic with function Find (HT : Hash_Table_Type; Key : Node_Access) return Boolean; function Generic_Equal (L, R : Hash_Table_Type) return Boolean; -- Used to implement hashed container equality. For each node in hash table -- L, it calls Find to search for an equivalent item in hash table R. If -- Find returns False for any node then Generic_Equal terminates -- immediately and returns False. Otherwise if Find returns True for every -- node then Generic_Equal returns True. procedure Clear (HT : in out Hash_Table_Type); -- Deallocates each node in hash table HT. (Note that it only deallocates -- the nodes, not the buckets array. Also note that for bounded containers, -- the buckets array is not dynamically allocated). Program_Error is raised -- if the hash table is busy. procedure Move (Target, Source : in out Hash_Table_Type); -- Moves (not copies) the buckets array and nodes from Source to -- Target. Program_Error is raised if Source is busy. The Target is first -- cleared to deallocate its nodes (implying that Program_Error is also -- raised if Target is busy). Source is empty following the move. function Capacity (HT : Hash_Table_Type) return Count_Type; -- Returns the length of the buckets array procedure Reserve_Capacity (HT : in out Hash_Table_Type; N : Count_Type); -- If N is greater than the current capacity, then it expands the buckets -- array to at least the value N. If N is less than the current capacity, -- then it contracts the buckets array. In either case existing nodes are -- rehashed onto the new buckets array, and the old buckets array is -- deallocated. Program_Error is raised if the hash table is busy. procedure Delete_Node_At_Index (HT : in out Hash_Table_Type; Indx : Hash_Type; X : in out Node_Access); -- Delete a node whose bucket position is known. Used to remove a node -- whose element has been modified through a key_preserving reference. -- We cannot use the value of the element precisely because the current -- value does not correspond to the hash code that determines the bucket. procedure Delete_Node_Sans_Free (HT : in out Hash_Table_Type; X : Node_Access); -- Removes node X from the hash table without deallocating the node function First (HT : Hash_Table_Type) return Node_Access; function First (HT : Hash_Table_Type; Position : out Hash_Type) return Node_Access; -- Returns the head of the list in the first (lowest-index) non-empty -- bucket. Position will be the index of the bucket of the first node. -- It is provided so that clients can implement efficient iterators. function Next (HT : aliased in out Hash_Table_Type; Node : Node_Access) return Node_Access; function Next (HT : aliased in out Hash_Table_Type; Node : Node_Access; Position : in out Hash_Type) return Node_Access; -- Returns the node that immediately follows Node. This corresponds to -- either the next node in the same bucket, or (if Node is the last node in -- its bucket) the head of the list in the first non-empty bucket that -- follows. -- -- If Node_Position is supplied, then it will be used as a starting point -- for iteration (Node_Position must be the index of Node's buckets). If it -- is not supplied, it will be recomputed. It is provided so that clients -- can implement efficient iterators. generic with procedure Process (Node : Node_Access; Position : Hash_Type); procedure Generic_Iteration_With_Position (HT : Hash_Table_Type); -- Calls Process for each node in hash table HT generic with procedure Process (Node : Node_Access); procedure Generic_Iteration (HT : Hash_Table_Type); -- Calls Process for each node in hash table HT generic use Ada.Streams; with procedure Write (Stream : not null access Root_Stream_Type'Class; Node : Node_Access); procedure Generic_Write (Stream : not null access Root_Stream_Type'Class; HT : Hash_Table_Type); -- Used to implement the streaming attribute for hashed containers. It -- calls Write for each node to write its value into Stream. generic use Ada.Streams; with function New_Node (Stream : not null access Root_Stream_Type'Class) return Node_Access; procedure Generic_Read (Stream : not null access Root_Stream_Type'Class; HT : out Hash_Table_Type); -- Used to implement the streaming attribute for hashed containers. It -- first clears hash table HT, then populates the hash table by calling -- New_Node for each item in Stream. function New_Buckets (Length : Hash_Type) return Buckets_Access; pragma Inline (New_Buckets); -- Allocate a new Buckets_Type array with bounds 0 .. Length - 1 procedure Free_Buckets (Buckets : in out Buckets_Access); pragma Inline (Free_Buckets); -- Unchecked_Deallocate Buckets -- Note: New_Buckets and Free_Buckets are needed because Buckets_Access has -- an empty pool. end Ada.Containers.Hash_Tables.Generic_Operations;
----------------------------------------------------------------------- -- servlet-parts -- Servlet Parts -- Copyright (C) 2011, 2012 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Finalization; -- The <b>Servlet.Parts</b> package is an Ada implementation of the Java servlet part -- (JSR 315 3. The Request) provided by the <tt>javax.servlet.http.Part</tt> class. package Servlet.Parts is -- ------------------------------ -- Multi part content -- ------------------------------ -- The <b>Part</b> type describes a mime part received in a request. -- The content is stored in a file and several operations are provided -- to manage the content. type Part is abstract new Ada.Finalization.Limited_Controlled with private; -- Get the size of the mime part. function Get_Size (Data : in Part) return Natural is abstract; -- Get the content name submitted in the mime part. function Get_Name (Data : in Part) return String is abstract; -- Get the path of the local file which contains the part. function Get_Local_Filename (Data : in Part) return String is abstract; -- Get the content type of the part. function Get_Content_Type (Data : in Part) return String is abstract; -- Write the part data item to the file. This method is not guaranteed to succeed -- if called more than once for the same part. This allows a particular implementation -- to use, for example, file renaming, where possible, rather than copying all of -- the underlying data, thus gaining a significant performance benefit. procedure Save (Data : in Part; Path : in String); -- Deletes the underlying storage for a file item, including deleting any associated -- temporary disk file. procedure Delete (Data : in out Part); private type Part is abstract new Ada.Finalization.Limited_Controlled with null record; end Servlet.Parts;
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2020 onox <denkpadje@gmail.com> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. package EGL.Errors is pragma Preelaborate; -- Not Pure because Error_Flag can change with each call type Error_Code is (Success, Not_Initialized, Bad_Access, Bad_Alloc, Bad_Attribute, Bad_Config, Bad_Context, Bad_Current_Surface, Bad_Display, Bad_Match, Bad_Native_Pixmap, Bad_Native_Window, Bad_Parameter, Bad_Surface, Context_Lost, Bad_Device); Context_Lost_Error : exception; Not_Initialized_Error : exception; Invalid_Operation_Error : exception; Invalid_Value_Error : exception; Internal_Error : exception; procedure Raise_Exception_On_EGL_Error with Inline; private for Error_Code use (Success => 16#3000#, Not_Initialized => 16#3001#, Bad_Access => 16#3002#, Bad_Alloc => 16#3003#, Bad_Attribute => 16#3004#, Bad_Config => 16#3005#, Bad_Context => 16#3006#, Bad_Current_Surface => 16#3007#, Bad_Display => 16#3008#, Bad_Match => 16#3009#, Bad_Native_Pixmap => 16#300A#, Bad_Native_Window => 16#300B#, Bad_Parameter => 16#300C#, Bad_Surface => 16#300D#, Context_Lost => 16#300E#, Bad_Device => 16#322B#); for Error_Code'Size use Enum'Size; end EGL.Errors;
-- This spec has been automatically generated from STM32L4x1.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package STM32_SVD.NVIC is pragma Preelaborate; --------------- -- Registers -- --------------- subtype ICTR_INTLINESNUM_Field is HAL.UInt4; -- Interrupt Controller Type Register type ICTR_Register is record -- Read-only. Total number of interrupt lines in groups INTLINESNUM : ICTR_INTLINESNUM_Field; -- unspecified Reserved_4_31 : HAL.UInt28; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for ICTR_Register use record INTLINESNUM at 0 range 0 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; -- IPR_IPR_N array element subtype IPR_IPR_N_Element is HAL.UInt8; -- IPR_IPR_N array type IPR_IPR_N_Field_Array is array (0 .. 3) of IPR_IPR_N_Element with Component_Size => 8, Size => 32; -- Interrupt Priority Register type IPR_Register (As_Array : Boolean := False) is record case As_Array is when False => -- IPR_N as a value Val : HAL.UInt32; when True => -- IPR_N as an array Arr : IPR_IPR_N_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for IPR_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; subtype STIR_INTID_Field is HAL.UInt9; -- Software Triggered Interrupt Register type STIR_Register is record -- Write-only. interrupt to be triggered INTID : STIR_INTID_Field := 16#0#; -- unspecified Reserved_9_31 : HAL.UInt23 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for STIR_Register use record INTID at 0 range 0 .. 8; Reserved_9_31 at 0 range 9 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Nested Vectored Interrupt Controller type NVIC_Peripheral is record -- Interrupt Controller Type Register ICTR : aliased ICTR_Register; -- Interrupt Set-Enable Register ISER0 : aliased HAL.UInt32; -- Interrupt Set-Enable Register ISER1 : aliased HAL.UInt32; -- Interrupt Set-Enable Register ISER2 : aliased HAL.UInt32; -- Interrupt Clear-Enable Register ICER0 : aliased HAL.UInt32; -- Interrupt Clear-Enable Register ICER1 : aliased HAL.UInt32; -- Interrupt Clear-Enable Register ICER2 : aliased HAL.UInt32; -- Interrupt Set-Pending Register ISPR0 : aliased HAL.UInt32; -- Interrupt Set-Pending Register ISPR1 : aliased HAL.UInt32; -- Interrupt Set-Pending Register ISPR2 : aliased HAL.UInt32; -- Interrupt Clear-Pending Register ICPR0 : aliased HAL.UInt32; -- Interrupt Clear-Pending Register ICPR1 : aliased HAL.UInt32; -- Interrupt Clear-Pending Register ICPR2 : aliased HAL.UInt32; -- Interrupt Active Bit Register IABR0 : aliased HAL.UInt32; -- Interrupt Active Bit Register IABR1 : aliased HAL.UInt32; -- Interrupt Active Bit Register IABR2 : aliased HAL.UInt32; -- Interrupt Priority Register IPR0 : aliased IPR_Register; -- Interrupt Priority Register IPR1 : aliased IPR_Register; -- Interrupt Priority Register IPR2 : aliased IPR_Register; -- Interrupt Priority Register IPR3 : aliased IPR_Register; -- Interrupt Priority Register IPR4 : aliased IPR_Register; -- Interrupt Priority Register IPR5 : aliased IPR_Register; -- Interrupt Priority Register IPR6 : aliased IPR_Register; -- Interrupt Priority Register IPR7 : aliased IPR_Register; -- Interrupt Priority Register IPR8 : aliased IPR_Register; -- Interrupt Priority Register IPR9 : aliased IPR_Register; -- Interrupt Priority Register IPR10 : aliased IPR_Register; -- Interrupt Priority Register IPR11 : aliased IPR_Register; -- Interrupt Priority Register IPR12 : aliased IPR_Register; -- Interrupt Priority Register IPR13 : aliased IPR_Register; -- Interrupt Priority Register IPR14 : aliased IPR_Register; -- Interrupt Priority Register IPR15 : aliased IPR_Register; -- Interrupt Priority Register IPR16 : aliased IPR_Register; -- Interrupt Priority Register IPR17 : aliased IPR_Register; -- Interrupt Priority Register IPR18 : aliased IPR_Register; -- Interrupt Priority Register IPR19 : aliased IPR_Register; -- Interrupt Priority Register IPR20 : aliased IPR_Register; -- Software Triggered Interrupt Register STIR : aliased STIR_Register; end record with Volatile; for NVIC_Peripheral use record ICTR at 16#4# range 0 .. 31; ISER0 at 16#100# range 0 .. 31; ISER1 at 16#104# range 0 .. 31; ISER2 at 16#108# range 0 .. 31; ICER0 at 16#180# range 0 .. 31; ICER1 at 16#184# range 0 .. 31; ICER2 at 16#188# range 0 .. 31; ISPR0 at 16#200# range 0 .. 31; ISPR1 at 16#204# range 0 .. 31; ISPR2 at 16#208# range 0 .. 31; ICPR0 at 16#280# range 0 .. 31; ICPR1 at 16#284# range 0 .. 31; ICPR2 at 16#288# range 0 .. 31; IABR0 at 16#300# range 0 .. 31; IABR1 at 16#304# range 0 .. 31; IABR2 at 16#308# range 0 .. 31; IPR0 at 16#400# range 0 .. 31; IPR1 at 16#404# range 0 .. 31; IPR2 at 16#408# range 0 .. 31; IPR3 at 16#40C# range 0 .. 31; IPR4 at 16#410# range 0 .. 31; IPR5 at 16#414# range 0 .. 31; IPR6 at 16#418# range 0 .. 31; IPR7 at 16#41C# range 0 .. 31; IPR8 at 16#420# range 0 .. 31; IPR9 at 16#424# range 0 .. 31; IPR10 at 16#428# range 0 .. 31; IPR11 at 16#42C# range 0 .. 31; IPR12 at 16#430# range 0 .. 31; IPR13 at 16#434# range 0 .. 31; IPR14 at 16#438# range 0 .. 31; IPR15 at 16#43C# range 0 .. 31; IPR16 at 16#440# range 0 .. 31; IPR17 at 16#444# range 0 .. 31; IPR18 at 16#448# range 0 .. 31; IPR19 at 16#44C# range 0 .. 31; IPR20 at 16#450# range 0 .. 31; STIR at 16#F00# range 0 .. 31; end record; -- Nested Vectored Interrupt Controller NVIC_Periph : aliased NVIC_Peripheral with Import, Address => System'To_Address (16#E000E000#); end STM32_SVD.NVIC;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with AMF.Internals.Tables.CMOF_Attributes; package body AMF.Internals.CMOF_Multiplicity_Elements is use AMF.Internals.Tables.CMOF_Attributes; -------------------- -- Get_Is_Ordered -- -------------------- overriding function Get_Is_Ordered (Self : not null access constant CMOF_Multiplicity_Element_Proxy) return Boolean is begin -- isOrdered : Boolean -- -- For a multivalued multiplicity, this attribute specifies whether the -- values in an instantiation of this element are sequentially ordered. -- Default is false. return Internal_Get_Is_Ordered (Self.Element); end Get_Is_Ordered; ------------------- -- Get_Is_Unique -- ------------------- overriding function Get_Is_Unique (Self : not null access constant CMOF_Multiplicity_Element_Proxy) return Boolean is begin -- isUnique : Boolean -- -- For a multivalued multiplicity, this attributes specifies whether the -- values in an instantiation of this element are unique. Default is -- true. return Internal_Get_Is_Unique (Self.Element); end Get_Is_Unique; --------------- -- Get_Lower -- --------------- overriding function Get_Lower (Self : not null access constant CMOF_Multiplicity_Element_Proxy) return Optional_Integer is begin -- lower : Integer [0..1] -- -- Specifies the lower bound of the multiplicity interval, if it is -- expressed as an integer. return Internal_Get_Lower (Self.Element); end Get_Lower; --------------- -- Get_Upper -- --------------- overriding function Get_Upper (Self : not null access constant CMOF_Multiplicity_Element_Proxy) return Optional_Unlimited_Natural is begin -- upper : UnlimitedNatural [0..1] -- -- Specifies the upper bound of the multiplicity interval, if it is -- expressed as an unlimited natural. return Internal_Get_Upper (Self.Element); end Get_Upper; -------------------- -- Is_Multivalued -- -------------------- overriding function Is_Multivalued (Self : not null access constant CMOF_Multiplicity_Element_Proxy) return Boolean is begin -- The query isMultivalued() checks whether this multiplicity has an -- upper bound greater than one. -- MultiplicityElement::isMultivalued() : Boolean; -- pre: upperBound()->notEmpty() -- isMultivalued = (upperBound() > 1) return CMOF_Multiplicity_Element_Proxy'Class (Self.all).Upper_Bound > 1; end Is_Multivalued; ----------------- -- Lower_Bound -- ----------------- overriding function Lower_Bound (Self : not null access constant CMOF_Multiplicity_Element_Proxy) return Integer is Lower : constant Optional_Integer := CMOF_Multiplicity_Element_Proxy'Class (Self.all).Get_Lower; begin -- The query lowerBound() returns the lower bound of the multiplicity as -- an integer. -- -- MultiplicityElement::lowerBound() : [Integer]; -- lowerBound = -- if lowerValue->isEmpty() then 1 -- else lowerValue.integerValue() endif if Lower.Is_Empty then return 1; else return Lower.Value; end if; end Lower_Bound; -------------------- -- Set_Is_Ordered -- -------------------- overriding procedure Set_Is_Ordered (Self : not null access CMOF_Multiplicity_Element_Proxy; To : Boolean) is begin Internal_Set_Is_Ordered (Self.Element, To); end Set_Is_Ordered; ------------------- -- Set_Is_Unique -- ------------------- overriding procedure Set_Is_Unique (Self : not null access CMOF_Multiplicity_Element_Proxy; To : Boolean) is begin Internal_Set_Is_Unique (Self.Element, To); end Set_Is_Unique; --------------- -- Set_Lower -- --------------- overriding procedure Set_Lower (Self : not null access CMOF_Multiplicity_Element_Proxy; To : Optional_Integer) is begin Internal_Set_Lower (Self.Element, To); end Set_Lower; --------------- -- Set_Upper -- --------------- overriding procedure Set_Upper (Self : not null access CMOF_Multiplicity_Element_Proxy; To : Optional_Unlimited_Natural) is begin Internal_Set_Upper (Self.Element, To); end Set_Upper; ----------------- -- Upper_Bound -- ----------------- overriding function Upper_Bound (Self : not null access constant CMOF_Multiplicity_Element_Proxy) return Unlimited_Natural is Upper : constant Optional_Unlimited_Natural := CMOF_Multiplicity_Element_Proxy'Class (Self.all).Get_Upper; begin -- The query upperBound() returns the upper bound of the multiplicity -- for a bounded multiplicity as an unlimited natural. -- -- MultiplicityElement::upperBound() : [UnlimitedNatural]; -- upperBound = -- if upperValue->isEmpty() then 1 -- else upperValue.unlimitedValue() endif if Upper.Is_Empty then return (False, 1); else return Upper.Value; end if; end Upper_Bound; end AMF.Internals.CMOF_Multiplicity_Elements;
-- Copyright (c) 2015-2017 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- package body Tests.Parser_Data.XML_Reader is function "+" (Text : Wide_Wide_String) return League.Strings.Universal_String renames League.Strings.To_Universal_String; Nil_Location : constant XML.Templates.Streams.Event_Location := (League.Strings.Empty_Universal_String, 0, 0); ---------------- -- Characters -- ---------------- overriding procedure Characters (Self : in out Reader; Text : League.Strings.Universal_String; Success : in out Boolean) is pragma Unreferenced (Success); begin if Self.Collect_Text then Self.Text.Append (Text); end if; end Characters; ----------------- -- End_Element -- ----------------- overriding procedure End_Element (Self : in out Reader; Namespace_URI : League.Strings.Universal_String; Local_Name : League.Strings.Universal_String; Qualified_Name : League.Strings.Universal_String; Success : in out Boolean) is pragma Unreferenced (Success); use type League.Strings.Universal_String; use type Incr.Nodes.Node_Kind; begin if Local_Name = +"names" then Self.Data.Names := Self.List; Self.List.Clear; elsif Local_Name = +"counts" then declare List : constant League.String_Vectors.Universal_String_Vector := Self.Text.Split (' ', League.Strings.Skip_Empty); begin Self.Data.Parts := new P.Parts_Count_Table (1 .. P.Production_Index (List.Length)); for J in Self.Data.Parts'Range loop Self.Data.Parts (J) := Natural'Wide_Wide_Value (List (Positive (J)).To_Wide_Wide_String); end loop; Self.Collect_Text := False; Self.Text.Clear; end; elsif Local_Name = +"nt" then declare List : constant League.String_Vectors.Universal_String_Vector := Self.Text.Split (' ', League.Strings.Skip_Empty); begin Self.Data.NT := new Node_Kind_Array (Self.Data.Parts'Range); for J in 1 .. List.Length loop declare Pair : constant League.String_Vectors.Universal_String_Vector := List (J).Split ('-'); begin for Prod in P.Production_Index'Wide_Wide_Value (Pair (1).To_Wide_Wide_String) .. P.Production_Index'Wide_Wide_Value (Pair (2).To_Wide_Wide_String) loop Self.Data.NT (Prod) := Self.Data.Max_Term + Incr.Nodes.Node_Kind (J); end loop; end; end loop; Self.Collect_Text := False; Self.Text.Clear; end; elsif Local_Name = +"states" then declare Last : Positive := 1; List : constant League.String_Vectors.Universal_String_Vector := Self.Text.Split (' ', League.Strings.Skip_Empty); begin for S in Self.Data.States'Range (1) loop for NT in Self.Data.States'Range (2) loop Self.Data.States (S, NT) := P.Parser_State'Wide_Wide_Value (List (Last).To_Wide_Wide_String); Last := Last + 1; end loop; end loop; Self.Collect_Text := False; Self.Text.Clear; end; elsif Local_Name = +"actions" then declare Last : Positive := 1; List : constant League.String_Vectors.Universal_String_Vector := Self.Text.Split (' ', League.Strings.Skip_Empty); begin for S in Self.Data.Actions'Range (1) loop for NT in Self.Data.Actions'Range (2) loop declare Item : constant Wide_Wide_String := List (Last).To_Wide_Wide_String; begin if Item = "F" then Self.Data.Actions (S, NT) := (Kind => P.Finish); elsif Item = "E" then Self.Data.Actions (S, NT) := (Kind => P.Error); elsif Item (1) = 'S' then Self.Data.Actions (S, NT) := (P.Shift, P.Parser_State'Wide_Wide_Value (Item (2 .. Item'Last))); else Self.Data.Actions (S, NT) := (P.Reduce, P.Production_Index'Wide_Wide_Value (Item)); end if; Last := Last + 1; end; end loop; end loop; Self.Collect_Text := False; Self.Text.Clear; end; elsif Local_Name = +"set-eos-text" then Self.Commands.Append ((Commands.Set_EOS_Text, Self.Text)); Self.Collect_Text := False; Self.Text.Clear; elsif Local_Name = +"set-token-text" then Self.Commands.Append ((Commands.Set_Token_Text, Self.Text, Self.Index)); Self.Collect_Text := False; Self.Text.Clear; elsif Local_Name = +"dump-tree" then Self.Commands.Append ((Commands.Dump_Tree, Self.Vector)); Self.Collect_XML := False; Self.Vector.Clear; Self.Collect_Text := False; Self.Text.Clear; elsif Self.Collect_XML then if not Self.Text.Is_Empty then if Local_Name.Starts_With ("token") then Self.Vector.Append ((Kind => XML.Templates.Streams.Text, Text => Self.Text, Location => Nil_Location)); end if; Self.Text.Clear; end if; Self.Vector.Append ((Kind => XML.Templates.Streams.End_Element, Namespace_URI => Namespace_URI, Local_Name => Local_Name, Qualified_Name => Qualified_Name, Location => Nil_Location)); return; end if; end End_Element; ------------------ -- Error_String -- ------------------ overriding function Error_String (Self : Reader) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return League.Strings.Empty_Universal_String; end Error_String; ------------------ -- Get_Commands -- ------------------ function Get_Commands (Self : Reader) return Tests.Commands.Command_Vectors.Vector is begin return Self.Commands; end Get_Commands; ------------------- -- Start_Element -- ------------------- overriding procedure Start_Element (Self : in out Reader; Namespace_URI : League.Strings.Universal_String; Local_Name : League.Strings.Universal_String; Qualified_Name : League.Strings.Universal_String; Attributes : XML.SAX.Attributes.SAX_Attributes; Success : in out Boolean) is pragma Unreferenced (Success); use type League.Strings.Universal_String; use type Incr.Nodes.Node_Kind; function "-" (Name : Wide_Wide_String) return League.Strings.Universal_String; function "-" (Name : Wide_Wide_String) return Incr.Nodes.Node_Kind; function "-" (Name : Wide_Wide_String) return P.Parser_State; function "-" (Name : Wide_Wide_String) return Integer; --------- -- "-" -- --------- function "-" (Name : Wide_Wide_String) return League.Strings.Universal_String is Local : constant League.Strings.Universal_String := +Name; begin for J in 1 .. Attributes.Length loop if Attributes.Local_Name (J) = Local then return Attributes.Value (J); end if; end loop; raise Constraint_Error; end "-"; function "-" (Name : Wide_Wide_String) return Incr.Nodes.Node_Kind is begin return Incr.Nodes.Node_Kind'Wide_Wide_Value ("-" (Name).To_Wide_Wide_String); end "-"; function "-" (Name : Wide_Wide_String) return P.Parser_State is begin return P.Parser_State'Wide_Wide_Value ("-" (Name).To_Wide_Wide_String); end "-"; function "-" (Name : Wide_Wide_String) return Integer is begin return Integer'Wide_Wide_Value ("-" (Name).To_Wide_Wide_String); end "-"; begin if Self.Collect_XML then Self.Vector.Append ((Kind => XML.Templates.Streams.Start_Element, Namespace_URI => Namespace_URI, Local_Name => Local_Name, Qualified_Name => Qualified_Name, Attributes => Attributes, Location => Nil_Location)); Self.Text.Clear; return; end if; if Local_Name = +"name" then Self.List.Append (-"name"); elsif Local_Name = +"names" then Self.Data.Max_Term := -"term"; Self.Data.Max_NT := Self.Data.Max_Term + (-"nt"); Self.List.Clear; elsif Local_Name = +"counts" then Self.Collect_Text := True; Self.Text.Clear; elsif Local_Name = +"nt" then Self.Collect_Text := True; Self.Text.Clear; elsif Local_Name = +"states" then Self.Data.States := new P.State_Table (1 .. -"count", Self.Data.Max_Term + 1 .. Self.Data.Max_NT); Self.Collect_Text := True; Self.Text.Clear; elsif Local_Name = +"actions" then Self.Data.Actions := new P.Action_Table (Self.Data.States'Range (1), 0 .. Self.Data.Max_NT); Self.Collect_Text := True; Self.Text.Clear; elsif Local_Name = +"commit" then Self.Commands.Append ((Kind => Commands.Commit)); elsif Local_Name = +"set-eos-text" then Self.Collect_Text := True; Self.Text.Clear; elsif Local_Name = +"set-token-text" then Self.Index := -"index"; Self.Collect_Text := True; Self.Text.Clear; elsif Local_Name = +"dump-tree" then Self.Collect_XML := True; Self.Collect_Text := True; Self.Vector.Clear; elsif Local_Name = +"run" then Self.Commands.Append ((Kind => Commands.Run)); end if; end Start_Element; end Tests.Parser_Data.XML_Reader;
-- ___ _ ___ _ _ -- -- / __| |/ (_) | | Common SKilL implementation -- -- \__ \ ' <| | | |__ iterator over types -- -- |___/_|\_\_|_|____| by: Timm Felden -- -- -- pragma Ada_2012; package body Skill.Iterators.Type_Hierarchy_Iterator is procedure Init (This : access Iterator'Class; First : Skill.Types.Pools.Pool := null) is begin This.Current := First; if null /= First then This.End_Height := First.Type_Hierarchy_Height; end if; end Init; procedure Next (This : access Iterator'Class) is begin This.Current := This.Current.Next; if null = This.Current or else This.End_Height >= This.Current.Type_Hierarchy_Height then This.Current := null; end if; end Next; function Next (This : access Iterator'Class) return Skill.Types.Pools.Pool is Rval : constant Skill.Types.Pools.Pool := This.Current; begin This.Current := This.Current.Next; if null = This.Current or else This.End_Height >= This.Current.Type_Hierarchy_Height then This.Current := null; end if; return Rval; end Next; end Skill.Iterators.Type_Hierarchy_Iterator;
-- C45201A.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- CHECK THAT '=' AND '/=' PRODUCE CORRECT RESULTS ON -- ENUMERATION-TYPE OPERANDS (IN PARTICULAR, FOR OPERANDS HAVING -- DIFFERENT SUBTYPES). -- THIS TEST'S FRAMEWORK IS FROM C45201B.ADA , C45210A.ADA . -- RM 20 OCTOBER 1980 -- JWC 7/8/85 RENAMED TO -AB WITH REPORT ; PROCEDURE C45201A IS USE REPORT; TYPE T IS ( A , SLIT , B , PLIT , C , NUL , D , 'R' , E ); -- S-LIT , P-LIT , NUL , 'R' CORRESPOND -- TO 'S' , 'P' , 'M' , 'R' IN C45210A. SUBTYPE T1 IS T RANGE A..B ; SUBTYPE T2 IS T RANGE A..C ; -- INCLUDES T1 SUBTYPE T3 IS T RANGE B..D ; -- INTERSECTS T2 , T4 SUBTYPE T4 IS T RANGE C..E ; -- DISJOINT FROM T1 , T2 MVAR : T3 := T'(NUL ) ; PVAR : T2 := T'(PLIT) ; RVAR : T4 := T'('R' ) ; SVAR : T1 := T'(SLIT) ; ERROR_COUNT : INTEGER := 0 ; -- INITIAL VALUE ESSENTIAL PROCEDURE BUMP IS BEGIN ERROR_COUNT := ERROR_COUNT + 1 ; END BUMP ; FUNCTION ITSELF( THE_ARGUMENT : T ) RETURN T IS BEGIN IF EQUAL(2,2) THEN RETURN THE_ARGUMENT; ELSE RETURN A ; END IF; END ; BEGIN TEST( "C45201A" , "CHECK THAT '=' AND '/=' PRODUCE CORRECT" & " RESULTS ON ENUMERATION-TYPE LITERALS" ) ; -- 128 CASES ( 4 * 4 ORDERED PAIRS OF OPERAND VALUES, -- 2 (4) OPERATORS (2, TWICE): '=' , '/=' , '=' , '/=' -- (IN THE TABLE: A , B , C , D ) -- (C45201B.ADA HAD < <= > >= ; REVERSED) -- 4 VARIABLE/LITERAL FOR LEFT OPERAND, -- VARIABLE/LITERAL FOR RIGHT OPERAND, -- (IN THE TABLE: VV = ALPHA , -- VL = BETA , -- LV = GAMMA , -- LL = DELTA ) RANDOMIZED -- INTO 16 (ONE FOR EACH PAIR OF VALUES) ACCORDING TO THE FOL- -- LOWING GRAECO-LATIN SQUARE (WITH ADDITIONAL PROPERTIES): -- RIGHT OPERAND: 'S' 'P' 'M' 'R' -- LEFT -- OPERAND: -- 'S' A-ALPHA B-BETA C-GAMMA D-DELTA -- 'P' C-DELTA D-GAMMA A-BETA B-ALPHA -- 'M' D-BETA C-ALPHA B-DELTA A-GAMMA -- 'R' B-GAMMA A-DELTA D-ALPHA C-BETA -- (BOTH THE LATIN DIAGONAL AND THE GREEK DIAGONAL CONTAIN 4 -- DISTINCT LETTERS, NON-TRIVIALLY PERMUTED.) -- THE ABOVE DESCRIBES PART 1 OF THE TEST. PART 2 PERFORMS AN -- EXHAUSTIVE VERIFICATION OF THE 'VARIABLE VS. VARIABLE' CASE -- ( VV , ALPHA ) FOR BOTH OPERATORS. ----------------------------------------------------------------- -- PART 1 -- 'BUMP' MEANS 'BUMP THE ERROR COUNT' IF T'(SVAR) = T'(SVAR) THEN NULL; ELSE BUMP ; END IF; IF T'(SVAR) /= T'(PLIT) THEN NULL; ELSE BUMP ; END IF; IF T'(SLIT) = T'(MVAR) THEN BUMP ; END IF; IF T'(SLIT) /= T'('R' ) THEN NULL; ELSE BUMP ; END IF; IF T'(PLIT) = T'(SLIT) THEN BUMP ; END IF; IF T'(PLIT) /= T'(PVAR) THEN BUMP ; END IF; IF T'(PVAR) = T'(NUL ) THEN BUMP ; END IF; IF T'(PVAR) /= T'(RVAR) THEN NULL; ELSE BUMP ; END IF; IF T'(MVAR) /= T'(SLIT) THEN NULL; ELSE BUMP ; END IF; IF T'(MVAR) = T'(PVAR) THEN BUMP ; END IF; IF T'(NUL ) /= T'(NUL ) THEN BUMP ; END IF; IF T'(NUL ) = T'(RVAR) THEN BUMP ; END IF; IF T'('R' ) /= T'(SVAR) THEN NULL; ELSE BUMP ; END IF; IF T'('R' ) = T'(PLIT) THEN BUMP ; END IF; IF T'(RVAR) /= T'(MVAR) THEN NULL; ELSE BUMP ; END IF; IF T'(RVAR) = T'('R' ) THEN NULL; ELSE BUMP ; END IF; IF ERROR_COUNT /= 0 THEN FAILED( "EQUALITY OF ENUMERATION VALUES - FAILURE1" ); END IF; ----------------------------------------------------------------- -- PART 2 -- 'BUMP' STILL MEANS 'BUMP THE ERROR COUNT' ERROR_COUNT := 0 ; FOR AVAR IN T'FIRST..T'LAST LOOP -- 9 VALUES FOR BVAR IN T'FIRST..T'LAST LOOP -- 9 VALUES IF AVAR = BVAR THEN IF AVAR /= BVAR THEN BUMP ; END IF; END IF; IF AVAR /= BVAR THEN IF AVAR = BVAR THEN BUMP ; END IF; END IF; END LOOP; END LOOP; IF ERROR_COUNT /= 0 THEN FAILED( "EQUALITY OF ENUMERATION VALUES - FAILURE2" ); END IF; ERROR_COUNT := 0 ; FOR AVAR IN T'FIRST..T'LAST LOOP -- 9 VALUES FOR BVAR IN T'FIRST..T'LAST LOOP -- 9 VALUES IF ( AVAR /= BVAR ) /= ( T'POS(AVAR) /= T'POS(BVAR) )THEN BUMP ; END IF; IF ( AVAR = BVAR ) /= ( T'POS(AVAR) = T'POS(BVAR) )THEN BUMP ; END IF; END LOOP; END LOOP; IF ERROR_COUNT /= 0 THEN FAILED( "EQUALITY OF ENUMERATION VALUES - FAILURE3" ); END IF; ERROR_COUNT := 0 ; FOR IVAR IN 0..8 LOOP -- 9 VALUES FOR JVAR IN 0..8 LOOP -- 9 VALUES IF ( IVAR /= JVAR ) /= ( T'VAL(IVAR) /= T'VAL(JVAR) )THEN BUMP ; END IF; IF ( IVAR = JVAR ) /= ( T'VAL(IVAR) = T'VAL(JVAR) )THEN BUMP ; END IF; END LOOP; END LOOP; IF ERROR_COUNT /= 0 THEN FAILED( "EQUALITY OF ENUMERATION VALUES - FAILURE4" ); END IF; ERROR_COUNT := 0 ; FOR AVAR IN T'FIRST..T'LAST LOOP -- 9 VALUES (THE DIAGONAL) IF AVAR = ITSELF(AVAR) THEN NULL; ELSE BUMP; END IF; IF AVAR /= ITSELF(AVAR) THEN BUMP; END IF; END LOOP; IF ERROR_COUNT /= 0 THEN FAILED( "EQUALITY OF ENUMERATION VALUES - FAILURE5" ); END IF; -- 'BUMP' MEANS 'INCREASE THE COUNT FOR THE NUMBER OF <TRUE>S' ERROR_COUNT := 0 ; FOR AVAR IN T'FIRST..T'LAST LOOP -- 9 VALUES FOR BVAR IN T'FIRST..T'LAST LOOP -- 9 VALUES IF AVAR /= BVAR THEN BUMP ; END IF; -- COUNT +:= 72 END LOOP; END LOOP; IF ERROR_COUNT /= 72 THEN -- THIS IS A PLAIN COUNT, NOT AN -- ERROR COUNT FAILED( "EQUALITY OF ENUMERATION VALUES - FAILURE6" ); END IF; RESULT; END C45201A;
with Adventofcode.File_Line_Readers; with Ada.Text_IO; use Ada.Text_IO; procedure Adventofcode.Day_2.Main is procedure Eval (Path : String) is Count : Natural := 0; begin for Line of Adventofcode.File_Line_Readers.Read_Lines (Path) loop if Parse (Line).Valid2 then Count := Count + 1; end if; end loop; Put_Line (Count'Img); end; begin Eval ("src/day-2/input.test"); Eval ("src/day-2/input"); end Adventofcode.Day_2.Main;
pragma Ada_2012; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; with Interfaces.C.Extensions; package a_nodes_h is type Program_Text is new Interfaces.C.Strings.chars_ptr; -- a_nodes.h:11 subtype ASIS_Integer is int; -- a_nodes.h:12 subtype Element_ID is int; -- a_nodes.h:19 type Element_ID_Ptr is access all Element_ID; -- a_nodes.h:36 type u_Element_ID_Array_Struct is record Length : aliased int; -- a_nodes.h:41 IDs : Element_ID_Ptr; -- a_nodes.h:42 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:40 subtype Element_ID_Array_Struct is u_Element_ID_Array_Struct; -- a_nodes.h:43 subtype Element_ID_List is Element_ID_Array_Struct; -- a_nodes.h:45 type Element_Kinds is (Not_An_Element, A_Pragma, A_Defining_Name, A_Declaration, A_Definition, An_Expression, An_Association, A_Statement, A_Path, A_Clause, An_Exception_Handler) with Convention => C; -- a_nodes.h:47 subtype Access_Type_Definition is Element_ID; -- a_nodes.h:69 subtype Association is Element_ID; -- a_nodes.h:70 subtype Association_List is Element_ID_List; -- a_nodes.h:71 subtype Case_Statement_Alternative is Element_ID; -- a_nodes.h:72 subtype Clause is Element_ID; -- a_nodes.h:73 subtype Component_Clause is Element_ID; -- a_nodes.h:74 subtype Component_Clause_List is Element_ID_List; -- a_nodes.h:75 subtype Component_Declaration is Element_ID; -- a_nodes.h:76 subtype Component_Definition is Element_ID; -- a_nodes.h:77 subtype Constraint_ID is Element_ID; -- a_nodes.h:78 subtype Constraint is Element_ID; -- a_nodes.h:79 subtype Context_Clause is Element_ID; -- a_nodes.h:80 subtype Context_Clause_List is Element_ID_List; -- a_nodes.h:81 subtype Declaration is Element_ID; -- a_nodes.h:82 subtype Declaration_ID is Element_ID; -- a_nodes.h:83 subtype Declaration_List is Element_ID_List; -- a_nodes.h:84 subtype Declarative_Item_List is Element_ID_List; -- a_nodes.h:85 subtype Defining_Name_ID is Element_ID; -- a_nodes.h:86 subtype Definition is Element_ID; -- a_nodes.h:87 subtype Definition_ID is Element_ID; -- a_nodes.h:88 subtype Definition_List is Element_ID_List; -- a_nodes.h:89 subtype Discrete_Range is Element_ID; -- a_nodes.h:90 subtype Discrete_Range_ID is Element_ID; -- a_nodes.h:91 subtype Discrete_Range_List is Element_ID_List; -- a_nodes.h:92 subtype Discrete_Subtype_Definition is Element_ID; -- a_nodes.h:93 subtype Discrete_Subtype_Definition_ID is Element_ID; -- a_nodes.h:94 subtype Discriminant_Association is Element_ID; -- a_nodes.h:95 subtype Discriminant_Association_List is Element_ID_List; -- a_nodes.h:96 subtype Discriminant_Specification_List is Element_ID_List; -- a_nodes.h:97 subtype Defining_Name is Element_ID; -- a_nodes.h:98 subtype Defining_Name_List is Element_ID_List; -- a_nodes.h:99 subtype Exception_Handler is Element_ID; -- a_nodes.h:100 subtype Exception_Handler_List is Element_ID_List; -- a_nodes.h:101 subtype Expression is Element_ID; -- a_nodes.h:102 subtype Expression_ID is Element_ID; -- a_nodes.h:103 subtype Expression_List is Element_ID_List; -- a_nodes.h:104 subtype Expression_Path_List is Element_ID_List; -- a_nodes.h:105 subtype Formal_Type_Definition is Element_ID; -- a_nodes.h:106 subtype Generic_Formal_Parameter is Element_ID; -- a_nodes.h:107 subtype Generic_Formal_Parameter_List is Element_ID_List; -- a_nodes.h:108 subtype Identifier is Element_ID; -- a_nodes.h:109 subtype Identifier_List is Element_ID_List; -- a_nodes.h:110 subtype Name is Element_ID; -- a_nodes.h:111 subtype Name_ID is Element_ID; -- a_nodes.h:112 subtype Name_List is Element_ID_List; -- a_nodes.h:113 subtype Parameter_Specification is Element_ID; -- a_nodes.h:114 subtype Parameter_Specification_List is Element_ID_List; -- a_nodes.h:115 subtype Path is Element_ID; -- a_nodes.h:116 subtype Path_List is Element_ID_List; -- a_nodes.h:117 subtype Pragma_Element is Element_ID; -- a_nodes.h:118 subtype Pragma_Element_ID_List is Element_ID_List; -- a_nodes.h:119 subtype Range_Constraint is Element_ID; -- a_nodes.h:120 subtype Record_Component is Element_ID; -- a_nodes.h:121 subtype Record_Component_List is Element_ID_List; -- a_nodes.h:122 subtype Record_Definition is Element_ID; -- a_nodes.h:123 subtype Representation_Clause is Element_ID; -- a_nodes.h:124 subtype Representation_Clause_List is Element_ID_List; -- a_nodes.h:125 subtype Root_Type_Definition is Element_ID; -- a_nodes.h:126 subtype Select_Alternative is Element_ID; -- a_nodes.h:127 subtype Statement is Element_ID; -- a_nodes.h:128 subtype Statement_ID is Element_ID; -- a_nodes.h:129 subtype Statement_List is Element_ID_List; -- a_nodes.h:130 subtype Subtype_Indication is Element_ID; -- a_nodes.h:131 subtype Subtype_Indication_ID is Element_ID; -- a_nodes.h:132 subtype Subtype_Mark is Element_ID; -- a_nodes.h:133 subtype Type_Definition is Element_ID; -- a_nodes.h:134 subtype Type_Definition_ID is Element_ID; -- a_nodes.h:135 subtype Variant is Element_ID; -- a_nodes.h:136 subtype Variant_Component_List is Element_ID_List; -- a_nodes.h:137 subtype Variant_List is Element_ID_List; -- a_nodes.h:138 type Operator_Kinds is (Not_An_Operator, An_And_Operator, An_Or_Operator, An_Xor_Operator, An_Equal_Operator, A_Not_Equal_Operator, A_Less_Than_Operator, A_Less_Than_Or_Equal_Operator, A_Greater_Than_Operator, A_Greater_Than_Or_Equal_Operator, A_Plus_Operator, A_Minus_Operator, A_Concatenate_Operator, A_Unary_Plus_Operator, A_Unary_Minus_Operator, A_Multiply_Operator, A_Divide_Operator, A_Mod_Operator, A_Rem_Operator, An_Exponentiate_Operator, An_Abs_Operator, A_Not_Operator) with Convention => C; -- a_nodes.h:142 type Pragma_Kinds is (Not_A_Pragma, An_All_Calls_Remote_Pragma, An_Assert_Pragma, An_Assertion_Policy_Pragma, An_Asynchronous_Pragma, An_Atomic_Pragma, An_Atomic_Components_Pragma, An_Attach_Handler_Pragma, A_Controlled_Pragma, A_Convention_Pragma, A_CPU_Pragma, A_Default_Storage_Pool_Pragma, A_Detect_Blocking_Pragma, A_Discard_Names_Pragma, A_Dispatching_Domain_Pragma, An_Elaborate_Pragma, An_Elaborate_All_Pragma, An_Elaborate_Body_Pragma, An_Export_Pragma, An_Independent_Pragma, A_Independent_Components_Pragma, An_Import_Pragma, An_Inline_Pragma, An_Inspection_Point_Pragma, An_Interrupt_Handler_Pragma, An_Interrupt_Priority_Pragma, A_Linker_Options_Pragma, A_List_Pragma, A_Locking_Policy_Pragma, A_No_Return_Pragma, A_Normalize_Scalars_Pragma, An_Optimize_Pragma, A_Pack_Pragma, A_Page_Pragma, A_Partition_Elaboration_Policy_Pragma, A_Preelaborable_Initialization_Pragma, A_Preelaborate_Pragma, A_Priority_Pragma, A_Priority_Specific_Dispatching_Pragma, A_Profile_Pragma, A_Pure_Pragma, A_Queuing_Policy_Pragma, A_Relative_Deadline_Pragma, A_Remote_Call_Interface_Pragma, A_Remote_Types_Pragma, A_Restrictions_Pragma, A_Reviewable_Pragma, A_Shared_Passive_Pragma, A_Storage_Size_Pragma, A_Suppress_Pragma, A_Task_Dispatching_Policy_Pragma, An_Unchecked_Union_Pragma, An_Unsuppress_Pragma, A_Volatile_Pragma, A_Volatile_Components_Pragma, An_Implementation_Defined_Pragma) with Convention => C; -- a_nodes.h:172 type Pragma_Struct is record Pragma_Kind : aliased Pragma_Kinds; -- a_nodes.h:233 Pragmas : aliased Pragma_Element_ID_List; -- a_nodes.h:234 Pragma_Name_Image : Program_Text; -- a_nodes.h:235 Pragma_Argument_Associations : aliased Association_List; -- a_nodes.h:236 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:232 type Defining_Name_Kinds is (Not_A_Defining_Name, A_Defining_Identifier, A_Defining_Character_Literal, A_Defining_Enumeration_Literal, A_Defining_Operator_Symbol, A_Defining_Expanded_Name) with Convention => C; -- a_nodes.h:247 type Defining_Name_Struct is record Defining_Name_Kind : aliased Defining_Name_Kinds; -- a_nodes.h:258 Defining_Name_Image : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:259 References : aliased Name_List; -- a_nodes.h:260 Is_Referenced : aliased Extensions.bool; -- a_nodes.h:261 Operator_Kind : aliased Operator_Kinds; -- a_nodes.h:265 Position_Number_Image : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:268 Representation_Value_Image : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:269 Defining_Prefix : aliased Name_ID; -- a_nodes.h:271 Defining_Selector : aliased Defining_Name_ID; -- a_nodes.h:272 Corresponding_Constant_Declaration : aliased Declaration_ID; -- a_nodes.h:274 Corresponding_Generic_Element : aliased Defining_Name_ID; -- a_nodes.h:277 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:257 type Declaration_Kinds is (Not_A_Declaration, An_Ordinary_Type_Declaration, A_Task_Type_Declaration, A_Protected_Type_Declaration, An_Incomplete_Type_Declaration, A_Tagged_Incomplete_Type_Declaration, A_Private_Type_Declaration, A_Private_Extension_Declaration, A_Subtype_Declaration, A_Variable_Declaration, A_Constant_Declaration, A_Deferred_Constant_Declaration, A_Single_Task_Declaration, A_Single_Protected_Declaration, An_Integer_Number_Declaration, A_Real_Number_Declaration, An_Enumeration_Literal_Specification, A_Discriminant_Specification, A_Component_Declaration, A_Loop_Parameter_Specification, A_Generalized_Iterator_Specification, An_Element_Iterator_Specification, A_Procedure_Declaration, A_Function_Declaration, A_Parameter_Specification, A_Procedure_Body_Declaration, A_Function_Body_Declaration, A_Return_Variable_Specification, A_Return_Constant_Specification, A_Null_Procedure_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_Entry_Declaration, An_Entry_Body_Declaration, An_Entry_Index_Specification, A_Procedure_Body_Stub, A_Function_Body_Stub, A_Package_Body_Stub, A_Task_Body_Stub, A_Protected_Body_Stub, An_Exception_Declaration, A_Choice_Parameter_Specification, A_Generic_Procedure_Declaration, A_Generic_Function_Declaration, A_Generic_Package_Declaration, A_Package_Instantiation, A_Procedure_Instantiation, A_Function_Instantiation, A_Formal_Object_Declaration, A_Formal_Type_Declaration, A_Formal_Incomplete_Type_Declaration, A_Formal_Procedure_Declaration, A_Formal_Function_Declaration, A_Formal_Package_Declaration, A_Formal_Package_Declaration_With_Box) with Convention => C; -- a_nodes.h:288 type Declaration_Origins is (Not_A_Declaration_Origin, An_Explicit_Declaration, An_Implicit_Predefined_Declaration, An_Implicit_Inherited_Declaration) with Convention => C; -- a_nodes.h:392 type Mode_Kinds is (Not_A_Mode, A_Default_In_Mode, An_In_Mode, An_Out_Mode, An_In_Out_Mode) with Convention => C; -- a_nodes.h:408 type Subprogram_Default_Kinds is (Not_A_Default, A_Name_Default, A_Box_Default, A_Null_Default, A_Nil_Default) with Convention => C; -- a_nodes.h:418 type Declaration_Struct is record Declaration_Kind : aliased Declaration_Kinds; -- a_nodes.h:431 Declaration_Origin : aliased Declaration_Origins; -- a_nodes.h:432 Corresponding_Pragmas : aliased Pragma_Element_ID_List; -- a_nodes.h:433 Names : aliased Defining_Name_List; -- a_nodes.h:434 Aspect_Specifications : aliased Element_ID_List; -- a_nodes.h:435 Corresponding_Representation_Clauses : aliased Representation_Clause_List; -- a_nodes.h:436 Has_Abstract : aliased Extensions.bool; -- a_nodes.h:446 Has_Aliased : aliased Extensions.bool; -- a_nodes.h:453 Has_Limited : aliased Extensions.bool; -- a_nodes.h:457 Has_Private : aliased Extensions.bool; -- a_nodes.h:460 Has_Protected : aliased Extensions.bool; -- a_nodes.h:465 Has_Reverse : aliased Extensions.bool; -- a_nodes.h:469 Has_Task : aliased Extensions.bool; -- a_nodes.h:474 Has_Null_Exclusion : aliased Extensions.bool; -- a_nodes.h:478 Is_Not_Null_Return : aliased Extensions.bool; -- a_nodes.h:486 Mode_Kind : aliased Mode_Kinds; -- a_nodes.h:489 Default_Kind : aliased Subprogram_Default_Kinds; -- a_nodes.h:492 Pragmas : aliased Pragma_Element_ID_List; -- a_nodes.h:512 Corresponding_End_Name : aliased Element_ID; -- a_nodes.h:525 Discriminant_Part : aliased Definition_ID; -- a_nodes.h:534 Type_Declaration_View : aliased Definition_ID; -- a_nodes.h:541 Object_Declaration_View : aliased Definition_ID; -- a_nodes.h:553 Initialization_Expression : aliased Expression_ID; -- a_nodes.h:563 Corresponding_Type_Declaration : aliased Declaration_ID; -- a_nodes.h:571 Corresponding_Type_Completion : aliased Declaration_ID; -- a_nodes.h:576 Corresponding_Type_Partial_View : aliased Declaration_ID; -- a_nodes.h:582 Corresponding_First_Subtype : aliased Declaration_ID; -- a_nodes.h:590 Corresponding_Last_Constraint : aliased Declaration_ID; -- a_nodes.h:591 Corresponding_Last_Subtype : aliased Declaration_ID; -- a_nodes.h:592 Specification_Subtype_Definition : aliased Discrete_Subtype_Definition_ID; -- a_nodes.h:595 Iteration_Scheme_Name : aliased Element_ID; -- a_nodes.h:598 Subtype_Indication : aliased Element_ID; -- a_nodes.h:600 Parameter_Profile : aliased Parameter_Specification_List; -- a_nodes.h:617 Result_Profile : aliased Element_ID; -- a_nodes.h:625 Result_Expression : aliased Expression_ID; -- a_nodes.h:627 Is_Overriding_Declaration : aliased Extensions.bool; -- a_nodes.h:643 Is_Not_Overriding_Declaration : aliased Extensions.bool; -- a_nodes.h:644 Body_Declarative_Items : aliased Element_ID_List; -- a_nodes.h:650 Body_Statements : aliased Statement_List; -- a_nodes.h:651 Body_Exception_Handlers : aliased Exception_Handler_List; -- a_nodes.h:652 Body_Block_Statement : aliased Declaration_ID; -- a_nodes.h:653 Is_Name_Repeated : aliased Extensions.bool; -- a_nodes.h:666 Corresponding_Declaration : aliased Declaration_ID; -- a_nodes.h:702 Corresponding_Body : aliased Declaration_ID; -- a_nodes.h:718 Corresponding_Subprogram_Derivation : aliased Declaration_ID; -- a_nodes.h:721 Corresponding_Type : aliased Type_Definition_ID; -- a_nodes.h:725 Corresponding_Equality_Operator : aliased Declaration_ID; -- a_nodes.h:727 Visible_Part_Declarative_Items : aliased Declarative_Item_List; -- a_nodes.h:730 Is_Private_Present : aliased Extensions.bool; -- a_nodes.h:731 Private_Part_Declarative_Items : aliased Declarative_Item_List; -- a_nodes.h:732 Declaration_Interface_List : aliased Expression_List; -- a_nodes.h:737 Renamed_Entity : aliased Expression_ID; -- a_nodes.h:746 Corresponding_Base_Entity : aliased Expression_ID; -- a_nodes.h:747 Protected_Operation_Items : aliased Declaration_List; -- a_nodes.h:749 Entry_Family_Definition : aliased Discrete_Subtype_Definition_ID; -- a_nodes.h:751 Entry_Index_Specification : aliased Declaration_ID; -- a_nodes.h:753 Entry_Barrier : aliased Expression_ID; -- a_nodes.h:754 Corresponding_Subunit : aliased Declaration_ID; -- a_nodes.h:760 Is_Subunit : aliased Extensions.bool; -- a_nodes.h:766 Corresponding_Body_Stub : aliased Declaration_ID; -- a_nodes.h:767 Generic_Formal_Part : aliased Element_ID_List; -- a_nodes.h:771 Generic_Unit_Name : aliased Expression_ID; -- a_nodes.h:777 Generic_Actual_Part : aliased Association_List; -- a_nodes.h:778 Formal_Subprogram_Default : aliased Expression_ID; -- a_nodes.h:781 Is_Dispatching_Operation : aliased Extensions.bool; -- a_nodes.h:792 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:430 type Definition_Kinds is (Not_A_Definition, A_Type_Definition, A_Subtype_Indication, A_Constraint, A_Component_Definition, A_Discrete_Subtype_Definition, A_Discrete_Range, An_Unknown_Discriminant_Part, A_Known_Discriminant_Part, A_Record_Definition, A_Null_Record_Definition, A_Null_Component, A_Variant_Part, A_Variant, An_Others_Choice, An_Access_Definition, A_Private_Type_Definition, A_Tagged_Private_Type_Definition, A_Private_Extension_Definition, A_Task_Definition, A_Protected_Definition, A_Formal_Type_Definition, An_Aspect_Specification) with Convention => C; -- a_nodes.h:803 type u_Type_Kinds is (Not_A_Type_Definition, A_Derived_Type_Definition, A_Derived_Record_Extension_Definition, An_Enumeration_Type_Definition, A_Signed_Integer_Type_Definition, A_Modular_Type_Definition, A_Root_Type_Definition, A_Floating_Point_Definition, An_Ordinary_Fixed_Point_Definition, A_Decimal_Fixed_Point_Definition, An_Unconstrained_Array_Definition, A_Constrained_Array_Definition, A_Record_Type_Definition, A_Tagged_Record_Type_Definition, An_Interface_Type_Definition, An_Access_Type_Definition) with Convention => C; -- a_nodes.h:836 subtype Type_Kinds is u_Type_Kinds; -- a_nodes.h:858 type u_Constraint_Kinds is (Not_A_Constraint, A_Range_Attribute_Reference, A_Simple_Expression_Range, A_Digits_Constraint, A_Delta_Constraint, An_Index_Constraint, A_Discriminant_Constraint) with Convention => C; -- a_nodes.h:860 subtype Constraint_Kinds is u_Constraint_Kinds; -- a_nodes.h:868 type u_Interface_Kinds is (Not_An_Interface, An_Ordinary_Interface, A_Limited_Interface, A_Task_Interface, A_Protected_Interface, A_Synchronized_Interface) with Convention => C; -- a_nodes.h:870 subtype Interface_Kinds is u_Interface_Kinds; -- a_nodes.h:877 type u_Root_Type_Kinds is (Not_A_Root_Type_Definition, A_Root_Integer_Definition, A_Root_Real_Definition, A_Universal_Integer_Definition, A_Universal_Real_Definition, A_Universal_Fixed_Definition) with Convention => C; -- a_nodes.h:879 subtype Root_Type_Kinds is u_Root_Type_Kinds; -- a_nodes.h:886 type u_Discrete_Range_Kinds is (Not_A_Discrete_Range, A_Discrete_Subtype_Indication, A_Discrete_Range_Attribute_Reference, A_Discrete_Simple_Expression_Range) with Convention => C; -- a_nodes.h:888 subtype Discrete_Range_Kinds is u_Discrete_Range_Kinds; -- a_nodes.h:893 type u_Formal_Type_Kinds is (Not_A_Formal_Type_Definition, A_Formal_Private_Type_Definition, A_Formal_Tagged_Private_Type_Definition, A_Formal_Derived_Type_Definition, A_Formal_Discrete_Type_Definition, A_Formal_Signed_Integer_Type_Definition, A_Formal_Modular_Type_Definition, A_Formal_Floating_Point_Definition, A_Formal_Ordinary_Fixed_Point_Definition, A_Formal_Decimal_Fixed_Point_Definition, A_Formal_Interface_Type_Definition, A_Formal_Unconstrained_Array_Definition, A_Formal_Constrained_Array_Definition, A_Formal_Access_Type_Definition) with Convention => C; -- a_nodes.h:895 subtype Formal_Type_Kinds is u_Formal_Type_Kinds; -- a_nodes.h:915 type u_Access_Type_Kinds is (Not_An_Access_Type_Definition, A_Pool_Specific_Access_To_Variable, An_Access_To_Variable, An_Access_To_Constant, An_Access_To_Procedure, An_Access_To_Protected_Procedure, An_Access_To_Function, An_Access_To_Protected_Function) with Convention => C; -- a_nodes.h:917 subtype Access_Type_Kinds is u_Access_Type_Kinds; -- a_nodes.h:926 type u_Access_Definition_Kinds is (Not_An_Access_Definition, An_Anonymous_Access_To_Variable, An_Anonymous_Access_To_Constant, An_Anonymous_Access_To_Procedure, An_Anonymous_Access_To_Protected_Procedure, An_Anonymous_Access_To_Function, An_Anonymous_Access_To_Protected_Function) with Convention => C; -- a_nodes.h:928 subtype Access_Definition_Kinds is u_Access_Definition_Kinds; -- a_nodes.h:936 type u_Access_Type_Struct is record Access_Type_Kind : aliased Access_Type_Kinds; -- a_nodes.h:939 Has_Null_Exclusion : aliased Extensions.bool; -- a_nodes.h:940 Is_Not_Null_Return : aliased Extensions.bool; -- a_nodes.h:944 Access_To_Object_Definition : aliased Subtype_Indication; -- a_nodes.h:948 Access_To_Subprogram_Parameter_Profile : aliased Parameter_Specification_List; -- a_nodes.h:953 Access_To_Function_Result_Profile : aliased Element_ID; -- a_nodes.h:956 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:938 subtype Access_Type_Struct is u_Access_Type_Struct; -- a_nodes.h:957 type u_Type_Definition_Struct is record Type_Kind : aliased Type_Kinds; -- a_nodes.h:960 Has_Abstract : aliased Extensions.bool; -- a_nodes.h:961 Has_Limited : aliased Extensions.bool; -- a_nodes.h:962 Has_Private : aliased Extensions.bool; -- a_nodes.h:963 Corresponding_Type_Operators : aliased Declaration_List; -- a_nodes.h:964 Has_Protected : aliased Extensions.bool; -- a_nodes.h:967 Has_Synchronized : aliased Extensions.bool; -- a_nodes.h:968 Has_Tagged : aliased Extensions.bool; -- a_nodes.h:970 Has_Task : aliased Extensions.bool; -- a_nodes.h:972 Has_Null_Exclusion : aliased Extensions.bool; -- a_nodes.h:977 Interface_Kind : aliased Interface_Kinds; -- a_nodes.h:979 Root_Type_Kind : aliased Root_Type_Kinds; -- a_nodes.h:981 Parent_Subtype_Indication : aliased Subtype_Indication; -- a_nodes.h:984 Record_Definition : aliased Definition; -- a_nodes.h:988 Implicit_Inherited_Declarations : aliased Declaration_List; -- a_nodes.h:991 Implicit_Inherited_Subprograms : aliased Declaration_List; -- a_nodes.h:992 Corresponding_Parent_Subtype : aliased Declaration; -- a_nodes.h:993 Corresponding_Root_Type : aliased Declaration; -- a_nodes.h:994 Corresponding_Type_Structure : aliased Declaration; -- a_nodes.h:995 Enumeration_Literal_Declarations : aliased Declaration_List; -- a_nodes.h:997 Integer_Constraint : aliased Range_Constraint; -- a_nodes.h:999 Mod_Static_Expression : aliased Expression; -- a_nodes.h:1001 Digits_Expression : aliased Expression; -- a_nodes.h:1004 Delta_Expression : aliased Expression; -- a_nodes.h:1007 Real_Range_Constraint : aliased Range_Constraint; -- a_nodes.h:1011 Index_Subtype_Definitions : aliased Expression_List; -- a_nodes.h:1013 Discrete_Subtype_Definitions : aliased Expression_List; -- a_nodes.h:1015 Array_Component_Definition : aliased Component_Definition; -- a_nodes.h:1018 Definition_Interface_List : aliased Expression_List; -- a_nodes.h:1021 Access_Type : aliased Access_Type_Struct; -- a_nodes.h:1023 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:959 subtype Type_Definition_Struct is u_Type_Definition_Struct; -- a_nodes.h:1024 type u_Subtype_Indication_Struct is record Has_Null_Exclusion : aliased Extensions.bool; -- a_nodes.h:1027 Subtype_Mark : aliased Expression; -- a_nodes.h:1028 Subtype_Constraint : aliased Constraint; -- a_nodes.h:1029 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1026 subtype Subtype_Indication_Struct is u_Subtype_Indication_Struct; -- a_nodes.h:1030 type u_Constraint_Struct is record Constraint_Kind : aliased Constraint_Kinds; -- a_nodes.h:1033 Digits_Expression : aliased Expression; -- a_nodes.h:1036 Delta_Expression : aliased Expression; -- a_nodes.h:1038 Real_Range_Constraint : aliased Range_Constraint; -- a_nodes.h:1041 Lower_Bound : aliased Expression; -- a_nodes.h:1043 Upper_Bound : aliased Expression; -- a_nodes.h:1044 Range_Attribute : aliased Expression; -- a_nodes.h:1046 Discrete_Ranges : aliased Discrete_Range_List; -- a_nodes.h:1048 Discriminant_Associations : aliased Discriminant_Association_List; -- a_nodes.h:1050 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1032 subtype Constraint_Struct is u_Constraint_Struct; -- a_nodes.h:1051 type u_Component_Definition_Struct is record Component_Definition_View : aliased Definition; -- a_nodes.h:1054 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1053 subtype Component_Definition_Struct is u_Component_Definition_Struct; -- a_nodes.h:1055 type u_Discrete_Subtype_Definition_Struct is record Discrete_Range_Kind : aliased Discrete_Range_Kinds; -- a_nodes.h:1058 Subtype_Mark : aliased Expression; -- a_nodes.h:1061 Subtype_Constraint : aliased Constraint; -- a_nodes.h:1062 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1057 subtype Discrete_Subtype_Definition_Struct is u_Discrete_Subtype_Definition_Struct; -- a_nodes.h:1063 type u_Discrete_Range_Struct is record Discrete_Range_Kind : aliased Discrete_Range_Kinds; -- a_nodes.h:1066 Subtype_Mark : aliased Expression; -- a_nodes.h:1069 Subtype_Constraint : aliased Constraint; -- a_nodes.h:1070 Lower_Bound : aliased Expression; -- a_nodes.h:1072 Upper_Bound : aliased Expression; -- a_nodes.h:1073 Range_Attribute : aliased Expression; -- a_nodes.h:1075 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1065 subtype Discrete_Range_Struct is u_Discrete_Range_Struct; -- a_nodes.h:1076 type u_Known_Discriminant_Part_Struct is record Discriminants : aliased Discriminant_Specification_List; -- a_nodes.h:1079 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1078 subtype Known_Discriminant_Part_Struct is u_Known_Discriminant_Part_Struct; -- a_nodes.h:1080 type u_Record_Definition_Struct is record Record_Components : aliased Record_Component_List; -- a_nodes.h:1083 Implicit_Components : aliased Record_Component_List; -- a_nodes.h:1084 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1082 subtype Record_Definition_Struct is u_Record_Definition_Struct; -- a_nodes.h:1085 type u_Variant_Part_Struct is record Discriminant_Direct_Name : aliased Name; -- a_nodes.h:1088 Variants : aliased Variant_List; -- a_nodes.h:1089 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1087 subtype Variant_Part_Struct is u_Variant_Part_Struct; -- a_nodes.h:1090 type u_Variant_Struct is record Record_Components : aliased Record_Component_List; -- a_nodes.h:1093 Implicit_Components : aliased Record_Component_List; -- a_nodes.h:1094 Variant_Choices : aliased Element_ID_List; -- a_nodes.h:1095 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1092 subtype Variant_Struct is u_Variant_Struct; -- a_nodes.h:1096 type u_Access_Definition_Struct is record Access_Definition_Kind : aliased Access_Definition_Kinds; -- a_nodes.h:1099 Has_Null_Exclusion : aliased Extensions.bool; -- a_nodes.h:1100 Is_Not_Null_Return : aliased Extensions.bool; -- a_nodes.h:1104 Anonymous_Access_To_Object_Subtype_Mark : aliased Expression; -- a_nodes.h:1107 Access_To_Subprogram_Parameter_Profile : aliased Parameter_Specification_List; -- a_nodes.h:1112 Access_To_Function_Result_Profile : aliased Element_ID; -- a_nodes.h:1115 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1098 subtype Access_Definition_Struct is u_Access_Definition_Struct; -- a_nodes.h:1116 type u_Private_Type_Definition_Struct is record Has_Abstract : aliased Extensions.bool; -- a_nodes.h:1119 Has_Limited : aliased Extensions.bool; -- a_nodes.h:1120 Has_Private : aliased Extensions.bool; -- a_nodes.h:1121 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1118 subtype Private_Type_Definition_Struct is u_Private_Type_Definition_Struct; -- a_nodes.h:1122 type u_Tagged_Private_Type_Definition_Struct is record Has_Abstract : aliased Extensions.bool; -- a_nodes.h:1125 Has_Limited : aliased Extensions.bool; -- a_nodes.h:1126 Has_Private : aliased Extensions.bool; -- a_nodes.h:1127 Has_Tagged : aliased Extensions.bool; -- a_nodes.h:1128 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1124 subtype Tagged_Private_Type_Definition_Struct is u_Tagged_Private_Type_Definition_Struct; -- a_nodes.h:1129 type u_Private_Extension_Definition_Struct is record Has_Abstract : aliased Extensions.bool; -- a_nodes.h:1132 Has_Limited : aliased Extensions.bool; -- a_nodes.h:1133 Has_Private : aliased Extensions.bool; -- a_nodes.h:1134 Has_Synchronized : aliased Extensions.bool; -- a_nodes.h:1135 Implicit_Inherited_Declarations : aliased Declaration_List; -- a_nodes.h:1136 Implicit_Inherited_Subprograms : aliased Declaration_List; -- a_nodes.h:1137 Definition_Interface_List : aliased Expression_List; -- a_nodes.h:1138 Ancestor_Subtype_Indication : aliased Subtype_Indication; -- a_nodes.h:1139 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1131 subtype Private_Extension_Definition_Struct is u_Private_Extension_Definition_Struct; -- a_nodes.h:1140 type u_Task_Definition_Struct is record Has_Task : aliased Extensions.bool; -- a_nodes.h:1143 Visible_Part_Items : aliased Declarative_Item_List; -- a_nodes.h:1144 Private_Part_Items : aliased Declarative_Item_List; -- a_nodes.h:1145 Is_Private_Present : aliased Extensions.bool; -- a_nodes.h:1146 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1142 subtype Task_Definition_Struct is u_Task_Definition_Struct; -- a_nodes.h:1147 type u_Protected_Definition_Struct is record Has_Protected : aliased Extensions.bool; -- a_nodes.h:1150 Visible_Part_Items : aliased Declarative_Item_List; -- a_nodes.h:1151 Private_Part_Items : aliased Declarative_Item_List; -- a_nodes.h:1152 Is_Private_Present : aliased Extensions.bool; -- a_nodes.h:1153 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1149 subtype Protected_Definition_Struct is u_Protected_Definition_Struct; -- a_nodes.h:1154 type u_Formal_Type_Definition_Struct is record Formal_Type_Kind : aliased Formal_Type_Kinds; -- a_nodes.h:1157 Corresponding_Type_Operators : aliased Declaration_List; -- a_nodes.h:1158 Has_Abstract : aliased Extensions.bool; -- a_nodes.h:1163 Has_Limited : aliased Extensions.bool; -- a_nodes.h:1164 Has_Private : aliased Extensions.bool; -- a_nodes.h:1167 Has_Synchronized : aliased Extensions.bool; -- a_nodes.h:1169 Has_Tagged : aliased Extensions.bool; -- a_nodes.h:1171 Interface_Kind : aliased Interface_Kinds; -- a_nodes.h:1173 Implicit_Inherited_Declarations : aliased Declaration_List; -- a_nodes.h:1175 Implicit_Inherited_Subprograms : aliased Declaration_List; -- a_nodes.h:1176 Index_Subtype_Definitions : aliased Expression_List; -- a_nodes.h:1178 Discrete_Subtype_Definitions : aliased Expression_List; -- a_nodes.h:1180 Array_Component_Definition : aliased Component_Definition; -- a_nodes.h:1183 Subtype_Mark : aliased Expression; -- a_nodes.h:1185 Definition_Interface_List : aliased Expression_List; -- a_nodes.h:1188 Access_Type : aliased Access_Type_Struct; -- a_nodes.h:1190 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1156 subtype Formal_Type_Definition_Struct is u_Formal_Type_Definition_Struct; -- a_nodes.h:1191 type u_Aspect_Specification_Struct is record Aspect_Mark : aliased Element_ID; -- a_nodes.h:1194 Aspect_Definition : aliased Element_ID; -- a_nodes.h:1195 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1193 subtype Aspect_Specification_Struct is u_Aspect_Specification_Struct; -- a_nodes.h:1196 subtype No_Struct is int; -- a_nodes.h:1198 subtype Unknown_Discriminant_Part_Struct is No_Struct; -- a_nodes.h:1199 subtype Null_Record_Definition_Struct is No_Struct; -- a_nodes.h:1200 subtype Null_Component_Struct is No_Struct; -- a_nodes.h:1201 subtype Others_Choice_Struct is No_Struct; -- a_nodes.h:1202 type u_Definition_Union (discr : unsigned := 0) is record case discr is when 0 => Dummy_Member : aliased int; -- a_nodes.h:1205 when 1 => The_Type_Definition : aliased Type_Definition_Struct; -- a_nodes.h:1206 when 2 => The_Subtype_Indication : aliased Subtype_Indication_Struct; -- a_nodes.h:1207 when 3 => The_Constraint : aliased Constraint_Struct; -- a_nodes.h:1208 when 4 => The_Component_Definition : aliased Component_Definition_Struct; -- a_nodes.h:1209 when 5 => The_Discrete_Subtype_Definition : aliased Discrete_Subtype_Definition_Struct; -- a_nodes.h:1210 when 6 => The_Discrete_Range : aliased Discrete_Range_Struct; -- a_nodes.h:1211 when 7 => The_Unknown_Discriminant_Part : aliased Unknown_Discriminant_Part_Struct; -- a_nodes.h:1212 when 8 => The_Known_Discriminant_Part : aliased Known_Discriminant_Part_Struct; -- a_nodes.h:1213 when 9 => The_Record_Definition : aliased Record_Definition_Struct; -- a_nodes.h:1214 when 10 => The_Null_Record_Definition : aliased Null_Record_Definition_Struct; -- a_nodes.h:1215 when 11 => The_Null_Component : aliased Null_Component_Struct; -- a_nodes.h:1216 when 12 => The_Variant_Part : aliased Variant_Part_Struct; -- a_nodes.h:1217 when 13 => The_Variant : aliased Variant_Struct; -- a_nodes.h:1218 when 14 => The_Others_Choice : aliased Others_Choice_Struct; -- a_nodes.h:1219 when 15 => The_Access_Definition : aliased Access_Definition_Struct; -- a_nodes.h:1220 when 16 => The_Private_Type_Definition : aliased Private_Type_Definition_Struct; -- a_nodes.h:1221 when 17 => The_Tagged_Private_Type_Definition : aliased Tagged_Private_Type_Definition_Struct; -- a_nodes.h:1222 when 18 => The_Private_Extension_Definition : aliased Private_Extension_Definition_Struct; -- a_nodes.h:1223 when 19 => The_Task_Definition : aliased Task_Definition_Struct; -- a_nodes.h:1224 when 20 => The_Protected_Definition : aliased Protected_Definition_Struct; -- a_nodes.h:1225 when 21 => The_Formal_Type_Definition : aliased Formal_Type_Definition_Struct; -- a_nodes.h:1226 when others => The_Aspect_Specification : aliased Aspect_Specification_Struct; -- a_nodes.h:1227 end case; end record with Convention => C_Pass_By_Copy, Unchecked_Union => True; -- a_nodes.h:1204 subtype Definition_Union is u_Definition_Union; -- a_nodes.h:1228 type Definition_Struct is record Definition_Kind : aliased Definition_Kinds; -- a_nodes.h:1232 The_Union : aliased Definition_Union; -- a_nodes.h:1233 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1231 type Expression_Kinds is (Not_An_Expression, A_Box_Expression, An_Integer_Literal, A_Real_Literal, A_String_Literal, An_Identifier, An_Operator_Symbol, A_Character_Literal, An_Enumeration_Literal, An_Explicit_Dereference, A_Function_Call, An_Indexed_Component, A_Slice, A_Selected_Component, An_Attribute_Reference, A_Record_Aggregate, An_Extension_Aggregate, A_Positional_Array_Aggregate, A_Named_Array_Aggregate, An_And_Then_Short_Circuit, An_Or_Else_Short_Circuit, An_In_Membership_Test, A_Not_In_Membership_Test, A_Null_Literal, A_Parenthesized_Expression, A_Raise_Expression, A_Type_Conversion, A_Qualified_Expression, An_Allocation_From_Subtype, An_Allocation_From_Qualified_Expression, A_Case_Expression, An_If_Expression, A_For_All_Quantified_Expression, A_For_Some_Quantified_Expression) with Convention => C; -- a_nodes.h:1244 type Attribute_Kinds is (Not_An_Attribute, An_Access_Attribute, An_Address_Attribute, An_Adjacent_Attribute, An_Aft_Attribute, An_Alignment_Attribute, A_Base_Attribute, A_Bit_Order_Attribute, A_Body_Version_Attribute, A_Callable_Attribute, A_Caller_Attribute, A_Ceiling_Attribute, A_Class_Attribute, A_Component_Size_Attribute, A_Compose_Attribute, A_Constrained_Attribute, A_Copy_Sign_Attribute, A_Count_Attribute, A_Definite_Attribute, A_Delta_Attribute, A_Denorm_Attribute, A_Digits_Attribute, An_Exponent_Attribute, An_External_Tag_Attribute, A_First_Attribute, A_First_Bit_Attribute, A_Floor_Attribute, A_Fore_Attribute, A_Fraction_Attribute, An_Identity_Attribute, An_Image_Attribute, An_Input_Attribute, A_Last_Attribute, A_Last_Bit_Attribute, A_Leading_Part_Attribute, A_Length_Attribute, A_Machine_Attribute, A_Machine_Emax_Attribute, A_Machine_Emin_Attribute, A_Machine_Mantissa_Attribute, A_Machine_Overflows_Attribute, A_Machine_Radix_Attribute, A_Machine_Rounds_Attribute, A_Max_Attribute, A_Max_Size_In_Storage_Elements_Attribute, A_Min_Attribute, A_Model_Attribute, A_Model_Emin_Attribute, A_Model_Epsilon_Attribute, A_Model_Mantissa_Attribute, A_Model_Small_Attribute, A_Modulus_Attribute, An_Output_Attribute, A_Partition_ID_Attribute, A_Pos_Attribute, A_Position_Attribute, A_Pred_Attribute, A_Range_Attribute, A_Read_Attribute, A_Remainder_Attribute, A_Round_Attribute, A_Rounding_Attribute, A_Safe_First_Attribute, A_Safe_Last_Attribute, A_Scale_Attribute, A_Scaling_Attribute, A_Signed_Zeros_Attribute, A_Size_Attribute, A_Small_Attribute, A_Storage_Pool_Attribute, A_Storage_Size_Attribute, A_Succ_Attribute, A_Tag_Attribute, A_Terminated_Attribute, A_Truncation_Attribute, An_Unbiased_Rounding_Attribute, An_Unchecked_Access_Attribute, A_Val_Attribute, A_Valid_Attribute, A_Value_Attribute, A_Version_Attribute, A_Wide_Image_Attribute, A_Wide_Value_Attribute, A_Wide_Width_Attribute, A_Width_Attribute, A_Write_Attribute, A_Machine_Rounding_Attribute, A_Mod_Attribute, A_Priority_Attribute, A_Stream_Size_Attribute, A_Wide_Wide_Image_Attribute, A_Wide_Wide_Value_Attribute, A_Wide_Wide_Width_Attribute, A_Max_Alignment_For_Allocation_Attribute, An_Overlaps_Storage_Attribute, An_Implementation_Defined_Attribute, An_Unknown_Attribute) with Convention => C; -- a_nodes.h:1289 type Expression_Struct is record Expression_Kind : aliased Expression_Kinds; -- a_nodes.h:1402 Is_Prefix_Notation : aliased Extensions.bool; -- a_nodes.h:1403 Corresponding_Expression_Type : aliased Declaration_ID; -- a_nodes.h:1404 Corresponding_Expression_Type_Definition : aliased Element_ID; -- a_nodes.h:1405 Operator_Kind : aliased Operator_Kinds; -- a_nodes.h:1409 Attribute_Kind : aliased Attribute_Kinds; -- a_nodes.h:1414 Value_Image : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:1415 Name_Image : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:1420 Corresponding_Name_Definition : aliased Defining_Name_ID; -- a_nodes.h:1421 Corresponding_Name_Definition_List : aliased Defining_Name_List; -- a_nodes.h:1422 Corresponding_Name_Declaration : aliased Element_ID; -- a_nodes.h:1423 Prefix : aliased Expression_ID; -- a_nodes.h:1430 Index_Expressions : aliased Expression_List; -- a_nodes.h:1432 Slice_Range : aliased Discrete_Range_ID; -- a_nodes.h:1434 Selector : aliased Expression_ID; -- a_nodes.h:1436 Attribute_Designator_Identifier : aliased Expression_ID; -- a_nodes.h:1438 Attribute_Designator_Expressions : aliased Expression_List; -- a_nodes.h:1447 Record_Component_Associations : aliased Association_List; -- a_nodes.h:1450 Extension_Aggregate_Expression : aliased Expression_ID; -- a_nodes.h:1452 Array_Component_Associations : aliased Association_List; -- a_nodes.h:1455 Expression_Parenthesized : aliased Expression_ID; -- a_nodes.h:1457 Is_Prefix_Call : aliased Extensions.bool; -- a_nodes.h:1459 Corresponding_Called_Function : aliased Declaration_ID; -- a_nodes.h:1462 Function_Call_Parameters : aliased Element_ID_List; -- a_nodes.h:1464 Short_Circuit_Operation_Left_Expression : aliased Expression_ID; -- a_nodes.h:1467 Short_Circuit_Operation_Right_Expression : aliased Expression_ID; -- a_nodes.h:1468 Membership_Test_Expression : aliased Expression_ID; -- a_nodes.h:1471 Membership_Test_Choices : aliased Element_ID_List; -- a_nodes.h:1472 Converted_Or_Qualified_Subtype_Mark : aliased Expression_ID; -- a_nodes.h:1475 Converted_Or_Qualified_Expression : aliased Expression_ID; -- a_nodes.h:1476 Allocator_Subtype_Indication : aliased Subtype_Indication_ID; -- a_nodes.h:1478 Allocator_Qualified_Expression : aliased Expression_ID; -- a_nodes.h:1480 Expression_Paths : aliased Expression_Path_List; -- a_nodes.h:1483 Is_Generalized_Indexing : aliased Extensions.bool; -- a_nodes.h:1485 Is_Generalized_Reference : aliased Extensions.bool; -- a_nodes.h:1487 Iterator_Specification : aliased Declaration_ID; -- a_nodes.h:1490 Predicate : aliased Expression_ID; -- a_nodes.h:1493 Subpool_Name : aliased Expression_ID; -- a_nodes.h:1496 Corresponding_Generic_Element : aliased Defining_Name_ID; -- a_nodes.h:1501 Is_Dispatching_Call : aliased Extensions.bool; -- a_nodes.h:1503 Is_Call_On_Dispatching_Operation : aliased Extensions.bool; -- a_nodes.h:1504 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1401 type Association_Kinds is (Not_An_Association, A_Pragma_Argument_Association, A_Discriminant_Association, A_Record_Component_Association, An_Array_Component_Association, A_Parameter_Association, A_Generic_Association) with Convention => C; -- a_nodes.h:1515 type Association_Struct is record Association_Kind : aliased Association_Kinds; -- a_nodes.h:1528 Array_Component_Choices : aliased Expression_List; -- a_nodes.h:1531 Record_Component_Choices : aliased Expression_List; -- a_nodes.h:1533 Component_Expression : aliased Expression_ID; -- a_nodes.h:1536 Formal_Parameter : aliased Expression_ID; -- a_nodes.h:1540 Actual_Parameter : aliased Expression_ID; -- a_nodes.h:1541 Discriminant_Selector_Names : aliased Expression_List; -- a_nodes.h:1543 Discriminant_Expression : aliased Expression_ID; -- a_nodes.h:1544 Is_Normalized : aliased Extensions.bool; -- a_nodes.h:1549 Is_Defaulted_Association : aliased Extensions.bool; -- a_nodes.h:1553 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1527 type Statement_Kinds is (Not_A_Statement, A_Null_Statement, An_Assignment_Statement, An_If_Statement, A_Case_Statement, A_Loop_Statement, A_While_Loop_Statement, A_For_Loop_Statement, A_Block_Statement, An_Exit_Statement, A_Goto_Statement, A_Procedure_Call_Statement, A_Return_Statement, An_Extended_Return_Statement, An_Accept_Statement, An_Entry_Call_Statement, A_Requeue_Statement, A_Requeue_Statement_With_Abort, A_Delay_Until_Statement, A_Delay_Relative_Statement, A_Terminate_Alternative_Statement, A_Selective_Accept_Statement, A_Timed_Entry_Call_Statement, A_Conditional_Entry_Call_Statement, An_Asynchronous_Select_Statement, An_Abort_Statement, A_Raise_Statement, A_Code_Statement) with Convention => C; -- a_nodes.h:1564 type Statement_Struct is record Statement_Kind : aliased Statement_Kinds; -- a_nodes.h:1601 Corresponding_Pragmas : aliased Pragma_Element_ID_List; -- a_nodes.h:1602 Label_Names : aliased Defining_Name_List; -- a_nodes.h:1603 Is_Prefix_Notation : aliased Extensions.bool; -- a_nodes.h:1607 Pragmas : aliased Pragma_Element_ID_List; -- a_nodes.h:1614 Corresponding_End_Name : aliased Element_ID; -- a_nodes.h:1620 Assignment_Variable_Name : aliased Expression_ID; -- a_nodes.h:1622 Assignment_Expression : aliased Expression_ID; -- a_nodes.h:1623 Statement_Paths : aliased Path_List; -- a_nodes.h:1630 Case_Expression : aliased Expression_ID; -- a_nodes.h:1632 Statement_Identifier : aliased Defining_Name_ID; -- a_nodes.h:1637 Is_Name_Repeated : aliased Extensions.bool; -- a_nodes.h:1641 While_Condition : aliased Expression_ID; -- a_nodes.h:1643 For_Loop_Parameter_Specification : aliased Declaration_ID; -- a_nodes.h:1645 Loop_Statements : aliased Statement_List; -- a_nodes.h:1649 Is_Declare_Block : aliased Extensions.bool; -- a_nodes.h:1651 Block_Declarative_Items : aliased Declarative_Item_List; -- a_nodes.h:1652 Block_Statements : aliased Statement_List; -- a_nodes.h:1653 Block_Exception_Handlers : aliased Exception_Handler_List; -- a_nodes.h:1654 Exit_Loop_Name : aliased Expression_ID; -- a_nodes.h:1656 Exit_Condition : aliased Expression_ID; -- a_nodes.h:1657 Corresponding_Loop_Exited : aliased Expression_ID; -- a_nodes.h:1658 Return_Expression : aliased Expression_ID; -- a_nodes.h:1660 Return_Object_Declaration : aliased Declaration_ID; -- a_nodes.h:1663 Extended_Return_Statements : aliased Statement_List; -- a_nodes.h:1664 Extended_Return_Exception_Handlers : aliased Exception_Handler_List; -- a_nodes.h:1665 Goto_Label : aliased Expression_ID; -- a_nodes.h:1667 Corresponding_Destination_Statement : aliased Statement_ID; -- a_nodes.h:1668 Called_Name : aliased Expression_ID; -- a_nodes.h:1671 Corresponding_Called_Entity : aliased Declaration_ID; -- a_nodes.h:1672 Call_Statement_Parameters : aliased Association_List; -- a_nodes.h:1673 Accept_Entry_Index : aliased Expression_ID; -- a_nodes.h:1676 Accept_Entry_Direct_Name : aliased Name_ID; -- a_nodes.h:1677 Accept_Parameters : aliased Parameter_Specification_List; -- a_nodes.h:1679 Accept_Body_Statements : aliased Statement_List; -- a_nodes.h:1680 Accept_Body_Exception_Handlers : aliased Statement_List; -- a_nodes.h:1681 Corresponding_Entry : aliased Declaration_ID; -- a_nodes.h:1682 Requeue_Entry_Name : aliased Name_ID; -- a_nodes.h:1685 Delay_Expression : aliased Expression_ID; -- a_nodes.h:1688 Aborted_Tasks : aliased Expression_List; -- a_nodes.h:1690 Raised_Exception : aliased Expression_ID; -- a_nodes.h:1692 Associated_Message : aliased Expression_ID; -- a_nodes.h:1693 Qualified_Expression : aliased Expression_ID; -- a_nodes.h:1695 Is_Dispatching_Call : aliased Extensions.bool; -- a_nodes.h:1697 Is_Call_On_Dispatching_Operation : aliased Extensions.bool; -- a_nodes.h:1698 Corresponding_Called_Entity_Unwound : aliased Declaration; -- a_nodes.h:1701 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1600 type Path_Kinds is (Not_A_Path, An_If_Path, An_Elsif_Path, An_Else_Path, A_Case_Path, A_Select_Path, An_Or_Path, A_Then_Abort_Path, A_Case_Expression_Path, An_If_Expression_Path, An_Elsif_Expression_Path, An_Else_Expression_Path) with Convention => C; -- a_nodes.h:1712 type Path_Struct is record Path_Kind : aliased Path_Kinds; -- a_nodes.h:1768 Sequence_Of_Statements : aliased Statement_List; -- a_nodes.h:1769 Dependent_Expression : aliased Expression; -- a_nodes.h:1770 Condition_Expression : aliased Expression_ID; -- a_nodes.h:1775 Case_Path_Alternative_Choices : aliased Element_ID_List; -- a_nodes.h:1778 Guard : aliased Expression_ID; -- a_nodes.h:1781 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1767 type Clause_Kinds is (Not_A_Clause, A_Use_Package_Clause, A_Use_Type_Clause, A_Use_All_Type_Clause, A_With_Clause, A_Representation_Clause, A_Component_Clause) with Convention => C; -- a_nodes.h:1792 type u_Representation_Clause_Kinds is (Not_A_Representation_Clause, An_Attribute_Definition_Clause, An_Enumeration_Representation_Clause, A_Record_Representation_Clause, An_At_Clause) with Convention => C; -- a_nodes.h:1804 subtype Representation_Clause_Kinds is u_Representation_Clause_Kinds; -- a_nodes.h:1810 type u_Representation_Clause_Struct is record Representation_Clause_Kind : aliased Representation_Clause_Kinds; -- a_nodes.h:1813 Representation_Clause_Name : aliased Name; -- a_nodes.h:1814 Pragmas : aliased Pragma_Element_ID_List; -- a_nodes.h:1818 Representation_Clause_Expression : aliased Expression; -- a_nodes.h:1822 Mod_Clause_Expression : aliased Expression; -- a_nodes.h:1824 Component_Clauses : aliased Component_Clause_List; -- a_nodes.h:1825 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1812 subtype Representation_Clause_Struct is u_Representation_Clause_Struct; -- a_nodes.h:1826 type Clause_Struct is record Clause_Kind : aliased Clause_Kinds; -- a_nodes.h:1830 Has_Limited : aliased Extensions.bool; -- a_nodes.h:1833 Clause_Names : aliased Name_List; -- a_nodes.h:1838 Representation_Clause_Name : aliased Name_ID; -- a_nodes.h:1840 Representation_Clause_Expression : aliased Expression_ID; -- a_nodes.h:1841 Mod_Clause_Expression : aliased Expression_ID; -- a_nodes.h:1842 Component_Clauses : aliased Element_ID_List; -- a_nodes.h:1843 Component_Clause_Position : aliased Expression_ID; -- a_nodes.h:1844 Component_Clause_Range : aliased Element_ID; -- a_nodes.h:1845 Representation_Clause : aliased Representation_Clause_Struct; -- a_nodes.h:1848 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1829 type Exception_Handler_Struct is record Pragmas : aliased Pragma_Element_ID_List; -- a_nodes.h:1864 Choice_Parameter_Specification : aliased Declaration_ID; -- a_nodes.h:1865 Exception_Choices : aliased Element_ID_List; -- a_nodes.h:1866 Handler_Statements : aliased Statement_List; -- a_nodes.h:1867 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1863 type Element_Union (discr : unsigned := 0) is record case discr is when 0 => Dummy_Member : aliased int; -- a_nodes.h:1880 when 1 => The_Pragma : aliased Pragma_Struct; -- a_nodes.h:1881 when 2 => Defining_Name : aliased Defining_Name_Struct; -- a_nodes.h:1882 when 3 => Declaration : aliased Declaration_Struct; -- a_nodes.h:1883 when 4 => Definition : aliased Definition_Struct; -- a_nodes.h:1884 when 5 => Expression : aliased Expression_Struct; -- a_nodes.h:1885 when 6 => Association : aliased Association_Struct; -- a_nodes.h:1886 when 7 => Statement : aliased Statement_Struct; -- a_nodes.h:1887 when 8 => Path : aliased Path_Struct; -- a_nodes.h:1888 when 9 => Clause : aliased Clause_Struct; -- a_nodes.h:1889 when others => Exception_Handler : aliased Exception_Handler_Struct; -- a_nodes.h:1890 end case; end record with Convention => C_Pass_By_Copy, Unchecked_Union => True; -- a_nodes.h:1879 type Enclosing_Kinds is (Not_Enclosing, Enclosing_Element, Enclosing_Unit) with Convention => C; -- a_nodes.h:1893 type Source_Location_Struct is record Unit_Name : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:1901 First_Line : aliased int; -- a_nodes.h:1902 First_Column : aliased int; -- a_nodes.h:1903 Last_Line : aliased int; -- a_nodes.h:1904 Last_Column : aliased int; -- a_nodes.h:1905 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1900 subtype Unit_ID is int; -- a_nodes.h:1909 type u_Element_Struct is record ID : aliased Element_ID; -- a_nodes.h:1913 Element_Kind : aliased Element_Kinds; -- a_nodes.h:1914 Enclosing_Compilation_Unit : aliased Unit_ID; -- a_nodes.h:1915 Is_Part_Of_Implicit : aliased Extensions.bool; -- a_nodes.h:1916 Is_Part_Of_Inherited : aliased Extensions.bool; -- a_nodes.h:1917 Is_Part_Of_Instance : aliased Extensions.bool; -- a_nodes.h:1918 Hash : aliased ASIS_Integer; -- a_nodes.h:1919 Enclosing_Element_ID : aliased Element_ID; -- a_nodes.h:1920 Enclosing_Kind : aliased Enclosing_Kinds; -- a_nodes.h:1921 Source_Location : aliased Source_Location_Struct; -- a_nodes.h:1922 Debug_Image : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:1923 The_Union : aliased Element_Union; -- a_nodes.h:1924 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1912 subtype Element_Struct is u_Element_Struct; -- a_nodes.h:1925 type Unit_ID_Ptr is access all Unit_ID; -- a_nodes.h:1935 type Unit_ID_Array_Struct is record Length : aliased int; -- a_nodes.h:1940 IDs : Unit_ID_Ptr; -- a_nodes.h:1941 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:1939 subtype Unit_List is Unit_ID_Array_Struct; -- a_nodes.h:1943 type Unit_Kinds is (Not_A_Unit, A_Procedure, A_Function, A_Package, A_Generic_Procedure, A_Generic_Function, A_Generic_Package, A_Procedure_Instance, A_Function_Instance, A_Package_Instance, A_Procedure_Renaming, A_Function_Renaming, A_Package_Renaming, A_Generic_Procedure_Renaming, A_Generic_Function_Renaming, A_Generic_Package_Renaming, A_Procedure_Body, A_Function_Body, A_Package_Body, A_Procedure_Body_Subunit, A_Function_Body_Subunit, A_Package_Body_Subunit, A_Task_Body_Subunit, A_Protected_Body_Subunit, A_Nonexistent_Declaration, A_Nonexistent_Body, A_Configuration_Compilation, An_Unknown_Unit) with Convention => C; -- a_nodes.h:1945 type Unit_Classes is (Not_A_Class, A_Public_Declaration, A_Public_Body, A_Public_Declaration_And_Body, A_Private_Declaration, A_Private_Body, A_Separate_Body) with Convention => C; -- a_nodes.h:2012 type Unit_Origins is (Not_An_Origin, A_Predefined_Unit, An_Implementation_Unit, An_Application_Unit) with Convention => C; -- a_nodes.h:2033 type u_Unit_Struct is record ID : aliased Unit_ID; -- a_nodes.h:2053 Unit_Kind : aliased Unit_Kinds; -- a_nodes.h:2054 Unit_Class : aliased Unit_Classes; -- a_nodes.h:2055 Unit_Origin : aliased Unit_Origins; -- a_nodes.h:2056 Unit_Full_Name : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2057 Unique_Name : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2058 Exists : aliased Extensions.bool; -- a_nodes.h:2059 Can_Be_Main_Program : aliased Extensions.bool; -- a_nodes.h:2060 Is_Body_Required : aliased Extensions.bool; -- a_nodes.h:2061 Text_Name : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2062 Text_Form : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2063 Object_Name : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2064 Object_Form : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2065 Compilation_Command_Line_Options : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2066 Debug_Image : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2067 Unit_Declaration : aliased Declaration_ID; -- a_nodes.h:2068 Context_Clause_Elements : aliased Context_Clause_List; -- a_nodes.h:2069 Compilation_Pragmas : aliased Pragma_Element_ID_List; -- a_nodes.h:2070 Is_Standard : aliased Extensions.bool; -- a_nodes.h:2071 Corresponding_Children : aliased Unit_List; -- a_nodes.h:2077 Corresponding_Parent_Declaration : aliased Unit_ID; -- a_nodes.h:2096 Corresponding_Declaration : aliased Unit_ID; -- a_nodes.h:2101 Corresponding_Body : aliased Unit_ID; -- a_nodes.h:2109 Subunits : aliased Unit_List; -- a_nodes.h:2118 Corresponding_Subunit_Parent_Body : aliased Unit_ID; -- a_nodes.h:2124 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:2052 subtype Unit_Struct is u_Unit_Struct; -- a_nodes.h:2125 type u_Context_Struct is record name : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2135 parameters : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2136 debug_image : Interfaces.C.Strings.chars_ptr; -- a_nodes.h:2137 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:2134 subtype Context_Struct is u_Context_Struct; -- a_nodes.h:2138 type u_Unit_Struct_List_Struct; type u_Unit_Struct_List_Struct is record Unit : aliased Unit_Struct; -- a_nodes.h:2145 Next : access u_Unit_Struct_List_Struct; -- a_nodes.h:2146 Next_Count : aliased int; -- a_nodes.h:2147 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:2144 subtype Unit_Struct_List_Struct is u_Unit_Struct_List_Struct; -- a_nodes.h:2148 type Unit_Structs_Ptr is access all Unit_Struct_List_Struct; -- a_nodes.h:2150 type u_Element_Struct_List_Struct; type u_Element_Struct_List_Struct is record Element : aliased Element_Struct; -- a_nodes.h:2153 Next : access u_Element_Struct_List_Struct; -- a_nodes.h:2154 Next_Count : aliased int; -- a_nodes.h:2155 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:2152 subtype Element_Struct_List_Struct is u_Element_Struct_List_Struct; -- a_nodes.h:2156 type Element_Structs_Ptr is access all Element_Struct_List_Struct; -- a_nodes.h:2158 type u_Nodes_Struct is record Context : aliased Context_Struct; -- a_nodes.h:2161 Units : Unit_Structs_Ptr; -- a_nodes.h:2162 Elements : Element_Structs_Ptr; -- a_nodes.h:2163 end record with Convention => C_Pass_By_Copy; -- a_nodes.h:2160 subtype Nodes_Struct is u_Nodes_Struct; -- a_nodes.h:2164 end a_nodes_h;
-- This file is generated by SWIG. Please do *not* modify by hand. -- with festival.Pointers; with interfaces.C; package festival.pointer_Pointers is -- FILE_Pointer_Pointer -- type FILE_Pointer_Pointer is access all festival.Pointers.FILE_Pointer; -- ostream_Pointer_Pointer -- type ostream_Pointer_Pointer is access all festival.Pointers.ostream_Pointer; -- ModuleDescription_Pointer_Pointer -- type ModuleDescription_Pointer_Pointer is access all festival.Pointers.ModuleDescription_Pointer; end festival.pointer_Pointers;
-- { dg-do compile } package constructor is type R (Name_Length : Natural) is record Name : Wide_String (1..Name_Length); Multiple : Boolean; end record; Null_Params : constant R := (Name_Length => 0, Name => "", Multiple => False); end;
-- -- echo [string ...] -- -- Write arguments to the standard output -- -- The echo utility writes any specified operands, separated by single blank -- (`` '') characters and followed by a newline (``\n'') character, to the -- standard output. -- with Ada.Command_Line; with Ada.Text_IO; use Ada; procedure Echo is begin if Command_Line.Argument_Count > 0 then Text_IO.Put (Command_Line.Argument (1)); for Arg in 2 .. Command_Line.Argument_Count loop Text_IO.Put (' '); Text_IO.Put (Command_Line.Argument (Arg)); end loop; end if; Text_IO.New_Line; end Echo;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_Io; use Ada.Integer_Text_Io; with MOS; use MOS; with Instruction; use Instruction; with Ada.Real_Time; package Main_Loop is use type Ada.Real_Time.Time; use type Ada.Real_Time.Time_Span; The_Clock : Ada.Real_Time.Time := Ada.Real_Time.Clock; procedure Main_Loop_f (This : in out MOS_T; Instruction : in Fun_Array); end Main_Loop;
package Array_Swapping is subtype ElementType is Natural range 0..1000; subtype IndexType is Positive range 1..100; type ArrayType is array (IndexType) of ElementType; procedure Rotate3(A: in out ArrayType; X, Y, Z: in IndexType) with Depends => (A => (A, X, Y, Z)), Pre => X /= Y and Y /= Z and X /= Z, Post => A = (A'Old with delta X => A'Old(Y), Y => A'Old(Z), Z => A'Old(X)); end Array_Swapping;
with Ada.Text_IO; use Ada.Text_IO; procedure Test is begin if 0=1 then Q(0); elsif 1=2 then Q(1); end if; end;
------------------------------------------------------------------------------ -- Copyright (c) 2013, 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.References.Tools is function Is_Consistent (Left, Right : Reference) return Boolean is begin return (Left.Data = Right.Data) = (Left.Count = Right.Count); end Is_Consistent; function Is_Valid (Ref : Reference) return Boolean is begin return (Ref.Data = null) = (Ref.Count = null); end Is_Valid; function Count (Ref : Reference) return Natural is begin if Ref.Count /= null then return Natural (Ref.Count.all); else return 0; end if; end Count; end Natools.References.Tools;
-- -- The author disclaims copyright to this source code. In place of -- a legal notice, here is a blessing: -- -- May you do good and not evil. -- May you find forgiveness for yourself and forgive others. -- May you share freely, not taking more than you give. -- with Ada.Text_IO; package body Exceptions is procedure Put (Occurrence : Ada.Exceptions.Exception_Occurrence) is use Ada.Exceptions; use Ada.Text_IO; Occ : Exception_Occurrence renames Occurrence; begin Put_Line (Exception_Name (Occ)); New_Line; Put_Line (Exception_Message (Occ)); New_Line; end Put; end Exceptions;
-- Display_NORX_Traces -- A utility to display traces of the encryption process for the test vectors -- suggested in Appendix A of the NORX specification -- Copyright (c) 2016, James Humphry - see LICENSE file for details with System.Storage_Elements; with NORX; generic with package NORX_Package is new NORX(<>); Test_Message_Length : System.Storage_Elements.Storage_Offset := 128; procedure Display_NORX_Traces;